Search in sources :

Example 26 with CheckBoxPreference

use of android.support.v7.preference.CheckBoxPreference in project packages_apps_AicpExtras by AICP.

the class AnonymousStats method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mPrefs = getPreferences(getActivity());
    PreferenceScreen prefSet = getPreferenceScreen();
    mPrefs = getActivity().getSharedPreferences(Utilities.SETTINGS_PREF_NAME, 0);
    mEnableReporting = (CheckBoxPreference) prefSet.findPreference(Const.ANONYMOUS_OPT_IN);
    mPersistentOptout = (CheckBoxPreference) prefSet.findPreference(Const.ANONYMOUS_OPT_OUT_PERSIST);
    mViewStats = (Preference) prefSet.findPreference(PREF_VIEW_STATS);
    boolean firstBoot = mPrefs.getBoolean(Const.ANONYMOUS_FIRST_BOOT, true);
    if (mEnableReporting.isChecked() && firstBoot) {
        Log.d(Const.TAG, "First app start, set params and report immediately");
        mPrefs.edit().putBoolean(Const.ANONYMOUS_FIRST_BOOT, false).apply();
        mPrefs.edit().putLong(Const.ANONYMOUS_LAST_CHECKED, 1).apply();
        ReportingServiceManager.launchService(getActivity());
    }
    Preference mPrefHolder;
    /* Experimental feature 2 */
    Long lastCheck = mPrefs.getLong(Const.ANONYMOUS_LAST_CHECKED, 0);
    if (lastCheck > 1) {
        // show last checkin date
        String lastCheckStr = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT).format(new java.util.Date(lastCheck));
        lastCheckStr = getResources().getString(R.string.last_report_on) + ": " + lastCheckStr;
        mPrefHolder = prefSet.findPreference(PREF_LAST_REPORT_ON);
        mPrefHolder.setTitle(lastCheckStr);
        Long nextCheck = mPrefs.getLong(Const.ANONYMOUS_NEXT_ALARM, 0);
        if (nextCheck > 0) {
            String nextAlarmStr = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT).format(new java.util.Date(nextCheck));
            nextAlarmStr = getResources().getString(R.string.next_report_on) + ": " + nextAlarmStr;
            mPrefHolder.setSummary(nextAlarmStr);
        }
    } else {
        mPrefHolder = prefSet.findPreference(PREF_LAST_REPORT_ON);
        mPrefHolder.getParent().removePreference(mPrefHolder);
    }
    mPrefHolder = prefSet.findPreference(PREF_REPORT_INTERVAL);
    int tFrame = (int) Utilities.getTimeFrame();
    mPrefHolder.setSummary(getResources().getQuantityString(R.plurals.reporting_interval_days, tFrame, tFrame));
}
Also used : PreferenceScreen(android.support.v7.preference.PreferenceScreen) CheckBoxPreference(android.support.v7.preference.CheckBoxPreference) Preference(android.support.v7.preference.Preference)

Example 27 with CheckBoxPreference

use of android.support.v7.preference.CheckBoxPreference in project Taskbar by farmerbb.

the class AdvancedFragment method onPreferenceClick.

