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

add topBarVisible config #765

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
62 changes: 57 additions & 5 deletions app/src/main/java/com/bigkoo/pickerviewdemo/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
private Button btn_CustomOptions;
private Button btn_CustomTime;

private TimePickerView pvTime, pvCustomTime, pvCustomLunar;
private TimePickerView pvTime,pvTimeGoneTopBar, pvCustomTime, pvCustomLunar;
private OptionsPickerView pvOptions, pvCustomOptions, pvNoLinkOptions;
private ArrayList<CardBean> cardItem = new ArrayList<>();

Expand All @@ -63,6 +63,7 @@ protected void onCreate(Bundle savedInstanceState) {
getOptionData();

initTimePicker();
initGoneTopBarTimePicker();
initCustomTimePicker();
initLunarPicker();
initOptionPicker();
Expand All @@ -75,13 +76,15 @@ protected void onCreate(Bundle savedInstanceState) {
btn_CustomTime = (Button) findViewById(R.id.btn_CustomTime);
Button btn_no_linkage = (Button) findViewById(R.id.btn_no_linkage);
Button btn_to_Fragment = (Button) findViewById(R.id.btn_fragment);
Button btn_time_gone_top_bar = findViewById(R.id.btn_time_gone_top_bar);

btn_Time.setOnClickListener(this);
btn_Options.setOnClickListener(this);
btn_CustomOptions.setOnClickListener(this);
btn_CustomTime.setOnClickListener(this);
btn_no_linkage.setOnClickListener(this);
btn_to_Fragment.setOnClickListener(this);
btn_time_gone_top_bar.setOnClickListener(this);

findViewById(R.id.btn_GotoJsonData).setOnClickListener(this);
findViewById(R.id.btn_lunar).setOnClickListener(this);
Expand All @@ -92,9 +95,11 @@ protected void onCreate(Bundle savedInstanceState) {
public void onClick(View v) {
if (v.getId() == R.id.btn_Time && pvTime != null) {
// pvTime.setDate(Calendar.getInstance());
/* pvTime.show(); //show timePicker*/
/* pvTime.show(); //show timePicker*/
pvTime.show(v);//弹出时间选择器,传递参数过去,回调的时候则可以绑定此view
} else if (v.getId() == R.id.btn_Options && pvOptions != null) {
}else if(v.getId() == R.id.btn_time_gone_top_bar && pvTime != null){
pvTimeGoneTopBar.show();
}else if (v.getId() == R.id.btn_Options && pvOptions != null) {
pvOptions.show(); //弹出条件选择器
} else if (v.getId() == R.id.btn_CustomOptions && pvCustomOptions != null) {
pvCustomOptions.show(); //弹出自定义条件选择器
Expand Down Expand Up @@ -235,6 +240,53 @@ public void onClick(View view) {
}
}

private void initGoneTopBarTimePicker() {//Dialog 模式下,在底部弹出

pvTimeGoneTopBar = new TimePickerBuilder(this, new OnTimeSelectListener() {
@Override
public void onTimeSelect(Date date, View v) {
Toast.makeText(MainActivity.this, getTime(date), Toast.LENGTH_SHORT).show();
Log.i("pvTimeGoneTopBar", "onTimeSelect");

}
})
.setTimeSelectChangeListener(new OnTimeSelectChangeListener() {
@Override
public void onTimeSelectChanged(Date date) {
Log.i("pvTimeGoneTopBar", "onTimeSelectChanged");
}
})
.setType(new boolean[]{true, true, true, true, true, true})
.isDialog(true) //默认设置false ,内部实现将DecorView 作为它的父控件。
.addOnCancelClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Log.i("pvTimeGoneTopBar", "onCancelClickListener");
}
})
.setTopBarVisible(View.GONE)
.build();

Dialog mDialog = pvTimeGoneTopBar.getDialog();
if (mDialog != null) {

FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT,
Gravity.BOTTOM);

params.leftMargin = 0;
params.rightMargin = 0;
pvTimeGoneTopBar.getDialogContainerLayout().setLayoutParams(params);

Window dialogWindow = mDialog.getWindow();
if (dialogWindow != null) {
dialogWindow.setWindowAnimations(com.bigkoo.pickerview.R.style.picker_view_slide_anim);//修改动画样式
dialogWindow.setGravity(Gravity.BOTTOM);//改成Bottom,底部显示
dialogWindow.setDimAmount(0.1f);
}
}
}

