Java Code Examples for com.grarak.kerneladiutor.utils.tools.Recovery

The following examples show how to use com.grarak.kerneladiutor.utils.tools.Recovery. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
private void add() {
    mAddDialog = new Dialog(getActivity()).setItems(getResources().getStringArray(
            R.array.recovery_commands), (dialogInterface, i) -> {
        switch (i) {
            case 0:
                addAction(Recovery.RECOVERY_COMMAND.WIPE_DATA, null);
                break;
            case 1:
                addAction(Recovery.RECOVERY_COMMAND.WIPE_CACHE, null);
                break;
            case 2:
                Intent intent = new Intent(getActivity(), FilePickerActivity.class);
                intent.putExtra(FilePickerActivity.PATH_INTENT,
                        Environment.getExternalStorageDirectory().toString());
                intent.putExtra(FilePickerActivity.EXTENSION_INTENT, ".zip");
                startActivityForResult(intent, 0);
                break;
        }
    }).setOnDismissListener(dialogInterface -> mAddDialog = null);
    mAddDialog.show();
}
 
Example 2
private void flashNow(final int recoveryOption) {
    mFlashDialog = ViewUtils.dialogBuilder(getString(R.string.flash_now_confirm),
            (dialogInterface, i) -> {
            },
            (dialogInterface, i) -> {
                String file = "/cache/recovery/" + mCommands.get(0).getFile(recoveryOption == 1 ?
                        Recovery.RECOVERY.TWRP : Recovery.RECOVERY.CWM);
                RootFile recoveryFile = new RootFile(file);
                recoveryFile.delete();
                for (Recovery commands : mCommands) {
                    for (String command : commands.getCommands(recoveryOption == 1 ?
                            Recovery.RECOVERY.TWRP :
                            Recovery.RECOVERY.CWM))
                        recoveryFile.write(command, true);
                }
                RootUtils.runCommand("reboot recovery");
            },
            dialogInterface -> mFlashDialog = null, getActivity());
    mFlashDialog.show();
}
 
Example 3
Source Project: KA27   Source File: RecoveryFragment.java    License: Apache License 2.0 5 votes vote down vote up
private void addAction(Recovery.RECOVERY_COMMAND recovery_command, File file) {
    String description = null;
    switch (recovery_command) {
        case WIPE_DATA:
            description = getString(R.string.wipe_data);
            break;
        case WIPE_CACHE:
            description = getString(R.string.wipe_cache);
            break;
        case FLASH_ZIP:
            description = file.getAbsolutePath();
            if (!description.endsWith(".zip")) {
                Utils.toast(getString(R.string.went_wrong), getActivity());
                return;
            }
            break;
    }

    final Recovery recovery = new Recovery(recovery_command, new File(description));
    mCommands.add(recovery);
    // null parent avoid Layout Inflation without a Parent
    ViewGroup base_parent = (ViewGroup) getActivity().findViewById(R.id.base_parent);
    View view = LayoutInflater.from(getActivity()).inflate(R.layout.recovery_actionview, base_parent, false);

    final CardViewItem.DCardView mActionCard = new CardViewItem.DCardView();

    ((TextView) view.findViewById(R.id.action_text)).setText(description);
    view.findViewById(R.id.delete_button).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            removeView(mActionCard);
            mCommands.remove(recovery);
        }
    });

    mActionCard.setView(view);
    addView(mActionCard);
}
 
Example 4
Source Project: kernel_adiutor   Source File: RecoveryFragment.java    License: Apache License 2.0 5 votes vote down vote up
private void addAction(Recovery.RECOVERY_COMMAND recovery_command, File file) {
    String description = null;
    switch (recovery_command) {
        case WIPE_DATA:
            description = getString(R.string.wipe_data);
            break;
        case WIPE_CACHE:
            description = getString(R.string.wipe_cache);
            break;
        case FLASH_ZIP:
            description = file.getAbsolutePath();
            if (!description.endsWith(".zip")) {
                Utils.toast(getString(R.string.went_wrong), getActivity());
                return;
            }
            break;
    }

    final Recovery recovery = new Recovery(recovery_command, new File(description));
    mCommands.add(recovery);

    View view = LayoutInflater.from(getActivity()).inflate(R.layout.recovery_actionview, null, false);

    final CardViewItem.DCardView mActionCard = new CardViewItem.DCardView();

    ((TextView) view.findViewById(R.id.action_text)).setText(description);
    view.findViewById(R.id.delete_button).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            removeView(mActionCard);
            mCommands.remove(recovery);
        }
    });

    mActionCard.setView(view);
    addView(mActionCard);
}
 
