iFish7/iFish7/src/main/java/com/ifish/activity/HotSpotConnentSetWIFIActivi...

124 lines
4.9 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package com.ifish.activity;
import android.app.Activity;
import android.content.Intent;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.provider.Settings;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.Nullable;
import com.bumptech.glide.Glide;
import com.ifish.basebean.ConnectMessageEvent;
import com.ifish.baseclass.BaseActivity;
import com.ifish.utils.AnimationUtil;
import com.ifish.utils.ToastUtil;
import de.greenrobot.event.EventBus;
public class HotSpotConnentSetWIFIActivity extends BaseActivity {
private Activity act;
ImageView iv_wifiset;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EventBus.getDefault().register(this);
act = this;
setContentView(R.layout.activity_hotconnect_setwifi);
initTitle("选择设备WI-FI");
iv_wifiset = findMyViewById(R.id.iv_wifiset);
findViewById(R.id.bt_setconnect).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// device_mac="5ccf7f99e929";
// doPostBindDevice();
isjump = true;
Intent i = new Intent();
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i = new Intent(Settings.ACTION_WIFI_SETTINGS);
startActivity(i);
}
});
TextView tv_two = findMyViewById(R.id.tv_two);
TextView tv_one = findMyViewById(R.id.tv_one);
String devicetype = getIntent().getStringExtra("devicetype");
if ("camera".equals(devicetype)) {
tv_one.setText("1.请长按摄像头背后复位孔,复位摄像头,进入热点模式。");
tv_two.setText("2.点击去设置:设置-WIFI-选择GW_AP_xxxx的网络连接好后返回爱鱼奇APP。");
Glide.with(this).load(R.drawable.hotsonnectimg2).into(iv_wifiset);
} else {
Glide.with(this).load(R.drawable.hotsonnectimg).into(iv_wifiset);
}
}
private boolean isjump = false;
@Override
protected void onResume() {
super.onResume();
if (isjump) {
WifiManager wifiManager = (WifiManager)getApplicationContext().getSystemService(WIFI_SERVICE);
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
if (!wifiManager.isWifiEnabled()) {
ToastUtil.show(getApplicationContext(), "请检查WiFi是否开启");
return;
}
String wifissid = wifiInfo.getSSID();
wifissid = wifissid.replaceAll("\"", "");
if (TextUtils.isEmpty(wifissid)) {
ToastUtil.show(getApplicationContext(), "您没有连接WiFi");
return;
}
Intent intent = new Intent();
String devicetype = getIntent().getStringExtra("devicetype");
if ("camera".equals(devicetype)) {
if (!wifissid.startsWith("GW_AP_")) {
ToastUtil.show(getApplicationContext(), "请先连接摄像头设备热点");
return;
}
intent.setClass(HotSpotConnentSetWIFIActivity.this, HotSpotConnentDeviceCameraActivity.class);
} else if ("pet".equals(devicetype)) {
if (!wifissid.startsWith("ifish-")) {
ToastUtil.show(getApplicationContext(), "请先连接宠物笼设备热点");
return;
}
intent.setClass(HotSpotConnentSetWIFIActivity.this, HotSpotConnentPetDeviceActivity.class);
} else {
if (!wifissid.startsWith("ifish-")) {
ToastUtil.show(getApplicationContext(), "请先连接设备热点");
return;
}
intent.setClass(HotSpotConnentSetWIFIActivity.this, HotSpotConnentDeviceActivity.class);
}
String wifiname = getIntent().getStringExtra("wifiname");
String wifipwd = getIntent().getStringExtra("wifipwd");
if (wifissid.equals(wifiname)) {
ToastUtil.show(getApplicationContext(), "WiFi名称不能和热点名称一致");
return;
}
intent.putExtra("wifiname", (!TextUtils.isEmpty(wifiname)?wifiname:""));
intent.putExtra("wifipwd", (!TextUtils.isEmpty(wifipwd)?wifipwd:""));
intent.putExtra("wifihotid", wifissid);
startActivity(intent);
AnimationUtil.startAnimation(act);
isjump = false;
}
}
@Override
protected void onDestroy() {
super.onDestroy();
EventBus.getDefault().unregister(this);
}
public void onEventMainThread(ConnectMessageEvent event) {
finish();
}
}