Mobike手机登录界面

Mobike手机登录界面原文:https://blog.csdn.net/yiwen01/article/details/726331141.登陆界面对于一个网络APP来说,刚开始首先必须登录,膜拜使用有手机登陆,当然还有微信什么其他的,不过

原文:Mobike手机登录界面

1.登陆界面

对于一个网络APP来说,刚开始首先必须登录,膜拜使用有手机登陆,当然还有微信什么其他的,不过绑定微信后又要绑定手机,所以手机登陆是必须的。

先看效果图:

Mobike手机登录界面


2.界面还比较简单,两个et 和两个bt.

xml文件:


 
 
 
 
  1. <?xml version= "1.0" encoding= "utf-8"?>
  2. <RelativeLayout
  3. xmlns:android= "http://schemas.android.com/apk/res/android"
  4. xmlns:app= "http://schemas.android.com/apk/res-auto"
  5. android:layout_width= "match_parent"
  6. android:layout_height= "match_parent"
  7. >
  8. <com.yiwen.mobike.views.MyToolBar
  9. android:id= "@+id/toolbar_login"
  10. android:layout_width= "match_parent"
  11. android:layout_height= "wrap_content"
  12. android:background= "?attr/colorPrimary"
  13. android:minHeight= "?attr/actionBarSize"
  14. app:leftButtonIcon= "@drawable/places_ic_clear"
  15. app:showSearchView= "false"
  16. app:title= "手机验证"
  17. >
  18. </com.yiwen.mobike.views.MyToolBar>
  19. <LinearLayout
  20. android:layout_width= "match_parent"
  21. android:layout_height= "wrap_content"
  22. android:layout_below= "@id/toolbar_login"
  23. android:layout_margin= "20dp"
  24. android:orientation= "vertical">
  25. <LinearLayout
  26. android:layout_width= "match_parent"
  27. android:layout_height= "wrap_content"
  28. android:background= "#F2F2F2"
  29. android:orientation= "horizontal">
  30. <TextView
  31. android:layout_marginLeft= "3dp"
  32. android:layout_width= "wrap_content"
  33. android:layout_height= "wrap_content"
  34. android:text= "手机号"
  35. android:textColor= "#333333"
  36. android:textSize= "18dp"/>
  37. <com.yiwen.mobike.views.ClearEditText
  38. android:id= "@+id/et_phone"
  39. android:layout_marginRight= "3dp"
  40. android:layout_width= "match_parent"
  41. android:layout_height= "wrap_content"
  42. android:hint= "请输入手机号"
  43. android:inputType= "phone"
  44. android:textColorHint= "#ABABAB"/>
  45. </LinearLayout>
  46. <LinearLayout
  47. android:layout_width= "match_parent"
  48. android:layout_height= "wrap_content"
  49. android:layout_marginTop= "15dp"
  50. android:background= "#F2F2F2"
  51. android:orientation= "horizontal">
  52. <TextView
  53. android:layout_width= "0dp"
  54. android:layout_marginLeft= "3dp"
  55. android:layout_height= "wrap_content"
  56. android:layout_weight= "2"
  57. android:text= "验证码"
  58. android:textColor= "#333333"
  59. android:textSize= "18dp"/>
  60. <EditText
  61. android:id= "@+id/et_code"
  62. android:layout_width= "0dp"
  63. android:layout_height= "wrap_content"
  64. android:layout_weight= "4"
  65. android:hint= "请输入验证码"
  66. android:inputType= "phone"
  67. android:textColorHint= "#ABABAB"/>
  68. <Button
  69. android:id= "@+id/get_code"
  70. android:layout_width= "0dp"
  71. android:layout_height= "wrap_content"
  72. android:layout_weight= "4"
  73. android:background= "@color/gray"
  74. android:text= "获取验证码"
  75. android:textColor= "@color/white"/>
  76. </LinearLayout>
  77. <TextView
  78. android:id= "@+id/loin_voice"
  79. android:layout_width= "wrap_content"
  80. android:layout_height= "wrap_content"
  81. android:layout_marginLeft= "2dp"
  82. android:layout_marginTop= "8dp"
  83. android:clickable= "true"
  84. android:text= "收不到短信,试试语音短信"
  85. android:textColor= "@color/red"/>
  86. <Button
  87. android:id= "@+id/login_query"
  88. android:layout_width= "match_parent"
  89. android:layout_height= "wrap_content"
  90. android:layout_marginTop= "8dp"
  91. android:layout_marginEnd= "8dp"
  92. android:background= "@color/gray"
  93. android:text= "确定"
  94. android:textColor= "@color/white"/>
  95. <LinearLayout
  96. android:layout_marginTop= "15dp"
  97. android:gravity= "center"
  98. android:layout_width= "match_parent"
  99. android:orientation= "horizontal"
  100. android:layout_height= "wrap_content">
  101. <TextView
  102. android:text= "点击-确定,即表示已阅读并同意"
  103. android:layout_width= "wrap_content"
  104. android:layout_height= "wrap_content"/>
  105. <TextView
  106. android:id= "@+id/login_services"
  107. android:text= "《用车服务条款》"
  108. android:textColor= "@color/red"
  109. android:layout_width= "wrap_content"
  110. android:layout_height= "wrap_content"/>
  111. </LinearLayout>
  112. </LinearLayout>
  113. </RelativeLayout>

