-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fragment support, javadoc updated, added new method "startApplication…
…SettingsActivity" and refacroting
- Loading branch information
Showing
13 changed files
with
416 additions
and
97 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
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
68 changes: 14 additions & 54 deletions
68
sample/src/main/java/ru/alexbykov/permissionssample/MainActivity.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 |
---|---|---|
@@ -1,75 +1,35 @@ | ||
package ru.alexbykov.permissionssample; | ||
|
||
import android.Manifest; | ||
import android.os.Bundle; | ||
import android.support.annotation.NonNull; | ||
import android.support.v4.app.Fragment; | ||
import android.support.v4.app.FragmentTransaction; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.util.Log; | ||
import android.view.View; | ||
import android.widget.TextView; | ||
import android.os.Bundle; | ||
|
||
import ru.alexbykov.nopermission.PermissionHelper; | ||
import ru.alexbykov.permissionssample.fragments.ChooseFragment; | ||
|
||
public class MainActivity extends AppCompatActivity { | ||
|
||
|
||
private final String TAG = "PermissionResult: "; | ||
private static final int LAYOUT = R.layout.activity_main; | ||
private PermissionHelper permissionHelper; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(LAYOUT); | ||
setupPermissionHelper(); | ||
setupUX(); | ||
} | ||
|
||
|
||
private void setupUX() { | ||
findViewById(R.id.btnAskPermission).setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View view) { | ||
askLocationPermission(); | ||
} | ||
}); | ||
startFragment(ChooseFragment.newInstance(), false); | ||
} | ||
|
||
private void askLocationPermission() { | ||
permissionHelper.check(Manifest.permission.ACCESS_COARSE_LOCATION).onSuccess(new Runnable() { | ||
@Override | ||
public void run() { | ||
Log.d(TAG, "LocationSuccess"); | ||
((TextView) findViewById(R.id.tvResult)).setText(R.string.result_success); | ||
} | ||
}).onDenied(new Runnable() { | ||
@Override | ||
public void run() { | ||
Log.d(TAG, "LocationDenied"); | ||
((TextView) findViewById(R.id.tvResult)).setText(R.string.result_failure); | ||
} | ||
}).onNeverAskAgain(new Runnable() { | ||
@Override | ||
public void run() { | ||
Log.d(TAG, "LocationNeverAskAgain"); | ||
((TextView) findViewById(R.id.tvResult)).setText(R.string.result_never_ask_again); | ||
} | ||
}).run(); | ||
|
||
} | ||
public void startFragment(Fragment fragment, boolean addToBackStack) { | ||
|
||
private void setupPermissionHelper() { | ||
permissionHelper = new PermissionHelper(this); | ||
FragmentTransaction transaction = | ||
getSupportFragmentManager() | ||
.beginTransaction() | ||
.replace(R.id.lt_container, fragment); | ||
if (addToBackStack) { | ||
transaction.addToBackStack(fragment.getTag()); | ||
} | ||
transaction.commit(); | ||
} | ||
|
||
@Override | ||
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { | ||
permissionHelper.onRequestPermissionsResult(requestCode, permissions, grantResults); | ||
} | ||
|
||
@Override | ||
protected void onDestroy() { | ||
permissionHelper.unsubscribe(); | ||
super.onDestroy(); | ||
} | ||
} |
Oops, something went wrong.