免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1619 | 回复: 0
打印 上一主题 下一主题

android uninstall小工具demo实现 (二)................... [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-11-24 14:38 |只看该作者 |倒序浏览
android uninstall小工具demo实现 (二)...................
  1. package com.jf.install;

  2. import java.util.List;
  3. import java.util.Map;

  4. import android.app.Activity;
  5. import android.content.Context;
  6. import android.graphics.drawable.Drawable;
  7. import android.view.LayoutInflater;
  8. import android.view.View;
  9. import android.view.ViewGroup;
  10. import android.widget.ImageView;
  11. import android.widget.SimpleAdapter;
  12. import android.widget.TextView;
  13. import android.widget.SimpleAdapter.ViewBinder;

  14. public class ListAdapter extends SimpleAdapter
  15. {
  16.         private int[] appTo;
  17.         private String[] appFrom;
  18.         private ViewBinder appViewBinder;
  19.         private List<? extends Map<String, ?>>  appData;
  20.         private int appResource;
  21.         private LayoutInflater appInflater;
  22.         private Context context;
  23.         public ListAdapter(Context context, List<? extends Map<String, ?>> data,
  24.                         int resource, String[] from, int[] to) {
  25.                 super(context, data, resource, from, to);
  26.                 appData = data;
  27.                 appResource = resource;
  28.                 appFrom = from;
  29.                 appTo = to;
  30.                 appInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  31.         }
  32.        
  33.         public View getView(int position, View convertView, ViewGroup parent)
  34.         {
  35.                 return createViewFromResource(position, convertView, parent, appResource);
  36.                
  37.         }
  38.        
  39.         private View createViewFromResource(int position, View convertView, ViewGroup parent, int resource)
  40.         {
  41.                 View v;
  42.                 if(convertView == null)
  43.                 {
  44.                         v = appInflater.inflate(resource, parent,false);
  45.                         final int[] to = appTo;
  46.                         final int count = to.length;
  47.                         final View[] holder = new View[count];
  48.                        
  49.                         for(int i = 0; i < count; i++)
  50.                         {
  51.                                 holder[i] = v.findViewById(to[i]);
  52.                         }
  53.                         v.setTag(holder);
  54.                 }else
  55.                 {
  56.                         v = convertView;
  57.                 }
  58.                 bindView(position, v);
  59.                 return v;       
  60.         }
  61.        
  62.         private void bindView(int position, View view)
  63.         {
  64.                 final Map dataSet = appData.get(position);
  65.                 if(dataSet == null)
  66.                 {
  67.                         return;
  68.                 }
  69.                
  70.                 final ViewBinder binder = appViewBinder;
  71.                 final View[] holder = (View[])view.getTag();
  72.                 final String[] from = appFrom;
  73.                 final int[] to = appTo;
  74.                 final int count = to.length;
  75.                
  76.                 for(int i = 0; i < count; i++)
  77.                 {
  78.                         final View v = holder[i];
  79.                         if(v != null)
  80.                         {
  81.                                 final Object data = dataSet.get(from[i]);
  82.                                 String text = data == null ? "":data.toString();
  83.                                 if(text == null)
  84.                                 {
  85.                                         text = "";
  86.                                 }
  87.                                
  88.                                 boolean bound = false;
  89.                                 if(binder != null)
  90.                                 {
  91.                                         bound = binder.setViewValue(v, data, text);
  92.                                 }
  93.                                
  94.                                 if(!bound)
  95.                                 {
  96.                                         /**
  97.                                          * 自定义适配器,关在在这里,根据传递过来的控件以及值的数据类型,
  98.                                          * 执行相应的方法,可以根据自己需要自行添加if语句。另外,CheckBox等
  99.                                          * 集成自TextView的控件也会被识别成TextView,这就需要判断值的类型
  100.                                          */
  101.                                         if(v instanceof TextView)
  102.                                         {
  103.                                                 //如果是TextView控件,则调用SimpleAdapter自带的方法,设置文本
  104.                                                 this.setViewText((TextView)v, text);
  105.                                         }else if(v instanceof ImageView)
  106.                                         {
  107.                                                 //如果是ImageView控件,调用自己写的方法,设置图片
  108.                                                 setViewImage((ImageView)v, (Drawable)data);
  109.                                         }else
  110.                                         {
  111.                                                 throw new IllegalStateException(v.getClass().getName() + " is not a " +
  112.                                                                 "view that can be bounds by this SimpleAdapter");
  113.                                         }
  114.                                 }
  115.                         }
  116.                 }
  117.         }
  118.         public void setViewImage(ImageView v, Drawable value)
  119.         {
  120.                 v.setImageDrawable(value);
  121.         }
  122. }
复制代码
下面的2个是自定义的加载框:

Java代码
  1. 1.package com.jf.install.util;   
  2. 2.  
  3. 3.  
  4. 4.import com.jf.install.R;   
  5. 5.  
  6. 6.import android.app.ProgressDialog;   
  7. 7.import android.content.Context;   
  8. 8.import android.graphics.Bitmap;   
  9. 9.import android.graphics.Paint;   
  10. 10.import android.widget.LinearLayout;   
  11. 11.import android.widget.TextView;   
  12. 12.  
  13. 13.public class ViewHandler {   
  14. 14.     static ProgressDialog dlg ;   
  15. 15.    public static ProgressDialog creteProgressDialog(Context context,   
  16. 16.            String text) {   
  17. 17.        dlg= new ProgressDialog(context);   
  18. 18.        dlg.show();   
  19. 19.        dlg.setContentView(R.layout.loading);   
  20. 20.        LinearLayout root = (LinearLayout) dlg   
  21. 21.                .findViewById(R.id.progressDialog);   
  22. 22.        root.setGravity(android.view.Gravity.CENTER);   
  23. 23.  
  24. 24.        LoadingView mLoadView = new LoadingView(context);   
  25. 25.        mLoadView.setDrawableResId(R.drawable.icon10);   
  26. 26.        root.addView(mLoadView);   
  27. 27.        TextView alert = new TextView(context);      
  28. 28.        Paint tPaint=alert.getPaint();   
  29. 29.         tPaint.setFakeBoldText(true);   
  30. 30.        alert.setText(text);   
  31. 31.        alert.setTextSize(18);   
  32. 32.           
  33. 33.    //  alert.setTextColor(R.drawable.red);   
  34. 34.        root.addView(alert);   
  35. 35.        return dlg;   
  36. 36.    }   
  37. 37.      public static void distoryBitmap(Bitmap mFgBitmap){     
  38. 38.  
  39. 39.              if ( null !=mFgBitmap&&!mFgBitmap.isRecycled())     
  40. 40.  
  41. 41.                  mFgBitmap.recycle();      
  42. 42.         }     
  43. 43.    public static void dissMiss(){   
  44. 44.        if(null!=dlg){   
  45. 45.            System.out.println("dialog dismiss***********************");   
  46. 46.            dlg.dismiss();   
  47. 47.        }   
  48. 48.    }   
  49. 49.}  
  50. package com.jf.install.util;


  51. import com.jf.install.R;

  52. import android.app.ProgressDialog;
  53. import android.content.Context;
  54. import android.graphics.Bitmap;
  55. import android.graphics.Paint;
  56. import android.widget.LinearLayout;
  57. import android.widget.TextView;

  58. public class ViewHandler {
  59.          static ProgressDialog dlg ;
  60.         public static ProgressDialog creteProgressDialog(Context context,
  61.                         String text) {
  62.                 dlg= new ProgressDialog(context);
  63.                 dlg.show();
  64.                 dlg.setContentView(R.layout.loading);
  65.                 LinearLayout root = (LinearLayout) dlg
  66.                                 .findViewById(R.id.progressDialog);
  67.                 root.setGravity(android.view.Gravity.CENTER);

  68.                 LoadingView mLoadView = new LoadingView(context);
  69.                 mLoadView.setDrawableResId(R.drawable.icon10);
  70.                 root.addView(mLoadView);
  71.                 TextView alert = new TextView(context);   
  72.                 Paint tPaint=alert.getPaint();
  73.              tPaint.setFakeBoldText(true);
  74.                 alert.setText(text);
  75.                 alert.setTextSize(18);
  76.                
  77.         //        alert.setTextColor(R.drawable.red);
  78.                 root.addView(alert);
  79.                 return dlg;
  80.         }
  81.           public static void distoryBitmap(Bitmap mFgBitmap){  

  82.                       if ( null !=mFgBitmap&&!mFgBitmap.isRecycled())  

  83.                               mFgBitmap.recycle();   
  84.                  }  
  85.         public static void dissMiss(){
  86.                 if(null!=dlg){
  87.                         System.out.println("dialog dismiss***********************");
  88.                         dlg.dismiss();
  89.                 }
  90.         }
  91. }
复制代码
Java代码
  1. 1.package com.jf.install.util;   
  2. 2.  
  3. 3.import android.content.Context;   
  4. 4.import android.graphics.Bitmap;   
  5. 5.import android.graphics.BitmapFactory;   
  6. 6.import android.graphics.Canvas;   
  7. 7.import android.graphics.Matrix;   
  8. 8.import android.os.Handler;   
  9. 9.import android.util.AttributeSet;   
  10. 10.import android.view.View;   
  11. 11.  
  12. 12.public class LoadingView extends View {   
  13. 13.  
  14. 14.    private Matrix mFgMatrix;   
  15. 15.    private Bitmap mFgBitmap;   
  16. 16.  
  17. 17.    public LoadingView(Context context) {   
  18. 18.        super(context);   
  19. 19.    }   
  20. 20.  
  21. 21.    public LoadingView(Context context, AttributeSet attrs) {   
  22. 22.        super(context, attrs);   
  23. 23.    }   
  24. 24.  
  25. 25.    public void setDrawableResId(int iconResId) {   
  26. 26.        mFgMatrix = new Matrix();   
  27. 27.        mFgBitmap = BitmapFactory.decodeResource(getResources(), iconResId);   
  28. 28.        myHandler.sendEmptyMessage(0);   
  29. 29.        onMeasure(mFgBitmap.getWidth(), mFgBitmap.getHeight());   
  30. 30.    }   
  31. 31.  
  32. 32.    @Override  
  33. 33.    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {   
  34. 34.        setMeasuredDimension(mFgBitmap.getWidth(), mFgBitmap.getHeight());   
  35. 35.    }   
  36. 36.  
  37. 37.    @Override  
  38. 38.    protected void onDraw(Canvas canvas) {   
  39. 39.        canvas.drawBitmap(mFgBitmap, mFgMatrix, null);   
  40. 40.    }   
  41. 41.  
  42. 42.    private Handler myHandler = new Handler() {   
  43. 43.        public void handleMessage(android.os.Message msg) {   
  44. 44.            mFgMatrix.postRotate(-10f, mFgBitmap.getWidth() / 2f, mFgBitmap   
  45. 45.                    .getHeight() / 2f);   
  46. 46.            invalidate();   
  47. 47.            myHandler.sendEmptyMessageDelayed(msg.what, 20);   
  48. 48.        };   
  49. 49.    };   
  50. 50.}  
  51. package com.jf.install.util;

  52. import android.content.Context;
  53. import android.graphics.Bitmap;
  54. import android.graphics.BitmapFactory;
  55. import android.graphics.Canvas;
  56. import android.graphics.Matrix;
  57. import android.os.Handler;
  58. import android.util.AttributeSet;
  59. import android.view.View;

  60. public class LoadingView extends View {

  61.         private Matrix mFgMatrix;
  62.         private Bitmap mFgBitmap;

  63.         public LoadingView(Context context) {
  64.                 super(context);
  65.         }

  66.         public LoadingView(Context context, AttributeSet attrs) {
  67.                 super(context, attrs);
  68.         }

  69.         public void setDrawableResId(int iconResId) {
  70.                 mFgMatrix = new Matrix();
  71.                 mFgBitmap = BitmapFactory.decodeResource(getResources(), iconResId);
  72.                 myHandler.sendEmptyMessage(0);
  73.                 onMeasure(mFgBitmap.getWidth(), mFgBitmap.getHeight());
  74.         }

  75.         @Override
  76.         protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
  77.                 setMeasuredDimension(mFgBitmap.getWidth(), mFgBitmap.getHeight());
  78.         }

  79.         @Override
  80.         protected void onDraw(Canvas canvas) {
  81.                 canvas.drawBitmap(mFgBitmap, mFgMatrix, null);
  82.         }

  83.         private Handler myHandler = new Handler() {
  84.                 public void handleMessage(android.os.Message msg) {
  85.                         mFgMatrix.postRotate(-10f, mFgBitmap.getWidth() / 2f, mFgBitmap
  86.                                         .getHeight() / 2f);
  87.                         invalidate();
  88.                         myHandler.sendEmptyMessageDelayed(msg.what, 20);
  89.                 };
  90.         };
  91. }
