Skip to content

Commit ea7470a

Browse files
committed
Added comments
1 parent 3f10938 commit ea7470a

File tree

1 file changed

+24
-47
lines changed

1 file changed

+24
-47
lines changed

pickerview/src/main/java/com/bigkoo/pickerview/view/BasePickerView.java

Lines changed: 24 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,13 @@
2424

2525
/**
2626
* Created by Sai on 15/11/22.
27-
* 精仿iOSPickerViewController控件
27+
* Fine imitation of iOSPickerViewController control
2828
*/
2929
public class BasePickerView {
30-
3130
private Context context;
3231
protected ViewGroup contentContainer;
33-
private ViewGroup rootView;//附加View 的 根View
34-
private ViewGroup dialogView;//附加Dialog 的 根View
32+
private ViewGroup rootView;
33+
private ViewGroup dialogView;
3534

3635
protected PickerOptions mPickerOptions;
3736
private OnDismissListener onDismissListener;
@@ -44,57 +43,53 @@ public class BasePickerView {
4443
protected int animGravity = Gravity.BOTTOM;
4544

4645
private Dialog mDialog;
47-
protected View clickView;//是通过哪个View弹出的
46+
protected View clickView;//Which View pops up through
4847
private boolean isAnim = true;
4948

5049
public BasePickerView(Context context) {
5150
this.context = context;
5251
}
5352

54-
5553
protected void initViews() {
56-
5754
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(
5855
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT, Gravity.BOTTOM);
5956

6057
LayoutInflater layoutInflater = LayoutInflater.from(context);
6158
if (isDialog()) {
62-
//如果是对话框模式
6359
dialogView = (ViewGroup) layoutInflater.inflate(R.layout.layout_basepickerview, null, false);
64-
//设置界面的背景为透明
6560
dialogView.setBackgroundColor(Color.TRANSPARENT);
66-
//这个是真正要加载选择器的父布局
61+
//This is the parent layout that actually loads the selector
6762
contentContainer = (ViewGroup) dialogView.findViewById(R.id.content_container);
68-
//设置对话框 默认左右间距屏幕30
63+
//Settings dialog box Default left and right spacing screen 30
6964
params.leftMargin = 30;
7065
params.rightMargin = 30;
7166
contentContainer.setLayoutParams(params);
72-
//创建对话框
67+
7368
createDialog();
74-
//给背景设置点击事件,这样当点击内容以外的地方会关闭界面
69+
//Set a click event for the background so that the interface will be closed when clicking outside the content
7570
dialogView.setOnClickListener(new View.OnClickListener() {
7671
@Override
7772
public void onClick(View view) {
7873
dismiss();
7974
}
8075
});
8176
} else {
82-
//如果只是要显示在屏幕的下方
83-
//decorView是activity的根View,包含 contentView 和 titleView
77+
//If you just want to display it at the bottom of the screen
8478
if (mPickerOptions.decorView == null) {
8579
if (context instanceof Activity) {
8680
mPickerOptions.decorView = (ViewGroup) ((Activity) context).getWindow().getDecorView();
8781
} else if (context instanceof ContextThemeWrapper && ((ContextThemeWrapper) context).getBaseContext() instanceof Activity) {
82+
// When showing from inside an AppCompatDialog, context will be a ContextThemeWrapper
8883
mPickerOptions.decorView = (ViewGroup) ((Activity) ((ContextThemeWrapper) context).getBaseContext()).getWindow().getDecorView();
8984
}
9085
}
91-
//将控件添加到decorView中
86+
//Add controls to decorView
9287
rootView = (ViewGroup) layoutInflater.inflate(R.layout.layout_basepickerview, mPickerOptions.decorView, false);
9388
rootView.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
9489
if (mPickerOptions.outSideColor != -1) {
9590
rootView.setBackgroundColor(mPickerOptions.outSideColor);
9691
}
97-
//这个是真正要加载时间选取器的父布局
92+
//This is the parent layout that actually loads the time picker
9893
contentContainer = (ViewGroup) rootView.findViewById(R.id.content_container);
9994
contentContainer.setLayoutParams(params);
10095
}
@@ -109,10 +104,9 @@ protected void initAnim() {
109104
protected void initEvents() {
110105
}
111106

112-
113107
/**
114-
* @param v (是通过哪个View弹出的)
115-
* @param isAnim 是否显示动画效果
108+
* @param v (Which View pops up through)
109+
* @param isAnim Whether to display animation effects
116110
*/
117111
public void show(View v, boolean isAnim) {
118112
this.clickView = v;
@@ -129,9 +123,8 @@ public void show(View v) {
129123
show();
130124
}
131125

132-
133126
/**
134-
* 添加View到根视图
127+
* Add View to root view
135128
*/
136129
public void show() {
137130
if (isDialog()) {
@@ -146,11 +139,10 @@ public void show() {
146139
}
147140
}
148141

149-
150142
/**
151-
* show的时候调用
143+
* Called during show
152144
*
153-
* @param view 这个View
145+
* @param view the view
154146
*/
155147
private void onAttached(View view) {
156148
mPickerOptions.decorView.addView(view);
@@ -159,19 +151,17 @@ private void onAttached(View view) {
159151
}
160152
}
161153

162-
163154
/**
164-
* 检测该View是不是已经添加到根视图
155+
* Check whether the View has been added to the root view
165156
*
166-
* @return 如果视图已经存在该View返回true
157+
* @return This View returns true if the view already exists
167158
*/
168159
public boolean isShowing() {
169160
if (isDialog()) {
170161
return false;
171162
} else {
172163
return rootView.getParent() != null || isShowing;
173164
}
174-
175165
}
176166

177167
public void dismiss() {
@@ -183,11 +173,10 @@ public void dismiss() {
183173
}
184174

185175
if (isAnim) {
186-
//消失动画
176+
//Disappear animation
187177
outAnim.setAnimationListener(new Animation.AnimationListener() {
188178
@Override
189179
public void onAnimationStart(Animation animation) {
190-
191180
}
192181

193182
@Override
@@ -197,7 +186,6 @@ public void onAnimationEnd(Animation animation) {
197186

198187
@Override
199188
public void onAnimationRepeat(Animation animation) {
200-
201189
}
202190
});
203191
contentContainer.startAnimation(outAnim);
@@ -206,16 +194,13 @@ public void onAnimationRepeat(Animation animation) {
206194
}
207195
dismissing = true;
208196
}
209-
210-
211197
}
212198

213199
public void dismissImmediately() {
214-
215200
mPickerOptions.decorView.post(new Runnable() {
216201
@Override
217202
public void run() {
218-
//从根视图移除
203+
//Remove from root view
219204
mPickerOptions.decorView.removeView(rootView);
220205
isShowing = false;
221206
dismissing = false;
@@ -224,8 +209,6 @@ public void run() {
224209
}
225210
}
226211
});
227-
228-
229212
}
230213

231214
private Animation getInAnimation() {
@@ -244,7 +227,6 @@ public BasePickerView setOnDismissListener(OnDismissListener onDismissListener)
244227
}
245228

246229
public void setKeyBackCancelable(boolean isCancelable) {
247-
248230
ViewGroup View;
249231
if (isDialog()) {
250232
View = dialogView;
@@ -273,7 +255,6 @@ public boolean onKey(View v, int keyCode, KeyEvent event) {
273255
};
274256

275257
protected BasePickerView setOutSideCancelable(boolean isCancelable) {
276-
277258
if (rootView != null) {
278259
View view = rootView.findViewById(R.id.outmost_container);
279260

@@ -288,15 +269,14 @@ protected BasePickerView setOutSideCancelable(boolean isCancelable) {
288269
}
289270

290271
/**
291-
* 设置对话框模式是否可以点击外部取消
272+
* Set whether the dialog mode can be canceled by clicking outside
292273
*/
293274
public void setDialogOutSideCancelable() {
294275
if (mDialog != null) {
295276
mDialog.setCancelable(mPickerOptions.cancelable);
296277
}
297278
}
298279

299-
300280
/**
301281
* Called when the user touch on black overlay, in order to dismiss the dialog.
302282
*/
@@ -317,13 +297,13 @@ public View findViewById(int id) {
317297
public void createDialog() {
318298
if (dialogView != null) {
319299
mDialog = new Dialog(context, R.style.custom_dialog2);
320-
mDialog.setCancelable(mPickerOptions.cancelable);//不能点外面取消,也不能点back取消
300+
mDialog.setCancelable(mPickerOptions.cancelable);//You cannot click outside to cancel, nor can you click back to cancel.
321301
mDialog.setContentView(dialogView);
322302

323303
Window dialogWindow = mDialog.getWindow();
324304
if (dialogWindow != null) {
325305
dialogWindow.setWindowAnimations(R.style.picker_view_scale_anim);
326-
dialogWindow.setGravity(Gravity.CENTER);//可以改成Bottom
306+
dialogWindow.setGravity(Gravity.CENTER);//Can be changed to Bottom
327307
}
328308

329309
mDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
@@ -353,14 +333,11 @@ public ViewGroup getDialogContainerLayout() {
353333
return contentContainer;
354334
}
355335

356-
357336
public Dialog getDialog() {
358337
return mDialog;
359338
}
360339

361-
362340
public boolean isDialog() {
363341
return false;
364342
}
365-
366343
}

0 commit comments

Comments
 (0)