Search in sources :

Example 1 with AlertDialogBuilder

use of com.topjohnwu.magisk.components.AlertDialogBuilder in project MagiskManager by topjohnwu.

the class ReposAdapter method onBindItemViewHolder.

@Override
public void onBindItemViewHolder(RepoHolder holder, int section, int position) {
    Repo repo = repoPairs.get(section).second.get(position);
    Context context = holder.itemView.getContext();
    holder.title.setText(repo.getName());
    holder.versionName.setText(repo.getVersion());
    String author = repo.getAuthor();
    holder.author.setText(TextUtils.isEmpty(author) ? null : context.getString(R.string.author, author));
    holder.description.setText(repo.getDescription());
    holder.updateTime.setText(context.getString(R.string.updated_on, repo.getLastUpdateString()));
    holder.infoLayout.setOnClickListener(v -> new MarkDownWindow((Activity) context, null, repo.getDetailUrl()).exec());
    holder.downloadImage.setOnClickListener(v -> {
        String filename = repo.getName() + "-" + repo.getVersion() + ".zip";
        new AlertDialogBuilder((Activity) context).setTitle(context.getString(R.string.repo_install_title, repo.getName())).setMessage(context.getString(R.string.repo_install_msg, filename)).setCancelable(true).setPositiveButton(R.string.install, (d, i) -> new ProcessRepoZip((Activity) context, repo.getZipUrl(), Utils.getLegalFilename(filename), true).exec()).setNeutralButton(R.string.download, (d, i) -> new ProcessRepoZip((Activity) context, repo.getZipUrl(), Utils.getLegalFilename(filename), false).exec()).setNegativeButton(R.string.no_thanks, null).show();
    });
}
Also used : Context(android.content.Context) Context(android.content.Context) LinearLayout(android.widget.LinearLayout) ButterKnife(butterknife.ButterKnife) MarkDownWindow(com.topjohnwu.magisk.asyncs.MarkDownWindow) AlertDialogBuilder(com.topjohnwu.magisk.components.AlertDialogBuilder) Pair(android.util.Pair) ImageView(android.widget.ImageView) ArrayList(java.util.ArrayList) BindView(butterknife.BindView) R(com.topjohnwu.magisk.R) ProcessRepoZip(com.topjohnwu.magisk.asyncs.ProcessRepoZip) Module(com.topjohnwu.magisk.container.Module) RepoDatabaseHelper(com.topjohnwu.magisk.database.RepoDatabaseHelper) Map(java.util.Map) View(android.view.View) Cursor(android.database.Cursor) LayoutInflater(android.view.LayoutInflater) TextUtils(android.text.TextUtils) ViewGroup(android.view.ViewGroup) RecyclerView(android.support.v7.widget.RecyclerView) List(java.util.List) TextView(android.widget.TextView) Utils(com.topjohnwu.magisk.utils.Utils) Activity(android.app.Activity) Repo(com.topjohnwu.magisk.container.Repo) AlertDialogBuilder(com.topjohnwu.magisk.components.AlertDialogBuilder) Repo(com.topjohnwu.magisk.container.Repo) ProcessRepoZip(com.topjohnwu.magisk.asyncs.ProcessRepoZip) Activity(android.app.Activity) MarkDownWindow(com.topjohnwu.magisk.asyncs.MarkDownWindow)

Example 2 with AlertDialogBuilder

use of com.topjohnwu.magisk.components.AlertDialogBuilder in project MagiskManager by topjohnwu.

