|
| 1 | +package com.github.ipcjs.screenshottile; |
| 2 | + |
| 3 | +import android.app.Activity; |
| 4 | +import android.app.AlertDialog; |
| 5 | +import android.app.Dialog; |
| 6 | +import android.app.DialogFragment; |
| 7 | +import android.content.DialogInterface; |
| 8 | +import android.content.Intent; |
| 9 | +import android.net.Uri; |
| 10 | +import android.os.Bundle; |
| 11 | + |
| 12 | +import static com.github.ipcjs.screenshottile.Utils.hasRoot; |
| 13 | +import static com.github.ipcjs.screenshottile.Utils.p; |
| 14 | + |
| 15 | +/** |
| 16 | + * Created by ipcjs on 02/07. |
| 17 | + */ |
| 18 | + |
| 19 | +public class RootDialogActivity extends Activity { |
| 20 | + @Override |
| 21 | + protected void onCreate(Bundle savedInstanceState) { |
| 22 | + super.onCreate(savedInstanceState); |
| 23 | + if (savedInstanceState == null) { |
| 24 | + RootDialogFragment fragment = RootDialogFragment.newInstance(); |
| 25 | +// fragment.setCancelable(false); |
| 26 | + fragment.show(getFragmentManager(), RootDialogFragment.class.getName()); |
| 27 | + } |
| 28 | + } |
| 29 | + |
| 30 | + public static class RootDialogFragment extends DialogFragment implements DialogInterface.OnClickListener { |
| 31 | + public static RootDialogFragment newInstance() { |
| 32 | + return new RootDialogFragment(); |
| 33 | + } |
| 34 | + |
| 35 | + @Override |
| 36 | + public Dialog onCreateDialog(Bundle savedInstanceState) { |
| 37 | + return new AlertDialog.Builder(getActivity(), getTheme()) |
| 38 | + .setTitle(R.string.dialog_obtain_root) |
| 39 | + .setMessage(getString(R.string.dialog_obtain_root_message, getString(R.string.app_name))) |
| 40 | + .setPositiveButton(R.string.dialog_reacquire, this) |
| 41 | + .setNeutralButton(R.string.dialog_i_know, this) |
| 42 | + .setNegativeButton(R.string.dialog_uninstall, this) |
| 43 | + .create(); |
| 44 | + } |
| 45 | + |
| 46 | + @Override |
| 47 | + public void onClick(DialogInterface dialog, int which) { |
| 48 | + switch (which) { |
| 49 | + case Dialog.BUTTON_POSITIVE: |
| 50 | + if (!hasRoot()) { |
| 51 | + startActivity(new Intent(getActivity(), RootDialogActivity.class)); |
| 52 | + } |
| 53 | + break; |
| 54 | + case Dialog.BUTTON_NEUTRAL: |
| 55 | + break; |
| 56 | + case Dialog.BUTTON_NEGATIVE: |
| 57 | + startActivity(new Intent(Intent.ACTION_UNINSTALL_PACKAGE, Uri.parse("package:" + getActivity().getPackageName()))); |
| 58 | + break; |
| 59 | + } |
| 60 | + getActivity().finish(); |
| 61 | + } |
| 62 | + |
| 63 | + @Override |
| 64 | + public void onDismiss(DialogInterface dialog) { |
| 65 | + super.onDismiss(dialog); |
| 66 | + p("RootDialogFragment.onDismiss"); |
| 67 | + } |
| 68 | + |
| 69 | + @Override |
| 70 | + public void onCancel(DialogInterface dialog) { |
| 71 | + super.onCancel(dialog); |
| 72 | + getActivity().finish(); |
| 73 | + } |
| 74 | + } |
| 75 | +} |
0 commit comments