登錄 註冊

首先咱們須要作的第一步就是ApiClient裏面編寫獲取驗證碼的方法,具體代碼以下:
java


?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<span style= "font-size:18px;" > /**
    * 說明:獲取驗證碼
    * 做者:丁國華
    * 時間:2015-8-27 下午5:47:36
    */
   public static String getValidateCode(AppContext appContext,
       Map<String, Object> map) throws AppException {
     // 定義要訪問的接口和要強轉的實體
     String validateUrl = _MakeURL(URLs.VALIDATE_CODE_URL, map);
     ValidateCode validateCode = null ;
     try {
       // 獲取服務器端Json數據
       String json = http_get(appContext, validateUrl);
  
       // 解析爲制定的實體對象
       validateCode = (ValidateCode) JSON.parseObject(json,
           ValidateCode. class );
  
     } catch (Exception e) {
       if (e instanceof AppException)
         throw (AppException) e;
       throw AppException.network(e);
     }
  
     // 返回驗證碼
     return validateCode.getCode();
   }
</span>

       第二步編寫AppContent裏面的接口方法,具體代碼以下所示:
android

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<span style= "font-size:18px;" > /**
    * 說明:獲取服務器驗證碼(不須要緩存)
    * 做者:丁國華
    * @date 2015-8-28 上午9:07:14
    */
   public String getCode(Map<String, Object> map) throws AppException {
  
     String validateCode = "" ;
  
     // 若是網絡可鏈接且解析無誤返回正確的驗證碼,不然返回空字符串
     if (isNetworkConnected()) {
       try {
         validateCode = ApiClient.getValidateCode( this , map);
       } catch (AppException e) {
         if (validateCode == "" ) {
           throw e;
         }
       }
     }
     return validateCode;
   }
</span>

        第三步,在StringUtils裏面編寫驗證號碼是不是手機號的正則表達式,具體代碼以下:正則表達式

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<span style= "font-size:18px;" > /* 說明:移動:13四、13五、13六、13七、13八、13九、150、15一、157(TD)、15八、15九、18七、188
    * 聯通:130、13一、13二、15二、15五、15六、18五、186
    * 電信:13三、15三、180、189
    * 總結起來就是第一位一定爲1,第二位一定爲3或5或8,其餘位置的能夠爲0-9
    * 驗證號碼 手機號 固話都可
    * 做者:丁國華
    * 2015年9月20日 13:52:35
    */
    public static boolean isPhoneNumberValid(String phoneNumber) {
    boolean isValid = false ;
    String expression = "((^(13|15|18)[0-9]{9}$)|(^0[1,2]{1}\\d{1}-?\\d{8}$)|(^0[3-9] {1}\\d{2}-?\\d{7,8}$)|(^0[1,2]{1}\\d{1}-?\\d{8}-(\\d{1,4})$)|(^0[3-9]{1}\\d{2}-? \\d{7,8}-(\\d{1,4})$))" ;
    CharSequence inputStr = phoneNumber;
    Pattern pattern = Pattern.compile(expression); 
    Matcher matcher = pattern.matcher(inputStr); 
    if (matcher.matches() ) {
    isValid = true ;
    }
    return isValid;
    }
   </span>

      第四步:編寫xml裏面的文件,具體代碼以下所示:
