@ -2,23 +2,25 @@ package gr.thmmy.mthmmy.utils;
import android.app.Activity ;
import android.app.Activity ;
import android.content.Context ;
import android.content.Context ;
import android.content.res.Resources ;
import android.support.v7.widget.AppCompatImageButton ;
import android.support.v7.widget.AppCompatImageButton ;
import android.text.Editable ;
import android.text.Editable ;
import android.util.AttributeSet ;
import android.util.AttributeSet ;
import android.util.TypedValue ;
import android.util.SparseArray ;
import android.view.LayoutInflater ;
import android.view.LayoutInflater ;
import android.view.inputmethod.EditorInfo ;
import android.view.inputmethod.EditorInfo ;
import android.view.inputmethod.InputConnection ;
import android.view.inputmethod.InputConnection ;
import android.view.inputmethod.InputMethodManager ;
import android.view.inputmethod.InputMethodManager ;
import android.widget.EditText ;
import android.widget.EditText ;
import android.widget.GridLayout ;
import android.widget.LinearLayout ;
import android.widget.LinearLayout ;
import android.widget.PopupWindow ;
import gr.thmmy.mthmmy.R ;
import gr.thmmy.mthmmy.R ;
public class EditorView extends LinearLayout {
public class EditorView extends LinearLayout {
private SparseArray < String > colors = new SparseArray < > ( ) ;
private SparseArray < String > fonts = new SparseArray < > ( ) ;
private EditText editText ;
private EditText editText ;
private AppCompatImageButton emojiButton ;
private AppCompatImageButton emojiButton ;
private AppCompatImageButton submitButton ;
private AppCompatImageButton submitButton ;
@ -93,12 +95,39 @@ public class EditorView extends LinearLayout {
getText ( ) . insert ( editText . getSelectionStart ( ) , "[s][/s]" ) ;
getText ( ) . insert ( editText . getSelectionStart ( ) , "[s][/s]" ) ;
editText . setSelection ( editText . getSelectionStart ( ) - 4 ) ;
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 - > {
findViewById ( R . id . text_color_button ) . setOnClickListener ( view - > {
if ( editText . hasSelection ( ) )
PopupWindow popupWindow = new PopupWindow ( view . getContext ( ) ) ;
editText . getText ( ) . delete ( editText . getSelectionStart ( ) , editText . getSelectionEnd ( ) ) ;
popupWindow . setHeight ( LayoutParams . WRAP_CONTENT ) ;
getText ( ) . insert ( editText . getSelectionStart ( ) , "[color=][/color]" ) ;
popupWindow . setWidth ( LayoutParams . WRAP_CONTENT ) ;
editText . setSelection ( editText . getSelectionStart ( ) - 8 ) ;
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=" + colors . get ( v . getId ( ) ) + "][/color]" ) ;
editText . setSelection ( editText . getSelectionStart ( ) - 8 ) ;
popupWindow . dismiss ( ) ;
} ) ;
}
popupWindow . showAsDropDown ( view ) ;
} ) ;
} ) ;
findViewById ( R . id . text_size_button ) . setOnClickListener ( view - > {
findViewById ( R . id . text_size_button ) . setOnClickListener ( view - > {
if ( editText . hasSelection ( ) )
if ( editText . hasSelection ( ) )
@ -106,6 +135,12 @@ public class EditorView extends LinearLayout {
getText ( ) . insert ( editText . getSelectionStart ( ) , "[size=10pt][/size]" ) ;
getText ( ) . insert ( editText . getSelectionStart ( ) , "[size=10pt][/size]" ) ;
editText . setSelection ( editText . getSelectionStart ( ) - 7 ) ;
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 - > {
findViewById ( R . id . align_left_button ) . setOnClickListener ( view - > {
if ( editText . hasSelection ( ) )
if ( editText . hasSelection ( ) )
editText . getText ( ) . delete ( editText . getSelectionStart ( ) , editText . getSelectionEnd ( ) ) ;
editText . getText ( ) . delete ( editText . getSelectionStart ( ) , editText . getSelectionEnd ( ) ) ;