您的位置:首页 > 移动开发 > Android开发

android应用市场源码发布【第二天】

2012-10-11 16:10 423 查看
今天的内容比较多 进入首页了,在这里先发一部分 因为这个类有1000多行的代码 分2次发布

【第一天】:点击打开链接

产品下载试用:http://download.csdn.net/detail/zxciop110/4625423

第一天忘了讲一个地方了 就是SharedPreferences 第二次打开的时候不会在是指导页,而是一个LOADING 这在很多项目中都这样搞的 我们也不例外,今天顺便也讲了先看图



/**
 * Animation_index.java
 * com.yzz.twan
 *
 * Function: TODO 
 *
 *   ver     date                      author
 * ──────────────────────────────────
 *                    2012-8-9                 HP
 *
 * Copyright (c) 2012, TNT All Rights Reserved.
*/
 
package com.yzz.twan;
 
 
import java.util.ArrayList;
import java.util.List;
 
import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.ComponentName;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.provider.Settings;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.view.Window;
import android.view.WindowManager;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
/**
 * ClassName:第一次启动页后
 * Function: TODO ADD FUNCTION
 * Reason:         TODO ADD REASON
 *
 * @author   HP
 * @version  
 * @since    Ver 1.1
 * @Date         2012-8-9                上午09:54:25
 *
 * <a href="\"http://www.eoeandroid.com/home.php?mod=space&uid=133757\"" target="\"_blank\"">@see</a>          
 */