express

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
<span style= "font-size:18px;" ><?xml version= "1.0" encoding= "utf-8" ?>
<LinearLayout xmlns:android= "http://schemas.android.com/apk/res/android"
   android:layout_width= "match_parent"
   android:layout_height= "match_parent"
   android:orientation= "vertical" >
   <LinearLayout style= "@style/top_title_style" >
     <Button
       android:id= "@+id/register_back_login"
       android:layout_width= "wrap_content"
       android:layout_height= "wrap_content"
       android:layout_marginTop= "5dp"
       android:background= "@null"
       android:drawableLeft= "@drawable/back"
       android:paddingLeft= "5dp"
       android:text= " 登陸"
       android:textColor= "#FFFFFF"
       android:textSize= "18sp" />
     <!-- 註冊的佈局 -->
     <TextView
       android:layout_width= "wrap_content"
       android:layout_height= "wrap_content"
       android:layout_margin= "5dp"
       android:layout_marginTop= "2dp"
       android:layout_weight= "1"
       android:gravity= "center"
       android:paddingLeft= "4dp"
       android:text= "註冊"
       android:textColor= "#FFFFFF"
       android:textSize= "20sp" />
     <!-- 註冊的佈局 -->
     <TextView
       android:id= "@+id/nickname_confirm"
       android:layout_width= "wrap_content"
       android:layout_height= "match_parent"
       android:layout_marginTop= "2dp"
       android:gravity= "center"
       android:paddingLeft= "60dp"
       android:paddingRight= "10dp"
       android:textColor= "#FFFFFF"
       android:textSize= "20sp" />
   </LinearLayout>
   <RelativeLayout
     android:layout_width= "fill_parent"
     android:layout_height= "45dp"
     android:minHeight= "50.0dip"
     android:paddingLeft= "14.0dip"
     android:paddingRight= "12.0dip" >
     <ImageView
       android:layout_width= "23.0dip"
       android:layout_height= "23.0dip"
       android:layout_centerVertical= "true"
       android:src= "@drawable/user_picture" />
     <EditText
      android:id= "@+id/et_register_username_id"
       android:layout_width= "wrap_content"
       android:layout_height= "wrap_content"
       android:layout_marginLeft= "20dp"
       android:background= "@null"
       android:hint= "用戶名/手機號"
       android:paddingLeft= "15dip"
       android:paddingTop= "8dp"
       android:textColorHint= "#BEBEBE"
       android:textSize= "20sp" />
   </RelativeLayout>
   <View style= "@style/PersonalLine" />
    <RelativeLayout
     android:layout_width= "fill_parent"
     android:layout_height= "45dp"
     android:minHeight= "50.0dip"
     android:paddingLeft= "14.0dip"
     android:paddingRight= "12.0dip" >
      <ImageView
       android:layout_width= "23.0dip"
       android:layout_height= "23.0dip"
       android:layout_centerVertical= "true"
       android:src= "@drawable/phone_picture" />
     <EditText
       android:id= "@+id/et_register_code_id"
       android:layout_width= "wrap_content"
       android:layout_height= "wrap_content"
       android:layout_marginLeft= "20dp"
       android:background= "@null"
       android:hint= "請輸入驗證碼"
       android:paddingLeft= "15dip"
       android:paddingTop= "8dp"
       android:textColorHint= "#BEBEBE"
       android:textSize= "20sp" />
     <Button
       android:id= "@+id/bt_getcode_id"
       android:layout_width= "120dp"
       android:layout_height= "35dp"
       android:layout_marginLeft= "200dp"
       android:layout_marginTop= "5dp"
       android:background= "@drawable/shape1"
       android:text= "獲取驗證碼"
       android:textColor= "#FFFFFF"
       android:textSize= "10sp" />
   </RelativeLayout>
   <View style= "@style/PersonalLine" />
   <RelativeLayout
     android:layout_width= "fill_parent"
     android:layout_height= "45dp"
     android:minHeight= "50.0dip"
     android:paddingLeft= "14.0dip"
     android:paddingRight= "12.0dip" >
     <ImageView
       android:layout_width= "23.0dip"
       android:layout_height= "23.0dip"
       android:layout_centerVertical= "true"
       android:src= "@drawable/lock" />
     <EditText
      android:id= "@+id/et_register_password_id"
       android:layout_width= "wrap_content"
       android:layout_height= "wrap_content"
       android:layout_marginLeft= "20dp"
       android:background= "@null"
       android:hint= "請輸入新密碼"
       android:paddingLeft= "15dip"
       android:paddingTop= "8dp"
       android:textColorHint= "#BEBEBE"
       android:textSize= "20sp" />
   </RelativeLayout>
   <View style= "@style/PersonalLine" />
   <LinearLayout
     android:layout_width= "fill_parent"
     android:layout_height= "wrap_content"
     android:orientation= "horizontal" >
     <!-- 小對勾的佈局 -->
     <CheckBox
       android:layout_width= "wrap_content"
       android:layout_height= "wrap_content"
       android:layout_margin= "10dp"
       android:layout_marginLeft= "-10dp"
       android:scaleX= "0.8"
       android:scaleY= "0.8" />
     <TextView
       android:layout_width= "wrap_content"
       android:layout_height= "wrap_content"
      android:layout_gravity= "center_vertical"
       android:text= "我贊成"
       android:textSize= "18sp" />
     <TextView
       android:id= "@+id/user_protocol"
       android:layout_width= "200dp"
       android:layout_height= "match_parent"
       android:layout_gravity= "center_vertical"
       android:layout_marginLeft= "5dp"
       android:gravity= "center"
       android:text= "用戶協議及隱私條款"
       android:textColor= "#FE8B4A"
       android:textSize= "18sp" />
   </LinearLayout>
   <Button
     android:id= "@+id/bt_register_id"
     android:layout_width= "245dp"
     android:layout_height= "45dp"
     android:layout_gravity= "center_horizontal"
     android:layout_marginBottom= "14dp"
     android:layout_marginLeft= "15dp"
     android:layout_marginRight= "15dp"
     android:layout_marginTop= "5dp"
     android:background= "@drawable/shape2"
     android:gravity= "center"
     android:text= "注 冊"
     android:textColor= "#FFFFFF"
     android:textSize= "15sp" />
   <TextView
     android:layout_width= "wrap_content"
     android:layout_height= "wrap_content"
     android:layout_marginLeft= "80dp"
     android:paddingTop= "5dp"
     android:text= "您也能夠直接登陸"
     android:textColor= "#BEBEBE"
     android:textSize= "20sp" />
   <LinearLayout
     android:layout_width= "match_parent"
     android:layout_height= "wrap_content"
     android:layout_marginTop= "10dp"
     android:baselineAligned= "false"
     android:gravity= "center"
     android:orientation= "horizontal" >
     <LinearLayout
       android:layout_width= "0dp"
       android:layout_height= "wrap_content"
       android:layout_weight= "1"
       android:gravity= "center"
       android:orientation= "vertical" >
       <Button
         android:layout_width= "60dp"
         android:layout_height= "60dp"
   android:background= "@drawable/weixin_login" />
  
       <TextView
         android:layout_width= "wrap_content"
         android:layout_height= "wrap_content"
         android:text= "微信登陸"
         android:textColor= "#BEBEBE"
         android:textSize= "20sp" />
     </LinearLayout>
     <LinearLayout
       android:layout_width= "0dp"
       android:layout_height= "wrap_content"
       android:layout_weight= "1"
       android:gravity= "center"
       android:orientation= "vertical" >
       <Button
         android:layout_width= "60dp"
         android:layout_height= "60dp"
    android:background= "@drawable/weibo_login" />
       <TextView
         android:layout_width= "wrap_content"
         android:layout_height= "wrap_content"
         android:text= "微博登陸"
         android:textColor= "#BEBEBE"
         android:textSize= "20sp" />
     </LinearLayout>
     <LinearLayout
       android:layout_width= "0dp"
       android:layout_height= "wrap_content"
       android:layout_weight= "1"
       android:gravity= "center"
       android:orientation= "vertical" >
       <Button
       android:layout_width= "60dp"       android:layout_height= "60dp"         android:background= "@drawable/qq_login" />
  
       <TextView
         android:layout_width= "wrap_content"
        android:layout_height= "wrap_content"
         android:text= "QQ登陸"
         android:textColor= "#BEBEBE"
         android:textSize= "20sp" />
     </LinearLayout>
   </LinearLayout>
