Skip to content

Commit

Permalink
library
Browse files Browse the repository at this point in the history
  • Loading branch information
demolishwall committed Jul 14, 2019
1 parent 289c1f0 commit 45b646b
Show file tree
Hide file tree
Showing 4 changed files with 140 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
package com.insightsurfface.stylelibrary.keyboard;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.Display;
import android.view.Gravity;
import android.view.Window;
import android.view.WindowManager;
import android.widget.EditText;

import com.insightsurfface.stylelibrary.R;
import com.insightsurfface.stylelibrary.listener.OnKeyboardChangeListener;
import com.insightsurfface.stylelibrary.listener.OnKeyboardListener;


public class KeyBoardDialog extends Dialog {
protected Context context;
protected English9KeyBoardView englishKeyboardView;
private EditText dialogEt;
protected OnKeyboardListener mOnKeyboardListener;
protected OnKeyboardChangeListener mOnKeyboardChangeListener;


public KeyBoardDialog(Context context) {
super(context);
// 閺夆晜鐟ч~鎺楀棘閻熸壆纭�闁告瑯鍨禍鎺旀媼閳哄伅顓㈠触閹存繂寮块悘鐑囨嫹 濞达絽妫欏Σ鎼佸极閸喓浜☉鎾崇Т閵囧﹥绺介敓锟�
// super(context, android.R.style.Theme);
// setOwnerActivity((Activity) context);
this.context = context;
}

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(getLayoutId());
init();

windowSet();
}

protected int getLayoutId() {
return R.layout.dialog_keyboard;
}

protected void windowSet() {
Window window = this.getWindow();
WindowManager.LayoutParams lp = window.getAttributes();
WindowManager wm = ((Activity) context).getWindowManager();
Display d = wm.getDefaultDisplay(); // 闁兼儳鍢茶ぐ鍥╀沪韫囨挾顔庨悗鐟邦潟閿熸垝绶氶悵顕�鎮介敓锟�
// lp.height = (int) (d.getHeight() * 0.4); // 濡ゅ倹锚鐎瑰磭鎷嬮崜褏鏋�
lp.width = (int) (d.getWidth() * 1); // 閻庣妫勭�瑰磭鎷嬮崜褏鏋�
// window.setGravity(Gravity.LEFT | Gravity.TOP);
window.setGravity(Gravity.BOTTOM);
// dialog濮掓稒顭堥鑽や焊鏉堛劍绠抪adding 閻庝絻澹堥崵褎淇婇崒娑氫函濞戞挸绉风换鏍ㄧ▕閸綆鍟庣紓鍐惧枤濞堟垹鎷犻敓锟�
// dialog婵ɑ鐡曠换娆愮▔瀹ュ牆鍘撮柛蹇嬪妼閻拷
window.getDecorView().setPadding(0, 0, 0, 0);
// lp.x = 100; // 闁哄倿顣︾紞鍛磾閻㈡棃宕搁幇顓犲灱
// lp.y = 100; // 闁哄倿顣︾紞鍛磾閻㈡洟宕搁幇顓犲灱
// lp.height = 30;
// lp.width = 20;
window.setAttributes(lp);
window.setDimAmount(0.2f);//去掉蒙层
window.setBackgroundDrawableResource(android.R.color.transparent);
}

protected void init() {
dialogEt = (EditText)findViewById( R.id.dialog_et );
englishKeyboardView = (English9KeyBoardView) findViewById(R.id.english_keyboard_view);
englishKeyboardView.attachTo(dialogEt);
englishKeyboardView.setOnKeyboardChangeListener(new OnKeyboardChangeListener() {
@Override
public void onChange(String res) {
if (null != mOnKeyboardChangeListener) {
mOnKeyboardChangeListener.onChange(res);
}
}

@Override
public void onFinish(String res) {
if (null != mOnKeyboardChangeListener) {
mOnKeyboardChangeListener.onFinish(res);
}
}
});
englishKeyboardView.setOnKeyboardListener(new OnKeyboardListener() {
@Override
public void onOptionsClick() {
if (null != mOnKeyboardListener) {
mOnKeyboardListener.onOptionsClick();
}
}

@Override
public void onQuestionClick() {
if (null != mOnKeyboardListener) {
mOnKeyboardListener.onQuestionClick();
}
}
});
}

public void setOnKeyboardListener(OnKeyboardListener onKeyboardListener) {
mOnKeyboardListener = onKeyboardListener;
}

public void setOnKeyboardChangeListener(OnKeyboardChangeListener onKeyboardChangeListener) {
mOnKeyboardChangeListener = onKeyboardChangeListener;
}
}
23 changes: 23 additions & 0 deletions app/src/main/res/layout/dialog_keyboard.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/transparency">

<EditText
android:id="@+id/dialog_et"
android:layout_width="match_parent"
android:layout_height="40dp"
android:hint="点按后滑动输入"
android:gravity="center"
android:textColor="@color/main_text_color"
android:textColorHint="@color/main_text_color_gray"
android:textSize="15sp"
android:background="@null"/>

<com.insightsurfface.stylelibrary.keyboard.English9KeyBoardView
android:id="@+id/english_keyboard_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="1dp"
android:layout_below="@+id/dialog_et"></com.insightsurfface.stylelibrary.keyboard.English9KeyBoardView>
</RelativeLayout>
5 changes: 3 additions & 2 deletions app/src/main/res/layout/keyboard_english9.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@
android:layout_height="78dp"
android:layout_below="@+id/delete_btn"
android:layout_alignParentRight="true"
android:padding="14dp"
android:layout_marginTop="5dp"
android:background="@drawable/item_click"
android:padding="14dp"
android:scaleType="centerInside"
android:src="@drawable/ic_space"/>

Expand All @@ -52,7 +52,8 @@
android:layout_toLeftOf="@id/delete_btn"
android:layout_toRightOf="@+id/options_iv"
android:orientation="vertical"
android:padding="5dp">
android:paddingLeft="5dp"
android:paddingRight="5dp">

<LinearLayout
android:layout_width="match_parent"
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@
<color name="divide_line">#e1e1e1</color>
<color name="transparency">#00000000</color>
<color name="main_text_color">#12274D</color>
<color name="main_text_color_gray">#8912274d</color>
</resources>

0 comments on commit 45b646b

Please sign in to comment.