Skip to content

view布局部分优化 #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

buildscript {
repositories {
// maven{url 'http://maven.aliyun.com/nexus/content/groups/public/'}
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
classpath 'com.android.tools.build:gradle:3.4.2'
classpath 'com.novoda:bintray-release:0.8.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand All @@ -14,6 +16,8 @@ buildscript {

allprojects {
repositories {
// maven{url 'http://maven.aliyun.com/nexus/content/groups/public/'}
google()
jcenter()
}
}
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip
17 changes: 9 additions & 8 deletions keyboard/src/main/java/cn/hadcn/keyboard/ChatKeyboardLayout.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ private Style() {
private int mLayoutOrderCount = 0;
private int mChildViewPosition = -1;
private HadEditText etInputArea;
private ViewGroup rlInput;
// private ViewGroup rlInput;
private LinearLayout lyBottomLayout;
private ImageView btnEmoticon;
private Button btnSend;
Expand Down Expand Up @@ -141,7 +141,7 @@ private void initView(Context context) {
EmoticonHandler.getInstance(context).loadEmoticonsToMemory();
LayoutInflater.from(context).inflate(R.layout.keyboard_bar_layout, this);

rlInput = (ViewGroup) findViewById(R.id.view_keyboard_input_layout);
// rlInput = (ViewGroup) findViewById(R.id.view_keyboard_input_layout);
lyBottomLayout = (LinearLayout) findViewById(R.id.view_keyboard_bottom);
btnEmoticon = (ImageView) findViewById(R.id.view_keyboard_face_icon);
leftIconView = (ImageView) findViewById(R.id.view_keyboard_left_icon);
Expand Down Expand Up @@ -389,11 +389,10 @@ public boolean dispatchKeyEvent(KeyEvent event) {
* @param view view
*/
protected void leftIconClicked(View view) {
if (rlInput.isShown()) {
if (!btnRecording.isShown()) {
// switch to voice recording bar
hideAutoView();
closeSoftKeyboard(etInputArea);
rlInput.setVisibility(INVISIBLE);
btnRecording.setVisibility(VISIBLE);
leftIconView.setImageDrawable(mLeftSecondIcon);
btnSend.setVisibility(GONE);
Expand All @@ -402,7 +401,6 @@ protected void leftIconClicked(View view) {
}
} else {
// switch to text input bar
rlInput.setVisibility(VISIBLE);
btnRecording.setVisibility(GONE);
setEditableState(true);
openSoftKeyboard(etInputArea);
Expand Down Expand Up @@ -432,7 +430,6 @@ protected void rightIconClicked(View view) {
break;
case KEYBOARD_STATE_NONE:
btnEmoticon.setSelected(false);
rlInput.setVisibility(VISIBLE);
btnRecording.setVisibility(GONE);
leftIconView.setImageDrawable(mLeftDefaultIcon);
setEditableState(true);
Expand Down Expand Up @@ -554,6 +551,10 @@ public boolean onTouch(View view, MotionEvent motionEvent) {
btnRecording.setText(getResources().getString(R.string.recording_end));
isCanceled = false;
}
} else if(motionEvent.getAction() == MotionEvent.ACTION_CANCEL){
btnRecording.setBackgroundResource(R.drawable.recording_n);
btnRecording.setText(getResources().getString(R.string.recording_start));
mOnChatKeyBoardListener.onRecordingAction(RecordingAction.CANCELED);
}
return false;
}
Expand Down Expand Up @@ -722,8 +723,8 @@ private EmoticonsKeyboardBuilder getBuilder(Context context) {
}

@Override
protected void onSoftKeyboardPop(int height) {
super.onSoftKeyboardPop(height);
protected void OnSoftKeyboardPop(int height) {
super.OnSoftKeyboardPop(height);
btnEmoticon.setSelected(false);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import android.view.View;
import android.view.ViewGroup;
import android.widget.GridView;
import android.widget.RelativeLayout;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -20,7 +19,6 @@
import cn.hadcn.keyboard.emoticon.util.EmoticonsKeyboardBuilder;
import cn.hadcn.keyboard.emoticon.view.EmoticonsAdapter.EmoticonsListener;
import cn.hadcn.keyboard.utils.Utils;
import cn.hadcn.keyboard.view.SoftListenLayout;

/**
* @author chris
Expand Down Expand Up @@ -79,21 +77,16 @@ private void updateView() {
int start = 0;
int end = everyPageMaxSum > emoticonSetSum ? emoticonSetSum : everyPageMaxSum;

RelativeLayout.LayoutParams gridParams = new RelativeLayout.LayoutParams
(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams
.WRAP_CONTENT);
gridParams.addRule(SoftListenLayout.CENTER_VERTICAL);

int horizontalSpacing = Utils.dip2px(mContext, bean.getHorizontalSpacing());
int verticalSpacing = Utils.dip2px(mContext, bean.getVerticalSpacing());
int itemHeight = Math.min(
(mPageWidth - getPaddingRight() - getPaddingLeft() -
(bean.getRow() - 1) * horizontalSpacing) / bean.getRow(),
(mPageHeight - getPaddingTop() - getPaddingBottom() -
(bean.getLine() - 1) * verticalSpacing) / bean.getLine());
int paddingTop = (mPageHeight-itemHeight*line-verticalSpacing*line)/2;

for (int i = 0; i < pageCount; i++) {
RelativeLayout rl = new RelativeLayout(mContext);
GridView gridView = new GridView(mContext);
gridView.setNumColumns(bean.getRow());
gridView.setBackgroundColor(Color.TRANSPARENT);
Expand Down Expand Up @@ -127,9 +120,9 @@ private void updateView() {
EmoticonsAdapter adapter = new EmoticonsAdapter(mContext, list, bean
.isShownName());
adapter.setHeight(itemHeight, Utils.dip2px(mContext, bean.getItemPadding()));
gridView.setPadding(0, paddingTop, 0, 0);
gridView.setAdapter(adapter);
rl.addView(gridView, gridParams);
emoticonPageViews.add(rl);
emoticonPageViews.add(gridView);
adapter.setOnItemListener(this);

start = everyPageMaxSum + i * everyPageMaxSum;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ protected void autoViewHeightChanged(final int height) {
}

@Override
protected void onSoftKeyboardPop(int height) {
protected void OnSoftKeyboardPop(int height) {
if (height > 0 && height != mAutoViewHeight) {
mAutoViewHeight = height;
Utils.setDefKeyboardHeight(mContext, mAutoViewHeight);
Expand All @@ -135,7 +135,7 @@ public void run() {
}

@Override
protected void onSoftKeyboardClose() {
protected void OnSoftKeyboardClose() {
mKeyboardState = mKeyboardState == KEYBOARD_STATE_BOTH ? KEYBOARD_STATE_FUNC :
KEYBOARD_STATE_NONE;

Expand Down
159 changes: 79 additions & 80 deletions keyboard/src/main/res/layout/keyboard_bar_layout.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
Expand All @@ -15,93 +16,91 @@
android:layout_height="wrap_content">
<ImageView
android:id="@+id/view_keyboard_left_icon"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_width="34dp"
android:layout_height="34dp"
android:layout_centerVertical="true"
android:layout_marginLeft="12dp"
android:layout_marginStart="12dp"
android:layout_marginLeft="8dp"
android:layout_marginStart="8dp"
android:scaleType="centerInside"
android:src="@drawable/default_record_icon" />
<RelativeLayout
android:id="@+id/rl_multi_and_send"
android:layout_width="36dp"
android:layout_height="28dp"
<View
android:id="@+id/v_empty"
android:layout_width="1px"
android:layout_height="10dp"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentRight="true" />
<ImageView
android:id="@+id/view_keyboard_right_icon"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_toLeftOf="@+id/view_keyboard_send_button"
android:layout_toStartOf="@+id/view_keyboard_send_button"
android:layout_marginRight="8dp"
android:layout_marginEnd="8dp"
android:layout_centerVertical="true"
android:layout_marginEnd="4dp"
android:layout_marginRight="4dp"
android:focusableInTouchMode="true">
<ImageView
android:id="@+id/view_keyboard_right_icon"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_centerInParent="true"
android:scaleType="centerInside"
android:src="@drawable/default_right_icon" />
<Button
android:id="@+id/view_keyboard_send_button"
android:layout_width="match_parent"
android:layout_height="32dp"
android:layout_centerInParent="true"
android:background="@drawable/send_button_bg"
android:gravity="center"
android:text="@string/btn_text_send"
android:textColor="@color/keyboard_white"
android:textSize="12sp" />
</RelativeLayout>
<RelativeLayout
android:scaleType="centerInside"
android:src="@drawable/default_right_icon" />
<Button
android:id="@+id/view_keyboard_send_button"
android:layout_width="45dp"
android:layout_height="32dp"
android:layout_toLeftOf="@+id/v_empty"
android:layout_toStartOf="@+id/v_empty"
android:layout_marginRight="8dp"
android:layout_marginEnd="8dp"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:background="@drawable/send_button_bg"
android:gravity="center"
android:text="@string/btn_text_send"
android:textColor="@color/keyboard_white"
android:textSize="14sp" />
<cn.hadcn.keyboard.view.HadEditText
android:id="@+id/et_chat"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_toEndOf="@id/view_keyboard_left_icon"
android:layout_toLeftOf="@id/rl_multi_and_send"
android:layout_toRightOf="@id/view_keyboard_left_icon"
android:layout_toStartOf="@id/rl_multi_and_send">
<Button
android:id="@+id/view_keyboard_recording_bar"
style="?android:attr/borderlessButtonStyle"
android:layout_width="match_parent"
android:layout_height="28dp"
android:layout_centerVertical="true"
android:background="@drawable/recording_n"
android:gravity="center"
android:text="@string/recording_start"
android:textColor="#727272"
android:visibility="gone" />
<LinearLayout
android:id="@+id/view_keyboard_input_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<cn.hadcn.keyboard.view.HadEditText
android:id="@+id/et_chat"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:focusable="true"
android:focusableInTouchMode="false"
android:lineSpacingExtra="4dp"
android:maxLines="4"
android:paddingEnd="8dp"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:paddingStart="8dp"
android:textColorHint="@color/keyboard_edit_text_hint"
android:textSize="14sp" />
<ImageView
android:id="@+id/view_keyboard_face_icon"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_gravity="center_vertical"
android:layout_marginEnd="8dp"
android:layout_marginLeft="12dp"
android:layout_marginRight="8dp"
android:layout_marginStart="12dp"
android:scaleType="centerInside"
android:src="@drawable/keyboard_face_icon" />
</LinearLayout>
</RelativeLayout>
android:layout_toRightOf="@+id/view_keyboard_left_icon"
android:layout_toEndOf="@+id/view_keyboard_left_icon"
android:layout_toLeftOf="@+id/view_keyboard_right_icon"
android:layout_toStartOf="@+id/view_keyboard_right_icon"
android:textColorHint="@color/keyboard_edit_text_hint"
android:layout_marginTop="6dp"
android:focusable="true"
android:focusableInTouchMode="false"
android:lineSpacingExtra="4dp"
android:maxLines="4"
android:paddingEnd="45dp"
android:paddingLeft="8dp"
android:paddingRight="45dp"
android:paddingStart="8dp"
android:textSize="16sp" />
<ImageView
android:id="@+id/view_keyboard_face_icon"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_centerVertical="true"
android:layout_toLeftOf="@+id/view_keyboard_right_icon"
android:layout_toStartOf="@+id/view_keyboard_right_icon"
android:layout_marginEnd="10dp"
android:layout_marginRight="10dp"
android:scaleType="centerInside"
android:src="@drawable/keyboard_face_icon" />

<Button
android:id="@+id/view_keyboard_recording_bar"
style="?android:attr/borderlessButtonStyle"
android:layout_width="match_parent"
android:layout_height="32dp"
android:layout_centerVertical="true"
android:background="@drawable/recording_n"
android:layout_marginRight="8dp"
android:layout_marginEnd="8dp"
android:layout_toLeftOf="@+id/view_keyboard_send_button"
android:layout_toStartOf="@+id/view_keyboard_send_button"
android:gravity="center"
android:text="@string/recording_start"
android:textColor="#727272"
android:visibility="gone" />
</RelativeLayout>
<LinearLayout
android:id="@+id/view_keyboard_bottom"
Expand Down
7 changes: 3 additions & 4 deletions keyboard/src/main/res/layout/keyboard_emoticon_layout.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
<merge xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/keyboard_white">
android:layout_height="match_parent" >
<View
android:id="@+id/view_line_top"
android:layout_width="match_parent"
Expand Down Expand Up @@ -36,4 +35,4 @@
android:layout_above="@id/emoticon_indicator_view"
android:layout_below="@id/view_line_top"
android:orientation="vertical" />
</RelativeLayout>
</merge>
1 change: 0 additions & 1 deletion keyboard/src/main/res/layout/keyboard_emoticon_tabbar.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:background="@color/keyboard_white"
android:scrollbars="none">
<LinearLayout
android:id="@+id/keyboard_emoticons_bar_content"
Expand Down
7 changes: 3 additions & 4 deletions keyboard/src/main/res/layout/keyboard_media_layout.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
<merge xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/keyboard_white">
android:layout_height="match_parent" >
<android.support.v4.view.ViewPager
android:id="@+id/popup_media_pager"
android:layout_width="match_parent"
Expand All @@ -19,4 +18,4 @@
android:gravity="center"
android:orientation="horizontal"
android:paddingBottom="@dimen/keyboard_indicator_margin"/>
</RelativeLayout>
</merge>