导航菜单

页面标题

页面副标题

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

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

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


package com.newheyd.JZKFcanjiren.Activity;

import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.IdRes;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.widget.RadioGroup;
import android.widget.Toast;
import com.igexin.sdk.PushManager;
import com.newheyd.JZKFcanjiren.BaseFragmentActiviy;
import com.newheyd.JZKFcanjiren.Fragment.FragmentIndex;
import com.newheyd.JZKFcanjiren.Fragment.FragmentMine;
import com.newheyd.JZKFcanjiren.Fragment.FragmentObject;
import com.newheyd.JZKFcanjiren.R;
import com.newheyd.JZKFcanjiren.Utils.NewLogUtil;
import com.newheyd.JZKFcanjiren.Utils.PermissionUtil;
import com.newheyd.JZKFcanjiren.Utils.ToastUtils;
import com.newheyd.JZKFcanjiren.Utils.locationUtil.BaseLocation;
import com.newheyd.JZKFcanjiren.listener.RequestPermissionCallBack;
import com.newheyd.JZKFcanjiren.model.BaseResult;
import com.newheyd.JZKFcanjiren.net.NewHYTask;
import com.newheyd.JZKFcanjiren.service.GeTuiIntentSeivice;
import com.newheyd.JZKFcanjiren.service.GeTuiPushService;
import java.util.List;

public class HomeFragActivity extends BaseFragmentActiviy {
    private int backNum = 1;
    private long firstBackTime;
    private RadioGroup radiogr_home;
    private long secondBackTime;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        setContentView(R.layout.page_home);
        super.onCreate(savedInstanceState);
        toogleFragment(FragmentIndex.class);
        startPush();
    }

    public void requestMultiPermission() {
        String[] permissionArr = {"android.permission.WRITE_EXTERNAL_STORAGE", "android.permission.READ_EXTERNAL_STORAGE", "android.permission.ACCESS_COARSE_LOCATION", "android.permission.ACCESS_FINE_LOCATION"};
        RequestPermissionCallBack requestPermissionCallBack2 = new RequestPermissionCallBack() {
            @Override
            public void granted() {
                BaseLocation.getInstance().startLocation(HomeFragActivity.this.mContext);
            }

            @Override
            public void denied() {
                ToastUtils.showLongToast(HomeFragActivity.this.mContext, "授权失败,某些功能可能无法使用!");
            }
        };
        PermissionUtil.getInstance().requestPermissions(this.mContext, permissionArr, requestPermissionCallBack2);
    }

    @Override
    public void onResponseBefore(NewHYTask task) {
    }

    @Override
    public void onResponseAfter(NewHYTask task) {
    }

    @Override
    public void onResponseSuccessful(NewHYTask task, BaseResult object) {
    }

    @Override
    public void onResponseError(NewHYTask task, BaseResult object) {
    }

    @Override
    public void onServerError(NewHYTask task, int failedType) {
    }

    public void toogleFragment(Class<? extends Fragment> c) {
        FragmentManager manager = getSupportFragmentManager();
        String tag = c.getName();
        FragmentTransaction transaction = manager.beginTransaction();
        Fragment fragment = manager.findFragmentByTag(tag);
        if (fragment == null) {
            try {
                fragment = c.newInstance();
                transaction.add(R.id.framelayout, fragment, tag);
            } catch (Exception e) {
            }
        }
        List<Fragment> fragments = manager.getFragments();
        if (fragments != null) {
            for (Fragment fm : fragments) {
                if (fm != null && !fm.equals(fragment)) {
                    transaction.hide(fm);
                }
            }
        }
        transaction.show(fragment);
        transaction.commitAllowingStateLoss();
    }

    @Override
    public void initViews() {
        this.radiogr_home = (RadioGroup) findViewById(R.id.radiogr_home);
    }

    @Override
    public void setListener() {
        this.radiogr_home.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, @IdRes int checkedId) {
                switch (checkedId) {
                    case R.id.rh_0:
                        HomeFragActivity.this.toogleFragment(FragmentIndex.class);
                        break;
                    case R.id.rh_1:
                        HomeFragActivity.this.toogleFragment(FragmentObject.class);
                        break;
                    case R.id.rh_4:
                        HomeFragActivity.this.toogleFragment(FragmentMine.class);
                        break;
                }
            }
        });
    }

    @Override
    public void onBackPressed() {
        if (this.backNum == 1) {
            this.firstBackTime = System.currentTimeMillis();
            Toast.makeText(getApplicationContext(), "再按一次退出程序", 0).show();
            this.backNum = 2;
        } else if (this.backNum == 2) {
            this.secondBackTime = System.currentTimeMillis();
            if (this.secondBackTime - this.firstBackTime <= 2000) {
                super.onBackPressed();
            } else {
                this.firstBackTime = System.currentTimeMillis();
                Toast.makeText(getApplicationContext(), "再按一次退出程序", 0).show();
            }
        }
    }

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

    private void startPush() {
        PackageManager pkgManager = getPackageManager();
        boolean sdCardWritePermission = pkgManager.checkPermission("android.permission.WRITE_EXTERNAL_STORAGE", getPackageName()) == 0;
        boolean phoneSatePermission = pkgManager.checkPermission("android.permission.READ_PHONE_STATE", getPackageName()) == 0;
        if ((Build.VERSION.SDK_INT >= 23 && !sdCardWritePermission) || !phoneSatePermission) {
            requestPermission();
        } else {
            PushManager.getInstance().initialize(this, GeTuiPushService.class);
        }
        PushManager.getInstance().registerPushIntentService(this, GeTuiIntentSeivice.class);
        String clientid = PushManager.getInstance().getClientid(this);
        NewLogUtil.debug(clientid);
    }

    private void requestPermission() {
        String[] pushPermissionStr = {"android.permission.READ_PHONE_STATE"};
        PermissionUtil.getInstance().requestPermissions(this.mContext, pushPermissionStr, new RequestPermissionCallBack() {
            @Override
            public void granted() {
                PushManager.getInstance().initialize(HomeFragActivity.this.getApplicationContext(), GeTuiPushService.class);
            }

            @Override
            public void denied() {
            }
        });
    }
}