Example 5
private void addAction(Recovery.RECOVERY_COMMAND recovery_command, String path) {
    String summary = null;
    switch (recovery_command) {
        case WIPE_DATA:
            summary = getString(R.string.wipe_data);
            break;
        case WIPE_CACHE:
            summary = getString(R.string.wipe_cache);
            break;
        case FLASH_ZIP:
            summary = new File(path).getName();
            break;
    }

    final Recovery recovery = new Recovery(recovery_command, path == null ? null : new File(path));
    mCommands.add(recovery);

    CardView cardView = new CardView();
    cardView.setOnMenuListener((cardView1, popupMenu) -> {
        popupMenu.getMenu().add(Menu.NONE, 0, Menu.NONE, getString(R.string.delete));
        popupMenu.setOnMenuItemClickListener(item -> {
            if (item.getItemId() == 0) {
                mCommands.remove(recovery);
                removeItem(cardView1);
            }
            return false;
        });
    });

    DescriptionView descriptionView = new DescriptionView();
    if (path != null) {
        descriptionView.setTitle(getString(R.string.flash_zip));
    }
    descriptionView.setSummary(summary);

    cardView.addItem(descriptionView);
    addItem(cardView);
}
 
Example 6
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == 0 && data != null) {
        addAction(Recovery.RECOVERY_COMMAND.FLASH_ZIP,
                data.getStringExtra(FilePickerActivity.RESULT_INTENT));
    }
}
 
Example 7
Source Project: KA27   Source File: RecoveryFragment.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (data != null)
        addAction(Recovery.RECOVERY_COMMAND.FLASH_ZIP, new File(data.getExtras().getString("path")));
}
 
Example 8
Source Project: kernel_adiutor   Source File: RecoveryFragment.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (data != null)
        addAction(Recovery.RECOVERY_COMMAND.FLASH_ZIP, new File(data.getExtras().getString("path")));
}
 
Example 9
private void postMD5Check(boolean match, final String path, final String installMethod) {
    if (match) {
        mInstallButton.setVisibility(View.VISIBLE);
        mInstallButton.setOnClickListener(view -> {
            if (!Utils.existFile(path)) {
                Utils.toast(view.getContext().getString(R.string.went_wrong),
                        view.getContext());
                return;
            }
            if (installMethod != null) {
                ViewUtils.dialogBuilder(view.getContext().getString(R.string.sure_question),
                        (dialogInterface, i) -> {
                        },
                        (dialogInterface, i) -> {
                            RootUtils.runCommand(installMethod.replace("$FILE", path));
                            RootUtils.runCommand("rm -f " + path);
                            RootUtils.runCommand("reboot");
                        },
                        dialogInterface -> {
                        }, view.getContext()).setTitle(view.getContext().getString(
                        R.string.install)).show();
            } else {
                mRecoverySelection = 0;
                String[] items = view.getResources().getStringArray(R.array.downloads_recovery);
                new Dialog(view.getContext()).setSingleChoiceItems(items, 0,
                        (dialogInterface, i) -> mRecoverySelection = i).setPositiveButton(view.getContext().getString(R.string.ok),
                        (dialogInterface, i) -> {
                            if (mRecoverySelection == 2) {
                                Utils.toast(view.getContext().getString(
                                        R.string.file_location, path), view.getContext());
                                return;
                            }

                            Recovery recovery = new Recovery(
                                    Recovery.RECOVERY_COMMAND.FLASH_ZIP, new File(path));
                            Recovery.RECOVERY type = mRecoverySelection == 1 ?
                                    Recovery.RECOVERY.TWRP : Recovery.RECOVERY.CWM;
                            RootFile recoveryFile = new RootFile("/cache/recovery/"
                                    + recovery.getFile(type));
                            for (String command : recovery.getCommands(type)) {
                                recoveryFile.write(command, true);
                            }
                            RootUtils.runCommand("reboot recovery");
                        }).show();
            }
        });
    } else {
        mMismatchMD5.setVisibility(View.VISIBLE);
    }
    mCheckMD5.setVisibility(View.GONE);
    mDownloadSection.setVisibility(View.VISIBLE);
    mCheckMD5Task = null;
}