Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue Rotational issue #7 #11

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions tedpermission/build.gradle
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ android {
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.squareup:otto:1.3.7'

compile 'com.android.support:appcompat-v7:23.3.0'
compile 'com.squareup:otto:1.3.8'
}
76 changes: 29 additions & 47 deletions tedpermission/src/main/java/com/gun0912/tedpermission/TedPermissionActivity.java
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ public class TedPermissionActivity extends AppCompatActivity {

String deniedCloseButtonText;
String rationaleConfirmText;
private AlertDialog rationalDialog;
private AlertDialog denyDialog;


@Override
Expand All @@ -72,7 +74,7 @@ private void setupFromSavedInstanceState(Bundle savedInstanceState) {
deniedCloseButtonText = savedInstanceState.getString(EXTRA_DENIED_DIALOG_CLOSE_TEXT);


settingButtonText =savedInstanceState.getString(EXTRA_SETTING_BUTTON_TEXT);
settingButtonText = savedInstanceState.getString(EXTRA_SETTING_BUTTON_TEXT);
} else {

Intent intent = getIntent();
Expand Down Expand Up @@ -123,30 +125,22 @@ private void checkPermissions(boolean fromOnActivityResult) {

ArrayList<String> needPermissions = new ArrayList<>();


for (String permission : permissions) {



if (ContextCompat.checkSelfPermission(this, permission) != PackageManager.PERMISSION_GRANTED) {
needPermissions.add(permission);
}

}


boolean showRationale = false;

for(String permission:needPermissions){

if(ActivityCompat.shouldShowRequestPermissionRationale(this,permission)){
showRationale=true;
for (String permission : needPermissions) {
if (ActivityCompat.shouldShowRequestPermissionRationale(this, permission)) {
showRationale = true;
}

}



if (needPermissions.isEmpty()) {
permissionGranted();
}
Expand All @@ -156,29 +150,21 @@ else if (fromOnActivityResult) {
}
//Need Show Rationale
else if (showRationale && !TextUtils.isEmpty(rationale_message)) {

showRationaleDialog(needPermissions);


}
//Need Request Permissions
else {

requestPermissions(needPermissions);


}


}

public void requestPermissions(ArrayList<String> needPermissions) {
ActivityCompat.requestPermissions(this, needPermissions.toArray(new String[needPermissions.size()]), REQ_CODE_PERMISSION_REQUEST);

}



@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions,
int[] grantResults) {
Expand All @@ -189,44 +175,34 @@ public void onRequestPermissionsResult(int requestCode, String[] permissions,
for (int i = 0; i < permissions.length; i++) {
String permission = permissions[i];
if (grantResults[i] == PackageManager.PERMISSION_DENIED) {


deniedPermissions.add(permission);

}
}

if (deniedPermissions.isEmpty()) {
permissionGranted();
if (permissions.length > 0) {
if (deniedPermissions.isEmpty()) {
permissionGranted();
} else {
showPermissionDenyDialog(deniedPermissions);
}
} else {


showPermissionDenyDialog(deniedPermissions);


checkPermissions(false);
}


}



private void showRationaleDialog(final ArrayList<String> needPermissions) {

new AlertDialog.Builder(this)
rationalDialog = new AlertDialog.Builder(this)
.setMessage(rationale_message)
.setCancelable(false)

.setNegativeButton(rationaleConfirmText, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
requestPermissions(needPermissions);

}
})
.show();


}).create();
rationalDialog.show();
}

public void showPermissionDenyDialog(final ArrayList<String> deniedPermissions) {
Expand All @@ -239,11 +215,8 @@ public void showPermissionDenyDialog(final ArrayList<String> deniedPermissions)


AlertDialog.Builder builder = new AlertDialog.Builder(this);


builder.setMessage(denyMessage)
.setCancelable(false)

.setNegativeButton(deniedCloseButtonText, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
Expand All @@ -254,7 +227,7 @@ public void onClick(DialogInterface dialogInterface, int i) {
if (hasSettingButton) {


if(TextUtils.isEmpty(settingButtonText)){
if (TextUtils.isEmpty(settingButtonText)) {
settingButtonText = getString(R.string.tedpermission_setting);
}

Expand All @@ -278,9 +251,8 @@ public void onClick(DialogInterface dialog, int which) {

}


builder.show();

denyDialog = builder.create();
denyDialog.show();
}


Expand All @@ -296,4 +268,14 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {

}

@Override
protected void onPause() {
if (rationalDialog != null && rationalDialog.isShowing()) {
rationalDialog.dismiss();
}
if (denyDialog != null && denyDialog.isShowing()) {
denyDialog.dismiss();
}
super.onPause();
}
}