public class Animation_index extends Activity {
    public  Animation anm,anms;
    public int marginsTop;
    public List<ImageView>images;
    public ImageView iv;
    public Button btn;
    private Context cont = this;
    public LinearLayout ll;
    boolean flag = true;
     
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        super.onCreate(savedInstanceState);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
//        setContentView(R.layout.animation_index);
         NetWorkStatus(cont);
        DisplayMetrics dm = this.getResources().getDisplayMetrics();
        int height = dm.heightPixels;//绝对高度
        marginsTop = height -100;
        anm = AnimationUtils.loadAnimation(this,R.anim.myanim);
        anms = AnimationUtils.loadAnimation(this,R.anim.push_right_in);
        Animation anim = AnimationUtils.loadAnimation(this, R.anim.round_loading);  
////        btn = (Button)findViewById(R.id.loadingBtn);
//        btn = new Button(this);
//        btn.startAnimation(anim);
        ll = new LinearLayout(this);
//        lls = new LinearLayout(this);
        ll.setBackgroundResource(R.drawable.animations);
//        ll.setBackgroundResource(R.drawable.ainmation);
        images = new ArrayList<ImageView>();
        initImage(ll);
        playAnimation();
        setContentView(ll);//
        LinearLayout.LayoutParams paramd = new LinearLayout.LayoutParams(40,40);
        paramd.gravity = Gravity.CENTER;
//        paramd.setMargins(0, 0, 100, 0);
//        
//        
        btn = new Button(this);
//      btn.startAnimation(anim);
       btn.setLayoutParams(paramd);
       btn.setBackgroundDrawable(getResources().getDrawable(R.drawable.refresh_normal));
       btn.startAnimation(anim);
       ll.addView(btn);
         
//        iv = new ImageView(this);
//        ll.setGravity(Gravity.CLIP_HORIZONTAL);
//        iv.setImageDrawable(Animation_index.this.getResources().getDrawable(R.drawable.ainmation));
////        iv.setPressed(pressed)
//        iv.setLayoutParams(paramd);
//        ll.addView(iv);
//        
//        ll.setGravity(Gravity.CENTER_HORIZONTAL);
//        LinearLayout.LayoutParams paramss = new LinearLayout.LayoutParams(40, 40);
//        paramss.setMargins(180, 180, 180, 180);
//        
//        iv.setLayoutParams(paramss);
//        ll.addView(iv);
//        images.add(iv);
         
//        images.get(4).setImageDrawable(Animation_index.this.getResources().getDrawable(R.drawable.ainmation));
         
//        images.add(30dip", R.drawable.a);
//        images.get(7).setAnimation(anms);
         
    }
  
    //线程启动加载小图标
    private void playAnimation() {
        new Thread(){
 
            @Override
            public void run() {
                // TODO Auto-generated method stub
//                super.run();
                try{
                    Thread.sleep(1000);
                     
                }catch (InterruptedException e){
                    e.printStackTrace();
                     
                }
                int runcount = 0;
                while (flag){
                    if(runcount <2){
                        for (int i= 0;i<=6;i++){
                            handler.sendEmptyMessage(i);
                            try {
                                Thread.sleep(400);
                            }catch (InterruptedException e){
                                e.printStackTrace();
                            }
                             
                        }
                        runcount++;
                         
                    }else {
                         
                        handler.sendEmptyMessage(99);
                        runcount=0;
                    }
                }
                 
            }
             
        }.start();
        // TODO Auto-generated method stub
         
    }
     
     
    //网络连接判断
    private boolean NetWorkStatus(Context con) {
 
//      boolean netSataus = false;
      ConnectivityManager cwjManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
//      Log.v("wjp", "cwjManager"+cwjManager);
      if (cwjManager == null)
          return false;
      NetworkInfo  netinfo = cwjManager.getActiveNetworkInfo();
      if(netinfo != null){
//          return netinfo.isAvailable();//是否可用
          return netinfo.isConnected();//检查连接上
      }
      if (netinfo ==null ) {
          Builder b = new AlertDialog.Builder(this).setTitle("没有可用的网络")
                  .setMessage("是否对网络进行设置?");
          b.setPositiveButton("是", new DialogInterface.OnClickListener() {
              public void onClick(DialogInterface dialog, int whichButton) {
                  Intent mIntent = new Intent("/");
                  ComponentName comp = new ComponentName(
                          "com.android.settings",
                          "com.android.settings.Wireless.Settings");
                  mIntent.setComponent(comp);
                  mIntent.setAction("android.intent.action.VIEW");
//                  startActivityForResult(mIntent,0);
                  startActivity(new Intent(Settings.ACTION_SETTINGS));
              }
          }).setNeutralButton("否", new DialogInterface.OnClickListener() {
              public void onClick(DialogInterface dialog, int whichButton) {
                  dialog.cancel();
              }
          }).show();
           
          return true;
      }
 
      return true;
  }
     
     
     
    @Override
    protected void onDestroy() {
        flag = false;
        // TODO Auto-generated method stub
        super.onDestroy();
    }
 
 
    Handler handler=new Handler(){
 
        @Override
        public void handleMessage(Message msg) {
             
            switch(msg.what){
                case 0:
                    images.get(0).setImageDrawable(Animation_index.this.getResources().getDrawable(R.drawable.loading_a));
                    images.get(0).startAnimation(anm);
                    break;
                case 1:
                    images.get(1).setImageDrawable(Animation_index.this.getResources().getDrawable(R.drawable.loading_b));
                    images.get(1).startAnimation(anm);
                    break;
                case 2:
                    images.get(2).setImageDrawable(Animation_index.this.getResources().getDrawable(R.drawable.loading_c));
                    images.get(2).startAnimation(anm);
                    break;
                case 3:
                    images.get(3).setImageDrawable(Animation_index.this.getResources().getDrawable(R.drawable.loading_d));
                    images.get(3).startAnimation(anm);
                    break;
                case 4:
                    images.get(4).setImageDrawable(Animation_index.this.getResources().getDrawable(R.drawable.loading_e));
                    images.get(4).startAnimation(anm);
                    break;
                case 5:
                    images.get(5).setImageDrawable(Animation_index.this.getResources().getDrawable(R.drawable.loading_f));
                    images.get(5).setAnimation(anm);
                    break;
                case 6:
                    images.get(6).setImageDrawable(Animation_index.this.getResources().getDrawable(R.drawable.loading_g));
                    images.get(6).setAnimation(anm);
                    break;
               
//                case 7:
//                    images.get(7).setImageDrawable(Animation_index.this.getResources().getDrawable(R.drawable.gam));
//                    images.get(7).setAnimation(anm);
//                    break;
//                case 8:
//                    images.get(8).setImageDrawable(Animation_index.this.getResources().getDrawable(R.drawable.gam));
//                    images.get(8).setAnimation(anm);
//                    break;
//                case 9:
//                    images.get(9).setImageDrawable(Animation_index.this.getResources().getDrawable(R.drawable.gam));
//                    images.get(9).setAnimation(anm);
//                    break;
                     
                case 99:
                    //clearImage();
                     
                    Intent intent=new Intent();
                    intent.setClass(Animation_index.this, MyTab.class);
                    startActivity(intent);
                    finish();
//*/                    //handler.removeCallbacks(handler);
                    break;
 
            }
             
        }
 
    };
     
     
     
 
     
     
