手机卫士07-设置向导

简介: 今天,我们要做的就是给我们的手机防盗这个功能添加一个设置向导的功能啦,指导用户进行一些设置,废话不多说,直接上图,看看我们要做的效果      UI不是很好看,各位可以自己修改一下哈 好啦,我们今天主要是把这两个界面写出来,还有把一些逻辑代码写一下 其实这主要就是两个xml文件啦 setup_guide1.xml &

今天,我们要做的就是给我们的手机防盗这个功能添加一个设置向导的功能啦,指导用户进行一些设置,废话不多说,直接上图,看看我们要做的效果

    


UI不是很好看,各位可以自己修改一下哈

好啦,我们今天主要是把这两个界面写出来,还有把一些逻辑代码写一下

其实这主要就是两个xml文件啦

setup_guide1.xml

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3.     android:layout_width="match_parent"
  4.     android:layout_height="match_parent"
  5.     android:background="@drawable/title_background"
  6.     android:orientation="vertical" >
  7.     
  8.     <TextView 
  9.         style="@style/SetupGuideTitle"
  10.         android:text="@string/guide1"/>
  11.     
  12.     <TextView 
  13.         style="@style/SetGuideUnderline"/>
  14.     
  15.     <TextView 
  16.         style="@style/SetupGuideContent"
  17.         android:text="@string/guide1_content"/>
  18.     
  19.     <TextView 
  20.         style="@style/SetupGuideItem"
  21.         android:text="@string/guide1_item1"/>
  22.     
  23.     <TextView 
  24.         style="@style/SetupGuideItem"
  25.         android:text="@string/guide1_item2"/>
  26.     
  27.     <TextView 
  28.         style="@style/SetupGuideItem"
  29.         android:text="@string/guide1_item3"/>
  30.     
  31.     <TextView 
  32.         style="@style/SetupGuideItem"
  33.         android:text="@string/guide1_item4"/>
  34.     
  35.     <LinearLayout 
  36.         android:layout_width="match_parent"
  37.         android:layout_height="wrap_content"
  38.         android:layout_marginTop="8dip"
  39.         android:gravity="center_horizontal"
  40.         android:orientation="horizontal">
  41.         
  42.         <ImageView 
  43.             android:layout_width="wrap_content"
  44.             android:layout_height="wrap_content"
  45.             android:src="@android:drawable/presence_online"
  46.             android:contentDescription="@string/hello_world"/>
  47.         
  48.         <ImageView 
  49.             android:layout_width="wrap_content"
  50.             android:layout_height="wrap_content"
  51.             android:src="@android:drawable/presence_invisible"
  52.             android:contentDescription="@string/hello_world"/>
  53.         
  54.         <ImageView 
  55.             android:layout_width="wrap_content"
  56.             android:layout_height="wrap_content"
  57.             android:src="@android:drawable/presence_invisible"
  58.             android:contentDescription="@string/hello_world"/>
  59.         
  60.         <ImageView 
  61.             android:layout_width="wrap_content"
  62.             android:layout_height="wrap_content"
  63.             android:src="@android:drawable/presence_invisible"
  64.             android:contentDescription="@string/hello_world"/>
  65.         
  66.     </LinearLayout>
  67.     
  68.     <RelativeLayout 
  69.         android:layout_width="match_parent"
  70.         android:layout_height="match_parent"
  71.         android:gravity="center_horizontal|center_vertical">
  72.         
  73.         <LinearLayout 
  74.             android:layout_width="match_parent"
  75.                 android:layout_height="match_parent"
  76.                 android:gravity="center_horizontal|center_vertical">
  77.                 
  78.                 <ImageView 
  79.                     android:layout_width="150dip"
  80.                     android:layout_height="150dip"
  81.                     android:src="@drawable/widget01"
  82.                     android:contentDescription="@string/hello_world"/>
  83.         
  84.         </LinearLayout>
  85.         
  86.         <Button 
  87.             android:id="@+id/bt_guide_next"
  88.             android:layout_width="wrap_content"
  89.             android:layout_height="wrap_content"
  90.             android:text="@string/next"
  91.             android:drawableRight="@drawable/next"
  92.             android:layout_alignParentBottom="true"
  93.             android:layout_alignParentRight="true"/>
  94.         
  95.     </RelativeLayout>
  96.         
  97. </LinearLayout>