其中

3.MyToolBar和ClearEditText 为自定义控件。

myToolBar代码:


 
 
 
 
  1. package com.yiwen.mobike.views;
  2. import android.content.Context;
  3. import android.graphics.drawable.Drawable;
  4. import android.support.annotation.StringRes;
  5. import android.support.v7.app.ActionBar;
  6. import android.support.v7.widget.TintTypedArray;
  7. import android.support.v7.widget.Toolbar;
  8. import android.util.AttributeSet;
  9. import android.util.Log;
  10. import android.view.LayoutInflater;
  11. import android.view.View;
  12. import android.view.ViewGroup;
  13. import android.widget.EditText;
  14. import android.widget.ImageView;
  15. import android.widget.TextView;
  16. import com.yiwen.mobike.R;
  17. /**
  18. * User: Yiwen(https://github.com/yiwent)
  19. * Date: 2017-05-02
  20. * Time: 11:00
  21. * FIXME
  22. */
  23. public class MyToolBar extends Toolbar {
  24. private LayoutInflater mInflater;
  25. private View mView;
  26. private TextView toolbar_title;
  27. private EditText toolbar_searchview;
  28. private ImageView toolbar_leftButton;
  29. private ImageView toolbar_rightButton;
  30. private boolean showSearchView;
  31. private Drawable left_button_icon;
  32. private Drawable right_button_icon;
  33. private String title;
  34. public MyToolBar(Context context) {
  35. this(context, null);
  36. }
  37. public MyToolBar(Context context, AttributeSet attrs) {
  38. this(context, attrs, 0);
  39. }
  40. public MyToolBar(Context context, AttributeSet attrs, int defStyleAttr) {
  41. super(context, attrs, defStyleAttr);
  42. initview();
  43. if (attrs != null) {
  44. final TintTypedArray a = TintTypedArray.obtainStyledAttributes(getContext(), attrs,
  45. R.styleable.MyToolBar, defStyleAttr, 0);
  46. showSearchView = a.getBoolean(R.styleable.MyToolBar_showSearchView, false);
  47. left_button_icon = a.getDrawable(R.styleable.MyToolBar_leftButtonIcon);
  48. right_button_icon = a.getDrawable(R.styleable.MyToolBar_rightButtonIcon);
  49. title = a.getString(R.styleable.MyToolBar_myTitle);
  50. a.recycle();
  51. }
  52. isShouw();
  53. setContentInsetsRelative( 15, 15);
  54. initListener();
  55. }
  56. private void initListener() {
  57. toolbar_leftButton.setOnClickListener( new OnClickListener() {
  58. @Override
  59. public void onClick(View v) {
  60. if (onLeftButtonClickListener != null) {
  61. onLeftButtonClickListener.onClick();
  62. }
  63. }
  64. });
  65. toolbar_rightButton.setOnClickListener( new OnClickListener() {
  66. @Override
  67. public void onClick(View v) {
  68. if (onRightButtonClickListener != null) {
  69. onRightButtonClickListener.onClick();
  70. }
  71. }
  72. });
  73. }
  74. public void isShouw() {
  75. if (showSearchView) {
  76. showSearchview();
  77. hideTitle();
  78. } else {
  79. hideSearchview();
  80. showTitle();
  81. if (title != null) {
  82. toolbar_title.setText(title);
  83. }
  84. }
  85. Log.d( "left_button_icon", "initview:5"+left_button_icon);
  86. if (left_button_icon != null) {
  87. toolbar_leftButton.setVisibility(VISIBLE);
  88. toolbar_leftButton.setBackground(left_button_icon);
  89. }
  90. if (right_button_icon != null) {
  91. toolbar_rightButton.setVisibility(VISIBLE);
  92. toolbar_rightButton.setImageDrawable(right_button_icon);
  93. }
  94. }
  95. public interface OnLeftButtonClickListener {
  96. void onClick();
  97. }
  98. public interface OnRightButtonClickListener {
  99. void onClick();
  100. }
  101. private OnLeftButtonClickListener onLeftButtonClickListener;
  102. private OnRightButtonClickListener onRightButtonClickListener;
  103. public void setOnLeftButtonClickListener(OnLeftButtonClickListener listener) {
  104. onLeftButtonClickListener = listener;
  105. }
  106. public void setOnRightButtonClickListener(OnRightButtonClickListener listener) {
  107. onRightButtonClickListener = listener;
  108. }
  109. private void initview() {
  110. if (mView == null) {
  111. mInflater = LayoutInflater.from(getContext());
  112. mView = mInflater.inflate(R.layout.toolbar, null);
  113. toolbar_rightButton = (ImageView) mView.findViewById(R.id.id_btn_right);
  114. toolbar_title = (TextView) mView.findViewById(R.id.id_tv_title);
  115. toolbar_searchview = (EditText) mView.findViewById(R.id.id_et_search);
  116. toolbar_leftButton = (ImageView) mView.findViewById(R.id.id_ib_navigation);
  117. ActionBar.LayoutParams lp = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
  118. ViewGroup.LayoutParams.WRAP_CONTENT);
  119. addView(mView, lp);
  120. // if (showSearchView) {
  121. // showSearchview();
  122. // hideTitle();
  123. // } else {
  124. // hideSearchview();
  125. // showTitle();
  126. // if (title != null) {
  127. // toolbar_title.setText(title);
  128. // }
  129. // }
  130. // Log.d("left_button_icon", "initview:5"+left_button_icon);
  131. // if (left_button_icon != null) {
  132. //
  133. // toolbar_leftButton.setBackground(left_button_icon);
  134. // toolbar_leftButton.setVisibility(VISIBLE);
  135. // }
  136. //
  137. // if (right_button_icon != null) {
  138. // toolbar_rightButton.setImageDrawable(right_button_icon);
  139. // toolbar_rightButton.setVisibility(VISIBLE);
  140. // }
  141. }
  142. }
  143. @Override
  144. public void setTitle(@StringRes int resId) {
  145. setTitle(getContext().getString(resId));
  146. }
  147. @Override
  148. public void setTitle(CharSequence title) {
  149. initview();
  150. if (toolbar_title != null) {
  151. toolbar_title.setText(title);
  152. showTitle();
  153. }
  154. }
  155. public void showSearchview() {
  156. if (toolbar_searchview != null) {
  157. toolbar_searchview.setVisibility(VISIBLE);
  158. }
  159. }
  160. public void hideSearchview() {
  161. if (toolbar_searchview != null) {
  162. toolbar_searchview.setVisibility(GONE);
  163. }
  164. }
  165. public void showTitle() {
  166. if (toolbar_title != null) {
  167. toolbar_title.setVisibility(VISIBLE);
  168. }
  169. }
  170. public void hideTitle() {
  171. if (toolbar_title != null) {
  172. toolbar_title.setVisibility(GONE);
  173. }
  174. }
  175. /**
  176. * 设置左右按钮的图标
  177. *
  178. * @param d
  179. */
  180. public void setLeftButtonIconDrawable(Drawable d) {
  181. toolbar_leftButton.setImageDrawable(d);
  182. toolbar_leftButton.setVisibility(VISIBLE);
  183. }
  184. public void setRightButtonIconDrawable(Drawable d) {
  185. toolbar_rightButton.setImageDrawable(d);
  186. toolbar_rightButton.setVisibility(VISIBLE);
  187. }
  188. /**
  189. * 标题与搜索框的切换
  190. */
  191. public void setShowSearchView() {
  192. hideTitle();
  193. showSearchview();
  194. }
  195. public void setShowTitleView(String title) {
  196. hideSearchview();
  197. showTitle();
  198. toolbar_title.setText(title);
  199. }
  200. }