@SuppressLint("SetTextI18n")
@Override
public boolean onPreferenceClick(final Preference p) {
    final SharedPreferences pref = U.getSharedPreferences(getActivity());
    switch(p.getKey()) {
        case "clear_pinned_apps":
            Intent clearIntent = null;
            switch(pref.getString("theme", "light")) {
                case "light":
                    clearIntent = new Intent(getActivity(), ClearDataActivity.class);
                    break;
                case "dark":
                    clearIntent = new Intent(getActivity(), ClearDataActivityDark.class);
                    break;
            }
            startActivity(clearIntent);
            break;
        case "launcher":
            if (U.canDrawOverlays(getActivity())) {
                ComponentName component = new ComponentName(getActivity(), HomeActivity.class);
                getActivity().getPackageManager().setComponentEnabledSetting(component, ((CheckBoxPreference) p).isChecked() ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED : PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
            } else {
                U.showPermissionDialog(getActivity());
                ((CheckBoxPreference) p).setChecked(false);
            }
            if (!((CheckBoxPreference) p).isChecked())
                LocalBroadcastManager.getInstance(getActivity()).sendBroadcast(new Intent("com.farmerbb.taskbar.KILL_HOME_ACTIVITY"));
            break;
        case "keyboard_shortcut":
            ComponentName component = new ComponentName(getActivity(), KeyboardShortcutActivity.class);
            getActivity().getPackageManager().setComponentEnabledSetting(component, ((CheckBoxPreference) p).isChecked() ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED : PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
            break;
        case "dashboard_grid_size":
            AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
            LinearLayout dialogLayout = (LinearLayout) View.inflate(getActivity(), R.layout.dashboard_size_dialog, null);
            boolean isPortrait = getActivity().getApplicationContext().getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT;
            boolean isLandscape = getActivity().getApplicationContext().getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE;
            int editTextId = -1;
            int editText2Id = -1;
            if (isPortrait) {
                editTextId = R.id.fragmentEditText2;
                editText2Id = R.id.fragmentEditText1;
            }
            if (isLandscape) {
                editTextId = R.id.fragmentEditText1;
                editText2Id = R.id.fragmentEditText2;
            }
            final EditText editText = U.findViewById(dialogLayout, editTextId);
            final EditText editText2 = U.findViewById(dialogLayout, editText2Id);
            builder.setView(dialogLayout).setTitle(R.string.dashboard_grid_size).setPositiveButton(R.string.action_ok, (dialog, id) -> {
                boolean successfullyUpdated = false;
                String widthString = editText.getText().toString();
                String heightString = editText2.getText().toString();
                if (widthString.length() > 0 && heightString.length() > 0) {
                    int width = Integer.parseInt(widthString);
                    int height = Integer.parseInt(heightString);
                    if (width > 0 && height > 0) {
                        SharedPreferences.Editor editor = pref.edit();
                        editor.putInt("dashboard_width", width);
                        editor.putInt("dashboard_height", height);
                        editor.apply();
                        updateDashboardGridSize(true);
                        successfullyUpdated = true;
                    }
                }
                if (!successfullyUpdated)
                    U.showToast(getActivity(), R.string.invalid_grid_size);
            }).setNegativeButton(R.string.action_cancel, null).setNeutralButton(R.string.use_default, (dialog, id) -> {
                pref.edit().remove("dashboard_width").remove("dashboard_height").apply();
                updateDashboardGridSize(true);
            });
            editText.setText(Integer.toString(pref.getInt("dashboard_width", getActivity().getApplicationContext().getResources().getInteger(R.integer.dashboard_width))));
            editText2.setText(Integer.toString(pref.getInt("dashboard_height", getActivity().getApplicationContext().getResources().getInteger(R.integer.dashboard_height))));
            AlertDialog dialog = builder.create();
            dialog.show();
            new Handler().post(() -> {
                InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.showSoftInput(editText2, InputMethodManager.SHOW_IMPLICIT);
            });
            break;
        case "navigation_bar_buttons":
            Intent intent = null;
            switch(pref.getString("theme", "light")) {
                case "light":
                    intent = new Intent(getActivity(), NavigationBarButtonsActivity.class);
                    break;
                case "dark":
                    intent = new Intent(getActivity(), NavigationBarButtonsActivityDark.class);
                    break;
            }
            startActivity(intent);
            break;
        case "secondscreen":
            PackageManager packageManager = getActivity().getPackageManager();
            String packageName = U.getSecondScreenPackageName(getActivity());
            Intent intent2;
            if (packageName == null) {
                intent2 = new Intent(Intent.ACTION_VIEW);
                intent2.setData(Uri.parse("https://play.google.com/store/apps/details?id=com.farmerbb.secondscreen.free"));
            } else
                intent2 = packageManager.getLaunchIntentForPackage(packageName);
            if (intent2 != null) {
                intent2.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                try {
                    startActivity(intent2);
                } catch (ActivityNotFoundException e) {
                /* Gracefully fail */
                }
            }
            break;
    }
    return true;
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) EditText(android.widget.EditText) ClearDataActivity(com.farmerbb.taskbar.activity.ClearDataActivity) SharedPreferences(android.content.SharedPreferences) CheckBoxPreference(android.preference.CheckBoxPreference) Handler(android.os.Handler) Intent(android.content.Intent) InputMethodManager(android.view.inputmethod.InputMethodManager) NavigationBarButtonsActivity(com.farmerbb.taskbar.activity.NavigationBarButtonsActivity) NavigationBarButtonsActivityDark(com.farmerbb.taskbar.activity.dark.NavigationBarButtonsActivityDark) SuppressLint(android.annotation.SuppressLint) ClearDataActivityDark(com.farmerbb.taskbar.activity.dark.ClearDataActivityDark) PackageManager(android.content.pm.PackageManager) ActivityNotFoundException(android.content.ActivityNotFoundException) ComponentName(android.content.ComponentName) LinearLayout(android.widget.LinearLayout) SuppressLint(android.annotation.SuppressLint)

Example 28 with CheckBoxPreference

use of android.support.v7.preference.CheckBoxPreference in project Taskbar by farmerbb.

the class FreeformModeFragment method onPreferenceClick.

@TargetApi(Build.VERSION_CODES.N)
@Override
public boolean onPreferenceClick(final Preference p) {
    final SharedPreferences pref = U.getSharedPreferences(getActivity());
    switch(p.getKey()) {
        case "freeform_hack":
            if (((CheckBoxPreference) p).isChecked()) {
                if (!U.hasFreeformSupport(getActivity())) {
                    try {
                        Settings.Global.putInt(getActivity().getContentResolver(), "enable_freeform_support", 1);
                        U.showToastLong(getActivity(), R.string.reboot_required);
                    } catch (Exception e) {
                        ((CheckBoxPreference) p).setChecked(false);
                        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
                        if (Build.VERSION.SDK_INT > Build.VERSION_CODES.N_MR1) {
                            builder.setTitle(R.string.freeform_dialog_title).setMessage(R.string.freeform_dialog_message_alt).setPositiveButton(R.string.action_continue, (dialogInterface, i) -> freeformSetupComplete());
                        } else {
                            builder.setTitle(R.string.freeform_dialog_title).setMessage(R.string.freeform_dialog_message).setPositiveButton(R.string.action_developer_options, (dialogInterface, i) -> {
                                showReminderToast = true;
                                Intent intent = new Intent(Settings.ACTION_APPLICATION_DEVELOPMENT_SETTINGS);
                                try {
                                    startActivity(intent);
                                    U.showToastLong(getActivity(), R.string.enable_force_activities_resizable);
                                } catch (ActivityNotFoundException e1) {
                                    intent = new Intent(Settings.ACTION_DEVICE_INFO_SETTINGS);
                                    try {
                                        startActivity(intent);
                                        U.showToastLong(getActivity(), R.string.enable_developer_options);
                                    } catch (ActivityNotFoundException e2) {
                                    /* Gracefully fail */
                                    }
                                }
                            });
                        }
                        AlertDialog dialog = builder.create();
                        dialog.show();
                        dialog.setCancelable(false);
                    }
                }
                if (pref.getBoolean("taskbar_active", false) && getActivity().isInMultiWindowMode() && !FreeformHackHelper.getInstance().isFreeformHackActive()) {
                    U.startFreeformHack(getActivity(), false, false);
                }
            } else {
                LocalBroadcastManager.getInstance(getActivity()).sendBroadcast(new Intent("com.farmerbb.taskbar.FINISH_FREEFORM_ACTIVITY"));
                LocalBroadcastManager.getInstance(getActivity()).sendBroadcast(new Intent("com.farmerbb.taskbar.FORCE_TASKBAR_RESTART"));
            }
            U.restartNotificationService(getActivity());
            break;
        case "freeform_mode_help":
            AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
            builder.setView(View.inflate(getActivity(), R.layout.freeform_help_dialog, null)).setTitle(R.string.freeform_help_dialog_title).setPositiveButton(R.string.action_close, null);
            AlertDialog dialog = builder.create();
            dialog.show();
            break;
        case "add_shortcut":
            CompatUtils.pinAppShortcut(getActivity());
            break;
        case "window_size":
            if (U.hasBrokenSetLaunchBoundsApi())
                U.showToastLong(getActivity(), R.string.window_sizes_not_available);
            break;
    }
    return true;
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) Context(android.content.Context) Bundle(android.os.Bundle) R(com.farmerbb.taskbar.R) IntentFilter(android.content.IntentFilter) U(com.farmerbb.taskbar.util.U) Intent(android.content.Intent) CheckBoxPreference(android.preference.CheckBoxPreference) CompatUtils(com.farmerbb.taskbar.util.CompatUtils) LocalBroadcastManager(android.support.v4.content.LocalBroadcastManager) BroadcastReceiver(android.content.BroadcastReceiver) AppCompatActivity(android.support.v7.app.AppCompatActivity) FreeformHackHelper(com.farmerbb.taskbar.util.FreeformHackHelper) AlertDialog(android.support.v7.app.AlertDialog) SharedPreferences(android.content.SharedPreferences) ActivityNotFoundException(android.content.ActivityNotFoundException) Preference(android.preference.Preference) View(android.view.View) Settings(android.provider.Settings) Build(android.os.Build) ActionBar(android.support.v7.app.ActionBar) TargetApi(android.annotation.TargetApi) SharedPreferences(android.content.SharedPreferences) CheckBoxPreference(android.preference.CheckBoxPreference) ActivityNotFoundException(android.content.ActivityNotFoundException) Intent(android.content.Intent) ActivityNotFoundException(android.content.ActivityNotFoundException) TargetApi(android.annotation.TargetApi)

Example 29 with CheckBoxPreference

use of android.support.v7.preference.CheckBoxPreference in project opacclient by opacapp.

the class MainPreferenceFragment method onCreatePreferences.

@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
    this.context = getActivity();
    addPreferencesFromResource(R.xml.settings);
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH || !context.getPackageManager().hasSystemFeature("android.hardware.nfc")) {
        if (findPreference("nfc_search") != null) {
            findPreference("nfc_search").setEnabled(false);
        }
    }
    Preference assistant = findPreference("accounts");
    assistant.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference arg0) {
            ((OpacClient) context.getApplication()).openAccountList(context);
            return false;
        }
    });
    if (!ebooksSupported()) {
        ((PreferenceCategory) findPreference("cat_web_opac")).removePreference(findPreference("email"));
    }
    CheckBoxPreference notification = (CheckBoxPreference) findPreference("notification_service");
    if (notification != null) {
        notification.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

            @Override
            public boolean onPreferenceChange(Preference preference, Object newValue) {
                boolean enabled = (Boolean) newValue;
                new ReminderHelper((OpacClient) getActivity().getApplication()).updateAlarms(enabled);
                return true;
            }
        });
    }
    ListPreference warning = (ListPreference) findPreference("notification_warning");
    if (warning != null) {
        warning.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

            @Override
            public boolean onPreferenceChange(Preference preference, Object newValue) {
                SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
                // int oldWarning = Integer.parseInt(prefs.getString("notification_warning",
                // "3"));
                int newWarning = Integer.parseInt((String) newValue);
                new ReminderHelper((OpacClient) getActivity().getApplication()).updateAlarms(newWarning);
                return true;
            }
        });
    }
    Preference meta_run_check = findPreference("meta_run_check");
    if (meta_run_check != null) {
        meta_run_check.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

            @Override
            public boolean onPreferenceClick(Preference arg0) {
                SyncAccountJob.runImmediately();
                return false;
            }
        });
    }
    Preference meta = findPreference("meta_clear");
    if (meta != null) {
        meta.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

            @Override
            public boolean onPreferenceClick(Preference arg0) {
                AccountDataSource adata = new AccountDataSource(context);
                adata.invalidateCachedData();
                new ReminderHelper((OpacClient) context.getApplication()).updateAlarms(-1);
                SearchFieldDataSource sfdata = new JsonSearchFieldDataSource(context);
                sfdata.clearAll();
                SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getActivity());
                sp.edit().remove("reservation_fee_warning_ignore").apply();
                SyncAccountJob.runImmediately();
                return false;
            }
        });
    }
    final Preference updateLibraryConfig = findPreference("update_library_config");
    if (updateLibraryConfig != null) {
        updateLibraryConfig.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

            @Override
            public boolean onPreferenceClick(Preference preference) {
                IntentFilter successFilter = new IntentFilter(LibraryConfigUpdateService.ACTION_SUCCESS);
                IntentFilter failureFilter = new IntentFilter(LibraryConfigUpdateService.ACTION_FAILURE);
                BroadcastReceiver receiver = new LibraryConfigServiceReceiver(updateLibraryConfig);
                LocalBroadcastManager.getInstance(context).registerReceiver(receiver, successFilter);
                LocalBroadcastManager.getInstance(context).registerReceiver(receiver, failureFilter);
                Intent i = new Intent(context, LibraryConfigUpdateService.class);
                context.startService(i);
                DialogFragment newFragment = ProgressDialogFragment.getInstance(R.string.updating_library_config);
                showDialog(newFragment);
                updateLibraryConfig.setEnabled(false);
                return false;
            }
        });
        refreshLastConfigUpdate(updateLibraryConfig);
    }
    final Preference resetLibraryConfig = findPreference("reset_library_config");
    if (resetLibraryConfig != null) {
        PreferenceDataSource prefs = new PreferenceDataSource(getActivity());
        resetLibraryConfig.setEnabled(prefs.hasBundledConfiguration());
        resetLibraryConfig.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

            @Override
            public boolean onPreferenceClick(Preference preference) {
                LibraryConfigUpdateService.clearConfigurationUpdates(getContext());
                if (getView() != null) {
                    Snackbar.make(getView(), R.string.library_config_reset, Snackbar.LENGTH_SHORT).show();
                    refreshLastConfigUpdate(updateLibraryConfig);
                }
                return false;
            }
        });
    }
}
Also used : IntentFilter(android.content.IntentFilter) AccountDataSource(de.geeksfactory.opacclient.storage.AccountDataSource) CheckBoxPreference(android.support.v7.preference.CheckBoxPreference) SharedPreferences(android.content.SharedPreferences) DialogFragment(android.support.v4.app.DialogFragment) JsonSearchFieldDataSource(de.geeksfactory.opacclient.storage.JsonSearchFieldDataSource) Intent(android.content.Intent) ListPreference(android.support.v7.preference.ListPreference) BroadcastReceiver(android.content.BroadcastReceiver) ReminderHelper(de.geeksfactory.opacclient.reminder.ReminderHelper) SearchFieldDataSource(de.geeksfactory.opacclient.storage.SearchFieldDataSource) JsonSearchFieldDataSource(de.geeksfactory.opacclient.storage.JsonSearchFieldDataSource) CheckBoxPreference(android.support.v7.preference.CheckBoxPreference) ListPreference(android.support.v7.preference.ListPreference) Preference(android.support.v7.preference.Preference) PreferenceCategory(android.support.v7.preference.PreferenceCategory) PreferenceDataSource(de.geeksfactory.opacclient.storage.PreferenceDataSource) LibraryConfigUpdateService(de.geeksfactory.opacclient.webservice.LibraryConfigUpdateService)