复制代码
setup_guide2.xml

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3.     android:layout_width="match_parent"
  4.     android:layout_height="match_parent"
  5.     android:background="@drawable/title_background"
  6.     android:orientation="vertical" >
  7.     
  8.     <TextView 
  9.         style="@style/SetupGuideTitle"
  10.         android:text="@string/guide2"/>
  11.     
  12.     <TextView 
  13.         style="@style/SetGuideUnderline"/>
  14.     
  15.     <TextView 
  16.         style="@style/SetupGuideContent"
  17.         android:text="@string/guide2_content"/>
  18.     
  19.     <LinearLayout 
  20.         android:layout_width="match_parent"
  21.         android:layout_height="wrap_content"
  22.         android:orientation="horizontal">
  23.         
  24.         <Button 
  25.             android:id="@+id/bt_guide_bind"
  26.             android:layout_width="240dip"
  27.             android:layout_height="wrap_content"
  28.             android:layout_marginTop="8dip"
  29.             android:text="@string/guide2_item1"/>
  30.         
  31.         <CheckBox 
  32.             android:id="@+id/cb_guide_check"
  33.             android:layout_width="wrap_content"
  34.             android:layout_height="wrap_content"
  35.             android:text="@string/guide2_item2"/>
  36.         
  37.     </LinearLayout>
  38.     
  39.     <LinearLayout 
  40.         android:layout_width="match_parent"
  41.         android:layout_height="wrap_content"
  42.         android:layout_marginTop="20dip"
  43.         android:gravity="center_horizontal"
  44.         android:orientation="horizontal">
  45.         
  46.         <ImageView 
  47.             android:layout_width="wrap_content"
  48.             android:layout_height="wrap_content"
  49.             android:src="@android:drawable/presence_invisible"
  50.             android:contentDescription="@string/hello_world"/>
  51.         
  52.         <ImageView 
  53.             android:layout_width="wrap_content"
  54.             android:layout_height="wrap_content"
  55.             android:src="@android:drawable/presence_online"
  56.             android:contentDescription="@string/hello_world"/>
  57.         
  58.         <ImageView 
  59.             android:layout_width="wrap_content"
  60.             android:layout_height="wrap_content"
  61.             android:src="@android:drawable/presence_invisible"
  62.             android:contentDescription="@string/hello_world"/>
  63.         
  64.         <ImageView 
  65.             android:layout_width="wrap_content"
  66.             android:layout_height="wrap_content"
  67.             android:src="@android:drawable/presence_invisible"
  68.             android:contentDescription="@string/hello_world"/>
  69.         
  70.     </LinearLayout>
  71.     
  72.     <RelativeLayout 
  73.         android:layout_width="match_parent"
  74.         android:layout_height="match_parent"
  75.         android:gravity="center_horizontal|center_vertical">
  76.         
  77.         <LinearLayout 
  78.             android:layout_width="match_parent"
  79.                 android:layout_height="match_parent"
  80.                 android:gravity="center_horizontal|center_vertical">
  81.                 
  82.                 <ImageView 
  83.                     android:layout_width="150dip"
  84.                     android:layout_height="150dip"
  85.                     android:src="@drawable/guide2"
  86.                     android:contentDescription="@string/hello_world"/>
  87.         
  88.         </LinearLayout>
  89.         
  90.         <Button 
  91.             android:id="@+id/bt_guide_pervious"
  92.             android:layout_width="wrap_content"
  93.             android:layout_height="wrap_content"
  94.             android:text="@string/perviout"
  95.             android:drawableRight="@drawable/previous"
  96.             android:layout_alignParentBottom="true"
  97.             android:layout_alignParentLeft="true"/>
  98.         
  99.         <Button 
  100.             android:id="@+id/bt_guide_next"
  101.             android:layout_width="wrap_content"
  102.             android:layout_height="wrap_content"
  103.             android:text="@string/next"
  104.             android:drawableRight="@drawable/next"
  105.             android:layout_alignParentBottom="true"
  106.             android:layout_alignParentRight="true"/>
  107.         
  108.     </RelativeLayout>
  109.         
  110. </LinearLayout>
