zoukankan      html  css  js  c++  java
  • 我的第一个开源App(*开奖查询)

    源码:https://github.com/feimengwang/lottery

    这个App其实2年前就写好了,那时候是抓取的网页里面的内容,也没有用第三方开源
    框架,写的也比较乱,最近没事的时候发现360有接口,返回JSON数据,所以重写了一次,这次也有很多不足,正在修正中。。。。

    用到的第三方库
    compile 'com.google.code.gson:gson:2.6.2'
    compile 'io.reactivex:rxjava:1.1.0'
    compile 'io.reactivex:rxandroid:1.1.0'
    compile 'com.squareup.retrofit2:retrofit:2.0.0'
    compile 'com.squareup.retrofit2:adapter-rxjava:2.0.0'

    先上图片(图片有点大)



    读取网络数据用Rxjava+retrofit

    public interface LotteryService {
    
        @GET("qkaijiang?r=1458219747840")
        Observable<Lottery> geLastData360();
    
        @GET("qkj")
        Observable<LotteryDetail> getLotteryDetail(@Query("lotId") String lotId, @Query("issue") String issue);
        @GET("qkjlist")
        Observable<LotteryHistory> geLotteryHistory(@Query("lotId") String lotId, @Query("page") String page);
    }
    
     

    下面就是create个retrofit 来取得数据了

            retrofit = new Retrofit.Builder()
                    .baseUrl(LotteryConstant.RETROFIT_BASE_URL)
                    .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                    .addConverterFactory(GsonConverterFactory.create())
                    .client(client)
                    .build();
            service = retrofit.create(LotteryService.class);
            service.geLastData360()
                    .subscribeOn(Schedulers.io())
                    .observeOn(AndroidSchedulers.mainThread())
                    .map(new Func1<Lottery, List>() {
                        @Override
                        public List call(Lottery lottery) {
                            return getLotteryList(lottery);
                        }
                    }).subscribe(subscriber);
    
     

    其中遇到Toolbar的Overflow menu 没有图标,网上找了一些方案,但是不生效,最后简单重写了Toolbar,终于可以了

    public class LotteryToolbar  extends Toolbar{
        public LotteryToolbar(Context context) {
            super(context);
        }
    
        public LotteryToolbar(Context context, @Nullable AttributeSet attrs) {
            super(context, attrs);
        }
    
        public LotteryToolbar(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
            super(context, attrs, defStyleAttr);
        }
    
        @Override
        public void inflateMenu(@MenuRes int resId) {
            Menu m = getMenu();
            if(m!=null &&m.getClass()== MenuBuilder.class){
                try {
                    Method method = m.getClass().getDeclaredMethod("setOptionalIconsVisible",Boolean.TYPE);
                    method.setAccessible(true);
                    method.invoke(m,true);
                } catch (NoSuchMethodException e) {
                    e.printStackTrace();
                } catch (InvocationTargetException e) {
                    e.printStackTrace();
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                }
            }
    
            super.inflateMenu(resId);
        }
    }
    
     

    就写这么多吧,,,

    文章首次发布到http://www.jianshu.com/p/d0e964da8767

  • 相关阅读:
    Linux下批处理文件
    linux代码端启动终端
    ubuntu截图
    Ubuntu安装多个版本的Opencv
    Ubuntu双系统启动卡死
    Ubuntu14.04运行lsdslam与问题解决
    js懒加载
    公众号开发-获取用户信息
    ClipboardJS 复制文本功能
    css3 Gradient线性渐变详解
  • 原文地址:https://www.cnblogs.com/feimeng0530/p/5337151.html
Copyright © 2011-2022 走看看