先从Launcher.xml看view的结构:
static final String FIRST_RUN_CLING_DISMISSED_KEY = "cling_gel.first_run.dismissed";
static final String WORKSPACE_CLING_DISMISSED_KEY = "cling_gel.workspace.dismissed";
static final String FOLDER_CLING_DISMISSED_KEY = "cling_gel.folder.dismissed";
public void showFirstRunCling() {
if (isClingsEnabled() &&
!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);
}
}
private void dismissCling(final Cling cling, final Runnable postAnimationCb,
final String flag, int duration, boolean restoreNavBarVisibilty) {
// To catch cases where siblings of top-level views are made invisible, just check whether
// the cling is directly set to GONE before dismissing it.
if (cling != null && cling.getVisibility() != View.GONE) {
final Runnable cleanUpClingCb = new Runnable() {
public void run() {
cling.cleanup();
// We should update the shared preferences on a background thread
new Thread("dismissClingThread") {
public void run() {
SharedPreferences.Editor editor = mSharedPrefs.edit();
editor.putBoolean(flag, true);
editor.commit();
}
}.start();
if (postAnimationCb != null) {
postAnimationCb.run();
}
}
};
if (duration <= 0) {
cleanUpClingCb.run();
} else {
cling.hide(duration, cleanUpClingCb);
}
mHideFromAccessibilityHelper.restoreImportantForAccessibility(mDragLayer);
if (restoreNavBarVisibilty) {
cling.setSystemUiVisibility(cling.getSystemUiVisibility() &
~View.SYSTEM_UI_FLAG_LOW_PROFILE);
}
}
}
private static String FIRST_RUN_PORTRAIT = "first_run_portrait";
private static String FIRST_RUN_LANDSCAPE = "first_run_landscape";
private static String WORKSPACE_PORTRAIT = "workspace_portrait";
private static String WORKSPACE_LANDSCAPE = "workspace_landscape";
private static String WORKSPACE_LARGE = "workspace_large";
private static String WORKSPACE_CUSTOM = "workspace_custom";
private static String FOLDER_PORTRAIT = "folder_portrait";
private static String FOLDER_LANDSCAPE = "folder_landscape";
private static String FOLDER_LARGE = "folder_large";
private int[] mTouchDownPt = new int[2];
private Drawable mFocusedHotseatApp;
private ComponentName mFocusedHotseatAppComponent;
private Rect mFocusedHotseatAppBounds;
//这个方法显然是FirstRunWorkspaceCling相关的东西
void setFocusedHotseatApp(int drawableId, int appRank, ComponentName cn, String title,
String description) {
....
}
这怎么又有hotSeat相关的代码呢?居然已经是一个躯壳就应该做它里面共有的事情,细节的不一样交给包裹里的东西实现,我是这么认为的.
Cling的初始化之init();
1.first_run_cling:Launcher.onCreate()->Launcher.showFirstRunCling()->Launcher.initCling();
2.workspace_cling:Cling.onClick()->Launcher.dismissFirstRunCling()->showFirstRunWorkspaceCling()->Launcher.initCling()
3.folder_cling:Folder.animateOpen->Launcher.showFirstRunFoldersCling()->Launcher.initCling();
可以看出,都是在要显示的时候初始化
if (isClingsEnabled() &&
!mSharedPrefs.getBoolean(Cling.FOLDER_CLING_DISMISSED_KEY, false)) {
Cling cling = initCling(R.id.folder_cling, R.id.cling_scrim,
true, true);
return cling;
} else {
removeCling(R.id.folder_cling);
return null;
}
如果发显示不该显示就remove()这个细节很赞!
后面dispatchDraw就是根据它包的不同东西去显示一些不同细节,我想说的是,为啥不能交给它们的子view实现。