复制代码
setup_guide3.xml

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3.     android:layout_width="match_parent"
  4.     android:layout_height="match_parent"
  5.     android:background="@drawable/title_background"
  6.     android:orientation="vertical" >
  7.     
  8.     <TextView 
  9.         style="@style/SetupGuideTitle"
  10.         android:text="@string/guide1"/>
  11.     
  12.     <TextView 
  13.         style="@style/SetGuideUnderline"/>
  14.     
  15.     <TextView 
  16.         style="@style/SetupGuideContent"
  17.         android:text="@string/guide1_content"/>
  18.     
  19.     <TextView 
  20.         style="@style/SetupGuideItem"
  21.         android:text="@string/guide1_item1"/>
  22.     
  23.     <TextView 
  24.         style="@style/SetupGuideItem"
  25.         android:text="@string/guide1_item2"/>
  26.     
  27.     <TextView 
  28.         style="@style/SetupGuideItem"
  29.         android:text="@string/guide1_item3"/>
  30.     
  31.     <TextView 
  32.         style="@style/SetupGuideItem"
  33.         android:text="@string/guide1_item4"/>
  34.     
  35.     <LinearLayout 
  36.         android:layout_width="match_parent"
  37.         android:layout_height="wrap_content"
  38.         android:layout_marginTop="8dip"
  39.         android:gravity="center_horizontal"
  40.         android:orientation="horizontal">
  41.         
  42.         <ImageView 
  43.             android:layout_width="wrap_content"
  44.             android:layout_height="wrap_content"
  45.             android:src="@android:drawable/presence_online"
  46.             android:contentDescription="@string/hello_world"/>
  47.         
  48.         <ImageView 
  49.             android:layout_width="wrap_content"
  50.             android:layout_height="wrap_content"
  51.             android:src="@android:drawable/presence_invisible"
  52.             android:contentDescription="@string/hello_world"/>
  53.         
  54.         <ImageView 
  55.             android:layout_width="wrap_content"
  56.             android:layout_height="wrap_content"
  57.             android:src="@android:drawable/presence_invisible"
  58.             android:contentDescription="@string/hello_world"/>
  59.         
  60.         <ImageView 
  61.             android:layout_width="wrap_content"
  62.             android:layout_height="wrap_content"
  63.             android:src="@android:drawable/presence_invisible"
  64.             android:contentDescription="@string/hello_world"/>
  65.         
  66.     </LinearLayout>
  67.     
  68.     <RelativeLayout 
  69.         android:layout_width="match_parent"
  70.         android:layout_height="match_parent"
  71.         android:gravity="center_horizontal|center_vertical">
  72.         
  73.         <LinearLayout 
  74.             android:layout_width="match_parent"
  75.                 android:layout_height="match_parent"
  76.                 android:gravity="center_horizontal|center_vertical">
  77.                 
  78.                 <ImageView 
  79.                     android:layout_width="150dip"
  80.                     android:layout_height="150dip"
  81.                     android:src="@drawable/widget01"
  82.                     android:contentDescription="@string/hello_world"/>
  83.         
  84.         </LinearLayout>
  85.         
  86.         <Button 
  87.             android:id="@+id/bt_guide_next"
  88.             android:layout_width="wrap_content"
  89.             android:layout_height="wrap_content"
  90.             android:text="@string/next"
  91.             android:drawableRight="@drawable/next"
  92.             android:layout_alignParentBottom="true"
  93.             android:layout_alignParentRight="true"/>
  94.         
  95.     </RelativeLayout>
  96.         
  97. </LinearLayout>
