desc:wifi 设置
parent
0a49b93b2a
commit
65d361cb77
@ -0,0 +1,33 @@
|
||||
package com.yinuo.safetywatcher.watcher.wifi;
|
||||
|
||||
/**
|
||||
* WiFi配置
|
||||
*/
|
||||
public class WiFiConfig {
|
||||
|
||||
//默认超时时间
|
||||
private static final long DEFAULT_TIME_OUT = 1000 * 15;
|
||||
|
||||
public long timeOut = DEFAULT_TIME_OUT;
|
||||
|
||||
private WiFiConfig() {
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
private WiFiConfig config;
|
||||
|
||||
public Builder() {
|
||||
config = new WiFiConfig();
|
||||
}
|
||||
|
||||
public Builder setTimeOut(long time) {
|
||||
config.timeOut = time;
|
||||
return this;
|
||||
}
|
||||
|
||||
public WiFiConfig build() {
|
||||
return config;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package com.yinuo.safetywatcher.watcher.wifi.info;
|
||||
|
||||
import android.net.wifi.WifiConfiguration;
|
||||
|
||||
/**
|
||||
* 创建WiFi配置状态
|
||||
*/
|
||||
public class WiFiCreateConfigStatusInfo {
|
||||
|
||||
public String SSID;
|
||||
public WifiConfiguration configuration;
|
||||
public boolean isSuccess;
|
||||
|
||||
public boolean isSuccess() {
|
||||
return isSuccess && null != configuration;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
package com.yinuo.safetywatcher.watcher.wifi.info;
|
||||
|
||||
/**
|
||||
* 删除WiFi状态
|
||||
*/
|
||||
public class WiFiRemoveStatusInfo {
|
||||
|
||||
public String SSID;
|
||||
public boolean isSuccess;
|
||||
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
package com.yinuo.safetywatcher.watcher.wifi.info.action;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.yinuo.safetywatcher.watcher.wifi.type.Types;
|
||||
|
||||
public abstract class IWiFiAction {
|
||||
|
||||
@Types.ActionStateType
|
||||
private int actionState;
|
||||
|
||||
IWiFiAction() {
|
||||
setState(Types.ActionStateType.WAITING);
|
||||
}
|
||||
|
||||
private String getActionName() {
|
||||
return getClass().getSimpleName();
|
||||
}
|
||||
|
||||
public int getActionState() {
|
||||
return actionState;
|
||||
}
|
||||
|
||||
public void setState(@Types.ActionStateType int state) {
|
||||
this.actionState = state;
|
||||
}
|
||||
|
||||
public void end() {
|
||||
this.actionState = Types.ActionStateType.END;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String toString() {
|
||||
return getActionName() + " | actionState:" + actionState;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
package com.yinuo.safetywatcher.watcher.wifi.info.action;
|
||||
|
||||
import android.net.wifi.WifiConfiguration;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.yinuo.safetywatcher.watcher.wifi.interfaces.ConnectWiFiActionListener;
|
||||
|
||||
/**
|
||||
* 通过配置直接连接
|
||||
*/
|
||||
public class WiFiDirectConnectAction extends WiFiConnectAction {
|
||||
|
||||
public WifiConfiguration configuration;
|
||||
|
||||
public WiFiDirectConnectAction(@NonNull String SSID, @NonNull WifiConfiguration configuration, @Nullable ConnectWiFiActionListener listener) {
|
||||
super(SSID, listener);
|
||||
this.configuration = configuration;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String toString() {
|
||||
return super.toString() + " | " + SSID;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
package com.yinuo.safetywatcher.watcher.wifi.info.action;
|
||||
|
||||
/**
|
||||
* 禁用WiFi
|
||||
*/
|
||||
public class WiFiDisableAction extends IWiFiAction {
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
package com.yinuo.safetywatcher.watcher.wifi.info.action;
|
||||
|
||||
/**
|
||||
* 启用WiFi
|
||||
*/
|
||||
public class WiFiEnableAction extends IWiFiAction {
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
package com.yinuo.safetywatcher.watcher.wifi.info.action;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.yinuo.safetywatcher.watcher.wifi.interfaces.ConnectWiFiActionListener;
|
||||
import com.yinuo.safetywatcher.watcher.wifi.type.WiFiCipherType;
|
||||
|
||||
/**
|
||||
* 通过密码连接WiFi
|
||||
*/
|
||||
public class WiFiNormalConnectAction extends WiFiConnectAction {
|
||||
|
||||
public WiFiCipherType cipherType;
|
||||
public String password;
|
||||
|
||||
public WiFiNormalConnectAction(@NonNull String SSID, @NonNull WiFiCipherType cipherType, @Nullable String password, @Nullable ConnectWiFiActionListener listener) {
|
||||
super(SSID, listener);
|
||||
|
||||
this.cipherType = cipherType;
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String toString() {
|
||||
return super.toString() + " | " + SSID + " | " + cipherType.name();
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
package com.yinuo.safetywatcher.watcher.wifi.info.action;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.yinuo.safetywatcher.watcher.wifi.interfaces.RemoveWiFiActionListener;
|
||||
|
||||
/**
|
||||
* 移除
|
||||
*/
|
||||
public class WiFiRemoveAction extends IWiFiAction {
|
||||
|
||||
public String SSID;
|
||||
public RemoveWiFiActionListener listener;
|
||||
|
||||
public WiFiRemoveAction(String SSID, RemoveWiFiActionListener listener) {
|
||||
this.SSID = SSID;
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String toString() {
|
||||
return super.toString() + " | " + SSID;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
package com.yinuo.safetywatcher.watcher.wifi.info.action;
|
||||
|
||||
import com.yinuo.safetywatcher.watcher.wifi.interfaces.ScanWiFiActionListener;
|
||||
|
||||
/**
|
||||
* 扫描WiFi
|
||||
*/
|
||||
public class WiFiScanAction extends IWiFiAction {
|
||||
|
||||
public ScanWiFiActionListener listener;
|
||||
|
||||
public WiFiScanAction(ScanWiFiActionListener listener) {
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package com.yinuo.safetywatcher.watcher.wifi.interfaces;
|
||||
|
||||
import android.net.wifi.WifiConfiguration;
|
||||
|
||||
import com.yinuo.safetywatcher.watcher.wifi.type.Types;
|
||||
|
||||
public interface ConnectWiFiActionListener extends IActionListener {
|
||||
|
||||
void onCreateConfig(WifiConfiguration configuration);
|
||||
|
||||
void onResult(@Types.ConnectResultType int type);
|
||||
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
package com.yinuo.safetywatcher.watcher.wifi.interfaces;
|
||||
|
||||
public interface IActionListener {
|
||||
|
||||
void onStart();
|
||||
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
package com.yinuo.safetywatcher.watcher.wifi.interfaces;
|
||||
|
||||
import com.yinuo.safetywatcher.watcher.wifi.type.Types;
|
||||
|
||||
public interface RemoveWiFiActionListener extends IActionListener {
|
||||
|
||||
void onResult(@Types.RemoveResultType int type);
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package com.yinuo.safetywatcher.watcher.wifi.interfaces;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.yinuo.safetywatcher.watcher.wifi.info.WiFiScanInfo;
|
||||
import com.yinuo.safetywatcher.watcher.wifi.type.Types;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface ScanWiFiActionListener extends IActionListener {
|
||||
|
||||
void onResult(@Types.ScanResultType int type, @Nullable List<WiFiScanInfo> list);
|
||||
}
|
@ -0,0 +1,61 @@
|
||||
package com.yinuo.safetywatcher.watcher.wifi.interfaces;
|
||||
|
||||
import android.net.wifi.WifiConfiguration;
|
||||
|
||||
import com.yinuo.safetywatcher.watcher.wifi.info.WiFiRemoveStatusInfo;
|
||||
import com.yinuo.safetywatcher.watcher.wifi.info.WiFiScanInfo;
|
||||
import com.yinuo.safetywatcher.watcher.wifi.type.WiFiConnectFailType;
|
||||
import com.yinuo.safetywatcher.watcher.wifi.type.WiFiGetListType;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* WiFi全局相关状态监听
|
||||
*/
|
||||
public interface WiFiListener {
|
||||
|
||||
/**
|
||||
* 开始扫描WiFi
|
||||
*/
|
||||
void onStartScan();
|
||||
|
||||
/**
|
||||
* 通知WiFi关闭
|
||||
*/
|
||||
void onCloseWiFi();
|
||||
|
||||
/**
|
||||
* WiFi数据更新
|
||||
*/
|
||||
void onDataChange(WiFiGetListType type, List<WiFiScanInfo> list);
|
||||
|
||||
/**
|
||||
* 开始连接WiFi
|
||||
*/
|
||||
void onWiFiStartConnect(String SSID);
|
||||
|
||||
/**
|
||||
* 创建WiFi配置
|
||||
*/
|
||||
void onWiFiCreateConfig(String SSID, WifiConfiguration configuration);
|
||||
|
||||
/**
|
||||
* WiFi连接成功
|
||||
*
|
||||
* @param isInit 标识是否是初始连接成功
|
||||
*/
|
||||
void onWiFiConnected(String SSID, boolean isInit);
|
||||
|
||||
/**
|
||||
* WiFi连接失败
|
||||
*
|
||||
* @param type 失败类型
|
||||
*/
|
||||
void onWiFiConnectFail(String SSID, WiFiConnectFailType type);
|
||||
|
||||
/**
|
||||
* 删除WiFi状态
|
||||
*/
|
||||
void onWiFiRemoveResult(WiFiRemoveStatusInfo info);
|
||||
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
package com.yinuo.safetywatcher.watcher.wifi.interfaces;
|
||||
|
||||
import android.content.Intent;
|
||||
|
||||
/**
|
||||
* WiFi状态回调
|
||||
*/
|
||||
public interface WiFiStatusListener {
|
||||
|
||||
/**
|
||||
* 处理扫描列表
|
||||
*/
|
||||
void handleScanResultsChanged(Intent intent);
|
||||
|
||||
/**
|
||||
* 处理WiFi状态
|
||||
*/
|
||||
void handleWiFiStateChanged(Intent intent);
|
||||
|
||||
/**
|
||||
* 处理网络状态
|
||||
*/
|
||||
void handleNetStateChanged(Intent intent);
|
||||
|
||||
/**
|
||||
* 处理WiFi状态(密码错误回调)
|
||||
*/
|
||||
void handleSupplicantStateChanged(Intent intent);
|
||||
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
package com.yinuo.safetywatcher.watcher.wifi.interfaces;
|
||||
|
||||
import android.net.wifi.WifiInfo;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.yinuo.safetywatcher.watcher.wifi.info.action.IWiFiAction;
|
||||
import com.yinuo.safetywatcher.watcher.wifi.info.action.WiFiConnectAction;
|
||||
import com.yinuo.safetywatcher.watcher.wifi.info.action.WiFiScanAction;
|
||||
import com.yinuo.safetywatcher.watcher.wifi.type.Types;
|
||||
|
||||
public interface WiFiSupportListener {
|
||||
|
||||
/**
|
||||
* 获取当前执行的action
|
||||
*/
|
||||
@Nullable
|
||||
IWiFiAction getCurrentAction();
|
||||
|
||||
/**
|
||||
* 获取当前了解的WiFi信息
|
||||
*/
|
||||
WifiInfo getConnectedWifiInfo();
|
||||
|
||||
void onWiFiClose();
|
||||
|
||||
void onWiFiListChange();
|
||||
|
||||
void doneScanAction(@NonNull WiFiScanAction action);
|
||||
|
||||
void doneConnectSuccess(@NonNull String SSID, @Types.ConnectSuccessType int type);
|
||||
|
||||
void doneConnectFail(@NonNull WiFiConnectAction action);
|
||||
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
package com.yinuo.safetywatcher.watcher.wifi.interfaces.impl;
|
||||
|
||||
import android.net.wifi.WifiConfiguration;
|
||||
|
||||
import com.yinuo.safetywatcher.watcher.wifi.info.WiFiRemoveStatusInfo;
|
||||
import com.yinuo.safetywatcher.watcher.wifi.info.WiFiScanInfo;
|
||||
import com.yinuo.safetywatcher.watcher.wifi.interfaces.WiFiListener;
|
||||
import com.yinuo.safetywatcher.watcher.wifi.type.WiFiConnectFailType;
|
||||
import com.yinuo.safetywatcher.watcher.wifi.type.WiFiGetListType;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class WiFiListenerImpl implements WiFiListener {
|
||||
|
||||
@Override
|
||||
public void onStartScan() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCloseWiFi() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDataChange(WiFiGetListType type, List<WiFiScanInfo> list) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWiFiStartConnect(String SSID) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWiFiCreateConfig(String SSID, WifiConfiguration configuration) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWiFiConnected(String SSID, boolean isInit) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWiFiConnectFail(String SSID, WiFiConnectFailType type) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWiFiRemoveResult(WiFiRemoveStatusInfo info) {
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
package com.yinuo.safetywatcher.watcher.wifi.receiver;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.yinuo.safetywatcher.watcher.wifi.interfaces.WiFiStatusListener;
|
||||
|
||||
/**
|
||||
* WiFi状态接受
|
||||
*/
|
||||
public class WiFiStatusReceiver extends BroadcastReceiver {
|
||||
|
||||
private WiFiStatusListener mCallback;
|
||||
|
||||
public WiFiStatusReceiver(WiFiStatusListener callback) {
|
||||
this.mCallback = callback;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
String action = intent.getAction();
|
||||
|
||||
if (null == mCallback || null == action || TextUtils.isEmpty(action)) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (action) {
|
||||
case WifiManager.SCAN_RESULTS_AVAILABLE_ACTION:
|
||||
mCallback.handleScanResultsChanged(intent);
|
||||
break;
|
||||
|
||||
case WifiManager.WIFI_STATE_CHANGED_ACTION:
|
||||
mCallback.handleWiFiStateChanged(intent);
|
||||
break;
|
||||
|
||||
case WifiManager.NETWORK_STATE_CHANGED_ACTION:
|
||||
mCallback.handleNetStateChanged(intent);
|
||||
break;
|
||||
|
||||
case WifiManager.SUPPLICANT_STATE_CHANGED_ACTION:
|
||||
mCallback.handleSupplicantStateChanged(intent);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,77 @@
|
||||
package com.yinuo.safetywatcher.watcher.wifi.type;
|
||||
|
||||
import androidx.annotation.IntDef;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
public class Types {
|
||||
|
||||
@IntDef({
|
||||
ScanResultType.UNKNOWN,
|
||||
ScanResultType.FREQUENTLY_SCAN_ERROR,
|
||||
ScanResultType.OPEN_WIFI_ERROR,
|
||||
ScanResultType.SUCCESS,
|
||||
})
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
public @interface ScanResultType {
|
||||
int UNKNOWN = -1;//未知错误
|
||||
int FREQUENTLY_SCAN_ERROR = 0;//频繁扫描
|
||||
int OPEN_WIFI_ERROR = 1;//开启WiFi失败
|
||||
int SUCCESS = 2;//扫描成功
|
||||
}
|
||||
|
||||
@IntDef({
|
||||
RemoveResultType.SYSTEM_LIMIT_ERROR,
|
||||
RemoveResultType.SUCCESS,
|
||||
})
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
public @interface RemoveResultType {
|
||||
int SYSTEM_LIMIT_ERROR = 0;//系统限制,删除失败
|
||||
int SUCCESS = 1;//删除成功
|
||||
}
|
||||
|
||||
@IntDef({
|
||||
ConnectResultType.UNKNOWN,
|
||||
ConnectResultType.SYSTEM_LIMIT_ERROR,
|
||||
ConnectResultType.TIMEOUT_ERROR,
|
||||
ConnectResultType.PASSWORD_ERROR,
|
||||
ConnectResultType.DIRECT_PASSWORD_ERROR,
|
||||
ConnectResultType.SUCCESS,
|
||||
})
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
public @interface ConnectResultType {
|
||||
int UNKNOWN = -1;//未知错误
|
||||
int SYSTEM_LIMIT_ERROR = 0;//系统限制,删除失败
|
||||
int TIMEOUT_ERROR = 1;//连接超时
|
||||
int PASSWORD_ERROR = 2;//密码错误
|
||||
int DIRECT_PASSWORD_ERROR = 3;//直连密码错误
|
||||
int SUCCESS = 5;//连接成功
|
||||
}
|
||||
|
||||
@IntDef({
|
||||
ActionStateType.WAITING,
|
||||
ActionStateType.PROCESS,
|
||||
ActionStateType.END,
|
||||
})
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
public @interface ActionStateType {
|
||||
int WAITING = 0;//待执行
|
||||
int PROCESS = 1;//执行中
|
||||
int END = 2;//执行完成
|
||||
}
|
||||
|
||||
|
||||
@IntDef({
|
||||
ConnectSuccessType.NOT_MATCH,
|
||||
ConnectSuccessType.NORMAL,
|
||||
ConnectSuccessType.SYSTEM,
|
||||
})
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
public @interface ConnectSuccessType {
|
||||
int NOT_MATCH = 1;//不匹配
|
||||
int NORMAL = 2;//正常处理
|
||||
int SYSTEM = 3;//没有执行操作时连接成功
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package com.yinuo.safetywatcher.watcher.wifi.type;
|
||||
|
||||
/**
|
||||
* WiFi加密方式
|
||||
*/
|
||||
public enum WiFiCipherType {
|
||||
|
||||
WIFI_CIPHER_WEP,
|
||||
WIFI_CIPHER_WPA,//默认都是这种
|
||||
WIFI_CIPHER_NO_PASS,
|
||||
WIFI_CIPHER_INVALID
|
||||
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
package com.yinuo.safetywatcher.watcher.wifi.type;
|
||||
|
||||
public enum WiFiConnectFailType {
|
||||
|
||||
PASSWORD_ERROR,//密码错误
|
||||
DIRECT_PASSWORD_ERROR,//直接连接,密码错误
|
||||
TIMEOUT_ERROR,//连接超时
|
||||
SYSTEM_LIMIT_ERROR,//系统限制
|
||||
UNKNOWN,//未知
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
package com.yinuo.safetywatcher.watcher.wifi.type;
|
||||
|
||||
/**
|
||||
* WiFi连接状态
|
||||
*/
|
||||
public enum WiFiConnectType {
|
||||
|
||||
DISCONNECTED(0, "未连接"),
|
||||
CONNECTING(1, "连接中"),
|
||||
CONNECTED(2, "已连接");
|
||||
|
||||
public int type;
|
||||
public String state;
|
||||
|
||||
WiFiConnectType(int type, String state) {
|
||||
this.type = type;
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
package com.yinuo.safetywatcher.watcher.wifi.type;
|
||||
|
||||
/**
|
||||
* 获取列表的类型
|
||||
*/
|
||||
public enum WiFiGetListType {
|
||||
|
||||
TYPE_SCAN,//扫描
|
||||
TYPE_SORT//排序
|
||||
|
||||
}
|
@ -0,0 +1,123 @@
|
||||
package com.yinuo.safetywatcher.watcher.wifi.ui
|
||||
|
||||
import android.graphics.Color
|
||||
import android.graphics.drawable.ColorDrawable
|
||||
import android.os.Bundle
|
||||
import android.text.TextUtils
|
||||
import android.view.Gravity
|
||||
import android.view.KeyEvent
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.view.Window
|
||||
import android.view.WindowManager
|
||||
import androidx.fragment.app.DialogFragment
|
||||
import com.yinuo.safetywatcher.databinding.DialogInputWifiPasswordBinding
|
||||
import com.yinuo.safetywatcher.watcher.utils.hideIme
|
||||
import com.yinuo.safetywatcher.watcher.utils.showIme
|
||||
import com.yinuo.safetywatcher.watcher.wifi.WiFiModule
|
||||
import com.yinuo.safetywatcher.watcher.wifi.info.WiFiScanInfo
|
||||
import com.yinuo.safetywatcher.watcher.wifi.interfaces.ConnectWiFiActionListener
|
||||
|
||||
/**
|
||||
* wifi密码输入框
|
||||
*/
|
||||
class InputWiFiPasswordDialog : DialogFragment() {
|
||||
private var mInfo: WiFiScanInfo? = null
|
||||
private var mConnectType = 0
|
||||
|
||||
private var mBinding: DialogInputWifiPasswordBinding? = null
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View? {
|
||||
dialog?.requestWindowFeature(Window.FEATURE_NO_TITLE)
|
||||
mBinding = DialogInputWifiPasswordBinding.inflate(inflater, container, false)
|
||||
return mBinding!!.root
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
val bundle = arguments
|
||||
if (null != bundle) {
|
||||
mInfo = bundle.getParcelable("info")
|
||||
mConnectType = bundle.getInt("connectType", 0)
|
||||
}
|
||||
if (null == mInfo) {
|
||||
dismissAllowingStateLoss()
|
||||
return
|
||||
}
|
||||
if (mConnectType == 1) {
|
||||
mBinding?.tvTitle?.text = "修改" + mInfo!!.scanResult.SSID
|
||||
} else {
|
||||
mBinding?.tvTitle?.text = mInfo!!.scanResult.SSID
|
||||
}
|
||||
setListener()
|
||||
}
|
||||
|
||||
private fun setListener() {
|
||||
mBinding?.etPassword?.setOnKeyListener { _, keyCode, event ->
|
||||
if (keyCode == KeyEvent.KEYCODE_DPAD_DOWN) {
|
||||
if (event.action == KeyEvent.ACTION_DOWN) {
|
||||
mBinding?.tvCancel?.requestFocus()
|
||||
}
|
||||
return@setOnKeyListener true
|
||||
} else if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER || keyCode == KeyEvent.KEYCODE_ENTER) {
|
||||
if (event.action == KeyEvent.ACTION_DOWN) {
|
||||
mBinding?.etPassword?.showIme()
|
||||
}
|
||||
return@setOnKeyListener true
|
||||
}
|
||||
return@setOnKeyListener false
|
||||
}
|
||||
mBinding?.etPassword?.setOnFocusChangeListener { v, hasFocus ->
|
||||
if (!hasFocus) {
|
||||
mBinding?.etPassword?.hideIme()
|
||||
} else {
|
||||
mBinding?.etPassword?.showIme()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
mBinding?.tvCancel?.setOnClickListener {
|
||||
dismissAllowingStateLoss()
|
||||
}
|
||||
|
||||
mBinding?.tvConnect?.setOnClickListener {
|
||||
val trimPass = mBinding?.etPassword?.text.toString().trim { it <= ' ' }
|
||||
//连接
|
||||
if (TextUtils.isEmpty(trimPass)) {
|
||||
return@setOnClickListener
|
||||
}
|
||||
WiFiModule.getInstance().connectWiFi(
|
||||
mInfo!!.scanResult.SSID,
|
||||
mInfo!!.cipherType,
|
||||
trimPass,
|
||||
mConnectActionListener
|
||||
)
|
||||
dismissAllowingStateLoss()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onStart() {
|
||||
super.onStart()
|
||||
val dialog = dialog
|
||||
dialog?.setCanceledOnTouchOutside(true)
|
||||
val window = dialog?.window
|
||||
if (null != window) {
|
||||
window.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
|
||||
val lp = window.attributes
|
||||
lp.gravity = Gravity.CENTER
|
||||
lp.width = 480
|
||||
lp.height = WindowManager.LayoutParams.WRAP_CONTENT
|
||||
window.attributes = lp
|
||||
}
|
||||
}
|
||||
|
||||
private var mConnectActionListener: ConnectWiFiActionListener? = null
|
||||
fun setConnectListener(actionListener: ConnectWiFiActionListener?) {
|
||||
mConnectActionListener = actionListener
|
||||
}
|
||||
}
|
@ -0,0 +1,84 @@
|
||||
package com.yinuo.safetywatcher.watcher.wifi.ui
|
||||
|
||||
import android.graphics.Color
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import com.yinuo.safetywatcher.R
|
||||
import com.yinuo.safetywatcher.databinding.ItemNetworkConfigBinding
|
||||
import com.yinuo.safetywatcher.watcher.base.BaseRvAdapter
|
||||
import com.yinuo.safetywatcher.watcher.wifi.info.WiFiScanInfo
|
||||
import com.yinuo.safetywatcher.watcher.wifi.type.WiFiCipherType
|
||||
import com.yinuo.safetywatcher.watcher.wifi.type.WiFiConnectType
|
||||
|
||||
class WiFIAdapter(
|
||||
private val onItemClick: ((WiFiScanInfo) -> Unit)? = null,
|
||||
private val onItemLongClick: ((WiFiScanInfo) -> Unit)? = null
|
||||
) :
|
||||
BaseRvAdapter<WiFiScanInfo, ItemNetworkConfigBinding, WiFIAdapter.WiFiViewHolder>() {
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): WiFiViewHolder {
|
||||
return WiFiViewHolder(
|
||||
ItemNetworkConfigBinding.inflate(
|
||||
LayoutInflater.from(parent.context),
|
||||
parent,
|
||||
false
|
||||
), onItemClick, onItemLongClick
|
||||
);
|
||||
}
|
||||
|
||||
class WiFiViewHolder(
|
||||
private val binding: ItemNetworkConfigBinding,
|
||||
private val onItemClick: ((WiFiScanInfo) -> Unit)?,
|
||||
private val onItemLongClick: ((WiFiScanInfo) -> Unit)?
|
||||
) :
|
||||
BaseViewHolder<WiFiScanInfo, ItemNetworkConfigBinding>(binding) {
|
||||
|
||||
override fun bindView(info: WiFiScanInfo) {
|
||||
val context = binding.root.context
|
||||
binding.root.setOnClickListener {
|
||||
onItemClick?.invoke(info)
|
||||
}
|
||||
binding.root.setOnLongClickListener {
|
||||
onItemLongClick?.invoke(info)
|
||||
return@setOnLongClickListener true
|
||||
}
|
||||
|
||||
if (null != info.configuration) {
|
||||
if (info.connectType == WiFiConnectType.CONNECTED.type) {
|
||||
binding.tvNetName.text = info.scanResult.SSID
|
||||
} else {
|
||||
binding.tvNetName.text = info.scanResult.SSID + "(已保存)"
|
||||
}
|
||||
} else {
|
||||
binding.tvNetName.text = info.scanResult.SSID
|
||||
}
|
||||
|
||||
val noPass = WiFiCipherType.WIFI_CIPHER_NO_PASS == info.cipherType
|
||||
if (noPass) {
|
||||
binding.ivStatusLock.visibility = View.GONE
|
||||
} else {
|
||||
binding.ivStatusLock.visibility = View.VISIBLE
|
||||
}
|
||||
binding.ivStatusLock.setColorFilter(Color.WHITE)
|
||||
|
||||
if (info.connectType == WiFiConnectType.CONNECTED.type) {
|
||||
binding.ivStatusConnect.visibility = View.VISIBLE
|
||||
binding.progressBar.visibility = View.GONE
|
||||
} else if (info.connectType == WiFiConnectType.CONNECTING.type) {
|
||||
//连接中
|
||||
binding.ivStatusConnect.visibility = View.GONE
|
||||
binding.progressBar.visibility = View.VISIBLE
|
||||
} else {
|
||||
binding.ivStatusConnect.visibility = View.GONE
|
||||
binding.progressBar.visibility = View.GONE
|
||||
}
|
||||
|
||||
when (info.level) {
|
||||
1 -> binding.ivStatusWifi.setImageResource(R.drawable.wifi_1)
|
||||
2 -> binding.ivStatusWifi.setImageResource(R.drawable.wifi_2)
|
||||
else -> binding.ivStatusWifi.setImageResource(R.drawable.wifi_3)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
package com.yinuo.safetywatcher.watcher.wifi.utils;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
public final class WiFiLogUtils {
|
||||
|
||||
private static final String TAG = "WiFiTool-log";
|
||||
|
||||
private static int log_level = 0;
|
||||
|
||||
/**
|
||||
* 设置日志级别
|
||||
*
|
||||
* @param level 级别
|
||||
*/
|
||||
public static void setLogLevel(int level) {
|
||||
log_level = level;
|
||||
}
|
||||
|
||||
public static void d(String msg) {
|
||||
if (log_level < 2) {
|
||||
Log.d(TAG, msg);
|
||||
}
|
||||
}
|
||||
|
||||
public static void e(Throwable throwable) {
|
||||
if (log_level < 7) {
|
||||
Log.e(TAG, "", throwable);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 471 B |
Binary file not shown.
After Width: | Height: | Size: 685 B |
Binary file not shown.
After Width: | Height: | Size: 502 B |
@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="rectangle">
|
||||
|
||||
<solid android:color="@color/colorTxt" />
|
||||
|
||||
<size android:width="2dp" />
|
||||
|
||||
</shape>
|
@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="rectangle">
|
||||
|
||||
<solid android:color="#F4F4F4" />
|
||||
|
||||
<corners android:radius="8dp" />
|
||||
|
||||
</shape>
|
@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item>
|
||||
<rotate
|
||||
android:drawable="@drawable/ic_progress"
|
||||
android:fromDegrees="0.0"
|
||||
android:pivotX="50.0%"
|
||||
android:pivotY="50.0%"
|
||||
android:toDegrees="360.0" />
|
||||
</item>
|
||||
</layer-list>
|
@ -0,0 +1,42 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/area_switch"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:focusable="true"
|
||||
android:gravity="center_vertical"
|
||||
android:paddingStart="@dimen/_61dp"
|
||||
android:paddingEnd="@dimen/_61dp">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_status"
|
||||
android:layout_width="0dp"
|
||||
android:layout_weight="1"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginVertical="20dp"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="@dimen/_36dp" />
|
||||
|
||||
<Switch
|
||||
android:id="@+id/wifi_switch"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="10dp"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/rv_data"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/wifi_switch" />
|
||||
|
||||
</LinearLayout>
|
@ -0,0 +1,86 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="@dimen/_480dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@drawable/warn_setting_btn_bg">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_title"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="10dp"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="@dimen/_38dp"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
tools:text="BLACK-1" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_password"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="10dp"
|
||||
android:text="密码"
|
||||
android:textColor="@color/colorTxtGray"
|
||||
android:textSize="@dimen/_23dp"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/tv_title" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/et_password"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="@dimen/_68dp"
|
||||
android:layout_margin="12dp"
|
||||
android:background="@drawable/bg_input"
|
||||
android:inputType="textPassword"
|
||||
android:paddingLeft="16dp"
|
||||
android:paddingRight="16dp"
|
||||
android:textCursorDrawable="@drawable/bg_cursor"
|
||||
android:textSize="@dimen/font_24dp"
|
||||
android:focusable="true"
|
||||
android:focusedByDefault="true"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/tv_password" />
|
||||
|
||||
<androidx.constraintlayout.widget.Guideline
|
||||
android:id="@+id/guideline"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
app:layout_constraintGuide_percent="0.5" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_cancel"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="@dimen/_81dp"
|
||||
android:background="@drawable/cancel_btn_bg"
|
||||
android:layout_marginTop="@dimen/_12dp"
|
||||
android:focusable="true"
|
||||
android:gravity="center"
|
||||
android:text="@string/cancel"
|
||||
android:textColor="@color/white_30"
|
||||
android:textSize="@dimen/_36dp"
|
||||
android:nextFocusRight="@id/tv_connect"
|
||||
app:layout_constraintEnd_toEndOf="@+id/guideline"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/et_password" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_connect"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="@dimen/_81dp"
|
||||
android:background="@drawable/confirm_btn_bg_red"
|
||||
android:focusable="true"
|
||||
android:gravity="center"
|
||||
android:text="@string/confirm"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="@dimen/_36dp"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="@+id/guideline"
|
||||
app:layout_constraintTop_toTopOf="@+id/tv_cancel" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
@ -0,0 +1,55 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/_108dp"
|
||||
android:paddingStart="@dimen/_121dp"
|
||||
android:paddingEnd="@dimen/_61dp"
|
||||
android:focusable="true"
|
||||
android:gravity="center_vertical">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/iv_status_connect"
|
||||
android:layout_width="@dimen/_32dp"
|
||||
android:layout_height="@dimen/_32dp"
|
||||
android:src="@drawable/ic_select_s"
|
||||
android:visibility="gone"
|
||||
tools:visibility="visible" />
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/progress_bar"
|
||||
android:layout_width="@dimen/_32dp"
|
||||
android:layout_height="@dimen/_32dp"
|
||||
android:indeterminate="false"
|
||||
android:indeterminateDrawable="@drawable/loading_img"
|
||||
android:visibility="gone"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_net_name"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:layout_marginLeft="@dimen/_12dp"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="@dimen/_36dp"
|
||||
tools:text="BLACK1" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/iv_status_wifi"
|
||||
android:layout_width="@dimen/_32dp"
|
||||
android:layout_height="@dimen/_32dp"
|
||||
android:layout_marginLeft="@dimen/_12dp"
|
||||
app:tint="@color/white"
|
||||
android:src="@drawable/wifi_3" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/iv_status_lock"
|
||||
android:layout_width="@dimen/_32dp"
|
||||
android:layout_height="@dimen/_32dp"
|
||||
android:layout_marginLeft="@dimen/_12dp"
|
||||
app:tint="@color/white"
|
||||
android:src="@drawable/ic_password" />
|
||||
|
||||
</LinearLayout>
|
Loading…
Reference in New Issue