Coder Social home page Coder Social logo

ponyexpress's Introduction

小马快递

前言

这是我第一个独立完成的项目,时隔多年又把它拿出来重构了一下代码。

简介

小马快递,您的好帮手。查询并跟踪快递,快递信息及时掌握。
支持全国100多家快递公司,支持扫码查询,智能识别快递公司。
附带生成二维码小工具,方便实用。体积小巧,无广告,无多余权限。

更新说明

v 2.0

  • 全新UI,高仿“支付宝-我的快递”
  • 新增智能识别快递公司
  • 新增扫一扫

v 1.5

  • 新增自动更新

v 1.4

  • 修复无法查询快递的问题
  • 支持Android 6.0
  • 支持运单备注
  • 优化单号扫描界面

下载地址

fir.im:http://fir.im/ponyexpress

项目

公开API

  • 快递查询:快递100(非公开,侵权删)

开源技术

关键代码

网络请求Volley+Gson

private void search() {
    GsonRequest<SearchResult> request = new GsonRequest<SearchResult>(Utils.formatSearchUrl(mSearchInfo),
            SearchResult.class, new Response.Listener<SearchResult>() {
        @Override
        public void onResponse(SearchResult searchResult) {
            Log.i(TAG, searchResult.getMessage());
            onSearch(searchResult);
        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError volleyError) {
            Log.e(TAG, volleyError.getMessage(), volleyError);
            onError();
        }
    }) {
        @Override
        public Map<String, String> getHeaders() throws AuthFailureError {
            Map<String, String> headers = new HashMap<>();
            headers.put(Constants.HEADER_REFERER, Constants.REFERER);
            return headers;
        }
    };
    request.setShouldCache(false);
    ExpressApplication.getInstance().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);
    }
}

截图

关于作者

简书:http://www.jianshu.com/users/3231579893ac
微博:http://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.

ponyexpress's People

Contributors

wangchenyan avatar

Watchers

James Cloos avatar tifancy avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.