复制代码
setup_guide4.xml

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3.     android:layout_width="match_parent"
  4.     android:layout_height="match_parent"
  5.     android:background="@drawable/title_background"
  6.     android:orientation="vertical" >
  7.     
  8.     <TextView 
  9.         style="@style/SetupGuideTitle"
  10.         android:text="@string/guide4"/>
  11.     
  12.     <TextView 
  13.         style="@style/SetGuideUnderline"/>
  14.     
  15.     <TextView 
  16.         style="@style/SetupGuideContent"
  17.         android:text="@string/guide4_content"/>
  18.     
  19.     <CheckBox 
  20.         android:id="@+id/cb_guide_protected"
  21.         android:layout_width="wrap_content"
  22.         android:layout_height="wrap_content"
  23.         android:textColor="@android:color/white"
  24.         android:text="@string/guide4_item1"/>
  25.     
  26.     <LinearLayout 
  27.         android:layout_width="match_parent"
  28.         android:layout_height="wrap_content"
  29.         android:layout_marginTop="8dip"
  30.         android:gravity="center_horizontal"
  31.         android:orientation="horizontal">
  32.         
  33.         <ImageView 
  34.             android:layout_width="wrap_content"
  35.             android:layout_height="wrap_content"
  36.             android:src="@android:drawable/presence_invisible"
  37.             android:contentDescription="@string/hello_world"/>
  38.         
  39.         <ImageView 
  40.             android:layout_width="wrap_content"
  41.             android:layout_height="wrap_content"
  42.             android:src="@android:drawable/presence_invisible"
  43.             android:contentDescription="@string/hello_world"/>
  44.         
  45.         <ImageView 
  46.             android:layout_width="wrap_content"
  47.             android:layout_height="wrap_content"
  48.             android:src="@android:drawable/presence_invisible"
  49.             android:contentDescription="@string/hello_world"/>
  50.         
  51.         <ImageView 
  52.             android:layout_width="wrap_content"
  53.             android:layout_height="wrap_content"
  54.             android:src="@android:drawable/presence_online"
  55.             android:contentDescription="@string/hello_world"/>
  56.         
  57.     </LinearLayout>
  58.     
  59.     <RelativeLayout 
  60.         android:layout_width="match_parent"
  61.         android:layout_height="match_parent"
  62.         android:gravity="center_horizontal|center_vertical">
  63.         
  64.         <LinearLayout 
  65.             android:layout_width="match_parent"
  66.                 android:layout_height="match_parent"
  67.                 android:gravity="center_horizontal|center_vertical">
  68.                 
  69.                 <ImageView 
  70.                     android:layout_width="150dip"
  71.                     android:layout_height="150dip"
  72.                     android:src="@drawable/guide4"
  73.                     android:contentDescription="@string/hello_world"/>
  74.         
  75.         </LinearLayout>
  76.         
  77.         <Button 
  78.             android:id="@+id/bt_guide_pervious"
  79.             android:layout_width="wrap_content"
  80.             android:layout_height="wrap_content"
  81.             android:text="@string/perviout"
  82.             android:drawableRight="@drawable/previous"
  83.             android:layout_alignParentBottom="true"
  84.             android:layout_alignParentLeft="true"/>
  85.         
  86.         <Button 
  87.             android:layout_width="wrap_content"
  88.             android:layout_height="wrap_content"
  89.             android:text="@string/finish"
  90.             android:drawableRight="@drawable/next"
  91.             android:layout_alignParentBottom="true"
  92.             android:layout_alignParentRight="true"/>
  93.         
  94.     </RelativeLayout>
  95.         
  96. </LinearLayout>
