Initial commit
This commit is contained in:
2
app/.gitignore
vendored
Normal file
2
app/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
/build
|
||||
/*.iml
|
||||
29
app/build.gradle
Normal file
29
app/build.gradle
Normal file
@@ -0,0 +1,29 @@
|
||||
apply plugin: 'com.android.application'
|
||||
|
||||
android {
|
||||
|
||||
buildTypes {
|
||||
release {
|
||||
//是否zip优化
|
||||
zipAlignEnabled true
|
||||
//是否移除无用的资源
|
||||
shrinkResources true
|
||||
//是否混淆
|
||||
minifyEnabled true
|
||||
//混淆配置文件
|
||||
proguardFile 'proguard-rules.pro'
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile 'com.alibaba:fastjson:1.1.46.android'
|
||||
compile 'com.github.florent37:viewanimator:1.0.2'
|
||||
compile project(':library:WheelPicker')
|
||||
compile project(':library:FilePicker')
|
||||
compile project(':library:ColorPicker')
|
||||
// compile 'cn.qqtheme.framework:WheelPicker:1.1.0'
|
||||
// compile 'cn.qqtheme.framework:FilePicker:1.1.0'
|
||||
// compile 'cn.qqtheme.framework:ColorPicker:1.1.0'
|
||||
}
|
||||
17
app/proguard-rules.pro
vendored
Normal file
17
app/proguard-rules.pro
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
# Add project specific ProGuard rules here.
|
||||
# By default, the flags in this file are appended to flags specified
|
||||
# in D:\android-develop\android-sdk/tools/proguard/proguard-android.txt
|
||||
# You can edit the include path and order by changing the proguardFiles
|
||||
# directive in build.gradle.
|
||||
#
|
||||
# For more details, see
|
||||
# http://developer.android.com/guide/developing/tools/proguard.html
|
||||
|
||||
# Add any project specific keep options here:
|
||||
|
||||
# If your project uses WebView with JS, uncomment the following
|
||||
# and specify the fully qualified class name to the JavaScript interface
|
||||
# class:
|
||||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
||||
# public *;
|
||||
#}
|
||||
24
app/src/main/AndroidManifest.xml
Normal file
24
app/src/main/AndroidManifest.xml
Normal file
@@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
package="cn.qqtheme.androidpicker">
|
||||
|
||||
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
|
||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:theme="@android:style/Theme.Holo.Light"
|
||||
tools:ignore="AllowBackup,GoogleAppIndexingWarning,NewApi">
|
||||
<activity android:name=".MainActivity">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
1
app/src/main/assets/city.json
Normal file
1
app/src/main/assets/city.json
Normal file
File diff suppressed because one or more lines are too long
424
app/src/main/assets/city2.json
Normal file
424
app/src/main/assets/city2.json
Normal file
@@ -0,0 +1,424 @@
|
||||
[
|
||||
{
|
||||
"cities": [
|
||||
{
|
||||
"counties": [
|
||||
{
|
||||
"areaName": "南明区 ",
|
||||
"areaId": "520102"
|
||||
},
|
||||
{
|
||||
"areaName": "云岩区",
|
||||
"areaId": "520103"
|
||||
},
|
||||
{
|
||||
"areaName": "花溪区 ",
|
||||
"areaId": "520111"
|
||||
},
|
||||
{
|
||||
"areaName": "乌当区 ",
|
||||
"areaId": "520112"
|
||||
},
|
||||
{
|
||||
"areaName": "白云区",
|
||||
"areaId": "520113"
|
||||
},
|
||||
{
|
||||
"areaName": "观山湖区",
|
||||
"areaId": "520115"
|
||||
},
|
||||
{
|
||||
"areaName": "开阳县",
|
||||
"areaId": "520121"
|
||||
},
|
||||
{
|
||||
"areaName": "息烽县",
|
||||
"areaId": "520122"
|
||||
},
|
||||
{
|
||||
"areaName": "修文县 ",
|
||||
"areaId": "520123"
|
||||
},
|
||||
{
|
||||
"areaName": "清镇市",
|
||||
"areaId": "520181"
|
||||
}
|
||||
],
|
||||
"areaName": "贵阳市 ",
|
||||
"areaId": "520100"
|
||||
},
|
||||
{
|
||||
"counties": [
|
||||
{
|
||||
"areaName": "钟山区",
|
||||
"areaId": "520201"
|
||||
},
|
||||
{
|
||||
"areaName": "六枝特区 ",
|
||||
"areaId": "520203"
|
||||
},
|
||||
{
|
||||
"areaName": "水城县 ",
|
||||
"areaId": "520221"
|
||||
},
|
||||
{
|
||||
"areaName": "盘县 ",
|
||||
"areaId": "520222"
|
||||
}
|
||||
],
|
||||
"areaName": "六盘水市",
|
||||
"areaId": "520200"
|
||||
},
|
||||
{
|
||||
"counties": [
|
||||
{
|
||||
"areaName": "红花岗区 ",
|
||||
"areaId": "520302"
|
||||
},
|
||||
{
|
||||
"areaName": "汇川区 ",
|
||||
"areaId": "520303"
|
||||
},
|
||||
{
|
||||
"areaName": "遵义县 ",
|
||||
"areaId": "520321"
|
||||
},
|
||||
{
|
||||
"areaName": "桐梓县",
|
||||
"areaId": "520322"
|
||||
},
|
||||
{
|
||||
"areaName": "绥阳县",
|
||||
"areaId": "520323"
|
||||
},
|
||||
{
|
||||
"areaName": "正安县",
|
||||
"areaId": "520324"
|
||||
},
|
||||
{
|
||||
"areaName": "道真仡佬族苗族自治县",
|
||||
"areaId": "520325"
|
||||
},
|
||||
{
|
||||
"areaName": "务川仡佬族苗族自治县 ",
|
||||
"areaId": "520326"
|
||||
},
|
||||
{
|
||||
"areaName": "凤冈县 ",
|
||||
"areaId": "520327"
|
||||
},
|
||||
{
|
||||
"areaName": "湄潭县 ",
|
||||
"areaId": "520328"
|
||||
},
|
||||
{
|
||||
"areaName": "余庆县 ",
|
||||
"areaId": "520329"
|
||||
},
|
||||
{
|
||||
"areaName": "习水县 ",
|
||||
"areaId": "520330"
|
||||
},
|
||||
{
|
||||
"areaName": "赤水市",
|
||||
"areaId": "520381"
|
||||
},
|
||||
{
|
||||
"areaName": "仁怀市",
|
||||
"areaId": "520382"
|
||||
}
|
||||
],
|
||||
"areaName": "遵义市 ",
|
||||
"areaId": "520300"
|
||||
},
|
||||
{
|
||||
"counties": [
|
||||
{
|
||||
"areaName": "西秀区 ",
|
||||
"areaId": "520402"
|
||||
},
|
||||
{
|
||||
"areaName": "平坝区 ",
|
||||
"areaId": "520403"
|
||||
},
|
||||
{
|
||||
"areaName": "普定县 ",
|
||||
"areaId": "520422"
|
||||
},
|
||||
{
|
||||
"areaName": "镇宁布依族苗族自治县 ",
|
||||
"areaId": "520423"
|
||||
},
|
||||
{
|
||||
"areaName": "关岭布依族苗族自治县 ",
|
||||
"areaId": "520424"
|
||||
},
|
||||
{
|
||||
"areaName": "紫云苗族布依族自治县",
|
||||
"areaId": "520425"
|
||||
}
|
||||
],
|
||||
"areaName": "安顺市 ",
|
||||
"areaId": "520400"
|
||||
},
|
||||
{
|
||||
"counties": [
|
||||
{
|
||||
"areaName": "七星关区 ",
|
||||
"areaId": "520502"
|
||||
},
|
||||
{
|
||||
"areaName": "大方县",
|
||||
"areaId": "520521"
|
||||
},
|
||||
{
|
||||
"areaName": "黔西县 ",
|
||||
"areaId": "520522"
|
||||
},
|
||||
{
|
||||
"areaName": "金沙县 ",
|
||||
"areaId": "520523"
|
||||
},
|
||||
{
|
||||
"areaName": "织金县 ",
|
||||
"areaId": "520524"
|
||||
},
|
||||
{
|
||||
"areaName": "纳雍县 ",
|
||||
"areaId": "520525"
|
||||
},
|
||||
{
|
||||
"areaName": "威宁彝族回族苗族自治县 ",
|
||||
"areaId": "520526"
|
||||
},
|
||||
{
|
||||
"areaName": " 赫章县 ",
|
||||
"areaId": "520527"
|
||||
}
|
||||
],
|
||||
"areaName": "毕节市 ",
|
||||
"areaId": "520500"
|
||||
},
|
||||
{
|
||||
"counties": [
|
||||
{
|
||||
"areaName": "碧江区 ",
|
||||
"areaId": "520602"
|
||||
},
|
||||
{
|
||||
"areaName": "万山区",
|
||||
"areaId": "520603"
|
||||
},
|
||||
{
|
||||
"areaName": "江口县 ",
|
||||
"areaId": "520621"
|
||||
},
|
||||
{
|
||||
"areaName": "玉屏侗族自治县",
|
||||
"areaId": "520622"
|
||||
},
|
||||
{
|
||||
"areaName": "石阡县 ",
|
||||
"areaId": "520623"
|
||||
},
|
||||
{
|
||||
"areaName": "思南县 ",
|
||||
"areaId": "520624"
|
||||
},
|
||||
{
|
||||
"areaName": "印江土家族苗族自治县 ",
|
||||
"areaId": "520625"
|
||||
},
|
||||
{
|
||||
"areaName": "德江县 ",
|
||||
"areaId": "520626"
|
||||
},
|
||||
{
|
||||
"areaName": "沿河土家族自治县 ",
|
||||
"areaId": "520627"
|
||||
},
|
||||
{
|
||||
"areaName": "松桃苗族自治县",
|
||||
"areaId": "520628"
|
||||
}
|
||||
],
|
||||
"areaName": "铜仁市",
|
||||
"areaId": "520600"
|
||||
},
|
||||
{
|
||||
"counties": [
|
||||
{
|
||||
"areaName": "兴义市 ",
|
||||
"areaId": "522301"
|
||||
},
|
||||
{
|
||||
"areaName": "兴仁县 ",
|
||||
"areaId": "522322"
|
||||
},
|
||||
{
|
||||
"areaName": "普安县 ",
|
||||
"areaId": "522323"
|
||||
},
|
||||
{
|
||||
"areaName": "晴隆县 ",
|
||||
"areaId": "522324"
|
||||
},
|
||||
{
|
||||
"areaName": "贞丰县 ",
|
||||
"areaId": "522325"
|
||||
},
|
||||
{
|
||||
"areaName": "望谟县 ",
|
||||
"areaId": "522326"
|
||||
},
|
||||
{
|
||||
"areaName": "册亨县 ",
|
||||
"areaId": "522327"
|
||||
},
|
||||
{
|
||||
"areaName": "安龙县 ",
|
||||
"areaId": "522328"
|
||||
}
|
||||
],
|
||||
"areaName": "黔西南布依族苗族自治州",
|
||||
"areaId": "522300"
|
||||
},
|
||||
{
|
||||
"counties": [
|
||||
{
|
||||
"areaName": "凯里市 ",
|
||||
"areaId": "522601"
|
||||
},
|
||||
{
|
||||
"areaName": "黄平县 ",
|
||||
"areaId": "522622"
|
||||
},
|
||||
{
|
||||
"areaName": "施秉县",
|
||||
"areaId": "522623"
|
||||
},
|
||||
{
|
||||
"areaName": "三穗县",
|
||||
"areaId": "522624"
|
||||
},
|
||||
{
|
||||
"areaName": "镇远县 ",
|
||||
"areaId": "522625"
|
||||
},
|
||||
{
|
||||
"areaName": "岑巩县",
|
||||
"areaId": "522626"
|
||||
},
|
||||
{
|
||||
"areaName": "天柱县 ",
|
||||
"areaId": "522627"
|
||||
},
|
||||
{
|
||||
"areaName": "锦屏县",
|
||||
"areaId": "522628"
|
||||
},
|
||||
{
|
||||
"areaName": "剑河县 ",
|
||||
"areaId": "522629"
|
||||
},
|
||||
{
|
||||
"areaName": "台江县 ",
|
||||
"areaId": "522630"
|
||||
},
|
||||
{
|
||||
"areaName": "黎平县 ",
|
||||
"areaId": "522631"
|
||||
},
|
||||
{
|
||||
"areaName": "榕江县 ",
|
||||
"areaId": "522632"
|
||||
},
|
||||
{
|
||||
"areaName": "从江县 ",
|
||||
"areaId": "522633"
|
||||
},
|
||||
{
|
||||
"areaName": "雷山县 ",
|
||||
"areaId": "522634"
|
||||
},
|
||||
{
|
||||
"areaName": "麻江县",
|
||||
"areaId": "522635"
|
||||
},
|
||||
{
|
||||
"areaName": "丹寨县",
|
||||
"areaId": "522636"
|
||||
}
|
||||
],
|
||||
"areaName": "黔东南苗族侗族自治州",
|
||||
"areaId": "522600"
|
||||
},
|
||||
{
|
||||
"counties": [
|
||||
{
|
||||
"areaName": "都匀市 ",
|
||||
"areaId": "522701"
|
||||
},
|
||||
{
|
||||
"areaName": "福泉市 ",
|
||||
"areaId": "522702"
|
||||
},
|
||||
{
|
||||
"areaName": "荔波县 ",
|
||||
"areaId": "522722"
|
||||
},
|
||||
{
|
||||
"areaName": "贵定县 ",
|
||||
"areaId": "522723"
|
||||
},
|
||||
{
|
||||
"areaName": "瓮安县",
|
||||
"areaId": "522725"
|
||||
},
|
||||
{
|
||||
"areaName": "独山县 ",
|
||||
"areaId": "522726"
|
||||
},
|
||||
{
|
||||
"areaName": "平塘县",
|
||||
"areaId": "522727"
|
||||
},
|
||||
{
|
||||
"areaName": "罗甸县",
|
||||
"areaId": "522728"
|
||||
},
|
||||
{
|
||||
"areaName": "长顺县 ",
|
||||
"areaId": "522729"
|
||||
},
|
||||
{
|
||||
"areaName": "龙里县",
|
||||
"areaId": "522730"
|
||||
},
|
||||
{
|
||||
"areaName": "惠水县 ",
|
||||
"areaId": "522731"
|
||||
},
|
||||
{
|
||||
"areaName": "三都水族自治县 ",
|
||||
"areaId": "522732"
|
||||
}
|
||||
],
|
||||
"areaName": "黔南布依族苗族自治州 ",
|
||||
"areaId": "522700"
|
||||
},
|
||||
{
|
||||
"counties": [
|
||||
{
|
||||
"areaName": "贵安新区",
|
||||
"areaId": "529900"
|
||||
}
|
||||
],
|
||||
"areaName": "贵安新区",
|
||||
"areaId": "529900"
|
||||
}
|
||||
],
|
||||
"areaName": "贵州省 ",
|
||||
"areaId": "520000"
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1,94 @@
|
||||
package cn.qqtheme.androidpicker;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.ProgressDialog;
|
||||
import android.os.AsyncTask;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import cn.qqtheme.framework.picker.AddressPicker;
|
||||
|
||||
/**
|
||||
* 获取地址数据并显示地址选择器
|
||||
*
|
||||
* @author 李玉江[QQ:1032694760]
|
||||
* @version 2015/12/15
|
||||
*/
|
||||
public class AddressInitTask extends AsyncTask<String, Void, ArrayList<AddressPicker.Province>> {
|
||||
private Activity activity;
|
||||
private ProgressDialog dialog;
|
||||
private String selectedProvince = "", selectedCity = "", selectedCounty = "";
|
||||
private boolean hideCounty=false;
|
||||
|
||||
/**
|
||||
* 初始化为不显示区县的模式
|
||||
* @param activity
|
||||
* @param hideCounty is hide County
|
||||
*/
|
||||
public AddressInitTask(Activity activity,boolean hideCounty) {
|
||||
this.activity = activity;
|
||||
this.hideCounty=hideCounty;
|
||||
dialog = ProgressDialog.show(activity, null, "正在初始化数据...", true, true);
|
||||
}
|
||||
|
||||
public AddressInitTask(Activity activity) {
|
||||
this.activity = activity;
|
||||
dialog = ProgressDialog.show(activity, null, "正在初始化数据...", true, true);
|
||||
}
|
||||
@Override
|
||||
protected ArrayList<AddressPicker.Province> doInBackground(String... params) {
|
||||
if (params != null) {
|
||||
switch (params.length) {
|
||||
case 1:
|
||||
selectedProvince = params[0];
|
||||
break;
|
||||
case 2:
|
||||
selectedProvince = params[0];
|
||||
selectedCity = params[1];
|
||||
break;
|
||||
case 3:
|
||||
selectedProvince = params[0];
|
||||
selectedCity = params[1];
|
||||
selectedCounty = params[2];
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
ArrayList<AddressPicker.Province> data = new ArrayList<AddressPicker.Province>();
|
||||
try {
|
||||
String json = AssetsUtils.readText(activity, "city.json");
|
||||
data.addAll(JSON.parseArray(json, AddressPicker.Province.class));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(ArrayList<AddressPicker.Province> result) {
|
||||
dialog.dismiss();
|
||||
if (result.size() > 0) {
|
||||
AddressPicker picker = new AddressPicker(activity, result);
|
||||
picker.setHideCounty(hideCounty);
|
||||
picker.setSelectedItem(selectedProvince, selectedCity, selectedCounty);
|
||||
picker.setOnAddressPickListener(new AddressPicker.OnAddressPickListener() {
|
||||
@Override
|
||||
public void onAddressPicked(String province, String city, String county) {
|
||||
if (county==null){
|
||||
Toast.makeText(activity, province + city, Toast.LENGTH_LONG).show();
|
||||
} else {
|
||||
Toast.makeText(activity, province + city + county, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
}
|
||||
});
|
||||
picker.show();
|
||||
} else {
|
||||
Toast.makeText(activity, "数据初始化失败", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
33
app/src/main/java/cn/qqtheme/androidpicker/AssetsUtils.java
Normal file
33
app/src/main/java/cn/qqtheme/androidpicker/AssetsUtils.java
Normal file
@@ -0,0 +1,33 @@
|
||||
package cn.qqtheme.androidpicker;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import cn.qqtheme.framework.util.ConvertUtils;
|
||||
import cn.qqtheme.framework.util.LogUtils;
|
||||
|
||||
/**
|
||||
* 操作安装包中的“assets”目录下的文件
|
||||
*
|
||||
* @author 李玉江[QQ:1023694760]
|
||||
* @version 2013-11-2
|
||||
*/
|
||||
public class AssetsUtils {
|
||||
|
||||
/**
|
||||
* read file content
|
||||
*
|
||||
* @param context the context
|
||||
* @param assetPath the asset path
|
||||
* @return String string
|
||||
*/
|
||||
public static String readText(Context context, String assetPath) {
|
||||
LogUtils.debug("read assets file as text: " + assetPath);
|
||||
try {
|
||||
return ConvertUtils.toString(context.getAssets().open(assetPath));
|
||||
} catch (Exception e) {
|
||||
LogUtils.error(e);
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
package cn.qqtheme.androidpicker;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.animation.AccelerateInterpolator;
|
||||
import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.github.florent37.viewanimator.AnimationListener;
|
||||
import com.github.florent37.viewanimator.ViewAnimator;
|
||||
|
||||
import cn.qqtheme.framework.picker.OptionPicker;
|
||||
|
||||
/**
|
||||
* 自定义顶部及底部
|
||||
* <p/>
|
||||
* Author:李玉江[QQ:1032694760]
|
||||
* Email:liyujiang_tk@yeah.net
|
||||
* DateTime:2016/1/29 14:47
|
||||
* Builder:Android Studio
|
||||
*/
|
||||
public class CustomHeaderAndFooterPicker extends OptionPicker {
|
||||
|
||||
public CustomHeaderAndFooterPicker(Activity activity) {
|
||||
super(activity, new String[]{
|
||||
"C/C++", "Java", "PHP", "Swift", "Node.js", "C#", "HTML5"
|
||||
});
|
||||
setTitleText("请选择你最擅长的语言");
|
||||
setSelectedItem("PHP");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void show() {
|
||||
super.show();
|
||||
ViewAnimator.animate(getRootView())
|
||||
.duration(2000)
|
||||
.interpolator(new AccelerateInterpolator())
|
||||
.slideBottom()
|
||||
.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dismiss() {
|
||||
ViewAnimator.animate(getRootView())
|
||||
.duration(1000)
|
||||
.rollOut()
|
||||
.onStop(new AnimationListener.Stop() {
|
||||
@Override
|
||||
public void onStop() {
|
||||
CustomHeaderAndFooterPicker.super.dismiss();
|
||||
}
|
||||
})
|
||||
.start();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
protected View makeHeaderView() {
|
||||
View view = LayoutInflater.from(activity).inflate(R.layout.picker_header, null);
|
||||
TextView titleView = (TextView) view.findViewById(R.id.picker_title);
|
||||
titleView.setText(titleText);
|
||||
return view;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
protected View makeFooterView() {
|
||||
View view = LayoutInflater.from(activity).inflate(R.layout.picker_footer, null);
|
||||
Button submitView = (Button) view.findViewById(R.id.picker_submit);
|
||||
submitView.setText(submitText);
|
||||
submitView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
dismiss();
|
||||
onSubmit();
|
||||
}
|
||||
});
|
||||
Button cancelView = (Button) view.findViewById(R.id.picker_cancel);
|
||||
cancelView.setText(cancelText);
|
||||
cancelView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
dismiss();
|
||||
onCancel();
|
||||
}
|
||||
});
|
||||
return view;
|
||||
}
|
||||
|
||||
}
|
||||
345
app/src/main/java/cn/qqtheme/androidpicker/MainActivity.java
Normal file
345
app/src/main/java/cn/qqtheme/androidpicker/MainActivity.java
Normal file
@@ -0,0 +1,345 @@
|
||||
package cn.qqtheme.androidpicker;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Color;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.github.florent37.viewanimator.ViewAnimator;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
|
||||
import cn.qqtheme.framework.picker.AddressPicker;
|
||||
import cn.qqtheme.framework.picker.ChineseZodiacPicker;
|
||||
import cn.qqtheme.framework.picker.ColorPicker;
|
||||
import cn.qqtheme.framework.picker.ConstellationPicker;
|
||||
import cn.qqtheme.framework.picker.DatePicker;
|
||||
import cn.qqtheme.framework.picker.FilePicker;
|
||||
import cn.qqtheme.framework.picker.MyTimePicker;
|
||||
import cn.qqtheme.framework.picker.NumberPicker;
|
||||
import cn.qqtheme.framework.picker.OptionPicker;
|
||||
import cn.qqtheme.framework.picker.SexPicker;
|
||||
import cn.qqtheme.framework.picker.TimePicker;
|
||||
import cn.qqtheme.framework.util.ConvertUtils;
|
||||
import cn.qqtheme.framework.util.StorageUtils;
|
||||
|
||||
public class MainActivity extends Activity {
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
System.exit(0);
|
||||
android.os.Process.killProcess(android.os.Process.myPid());
|
||||
finish();
|
||||
}
|
||||
|
||||
private void showToast(String msg) {
|
||||
Toast.makeText(this, msg, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
public void onAnimationStyle(View view) {
|
||||
NumberPicker picker = new NumberPicker(this);
|
||||
picker.setAnimationStyle(R.style.Animation_CustomPopup);
|
||||
picker.setOffset(2);//偏移量
|
||||
picker.setRange(40, 100);//数字范围
|
||||
picker.setSelectedItem(65);
|
||||
picker.setLabel("Kg");
|
||||
picker.setOnOptionPickListener(new OptionPicker.OnOptionPickListener() {
|
||||
@Override
|
||||
public void onOptionPicked(String option) {
|
||||
showToast(option);
|
||||
}
|
||||
});
|
||||
picker.show();
|
||||
}
|
||||
|
||||
public void onAnimator(View view) {
|
||||
CustomHeaderAndFooterPicker picker = new CustomHeaderAndFooterPicker(this);
|
||||
picker.setOnOptionPickListener(new OptionPicker.OnOptionPickListener() {
|
||||
@Override
|
||||
public void onOptionPicked(String option) {
|
||||
showToast(option);
|
||||
}
|
||||
});
|
||||
picker.show();
|
||||
}
|
||||
|
||||
public void onYearMonthDayPicker(View view) {
|
||||
DatePicker picker = new DatePicker(this);
|
||||
picker.setRange(2000, 2016);
|
||||
picker.setSelectedItem(2015, 10, 10);
|
||||
picker.setOnDatePickListener(new DatePicker.OnYearMonthDayPickListener() {
|
||||
@Override
|
||||
public void onDatePicked(String year, String month, String day) {
|
||||
showToast(year + "-" + month + "-" + day);
|
||||
}
|
||||
});
|
||||
picker.show();
|
||||
}
|
||||
|
||||
public void onYearMonthPicker(View view) {
|
||||
DatePicker picker = new DatePicker(this, DatePicker.YEAR_MONTH);
|
||||
picker.setRange(1990, 2015);
|
||||
picker.setOnDatePickListener(new DatePicker.OnYearMonthPickListener() {
|
||||
@Override
|
||||
public void onDatePicked(String year, String month) {
|
||||
showToast(year + "-" + month);
|
||||
}
|
||||
});
|
||||
picker.show();
|
||||
}
|
||||
|
||||
public void onMonthDayPicker(View view) {
|
||||
DatePicker picker = new DatePicker(this, DatePicker.MONTH_DAY);
|
||||
picker.setOnDatePickListener(new DatePicker.OnMonthDayPickListener() {
|
||||
@Override
|
||||
public void onDatePicked(String month, String day) {
|
||||
showToast(month + "-" + day);
|
||||
}
|
||||
});
|
||||
picker.show();
|
||||
}
|
||||
|
||||
public void onTimePicker(View view) {
|
||||
//默认选中当前时间
|
||||
TimePicker picker = new TimePicker(this, TimePicker.HOUR_OF_DAY);
|
||||
picker.setTopLineVisible(false);
|
||||
picker.setOnTimePickListener(new TimePicker.OnTimePickListener() {
|
||||
@Override
|
||||
public void onTimePicked(String hour, String minute) {
|
||||
showToast(hour + ":" + minute);
|
||||
}
|
||||
});
|
||||
picker.show();
|
||||
}
|
||||
|
||||
public void onOptionPicker(View view) {
|
||||
OptionPicker picker = new OptionPicker(this, new String[]{
|
||||
"第一项", "第二项", "这是一个很长很长很长很长很长很长很长很长很长的很长很长的很长很长的项"
|
||||
});
|
||||
picker.setOffset(2);
|
||||
picker.setSelectedIndex(1);
|
||||
picker.setTextSize(11);
|
||||
picker.setOnOptionPickListener(new OptionPicker.OnOptionPickListener() {
|
||||
@Override
|
||||
public void onOptionPicked(String option) {
|
||||
showToast(option);
|
||||
}
|
||||
});
|
||||
picker.show();
|
||||
}
|
||||
|
||||
public void onConstellationPicker(View view) {
|
||||
ConstellationPicker picker = new ConstellationPicker(this);
|
||||
picker.setTopBackgroundColor(0xFFEEEEEE);
|
||||
picker.setTopLineVisible(false);
|
||||
picker.setCancelTextColor(0xFF33B5E5);
|
||||
picker.setSubmitTextColor(0xFF33B5E5);
|
||||
picker.setTextColor(0xFFFF0000, 0xFFCCCCCC);
|
||||
picker.setLineColor(0xFFEE0000);
|
||||
picker.setSelectedItem("射手");
|
||||
picker.setOnOptionPickListener(new OptionPicker.OnOptionPickListener() {
|
||||
@Override
|
||||
public void onOptionPicked(String option) {
|
||||
showToast(option);
|
||||
}
|
||||
});
|
||||
picker.show();
|
||||
}
|
||||
|
||||
public void onChineseZodiacPicker(View view) {
|
||||
ChineseZodiacPicker picker = new ChineseZodiacPicker(this);
|
||||
picker.setLineVisible(false);
|
||||
picker.setSelectedItem("羊");
|
||||
picker.setOnOptionPickListener(new OptionPicker.OnOptionPickListener() {
|
||||
@Override
|
||||
public void onOptionPicked(String option) {
|
||||
showToast(option);
|
||||
}
|
||||
});
|
||||
picker.show();
|
||||
}
|
||||
|
||||
public void onNumberPicker(View view) {
|
||||
NumberPicker picker = new NumberPicker(this);
|
||||
picker.setOffset(2);//偏移量
|
||||
picker.setRange(145, 200);//数字范围
|
||||
picker.setSelectedItem(172);
|
||||
picker.setLabel("厘米");
|
||||
picker.setOnOptionPickListener(new OptionPicker.OnOptionPickListener() {
|
||||
@Override
|
||||
public void onOptionPicked(String option) {
|
||||
showToast(option);
|
||||
}
|
||||
});
|
||||
picker.show();
|
||||
}
|
||||
|
||||
public void onSexPicker(View view) {
|
||||
SexPicker picker = new SexPicker(this);
|
||||
//picker.onlyMaleAndFemale();
|
||||
picker.setOnOptionPickListener(new OptionPicker.OnOptionPickListener() {
|
||||
@Override
|
||||
public void onOptionPicked(String option) {
|
||||
showToast(option);
|
||||
}
|
||||
});
|
||||
picker.show();
|
||||
}
|
||||
|
||||
public void onAddressPicker(View view) {
|
||||
new AddressInitTask(this).execute("贵州", "毕节", "纳雍");
|
||||
}
|
||||
|
||||
public void onAddress2Picker(View view) {
|
||||
try {
|
||||
ArrayList<AddressPicker.Province> data = new ArrayList<AddressPicker.Province>();
|
||||
String json = AssetsUtils.readText(this, "city2.json");
|
||||
data.addAll(JSON.parseArray(json, AddressPicker.Province.class));
|
||||
AddressPicker picker = new AddressPicker(this, data);
|
||||
picker.setHideProvince(true);
|
||||
picker.setSelectedItem("贵州", "贵阳", "花溪");
|
||||
picker.setOnAddressPickListener(new AddressPicker.OnAddressPickListener() {
|
||||
@Override
|
||||
public void onAddressPicked(String province, String city, String county) {
|
||||
showToast(city + county);
|
||||
}
|
||||
});
|
||||
picker.show();
|
||||
} catch (Exception e) {
|
||||
showToast(e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void onAddress3Picker(View view) {
|
||||
new AddressInitTask(this,true).execute("四川", "成都");
|
||||
}
|
||||
|
||||
public void onColorPicker(View view) {
|
||||
ColorPicker picker = new ColorPicker(this);
|
||||
picker.setInitColor(0xDD00DD);
|
||||
picker.setOnColorPickListener(new ColorPicker.OnColorPickListener() {
|
||||
@Override
|
||||
public void onColorPicked(int pickedColor) {
|
||||
showToast(ConvertUtils.toColorString(pickedColor));
|
||||
}
|
||||
});
|
||||
picker.show();
|
||||
}
|
||||
|
||||
public void onFilePicker(View view) {
|
||||
//noinspection MissingPermission
|
||||
FilePicker picker = new FilePicker(this, FilePicker.FILE);
|
||||
picker.setShowHideDir(false);
|
||||
//picker.setAllowExtensions(new String[]{".apk"});
|
||||
picker.setOnFilePickListener(new FilePicker.OnFilePickListener() {
|
||||
@Override
|
||||
public void onFilePicked(String currentPath) {
|
||||
showToast(currentPath);
|
||||
}
|
||||
});
|
||||
picker.show();
|
||||
}
|
||||
|
||||
public void onDirPicker(View view) {
|
||||
//noinspection MissingPermission
|
||||
FilePicker picker = new FilePicker(this, FilePicker.DIRECTORY);
|
||||
picker.setRootPath(StorageUtils.getRootPath(this) + "Download/");
|
||||
picker.setOnFilePickListener(new FilePicker.OnFilePickListener() {
|
||||
@Override
|
||||
public void onFilePicked(String currentPath) {
|
||||
showToast(currentPath);
|
||||
}
|
||||
});
|
||||
picker.show();
|
||||
}
|
||||
|
||||
public void onContact(View view) {
|
||||
final ArrayList<String> minutes = get64minutes();
|
||||
final ArrayList<String> hours = get24hours();
|
||||
final ArrayList<String> dates = get7Date();
|
||||
|
||||
MyTimePicker myTimePicker=new MyTimePicker(this,dates,hours,minutes);
|
||||
myTimePicker.setSelectedItem(0,0,0);
|
||||
myTimePicker.setTitleText("选择时间");
|
||||
myTimePicker.setTitleTextSize(16);
|
||||
|
||||
myTimePicker.setTopBackgroundColor(Color.parseColor("#FFEAEAEB"));
|
||||
myTimePicker.setTextSize(21);
|
||||
|
||||
myTimePicker.setCancelText("取消");
|
||||
myTimePicker.setSubmitText("完成");
|
||||
myTimePicker.setSubmitTextColor(Color.parseColor("#F77B55"));
|
||||
myTimePicker.setLineColor(Color.parseColor("#FFEAEAEB"));
|
||||
myTimePicker.setTextColor(Color.parseColor("#000000"));
|
||||
myTimePicker.show();
|
||||
myTimePicker.setOnAddressPickListener(new MyTimePicker.OnAddressPickListener() {
|
||||
@Override
|
||||
public void onAddressPicked(String province, String city, String county) {
|
||||
System.out.println("province="+province);
|
||||
System.out.println("city="+city);
|
||||
System.out.println("county="+county);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
// Intent intent = new Intent(Intent.ACTION_SENDTO);
|
||||
// intent.setData(Uri.parse("mailto:liyujiang_tk@yeah.net"));
|
||||
// intent.putExtra(Intent.EXTRA_CC, new String[]
|
||||
// {"1032694760@qq.com"});
|
||||
// intent.putExtra(Intent.EXTRA_EMAIL, "");
|
||||
// intent.putExtra(Intent.EXTRA_TEXT, "欢迎提供意您的见或建议");
|
||||
// startActivity(Intent.createChooser(intent, "选择邮件客户端"));
|
||||
}
|
||||
private ArrayList<String> get7Date() {
|
||||
ArrayList<String> dates = new ArrayList<String>();
|
||||
for (int i = 0; i < 7; i++) {
|
||||
dates.add(getStatetime(i));
|
||||
}
|
||||
return dates;
|
||||
}
|
||||
|
||||
private ArrayList<String> get24hours() {
|
||||
ArrayList<String> dates = new ArrayList<String>();
|
||||
for (int i = 0; i < 24; i++) {
|
||||
|
||||
dates.add((i < 10 ? "0" + i : i) + "时");
|
||||
}
|
||||
return dates;
|
||||
}
|
||||
|
||||
private ArrayList<String> get64minutes() {
|
||||
ArrayList<String> dates = new ArrayList<String>();
|
||||
for (int i = 0; i < 60; i++) {
|
||||
dates.add((i < 10 ? "0" + i : i) + "分");
|
||||
}
|
||||
return dates;
|
||||
}
|
||||
|
||||
private String getStatetime(int i) {
|
||||
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("MM月dd日");
|
||||
|
||||
Calendar c = Calendar.getInstance();
|
||||
c.add(Calendar.DATE, i);
|
||||
Date monday = c.getTime();
|
||||
String preMonday = sdf.format(monday);
|
||||
return preMonday;
|
||||
}
|
||||
|
||||
}
|
||||
11
app/src/main/res/anim/popup_in.xml
Normal file
11
app/src/main/res/anim/popup_in.xml
Normal file
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<set xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<translate
|
||||
android:duration="1000"
|
||||
android:fromYDelta="100%p"
|
||||
android:toYDelta="0" />
|
||||
<alpha
|
||||
android:duration="500"
|
||||
android:fromAlpha="0"
|
||||
android:toAlpha="1" />
|
||||
</set>
|
||||
11
app/src/main/res/anim/popup_out.xml
Normal file
11
app/src/main/res/anim/popup_out.xml
Normal file
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<set xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<translate
|
||||
android:duration="1000"
|
||||
android:fromYDelta="0"
|
||||
android:toYDelta="50%p" />
|
||||
<alpha
|
||||
android:duration="500"
|
||||
android:fromAlpha="1"
|
||||
android:toAlpha="0" />
|
||||
</set>
|
||||
120
app/src/main/res/layout/activity_main.xml
Normal file
120
app/src/main/res/layout/activity_main.xml
Normal file
@@ -0,0 +1,120 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<Button
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:onClick="onAnimationStyle"
|
||||
android:text="窗口动画(基于XML)" />
|
||||
|
||||
<Button
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:onClick="onAnimator"
|
||||
android:text="窗口动画(基于Java)" />
|
||||
|
||||
<Button
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:onClick="onYearMonthDayPicker"
|
||||
android:text="年月日选择" />
|
||||
|
||||
<Button
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:onClick="onYearMonthPicker"
|
||||
android:text="年月选择" />
|
||||
|
||||
<Button
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:onClick="onMonthDayPicker"
|
||||
android:text="月日选择" />
|
||||
|
||||
<Button
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:onClick="onTimePicker"
|
||||
android:text="时间选择" />
|
||||
|
||||
<Button
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:onClick="onOptionPicker"
|
||||
android:text="单项选择" />
|
||||
|
||||
<Button
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:onClick="onConstellationPicker"
|
||||
android:text="星座选择" />
|
||||
|
||||
<Button
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:onClick="onChineseZodiacPicker"
|
||||
android:text="生肖选择" />
|
||||
|
||||
<Button
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:onClick="onNumberPicker"
|
||||
android:text="数字选择(如身高、体重、年龄)" />
|
||||
|
||||
<Button
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:onClick="onSexPicker"
|
||||
android:text="性别选择" />
|
||||
|
||||
<Button
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:onClick="onAddressPicker"
|
||||
android:text="地址选择(包括省级、地级、县级)" />
|
||||
|
||||
<Button
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:onClick="onAddress2Picker"
|
||||
android:text="地址选择(只包括地级、县级)" />
|
||||
<Button
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:onClick="onAddress3Picker"
|
||||
android:text="地址选择(只包括省级、地级)" />
|
||||
|
||||
<Button
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:onClick="onColorPicker"
|
||||
android:text="颜色选择" />
|
||||
|
||||
<Button
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:onClick="onFilePicker"
|
||||
android:text="文件选择" />
|
||||
|
||||
<Button
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:onClick="onDirPicker"
|
||||
android:text="目录选择" />
|
||||
|
||||
<Button
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:onClick="onContact"
|
||||
android:text="建议收集" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</ScrollView>
|
||||
36
app/src/main/res/layout/picker_footer.xml
Normal file
36
app/src/main/res/layout/picker_footer.xml
Normal file
@@ -0,0 +1,36 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:layout_marginTop="10dp"
|
||||
android:background="#FFEEEEEE" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="10dp"
|
||||
android:gravity="center_horizontal"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<Button
|
||||
android:id="@+id/picker_submit"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="submit" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/picker_cancel"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="10dp"
|
||||
android:text="cancel"
|
||||
android:textColor="#FFFF0000" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
14
app/src/main/res/layout/picker_header.xml
Normal file
14
app/src/main/res/layout/picker_header.xml
Normal file
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/picker_title"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="40dp"
|
||||
android:gravity="center"
|
||||
android:text="New Text" />
|
||||
|
||||
</LinearLayout>
|
||||
BIN
app/src/main/res/mipmap-hdpi/ic_launcher.png
Normal file
BIN
app/src/main/res/mipmap-hdpi/ic_launcher.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.0 KiB |
3
app/src/main/res/values/strings.xml
Normal file
3
app/src/main/res/values/strings.xml
Normal file
@@ -0,0 +1,3 @@
|
||||
<resources>
|
||||
<string name="app_name">AndroidPicker</string>
|
||||
</resources>
|
||||
9
app/src/main/res/values/styles.xml
Normal file
9
app/src/main/res/values/styles.xml
Normal file
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
|
||||
<style name="Animation.CustomPopup" parent="@android:style/Animation">
|
||||
<item name="android:windowEnterAnimation">@anim/popup_in</item>
|
||||
<item name="android:windowExitAnimation">@anim/popup_out</item>
|
||||
</style>
|
||||
|
||||
</resources>
|
||||
Reference in New Issue
Block a user