</LinearLayout></span>

        第五步:編寫java類RegisterActivity裏面的代碼,具體以下所示:json

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
<span style= "font-size:18px;" > package com.jczb.car.ui;
import java.lang.ref.WeakReference;
import java.util.HashMap;
import java.util.Map;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import com.jczb.car.AppContext;
import com.jczb.car.AppException;
import com.jczb.car.R;
import com.jczb.car.common.StringUtils;
/**
  * 說明:註冊功能頁面 咱們實現了取消線程的機制,從而保證它不會泄露 onDestroy()經常被用來在Activity推出前取消線程
  * 做者: 吳利昌
  * 時間: 2015-9-3上午9:19:15
  */
public class RegisterActivity extends Activity implements OnClickListener {
     // 聲明用到的頁面控件
   private EditText etRegisterName;
   private EditText etCode;
   private EditText etPassword;
   private Button btCode;
   private Button btRegister;
   private TextView tvUserProtocol;
   private Button btRegisterLoginBack;
   // 定義變量
   private String userName;
   private String passWord;
   public boolean isChange = false ;
   private boolean tag = true ;
   private int i = 60 ;
   Thread thread = null ;
   /**客戶端輸入的驗證碼*/
   private String valicationCode;
   /**服務器端獲取的驗證碼*/
   private static String serverValicationCode;
   /** 註冊時所帶的參數 */
   private Map<String, Object> registerParams = new HashMap<String, Object>();
   /** 獲取驗證碼時所帶的參數 */
   private Map<String, Object> codeParams = new HashMap<String, Object>();
   /** 註冊是否成功 */
   private String regisgerStatus;
   @Override
   protected void onCreate(Bundle savedInstanceState) {
     super .onCreate(savedInstanceState);
     setContentView(R.layout.register);
     initView();   
   }
   /**
    * 說明:初始化頁面控件和事件
    * 做者: 吳利昌
    * 時間: 2015-9-3 上午9:23:42
    */
   public void initView() {
     // 初始化控件
     etRegisterName = (EditText) findViewById(R.id.et_register_username_id);
     etCode = (EditText) findViewById(R.id.et_register_code_id);
     etPassword = (EditText) findViewById(R.id.et_register_password_id);
     btCode = (Button) findViewById(R.id.bt_getcode_id);
     btRegister = (Button) findViewById(R.id.bt_register_id);
     tvUserProtocol=(TextView)findViewById(R.id.user_protocol);
     btRegisterLoginBack=(Button)findViewById(R.id.register_back_login);
     // 初始化監聽事件
     btCode.setOnClickListener( this );
     btRegister.setOnClickListener( this );
     tvUserProtocol.setOnClickListener( this );
     btRegisterLoginBack.setOnClickListener( this );
   }
   private boolean isvalidate() {
     // TODO Auto-generated method stub
     // 獲取控件輸入的值
     String userName = etRegisterName.getText().toString().trim();
     if (StringUtils.isEmpty(userName)) {
       Toast.makeText( this , "手機號不能爲空" , Toast.LENGTH_SHORT).show();
       return false ;
     }
     if (!StringUtils.isPhoneNumberValid(userName)) {
       Toast.makeText( this , "手機號有誤" , Toast.LENGTH_SHORT).show();
       return false ;
     }
     return true ;
   }
  