复制代码
上面四个xml文件,就是我们要做的向导的界面啦,其中都用到了样式的定义,各位如果有什么不明白的,可以回头再看一下我们之前写的,毕竟是一步接一步的,肯定要先把前面的弄清楚的,因为后面还会用到那些知识点的。我们今天主要是把前两个页面的逻辑加上,后面两个页面的逻辑在明天再加,因为第三个页面,要涉及到读取用户的联系人这一非常常用的操作,所以单独来讲一下我们的设置向导是在用户第一次打开我们的手机防盗这个功能时才启动的,所以我们还要在手机防盗这个功能的界面里面加一些逻辑,好,废话不多说, 直接上代码com.xiaobin.security.ui.LostProtectedActivity
  1. package com.xiaobin.security.ui;

  2. import android.app.Activity;
  3. import android.app.Dialog;
  4. import android.content.Context;
  5. import android.content.Intent;
  6. import android.content.SharedPreferences;
  7. import android.content.SharedPreferences.Editor;
  8. import android.os.Bundle;
  9. import android.view.View;
  10. import android.view.View.OnClickListener;
  11. import android.widget.Button;
  12. import android.widget.EditText;
  13. import android.widget.Toast;

  14. import com.xiaobin.security.R;
  15. import com.xiaobin.security.utils.MD5Encoder;

  16. public class LostProtectedActivity extends Activity implements OnClickListener
  17. {
  18.         private SharedPreferences sp;
  19.         private Dialog dialog;
  20.         private EditText password;
  21.         private EditText confirmPassword;
  22.         
  23.         @Override
  24.         protected void onCreate(Bundle savedInstanceState)
  25.         {
  26.                 super.onCreate(savedInstanceState);
  27.                 
  28.                 sp = getSharedPreferences("cofig", Context.MODE_PRIVATE);
  29.                 
  30.                 if(isSetPassword())
  31.                 {
  32.                         showLoginDialog();
  33.                 }
  34.                 else
  35.                 {
  36.                         showFirstDialog();
  37.                 }
  38.         }
  39.         
  40.         private void showLoginDialog()
  41.         {
  42.                 dialog = new Dialog(this, R.style.MyDialog);
  43.                 View view = View.inflate(this, R.layout.login_dialog, null);
  44.                 password = (EditText) view.findViewById(R.id.et_protected_password);
  45.                 Button yes = (Button) view.findViewById(R.id.bt_protected_login_yes);
  46.                 Button cancel = (Button) view.findViewById(R.id.bt_protected_login_no);
  47.                 yes.setOnClickListener(this);
  48.                 cancel.setOnClickListener(this);
  49.                 dialog.setContentView(view);
  50.                 dialog.setCancelable(false);
  51.                 dialog.show();
  52.         }

  53.         private void showFirstDialog()
  54.         {
  55.                 dialog = new Dialog(this, R.style.MyDialog);
  56.                 //dialog.setContentView(R.layout.first_dialog);
  57.                 View view = View.inflate(this, R.layout.first_dialog, null);//这种填充布局的方式比较方便,峭用拿到一个LayoutInflate对象
  58.                 password = (EditText) view.findViewById(R.id.et_protected_first_password);
  59.                 confirmPassword = (EditText) view.findViewById(R.id.et_protected_confirm_password);
  60.                 Button yes = (Button) view.findViewById(R.id.bt_protected_first_yes);
  61.                 Button cancel = (Button) view.findViewById(R.id.bt_protected_first_no);
  62.                 yes.setOnClickListener(this);
  63.                 cancel.setOnClickListener(this);
  64.                 dialog.setContentView(view);
  65.                 dialog.setCancelable(false);
  66.                 dialog.show();
  67.         }

  68.         private boolean isSetPassword()
  69.         {
  70.                 String pwd = sp.getString("password", "");
  71.                 if(pwd.equals("") || pwd == null)
  72.                 {
  73.                         return false;
  74.                 }
  75.                 return true;
  76.         }
  77.         
  78.         private boolean isSetupGuide()
  79.         {
  80.                 return sp.getBoolean("setupGuide", false);
  81.         }

  82.         @Override
  83.         public void onClick(View v)
  84.         {
  85.                 switch(v.getId())
  86.                 {
  87.                         case R.id.bt_protected_first_yes : 
  88.                                 String fp = password.getText().toString().trim();
  89.                                 String cp = confirmPassword.getText().toString().trim();
  90.                                 if(fp.equals("") || cp.equals(""))
  91.                                 {
  92.                                         Toast.makeText(this, "密码不能为空", Toast.LENGTH_SHORT).show();
  93.                                         return;
  94.                                 }
  95.                                 else 
  96.                                 {
  97.                                         if(fp.equals(cp))
  98.                                         {
  99.                                                 Editor editor = sp.edit();
  100.                                                 editor.putString("password", MD5Encoder.encode(fp));
  101.                                                 editor.commit();
  102.                                                 dialog.dismiss();
  103.                                                 
  104.                                                 if(!isSetupGuide())
  105.                                                 {
  106.                                                         finish();
  107.                                                         Intent intent = new Intent(this, SetupGuide1Activity.class);
  108.                                                         startActivity(intent);
  109.                                                 }
  110.                                         }
  111.                                         else
  112.                                         {
  113.                                                 Toast.makeText(this, "两次密码不相同", Toast.LENGTH_SHORT).show();
  114.                                                 return;
  115.                                         }
  116.                                 }
  117.                                 dialog.dismiss();
  118.                                 break;
  119.                                 
  120.                         case R.id.bt_protected_first_no : 
  121.                                 dialog.dismiss();
  122.                                 finish();
  123.                                 break;
  124.                                 
  125.                         case R.id.bt_protected_login_yes : 
  126.                                 String pwd = password.getText().toString().toString();
  127.                                 if(pwd.equals(""))
  128.                                 {
  129.                                         Toast.makeText(this, "请输入密码", Toast.LENGTH_SHORT).show();
  130.                                 }
  131.                                 else
  132.                                 {
  133.                                         String str = sp.getString("password", "");
  134.                                         if(MD5Encoder.encode(pwd).equals(str))
  135.                                         {
  136.                                                 if(!isSetupGuide())
  137.                                                 {
  138.                                                         finish();
  139.                                                         Intent intent = new Intent(this, SetupGuide1Activity.class);
  140.                                                         startActivity(intent);
  141.                                                 }
  142.                                                 dialog.dismiss();
  143.                                         }
  144.                                         else
  145.                                         {
  146.                                                 Toast.makeText(this, "密码错误", Toast.LENGTH_SHORT).show();
  147.                                         }
  148.                                 }
  149.                                 break;
  150.                                 
  151.                         case R.id.bt_protected_login_no : 
  152.                                 dialog.dismiss();
  153.                                 finish();
  154.                                 break;
  155.                                 
  156.                         default : 
  157.                                 break;
  158.                 }
  159.         }

  160. }