//    private void clearImage()
//    {
//        for(ImageView image:images)
//        {
//            image.setImageDrawable(null);
//            image.destroyDrawingCache();
//        }
//    }  
    //布局
    private void initImage(LinearLayout layout) {
        layout.setGravity(Gravity.CENTER_HORIZONTAL);
        LinearLayout.LayoutParams param = new LinearLayout.LayoutParams(40, 40);
        param.setMargins(130, marginsTop, 0, 0);
         
        LinearLayout.LayoutParams param2 = new LinearLayout.LayoutParams(40, 40);
        param2.setMargins(-5, marginsTop, 0, 0);
         
         
         
//        layout.setGravity(Gravity.CENTER_HORIZONTAL);
//        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(140, 140);
//        params.setMargins(30, marginsTop, 0, 0);
//        
//        LinearLayout.LayoutParams paramsd = new LinearLayout.LayoutParams(40, 40);
//        paramsd.setMargins(-5, marginsTop, 0, 0);
         
 
        ImageView l = new ImageView(this);
        l.setLayoutParams(param);
        layout.addView(l);
        images.add(l);
 
        ImageView o = new ImageView(this);
        o.setLayoutParams(param2);
        layout.addView(o);
        images.add(o);
         
         
        ImageView a = new ImageView(this);
        a.setLayoutParams(param2);
        layout.addView(a);
        images.add(a);
         
        ImageView d = new ImageView(this);
        d.setLayoutParams(param2);
        layout.addView(d);
        images.add(d);
         
        ImageView i = new ImageView(this);
        i.setLayoutParams(param2);
        layout.addView(i);
        images.add(i);
         
        ImageView n = new ImageView(this);
        n.setLayoutParams(param2);
        layout.addView(n);
        images.add(n);
         
        ImageView g = new ImageView(this);
        g.setLayoutParams(param2);
        layout.addView(g);
        images.add(g);
         
         
        ImageView h = new ImageView(this);
        h.setLayoutParams(param2);
        layout.addView(h);
        images.add(h);
         
       
        ImageView y = new ImageView(this);
        y.setLayoutParams(param2);
        layout.addView(y);
        images.add(y);
         
         
        ImageView k = new ImageView(this);
        k.setLayoutParams(param2);
        layout.addView(k);
        images.add(k); 
         
         
//        finish();
        // TODO Auto-generated method stub
         
    }
 
}


其实这里没比较讲很多 其实很简单 主要看一下自定义布局那个LOADING实现,还有那个圆一直在转圈

方法:playAnimation

//线程启动加载小图标
    private void playAnimation() {
        new Thread(){
 
            @Override
            public void run() {
                // TODO Auto-generated method stub
//                super.run();
                try{
                    Thread.sleep(1000);
                     
                }catch (InterruptedException e){
                    e.printStackTrace();
                     
                }
                int runcount = 0;
                while (flag){
                    if(runcount <2){
                        for (int i= 0;i<=6;i++){
                            handler.sendEmptyMessage(i);
                            try {
                                Thread.sleep(400);
                            }catch (InterruptedException e){
                                e.printStackTrace();
                            }
                             
                        }
                        runcount++;
                         
                    }else {
                         
                        handler.sendEmptyMessage(99);
                        runcount=0;
                    }
                }
                 
            }
             
        }.start();
        // TODO Auto-generated method stub
         
    }


Handler handler=new Handler(){
 
        @Override
        public void handleMessage(Message msg) {
             
            switch(msg.what){
                case 0:
                    images.get(0).setImageDrawable(Animation_index.this.getResources().getDrawable(R.drawable.loading_a));
                    images.get(0).startAnimation(anm);
                    break;
                case 1:
                    images.get(1).setImageDrawable(Animation_index.this.getResources().getDrawable(R.drawable.loading_b));
                    images.get(1).startAnimation(anm);
                    break;
                case 2:
                    images.get(2).setImageDrawable(Animation_index.this.getResources().getDrawable(R.drawable.loading_c));
                    images.get(2).startAnimation(anm);
                    break;
                case 3:
                    images.get(3).setImageDrawable(Animation_index.this.getResources().getDrawable(R.drawable.loading_d));
                    images.get(3).startAnimation(anm);
                    break;
                case 4:
                    images.get(4).setImageDrawable(Animation_index.this.getResources().getDrawable(R.drawable.loading_e));
                    images.get(4).startAnimation(anm);
                    break;
                case 5:
                    images.get(5).setImageDrawable(Animation_index.this.getResources().getDrawable(R.drawable.loading_f));
                    images.get(5).setAnimation(anm);
                    break;
                case 6:
                    images.get(6).setImageDrawable(Animation_index.this.getResources().getDrawable(R.drawable.loading_g));
                    images.get(6).setAnimation(anm);
                    break;
               
//                case 7:
//                    images.get(7).setImageDrawable(Animation_index.this.getResources().getDrawable(R.drawable.gam));
//                    images.get(7).setAnimation(anm);
//                    break;
//                case 8:
//                    images.get(8).setImageDrawable(Animation_index.this.getResources().getDrawable(R.drawable.gam));
//                    images.get(8).setAnimation(anm);
//                    break;
//                case 9:
//                    images.get(9).setImageDrawable(Animation_index.this.getResources().getDrawable(R.drawable.gam));
//                    images.get(9).setAnimation(anm);
//                    break;
                     
                case 99:
                    //clearImage();
                     
                    Intent intent=new Intent();
                    intent.setClass(Animation_index.this, MyTab.class);
                    startActivity(intent);
                    finish();
//*/                    //handler.removeCallbacks(handler);
                    break;
 
            }
             
        }
 
    };


这一页很简单 没比较在讲了 首页多讲讲吧 代码比较多
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: