Browse Source

colored letters and dot in color picker

pull/49/head
Thodoris1999 6 years ago
parent
commit
b6bd67b7cf
  1. 7
      app/src/main/java/gr/thmmy/mthmmy/editorview/EditorView.java
  2. 42
      app/src/main/res/layout/editor_view_color_picker.xml
  3. 21
      app/src/main/res/values/colors.xml

7
app/src/main/java/gr/thmmy/mthmmy/editorview/EditorView.java

@ -1,5 +1,6 @@
package gr.thmmy.mthmmy.editorview; package gr.thmmy.mthmmy.editorview;
import android.annotation.SuppressLint;
import android.app.Activity; import android.app.Activity;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.content.Context; import android.content.Context;
@ -20,6 +21,7 @@ import android.view.inputmethod.InputMethodManager;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.PopupWindow; import android.widget.PopupWindow;
import android.widget.ScrollView; import android.widget.ScrollView;
import android.widget.TextView;
import java.util.Objects; import java.util.Objects;
@ -50,6 +52,7 @@ public class EditorView extends LinearLayout {
init(context, attrs); init(context, attrs);
} }
@SuppressLint("SetTextI18n")
private void init(Context context, AttributeSet attrs) { private void init(Context context, AttributeSet attrs) {
LayoutInflater.from(context).inflate(R.layout.editor_view, this, true); LayoutInflater.from(context).inflate(R.layout.editor_view, this, true);
setOrientation(VERTICAL); setOrientation(VERTICAL);
@ -142,7 +145,9 @@ public class EditorView extends LinearLayout {
LinearLayout colorPicker = (LinearLayout) colorPickerScrollview.getChildAt(0); LinearLayout colorPicker = (LinearLayout) colorPickerScrollview.getChildAt(0);
popupWindow.setContentView(colorPickerScrollview); popupWindow.setContentView(colorPickerScrollview);
for (int i = 0; i < colorPicker.getChildCount(); i++) { for (int i = 0; i < colorPicker.getChildCount(); i++) {
colorPicker.getChildAt(i).setOnClickListener(v -> { TextView child = (TextView) colorPicker.getChildAt(i);
child.setText("\u2B24 " + child.getText());
child.setOnClickListener(v -> {
boolean hadTextSelection = editText.hasSelection(); boolean hadTextSelection = editText.hasSelection();
getText().insert(editText.getSelectionStart(), "[color=" + colors.get(v.getId()) + "]"); getText().insert(editText.getSelectionStart(), "[color=" + colors.get(v.getId()) + "]");
getText().insert(editText.getSelectionEnd(), "[/color]"); getText().insert(editText.getSelectionEnd(), "[/color]");

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

@ -13,71 +13,85 @@
<TextView <TextView
android:id="@+id/black" android:id="@+id/black"
style="@style/PopupMenuItem.TopItem" style="@style/PopupMenuItem.TopItem"
android:text="@string/black" /> android:text="@string/black"
android:textColor="@color/black"/>
<TextView <TextView
android:id="@+id/red" android:id="@+id/red"
style="@style/PopupMenuItem" style="@style/PopupMenuItem"
android:text="@string/red" /> android:text="@string/red"
android:textColor="@color/red"/>
<TextView <TextView
android:id="@+id/yellow" android:id="@+id/yellow"
style="@style/PopupMenuItem" style="@style/PopupMenuItem"
android:text="@string/yellow" /> android:text="@string/yellow"
android:textColor="@color/yellow"/>
<TextView <TextView
android:id="@+id/pink" android:id="@+id/pink"
style="@style/PopupMenuItem" style="@style/PopupMenuItem"
android:text="@string/pink" /> android:text="@string/pink"
android:textColor="@color/pink"/>
<TextView <TextView
android:id="@+id/green" android:id="@+id/green"
style="@style/PopupMenuItem" style="@style/PopupMenuItem"
android:text="@string/green" /> android:text="@string/green"
android:textColor="@color/green"/>
<TextView <TextView
android:id="@+id/orange" android:id="@+id/orange"
style="@style/PopupMenuItem" style="@style/PopupMenuItem"
android:text="@string/orange" /> android:text="@string/orange"
android:textColor="@color/orange"/>
<TextView <TextView
android:id="@+id/purple" android:id="@+id/purple"
style="@style/PopupMenuItem" style="@style/PopupMenuItem"
android:text="@string/purple" /> android:text="@string/purple"
android:textColor="@color/purple"/>
<TextView <TextView
android:id="@+id/blue" android:id="@+id/blue"
style="@style/PopupMenuItem" style="@style/PopupMenuItem"
android:text="@string/blue" /> android:text="@string/blue"
android:textColor="@color/blue"/>
<TextView <TextView
android:id="@+id/beige" android:id="@+id/beige"
style="@style/PopupMenuItem" style="@style/PopupMenuItem"
android:text="@string/beige" /> android:text="@string/beige"
android:textColor="@color/beige"/>
<TextView <TextView
android:id="@+id/brown" android:id="@+id/brown"
style="@style/PopupMenuItem" style="@style/PopupMenuItem"
android:text="@string/brown" /> android:text="@string/brown"
android:textColor="@color/brown"/>
<TextView <TextView
android:id="@+id/teal" android:id="@+id/teal"
style="@style/PopupMenuItem" style="@style/PopupMenuItem"
android:text="@string/teal" /> android:text="@string/teal"
android:textColor="@color/teal"/>
<TextView <TextView
android:id="@+id/navy" android:id="@+id/navy"
style="@style/PopupMenuItem" style="@style/PopupMenuItem"
android:text="@string/navy" /> android:text="@string/navy"
android:textColor="@color/navy"/>
<TextView <TextView
android:id="@+id/maroon" android:id="@+id/maroon"
style="@style/PopupMenuItem" style="@style/PopupMenuItem"
android:text="@string/maroon" /> android:text="@string/maroon"
android:textColor="@color/maroon"/>
<TextView <TextView
android:id="@+id/lime_green" android:id="@+id/lime_green"
style="@style/PopupMenuItem.BottomItem" style="@style/PopupMenuItem.BottomItem"
android:text="@string/lime_green" /> android:text="@string/lime_green"
android:textColor="@color/lime_green"/>
</LinearLayout> </LinearLayout>
</ScrollView> </ScrollView>

21
app/src/main/res/values/colors.xml

@ -26,4 +26,25 @@
<color name="dialog_bg_semi_transparent_dark">#D92B2B2B</color> <color name="dialog_bg_semi_transparent_dark">#D92B2B2B</color>
<color name="member_of_the_month">#E91E63</color> <color name="member_of_the_month">#E91E63</color>
<color name="topic_post_icon">@color/primary_text</color> <color name="topic_post_icon">@color/primary_text</color>
<color name="red">#FF0000</color>
<color name="maroon">#800000</color>
<color name="brown">#A52A2A</color>
<color name="orange">#FFA500</color>
<color name="yellow">#FFFF00</color>
<color name="olive">#808000</color>
<color name="green">#008000</color>
<color name="purple">#800080</color>
<color name="fuchsia">#FF00FF</color>
<color name="pink">#FFC0CB</color>
<color name="beige">#F5F5DC</color>
<color name="lime">#00FF00</color>
<color name="lime_green">#32CD32</color>
<color name="teal">#008080</color>
<color name="aqua">#00FFFF</color>
<color name="blue">#0000FF</color>
<color name="navy">#000080</color>
<color name="black">#000000</color>
<color name="grey">#808080</color>
<color name="silver">#C0C0C0</color>
</resources> </resources>

Loading…
Cancel
Save