文章出处:http://blog.csdn.net/wangjicong_215/article/details/52605255
Android Launcher 一些默认修改(一)
1.如何设置Launcher2、Launcher3的壁纸同步
由于SprdLauncher1和SprdLauncher2中支持分开设置主屏壁纸和锁屏壁纸,
所以锁屏在获取壁纸的时候,会获取对齐的锁屏壁纸类型。
目前原生Launcher2和原生Launcher3不支持分开设置,
所以要保证原生Launcher2和原生Launcher3设置壁纸的时候,锁屏跟主屏保持一致,
只需要锁屏在获取壁纸的时候,获取的壁纸类型也是主屏壁纸类型。
修改如下:
请定位到KeyguardViewManager.java中的maybeCreateKeyguardLocked方法:
把Drawable drawable = wm.getDrawable(WallpaperInfo.WALLPAPER_LOCKSCREEN_TYPE);
修改为Drawable drawable = wm.getDrawable(WallpaperInfo.WALLPAPER_MAINMENU_TYPE);
2.如何修改使Launcher2中文件夹图标名称与应用名称保持水平
请定为到/packages/apps/Launcher2/res/values/dimens.xml文件中
调整下面的值即可:
<dimen name="folder_icon_padding_top">2dp</dimen>
3.android4.4 Launcher中如何隐藏主界面应用图标的应用名称?
以sprdLauncher2举例:
请定位到vendor/sprd/UniverseUI/SprdLauncher2/src/com/android/sprdlauncher2/CellLayout.java文件:
然后定位到addViewToCellLayout方法:
if (child instanceof BubbleTextView) {
BubbleTextView bubbleChild = (BubbleTextView) child;
bubbleChild.setTextVisibility(!mIsHotseat);
}
修改为:
if (child instanceof BubbleTextView) {
BubbleTextView bubbleChild = (BubbleTextView) child;
bubbleChild.setTextVisibility(false);
}
4.如何在sprdLauncher2中隐藏一个应用图标?
以隐藏百度地图为例,修改如下:
请定位到/vendor/sprd/UniverseUI/SprdLauncher2/src/com/android/sprdlauncher2/LauncherModel.java文件,
查找verifyApplications方法:
if (tmpInfos.isEmpty()) {
added.add(app);
}
修改为:
if (tmpInfos.isEmpty()) {
ComponentName cn = app.componentName;
Log.e(TAG,"cn = "+cn);
if(cn != null && !cn.equals("")){
if(!cn.toString().equals("ComponentInfo{com.baidu.BaiduMap/com.baidu.BaiduMap.BaiduMap}")){
added.add(app);
}
}
}
5.如果实现Launcher2中菜单列表背景半透明效果?
Android4.4中的Launcher2默认没有开启菜单列表背景透明效果,纯黑色背景效果不是太好,如果需要开启菜单背景透明效果,可以参考如下修改来实现:
diff --git a/packages/apps/Launcher2/res/layout/apps_customize_pane.xml b/packages/apps/Launcher2/res/layout/apps_customize_pane.xml
index a9d7ded..70ee6b5 100644
--- a/packages/apps/Launcher2/res/layout/apps_customize_pane.xml
+++ b/packages/apps/Launcher2/res/layout/apps_customize_pane.xml
@@ -16,7 +16,7 @@
<com.android.launcher2.AppsCustomizeTabHost
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:launcher="http://schemas.android.com/apk/res/com.android.launcher"
- android:background="#FF000000">
+ android:background="#00000000">
<LinearLayout
android:id="@+id/apps_customize_content"
android:orientation="vertical"
@@ -74,7 +74,7 @@
android:id="@+id/animation_buffer"
android:layout_width="match_parent"
android:layout_height="match_parent"
- android:background="#FF000000"
+ android:background="#00000000"
android:visibility="gone" />
<include
diff --git a/packages/apps/Launcher2/src/com/android/launcher2/AppsCustomizeTabHost.java b/packages/apps/Launcher2/src/com/android/launcher2/AppsCustomizeTabHost.java
index 225b056..076b14d 100644
--- a/packages/apps/Launcher2/src/com/android/launcher2/AppsCustomizeTabHost.java
+++ b/packages/apps/Launcher2/src/com/android/launcher2/AppsCustomizeTabHost.java
@@ -32,6 +32,7 @@ import android.widget.LinearLayout;
import android.widget.TabHost;
import android.widget.TabWidget;
import android.widget.TextView;
+import android.graphics.Color;
import com.android.launcher.R;
@@ -138,6 +139,7 @@ public class AppsCustomizeTabHost extends TabHost implements LauncherTransitiona
// Hide the tab bar until we measure
mTabsContainer.setAlpha(0f);
+ mContent.setBackgroundColor(Color.argb(100, 0, 0, 0));
}
@Override
diff --git a/packages/apps/Launcher2/src/com/android/launcher2/CellLayout.java b/packages/apps/Launcher2/src/com/android/launcher2/CellLayout.java
index 024bb37..cbc3a26 100644
--- a/packages/apps/Launcher2/src/com/android/launcher2/CellLayout.java
+++ b/packages/apps/Launcher2/src/com/android/launcher2/CellLayout.java
@@ -549,6 +549,7 @@ public class CellLayout extends ViewGroup {
p.setXfermode(sAddBlendMode);
mOverScrollForegroundDrawable.draw(canvas);
p.setXfermode(null);
+ p.setDither(true);
}
}
diff --git a/packages/apps/Launcher2/src/com/android/launcher2/Launcher.java b/packages/apps/Launcher2/src/com/android/launcher2/Launcher.java
index 56aa73b..51024f9 100644
--- a/packages/apps/Launcher2/src/com/android/launcher2/Launcher.java
+++ b/packages/apps/Launcher2/src/com/android/launcher2/Launcher.java
@@ -2475,7 +2475,7 @@ public final class Launcher extends Activity
if (isAllAppsVisible()) {
if (mAppsCustomizeTabHost != null &&
!mAppsCustomizeTabHost.isTransitioning()) {
- updateWallpaperVisibility(false);
+ updateWallpaperVisibility(true);
}
}
}
@@ -2648,7 +2648,7 @@ public final class Launcher extends Activity
hideDockDivider();
}
if (!animationCancelled) {
- updateWallpaperVisibility(false);
+ updateWallpaperVisibility(true);
}
// Hide the search bar
@@ -2728,7 +2728,7 @@ public final class Launcher extends Activity
dispatchOnLauncherTransitionPrepare(toView, animated, false);
dispatchOnLauncherTransitionStart(toView, animated, false);
dispatchOnLauncherTransitionEnd(toView, animated, false);
- updateWallpaperVisibility(false);
+ updateWallpaperVisibility(true);
}
}
6.0如何让launcher不被一键清理?
一键清理应用的目录:
\packages\apps\RamOptimize
在\res\values\arrays.xml文件里有对不需要清理的应用进行配置:
<!-- the name of app that we wan't to kill -->
<string-array name="recent_keep_app" translatable="false">
<item>com.sprd.ramoptimizer</item>
<item>com.android.sprdlauncher2</item>
...
</string-array>
<!-- the name of service that we wan't to kill -->
<string-array name="recent_keep_service" translatable="false">
<item>com.sprd.ramoptimizer</item>
<item>com.sprd.videoswallpapers</item>
</string-array>
如果想让自己的应用不被清理,把包名添加到recent_keep_app数组即可。
7.0LOCAL_OVERRIDES_PACKAGES的作用
关于android.mk中的LOCAL_OVERRIDES_PACKAGES,此变量可以使定义的其它模块无法编译生成到系统中,使用本模块作为替换。
比如在SprdLauncher2的android.mk里
定义了LOCAL_OVERRIDES_PACKAGES := Launcher3
在使用了SprdLauncher2的工程里就无法集成原生的 Launcher3。
8.如何提升Launcher中盒子等滑动特效的流畅度
Launcher中滑动特效的文件在:
SprdLauncher1\src\com\sprd\launcher3\effect
SprdLauncher2\src\com\sprd\sprdlauncher2\effect
盒子等特效相比于page特效主要慢在ALPHA绘制上,因为ALPHA绘制本身耗时就比较长,所以:
如果想提升滑动特效流畅度,请删除特效中getTransformationMatrix函数中关于ALPHA变化的代码:
如:
CrossEffect.java中:
去掉以下代码:
float absOffset = Math.abs(offset);
float mAlpha = 1.0F - absOffset * 0.4f;
view.setAlpha(mAlpha);
9.如何把SprdLaucher2的hotseat图标底下把对应的应用名称item显示出来?
1.代码调整:
CellLayout.java 里面的BubbleTextView bubbleChild = (BubbleTextView) child;
bubbleChild.setTextVisibility(!mIsHotseat); 改为bubbleChild.setTextVisibility(true);
Workspace.java 里面的((FolderIcon)child).setTextVisible(false);改为 ((FolderIcon)child).setTextVisible(true);
2.修改hotseat.xml布局文件:
根据需要调整,例如:
修改为
<com.android.sprdlauncher2.Hotseat
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:launcher="http://schemas.android.com/apk/res-auto/com.android.sprdlauncher2">
<com.android.sprdlauncher2.CellLayout
android:id="@+id/layout"
android:layout_marginBottom="XXXdp" //修改hotseat距离底部的位置
android:layout_width="wrap_content"
android:layout_height="XXXdp" // hotseat高度
android:layout_gravity="center" />
</com.android.sprdlauncher2.Hotseat>
10.如何修改launcher中应用图标的行数和列数?
横屏:
\packages\apps\Launcher2\res\layout-land\workspace_screen.xml
竖屏
\packages\apps\Launcher2\res\layout-port\workspace_screen.xml
修改里面格子的数量
launcher:shortAxisCells=”4″
launcher:longAxisCells=”4″
还可以调整一下格子们与左右和上下的边距
launcher:longAxisStartPadding=”65dip”
launcher:longAxisEndPadding=”65dip”
launcher:shortAxisStartPadding=”0dip”
launcher:shortAxisEndPadding=”0dip”
11.如何修改launcher的屏幕数
首先,在Launcher.java代码中修改总的页数和默认显示页:
static final int SCREEN_COUNT = 5;
static final int DEFAULT_SCREEN = 2;//第一页是从0开始计数,这里是把第三个页面作为默认首页
第一个是定义屏幕个数,第一个参数是默认的首页。
其次:还需要修改 launcher.xml
<!-- The workspace contains 5 screens of cells -->
<com.android.launcher2.Workspace
android:id="@+id/workspace"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="horizontal"
android:fadeScrollbars="true"
launcher:defaultScreen="2">
<include android:id="@+id/cell1" layout="@layout/workspace_screen" />
<include android:id="@+id/cell2" layout="@layout/workspace_screen" />
<include android:id="@+id/cell3" layout="@layout/workspace_screen" />
<include android:id="@+id/cell4" layout="@layout/workspace_screen" />
<include android:id="@+id/cell5" layout="@layout/workspace_screen" />
</com.android.launcher2.Workspace>
导入了五个workspace_screen,在这里,参照上面修改的参数,添加或者删除workspace_screen。
并且 launcher:defaultScreen="2"> 定义的defaultScreen.要修改成对应的值。
另外,修改workspace.java中获取不到值时的默认首页,确保异常情况下默认首页一致
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.Workspace, defStyle, 0);
mDefaultScreen = a.getInt(R.styleable.Workspace_defaultScreen, 1);
最后,对 res/xml文件中default_workspace.xml做出相应的修改。这里面是workspace初始显示的icon和widget。
12.如何添加壁纸资源到壁纸列表?
解决: 以wallpaper_lake.jpg为例
1.拷贝壁纸图片 wallpaper_lake.jpg和wallpaper_lake_small.jpg 到相应目录
packages/apps/Launcher2/res/drawable-对应像素/wallpaper_lake.jpg
packages/apps/Launcher2/res/drawable-对应像素/wallpaper_lake_small.jpg
2.在 res/values-hdpi/wallpapers.xml 中添加wallpaper_lake条目
<string-array name="wallpapers" translatable="false">
+ <item>wallpaper_lake</item>
..
此时,长按桌面,选择壁纸选项,就会在壁纸列表看到一个新的壁纸。
13.如何更换launcher中点击应用的高亮背景
workspace(idle)点击快捷图标的高亮背景为:
packages/apps/Launcher2/res/drawable/pressed_application_background.9.png
workspace(idle)方向键选中的高亮背景:
/packages/apps/Launcher2/res/drawable-hdpi/focused_application_background.9.png
Mainmenu(主菜单)点击应用的高亮背景为:
packages/apps/Launcher2/res/drawable-hdpi/background_icon.9.png
默认的高亮背景是点九格式的png文件,这样可以适应不同的布局大小,也可以设置不是点九的图片!
更换上面的图片实现自定义的背景
14.如何配置launcher使用大内存?
在launcher的AndroidManifest.xml中可以配置launcher使用大的堆内存,这样可以在一定程度上避免内存不足出现的out of memory错误。配置launcher使用大内存需要更改的属性名称为android:largeHeap。如下所示:
<application
android:name="com.android.launcher2.LauncherApplication"
android:label="@string/application_name"
android:icon="@drawable/ic_launcher_home"
android:hardwareAccelerated="@bool/config_hardwareAccelerated"
android:largeHeap="@bool/config_largeHeap">
可以在values文件夹的config.xml中修改largeHeap的属性值。如下所示:
<bool name="config_largeHeap">false</bool>
15.如何更改系统默认墙纸
默认墙纸位置在frameworks/base/core/res/res/drawable-nodpi/default_wallpaper.jpg
不同分辨率的项目在对应的drawable目录下。
更改了默认墙纸后,为了与墙纸设置里面待选的墙纸保持一致,最好同步修改对应launcher下的墙纸。
launcher下墙纸位置:package/apps/Launcher2/res/drawable-nodpi/