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:@& ...
随机推荐
- sulime的必备插件
常用插件 : SideBarEnhancements HTML-CSS-JS Prettify BracketHighlighter SublimeCodeIntel Emmet CTags Mark ...
- 【转】Android Menu
Menu由两种形式,Option menu和Context menu.前者是按下设备的Menu硬按钮弹出,后者是长按widget弹出. Option Menu 当我们按下Menu的硬件按钮时,Opti ...
- css3 翻起页脚
html <div class="demo2"> <img src="images/1.jpg"> </div> css . ...
- Java 日志记录规则
Java 日志记录规则 规则一:日志是面向读者的 我们不应该让无价值的信息使日志文件变得乱糟糟,比如说完整打印所有的实体字段. 通常,实体名字和其逻辑关键字足以识别在表格中的一条记录了. 规则二:匹配 ...
- openstack介绍(二)
OpenStack services 本节将详细描述OpenStack服务. Compute service overview(计算服务概述) 使用OpenStack云计算计算主机和管理系统.Open ...
- 【hdu2955】 Robberies 01背包
标签:01背包 hdu2955 http://acm.hdu.edu.cn/showproblem.php?pid=2955 题意:盗贼抢银行,给出n个银行,每个银行有一定的资金和抢劫后被抓的概率,在 ...
- Redis使用的相关问题
Redis用那些数据结构? 字符串类型String 字典Hash 列表List 集合Set 有序集合SortedSet HyperLogLog.Geo.Pub/Sub Redis Module.Blo ...
- hostent结构体和wsadata结构体
一.hostent结构体 使用这个东西,首先要包含2个头文件:#include <netdb.h>#include <sys/socket.h> struct hostent ...
- 大话Spark(1)-Spark概述与核心概念
说到Spark就不得不提MapReduce/Hadoop, 当前越来越多的公司已经把大数据计算引擎从MapReduce升级到了Spark. 至于原因当然是MapReduce的一些局限性了, 我们一起先 ...
- Flutter起步之安装
官网有介绍的这里就不说,主要有几个步骤: 镜像设置 下载flutter SDK(更新系统环境变量PATH,先不要运行flutter doctor,因为你还没有装android sdk和编辑器) and ...