复制代码
com.xiaobin.security.ui.SetupGuide1
  1. package com.xiaobin.security.ui;

  2. import android.app.Activity;
  3. import android.content.Intent;
  4. import android.os.Bundle;
  5. import android.view.View;
  6. import android.view.View.OnClickListener;
  7. import android.widget.Button;

  8. import com.xiaobin.security.R;

  9. public class SetupGuide1Activity extends Activity implements OnClickListener
  10. {
  11.         private Button next;
  12.         
  13.         @Override
  14.         protected void onCreate(Bundle savedInstanceState)
  15.         {
  16.                 super.onCreate(savedInstanceState);
  17.                 setContentView(R.layout.setup_guide1);
  18.                 
  19.                 next = (Button) findViewById(R.id.bt_guide_next);
  20.                 next.setOnClickListener(this);
  21.         }

  22.         @Override
  23.         public void onClick(View v)
  24.         {
  25.                 switch(v.getId())
  26.                 {
  27.                         case R.id.bt_guide_next : 
  28.                                 Intent intent = new Intent(this, SetupGuide2Activity.class);
  29.                                 finish();
  30.                                 startActivity(intent);
  31.                                 //这个是定义activity切换时的动画效果的
  32.                                 overridePendingTransition(R.anim.alpha_in, R.anim.alpha_out);
  33.                                 break;
  34.                                 
  35.                         default : 
  36.                                 break;
  37.                 }
  38.         }

  39. }
复制代码
大家可以看到,我们在上面切换activity时,加了一些效果,其实就是通过overridePendingTransition这个方法来实现的,所以大家以后想让自己的activity之间切换,多一些动态的效果,就可以用这个方法啦。上面只是我自己定义的一个简单的动画文件,要定义一个动画文件也很简单,只要在res下面新建一个anim目录,然后在里面新建一些动画的xml就行啦下面是我们上面的那两个xml动画alpha_in.xml
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <alpha xmlns:android="http://schemas.android.com/apk/res/android"
  3.     android:fromAlpha="0.0"
  4.     android:toAlpha="1.0"
  5.     android:duration="300" >
  6.     

  7. </alpha>
