Java Code Examples for com.grarak.kerneladiutor.utils.Utils#toast()

The following examples show how to use com.grarak.kerneladiutor.utils.Utils#toast() . 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
Source File: SupportedDownloads.java    From KernelAdiutor with GNU General Public License v3.0 6 votes vote down vote up
public SupportedDownloads(Context context) {
    try {
        String json = Utils.existFile(context.getFilesDir() + "/downloads.json") ?
                Utils.readFile(context.getFilesDir() + "/downloads.json", false) :
                Utils.readAssetFile(context, "downloads.json");
        JSONArray devices = new JSONArray(json);
        for (int i = 0; i < devices.length(); i++) {
            JSONObject device = devices.getJSONObject(i);
            JSONArray vendors = device.getJSONArray("vendor");
            for (int x = 0; x < vendors.length(); x++) {
                if (vendors.getString(x).equals(Device.getVendor())) {
                    JSONArray names = device.getJSONArray("device");
                    for (int y = 0; y < names.length(); y++) {
                        if (names.getString(y).equals(Device.getDeviceName())) {
                            mLink = device.getString("link");
                        }
                    }
                }
            }
        }
    } catch (JSONException e) {
        Utils.toast("Failed to read downloads.json " + e.getMessage(), context);
    }
}
 
Example 2
Source File: CustomControlsFragment.java    From KernelAdiutor with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void onPostExecute(ImportControl importControl) {
    super.onPostExecute(importControl);
    CustomControlsFragment fragment = mRefFragment.get();
    if (fragment == null) return;

    fragment.hideProgress();
    fragment.mImportingThread = null;
    if (!importControl.readable()) {
        Utils.toast(R.string.import_malformed, fragment.getActivity());
    } else if (!importControl.matchesVersion()) {
        Utils.toast(R.string.import_wrong_version, fragment.getActivity());
    } else {
        fragment.updateControls(importControl.getResults());
    }
}
 
Example 3
Source File: MainActivity.java    From KA27 with Apache License 2.0 6 votes vote down vote up
/**
 * This makes onBackPressed function work in Fragments
 */