复制代码
Java代码
  1. 1.<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  2. 2.    android:orientation="horizontal" android:layout_width="wrap_content"  
  3. 3.    android:layout_height="wrap_content" android:id="@+id/progressDialog">   
  4. 4.</LinearLayout>  
  5. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  6.         android:orientation="horizontal" android:layout_width="wrap_content"
  7.         android:layout_height="wrap_content" android:id="@+id/progressDialog">
  8. </LinearLayout>
复制代码
Java代码
  1. 1.<?xml version="1.0" encoding="utf-8"?>   
  2. 2.<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3. 3.    android:layout_width="fill_parent"  
  4. 4.    android:layout_height="fill_parent"  
  5. 5.    android:orientation="vertical" >   
  6. 6.  
  7. 7.    <ListView   
  8. 8.        android:id="@+id/applist"  
  9. 9.        android:layout_width="fill_parent"  
  10. 10.        android:layout_height="wrap_content"  
  11. 11.        android:text="@string/hello" />   
  12. 12.  
  13. 13.</LinearLayout>  
  14. <?xml version="1.0" encoding="utf-8"?>
  15. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  16.     android:layout_width="fill_parent"
  17.     android:layout_height="fill_parent"
  18.     android:orientation="vertical" >

  19.     <ListView
  20.         android:id="@+id/applist"
  21.         android:layout_width="fill_parent"
  22.         android:layout_height="wrap_content"
  23.         android:text="@string/hello" />

  24. </LinearLayout>
复制代码
Java代码
  1. 1.<?xml version="1.0" encoding="utf-8"?>   
  2. 2.<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3. 3.    android:orientation="horizontal" android:layout_width="fill_parent"  
  4. 4.    android:layout_height="fill_parent">   
  5. 5.    <ImageView android:id="@+id/icon"   
  6. 6.        android:layout_width="48dip"  
  7. 7.        android:layout_height="48dip"   
  8. 8.        android:padding="4dip" />   
  9. 9.    <LinearLayout android:orientation="vertical"  
  10. 10.        android:layout_width="fill_parent" android:layout_height="wrap_content">   
  11. 11.        <TextView android:id="@+id/appName" android:layout_width="fill_parent" android:layout_height="wrap_content"/>   
  12. 12.        <TextView android:id="@+id/packageName" android:layout_width="fill_parent" android:layout_height="wrap_content"/>   
  13. 13.    </LinearLayout>   
  14. 14.</LinearLayout>  
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP