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

The following examples show how to use com.grarak.kerneladiutor.utils.Utils#getBoolean() . 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: HBMWidget.java    From kernel_adiutor with Apache License 2.0 6 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    super.onReceive(context, intent);
    if (Utils.getBoolean("Widget_Active", false, context) && Screen.hasScreenHBM()) {
        if (intent.getAction().equals("com.kerneladiutor.mod.action.TOGGLE_HBM")) {
            if (Screen.hasScreenHBM()) {
                Log.i(Constants.TAG + ": " + getClass().getSimpleName(), "Toggling High Brightness Mode");
                if (Screen.isScreenHBMActive()) {
                    Screen.activateScreenHBM(false, context, "Manual");
                    doupdate(context, false);
                } else {
                    Screen.activateScreenHBM(true, context, "Manual");
                    doupdate(context, true);
                }
            }
        }
        // Make sure that the widget is in the correct state when the phone is unlocked.
        if (intent.getAction().equals("android.intent.action.USER_PRESENT") && Screen.hasScreenHBM()) {
            doupdate(context, Screen.isScreenHBMActive());
        }
    }
}
 
Example 2
Source File: MainActivity.java    From kernel_adiutor with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if(!BuildConfig.DEBUG){
        Fabric.with(this, new Crashlytics());
    }

    setView();
    String password;
    if (!(password = Utils.getString("password", "", this)).isEmpty())
        askPassword(password);
    else // Use an AsyncTask to initialize everything
        new Task().execute();

    if (Utils.getBoolean("AutoHBM", false, getApplicationContext()) && Screen.hasScreenHBM() && !isMyServiceRunning(AutoHighBrightnessModeService.class)) {
        startService(new Intent(this, AutoHighBrightnessModeService.class));
    }
}
 
Example 3
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 4
Source File: Sound.java    From kernel_adiutor with Apache License 2.0 5 votes vote down vote up
public static boolean isIndependentHeadphoneGainEnabled(Context context) {
    try {
        return Utils.getBoolean("Independent_Headphone_Gain_Enabled", false, context);
    } catch (NullPointerException err) {
        return false;
    }
}
 
Example 5
Source File: Screen.java    From kernel_adiutor with Apache License 2.0 5 votes vote down vote up
public static void activateScreenHBM(boolean active, Context context, String source) {
    if (source.equals("Manual")) {
        if (Screen.isScreenAutoHBMActive(context) && AutoHighBrightnessModeService.HBM_Manually_Toggled) {
            AutoHighBrightnessModeService.HBM_Manually_Toggled = false;
        } else {
            AutoHighBrightnessModeService.HBM_Manually_Toggled = true;
        }
    }
    Control.runCommand(active ? "1" : "0", Utils.getsysfspath(SCREEN_HBM), Control.CommandType.GENERIC, context);
    if (Utils.getBoolean("Widget_Active", false, context)) {
        HBMWidget.doupdate(context, active);
    }
}
 
Example 6
Source File: BootReceiver.java    From KA27 with Apache License 2.0 5 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {

    String action = intent.getAction();

    if (Intent.ACTION_BOOT_COMPLETED.equals(action) && Utils.getBoolean("ka_run", false, context)) {
        ContextCompat.startForegroundService(context, new Intent(context, BootService.class));

        if (Utils.getBoolean("emulateinit.d", false, context))
            ContextCompat.startForegroundService(context, new Intent(context, InitdService.class));
    }
}
 
Example 7
Source File: BootService.java    From KA27 with Apache License 2.0 5 votes vote down vote up
private void toast(final String message) {
    if (Utils.getBoolean("applyonbootshowtoast", true, this))
        hand.post(new Runnable() {
            @Override
            public void run() {
                Utils.toast(getString(R.string.app_name) + ": " + message, BootService.this);
            }
        });
}
 
Example 8
Source File: RecyclerViewFragment.java    From KA27 with Apache License 2.0 5 votes vote down vote up
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
    super.onScrolled(recyclerView, dx, dy);

    if (scroll && Utils.getBoolean("hideapplyonboot", true, getActivity())) {
        int height = applyOnBootLayout.getHeight();
        offset += dy;
        if (offset > height) offset = height;
        else if (offset < 0) offset = 0;
        move(offset);
    }
    scroll = true;
}
 
Example 9
Source File: BaseActivity.java    From kernel_adiutor with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Set english as default language if option is enabled
    if (Utils.getBoolean("forceenglish", false, this)) Utils.setLocale("en_US", this);

    // 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(getResources().getColor(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: BootService.java    From kernel_adiutor with Apache License 2.0 5 votes vote down vote up
private void toast(final String message) {
    if (Utils.getBoolean("applyonbootshowtoast", true, this))
        hand.post(new Runnable() {
            @Override
            public void run() {
                Utils.toast(getString(R.string.app_name) + ": " + message, BootService.this);
            }
        });
}
 
Example 11
Source File: MainActivity.java    From KA27 with Apache License 2.0 5 votes vote down vote up
public static void reconfigureNavigationDrawer(Context context) {
    if (mScrimInsetsFrameLayout != null) {
        DrawerLayout.LayoutParams params = (DrawerLayout.LayoutParams) mScrimInsetsFrameLayout.getLayoutParams();
        // Allow configuration of the Navigation drawer to the right side rather than the left
        if (Utils.getBoolean("Navbar_Position_Alternate", false, context)) {
            params.gravity = Gravity.END;
        } else {
            params.gravity = Gravity.START;
        }
    }
}
 