@Override
public void onBackPressed() {
    try {
        if (!VISIBLE_ITEMS.get(cur_position).getFragment().onBackPressed())
            if (mDrawerLayout == null || !mDrawerLayout.isDrawerOpen(mScrimInsetsFrameLayout)) {
                if (pressAgain) {
                    Utils.toast(getString(R.string.press_back_again), this);
                    pressAgain = false;
                    new Handler().postDelayed(new Runnable() {
                        @Override
                        public void run() {
                            pressAgain = true;
                        }
                    }, 2000);
                } else super.onBackPressed();
            } else mDrawerLayout.closeDrawer(mScrimInsetsFrameLayout);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example 4
Source File: CPUVoltageFragment.java    From KA27 with Apache License 2.0 5 votes vote down vote up
@Override
public void preInit(Bundle savedInstanceState) {
    super.preInit(savedInstanceState);
    SharedPreferences storedvoltagetable = getContext().getSharedPreferences("voltage_table", 0);
    // Save the current Voltage table if it doesn't exist. This will prevent issues in the table if they open it before a reboot.
    // On reboot, the default table will overwrite this as it will have any adjustments done since boot as the reference. This is imperfect, but no better way to do it.
    String toasttext = "";
    List < String > frequencies = CPUVoltage.getFreqs();
    if (frequencies.isEmpty()) return;
    if (storedvoltagetable.getString(frequencies.get(0), "-1").equals("-1")) {
        toasttext = getString(R.string.non_default_reference) + " -- ";
        CPUVoltage.storeVoltageTable(getContext());
    }
    Utils.toast(toasttext + getString(R.string.voltages_toast_notification), getActivity(), Toast.LENGTH_LONG);
}
 
Example 5
Source File: ProfileTileReceiver.java    From kernel_adiutor with Apache License 2.0 5 votes vote down vote up
public static void publishProfileTile(List<ProfileDB.ProfileItem> profiles, Context context) {
    if (!Utils.hasCMSDK()) return;
    if (profiles == null || profiles.size() < 1 || !Utils.getBoolean("profiletile", true, context)) {
        CMStatusBarManager.getInstance(context).removeTile(0);
        return;
    }

    Intent intent = new Intent();
    intent.setAction(ACTION_TOGGLE_STATE);

    ArrayList<CustomTile.ExpandedGridItem> expandedGridItems = new ArrayList<>();
    for (ProfileDB.ProfileItem item : profiles) {
        CustomTile.ExpandedGridItem expandedGridItem = new CustomTile.ExpandedGridItem();
        expandedGridItem.setExpandedGridItemTitle(item.getName());
        expandedGridItem.setExpandedGridItemDrawable(R.drawable.ic_launcher_preview);

        intent.putExtra(NAME, item.getName());
        intent.putExtra(COMMANDS, item.getCommands().toArray(new String[item.getCommands().size()]));
        PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intent,
                PendingIntent.FLAG_UPDATE_CURRENT);

        expandedGridItem.setExpandedGridItemOnClickIntent(pendingIntent);
        expandedGridItems.add(expandedGridItem);
    }

    CustomTile.GridExpandedStyle gridExpandedStyle = new CustomTile.GridExpandedStyle();
    gridExpandedStyle.setGridItems(expandedGridItems);

    CustomTile mCustomTile = new CustomTile.Builder(context)
            .setExpandedStyle(gridExpandedStyle)
            .setLabel(R.string.profile)
            .setIcon(R.drawable.ic_launcher_preview)
            .build();
    try {
        CMStatusBarManager.getInstance(context).publishTile(0, mCustomTile);
    } catch (Exception e) {
        Utils.saveBoolean("profiletile", false, context);
        Utils.toast(e.getMessage(), context, Toast.LENGTH_LONG);
    }
}
 
Example 6
Source File: SettingsFragment.java    From kernel_adiutor with Apache License 2.0 5 votes vote down vote up
private void deletePasswordDialog(final String password) {
    if (password.isEmpty()) {
        Utils.toast(getString(R.string.set_password_first), getActivity());
        return;
    }

    LinearLayout linearLayout = new LinearLayout(getActivity());
    linearLayout.setOrientation(LinearLayout.VERTICAL);
    linearLayout.setGravity(Gravity.CENTER);
    linearLayout.setPadding(30, 20, 30, 20);

    final AppCompatEditText mPassword = new AppCompatEditText(getActivity());
    mPassword.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
    mPassword.setHint(getString(R.string.password));
    linearLayout.addView(mPassword);

    new AlertDialog.Builder(getActivity()).setView(linearLayout)
            .setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    if (!mPassword.getText().toString().equals(Utils.decodeString(password))) {
                        Utils.toast(getString(R.string.password_wrong), getActivity());
                        return;
                    }

                    Utils.saveString("password", "", getActivity());
                }
            }).show();
}
 
