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

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

  <!-- Wifi -->
<dashboard-tile
android:id="@+id/wifi_settings"
android:fragment="com.android.settings.wifi.WifiSettings"
android:icon="@drawable/sunmi_wifi"
android:title="@string/wifi_settings_title" />
<!-- 移动网络 -->
<dashboard-tile
android:id="@+id/mobile_net_settings"
android:icon="@drawable/sunmi_network"
android:title="@string/network_settings_title" >
<intent
android:action="android.intent.action.MAIN"
android:targetClass="com.android.phone.MobileNetworkSettings"
android:targetPackage="com.android.phone" />
</dashboard-tile>

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

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

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

 private void rebuildUI(Context context) {
if (!isAdded()) {
return;
}
final Resources res = getResources();
mDashboard.removeAllViews();
List<DashboardCategory> categories = ((SettingsActivity) context).getDashboardCategories(true);
final int count = categories.size();
for (int n = 0; n < count; n++) {
DashboardCategory category = categories.get(n);
View categoryView = mLayoutInflater.inflate(R.layout.dashboard_category, mDashboard, false);
TextView categoryLabel = (TextView) categoryView.findViewById(R.id.category_title);
categoryLabel.setText(category.getTitle(res)); ViewGroup categoryContent = (ViewGroup) categoryView.findViewById(R.id.category_content); final int tilesCount = category.getTilesCount();
for (int i = 0; i < tilesCount; i++) {
DashboardTile tile = category.getTile(i);
DashboardTileView tileView = new DashboardTileView(context);
updateTileView(context, res, tile, tileView.getImageView(), tileView.getTitleTextView(),
tileView.getStatusTextView()); tileView.setTile(tile);
categoryContent.addView(tileView);
} // Add the category
mDashboard.addView(categoryView);
}
}

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

三,DashboardTileView的点击事件

 public class DashboardTileView extends FrameLayout implements View.OnClickListener 

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

  @Override
public void onClick(View v) {
if (mTile.fragment != null) {
Utils.startWithFragment(getContext(), mTile.fragment, mTile.fragmentArguments, null, 0,
mTile.titleRes, mTile.getTitle(getResources()));
} else if (mTile.intent != null) {
getContext().startActivity(mTile.intent);
}
}

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

四,fragment的跳转细节

 public static void startWithFragment(Context context, String fragmentName, Bundle args,
Fragment resultTo, int resultRequestCode, int titleResId,
CharSequence title) {
startWithFragment(context, fragmentName, args, resultTo, resultRequestCode,
null /* titleResPackageName */, titleResId, title, false /* not a shortcut */);
} public static void startWithFragment(Context context, String fragmentName, Bundle args,
Fragment resultTo, int resultRequestCode, String titleResPackageName, int titleResId,
CharSequence title, boolean isShortcut) {
Intent intent = onBuildStartFragmentIntent(context, fragmentName, args, titleResPackageName,
titleResId, title, isShortcut);
if (resultTo == null) {
context.startActivity(intent);
} else {
resultTo.startActivityForResult(intent, resultRequestCode);
}
} public static Intent onBuildStartFragmentIntent(Context context, String fragmentName,
Bundle args, String titleResPackageName, int titleResId, CharSequence title,
boolean isShortcut) {
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setClass(context, SubSettings.class);
intent.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT, fragmentName);
intent.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_ARGUMENTS, args);
intent.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_TITLE_RES_PACKAGE_NAME,
titleResPackageName);
intent.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_TITLE_RESID, titleResId);
intent.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_TITLE, title);
intent.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_AS_SHORTCUT, isShortcut);
return intent;
}

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

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

转自:http://blog.csdn.net/kingyc123456789/article/details/53175624

