LeftMoreActivity.java 源代码


package activity.Left;

import android.app.AppOpsManager;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.NotificationManagerCompat;
import android.util.Log;
import android.view.View;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import base.HiActivity;
import base.MyApplication;
import bean.MyCamera;
import com.hichip.campro.R;
import common.Constant;
import common.HiDataValue;
import common.TitleView;
import custom.SwitchButton;
import java.util.Iterator;
import utils.HiTools;
import utils.SharePreUtils;
import utils.SystemUtils;

public class LeftMoreActivity extends HiActivity implements View.OnClickListener {
    ImageView iv_arrow;
    RelativeLayout rl_ad;
    RelativeLayout rl_custom_ad;
    RelativeLayout rl_notification;
    RelativeLayout rl_notification_log;
    RelativeLayout rl_vivomediacodec;
    SwitchButton switch_ad;
    SwitchButton switch_btn_log;
    SwitchButton switch_btn_media;
    SwitchButton switch_custom_ad;
    TitleView title;
    TextView tv_isopen;
    TextView tv_loglocation;

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

    @Override
    protected void init(Bundle bundle) {
        initViewAndData();
        if (NotificationManagerCompat.from(this).areNotificationsEnabled()) {
            this.tv_isopen.setText(getString(R.string.opended));
            this.iv_arrow.setVisibility(4);
        } else {
            this.tv_isopen.setText(getString(R.string.shut_down));
        }
        if (SystemUtils.isVIVOMobile(this) && Build.VERSION.SDK_INT > 29) {
            this.rl_vivomediacodec.setVisibility(0);
        } else {
            this.rl_vivomediacodec.setVisibility(8);
        }
        setListeners();
    }

    private void setListeners() {
        this.rl_notification.setOnClickListener(this);
        this.switch_btn_log.setChecked(true);
        this.switch_btn_log.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public final void onCheckedChanged(CompoundButton compoundButton, boolean z) {
                LeftMoreActivity.this.lambda$setListeners$0$LeftMoreActivity(compoundButton, z);
            }
        });
        if (!SharePreUtils.getBoolean(HiDataValue.CACHE, this, Constant.DEV_IsVivoMedia, false)) {
            this.switch_btn_media.setChecked(false);
        } else {
            this.switch_btn_media.setChecked(true);
        }
        this.switch_btn_media.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public final void onCheckedChanged(CompoundButton compoundButton, boolean z) {
                LeftMoreActivity.this.lambda$setListeners$1$LeftMoreActivity(compoundButton, z);
            }
        });
    }

    public void lambda$setListeners$0$LeftMoreActivity(CompoundButton compoundButton, boolean z) {
        if (z) {
            return;
        }
        HiDataValue.isWrightLogStatus = false;
        this.rl_notification_log.setVisibility(8);
        MyApplication.getInstance().shutdownSDKLog();
        MyApplication.getInstance().shutdownWriteLog();
        MyApplication.getInstance().endFileCutCount();
    }

    public void lambda$setListeners$1$LeftMoreActivity(CompoundButton compoundButton, boolean z) {
        Log.e("switch_btn_media", "isChecked" + z);
        if (z) {
            SharePreUtils.putBoolean(HiDataValue.CACHE, this, Constant.DEV_IsVivoMedia, true);
            Iterator<MyCamera> it = HiDataValue.CameraList.iterator();
            while (it.hasNext()) {
                it.next().SetDecodeViVoVideoType(1);
            }
            return;
        }
        SharePreUtils.putBoolean(HiDataValue.CACHE, this, Constant.DEV_IsVivoMedia, false);
        Iterator<MyCamera> it2 = HiDataValue.CameraList.iterator();
        while (it2.hasNext()) {
            it2.next().SetDecodeViVoVideoType(0);
        }
    }

    private void initViewAndData() {
        if (HiDataValue.isWrightLogStatus) {
            this.rl_notification_log.setVisibility(0);
            if (!HiTools.isExternalStorageLegacy()) {
                this.tv_loglocation.setText(getResources().getString(R.string.app_log_noti_new));
            } else {
                this.tv_loglocation.setText(getResources().getString(R.string.app_log_noti));
            }
        } else {
            this.rl_notification_log.setVisibility(8);
            this.rl_ad.setVisibility(8);
            this.rl_custom_ad.setVisibility(8);
        }
        this.title.setButton(0);
        this.title.setTitle(getString(R.string.more));
        this.title.setNavigationBarButtonListener(new TitleView.NavigationBarButtonListener() {
            @Override
            public void OnNavigationButtonClick(int i) {
                if (i != 0) {
                    return;
                }
                LeftMoreActivity.this.finish();
            }
        });
    }

    private boolean isNotificationEnable(Context context) {
        AppOpsManager appOpsManager = Build.VERSION.SDK_INT >= 19 ? (AppOpsManager) context.getSystemService("appops") : null;
        ApplicationInfo applicationInfo = context.getApplicationInfo();
        String packageName = context.getApplicationContext().getPackageName();
        int i = applicationInfo.uid;
        try {
            Class<?> cls = Build.VERSION.SDK_INT >= 19 ? Class.forName(AppOpsManager.class.getName()) : null;
            return ((Integer) cls.getMethod("checkOpNoThrow", Integer.TYPE, Integer.TYPE, String.class).invoke(appOpsManager, Integer.valueOf(((Integer) cls.getDeclaredField("OP_POST_NOTIFICATION").get(Integer.class)).intValue()), Integer.valueOf(i), packageName)).intValue() == 0;
        } catch (Exception e) {
            e.printStackTrace();
            return true;
        }
    }

    @Override
    public void onClick(View view) {
        if (view.getId() == R.id.rl_notification && this.iv_arrow.getVisibility() == 0) {
            Intent intent = new Intent();
            intent.addFlags(268435456);
            if (Build.VERSION.SDK_INT >= 9) {
                intent.setAction("android.settings.APPLICATION_DETAILS_SETTINGS");
                intent.setData(Uri.fromParts("package", getPackageName(), null));
            } else if (Build.VERSION.SDK_INT <= 8) {
                intent.setAction("android.intent.action.VIEW");
                intent.setClassName("com.android.settings", "com.android.settings.InstalledAppDetails");
                intent.putExtra("com.android.settings.ApplicationPkgName", getPackageName());
            }
            startActivity(intent);
        }
    }
}