Setting 之dashboard 点击跳转流程
设置的主界面的可以通过修改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 点击跳转流程的更多相关文章
- php防盗链,php ci在control里面控制除了自己站内的链接点击跳转,其他来源的都跳到站内页面
php防盗链,php ci在control里面控制除了自己站内的链接点击跳转,其他来源的都跳到站内页面 $route['jump/(:any)/(:any)'] = "index/jump/ ...
- html锚点 点击跳转到页面指定位置
本来是在看阮大神写的ajax教程,突然发现点击目录文字会跳转到相对应的文本内容,于是乎激发了我的兴趣. 这个究竟怎么做的,刚开始看的时候一知半解,找度娘就是:"点击跳转到页面指定位置&quo ...
- js模拟form表单提交数据, js模拟a标签点击跳转,避开使用window.open引起来的浏览器阻止问题
js模拟form表单提交数据, js模拟a标签点击跳转,避开使用window.open引起来的浏览器阻止问题 js模拟form表单提交数据源码: /** * js模拟form表单提交 * @param ...
- Android开发欢迎页点击跳过倒计时进入主页
没点击跳过自然进入主页,点击跳过之后立即进入主页 1.欢迎页布局activity_sp.xml放一张背景图(图片随你便啦)再放一个盛放倒计时的TextView <?xml versi ...
- Android Studio计时跳转或点击跳转至主页面
这个总体来说是比较简单的,计时跳转一般调用Android Studio中的Handler方法. 一.发生点击事件跳转页面 mBtnTextView = (Button) findViewById(R. ...
- react中实现点击跳转到新页面方法
实现点击跳转到新页面,可以有两种形式,一个是本地页面打开,一个是本地页面不变跳转到新的页面. (一)页面点击本地页面打开新页面 引入ant的Button组件 <Button style={{ba ...
- 小程序点击跳转外部链接 微信小程序提示:不支持打开非业务域名怎么办 使用web-view 配置业务域名
小程序点击跳转外部页面 1.index.wxml 添加点击事件 标签可以是小程序支持的 <!-- 邀请好友 --> <cover-image src='/img/invitat ...
- 在vue中无论使用router-link 还是 @click事件,发现都没法从列表页点击跳转到内容页去
在vue中如论使用router-link 还是 @click事件,发现都没法从列表页点击跳转到内容页去,以前都是可以的,想着唯一不同的场景就是因为运用了scroll组件(https://ustbhua ...
- 【iOS】UIAlertView 点击跳转事件
iOS 开发中,UIAlertView 经常用到.这里记录下曾用到的点击跳转事件. UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@& ...
随机推荐
- 15 Vue项目部署
前言: VUE 是一个javascript的前端框架,注定了它是运行在浏览器里的,对服务器本地没有任何要求,只要一个静态文件服务器能通过http访问到其资源文件就足矣!无论你是用apache ,ngn ...
- bzoj4453
单调栈+set+后缀数组 一道奇妙的题 这道题如果对于每个询问$r$是固定的,那么就很简单了,可惜并不是 由于r会变化,那么对于两个子串$[i...r],[j...r]$,他们的大小关系随着r的变化也 ...
- java 通过System.getProperties()获取系统参数
转自:https://www.cnblogs.com/ksuifeng/archive/2010/09/25/1834416.html 1.java的System.getProperty()方法可以获 ...
- PCL推荐的命名规范(2)
博客转载自:http://www.pclcn.org/study/shownews.php?lang=cn&id=210 函数/成员函数命名 函数和类的成员函数的命名应该采用camelCase ...
- Linux下使用doxygen+vim生成c语言源程序文档的方法
1.安装 doxygen 有两种获得 doxygen 的方法.可以下载预编译的可执行文件,也可以从 SVN 存储库下载源代码并自己编译.清单 1 演示的是后一种方法. 清单 1. 安装和构建 doxy ...
- 使用gRPC搭建Server端与Client端
gRPC简介 gRPC是一种RPC框架技术,采用Protocal Buffers(协议缓存) 作为其接口定义的语言(就是Proto来写接口)和基础的消息交换格式. 在gRPC中,客户端应用程序可以直接 ...
- Git 分支管理 多人协作 远程仓库 补充
当你从远程仓库克隆时,实际上Git自动把本地的master分支和远程的master分支对应起来了, 并且,远程仓库的默认名称是origin. 如果是本地仓库关联远程仓库 --- 要查看远程库的信息,用 ...
- SP2-0734: 未知的命令开头 “IMP ” - 忽略了剩余的行
描述 在cmd命令窗口中使用imp命令将dmp文件导入到oracle中时,出现了错误: SP2-0734: 未知的命令开头 “IMP ” - 忽略了剩余的行,如图 原因 imp命令是oracle提供的 ...
- GoWeb开发_Iris框架讲解(一)
Golang介绍 Go语言是谷歌推出的一种全新的编程语言,可以在不损失应用程序性能的情况下降低代码的复杂性.谷歌首席软件工程师罗布派克(Rob Pike)说:我们之所以开发Go,是因为过去10多年间软 ...
- ORM应用
目录 ORM概念 ORM由来 ORM的优势 ORM的劣势 ORM总结 ORM 与 DB 的对应关系图 Model 模块 ORM操作 增删改查操作 ORM概念 对象关系映射(Object Relatio ...