Browse Source

emoji keyboard progress

pull/45/head
Thodoris1999 6 years ago
parent
commit
c34b7cdc09
  1. 95
      app/src/main/java/gr/thmmy/mthmmy/utils/EditorView.java
  2. 22
      app/src/main/res/layout/editor_view.xml
  3. 11
      app/src/main/res/xml-keyssoft/emoji_keyboard.xml

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

@ -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() {
}
} }
} }

22
app/src/main/res/layout/editor_view.xml

@ -1,13 +1,11 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout <merge
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android">
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout <LinearLayout
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content"> android:layout_height="wrap_content"
android:orientation="horizontal">
<!--bold, italic, etc buttons--> <!--bold, italic, etc buttons-->
</LinearLayout> </LinearLayout>
<LinearLayout <LinearLayout
@ -42,4 +40,14 @@
android:contentDescription="@string/submit" android:contentDescription="@string/submit"
app:srcCompat="@drawable/ic_send_accent_24dp" /> app:srcCompat="@drawable/ic_send_accent_24dp" />
</LinearLayout> </LinearLayout>
</LinearLayout>
<android.inputmethodservice.KeyboardView
android:id="@+id/emoji_keyboard"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"
android:focusable="true"
android:focusableInTouchMode="true"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" />
</merge>

11
app/src/main/res/xml-keyssoft/emoji_keyboard.xml

@ -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…
Cancel
Save