- 论坛徽章:
- 0
|
android uninstall小工具demo实现 (二)................... - package com.jf.install;
- import java.util.List;
- import java.util.Map;
- import android.app.Activity;
- import android.content.Context;
- import android.graphics.drawable.Drawable;
- import android.view.LayoutInflater;
- import android.view.View;
- import android.view.ViewGroup;
- import android.widget.ImageView;
- import android.widget.SimpleAdapter;
- import android.widget.TextView;
- import android.widget.SimpleAdapter.ViewBinder;
- public class ListAdapter extends SimpleAdapter
- {
- private int[] appTo;
- private String[] appFrom;
- private ViewBinder appViewBinder;
- private List<? extends Map<String, ?>> appData;
- private int appResource;
- private LayoutInflater appInflater;
- private Context context;
- public ListAdapter(Context context, List<? extends Map<String, ?>> data,
- int resource, String[] from, int[] to) {
- super(context, data, resource, from, to);
- appData = data;
- appResource = resource;
- appFrom = from;
- appTo = to;
- appInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
- }
-
- public View getView(int position, View convertView, ViewGroup parent)
- {
- return createViewFromResource(position, convertView, parent, appResource);
-
- }
-
- private View createViewFromResource(int position, View convertView, ViewGroup parent, int resource)
- {
- View v;
- if(convertView == null)
- {
- v = appInflater.inflate(resource, parent,false);
- final int[] to = appTo;
- final int count = to.length;
- final View[] holder = new View[count];
-
- for(int i = 0; i < count; i++)
- {
- holder[i] = v.findViewById(to[i]);
- }
- v.setTag(holder);
- }else
- {
- v = convertView;
- }
- bindView(position, v);
- return v;
- }
-
- private void bindView(int position, View view)
- {
- final Map dataSet = appData.get(position);
- if(dataSet == null)
- {
- return;
- }
-
- final ViewBinder binder = appViewBinder;
- final View[] holder = (View[])view.getTag();
- final String[] from = appFrom;
- final int[] to = appTo;
- final int count = to.length;
-
- for(int i = 0; i < count; i++)
- {
- final View v = holder[i];
- if(v != null)
- {
- final Object data = dataSet.get(from[i]);
- String text = data == null ? "":data.toString();
- if(text == null)
- {
- text = "";
- }
-
- boolean bound = false;
- if(binder != null)
- {
- bound = binder.setViewValue(v, data, text);
- }
-
- if(!bound)
- {
- /**
- * 自定义适配器,关在在这里,根据传递过来的控件以及值的数据类型,
- * 执行相应的方法,可以根据自己需要自行添加if语句。另外,CheckBox等
- * 集成自TextView的控件也会被识别成TextView,这就需要判断值的类型
- */
- if(v instanceof TextView)
- {
- //如果是TextView控件,则调用SimpleAdapter自带的方法,设置文本
- this.setViewText((TextView)v, text);
- }else if(v instanceof ImageView)
- {
- //如果是ImageView控件,调用自己写的方法,设置图片
- setViewImage((ImageView)v, (Drawable)data);
- }else
- {
- throw new IllegalStateException(v.getClass().getName() + " is not a " +
- "view that can be bounds by this SimpleAdapter");
- }
- }
- }
- }
- }
- public void setViewImage(ImageView v, Drawable value)
- {
- v.setImageDrawable(value);
- }
- }
-
复制代码 下面的2个是自定义的加载框:
Java代码- 1.package com.jf.install.util;
- 2.
- 3.
- 4.import com.jf.install.R;
- 5.
- 6.import android.app.ProgressDialog;
- 7.import android.content.Context;
- 8.import android.graphics.Bitmap;
- 9.import android.graphics.Paint;
- 10.import android.widget.LinearLayout;
- 11.import android.widget.TextView;
- 12.
- 13.public class ViewHandler {
- 14. static ProgressDialog dlg ;
- 15. public static ProgressDialog creteProgressDialog(Context context,
- 16. String text) {
- 17. dlg= new ProgressDialog(context);
- 18. dlg.show();
- 19. dlg.setContentView(R.layout.loading);
- 20. LinearLayout root = (LinearLayout) dlg
- 21. .findViewById(R.id.progressDialog);
- 22. root.setGravity(android.view.Gravity.CENTER);
- 23.
- 24. LoadingView mLoadView = new LoadingView(context);
- 25. mLoadView.setDrawableResId(R.drawable.icon10);
- 26. root.addView(mLoadView);
- 27. TextView alert = new TextView(context);
- 28. Paint tPaint=alert.getPaint();
- 29. tPaint.setFakeBoldText(true);
- 30. alert.setText(text);
- 31. alert.setTextSize(18);
- 32.
- 33. // alert.setTextColor(R.drawable.red);
- 34. root.addView(alert);
- 35. return dlg;
- 36. }
- 37. public static void distoryBitmap(Bitmap mFgBitmap){
- 38.
- 39. if ( null !=mFgBitmap&&!mFgBitmap.isRecycled())
- 40.
- 41. mFgBitmap.recycle();
- 42. }
- 43. public static void dissMiss(){
- 44. if(null!=dlg){
- 45. System.out.println("dialog dismiss***********************");
- 46. dlg.dismiss();
- 47. }
- 48. }
- 49.}
- package com.jf.install.util;
- import com.jf.install.R;
- import android.app.ProgressDialog;
- import android.content.Context;
- import android.graphics.Bitmap;
- import android.graphics.Paint;
- import android.widget.LinearLayout;
- import android.widget.TextView;
- public class ViewHandler {
- static ProgressDialog dlg ;
- public static ProgressDialog creteProgressDialog(Context context,
- String text) {
- dlg= new ProgressDialog(context);
- dlg.show();
- dlg.setContentView(R.layout.loading);
- LinearLayout root = (LinearLayout) dlg
- .findViewById(R.id.progressDialog);
- root.setGravity(android.view.Gravity.CENTER);
- LoadingView mLoadView = new LoadingView(context);
- mLoadView.setDrawableResId(R.drawable.icon10);
- root.addView(mLoadView);
- TextView alert = new TextView(context);
- Paint tPaint=alert.getPaint();
- tPaint.setFakeBoldText(true);
- alert.setText(text);
- alert.setTextSize(18);
-
- // alert.setTextColor(R.drawable.red);
- root.addView(alert);
- return dlg;
- }
- public static void distoryBitmap(Bitmap mFgBitmap){
- if ( null !=mFgBitmap&&!mFgBitmap.isRecycled())
- mFgBitmap.recycle();
- }
- public static void dissMiss(){
- if(null!=dlg){
- System.out.println("dialog dismiss***********************");
- dlg.dismiss();
- }
- }
- }
复制代码 Java代码- 1.package com.jf.install.util;
- 2.
- 3.import android.content.Context;
- 4.import android.graphics.Bitmap;
- 5.import android.graphics.BitmapFactory;
- 6.import android.graphics.Canvas;
- 7.import android.graphics.Matrix;
- 8.import android.os.Handler;
- 9.import android.util.AttributeSet;
- 10.import android.view.View;
- 11.
- 12.public class LoadingView extends View {
- 13.
- 14. private Matrix mFgMatrix;
- 15. private Bitmap mFgBitmap;
- 16.
- 17. public LoadingView(Context context) {
- 18. super(context);
- 19. }
- 20.
- 21. public LoadingView(Context context, AttributeSet attrs) {
- 22. super(context, attrs);
- 23. }
- 24.
- 25. public void setDrawableResId(int iconResId) {
- 26. mFgMatrix = new Matrix();
- 27. mFgBitmap = BitmapFactory.decodeResource(getResources(), iconResId);
- 28. myHandler.sendEmptyMessage(0);
- 29. onMeasure(mFgBitmap.getWidth(), mFgBitmap.getHeight());
- 30. }
- 31.
- 32. @Override
- 33. protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
- 34. setMeasuredDimension(mFgBitmap.getWidth(), mFgBitmap.getHeight());
- 35. }
- 36.
- 37. @Override
- 38. protected void onDraw(Canvas canvas) {
- 39. canvas.drawBitmap(mFgBitmap, mFgMatrix, null);
- 40. }
- 41.
- 42. private Handler myHandler = new Handler() {
- 43. public void handleMessage(android.os.Message msg) {
- 44. mFgMatrix.postRotate(-10f, mFgBitmap.getWidth() / 2f, mFgBitmap
- 45. .getHeight() / 2f);
- 46. invalidate();
- 47. myHandler.sendEmptyMessageDelayed(msg.what, 20);
- 48. };
- 49. };
- 50.}
- package com.jf.install.util;
- import android.content.Context;
- import android.graphics.Bitmap;
- import android.graphics.BitmapFactory;
- import android.graphics.Canvas;
- import android.graphics.Matrix;
- import android.os.Handler;
- import android.util.AttributeSet;
- import android.view.View;
- public class LoadingView extends View {
- private Matrix mFgMatrix;
- private Bitmap mFgBitmap;
- public LoadingView(Context context) {
- super(context);
- }
- public LoadingView(Context context, AttributeSet attrs) {
- super(context, attrs);
- }
- public void setDrawableResId(int iconResId) {
- mFgMatrix = new Matrix();
- mFgBitmap = BitmapFactory.decodeResource(getResources(), iconResId);
- myHandler.sendEmptyMessage(0);
- onMeasure(mFgBitmap.getWidth(), mFgBitmap.getHeight());
- }
- @Override
- protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
- setMeasuredDimension(mFgBitmap.getWidth(), mFgBitmap.getHeight());
- }
- @Override
- protected void onDraw(Canvas canvas) {
- canvas.drawBitmap(mFgBitmap, mFgMatrix, null);
- }
- private Handler myHandler = new Handler() {
- public void handleMessage(android.os.Message msg) {
- mFgMatrix.postRotate(-10f, mFgBitmap.getWidth() / 2f, mFgBitmap
- .getHeight() / 2f);
- invalidate();
- myHandler.sendEmptyMessageDelayed(msg.what, 20);
- };
- };
- }
复制代码 Java代码- 1.<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- 2. android:orientation="horizontal" android:layout_width="wrap_content"
- 3. android:layout_height="wrap_content" android:id="@+id/progressDialog">
- 4.</LinearLayout>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="horizontal" android:layout_width="wrap_content"
- android:layout_height="wrap_content" android:id="@+id/progressDialog">
- </LinearLayout>
复制代码 Java代码- 1.<?xml version="1.0" encoding="utf-8"?>
- 2.<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- 3. android:layout_width="fill_parent"
- 4. android:layout_height="fill_parent"
- 5. android:orientation="vertical" >
- 6.
- 7. <ListView
- 8. android:id="@+id/applist"
- 9. android:layout_width="fill_parent"
- 10. android:layout_height="wrap_content"
- 11. android:text="@string/hello" />
- 12.
- 13.</LinearLayout>
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:orientation="vertical" >
- <ListView
- android:id="@+id/applist"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:text="@string/hello" />
- </LinearLayout>
复制代码 Java代码- 1.<?xml version="1.0" encoding="utf-8"?>
- 2.<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- 3. android:orientation="horizontal" android:layout_width="fill_parent"
- 4. android:layout_height="fill_parent">
- 5. <ImageView android:id="@+id/icon"
- 6. android:layout_width="48dip"
- 7. android:layout_height="48dip"
- 8. android:padding="4dip" />
- 9. <LinearLayout android:orientation="vertical"
- 10. android:layout_width="fill_parent" android:layout_height="wrap_content">
- 11. <TextView android:id="@+id/appName" android:layout_width="fill_parent" android:layout_height="wrap_content"/>
- 12. <TextView android:id="@+id/packageName" android:layout_width="fill_parent" android:layout_height="wrap_content"/>
- 13. </LinearLayout>
- 14.</LinearLayout>
复制代码 |
|