diff --git a/ChangeLog.md b/ChangeLog.md index 0cbfa7ab..baff465d 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -3,6 +3,8 @@ ## 4.1.10 - 2022.11.04 - Fix [issues#324](https://github.com/gzu-liyujiang/AndroidPicker/issues/324) 。 +- Opt [issues#294](https://github.com/gzu-liyujiang/AndroidPicker/issues/294) [issues#296](https://github.com/gzu-liyujiang/AndroidPicker/issues/296) 。 +- `XXXPicker`和`DialogFragment`结合使用示例。 ## 4.1.9 - 2022.08.31 diff --git a/Common/build.gradle b/Common/build.gradle index 4e3d1e0d..38483c39 100644 --- a/Common/build.gradle +++ b/Common/build.gradle @@ -17,4 +17,5 @@ apply from: "${rootDir}/gradle/publish.gradle" dependencies { implementation androidxLibrary.annotation implementation androidxLibrary.core + api androidxLibrary.activity } diff --git a/README.md b/README.md index 20f76d62..f4fac6bb 100644 --- a/README.md +++ b/README.md @@ -386,6 +386,31 @@ public class AntFortuneLikePicker extends LinkagePicker { } ```` +### 和`DialogFragment`结合 + +`XXXPicker` 都继承自 `android.app.Dialog` ,因此可以直接和`androidx.fragment.app.DialogFragment`结合使用。 + +```java +public class OptionPickerFragment extends DialogFragment { + + @NonNull + @Override + public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) { + OptionPicker picker = new OptionPicker(requireActivity()); + picker.setData("土人", "里民子", "羡民", "穿青人", "不在56个民族之内", "未定民族"); + picker.setOnOptionPickedListener(new OnOptionPickedListener() { + @Override + public void onOptionPicked(int position, Object item) { + Toast.makeText(requireContext(), item.toString(), Toast.LENGTH_SHORT).show(); + } + }); + picker.getWheelView().setStyle(R.style.WheelStyleDemo); + return picker; + } + +} +``` + ## 效果预览 以下图片显示的效果可能已修改过,实际效果请运行 demo 查看。 diff --git a/app/src/main/java/com/github/gzuliyujiang/fallback/activity/AddressPickerActivity.java b/app/src/main/java/com/github/gzuliyujiang/fallback/activity/AddressPickerActivity.java index 1d99e100..51c83ccb 100644 --- a/app/src/main/java/com/github/gzuliyujiang/fallback/activity/AddressPickerActivity.java +++ b/app/src/main/java/com/github/gzuliyujiang/fallback/activity/AddressPickerActivity.java @@ -109,7 +109,7 @@ public void onProvinceCityForGuiZhou(View view) { wheelLayout.setSelectedTextSize(17 * view.getResources().getDisplayMetrics().scaledDensity); wheelLayout.setSelectedTextBold(true); wheelLayout.setCurtainEnabled(true); - wheelLayout.setCurtainColor(0xEE0081FF); + wheelLayout.setCurtainColor(0xFF22EEFF); wheelLayout.setCurtainRadius(8 * view.getResources().getDisplayMetrics().density); int padding = (int) (10 * view.getResources().getDisplayMetrics().density); wheelLayout.setPadding(padding, 0, padding, 0); diff --git a/app/src/main/java/com/github/gzuliyujiang/fallback/activity/FileExplorerFragment.java b/app/src/main/java/com/github/gzuliyujiang/fallback/activity/FileExplorerFragment.java index b244a79c..87c03d57 100644 --- a/app/src/main/java/com/github/gzuliyujiang/fallback/activity/FileExplorerFragment.java +++ b/app/src/main/java/com/github/gzuliyujiang/fallback/activity/FileExplorerFragment.java @@ -40,9 +40,6 @@ */ public class FileExplorerFragment extends DialogFragment { - public FileExplorerFragment() { - } - @Override @SuppressLint("PrivateResource") public void onCreate(@Nullable Bundle savedInstanceState) { diff --git a/app/src/main/java/com/github/gzuliyujiang/fallback/activity/MainActivity.java b/app/src/main/java/com/github/gzuliyujiang/fallback/activity/MainActivity.java index 0a1d9b24..4c2875a5 100644 --- a/app/src/main/java/com/github/gzuliyujiang/fallback/activity/MainActivity.java +++ b/app/src/main/java/com/github/gzuliyujiang/fallback/activity/MainActivity.java @@ -81,6 +81,10 @@ public void onOptionPicked(int position, Object item) { picker.show(); } + public void onDialogFragment(View view) { + new OptionPickerFragment().show(getSupportFragmentManager(), OptionPickerFragment.class.getName()); + } + public void onDateTimePicker(View view) { startActivity(DateTimePickerActivity.class); } diff --git a/app/src/main/java/com/github/gzuliyujiang/fallback/activity/OptionPickerFragment.java b/app/src/main/java/com/github/gzuliyujiang/fallback/activity/OptionPickerFragment.java new file mode 100644 index 00000000..dd99c262 --- /dev/null +++ b/app/src/main/java/com/github/gzuliyujiang/fallback/activity/OptionPickerFragment.java @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2016-present 贵州纳雍穿青人李裕江<1032694760@qq.com> + * + * The software is licensed under the Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * http://license.coscl.org.cn/MulanPSL2 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR + * PURPOSE. + * See the Mulan PSL v2 for more details. + */ + +package com.github.gzuliyujiang.fallback.activity; + +import android.app.Dialog; +import android.os.Bundle; +import android.widget.Toast; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.fragment.app.DialogFragment; + +import com.github.gzuliyujiang.fallback.R; +import com.github.gzuliyujiang.wheelpicker.OptionPicker; +import com.github.gzuliyujiang.wheelpicker.contract.OnOptionPickedListener; + +/** + * {@link androidx.fragment.app.Fragment}形式的弹窗 + * + * @author 贵州山野羡民(1032694760@qq.com) + * @since 2022/11/04 + */ +public class OptionPickerFragment extends DialogFragment { + + @NonNull + @Override + public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) { + OptionPicker picker = new OptionPicker(requireActivity()); + picker.setData("土人", "里民子", "羡民", "穿青人", "不在56个民族之内", "未定民族"); + picker.setOnOptionPickedListener(new OnOptionPickedListener() { + @Override + public void onOptionPicked(int position, Object item) { + Toast.makeText(requireContext(), item.toString(), Toast.LENGTH_SHORT).show(); + } + }); + picker.getWheelView().setStyle(R.style.WheelStyleDemo); + return picker; + } + +} \ No newline at end of file diff --git a/app/src/main/res/layout/activity_picker_main.xml b/app/src/main/res/layout/activity_picker_main.xml index d53f3f0a..5a5a813c 100644 --- a/app/src/main/res/layout/activity_picker_main.xml +++ b/app/src/main/res/layout/activity_picker_main.xml @@ -42,6 +42,12 @@ android:text="切换弹窗样式" android:textColor="#FFFF0000" /> +