Example 7
Source File: ProfileWidget.java    From KA27 with Apache License 2.0 5 votes vote down vote up
@Override
public void onReceive(@NonNull final Context context, @NonNull Intent intent) {
    if (intent.getAction().equals(LIST_ITEM_CLICK)) {
        if (!Utils.getBoolean("profileclicked", false, context)) {
            Utils.saveBoolean("profileclicked", true, context);
            Utils.toast(context.getString(R.string.press_again_to_apply), context);
            new Thread(new Runnable() {
                @Override
                public void run() {
                    try {
                        Thread.sleep(2000);
                        Utils.saveBoolean("profileclicked", false, context);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }).start();
        } else {
            Utils.saveBoolean("profileclicked", false, context);
            int position = intent.getIntExtra(ITEM_ARG, 0);
            ProfileDB profileDB = new ProfileDB(context);
            ProfileDB.ProfileItem profileItem = profileDB.getAllProfiles().get(position);
            RootUtils.SU su = new RootUtils.SU();

            List < String > paths = profileItem.getPath();
            for (int i = 0; i < paths.size(); i++) {
                Control.commandSaver(context, paths.get(i), profileItem.getCommands().get(i));
                su.runCommand(profileItem.getCommands().get(i));
            }
            su.close();
            Utils.toast("Profile: \"" + profileItem.getName() + "\" applied.", context);
        }
    }

    super.onReceive(context, intent);
}
 
Example 8
Source File: HBMWidget.java    From kernel_adiutor with Apache License 2.0 5 votes vote down vote up
@Override
public void onEnabled(Context context) {
    super.onEnabled(context);
    if (Screen.hasScreenHBM()) {
        setWidgetActive(true, context.getApplicationContext());
    } else {
        Utils.toast("Your device does not have HBM/SRE, this widget will not work. Please remove it.", context);
    }
}
 
Example 9
Source File: BaseActivity.java    From KA27 with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Check if darktheme is in use and cache it as boolean
    if (Utils.DARKTHEME = Utils.getBoolean("darktheme", false, this)) {
        super.setTheme(getDarkTheme());
        getWindow().getDecorView().getRootView().setBackgroundColor(ContextCompat.getColor(this, R.color.black));
    }

    if (getParentViewId() != 0) setContentView(getParentViewId());
    else if (getParentView() != null) setContentView(getParentView());

    Toolbar toolbar;
    if ((toolbar = getToolbar()) != null) {
        if (Utils.DARKTHEME) toolbar.setPopupTheme(R.style.ThemeOverlay_AppCompat_Dark);
        try {
            setSupportActionBar(toolbar);
        } catch (NoClassDefFoundError e) {
            Utils.toast(e.getMessage(), this, Toast.LENGTH_LONG);
            finish();
        }
    }

    ActionBar actionBar;
    if ((actionBar = getSupportActionBar()) != null)
        actionBar.setDisplayHomeAsUpEnabled(getDisplayHomeAsUpEnabled());

    setStatusBarColor();
}
 
Example 10
Source File: DAdapter.java    From KA27 with Apache License 2.0 5 votes vote down vote up
@Override
protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode == RESULT_OK && requestCode == 0)
        try {
            Uri selectedImageUri = data.getData();
            setImage(selectedImageUri);
            Utils.saveString("previewpicture", selectedImageUri.toString(), this);
            animate();
        } catch (Exception e) {
            e.printStackTrace();
            Utils.toast(getString(R.string.went_wrong), MainHeaderActivity.this);
        }
    finish();
}
 
Example 11
Source File: RunProfileReceiver.java    From KA27 with Apache License 2.0 5 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    if (!ACTION_FIRE_SETTING.equals(intent.getAction()) || !RootUtils.rootAccess() || !RootUtils.hasAppletSupport(context))
        return;
    RootUtils.closeSU();

    BundleScrubber.scrub(intent);

    final Bundle bundle = intent.getBundleExtra(AddProfileActivity.EXTRA_BUNDLE);
    BundleScrubber.scrub(bundle);

    if (PluginBundleManager.isBundleValid(bundle)) {
        String commands = bundle.getString(PluginBundleManager.BUNDLE_EXTRA_STRING_MESSAGE);
        if (commands != null) {
            String[] cs = commands.split(AddProfileActivity.DIVIDER);
            Log.i(Constants.TAG + ": " + getClass().getSimpleName(), "Applying " + cs[0]);
            Utils.toast(context.getString(R.string.applying_profile, cs[0]), context, Toast.LENGTH_LONG);

            if (cs.length > 1) {
                RootUtils.SU su = new RootUtils.SU();
                for (int i = 1; i < cs.length; i++) {
                    Log.i(Constants.TAG + ": " + getClass().getSimpleName(), "Run: " + cs[i]);
                    su.runCommand(cs[i]);
                }
                su.close();
            }
        }
    }
}
 
