Skip to content

Commit

Permalink
XXXPickerDialogFragment结合使用示例
Browse files Browse the repository at this point in the history
  • Loading branch information
liyujiang-gzu committed Nov 3, 2022
1 parent f5751c3 commit 9a61063
Show file tree
Hide file tree
Showing 9 changed files with 92 additions and 6 deletions.
2 changes: 2 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions Common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ apply from: "${rootDir}/gradle/publish.gradle"
dependencies {
implementation androidxLibrary.annotation
implementation androidxLibrary.core
api androidxLibrary.activity
}
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 查看。
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@
*/
public class FileExplorerFragment extends DialogFragment {

public FileExplorerFragment() {
}

@Override
@SuppressLint("PrivateResource")
public void onCreate(@Nullable Bundle savedInstanceState) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright (c) 2016-present 贵州纳雍穿青人李裕江<[email protected]>
*
* 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 贵州山野羡民([email protected]
* @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;
}

}
6 changes: 6 additions & 0 deletions app/src/main/res/layout/activity_picker_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@
android:text="切换弹窗样式"
android:textColor="#FFFF0000" />

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="onDialogFragment"
android:text="结合DialogFragment" />

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
Expand Down
4 changes: 2 additions & 2 deletions gradle/dependency.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ ext {
// 谷歌支持库 https://developer.android.google.cn/jetpack/androidx/versions/stable-channel?hl=zh-cn
androidxLibrary = [
annotation : "androidx.annotation:annotation:1.1.0",
core : "androidx.core:core:1.5.0-rc01",
core : "androidx.core:core:1.5.0",
collection : "androidx.collection:collection:1.1.0",
multidex : "androidx.multidex:multidex:2.0.0",
activity : "androidx.activity:activity:1.3.0-beta01",
activity : "androidx.activity:activity:1.2.4",
fragment : "androidx.fragment:fragment:1.3.4",
appcompat : "androidx.appcompat:appcompat:1.3.0",
localbroadcastmanager : "androidx.localbroadcastmanager:localbroadcastmanager:1.0.0",
Expand Down

0 comments on commit 9a61063

Please sign in to comment.