   @Override
   public void onClick(View v) {
     switch (v.getId()) {
     case R.id.bt_getcode_id:
       if (!isvalidate())
         break ;  
       btCode.setText( "獲取驗證碼" );
       btCode.setClickable( true );
       isChange = true ;
       changeBtnGetCode();
       getValidateCode();
       break ;
     case R.id.bt_register_id:
       register();
       break ;
     case R.id.user_protocol:
       Intent intentUserProtocol = new Intent( this ,UserProtocolActivity. class );
       startActivity(intentUserProtocol);
       break ;
     case R.id.register_back_login:
       this .finish();
       break ;
     default :
       break ;
     }
   }
      private void changeBtnGetCode() {
     thread = new Thread() {
       @Override
       public void run() {
         if (tag) {
           while (i > 0 ) {
             i--;
             if (RegisterActivity. this == null ) {
               break ;
             }  
             RegisterActivity. this
                 .runOnUiThread( new Runnable() {
                   @Override
                   public void run() {
                     btCode.setText( "獲取驗證碼("
                         + i + ")" );
                     btCode
                         .setClickable( false );
                   }
                 });
             try {
               Thread.sleep( 1000 );
             } catch (InterruptedException e) {
               throw new RuntimeException(e);
             }
           }
           tag = false ;
         }
         i = 60 ;
         tag = true ;
         if (RegisterActivity. this != null ) {
           RegisterActivity. this .runOnUiThread( new Runnable() {
             @Override
             public void run() {
               btCode.setText( "獲取驗證碼" );
               btCode.setClickable( true );
             }
           });
         }
       };
     };
     thread.start();
   }
   /**
    * 說明:獲取驗證碼
    *
    * 做者: 吳利昌
    * 時間: 2015-9-3 下午3:26:55
    */
   public boolean getValidateCode() {
      String name = etRegisterName.getText().toString().trim();
     String code = etCode.getText().toString().trim();
     if (name.equals( "" )) {
       Toast.makeText( this , "請輸入用戶名或手機號!" , Toast.LENGTH_SHORT).show();
       return false ;
     } else {
       userName = name;
       valicationCode = code;
       Thread codeThread = new Thread(codeRunnable);
       codeThread.start();
     }
     return true ;
   }
   /**
    * 說明:註冊
    *
    * 做者: 吳利昌
    * 時間: 2015-9-3 下午3:27:23
    */
   public void register() {
     // 1.首先判斷輸入的值是否有效
     // 2.而後判斷輸入的驗證碼是否有效(防止沒有點擊獲取驗證碼本身填的錯誤驗證碼)
     // 3.最後註冊
     if (isValid()) {
       if (valicationCode.equals(serverValicationCode)) {
         Thread thread = new Thread(sRunnable);
         thread.start();
       } else {
         Toast.makeText( this , "輸入的驗證碼不正確!" , Toast.LENGTH_SHORT).show();
       }
        
     }
   }
   //--------------------------------獲取驗證碼線程處理過程---開始-----------------------------
   /**
    * 自定義一個靜態的具備弱引用的Handler,解決內存泄漏的問題,本handler用來獲取驗證碼
    */
   private static class CodeHandler extends Handler {
     // 持有對本外部類的弱引用
     private final WeakReference<RegisterActivity> mActivity;
     public CodeHandler(RegisterActivity activity) {
       mActivity = new WeakReference<RegisterActivity>(activity);
     }
     @Override
     public void handleMessage(Message msg) {
       // 獲取上下文對象
       RegisterActivity activity = mActivity.get();
       if (activity != null ) {
         switch (msg.what) {
         case 1 :
           serverValicationCode = (String)msg.obj;
           //activity.etCode.setText(serverValicationCode);
           break ;
         case - 1 :
           Toast.makeText(activity, "獲取驗證碼失敗!" , Toast.LENGTH_SHORT).show();
           break ;
         case 0 :
           Toast.makeText(activity, "哎呀,出錯啦.." , Toast.LENGTH_SHORT).show();
           break ;
         default :
           break ;
         }
       }
     }
   }
   /**實例化自定義的handler*/
   private final CodeHandler codeHandler = new CodeHandler( this );
   private String serverCode= null ;
   /**定義獲取驗證碼的子線程*/
   private Runnable codeRunnable = new Runnable() {
     @Override
     public void run() {
       Message msg = new Message();
       Map<String, Object> map = new HashMap<String, Object>();
       map.put( "jbPhone" , userName);
       // 獲取全局對象Application
       AppContext appContext = (AppContext) getApplication();
       try {
         // 獲取服務器數據
         serverValicationCode = appContext.getCode(map);
         // 返回true則將消息的what值爲1,爲false則what爲-1,異常爲0
         if (serverValicationCode.equals( "" )) {
           msg.what = - 1 ;
         } else {
           msg.what = 1 ;
           msg.obj = serverValicationCode;
         }
       } catch (AppException e) {
         msg.what = 0 ;
         e.printStackTrace();
       }
       codeHandler.sendMessage(msg);
     }
   };

