shake phone and rearrange workspace apps
来源:互联网 发布:农业大数据公司有哪些 编辑:程序博客网 时间:2024/05/21 19:24
新增功能,基本上国内手机产商都会加上的功能,其实主要做的就是桌面图标重新排列的算法。
Launcher.java继承SensorEventListener重写监听接口
@Overridepublic void onSensorChanged(SensorEvent event) {// TODO Auto-generated method stub int sensorType = event.sensor.getType(); float[] values = event.values; long vibrateTime = 200L; if (sensorType == Sensor.TYPE_ACCELEROMETER) { int value = 15; if ((Math.abs(values[0]) > value || Math.abs(values[1]) > value || Math .abs(values[2]) > value + 10)) { if (mWorkspace.isInOverviewMode()){ if (CommonUtils.isFastDoubleClick()) { } else { mWorkspace.rearrangeApps(); mVibrator.vibrate(vibrateTime); } } } } }CommonUtils 这个类是防止连续触发用的
class CommonUtils { private static long lastClickTime; public static boolean isFastDoubleClick() { long time = System.currentTimeMillis(); long timeD = time - lastClickTime; if ( 0 < timeD && timeD < 1000) { return true; } lastClickTime = time; return false; }}
workspace.java
public void rearrangeApps(){ int count = getChildCount(); for (int i=0 ; i<count ; i++ ){ long screenID = getScreenIdForPageIndex(i); if (screenID == CUSTOM_CONTENT_SCREEN_ID){ continue; } if (i == 1){ CellLayout cl = (CellLayout)getChildAt(i); cl.setUseTempCoords(false); cl.rearrangeHomePage(); } else { CellLayout cl = (CellLayout)getChildAt(i); cl.setUseTempCoords(false); cl.rearrangeAppItems(); } } }
CellLayout.java
public void rearrangeAppItems(){ ArrayList<View> list = new ArrayList<View>(); ArrayList<String> blackList = new ArrayList<String>(); int neadReoderSize = getShortcutsAndWidgets().getChildCount(); for (int i=0; i<getShortcutsAndWidgets().getChildCount(); i++){ View tempView = getShortcutsAndWidgets().getChildAt(i); list.add(tempView); ItemInfo info = (ItemInfo) tempView.getTag(); if (info.spanX > 1 || info.spanY > 1){ neadReoderSize --; for (int y=info.cellY; y<info.cellY+info.spanY; y++){ for (int x=info.cellX; x<info.cellX+info.spanX; x++){ int a = x + y*4; blackList.add(a + ""); if (a < neadReoderSize) { neadReoderSize ++; } } } } } for (int i=0; i<list.size(); i++){ ItemInfo info = (ItemInfo) list.get(i).getTag(); if (info.spanX > 1 || info.spanY > 1){ } else { int oldPosition = info.cellX + info.cellY*4; if (oldPosition < neadReoderSize ) { blackList.add(oldPosition + ""); info.neadReoder = false; } else { info.neadReoder = true; } } } // getShortcutsAndWidgets().removeAllViews(); int position = 0; int newX, newY, rank; rank = 0; InvariantDeviceProfile grid = LauncherAppState.getInstance().getInvariantDeviceProfile(); for (int i=0; i<list.size(); i++){ View v = list.get(i); if (v != null){// CellLayout.LayoutParams lp = (CellLayout.LayoutParams) v.getLayoutParams(); newX = position % grid.numColumns; newY = position / grid.numColumns; ItemInfo info = (ItemInfo) v.getTag(); if (blackList != null){ while(blackList.contains(position + "")){ newX ++; rank ++; position++; if (newX > 3){ newY++; newX = 0; } } } if (info.cellX != newX || info.cellY != newY || info.rank != rank) { if (info.spanX == 1 && info.spanY == 1 & info.neadReoder ){ info.cellX = newX; info.cellY = newY; info.rank = rank; if (animateChildToPosition(v, info.cellX, info.cellY, REORDER_ANIMATION_DURATION, 0, true, true)){ Log.d("txk", "info.title=" + info.title + "; info.cellX=" + info.cellX + "; info.cellY=" + info.cellY + ";newX=" + newX + ";newY=" + newY); LauncherModel.modifyItemInDatabase(getContext(), info, info.container, info.screenId, info.cellX, info.cellY, info.spanX, info.spanY); } } else { rank --; position --; } } } rank ++; position++; } } public void rearrangeHomePage(){ ArrayList<View> list = new ArrayList<View>(); ArrayList<String> blackList = new ArrayList<String>(); int neadReoderSize = 20 - getShortcutsAndWidgets().getChildCount(); for (int i=0; i<getShortcutsAndWidgets().getChildCount(); i++){ View tempView = getShortcutsAndWidgets().getChildAt(i); list.add(tempView); ItemInfo info = (ItemInfo) tempView.getTag(); if (info.spanX > 1 || info.spanY > 1){ neadReoderSize ++; for (int y=info.cellY; y<info.cellY+info.spanY; y++){ for (int x=info.cellX; x<info.cellX+info.spanX; x++){ int a = x + y*4; blackList.add(a + ""); if (a > neadReoderSize) { neadReoderSize --; } } } } } for (int i=0; i<list.size(); i++){ ItemInfo info = (ItemInfo) list.get(i).getTag(); if (info.spanX > 1 || info.spanY > 1){ } else { int oldPosition = info.cellX + info.cellY*4; if (oldPosition > neadReoderSize ) { blackList.add(oldPosition + ""); info.neadReoder = false; } else { info.neadReoder = true; } } }// getShortcutsAndWidgets().removeAllViews(); InvariantDeviceProfile grid = LauncherAppState.getInstance().getInvariantDeviceProfile(); int position = grid.numRows * grid.numColumns - 1; int newX, newY, rank; rank = grid.numRows * grid.numColumns - 1; for (int i=0; i<list.size(); i++){ View v = list.get(i); if (v != null){// CellLayout.LayoutParams lp = (CellLayout.LayoutParams) v.getLayoutParams(); newX = position % grid.numColumns; newY = position / grid.numColumns; ItemInfo info = (ItemInfo) v.getTag(); if (blackList != null){ while(blackList.contains(position + "")){ newX --; rank --; position --; if (newX < 0 ){ newY--; newX = 3; } } } if (info.cellX != newX || info.cellY != newY || info.rank != rank) { if (info.spanX == 1 && info.spanY == 1 & info.neadReoder ){ info.cellX = newX; info.cellY = newY; info.rank = rank; if (animateChildToPosition(v, info.cellX, info.cellY, REORDER_ANIMATION_DURATION, 0, true, true)){ LauncherModel.modifyItemInDatabase(getContext(), info, info.container, info.screenId, info.cellX, info.cellY, info.spanX, info.spanY); } } else { rank ++; position ++; } } } rank --; position--; } }
0 0
- shake phone and rearrange workspace apps
- shake
- SHAKE
- shake
- Native Apps, Web Apps, and Hybrid Apps
- Rearrange an array of positive and negative integers
- Workspace, notbook and DocBook
- Top Grossing Apps and cocos2d
- django installed on APPS and ...
- swirl 2: Workspace and Files
- Rearrange int array to put odd number to left and even to right
- Websites for iOS apps and OS X apps
- Windows Phone 7 & “native” apps, the missing link!
- Apple 正式进军 Android 及 Windows Phone Apps
- shake插补器
- windows phone:Using the SQLite database engine with Windows Phone 8 apps
- Threads and Pipes in Console Apps
- Dirty Apps and Dirty Marketing Tricks
- Android Activity为什么要细化出onCreate、onStart、onResume、onPause、onStop、onDesdroy这么多方法让应用去重载?
- C:指针
- JS表单验证
- DWZ
- Java AWT实践——NoteBook
- shake phone and rearrange workspace apps
- 一种融合异构信息网络和评分矩阵的推荐新算法
- js表单验证控制代码大全
- MySql 启动失败,提示:NET HELPMSG 3534 以获得更多的帮助
- 网吧计费系统数据库修复/网吧收银系统数据库恢复
- 第十三周项目54-交通工具类
- 整理一下常用的Linux命令(1)(未完待续)
- Java的hashcode的作用
- 数据预处理技术