4.ClearEditText代码:




 
 
 
 
  1. package com.yiwen.mobike.views;
  2. import android.content.Context;
  3. import android.graphics.drawable.Drawable;
  4. import android.support.v4.content.ContextCompat;
  5. import android.support.v4.graphics.drawable.DrawableCompat;
  6. import android.support.v7.widget.AppCompatEditText;
  7. import android.text.Editable;
  8. import android.text.TextWatcher;
  9. import android.util.AttributeSet;
  10. import android.view.MotionEvent;
  11. import android.view.View;
  12. import com.yiwen.mobike.R;
  13. public class ClearEditText extends AppCompatEditText implements View.OnTouchListener, View.OnFocusChangeListener, TextWatcher {
  14. private Drawable mClearTextIcon;
  15. private OnFocusChangeListener mOnFocusChangeListener;
  16. private OnTouchListener mOnTouchListener;
  17. public ClearEditText(final Context context) {
  18. super(context);
  19. init(context);
  20. }
  21. public ClearEditText(final Context context, final AttributeSet attrs) {
  22. super(context, attrs);
  23. init(context);
  24. }
  25. public ClearEditText(final Context context, final AttributeSet attrs, final int defStyleAttr) {
  26. super(context, attrs, defStyleAttr);
  27. init(context);
  28. }
  29. private void init(final Context context) {
  30. final Drawable drawable = ContextCompat.getDrawable(context, R.mipmap.places_ic_clear);
  31. final Drawable wrappedDrawable = DrawableCompat.wrap(drawable); //Wrap the drawable so that it can be tinted pre Lollipop
  32. DrawableCompat.setTint(wrappedDrawable, getCurrentHintTextColor());
  33. mClearTextIcon = wrappedDrawable;
  34. // mClearTextIcon= context.getResources().getDrawable(R.drawable.icon_delete_32);
  35. mClearTextIcon.setBounds( 0, 0, mClearTextIcon.getIntrinsicHeight(), mClearTextIcon.getIntrinsicHeight());
  36. setClearIconVisible( false);
  37. /*
  38. * 设置父类的监听器,还可以单独给该类设置监听器
  39. * */
  40. super.setOnTouchListener( this);
  41. super.setOnFocusChangeListener( this);
  42. addTextChangedListener( this);
  43. }
  44. @Override
  45. public void setOnFocusChangeListener(OnFocusChangeListener l) {
  46. mOnFocusChangeListener = l;
  47. }
  48. @Override
  49. public void setOnTouchListener(OnTouchListener l) {
  50. mOnTouchListener = l;
  51. }
  52. @Override
  53. public void onFocusChange(View v, boolean hasFocus) {
  54. if (hasFocus) {
  55. setClearIconVisible(getText().length() > 0);
  56. } else {
  57. setClearIconVisible( false);
  58. }
  59. if (mOnFocusChangeListener != null) {
  60. mOnFocusChangeListener.onFocusChange(v, hasFocus);
  61. }
  62. }
  63. @Override
  64. public boolean onTouch(View view, MotionEvent motionEvent) {
  65. final int x = ( int) motionEvent.getX();
  66. /*
  67. 判断是否触摸在清楚按钮上
  68. * */
  69. if (mClearTextIcon.isVisible() && x > getWidth() - getPaddingRight() - mClearTextIcon.getIntrinsicWidth()) {
  70. if (motionEvent.getAction() == MotionEvent.ACTION_UP) {
  71. setError( null);
  72. setText( "");
  73. }
  74. return true;
  75. }
  76. return mOnTouchListener != null && mOnTouchListener.onTouch(view, motionEvent);
  77. }
  78. @Override
  79. public final void onTextChanged(CharSequence text, int start, int lengthBefore, int lengthAfter) {
  80. if (isFocused()) {
  81. setClearIconVisible(text.length() > 0);
  82. }
  83. }
  84. @Override
  85. public void beforeTextChanged(CharSequence s, int start, int count, int after) {
  86. }
  87. @Override
  88. public void afterTextChanged(Editable s) {
  89. }
  90. private void setClearIconVisible(final boolean visible) {
  91. mClearTextIcon.setVisible(visible, false);
  92. final Drawable[] compoundDrawables = getCompoundDrawables();
  93. setCompoundDrawables(
  94. compoundDrawables[ 0],
  95. compoundDrawables[ 1],
  96. visible ? mClearTextIcon : null,
  97. compoundDrawables[ 3]);
  98. }
  99. }

