// 判断是否需要自动更新
boolean autoUpdate = mPref.getBoolean("auto_update", true);
if (autoUpdate) {
checkVerson();
} else {
mHandler.sendEmptyMessageDelayed(CODE_ENTER_HOME, );// 延时2秒后发送消息
}
// 渐变的动画效果
AlphaAnimation anim = new AlphaAnimation(0.3f, 1f);//透明度从0.3到1
anim.setDuration();//延迟时间是2秒
rlRoot.startAnimation(anim);//rlRoot是闪屏页xml的根布局

SettingActivity.java

package com.itheima52.mobilesafe.activity;

import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener; import com.itheima52.mobilesafe.R;
import com.itheima52.mobilesafe.view.SettingItemView; /**
* 设置中心
*/
public class SettingActivity extends Activity { private SettingItemView sivUpdate;// 设置升级
private SharedPreferences mPref; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_setting); mPref = getSharedPreferences("config", MODE_PRIVATE); sivUpdate = (SettingItemView) findViewById(R.id.siv_update);
// sivUpdate.setTitle("自动更新设置"); boolean autoUpdate = mPref.getBoolean("auto_update", true);//是否自动更新,true是默认值。 if (autoUpdate) {
// sivUpdate.setDesc("自动更新已开启");
sivUpdate.setChecked(true);
} else {
// sivUpdate.setDesc("自动更新已关闭");
sivUpdate.setChecked(false);
} sivUpdate.setOnClickListener(new OnClickListener() { @Override
public void onClick(View v) {
// 判断当前的勾选状态
if (sivUpdate.isChecked()) {
// 设置不勾选
sivUpdate.setChecked(false);
// sivUpdate.setDesc("自动更新已关闭");
// 更新是否自动更新
mPref.edit().putBoolean("auto_update", false).commit();
} else {
sivUpdate.setChecked(true);
// sivUpdate.setDesc("自动更新已开启");
// 更新是否自动更新
mPref.edit().putBoolean("auto_update", true).commit();
}
}
});
}
}

activity_setting.xml

<!--
xmlns:android="http://schemas.android.com/apk/res/android"中的android是命名空间,
xmlns:itheima="http://schemas.android.com/apk/res/com.itheima52.mobilesafe"中的itheima是命名空间,com.itheima52.mobilesafe是清单文件中的包名。
-->
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:itheima="http://schemas.android.com/apk/res/com.itheima52.mobilesafe"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" > <TextView
style="@style/TitleStyle"
android:text="设置中心" />
<!--style.xml
<style name="TitleStyle">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">50dp</item>
<item name="android:background">#8866ff00</item>
<item name="android:gravity">center</item>
<item name="android:textColor">@color/black</item>
<item name="android:textSize">22sp</item>
</style>
--> <!-- 加载这个控件的时候会去调用SettingItemView的构造函数,
调用构造函数的时候会去执行initView()方法加载R.layout.view_setting_item布局。 -->
<com.itheima52.mobilesafe.view.SettingItemView
android:id="@+id/siv_update"
android:layout_width="match_parent"
android:layout_height="wrap_content"
itheima:desc_off="自动更新已关闭"
itheima:desc_on="自动更新已开启"
itheima:title="自动更新设置" /> <!--自定义属性,values文件夹下attrs.xml,SettingItemView相当于是一个TextView,下面是TextView的属性。
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="SettingItemView">
<attr name="title" format="string" />
<attr name="desc_on" format="string" />
<attr name="desc_off" format="string" />
</declare-styleable>
</resources> --> </LinearLayout>

自定义控件SettingItemView.java

