From cb3313111991665b526bc25296e0079bd2ead14b Mon Sep 17 00:00:00 2001 From: lihuichao Date: Sat, 30 Sep 2017 11:29:41 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B91.0.0bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/vcs.xml | 6 ++ addresspickerlibrary/build.gradle | 6 +- .../addresspickerlibrary/InitAreaTask.java | 78 +++++++++++++++++++ build.gradle | 3 +- 4 files changed, 90 insertions(+), 3 deletions(-) create mode 100644 .idea/vcs.xml create mode 100644 addresspickerlibrary/src/main/java/com/addresspicker/huichao/addresspickerlibrary/InitAreaTask.java diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/addresspickerlibrary/build.gradle b/addresspickerlibrary/build.gradle index 8a840a9..8de3ae9 100644 --- a/addresspickerlibrary/build.gradle +++ b/addresspickerlibrary/build.gradle @@ -1,5 +1,6 @@ apply plugin: 'com.android.library' - +apply plugin: 'com.github.dcendents.android-maven' +group='com.github.CHAOHUILI' android { compileSdkVersion 26 buildToolsVersion "25.0.2" @@ -22,5 +23,6 @@ android { } dependencies { - compile fileTree(dir: 'libs', include: ['*.jar']) + compile fileTree(include: ['*.jar'], dir: 'libs') + compile 'com.alibaba:fastjson:1.2.38' } diff --git a/addresspickerlibrary/src/main/java/com/addresspicker/huichao/addresspickerlibrary/InitAreaTask.java b/addresspickerlibrary/src/main/java/com/addresspicker/huichao/addresspickerlibrary/InitAreaTask.java new file mode 100644 index 0000000..15347bb --- /dev/null +++ b/addresspickerlibrary/src/main/java/com/addresspicker/huichao/addresspickerlibrary/InitAreaTask.java @@ -0,0 +1,78 @@ +package com.addresspicker.huichao.addresspickerlibrary; + +import android.content.Context; +import android.os.AsyncTask; +import android.widget.Toast; + + +import com.addresspicker.huichao.addresspickerlibrary.address.Province; +import com.alibaba.fastjson.JSON; + +import java.io.IOException; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.List; + +/** + * Created by lihuichao on 2017/9/27. + */ + +public class InitAreaTask extends AsyncTask { + protected onLoadingAddressListener onLoadingAddressListener; + Context mContext; + ArrayList provinces; + + + public InitAreaTask(Context context, ArrayList provinces) { + mContext = context; + this.provinces = provinces; + } + + public void setOnLoadingAddressListener(onLoadingAddressListener onLoadingAddressListener) { + this.onLoadingAddressListener = onLoadingAddressListener; + } + + @Override + protected void onPreExecute() { + } + + @Override + protected void onPostExecute(Boolean result) { + if (provinces.size() > 0) { + this.onLoadingAddressListener.onLoadFinished(); + } else { + Toast.makeText(mContext, "数据初始化失败", Toast.LENGTH_SHORT).show(); + } + } + + @Override + protected Boolean doInBackground(Integer... params) { + String address = null; + InputStream in = null; + try { + in = mContext.getResources().getAssets().open("address.txt"); + byte[] arrayOfByte = new byte[in.available()]; + in.read(arrayOfByte); + address = new String(arrayOfByte, "UTF-8"); + + List provinces1 = JSON.parseArray(address, Province.class); + provinces.addAll(provinces1); + return true; + } catch (Exception e) { + e.printStackTrace(); + } finally { + if (in != null) { + try { + in.close(); + } catch (IOException e) { + } + } + } + return false; + } + + public interface onLoadingAddressListener { + void onLoadFinished(); + } + +} diff --git a/build.gradle b/build.gradle index c2eea8e..7cc2970 100644 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,7 @@ buildscript { } dependencies { classpath 'com.android.tools.build:gradle:2.3.3' - + classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } @@ -15,6 +15,7 @@ buildscript { allprojects { repositories { jcenter() + maven { url "https://jitpack.io"} } }