    //--------------------------------獲取驗證碼線程處理過程----完成------------------------------  緩存

   //--------------------------------註冊線程處理過程--開始----------------------------------  服務器

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/**
  * 自定義一個靜態的具備弱引用的Handler,解決內存泄漏的問題,註冊使用
  */
private static class MyHandler extends Handler {
   // 持有對本外部類的弱引用
   private final WeakReference<RegisterActivity> mActivity;
 
   public MyHandler(RegisterActivity activity) {
     mActivity = new WeakReference<RegisterActivity>(activity);
   }
   @Override
   public void handleMessage(Message msg) {
      
     // 獲取上下文對象
     RegisterActivity activity = mActivity.get();
     if (activity != null ) {
       switch (msg.what) {
       case 1 :
         Toast.makeText(activity, "註冊成功!" , Toast.LENGTH_SHORT).show();
         activity.finish();
         break ;
       case - 1 :
         Toast.makeText(activity, "註冊失敗!" , Toast.LENGTH_SHORT).show();
         break ;
       case - 2 :
         Toast.makeText(activity, "該號已經註冊!" , Toast.LENGTH_SHORT).show();
         break ;
       case 0 :
         Toast.makeText(activity, "哎呀,出錯啦.." , Toast.LENGTH_SHORT).show();
         break ;
       default :
         break ;
       }
     }
   }
}
/**實例化自定義的handler*/
private final MyHandler mHandler = new MyHandler( this );
/**自定義子線程*/
private Runnable sRunnable = new Runnable() {
   @Override
   public void run() {
     Message msg = new Message();
     // 獲取全局對象Application
     AppContext appContext = (AppContext) getApplication();
     try {
       // 獲取服務器數據
       regisgerStatus = appContext.register(registerParams);
 
       // 返回true則將消息的what值爲1,爲false則what爲-1,異常爲0
       if (regisgerStatus.equals( "true" )) {
         msg.what = 1 ;         
         msg.obj = regisgerStatus;
       } else if (regisgerStatus.equals( "1" )){
         msg.what = - 2 ;           
       } else if (regisgerStatus.equals( "false" )){
         msg.what = - 1 ;}
     } catch (AppException e) {
       msg.what = 0 ;
       e.printStackTrace();
     }
     mHandler.sendMessage(msg);
   }
};