package com.itheima52.mobilesafe.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.CheckBox;
import android.widget.RelativeLayout;
import android.widget.TextView; import com.itheima52.mobilesafe.R; /**
* 设置中心的自定义组合控件
*/
public class SettingItemView extends RelativeLayout {//RelativeLayout是一个ViewGroup也就是一个View的容器。
//NAMESPACE是xmlns:itheima="http://schemas.android.com/apk/res/com.itheima52.mobilesafe"中itheima的位置。
private static final String NAMESPACE = "http://schemas.android.com/apk/res/com.itheima52.mobilesafe";
private TextView tvTitle;
private TextView tvDesc;
private CheckBox cbStatus;
private String mTitle;
private String mDescOn;
private String mDescOff;
//xml布局解析成java对象的时候有style走这个方法
public SettingItemView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
initView();
}
//xml布局解析成java对象的时候有属性走这个方法
public SettingItemView(Context context, AttributeSet attrs) {
super(context, attrs);
mTitle = attrs.getAttributeValue(NAMESPACE, "title");// 根据属性名称,获取属性的值
mDescOn = attrs.getAttributeValue(NAMESPACE, "desc_on");
mDescOff = attrs.getAttributeValue(NAMESPACE, "desc_off");
initView(); int attributeCount = attrs.getAttributeCount();
for (int i = 0; i < attributeCount; i++) {
String attributeName = attrs.getAttributeName(i);
String attributeValue = attrs.getAttributeValue(i);
System.out.println(attributeName + "=" + attributeValue);
}
}
//不通过xml布局用代码new走这个方法
public SettingItemView(Context context) {
super(context);
initView();
} /**
* 初始化布局
*/
private void initView() {
// 将自定义好的布局文件设置给当前的SettingItemView,this将成为view_setting_item的父容器,this是一个ViewGroup是一个view容器可以拥有子布局。
View.inflate(getContext(), R.layout.view_setting_item, this);//View里面用getContext()拿到context对象。
//view_setting_item.xml
/*<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="70dp" 整个RelativeLayout的高度
android:padding="5dp" >
<TextView
android:id="@+id/tv_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/black"
android:textSize="22sp" />
<TextView
android:id="@+id/tv_desc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/tv_title"
android:layout_marginTop="3dp"
android:textColor="#a000"
android:textSize="18sp" />
<CheckBox
android:id="@+id/cb_status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:clickable="false" 不能点击
android:focusable="false" 不能获取焦点
android:focusableInTouchMode="false" /> 触摸状态能不能获取焦点
<View
android:layout_width="match_parent"
android:layout_height="0.2dp"
android:layout_alignParentBottom="true"
android:background="#a000" />
</RelativeLayout>*/
tvTitle = (TextView) findViewById(R.id.tv_title);
tvDesc = (TextView) findViewById(R.id.tv_desc);
cbStatus = (CheckBox) findViewById(R.id.cb_status); setTitle(mTitle);// 设置标题
} public void setTitle(String title) {
tvTitle.setText(title);
} public void setDesc(String desc) {
tvDesc.setText(desc);
} /**
* 返回勾选状态
*/
public boolean isChecked() {
return cbStatus.isChecked();
} public void setChecked(boolean check) {
cbStatus.setChecked(check); // 根据选择的状态,更新文本描述
if (check) {
setDesc(mDescOn);
} else {
setDesc(mDescOff);
}
}
}

