// 判断是否需要自动更新
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. 自定义View 实现软键盘实现搜索

    1. xml文件中加入自定义 搜索view <com.etoury.etoury.ui.view.IconCenterEditText android:id="@+id/search_ ...

  2. 利用icepdf将pdf文件转为图片

    所需jar 包为icepdf-core.jar.icepdf-extra.jar.icepdf-pro-intl.jar.icepdf-pro.jar和icepdf-viewer.jar. 示例代码如 ...

  3. cell1这个字符串如何截取掉前边的cell剩下后边的数字 后边数字长度不固定

    cell1这个字符串如何截取掉前边的cell剩下后边的数字  后边数字长度不固定'cell1'.replace(/cell/,'')string.substr(4)string.slice(4)

  4. C++ 文件操作(CFile类)

    原文:文件操作(CFile),C吉羊 一.Visual C++编程文件操作 有如下方法可进行操作: (1)使用标准C运行库函数,包括fopen.fclose.fseek等. (2)使用Win16下的文 ...

  5. HDU 3533 Escape BFS搜索

    题意:懒得说了 分析:开个no[100][100][1000]的bool类型的数组就行了,没啥可说的 #include <iostream> #include <cstdio> ...

  6. 统计计算与R语言的资料汇总(截止2016年12月)

    本文在Creative Commons许可证下发布. 在fedora Linux上断断续续使用R语言过了9年后,发现R语言在国内用的人逐渐多了起来.由于工作原因,直到今年暑假一个赴京工作的机会与一位统 ...

  7. ASP.NET服务器端控件(class0617)

    ASP.Net服务端基本控件介绍 ASP.Net服务端控件是ASP.Net对HTML的封装,在C#代码中就可以用txt1.Text=‘abc’这种方式来修改input的值,ASP.Net会将服务端控件 ...

  8. 配置OpenStack以使用LDAP实现身份管理

    本文展示了如何配置 Keystone,以便使用轻量级目录http://www.aliyun.com/zixun/aggregation/34570.html">访问协议( LDAP)服 ...

  9. Android实例-程序界面内截取屏幕(XE8+小米2)

    结果: 1.只能截取程序界面内的图片. 2.图片有点不清楚,自己设置清楚度. 实例代码: unit Unit1; interface uses System.SysUtils, System.Type ...

  10. nyoj 49 开心的小明

    开心的小明 时间限制:1000 ms  |  内存限制:65535 KB 难度:4   描述 小明今天很开心,家里购置的新房就要领钥匙了,新房里有一间他自己专用的很宽敞的房间.更让他高兴的是,妈妈昨天 ...