LANSearchCameraActivity.java 源代码


package activity.addCamera;

import activity.addCamera.adapter.SearchResultListAdapter;
import android.content.Intent;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.os.Handler;
import android.os.Message;
import android.text.TextUtils;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.LayoutAnimationController;
import android.widget.AdapterView;
import android.widget.LinearLayout;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.ProgressBar;
import android.widget.TextView;
import base.HiActivity;
import bean.MyCamera;
import com.bytedance.android.live.base.api.push.model.PushUIConfig;
import com.bytedance.sdk.openadsdk.TTAdConstant;
import com.hichip.campro.R;
import com.hichip.tools.HiLitosSDK;
import com.hichip.tools.HiSearchSDK;
import com.xiaomi.mipush.sdk.Constants;
import common.Constant;
import common.HiDataValue;
import common.TitleView;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import liteos.addCamera.OSAddAndConfigWiFiActivity;
import org.json.JSONException;
import org.json.JSONObject;
import utils.HiLogcatUtil;
import utils.HiTools;
import utils.MyToast;
import utils.WifiUtils;

public class LANSearchCameraActivity extends HiActivity {
    private static final int MY_PERMISSION_REQUEST_CODE = 10010;
    private static final int isCheckData = 0;
    private Animation AnimlvItem;
    private SearchResultListAdapter adapter;
    private int category;
    private LinearLayout layFailSearch;
    private View listFootView;
    private ListView listSearchResult;
    private String mCurrentPhoneWiFi;
    private String mUid;
    ProgressBar progressbar;
    private HiSearchSDK searchSDK;
    private CountDownTimer timer;
    TitleView titleview;
    TextView tv_device;
    private long oldClickTime = 0;
    private List<HiSearchSDK.HiSearchResult> list = new ArrayList();
    private int type = 0;
    private boolean isApMode = false;
    private HiLitosSDK hiLitosSDK = null;
    private Handler handler = new Handler() {
        @Override
        public void handleMessage(Message message) {
            boolean z;
            switch (message.what) {
                case HiDataValue.HANDLE_MESSAGE_SCAN_RESULT:
                    if (LANSearchCameraActivity.this.progressbar.getVisibility() == 0) {
                        LANSearchCameraActivity.this.progressbar.setVisibility(8);
                    }
                    LANSearchCameraActivity.this.listviewAddFoot();
                    HiSearchSDK.HiSearchResult hiSearchResult = (HiSearchSDK.HiSearchResult) message.obj;
                    if (LANSearchCameraActivity.this.adapter != null) {
                        int i = 0;
                        while (true) {
                            if (i >= LANSearchCameraActivity.this.list.size()) {
                                z = false;
                            } else if (((HiSearchSDK.HiSearchResult) LANSearchCameraActivity.this.list.get(i)).uid.equalsIgnoreCase(hiSearchResult.uid)) {
                                z = true;
                            } else {
                                i++;
                            }
                        }
                        if (!z) {
                            LANSearchCameraActivity.this.list.add(hiSearchResult);
                            LANSearchCameraActivity.this.listSearchResult.requestLayout();
                            LANSearchCameraActivity.this.adapter.notifyDataSetChanged();
                        }
                    }
                    LANSearchCameraActivity.this.tv_device.setVisibility(0);
                    if (LANSearchCameraActivity.this.list == null || LANSearchCameraActivity.this.list.size() <= 0 || LANSearchCameraActivity.this.layFailSearch.getVisibility() != 0) {
                        return;
                    }
                    LANSearchCameraActivity.this.layFailSearch.setVisibility(8);
                    return;
                case HiDataValue.HANDLE_MESSAGE_SCAN_CHECK:
                    if (message.arg1 == 0) {
                        if (LANSearchCameraActivity.this.list == null || LANSearchCameraActivity.this.list.size() == 0) {
                            LANSearchCameraActivity.this.searchSDK.stop();
                            LANSearchCameraActivity.this.layFailSearch.setVisibility(0);
                            return;
                        }
                        return;
                    }
                    return;
                default:
                    return;
            }
        }
    };

    @Override
    protected int setLayoutId() {
        return R.layout.activity_lan_search_camera;
    }

    @Override
    protected void init(Bundle bundle) {
        getWindow().setSoftInputMode(3);
        getIntentData();
        initView();
    }

