Skip to content

Commit

Permalink
refactor code
Browse files Browse the repository at this point in the history
  • Loading branch information
jokermonn committed Sep 3, 2017
1 parent ccd149e commit 4ec3341
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 15 deletions.
15 changes: 8 additions & 7 deletions app/src/main/java/com/joker/permissions4m/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.joker.annotation.PermissionsRequestSync;
import com.joker.api.Permissions4M;
import com.joker.api.support.PermissionsPageManager;
import com.joker.api.wrapper.ListenerWrapper;
import com.joker.api.wrapper.Wrapper;
import com.joker.permissions4m.other.ToastUtil;

Expand Down Expand Up @@ -59,8 +60,8 @@ protected void onCreate(Bundle savedInstanceState) {
@Override
public void onClick(View v) {
Permissions4M.get(MainActivity.this)
.requestCodes(CALL_LOG_CODE)
.requestPermissions(Manifest.permission.READ_CALL_LOG)
.requestCodes(CALL_LOG_CODE)
.requestPageType(Permissions4M.PageType.MANAGER_PAGE)
.request();
}
Expand Down Expand Up @@ -108,7 +109,7 @@ public void onClick(View v) {
Permissions4M.get(MainActivity.this)
.requestPermissions(Manifest.permission.READ_CONTACTS)
.requestCodes(READ_CONTACTS_CODE)
.requestCallback(new Wrapper.PermissionRequestListener() {
.requestListener(new ListenerWrapper.PermissionRequestListener() {
@Override
public void permissionGranted(int code) {
ToastUtil.show("读取通讯录权限成功 in activity with listener");
Expand All @@ -129,8 +130,8 @@ public void permissionRationale(int code) {
@Override
public void pageIntent(final Intent intent) {
new AlertDialog.Builder(MainActivity.this)
.setMessage("读取通讯录权限申请:\n我们需要您开启读取通讯录权限(in activity with listener)")
.setPositiveButton("确定", new DialogInterface.OnClickListener() {
.setMessage("傻逼用户,我们需要您开启读取通讯录权限申请:\n请点击前往设置页面\n(in activity with listener)")
.setPositiveButton("前往设置页面", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
startActivity(intent);
Expand All @@ -139,7 +140,7 @@ public void onClick(DialogInterface dialog, int which) {
.setNegativeButton("取消", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
dialog.dismiss();
}
})
.show();
Expand Down Expand Up @@ -268,7 +269,7 @@ public void storageAndCallRationale(int code, final Intent intent) {
switch (code) {
case AUDIO_CODE:
new AlertDialog.Builder(MainActivity.this)
.setMessage("读取录音权限申请:\n我们需要您开启读取录音权限(in activity with listener)")
.setMessage("傻逼用户,我们需要您开启读取录音权限\n请点击前往设置页面\n(in activity with listener)")
.setPositiveButton("确定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Expand All @@ -285,7 +286,7 @@ public void onClick(DialogInterface dialog, int which) {
break;
case CALL_LOG_CODE:
new AlertDialog.Builder(MainActivity.this)
.setMessage("读取通话记录权限申请:\n我们需要您开启读取通话记录权限(in activity with listener)")
.setMessage("傻逼用户,我们需要您开启读取通话记录权限\n请点击前往设置页面\n(in activity with listener)")
.setPositiveButton("确定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Expand Down
34 changes: 26 additions & 8 deletions app/src/main/java/com/joker/permissions4m/NormalFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
* A simple {@link Fragment} subclass.
*/
public class NormalFragment extends Fragment {
private static final int CALENDAR_CODE = 700;
private static final int SENSORS_CODE = 800;
private static final int LOCATION_CODE = 900;
private static final int SENSORS_CODE = 700;
private static final int LOCATION_CODE = 800;
private static final int CALENDAR_CODE = 900;
private static final int SMS_CODE = 500;
private static final int AUDIO_CODE = 600;
private static final int PHONE_STATE_CODE = 1000;
Expand Down Expand Up @@ -69,7 +69,7 @@ public void onClick(View v) {
.requestPermissions(Manifest.permission.BODY_SENSORS, Manifest.permission
.ACCESS_FINE_LOCATION, Manifest.permission.READ_CALENDAR)
.requestCodes(SENSORS_CODE, LOCATION_CODE, CALENDAR_CODE)
.requestCallback(new ListenerWrapper.PermissionRequestListener() {
.requestListener(new ListenerWrapper.PermissionRequestListener() {
@Override
public void permissionGranted(int code) {
switch (code) {
Expand Down Expand Up @@ -140,7 +140,7 @@ public void onClick(View v) {
Permissions4M.get(NormalFragment.this)
.requestPermissions(Manifest.permission.READ_PHONE_STATE)
.requestCodes(PHONE_STATE_CODE)
.requestCallback(new ListenerWrapper.PermissionRequestListener() {
.requestListener(new ListenerWrapper.PermissionRequestListener() {
@Override
public void permissionGranted(int code) {
ToastUtil.show("读取手机状态权限成功 in activity with listener");
Expand All @@ -161,9 +161,9 @@ public void permissionRationale(int code) {
@Override
public void pageIntent(final Intent intent) {
new AlertDialog.Builder(getActivity())
.setMessage("读取手机状态权限申请:\n我们需要您开启读取手机状态权限(in activity with " +
.setMessage("傻逼用户,我们需要您开启读取手机状态权限:\n请点击前往设置页面\n(in activity with " +
"listener)")
.setPositiveButton("确定", new DialogInterface.OnClickListener() {
.setPositiveButton("前往设置页面", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
startActivity(intent);
Expand All @@ -178,6 +178,24 @@ public void onClick(DialogInterface dialog, int which) {
.show();
}
})
.requestCustomRationaleListener(new ListenerWrapper.PermissionCustomRationaleListener() {
@Override
public void permissionCustomRationale(int code) {
new AlertDialog.Builder(getActivity())
.setMessage("手机状态权限申请:\n我们需要您开启手机状态权限(in fragment with annotation)")
.setPositiveButton("确定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Permissions4M.get(NormalFragment.this)
.requestOnRationale()
.requestPermissions(Manifest.permission.READ_PHONE_STATE)
.requestCodes(PHONE_STATE_CODE)
.request();
}
})
.show();
}
})
.request();
}
});
Expand Down Expand Up @@ -265,7 +283,7 @@ public void nonRationale(int code, final Intent intent) {
switch (code) {
case SMS_CODE:
new AlertDialog.Builder(getActivity())
.setMessage("短信权限申请:\n我们需要您开启短信权限(in fragment with annotation)")
.setMessage("傻逼用户,我们需要您开启读取短信权限申请:\n请点击前往设置页面\n(in fragment with annotation)")
.setPositiveButton("确定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Expand Down

0 comments on commit 4ec3341

Please sign in to comment.