Setting dashboard click to jump to the process, settingdashboard
You can modify the dashboard_categaries.xml file in the xml file. in the rebuildUI () method of the java file, convert the object class corresponding to xml to the corresponding view. For details, see the source code of the settings. 1. dashboard_categaries defines the node style:
1 <! -- Wifi --> 2 <dashboard-tile 3 android: id = "@ + id/wifi_settings" 4 android: fragment = "com. android. settings. wifi. wifiSettings "5 android: icon =" @ drawable/sunmi_wifi "6 android: title =" @ string/wifi_settings_title "/> 7 <! -- Mobile Network --> 8 <dashboard-tile 9 android: id = "@ + id/mobile_net_settings" 10 android: icon = "@ drawable/sunmi_network" 11 android: title = "@ string/network_settings_title"> 12 <intent13 android: action = "android. intent. action. MAIN "14 android: targetClass =" com. android. phone. mobileNetworkSettings "15 android: targetPackage =" com. android. phone "/> 16 </dashboard-tile>
This is the set Wi-Fi and mobile network options. One is to add fragment, and the other is to add intent.
Parsing this xml is in the SettingActivity loadCategoriesFromResource (R. xml. dashboard_categories, categories); method,
2. rebuildUI () method in the DashboardSummary. java File
1 private void rebuildUI(Context context) { 2 if (!isAdded()) { 3 return; 4 } 5 final Resources res = getResources(); 6 mDashboard.removeAllViews(); 7 List<DashboardCategory> categories = ((SettingsActivity) context).getDashboardCategories(true); 8 final int count = categories.size(); 9 for (int n = 0; n < count; n++) {10 DashboardCategory category = categories.get(n);11 View categoryView = mLayoutInflater.inflate(R.layout.dashboard_category, mDashboard, false);12 TextView categoryLabel = (TextView) categoryView.findViewById(R.id.category_title);13 categoryLabel.setText(category.getTitle(res));14 15 ViewGroup categoryContent = (ViewGroup) categoryView.findViewById(R.id.category_content);16 17 final int tilesCount = category.getTilesCount();18 for (int i = 0; i < tilesCount; i++) {19 DashboardTile tile = category.getTile(i);20 DashboardTileView tileView = new DashboardTileView(context);21 updateTileView(context, res, tile, tileView.getImageView(), tileView.getTitleTextView(),22 tileView.getStatusTextView());23 24 tileView.setTile(tile);25 categoryContent.addView(tileView);26 }27 28 // Add the category29 mDashboard.addView(categoryView);30 }31 }
The source code of the analysis shows that rebuildui () is the entity class parsed in xml and constructed into the corresponding view (categoryView, DashboardTileView). No click addition event is displayed here, so I guess it should be written to DashboardTileView.
3. Click events of DashboardTileView
1 public class DashboardTileView extends FrameLayout implements View.OnClickListener
Click Event processing is implemented here.
1 @Override2 public void onClick(View v) {3 if (mTile.fragment != null) {4 Utils.startWithFragment(getContext(), mTile.fragment, mTile.fragmentArguments, null, 0,5 mTile.titleRes, mTile.getTitle(getResources()));6 } else if (mTile.intent != null) {7 getContext().startActivity(mTile.intent);8 }9 }
Now you can see the fragment priority> intent.
Let's take a look at fragment's jump
Iv. fragment jump details
1 public static void startWithFragment(Context context, String fragmentName, Bundle args, 2 Fragment resultTo, int resultRequestCode, int titleResId, 3 CharSequence title) { 4 startWithFragment(context, fragmentName, args, resultTo, resultRequestCode, 5 null /* titleResPackageName */, titleResId, title, false /* not a shortcut */); 6 } 7 8 public static void startWithFragment(Context context, String fragmentName, Bundle args, 9 Fragment resultTo, int resultRequestCode, String titleResPackageName, int titleResId,10 CharSequence title, boolean isShortcut) {11 Intent intent = onBuildStartFragmentIntent(context, fragmentName, args, titleResPackageName,12 titleResId, title, isShortcut);13 if (resultTo == null) {14 context.startActivity(intent);15 } else {16 resultTo.startActivityForResult(intent, resultRequestCode);17 }18 }19 20 public static Intent onBuildStartFragmentIntent(Context context, String fragmentName,21 Bundle args, String titleResPackageName, int titleResId, CharSequence title,22 boolean isShortcut) {23 Intent intent = new Intent(Intent.ACTION_MAIN);24 intent.setClass(context, SubSettings.class);25 intent.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT, fragmentName);26 intent.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_ARGUMENTS, args);27 intent.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_TITLE_RES_PACKAGE_NAME,28 titleResPackageName);29 intent.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_TITLE_RESID, titleResId);30 intent.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_TITLE, title);31 intent.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_AS_SHORTCUT, isShortcut);32 return intent;33 }
You can understand that SubSettings. class is started by constructing an intent with the fragmentName parameter.
In SubSettings. class, fragment is not added. You can obtain the specific parameters in oncrreate () of the parent class SettingsActivity and add the corresponding fragment.
Click the Setting dashboard and click the jump process.