这个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
publicinterfaceLotteryService{@GET("qkaijiangr=1458219747840")Observable
下面就是create个retrofit来取得数据了
retrofit=newRetrofit.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(newFunc1
其中遇到Toolbar的Overflowmenu没有图标,网上找了一些方案,但是不生效,最后简单重写了Toolbar,终于可以了
publicclassLotteryToolbarextendsToolbar{publicLotteryToolbar(Contextcontext){super(context);}publicLotteryToolbar(Contextcontext,@NullableAttributeSetattrs){super(context,attrs);}publicLotteryToolbar(Contextcontext,@NullableAttributeSetattrs,intdefStyleAttr){super(context,attrs,defStyleAttr);}@OverridepublicvoidinflateMenu(@MenuResintresId){Menum=getMenu();if(m!=null&&m.getClass()==MenuBuilder.class){try{Methodmethod=m.getClass().getDeclaredMethod("setOptionalIconsVisible",Boolean.TYPE);method.setAccessible(true);method.invoke(m,true);}catch(NoSuchMethodExceptione){e.printStackTrace();}catch(InvocationTargetExceptione){e.printStackTrace();}catch(IllegalAccessExceptione){e.printStackTrace();}}super.inflateMenu(resId);}}