From e82043a5471f4032e1c58eba31cfa1e05bce1003 Mon Sep 17 00:00:00 2001 From: tom <01wukong10@gmail.com> Date: Mon, 20 May 2019 15:14:40 +0800 Subject: [PATCH] =?UTF-8?q?1.=20=E5=9C=A8=20PickerOptions=20=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E4=B8=AD=E6=B7=BB=E5=8A=A0=E4=BA=86=E6=A0=87=E5=BF=97?= =?UTF-8?q?=E4=BD=8D=20topBarVisible(=E6=98=AF=E5=90=A6=E6=98=BE=E7=A4=BA?= =?UTF-8?q?=E6=A0=87=E9=A2=98=E6=A0=8F=3F=20=E9=BB=98=E8=AE=A4=20VISIBLE)?= =?UTF-8?q?=202.=20=E5=85=B6=E4=BB=96=E6=96=87=E4=BB=B6=E7=9A=84=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E4=BB=A5=E6=AD=A4=E4=B8=BA=E4=B8=AD=E5=BF=83=E5=B1=95?= =?UTF-8?q?=E5=BC=80=203.=20=E5=9C=A8=20app(moudle)=20=E4=B8=AD=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E4=BA=86=E4=B8=80=E4=B8=AA=E6=AD=A4=E6=95=88=E6=9E=9C?= =?UTF-8?q?=E7=9A=84=E7=A4=BA=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bigkoo/pickerviewdemo/MainActivity.java | 62 +++++++++++++++++-- app/src/main/res/layout/activity_main.xml | 7 +++ app/src/main/res/values-en/strings.xml | 1 + app/src/main/res/values/strings.xml | 1 + .../builder/OptionsPickerBuilder.java | 4 ++ .../pickerview/builder/TimePickerBuilder.java | 5 ++ .../pickerview/configure/PickerOptions.java | 1 + .../pickerview/view/OptionsPickerView.java | 3 + .../pickerview/view/TimePickerView.java | 7 ++- 9 files changed, 84 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/com/bigkoo/pickerviewdemo/MainActivity.java b/app/src/main/java/com/bigkoo/pickerviewdemo/MainActivity.java index 31d514aa..0dfe3053 100644 --- a/app/src/main/java/com/bigkoo/pickerviewdemo/MainActivity.java +++ b/app/src/main/java/com/bigkoo/pickerviewdemo/MainActivity.java @@ -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 cardItem = new ArrayList<>(); @@ -63,6 +63,7 @@ protected void onCreate(Bundle savedInstanceState) { getOptionData(); initTimePicker(); + initGoneTopBarTimePicker(); initCustomTimePicker(); initLunarPicker(); initOptionPicker(); @@ -75,6 +76,7 @@ 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); @@ -82,6 +84,7 @@ protected void onCreate(Bundle savedInstanceState) { 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); @@ -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(); //弹出自定义条件选择器 @@ -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() { @@ -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() { @@ -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); } }) diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 24422b23..f0e3704e 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -29,6 +29,13 @@ android:layout_margin="10dp" android:text="@string/picker_time" /> +