复制代码
alpha_out.xml有一个地方要注意的,我们新建动画的xml时,一定要把那个命名空间 http://schemas.android.com/apk/res/android指定好,不然就不行的 好啦,现在我们把第二个guide的逻辑代码也写一下com.xiaobin.security.ui.SetupGuide2
  1. package com.xiaobin.security.ui;

  2. import android.app.Activity;
  3. import android.content.Context;
  4. import android.content.Intent;
  5. import android.content.SharedPreferences;
  6. import android.content.SharedPreferences.Editor;
  7. import android.os.Bundle;
  8. import android.telephony.TelephonyManager;
  9. import android.view.View;
  10. import android.view.View.OnClickListener;
  11. import android.widget.Button;
  12. import android.widget.CheckBox;
  13. import android.widget.CompoundButton;
  14. import android.widget.CompoundButton.OnCheckedChangeListener;

  15. import com.xiaobin.security.R;

  16. public class SetupGuide2Activity extends Activity implements OnClickListener
  17. {
  18.         private Button bt_bind;
  19.         private Button bt_next;
  20.         private Button bt_perviout;
  21.         private CheckBox cb_bind;
  22.         private SharedPreferences sp;
  23.         
  24.         @Override
  25.         protected void onCreate(Bundle savedInstanceState)
  26.         {
  27.                 super.onCreate(savedInstanceState);
  28.                 setContentView(R.layout.setup_guide2);
  29.                 
  30.                 sp = getSharedPreferences("config", Context.MODE_PRIVATE);
  31.                 
  32.                 bt_bind = (Button) findViewById(R.id.bt_guide_bind);
  33.                 bt_next = (Button) findViewById(R.id.bt_guide_next);
  34.                 bt_perviout = (Button) findViewById(R.id.bt_guide_pervious);
  35.                 bt_bind.setOnClickListener(this);
  36.                 bt_next.setOnClickListener(this);
  37.                 bt_perviout.setOnClickListener(this);
  38.                 
  39.                 cb_bind = (CheckBox) findViewById(R.id.cb_guide_check);
  40.                 //初始化CheckBox状态
  41.                 String sim = sp.getString("simSerial", null);
  42.                 if(sim != null)
  43.                 {
  44.                         cb_bind.setText("已经绑定");
  45.                         cb_bind.setChecked(true);
  46.                 }
  47.                 else
  48.                 {
  49.                         cb_bind.setText("没有绑定");
  50.                         cb_bind.setChecked(false);
  51.                 }
  52.                 cb_bind.setOnCheckedChangeListener(new OnCheckedChangeListener()
  53.                 {
  54.                         @Override
  55.                         public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
  56.                         {
  57.                                 //那个解除绑定的我还没做的呢,各位可以自己去完成,就是把那个SharedPreferences里面的值设置一下就行啦
  58.                                 if(isChecked)
  59.                                 {
  60.                                         cb_bind.setText("已经绑定");
  61.                                         setSimInfo();
  62.                                 }
  63.                                 else
  64.                                 {
  65.                                         cb_bind.setText("没有绑定");
  66.                                 }
  67.                         }
  68.                 });
  69.         }

  70.         @Override
  71.         public void onClick(View v)
  72.         {
  73.                 switch(v.getId())
  74.                 {
  75.                         case R.id.bt_guide_bind : 
  76.                                 setSimInfo();
  77.                                 cb_bind.setText("已经绑定");
  78.                                 cb_bind.setChecked(true);
  79.                                 break;
  80.                                 
  81.                         case R.id.bt_guide_next : 
  82.                                 Intent intent = new Intent(this, SetupGuide3Activity.class);
  83.                                 finish();
  84.                                 startActivity(intent);
  85.                                 //这个是定义activity切换时的动画效果的
  86.                                 overridePendingTransition(R.anim.alpha_in, R.anim.alpha_out);
  87.                                 break;
  88.                         case R.id.bt_guide_pervious : 
  89.                                 
  90.                                 Intent i = new Intent(this, SetupGuide1Activity.class);
  91.                                 finish();
  92.                                 startActivity(i);
  93.                                 //这个是定义activity切换时的动画效果的
  94.                                 overridePendingTransition(R.anim.alpha_in, R.anim.alpha_out);
  95.                                 break;
  96.                                 
  97.                         default : 
  98.                                 break;
  99.                 }
  100.         }
  101.         
  102.         private void setSimInfo()
  103.         {
  104.                 TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
  105.                 String simSerial = telephonyManager.getSimSerialNumber();//拿到sim卡的序列号,是唯一的
  106.                 Editor editor = sp.edit();
  107.                 editor.putString("simSerial", simSerial);
  108.                 editor.commit();
  109.         }

  110. }
