// 判断是否需要自动更新
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. MySQL查询执行过程

    MySQL查询执行路径 1. 客户端发送一条查询给服务器: 2. 服务器先会检查查询缓存,如果命中了缓存,则立即返回存储在缓存中的结果.否则进入下一阶段: 3. 服务器端进行SQL解析.预处理,再由优 ...

  2. ArcGIS 读写lyr层文件

    原文arcengine C# 读写lyr(转) 写lyr IFeatureLayer LineLayer = axMapControl1.get_Layer() as IFeatureLayer; I ...

  3. C# using SendMessage, problem with WM_COPYDATA z

    The final missing piece depends on if you are using any processor, x86 or x64. The details using the ...

  4. 【mongodb 学习一】环境搭建之 mac 下连接 mongodb 的UI 客户端

    记录下 mongodb 的学习 懒得自己达 mongodb 的服务器了 虽然一句命令就能搞定了 brew install mongodb 可是考虑到以后的应用还是放在网上的,就直接用现成的服务吧 下载 ...

  5. 【转】vnc centos

    原文:http://www.cnblogs.com/niocai/archive/2011/11/02/2233332.html 我的CentOS版本是6.0,下述方法在i386和x86_64中均适用 ...

  6. 在MFC框架中使用OpenGL的简单实例

    引言 我们知道,在MFC框架中,用于绘图的接口是GDI.但GDI只能绘制简单的2D图形,要想制作精美的3D图形,一个可行的办法是使用OpenGL或者Direct3D等第三方库. 由于最近在给导师的一个 ...

  7. jenkins api调用

    在使用jenkins的时候,有时候需要其他外部调用,下面是调用方法,不定期更新 job调用 使用user和password: curl -X POST "jobPath/buildWithP ...

  8. STL --最常见的容器使用要点

    如果只是要找到STL某个容器的用法, 可以参考msdn和C++ Library Reference,msdn 上面的知识点应该是最新的,C++ Library Reference虽古老但是很多经典的容 ...

  9. algorithm@ Divide two integers without using multiplication, division and mod operator. (Bit Operation)

    #include<bits/stdc++.h> using namespace std; int divide(int dividend, int divisor) { long long ...

  10. HDU-4705 Y 树形DP

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4705 题意:给一颗树,从树上任意选择3个点{A,B,C},要求他们不在一条链上,求总共的数目. 容易想 ...