mirror of https://github.com/ThmmyNoLife/mTHMMY
Thodoris1999
6 years ago
3 changed files with 119 additions and 9 deletions
@ -1,10 +1,101 @@ |
|||||
package gr.thmmy.mthmmy.utils; |
package gr.thmmy.mthmmy.utils; |
||||
|
|
||||
import android.content.Context; |
import android.content.Context; |
||||
|
import android.inputmethodservice.Keyboard; |
||||
|
import android.inputmethodservice.KeyboardView; |
||||
|
import android.support.design.widget.TextInputLayout; |
||||
|
import android.support.v7.widget.AppCompatImageButton; |
||||
|
import android.text.Editable; |
||||
|
import android.view.LayoutInflater; |
||||
|
import android.widget.EditText; |
||||
import android.widget.LinearLayout; |
import android.widget.LinearLayout; |
||||
|
import android.widget.RelativeLayout; |
||||
|
|
||||
|
import gr.thmmy.mthmmy.R; |
||||
|
|
||||
|
public class EditorView extends RelativeLayout { |
||||
|
|
||||
|
private EditText editText; |
||||
|
private AppCompatImageButton submitButton; |
||||
|
|
||||
public class EditorView extends LinearLayout { |
|
||||
public EditorView(Context context) { |
public EditorView(Context context) { |
||||
super(context); |
super(context); |
||||
|
|
||||
|
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); |
||||
|
inflater.inflate(R.layout.editor_view, this, true); |
||||
|
|
||||
|
LinearLayout controls = (LinearLayout) getChildAt(0); |
||||
|
LinearLayout ediTextKeyboardAndSubmit = (LinearLayout) getChildAt(1); |
||||
|
editText = ((TextInputLayout) ediTextKeyboardAndSubmit.getChildAt(0)).getEditText(); |
||||
|
submitButton = (AppCompatImageButton) ediTextKeyboardAndSubmit.getChildAt(1); |
||||
|
|
||||
|
Keyboard emojiKeyboard = new Keyboard(context, R.xml.emoji_keyboard); |
||||
|
KeyboardView emojiKeyboardView= (KeyboardView) getChildAt(2); |
||||
|
emojiKeyboardView.setKeyboard(emojiKeyboard); |
||||
|
emojiKeyboardView.setPreviewEnabled(false); |
||||
|
emojiKeyboardView.setOnKeyboardActionListener(new EmojiKeyboardListener()); |
||||
|
} |
||||
|
|
||||
|
public Editable getText() { |
||||
|
return editText.getText(); |
||||
|
} |
||||
|
|
||||
|
public void setOnSubmitListener(OnClickListener onSubmitListener) { |
||||
|
submitButton.setOnClickListener(onSubmitListener); |
||||
|
} |
||||
|
|
||||
|
class EmojiKeyboardListener implements KeyboardView.OnKeyboardActionListener { |
||||
|
|
||||
|
public final static int SMILE = 10; |
||||
|
|
||||
|
@Override |
||||
|
public void onPress(int primaryCode) { |
||||
|
|
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void onRelease(int primaryCode) { |
||||
|
|
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void onKey(int primaryCode, int[] keyCodes) { |
||||
|
Editable editable = editText.getText(); |
||||
|
if (editText.hasSelection()) |
||||
|
editable.delete(editText.getSelectionStart(), editText.getSelectionEnd()); |
||||
|
int cursorIndex = editText.getSelectionStart(); |
||||
|
String appendedText = ""; |
||||
|
switch (primaryCode) { |
||||
|
case SMILE: |
||||
|
appendedText = "^:)^"; |
||||
|
break; |
||||
|
} |
||||
|
editable.insert(cursorIndex, appendedText); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void onText(CharSequence text) { |
||||
|
|
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void swipeLeft() { |
||||
|
|
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void swipeRight() { |
||||
|
|
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void swipeDown() { |
||||
|
|
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void swipeUp() { |
||||
|
|
||||
|
} |
||||
} |
} |
||||
} |
} |
||||
|
@ -0,0 +1,11 @@ |
|||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||
|
<Keyboard |
||||
|
xmlns:android="http://schemas.android.com/apk/res/android" |
||||
|
android:keyWidth="20%" |
||||
|
android:keyHeight="10%"> |
||||
|
|
||||
|
<Row> |
||||
|
<Key android:codes="10" android:keyIcon="@drawable/ic_arrow_drop_up_accent_24dp"/> |
||||
|
</Row> |
||||
|
|
||||
|
</Keyboard> |
Loading…
Reference in new issue