|  
 
 
11.import android.view.WindowManager;   12.import android.widget.ImageView;   13.   14.public class WindowManagerTest extends Activity {   15.    /** Called when the activity is first created. */   16.       17.    private float mPosX;   18.    private float mPosY;   19.       20.    Bitmap bitmap;   21.       22.    WindowManager.LayoutParams mWindowParams;   23.       24.    WindowManager mWindowManager;   25.       26.    ImageView v;   27.       28.    @Override   29.    public void onCreate(Bundle savedInstanceState) {   30.        super.onCreate(savedInstanceState);   31.           32.        setContentView(R.layout.main);   33.          34.        bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.button);   35.           36.        addViewToWindowManage(bitmap, 200, 200);   37.    }   38.       39.    public boolean onTouchEvent(MotionEvent motion){   40.        switch(motion.getAction()){   41.        case MotionEvent.ACTION_DOWN:   42.            mPosX = motion.getX();   43.            mPosY = motion.getY();   44.            return true;   45.        case MotionEvent.ACTION_MOVE:   46.            mPosX = motion.getX();   47.            mPosY = motion.getY();   48.            updateViewPosition(v, (int)mPosX,(int) mPosY);   49.            return true;   50.        case MotionEvent.ACTION_UP:   51.            removeView(v);   52.            return true;   53.        }   54.           55.        return true;   56.    }   57.      58.    void addViewToWindowManage(Bitmap bm, int x, int y) {   59.        mWindowParams = new WindowManager.LayoutParams();   60.        mWindowParams.gravity = Gravity.LEFT | Gravity.TOP;   61.        mWindowParams.x = x;   62.        mWindowParams.y = y;   63.        mWindowParams.height = WindowManager.LayoutParams.WRAP_CONTENT;   64.        mWindowParams.width = WindowManager.LayoutParams.WRAP_CONTENT;   65.        mWindowParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE   66.                | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE   67.                | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON   68.                | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;   69.        mWindowParams.format = PixelFormat.TRANSLUCENT;   70.        mWindowParams.windowAnimations = 0;   71.        v = new ImageView(this);   72.        v.setImageBitmap(bm);   73.        mWindowManager = (WindowManager) this.getSystemService("window");   74.        mWindowManager.addView(v, mWindowParams);   75.    }   76.       77.    void updateViewPosition(View v,int x,int y){   78.        mWindowParams.alpha = 1.0f;   79.        mWindowParams.x = x ;   80.        mWindowParams.y = y;   81.        mWindowManager.updateViewLayout(v, mWindowParams);   82.    }   83.       84.    void removeView(View v){   85.        mWindowManager.removeView(v);;   86.    }   87.}   代码包下载地址:http-://download.csdn.-net/source/3521066
 LauncherApplication中有变量,一个是LauncherModel,一个是IconCache。在本类中生成LauncherModel对象,作为全局使用的操作数据的对象,并且为Launcher注册了相应的广播,一种是package的remove,update,add,还有快捷方式的Observer,在有快捷方式的变动,重新load。IconCache,是为程序的快捷方式提供默认的图标。
 上一页  [1] [2]  
 |