handle

来源:互联网 发布:聚合数据公司怎么样 编辑:程序博客网 时间:2024/06/09 17:23

package com.android.isoftstone;

 

import android.app.Activity;
import android.app.ListActivity;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class TestHandler extends ListActivity {
 protected static final int GUIUPDATEIDENTIFIER = 0x101;   
 protected static final int GUIUPDATEIDENTIFIERNEW = 0x102;   
 public static int flag=1;
    Thread myRefreshThread = null;   
    BounceView myBounceView = null;   
  
    Handler myHandler = new Handler() {  
         public void handleMessage(Message msg) {   
              switch (msg.what) {   
                   case TestHandler.GUIUPDATEIDENTIFIER:   
                        myBounceView.invalidate();  
                        break;  
                   case TestHandler.GUIUPDATEIDENTIFIERNEW: 
                   
                       myBounceView.invalidate();
//                     ImageView mImageView= new ImageView(null);
//                       TextView mTextView= new TextView(context);
//                       mTextView.setText("AAAAAAAAAAAA");
                       break;
              }   
              super.handleMessage(msg);   
         }   
    };  
    public void onCreate(Bundle savedInstanceState) {   
         super.onCreate(savedInstanceState);   
         this.requestWindowFeature(Window.FEATURE_NO_TITLE);   

         this.myBounceView = new BounceView(this);  
         this.setContentView(this.myBounceView);
//         setAdapter(new EfficientAdapter());
         new Thread(new myThread()).start();  
         Log.d("********************", "===================="+flag);
    }   
  
    class myThread implements Runnable {   
         public void run() {  
              while (!Thread.currentThread().isInterrupted()) {    
                      
                   Message message = new Message();   
                   message.what = TestHandler.GUIUPDATEIDENTIFIER;   
                     
                   TestHandler.this.myHandler.sendMessage(message);   
                   try {   
                        Thread.sleep(3000); 
                       
                        if (flag==2)
                        {
                        Thread.currentThread().interrupt();
                       
                        message.what = TestHandler.GUIUPDATEIDENTIFIERNEW;   
                       
                        TestHandler.this.myHandler.sendMessage(message);  
                       
                        }
                        flag++;
                   } catch (InterruptedException e) {   
                        Thread.currentThread().interrupt();   
                   }   
              }   
         }   
    }   
  

 

 

 

 

 

 

 

 

 

 

 

 

 

package com.android.isoftstone;

 


import android.app.ListActivity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Adapter;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

public class BounceView extends View{  
    float x = 40;  
    public static Context mConText;  
    public BounceView(Context context) {
     
         super(context);   
         mConText=context;
    }   
 
    @Override   
    protected void onDraw(Canvas canvas) {   
        if (TestHandler.flag== 1)
        { 
       
        Paint mPaint = new Paint();  
        mPaint.setAntiAlias(true);  
        mPaint.setColor(Color.GREEN);
        Log.d("********************", "===================="+x);
       
        canvas.drawCircle(x, 40, 40, mPaint); 
      
        }
        else
        {
          Paint mPaint = new Paint();  
          mPaint.setAntiAlias(true);  
          mPaint.setColor(Color.GREEN);
          Log.d("********************", "===================="+x);
          canvas.drawCircle(180, 40, 40, mPaint);

        }
       
    }  
 
    private static class EfficientAdapter extends BaseAdapter {
        private LayoutInflater mInflater;
        private Bitmap mIcon1;
        private Bitmap mIcon2;

        public EfficientAdapter() {
          /*  // Cache the LayoutInflate to avoid asking for a new one each time.
            mInflater = LayoutInflater.from(context);

            // Icons bound to the rows.
            mIcon1 = BitmapFactory.decodeResource(context.getResources(), R.drawable.icon48x48_1);
            mIcon2 = BitmapFactory.decodeResource(context.getResources(), R.drawable.icon48x48_2);*/
        }

        /**
         * The number of items in the list is determined by the number of speeches
         * in our array.
         *
         * @see android.widget.ListAdapter#getCount()
         */
        public int getCount() {
            return 4;
        }

        /**
         * Since the data comes from an array, just returning the index is
         * sufficent to get at the data. If we were using a more complex data
         * structure, we would return whatever object represents one row in the
         * list.
         *
         * @see android.widget.ListAdapter#getItem(int)
         */
        public Object getItem(int position) {
            return position;
        }

        /**
         * Use the array index as a unique id.
         *
         * @see android.widget.ListAdapter#getItemId(int)
         */
        public long getItemId(int position) {
            return position;
        }

        /**
         * Make a view to hold each row.
         *
         * @see android.widget.ListAdapter#getView(int, android.view.View,
         *      android.view.ViewGroup)
         */
        public View getView(int position, View convertView, ViewGroup parent) {
         
         TextView mTextView=new TextView(mConText);
         mTextView.setText("AAAAA");
         return mTextView;
        }

        static class ViewHolder {
            TextView text;
//            ImageView icon;
        }
    }


    private static final String[] DATA = {
            "Abbaye de Belloc", "Abbaye du Mont des Cats", "Abertam",
            "Abondance", "Ackawi", "Acorn", "Adelost", "Affidelice au Chablis",
            "Afuega'l Pitu", "Airag", "Airedale", "Aisy Cendre",
            "Allgauer Emmentaler", "Alverca", "Ambert", "American Cheese",
            "Ami du Chambertin", "Anejo Enchilado", "Anneau du Vic-Bilh",
            "Anthoriro", "Appenzell", "Aragon", "Ardi Gasna", "Ardrahan"
            };

 

原创粉丝点击