小馬快遞
前言
這是我第一個(gè)獨(dú)立完成的項(xiàng)目歇僧,時(shí)隔多年又把它拿出來重構(gòu)了一下代碼敦姻。
- 項(xiàng)目地址:https://github.com/wangchenyan/ponyexpress
- 有問題請?zhí)酙ssues
- 如果喜歡耕蝉,歡迎Star宛徊!
簡介
小馬快遞佛嬉,您的好幫手。查詢并跟蹤快遞闸天,快遞信息及時(shí)掌握暖呕。
支持全國100多家快遞公司,支持掃碼查詢苞氮,智能識別快遞公司湾揽。
附帶生成二維碼小工具,方便實(shí)用笼吟。體積小巧库物,無廣告,無多余權(quán)限贷帮。
更新說明
v 2.0
- 全新UI戚揭,高仿“支付寶-我的快遞”
- 新增智能識別快遞公司
- 新增掃一掃
v 1.5
- 新增自動更新
v 1.4
- 修復(fù)無法查詢快遞的問題
- 支持Android 6.0
- 支持運(yùn)單備注
- 優(yōu)化單號掃描界面
下載地址
V2.1
https://github.com/wangchenyan/ponyexpress/releases/download/2.1/ponyexpress-2.1.apk
項(xiàng)目
公開API
- 快遞查詢:快遞100(非公開,侵權(quán)刪)
開源技術(shù)
關(guān)鍵代碼
網(wǎng)絡(luò)請求Volley + Gson
public static void query(String type, String postId, final HttpCallback<SearchResult> callback) {
String action = "/query";
Map<String, String> params = new HashMap<>(2);
params.put("type", type);
params.put("postid", postId);
String url = makeUrl(action, params);
GsonRequest<SearchResult> request = new GsonRequest<SearchResult>(url, SearchResult.class,
new Response.Listener<SearchResult>() {
@Override
public void onResponse(SearchResult searchResult) {
callback.onResponse(searchResult);
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError volleyError) {
callback.onError(volleyError);
}
}) {
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
Map<String, String> headers = new HashMap<>();
headers.put(HEADER_REFERER, BASE_URL);
return headers;
}
};
request.setShouldCache(false);
getRequestQueue().add(request);
}
封裝GsonRequest
public class GsonRequest<T> extends Request<T> {
private Class<T> mClass;
private Response.Listener<T> mListener;
private Gson mGson;
public GsonRequest(int method, String url, Class<T> clazz, Response.Listener<T> listener, Response.ErrorListener errorListener) {
super(method, url, errorListener);
mClass = clazz;
mListener = listener;
mGson = new Gson();
}
public GsonRequest(String url, Class<T> clazz, Response.Listener<T> listener, Response.ErrorListener errorListener) {
this(Method.GET, url, clazz, listener, errorListener);
}
@Override
protected Response<T> parseNetworkResponse(NetworkResponse response) {
String jsonString;
try {
jsonString = new String(response.data, HttpHeaderParser.parseCharset(response.headers));
return Response.success(mGson.fromJson(jsonString, mClass), HttpHeaderParser.parseCacheHeaders(response));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
return Response.error(new ParseError(e));
}
}
@Override
protected void deliverResponse(T response) {
mListener.onResponse(response);
}
}
截圖
關(guān)于作者
掘金:https://juejin.im/user/2313028193754168
微博:https://weibo.com/wangchenyan1993
License
Copyright 2016 wangchenyan
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.