    private void getIntentData() {
        this.mCurrentPhoneWiFi = getIntent().getStringExtra("mCurrentPhoneWiFi");
        this.type = getIntent().getIntExtra("type", 0);
        this.mUid = getIntent().getStringExtra(HiDataValue.EXTRAS_KEY_UID);
        this.category = getIntent().getIntExtra("category", 0);
        if (TextUtils.isEmpty(this.mCurrentPhoneWiFi)) {
            this.mCurrentPhoneWiFi = WifiUtils.getCurrentWifiSSID(this, true);
        }
    }

    @Override
    public void onResume() {
        super.onResume();
        startSearch();
        if (this.type != 101) {
            Hi_osSearch();
        }
    }

    private void initView() {
        initTopView();
        this.layFailSearch = (LinearLayout) findViewById(R.id.lay_fail_lan_search);
        this.listSearchResult = (ListView) findViewById(R.id.list_search_result);
        SearchResultListAdapter searchResultListAdapter = new SearchResultListAdapter(this, this.list);
        this.adapter = searchResultListAdapter;
        this.listSearchResult.setAdapter((ListAdapter) searchResultListAdapter);
        this.listSearchResult.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long j) {
                if (!HiTools.isCustomFastClick(TTAdConstant.STYLE_SIZE_RADIO_2_3) && i < LANSearchCameraActivity.this.list.size()) {
                    HiSearchSDK.HiSearchResult hiSearchResult = (HiSearchSDK.HiSearchResult) LANSearchCameraActivity.this.list.get(i);
                    Iterator<MyCamera> it = HiDataValue.CameraList.iterator();
                    while (it.hasNext()) {
                        if (hiSearchResult.uid.equalsIgnoreCase(it.next().getUid())) {
                            LANSearchCameraActivity lANSearchCameraActivity = LANSearchCameraActivity.this;
                            MyToast.showToast(lANSearchCameraActivity, lANSearchCameraActivity.getString(R.string.tip_device_add));
                            return;
                        }
                    }
                    Bundle bundle = new Bundle();
                    bundle.putString(HiDataValue.EXTRAS_KEY_UID, hiSearchResult.uid);
                    Intent intent = new Intent();
                    intent.putExtras(bundle);
                    if (LANSearchCameraActivity.this.type == 3) {
                        intent.putExtra("type", LANSearchCameraActivity.this.type);
                        intent.putExtra("isApMode", LANSearchCameraActivity.this.isApMode);
                        LANSearchCameraActivity.this.setResult(-1, intent);
                        LANSearchCameraActivity.this.finish();
                        return;
                    }
                    if (LANSearchCameraActivity.this.type != 4) {
                        if (LANSearchCameraActivity.this.type != 101) {
                            if (LANSearchCameraActivity.this.isApMode) {
                                intent.setClass(LANSearchCameraActivity.this, OSAddAndConfigWiFiActivity.class);
                                intent.putExtra("type", 2);
                                intent.putExtra("ssid", "");
                                intent.putExtra("mCurrentPhoneWiFi", LANSearchCameraActivity.this.mCurrentPhoneWiFi);
                                intent.putExtra("isAP", true);
                                intent.putExtra(Constant.MODE, "2");
                                LANSearchCameraActivity.this.startActivity(intent);
                                return;
                            }
                            intent.setClass(LANSearchCameraActivity.this, AddAndConfigWiFiActivity.class);
                            intent.putExtra("type", 2);
                            LANSearchCameraActivity.this.startActivity(intent);
                            return;
                        }
                        intent.setClass(LANSearchCameraActivity.this, AddCameraActivity.class);
                        intent.putExtra("type", 101);
                        intent.putExtra(HiDataValue.EXTRAS_KEY_UID, hiSearchResult.uid);
                        LANSearchCameraActivity.this.startActivity(intent);
                        LANSearchCameraActivity.this.finish();
                        return;
                    }
                    intent.setClass(LANSearchCameraActivity.this, AddCameraActivity.class);
                    intent.putExtra("isApMode", LANSearchCameraActivity.this.isApMode);
                    intent.putExtra("type", LANSearchCameraActivity.this.type);
                    LANSearchCameraActivity.this.startActivity(intent);
                }
            }
        });
    }

    public void listviewAddFoot() {
        ListView listView = this.listSearchResult;
        if (listView == null || listView.getFooterViewsCount() != 0) {
            return;
        }
        View inflate = View.inflate(this, R.layout.listview_lansearch_footer, null);
        this.listFootView = inflate;
        TextView textView = (TextView) inflate.findViewById(R.id.lv__tv_unsearch_device);
        textView.getPaint().setFlags(8);
        textView.getPaint().setAntiAlias(true);
        Animation loadAnimation = AnimationUtils.loadAnimation(this, R.anim.list_anim);
        loadAnimation.setDuration(666L);
        this.listFootView.startAnimation(loadAnimation);
        this.listSearchResult.addFooterView(this.listFootView);
        textView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (LANSearchCameraActivity.this.type == 4) {
                    LANSearchCameraActivity.this.handSoundWavesHint();
                } else {
                    LANSearchCameraActivity.this.handConmmonHint();
                }
            }
        });
    }

    public void handSoundWavesHint() {
        View inflate;
        if (this.category == 2) {
            inflate = View.inflate(this, R.layout.pup_sound_waves_fail_cate2, null);
        } else {
            inflate = View.inflate(this, R.layout.pup_sound_waves_fail, null);
        }
        final PopupWindow popupWindow = new PopupWindow(inflate);
        popupWindow.setBackgroundDrawable(new ColorDrawable(0));
        popupWindow.setWidth(-1);
        popupWindow.setHeight(-1);
        popupWindow.showAtLocation(inflate, 17, 0, 0);
        ((TextView) inflate.findViewById(R.id.tv_know)).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                popupWindow.dismiss();
            }
        });
        ((TextView) inflate.findViewById(R.id.tv_try)).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                popupWindow.dismiss();
                Intent intent = new Intent(LANSearchCameraActivity.this, (Class<?>) SeleApOrSoundwaveActivty.class);
                intent.putExtra("mCurrentPhoneWiFi", LANSearchCameraActivity.this.mCurrentPhoneWiFi);
                LANSearchCameraActivity.this.startActivity(intent);
            }
        });
    }

    public void handConmmonHint() {
        View inflate;
        if (this.type == 3) {
            inflate = View.inflate(this, R.layout.pup_not_search_dev_3, null);
        } else {
            inflate = View.inflate(this, R.layout.pup_not_search_dev, null);
        }
        final PopupWindow popupWindow = new PopupWindow(inflate);
        popupWindow.setBackgroundDrawable(new ColorDrawable(0));
        popupWindow.setWidth(-1);
        popupWindow.setHeight(-1);
        popupWindow.showAtLocation(inflate, 17, 0, 0);
        ((TextView) inflate.findViewById(R.id.tv_know)).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                popupWindow.dismiss();
            }
        });
    }

    private void initTopView() {
        this.titleview.setButton(0);
        this.titleview.setButton(1);
        this.titleview.setRightTxt(getString(R.string.searching));
        this.titleview.setTitle(getString(R.string.device_list));
        this.titleview.setNavigationBarButtonListener(new TitleView.NavigationBarButtonListener() {
            @Override
            public void OnNavigationButtonClick(int i) {
                if (i == 0) {
                    LANSearchCameraActivity.this.finish();
                    return;
                }
                if (i == 1 && System.currentTimeMillis() - LANSearchCameraActivity.this.oldClickTime >= PushUIConfig.dismissTime) {
                    LANSearchCameraActivity.this.titleview.setRightTxt(LANSearchCameraActivity.this.getString(R.string.searching));
                    LANSearchCameraActivity.this.startSearch();
                    if (LANSearchCameraActivity.this.type != 101) {
                        LANSearchCameraActivity.this.Hi_osSearch();
                    }
                    LANSearchCameraActivity.this.oldClickTime = System.currentTimeMillis();
                }
            }
        });
    }

    public void startSearch() {
        View view;
        this.titleview.setRightTxt(getString(R.string.searching));
        if (this.progressbar.getVisibility() == 8) {
            this.progressbar.setVisibility(0);
        }
        CountDownTimer countDownTimer = this.timer;
        if (countDownTimer != null) {
            countDownTimer.cancel();
            this.timer = null;
        }
        if (this.adapter != null) {
            this.list.clear();
            this.listSearchResult.requestLayout();
            if (this.listSearchResult.getFooterViewsCount() != 0 && (view = this.listFootView) != null) {
                this.listSearchResult.removeFooterView(view);
            }
            this.adapter.notifyDataSetChanged();
        }
        HiSearchSDK hiSearchSDK = new HiSearchSDK(new HiSearchSDK.ISearchResult() {
            @Override
            public void onReceiveSearchResult(HiSearchSDK.HiSearchResult hiSearchResult) {
                if (TextUtils.isEmpty(hiSearchResult.uid.substring(0, 4))) {
                    return;
                }
                Message obtainMessage = LANSearchCameraActivity.this.handler.obtainMessage();
                obtainMessage.obj = hiSearchResult;
                obtainMessage.what = HiDataValue.HANDLE_MESSAGE_SCAN_RESULT;
                LANSearchCameraActivity.this.handler.sendMessage(obtainMessage);
            }
        });
        this.searchSDK = hiSearchSDK;
        if (this.category == 4) {
            hiSearchSDK.search_Ext(0);
        } else if (this.type != 101) {
            hiSearchSDK.search_Ext(10);
        } else {
            hiSearchSDK.search_NVR();
        }
        final int i = 20000;
        this.timer = new CountDownTimer(20000, 1000L) {
            @Override
            public void onFinish() {
                if (LANSearchCameraActivity.this.list == null || LANSearchCameraActivity.this.list.size() == 0) {
                    LANSearchCameraActivity.this.searchSDK.stop();
                    LANSearchCameraActivity.this.layFailSearch.setVisibility(0);
                    if (LANSearchCameraActivity.this.progressbar.getVisibility() == 0) {
                        LANSearchCameraActivity.this.progressbar.setVisibility(8);
                    }
                }
            }

            @Override
            public void onTick(long j) {
                if (j <= i - 3000) {
                    LANSearchCameraActivity.this.titleview.setRightTxt(LANSearchCameraActivity.this.getString(R.string.refresh));
                }
            }
        }.start();
        this.layFailSearch.setVisibility(8);
        this.list.clear();
    }

    public void Hi_osSearch() {
        this.isApMode = false;
        HiLitosSDK hiLitosSDK = new HiLitosSDK(new HiLitosSDK.ILitosResult() {
            @Override
            public void onReceiveLitosResult(String str, int i, int i2, int i3) {
                if (TextUtils.isEmpty(str) || str.split("\r\n").length <= 3) {
                    return;
                }
                String[] split = str.split("\r\n");
                try {
                    JSONObject jSONObject = new JSONObject(split[split.length - 1]).getJSONObject("devinfo");
                    String string = jSONObject.getString(HiDataValue.EXTRAS_KEY_UID);
                    String string2 = jSONObject.getString("mac");
                    jSONObject.getString(Constant.MODE);
                    LANSearchCameraActivity.this.isApMode = true;
                    HiSearchSDK.HiSearchResult hiSearchResult = new HiSearchSDK.HiSearchResult(string, string2, "192.168.55.1", 15555, "admin", "");
                    Message obtainMessage = LANSearchCameraActivity.this.handler.obtainMessage();
                    obtainMessage.obj = hiSearchResult;
                    obtainMessage.what = HiDataValue.HANDLE_MESSAGE_SCAN_RESULT;
                    LANSearchCameraActivity.this.handler.sendMessage(obtainMessage);
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        });
        this.hiLitosSDK = hiLitosSDK;
        hiLitosSDK.HttpRequest("192.168.55.1", 15555, "/liteos/param.cgi?cmd=getdevinfo", 5, 6);
    }

    private void startListItemAnim() {
        this.AnimlvItem = AnimationUtils.loadAnimation(this, R.anim.list_anim);
        LayoutAnimationController layoutAnimationController = new LayoutAnimationController(this.AnimlvItem);
        layoutAnimationController.setDelay(0.2f);
        layoutAnimationController.setOrder(0);
        this.listSearchResult.setLayoutAnimation(layoutAnimationController);
    }

    @Override
    public void onPause() {
        super.onPause();
        this.searchSDK.stop();
        CountDownTimer countDownTimer = this.timer;
        if (countDownTimer != null) {
            countDownTimer.cancel();
            this.timer = null;
        }
        Handler handler = this.handler;
        if (handler != null) {
            handler.removeCallbacksAndMessages(null);
        }
        if (this.searchSDK != null) {
            this.searchSDK = null;
        }
    }

    @Override
    public void onRequestPermissionsResult(int i, String[] strArr, int[] iArr) {
        super.onRequestPermissionsResult(i, strArr, iArr);
        boolean z = true;
        HiLogcatUtil.e("" + i);
        int length = strArr.length;
        for (int i2 = 0; i2 < length; i2++) {
            HiLogcatUtil.e(strArr.length + Constants.COLON_SEPARATOR + strArr[i2]);
        }
        for (int i3 : iArr) {
            HiLogcatUtil.e(iArr.length + Constants.COLON_SEPARATOR + i3);
        }
        if (i == 10010) {
            int length2 = iArr.length;
            int i4 = 0;
            while (true) {
                if (i4 >= length2) {
                    break;
                }
                if (iArr[i4] != 0) {
                    z = false;
                    break;
                }
                i4++;
            }
            if (z) {
                return;
            }
            HiTools.Hi_GoToSetting(strArr, this, this);
        }
    }
}