Example 12
Source File: ProfileWidget.java    From kernel_adiutor 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 13
Source File: MainActivity.java    From KA27 with Apache License 2.0 5 votes vote down vote up
public void setItems(BaseFragment fragment) {
    List < DAdapter.DView > tmpViews = new ArrayList < > ();
    for (DAdapter.DView item: ITEMS)
        if (item.getFragment() == null ||
            Utils.getBoolean(item.getFragment().getClass().getSimpleName() + "visible", true, this))
            tmpViews.add(item);

    VISIBLE_ITEMS.clear();
    // Sort out headers without any sections
    for (int i = 0; i < tmpViews.size(); i++)
        if ((tmpViews.get(i).getFragment() == null && i < tmpViews.size() && tmpViews.get(i + 1).getFragment() != null) ||
            tmpViews.get(i).getFragment() != null ||
            tmpViews.get(i) instanceof DAdapter.MainHeader)
            VISIBLE_ITEMS.add(tmpViews.get(i));

    mAdapter = new DAdapter.Adapter(VISIBLE_ITEMS);
    mDrawerList.setAdapter(mAdapter);
    mAdapter.setItemOnly(true);
    mAdapter.setOnItemClickListener(new DAdapter.Adapter.OnItemClickListener() {
        @Override
        public void onItemClick(View view, int position) {
            selectItem(position);
        }
    });
    if (fragment != null)
        for (int i = 0; i < VISIBLE_ITEMS.size(); i++)
            if (VISIBLE_ITEMS.get(i).getFragment() != null && VISIBLE_ITEMS.get(i).getFragment() == fragment) {
                cur_position = i;
                mAdapter.setItemChecked(i, true);
            }

}
 
Example 14
Source File: InitdService.java    From kernel_adiutor with Apache License 2.0 5 votes vote down vote up
private void toast(final String message) {
    if (Utils.getBoolean("applyonbootshowtoast", true, getApplicationContext()))
        hand.post(new Runnable() {
            @Override
            public void run() {
                Utils.toast(getString(R.string.app_name) + ": " + message, InitdService.this);
            }
        });
}
 
Example 15
Source File: CPU.java    From KA27 with Apache License 2.0 5 votes vote down vote up
public static boolean isPerCoreGovControlEnabled(Context context) {
    try {
        return Utils.getBoolean("Per_Core_Gov_Control_Enabled", false, context);
    } catch (NullPointerException err) {
        return false;
    }
}
 
Example 16
Source File: CPU.java    From KA27 with Apache License 2.0 5 votes vote down vote up
public static boolean isPerCoreFreqControlEnabled(Context context) {
    try {
        return Utils.getBoolean("Per_Core_Freq_Control_Enabled", false, context);
    } catch (NullPointerException err) {
        return false;
    }
}
 
Example 17
Source File: BootService.java    From KA27 with Apache License 2.0 4 votes vote down vote up
private void init() {
    final List < String > applys = new ArrayList < > ();

    CPUVoltage.storeVoltageTable(this);

    Class[] classes = {
        BatteryFragment.class,
        CPUFragment.class,
        CPUHotplugFragment.class,
        CPUVoltageFragment.class,
        EntropyFragment.class,
        GPUFragment.class,
        IOFragment.class,
        KSMFragment.class,
        LMKFragment.class,
        MiscFragment.class,
        RamFragment.class,
        ScreenFragment.class,
        SoundFragment.class,
        ThermalFragment.class,
        VMFragment.class,
        WakeFragment.class,
        WakeLockFragment.class
    };

    for (Class mClass: classes)
        if (Utils.getBoolean(mClass.getSimpleName() + "onboot", false, this)) {
            log("Applying on boot for " + mClass.getSimpleName());
            applys.addAll(Utils.getApplys(mClass));
        }

    if (applys.size() > 0) {

        if (!needNotification) {
            TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
            stackBuilder.addParentStack(MainActivity.class);
            stackBuilder.addNextIntent(new Intent(this, MainActivity.class));
            PendingIntent pendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
            mBuilder.setContentIntent(pendingIntent);
        }

        new Thread(new Runnable() {
            @Override
            public void run() {
                boolean notification = Utils.getBoolean("applyonbootnotification", false, BootService.this);
                if (delay > 0) {
                    for (int i = delay; i >= 0; i--) {
                        try {
                            Thread.sleep(1000);
                            String note = getString(R.string.apply_on_boot_time, i);
                            if (notification) {
                                mBuilder.setContentText(note).setProgress(delay, delay - i, false);
                                mNotifyManager.notify(NOTIFY_ID, mBuilder.build());
                            } else if ((i % 10 == 0 || i == delay) && i != 0) toast(note);
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }
                }
                apply(applys);
                if (notification) {
                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
                        mBuilder.setContentText(getString(R.string.apply_on_boot_finished));
                        mNotifyManager.notify(102, mBuilder.build());
                    } else {
                        mBuilder.setContentText(getString(R.string.apply_on_boot_finished)).setProgress(0, 0, false);
                        mNotifyManager.notify(NOTIFY_ID, mBuilder.build());
                    }
                }
                stopSelf();
            }
        }).start();
    } else stopSelf();
}
 
Example 18
Source File: Screen.java    From kernel_adiutor with Apache License 2.0 4 votes vote down vote up
public static boolean isScreenAutoHBMActive(Context context) {
    return Utils.getBoolean("AutoHBM", false, context);
}
 
Example 19
Source File: Screen.java    From kernel_adiutor with Apache License 2.0 4 votes vote down vote up
public static boolean isScreenAutoHBMSmoothingActive(Context context) {
    return Utils.getBoolean("AutoHBM_Smoothing", false, context);
}
 
Example 20
Source File: CPU.java    From kernel_adiutor with Apache License 2.0 4 votes vote down vote up
public static boolean isPerCoreControlActive (Context context) {
    return Utils.getBoolean("MSM_Limiter_Per_Core_Control", false, context);
}