the class PolicyAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(ViewHolder holder, int position) {
    Policy policy = policyList.get(position);
    holder.setExpanded(expandList.contains(policy));
    holder.itemView.setOnClickListener(view -> {
        if (holder.isExpanded()) {
            holder.collapse();
            expandList.remove(policy);
        } else {
            holder.expand();
            expandList.add(policy);
        }
    });
    holder.appName.setText(policy.appName);
    holder.packageName.setText(policy.packageName);
    holder.appIcon.setImageDrawable(policy.info.loadIcon(pm));
    holder.masterSwitch.setOnCheckedChangeListener((v, isChecked) -> {
        if ((isChecked && policy.policy == Policy.DENY) || (!isChecked && policy.policy == Policy.ALLOW)) {
            policy.policy = isChecked ? Policy.ALLOW : Policy.DENY;
            String message = v.getContext().getString(isChecked ? R.string.su_snack_grant : R.string.su_snack_deny, policy.appName);
            SnackbarMaker.make(holder.itemView, message, Snackbar.LENGTH_SHORT).show();
            dbHelper.updatePolicy(policy);
        }
    });
    holder.notificationSwitch.setOnCheckedChangeListener((v, isChecked) -> {
        if ((isChecked && !policy.notification) || (!isChecked && policy.notification)) {
            policy.notification = isChecked;
            String message = v.getContext().getString(isChecked ? R.string.su_snack_notif_on : R.string.su_snack_notif_off, policy.appName);
            SnackbarMaker.make(holder.itemView, message, Snackbar.LENGTH_SHORT).show();
            dbHelper.updatePolicy(policy);
        }
    });
    holder.loggingSwitch.setOnCheckedChangeListener((v, isChecked) -> {
        if ((isChecked && !policy.logging) || (!isChecked && policy.logging)) {
            policy.logging = isChecked;
            String message = v.getContext().getString(isChecked ? R.string.su_snack_log_on : R.string.su_snack_log_off, policy.appName);
            SnackbarMaker.make(holder.itemView, message, Snackbar.LENGTH_SHORT).show();
            dbHelper.updatePolicy(policy);
        }
    });
    holder.delete.setOnClickListener(v -> new AlertDialogBuilder((Activity) v.getContext()).setTitle(R.string.su_revoke_title).setMessage(v.getContext().getString(R.string.su_revoke_msg, policy.appName)).setPositiveButton(R.string.yes, (dialog, which) -> {
        policyList.remove(position);
        notifyItemRemoved(position);
        notifyItemRangeChanged(position, policyList.size());
        SnackbarMaker.make(holder.itemView, v.getContext().getString(R.string.su_snack_revoke, policy.appName), Snackbar.LENGTH_SHORT).show();
        dbHelper.deletePolicy(policy);
    }).setNegativeButton(R.string.no_thanks, null).setCancelable(true).show());
    holder.masterSwitch.setChecked(policy.policy == Policy.ALLOW);
    holder.notificationSwitch.setChecked(policy.notification);
    holder.loggingSwitch.setChecked(policy.logging);
    // Hide for now
    holder.moreInfo.setVisibility(View.GONE);
}
Also used : Policy(com.topjohnwu.magisk.container.Policy) AlertDialogBuilder(com.topjohnwu.magisk.components.AlertDialogBuilder) Activity(android.app.Activity)

Example 3 with AlertDialogBuilder

use of com.topjohnwu.magisk.components.AlertDialogBuilder in project MagiskManager by topjohnwu.

the class ShowUI method uninstallDialog.

