-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed #1, fixed issue when switching activities.
- Loading branch information
Showing
9 changed files
with
141 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
app/src/main/java/com/greysonparrelli/permisodemo/NonPermisoActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package com.greysonparrelli.permisodemo; | ||
|
||
import android.Manifest; | ||
import android.os.Bundle; | ||
import android.support.annotation.NonNull; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.view.View; | ||
import android.widget.Toast; | ||
|
||
import com.greysonparrelli.permiso.Permiso; | ||
|
||
/** | ||
* Created to demonstrate how to use Permiso without extending PermisoActivity. | ||
*/ | ||
public class NonPermisoActivity extends AppCompatActivity { | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_non_permiso); | ||
|
||
// | ||
// First, tell Permiso that you're using this activity | ||
// | ||
Permiso.getInstance().setActivity(this); | ||
|
||
findViewById(R.id.btn_request).setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
onRequestClick(); | ||
} | ||
}); | ||
} | ||
|
||
@Override | ||
protected void onResume() { | ||
super.onResume(); | ||
|
||
// | ||
// Second, we also have to set the activity here to handle transitioning between activities | ||
// | ||
Permiso.getInstance().setActivity(this); | ||
} | ||
|
||
@Override | ||
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { | ||
super.onRequestPermissionsResult(requestCode, permissions, grantResults); | ||
|
||
// | ||
// Third, forward the results of this method to Permiso | ||
// | ||
Permiso.getInstance().onRequestPermissionResult(requestCode, permissions, grantResults); | ||
} | ||
|
||
private void onRequestClick() { | ||
// | ||
// And that's it! Now you can make permission requests as usual | ||
// | ||
Permiso.getInstance().requestPermissions(new Permiso.IOnPermissionResult() { | ||
@Override | ||
public void onPermissionResult(Permiso.ResultSet resultSet) { | ||
if (resultSet.areAllPermissionsGranted()) { | ||
Toast.makeText(NonPermisoActivity.this, "Permission Granted!", Toast.LENGTH_SHORT).show(); | ||
} else { | ||
Toast.makeText(NonPermisoActivity.this, "Permission Denied.", Toast.LENGTH_SHORT).show(); | ||
} | ||
} | ||
|
||
@Override | ||
public void onRationaleRequested(Permiso.IOnRationaleProvided callback, String... permissions) { | ||
Permiso.getInstance().showRationaleInDialog("Permission Rationale", "Needed for demo purposes.", null, callback); | ||
} | ||
}, Manifest.permission.READ_EXTERNAL_STORAGE); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
tools:context="com.greysonparrelli.permisodemo.MainActivity" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:orientation="vertical" | ||
android:layout_gravity="center"> | ||
|
||
<Button | ||
android:id="@+id/btn_request" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:text="Request a Permission"/> | ||
|
||
</LinearLayout> |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters