Launcher3除了保留了原来的OOBE了外,在原有的基础上还增加了cling功能,这些都出现在机器的第一次开机,以后不会再出现。
按理说这是一个人性话的设计,主要考虑两点:第一,很明显就是一个导航作用。第二,考虑到机器刚开机的时候,系统初始化没有完全完成,这时候人机交互的体验感很差。说白了就是让你等一下。但是就是很多人不喜欢这个。去掉oobe很简单,它是一个单独的apk,这里重点说下cling。
googel做这个之前可能已经考虑到了这点,所有整个cling都有一个开关来控制。
private static final boolean <span style="color:#ff0000;"><strong>DISABLE_CLINGS </strong></span>= false;
具体的代码如下(launcher.xml):
<com.android.launcher3.ScrimView由以上可以看出主要是在四个地方出现。
android:id="@+id/cling_scrim"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone" />
<include layout="@layout/first_run_cling"
android:id="@+id/first_run_cling"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone" />
<include layout="@layout/workspace_cling"
android:id="@+id/workspace_cling"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone" />
<include layout="@layout/folder_cling"
android:id="@+id/folder_cling"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone" />
/* Cling related */以一个为例,其他的类似:
private boolean isClingsEnabled() {
if (<span style="color:#ff0000;">DISABLE_CLINGS</span>) { //这么搞有点想c语言中的宏开关,转到面向对象的编程中这一点得好好学学
return false;
}
// For now, limit only to phones
LauncherAppState app = LauncherAppState.getInstance();
DeviceProfile grid = app.getDynamicGrid().getDeviceProfile();
if (grid.isTablet()) {
return false;
}
// disable clings when running in a test harness
if(ActivityManager.isRunningInTestHarness()) return false;
// Disable clings for accessibility when explore by touch is enabled
final AccessibilityManager a11yManager = (AccessibilityManager) getSystemService(
ACCESSIBILITY_SERVICE);
if (a11yManager.isTouchExplorationEnabled()) {
return false;
}
…………
return true;
}
public void showFirstRunCling() {
if (<span style="color:#ff0000;">isClingsEnabled()</span> &&
!mSharedPrefs.getBoolean(Cling.FIRST_RUN_CLING_DISMISSED_KEY, false) &&
!skipCustomClingIfNoAccounts() ) {
// If we're not using the default workspace layout, replace workspace cling
// with a custom workspace cling (usually specified in an overlay)
// For now, only do this on tablets
if (!DISABLE_CUSTOM_CLINGS) {
if (mSharedPrefs.getInt(LauncherProvider.DEFAULT_WORKSPACE_RESOURCE_ID, 0) != 0 &&
getResources().getBoolean(R.bool.config_useCustomClings)) {
// Use a custom cling
View cling = findViewById(R.id.workspace_cling);
ViewGroup clingParent = (ViewGroup) cling.getParent();
int clingIndex = clingParent.indexOfChild(cling);
clingParent.removeViewAt(clingIndex);
View customCling = mInflater.inflate(R.layout.custom_workspace_cling, clingParent, false);
clingParent.addView(customCling, clingIndex);
customCling.setId(R.id.workspace_cling);
}
}
Cling cling = (Cling) findViewById(R.id.first_run_cling);
if (cling != null) {
String sbHintStr = getFirstRunClingSearchBarHint();
String ccHintStr = getFirstRunCustomContentHint();
if (!sbHintStr.isEmpty()) {
TextView sbHint = (TextView) cling.findViewById(R.id.search_bar_hint);
sbHint.setText(sbHintStr);
sbHint.setVisibility(View.VISIBLE);
}
setCustomContentHintVisibility(cling, ccHintStr, true, false);
}
initCling(R.id.first_run_cling, 0, false, true);
} else {
removeCling(R.id.first_run_cling); //这里对比面向过程的宏就显得有点……,其实这么比是不对的。有点自生自灭的意思
}
}
从面向过程的c转过来,最大的发现就是麻烦和方便并存着。