public static void uninstallDialog(Activity activity) {
    MagiskManager mm = Utils.getMagiskManager(activity);
    new AlertDialogBuilder(activity).setTitle(R.string.uninstall_magisk_title).setMessage(R.string.uninstall_magisk_msg).setPositiveButton(R.string.complete_uninstall, (d, i) -> {
        ByteArrayOutputStream uninstaller = new ByteArrayOutputStream();
        try (InputStream in = mm.getAssets().open(Const.UNINSTALLER)) {
            ShellUtils.pump(in, uninstaller);
        } catch (IOException e) {
            e.printStackTrace();
            return;
        }
        ByteArrayOutputStream utils = new ByteArrayOutputStream();
        try (InputStream in = mm.getAssets().open(Const.UTIL_FUNCTIONS)) {
            ShellUtils.pump(in, utils);
        } catch (IOException e) {
            e.printStackTrace();
            return;
        }
        Shell.Sync.su(Utils.fmt("echo '%s' > /cache/%s", uninstaller.toString().replace("'", "'\\''"), Const.UNINSTALLER), Utils.fmt("echo '%s' > %s/%s", utils.toString().replace("'", "'\\''"), mm.magiskVersionCode >= 1464 ? "/data/adb/magisk" : "/data/magisk", Const.UTIL_FUNCTIONS));
        try {
            uninstaller.close();
            utils.close();
        } catch (IOException ignored) {
        }
        MagiskManager.toast(R.string.uninstall_toast, Toast.LENGTH_LONG);
        new Handler().postDelayed(() -> Utils.uninstallPkg(mm.getPackageName()), 5000);
    }).setNeutralButton(R.string.restore_img, (d, i) -> new RestoreImages().exec()).setNegativeButton(R.string.uninstall_app, (d, i) -> Utils.uninstallPkg(mm.getPackageName())).show();
}
Also used : Context(android.content.Context) ByteArrayOutputStream(java.io.ByteArrayOutputStream) AlertDialogBuilder(com.topjohnwu.magisk.components.AlertDialogBuilder) Uri(android.net.Uri) TaskStackBuilder(android.support.v4.app.TaskStackBuilder) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) FlashActivity(com.topjohnwu.magisk.FlashActivity) RebootReceiver(com.topjohnwu.magisk.receivers.RebootReceiver) Shell(com.topjohnwu.superuser.Shell) ManagerUpdate(com.topjohnwu.magisk.receivers.ManagerUpdate) ArrayList(java.util.ArrayList) R(com.topjohnwu.magisk.R) ShellUtils(com.topjohnwu.superuser.ShellUtils) Manifest(android.Manifest) Handler(android.os.Handler) Toast(android.widget.Toast) MagiskManager(com.topjohnwu.magisk.MagiskManager) SplashActivity(com.topjohnwu.magisk.SplashActivity) RestoreImages(com.topjohnwu.magisk.asyncs.RestoreImages) NotificationManager(android.app.NotificationManager) DownloadReceiver(com.topjohnwu.magisk.receivers.DownloadReceiver) IOException(java.io.IOException) List(java.util.List) AlertDialog(android.support.v7.app.AlertDialog) NotificationCompat(android.support.v4.app.NotificationCompat) Activity(android.app.Activity) InputStream(java.io.InputStream) AlertDialogBuilder(com.topjohnwu.magisk.components.AlertDialogBuilder) MagiskManager(com.topjohnwu.magisk.MagiskManager) InputStream(java.io.InputStream) Handler(android.os.Handler) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) RestoreImages(com.topjohnwu.magisk.asyncs.RestoreImages)

Example 4 with AlertDialogBuilder

use of com.topjohnwu.magisk.components.AlertDialogBuilder in project MagiskManager by topjohnwu.

the class ShowUI method magiskInstallDialog.