Example 12
Source File: PerAppMonitor.java    From kernel_adiutor with Apache License 2.0 5 votes vote down vote up
private void process_window_change (String packageName) {
    if (!Per_App.app_profile_exists(packageName, getApplicationContext())) {
        packageName = "Default";
        Log.d(TAG, "Profile does not exist. Using Default");
    }
    if (Per_App.app_profile_exists(packageName, getApplicationContext())) {
        ArrayList<String> info = new ArrayList<String>();
        // Item 0 is package name Item 1 is the profile ID
        info = Per_App.app_profile_info(packageName, getApplicationContext());

        if (!packageName.equals(last_package) && !info.get(1).equals(last_profile)) {
            last_package = packageName;
            last_profile = info.get(1);
            time = System.currentTimeMillis();
            ProfileDB profileDB = new ProfileDB(getApplicationContext());
            final List<ProfileDB.ProfileItem> profileItems = profileDB.getAllProfiles();

            for (int i = 0; i < profileItems.size(); i++) {
                if (profileItems.get(i).getID().equals(info.get(1))) {
                    if (Utils.getBoolean("Per_App_Toast", false, this)) {
                        Utils.toast("Applying Profile: " + profileItems.get(i).getName(), this);
                    }
                    Log.i(TAG, "Applying Profile:  " + profileItems.get(i).getName() + " for package " + packageName);
                    ProfileDB.ProfileItem profileItem = profileItems.get(i);
                    List<String> paths = profileItem.getPath();
                    for (int x = 0; x < paths.size(); x++) {
                        RootUtils.runCommand(profileItem.getCommands().get(x));
                    }
                }
            }
        }
    }
}
 
Example 13
Source File: ProfileFragment.java    From KernelAdiutor with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onPermissionDenied(int request) {
    super.onPermissionDenied(request);

    if (request == 0) {
        Utils.toast(R.string.permission_denied_write_storage, getActivity());
    }
}
 
Example 14
Source File: RunProfileReceiver.java    From kernel_adiutor with Apache License 2.0 5 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    if (!ACTION_FIRE_SETTING.equals(intent.getAction()) || !RootUtils.rootAccess() || !RootUtils.hasAppletSupport())
        return;
    RootUtils.closeSU();

    BundleScrubber.scrub(intent);

    final Bundle bundle = intent.getBundleExtra(AddProfileActivity.EXTRA_BUNDLE);
    BundleScrubber.scrub(bundle);

    if (PluginBundleManager.isBundleValid(bundle)) {
        String commands = bundle.getString(PluginBundleManager.BUNDLE_EXTRA_STRING_MESSAGE);
        if (commands != null) {
            String[] cs = commands.split(AddProfileActivity.DIVIDER);
            Log.i(Constants.TAG + ": " + getClass().getSimpleName(), "Applying " + cs[0]);
            Utils.toast(context.getString(R.string.applying_profile, cs[0]), context, Toast.LENGTH_LONG);

            if (cs.length > 1) {
                RootUtils.SU su = new RootUtils.SU();
                for (int i = 1; i < cs.length; i++) {
                    Log.i(Constants.TAG + ": " + getClass().getSimpleName(), "Run: " + cs[i]);
                    su.runCommand(cs[i]);
                }
                su.close();
            }
        }
    }
}
 
Example 15
Source File: Tasker.java    From KernelAdiutor with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    if (!ACTION_FIRE_SETTING.equals(intent.getAction())) {
        return;
    }

    final Bundle bundle = intent.getBundleExtra(EXTRA_BUNDLE);
    if (isBundleValid(bundle)) {
        String commands = bundle.getString(BUNDLE_EXTRA_STRING_MESSAGE);
        if (commands != null) {
            String[] cs = commands.split(DIVIDER);
            Log.i(TAG + ": " + getClass().getSimpleName(), "Applying " + cs[0]);
            if (AppSettings.isShowTaskerToast(context)) {
                Utils.toast(context.getString(R.string.applying_profile, cs[0]), context, Toast.LENGTH_LONG);
            }

            if (cs.length > 1) {
                RootUtils.SU su = new RootUtils.SU();
                for (int i = 1; i < cs.length; i++) {
                    if (cs[i].isEmpty()) {
                        continue;
                    }
                    synchronized (this) {
                        CPUFreq.ApplyCpu applyCpu;
                        if (cs[i].startsWith("#") && (applyCpu =
                                new CPUFreq.ApplyCpu(cs[i].substring(1))).toString() != null) {
                            for (String applyCpuCommand : ApplyOnBoot.getApplyCpu(applyCpu, su)) {
                                Log.i(TAG + ": " + getClass().getSimpleName(), "Run: " + applyCpuCommand);
                                su.runCommand(applyCpuCommand);
                            }
                        } else {
                            Log.i(TAG + ": " + getClass().getSimpleName(), "Run: " + cs[i]);
                            su.runCommand(cs[i]);
                        }
                    }
                }
                su.close();
            }
        }
    }
}
 
