cookies = allCookies.get(uri);
77 | if (cookie != null)
78 | {
79 | return cookies.remove(cookie);
80 | }
81 | return false;
82 | }
83 |
84 |
85 | }
86 |
--------------------------------------------------------------------------------
/base/src/main/java/com/apple/http/cookie/okhttp/SerializableHttpCookie.java:
--------------------------------------------------------------------------------
1 | package com.apple.http.cookie.okhttp;
2 |
3 | import java.io.IOException;
4 | import java.io.ObjectInputStream;
5 | import java.io.ObjectOutputStream;
6 | import java.io.Serializable;
7 |
8 | import okhttp3.Cookie;
9 |
10 | /**
11 | * from http://stackoverflow.com/questions/25461792/persistent-cookie-store-using-okhttp-2-on-android
12 | * and
13 | * http://www.geebr.com/post/okHttp3%E4%B9%8BCookies%E7%AE%A1%E7%90%86%E5%8F%8A%E6%8C%81%E4%B9%85%E5%8C%96
14 | */
15 |
16 | public class SerializableHttpCookie implements Serializable
17 | {
18 | private static final long serialVersionUID = 6374381323722046732L;
19 |
20 | private transient final Cookie cookie;
21 | private transient Cookie clientCookie;
22 |
23 | public SerializableHttpCookie(Cookie cookie)
24 | {
25 | this.cookie = cookie;
26 | }
27 |
28 | public Cookie getCookie()
29 | {
30 | Cookie bestCookie = cookie;
31 | if (clientCookie != null)
32 | {
33 | bestCookie = clientCookie;
34 | }
35 |
36 | return bestCookie;
37 | }
38 |
39 | private void writeObject(ObjectOutputStream out) throws IOException
40 | {
41 | out.writeObject(cookie.name());
42 | out.writeObject(cookie.value());
43 | out.writeLong(cookie.expiresAt());
44 | out.writeObject(cookie.domain());
45 | out.writeObject(cookie.path());
46 | out.writeBoolean(cookie.secure());
47 | out.writeBoolean(cookie.httpOnly());
48 | out.writeBoolean(cookie.hostOnly());
49 | out.writeBoolean(cookie.persistent());
50 | }
51 |
52 | private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException
53 | {
54 | String name = (String) in.readObject();
55 | String value = (String) in.readObject();
56 | long expiresAt = in.readLong();
57 | String domain = (String) in.readObject();
58 | String path = (String) in.readObject();
59 | boolean secure = in.readBoolean();
60 | boolean httpOnly = in.readBoolean();
61 | boolean hostOnly = in.readBoolean();
62 | boolean persistent = in.readBoolean();
63 | Cookie.Builder builder = new Cookie.Builder();
64 | builder = builder.name(name);
65 | builder = builder.value(value);
66 | builder = builder.expiresAt(expiresAt);
67 | builder = hostOnly ? builder.hostOnlyDomain(domain) : builder.domain(domain);
68 | builder = builder.path(path);
69 | builder = secure ? builder.secure() : builder;
70 | builder = httpOnly ? builder.httpOnly() : builder;
71 | clientCookie = builder.build();
72 |
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/base/src/main/java/com/apple/http/entity/DownEntity.java:
--------------------------------------------------------------------------------
1 | package com.apple.http.entity;
2 |
3 |
4 | /**
5 | * 下载返回实体类
6 | * @author hushaoping
7 | */
8 | public class DownEntity {
9 |
10 | public String name;
11 | public String path;
12 | public String url;
13 | public int httpCode;
14 | //下载是否完成
15 | public int statue=0;
16 | public long currentByte;
17 | public long totalByte;
18 | public boolean isExecuted;
19 | public String dir;
20 |
21 | public boolean isCanceled;
22 | public String message;
23 | /**
24 | */
25 | public DownEntity() {
26 | this.url = "";
27 | this.path = "";
28 | this.statue = 0;
29 | this.httpCode =-1;
30 | this.totalByte = 0;
31 | this.currentByte = 0;
32 | this.isCanceled=false;
33 | this.isExecuted=false;
34 | this.dir="";
35 | this.message="";
36 | }
37 |
38 | public DownEntity downDir(String dir) {
39 | this.dir=dir;
40 | return this;
41 | }
42 |
43 | public DownEntity downMessage(String message) {
44 | this.message=message;
45 | return this;
46 | }
47 | public DownEntity downName(String name) {
48 | this.name=name;
49 | return this;
50 | }
51 | public DownEntity downPath(String path) {
52 | this.path=path;
53 | return this;
54 | }
55 | public DownEntity downUrl(String url) {
56 | this.url=url;
57 | return this;
58 | }
59 | public DownEntity downCode(int code) {
60 | this.httpCode=code;
61 | return this;
62 | }
63 |
64 | public DownEntity downStatue(int statue) {
65 | this.statue = statue;
66 | return this;
67 | }
68 |
69 |
70 | public DownEntity currentByte(long currentByte) {
71 | this.currentByte=currentByte;
72 | return this;
73 | }
74 | public DownEntity totalByte(long totalByte) {
75 | this.totalByte=totalByte;
76 | return this;
77 | }
78 |
79 | // public DownEntity build() {
80 | // return new DownEntity();
81 | // }
82 |
83 | }
84 |
--------------------------------------------------------------------------------
/base/src/main/java/com/apple/http/entity/DownType.java:
--------------------------------------------------------------------------------
1 | package com.apple.http.entity;
2 |
3 | /**
4 | * Created by apple_hsp on 16/3/31.
5 | * 定义请求访问方式
6 | */
7 | public class DownType {
8 | //开始下载
9 | public static final int DOWNLOAD_START =0;
10 | //正在下载
11 | public static final int DOWNLOAD_GOING=1;
12 | //下载完成
13 | public static final int DOWNLOAD_COMPLETE = 2;
14 | //空间不足
15 | public static final int DOWNLOAD_SPACE =3;
16 | //下载错误
17 | public static final int DOWNLOAD_ERROR =4;
18 |
19 | }
20 |
--------------------------------------------------------------------------------
/base/src/main/java/com/apple/http/entity/METHOD.java:
--------------------------------------------------------------------------------
1 | package com.apple.http.entity;
2 |
3 | /**
4 | * Created by apple_hsp on 16/3/31.
5 | * 定义请求访问方式
6 | */
7 | public class METHOD {
8 | public static final String GET = "GET";
9 | public static final String POST_STRING = "POST_STRING";
10 | public static final String POST_FORM = "POST_FORM";
11 | public static final String POST_FORM_FILE = "POST_FORM_FILE";
12 | public static final String POST_FILE = "POST_FILE";
13 | public static final String DOWNLOAD_FILE = "DOWN_FILE";
14 | public static final String POST_FILE_PROGRESS = "POST_FILE_PROGRESS";
15 | public static final String POST_FORM_PROGRESS = "POST_FORM_PROGRESS";
16 | public static final String PUT = "PUT";
17 | public static final String PATCH = "PATCH";
18 | public static final String DELETE = "DELETE";
19 | }
20 |
--------------------------------------------------------------------------------
/base/src/main/java/com/apple/http/impl/BaseHttpImpl.java:
--------------------------------------------------------------------------------
1 | package com.apple.http.impl;
2 |
3 | import com.apple.http.common.HttpConfiguration;
4 | import com.apple.http.listener.BaseCallback;
5 | import com.apple.http.common.BaseHttpClient;
6 |
7 |
8 | /**
9 | * 请求对象模板接口
10 | * BaseHttpClient such is the definition of a common network parameters into the model,
11 | * all network expansion interface to implement the first
12 | * interface to define the request, and can be customized to achieve a new interface
13 | @author 胡少平
14 | */
15 |
16 |
17 | public interface BaseHttpImpl {
18 | /**
19 | * 网络库接口定义
20 | * public static final String GET = "GET";
21 | public static final String POST_STRING = "POST_STRING";
22 | public static final String POST_FORM = "POST_FORM";
23 | public static final String POST_FILE = "POST_FILE";
24 | public static final String DOWNLOAD_FILE = "DOWN_FILE";
25 | public static final String POST_FILE_PROGRESS = "POST_FILE_PROGRESS";
26 | public static final String POST_FORM_PROGRESS = "POST_FORM_PROGRESS";
27 | public static final String PUT = "PUT";
28 | public static final String PATCH = "PATCH";
29 | public static final String DELETE = "DELETE";
30 | */
31 | void get(BaseHttpClient client, BaseCallback callback);
32 | void put(BaseHttpClient client, BaseCallback callback);
33 | void patch(BaseHttpClient client, BaseCallback callback);
34 | void delete(BaseHttpClient client, BaseCallback callback);
35 |
36 | void postString(BaseHttpClient client, BaseCallback callback);
37 | void postFile(BaseHttpClient client, BaseCallback callback);
38 | void postForm(BaseHttpClient client, BaseCallback callback);
39 | void postFormFile(BaseHttpClient client, BaseCallback callback);
40 | void downloadFile(BaseHttpClient client, BaseCallback callback);
41 |
42 | void postFileProgress(BaseHttpClient client, BaseCallback callback);
43 | void postFormProgress(BaseHttpClient client, BaseCallback callback);
44 | void execute(BaseHttpClient client, BaseCallback callback);
45 |
46 | /**
47 | * 配置初始化操作
48 | * @param configuration
49 | */
50 | void init(HttpConfiguration configuration);
51 | }
52 |
--------------------------------------------------------------------------------
/base/src/main/java/com/apple/http/impl/async/AsyncHttpImpl.java:
--------------------------------------------------------------------------------
1 | package com.apple.http.impl.async;
2 |
3 |
4 | /**
5 | * AsyncHttpClient async网络申请实现类
6 | * 如果有新网络tcp请求,就要重新实现一个网络交互类
7 | *
8 | * @author 胡少平
9 | *
10 | */
11 | //public class AsyncHttpClientImpl implements BaseHttpClient {
12 | //
13 | // private AsyncHttpClient client=null;
14 | //
15 | // //单例模式实现
16 | // private static AsyncHttpClientImpl instance;
17 | //
18 | // public static AsyncHttpClientImpl getHupuHttpClient() {
19 | // if (instance == null)
20 | // instance = new AsyncHttpClientImpl();
21 | // return instance;
22 | // }
23 | //
24 | // private AsyncHttpClientImpl() {
25 | // client = new AsyncHttpClient();
26 | // }
27 | //
28 | // @Override
29 | // public void get(String reqType, String url, RequestParams cacheParams,
30 | // HttpCallback callback) {
31 | // client.get(null, url, cacheParams, new BaseHttpHandler(callback, reqType));
32 | // }
33 | //
34 | // @Override
35 | // public void get(String reqType, Context context, String url,
36 | // RequestParams cacheParams, HttpCallback callback) {
37 | // // TODO Auto-generated method stub
38 | // client.get(context, url, cacheParams, new BaseHttpHandler(callback,reqType));
39 | // }
40 | //
41 | // @Override
42 | // public void post(String reqType, Context context, String url,
43 | // RequestParams params, HttpCallback callback) {
44 | // // TODO Auto-generated method stub
45 | // client.post(context,url,params,new BaseHttpHandler(callback,reqType));
46 | // }
47 | //
48 | // @Override
49 | // public void post(String reqType, Context context, String url, HttpEntity entity, String contentType, HttpCallback callback) {
50 | //
51 | // }
52 | //
53 | //
54 | // @Override
55 | // public void get(Context context, BaseParams params, HttpCallback callback) {
56 | //
57 | // }
58 | //
59 | // @Override
60 | // public void post(Context context, BaseParams params, HttpCallback callback) {
61 | //
62 | // }
63 | //
64 | // @Override
65 | // public void post(String reqType, Context context, String url,
66 | // Header[] headers, HttpEntity entity, String contentType,
67 | // HttpCallback callback) {
68 | // // TODO Auto-generated method stub
69 | // client.post(context,url,headers,entity,null,new BaseHttpHandler(callback,reqType));
70 | // }
71 | //
72 | // public void clearRequest(){
73 | // client.cancelAllRequests(true);
74 | // }
75 | //
76 | //}
77 |
--------------------------------------------------------------------------------
/base/src/main/java/com/apple/http/listener/BaseCallback.java:
--------------------------------------------------------------------------------
1 | package com.apple.http.listener;
2 |
3 |
4 | import com.apple.http.entity.DownEntity;
5 | import com.apple.http.common.BaseHttpClient;
6 |
7 | /**
8 | * 请求callback;
9 | *
10 | * @author hushaoping
11 | */
12 | public abstract class BaseCallback{
13 | /**
14 | * 请求成功
15 | * @param content 返回值
16 | * @param client 返回的发起端对象
17 | * @param parse 解析对象
18 | */
19 | public abstract void success(String content, BaseHttpClient client, Object parse);
20 |
21 | /**
22 | * 请求失败
23 | *
24 | * @param error 错误
25 | * @param client client发起者
26 | */
27 | public abstract void error(Throwable error, BaseHttpClient client);
28 |
29 | /**
30 | * 文件上传进度
31 | * @param bytesRead
32 | * @param contentLength
33 | * @param done
34 | */
35 |
36 | public abstract void uploadProgress(long bytesRead, long contentLength, boolean done);
37 |
38 | /**
39 | * 文件下载进度返回
40 | * @param entity
41 | */
42 | public abstract void downProgress(DownEntity entity);
43 |
44 | public static BaseCallback CALLBACK_DEFAULT = new BaseCallback()
45 | {
46 | @Override
47 | public void success(String content, BaseHttpClient client, Object parse) {
48 |
49 | }
50 |
51 | @Override
52 | public void error(Throwable error, BaseHttpClient client) {
53 |
54 | }
55 |
56 | @Override
57 | public void uploadProgress(long bytesRead, long contentLength, boolean done) {
58 |
59 | }
60 |
61 | @Override
62 | public void downProgress(DownEntity entity) {
63 |
64 | }
65 | };
66 | }
67 |
--------------------------------------------------------------------------------
/base/src/main/java/com/apple/http/listener/DownCallback.java:
--------------------------------------------------------------------------------
1 | package com.apple.http.listener;
2 |
3 |
4 | import com.apple.http.common.BaseHttpClient;
5 |
6 | /**
7 | * 下载文件请求返回
8 | * @author hushaoping
9 | */
10 | public abstract class DownCallback extends BaseCallback {
11 |
12 | @Override
13 | public void success(String content, BaseHttpClient object, Object parse) {
14 |
15 | }
16 |
17 | @Override
18 | public void error(Throwable error,BaseHttpClient client) {
19 |
20 | }
21 |
22 | @Override
23 | public void uploadProgress(long bytesRead, long contentLength, boolean done) {
24 |
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/base/src/main/java/com/apple/http/listener/HttpCallback.java:
--------------------------------------------------------------------------------
1 | package com.apple.http.listener;
2 |
3 |
4 | import com.apple.http.entity.DownEntity;
5 |
6 | /**
7 | *
8 | * 普通请求返回成功失败数据
9 | * @author hushaoping
10 | */
11 | public abstract class HttpCallback extends BaseCallback {
12 | @Override
13 | public void uploadProgress(long bytesRead, long contentLength, boolean done) {
14 |
15 | }
16 |
17 | @Override
18 | public void downProgress(DownEntity entity) {
19 |
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/base/src/main/java/com/apple/http/listener/UploadCallback.java:
--------------------------------------------------------------------------------
1 | package com.apple.http.listener;
2 |
3 |
4 | import com.apple.http.entity.DownEntity;
5 |
6 | /**
7 | *
8 | * 网络上传请求返回进度监听
9 | *
10 | * @author hushaoping
11 | */
12 | public abstract class UploadCallback extends BaseCallback {
13 | @Override
14 | public void downProgress(DownEntity entity) {
15 |
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/base/src/main/java/com/apple/http/retrofit/FieldParam.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014 Square, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.apple.http.retrofit;
17 |
18 |
19 | import java.lang.annotation.Documented;
20 | import java.lang.annotation.Retention;
21 | import java.lang.annotation.Target;
22 |
23 | import static java.lang.annotation.ElementType.PARAMETER;
24 | import static java.lang.annotation.RetentionPolicy.RUNTIME;
25 |
26 | /**
27 | * Named key/value pairs for a form-encoded request.
28 | *
29 | * Simple Example:
30 | *
31 | * @FormUrlEncoded
32 | * @POST("/things")
33 | * Call<ResponseBody> things(@FieldMap Map<String, String> fields);
34 | *
35 | * Calling with {@code foo.things(ImmutableMap.of("foo", "bar", "kit", "kat")} yields a request
36 | * body of {@code foo=bar&kit=kat}.
37 | *
38 | * A {@code null} value for the map, as a key, or as a value is not allowed.
39 | *
40 | * @see FormUrlEncoded
41 | * @see Field
42 | */
43 | @Documented
44 | @Target(PARAMETER)
45 | @Retention(RUNTIME)
46 | public @interface FieldParam {
47 | /** Specifies whether the names and values are already URL encoded. */
48 | boolean encoded() default false;
49 | }
50 |
--------------------------------------------------------------------------------
/base/src/main/java/com/apple/http/retrofit/HttpBaseUrl.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2013 Square, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.apple.http.retrofit;
17 |
18 | import java.lang.annotation.Documented;
19 | import java.lang.annotation.Retention;
20 | import java.lang.annotation.Target;
21 |
22 | import static java.lang.annotation.ElementType.METHOD;
23 | import static java.lang.annotation.ElementType.PARAMETER;
24 | import static java.lang.annotation.RetentionPolicy.RUNTIME;
25 |
26 | /**
27 | * Named replacement in a URL path segment. Values are converted to string using
28 | * {@link String#valueOf(Object)} and URL encoded.
29 | *
30 | * Simple example:
31 | *
32 | * @GET("/image/{id}")
33 | * Call<ResponseBody> example(@Path("id") int id);
34 | *
35 | * Calling with {@code foo.example(1)} yields {@code /image/1}.
36 | *
37 | * Values are URL encoded by default. Disable with {@code encoded=true}.
38 | *
39 | * @GET("/user/{name}")
40 | * Call<ResponseBody> encoded(@Path("name") String name);
41 | *
42 | * @GET("/user/{name}")
43 | * Call<ResponseBody> notEncoded(@Path(value="name", encoded=true) String name);
44 | *
45 | * Calling {@code foo.encoded("John+Doe")} yields {@code /user/John%2BDoe} whereas
46 | * {@code foo.notEncoded("John+Doe")} yields {@code /user/John+Doe}.
47 | *
48 | * Path parameters may not be {@code null}.
49 | */
50 | @Documented
51 | @Target(METHOD)
52 | @Retention(RUNTIME)
53 | public @interface HttpBaseUrl {
54 | String value();
55 | }
56 |
--------------------------------------------------------------------------------
/base/src/main/java/com/apple/http/retrofit/HttpMehod.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2013 Square, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.apple.http.retrofit;
17 |
18 |
19 | import java.lang.annotation.Documented;
20 | import java.lang.annotation.Retention;
21 | import java.lang.annotation.Target;
22 |
23 | import okhttp3.HttpUrl;
24 |
25 | import static java.lang.annotation.ElementType.METHOD;
26 | import static java.lang.annotation.RetentionPolicy.RUNTIME;
27 |
28 | /** Make a POST request. */
29 | @Documented
30 | @Target(METHOD)
31 | @Retention(RUNTIME)
32 | public @interface HttpMehod {
33 | /**
34 | * A relative or absolute path, or full URL of the endpoint. This value is optional if the first
35 | * parameter of the method is annotated with {@link Url @Url}.
36 | *
37 | * See {@linkplain retrofit2.Retrofit.Builder#baseUrl(HttpUrl) base URL} for details of how
38 | * this is resolved against a base URL to create the full endpoint URL.
39 | */
40 | String value() default "";
41 | }
42 |
--------------------------------------------------------------------------------
/base/src/main/java/com/apple/http/retrofit/HttpParse.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015 Square, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.apple.http.retrofit;
17 |
18 |
19 | import java.lang.annotation.Documented;
20 | import java.lang.annotation.Retention;
21 | import java.lang.annotation.Target;
22 |
23 | import okhttp3.HttpUrl;
24 |
25 | import static java.lang.annotation.ElementType.METHOD;
26 | import static java.lang.annotation.RetentionPolicy.RUNTIME;
27 |
28 | /**
29 | * Make an OPTIONS request.
30 | */
31 | @Documented
32 | @Target(METHOD)
33 | @Retention(RUNTIME)
34 | public @interface HttpParse {
35 | /**
36 | * A relative or absolute path, or full URL of the endpoint. This value is optional if the first
37 | * parameter of the method is annotated with {@link Url @Url}.
38 | *
39 | * See {@linkplain retrofit2.Retrofit.Builder#baseUrl(HttpUrl) base URL} for details of how
40 | * this is resolved against a base URL to create the full endpoint URL.
41 | */
42 | Class value() ;
43 | }
44 |
--------------------------------------------------------------------------------
/base/src/main/java/com/apple/http/utils/L.java:
--------------------------------------------------------------------------------
1 | package com.apple.http.utils;
2 |
3 | import android.util.Log;
4 |
5 | import com.apple.http.common.BaseHttpClient;
6 |
7 |
8 | /**
9 | * "Less-word" analog of Android {@link Log logger}
10 | *
11 | * @author Sergey Tarasevich (nostra13[at]gmail[dot]com)
12 | * @since 1.6.4
13 | */
14 | public final class L {
15 |
16 | private static final String LOG_FORMAT = "http";
17 | private static volatile boolean writeDebugLogs = false;
18 | private static volatile boolean writeLogs = true;
19 |
20 | private L() {
21 | }
22 |
23 | /**
24 | * Enables logger (if {@link #disableLogging()} was called before)
25 | *
26 | * @deprecated Use {@link #writeLogs(boolean) writeLogs(true)} instead
27 | */
28 | @Deprecated
29 | public static void enableLogging() {
30 | writeLogs(true);
31 | }
32 |
33 | /**
34 | * Disables logger, no logs will be passed to LogCat, all log methods will do nothing
35 | *
36 | * @deprecated Use {@link #writeLogs(boolean) writeLogs(false)} instead
37 | */
38 | @Deprecated
39 | public static void disableLogging() {
40 | writeLogs(false);
41 | }
42 |
43 | /**
44 | * Enables/disables detail logging of {@link BaseHttpClient} work.
45 | */
46 | public static void writeDebugLogs(boolean writeDebugLogs) {
47 | L.writeDebugLogs = writeDebugLogs;
48 | }
49 |
50 | /** Enables/disables logging of {@link BaseHttpClient} completely (even error logs). */
51 | public static void writeLogs(boolean writeLogs) {
52 | L.writeLogs = writeLogs;
53 | }
54 |
55 | public static void d(String message, Object... args) {
56 | if (writeDebugLogs) {
57 | log(Log.DEBUG, null, message, args);
58 | }
59 | }
60 |
61 | public static void i(String message, Object... args) {
62 | log(Log.INFO, null, message, args);
63 | }
64 |
65 | public static void w(String message, Object... args) {
66 | log(Log.WARN, null, message, args);
67 | }
68 |
69 | public static void e(Throwable ex) {
70 | log(Log.ERROR, ex, null);
71 | }
72 |
73 | public static void e(String message, Object... args) {
74 | log(Log.ERROR, null, message, args);
75 | }
76 |
77 | public static void e(Throwable ex, String message, Object... args) {
78 | log(Log.ERROR, ex, message, args);
79 | }
80 |
81 | private static void log(int priority, Throwable ex, String message, Object... args) {
82 | if (!writeLogs) return;
83 | if (args.length > 0) {
84 | message = String.format(message, args);
85 | }
86 |
87 | String log;
88 | if (ex == null) {
89 | log = message;
90 | } else {
91 | String logMessage = message == null ? ex.getMessage() : message;
92 | String logBody = Log.getStackTraceString(ex);
93 | log = String.format(LOG_FORMAT, logMessage, logBody);
94 | }
95 | Log.println(priority, BaseHttpClient.TAG, log);
96 | }
97 | }
98 |
--------------------------------------------------------------------------------
/base/src/main/java/com/apple/http/utils/NameValuePair.java:
--------------------------------------------------------------------------------
1 | package com.apple.http.utils;
2 |
3 | /**
4 | * Created by apple_hsp on 16/3/23.
5 | */
6 | public interface NameValuePair {
7 | String getName();
8 |
9 | String getValue();
10 | }
11 |
--------------------------------------------------------------------------------
/base/src/main/java/com/apple/images/BaseImageLoadingListener.java:
--------------------------------------------------------------------------------
1 | package com.apple.images;
2 |
3 | import android.graphics.Bitmap;
4 | import android.view.View;
5 |
6 | /**
7 | * Created by apple_hsp on 15/12/2.
8 | * 图片组件事件提炼解耦
9 | */
10 | public interface BaseImageLoadingListener {
11 | /**
12 | * Is called when image loading task was started
13 | *
14 | * @param imageUri Loading image URI
15 | * @param view View for image
16 | */
17 | void onLoadingStarted(String imageUri, View view);
18 |
19 | /**
20 | * Is called when an error was occurred during image loading
21 | *
22 | * @param imageUri Loading image URI
23 | * @param view View for image. Can be null.
24 | * @param failReason why image
25 | * loading was failed
26 | */
27 | void onLoadingFailed(String imageUri, View view, int failReason);
28 |
29 | /**
30 | * Is called when image is loaded successfully (and displayed in View if one was specified)
31 | *
32 | * @param imageUri Loaded image URI
33 | * @param view View for image. Can be null.
34 | * @param loadedImage Bitmap of loaded and decoded image
35 | */
36 | void onLoadingComplete(String imageUri, View view, Bitmap loadedImage);
37 |
38 | /**
39 | * Is called when image loading task was cancelled because View for image was reused in newer task
40 | *
41 | * @param imageUri Loading image URI
42 | * @param view View for image. Can be null.
43 | */
44 | void onLoadingCancelled(String imageUri, View view);
45 | }
46 |
--------------------------------------------------------------------------------
/base/src/main/java/com/apple/images/BaseImageProgressListener.java:
--------------------------------------------------------------------------------
1 | package com.apple.images;
2 |
3 | import android.view.View;
4 |
5 | /**
6 | * Created by apple_hsp on 15/12/2.
7 | */
8 | public interface BaseImageProgressListener {
9 | /**
10 | * Is called when image loading progress changed.
11 | *
12 | * @param imageUri Image URI
13 | * @param view View for image. Can be null.
14 | * @param current Downloaded size in bytes
15 | * @param total Total size in bytes
16 | */
17 | void onProgressUpdate(String imageUri, View view, int current, int total);
18 | }
19 |
--------------------------------------------------------------------------------
/base/src/main/java/com/apple/images/BaseImages.java:
--------------------------------------------------------------------------------
1 | package com.apple.images;
2 |
3 | import android.graphics.Bitmap;
4 | import android.widget.ImageView;
5 |
6 | /*******************************************************************************
7 | *
8 | * 图片库结构解耦
9 | * 公共扩张借口
10 | * 作用任何一个图片组件可以继承并扩展
11 | *
12 | *******************************************************************************/
13 | public interface BaseImages{
14 |
15 | /**
16 | *
17 | * @param uri Image URI (i.e. "http://site.com/image.png", "file:///mnt/sdcard/image.png")
18 | * @param imageView {@link ImageView} which should display image
19 | * @throws IllegalArgumentException if passed imageView is null
20 | */
21 | public void displayImage(String uri, ImageView imageView);
22 |
23 | /**
24 | * Adds display image task to execution pool. Image will be set to ImageView when it's turn.
25 | * @param uri Image URI (i.e. "http://site.com/image.png", "file:///mnt/sdcard/image.png")
26 | * @param imageView {@link ImageView} which should display image
27 | * @param options {@linkplain AppImageOptions} for image
28 | * decoding and displaying. If null - default display image options
29 | * will be used.
30 | * @throws IllegalArgumentException if passed imageView is null
31 | */
32 | void displayImage(String uri, ImageView imageView, AppImageOptions options);
33 |
34 | /**
35 | *
36 | * @param uri Image URI (i.e. "http://site.com/image.png", "file:///mnt/sdcard/image.png")
37 | * @param imageView {@link ImageView} which should display image
38 | * @param listener {@linkplain BaseImageLoadingListener Listener} for image loading process. Listener fires events on
39 | * UI thread if this method is called on UI thread.
40 | * @throws IllegalArgumentException if passed imageView is null
41 | */
42 | void displayImage(String uri, ImageView imageView, AppImageOptions options, BaseImageLoadingListener listener);
43 | /**
44 | * Adds load image task to execution pool. Image will be returned with
45 | * @param ( "http://site.com/image.png", "file:///mnt/sdcard/image.png")
46 | * @param {@linkplain BaseImageLoadingListener Listener} for image loading process. Listener fires events on UI
47 | * thread if this method is called on UI thread.
48 | */
49 | void loadImage(String uri, AppImageOptions options, BaseImageLoadingListener listener);
50 |
51 | void loadImage(String uri, BaseImageLoadingListener listener);
52 | Bitmap loadImage(String uri);
53 | void initImagesHelper();
54 | long getImageSize();
55 | void clearImages();
56 | }
57 |
--------------------------------------------------------------------------------
/base/src/main/java/com/apple/routable/BuildConfig.java:
--------------------------------------------------------------------------------
1 | package com.apple.routable;
2 |
3 | /**
4 | * Created by apple_hsp on 17/6/19.
5 | */
6 |
7 | public class BuildConfig {
8 | public static final boolean DEBUG = false;
9 | public static final String APPLICATION_ID = "com.wj.uiroutable";
10 | public static final String BUILD_TYPE = "release";
11 | public static final String FLAVOR = "";
12 | public static final int VERSION_CODE = -1;
13 | public static final String VERSION_NAME = "";
14 |
15 | public BuildConfig() {
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/base/src/main/java/com/apple/routable/IRouterAction.java:
--------------------------------------------------------------------------------
1 | package com.apple.routable;
2 |
3 | import android.app.Activity;
4 | import android.content.Context;
5 |
6 | import com.apple.routable.model.RouterOptions;
7 |
8 | import java.util.List;
9 | import java.util.Map;
10 |
11 | /**
12 | * Created by apple_hsp on 17/6/19.
13 | */
14 |
15 | public interface IRouterAction {
16 | void openExternal(String var1);
17 |
18 | void open(String var1);
19 |
20 | void open(String var1, boolean var2);
21 |
22 | void open(String var1, Map var2);
23 |
24 | void open(String var1, Map var2, boolean var3);
25 |
26 | Context currentContext();
27 |
28 | void close();
29 |
30 | void close(boolean var1);
31 |
32 | void map(String var1, IRouterCallback var2);
33 |
34 | void maps(List var1, IRouterCallback var2);
35 |
36 | void map(String var1, IRouterCallback var2, RouterOptions var3);
37 |
38 | void maps(List var1, IRouterCallback var2, RouterOptions var3);
39 |
40 | void map(String var1, Class extends Activity> var2);
41 |
42 | void maps(List var1, Class extends Activity> var2);
43 |
44 | void map(String var1, Class extends Activity> var2, RouterOptions var3);
45 |
46 | void maps(List var1, Class extends Activity> var2, RouterOptions var3);
47 |
48 | }
49 |
--------------------------------------------------------------------------------
/base/src/main/java/com/apple/routable/IRouterCallback.java:
--------------------------------------------------------------------------------
1 | package com.apple.routable;
2 |
3 | import java.util.Map;
4 |
5 | /**
6 | * Created by apple_hsp on 17/6/19.
7 | */
8 |
9 | public interface IRouterCallback {
10 | void callback(String var1, Map var2);
11 | }
12 |
--------------------------------------------------------------------------------
/base/src/main/java/com/apple/routable/IRouterRegister.java:
--------------------------------------------------------------------------------
1 | package com.apple.routable;
2 |
3 | import android.app.Activity;
4 |
5 | /**
6 | * Created by apple_hsp on 17/6/19.
7 | */
8 |
9 | public interface IRouterRegister {
10 | void register(Activity var1);
11 | }
12 |
--------------------------------------------------------------------------------
/base/src/main/java/com/apple/routable/RouterConstant.java:
--------------------------------------------------------------------------------
1 | package com.apple.routable;
2 |
3 | /**
4 | * Created by apple_hsp on 17/6/19.
5 | */
6 |
7 | public class RouterConstant {
8 | public static final String WJ_ROUTER_INTENT_FLAG = "WJ_ROUTER_INTENT_FLAG";
9 | public static final String WJ_ROUTER_ACTIVITY_TITLE = "WJ_ROUTER_TITLE";
10 | public static final String WJ_ROUTER_URL_KEY = "WJ_OPEN_URL";
11 | public static final String WJ_ROUTER_PARAMS_KEY = "WJ_ROUTER_PARAMS";
12 | public static final String WJ_ROUTER_ACTIVITY_CLOSE_ANIMATE_KEY = "WJ_ROUTER_ACTIVITY_CLOSE_ANIMATE";
13 |
14 | public RouterConstant() {
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/base/src/main/java/com/apple/routable/exception/IIegaURLException.java:
--------------------------------------------------------------------------------
1 | package com.apple.routable.exception;
2 |
3 | /**
4 | * Created by apple_hsp on 17/6/19.
5 | */
6 |
7 | public class IIegaURLException extends RuntimeException{
8 | public IIegaURLException() {
9 | }
10 |
11 | public IIegaURLException(String message) {
12 | super(message);
13 | }
14 |
15 | public IIegaURLException(String message, Throwable cause) {
16 | super(message, cause);
17 | }
18 |
19 | }
20 |
--------------------------------------------------------------------------------
/base/src/main/java/com/apple/routable/model/Animate.java:
--------------------------------------------------------------------------------
1 | package com.apple.routable.model;
2 |
3 | import com.market.R;
4 |
5 | /**
6 | * Created by apple_hsp on 17/6/19.
7 | */
8 |
9 | public enum Animate {
10 | NONE,
11 | PUSH(R.anim.wj_push_open, R.anim.wj_push_close),
12 | MODAL(R.anim.wj_modal_open, R.anim.wj_modal_close);
13 |
14 | private int openAnimValue;
15 | private int closeAnimValue;
16 |
17 | private Animate(int openAnimValue, int closeAnimValue) {
18 | this.openAnimValue = openAnimValue;
19 | this.closeAnimValue = closeAnimValue;
20 | }
21 |
22 | private Animate() {
23 | }
24 |
25 | public int getOpenAnimValue() {
26 | return this.openAnimValue;
27 | }
28 |
29 | public int getCloseAnimValue() {
30 | return this.closeAnimValue;
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/base/src/main/java/com/apple/routable/model/RouterOptions.java:
--------------------------------------------------------------------------------
1 | package com.apple.routable.model;
2 |
3 | import android.app.Activity;
4 |
5 | import com.apple.routable.IRouterCallback;
6 |
7 | import java.util.Map;
8 |
9 | /**
10 | * Created by apple_hsp on 17/6/19.
11 | */
12 |
13 | public class RouterOptions {
14 | private Animate animate;
15 | private Map defaultParams;
16 | private Class extends Activity> openClass;
17 | private IRouterCallback routerCallback;
18 |
19 | private RouterOptions() {
20 | this.animate = Animate.NONE;
21 | }
22 |
23 | public void setAnimate(Animate animate) {
24 | this.animate = animate;
25 | }
26 |
27 | public void setDefaultParams(Map defaultParams) {
28 | this.defaultParams = defaultParams;
29 | }
30 |
31 | public void setOpenClass(Class extends Activity> openClass) {
32 | this.openClass = openClass;
33 | }
34 |
35 | public void setRouterCallback(IRouterCallback routerCallback) {
36 | this.routerCallback = routerCallback;
37 | }
38 |
39 | public Animate getAnimate() {
40 | return this.animate;
41 | }
42 |
43 | public Map getDefaultParams() {
44 | return this.defaultParams;
45 | }
46 |
47 | public Class extends Activity> getOpenClass() {
48 | return this.openClass;
49 | }
50 |
51 | public IRouterCallback getRouterCallback() {
52 | return this.routerCallback;
53 | }
54 |
55 | public static RouterOptions routerOptions() {
56 | RouterOptions routerOptions = new RouterOptions();
57 | return routerOptions;
58 | }
59 |
60 | public static RouterOptions routerOptionsAsModal() {
61 | RouterOptions routerOptions = new RouterOptions();
62 | routerOptions.animate = Animate.MODAL;
63 | return routerOptions;
64 | }
65 |
66 | public static RouterOptions routerOptionsForDefaultParams(Map defaultParams) {
67 | RouterOptions routerOptions = new RouterOptions();
68 | routerOptions.defaultParams = defaultParams;
69 | return routerOptions;
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/base/src/main/java/com/apple/routable/model/RouterParams.java:
--------------------------------------------------------------------------------
1 | package com.apple.routable.model;
2 |
3 | import java.util.HashMap;
4 | import java.util.Map;
5 |
6 | /**
7 | * Created by apple_hsp on 17/6/19.
8 | */
9 |
10 | public class RouterParams {
11 | private RouterOptions routerOptions;
12 | private Map openParams;
13 | private Map extraParams;
14 | private String url;
15 |
16 | public String getUrl() {
17 | return this.url;
18 | }
19 |
20 | public RouterParams(String url, RouterOptions routerOptions, Map openParams, Map extraParams) {
21 | this.url = url;
22 | this.routerOptions = routerOptions;
23 | this.openParams = openParams;
24 | this.extraParams = extraParams;
25 | }
26 |
27 | public Map getAllParams() {
28 | HashMap result = new HashMap();
29 | if(null != this.openParams && this.openParams.size() > 0) {
30 | result.putAll(this.openParams);
31 | }
32 |
33 | if(null != this.extraParams && this.extraParams.size() > 0) {
34 | result.putAll(this.extraParams);
35 | }
36 |
37 | if(null != this.url) {
38 | result.put("WJ_OPEN_URL", this.url);
39 | }
40 |
41 | return result;
42 | }
43 |
44 | public RouterOptions getRouterOptions() {
45 | return this.routerOptions;
46 | }
47 |
48 | public void setRouterOptions(RouterOptions routerOptions) {
49 | this.routerOptions = routerOptions;
50 | }
51 |
52 | public Map getOpenParams() {
53 | return this.openParams;
54 | }
55 |
56 | public void setOpenParams(Map openParams) {
57 | this.openParams = openParams;
58 | }
59 |
60 | public Map getExtraParams() {
61 | return this.extraParams;
62 | }
63 |
64 | public void setExtraParams(Map extraParams) {
65 | this.extraParams = extraParams;
66 | }
67 |
68 | }
69 |
--------------------------------------------------------------------------------
/base/src/main/java/com/apple/tool/DensityUtility.java:
--------------------------------------------------------------------------------
1 | package com.apple.tool;
2 |
3 | /**
4 | * Created by HUANG on 14-6-27.
5 | * 像素和密度的关系
6 | */
7 |
8 | import android.content.Context;
9 |
10 | public class DensityUtility {
11 |
12 | /**
13 | * 根据手机的分辨率从 dp 的单位 转成为 px(像素)
14 | */
15 | public static int dip2px(Context context, float dpValue) {
16 | final float scale = context.getResources().getDisplayMetrics().density;
17 | return (int) (dpValue * scale + 0.5f);
18 | }
19 |
20 | /**
21 | * 根据手机的分辨率从 px(像素) 的单位 转成为 dp
22 | */
23 | public static int px2dip(Context context, float pxValue) {
24 | final float scale = context.getResources().getDisplayMetrics().density;
25 | return (int) (pxValue / scale + 0.5f);
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/base/src/main/java/com/apple/tool/GenericsUtils.java:
--------------------------------------------------------------------------------
1 | package com.apple.tool;
2 |
3 | import java.lang.reflect.ParameterizedType;
4 | import java.lang.reflect.Type;
5 |
6 | /**
7 | *
8 | * 泛型工具
9 | *
10 | * Created by 吴云海 on 17/4/6.
11 | */
12 |
13 | public final class GenericsUtils {
14 |
15 | private GenericsUtils() {
16 | }
17 |
18 | public static Class getSuperClassGenricType(Class clazz) {
19 | return getSuperClassGenricType(clazz, 0);
20 | }
21 |
22 | public static Class getSuperClassGenricType(Class clazz, int index) {
23 | Type genType = clazz.getGenericSuperclass();
24 | if(!(genType instanceof ParameterizedType)) {
25 | return Object.class;
26 | } else {
27 | Type[] params = ((ParameterizedType)genType).getActualTypeArguments();
28 | return index < params.length && index >= 0?(!(params[index] instanceof Class)?Object.class:(Class)params[index]):Object.class;
29 | }
30 | }
31 |
32 | public static Class getGenericInterfaceGenricType(Class clazz) {
33 | return getGenericInterfaceGenricType(clazz, (Class)null, 0);
34 | }
35 |
36 | public static Class getGenericInterfaceGenricType(Class clazz, Class interfaceClass, int index) {
37 | Type[] types = clazz.getGenericInterfaces();
38 | Type[] var4 = types;
39 | int var5 = types.length;
40 |
41 | for(int var6 = 0; var6 < var5; ++var6) {
42 | Type t = var4[var6];
43 | if(!(t instanceof ParameterizedType)) {
44 | return Object.class;
45 | }
46 |
47 | if(null == interfaceClass || ((ParameterizedType)t).getRawType() == interfaceClass) {
48 | Type[] params = ((ParameterizedType)t).getActualTypeArguments();
49 | return index < params.length && index >= 0?(!(params[index] instanceof Class)?Object.class:(Class)params[index]):Object.class;
50 | }
51 | }
52 |
53 | return Object.class;
54 | }
55 |
56 | }
57 |
--------------------------------------------------------------------------------
/base/src/main/java/com/apple/tool/LoadingDialog.java:
--------------------------------------------------------------------------------
1 | package com.apple.tool;
2 |
3 | import android.app.Dialog;
4 | import android.content.Context;
5 | import android.os.Bundle;
6 |
7 | import com.market.R;
8 |
9 |
10 | /**
11 | * Created by zhangliang on 16/4/21. 加载Dialog
12 | */
13 | public class LoadingDialog extends Dialog {
14 |
15 |
16 |
17 | public LoadingDialog(Context context) {
18 | super(context, R.style.loading);
19 | }
20 |
21 | protected LoadingDialog(Context context, boolean cancelable, OnCancelListener cancelListener) {
22 | super(context, cancelable, cancelListener);
23 | }
24 |
25 | @Override
26 | protected void onCreate(Bundle savedInstanceState) {
27 | super.onCreate(savedInstanceState);
28 | setContentView(R.layout.loading);
29 | this.setCanceledOnTouchOutside(false);
30 | }
31 |
32 |
33 |
34 | @Override
35 | protected void onStop() {
36 | super.onStop();
37 | this.dismiss();
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/base/src/main/java/com/apple/tool/MD5Util.java:
--------------------------------------------------------------------------------
1 | package com.apple.tool;
2 |
3 | import java.security.MessageDigest;
4 | import java.security.NoSuchAlgorithmException;
5 |
6 | public class MD5Util {
7 |
8 | private static MessageDigest sMd5MessageDigest;
9 | private static StringBuilder sStringBuilder;
10 |
11 | static {
12 | try {
13 | sMd5MessageDigest = MessageDigest.getInstance("MD5");
14 | } catch (NoSuchAlgorithmException e) {
15 | }
16 | sStringBuilder = new StringBuilder();
17 | }
18 |
19 | private MD5Util() {
20 | }
21 |
22 | public static String md5(String s) {
23 |
24 | sMd5MessageDigest.reset();
25 | sMd5MessageDigest.update(s.getBytes());
26 |
27 | byte digest[] = sMd5MessageDigest.digest();
28 |
29 | sStringBuilder.setLength(0);
30 | for (int i = 0; i < digest.length; i++) {
31 | final int b = digest[i] & 255;
32 | if (b < 16) {
33 | sStringBuilder.append('0');
34 | }
35 | sStringBuilder.append(Integer.toHexString(b));
36 | }
37 |
38 | return sStringBuilder.toString();
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/base/src/main/java/com/apple/tool/SDKVersionUtils.java:
--------------------------------------------------------------------------------
1 | package com.apple.tool;
2 |
3 | import android.os.Build;
4 |
5 | /**
6 | * @author hao.xiong
7 | * @version 1.0.0
8 | */
9 | public class SDKVersionUtils {
10 |
11 | /**
12 | * hasEclairMR1
13 | * @return true false
14 | */
15 | public static boolean hasEclairMR1() {
16 | return Build.VERSION.SDK_INT >= Build.VERSION_CODES.ECLAIR_MR1;
17 | }
18 |
19 |
20 | /**
21 | * hasForyo
22 | * @return true false
23 | */
24 | public static boolean hasFroyo() {
25 | return Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO;
26 | }
27 |
28 | /**
29 | * hasGingerbread
30 | * @return true false
31 | */
32 | public static boolean hasGingerbread() {
33 | return Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD;
34 | }
35 |
36 | /**
37 | * hasHoneycomb
38 | * @return true false
39 | */
40 | public static boolean hasHoneycomb() {
41 | return Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB;
42 | }
43 |
44 | /**
45 | * hasHoneycombMR1
46 | * @return true false
47 | */
48 | public static boolean hasHoneycombMR1() {
49 | return Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR1;
50 | }
51 |
52 | /**
53 | * hasHoneycombMR2
54 | * @return true false
55 | */
56 | public static boolean hasHoneycombMR2() {
57 | return Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2;
58 | }
59 |
60 | /**
61 | * hasIceCreamSandwich
62 | * @return true false
63 | */
64 | public static boolean hasIceCreamSandwich() {
65 | return Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH;
66 | }
67 |
68 | /**
69 | * hasJellyBean
70 | * @return true false
71 | */
72 | public static boolean hasJellyBean() {
73 | return Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN;
74 | }
75 |
76 | private static final int JELLY_BEAN_MR1 = 17; // Build.VERSION_CODES.JELLY_BEAN_MR1
77 | /**
78 | * 4.2以上
79 | * @return true false
80 | */
81 | public static boolean hasJellyBeanMR1() {
82 | return Build.VERSION.SDK_INT >= JELLY_BEAN_MR1;
83 | }
84 |
85 | private static final int JELLY_BEAN_MR2 = 18;
86 |
87 | /**
88 | * 4.3及以上
89 | * @return 4.3及以上
90 | */
91 | public static boolean hasJellyBeanMR2() {
92 | return Build.VERSION.SDK_INT >= JELLY_BEAN_MR2;
93 | }
94 |
95 | private static final int KITKAT = 19;
96 |
97 | /**
98 | * 4.4及以上
99 | * @return 4.4及以上
100 | */
101 | public static boolean hasKitKat() {
102 | return Build.VERSION.SDK_INT >= KITKAT;
103 | }
104 | }
105 |
--------------------------------------------------------------------------------
/base/src/main/java/com/apple/tool/SharedPreferencesMgr.java:
--------------------------------------------------------------------------------
1 | package com.apple.tool;
2 |
3 |
4 | import android.content.Context;
5 | import android.content.SharedPreferences;
6 |
7 | public class SharedPreferencesMgr {
8 |
9 | private static Context context;
10 | private static SharedPreferences sPrefs ;
11 |
12 | private SharedPreferencesMgr(Context context, String fileName)
13 | {
14 | this.context=context;
15 | sPrefs= context.getSharedPreferences(
16 | fileName, Context.MODE_PRIVATE );
17 | }
18 |
19 | public static void init(Context context,String fileName)
20 | {
21 | new SharedPreferencesMgr(context,fileName);
22 | }
23 | public static String fileName ;
24 |
25 | public static int getInt(String key,int defaultValue)
26 | {
27 | return sPrefs.getInt(key, defaultValue);
28 | }
29 | public static void setInt(String key,int value) {
30 | sPrefs.edit().putInt(key, value).commit();
31 | }
32 | public static boolean getBoolean(String key,boolean defaultValue)
33 | {
34 | return sPrefs.getBoolean(key, defaultValue);
35 | }
36 | public static void setBoolean(String key,boolean value) {
37 | sPrefs.edit().putBoolean(key, value).commit();
38 | }
39 |
40 | public static String getString(String key,String defaultValue)
41 | {
42 | if(sPrefs ==null)
43 | return null;
44 | return sPrefs.getString(key, defaultValue);
45 | }
46 |
47 | public static void setString(String key,String value) {
48 | if(sPrefs ==null)
49 | return ;
50 | sPrefs.edit().putString(key, value).commit();
51 | }
52 |
53 | public static void setLong(String key,long value) {
54 | if(sPrefs ==null)
55 | return ;
56 | sPrefs.edit().putLong(key, value).commit();
57 | }
58 |
59 | public static long getLong(String key,long value){
60 | return sPrefs.getLong(key,value);
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/base/src/main/java/com/apple/tool/Toast.java:
--------------------------------------------------------------------------------
1 | package com.apple.tool;
2 |
3 | import android.content.Context;
4 | import android.os.Handler;
5 | import android.view.Gravity;
6 |
7 | public abstract class Toast {
8 | public static final int LENGTH_SHORT = android.widget.Toast.LENGTH_SHORT;
9 | public static final int LENGTH_LONG = android.widget.Toast.LENGTH_LONG;
10 |
11 | private static android.widget.Toast toast;
12 | private static Handler handler = new Handler();
13 |
14 | private static Runnable run = new Runnable() {
15 | public void run() {
16 | toast.cancel();
17 | }
18 | };
19 |
20 | private static void toast(Context ctx, CharSequence msg, int duration) {
21 | handler.removeCallbacks(run);
22 | // handler的duration不能直接对应Toast的常量时长,在此针对Toast的常量相应定义时长
23 | switch (duration) {
24 | case LENGTH_SHORT:// Toast.LENGTH_SHORT值为0,对应的持续时间大概为1s
25 | duration = 1000;
26 | break;
27 | case LENGTH_LONG:// Toast.LENGTH_LONG值为1,对应的持续时间大概为3s
28 | duration = 3000;
29 | break;
30 | default:
31 | break;
32 | }
33 | if (null != toast) {
34 | toast.setText(msg);
35 | } else {
36 | toast = android.widget.Toast.makeText(ctx, msg, duration);
37 | toast.setGravity(Gravity.CENTER, 0, 0);
38 | }
39 | handler.postDelayed(run, duration);
40 | toast.show();
41 | }
42 |
43 | /**
44 | * 弹出Toast
45 | *
46 | * @param ctx
47 | * 弹出Toast的上下文
48 | * @param msg
49 | * 弹出Toast的内容
50 | * @param duration
51 | * 弹出Toast的持续时间
52 | */
53 | public static void show(Context ctx, CharSequence msg, int duration)
54 | throws NullPointerException {
55 | if (null == ctx) {
56 | throw new NullPointerException("The ctx is null!");
57 | }
58 | if (0 > duration) {
59 | duration = LENGTH_SHORT;
60 | }
61 | toast(ctx, msg, duration);
62 | }
63 |
64 | /**
65 | * 弹出Toast
66 | *
67 | * @param ctx
68 | * 弹出Toast的上下文
69 | * @param resId
70 | * 弹出Toast的内容的资源ID
71 | * @param duration
72 | * 弹出Toast的持续时间
73 | */
74 | public static void show(Context ctx, int resId, int duration)
75 | throws NullPointerException {
76 | if (null == ctx) {
77 | throw new NullPointerException("The ctx is null!");
78 | }
79 | if (0 > duration) {
80 | duration = LENGTH_SHORT;
81 | }
82 | toast(ctx, ctx.getResources().getString(resId), duration);
83 | }
84 |
85 | public static void getToast(String msg, Context c) {
86 | show(c, msg, 1);
87 | }
88 |
89 | }
90 |
--------------------------------------------------------------------------------
/base/src/main/java/com/apple/tool/UserPreferencesMgr.java:
--------------------------------------------------------------------------------
1 | package com.apple.tool;
2 |
3 |
4 | import android.content.Context;
5 | import android.content.SharedPreferences;
6 |
7 | public class UserPreferencesMgr {
8 |
9 | private static Context context;
10 | private static SharedPreferences sPrefs ;
11 |
12 | private UserPreferencesMgr(Context context, String fileName)
13 | {
14 | this.context=context;
15 | sPrefs= context.getSharedPreferences(
16 | fileName, Context.MODE_PRIVATE );
17 | }
18 |
19 | public static void init(Context context,String fileName)
20 | {
21 | new UserPreferencesMgr(context,fileName);
22 | }
23 | public static String fileName ;
24 |
25 | public static int getInt(String key,int defaultValue)
26 | {
27 | return sPrefs.getInt(key, defaultValue);
28 | }
29 | public static void setInt(String key,int value) {
30 | sPrefs.edit().putInt(key, value).commit();
31 | }
32 | public static boolean getBoolean(String key,boolean defaultValue)
33 | {
34 | return sPrefs.getBoolean(key, defaultValue);
35 | }
36 | public static void setBoolean(String key,boolean value) {
37 | sPrefs.edit().putBoolean(key, value).commit();
38 | }
39 |
40 | public static String getString(String key,String defaultValue)
41 | {
42 | if(sPrefs ==null)
43 | return null;
44 | return sPrefs.getString(key, defaultValue);
45 | }
46 |
47 | public static void setString(String key,String value) {
48 | if(sPrefs ==null)
49 | return ;
50 | sPrefs.edit().putString(key, value).commit();
51 | }
52 |
53 | public static void setLong(String key,long value) {
54 | if(sPrefs ==null)
55 | return ;
56 | sPrefs.edit().putLong(key, value).commit();
57 | }
58 |
59 |
60 | public static void clearData(){
61 | if(sPrefs ==null)
62 | return ;
63 | sPrefs.edit().clear().apply();
64 | }
65 |
66 | public static long getLong(String key,long value){
67 | return sPrefs.getLong(key,value);
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/base/src/main/java/com/apple/tool/Utility.java:
--------------------------------------------------------------------------------
1 | package com.apple.tool;
2 |
3 | import android.app.Dialog;
4 | import android.content.Context;
5 | import android.content.pm.ApplicationInfo;
6 | import android.content.pm.PackageManager;
7 | import android.widget.EditText;
8 |
9 |
10 | /**
11 | * Created by zhangliang on 2016/11/1.
12 | */
13 | public class Utility {
14 | public static void getToast(String msg, Context c) {
15 | Toast.show(c, msg, 1);
16 | }
17 |
18 | public static Dialog getDialog(Context context) {
19 | return new LoadingDialog(context);
20 | }
21 |
22 | public static String getString(EditText s){
23 | return s.getText().toString().trim();
24 | }
25 |
26 | public static int getAppVersionId (Context context){
27 | int code=0;
28 | try {
29 | code= context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionCode;
30 | return code;
31 | }catch (Exception e){
32 | e.printStackTrace();
33 | }
34 | return code;
35 | }
36 | public static String decode(String unicodeStr) {
37 | if (unicodeStr == null) {
38 | return null;
39 | }
40 | StringBuffer retBuf = new StringBuffer();
41 | int maxLoop = unicodeStr.length();
42 | for (int i = 0; i < maxLoop; i++) {
43 | if (unicodeStr.charAt(i) == '\\') {
44 | if ((i < maxLoop - 5) && ((unicodeStr.charAt(i + 1) == 'u') || (unicodeStr.charAt(i + 1) == 'U')))
45 | try {
46 | retBuf.append((char) Integer.parseInt(unicodeStr.substring(i + 2, i + 6), 16));
47 | i += 5;
48 | } catch (NumberFormatException localNumberFormatException) {
49 | retBuf.append(unicodeStr.charAt(i));
50 | }
51 | else
52 | retBuf.append(unicodeStr.charAt(i));
53 | } else {
54 | retBuf.append(unicodeStr.charAt(i));
55 | }
56 | }
57 | return retBuf.toString();
58 | }
59 |
60 | /**
61 | * 根据手机的分辨率从 dp 的单位 转成为 px(像素)
62 | */
63 | public static int dip2px(Context context, float dpValue) {
64 | final float scale = context.getResources().getDisplayMetrics().density;
65 | return (int) (dpValue * scale + 0.5f);
66 | }
67 |
68 | /**
69 | * 根据手机的分辨率从 px(像素) 的单位 转成为 dp
70 | */
71 | public static int px2dip(Context context, float pxValue) {
72 | final float scale = context.getResources().getDisplayMetrics().density;
73 | return (int) (pxValue / scale + 0.5f);
74 | }
75 |
76 |
77 | public static String channelName(Context a){
78 | String msg="sdm";
79 | try {
80 | ApplicationInfo appInfo = a.getPackageManager()
81 | .getApplicationInfo(a.getPackageName(),
82 | PackageManager.GET_META_DATA);
83 | msg = appInfo.metaData.getString("UMENG_CHANNEL", "");
84 | }catch (Exception e){
85 | e.printStackTrace();
86 | }
87 |
88 | return msg;
89 |
90 |
91 | }
92 | public static String Stringinsert(String a, String s, int t) {
93 | return a.substring(0, t) + s + a.substring(t);
94 | }
95 | }
96 |
--------------------------------------------------------------------------------
/base/src/main/java/com/apple/tool/Validation.java:
--------------------------------------------------------------------------------
1 | package com.apple.tool;
2 |
3 | import java.util.regex.Matcher;
4 | import java.util.regex.Pattern;
5 |
6 | /**
7 | * Created by HUANG on 14-7-4.
8 | * 常用验证方式
9 | */
10 | public class Validation {
11 | /**
12 | * 手机号验证
13 | *
14 | * @param str
15 | * @return 验证通过返回true
16 | */
17 | public static boolean isMobilePhoneNumber(String str) {
18 | Pattern p;
19 | Matcher m;
20 | boolean b;
21 | p = Pattern.compile("^[1][3,4,5,7,8][0-9]{9}$"); // 验证手机号
22 | m = p.matcher(str);
23 | b = m.matches();
24 | return b;
25 | }
26 |
27 | public static boolean isNonEmptyString(String str) {
28 | return !"".equals(str.trim());
29 | }
30 |
31 | public static boolean isNonNull(Object obj) {
32 | return !(obj == null);
33 | }
34 |
35 | public static boolean isPassword(String str) {
36 | return str.length() >= 6;
37 | }
38 |
39 | public static boolean isVerificationCode(String str) {
40 | Pattern p;
41 | Matcher m;
42 | boolean b;
43 | p = Pattern.compile("^[0-9]{6}$"); //校验验证码
44 | m = p.matcher(str);
45 | b = m.matches();
46 | return b;
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/base/src/main/java/com/apple/uichoose/common/BaseFilter.java:
--------------------------------------------------------------------------------
1 | package com.apple.uichoose.common;
2 |
3 |
4 | /**
5 | * 路由跳转
6 | * 过滤器
7 | * @author hushaoping
8 | */
9 | public abstract class BaseFilter
10 | {
11 |
12 | public Class actionClass;
13 |
14 | public abstract boolean executeFilter(String url);
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/base/src/main/java/com/apple/uichoose/common/ChooseClient.java:
--------------------------------------------------------------------------------
1 | package com.apple.uichoose.common;
2 |
3 |
4 | import android.app.Activity;
5 |
6 | import com.apple.uichoose.impl.ChooseImpl;
7 | import com.apple.uichoose.listener.ChooseListener;
8 |
9 | import java.util.HashMap;
10 |
11 | /**
12 | * @author 胡少平
13 | */
14 | public class ChooseClient {
15 |
16 | //单例模式实现
17 | static ChooseClient baseClient = null;
18 |
19 | public static ChooseConf chooseConf;
20 |
21 | private HashMap paramData;
22 |
23 | private String url;
24 | private int requestCode = -1;
25 |
26 | public static ChooseClient getBaseClient() {
27 | if (baseClient == null) {
28 | synchronized (ChooseClient.class) {
29 | if (baseClient == null) {
30 | baseClient = new ChooseClient();
31 | }
32 | }
33 | }
34 | return baseClient;
35 | }
36 |
37 | public ChooseClient() {
38 | }
39 |
40 | private ChooseClient(Builder builder) {
41 | this.url = builder.url;
42 | this.requestCode = builder.requestCode;
43 | this.paramData=builder.paramData;
44 | }
45 |
46 |
47 | public HashMap getParamData() {
48 | return paramData;
49 | }
50 |
51 | public int getRequestCode() {
52 | return requestCode;
53 | }
54 |
55 | public String getUrl() {
56 | return url;
57 | }
58 |
59 | /**
60 | * 路由url配置
61 | */
62 | public synchronized void init(ChooseConf chooseConf) {
63 | if (chooseConf == null) {
64 | throw new IllegalArgumentException("");
65 | }
66 | this.chooseConf = chooseConf;
67 | }
68 |
69 |
70 | public static Builder newBuilder() {
71 | return new Builder();
72 | }
73 |
74 |
75 | /**
76 | * 路由控制器执行
77 | *
78 | * @BaseFilter 过滤器
79 | */
80 | public void execute(BaseFilter baseFilter) {
81 | ChooseImpl.getChooseImpl().openUrl(baseFilter, chooseConf, baseClient);
82 | }
83 |
84 |
85 | public static final class Builder {
86 |
87 | String url;
88 | int requestCode = -1;
89 |
90 | HashMap paramData;
91 |
92 | public Builder() {
93 | url = "";
94 | }
95 |
96 |
97 | /**
98 | * 设置路由传递数值
99 | *
100 | * @param parameter
101 | */
102 | public Builder setParameter(HashMap parameter) {
103 | this.paramData = parameter;
104 | return this;
105 | }
106 |
107 |
108 | /**
109 | * @param url
110 | * @return
111 | */
112 | public Builder url(String url) {
113 | if (url == null) throw new IllegalArgumentException("url ==null");
114 | if (url.trim().equals(""))
115 | throw new IllegalArgumentException("Url is empty.");
116 | this.url = url;
117 | return this;
118 | }
119 |
120 |
121 | /**
122 | * @param requestCode
123 | * @return
124 | */
125 | public Builder requestCode(int requestCode) {
126 | this.requestCode = requestCode;
127 | return this;
128 | }
129 |
130 |
131 | public ChooseClient build() {
132 | return new ChooseClient(this);
133 | }
134 |
135 |
136 | }
137 |
138 |
139 | }
140 |
--------------------------------------------------------------------------------
/base/src/main/java/com/apple/uichoose/common/ChooseConf.java:
--------------------------------------------------------------------------------
1 | package com.apple.uichoose.common;
2 |
3 |
4 | import android.content.Context;
5 |
6 | /**
7 | * 定义路由配置类
8 | * @author hushaoping
9 | */
10 | public class ChooseConf {
11 |
12 | private final ConfFactory confFactory;
13 | private final Context context;
14 |
15 |
16 |
17 | private ChooseConf(Builder builder) {
18 | this.confFactory=builder.confFactory;
19 | this.context=builder.mContext;
20 | }
21 |
22 |
23 | public Context getContext() {
24 | return context;
25 | }
26 |
27 | public ConfFactory getConfFactory() {
28 | return confFactory;
29 | }
30 |
31 |
32 |
33 | /**
34 | * Builder for {@link ChooseConf}
35 | * @author Sergey Tarasevich (nostra13[at]gmail[dot]com)
36 | */
37 | public static class Builder {
38 | private ConfFactory confFactory;
39 | private Context mContext;
40 | public Builder() {
41 | }
42 |
43 | /**
44 | * 路由配置
45 | * @param confFactory
46 | * @return
47 | */
48 | public Builder setConfFactory(ConfFactory confFactory) {
49 | this.confFactory = confFactory;
50 | return this;
51 | }
52 |
53 | public Builder setmContext(Context mContext) {
54 | this.mContext = mContext;
55 | return this;
56 | }
57 |
58 | /** Builds configured {@link ChooseConf} object */
59 | public ChooseConf build() {
60 | return new ChooseConf(this);
61 | }
62 | }
63 |
64 |
65 | }
66 |
--------------------------------------------------------------------------------
/base/src/main/java/com/apple/uichoose/common/ConfFactory.java:
--------------------------------------------------------------------------------
1 | package com.apple.uichoose.common;
2 |
3 | import java.util.HashMap;
4 |
5 | /**
6 | * 定义配置工厂
7 | * @author hushaoping
8 | */
9 | public abstract class ConfFactory
10 | {
11 |
12 | public HashMap factoryMap;
13 | protected ConfFactory() {
14 | }
15 | public abstract HashMap createFactory();
16 | }
17 |
--------------------------------------------------------------------------------
/base/src/main/java/com/apple/uichoose/impl/ChooseImpl.java:
--------------------------------------------------------------------------------
1 | package com.apple.uichoose.impl;
2 |
3 |
4 | import android.app.Activity;
5 | import android.content.Intent;
6 | import android.net.Uri;
7 | import android.os.Bundle;
8 |
9 |
10 | import com.apple.uichoose.common.BaseFilter;
11 | import com.apple.uichoose.common.ChooseClient;
12 | import com.apple.uichoose.common.ChooseConf;
13 | import com.apple.uichoose.listener.ChooseListener;
14 |
15 | import java.util.Iterator;
16 | import java.util.Set;
17 |
18 | /**
19 | * @author 胡少平
20 | */
21 | public class ChooseImpl {
22 |
23 | //单例模式实现
24 | public static ChooseImpl instance;
25 |
26 | public static ChooseImpl getChooseImpl() {
27 | if (instance == null) {
28 | synchronized (ChooseImpl.class) {
29 | if (instance == null) {
30 | instance = new ChooseImpl();
31 | }
32 | }
33 | }
34 | return instance;
35 | }
36 |
37 |
38 | public ChooseImpl() {
39 |
40 | }
41 |
42 |
43 | /**
44 | * 路由核心跳转逻辑
45 | */
46 | public void openUrl(BaseFilter baseFilter, ChooseConf chooseConf, ChooseClient chooseClient) {
47 | if (baseFilter != null) {
48 | if (baseFilter.executeFilter(chooseClient.getUrl())) {
49 | if (baseFilter.actionClass != null) {
50 | Intent intent = new Intent();
51 | intent.setClass(chooseConf.getContext(), baseFilter.actionClass);
52 | intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
53 | intent.putExtra("choose_data", chooseClient.getParamData());
54 | chooseConf.getContext().startActivity(intent);
55 | }
56 | }
57 | }
58 | }
59 |
60 |
61 | }
62 |
--------------------------------------------------------------------------------
/base/src/main/java/com/apple/uichoose/listener/ChooseListener.java:
--------------------------------------------------------------------------------
1 | package com.apple.uichoose.listener;
2 |
3 |
4 | /**
5 | * 路由控制器事件
6 | *
7 | * @author hushaoping
8 | */
9 | public interface ChooseListener {
10 | /**
11 | * 请求成功
12 | * @param url 路由地址
13 | * @param statue 是否跳转
14 | * 1:成功跳转
15 | * 2:跳转不了
16 | */
17 | abstract void success(String url, int statue);
18 | }
19 |
--------------------------------------------------------------------------------
/base/src/main/java/com/apple/web/IBridgeEngine.java:
--------------------------------------------------------------------------------
1 | package com.apple.web;
2 |
3 | import android.net.Uri;
4 |
5 | /**
6 | *
7 | */
8 | public interface IBridgeEngine extends IWebViewJavascriptBridge {
9 |
10 |
11 | /**
12 | * 是否为JS回调Scheme
13 | * @param url
14 | * @return
15 | */
16 | boolean isCorrectProcotocolScheme(Uri url);
17 |
18 | /**
19 | * 是否为初始化加载
20 | * @param url
21 | * @return
22 | */
23 | boolean isBridgeLoadedURL(Uri url);
24 |
25 | /**
26 | * 是否为获取消息url
27 | * @param url
28 | * @return
29 | */
30 | // boolean isQueueMessageURL(Uri url);
31 |
32 | /**
33 | * 注入JS引擎代码
34 | */
35 | void injectJavascriptFile();
36 |
37 | /**
38 | * 处理JS回调消息
39 | */
40 | void flushMessageQueue(String messageQueue);
41 |
42 | /**
43 | * 调度消息
44 | * @param msg
45 | */
46 | void dispatchMessage(IBridgeMessage msg);
47 | }
48 |
--------------------------------------------------------------------------------
/base/src/main/java/com/apple/web/IBridgeMessage.java:
--------------------------------------------------------------------------------
1 | package com.apple.web;
2 |
3 | /**
4 | *
5 | */
6 | public interface IBridgeMessage {
7 |
8 | /**
9 | * 回调id
10 | * @return
11 | */
12 | String callbackId();
13 |
14 | /**
15 | * 响应id
16 | * @return
17 | */
18 | String responseId();
19 |
20 | /**
21 | * 处理名称
22 | * @return
23 | */
24 | String handlerName();
25 |
26 | /**
27 | * 获取数据
28 | * @return
29 | */
30 | Object data();
31 |
32 | /**
33 | * 是否为回调
34 | * @return
35 | */
36 | boolean isCallback();
37 |
38 | /**
39 | * 是否为响应
40 | * @return
41 | */
42 | boolean isResponse();
43 |
44 | /**
45 | * 响应数据
46 | * @return
47 | */
48 | Object responseData();
49 | }
50 |
--------------------------------------------------------------------------------
/base/src/main/java/com/apple/web/IJSCallback.java:
--------------------------------------------------------------------------------
1 | package com.apple.web;
2 |
3 | /**
4 | *
5 | */
6 | public interface IJSCallback {
7 |
8 | /**
9 | * js执行结果
10 | * @param messageData 消息数据
11 | */
12 | void callback(String messageData);
13 |
14 | }
15 |
--------------------------------------------------------------------------------
/base/src/main/java/com/apple/web/IJSCommandExecuter.java:
--------------------------------------------------------------------------------
1 | package com.apple.web;
2 |
3 | /**
4 | *
5 | */
6 | public interface IJSCommandExecuter {
7 |
8 | /**
9 | * 执行JS命令
10 | * @param jsCommand
11 | */
12 | void evaluateJS(String jsCommand);
13 |
14 | /**
15 | * JS引擎代码
16 | * @return
17 | */
18 | String jsEngineCode();
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/base/src/main/java/com/apple/web/IRegisterHandler.java:
--------------------------------------------------------------------------------
1 | package com.apple.web;
2 |
3 | /**
4 | * Created by halayun on 16/6/25.
5 | */
6 | public interface IRegisterHandler {
7 |
8 | /**
9 | * 处理消息
10 | * @param data js传过来的参数
11 | * @param responseCallback 响应回调
12 | */
13 | void handler(Object data, IResponseCallback responseCallback);
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/base/src/main/java/com/apple/web/IResponseCallback.java:
--------------------------------------------------------------------------------
1 | package com.apple.web;
2 |
3 | /**
4 | *
5 | */
6 | public interface IResponseCallback {
7 |
8 | //回调数据
9 | void responseCallback(Object responseData);
10 |
11 | }
12 |
--------------------------------------------------------------------------------
/base/src/main/java/com/apple/web/IWebViewJavascriptBridge.java:
--------------------------------------------------------------------------------
1 | package com.apple.web;
2 |
3 | /**
4 | * WebView桥接接口
5 | */
6 | public interface IWebViewJavascriptBridge {
7 |
8 |
9 | /**
10 | * 接收JS调用
11 | * @param handlerName 函数名称
12 | * @param handler 处理器
13 | */
14 | void registerHandler(String handlerName, IRegisterHandler handler);
15 |
16 | /**
17 | * 调用JS
18 | * @param handlerName 函数名称
19 | */
20 | void callHandler(String handlerName);
21 |
22 | /**
23 | * 调用JS
24 | * @param handlerName 函数名称
25 | * @param callback 响应结果
26 | */
27 | void callHandler(String handlerName, IResponseCallback callback);
28 |
29 | /**
30 | * 调用JS
31 | * @param handlerName 函数名称
32 | * @param data 发送数据
33 | * @param callback 响应结果
34 | */
35 | void callHandler(String handlerName, Object data, IResponseCallback callback);
36 |
37 |
38 |
39 | }
40 |
--------------------------------------------------------------------------------
/base/src/main/java/com/apple/web/SimpleBridgeMessage.java:
--------------------------------------------------------------------------------
1 | package com.apple.web;
2 |
3 | /**
4 | *
5 | */
6 | public class SimpleBridgeMessage implements IBridgeMessage {
7 |
8 | /**
9 | * 回调id
10 | */
11 | private String callbackId;
12 |
13 | /**
14 | * 响应id
15 | */
16 | private String responseId;
17 |
18 | /**
19 | * 函数名称
20 | */
21 | private String handlerName;
22 |
23 | /**
24 | * 传输参数数据
25 | */
26 | private Object data;
27 |
28 | /**
29 | * 响应数据
30 | */
31 | private Object responseData;
32 |
33 | public void setCallbackId(String callbackId) {
34 | this.callbackId = callbackId;
35 | }
36 |
37 | public void setResponseId(String responseId) {
38 | this.responseId = responseId;
39 | }
40 |
41 | public void setData(Object data) {
42 | this.data = data;
43 | }
44 |
45 | public void setResponseData(Object responseData) {
46 | this.responseData = responseData;
47 | }
48 |
49 | public void setHandlerName(String handlerName) {
50 | this.handlerName = handlerName;
51 | }
52 |
53 | @Override
54 | public String callbackId() {
55 | return this.callbackId;
56 | }
57 |
58 | @Override
59 | public String responseId() {
60 | return this.responseId;
61 | }
62 |
63 | @Override
64 | public Object data() {
65 | return this.data;
66 | }
67 |
68 | @Override
69 | public boolean isCallback() {
70 | if (null != callbackId) return true;
71 | return false;
72 | }
73 |
74 | @Override
75 | public String handlerName() {
76 | return this.handlerName;
77 | }
78 |
79 | @Override
80 | public boolean isResponse() {
81 | if (null != responseId) return true;
82 | return false;
83 | }
84 |
85 | @Override
86 | public Object responseData() {
87 | return this.responseData;
88 | }
89 | }
90 |
--------------------------------------------------------------------------------
/base/src/main/res/anim/wj_modal_close.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
8 |
--------------------------------------------------------------------------------
/base/src/main/res/anim/wj_modal_open.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
8 |
--------------------------------------------------------------------------------
/base/src/main/res/anim/wj_push_close.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
5 |
6 |
--------------------------------------------------------------------------------
/base/src/main/res/anim/wj_push_open.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
5 |
--------------------------------------------------------------------------------
/base/src/main/res/drawable/indicator_lock_area.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/apple317/HttpClientUtils/ef18d39f0cef939d89be0fb07184addef83795ad/base/src/main/res/drawable/indicator_lock_area.png
--------------------------------------------------------------------------------
/base/src/main/res/drawable/lock.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/apple317/HttpClientUtils/ef18d39f0cef939d89be0fb07184addef83795ad/base/src/main/res/drawable/lock.png
--------------------------------------------------------------------------------
/base/src/main/res/layout/loading.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
15 |
16 |
--------------------------------------------------------------------------------
/base/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | base
3 |
4 |
--------------------------------------------------------------------------------
/base/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:2.2.3'
9 |
10 | // NOTE: Do not place your application dependencies here; they belong
11 | // in the individual module build.gradle files
12 | }
13 | }
14 |
15 | allprojects {
16 | repositories {
17 | jcenter()
18 | }
19 | }
20 |
21 | task clean(type: Delete) {
22 | delete rootProject.buildDir
23 | }
24 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/apple317/HttpClientUtils/ef18d39f0cef939d89be0fb07184addef83795ad/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Sun Apr 30 20:22:28 CST 2017
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':BaseProject'
2 | project(':BaseProject').projectDir = new File('base')
--------------------------------------------------------------------------------