导航菜单

页面标题

页面副标题

爱心e站 v1.0.0 - SplashActivity.java 源代码

正在查看: 爱心e站 v1.0.0 应用的 SplashActivity.java JAVA 源代码文件

本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。


package com.newheyd.JZKFcanjiren.Activity;

import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.widget.RelativeLayout;
import com.igexin.assist.sdk.AssistPushConsts;
import com.newheyd.JZKFcanjiren.BaseActivity;
import com.newheyd.JZKFcanjiren.Bean.UserInfo;
import com.newheyd.JZKFcanjiren.MyApplication;
import com.newheyd.JZKFcanjiren.R;
import com.newheyd.JZKFcanjiren.Utils.DataBaseUtils.DictionaryDatabaseManager;
import com.newheyd.JZKFcanjiren.Utils.DataDictionary;
import com.newheyd.JZKFcanjiren.Utils.NewUtil;
import com.newheyd.JZKFcanjiren.Utils.SharedPreferencedUtils;
import com.newheyd.JZKFcanjiren.Utils.ToastUtils;
import com.newheyd.JZKFcanjiren.View.PhotoSelect.CommonMethod;
import com.newheyd.JZKFcanjiren.config.NewHYConfig;
import com.newheyd.JZKFcanjiren.model.BaseResult;
import com.newheyd.JZKFcanjiren.net.LoginTask;
import com.newheyd.JZKFcanjiren.net.NewHYTask;
import com.newheyd.JZKFcanjiren.net.RequestServiceList;
import java.util.HashMap;
import org.json.JSONArray;
import org.json.JSONException;

public class SplashActivity extends BaseActivity {
    private CommonMethod commonMethod;
    private DictionaryDatabaseManager dbManager;
    private RelativeLayout rlRoot;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.page_splash);
        this.dbManager = new DictionaryDatabaseManager(this);
        this.rlRoot = (RelativeLayout) findViewById(R.id.activity_splash);
        requestStoragePermission();
        startAnimation();
    }

    public void checkLogin() {
        if (isAutoLogin()) {
            if (MyApplication.getInstance().getUserInfo() != null) {
                HashMap<String, String> params = new HashMap<>();
                params.put("loginName", SharedPreferencedUtils.getInstance(this.mContext).getString("loginName"));
                params.put("password", SharedPreferencedUtils.getInstance(this.mContext).getString("password"));
                LoginTask loginTask = new LoginTask(RequestServiceList.CLIENT_LOGIN, params);
                executeRequest(loginTask);
                return;
            }
            toLogin();
            return;
        }
        toLogin();
    }

    private boolean isAutoLogin() {
        String autoLogin = SharedPreferencedUtils.getInstance(this.mContext).getString("autoLogin");
        boolean no = "no".equals(autoLogin);
        return !no;
    }

    private void toLogin() {
        if (!SharedPreferencedUtils.getInstance(this.mContext).getBoolean("isFirstOpen", false)) {
            startActivity(new Intent(this, (Class<?>) HomeFragActivity.class));
        } else {
            startActivity(new Intent(this, (Class<?>) GuideActivity.class));
        }
        finish();
    }

    @Override
    public void onResponseBefore(NewHYTask task) {
        switch (task.getService()) {
            case CLIENT_LOGIN:
                showProgress(NewHYConfig.LOADING_HINT, false);
                break;
        }
    }

    @Override
    public void onResponseAfter(NewHYTask task) {
        switch (task.getService()) {
            case CLIENT_LOGIN:
                cancleProgress();
                break;
        }
    }

    @Override
    public void onResponseSuccessful(NewHYTask task, BaseResult object) {
        switch (task.getService()) {
            case CLIENT_LOGIN:
                SharedPreferencedUtils.getInstance(this.mContext).putString(AssistPushConsts.MSG_TYPE_TOKEN, object.getData());
                UserInfo userInfo = new UserInfo();
                userInfo.setToken(object.getData());
                userInfo.setRoleIdList(object.getData2());
                userInfo.setUsername(task.getParamsMap().get("loginName"));
                MyApplication.getInstance().saveUserInfo(userInfo);
                SharedPreferencedUtils.getInstance(this.mContext).putString("loginName", task.getParamsMap().get("loginName"));
                SharedPreferencedUtils.getInstance(this.mContext).putString("password", task.getParamsMap().get("password"));
                SharedPreferencedUtils.getInstance(this.mContext).putString("autoLogin", "yes");
                Intent intent = new Intent(this, (Class<?>) HomeFragActivity.class);
                startActivity(intent);
                finish();
                break;
        }
    }

    @Override
    public void onResponseError(NewHYTask task, BaseResult object) {
        switch (task.getService()) {
            case CLIENT_LOGIN:
                ToastUtils.showShortToast(this.mContext, object.getMsg());
                if (1 == object.getErrorcode()) {
                    finish();
                    ReLogin();
                    break;
                }
                break;
        }
    }

    @Override
    public void onServerError(NewHYTask task, int failedType) {
        switch (task.getService()) {
            case CLIENT_LOGIN:
                onResultShow(failedType);
                finish();
                ReLogin();
                break;
        }
    }

    public void startAnimation() {
        AlphaAnimation animation = new AlphaAnimation(0.4f, 1.0f);
        animation.setDuration(1500L);
        this.rlRoot.startAnimation(animation);
        animation.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation2) {
            }

            @Override
            public void onAnimationEnd(Animation animation2) {
                SplashActivity.this.initDataDictionary();
                SplashActivity.this.checkLogin();
            }

            @Override
            public void onAnimationRepeat(Animation animation2) {
            }
        });
    }

    public void initDataDictionary() {
        String currentVersion = NewUtil.getCurrentVersion(this.mContext);
        String oldVersion = SharedPreferencedUtils.getInstance(this.mContext).getString("version");
        if (!currentVersion.equals(oldVersion)) {
            SharedPreferencedUtils.getInstance(this.mContext).putString("version", currentVersion);
            try {
                this.dbManager.add(new JSONArray(DataDictionary.Data));
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }

    @Override
    public void initViews() {
    }

    @Override
    public void setListener() {
    }

    public void requestStoragePermission() {
        this.commonMethod = new CommonMethod(this);
        if (Build.VERSION.SDK_INT >= 23 && ContextCompat.checkSelfPermission(this.mContext, "android.permission.WRITE_EXTERNAL_STORAGE") != 0) {
            ActivityCompat.requestPermissions(this, new String[]{"android.permission.WRITE_EXTERNAL_STORAGE", "android.permission.READ_EXTERNAL_STORAGE"}, 129);
        }
    }

    @Override
    public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
        switch (requestCode) {
            case 129:
                if (grantResults[0] != 0) {
                    if (!ActivityCompat.shouldShowRequestPermissionRationale(this, "android.permission.READ_EXTERNAL_STORAGE")) {
                        this.commonMethod.dialogAndInset("读写手机存储权限");
                        break;
                    } else {
                        this.commonMethod.dialogAndInset("读写手机存储权限");
                        break;
                    }
                }
                break;
            default:
                super.onRequestPermissionsResult(requestCode, permissions, grantResults);
                break;
        }
    }
}