复制代码
好,现在只要去AndroidManifest文件里面注册一下这两个activity就可以看看我们的设置向导啦 今天的代码就到这里了,有什么不明白的可以留言,或看一下我们之前的写的代码,明天我们将会讲解系统联系人的获取    Security_07设置向导.rar (929.18 KB, 下载次数: 145) 

目录
相关文章
|
Android开发
《手机卫士性能优化方案-Android篇》电子版地址
手机卫士性能优化方案-Android篇
75 0
《手机卫士性能优化方案-Android篇》电子版地址
|
安全
金山手机卫士正式版发布 永久免费
近日,金山安全软件有限公司首次公开发布金山手机卫士正式版,并宣布下载,安装,升级金山手机卫士完全免费,手机卫士是金山安全软件公司今年成立后回馈用户的又一力作。目前支持主流的智能手机操作系统——塞班S60和Android。
988 0
|
XML API Android开发
Android--手机卫士涉及的知识点总结(一)
Splash界面 splash: 溅,洒 展现产品的logo提升产品的知名度 初始化操作(创建数据库,读取配置文件) 连接服务器检查软件授权 连接服务器检查软件的更新 自动更新的前提 包名...
1121 0
|
算法 数据库 Android开发
Android--手机卫士涉及的知识点总结(二)
短信拦截:开启服务并在里面注册一个广播接收者 ? 1 2 3 开启服务: Intent intent=new Intent(SettingActivity.
903 0
|
数据库 Android开发 数据安全/隐私保护
Android--手机卫士涉及的知识点总结(五)
主活动中点击切换 ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 ...
871 0
|
缓存 安全 数据库
Android--手机卫士涉及的知识点总结(六)
内容观察者 数据库中大声发个消息 ? 1 2 Uri uri=Uri.
1429 0
|
XML Android开发 数据格式
手机卫士08-获取手机联系人
首先,我把把昨天忘记了的两张设置向导的图片放出来先     我们从上面的第一张图片可以看到,我们有一个选择联系人这一操作,那么怎样才能获取到手机里面的联系人呢,其实方法有很多的,现在我们来讲一下我们这个项目里面用到的方法 其实要想知道怎样获取手机里面的联系人,去看一下Android自己的源码就知道的了 我们只
1799 0
|
数据安全/隐私保护 Android开发 安全
手机卫士09-防盗逻辑实现
好啦,我们之前已经把设置向导的界面已经全部完成的了,而且界面也已经完成了三个的啦,今天我们把最后的一个界面完成它,还有把防盗的逻辑也完成一下 废话不多说,直接上代码 com.xiaobin.security.ui.SetupGuide4Activity package com.xiaobin.security.ui; import
1074 0
|
定位技术 Android开发 安全
手机卫士10-手机被盗后定位实现
好啦,废话不多说,我们进入主题,今天我们要继续上一次讲的,就是手机被盗之后,获得手机所在的位置。 上一次,我们说到了,如果我们的sim卡被人换掉了,那么就会发送一条短信到我们的原来设定的安全号码那里的,而今天,我们就要获取到手机的位置啦,以便追踪回手机。 我们是这样设计的,我们通过发送一条短信,短信的内容就是一些要执行的操作的指令(比如说#*location*#),我
1302 0

热门文章

最新文章