├── .gitignore
├── .idea
├── compiler.xml
├── copyright
│ └── profiles_settings.xml
├── gradle.xml
├── misc.xml
├── modules.xml
└── runConfigurations.xml
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── leavesc
│ │ └── hello
│ │ └── keyboard
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── leavesc
│ │ │ └── hello
│ │ │ └── keyboard
│ │ │ ├── EmojiKeyboard.java
│ │ │ ├── MainActivity.java
│ │ │ ├── ResolvedActivity.java
│ │ │ ├── ScreenUtils.java
│ │ │ ├── UnresolvedActivity.java
│ │ │ └── common
│ │ │ ├── CommonRecyclerAdapter.java
│ │ │ ├── CommonRecyclerHolder.java
│ │ │ ├── Message.java
│ │ │ └── MessageAdapter.java
│ └── res
│ │ ├── drawable-xxhdpi
│ │ ├── icon_file.png
│ │ ├── icon_more.png
│ │ ├── icon_photo.png
│ │ └── icon_voice.png
│ │ ├── drawable
│ │ └── edit_bg.xml
│ │ ├── layout
│ │ ├── activity_main.xml
│ │ ├── activity_resolved.xml
│ │ ├── activity_unresolved.xml
│ │ ├── item_message.xml
│ │ ├── view_emoji_panel.xml
│ │ ├── view_input.xml
│ │ └── view_message_list.xml
│ │ ├── mipmap-hdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-mdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ └── values
│ │ ├── colors.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── leavesc
│ └── hello
│ └── keyboard
│ └── ExampleUnitTest.java
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── resolved.gif
├── settings.gradle
└── unresolved.gif
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 | .externalNativeBuild
10 |
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
17 |
18 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Keyboard
2 | 解决软键盘和表情面板切换时的跳闪问题
3 |
4 | 解决前
5 |
6 | 
7 |
8 |
9 | 解决后
10 |
11 | 
12 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 28
5 | defaultConfig {
6 | applicationId "leavesc.hello.keyboard"
7 | minSdkVersion 21
8 | targetSdkVersion 28
9 | versionCode 1
10 | versionName "1.0"
11 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
12 | }
13 | buildTypes {
14 | release {
15 | minifyEnabled false
16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 | }
20 |
21 | dependencies {
22 | implementation fileTree(dir: 'libs', include: ['*.jar'])
23 | implementation 'com.android.support:appcompat-v7:28.0.0'
24 | implementation 'com.android.support.constraint:constraint-layout:1.1.3'
25 | testImplementation 'junit:junit:4.12'
26 | androidTestImplementation 'com.android.support.test:runner:1.0.2'
27 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
28 | implementation 'com.android.support:recyclerview-v7:28.0.0'
29 | }
30 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in E:\Software\SDK/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
19 | # Uncomment this to preserve the line number information for
20 | # debugging stack traces.
21 | #-keepattributes SourceFile,LineNumberTable
22 |
23 | # If you keep the line number information, uncomment this to
24 | # hide the original source file name.
25 | #-renamesourcefileattribute SourceFile
26 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/leavesc/hello/keyboard/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package leavesc.hello.keyboard;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumentation test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("leavesc.hello.keyboard", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/app/src/main/java/leavesc/hello/keyboard/EmojiKeyboard.java:
--------------------------------------------------------------------------------
1 | package leavesc.hello.keyboard;
2 |
3 | import android.app.Activity;
4 | import android.content.Context;
5 | import android.content.SharedPreferences;
6 | import android.graphics.Rect;
7 | import android.os.Handler;
8 | import android.util.Log;
9 | import android.view.MotionEvent;
10 | import android.view.View;
11 | import android.view.WindowManager;
12 | import android.view.inputmethod.InputMethodManager;
13 | import android.widget.EditText;
14 | import android.widget.LinearLayout;
15 |
16 | /**
17 | * 作者: chenZY
18 | * 时间: 2017/8/26 18:12
19 | * 描述:
20 | */
21 | public class EmojiKeyboard {
22 |
23 | private Activity activity;
24 |
25 | //文本输入框
26 | private EditText editText;
27 |
28 | //表情面板
29 | private View emojiPanelView;
30 |
31 | //内容View,即除了表情布局和输入框布局以外的布局
32 | //用于固定输入框一行的高度以防止跳闪
33 | private View contentView;
34 |
35 | private InputMethodManager inputMethodManager;
36 |
37 | private SharedPreferences sharedPreferences;
38 |
39 | private static final String EMOJI_KEYBOARD = "EmojiKeyboard";
40 |
41 | private static final String KEY_SOFT_KEYBOARD_HEIGHT = "SoftKeyboardHeight";
42 |
43 | private static final int SOFT_KEYBOARD_HEIGHT_DEFAULT = 654;
44 |
45 | private Handler handler;
46 |
47 | public EmojiKeyboard(Activity activity, EditText editText, View emojiPanelView, View emojiPanelSwitchView, View contentView) {
48 | init(activity, editText, emojiPanelView, emojiPanelSwitchView, contentView);
49 | }
50 |
51 | private void init(Activity activity, EditText editText, View emojiPanelView, View emojiPanelSwitchView, View contentView) {
52 | this.activity = activity;
53 | this.editText = editText;
54 | this.emojiPanelView = emojiPanelView;
55 | this.contentView = contentView;
56 | this.editText.setOnTouchListener(new View.OnTouchListener() {
57 | @Override
58 | public boolean onTouch(final View v, MotionEvent event) {
59 | if (event.getAction() == MotionEvent.ACTION_UP && EmojiKeyboard.this.emojiPanelView.isShown()) {
60 | lockContentViewHeight();
61 | hideEmojiPanel(true);
62 | unlockContentViewHeight();
63 | }
64 | return false;
65 | }
66 | });
67 | this.contentView.setOnTouchListener(new View.OnTouchListener() {
68 | @Override
69 | public boolean onTouch(View view, MotionEvent motionEvent) {
70 | if (motionEvent.getAction() == MotionEvent.ACTION_UP) {
71 | if (EmojiKeyboard.this.emojiPanelView.isShown()) {
72 | hideEmojiPanel(false);
73 | } else if (isSoftKeyboardShown()) {
74 | hideSoftKeyboard();
75 | }
76 | }
77 | return false;
78 | }
79 | });
80 | //用于弹出表情面板的View
81 | emojiPanelSwitchView.setOnClickListener(new View.OnClickListener() {
82 | @Override
83 | public void onClick(View v) {
84 | if (EmojiKeyboard.this.emojiPanelView.isShown()) {
85 | lockContentViewHeight();
86 | hideEmojiPanel(true);
87 | unlockContentViewHeight();
88 | } else {
89 | if (isSoftKeyboardShown()) {
90 | lockContentViewHeight();
91 | showEmojiPanel();
92 | unlockContentViewHeight();
93 | } else {
94 | showEmojiPanel();
95 | }
96 | }
97 | }
98 | });
99 | this.inputMethodManager = (InputMethodManager) this.activity.getSystemService(Context.INPUT_METHOD_SERVICE);
100 | this.sharedPreferences = this.activity.getSharedPreferences(EMOJI_KEYBOARD, Context.MODE_PRIVATE);
101 | this.activity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
102 | this.handler = new Handler();
103 | init();
104 | }
105 |
106 | /**
107 | * 如果之前没有保存过键盘高度值
108 | * 则在进入Activity时自动打开键盘,并把高度值保存下来
109 | */
110 | private void init() {
111 | if (!sharedPreferences.contains(KEY_SOFT_KEYBOARD_HEIGHT)) {
112 | handler.postDelayed(new Runnable() {
113 | @Override
114 | public void run() {
115 | showSoftKeyboard(true);
116 | }
117 | }, 200);
118 | }
119 | }
120 |
121 | /**
122 | * 当点击返回键时需要先隐藏表情面板
123 | */
124 | public boolean interceptBackPress() {
125 | if (emojiPanelView.isShown()) {
126 | hideEmojiPanel(false);
127 | return true;
128 | }
129 | return false;
130 | }
131 |
132 | /**
133 | * 锁定内容View以防止跳闪
134 | */
135 | private void lockContentViewHeight() {
136 | LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) contentView.getLayoutParams();
137 | layoutParams.height = contentView.getHeight();
138 | layoutParams.weight = 0;
139 | }
140 |
141 | /**
142 | * 释放锁定的内容View
143 | */
144 | private void unlockContentViewHeight() {
145 | handler.postDelayed(new Runnable() {
146 | @Override
147 | public void run() {
148 | ((LinearLayout.LayoutParams) contentView.getLayoutParams()).weight = 1;
149 | }
150 | }, 200);
151 | }
152 |
153 | /**
154 | * 获取键盘的高度
155 | */
156 | private int getSoftKeyboardHeight() {
157 | Rect rect = new Rect();
158 | activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(rect);
159 | //屏幕当前可见高度,不包括状态栏
160 | int displayHeight = rect.bottom - rect.top;
161 | //屏幕可用高度
162 | int availableHeight = ScreenUtils.getAvailableScreenHeight(activity);
163 | //用于计算键盘高度
164 | int softInputHeight = availableHeight - displayHeight - ScreenUtils.getStatusBarHeight(activity);
165 | Log.e("TAG-di", displayHeight + "");
166 | Log.e("TAG-av", availableHeight + "");
167 | Log.e("TAG-so", softInputHeight + "");
168 | if (softInputHeight != 0) {
169 | // 因为考虑到用户可能会主动调整键盘高度,所以只能是每次获取到键盘高度时都将其存储起来
170 | sharedPreferences.edit().putInt(KEY_SOFT_KEYBOARD_HEIGHT, softInputHeight).apply();
171 | }
172 | return softInputHeight;
173 | }
174 |
175 | /**
176 | * 获取本地存储的键盘高度值或者是返回默认值
177 | */
178 | private int getSoftKeyboardHeightLocalValue() {
179 | return sharedPreferences.getInt(KEY_SOFT_KEYBOARD_HEIGHT, SOFT_KEYBOARD_HEIGHT_DEFAULT);
180 | }
181 |
182 | /**
183 | * 判断是否显示了键盘
184 | */
185 | private boolean isSoftKeyboardShown() {
186 | return getSoftKeyboardHeight() != 0;
187 | }
188 |
189 | /**
190 | * 令编辑框获取焦点并显示键盘
191 | */
192 | private void showSoftKeyboard(boolean saveSoftKeyboardHeight) {
193 | editText.requestFocus();
194 | inputMethodManager.showSoftInput(editText, 0);
195 | if (saveSoftKeyboardHeight) {
196 | handler.postDelayed(new Runnable() {
197 | @Override
198 | public void run() {
199 | getSoftKeyboardHeight();
200 | }
201 | }, 200);
202 | }
203 | }
204 |
205 | /**
206 | * 隐藏键盘
207 | */
208 | private void hideSoftKeyboard() {
209 | inputMethodManager.hideSoftInputFromWindow(editText.getWindowToken(), 0);
210 | }
211 |
212 | /**
213 | * 显示表情面板
214 | */
215 | private void showEmojiPanel() {
216 | int softKeyboardHeight = getSoftKeyboardHeight();
217 | if (softKeyboardHeight == 0) {
218 | softKeyboardHeight = getSoftKeyboardHeightLocalValue();
219 | } else {
220 | hideSoftKeyboard();
221 | }
222 | emojiPanelView.getLayoutParams().height = softKeyboardHeight;
223 | emojiPanelView.setVisibility(View.VISIBLE);
224 | if (emojiPanelVisibilityChangeListener != null) {
225 | emojiPanelVisibilityChangeListener.onShowEmojiPanel();
226 | }
227 | }
228 |
229 | /**
230 | * 隐藏表情面板,同时指定是否随后开启键盘
231 | */
232 | private void hideEmojiPanel(boolean showSoftKeyboard) {
233 | if (emojiPanelView.isShown()) {
234 | emojiPanelView.setVisibility(View.GONE);
235 | if (showSoftKeyboard) {
236 | showSoftKeyboard(false);
237 | }
238 | if (emojiPanelVisibilityChangeListener != null) {
239 | emojiPanelVisibilityChangeListener.onHideEmojiPanel();
240 | }
241 | }
242 | }
243 |
244 | public interface OnEmojiPanelVisibilityChangeListener {
245 |
246 | void onShowEmojiPanel();
247 |
248 | void onHideEmojiPanel();
249 | }
250 |
251 | private OnEmojiPanelVisibilityChangeListener emojiPanelVisibilityChangeListener;
252 |
253 | public void setEmoticonPanelVisibilityChangeListener(OnEmojiPanelVisibilityChangeListener emojiPanelVisibilityChangeListener) {
254 | this.emojiPanelVisibilityChangeListener = emojiPanelVisibilityChangeListener;
255 | }
256 |
257 | }
258 |
--------------------------------------------------------------------------------
/app/src/main/java/leavesc/hello/keyboard/MainActivity.java:
--------------------------------------------------------------------------------
1 | package leavesc.hello.keyboard;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import android.support.v7.app.AppCompatActivity;
6 | import android.view.View;
7 |
8 | public class MainActivity extends AppCompatActivity {
9 |
10 | @Override
11 | protected void onCreate(Bundle savedInstanceState) {
12 | super.onCreate(savedInstanceState);
13 | setContentView(leavesc.hello.keyboard.R.layout.activity_main);
14 | findViewById(leavesc.hello.keyboard.R.id.btn_unresolved).setOnClickListener(new View.OnClickListener() {
15 | @Override
16 | public void onClick(View v) {
17 | startActivity(new Intent(MainActivity.this, UnresolvedActivity.class));
18 | }
19 | });
20 | findViewById(leavesc.hello.keyboard.R.id.btn_resolved).setOnClickListener(new View.OnClickListener() {
21 | @Override
22 | public void onClick(View v) {
23 | startActivity(new Intent(MainActivity.this, ResolvedActivity.class));
24 | }
25 | });
26 | }
27 |
28 | }
29 |
--------------------------------------------------------------------------------
/app/src/main/java/leavesc/hello/keyboard/ResolvedActivity.java:
--------------------------------------------------------------------------------
1 | package leavesc.hello.keyboard;
2 |
3 | import android.os.Bundle;
4 | import android.support.v7.app.AppCompatActivity;
5 | import android.support.v7.widget.LinearLayoutManager;
6 | import android.support.v7.widget.RecyclerView;
7 | import android.util.Log;
8 | import android.widget.EditText;
9 | import android.widget.ImageView;
10 | import android.widget.LinearLayout;
11 |
12 | import leavesc.hello.keyboard.common.Message;
13 | import leavesc.hello.keyboard.common.MessageAdapter;
14 |
15 | import java.util.ArrayList;
16 | import java.util.List;
17 |
18 | public class ResolvedActivity extends AppCompatActivity {
19 |
20 | private EmojiKeyboard emojiKeyboard;
21 |
22 | private final String TAG = "ResolvedActivity";
23 |
24 | @Override
25 | protected void onCreate(Bundle savedInstanceState) {
26 | super.onCreate(savedInstanceState);
27 | setContentView(leavesc.hello.keyboard.R.layout.activity_resolved);
28 | initView();
29 | }
30 |
31 | private void initView() {
32 | RecyclerView rv_messageList = (RecyclerView) findViewById(leavesc.hello.keyboard.R.id.rv_messageList);
33 | LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
34 | linearLayoutManager.setStackFromEnd(true);
35 | rv_messageList.setLayoutManager(linearLayoutManager);
36 | List messageList = new ArrayList<>();
37 | messageList.add(new Message("1"));
38 | messageList.add(new Message("2"));
39 | messageList.add(new Message("3"));
40 | messageList.add(new Message("4"));
41 | messageList.add(new Message("5"));
42 | messageList.add(new Message("6"));
43 | messageList.add(new Message("7"));
44 | messageList.add(new Message("8"));
45 | messageList.add(new Message("9"));
46 | messageList.add(new Message("10"));
47 | messageList.add(new Message("11"));
48 | messageList.add(new Message("12"));
49 | messageList.add(new Message("13"));
50 | messageList.add(new Message("14"));
51 | messageList.add(new Message("15"));
52 | messageList.add(new Message("16"));
53 | messageList.add(new Message("17"));
54 | messageList.add(new Message("18"));
55 | messageList.add(new Message("19"));
56 | messageList.add(new Message("20"));
57 | MessageAdapter messageAdapter = new MessageAdapter(this, messageList, leavesc.hello.keyboard.R.layout.item_message);
58 | rv_messageList.setAdapter(messageAdapter);
59 |
60 | EditText et_inputMessage = (EditText) findViewById(leavesc.hello.keyboard.R.id.et_inputMessage);
61 | ImageView iv_more = (ImageView) findViewById(leavesc.hello.keyboard.R.id.iv_more);
62 | LinearLayout ll_rootEmojiPanel = (LinearLayout) findViewById(leavesc.hello.keyboard.R.id.ll_rootEmojiPanel);
63 | emojiKeyboard = new EmojiKeyboard(this, et_inputMessage, ll_rootEmojiPanel, iv_more, rv_messageList);
64 | emojiKeyboard.setEmoticonPanelVisibilityChangeListener(new EmojiKeyboard.OnEmojiPanelVisibilityChangeListener() {
65 | @Override
66 | public void onShowEmojiPanel() {
67 | Log.e(TAG, "onShowEmojiPanel");
68 | }
69 |
70 | @Override
71 | public void onHideEmojiPanel() {
72 | Log.e(TAG, "onHideEmojiPanel");
73 | }
74 | });
75 | }
76 |
77 | @Override
78 | public void onBackPressed() {
79 | if (!emojiKeyboard.interceptBackPress()) {
80 | super.onBackPressed();
81 | }
82 | }
83 |
84 | }
85 |
--------------------------------------------------------------------------------
/app/src/main/java/leavesc/hello/keyboard/ScreenUtils.java:
--------------------------------------------------------------------------------
1 | package leavesc.hello.keyboard;
2 |
3 | import android.app.Activity;
4 | import android.content.Context;
5 | import android.util.DisplayMetrics;
6 | import android.view.Window;
7 |
8 | /**
9 | * 作者: chenZY
10 | * 时间: 2017/8/26 18:11
11 | * 描述:
12 | */
13 | public class ScreenUtils {
14 |
15 | /**
16 | * 返回包括虚拟键在内的总的屏幕高度
17 | * 即使虚拟按键显示着,也会加上虚拟按键的高度
18 | */
19 | public static int getTotalScreenHeight(Activity activity) {
20 | DisplayMetrics displayMetrics = new DisplayMetrics();
21 | activity.getWindowManager().getDefaultDisplay().getRealMetrics(displayMetrics);
22 | return displayMetrics.heightPixels;
23 | }
24 |
25 | /**
26 | * 返回屏幕的宽度
27 | */
28 | public static int getScreenWidth(Activity activity) {
29 | DisplayMetrics displayMetrics = new DisplayMetrics();
30 | activity.getWindowManager().getDefaultDisplay().getRealMetrics(displayMetrics);
31 | return displayMetrics.widthPixels;
32 | }
33 |
34 | /**
35 | * 返回屏幕可用高度
36 | * 当显示了虚拟按键时,会自动减去虚拟按键高度
37 | */
38 | public static int getAvailableScreenHeight(Activity activity) {
39 | DisplayMetrics displayMetrics = new DisplayMetrics();
40 | activity.getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
41 | return displayMetrics.heightPixels;
42 | }
43 |
44 | /**
45 | * 状态栏高度
46 | */
47 | public static int getStatusBarHeight(Activity activity) {
48 | int resourceId = activity.getResources().getIdentifier("status_bar_height", "dimen", "android");
49 | return activity.getResources().getDimensionPixelSize(resourceId);
50 | }
51 |
52 | /**
53 | * 获取虚拟按键的高度
54 | * 会根据当前是否有显示虚拟按键来返回相应的值
55 | * 即如果隐藏了虚拟按键,则返回零
56 | */
57 | public static int getVirtualBarHeightIfRoom(Activity activity) {
58 | DisplayMetrics displayMetrics = new DisplayMetrics();
59 | activity.getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
60 | int usableHeight = displayMetrics.heightPixels;
61 | activity.getWindowManager().getDefaultDisplay().getRealMetrics(displayMetrics);
62 | int realHeight = displayMetrics.heightPixels;
63 | return realHeight - usableHeight;
64 | }
65 |
66 | /**
67 | * 获取虚拟按键的高度,不论虚拟按键是否显示都会返回其固定高度
68 | */
69 | public static int getVirtualBarHeight(Activity activity) {
70 | int resourceId = activity.getResources().getIdentifier("navigation_bar_height", "dimen", "android");
71 | return activity.getResources().getDimensionPixelSize(resourceId);
72 | }
73 |
74 | /**
75 | * 标题栏高度,如果隐藏了标题栏则返回零
76 | */
77 | public static int getTitleHeight(Activity activity) {
78 | return activity.getWindow().findViewById(Window.ID_ANDROID_CONTENT).getTop();
79 | }
80 |
81 | /**
82 | * 将dp值转换为px值
83 | */
84 | public static int dp2px(Context context, float dpValue) {
85 | final float scale = context.getResources().getDisplayMetrics().density;
86 | return (int) (dpValue * scale + 0.5f);
87 | }
88 |
89 | /**
90 | * 将px值转换为dp值
91 | */
92 | public static int px2dp(Context context, float pxValue) {
93 | float scale = context.getResources().getDisplayMetrics().density;
94 | return (int) (pxValue / scale + 0.5f);
95 | }
96 |
97 | }
98 |
--------------------------------------------------------------------------------
/app/src/main/java/leavesc/hello/keyboard/UnresolvedActivity.java:
--------------------------------------------------------------------------------
1 | package leavesc.hello.keyboard;
2 |
3 | import android.content.Context;
4 | import android.os.Bundle;
5 | import android.support.v7.app.AppCompatActivity;
6 | import android.support.v7.widget.LinearLayoutManager;
7 | import android.support.v7.widget.RecyclerView;
8 | import android.view.KeyEvent;
9 | import android.view.MotionEvent;
10 | import android.view.View;
11 | import android.view.inputmethod.InputMethodManager;
12 | import android.widget.EditText;
13 | import android.widget.ImageView;
14 | import android.widget.LinearLayout;
15 |
16 | import leavesc.hello.keyboard.common.Message;
17 | import leavesc.hello.keyboard.common.MessageAdapter;
18 |
19 | import java.util.ArrayList;
20 | import java.util.List;
21 |
22 | public class UnresolvedActivity extends AppCompatActivity {
23 |
24 | private EditText et_inputMessage;
25 |
26 | private LinearLayout ll_rootEmojiPanel;
27 |
28 | @Override
29 | protected void onCreate(Bundle savedInstanceState) {
30 | super.onCreate(savedInstanceState);
31 | setContentView(leavesc.hello.keyboard.R.layout.activity_unresolved);
32 | initView();
33 | }
34 |
35 | private void initView() {
36 | RecyclerView rv_messageList = (RecyclerView) findViewById(leavesc.hello.keyboard.R.id.rv_messageList);
37 | LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
38 | linearLayoutManager.setStackFromEnd(true);
39 | rv_messageList.setLayoutManager(linearLayoutManager);
40 | List messageList = new ArrayList<>();
41 | messageList.add(new Message("1"));
42 | messageList.add(new Message("2"));
43 | messageList.add(new Message("3"));
44 | messageList.add(new Message("4"));
45 | messageList.add(new Message("5"));
46 | messageList.add(new Message("6"));
47 | messageList.add(new Message("7"));
48 | messageList.add(new Message("8"));
49 | messageList.add(new Message("9"));
50 | messageList.add(new Message("10"));
51 | messageList.add(new Message("11"));
52 | messageList.add(new Message("12"));
53 | messageList.add(new Message("13"));
54 | messageList.add(new Message("14"));
55 | messageList.add(new Message("15"));
56 | messageList.add(new Message("16"));
57 | messageList.add(new Message("17"));
58 | messageList.add(new Message("18"));
59 | messageList.add(new Message("19"));
60 | messageList.add(new Message("20"));
61 | MessageAdapter messageAdapter = new MessageAdapter(this, messageList, leavesc.hello.keyboard.R.layout.item_message);
62 | rv_messageList.setAdapter(messageAdapter);
63 |
64 | et_inputMessage = (EditText) findViewById(leavesc.hello.keyboard.R.id.et_inputMessage);
65 | ImageView iv_more = (ImageView) findViewById(leavesc.hello.keyboard.R.id.iv_more);
66 | ll_rootEmojiPanel = (LinearLayout) findViewById(leavesc.hello.keyboard.R.id.ll_rootEmojiPanel);
67 | iv_more.setOnClickListener(new View.OnClickListener() {
68 | @Override
69 | public void onClick(View v) {
70 | if (ll_rootEmojiPanel.getVisibility() == View.VISIBLE) {
71 | showKeyboard();
72 | } else {
73 | hideKeyboard();
74 | ll_rootEmojiPanel.setVisibility(View.VISIBLE);
75 | }
76 | }
77 | });
78 | et_inputMessage.setOnFocusChangeListener(new View.OnFocusChangeListener() {
79 | @Override
80 | public void onFocusChange(View view, boolean b) {
81 | if (b) {
82 | ll_rootEmojiPanel.setVisibility(View.GONE);
83 | }
84 | }
85 | });
86 | rv_messageList.setOnTouchListener(new View.OnTouchListener() {
87 | @Override
88 | public boolean onTouch(View view, MotionEvent motionEvent) {
89 | if (motionEvent.getAction() == MotionEvent.ACTION_UP) {
90 | hideKeyboard();
91 | ll_rootEmojiPanel.setVisibility(View.GONE);
92 | }
93 | return false;
94 | }
95 | });
96 | }
97 |
98 | private void showKeyboard() {
99 | et_inputMessage.requestFocus();
100 | InputMethodManager inputMethodManager = (InputMethodManager) et_inputMessage.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
101 | inputMethodManager.showSoftInput(et_inputMessage, 0);
102 | }
103 |
104 | private void hideKeyboard() {
105 | InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
106 | et_inputMessage.clearFocus();
107 | inputMethodManager.hideSoftInputFromWindow(et_inputMessage.getWindowToken(), 0);
108 | }
109 |
110 | @Override
111 | public boolean dispatchKeyEvent(KeyEvent event) {
112 | // if (event.getAction() == KeyEvent.ACTION_UP && event.getKeyCode() == KeyEvent.KEYCODE_BACK) {
113 | // if (ll_rootEmojiPanel.getVisibility() == View.VISIBLE) {
114 | // ll_rootEmojiPanel.setVisibility(View.GONE);
115 | // return true;
116 | // }
117 | // }
118 | return super.dispatchKeyEvent(event);
119 | }
120 |
121 | }
122 |
--------------------------------------------------------------------------------
/app/src/main/java/leavesc/hello/keyboard/common/CommonRecyclerAdapter.java:
--------------------------------------------------------------------------------
1 | package leavesc.hello.keyboard.common;
2 |
3 | import android.content.Context;
4 | import android.support.annotation.LayoutRes;
5 | import android.support.v7.widget.RecyclerView;
6 | import android.view.LayoutInflater;
7 | import android.view.View;
8 | import android.view.ViewGroup;
9 |
10 | import java.util.List;
11 |
12 | /**
13 | * 通用RecyclerView Adapter
14 | * Created by ZY on 2017/6/3.
15 | */
16 | public abstract class CommonRecyclerAdapter extends RecyclerView.Adapter {
17 |
18 | //多布局支持
19 | public interface MultiTypeSupport {
20 |
21 | int getLayoutId(T item, int position);
22 |
23 | }
24 |
25 | private MultiTypeSupport multiTypeSupport;
26 |
27 | private LayoutInflater layoutInflater;
28 |
29 | private List dataList;
30 |
31 | @LayoutRes
32 | private int layoutId;
33 |
34 | private CommonRecyclerHolder.onClickCommonListener clickCommonListener;
35 |
36 | /**
37 | * 私有构造函数
38 | *
39 | * @param context 上下文
40 | * @param dataList 数据集合
41 | */
42 | private CommonRecyclerAdapter(Context context, List dataList) {
43 | this.layoutInflater = LayoutInflater.from(context);
44 | this.dataList = dataList;
45 | }
46 |
47 | /**
48 | * 适用于:列表所有的子项都使用相同的布局文件,且不需要监听点击事件
49 | *
50 | * @param context 上下文
51 | * @param dataList 数据集合
52 | * @param layoutId 布局文件ID
53 | */
54 | protected CommonRecyclerAdapter(Context context, List dataList, @LayoutRes int layoutId) {
55 | this(context, dataList);
56 | this.layoutId = layoutId;
57 | }
58 |
59 | /**
60 | * 适用于:列表的子项使用不同的布局文件,且不需要监听点击事件
61 | *
62 | * @param context 上下文
63 | * @param dataList 数据集合
64 | * @param multiTypeSupport 支持多个布局文件
65 | */
66 | protected CommonRecyclerAdapter(Context context, List dataList, MultiTypeSupport multiTypeSupport) {
67 | this(context, dataList);
68 | this.multiTypeSupport = multiTypeSupport;
69 | }
70 |
71 | /**
72 | * 适用于:列表所有的子项都使用相同的布局文件,且需要监听点击事件
73 | *
74 | * @param context 上下文
75 | * @param dataList 数据集合
76 | * @param layoutId 布局文件ID
77 | * @param clickCommonListener 点击事件监听
78 | */
79 | protected CommonRecyclerAdapter(Context context, List dataList, @LayoutRes int layoutId,
80 | CommonRecyclerHolder.onClickCommonListener clickCommonListener) {
81 | this(context, dataList, layoutId);
82 | this.clickCommonListener = clickCommonListener;
83 | }
84 |
85 | /**
86 | * 适用于:列表的子项使用不同的布局文件,且需要监听点击事件
87 | *
88 | * @param context 上下文
89 | * @param dataList 数据集合
90 | * @param multiTypeSupport 支持多个布局文件
91 | * @param clickCommonListener 点击事件监听
92 | */
93 | protected CommonRecyclerAdapter(Context context, List dataList, MultiTypeSupport multiTypeSupport,
94 | CommonRecyclerHolder.onClickCommonListener clickCommonListener) {
95 | this(context, dataList, multiTypeSupport);
96 | this.clickCommonListener = clickCommonListener;
97 | }
98 |
99 | @Override
100 | public int getItemViewType(int position) {
101 | if (multiTypeSupport != null) {
102 | return multiTypeSupport.getLayoutId(dataList.get(position), position);
103 | }
104 | return super.getItemViewType(position);
105 | }
106 |
107 | @Override
108 | public CommonRecyclerHolder onCreateViewHolder(ViewGroup parent, int viewType) {
109 | if (multiTypeSupport != null) {
110 | layoutId = viewType;
111 | }
112 | View view = layoutInflater.inflate(layoutId, parent, false);
113 | return new CommonRecyclerHolder(view);
114 | }
115 |
116 | @Override
117 | public void onBindViewHolder(CommonRecyclerHolder holder, int position) {
118 | bindData(holder, dataList.get(position));
119 | holder.setClickCommonListener(clickCommonListener);
120 | }
121 |
122 | @Override
123 | public int getItemCount() {
124 | return dataList.size();
125 | }
126 |
127 | protected abstract void bindData(CommonRecyclerHolder holder, T data);
128 |
129 | }
130 |
131 |
--------------------------------------------------------------------------------
/app/src/main/java/leavesc/hello/keyboard/common/CommonRecyclerHolder.java:
--------------------------------------------------------------------------------
1 | package leavesc.hello.keyboard.common;
2 |
3 | import android.graphics.Bitmap;
4 | import android.support.annotation.DrawableRes;
5 | import android.support.annotation.IdRes;
6 | import android.support.v7.widget.RecyclerView;
7 | import android.util.SparseArray;
8 | import android.view.View;
9 | import android.widget.ImageView;
10 | import android.widget.TextView;
11 |
12 | /**
13 | * 通用ViewHolder
14 | * Created by ZY on 2017/6/3.
15 | */
16 | public class CommonRecyclerHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener {
17 |
18 | public interface onClickCommonListener {
19 |
20 | void onClick(int position);
21 |
22 | void onLongClick(int position);
23 |
24 | }
25 |
26 | private onClickCommonListener clickCommonListener;
27 |
28 | //用来存放View以减少findViewById的次数
29 | private SparseArray viewSparseArray;
30 |
31 | CommonRecyclerHolder(View itemView) {
32 | super(itemView);
33 | viewSparseArray = new SparseArray<>();
34 | itemView.setOnClickListener(this);
35 | itemView.setOnLongClickListener(this);
36 | }
37 |
38 | void setClickCommonListener(onClickCommonListener clickCommonListener) {
39 | this.clickCommonListener = clickCommonListener;
40 | }
41 |
42 | @Override
43 | public void onClick(View view) {
44 | if (clickCommonListener != null) {
45 | clickCommonListener.onClick(getAdapterPosition());
46 | }
47 | }
48 |
49 | @Override
50 | public boolean onLongClick(View view) {
51 | if (clickCommonListener != null) {
52 | clickCommonListener.onLongClick(getAdapterPosition());
53 | }
54 | return true;
55 | }
56 |
57 | /**
58 | * 根据 ID 来获取 View
59 | *
60 | * @param viewId viewID
61 | * @param 泛型
62 | * @return 将结果强转为 View 或 View 的子类型
63 | */
64 | private T getView(@IdRes int viewId) {
65 | // 先从缓存中找,找到的话则直接返回
66 | // 如果找不到则findViewById,再把结果存入缓存中
67 | View view = viewSparseArray.get(viewId);
68 | if (view == null) {
69 | view = itemView.findViewById(viewId);
70 | viewSparseArray.put(viewId, view);
71 | }
72 | return (T) view;
73 | }
74 |
75 | public CommonRecyclerHolder setText(@IdRes int viewId, CharSequence text) {
76 | TextView tv = getView(viewId);
77 | tv.setText(text);
78 | return this;
79 | }
80 |
81 | public CommonRecyclerHolder setImageResource(@IdRes int viewId, @DrawableRes int resourceId) {
82 | ImageView imageView = getView(viewId);
83 | imageView.setImageResource(resourceId);
84 | return this;
85 | }
86 |
87 | public CommonRecyclerHolder setImageResource(@IdRes int viewId, Bitmap bitmap) {
88 | ImageView imageView = getView(viewId);
89 | imageView.setImageBitmap(bitmap);
90 | return this;
91 | }
92 |
93 | public CommonRecyclerHolder setViewVisibility(@IdRes int viewId, int visibility) {
94 | getView(viewId).setVisibility(visibility);
95 | return this;
96 | }
97 |
98 | }
99 |
--------------------------------------------------------------------------------
/app/src/main/java/leavesc/hello/keyboard/common/Message.java:
--------------------------------------------------------------------------------
1 | package leavesc.hello.keyboard.common;
2 |
3 | /**
4 | * 作者:叶应是叶
5 | * 时间:2017/8/27 14:17
6 | * 描述:
7 | */
8 | public class Message {
9 |
10 | private String message;
11 |
12 | public Message(String message) {
13 | this.message = message;
14 | }
15 |
16 | public String getMessage() {
17 | return message;
18 | }
19 |
20 | public void setMessage(String message) {
21 | this.message = message;
22 | }
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/app/src/main/java/leavesc/hello/keyboard/common/MessageAdapter.java:
--------------------------------------------------------------------------------
1 | package leavesc.hello.keyboard.common;
2 |
3 | import android.content.Context;
4 | import android.support.annotation.LayoutRes;
5 |
6 | import java.util.List;
7 |
8 | import leavesc.hello.keyboard.R;
9 |
10 | /**
11 | * 作者:叶应是叶
12 | * 时间:2017/8/27 14:17
13 | * 描述:
14 | */
15 | public class MessageAdapter extends CommonRecyclerAdapter {
16 |
17 | public MessageAdapter(Context context, List messageList, @LayoutRes int layoutId) {
18 | super(context, messageList, layoutId);
19 | }
20 |
21 | @Override
22 | protected void bindData(CommonRecyclerHolder holder, Message message) {
23 | holder.setText(R.id.tv_message, message.getMessage());
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/icon_file.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leavesCZY/Keyboard/4a7492a00d5452a563f2ba4db5a6a9ba91e94846/app/src/main/res/drawable-xxhdpi/icon_file.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/icon_more.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leavesCZY/Keyboard/4a7492a00d5452a563f2ba4db5a6a9ba91e94846/app/src/main/res/drawable-xxhdpi/icon_more.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/icon_photo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leavesCZY/Keyboard/4a7492a00d5452a563f2ba4db5a6a9ba91e94846/app/src/main/res/drawable-xxhdpi/icon_photo.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/icon_voice.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leavesCZY/Keyboard/4a7492a00d5452a563f2ba4db5a6a9ba91e94846/app/src/main/res/drawable-xxhdpi/icon_voice.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/edit_bg.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | -
8 |
9 |
10 |
11 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
14 |
15 |
21 |
22 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_resolved.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
10 |
11 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_unresolved.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
10 |
11 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/item_message.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
13 |
14 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/view_emoji_panel.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
9 |
10 |
16 |
17 |
21 |
22 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/view_input.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
18 |
19 |
29 |
30 |
38 |
39 |
40 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/view_message_list.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leavesCZY/Keyboard/4a7492a00d5452a563f2ba4db5a6a9ba91e94846/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leavesCZY/Keyboard/4a7492a00d5452a563f2ba4db5a6a9ba91e94846/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leavesCZY/Keyboard/4a7492a00d5452a563f2ba4db5a6a9ba91e94846/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leavesCZY/Keyboard/4a7492a00d5452a563f2ba4db5a6a9ba91e94846/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leavesCZY/Keyboard/4a7492a00d5452a563f2ba4db5a6a9ba91e94846/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leavesCZY/Keyboard/4a7492a00d5452a563f2ba4db5a6a9ba91e94846/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leavesCZY/Keyboard/4a7492a00d5452a563f2ba4db5a6a9ba91e94846/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leavesCZY/Keyboard/4a7492a00d5452a563f2ba4db5a6a9ba91e94846/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leavesCZY/Keyboard/4a7492a00d5452a563f2ba4db5a6a9ba91e94846/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leavesCZY/Keyboard/4a7492a00d5452a563f2ba4db5a6a9ba91e94846/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Keyboard
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
17 |
18 |
26 |
27 |
--------------------------------------------------------------------------------
/app/src/test/java/leavesc/hello/keyboard/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package leavesc.hello.keyboard;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | google()
6 | jcenter()
7 | }
8 | dependencies {
9 | classpath 'com.android.tools.build:gradle:3.2.1'
10 |
11 | // NOTE: Do not place your application dependencies here; they belong
12 | // in the individual module build.gradle files
13 | }
14 | }
15 |
16 | allprojects {
17 | repositories {
18 | google()
19 | jcenter()
20 | }
21 | }
22 |
23 | task clean(type: Delete) {
24 | delete rootProject.buildDir
25 | }
26 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leavesCZY/Keyboard/4a7492a00d5452a563f2ba4db5a6a9ba91e94846/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Sat Aug 26 18:08:34 CST 2017
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/resolved.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leavesCZY/Keyboard/4a7492a00d5452a563f2ba4db5a6a9ba91e94846/resolved.gif
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------
/unresolved.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leavesCZY/Keyboard/4a7492a00d5452a563f2ba4db5a6a9ba91e94846/unresolved.gif
--------------------------------------------------------------------------------