1 hotseat位置:O版本有五个图标,Go版本有四个图标,它们之间的差别在哪?
在InvariantDeviceProfile文件如下函数中
ArrayList getPredefinedDeviceProfiles(Context context) {
ArrayList profiles = new ArrayList<>();
try (XmlResourceParser parser = context.getResources().getXml(R.xml.device_profiles)) {
final int depth = parser.getDepth();
int type;
while (((type = parser.next()) != XmlPullParser.END_TAG ||
parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) {
if ((type == XmlPullParser.START_TAG) && "profile".equals(parser.getName())) {
TypedArray a = context.obtainStyledAttributes(
Xml.asAttributeSet(parser), R.styleable.InvariantDeviceProfile);
int numRows = a.getInt(R.styleable.InvariantDeviceProfile_numRows, 0);
int numColumns = a.getInt(R.styleable.InvariantDeviceProfile_numColumns, 0);
float iconSize = a.getFloat(R.styleable.InvariantDeviceProfile_iconSize, 0);
profiles.add(new InvariantDeviceProfile(
a.getString(R.styleable.InvariantDeviceProfile_name),
a.getFloat(R.styleable.InvariantDeviceProfile_minWidthDps, 0),
a.getFloat(R.styleable.InvariantDeviceProfile_minHeightDps, 0),
numRows,
numColumns,
a.getInt(R.styleable.InvariantDeviceProfile_numFolderRows, numRows),
a.getInt(R.styleable.InvariantDeviceProfile_numFolderColumns, numColumns),
a.getInt(R.styleable.InvariantDeviceProfile_minAllAppsPredictionColumns, numColumns),
iconSize,
a.getFloat(R.styleable.InvariantDeviceProfile_landscapeIconSize, iconSize),
a.getFloat(R.styleable.InvariantDeviceProfile_iconTextSize, 0),
a.getInt(R.styleable.InvariantDeviceProfile_numHotseatIcons, numColumns),
a.getResourceId(R.styleable.InvariantDeviceProfile_defaultLayoutId, 0),
a.getResourceId(R.styleable.InvariantDeviceProfile_demoModeLayoutId, 0)));
a.recycle();
}
}
} catch (IOException|XmlPullParserException e) {
throw new RuntimeException(e);
}
return profiles;
}
它会首先去解析device_profiles.xml文件,获取相应的属性:如hotseta位置的数量是由 launcher:numHotseatIcons决定
Android O对应的解析文件:res/xml/device_profiles.xml 有多套不同的profile,代码中通过计算屏幕的最小宽度和高度,在device_profiles中查找到最接近的一个profile进行匹配设置!
// This guarantees that width < height
minWidthDps = Utilities.dpiFromPx(Math.min(smallestSize.x, smallestSize.y), dm);
minHeightDps = Utilities.dpiFromPx(Math.min(largestSize.x, largestSize.y), dm);
ArrayList closestProfiles = findClosestDeviceProfiles(
minWidthDps, minHeightDps, getPredefinedDeviceProfiles(context));
InvariantDeviceProfile interpolatedDeviceProfileOut =
invDistWeightedInterpolate(minWidthDps, minHeightDps, closestProfiles);
InvariantDeviceProfile closestProfile = closestProfiles.get(0);
numRows = closestProfile.numRows;
numColumns = closestProfile.numColumns;
numHotseatIcons = closestProfile.numHotseatIcons;
defaultLayoutId = closestProfile.defaultLayoutId;
demoModeLayoutId = closestProfile.demoModeLayoutId;
numFolderRows = closestProfile.numFolderRows;
numFolderColumns = closestProfile.numFolderColumns;
minAllAppsPredictionColumns = closestProfile.minAllAppsPredictionColumns;
注:如何计算手机分辨率的最小宽度和高度?
例如:手机分辨率为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)
Android Go对应的解析文件:go/res/xml/device_profiles.xml 只有固定的一个profile
2 Launcher3 如果桌面壁纸是单一颜色,AllApps和状态栏背景色会由于壁纸颜色单一而变成透明
针对该问题,有客户会认为该问题是一个Bug;如果屏蔽Launcher3对于壁纸颜色的监听?
在 packages/apps/Launcher3/com/android/launcher3/dynamicui/WallpaperColorInfo.java 构造函数中去除
private WallpaperColorInfo(Context context) {
mWallpaperManager = WallpaperManagerCompat.getInstance(context);
- mWallpaperManager.addOnColorsChangedListener(this);
+ //mWallpaperManager.addOnColorsChangedListener(this);
mExtractionType = ColorExtractionAlgorithm.newInstance(context);
update(mWallpaperManager.getWallpaperColors(FLAG_SYSTEM));
}
3 有的项目,在进入主屏幕设置后,导致导航栏看不清问题;见下图
在packages/apps/Launcher3/src/com/android/launcher3/SettingsActivity.java的onCreate函数中增加对于导航栏相关控制即可,如下所示:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
View decorView = getWindow().getDecorView();
decorView.setSystemUiVisibility(View.NAVIGATION_BAR_TRANSLUCENT);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
//getWindow().setNavigationBarColor(Color.TRANSPARENT);
if (savedInstanceState == null) {
// Display the fragment as the main content.
getFragmentManager().beginTransaction()
.replace(android.R.id.content, new LauncherSettingsFragment())
.commit();
}
}