public static void magiskInstallDialog(Activity activity) {
    MagiskManager mm = Utils.getMagiskManager(activity);
    String filename = Utils.fmt("Magisk-v%s(%d).zip", mm.remoteMagiskVersionString, mm.remoteMagiskVersionCode);
    new AlertDialogBuilder(activity).setTitle(mm.getString(R.string.repo_install_title, mm.getString(R.string.magisk))).setMessage(mm.getString(R.string.repo_install_msg, filename)).setCancelable(true).setPositiveButton(R.string.install, (d, i) -> {
        List<String> options = new ArrayList<>();
        options.add(mm.getString(R.string.download_zip_only));
        options.add(mm.getString(R.string.patch_boot_file));
        if (Shell.rootAccess()) {
            options.add(mm.getString(R.string.direct_install));
        }
        String s = Utils.cmd("echo $SLOT");
        if (s != null) {
            options.add(mm.getString(R.string.install_second_slot));
        }
        char[] slot = s == null ? null : s.toCharArray();
        new AlertDialog.Builder(activity).setTitle(R.string.select_method).setItems(options.toArray(new String[0]), (dialog, idx) -> {
            String boot;
            DownloadReceiver receiver = null;
            switch(idx) {
                case 1:
                    if (mm.remoteMagiskVersionCode < 1400) {
                        MagiskManager.toast(R.string.no_boot_file_patch_support, Toast.LENGTH_LONG);
                        return;
                    }
                    MagiskManager.toast(R.string.boot_file_patch_msg, Toast.LENGTH_LONG);
                    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
                    intent.setType("*/*");
                    ((com.topjohnwu.magisk.components.Activity) activity).startActivityForResult(intent, Const.ID.SELECT_BOOT, (requestCode, resultCode, data) -> {
                        if (requestCode == Const.ID.SELECT_BOOT && resultCode == Activity.RESULT_OK && data != null) {
                            Utils.dlAndReceive(activity, new DownloadReceiver() {

                                @Override
                                public void onDownloadDone(Uri uri) {
                                    Intent intent = new Intent(mm, FlashActivity.class);
                                    intent.setData(uri).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK).putExtra(Const.Key.FLASH_SET_BOOT, data.getData()).putExtra(Const.Key.FLASH_ACTION, Const.Value.PATCH_BOOT);
                                    mm.startActivity(intent);
                                }
                            }, mm.magiskLink, filename);
                        }
                    });
                    return;
                case 0:
                    receiver = new DownloadReceiver() {

                        @Override
                        public void onDownloadDone(Uri uri) {
                            Utils.showUriSnack(activity, uri);
                        }
                    };
                    break;
                case 2:
                    boot = mm.bootBlock;
                    if (boot == null)
                        return;
                    receiver = new DownloadReceiver() {

                        @Override
                        public void onDownloadDone(Uri uri) {
                            Intent intent = new Intent(mm, FlashActivity.class);
                            intent.setData(uri).putExtra(Const.Key.FLASH_SET_BOOT, boot).putExtra(Const.Key.FLASH_ACTION, Const.Value.FLASH_MAGISK);
                            activity.startActivity(intent);
                        }
                    };
                    break;
                case 3:
                    assert (slot != null);
                    // Choose the other slot
                    if (slot[1] == 'a')
                        slot[1] = 'b';
                    else
                        slot[1] = 'a';
                    // Then find the boot image again
                    boot = Utils.cmd("SLOT=" + String.valueOf(slot) + "; find_boot_image;" + "echo \"$BOOTIMAGE\"");
                    Shell.Async.su("mount_partitions");
                    if (boot == null)
                        return;
                    receiver = new DownloadReceiver() {

                        @Override
                        public void onDownloadDone(Uri uri) {
                            Intent intent = new Intent(mm, FlashActivity.class);
                            intent.setData(uri).putExtra(Const.Key.FLASH_SET_BOOT, boot).putExtra(Const.Key.FLASH_ACTION, Const.Value.FLASH_MAGISK);
                            activity.startActivity(intent);
                        }
                    };
                default:
            }
            Utils.dlAndReceive(activity, receiver, mm.magiskLink, filename);
        }).show();
    }).setNeutralButton(R.string.release_notes, (d, i) -> {
        if (mm.releaseNoteLink != null) {
            Intent openLink = new Intent(Intent.ACTION_VIEW, Uri.parse(mm.releaseNoteLink));
            openLink.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            mm.startActivity(openLink);
        }
    }).setNegativeButton(R.string.no_thanks, null).show();
}
Also used : Context(android.content.Context) ByteArrayOutputStream(java.io.ByteArrayOutputStream) AlertDialogBuilder(com.topjohnwu.magisk.components.AlertDialogBuilder) Uri(android.net.Uri) TaskStackBuilder(android.support.v4.app.TaskStackBuilder) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) FlashActivity(com.topjohnwu.magisk.FlashActivity) RebootReceiver(com.topjohnwu.magisk.receivers.RebootReceiver) Shell(com.topjohnwu.superuser.Shell) ManagerUpdate(com.topjohnwu.magisk.receivers.ManagerUpdate) ArrayList(java.util.ArrayList) R(com.topjohnwu.magisk.R) ShellUtils(com.topjohnwu.superuser.ShellUtils) Manifest(android.Manifest) Handler(android.os.Handler) Toast(android.widget.Toast) MagiskManager(com.topjohnwu.magisk.MagiskManager) SplashActivity(com.topjohnwu.magisk.SplashActivity) RestoreImages(com.topjohnwu.magisk.asyncs.RestoreImages) NotificationManager(android.app.NotificationManager) DownloadReceiver(com.topjohnwu.magisk.receivers.DownloadReceiver) IOException(java.io.IOException) List(java.util.List) AlertDialog(android.support.v7.app.AlertDialog) NotificationCompat(android.support.v4.app.NotificationCompat) Activity(android.app.Activity) InputStream(java.io.InputStream) FlashActivity(com.topjohnwu.magisk.FlashActivity) MagiskManager(com.topjohnwu.magisk.MagiskManager) AlertDialogBuilder(com.topjohnwu.magisk.components.AlertDialogBuilder) TaskStackBuilder(android.support.v4.app.TaskStackBuilder) FlashActivity(com.topjohnwu.magisk.FlashActivity) SplashActivity(com.topjohnwu.magisk.SplashActivity) Activity(android.app.Activity) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) Uri(android.net.Uri) DownloadReceiver(com.topjohnwu.magisk.receivers.DownloadReceiver) AlertDialogBuilder(com.topjohnwu.magisk.components.AlertDialogBuilder) ArrayList(java.util.ArrayList) List(java.util.List)

