Skip to content

Commit 90f91b7

Browse files
committed
文件选择器添加更多设置项;
颜色选择器布局调整; 日期时间选择器0-9前补0显示
1 parent e330d4e commit 90f91b7

13 files changed

Lines changed: 157 additions & 114 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ Picker for android, include date&time/option/color/file&directory.
9696
文件选择器:
9797
```java
9898
FilePicker picker = new FilePicker(this, FilePicker.PickMode.File);
99+
picker.setShowHideDir(false);
99100
picker.setOnFilePickListener(new FilePicker.OnFilePickListener() {
100101
@Override
101102
public void onPicked(String currentPath) {

app/app.iml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<module external.linked.project.id=":app" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="AndroidPicker" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
2+
<module external.linked.project.id=":app" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="trunk" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
33
<component name="FacetManager">
44
<facet type="android-gradle" name="Android-Gradle">
55
<configuration>
@@ -71,7 +71,7 @@
7171
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dependency-cache" />
7272
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex" />
7373
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex-cache" />
74-
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-v4/23.1.0/jars" />
74+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-v4/23.0.1/jars" />
7575
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
7676
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/jacoco" />
7777
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/javaResources" />
@@ -89,8 +89,8 @@
8989
</content>
9090
<orderEntry type="jdk" jdkName="Android API 23 Platform" jdkType="Android SDK" />
9191
<orderEntry type="sourceFolder" forTests="false" />
92-
<orderEntry type="library" exported="" name="support-v4-23.1.0" level="project" />
93-
<orderEntry type="library" exported="" name="support-annotations-23.1.0" level="project" />
92+
<orderEntry type="library" exported="" name="support-v4-23.0.1" level="project" />
93+
<orderEntry type="library" exported="" name="support-annotations-23.0.1" level="project" />
9494
<orderEntry type="module" module-name="framework-picker" exported="" />
9595
</component>
9696
</module>

app/src/main/java/cn/qqtheme/androidpicker/MainActivity.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public void on2OptionPicker(View view) {
8888
language.add("H5+/MUI");
8989
option2.add(language);
9090
ArrayList<String> tool = new ArrayList<String>();
91-
tool.add("Android Studio");
91+
tool.add("IntelliJ IDEA");
9292
tool.add("PhpStorm");
9393
tool.add("HBuilder");
9494
option2.add(tool);
@@ -122,7 +122,8 @@ public void onColorPicked(int pickedColor) {
122122
}
123123

124124
public void onFilePicker(View view) {
125-
FilePicker picker = new FilePicker(this, FilePicker.PickMode.File);
125+
FilePicker picker = new FilePicker(this, FilePicker.Mode.File);
126+
picker.setShowHideDir(false);
126127
picker.setOnFilePickListener(new FilePicker.OnFilePickListener() {
127128
@Override
128129
public void onPicked(String currentPath) {
@@ -133,7 +134,7 @@ public void onPicked(String currentPath) {
133134
}
134135

135136
public void onDirPicker(View view) {
136-
FilePicker picker = new FilePicker(this, FilePicker.PickMode.Directory);
137+
FilePicker picker = new FilePicker(this, FilePicker.Mode.Directory);
137138
picker.setOnFilePickListener(new FilePicker.OnFilePickListener() {
138139
@Override
139140
public void onPicked(String currentPath) {

framework-picker/framework-picker.iml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<module external.linked.project.id=":framework-picker" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="AndroidPicker" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
2+
<module external.linked.project.id=":framework-picker" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="trunk" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
33
<component name="FacetManager">
44
<facet type="android-gradle" name="Android-Gradle">
55
<configuration>
@@ -89,7 +89,7 @@
8989
</content>
9090
<orderEntry type="jdk" jdkName="Android API 23 Platform" jdkType="Android SDK" />
9191
<orderEntry type="sourceFolder" forTests="false" />
92-
<orderEntry type="library" exported="" name="support-v4-23.1.0" level="project" />
93-
<orderEntry type="library" exported="" name="support-annotations-23.1.0" level="project" />
92+
<orderEntry type="library" exported="" name="support-v4-23.0.1" level="project" />
93+
<orderEntry type="library" exported="" name="support-annotations-23.0.1" level="project" />
9494
</component>
9595
</module>

framework-picker/src/main/java/cn/qqtheme/framework/adapter/FileAdapter.java

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package cn.qqtheme.framework.adapter;
22

33
import android.content.Context;
4-
import android.graphics.Color;
54

65
import cn.qqtheme.framework.entity.FileItem;
76
import cn.qqtheme.framework.helper.FileUtils;
@@ -16,11 +15,13 @@ public class FileAdapter extends IconTextAdapter<FileItem> {
1615
public static final String DIR_ROOT = "..";
1716
public static final String DIR_PARENT = ".";
1817
private String rootPath = null;
18+
private String currentPath = null;
1919
private String[] allowExtensions = null;//允许的扩展名
20-
private boolean showUpOrRoot = true;//是否显示返回上一级或根目录
21-
private boolean showHiddenDir = true;//是否显示隐藏的目录(以“.”开头)
20+
private boolean showHomeDir = false;//是否显示返回主目录
21+
private boolean showUpDir = true;//是否显示返回上一级
22+
private boolean showHideDir = true;//是否显示隐藏的目录(以“.”开头)
2223
private int homeIcon = R.drawable.file_picker_home;
23-
private int updirIcon = R.drawable.file_picker_updir;
24+
private int upIcon = R.drawable.file_picker_updir;
2425
private int folderIcon = R.drawable.file_picker_folder;
2526
private int fileIcon = R.drawable.file_picker_file;
2627

@@ -40,22 +41,24 @@ public FileAdapter(Context context, int layoutRes, List<FileItem> data) {
4041
super(context, layoutRes, data);
4142
}
4243

43-
@Override
44-
protected void convert(AdapterHelper helper, FileItem item) {
45-
super.convert(helper, item);
46-
helper.setTextColor(R.id.text, Color.BLACK);
44+
public String getCurrentPath() {
45+
return currentPath;
4746
}
4847

4948
public void setAllowExtensions(String[] allowExtensions) {
5049
this.allowExtensions = allowExtensions;
5150
}
5251

53-
public void setShowUpOrRoot(boolean showUpOrRoot) {
54-
this.showUpOrRoot = showUpOrRoot;
52+
public void setShowHomeDir(boolean showHomeDir) {
53+
this.showHomeDir = showHomeDir;
5554
}
5655

57-
public void setShowHiddenDir(boolean showHiddenDir) {
58-
this.showHiddenDir = showHiddenDir;
56+
public void setShowUpDir(boolean showUpDir) {
57+
this.showUpDir = showUpDir;
58+
}
59+
60+
public void setShowHideDir(boolean showHideDir) {
61+
this.showHideDir = showHideDir;
5962
}
6063

6164
public ArrayList<FileItem> loadData(String path) {
@@ -72,24 +75,26 @@ public ArrayList<FileItem> loadData(String path, boolean notifyDataSetChanged) {
7275
rootPath = path;
7376
}
7477
Logger.debug("current directory path: " + path);
75-
if (showUpOrRoot) {
76-
//添加“返回主目录”及“返回上一级”
78+
currentPath = path;
79+
if (showHomeDir) {
80+
//添加“返回主目录”
7781
FileItem fileRoot = new FileItem();
7882
fileRoot.setDirectory(true);
7983
fileRoot.setIcon(homeIcon);
8084
fileRoot.setName(DIR_ROOT);
8185
fileRoot.setSize(0);
8286
fileRoot.setPath(rootPath);
8387
datas.add(fileRoot);
84-
if (!path.equals("/")) {
85-
FileItem fileParent = new FileItem();
86-
fileParent.setDirectory(true);
87-
fileParent.setIcon(updirIcon);
88-
fileParent.setName(DIR_PARENT);
89-
fileRoot.setSize(0);
90-
fileParent.setPath(new File(path).getParent());
91-
datas.add(fileParent);
92-
}
88+
}
89+
if (showUpDir && !path.equals("/")) {
90+
//添加“返回上一级目录”
91+
FileItem fileParent = new FileItem();
92+
fileParent.setDirectory(true);
93+
fileParent.setIcon(upIcon);
94+
fileParent.setName(DIR_PARENT);
95+
fileParent.setSize(0);
96+
fileParent.setPath(new File(path).getParent());
97+
datas.add(fileParent);
9398
}
9499
File[] files;
95100
if (allowExtensions == null) {
@@ -99,7 +104,7 @@ public ArrayList<FileItem> loadData(String path, boolean notifyDataSetChanged) {
99104
}
100105
if (files != null) {
101106
for (File file : files) {
102-
if (!showHiddenDir && file.getName().startsWith(".")) {
107+
if (!showHideDir && file.getName().startsWith(".")) {
103108
continue;
104109
}
105110
FileItem fileItem = new FileItem();

framework-picker/src/main/java/cn/qqtheme/framework/helper/Common.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ public class Common {
3131
/**
3232
* 判断外置存储是否可用
3333
*/
34-
public static boolean externalAvailable() {
34+
public static boolean externalMounted() {
3535
String state = Environment.getExternalStorageState();
36-
if (state.equals(Environment.MEDIA_MOUNTED) && Environment.getExternalStorageDirectory().canWrite()) {
36+
if (state.equals(Environment.MEDIA_MOUNTED)) {
3737
return true;
3838
}
39-
Logger.warn("external storage unavailable (unmounted or can't write)");
39+
Logger.warn("external storage unmounted");
4040
return false;
4141
}
4242

@@ -47,7 +47,7 @@ public static boolean externalAvailable() {
4747
*/
4848
public static String getRootPath(Context context) {
4949
File file;
50-
if (externalAvailable()) {
50+
if (externalMounted()) {
5151
file = Environment.getExternalStorageDirectory();
5252
} else {
5353
file = context.getFilesDir();

framework-picker/src/main/java/cn/qqtheme/framework/helper/FileUtils.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ public boolean accept(File f) {
8181
if (dirs == null) {
8282
return new File[0];
8383
}
84-
int len = dirs.length;
8584
if (excludeDirs == null) {
8685
excludeDirs = new String[0];
8786
}

framework-picker/src/main/java/cn/qqtheme/framework/picker/ColorPicker.java

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717
import java.util.Locale;
1818

1919
public class ColorPicker extends ConfirmPopup<LinearLayout> implements TextView.OnEditorActionListener {
20-
private static final int TOP_ID = 0x1;
21-
private static final int BOTTOM_ID = 0x2;
20+
private static final int MULTI_ID = 0x1;
21+
private static final int BLACK_ID = 0x2;
2222
private int initColor = Color.WHITE;
23-
private ColorPanelView topColorView, bottomColorView;
23+
private ColorPanelView multiColorView, blackColorView;
2424
private EditText hexValView;
2525
private ColorStateList hexValDefaultColor;
2626
private OnColorPickListener onColorPickListener;
@@ -32,41 +32,40 @@ public ColorPicker(Activity activity) {
3232
@Override
3333
protected LinearLayout initContentView() {
3434
LinearLayout rootLayout = new LinearLayout(activity);
35-
rootLayout.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT));
35+
rootLayout.setLayoutParams(new LinearLayout.LayoutParams(MATCH_PARENT, MATCH_PARENT));
3636
rootLayout.setOrientation(LinearLayout.VERTICAL);
37-
topColorView = new ColorPanelView(activity);
37+
blackColorView = new ColorPanelView(activity);
3838
//noinspection ResourceType
39-
topColorView.setId(TOP_ID);
40-
int screenHeight = Common.getPixels(activity)[1];
41-
topColorView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, screenHeight / 3));
42-
topColorView.setPointerDrawable(Common.getDrawable(activity, R.drawable.color_picker_cursor_top));
43-
topColorView.setLockPointerInBounds(true);
44-
topColorView.setOnColorChangedListener(new ColorPanelView.OnColorChangedListener() {
39+
blackColorView.setId(BLACK_ID);
40+
blackColorView.setLayoutParams(new LinearLayout.LayoutParams(MATCH_PARENT, Common.toPx(activity, 30)));
41+
blackColorView.setPointerDrawable(Common.getDrawable(activity, R.drawable.color_picker_cursor_bottom));
42+
blackColorView.setLockPointerInBounds(false);
43+
blackColorView.setOnColorChangedListener(new ColorPanelView.OnColorChangedListener() {
4544
@Override
4645
public void onColorChanged(ColorPanelView view, int color) {
4746
updateCurrentColor(color);
4847
}
4948
});
50-
rootLayout.addView(topColorView);
51-
bottomColorView = new ColorPanelView(activity);
49+
rootLayout.addView(blackColorView);
50+
multiColorView = new ColorPanelView(activity);
5251
//noinspection ResourceType
53-
bottomColorView.setId(BOTTOM_ID);
54-
bottomColorView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, Common.toPx(activity, 30)));
55-
bottomColorView.setPointerDrawable(Common.getDrawable(activity, R.drawable.color_picker_cursor_bottom));
56-
bottomColorView.setLockPointerInBounds(false);
57-
bottomColorView.setOnColorChangedListener(new ColorPanelView.OnColorChangedListener() {
52+
multiColorView.setId(MULTI_ID);
53+
multiColorView.setLayoutParams(new LinearLayout.LayoutParams(MATCH_PARENT, 0, 1.0f));
54+
multiColorView.setPointerDrawable(Common.getDrawable(activity, R.drawable.color_picker_cursor_top));
55+
multiColorView.setLockPointerInBounds(true);
56+
multiColorView.setOnColorChangedListener(new ColorPanelView.OnColorChangedListener() {
5857
@Override
5958
public void onColorChanged(ColorPanelView view, int color) {
6059
updateCurrentColor(color);
6160
}
6261
});
63-
rootLayout.addView(bottomColorView);
62+
rootLayout.addView(multiColorView);
6463
LinearLayout previewLayout = new LinearLayout(activity);
6564
previewLayout.setOrientation(LinearLayout.HORIZONTAL);
6665
previewLayout.setGravity(Gravity.CENTER);
67-
previewLayout.setLayoutParams(new LinearLayout.LayoutParams(MATCH_PARENT, Common.toPx(activity, 40)));
66+
previewLayout.setLayoutParams(new LinearLayout.LayoutParams(MATCH_PARENT, Common.toPx(activity, 30)));
6867
hexValView = new EditText(activity);
69-
hexValView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT));
68+
hexValView.setLayoutParams(new LinearLayout.LayoutParams(MATCH_PARENT, MATCH_PARENT));
7069
hexValView.setInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
7170
hexValView.setImeOptions(EditorInfo.IME_ACTION_DONE);
7271
hexValView.setGravity(Gravity.CENTER);
@@ -85,15 +84,15 @@ public void onColorChanged(ColorPanelView view, int color) {
8584
}
8685

8786
@Override
88-
protected void onShowPrepare() {
89-
super.onShowPrepare();
90-
topColorView.setColor(initColor);//将触发onColorChanged,故必须先待其他控件初始化完成后才能调用
91-
topColorView.setBrightnessGradientView(bottomColorView);
87+
protected void setContentViewAfter(View contentView) {
88+
setHeight(screenHeight / 2);
89+
multiColorView.setColor(initColor);//将触发onColorChanged,故必须先待其他控件初始化完成后才能调用
90+
multiColorView.setBrightnessGradientView(blackColorView);
9291
if (onColorPickListener != null) {
9392
super.setOnConfirmListener(new OnConfirmListener() {
9493
@Override
9594
public void onConfirm() {
96-
onColorPickListener.onColorPicked(bottomColorView.getSelectedColor());
95+
onColorPickListener.onColorPicked(blackColorView.getSelectedColor());
9796
}
9897

9998
@Override
@@ -138,7 +137,7 @@ public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
138137
if (length == 6 || length == 8) {
139138
try {
140139
int color = Color.parseColor("#" + hexString);
141-
topColorView.setColor(color);
140+
multiColorView.setColor(color);
142141
hexValView.setTextColor(hexValDefaultColor);
143142
} catch (IllegalArgumentException e) {
144143
hexValView.setTextColor(Color.RED);

0 commit comments

Comments
 (0)