com.hadoopz.MyDroidLib.activity.IDroidBaseActivity Maven / Gradle / Ivy
/*
* Copyright 2018 jw362j.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.hadoopz.MyDroidLib.activity;
import android.app.Activity;
import android.os.Bundle;
import android.view.Window;
import com.hadoopz.MyDroidLib.inject.y;
import com.hadoopz.MyDroidLib.util.ActivityStack;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.os.Build;
import android.content.pm.PackageManager;
import java.util.ArrayList;
import java.util.List;
/**
*
* @author jw362j
*/
public abstract class IDroidBaseActivity extends Activity {
protected final int DEFAULT_PERMISSION_REQUEST_CODE = 20;
private String[] PERMISSIONS;//= new String[]{REBOOT, READ_PHONE_STATE, READ_EXTERNAL_STORAGE, WRITE_EXTERNAL_STORAGE};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
ActivityStack.getInstance().addActivity(this);
y.view().inject(this);
checkPermission();
}
private void checkPermission() {
if (Build.VERSION.SDK_INT < 23) {
return;
}
PERMISSIONS = allPermissionsNeedToCheck();
if (PERMISSIONS == null && PERMISSIONS.length == 0) {
return;
}
List permsTemp = new ArrayList();
for (String permisionItem : PERMISSIONS) {
int permissionCheck = ContextCompat.checkSelfPermission(this, permisionItem);
if (permissionCheck != PackageManager.PERMISSION_GRANTED) {
permsTemp.add(permisionItem);
}
}
if (!permsTemp.isEmpty()) {
String[] targetPermissions = new String[permsTemp.size()];
int flag = 0;
for (String item : permsTemp) {
targetPermissions[flag++] = item;
}
ActivityCompat.requestPermissions(this, targetPermissions, DEFAULT_PERMISSION_REQUEST_CODE);
}
}
public abstract String[] allPermissionsNeedToCheck();
@Override
protected void onResume() {
super.onResume();
ActivityStack.getInstance().resetCurrentActivity(this);
// Variables.backgroundRun = false;
}
@Override
protected void onPause() {
super.onPause();
// Variables.backgroundRun = true;
}
@Override
protected void onDestroy() {
super.onDestroy();
ActivityStack.getInstance().removeActivity(this);
System.gc();
}
}