Example 5 with AlertDialogBuilder

use of com.topjohnwu.magisk.components.AlertDialogBuilder in project MagiskManager by topjohnwu.

the class ShowUI method managerInstallDialog.

public static void managerInstallDialog(Activity activity) {
    MagiskManager mm = Utils.getMagiskManager(activity);
    String filename = Utils.fmt("MagiskManager-v%s(%d).apk", mm.remoteManagerVersionString, mm.remoteManagerVersionCode);
    new AlertDialogBuilder(activity).setTitle(mm.getString(R.string.repo_install_title, mm.getString(R.string.app_name))).setMessage(mm.getString(R.string.repo_install_msg, filename)).setCancelable(true).setPositiveButton(R.string.install, (d, i) -> {
        Utils.runWithPermission(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE, () -> {
            Intent intent = new Intent(mm, ManagerUpdate.class);
            intent.putExtra(Const.Key.INTENT_SET_LINK, mm.managerLink);
            intent.putExtra(Const.Key.INTENT_SET_FILENAME, filename);
            mm.sendBroadcast(intent);
        });
    }).setNegativeButton(R.string.no_thanks, null).show();
}
Also used : AlertDialogBuilder(com.topjohnwu.magisk.components.AlertDialogBuilder) MagiskManager(com.topjohnwu.magisk.MagiskManager) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent)

Aggregations

AlertDialogBuilder (com.topjohnwu.magisk.components.AlertDialogBuilder)5 Activity (android.app.Activity)4 PendingIntent (android.app.PendingIntent)3 Context (android.content.Context)3 Intent (android.content.Intent)3 MagiskManager (com.topjohnwu.magisk.MagiskManager)3 R (com.topjohnwu.magisk.R)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Manifest (android.Manifest)2 NotificationManager (android.app.NotificationManager)2 Uri (android.net.Uri)2 Handler (android.os.Handler)2 NotificationCompat (android.support.v4.app.NotificationCompat)2 TaskStackBuilder (android.support.v4.app.TaskStackBuilder)2 AlertDialog (android.support.v7.app.AlertDialog)2 Toast (android.widget.Toast)2 FlashActivity (com.topjohnwu.magisk.FlashActivity)2 SplashActivity (com.topjohnwu.magisk.SplashActivity)2 RestoreImages (com.topjohnwu.magisk.asyncs.RestoreImages)2