非常简单的自定义控件,加了几个属性。


5.LoginActivity包含手机验证,和判断手机输入对错,控制控件颜色,膜拜主色为黑 、白、红还有灰色。


 
 
 
 
  1. package com.yiwen.mobike.activity;
  2. import android.content.Intent;
  3. import android.os.Bundle;
  4. import android.support.v7.app.AppCompatActivity;
  5. import android.text.Editable;
  6. import android.text.TextUtils;
  7. import android.text.TextWatcher;
  8. import android.util.Log;
  9. import android.view.View;
  10. import android.widget.Button;
  11. import android.widget.EditText;
  12. import android.widget.TextView;
  13. import com.yiwen.mobike.R;
  14. import com.yiwen.mobike.utils.MyConstains;
  15. import com.yiwen.mobike.utils.ToastUtils;
  16. import com.yiwen.mobike.views.ClearEditText;
  17. import com.yiwen.mobike.views.CountTimerView;
  18. import com.yiwen.mobike.views.MyToolBar;
  19. import org.json.JSONObject;
  20. import java.util.ArrayList;
  21. import java.util.HashMap;
  22. import java.util.regex.Matcher;
  23. import java.util.regex.Pattern;
  24. import butterknife.BindView;
  25. import butterknife.ButterKnife;
  26. import butterknife.OnClick;
  27. import cn.smssdk.EventHandler;
  28. import cn.smssdk.SMSSDK;
  29. import cn.smssdk.utils.SMSLog;
  30. public class LoginActivity extends AppCompatActivity {
  31. private static final String TAG = "LoginActivity";
  32. @BindView(R.id.toolbar_login)
  33. MyToolBar mToolbarLogin;
  34. @BindView(R.id.et_phone)
  35. ClearEditText mEtPhone;
  36. @BindView(R.id.et_code)
  37. EditText mEtCode;
  38. @BindView(R.id.get_code)
  39. Button mGetCode;
  40. @BindView(R.id.loin_voice)
  41. TextView mLoinVoice;
  42. @BindView(R.id.login_query)
  43. Button mLoginQuery;
  44. @BindView(R.id.login_services)
  45. TextView mLoginServices;
  46. private boolean isNeedLogin = true;
  47. private TextView mTvCountryCode;
  48. private CountTimerView mCountTimeView;
  49. private int phoneLength = 0;
  50. private int codeLength = 0;
  51. // 默认使用中国区号
  52. private static final String DEFAULT_COUNTRY_ID = "42";
  53. private SmsEventHandler mEventHandler;
  54. private boolean isSendCode;
  55. @Override
  56. protected void onCreate(Bundle savedInstanceState) {
  57. super.onCreate(savedInstanceState);
  58. setContentView(R.layout.activity_login);
  59. ButterKnife.bind( this);
  60. intView();
  61. initDate();
  62. initEvent();
  63. }
  64. private void intView() {
  65. ButterKnife.bind( this);
  66. }
  67. private void initDate() {
  68. SMSSDK.initSDK( this, "1dfed2cdde843", "4266d445a7c298caecfb04ecb165fde7");
  69. mEventHandler = new SmsEventHandler();
  70. SMSSDK.registerEventHandler(mEventHandler);
  71. }
  72. private void initEvent() {
  73. mToolbarLogin.setOnLeftButtonClickListener( new MyToolBar.OnLeftButtonClickListener() {
  74. @Override
  75. public void onClick() {
  76. Go2Main();
  77. }
  78. });
  79. mEtPhone.addTextChangedListener( new TextWatcher() {
  80. @Override
  81. public void beforeTextChanged(CharSequence s, int start, int count, int after) {
  82. }
  83. @Override
  84. public void onTextChanged(CharSequence s, int start, int before, int count) {
  85. phoneLength = s.length();
  86. if (phoneLength > 0) {
  87. setRed(mGetCode);
  88. } else {
  89. setGray(mGetCode);
  90. }
  91. if (phoneLength > 0 && codeLength > 0) {
  92. setRed(mLoginQuery);
  93. } else {
  94. setGray(mLoginQuery);
  95. }
  96. }
  97. @Override
  98. public void afterTextChanged(Editable s) {
  99. }
  100. });
  101. mEtCode.addTextChangedListener( new TextWatcher() {
  102. @Override
  103. public void beforeTextChanged(CharSequence s, int start, int count, int after) {
  104. }
  105. @Override
  106. public void onTextChanged(CharSequence s, int start, int before, int count) {
  107. codeLength = s.length();
  108. if (phoneLength > 0 && codeLength > 0) {
  109. setRed(mLoginQuery);
  110. } else {
  111. setGray(mLoginQuery);
  112. }
  113. }
  114. @Override
  115. public void afterTextChanged(Editable s) {
  116. }
  117. });
  118. }
  119. /**
  120. * 改变bt颜色red设置可点击
  121. *
  122. * @param bt
  123. */
  124. private void setRed(Button bt) {
  125. bt.setClickable( true);
  126. bt.setBackgroundResource(R.color.red);
  127. }
  128. /**
  129. * 改变bt颜色gray设置不可点击
  130. *
  131. * @param bt
  132. */
  133. private void setGray(Button bt) {
  134. bt.setClickable( false);
  135. bt.setBackgroundResource(R.color.gray);
  136. }
  137. class SmsEventHandler extends EventHandler {
  138. @Override
  139. public void afterEvent(final int event, final int result, final Object data) {
  140. runOnUiThread( new Runnable() {
  141. @Override
  142. public void run() {
  143. //回调完成
  144. if (result == SMSSDK.RESULT_COMPLETE) {
  145. //返回支持发送验证码的国家列表
  146. if (event == SMSSDK.EVENT_GET_SUPPORTED_COUNTRIES) {
  147. // SMSSDK.getSupportedCountries();
  148. onCountryListGot((ArrayList<HashMap<String, Object>>) data);
  149. //获取验证码成功
  150. } else if (event == SMSSDK.EVENT_GET_VERIFICATION_CODE) {
  151. // 请求验证码后,跳转到验证码填写页面
  152. afterVerificationCodeRequested((Boolean) data);
  153. //提交验证码成功
  154. } else if (event == SMSSDK.EVENT_SUBMIT_VERIFICATION_CODE) {
  155. // ToastUtils.show(LoginActivity.this, "验证码已发送");
  156. mEtCode.setText( "");
  157. RegOK();
  158. }
  159. } else {
  160. // 根据服务器返回的网络错误,给toast提示
  161. try {
  162. ((Throwable) data).printStackTrace();
  163. Throwable throwable = (Throwable) data;
  164. JSONObject object = new JSONObject(
  165. throwable.getMessage());
  166. String des = object.optString( "detail");
  167. if (!TextUtils.isEmpty(des)) {
  168. ToastUtils.show(LoginActivity. this, des);
  169. return;
  170. }
  171. } catch (Exception e) {
  172. SMSLog.getInstance().w(e);
  173. }
  174. }
  175. }
  176. });
  177. }
  178. private void RegOK() {
  179. // ToastUtils.show(LoginActivity.this, "注册成功");
  180. getSharedPreferences(MyConstains.IS_NEED_LOGIN, MODE_PRIVATE)
  181. .edit()
  182. .putBoolean(MyConstains.IS_NEED_LOGIN, false)
  183. .apply();
  184. Go2Main();
  185. }
  186. }
  187. /**
  188. * 获得支持的国家列表
  189. *
  190. * @param data
  191. */
  192. private void onCountryListGot(ArrayList<HashMap<String, Object>> data) {
  193. for (HashMap<String, Object> country : data) {
  194. String code = (String) country.get( "zone");
  195. String rule = (String) country.get( "rule");
  196. if (TextUtils.isEmpty(code) || TextUtils.isEmpty(rule)) {
  197. continue;
  198. }
  199. Log.d(TAG, "onCountryListGot: " + code + ":" + rule);
  200. }
  201. }
  202. /**
  203. * 请求验证码成功后跳转
  204. *
  205. * @param data
  206. */
  207. private void afterVerificationCodeRequested(Boolean data) {
  208. String phone = mEtPhone.getText().toString().trim().replace( "\\s*", "");
  209. // String countryCode = mTvCountryCode.getText().toString().trim();
  210. String countryCode = "86";
  211. if (countryCode.startsWith( "+")) {
  212. countryCode = countryCode.substring( 1);
  213. }
  214. isSendCode = false;
  215. }
  216. private void Go2Main() {
  217. Intent intent = new Intent(LoginActivity. this, MainActivity.class);
  218. startActivity(intent);
  219. finish();
  220. }
  221. @OnClick({R.id.get_code, R.id.loin_voice, R.id.login_query, R.id.login_services})
  222. public void onViewClicked(View view) {
  223. switch (view.getId()) {
  224. case R.id.get_code:
  225. getCode();
  226. break;
  227. case R.id.loin_voice:
  228. ToastUtils.show(LoginActivity. this, "语音验证");
  229. break;
  230. case R.id.login_query:
  231. submitCode();
  232. break;
  233. case R.id.login_services:
  234. ToastUtils.show(LoginActivity. this, "服务点击");
  235. break;
  236. }
  237. }
  238. /**
  239. * 获取验证码
  240. */
  241. private void getCode() {
  242. String phone = mEtPhone.getText().toString().trim().replace( "\\s*", "");
  243. // String countryCode = mTvCountryCode.getText().toString().trim();
  244. String countryCode = "+86";
  245. // String countryCode = mTvCountryCode.getText().toString().trim();
  246. if (checkPhoneNum(phone, countryCode)) {
  247. /*请求获得验证码*/
  248. Log.d(TAG, "getCode: " + phone + "**" + countryCode);
  249. SMSSDK.getVerificationCode(countryCode, phone);
  250. mCountTimeView = new CountTimerView(mGetCode);
  251. mCountTimeView.start();
  252. }
  253. }
  254. /**
  255. * 检查手机号格式
  256. *
  257. * @param phone
  258. * @param countryCode
  259. */
  260. private boolean checkPhoneNum(String phone, String countryCode) {
  261. if (countryCode.startsWith( "+")) {
  262. countryCode = countryCode.substring( 1);
  263. }
  264. if (TextUtils.isEmpty(phone)) {
  265. mEtPhone.setError( "手机号格式有误");
  266. //ToastUtils.show(this, "请输入手机号码");
  267. // dissmissDialog();
  268. return false;
  269. }
  270. if (countryCode.equals( "86")) {
  271. if (phone.length() != 11) {
  272. mEtPhone.setError( "手机号长度不正确");
  273. // ToastUtils.show(this, "手机号长度不正确");
  274. // dissmissDialog();
  275. return false;
  276. }
  277. }
  278. String rule = "^1(3|5|7|8|4)\\d{9}";
  279. Pattern compile = Pattern.compile(rule);
  280. Matcher matcher = compile.matcher(phone);
  281. if (!matcher.matches()) {
  282. mEtPhone.setError( "您输入的手机号码格式不正确");
  283. // ToastUtils.show(this, "您输入的手机号码格式不正确");
  284. // dissmissDialog();
  285. return false;
  286. }
  287. return true;
  288. }
  289. private void submitCode() {
  290. String code = mEtCode.getText().toString().trim();
  291. String mPhone = mEtPhone.getText().toString().trim().replace( "\\s*", "");
  292. if (TextUtils.isEmpty(code)) {
  293. mEtCode.setError( "请输入验证码");
  294. // ToastUtils.show(this, "请输入验证码");
  295. return;
  296. }
  297. Log.d(TAG, "submitCode: " + mPhone + code);
  298. SMSSDK.submitVerificationCode( "86", mPhone, code);
  299. }
  300. @Override
  301. protected void onDestroy() {
  302. super.onDestroy();
  303. SMSSDK.unregisterEventHandler(mEventHandler);
  304. }
  305. }

6.最后说明:

    验证手机号用了mob的SDK,经测试还是可以发短信的,不过用同一号码,两三次就没有用了,估计是仿真频繁获取短信吧
今天就到这里了,具体代码可以到GitHub下载查看
github代码下载:yiwent
写博客不容易,喜欢希望多给个start,老铁,抱拳了。


今天的文章Mobike手机登录界面分享到此就结束了,感谢您的阅读。

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/61374.html

(0)
编程小号编程小号

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注