Setting 之dashboard 点击跳转流程

设置的主界面的可以通过修改xml中的dashboard_categaries.xml 文件实现,在DashboardSummary.java 文件中的rebuildUI()方法中将xml对应的实体类转换成对应的view,具体细节可以看设置源码。

一,dashboard_categaries中定义节点的样式:

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<!-- 移动网络 --> 8<dashboard-tile 9 android:id="@+id/mobile_net_settings" 10 android:icon="@drawable/sunmi_network" 11 android:title="@string/network_settings_title" > 12 <intent 13 android:action="android.intent.action.MAIN" 14 android:targetClass="com.android.phone.MobileNetworkSettings" 15 android:targetPackage="com.android.phone" /> 16</dashboard-tile>

这是设置中的wifi,和移动网络选项,一个是添加fragment ,另一个是添加intent

解析这个xml是在SettingActivity中的loadCategoriesFromResource(R.xml.dashboard_categories, categories);方法中,

二,DashboardSummary.java 文件中的rebuildUI()方法

1private 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 category 29 mDashboard.addView(categoryView); 30 } 31 }

分析源码可知rebuildui()是将xml中解析的实体类,构建成对应的view(categoryView,DashboardTileView)在这并没有看到添加点击事件,所以猜测应该写到DashboardTileView中了

三,DashboardTileView的点击事件

public class DashboardTileView extends FrameLayout implements View.OnClickListener 

看到这里就知道是在这里实现点击事件处理的

1 @Override 2 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 }

看到这里一目了然啦,可以知道fragment 优先级>intent ,再来看fragment的跳转

四,fragment的跳转细节

1public 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 8public 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 }

可以知道是通过构建一个带fragmentName参数的intent来启动SubSettings.class 
而SubSettings.class中并没有实现具体添加fragment,在父类SettingsActivity中oncrreate()中获取具体参数,添加对应fragment

点击Setting 之dashboard 点击跳转流程就是这样啦

点赞
收藏

评论区

加载中...

相关推荐

MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1

文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s

Oracle 分组与拼接字符串同时使用

SELECTT.,ROWNUMIDFROM(SELECTT.EMPLID,T.NAME,T.BU,T.REALDEPART,T.FORMATDATE,SUM(T.S0)S0,MAX(UPDATETIME)CREATETIME,LISTAGG(TOCHAR(

皕杰报表之UUID

​在我们用皕杰报表工具设计填报报表时,如何在新增行里自动增加id呢?能新增整数排序id吗?目前可以在新增行里自动增加id,但只能用uuid函数增加UUID编码,不能新增整数排序id。uuid函数说明:获取一个UUID,可以在填报表中用来创建数据ID语法:uuid()或uuid(sep)参数说明:sep布尔值,生成的uuid中是否包含分隔符'',缺省为

手写Java HashMap源码

HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程22

2020年前端实用代码段,为你的工作保驾护航

有空的时候,自己总结了几个代码段,在开发中也经常使用,谢谢。1、使用解构获取json数据let jsonData  id: 1,status: "OK",data: 'a', 'b';let  id, status, data: number   jsonData;console.log(id, status, number )

PhoneGap设置Icon

参考:http://cordova.apache.org/docs/en/latest/config\_ref/images.html通过config.xml中的<icon标签来设置Icon<iconsrc"res/ios/icon.png"platform"ios"width"57"height"57"densi