Android Launcher 部分修改(6.0)
这些天小小地修改了下6.0的Launcher,零零散散找了很多资料,现将有用到的部分在此汇个总,做个笔记
有些修改后需格式化刷机
-
- Android Launcher 部分修改(6.0)
- Hotset横屏展示
- 隐藏桌面上的图标
- 去掉Google原生系统里面的搜索条。
- Launcher3桌面的行数和列数是动态计算的,如何修改?
- Android Launcher 部分修改(6.0)
Hotset横屏展示
config.xml中<bool name="hotseat_transpose_layout_with_orientation">false</bool>hotseat.java 中onFinishInflate()方法// 屏蔽其它方向设置//if (grid.isLandscape && !grid.isLargeTablet) {// mContent.setGridSize(1, (int) grid.inv.numHotseatIcons);//} else {// 固定横屏底部展示mContent.setGridSize((int) grid.inv.numHotseatIcons, 1);//}
隐藏桌面上的图标
Y:\mggd\android\device\softwinner\astar-d7\overlay\packages\apps\Launcher3\res\xml\default_workspace_5x6.xml
在default_workspace.xml中注释掉要隐藏的内容
示例:
<favorites xmlns:launcher="http://schemas.android.com/apk/res-auto/com.android.launcher3"><!-- 屏蔽时钟小部件 --><!--<appwidgetlauncher:packageName="com.android.deskclock"launcher:className="com.android.alarmclock.AnalogAppWidgetProvider"launcher:screen="1"launcher:x="1"launcher:y="0"launcher:spanX="2"launcher:spanY="2" />--><folder launcher:title="@string/naming_is_Google"launcher:screen="1"launcher:x="5"launcher:y="4" ><favorite launcher:className="com.google.android.apps.chrome.Main"launcher:packageName="com.android.chrome" />......<favorite launcher:className="com.google.android.talk.SigningInActivity"launcher:packageName="com.google.android.talk" /></folder><!-- Hotseat 部件 --><!-- Hotseat (We use the screen as the position of the item in the hotseat) --><!-- Dialer, Contacts, [All Apps], Messaging, Browser --><!-- 隐藏 相机 按钮 --><!-- <favoritelauncher:packageName="com.android.camera2"launcher:className="com.android.camera.CameraLauncher"launcher:container="-101"launcher:screen="0"launcher:x="0"launcher:y="0" /> --><!-- 隐藏浏览器 --><!-- <resolvelauncher:container="-101"launcher:screen="1"launcher:x="1"launcher:y="0" ><favoritelauncher:uri="#Intent;action=android.intent.action.MAIN;category=android.intent.category.APP_BROWSER;end" /><favorite launcher:uri="http://www.example.com/" /><favoritelauncher:packageName="com.android.browser"launcher:className="com.android.browser.BrowserActivity" /></resolve> --><!-- 隐藏设置 --><!-- <resolvelauncher:container="-101"launcher:screen="4"launcher:x="4"launcher:y="0" ><favoritelauncher:uri="#Intent;action=android.settings.SETTINGS;end" /></resolve> --><!-- 把 设置 按钮从 Hotseat 中移动到桌面 --><resolve launcher:screen="3"launcher:x="2"launcher:y="3" ><favorite launcher:uri="#Intent;action=android.settings.SETTINGS;end" /></resolve> <favorite launcher:packageName="com.google.android.music"launcher:className="com.android.music.activitymanagement.TopLevelActivity"launcher:container="-101"launcher:screen="5"launcher:x="5"launcher:y="0" /><favorite launcher:packageName="com.google.android.apps.photos"launcher:className="com.google.android.apps.photos.home.HomeActivity"launcher:container="-101"launcher:screen="6"launcher:x="6"launcher:y="0" /></favorites>
去掉Google原生系统里面的搜索条。
* Android 6.0 *
在Launcher3里面src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java
--- a/src/com/android/launcher3/Launcher.java
+++ b/src/com/android/launcher3/Launcher.java
@@ -3465,6 +3465,10 @@ public class Launcher extends Activity}public View getOrCreateQsbBar() {
+
+ if(true){
+ return null;
+ }if (mLauncherCallbacks != null && mLauncherCallbacks.providesSearch()) {return mLauncherCallbacks.getQsbBar();}
直接返回null,就OK;
* Android 7.1 系统 *
diff --git a/res/layout-land/launcher.xml b/res/layout-land/launcher.xml
index 3a25d68..1247875 100644
--- a/res/layout-land/launcher.xml
+++ b/res/layout-land/launcher.xml
@@ -65,11 +65,11 @@
android:layout_marginBottom="30dp"/><!-- A place holder view instead of the QSB in transposed layout -->
- <View
+ <!-- <View
android:layout_width="0dp"
android:layout_height="10dp"
android:id="@+id/workspace_blocked_row" />
-
+-->
<include layout="@layout/widgets_view"
android:id="@+id/widgets_view"
android:layout_width="match_parent"
diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java
index 2c9dc3e..cd922b8 100755
--- a/src/com/android/launcher3/Launcher.java
+++ b/src/com/android/launcher3/Launcher.java
@@ -1324,7 +1324,9 @@ public class Launcher extends Activity mLauncherView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
-
+ //add by neil
+ mDragLayer.removeView(mQsbContainer);
+ //end
// Setup the drag layer
mDragLayer.setup(this, mDragController, mAllAppsController);diff --git a/src/com/android/launcher3/LauncherModel.java b/src/com/android/launcher3/LauncherModel.java
index 3ac9773..d3b6224 100644
--- a/src/com/android/launcher3/LauncherModel.java
+++ b/src/com/android/launcher3/LauncherModel.java
@@ -1620,11 +1620,11 @@ public class LauncherModel extends BroadcastReceiverif (!occupied.containsKey(item.screenId)) {
GridOccupancy screen = new GridOccupancy(countX + 1, countY + 1);
- if (item.screenId == Workspace.FIRST_SCREEN_ID) {
+ // if (item.screenId == Workspace.FIRST_SCREEN_ID) {
// Mark the first row as occupied (if the feature is enabled)
// in order to account for the QSB.
- screen.markCells(0, 0, countX + 1, 1, FeatureFlags.QSB_ON_FIRST_SCREEN);
- }
+ // screen.markCells(0, 0, countX + 1, 1, FeatureFlags.QSB_ON_FIRST_SCREEN);
+ // }
occupied.put(item.screenId, screen);
}
final GridOccupancy occupancy = occupied.get(item.screenId);
diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java
index 340177d..2297ee4 100644
--- a/src/com/android/launcher3/Workspace.java
+++ b/src/com/android/launcher3/Workspace.java
@@ -618,7 +618,7 @@ public class Workspace extends PagedView });
}
// Always add a QSB on the first screen.
- if (qsb == null) {
+ /* if (qsb == null) { // In transposed layout, we add the QSB in the Grid. As workspace does not touch the // edges, we do not need a full width QSB. qsb = mLauncher.getLayoutInflater().inflate( @@ -626,12 +626,12 @@ public class Workspace extends PagedView ? R.layout.qsb_container : R.layout.qsb_blocker_view, firstPage, false); } - - CellLayout.LayoutParams lp = new CellLayout.LayoutParams(0, 0, firstPage.getCountX(), 1); - lp.canReorder = false; - if (!firstPage.addViewToCellLayout(qsb, 0, getEmbeddedQsbId(), lp, true)) { +*/
+ // CellLayout.LayoutParams lp = new CellLayout.LayoutParams(0, 0, firstPage.getCountX(), 1);
+ // lp.canReorder = false;
+ /* if (!firstPage.addViewToCellLayout(qsb, 0, getEmbeddedQsbId(), lp, true)) { Log.e(TAG, "Failed to add to item at (0, 0) to CellLayout"); - } + }*/
}@Override
@@ -779,6 +779,9 @@ public class Workspace extends PagedView CellLayout customScreen = getScreenWithId(CUSTOM_CONTENT_SCREEN_ID);
int spanX = customScreen.getCountX();
int spanY = customScreen.getCountY();+ android.util.Log.i("neil","spanX = "+spanX+"spanY = "+spanY);
+
CellLayout.LayoutParams lp = new CellLayout.LayoutParams(0, 0, spanX, spanY);
lp.canReorder = false;
lp.isFullscreen = true;
7.1系统隐藏谷歌搜索未测试
Launcher3桌面的行数和列数是动态计算的,如何修改?
* 桌面行、列计算部分转自 LYJ的IT生活 *
Launcher3桌面的行数和列数都是在InvariantDeviceProfile.java和DeviceProfile.java中动态计算的,xml中无法配置。
Note:L版本无InvariantDeviceProfile.java,是DynamicGrid.java,但是计算方法都是一样的。
InvariantDeviceProfile中用InvariantDeviceProfile来配置各种屏幕的手机桌面。
ArrayList<InvariantDeviceProfile> getPredefinedDeviceProfiles() {ArrayList<InvariantDeviceProfile> predefinedDeviceProfiles = new ArrayList<>();// width, height, #rows, #columns, #folder rows, #folder columns,// iconSize, iconTextSize, #hotseat, #hotseatIconSize, defaultLayoutId.predefinedDeviceProfiles.add(new InvariantDeviceProfile("Super Short Stubby",255, 300, 2, 3, 2, 3, 3, 48, 13, 3, 48, R.xml.default_workspace_4x4));predefinedDeviceProfiles.add(new InvariantDeviceProfile("Shorter Stubby",255, 400, 3, 3, 3, 3, 3, 48, 13, 3, 48, R.xml.default_workspace_4x4));predefinedDeviceProfiles.add(new InvariantDeviceProfile("Short Stubby",275, 420, 3, 4, 3, 4, 4, 48, 13, 5, 48, R.xml.default_workspace_4x4));predefinedDeviceProfiles.add(new InvariantDeviceProfile("Stubby",255, 450, 3, 4, 3, 4, 4, 48, 13, 5, 48, R.xml.default_workspace_4x4));predefinedDeviceProfiles.add(new InvariantDeviceProfile("Nexus S",296, 491.33f, 4, 4, 4, 4, 4, 48, 13, 5, 48, R.xml.default_workspace_4x4));predefinedDeviceProfiles.add(new InvariantDeviceProfile("Nexus 4",335, 567, 4, 4, 4, 4, 4, DEFAULT_ICON_SIZE_DP, 13, 5, 56, R.xml.default_workspace_4x4));predefinedDeviceProfiles.add(new InvariantDeviceProfile("Nexus 5",359, 567, 4, 4, 4, 4, 4, DEFAULT_ICON_SIZE_DP, 13, 5, 56, R.xml.default_workspace_4x4));predefinedDeviceProfiles.add(new InvariantDeviceProfile("Large Phone",406, 694, 5, 5, 4, 4, 4, 64, 14.4f, 5, 56, R.xml.default_workspace_5x5));// The tablet profile is odd in that the landscape orientation// also includes the nav bar on the sidepredefinedDeviceProfiles.add(new InvariantDeviceProfile("Nexus 7",//575, 904, 5, 6, 4, 5, 4, 72, 14.4f, 7, 60, R.xml.default_workspace_5x6));// 更改桌面行数为 4 * 5575, 904, 4, 5, 4, 5, 4, 72, 14.4f, 7, 60, R.xml.default_workspace_5x6));// Larger tablet profiles always have system bars on the top & bottompredefinedDeviceProfiles.add(new InvariantDeviceProfile("Nexus 10",727, 1207, 5, 6, 4, 5, 4, 76, 14.4f, 7, 64, R.xml.default_workspace_5x6));predefinedDeviceProfiles.add(new InvariantDeviceProfile("20-inch Tablet",1527, 2527, 7, 7, 6, 6, 4, 100, 20, 7, 72, R.xml.default_workspace_4x4));return predefinedDeviceProfiles;}
InvariantDeviceProfile的各个参数依次代表:
配置名字(任意定义)、最小宽度(单位是dp)、最小高度(单位是dp)、桌面行数、桌面列数、文件夹行数、文件夹列数、主菜单中predicted apps最小列数、桌面Icon的size(单位是dp)、桌面Icon的文字size(单位是dp)、Hotseat的Icon个数、Hotseat的Icon的size(单位是dp)、默认的桌面配置LayoutId。
PS:
如何由手机分辨率计算最小宽度、最小高度?
例如:手机分辨率为720*1280,DPI=320。
竖屏时:X*Y=720*1230(1230=屏幕高度-状态栏高度-NavigationBar高度)
横屏时:Y*X=646*1280(646=屏幕宽度-状态栏高度-NavigationBar高度)
最小宽度为:323=Min(720,646)/(320/160)
最小高度为:615=Min(1230,1280)/(320/160)