public class AllAppsView extends GridView implements OnClickListener,OnItemClickListener, OnItemLongClickListener,DragSource,DropTarget{ private LayoutInflater mLayoutInflater; //private ImageButton mHomeButton; //public MyGridView mGridView; private Context mContext; //public static View mCurrentgridviewitem; //private View mView; private boolean isVisible = false; private Launcher mLauncher; private DragController mDragController; public View mCurrentView=null; private int mCurrentX; private int mCurrentY; private int mCurrentPostion; private int mCurrentSelection=0; private final static int mCurrentScroolPix=30; private int mOldCurrentPositon; private boolean mIsApplication=true; private boolean mIsUpdateOver=true; private boolean mIsOver=true; private int mFirstY; public int motionPosition; public static View v; private Animation m_animation; private int mFirstClickPosition; private int mTopPos=0; private boolean mIsDroped=false; private Timer mTimer=null; public Handler mHandler = new Handler() {
public void handleMessage(Message msg) { switch (msg.what) { case 0: //滚动条向下滚动,top position增加 /*int max = mLauncher.mScrollView.getMeasuredHeight(); Log.e("handleMessage", "mLauncher.mScrollView.getMaxScrollAmount()="+max);*/ /*mCurrentSelection=mCurrentSelection+3; if(mCurrentSelection<mLauncher.mAllAppsGrid.getCount()) { mLauncher.mAllAppsGrid.smoothScrollBy(distance, duration); } */ mLauncher.mAllAppsGrid.smoothScrollBy(mCurrentScroolPix,300); break; case 1: //滚动条向上滚动,top position减少 /*mCurrentSelection=mCurrentSelection-3; if(mCurrentSelection>=3) { mLauncher.mAllAppsGrid.smoothScrollToPosition(mCurrentSelection); }*/ mLauncher.mAllAppsGrid.smoothScrollBy(-mCurrentScroolPix,300); break; case 2: /*if(!mLauncher.isAllAppsVisible()) { mLauncher.HideUninstallButton(); }*/ } super.handleMessage(msg); }; };
public void addUpdateGridViewAnimations() { this.startAnimation(AnimationUtils.loadAnimation(mContext, R.anim.activity_close_enter)); } public AllAppsView(Context context) { super(context); mContext = context; m_animation = AnimationUtils.loadAnimation(mContext,R.anim.my_scale_action); setupViews(); //addView(mView); } public AllAppsView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); m_animation = AnimationUtils.loadAnimation(mContext,R.anim.my_scale_action); // TODO Auto-generated constructor stub } public AllAppsView(Context context,AttributeSet attr){ super(context,attr); mContext = context; m_animation = AnimationUtils.loadAnimation(mContext,R.anim.my_scale_action); setupViews(); //addView(mView); } public void setupViews(){ registerIntentReceivers(); loadApplications(false); /* mLayoutInflater = LayoutInflater.from(getContext()); mView = mLayoutInflater.inflate(R.layout.all_apps, null); //mHomeButton = (ImageButton)mView.findViewById(R.id.home_button); //mHomeButton.setOnClickListener(this); mGridView = (MyGridView)mView.findViewById(R.id.all_apps);*/ bindApplications(); }
public void bindApplications(){ mPositionList=LauncherModel.GetPositonOrderByType(mContext,LauncherSettings.Favorites.SORT_APPVIEWS); mApplicationsType=LauncherModel.RecombineApplicationInfo(mContext,mApplications,mPositionList); mApplications=mApplicationsType;// ArrayList<ApplicationInfo> sdataAppviews = LauncherModel.RecombineApplicationInfo(mContext,mApplications,mPositionList);// mApplications = sdataAppviews; //mApplicationsType = mApplications; if(mAppAdapter==null) { mAppAdapter=new ApplicationsAdapter(mContext); } this.setAdapter(mAppAdapter); this.setVisibility(View.VISIBLE); this.setOnItemClickListener(this); this.setOnItemLongClickListener(this); this.setAlwaysDrawnWithCacheEnabled(true); this.setAnimationCacheEnabled(false); this.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_OVERLAY); this.setScrollingCacheEnabled(true); } private void loadApplications(boolean isLaunching ) { if (isLaunching && mApplications!= null) { return; } PackageManager manager = mContext.getPackageManager();
Intent mainIntent = new Intent(Intent.ACTION_MAIN, null); mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
final List<ResolveInfo> apps = manager.queryIntentActivities(mainIntent, 0); Collections.sort(apps, new ResolveInfo.DisplayNameComparator(manager));
if (apps != null) { final int count = apps.size();
if (mApplications == null) { mApplications= new ArrayList<ApplicationInfo>(count); } mApplications.clear();
for (int i = 0; i < count; i++) { ApplicationInfo application = new ApplicationInfo(); ResolveInfo info = apps.get(i); application.title = info.loadLabel(manager); application.setActivity(new ComponentName( info.activityInfo.applicationInfo.packageName, info.activityInfo.name), Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); application.icon = info.activityInfo.loadIcon(manager);
mApplications.add(application); } } } }
/* *//** * GridView adapter to show the list of all installed applications. */ public class ApplicationsAdapter extends BaseAdapter{ private Rect mOldBounds = new Rect(); //private int mCount; public ApplicationsAdapter(Context context) { Log.i("==ApplicationsAdapter====", "===motionPosition====="+motionPosition+"====mCurrentPostion=="+mCurrentPostion); } @Override public int getCount() { // TODO Auto-generated method stub if (mApplicationsType != null) { return mApplicationsType.size(); }else { return 0; }
} @Override public Object getItem(int arg0) { // TODO Auto-generated method stub if(mApplicationsType != null&& mApplicationsType.size()>arg0){ return mApplicationsType.get(arg0); } return null; } @Override public long getItemId(int arg0) { // TODO Auto-generated method stub return arg0; } public View getView(int position, View convertView, ViewGroup parent) { //Log.i("==getView====", "===motionPosition====="+motionPosition+"====mCurrentPostion=="+mCurrentPostion); convertView = LayoutInflater.from(mContext).inflate(R.layout.application_allapps, parent, false); if(mCurrentView==null) { // Log.i("==getView====", "===motionPosition====="+motionPosition+"====mCurrentPostion=="+mCurrentPostion); final ApplicationInfo info = mApplicationsType.get(position); if(info.icon==null) { info.icon =new BitmapDrawable(info.iconBitmap); } Drawable icon = info.icon; if (false) {//!info.filtered //final Resources resources = getContext().getResources(); int width = 35;//(int) resources.getDimension(android.R.dimen.app_icon_size); int height = 35;//(int) resources.getDimension(android.R.dimen.app_icon_size); final int iconWidth = icon.getIntrinsicWidth(); final int iconHeight = icon.getIntrinsicHeight(); if (icon instanceof PaintDrawable) { PaintDrawable painter = (PaintDrawable) icon; painter.setIntrinsicWidth(width); painter.setIntrinsicHeight(height); } if (width > 0 && height > 0 && (width < iconWidth || height < iconHeight)) { final float ratio = (float) iconWidth / iconHeight; if (iconWidth > iconHeight) { height = (int) (width / ratio); } else if (iconHeight > iconWidth) { width = (int) (height * ratio); } final Bitmap.Config c = icon.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565; final Bitmap thumb = Bitmap.createBitmap(width, height, c); final Canvas canvas = new Canvas(thumb); canvas.setDrawFilter(new PaintFlagsDrawFilter(Paint.DITHER_FLAG, 0)); mOldBounds.set(icon.getBounds()); icon.setBounds(0, 0, width, height); icon.draw(canvas); icon.setBounds(mOldBounds); icon = info.icon = new BitmapDrawable(thumb); info.filtered = true; } } final TextView textView = (TextView) convertView.findViewById(R.id.label); final ImageView imageView = (ImageView) convertView.findViewById(R.id.appicon); imageView.setBackgroundDrawable(icon); textView.setTextColor(Color.BLACK); textView.setText(info.title); }else { if(position==mCurrentPostion) { convertView.setBackgroundColor(android.R.color.transparent); }else{ ApplicationInfo info=null; if(position>mCurrentPostion&&position<=motionPosition)//向 上 滑 动 { int movePostion=position-1;// Log.i("==getView()=", "==== movePostion=position-1==motionPosition"+motionPosition+"===mCurrentPostion==="+mCurrentPostion);// Log.i("==getView()=", "==== movePostion=position-1==movePostion"+movePostion+"===position==="+position); if(movePostion>=0) { info = mApplicationsType.get(movePostion); } }else if(position>=motionPosition&&position<mCurrentPostion) { int movePostion=position+1;// Log.i("==getView()=", "====movePostion=position+1==motionPosition"+motionPosition+"===mCurrentPostion==="+mCurrentPostion);// Log.i("==getView()=", "====movePostion=position+1==movePostion"+movePostion+"===position==="+position); if(movePostion>=0&&movePostion<mApplicationsType.size()) { info = mApplicationsType.get(movePostion); } }else{ Log.i("==getView()=", "===position==="+position); info = mApplicationsType.get(position); } if(info.icon==null) { info.icon =new BitmapDrawable(info.iconBitmap); } Drawable icon = info.icon; if (false) {//!info.filtered int width = 35; int height = 35; final int iconWidth = icon.getIntrinsicWidth(); final int iconHeight = icon.getIntrinsicHeight(); if (icon instanceof PaintDrawable) { PaintDrawable painter = (PaintDrawable) icon; painter.setIntrinsicWidth(width); painter.setIntrinsicHeight(height); } if (width > 0 && height > 0 && (width < iconWidth || height < iconHeight)) { final float ratio = (float) iconWidth / iconHeight; if (iconWidth > iconHeight) { height = (int) (width / ratio); } else if (iconHeight > iconWidth) { width = (int) (height * ratio); } final Bitmap.Config c = icon.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565; final Bitmap thumb = Bitmap.createBitmap(width, height, c); final Canvas canvas = new Canvas(thumb); canvas.setDrawFilter(new PaintFlagsDrawFilter(Paint.DITHER_FLAG, 0)); mOldBounds.set(icon.getBounds()); icon.setBounds(0, 0, width, height); icon.draw(canvas); icon.setBounds(mOldBounds); icon = info.icon = new BitmapDrawable(thumb); info.filtered = true; } } final TextView textView = (TextView) convertView.findViewById(R.id.label); final ImageView imageView = (ImageView) convertView.findViewById(R.id.appicon); imageView.setBackgroundDrawable(icon); // textView.setCompoundDrawablesWithIntrinsicBounds(null, icon, null, null); textView.setTextColor(Color.BLACK); textView.setText(info.title); } } return convertView; } } public void onItemClick(AdapterView<?> parent, View v, int position, long id) { if(parent.getItemAtPosition(position) instanceof ApplicationInfo) { ApplicationInfo app = (ApplicationInfo) parent.getItemAtPosition(position); LauncherModel.addOrupdateLatestDB(mContext,app.intent.getComponent().getPackageName()); mContext.startActivity(app.intent); }else if(parent.getItemAtPosition(position) instanceof ShortcutInfo) { ShortcutInfo app = (ShortcutInfo) parent.getItemAtPosition(position); LauncherModel.addOrupdateLatestDB(mContext,app.intent.getComponent().getPackageName()); mContext.startActivity(app.intent); } } public void onClick(View v) {
//mLauncher.closeAllApps(true);//mod:lsj } void setLauncher(Launcher launcher){ mLauncher = launcher; }//mod:lsj/* boolean isVisible(){ return isVisible; } public void setVisible(boolean visible){ this.isVisible = visible; }*/
public void onDropCompleted(View target, boolean success) { // TODO Auto-generated method stub }
public void setDragController(DragController dragger) { mDragController = dragger; }
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { if (!view.isInTouchMode()) { return false; } /*Animation animation=AnimationUtils.loadAnimation(mContext,R.anim.my_scale_action); view.startAnimation(animation);*/ //mCurrentgridviewitem = view; //view.setBackgroundDrawable(getResources().getDrawable(R.drawable.itembackground)); //view.invalidate(); if (parent.getItemAtPosition(position) instanceof ApplicationInfo) { mLauncher.VisibleUninstallZoneView(true); mLauncher.inVisibleDeleteZoneView(false);//allappviews,ususally,recent no need delete ApplicationInfo app = (ApplicationInfo) parent.getItemAtPosition(position); app = new ApplicationInfo(app); mDragController.startDrag(view, this, app,DragController.DRAG_ACTION_MOVE); mIsApplication=true; } else if (parent.getItemAtPosition(position) instanceof ShortcutInfo) { mLauncher.VisibleUninstallZoneView(true); mLauncher.inVisibleDeleteZoneView(true); ShortcutInfo app = (ShortcutInfo) parent .getItemAtPosition(position); app = new ShortcutInfo(app); mDragController.startDrag(view, this, app,DragController.DRAG_ACTION_MOVE); mIsApplication=false; } return true;
} public void setApps(ArrayList<ApplicationInfo> list) { mAllAppsList.clear(); addApps(list); }
public void addApps(ArrayList<ApplicationInfo> list) { final int N = list.size(); for (int i=0; i<N; i++) { final ApplicationInfo item = list.get(i); int index = Collections.binarySearch(mAllAppsList, item, LauncherModel.APP_NAME_COMPARATOR); if (index < 0) { index = -(index+1); } mAllAppsList.add(index, item); } }
public void removeApps(ArrayList<ApplicationInfo> list) { final int N = list.size(); for (int i=0; i<N; i++) { final ApplicationInfo item = list.get(i); int index = findAppByComponent(mAllAppsList, item); if (index >= 0) { mAllAppsList.remove(index); } else { } } }
public void updateApps(ArrayList<ApplicationInfo> list) { // Just remove and add, because they may need to be re-sorted. removeApps(list); addApps(list); }
private static int findAppByComponent(ArrayList<ApplicationInfo> list, ApplicationInfo item) { ComponentName component = item.intent.getComponent(); final int N = list.size(); for (int i=0; i<N; i++) { ApplicationInfo x = list.get(i); if (x.intent.getComponent().equals(component)) { return i; } } return -1; } /*@Override public void onDragStart(DragSource source, Object info, int dragAction) { } @Override public void onDragEnd() {//拖动完成响应数据更新,GridView更新// mCurrentView=null;// if(mCurrentPostion>=0)// {// Log.i("==AllAppsView=========", "======onDragEnd======");// getCurrentApplicationPosition(mContext,mLauncher.mApplicationType);// }else// {// this.upateGridView(mLauncher.mApplicationType); // } }*/ @Override public void onDrop(DragSource source, int x, int y, int xOffset, int yOffset, DragView dragView, Object dragInfo) { // 取消定时器 if (mTimer != null) { mTimer.cancel(); mTimer.purge(); mTimer = null; Log.e("onDrop", "Timer is canceled!"); } mIsDroped = true; mCurrentX=x; mCurrentY=y; //Log.i("==AllAppsView=========", "======onDrop======"); //先后顺序: onDragExit,onDragEnd onDrageExit 是离开当前view的范围后才调用这个方法 final ItemInfo itemInfo = (ItemInfo) dragInfo; if(source instanceof Workspace) { }else{ // addCurrentOverAppview(); mCurrentX=x;//113 mCurrentY=y;//191 Log.i("==AllAppsView====onDrop=","==mCurrentPostion=="+mCurrentPostion+"==motionPosition="+motionPosition+"mIsOver=="+mIsOver); if(mIsOver) { mCurrentView=null; getCurrentApplicationPosition(mContext,mLauncher.mApplicationType); //this.smoothScrollToPosition(mCurrentPostion); //this.smoothScrollToPosition(mCurrentPostion, mCurrentPostion+6); //this.smoothScrollToPosition(mCurrentPostion); //this.setSelection(mCurrentPostion-(mFirstY/81)*3); }else { mCurrentView=null; //this.upateGridView(mLauncher.mApplicationType); this.invalidateViews(); } Log.i("====AllAppsView===========","====mFirstY====="+mFirstY); } } @Override public void onDragEnter(DragSource source, int x, int y, int xOffset, int yOffset, DragView dragView, Object dragInfo) { mIsDroped = false; if(source instanceof Workspace) { }else { //deleteCurrentOverAppview(); } //Log.i("==AllAppsView=========", "======onDragEnter======"); } @Override public void onDragOver(DragSource source, int x, int y, int xOffset, int yOffset, DragView dragView, Object dragInfo) { //x:1-171dp y:1-408dp reference launcher.xml final ItemInfo itemInfo = (ItemInfo) dragInfo; if(source instanceof Workspace) { }else { mCurrentX=x; mCurrentY=y; Log.i("====onDragOver===", "===mCurrentX===="+mCurrentX+"====mCurrentY=="+mCurrentY+"====mLauncher.mLauncherY==="); mOldCurrentPositon=mCurrentPostion; // mCurrentPostion=this.pointToPosition(x, y)-this.getFirstVisiblePosition(); int nTmp = this.pointToPosition(x, y); if(nTmp>=0&&nTmp<this.getCount()) { mCurrentPostion= nTmp; mIsOver=true; }else { mIsOver=false; } /*rcBottom.set(135, 400,306,480); rcTop.set(135, 10, 306, 80);*/
// 开启定时器 if (mTimer == null) { mTimer = new Timer(); mTimer.schedule(new TimerTask() { @Override public void run() { if (mIsDroped == false) { if(mContext.getResources().getConfiguration().orientation==ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) { Log.i("===dragover======", "====SCREEN_ORIENTATION_PORTRAIT======"); if (DragController.mLauncherY>730) { Message msg = new Message(); msg.what =0; mHandler.sendMessage(msg); }else if(DragController.mLauncherY<440&&DragController.mLauncherY>405) { Message msg = new Message(); msg.what = 1; mHandler.sendMessage(msg); } }else//(mContext.getResources().getConfiguration().orientation==ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) { Log.i("=====dragover====", "====ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE======"); if (DragController.mLauncherY>410) { Message msg = new Message(); msg.what =0; mHandler.sendMessage(msg); }else if(DragController.mLauncherY<50) { Message msg = new Message(); msg.what = 1; mHandler.sendMessage(msg); } } } } },50, 100); } //Log.i("==AllAppsView=onDragOver==", "==mCurrentX=="+mCurrentX+"==mCurrentY="+mCurrentY+"==mCurrentPostion=="+mCurrentPostion); if(mIsOver==true) { mCurrentView=this.getChildAt(this.pointToPosition(x, y) - this.getFirstVisiblePosition()); if(mCurrentPostion!=mOldCurrentPositon)//if(x>40||y>50) { if(mIsUpdateOver) { mIsUpdateOver=false; Log.i("===AllAppsView ==οndragοver==", "======mCurrentPostion=="+mCurrentPostion); if(mCurrentPostion>=0) { this.invalidateViews(); } Log.i("=====onDragOver==", "========"+y); mIsUpdateOver=true; } } } } } @Override public void onDragExit(DragSource source, int x, int y, int xOffset, int yOffset, DragView dragView, Object dragInfo) { Log.i("====AllAppsView===========","====onDragExit====y="+y); /* //先后顺序: onDragExit,onDragEnd,onDrop onDrageExit 是离开当前view的范围后才调用这个方法 final ItemInfo itemInfo = (ItemInfo) dragInfo; if(source instanceof Workspace) { }else{ // addCurrentOverAppview(); mCurrentX=x;//113 mCurrentY=y;//191 mCurrentView=null; Log.i("====AllAppsView===========","====onDragExit====="); if(mCurrentPostion>=0) { getCurrentApplicationPosition(mContext,mLauncher.mApplicationType); }else { this.upateGridView(mLauncher.mApplicationType); } Log.i("====AllAppsView===========","====mFirstY====="+mFirstY); this.setSelection(mCurrentPostion-(mFirstY/81)*3); }*/ mCurrentView=null; this.upateGridView(mLauncher.mApplicationType,false); // 取消定时器 if (mTimer != null) { mTimer.cancel(); mTimer.purge(); mTimer = null; Log.e("onDrop", "Timer is canceled!"); } mIsDroped = true;
} @Override public boolean acceptDrop(DragSource source, int x, int y, int xOffset, int yOffset, DragView dragView, Object dragInfo) { return true; } @Override public Rect estimateDropLocation(DragSource source, int x, int y, int xOffset, int yOffset, DragView dragView, Object dragInfo, Rect recycle) { return null; } /** * function: * @param context */ void getCurrentApplicationPosition(Context context,int nType){ //addCurrentOverAppview(); ApplicationInfo firstApp=null; ShortcutInfo firstShortcutApp=null; int nsize=0; switch(nType)//如果当前位置为小于零的要不进入.mCurrentPostion有为小于零的现象 { case LauncherSettings.Favorites.SORT_APPVIEWS: mPositionList.clear(); nsize=mApplications.size();//original data size Log.i("====getCurrentApplicationPosition====", "======mApplications.size====="+nsize); firstApp=mApplications.get(motionPosition); mApplications.remove(motionPosition); mApplications.add(mCurrentPostion,firstApp); for(int i = 0;i < nsize;i++ ){//重新封装位置数据 mPositionList.add(new PositionOrderInfo(-1,LauncherSettings.Favorites.SORT_APPVIEWS,i,mApplications.get(i).intent.getComponent().getPackageName())); } //更新数据到数据库 ,并重新刷新数据到表格中 LauncherModel.UpdatePositionOrder(context,LauncherSettings.Favorites.SORT_APPVIEWS,mPositionList); this.upateGridView(LauncherSettings.Favorites.SORT_APPVIEWS,false); break; case LauncherSettings.Favorites.SORT_USUALLY: mUsuallyPositionList.clear(); nsize=usuallyList.size(); firstApp=usuallyList.get(motionPosition); usuallyList.remove(motionPosition); usuallyList.add(mCurrentPostion,firstApp); for(int i = 0;i < nsize;i++ ){ mUsuallyPositionList.add(new PositionOrderInfo(-1,LauncherSettings.Favorites.SORT_USUALLY,i,usuallyList.get(i).intent.getComponent().getPackageName())); } LauncherModel.UpdatePositionOrder(context,LauncherSettings.Favorites.SORT_USUALLY,mUsuallyPositionList); this.upateGridView(LauncherSettings.Favorites.SORT_USUALLY,false); break; case LauncherSettings.Favorites.SORT_LATEST: mLatestPositionList.clear(); nsize=latestList.size(); firstApp=latestList.get(motionPosition); latestList.remove(motionPosition); latestList.add(mCurrentPostion,firstApp); for(int i = 0;i < nsize;i++ ){ mLatestPositionList.add(new PositionOrderInfo(-1,LauncherSettings.Favorites.SORT_LATEST,i,latestList.get(i).intent.getComponent().getPackageName())); } LauncherModel.UpdatePositionOrder(context,LauncherSettings.Favorites.SORT_LATEST,mLatestPositionList); this.upateGridView(LauncherSettings.Favorites.SORT_LATEST,false); break; case LauncherSettings.Favorites.SORT_AMUSEMENT: mAmusementPositionList.clear(); nsize=amusementlist.size(); firstShortcutApp=amusementlist.get(motionPosition); amusementlist.remove(motionPosition); amusementlist.add(mCurrentPostion,firstShortcutApp); for(int i = 0;i < nsize;i++ ){ mAmusementPositionList.add(new PositionOrderInfo(-1,LauncherSettings.Favorites.SORT_AMUSEMENT,i,amusementlist.get(i).intent.getComponent().getPackageName())); } LauncherModel.UpdatePositionOrder(context,LauncherSettings.Favorites.SORT_AMUSEMENT,mAmusementPositionList); this.upateGridView(LauncherSettings.Favorites.SORT_AMUSEMENT,false); break; case LauncherSettings.Favorites.SORT_MEDIA: mMediaPositionList.clear(); nsize=medialist.size(); firstShortcutApp=medialist.get(motionPosition); medialist.remove(motionPosition); medialist.add(mCurrentPostion,firstShortcutApp); for(int i = 0;i < nsize;i++ ){ mMediaPositionList.add(new PositionOrderInfo(-1,LauncherSettings.Favorites.SORT_MEDIA,i,medialist.get(i).intent.getComponent().getPackageName())); } LauncherModel.UpdatePositionOrder(context,LauncherSettings.Favorites.SORT_MEDIA,mMediaPositionList); this.upateGridView(LauncherSettings.Favorites.SORT_MEDIA,false); break; case LauncherSettings.Favorites.SORT_OFFICE: mOfficePositionList.clear(); nsize=officelist.size(); firstShortcutApp=officelist.get(motionPosition); officelist.remove(motionPosition); officelist.add(mCurrentPostion,firstShortcutApp); for(int i = 0;i < nsize;i++ ){ mOfficePositionList.add(new PositionOrderInfo(-1,LauncherSettings.Favorites.SORT_OFFICE,i,officelist.get(i).intent.getComponent().getPackageName())); } LauncherModel.UpdatePositionOrder(context,LauncherSettings.Favorites.SORT_OFFICE,mOfficePositionList); this.upateGridView(LauncherSettings.Favorites.SORT_OFFICE,false); break; case LauncherSettings.Favorites.SORT_TOOLS: mToolsPositionList.clear(); nsize=toollist.size(); firstShortcutApp=toollist.get(motionPosition); toollist.remove(motionPosition); toollist.add(mCurrentPostion,firstShortcutApp); for(int i = 0;i < nsize;i++ ){ mToolsPositionList.add(new PositionOrderInfo(-1,LauncherSettings.Favorites.SORT_TOOLS,i,toollist.get(i).intent.getComponent().getPackageName())); } LauncherModel.UpdatePositionOrder(context,LauncherSettings.Favorites.SORT_TOOLS,mToolsPositionList); this.upateGridView(LauncherSettings.Favorites.SORT_TOOLS,false); break; default:break; } } @Override public boolean onTouchEvent(MotionEvent event) { int height=this.getMeasuredHeight(); final int x = (int) event.getX(); final int y = (int) event.getY(); switch(event.getAction()) { case MotionEvent.ACTION_DOWN: mFirstY=y; motionPosition = this.pointToPosition(x, y); //Log.i("==MyGridview==onTouchEvent====", "==motionPosition="+motionPosition); mFirstClickPosition=this.getFirstVisiblePosition(); // Log.i("======onTouchEvent======", "=y="+y); // Log.i("======onTouchEvent======", "=mFirstClickPosition="+mFirstClickPosition); if (motionPosition >= 0) { v = getChildAt(motionPosition - this.getFirstVisiblePosition()); v.startAnimation(m_animation); } break; case MotionEvent.ACTION_MOVE: mFirstY=y; Log.i("======onTouchEvent======", "=y="+y); break; } return super.onTouchEvent(event); }}