Example 16
Source File: ProfileActivity.java    From KernelAdiutor with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected void onCreate(final @Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Intent intent = getIntent();

    ArrayList<NavigationActivity.NavigationFragment> fragments =
            intent.getParcelableArrayListExtra(FRAGMENTS_INTENT);

    for (NavigationActivity.NavigationFragment navigationFragment : fragments) {
        mItems.put(getString(navigationFragment.mId), getFragment(navigationFragment.mId,
                navigationFragment.mFragmentClass));
    }

    if (mItems.size() < 1) {
        Utils.toast(R.string.sections_disabled, this);
        finish();
        return;
    }

    mProfilePosition = intent.getIntExtra(POSITION_INTENT, -1);
    if (savedInstanceState != null && (mMode = savedInstanceState.getInt("mode")) != 0) {
        if (mMode == 1) {
            initNewMode(savedInstanceState);
        } else {
            currentSettings();
        }
    } else {
        new Dialog(this).setItems(getResources().getStringArray(R.array.profile_modes),
                (dialog, which) -> {
                    switch (which) {
                        case 0:
                            initNewMode(savedInstanceState);
                            break;
                        case 1:
                            currentSettings();
                            break;
                    }
                }).setCancelable(false).show();
    }
}
 
Example 17
Source File: RecyclerViewFragment.java    From kernel_adiutor with Apache License 2.0 4 votes vote down vote up
public void applyOnBootChecked(boolean isChecked) {
    Utils.saveBoolean(getClassName() + "onboot", isChecked, getActivity());
    Utils.toast(getString(isChecked ? R.string.apply_on_boot_enabled : R.string.apply_on_boot_disabled,
            getActionBar().getTitle()), getActivity());
}
 
Example 18
Source File: BuildpropFragment.java    From KA27 with Apache License 2.0 4 votes vote down vote up
private void backup() {
    RootUtils.mountSystem(true);
    RootUtils.runCommand("cp -f " + Constants.BUILD_PROP + " " + Constants.BUILD_PROP + ".bak");
    RootUtils.mountSystem(false);
    Utils.toast(getString(R.string.backup_created, Constants.BUILD_PROP + ".bak"), getActivity());
}
 
Example 19
Source File: InitdFragment.java    From kernel_adiutor with Apache License 2.0 4 votes vote down vote up
@Override
public void postInit(Bundle savedInstanceState) {
    super.postInit(savedInstanceState);
    if (getCount() < 1) Utils.toast(getString(R.string.no_scripts_found), getActivity());
}
 
Example 20
Source File: ScreenFragment.java    From KA27 with Apache License 2.0 4 votes vote down vote up
private void showMoreGammaProfiles(GammaProfiles gammaProfiles) {
    GammaProfiles.GammaProfile profile = null;
    int screen = -1;
    if (mKGammaProfilesCard != null) {
        profile = gammaProfiles.getKGamma();
        screen = 0;
    } else if (mGammaControlProfilesCard != null) {
        profile = gammaProfiles.getGammaControl();
        screen = 1;
    } else if (mDsiPanelProfilesCard != null) {
        profile = gammaProfiles.getDsiPanelProfiles();
        screen = 2;
    }

    if (profile == null) Utils.toast(getString(R.string.no_additional_profiles), getActivity());
    else {
        String[] names = new String[profile.length()];
        for (int i = 0; i < names.length; i++)
            names[i] = profile.getName(i);
        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
        final int profileType = screen;
        final GammaProfiles.GammaProfile gammaProfile = profile;
        builder.setItems(names, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                switch (profileType) {
                    case 0:
                        Screen.setKGammaProfile(which, (GammaProfiles.KGammaProfiles) gammaProfile, getActivity());
                        refreshKGamma();
                        break;
                    case 1:
                        Screen.setGammaControlProfile(which, (GammaProfiles.GammaControlProfiles) gammaProfile, getActivity());
                        refreshGammaControl();
                        break;
                    case 2:
                        Screen.setDsiPanelProfile(which, (GammaProfiles.DsiPanelProfiles) gammaProfile, getActivity());
                        refreshDsiPanel();
                        break;
                }
            }
        }).show();
    }
}