    //--------------------------------註冊線程處理過程---完成-----------------------------------  微信

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
   /**
    * 說明:註冊以前判斷數據是否爲空
    *
    * @return
    * 做者: 吳利昌
    * 時間: 2015-9-3 下午3:29:04
    */
   public boolean isValid() {
     userName = etRegisterName.getText().toString().trim();
     valicationCode = etCode.getText().toString().trim();
     passWord = etPassword.getText().toString().trim();     
     if (userName.equals( "" )) {
       Toast.makeText( this , "用戶名不能爲空!" , Toast.LENGTH_SHORT).show();
       return false ;
     }
     if (valicationCode.equals( "" )) {
       Toast.makeText( this , "驗證碼不能爲空!" , Toast.LENGTH_SHORT).show();
       return false ;
    
     if (!serverValicationCode.equals(valicationCode))
      {
       Toast.makeText( this , "驗證碼錯誤" , Toast.LENGTH_SHORT).show();
       return false ;
    
     if (passWord.equals( "" )) {
       Toast.makeText( this , "密碼不能爲空!" , Toast.LENGTH_SHORT).show();
       return false ;
     } else if (passWord.length() < 6 ) {
       Toast.makeText( this , "密碼至少6位!" , Toast.LENGTH_SHORT).show();
       return false ;
    
     registerParams.put( "username" , userName);
     registerParams.put( "psd" , passWord); 
     return true ;
   }
}
</span>

 

       最後,咱們來運行一下,看看咱們的效果,因爲小編的genymotion不知道爲何不能運行了,因此委屈小夥伴們一下,看不了動態圖片了,不過並不影響,咱們首先用一個號碼好註冊一下,以下圖所示:網絡

手機註冊
手機註冊
短信驗證碼
短信驗證碼

 

 

        看一下手機收到的驗證碼:   app

 
 
 

 

 

        最後來看一下,咱們的註冊:       

  

相關文章
相關標籤/搜索