11 changed files with 607 additions and 77 deletions
-
6app/src/main/AndroidManifest.xml
-
130app/src/main/java/com/ouxuan/oxface/OXFaceOnlineActivity.java
-
205app/src/main/java/com/ouxuan/oxface/orderOX/VerificationCodeActivity.java
-
8app/src/main/res/drawable/btn_cancel_bg.xml
-
5app/src/main/res/drawable/btn_confirm_bg.xml
-
2app/src/main/res/drawable/dialog_background.xml
-
12app/src/main/res/drawable/primary_color_rounded_background.xml
-
8app/src/main/res/drawable/verification_code_bg.xml
-
2app/src/main/res/layout/activity_oxface_online.xml
-
272app/src/main/res/layout/activity_verification_code.xml
-
12app/src/main/res/values/styles.xml
@ -0,0 +1,205 @@ |
|||||
|
package com.ouxuan.oxface.orderOX; |
||||
|
|
||||
|
import android.content.Intent; |
||||
|
import android.os.Bundle; |
||||
|
import android.text.Editable; |
||||
|
import android.text.TextWatcher; |
||||
|
import android.view.View; |
||||
|
import android.view.Window; |
||||
|
import android.view.WindowManager; |
||||
|
import android.widget.Button; |
||||
|
import android.widget.EditText; |
||||
|
import android.widget.ImageButton; |
||||
|
import android.widget.TextView; |
||||
|
import android.widget.Toast; |
||||
|
|
||||
|
import androidx.appcompat.app.AppCompatActivity; |
||||
|
import androidx.core.content.ContextCompat; |
||||
|
|
||||
|
import com.ouxuan.oxface.R; |
||||
|
import com.ouxuan.oxface.utils.LogManager; |
||||
|
|
||||
|
/** |
||||
|
* 验证码开门Activity |
||||
|
* 提供一个覆盖在视频流上的弹窗界面,用于输入12位数字验证码 |
||||
|
*/ |
||||
|
public class VerificationCodeActivity extends AppCompatActivity { |
||||
|
|
||||
|
private static final String TAG = "VerificationCodeActivity"; |
||||
|
|
||||
|
private EditText etVerificationCode1, etVerificationCode2, etVerificationCode3, etVerificationCode4; |
||||
|
private EditText etVerificationCode5, etVerificationCode6, etVerificationCode7, etVerificationCode8; |
||||
|
private EditText etVerificationCode9, etVerificationCode10, etVerificationCode11, etVerificationCode12; |
||||
|
private Button btnConfirm, btnCancel; |
||||
|
private ImageButton btnClose; |
||||
|
private TextView tvTitle, tvSubtitle; |
||||
|
|
||||
|
private EditText[] verificationCodeInputs; |
||||
|
|
||||
|
@Override |
||||
|
protected void onCreate(Bundle savedInstanceState) { |
||||
|
super.onCreate(savedInstanceState); |
||||
|
|
||||
|
// 设置无标题栏 |
||||
|
requestWindowFeature(Window.FEATURE_NO_TITLE); |
||||
|
|
||||
|
// 设置背景透明,实现弹窗效果 |
||||
|
getWindow().setBackgroundDrawableResource(android.R.color.transparent); |
||||
|
|
||||
|
setContentView(R.layout.activity_verification_code); |
||||
|
|
||||
|
// 设置窗口属性 |
||||
|
Window window = getWindow(); |
||||
|
window.setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT); |
||||
|
window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); |
||||
|
|
||||
|
initViews(); |
||||
|
setupListeners(); |
||||
|
setupAutoFocus(); |
||||
|
|
||||
|
LogManager.logInfo(TAG, "验证码Activity启动成功"); |
||||
|
} |
||||
|
|
||||
|
private void initViews() { |
||||
|
// 初始化输入框 |
||||
|
etVerificationCode1 = findViewById(R.id.et_verification_code_1); |
||||
|
etVerificationCode2 = findViewById(R.id.et_verification_code_2); |
||||
|
etVerificationCode3 = findViewById(R.id.et_verification_code_3); |
||||
|
etVerificationCode4 = findViewById(R.id.et_verification_code_4); |
||||
|
etVerificationCode5 = findViewById(R.id.et_verification_code_5); |
||||
|
etVerificationCode6 = findViewById(R.id.et_verification_code_6); |
||||
|
etVerificationCode7 = findViewById(R.id.et_verification_code_7); |
||||
|
etVerificationCode8 = findViewById(R.id.et_verification_code_8); |
||||
|
etVerificationCode9 = findViewById(R.id.et_verification_code_9); |
||||
|
etVerificationCode10 = findViewById(R.id.et_verification_code_10); |
||||
|
etVerificationCode11 = findViewById(R.id.et_verification_code_11); |
||||
|
etVerificationCode12 = findViewById(R.id.et_verification_code_12); |
||||
|
|
||||
|
// 初始化按钮 |
||||
|
btnConfirm = findViewById(R.id.btn_confirm); |
||||
|
btnCancel = findViewById(R.id.btn_cancel); |
||||
|
btnClose = findViewById(R.id.btn_close); |
||||
|
|
||||
|
// 初始化标题 |
||||
|
tvTitle = findViewById(R.id.tv_title); |
||||
|
tvSubtitle = findViewById(R.id.tv_subtitle); |
||||
|
|
||||
|
// 设置输入框数组 |
||||
|
verificationCodeInputs = new EditText[]{ |
||||
|
etVerificationCode1, etVerificationCode2, etVerificationCode3, etVerificationCode4, |
||||
|
etVerificationCode5, etVerificationCode6, etVerificationCode7, etVerificationCode8, |
||||
|
etVerificationCode9, etVerificationCode10, etVerificationCode11, etVerificationCode12 |
||||
|
}; |
||||
|
|
||||
|
// 设置输入限制为数字 |
||||
|
for (EditText editText : verificationCodeInputs) { |
||||
|
editText.setInputType(android.text.InputType.TYPE_CLASS_NUMBER); |
||||
|
editText.setFilters(new android.text.InputFilter[]{ |
||||
|
new android.text.InputFilter.LengthFilter(1) |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
private void setupListeners() { |
||||
|
// 确认按钮 |
||||
|
btnConfirm.setOnClickListener(new View.OnClickListener() { |
||||
|
@Override |
||||
|
public void onClick(View v) { |
||||
|
handleConfirm(); |
||||
|
} |
||||
|
}); |
||||
|
|
||||
|
// 取消按钮 |
||||
|
btnCancel.setOnClickListener(new View.OnClickListener() { |
||||
|
@Override |
||||
|
public void onClick(View v) { |
||||
|
handleCancel(); |
||||
|
} |
||||
|
}); |
||||
|
|
||||
|
// 关闭按钮 |
||||
|
btnClose.setOnClickListener(new View.OnClickListener() { |
||||
|
@Override |
||||
|
public void onClick(View v) { |
||||
|
finish(); |
||||
|
} |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
private void setupAutoFocus() { |
||||
|
for (int i = 0; i < verificationCodeInputs.length; i++) { |
||||
|
final int index = i; |
||||
|
verificationCodeInputs[i].addTextChangedListener(new TextWatcher() { |
||||
|
@Override |
||||
|
public void beforeTextChanged(CharSequence s, int start, int count, int after) {} |
||||
|
|
||||
|
@Override |
||||
|
public void onTextChanged(CharSequence s, int start, int before, int count) { |
||||
|
if (s.length() == 1 && index < verificationCodeInputs.length - 1) { |
||||
|
verificationCodeInputs[index + 1].requestFocus(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void afterTextChanged(Editable s) {} |
||||
|
}); |
||||
|
|
||||
|
// 设置删除键监听 |
||||
|
verificationCodeInputs[i].setOnKeyListener(new View.OnKeyListener() { |
||||
|
@Override |
||||
|
public boolean onKey(View v, int keyCode, android.view.KeyEvent event) { |
||||
|
if (event.getAction() == android.view.KeyEvent.ACTION_DOWN && |
||||
|
keyCode == android.view.KeyEvent.KEYCODE_DEL) { |
||||
|
if (verificationCodeInputs[index].getText().toString().isEmpty() && |
||||
|
index > 0) { |
||||
|
verificationCodeInputs[index - 1].requestFocus(); |
||||
|
verificationCodeInputs[index - 1].setText(""); |
||||
|
return true; |
||||
|
} |
||||
|
} |
||||
|
return false; |
||||
|
} |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
private void handleConfirm() { |
||||
|
StringBuilder verificationCode = new StringBuilder(); |
||||
|
|
||||
|
for (EditText editText : verificationCodeInputs) { |
||||
|
String digit = editText.getText().toString().trim(); |
||||
|
if (digit.isEmpty()) { |
||||
|
Toast.makeText(this, "请输入完整的12位验证码", Toast.LENGTH_SHORT).show(); |
||||
|
return; |
||||
|
} |
||||
|
verificationCode.append(digit); |
||||
|
} |
||||
|
|
||||
|
String code = verificationCode.toString(); |
||||
|
LogManager.logInfo(TAG, "用户输入验证码: " + code); |
||||
|
|
||||
|
// 验证验证码格式 |
||||
|
if (code.length() != 12 || !code.matches("\\d{12}")) { |
||||
|
Toast.makeText(this, "请输入正确的12位数字验证码", Toast.LENGTH_SHORT).show(); |
||||
|
return; |
||||
|
} |
||||
|
|
||||
|
// 返回验证码结果 |
||||
|
Intent resultIntent = new Intent(); |
||||
|
resultIntent.putExtra("verification_code", code); |
||||
|
setResult(RESULT_OK, resultIntent); |
||||
|
finish(); |
||||
|
} |
||||
|
|
||||
|
private void handleCancel() { |
||||
|
LogManager.logInfo(TAG, "用户取消验证码输入"); |
||||
|
setResult(RESULT_CANCELED); |
||||
|
finish(); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void onBackPressed() { |
||||
|
super.onBackPressed(); |
||||
|
setResult(RESULT_CANCELED); |
||||
|
} |
||||
|
} |
@ -0,0 +1,8 @@ |
|||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||
|
<shape xmlns:android="http://schemas.android.com/apk/res/android"> |
||||
|
<solid android:color="#F5F5F5" /> |
||||
|
<corners android:radius="8dp" /> |
||||
|
<stroke |
||||
|
android:width="1dp" |
||||
|
android:color="#E0E0E0" /> |
||||
|
</shape> |
@ -0,0 +1,5 @@ |
|||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||
|
<shape xmlns:android="http://schemas.android.com/apk/res/android"> |
||||
|
<solid android:color="@color/primary_color" /> |
||||
|
<corners android:radius="8dp" /> |
||||
|
</shape> |
@ -0,0 +1,12 @@ |
|||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||
|
<shape xmlns:android="http://schemas.android.com/apk/res/android" |
||||
|
android:shape="rectangle"> |
||||
|
|
||||
|
<!-- 填充的颜色为主题色 --> |
||||
|
<solid android:color="@color/primary_color" /> |
||||
|
|
||||
|
<!-- 设置按钮的四个角为弧形 --> |
||||
|
<!-- android:radius 弧形的半径 --> |
||||
|
<corners android:radius="2dp" /> |
||||
|
|
||||
|
</shape> |
@ -0,0 +1,8 @@ |
|||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||
|
<shape xmlns:android="http://schemas.android.com/apk/res/android"> |
||||
|
<solid android:color="#F5F5F5" /> |
||||
|
<corners android:radius="4dp" /> |
||||
|
<!-- <stroke |
||||
|
android:width="1dp" |
||||
|
android:color="#E0E0E0" /> --> |
||||
|
</shape> |
@ -0,0 +1,272 @@ |
|||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||
|
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" |
||||
|
android:layout_width="match_parent" |
||||
|
android:layout_height="match_parent" |
||||
|
android:background="#80000000"> |
||||
|
|
||||
|
<!-- 主内容区域 --> |
||||
|
<LinearLayout |
||||
|
android:layout_width="match_parent" |
||||
|
android:layout_height="wrap_content" |
||||
|
android:layout_centerInParent="true" |
||||
|
android:layout_marginLeft="32dp" |
||||
|
android:layout_marginRight="32dp" |
||||
|
android:background="@drawable/dialog_background" |
||||
|
android:orientation="vertical" |
||||
|
android:padding="24dp"> |
||||
|
|
||||
|
<!-- 标题栏 --> |
||||
|
<RelativeLayout |
||||
|
android:layout_width="match_parent" |
||||
|
android:layout_height="wrap_content"> |
||||
|
|
||||
|
<TextView |
||||
|
android:id="@+id/tv_title" |
||||
|
android:layout_width="wrap_content" |
||||
|
android:layout_height="wrap_content" |
||||
|
android:layout_centerHorizontal="true" |
||||
|
android:text="订单验证码开门" |
||||
|
android:textColor="#333333" |
||||
|
android:textSize="18sp" |
||||
|
android:textStyle="bold" /> |
||||
|
|
||||
|
<ImageButton |
||||
|
android:id="@+id/btn_close" |
||||
|
android:layout_width="32dp" |
||||
|
android:layout_height="32dp" |
||||
|
android:layout_alignParentRight="true" |
||||
|
android:background="?attr/selectableItemBackgroundBorderless" |
||||
|
android:src="@drawable/ic_close" /> |
||||
|
</RelativeLayout> |
||||
|
|
||||
|
<!-- 副标题 --> |
||||
|
<TextView |
||||
|
android:id="@+id/tv_subtitle" |
||||
|
android:layout_width="wrap_content" |
||||
|
android:layout_height="wrap_content" |
||||
|
android:layout_gravity="center_horizontal" |
||||
|
android:layout_marginTop="8dp" |
||||
|
android:text="请输入12位数字验证码开门" |
||||
|
android:textColor="#666666" |
||||
|
android:textSize="14sp" /> |
||||
|
|
||||
|
<!-- 验证码输入框 --> |
||||
|
<LinearLayout |
||||
|
android:layout_width="match_parent" |
||||
|
android:layout_height="wrap_content" |
||||
|
android:layout_marginTop="24dp" |
||||
|
android:gravity="center" |
||||
|
android:orientation="horizontal"> |
||||
|
|
||||
|
<EditText |
||||
|
android:id="@+id/et_verification_code_1" |
||||
|
android:layout_width="0dp" |
||||
|
android:layout_height="48dp" |
||||
|
android:layout_weight="1" |
||||
|
android:background="@drawable/verification_code_bg" |
||||
|
android:gravity="center" |
||||
|
android:hint="0" |
||||
|
android:inputType="number" |
||||
|
android:maxLength="1" |
||||
|
android:textColor="#333333" |
||||
|
android:textSize="20sp" |
||||
|
android:textStyle="bold" /> |
||||
|
|
||||
|
<EditText |
||||
|
android:id="@+id/et_verification_code_2" |
||||
|
android:layout_width="0dp" |
||||
|
android:layout_height="48dp" |
||||
|
android:layout_marginLeft="4dp" |
||||
|
android:layout_weight="1" |
||||
|
android:background="@drawable/verification_code_bg" |
||||
|
android:gravity="center" |
||||
|
android:hint="0" |
||||
|
android:inputType="number" |
||||
|
android:maxLength="1" |
||||
|
android:textColor="#333333" |
||||
|
android:textSize="20sp" |
||||
|
android:textStyle="bold" /> |
||||
|
|
||||
|
<EditText |
||||
|
android:id="@+id/et_verification_code_3" |
||||
|
android:layout_width="0dp" |
||||
|
android:layout_height="48dp" |
||||
|
android:layout_marginLeft="4dp" |
||||
|
android:layout_weight="1" |
||||
|
android:background="@drawable/verification_code_bg" |
||||
|
android:gravity="center" |
||||
|
android:hint="0" |
||||
|
android:inputType="number" |
||||
|
android:maxLength="1" |
||||
|
android:textColor="#333333" |
||||
|
android:textSize="20sp" |
||||
|
android:textStyle="bold" /> |
||||
|
|
||||
|
<EditText |
||||
|
android:id="@+id/et_verification_code_4" |
||||
|
android:layout_width="0dp" |
||||
|
android:layout_height="48dp" |
||||
|
android:layout_marginLeft="4dp" |
||||
|
android:layout_weight="1" |
||||
|
android:background="@drawable/verification_code_bg" |
||||
|
android:gravity="center" |
||||
|
android:hint="0" |
||||
|
android:inputType="number" |
||||
|
android:maxLength="1" |
||||
|
android:textColor="#333333" |
||||
|
android:textSize="20sp" |
||||
|
android:textStyle="bold" /> |
||||
|
|
||||
|
<EditText |
||||
|
android:id="@+id/et_verification_code_5" |
||||
|
android:layout_width="0dp" |
||||
|
android:layout_height="48dp" |
||||
|
android:layout_marginLeft="4dp" |
||||
|
android:layout_weight="1" |
||||
|
android:background="@drawable/verification_code_bg" |
||||
|
android:gravity="center" |
||||
|
android:hint="0" |
||||
|
android:inputType="number" |
||||
|
android:maxLength="1" |
||||
|
android:textColor="#333333" |
||||
|
android:textSize="20sp" |
||||
|
android:textStyle="bold" /> |
||||
|
|
||||
|
<EditText |
||||
|
android:id="@+id/et_verification_code_6" |
||||
|
android:layout_width="0dp" |
||||
|
android:layout_height="48dp" |
||||
|
android:layout_marginLeft="4dp" |
||||
|
android:layout_weight="1" |
||||
|
android:background="@drawable/verification_code_bg" |
||||
|
android:gravity="center" |
||||
|
android:hint="0" |
||||
|
android:inputType="number" |
||||
|
android:maxLength="1" |
||||
|
android:textColor="#333333" |
||||
|
android:textSize="20sp" |
||||
|
android:textStyle="bold" /> |
||||
|
|
||||
|
<EditText |
||||
|
android:id="@+id/et_verification_code_7" |
||||
|
android:layout_width="0dp" |
||||
|
android:layout_height="48dp" |
||||
|
android:layout_marginLeft="4dp" |
||||
|
android:layout_weight="1" |
||||
|
android:background="@drawable/verification_code_bg" |
||||
|
android:gravity="center" |
||||
|
android:hint="0" |
||||
|
android:inputType="number" |
||||
|
android:maxLength="1" |
||||
|
android:textColor="#333333" |
||||
|
android:textSize="20sp" |
||||
|
android:textStyle="bold" /> |
||||
|
|
||||
|
<EditText |
||||
|
android:id="@+id/et_verification_code_8" |
||||
|
android:layout_width="0dp" |
||||
|
android:layout_height="48dp" |
||||
|
android:layout_marginLeft="4dp" |
||||
|
android:layout_weight="1" |
||||
|
android:background="@drawable/verification_code_bg" |
||||
|
android:gravity="center" |
||||
|
android:hint="0" |
||||
|
android:inputType="number" |
||||
|
android:maxLength="1" |
||||
|
android:textColor="#333333" |
||||
|
android:textSize="20sp" |
||||
|
android:textStyle="bold" /> |
||||
|
|
||||
|
<EditText |
||||
|
android:id="@+id/et_verification_code_9" |
||||
|
android:layout_width="0dp" |
||||
|
android:layout_height="48dp" |
||||
|
android:layout_marginLeft="4dp" |
||||
|
android:layout_weight="1" |
||||
|
android:background="@drawable/verification_code_bg" |
||||
|
android:gravity="center" |
||||
|
android:hint="0" |
||||
|
android:inputType="number" |
||||
|
android:maxLength="1" |
||||
|
android:textColor="#333333" |
||||
|
android:textSize="20sp" |
||||
|
android:textStyle="bold" /> |
||||
|
|
||||
|
<EditText |
||||
|
android:id="@+id/et_verification_code_10" |
||||
|
android:layout_width="0dp" |
||||
|
android:layout_height="48dp" |
||||
|
android:layout_marginLeft="4dp" |
||||
|
android:layout_weight="1" |
||||
|
android:background="@drawable/verification_code_bg" |
||||
|
android:gravity="center" |
||||
|
android:hint="0" |
||||
|
android:inputType="number" |
||||
|
android:maxLength="1" |
||||
|
android:textColor="#333333" |
||||
|
android:textSize="20sp" |
||||
|
android:textStyle="bold" /> |
||||
|
|
||||
|
<EditText |
||||
|
android:id="@+id/et_verification_code_11" |
||||
|
android:layout_width="0dp" |
||||
|
android:layout_height="48dp" |
||||
|
android:layout_marginLeft="4dp" |
||||
|
android:layout_weight="1" |
||||
|
android:background="@drawable/verification_code_bg" |
||||
|
android:gravity="center" |
||||
|
android:hint="0" |
||||
|
android:inputType="number" |
||||
|
android:maxLength="1" |
||||
|
android:textColor="#333333" |
||||
|
android:textSize="20sp" |
||||
|
android:textStyle="bold" /> |
||||
|
|
||||
|
<EditText |
||||
|
android:id="@+id/et_verification_code_12" |
||||
|
android:layout_width="0dp" |
||||
|
android:layout_height="48dp" |
||||
|
android:layout_marginLeft="4dp" |
||||
|
android:layout_weight="1" |
||||
|
android:background="@drawable/verification_code_bg" |
||||
|
android:gravity="center" |
||||
|
android:hint="0" |
||||
|
android:inputType="number" |
||||
|
android:maxLength="1" |
||||
|
android:textColor="#333333" |
||||
|
android:textSize="20sp" |
||||
|
android:textStyle="bold" /> |
||||
|
</LinearLayout> |
||||
|
|
||||
|
<!-- 按钮区域 --> |
||||
|
<LinearLayout |
||||
|
android:layout_width="match_parent" |
||||
|
android:layout_height="wrap_content" |
||||
|
android:layout_marginTop="32dp" |
||||
|
android:orientation="horizontal"> |
||||
|
|
||||
|
<Button |
||||
|
android:id="@+id/btn_cancel" |
||||
|
android:layout_width="0dp" |
||||
|
android:layout_height="44dp" |
||||
|
android:layout_marginRight="8dp" |
||||
|
android:layout_weight="1" |
||||
|
android:background="@drawable/btn_cancel_bg" |
||||
|
android:text="取消" |
||||
|
android:textColor="#666666" |
||||
|
android:textSize="16sp" /> |
||||
|
|
||||
|
<Button |
||||
|
android:id="@+id/btn_confirm" |
||||
|
android:layout_width="0dp" |
||||
|
android:layout_height="44dp" |
||||
|
android:layout_marginLeft="8dp" |
||||
|
android:layout_weight="1" |
||||
|
android:background="@drawable/btn_confirm_bg" |
||||
|
android:text="验证开门" |
||||
|
android:textColor="#FFFFFF" |
||||
|
android:textSize="16sp" /> |
||||
|
</LinearLayout> |
||||
|
</LinearLayout> |
||||
|
|
||||
|
</RelativeLayout> |
@ -0,0 +1,12 @@ |
|||||
|
<resources> |
||||
|
<!-- 透明主题 --> |
||||
|
<style name="Theme.Transparent" parent="Theme.AppCompat.Light.NoActionBar"> |
||||
|
<item name="android:windowIsTranslucent">true</item> |
||||
|
<item name="android:windowBackground">@android:color/transparent</item> |
||||
|
<item name="android:windowContentOverlay">@null</item> |
||||
|
<item name="android:windowNoTitle">true</item> |
||||
|
<item name="android:windowIsFloating">false</item> |
||||
|
<item name="android:backgroundDimEnabled">true</item> |
||||
|
<item name="android:backgroundDimAmount">0.5</item> |
||||
|
</style> |
||||
|
</resources> |
Write
Preview
Loading…
Cancel
Save
Reference in new issue