Skip to content
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

fix the bug that PickView disappears #1025

Open
wants to merge 1 commit 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
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.content.Context;
import android.graphics.Typeface;
import android.support.annotation.ColorInt;
import android.support.annotation.LayoutRes;
import android.view.View;
import android.view.ViewGroup;

Expand Down Expand Up @@ -102,7 +103,19 @@ public OptionsPickerBuilder setDecorView(ViewGroup decorView) {
return this;
}

public OptionsPickerBuilder setLayoutRes(int res, CustomListener listener) {
/**
* 设置选择器自定义布局
* 注意:CustomListener不能为null, 否则该方法调用无效,即无法加载传入的自定义布局,详情查看
* {@link OptionsPickerView#initView(Context)}
*
* @param res 自定义布局
* @param listener 布局加载监听
* @return OptionsPickerBuilder
*/
public OptionsPickerBuilder setLayoutRes(@LayoutRes int res, CustomListener listener) {
if (listener == null){
throw new IllegalArgumentException("CustomListener is null");
}
mPickerOptions.layoutRes = res;
mPickerOptions.customListener = listener;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.content.Context;
import android.support.annotation.ColorInt;
import android.support.annotation.LayoutRes;
import android.view.View;
import android.view.ViewGroup;

Expand Down Expand Up @@ -155,7 +156,19 @@ public TimePickerBuilder setDate(Calendar date) {
return this;
}

public TimePickerBuilder setLayoutRes(int res, CustomListener customListener) {
/**
* 设置时间选择器自定义布局
* 注意:CustomListener不能为null, 否则该方法调用无效,即无法加载传入的自定义布局,详情查看
* {@link TimePickerView#initView(Context)}
*
* @param res 自定义布局
* @param customListener 布局加载监听
* @return TimePickerBuilder
*/
public TimePickerBuilder setLayoutRes(@LayoutRes int res, CustomListener customListener) {
if (customListener == null){
throw new IllegalArgumentException("CustomListener is null");
}
mPickerOptions.layoutRes = res;
mPickerOptions.customListener = customListener;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,6 @@ protected void initViews() {
contentContainer.setLayoutParams(params);
//创建对话框
createDialog();
//给背景设置点击事件,这样当点击内容以外的地方会关闭界面
dialogView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
dismiss();
}
});
} else {
//如果只是要显示在屏幕的下方
//decorView是activity的根View,包含 contentView 和 titleView
Expand Down Expand Up @@ -277,6 +270,17 @@ protected BasePickerView setOutSideCancelable(boolean isCancelable) {
} else {
view.setOnTouchListener(null);
}

View pickViewContainer = rootView.findViewById(R.id.content_container);
pickViewContainer.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
//do nothing, just consume touch events to avoid that PickView
//disappears while clicking this PickView own area under the
//condition that setOutSideCancelable() is true
return true;
}
});
}

return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public OptionsPickerView(PickerOptions pickerOptions) {
}

private void initView(Context context) {
setDialogOutSideCancelable();
initViews();
initAnim();
initEvents();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ public TimePickerView(PickerOptions pickerOptions) {
}

private void initView(Context context) {
setDialogOutSideCancelable();
initViews();
initAnim();

Expand Down