Browse Source

color picker

pull/45/head
Thodoris1999 6 years ago
parent
commit
c89117c884
  1. 45
      app/src/main/java/gr/thmmy/mthmmy/utils/EditorView.java
  2. 21
      app/src/main/res/layout/editor_view_color_picker.xml
  3. 16
      app/src/main/res/values/strings.xml
  4. 17
      app/src/main/res/values/styles.xml

45
app/src/main/java/gr/thmmy/mthmmy/utils/EditorView.java

@ -2,23 +2,25 @@ package gr.thmmy.mthmmy.utils;
import android.app.Activity;
import android.content.Context;
import android.content.res.Resources;
import android.support.v7.widget.AppCompatImageButton;
import android.text.Editable;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.util.SparseArray;
import android.view.LayoutInflater;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputConnection;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.GridLayout;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import gr.thmmy.mthmmy.R;
public class EditorView extends LinearLayout {
private SparseArray<String> colors = new SparseArray<>();
private SparseArray<String> fonts = new SparseArray<>();
private EditText editText;
private AppCompatImageButton emojiButton;
private AppCompatImageButton submitButton;
@ -93,12 +95,39 @@ public class EditorView extends LinearLayout {
getText().insert(editText.getSelectionStart(), "[s][/s]");
editText.setSelection(editText.getSelectionStart() - 4);
});
// TODO: popup menu for colors
colors.append(R.id.black, "black");
colors.append(R.id.red, "red");
colors.append(R.id.yellow, "yellow");
colors.append(R.id.pink, "pink");
colors.append(R.id.green, "green");
colors.append(R.id.orange, "orange");
colors.append(R.id.purple, "purple");
colors.append(R.id.blue, "blue");
colors.append(R.id.beige, "beige");
colors.append(R.id.brown, "brown");
colors.append(R.id.teal, "teal");
colors.append(R.id.navy, "navy");
colors.append(R.id.maroon, "maroon");
colors.append(R.id.lime_green, "limegreen");
findViewById(R.id.text_color_button).setOnClickListener(view -> {
PopupWindow popupWindow = new PopupWindow(view.getContext());
popupWindow.setHeight(LayoutParams.WRAP_CONTENT);
popupWindow.setWidth(LayoutParams.WRAP_CONTENT);
popupWindow.setFocusable(true);
LinearLayout colorPicker = (LinearLayout) LayoutInflater.from(context).inflate(R.layout.editor_view_color_picker, null);
popupWindow.setContentView(colorPicker);
for (int i = 0; i < colorPicker.getChildCount(); i++) {
colorPicker.getChildAt(i).setOnClickListener(v -> {
if (editText.hasSelection())
editText.getText().delete(editText.getSelectionStart(), editText.getSelectionEnd());
getText().insert(editText.getSelectionStart(), "[color=][/color]");
getText().insert(editText.getSelectionStart(), "[color=" + colors.get(v.getId()) + "][/color]");
editText.setSelection(editText.getSelectionStart() - 8);
popupWindow.dismiss();
});
}
popupWindow.showAsDropDown(view);
});
findViewById(R.id.text_size_button).setOnClickListener(view -> {
if (editText.hasSelection())
@ -106,6 +135,12 @@ public class EditorView extends LinearLayout {
getText().insert(editText.getSelectionStart(), "[size=10pt][/size]");
editText.setSelection(editText.getSelectionStart() - 7);
});
findViewById(R.id.unordered_list_button).setOnClickListener(view -> {
if (editText.hasSelection())
editText.getText().delete(editText.getSelectionStart(), editText.getSelectionEnd());
getText().insert(editText.getSelectionStart(), "[list]\n[li][/li]\n[li][/li]\n[/list]");
editText.setSelection(editText.getSelectionStart() - 23);
});
findViewById(R.id.align_left_button).setOnClickListener(view -> {
if (editText.hasSelection())
editText.getText().delete(editText.getSelectionStart(), editText.getSelectionEnd());

21
app/src/main/res/layout/editor_view_color_picker.xml

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView android:id="@+id/black" android:text="@string/black" style="@style/PopupMenuItem.TopItem"/>
<TextView android:id="@+id/red" android:text="@string/red" style="@style/PopupMenuItem"/>
<TextView android:id="@+id/yellow" android:text="@string/yellow" style="@style/PopupMenuItem"/>
<TextView android:id="@+id/pink" android:text="@string/pink" style="@style/PopupMenuItem"/>
<TextView android:id="@+id/green" android:text="@string/green" style="@style/PopupMenuItem"/>
<TextView android:id="@+id/orange" android:text="@string/orange" style="@style/PopupMenuItem"/>
<TextView android:id="@+id/purple" android:text="@string/purple" style="@style/PopupMenuItem"/>
<TextView android:id="@+id/blue" android:text="@string/blue" style="@style/PopupMenuItem"/>
<TextView android:id="@+id/beige" android:text="@string/beige" style="@style/PopupMenuItem"/>
<TextView android:id="@+id/brown" android:text="@string/brown" style="@style/PopupMenuItem"/>
<TextView android:id="@+id/teal" android:text="@string/teal" style="@style/PopupMenuItem"/>
<TextView android:id="@+id/navy" android:text="@string/navy" style="@style/PopupMenuItem"/>
<TextView android:id="@+id/maroon" android:text="@string/maroon" style="@style/PopupMenuItem"/>
<TextView android:id="@+id/lime_green" android:text="@string/lime_green" style="@style/PopupMenuItem.BottomItem"/>
</LinearLayout>

16
app/src/main/res/values/strings.xml

@ -156,4 +156,20 @@
<string name="pref_category_uploading">Uploading</string>
<string name="pref_title_uploading_app_signature_enable">App signature</string>
<string name="pref_summary_uploading_app_signature_enable">If enabled, an \"uploaded from mTHMMY\" message will be inserted at the end of your uploads descriptions</string>
<!-- EditorView -->
<string name="black">Black</string>
<string name="red">Red</string>
<string name="yellow">Yellow</string>
<string name="pink">Pink</string>
<string name="green">Green</string>
<string name="purple">Purple</string>
<string name="orange">Orange</string>
<string name="blue">Blue</string>
<string name="beige">Beige</string>
<string name="brown">Brown</string>
<string name="teal">Teal</string>
<string name="navy">Navy</string>
<string name="maroon">Maroon</string>
<string name="lime_green">Lime Green</string>
</resources>

17
app/src/main/res/values/styles.xml

@ -33,6 +33,23 @@
<item name="android:textAppearanceSmallPopupMenu">@color/accent</item>
</style>
<style name="PopupMenuItem" parent="Widget.AppCompat.PopupMenu">
<item name="android:layout_height">32dp</item>
<item name="android:layout_width">128dp</item>
<item name="android:background">?android:attr/selectableItemBackground</item>
<item name="android:gravity">center_vertical</item>
<item name="android:paddingStart">16dp</item>
<item name="android:textColor">@color/primary_text</item>
</style>
<style name="PopupMenuItem.TopItem" parent="PopupMenuItem" >
<item name="android:paddingTop">8dp</item>
</style>
<style name="PopupMenuItem.BottomItem" parent="PopupMenuItem" >
<item name="android:paddingBottom">8dp</item>
</style>
<style name="ToolbarTheme" parent="ThemeOverlay.AppCompat.Light">
<item name="android:textColorPrimary">@android:color/white</item>
<item name="android:colorBackground">@color/colorPrimary</item>

Loading…
Cancel
Save