android131 360 02 设置中心的更多相关文章

  1. android131 360 01 闪屏页和主页面

    主界面: 软件升级流程: 清单文件: <?xml version="1.0" encoding="utf-8"?> <manifest xml ...

  2. android131 360 03 输入密码

    package com.itheima52.mobilesafe.activity; import android.app.Activity; import android.app.AlertDial ...

  3. android131 360 05 手势触摸滑动,sim卡,开机启动的广播,手机联系人,SharedPreferences,拦截短信

    安卓手势触摸滑动: package com.itheima52.mobilesafe.activity; import android.app.Activity; import android.con ...

  4. android131 360 04 手机安全页面

    ## Root权限 ## > 什么是Root权限? Root权限相当于系统管理员权限, 有了root权限,就可以随意修改和删除手机内部的文件. > 一般手机购买之后, 都没有root权限. ...

  5. AWR報告詳解

    AWR是Oracle  10g 版本 推出的新特性, 全称叫Automatic Workload Repository-自动负载信息库, AWR 是通过对比两次快照(snapshot)收集到的统计信息 ...

  6. 02.Windows2012R2安装360安全卫士失败及无法卸载问题

    问题: Windows 2012 R2 安装360安全卫士失败及无法卸载,导致网络无法通信问题解决. 解决:1.进入 Windows2012R2 安全模式下:2.进行覆盖安装360安全卫士:3.覆盖安 ...

  7. [原创]LoadRunner 12.02 录制脚本时提示无Internet访问,如何解决?

    在使用LoadRunner 12.02 进行录制脚本时提示无Internet访问,如下图: 翻译中文如下: 可以尝试以下方式解决:点击弹出框中的“Yes”即可. 若还是有问题,尝试以下方式: (1)L ...

  8. 《30天自制操作系统》笔记(02)——导入C语言

    <30天自制操作系统>笔记(02)——导入C语言 进度回顾 在上一篇,记录了计算机开机时加载IPL程序(initial program loader,一个nas汇编程序)的情况,包括IPL ...

  9. 分享4种CSS3效果(360度旋转、旋转放大、放大、移动)

    转自:http://www.j                     q-school.com/Show.aspx?id=281 本文仅供自己学习而转载,由于效果掩饰地址的转载出现问题,强烈建议去源 ...

随机推荐

  1. echarts-noDataLoadingOption问题

    目前echarts暂时不支持noDataLoadingOption外挂,所以我为此diy了一个无数据展示文字. 但是echarts很奇怪,它是判断serises==[]空数组才会自动出现echarts ...

  2. HDU 1533 Going Home (最小费用流)

    题意: 一个矩阵n*m,其中有k个房子和k个人,k个人分别必须走到任意一个房子中(匹配),但是权值就是长度(非欧拉距离),求匹配完的权之和. 思路: 建图方法是,首先将k个人和k个房子分别抽出来到集合 ...

  3. 对 Azure 虚拟网络网关的改进

    YU-SHUN WANG Azure 网络高级项目经理 在 2014 年欧洲 TechEd 大会上,我们宣布了对Azure 虚拟网络网关的多项改进: 1.  高性能网关 SKU 2.  Azure 虚 ...

  4. 【转】C,C++中使用可变参数

    可变参数即表示参数个数可以变化,可多可少,也表示参数的类型也可以变化,可以是 int,double还可以是char*,类,结构体等等.可变参数是实现printf(),sprintf()等函数的关键之处 ...

  5. [JS前端开发] js/jquery控制页面动态加载数据 滑动滚动条自动加载事件

    页面滚动动态加载数据,页面下拉自动加载内容 相信很多人都见过瀑布流图片布局,那些图片是动态加载出来的,效果很好,对服务器的压力相对来说也小了很多 有手机的相信都见过这样的效果:进入qq空间,向下拉动空 ...

  6. 黑盒测试用例设计方法&理论结合实际 -> 场景法

    一概念 现在的软件几乎都是用事件触发来控制流程的,事件触发时的情景便形成了场景,而同一事件不同的触发顺序和处理结果就形成事件流.这种在软件设计方面的思想也可以引入到软件测试中,可以比较生动地描绘出事件 ...

  7. 【原】理解Storm拓扑的并行

    Storm入门教程 1. Storm基础 Storm Storm主要特点 Storm基本概念 Storm调度器 Storm配置 Guaranteeing Message Processing(消息处理 ...

  8. JDK1.5新特性(六)……Generics

    概述 Generics - This long-awaited enhancement to the type system allows a type or method to operate on ...

  9. algorithm: heap sort in python 算法导论 堆排序

    An Python implementation of heap-sort based on the detailed algorithm description in Introduction to ...

  10. SRM 599 DIV 2

    rating又掉了...变灰色了%>_<%.250pt很简单,一眼看上去是个背包,没有多想立马写了个01背包,后面发现其实就是个简单的排序...因为只是需要求数量而已.500pt被我写残了 ...