閱讀825 返回首頁    go iPhone_iPad_Mac_apple


手機衛士07-設置向導

今天,我們要做的就是給我們的手機防盜這個功能添加一個設置向導的功能啦,指導用戶進行一些設置,廢話不多說,直接上圖,看看我們要做的效果

    


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

好啦,我們今天主要是把這兩個界麵寫出來,還有把一些邏輯代碼寫一下

其實這主要就是兩個xml文件啦

setup_guide1.xml

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:andro
  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.         
  10.         android:text="@string/guide1"/>
  11.     
  12.     <TextView 
  13.         />
  14.     
  15.     <TextView 
  16.         
  17.         android:text="@string/guide1_content"/>
  18.     
  19.     <TextView 
  20.         
  21.         android:text="@string/guide1_item1"/>
  22.     
  23.     <TextView 
  24.         
  25.         android:text="@string/guide1_item2"/>
  26.     
  27.     <TextView 
  28.         
  29.         android:text="@string/guide1_item3"/>
  30.     
  31.     <TextView 
  32.         
  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:
  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:andro
  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.         
  10.         android:text="@string/guide2"/>
  11.     
  12.     <TextView 
  13.         />
  14.     
  15.     <TextView 
  16.         
  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:
  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:
  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:
  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:
  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:andro
  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.         
  10.         android:text="@string/guide1"/>
  11.     
  12.     <TextView 
  13.         />
  14.     
  15.     <TextView 
  16.         
  17.         android:text="@string/guide1_content"/>
  18.     
  19.     <TextView 
  20.         
  21.         android:text="@string/guide1_item1"/>
  22.     
  23.     <TextView 
  24.         
  25.         android:text="@string/guide1_item2"/>
  26.     
  27.     <TextView 
  28.         
  29.         android:text="@string/guide1_item3"/>
  30.     
  31.     <TextView 
  32.         
  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:
  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:andro
  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.         
  10.         android:text="@string/guide4"/>
  11.     
  12.     <TextView 
  13.         />
  14.     
  15.     <TextView 
  16.         
  17.         android:text="@string/guide4_content"/>
  18.     
  19.     <CheckBox 
  20.         android:
  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:
  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:andro
  3.     android:fromAlpha="0.0"
  4.     android:toAlpha="1.0"
  5.     android:duration="300" >
  6.     

  7. </alpha>
複製代碼
alpha_out.xml有一個地方要注意的,我們新建動畫的xml時,一定要把那個命名空間https://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) 

最後更新:2017-04-03 14:54:25

  上一篇:go 鎵嬫満鍗+07-璁劇疆鍚戝-鍗氬-浜戞爾紺懼尯-闃塊噷浜?
  下一篇:go 給出任意一個正整數,算出大於它的最小不重複數——最高效[2014百度筆試題]