-
Notifications
You must be signed in to change notification settings - Fork 687
/
Copy pathChattingResolvedActivity.java
208 lines (174 loc) · 8.07 KB
/
ChattingResolvedActivity.java
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
package cn.dreamtobe.kpswitch.demo.activity;
import android.annotation.TargetApi;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.view.WindowManager;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import cn.dreamtobe.kpswitch.demo.R;
import cn.dreamtobe.kpswitch.util.KPSwitchConflictUtil;
import cn.dreamtobe.kpswitch.util.KeyboardUtil;
import cn.dreamtobe.kpswitch.widget.KPSwitchPanelLinearLayout;
/**
* Created by Jacksgong on 15/7/1.
* <p/>
* For AppCompatActivity. (Just for test(because has different view hierarchy, but has already
* handled internal), all calls are identical to the {@link ChattingResolvedFragmentActivity}).
* <p/>
* For resolving the conflict by delay the visible or gone of panel.
* <p/>
* In case of Normal(not fullscreen) Theme.
* In case of Translucent Status Theme with the {@code getFitSystemWindow()} is true in root view.
*/
public class ChattingResolvedActivity extends AppCompatActivity {
private static final String TAG = "ResolvedActivity";
private RecyclerView mContentRyv;
private EditText mSendEdt;
private KPSwitchPanelLinearLayout mPanelRoot;
private TextView mSendImgTv;
private ImageView mPlusIv;
private void assignViews() {
mContentRyv = (RecyclerView) findViewById(R.id.content_ryv);
mSendEdt = (EditText) findViewById(R.id.send_edt);
mPanelRoot = (KPSwitchPanelLinearLayout) findViewById(R.id.panel_root);
mSendImgTv = (TextView) findViewById(R.id.send_img_tv);
mPlusIv = (ImageView) findViewById(R.id.plus_iv);
}
@TargetApi(Build.VERSION_CODES.KITKAT)
private void adaptTheme(final boolean isTranslucentStatusFitSystemWindowTrue) {
if (isTranslucentStatusFitSystemWindowTrue
&& Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
}
}
private void adaptTitle(final boolean isTranslucentStatusFitSystemWindowTrue) {
if (isTranslucentStatusFitSystemWindowTrue) {
setTitle(R.string.activity_chatting_translucent_status_true_resolved_title);
} else {
setTitle(R.string.activity_chatting_resolved_title);
}
}
private View mSubPanel1, mSubPanel2;
private ImageView mPlusIv1, mPlusIv2;
private void adaptMultiSubPanel(final boolean isMultiSubPanel) {
if (isMultiSubPanel) {
setContentView(R.layout.activity_multiple_sub_panel_chatting_resolved);
} else {
setContentView(R.layout.activity_chatting_resolved);
}
assignViews();
if (isMultiSubPanel) {
mSubPanel1 = mPanelRoot.findViewById(R.id.sub_panel_1);
mSubPanel2 = mPanelRoot.findViewById(R.id.sub_panel_2);
mPlusIv1 = (ImageView) findViewById(R.id.voice_text_switch_iv);
mPlusIv2 = mPlusIv;
mPlusIv1.setImageResource(R.drawable.chatting_plus_btn_icon);
mSendImgTv.setText(R.string.mark_panel1_to_img);
}
}
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
private void adaptFitsSystemWindows(final boolean isTranslucentStatusFitSystemWindowTrue) {
if (isTranslucentStatusFitSystemWindowTrue
&& Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
findViewById(R.id.rootView).setFitsSystemWindows(true);
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// ********* Below code Just for Demo Test, do not need to adapt in your code. ************
final boolean isTranslucentStatusFitSystemWindowTrue = getIntent().
getBooleanExtra(MainActivity.KEY_TRANSLUCENT_STATUS_FIT_SYSTEM_WINDOW_TRUE, false);
adaptTheme(isTranslucentStatusFitSystemWindowTrue);
final boolean isMultiSubPanel = getIntent()
.getBooleanExtra(MainActivity.KEY_MULTI_SUB_PANEL, false);
adaptMultiSubPanel(isMultiSubPanel);
adaptFitsSystemWindows(isTranslucentStatusFitSystemWindowTrue);
adaptTitle(isTranslucentStatusFitSystemWindowTrue);
if (getIntent().getBooleanExtra(MainActivity.KEY_IGNORE_RECOMMEND_PANEL_HEIGHT, false)) {
mPanelRoot.setIgnoreRecommendHeight(true);
}
// ********* Above code Just for Demo Test, do not need to adapt in your code. ************
KeyboardUtil.attach(this, mPanelRoot,
// Add keyboard showing state callback, do like this when you want to listen in the
// keyboard's show/hide change.
new KeyboardUtil.OnKeyboardShowingListener() {
@Override
public void onKeyboardShowing(boolean isShowing) {
Log.d(TAG, String.format("Keyboard is %s", isShowing
? "showing" : "hiding"));
}
});
if (isMultiSubPanel) {
// If there are several sub-panels in this activity ( e.p. function-panel, emoji-panel).
KPSwitchConflictUtil.attach(mPanelRoot, mSendEdt,
new KPSwitchConflictUtil.SwitchClickListener() {
@Override
public void onClickSwitch(View v, boolean switchToPanel) {
if (switchToPanel) {
mSendEdt.clearFocus();
} else {
mSendEdt.requestFocus();
}
}
},
new KPSwitchConflictUtil.SubPanelAndTrigger(mSubPanel1, mPlusIv1),
new KPSwitchConflictUtil.SubPanelAndTrigger(mSubPanel2, mPlusIv2));
} else {
// In the normal case.
KPSwitchConflictUtil.attach(mPanelRoot, mPlusIv, mSendEdt,
new KPSwitchConflictUtil.SwitchClickListener() {
@Override
public void onClickSwitch(View v, boolean switchToPanel) {
if (switchToPanel) {
mSendEdt.clearFocus();
} else {
mSendEdt.requestFocus();
}
}
});
}
mSendImgTv.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// mock start the translucent full screen activity.
startActivity(new Intent(ChattingResolvedActivity.this, TranslucentActivity.class));
}
});
mContentRyv.setLayoutManager(new LinearLayoutManager(this));
mContentRyv.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
if (motionEvent.getAction() == MotionEvent.ACTION_UP) {
KPSwitchConflictUtil.hidePanelAndKeyboard(mPanelRoot);
}
return false;
}
});
}
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
if (event.getAction() == KeyEvent.ACTION_UP
&& event.getKeyCode() == KeyEvent.KEYCODE_BACK
&& Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
KPSwitchConflictUtil.hidePanelAndKeyboard(mPanelRoot);
return true;
}
return super.dispatchKeyEvent(event);
}
// 当屏幕分屏/多窗口变化时回调
@Override
public void onMultiWindowModeChanged(boolean isInMultiWindowMode) {
super.onMultiWindowModeChanged(isInMultiWindowMode);
KPSwitchConflictUtil.onMultiWindowModeChanged(isInMultiWindowMode);
}
}