|
|
@@ -1,12 +1,16 @@
|
|
|
package com.paul.drone.activity;
|
|
|
-
|
|
|
+// 在文件顶部添加导入
|
|
|
+import android.view.WindowManager;
|
|
|
+import android.view.ViewGroup;
|
|
|
import android.annotation.SuppressLint;
|
|
|
import android.app.DownloadManager;
|
|
|
import android.content.BroadcastReceiver;
|
|
|
import android.content.Context;
|
|
|
import android.content.Intent;
|
|
|
import android.content.IntentFilter;
|
|
|
+import android.content.res.ColorStateList;
|
|
|
import android.database.Cursor;
|
|
|
+import android.graphics.Color;
|
|
|
import android.net.Uri;
|
|
|
import android.os.Build;
|
|
|
import android.os.Bundle;
|
|
|
@@ -32,6 +36,7 @@ import com.paul.drone.data.UpdateInfoResponse;
|
|
|
import com.paul.drone.manager.DJISDKManager;
|
|
|
import com.paul.drone.network.SessionManager;
|
|
|
import com.paul.drone.repository.NetworkRepository;
|
|
|
+import com.paul.drone.util.AESHelper;
|
|
|
import com.paul.drone.util.VersionUpdateUtil;
|
|
|
|
|
|
import java.io.File;
|
|
|
@@ -77,33 +82,107 @@ public class LoginActivity extends AppCompatActivity {
|
|
|
|
|
|
// 切换到短信登录
|
|
|
private void switchToSmsLogin() {
|
|
|
+ // 显示短信登录界面,隐藏密码登录界面
|
|
|
layoutSmsLogin.setVisibility(View.VISIBLE);
|
|
|
layoutPasswordLogin.setVisibility(View.GONE);
|
|
|
- btnSwitchSms.setEnabled(false);
|
|
|
- btnSwitchPassword.setEnabled(true);
|
|
|
+
|
|
|
+ // 给按钮背景上色
|
|
|
+ // 短信按钮设为蓝色背景
|
|
|
+ int blueColor = Color.parseColor("#1088F2");
|
|
|
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
|
|
+ btnSwitchSms.setBackgroundTintList(ColorStateList.valueOf(blueColor));
|
|
|
+ btnSwitchSms.setTextColor(Color.WHITE);
|
|
|
+ btnSwitchSms2.setBackgroundTintList(ColorStateList.valueOf(blueColor));
|
|
|
+ btnSwitchSms2.setTextColor(Color.WHITE);
|
|
|
+
|
|
|
+ // 密码按钮设为默认背景(灰色)
|
|
|
+ btnSwitchPassword.setBackgroundTintList(ColorStateList.valueOf(Color.parseColor("#E0E0E0")));
|
|
|
+ btnSwitchPassword.setTextColor(Color.BLACK);
|
|
|
+ btnSwitchPassword2.setBackgroundTintList(ColorStateList.valueOf(Color.parseColor("#E0E0E0")));
|
|
|
+ btnSwitchPassword2.setTextColor(Color.BLACK);
|
|
|
+ } else {
|
|
|
+ // 旧版本Android兼容处理
|
|
|
+ btnSwitchSms.setBackgroundColor(blueColor);
|
|
|
+ btnSwitchSms.setTextColor(Color.WHITE);
|
|
|
+ btnSwitchSms2.setBackgroundColor(blueColor);
|
|
|
+ btnSwitchSms2.setTextColor(Color.WHITE);
|
|
|
+
|
|
|
+ btnSwitchPassword.setBackgroundColor(Color.parseColor("#E0E0E0"));
|
|
|
+ btnSwitchPassword.setTextColor(Color.BLACK);
|
|
|
+ btnSwitchPassword2.setBackgroundColor(Color.parseColor("#E0E0E0"));
|
|
|
+ btnSwitchPassword2.setTextColor(Color.BLACK);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- // 切换到密码登录
|
|
|
+ // 修改switchToPasswordLogin方法
|
|
|
private void switchToPasswordLogin() {
|
|
|
+ // 显示密码登录界面,隐藏短信登录界面
|
|
|
layoutSmsLogin.setVisibility(View.GONE);
|
|
|
layoutPasswordLogin.setVisibility(View.VISIBLE);
|
|
|
- btnSwitchSms.setEnabled(true);
|
|
|
- btnSwitchPassword.setEnabled(false);
|
|
|
+ // 给按钮背景上色
|
|
|
+ // 密码按钮设为蓝色背景
|
|
|
+ int blueColor = Color.parseColor("#1088F2");
|
|
|
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
|
|
+ btnSwitchPassword.setBackgroundTintList(ColorStateList.valueOf(blueColor));
|
|
|
+ btnSwitchPassword.setTextColor(Color.WHITE);
|
|
|
+ btnSwitchPassword2.setBackgroundTintList(ColorStateList.valueOf(blueColor));
|
|
|
+ btnSwitchPassword2.setTextColor(Color.WHITE);
|
|
|
+
|
|
|
+ // 短信按钮设为默认背景(灰色)
|
|
|
+ btnSwitchSms.setBackgroundTintList(ColorStateList.valueOf(Color.parseColor("#E0E0E0")));
|
|
|
+ btnSwitchSms.setTextColor(Color.BLACK);
|
|
|
+ btnSwitchSms2.setBackgroundTintList(ColorStateList.valueOf(Color.parseColor("#E0E0E0")));
|
|
|
+ btnSwitchSms2.setTextColor(Color.BLACK);
|
|
|
+ } else {
|
|
|
+ // 旧版本Android兼容处理
|
|
|
+ btnSwitchPassword.setBackgroundColor(blueColor);
|
|
|
+ btnSwitchPassword.setTextColor(Color.WHITE);
|
|
|
+ btnSwitchPassword2.setBackgroundColor(blueColor);
|
|
|
+ btnSwitchPassword2.setTextColor(Color.WHITE);
|
|
|
+
|
|
|
+ btnSwitchSms.setBackgroundColor(Color.parseColor("#E0E0E0"));
|
|
|
+ btnSwitchSms.setTextColor(Color.BLACK);
|
|
|
+ btnSwitchSms2.setBackgroundColor(Color.parseColor("#E0E0E0"));
|
|
|
+ btnSwitchSms2.setTextColor(Color.BLACK);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
super.onCreate(savedInstanceState);
|
|
|
-
|
|
|
+
|
|
|
+ // 设置状态栏颜色为蓝色#1088F2
|
|
|
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
|
|
+ getWindow().setStatusBarColor(Color.parseColor("#1088F2"));
|
|
|
+ // 确保状态栏文字为白色,提高可读性
|
|
|
+ getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
|
|
|
+ } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
|
|
+ // 旧版Android兼容处理
|
|
|
+ getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
|
|
|
+ // 创建一个与状态栏高度相同的View并设置背景色
|
|
|
+ View statusBarView = new View(this);
|
|
|
+ LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
|
|
|
+ LinearLayout.LayoutParams.MATCH_PARENT,
|
|
|
+ getStatusBarHeight()
|
|
|
+ );
|
|
|
+ statusBarView.setBackgroundColor(Color.parseColor("#1088F2"));
|
|
|
+ // 添加到布局顶部
|
|
|
+ ViewGroup decorView = (ViewGroup) getWindow().getDecorView();
|
|
|
+ decorView.addView(statusBarView, params);
|
|
|
+ // 确保内容不被状态栏遮挡
|
|
|
+ ViewGroup rootView = findViewById(android.R.id.content);
|
|
|
+ rootView.setPadding(0, getStatusBarHeight(), 0, 0);
|
|
|
+ }
|
|
|
+
|
|
|
// 初始化 NetworkRepository
|
|
|
networkRepository = NetworkRepository.getInstance();
|
|
|
sessionManager = new SessionManager(this);
|
|
|
-
|
|
|
+
|
|
|
updateUtil = VersionUpdateUtil.getInstance(this);
|
|
|
-
|
|
|
+
|
|
|
String currentVersion = updateUtil.getCurrentVersion();
|
|
|
Single<UpdateInfoResponse> updateInfoResponseSingle = updateUtil.checkLatestVersion();
|
|
|
-
|
|
|
+
|
|
|
disposables.add(updateInfoResponseSingle.subscribeOn(Schedulers.io())
|
|
|
.observeOn(AndroidSchedulers.mainThread())
|
|
|
.subscribe(
|
|
|
@@ -123,7 +202,7 @@ public class LoginActivity extends AppCompatActivity {
|
|
|
checkLoginStatus(sessionManager);
|
|
|
}
|
|
|
));
|
|
|
-
|
|
|
+
|
|
|
// 注意:不要在这里添加其他逻辑,所有后续操作应该在subscribe回调中处理
|
|
|
}
|
|
|
|
|
|
@@ -166,6 +245,48 @@ public class LoginActivity extends AppCompatActivity {
|
|
|
etUsername = findViewById(R.id.et_username);
|
|
|
etPassword = findViewById(R.id.et_password);
|
|
|
btnPasswordLogin = findViewById(R.id.btn_password_login);
|
|
|
+
|
|
|
+ // 设置按钮默认背景色为#1088F2
|
|
|
+ int blueColor = Color.parseColor("#1088F2");
|
|
|
+
|
|
|
+ // 登录按钮
|
|
|
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
|
|
+ buttonLogin.setBackgroundTintList(ColorStateList.valueOf(blueColor));
|
|
|
+ btnPasswordLogin.setBackgroundTintList(ColorStateList.valueOf(blueColor));
|
|
|
+ // 为验证码按钮设置背景色
|
|
|
+ buttonSendSms.setBackgroundTintList(ColorStateList.valueOf(blueColor));
|
|
|
+ } else {
|
|
|
+ buttonLogin.setBackgroundColor(blueColor);
|
|
|
+ btnPasswordLogin.setBackgroundColor(blueColor);
|
|
|
+ // 为验证码按钮设置背景色
|
|
|
+ buttonSendSms.setBackgroundColor(blueColor);
|
|
|
+ }
|
|
|
+ buttonLogin.setTextColor(Color.WHITE);
|
|
|
+ btnPasswordLogin.setTextColor(Color.WHITE);
|
|
|
+ buttonSendSms.setTextColor(Color.WHITE);
|
|
|
+
|
|
|
+ // 登录方式切换按钮 - 初始状态(短信登录为蓝色,密码登录为灰色)
|
|
|
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
|
|
+ btnSwitchSms.setBackgroundTintList(ColorStateList.valueOf(blueColor));
|
|
|
+ btnSwitchSms2.setBackgroundTintList(ColorStateList.valueOf(blueColor));
|
|
|
+ btnSwitchSms.setTextColor(Color.WHITE);
|
|
|
+ btnSwitchSms2.setTextColor(Color.WHITE);
|
|
|
+
|
|
|
+ btnSwitchPassword.setBackgroundTintList(ColorStateList.valueOf(Color.parseColor("#E0E0E0")));
|
|
|
+ btnSwitchPassword2.setBackgroundTintList(ColorStateList.valueOf(Color.parseColor("#E0E0E0")));
|
|
|
+ btnSwitchPassword.setTextColor(Color.BLACK);
|
|
|
+ btnSwitchPassword2.setTextColor(Color.BLACK);
|
|
|
+ } else {
|
|
|
+ btnSwitchSms.setBackgroundColor(blueColor);
|
|
|
+ btnSwitchSms2.setBackgroundColor(blueColor);
|
|
|
+ btnSwitchSms.setTextColor(Color.WHITE);
|
|
|
+ btnSwitchSms2.setTextColor(Color.WHITE);
|
|
|
+
|
|
|
+ btnSwitchPassword.setBackgroundColor(Color.parseColor("#E0E0E0"));
|
|
|
+ btnSwitchPassword2.setBackgroundColor(Color.parseColor("#E0E0E0"));
|
|
|
+ btnSwitchPassword.setTextColor(Color.BLACK);
|
|
|
+ btnSwitchPassword2.setTextColor(Color.BLACK);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
private void setupListeners() {
|
|
|
@@ -313,13 +434,15 @@ public class LoginActivity extends AppCompatActivity {
|
|
|
*/
|
|
|
private void performPasswordLogin(String phoneNumber, String password) {
|
|
|
Log.i(TAG, "登录: " + phoneNumber + ", 密码: " + password);
|
|
|
+ // 加密密码
|
|
|
+ String encryptedPassword = AESHelper.encrypt("hntt,sddn,-cloud",password);
|
|
|
|
|
|
// 禁用登录按钮
|
|
|
buttonLogin.setEnabled(false);
|
|
|
buttonLogin.setText("登录中...");
|
|
|
|
|
|
// 使用 NetworkRepository 执行登录
|
|
|
- disposables.add(networkRepository.loginWithPassword(phoneNumber,password)
|
|
|
+ disposables.add(networkRepository.loginWithPassword(phoneNumber,encryptedPassword)
|
|
|
.subscribeOn(Schedulers.io())
|
|
|
.observeOn(AndroidSchedulers.mainThread())
|
|
|
.subscribe(
|
|
|
@@ -737,5 +860,13 @@ public class LoginActivity extends AppCompatActivity {
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
-}
|
|
|
+ // 添加获取状态栏高度的辅助方法
|
|
|
+ private int getStatusBarHeight() {
|
|
|
+ int result = 0;
|
|
|
+ int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
|
|
|
+ if (resourceId > 0) {
|
|
|
+ result = getResources().getDimensionPixelSize(resourceId);
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+}
|