Example 30 with CheckBoxPreference

use of android.support.v7.preference.CheckBoxPreference in project vlc-android by GeoffreyMetais.

the class PreferencesExtensionFragment method createCheckboxes.

private void createCheckboxes() {
    preferenceScreen = this.getPreferenceScreen();
    // Main switch
    SwitchPreferenceCompat switchPreference = new SwitchPreferenceCompat(preferenceScreen.getContext());
    switchPreference.setTitle(preferenceScreen.getContext().getString(R.string.extension_prefs_activation_title).toUpperCase());
    switchPreference.setKey(mExtensionKey);
    switchPreference.setChecked(mSettings.getBoolean(mExtensionKey, false));
    switchPreference.setOnPreferenceChangeListener(null);
    preferenceScreen.addPreference(switchPreference);
    // Android-auto
    if (androidAutoAvailable) {
        CheckBoxPreference checkbox = new CheckBoxPreference(preferenceScreen.getContext());
        checkbox.setTitle(R.string.android_auto);
        String key = mExtensionKey + "_" + ExtensionsManager.ANDROID_AUTO_SUFFIX;
        checkbox.setKey(key);
        checkbox.setChecked(switchPreference.isChecked() && mSettings.getBoolean(key, false));
        checkbox.setEnabled(switchPreference.isChecked());
        preferences.add(checkbox);
        preferenceScreen.addPreference(checkbox);
    }
}
Also used : SwitchPreferenceCompat(android.support.v7.preference.SwitchPreferenceCompat) CheckBoxPreference(android.support.v7.preference.CheckBoxPreference)

Aggregations

CheckBoxPreference (android.support.v7.preference.CheckBoxPreference)31 Preference (android.support.v7.preference.Preference)17 ListPreference (android.support.v7.preference.ListPreference)13 Intent (android.content.Intent)10 CheckBoxPreference (android.preference.CheckBoxPreference)8 Context (android.content.Context)7 SharedPreferences (android.content.SharedPreferences)7 OnPreferenceChangeListener (android.support.v7.preference.Preference.OnPreferenceChangeListener)7 Preference (android.preference.Preference)6 AlertDialog (android.support.v7.app.AlertDialog)6 PreferenceScreen (android.support.v7.preference.PreferenceScreen)5 SwitchPreferenceCompat (android.support.v7.preference.SwitchPreferenceCompat)5 Uri (android.net.Uri)4 Build (android.os.Build)4 PreferenceScreen (android.preference.PreferenceScreen)4 View (android.view.View)4 ArrayList (java.util.ArrayList)4 PackageManager (android.content.pm.PackageManager)3 Bundle (android.os.Bundle)3 ListPreference (android.preference.ListPreference)3