Setting 之dashboard 点击跳转流程的更多相关文章

  1. php防盗链,php ci在control里面控制除了自己站内的链接点击跳转,其他来源的都跳到站内页面

    php防盗链,php ci在control里面控制除了自己站内的链接点击跳转,其他来源的都跳到站内页面 $route['jump/(:any)/(:any)'] = "index/jump/ ...

  2. html锚点 点击跳转到页面指定位置

    本来是在看阮大神写的ajax教程,突然发现点击目录文字会跳转到相对应的文本内容,于是乎激发了我的兴趣. 这个究竟怎么做的,刚开始看的时候一知半解,找度娘就是:"点击跳转到页面指定位置&quo ...

  3. js模拟form表单提交数据, js模拟a标签点击跳转,避开使用window.open引起来的浏览器阻止问题

    js模拟form表单提交数据, js模拟a标签点击跳转,避开使用window.open引起来的浏览器阻止问题 js模拟form表单提交数据源码: /** * js模拟form表单提交 * @param ...

  4. Android开发欢迎页点击跳过倒计时进入主页

    没点击跳过自然进入主页,点击跳过之后立即进入主页     1.欢迎页布局activity_sp.xml放一张背景图(图片随你便啦)再放一个盛放倒计时的TextView   <?xml versi ...

  5. Android Studio计时跳转或点击跳转至主页面

    这个总体来说是比较简单的,计时跳转一般调用Android Studio中的Handler方法. 一.发生点击事件跳转页面 mBtnTextView = (Button) findViewById(R. ...

  6. react中实现点击跳转到新页面方法

    实现点击跳转到新页面,可以有两种形式,一个是本地页面打开,一个是本地页面不变跳转到新的页面. (一)页面点击本地页面打开新页面 引入ant的Button组件 <Button style={{ba ...

  7. 小程序点击跳转外部链接 微信小程序提示:不支持打开非业务域名怎么办 使用web-view 配置业务域名

    小程序点击跳转外部页面 1.index.wxml  添加点击事件   标签可以是小程序支持的 <!-- 邀请好友 --> <cover-image src='/img/invitat ...

  8. 在vue中无论使用router-link 还是 @click事件,发现都没法从列表页点击跳转到内容页去

    在vue中如论使用router-link 还是 @click事件,发现都没法从列表页点击跳转到内容页去,以前都是可以的,想着唯一不同的场景就是因为运用了scroll组件(https://ustbhua ...

  9. 【iOS】UIAlertView 点击跳转事件

    iOS 开发中,UIAlertView 经常用到.这里记录下曾用到的点击跳转事件. UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@& ...

随机推荐

  1. vmware 虚拟网卡配置

    VMware虚拟机进阶:[1]网卡配置 1. 可以在下面这个图中看到几种网络设置模式,一直以来我们都喜欢用桥接模式和NAT模式,因为这两种模式是最符合一般人上网设置的模式,下面我们就一种种介绍个大家 ...

  2. JavaScript高级程序设计学习笔记第十三章--事件

    事件冒泡: IE 的事件流,事件开始时由最具体的元素(文档中嵌套层次最深的那个节点)接收,然后逐级向上传播到较为不具体的节点(文档).例如: <!DOCTYPE html> <htm ...

  3. excel批量提取网页标题

    最近时间比较忙,有时候很多网页需要临时保存,以便空闲的时候查看.单纯的保存网页链接会让人很枯燥,所以需要自动批量提取标题. 为了这个小功能去写个小程序有点不划算,所以就利用excel实现了这个功能. ...

  4. xgene:WGS,突变与癌,RNA-seq,WES

     人类全基因组测序06 SNP(single nucleotide polymorphism):有了10倍以上的覆盖深度以后,来确认SNP信息,就相当可靠了. 一个普通黄种人的基因组,与hg19这个参 ...

  5. linux系统下file使用的magic文件格式说明

    magic 本手册是file命令所使用的magic文件的格式说明文档,版本是5.04. file命令用于识别文件类型,其他检测,检测文件内容中是否符合 'magic模式',也就是规则. /usr/sh ...

  6. Umbraco back office 登录不了,如何解决

    通过设置User的默认密码为"default", 它的Hash值为 bnWxWyFdCueCcKrqniYK9iAS+7E= 所以在SQL Server中执行以下脚本 UPDATE ...

  7. Invalidate()这个函数有什么用?

    c++中的这个函数,一会是刷新窗口的作用,一会是使区域无效.我搞不懂这个函数究竟是有什么作用?谢谢赐教. void Invalidate( BOOL bErase = TRUE ); 该函数的作用是使 ...

  8. HDU - 5950 Recursive sequence(二项式+矩阵合并+矩阵快速幂)

    Recursive sequence Farmer John likes to play mathematics games with his N cows. Recently, they are a ...

  9. 数据可视化系列--svg入门基础(一)

    一.前言 1.SVG(Scalable Vector Graphics)可伸缩矢量图形 特点: (1)使用xml格式来定义图形: (2)用来定义web上的使用的矢量图: (3)改变图像尺寸,图片质量不 ...

  10. 51nod1117【贪心】

    思路:哈夫曼树~~哇塞,那么有道理. 利用堆维护:每次从堆里取两个最小加起来,然后还是最小的两个,最后只剩一根总的 #include <bits/stdc++.h> using names ...