android项目《刷刷手环》代码review

来源:互联网 发布:淘宝五金店铺描述 编辑:程序博客网 时间:2024/05/21 09:47

1.首先进入app判断是否第一次使用该app,如果是第一次则加载引导页(Viewpager实现) 否则加载点击打开链接默认欢迎页(可以延迟几秒钟)

2.进来弹出对话框  用的是Dialog   或者Popuwindow

3.弹出对话框   询问是否发送推送信息,用的是个推,个推android如何配合使用实现推送业务http://www.oschina.net/question/1782938_157021?sort=time

4.第一次进入页面实现遮盖效果,蒙层效果,定义一个BaseActivity  在onstart方法中添加引导页,怎么添加?做相应缓存判断该activity是否是第一次加载,然后用FrameLayout

FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT);guideImage.setLayoutParams(params);guideImage.setScaleType(ImageView.ScaleType.FIT_XY);guideImage.setImageResource(guideResourceId);guideImage.setOnClickListener(new View.OnClickListener() {    @Override    public void onClick(View v) {        frameLayout.removeView(guideImage);        MyPreferences.setIsGuided(getApplicationContext(), BaseActivity.this.getClass().getName());//设为已引导    }});frameLayout.addView(guideImage);//添加引导图片
 定义好这个类之后,所有activity都继承这个基类来实现 蒙层效果
5.定义一个include  title 布局文件通用,Activity+fragment的布局
6.自定义的控件












很多程序很多程序猿可能会和我一样,当公司开发项目时,完成功能是第一位,从而总会出现这样的话,这里应该可以写的更好,下版本再说。最近项目接近尾声,感觉需要重新审视一下这个项目,这应该是提升自己和优化项目的最好的办法之一。
废话结束。。。。

一、分享

方案一:直接使用友盟分享 


http://dev.umeng.com/social/android/quick-integration





方案二:分别调用各个平台的sdk



 1、分享朋友圈和微信
private void regToWx() {api = WXAPIFactory.createWXAPI(this, APP_ID, true);// 获得IWXAPI实例api.registerApp(APP_ID);}//分享微信private void sendReq(boolean ryan) {regToWx();Bitmap bmp = captureWebView(wb);WXImageObject imgObj = new WXImageObject(bmp);WXMediaMessage msg = new WXMediaMessage();msg.mediaObject = imgObj;Bitmap thumbBmp = Bitmap.createScaledBitmap(bmp, 80, THUMB_SIZE, true);bmp.recycle();msg.thumbData = Util.bmpToByteArray(thumbBmp, true);SendMessageToWX.Req req = new SendMessageToWX.Req();req.transaction = getTransaction();req.message = msg;req.scene = SendMessageToWX.Req.WXSceneSession;api.sendReq(req);}//分享朋友圈private void sendReqa() {regToWx();Bitmap bmp = captureWebView(wb);WXImageObject imgObj = new WXImageObject(bmp);WXMediaMessage msg = new WXMediaMessage();msg.mediaObject = imgObj;Bitmap thumbBmp = Bitmap.createScaledBitmap(bmp, 80, THUMB_SIZE, true);bmp.recycle();msg.thumbData = Util.bmpToByteArray(thumbBmp, true);SendMessageToWX.Req req = new SendMessageToWX.Req();req.transaction = getTransaction();req.message = msg;req.scene = SendMessageToWX.Req.WXSceneTimeline;api.sendReq(req);}


/**   * 截屏--当前屏幕   * @param context   * @return   */     private Bitmap captureScreen(Activity context){       View cv = context.getWindow().getDecorView();       Bitmap bmp = Bitmap.createBitmap(cv.getWidth(), cv.getHeight(),Config.ARGB_8888);       Canvas canvas = new Canvas(bmp);       cv.draw(canvas);       return bmp;  


/** * 截取webView快照(webView加载的整个内容的大小) *  * @param webView * @return */public static Bitmap captureWebView(WebView webView) {Picture snapShot = webView.capturePicture();Bitmap bmp = Bitmap.createBitmap(snapShot.getWidth(),snapShot.getHeight(), Bitmap.Config.ARGB_8888);Canvas canvas = new Canvas(bmp);snapShot.draw(canvas);return bmp;}

    

2、新浪分享

    第一步:下载新浪sdk

   第二步:到新浪公共账号平台申请开发者账号  获取appid

     

private void sendMultiMessage() {// 1. 初始化微博的分享消息WeiboMultiMessage weiboMessage = new WeiboMultiMessage();weiboMessage.mediaObject = getImageObj();weiboMessage.textObject = getTextObj();// 2. 初始化从第三方到微博的消息请求SendMultiMessageToWeiboRequest request = new SendMultiMessageToWeiboRequest();// 用transaction唯一标识一个请求request.transaction = String.valueOf(System.currentTimeMillis());request.multiMessage = weiboMessage;// 3. 发送请求消息到微博,唤起微博分享界面weiboApi.sendRequest(request);}/** * 创建文本消息对象。 *  * @return 文本消息对象。 */private TextObject getTextObj() {TextObject textObject = new TextObject();textObject.text = "分享图片";return textObject;}/** * 创建图片消息对象。 *  * @return 图片消息对象。 */private ImageObject getImageObj() {ImageObject imageObject = new ImageObject();Bitmap bmp = captureWebView(wb);imageObject.setImageObject(bmp);return imageObject;}

private String getTransaction() {final GetMessageFromWX.Req req = new GetMessageFromWX.Req(bundle);return req.transaction;}

 




二、dialog和popupwindow的使用

       1、dialog的使用

      

private void UpdateVersiondialog(String title, String text, String yes,String no, final Integer isUpdateNewestVersion,final Integer nowSystemNum) {CustomDialog.Builder ibuilder = new CustomDialog.Builder(getActivity());ibuilder.setTitle(title);ibuilder.setMessage(text);ibuilder.setPositiveButton(yes, new DialogInterface.OnClickListener() {@Overridepublic void onClick(DialogInterface dialog, int which) {//ok 后的操作dialog.dismiss();}});ibuilder.setNegativeButton(no, new DialogInterface.OnClickListener() {@Overridepublic void onClick(DialogInterface dialog, int which) {// 随机绑定dialog.dismiss();<pre name="code" class="plain">//ok 取消的操作
}});CustomDialog dialog = ibuilder.create();dialog.show();dialog.setCanceledOnTouchOutside(false);//屏蔽背景的触发
dialog.setCancelable(false);//屏蔽返回按钮的触发}

            2、popupwindow的使用

1、为PopupWindow的view布局,通过LayoutInflator获取布局的view.如:LayoutInflater inflater =(LayoutInflater)            this.anchor.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);View textEntryView =  inflater.inflate(R.layout.paopao_alert_dialog, null);       2、显示位置,可以有很多方式设置显示方式pop.showAtLocation(findViewById(R.id.ll2), Gravity.LEFT, 0, -90);或者pop.showAsDropDown(View anchor, int xoff, int yoff) 3、进出场动画pop.setAnimationStyle(R.style.PopupAnimation); 4、点击PopupWindow区域外部,PopupWindow消失   this.window = new PopupWindow(anchor.getContext()); this.window.setTouchInterceptor(new OnTouchListener() {@Overridepublic boolean onTouch(View v, MotionEvent event) {if(event.getAction() ==MotionEvent.ACTION_OUTSIDE) {              BetterPopupWindow.this.window.dismiss();return true;}return false;}});


两者区别:

PopupWindow与Dialog不同之处在于PopupWindow弹出时背景Activity仍可以获取焦点(PopupWindow setFocusable(false) 除外),设置SetFocusable(true)后,与Dialog相似,并且不能接收按键事件。        如果要使PopupWindow能响应按键事件或点击背景Activity以关闭弹出对话框 最简单的方法是使用setBackgroundDrawable(),或者使用能创建Background的构造方法 这是因为当设置了background后会将contentView放在一个PopupViewContainer类的容器中交给WindowManager,PopupViewContainer是PopupView的内部类,实现了对按键及Touch事件的处理。当然不设background自己通过set对最外层contentView调用setOnKeyListener(),setOnTouchListener()也可实现。这里当键盘出来时,原布局并没有压缩。






待续中............................

待续中............................

待续中............................




三、slidingmenu的使用


四、fragment和radiogroup组合实现tabhost


五、图片listview 缓存处理。优化图片缓存、图片加载优化、图片加载队列根据当前滑动的位置优先加载





六、起始页的处理viewpager


七、andorid中通过webview通过js调用highcharts 展示各类图表


八、viewPager+滑动条实现两页头部按钮来回切换,viewpager滑动时选项卡的下滑线动画滑动,可以尝试用 actionbar+viewpager来实现


九、下拉刷新,使用listview的下拉刷新 ,开源库PullToRefreshListView,在android19版本上提供了新的下拉刷新的api


十、小图标适应各种兼容,考虑使用 icomoon 图标通过字符串处理


十一、头像圆形处理。可以通过xml覆盖一层圆角,或者通过集成view重新onDraw重画


十二、身高、日期、年龄选项卡的更好展示方案


十三、分享当前页。原理:将当前的view 设置存到缓存cache中然后 measure 得到缓存当前的view的 bitmap


十四、声音、震动的提醒


十五、通知接收,暂时用的是轮询,考虑自己使用长连接实现通知,通过心跳包来保持连接考虑断网等情况,或者直接使用个推


十六、我的目标中进度条的切换


十七、调用手机相册设置头像


十八、gif图片的加载


十九、activity上下左右滑出动画


二十、数据存储:application保存全局变量、shareperefence存储数据到文件中、sqlite保存数据库、intent  blind对象传递数值(特殊对象可以考虑转成base64存储)、content provider 好像该项目中没用到


二十一、service  broadcast  notification 的使用


1 0
原创粉丝点击