private void initCustomTimePicker() {

Expand Down Expand Up @@ -273,7 +325,7 @@ public void onTimeSelect(Date date, View v) {//选中事件回调
.setBgColor(Color.BLACK)//滚轮背景颜色 Night mode
.setSubmitColor(Color.WHITE)
.setCancelColor(Color.WHITE)*/
/*.animGravity(Gravity.RIGHT)// default is center*/
/*.animGravity(Gravity.RIGHT)// default is center*/
.setDate(selectedDate)
.setRangDate(startDate, endDate)
.setLayoutRes(R.layout.pickerview_custom_time, new CustomListener() {
Expand Down Expand Up @@ -321,7 +373,7 @@ public void onOptionsSelect(int options1, int options2, int options3, View v) {
//返回的分别是三个级别的选中位置
String tx = options1Items.get(options1).getPickerViewText()
+ options2Items.get(options1).get(options2)
/* + options3Items.get(options1).get(options2).get(options3).getPickerViewText()*/;
/* + options3Items.get(options1).get(options2).get(options3).getPickerViewText()*/;
btn_Options.setText(tx);
}
})
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@
android:layout_margin="10dp"
android:text="@string/picker_time" />

<Button
android:id="@+id/btn_time_gone_top_bar"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_margin="10dp"
android:text="@string/picker_time_gone_top_bar" />

<Button
android:id="@+id/btn_Options"
android:layout_width="match_parent"
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-en/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<string name="picker_custom_lunar">LunarTimePicker</string>

<string name="picker_time">TimePicker</string>
<string name="picker_time_gone_top_bar">TimePicker Gone TopBar</string>
<string name="picker_province">OptionsPicker</string>

<string name="picker_custom_time">CustomLayoutTimePicker</string>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

<string name="picker_custom_lunar">公农历切换</string>
<string name="picker_time">时间选择器</string>
<string name="picker_time_gone_top_bar">隐藏 TopBar 的时间选择器</string>
<string name="picker_province">条件选择器</string>

<string name="picker_custom_time">时间选择器自定义布局</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,10 @@ public OptionsPickerBuilder setOptionsSelectChangeListener(OnOptionsSelectChange
return this;
}

public OptionsPickerBuilder setTopBarVisible(int topBarVisible) {
mPickerOptions.topBarVisible = topBarVisible;
return this;
}

public <T> OptionsPickerView<T> build() {
return new OptionsPickerView<>(mPickerOptions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,11 @@ public TimePickerBuilder setTimeSelectChangeListener(OnTimeSelectChangeListener
return this;
}

public TimePickerBuilder setTopBarVisible(int topBarVisible) {
mPickerOptions.topBarVisible = topBarVisible;
return this;
}

public TimePickerView build() {
return new TimePickerView(mPickerOptions);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public PickerOptions(int buildType) {
public int textGravity = Gravity.CENTER;
public Context context;

public int topBarVisible = View.VISIBLE;//是否显示标题栏? 默认 VISIBLE
public String textContentConfirm;//确定按钮文字
public String textContentCancel;//取消按钮文字
public String textContentTitle;//标题文字
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ private void initView(Context context) {
btnSubmit.setOnClickListener(this);
btnCancel.setOnClickListener(this);

//设置 top bar 的显示状态
rv_top_bar.setVisibility(mPickerOptions.topBarVisible);

//设置文字
btnSubmit.setText(TextUtils.isEmpty(mPickerOptions.textContentConfirm) ? context.getResources().getString(R.string.pickerview_submit) : mPickerOptions.textContentConfirm);
btnCancel.setText(TextUtils.isEmpty(mPickerOptions.textContentCancel) ? context.getResources().getString(R.string.pickerview_cancel) : mPickerOptions.textContentCancel);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ private void initView(Context context) {
btnSubmit.setOnClickListener(this);
btnCancel.setOnClickListener(this);

//设置 top bar 的显示状态
rv_top_bar.setVisibility(mPickerOptions.topBarVisible);

//设置文字
btnSubmit.setText(TextUtils.isEmpty(mPickerOptions.textContentConfirm) ? context.getResources().getString(R.string.pickerview_submit) : mPickerOptions.textContentConfirm);
btnCancel.setText(TextUtils.isEmpty(mPickerOptions.textContentCancel) ? context.getResources().getString(R.string.pickerview_cancel) : mPickerOptions.textContentCancel);
Expand Down Expand Up @@ -132,7 +135,7 @@ public void onTimeSelectChanged() {
wheelTime.setLabels(mPickerOptions.label_year, mPickerOptions.label_month, mPickerOptions.label_day
, mPickerOptions.label_hours, mPickerOptions.label_minutes, mPickerOptions.label_seconds);
wheelTime.setTextXOffset(mPickerOptions.x_offset_year, mPickerOptions.x_offset_month, mPickerOptions.x_offset_day,
mPickerOptions.x_offset_hours, mPickerOptions.x_offset_minutes, mPickerOptions.x_offset_seconds);
mPickerOptions.x_offset_hours, mPickerOptions.x_offset_minutes, mPickerOptions.x_offset_seconds);

setOutSideCancelable(mPickerOptions.cancelable);
wheelTime.setCyclic(mPickerOptions.cyclic);
Expand Down Expand Up @@ -269,7 +272,7 @@ public void setLunarCalendar(boolean lunar) {

wheelTime.setLunarMode(lunar);
wheelTime.setLabels(mPickerOptions.label_year, mPickerOptions.label_month, mPickerOptions.label_day,
mPickerOptions.label_hours, mPickerOptions.label_minutes, mPickerOptions.label_seconds);
mPickerOptions.label_hours, mPickerOptions.label_minutes, mPickerOptions.label_seconds);
wheelTime.setPicker(year, month, day, hours, minute, seconds);
} catch (ParseException e) {
e.printStackTrace();
Expand Down