Search in sources :

Example 36 with PopupMenu

use of android.support.v7.widget.PopupMenu in project Slide by ccrama.

the class SettingsTheme method onCreate.

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    applyColorTheme();
    setContentView(R.layout.activity_settings_theme);
    setupAppBar(R.id.toolbar, R.string.title_edit_theme, true, true);
    back = new ColorPreferences(SettingsTheme.this).getFontStyle().getThemeType();
    findViewById(R.id.accent).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            LayoutInflater inflater = getLayoutInflater();
            final View dialoglayout = inflater.inflate(R.layout.chooseaccent, null);
            AlertDialogWrapper.Builder builder = new AlertDialogWrapper.Builder(SettingsTheme.this);
            final TextView title = (TextView) dialoglayout.findViewById(R.id.title);
            title.setBackgroundColor(Palette.getDefaultColor());
            final LineColorPicker colorPicker = (LineColorPicker) dialoglayout.findViewById(R.id.picker3);
            int[] arrs = new int[ColorPreferences.getNumColorsFromThemeType(0)];
            int i = 0;
            for (ColorPreferences.Theme type : ColorPreferences.Theme.values()) {
                if (type.getThemeType() == 0) {
                    arrs[i] = ContextCompat.getColor(SettingsTheme.this, type.getColor());
                    i++;
                }
            }
            colorPicker.setColors(arrs);
            colorPicker.setSelectedColor(ContextCompat.getColor(SettingsTheme.this, new ColorPreferences(SettingsTheme.this).getFontStyle().getColor()));
            dialoglayout.findViewById(R.id.ok).setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    SettingsTheme.changed = true;
                    int color = colorPicker.getColor();
                    ColorPreferences.Theme t = null;
                    for (ColorPreferences.Theme type : ColorPreferences.Theme.values()) {
                        if (ContextCompat.getColor(SettingsTheme.this, type.getColor()) == color && back == type.getThemeType()) {
                            t = type;
                            LogUtil.v("Setting to " + t.getTitle());
                            break;
                        }
                    }
                    new ColorPreferences(SettingsTheme.this).setFontStyle(t);
                    Intent i = new Intent(SettingsTheme.this, SettingsTheme.class);
                    i.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
                    startActivity(i);
                    overridePendingTransition(0, 0);
                    finish();
                    overridePendingTransition(0, 0);
                }
            });
            builder.setView(dialoglayout);
            builder.show();
        }
    });
    findViewById(R.id.theme).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            LayoutInflater inflater = getLayoutInflater();
            final View dialoglayout = inflater.inflate(R.layout.choosethemesmall, null);
            AlertDialogWrapper.Builder builder = new AlertDialogWrapper.Builder(SettingsTheme.this);
            final TextView title = (TextView) dialoglayout.findViewById(R.id.title);
            title.setBackgroundColor(Palette.getDefaultColor());
            if (SettingValues.isNight()) {
                dialoglayout.findViewById(R.id.nightmsg).setVisibility(View.VISIBLE);
            }
            dialoglayout.findViewById(R.id.black).setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    SettingsTheme.changed = true;
                    String[] names = new ColorPreferences(SettingsTheme.this).getFontStyle().getTitle().split("_");
                    String name = names[names.length - 1];
                    final String newName = name.replace("(", "");
                    for (ColorPreferences.Theme theme : ColorPreferences.Theme.values()) {
                        if (theme.toString().contains(newName) && theme.getThemeType() == 2) {
                            back = theme.getThemeType();
                            new ColorPreferences(SettingsTheme.this).setFontStyle(theme);
                            Intent i = new Intent(SettingsTheme.this, SettingsTheme.class);
                            i.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
                            startActivity(i);
                            overridePendingTransition(0, 0);
                            finish();
                            overridePendingTransition(0, 0);
                            break;
                        }
                    }
                }
            });
            dialoglayout.findViewById(R.id.light).setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    SettingsTheme.changed = true;
                    String[] names = new ColorPreferences(SettingsTheme.this).getFontStyle().getTitle().split("_");
                    String name = names[names.length - 1];
                    final String newName = name.replace("(", "");
                    for (ColorPreferences.Theme theme : ColorPreferences.Theme.values()) {
                        if (theme.toString().contains(newName) && theme.getThemeType() == 1) {
                            new ColorPreferences(SettingsTheme.this).setFontStyle(theme);
                            back = theme.getThemeType();
                            Intent i = new Intent(SettingsTheme.this, SettingsTheme.class);
                            i.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
                            startActivity(i);
                            overridePendingTransition(0, 0);
                            finish();
                            overridePendingTransition(0, 0);
                            break;
                        }
                    }
                }
            });
            dialoglayout.findViewById(R.id.pixel).setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    SettingsTheme.changed = true;
                    String[] names = new ColorPreferences(SettingsTheme.this).getFontStyle().getTitle().split("_");
                    String name = names[names.length - 1];
                    final String newName = name.replace("(", "");
                    for (ColorPreferences.Theme theme : ColorPreferences.Theme.values()) {
                        if (theme.toString().contains(newName) && theme.getThemeType() == 7) {
                            new ColorPreferences(SettingsTheme.this).setFontStyle(theme);
                            back = theme.getThemeType();
                            Intent i = new Intent(SettingsTheme.this, SettingsTheme.class);
                            i.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
                            startActivity(i);
                            overridePendingTransition(0, 0);
                            finish();
                            overridePendingTransition(0, 0);
                            break;
                        }
                    }
                }
            });
            dialoglayout.findViewById(R.id.dark).setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    SettingsTheme.changed = true;
                    String[] names = new ColorPreferences(SettingsTheme.this).getFontStyle().getTitle().split("_");
                    String name = names[names.length - 1];
                    final String newName = name.replace("(", "");
                    for (ColorPreferences.Theme theme : ColorPreferences.Theme.values()) {
                        if (theme.toString().contains(newName) && theme.getThemeType() == 0) {
                            new ColorPreferences(SettingsTheme.this).setFontStyle(theme);
                            back = theme.getThemeType();
                            Intent i = new Intent(SettingsTheme.this, SettingsTheme.class);
                            i.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
                            startActivity(i);
                            overridePendingTransition(0, 0);
                            finish();
                            overridePendingTransition(0, 0);
                            break;
                        }
                    }
                }
            });
            dialoglayout.findViewById(R.id.blacklighter).setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    SettingsTheme.changed = true;
                    String[] names = new ColorPreferences(SettingsTheme.this).getFontStyle().getTitle().split("_");
                    String name = names[names.length - 1];
                    final String newName = name.replace("(", "");
                    for (ColorPreferences.Theme theme : ColorPreferences.Theme.values()) {
                        if (theme.toString().contains(newName) && theme.getThemeType() == 4) {
                            back = theme.getThemeType();
                            new ColorPreferences(SettingsTheme.this).setFontStyle(theme);
                            Intent i = new Intent(SettingsTheme.this, SettingsTheme.class);
                            i.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
                            startActivity(i);
                            overridePendingTransition(0, 0);
                            finish();
                            overridePendingTransition(0, 0);
                            break;
                        }
                    }
                }
            });
            dialoglayout.findViewById(R.id.deep).setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    SettingsTheme.changed = true;
                    String[] names = new ColorPreferences(SettingsTheme.this).getFontStyle().getTitle().split("_");
                    String name = names[names.length - 1];
                    final String newName = name.replace("(", "");
                    for (ColorPreferences.Theme theme : ColorPreferences.Theme.values()) {
                        if (theme.toString().contains(newName) && theme.getThemeType() == 8) {
                            back = theme.getThemeType();
                            new ColorPreferences(SettingsTheme.this).setFontStyle(theme);
                            Intent i = new Intent(SettingsTheme.this, SettingsTheme.class);
                            i.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
                            startActivity(i);
                            overridePendingTransition(0, 0);
                            finish();
                            overridePendingTransition(0, 0);
                            break;
                        }
                    }
                }
            });
            dialoglayout.findViewById(R.id.sepia).setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    SettingsTheme.changed = true;
                    String[] names = new ColorPreferences(SettingsTheme.this).getFontStyle().getTitle().split("_");
                    String name = names[names.length - 1];
                    final String newName = name.replace("(", "");
                    for (ColorPreferences.Theme theme : ColorPreferences.Theme.values()) {
                        if (theme.toString().contains(newName) && theme.getThemeType() == 5) {
                            back = theme.getThemeType();
                            new ColorPreferences(SettingsTheme.this).setFontStyle(theme);
                            Intent i = new Intent(SettingsTheme.this, SettingsTheme.class);
                            i.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
                            startActivity(i);
                            overridePendingTransition(0, 0);
                            finish();
                            overridePendingTransition(0, 0);
                            break;
                        }
                    }
                }
            });
            dialoglayout.findViewById(R.id.red).setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    SettingsTheme.changed = true;
                    String[] names = new ColorPreferences(SettingsTheme.this).getFontStyle().getTitle().split("_");
                    String name = names[names.length - 1];
                    final String newName = name.replace("(", "");
                    for (ColorPreferences.Theme theme : ColorPreferences.Theme.values()) {
                        if (theme.toString().contains(newName) && theme.getThemeType() == 6) {
                            back = theme.getThemeType();
                            new ColorPreferences(SettingsTheme.this).setFontStyle(theme);
                            Intent i = new Intent(SettingsTheme.this, SettingsTheme.class);
                            i.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
                            startActivity(i);
                            overridePendingTransition(0, 0);
                            finish();
                            overridePendingTransition(0, 0);
                            break;
                        }
                    }
                }
            });
            dialoglayout.findViewById(R.id.blue).setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    SettingsTheme.changed = true;
                    String[] names = new ColorPreferences(SettingsTheme.this).getFontStyle().getTitle().split("_");
                    String name = names[names.length - 1];
                    final String newName = name.replace("(", "");
                    for (ColorPreferences.Theme theme : ColorPreferences.Theme.values()) {
                        if (theme.toString().contains(newName) && theme.getThemeType() == 3) {
                            new ColorPreferences(SettingsTheme.this).setFontStyle(theme);
                            back = theme.getThemeType();
                            Intent i = new Intent(SettingsTheme.this, SettingsTheme.class);
                            i.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
                            startActivity(i);
                            overridePendingTransition(0, 0);
                            finish();
                            overridePendingTransition(0, 0);
                            break;
                        }
                    }
                }
            });
            builder.setView(dialoglayout);
            builder.show();
        }
    });
    findViewById(R.id.main).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            LayoutInflater inflater = getLayoutInflater();
            final View dialoglayout = inflater.inflate(R.layout.choosemain, null);
            AlertDialogWrapper.Builder builder = new AlertDialogWrapper.Builder(SettingsTheme.this);
            final TextView title = (TextView) dialoglayout.findViewById(R.id.title);
            title.setBackgroundColor(Palette.getDefaultColor());
            final LineColorPicker colorPicker = (LineColorPicker) dialoglayout.findViewById(R.id.picker);
            final LineColorPicker colorPicker2 = (LineColorPicker) dialoglayout.findViewById(R.id.picker2);
            colorPicker.setColors(ColorPreferences.getBaseColors(SettingsTheme.this));
            int currentColor = Palette.getDefaultColor();
            for (int i : colorPicker.getColors()) {
                for (int i2 : ColorPreferences.getColors(getBaseContext(), i)) {
                    if (i2 == currentColor) {
                        colorPicker.setSelectedColor(i);
                        colorPicker2.setColors(ColorPreferences.getColors(getBaseContext(), i));
                        colorPicker2.setSelectedColor(i2);
                        break;
                    }
                }
            }
            colorPicker.setOnColorChangedListener(new OnColorChangedListener() {

                @Override
                public void onColorChanged(int c) {
                    SettingsTheme.changed = true;
                    colorPicker2.setColors(ColorPreferences.getColors(getBaseContext(), c));
                    colorPicker2.setSelectedColor(c);
                }
            });
            colorPicker2.setOnColorChangedListener(new OnColorChangedListener() {

                @Override
                public void onColorChanged(int i) {
                    SettingsTheme.changed = true;
                    title.setBackgroundColor(colorPicker2.getColor());
                    if (mToolbar != null)
                        mToolbar.setBackgroundColor(colorPicker2.getColor());
                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                        Window window = getWindow();
                        window.setStatusBarColor(Palette.getDarkerColor(colorPicker2.getColor()));
                    }
                    setRecentBar(getString(R.string.title_theme_settings), colorPicker2.getColor());
                }
            });
            dialoglayout.findViewById(R.id.ok).setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    if (SettingValues.colorIcon) {
                        getPackageManager().setComponentEnabledSetting(new ComponentName(SettingsTheme.this, ColorPreferences.getIconName(SettingsTheme.this, Reddit.colors.getInt("DEFAULTCOLOR", 0))), PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
                        getPackageManager().setComponentEnabledSetting(new ComponentName(SettingsTheme.this, ColorPreferences.getIconName(SettingsTheme.this, colorPicker2.getColor())), PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
                    }
                    Reddit.colors.edit().putInt("DEFAULTCOLOR", colorPicker2.getColor()).apply();
                    Intent i = new Intent(SettingsTheme.this, SettingsTheme.class);
                    i.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
                    startActivity(i);
                    overridePendingTransition(0, 0);
                    finish();
                    overridePendingTransition(0, 0);
                }
            });
            builder.setView(dialoglayout);
            builder.show();
        }
    });
    // Color tinting mode
    final SwitchCompat s2 = (SwitchCompat) findViewById(R.id.tint_everywhere);
    ((TextView) findViewById(R.id.tint_current)).setText(SettingValues.colorBack ? (SettingValues.colorSubName ? getString(R.string.subreddit_name_tint) : getString(R.string.card_background_tint)) : getString(R.string.misc_none));
    boolean enabled = !((TextView) findViewById(R.id.tint_current)).getText().equals(getString(R.string.misc_none));
    findViewById(R.id.dotint).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            PopupMenu popup = new PopupMenu(SettingsTheme.this, v);
            popup.getMenuInflater().inflate(R.menu.color_tinting_mode_settings, popup.getMenu());
            popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {

                public boolean onMenuItemClick(MenuItem item) {
                    switch(item.getItemId()) {
                        case R.id.none:
                            SettingValues.colorBack = false;
                            SettingValues.prefs.edit().putBoolean(SettingValues.PREF_COLOR_BACK, false).apply();
                            break;
                        case R.id.background:
                            SettingValues.colorBack = true;
                            SettingValues.colorSubName = false;
                            SettingValues.prefs.edit().putBoolean(SettingValues.PREF_COLOR_BACK, true).apply();
                            SettingValues.prefs.edit().putBoolean(SettingValues.PREF_COLOR_SUB_NAME, false).apply();
                            break;
                        case R.id.name:
                            SettingValues.colorBack = true;
                            SettingValues.colorSubName = true;
                            SettingValues.prefs.edit().putBoolean(SettingValues.PREF_COLOR_BACK, true).apply();
                            SettingValues.prefs.edit().putBoolean(SettingValues.PREF_COLOR_SUB_NAME, true).apply();
                            break;
                    }
                    ((TextView) findViewById(R.id.tint_current)).setText(SettingValues.colorBack ? (SettingValues.colorSubName ? getString(R.string.subreddit_name_tint) : getString(R.string.card_background_tint)) : getString(R.string.misc_none));
                    boolean enabled = !((TextView) findViewById(R.id.tint_current)).getText().equals(getString(R.string.misc_none));
                    s2.setEnabled(enabled);
                    s2.setChecked(SettingValues.colorEverywhere);
                    s2.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

                        @Override
                        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                            SettingValues.colorEverywhere = isChecked;
                            SettingValues.prefs.edit().putBoolean(SettingValues.PREF_COLOR_EVERYWHERE, isChecked).apply();
                        }
                    });
                    return true;
                }
            });
            popup.show();
        }
    });
    s2.setEnabled(enabled);
    s2.setChecked(SettingValues.colorEverywhere);
    s2.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            SettingValues.colorEverywhere = isChecked;
            SettingValues.prefs.edit().putBoolean(SettingValues.PREF_COLOR_EVERYWHERE, isChecked).apply();
        }
    });
    final SwitchCompat colorNavbarSwitch = (SwitchCompat) findViewById(R.id.color_navigation_bar);
    colorNavbarSwitch.setChecked(SettingValues.colorNavBar);
    colorNavbarSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            SettingsTheme.changed = true;
            SettingValues.colorNavBar = isChecked;
            SettingValues.prefs.edit().putBoolean(SettingValues.PREF_COLOR_NAV_BAR, isChecked).apply();
            themeSystemBars("");
            if (!isChecked) {
                getWindow().setNavigationBarColor(Color.TRANSPARENT);
            }
        }
    });
    final SwitchCompat colorIcon = (SwitchCompat) findViewById(R.id.color_icon);
    colorIcon.setChecked(SettingValues.colorIcon);
    colorIcon.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            SettingValues.colorIcon = isChecked;
            SettingValues.prefs.edit().putBoolean(SettingValues.PREF_COLOR_ICON, isChecked).apply();
            if (isChecked) {
                getPackageManager().setComponentEnabledSetting(new ComponentName(SettingsTheme.this, Slide.class.getPackage().getName() + ".Slide"), PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
                getPackageManager().setComponentEnabledSetting(new ComponentName(SettingsTheme.this, ColorPreferences.getIconName(SettingsTheme.this, Reddit.colors.getInt("DEFAULTCOLOR", 0))), PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
            } else {
                getPackageManager().setComponentEnabledSetting(new ComponentName(SettingsTheme.this, ColorPreferences.getIconName(SettingsTheme.this, Reddit.colors.getInt("DEFAULTCOLOR", 0))), PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
                getPackageManager().setComponentEnabledSetting(new ComponentName(SettingsTheme.this, Slide.class.getPackage().getName() + ".Slide"), PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
            }
        }
    });
    LinearLayout nightMode = (LinearLayout) findViewById(R.id.night);
    assert nightMode != null;
    nightMode.setOnClickListener(new OnSingleClickListener() {

        @Override
        public void onSingleClick(View view) {
            if (SettingValues.tabletUI) {
                LayoutInflater inflater = getLayoutInflater();
                final View dialoglayout = inflater.inflate(R.layout.nightmode, null);
                final AlertDialogWrapper.Builder builder = new AlertDialogWrapper.Builder(SettingsTheme.this);
                final Dialog dialog = builder.setView(dialoglayout).create();
                dialog.show();
                dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {

                    @Override
                    public void onDismiss(DialogInterface dialog) {
                    // todo save
                    }
                });
                SwitchCompat s = (SwitchCompat) dialog.findViewById(R.id.enabled);
                s.setChecked(SettingValues.nightMode);
                s.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

                    @Override
                    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                        SettingValues.nightMode = isChecked;
                        SettingValues.prefs.edit().putBoolean(SettingValues.PREF_NIGHT_MODE, isChecked).apply();
                        SettingsTheme.changed = true;
                    }
                });
                switch(SettingValues.nightTheme) {
                    case 0:
                        ((RadioButton) dialoglayout.findViewById(R.id.dark)).setChecked(true);
                        break;
                    case 2:
                        ((RadioButton) dialoglayout.findViewById(R.id.amoled)).setChecked(true);
                        break;
                    case 3:
                        ((RadioButton) dialoglayout.findViewById(R.id.blue)).setChecked(true);
                        break;
                    case 6:
                        ((RadioButton) dialoglayout.findViewById(R.id.red)).setChecked(true);
                        break;
                    case 4:
                        ((RadioButton) dialoglayout.findViewById(R.id.amoled_contrast)).setChecked(true);
                        break;
                    default:
                        ((RadioButton) dialoglayout.findViewById(R.id.dark)).setChecked(true);
                        break;
                }
                ((RadioButton) dialoglayout.findViewById(R.id.dark)).setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

                    @Override
                    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                        if (isChecked) {
                            SettingsTheme.changed = true;
                            SettingValues.nightTheme = 0;
                            SettingValues.prefs.edit().putInt(SettingValues.PREF_NIGHT_THEME, 0).apply();
                        }
                    }
                });
                ((RadioButton) dialoglayout.findViewById(R.id.amoled)).setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

                    @Override
                    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                        if (isChecked) {
                            SettingsTheme.changed = true;
                            SettingValues.nightTheme = 2;
                            SettingValues.prefs.edit().putInt(SettingValues.PREF_NIGHT_THEME, 2).apply();
                        }
                    }
                });
                ((RadioButton) dialoglayout.findViewById(R.id.red)).setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

                    @Override
                    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                        if (isChecked) {
                            SettingsTheme.changed = true;
                            SettingValues.nightTheme = 6;
                            SettingValues.prefs.edit().putInt(SettingValues.PREF_NIGHT_THEME, 6).apply();
                        }
                    }
                });
                ((RadioButton) dialoglayout.findViewById(R.id.blue)).setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

                    @Override
                    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                        if (isChecked) {
                            SettingsTheme.changed = true;
                            SettingValues.nightTheme = 3;
                            SettingValues.prefs.edit().putInt(SettingValues.PREF_NIGHT_THEME, 3).apply();
                        }
                    }
                });
                ((RadioButton) dialoglayout.findViewById(R.id.amoled_contrast)).setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

                    @Override
                    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                        if (isChecked) {
                            SettingsTheme.changed = true;
                            SettingValues.nightTheme = 4;
                            SettingValues.prefs.edit().putInt(SettingValues.PREF_NIGHT_THEME, 4).apply();
                        }
                    }
                });
                {
                    final List<String> timesStart = new ArrayList<String>() {

                        {
                            add("6pm");
                            add("7pm");
                            add("8pm");
                            add("9pm");
                            add("10pm");
                            add("11pm");
                        }
                    };
                    final Spinner startSpinner = (Spinner) dialoglayout.findViewById(R.id.start_spinner);
                    final ArrayAdapter<String> startAdapter = new ArrayAdapter<>(SettingsTheme.this, android.R.layout.simple_spinner_item, timesStart);
                    startAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
                    startSpinner.setAdapter(startAdapter);
                    // set the currently selected pref
                    startSpinner.setSelection(startAdapter.getPosition(Integer.toString(SettingValues.nightStart).concat("pm")));
                    startSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

                        @Override
                        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                            // get the time, but remove the "pm" from the string when parsing
                            final int time = Integer.parseInt(((String) startSpinner.getItemAtPosition(position)).replaceAll("pm", ""));
                            SettingValues.nightStart = time;
                            SettingValues.prefs.edit().putInt(SettingValues.PREF_NIGHT_START, time).apply();
                        }

                        @Override
                        public void onNothingSelected(AdapterView<?> parent) {
                        }
                    });
                }
                {
                    final List<String> timesEnd = new ArrayList<String>() {

                        {
                            add("12am");
                            add("1am");
                            add("2am");
                            add("3am");
                            add("4am");
                            add("5am");
                            add("6am");
                            add("7am");
                            add("8am");
                            add("9am");
                            add("10am");
                        }
                    };
                    final Spinner endSpinner = (Spinner) dialoglayout.findViewById(R.id.end_spinner);
                    final ArrayAdapter<String> endAdapter = new ArrayAdapter<>(SettingsTheme.this, android.R.layout.simple_spinner_item, timesEnd);
                    endAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
                    endSpinner.setAdapter(endAdapter);
                    // set the currently selected pref
                    endSpinner.setSelection(endAdapter.getPosition(Integer.toString(SettingValues.nightEnd).concat("am")));
                    endSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

                        @Override
                        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                            // get the time, but remove the "am" from the string when parsing
                            final int time = Integer.parseInt(((String) endSpinner.getItemAtPosition(position)).replaceAll("am", ""));
                            SettingValues.nightEnd = time;
                            SettingValues.prefs.edit().putInt(SettingValues.PREF_NIGHT_END, time).apply();
                        }

                        @Override
                        public void onNothingSelected(AdapterView<?> parent) {
                        }
                    });
                }
                {
                    Button okayButton = (Button) dialoglayout.findViewById(R.id.ok);
                    okayButton.setOnClickListener(new View.OnClickListener() {

                        @Override
                        public void onClick(View v) {
                            dialog.dismiss();
                        }
                    });
                }
            } else {
                new AlertDialogWrapper.Builder(SettingsTheme.this).setTitle(R.string.general_nighttheme_ispro).setMessage(R.string.pro_upgrade_msg).setPositiveButton(R.string.btn_yes_exclaim, new DialogInterface.OnClickListener() {

                    public void onClick(DialogInterface dialog, int whichButton) {
                        try {
                            startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=me.ccrama.slideforreddittabletuiunlock")));
                        } catch (android.content.ActivityNotFoundException anfe) {
                            startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://play.google.com/store/apps/details?id=me.ccrama.slideforreddittabletuiunlock")));
                        }
                    }
                }).setNegativeButton(R.string.btn_no_danks, new DialogInterface.OnClickListener() {

                    public void onClick(DialogInterface dialog, int whichButton) {
                    }
                }).show();
            }
        }
    });
}
Also used : DialogInterface(android.content.DialogInterface) Spinner(android.widget.Spinner) OnSingleClickListener(me.ccrama.redditslide.util.OnSingleClickListener) ArrayList(java.util.ArrayList) AlertDialogWrapper(com.afollestad.materialdialogs.AlertDialogWrapper) RadioButton(android.widget.RadioButton) Button(android.widget.Button) CompoundButton(android.widget.CompoundButton) Dialog(android.app.Dialog) TextView(android.widget.TextView) ComponentName(android.content.ComponentName) Window(android.view.Window) ColorPreferences(me.ccrama.redditslide.ColorPreferences) Intent(android.content.Intent) MenuItem(android.view.MenuItem) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) LineColorPicker(uz.shift.colorpicker.LineColorPicker) OnColorChangedListener(uz.shift.colorpicker.OnColorChangedListener) LayoutInflater(android.view.LayoutInflater) AdapterView(android.widget.AdapterView) CompoundButton(android.widget.CompoundButton) LinearLayout(android.widget.LinearLayout) ArrayAdapter(android.widget.ArrayAdapter) SwitchCompat(android.support.v7.widget.SwitchCompat) PopupMenu(android.support.v7.widget.PopupMenu)

Example 37 with PopupMenu

use of android.support.v7.widget.PopupMenu in project Slide by ccrama.

the class SettingsViewType method onCreate.

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    applyColorTheme();
    setContentView(R.layout.activity_settings_viewtype);
    setupAppBar(R.id.toolbar, R.string.settings_view_type, true, true);
    // View type multi choice
    ((TextView) findViewById(R.id.currentViewType)).setText(SettingValues.single ? (SettingValues.commentPager ? getString(R.string.view_type_comments) : getString(R.string.view_type_none)) : getString(R.string.view_type_tabs));
    findViewById(R.id.viewtype).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            PopupMenu popup = new PopupMenu(SettingsViewType.this, v);
            popup.getMenuInflater().inflate(R.menu.view_type_settings, popup.getMenu());
            popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {

                public boolean onMenuItemClick(MenuItem item) {
                    switch(item.getItemId()) {
                        case R.id.tabs:
                            SettingValues.single = false;
                            SettingValues.prefs.edit().putBoolean(SettingValues.PREF_SINGLE, false).apply();
                            break;
                        case R.id.notabs:
                            SettingValues.single = true;
                            SettingValues.commentPager = false;
                            SettingValues.prefs.edit().putBoolean(SettingValues.PREF_SINGLE, true).apply();
                            SettingValues.prefs.edit().putBoolean(SettingValues.PREF_COMMENT_PAGER, false).apply();
                            break;
                        case R.id.comments:
                            SettingValues.single = true;
                            SettingValues.commentPager = true;
                            SettingValues.prefs.edit().putBoolean(SettingValues.PREF_SINGLE, true).apply();
                            SettingValues.prefs.edit().putBoolean(SettingValues.PREF_COMMENT_PAGER, true).apply();
                            break;
                    }
                    ((TextView) findViewById(R.id.currentViewType)).setText(SettingValues.single ? (SettingValues.commentPager ? getString(R.string.view_type_comments) : getString(R.string.view_type_none)) : getString(R.string.view_type_tabs));
                    SettingsTheme.changed = true;
                    return true;
                }
            });
            popup.show();
        }
    });
}
Also used : TextView(android.widget.TextView) MenuItem(android.view.MenuItem) TextView(android.widget.TextView) View(android.view.View) PopupMenu(android.support.v7.widget.PopupMenu)

Example 38 with PopupMenu

use of android.support.v7.widget.PopupMenu in project Slide by ccrama.

the class SettingsHandling method onCreate.

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    applyColorTheme();
    setContentView(R.layout.activity_settings_handling);
    setupAppBar(R.id.toolbar, R.string.settings_link_handling, true, true);
    TextView web = (TextView) findViewById(R.id.browser);
    // todo web stuff
    SwitchCompat image = (SwitchCompat) findViewById(R.id.image);
    SwitchCompat gif = (SwitchCompat) findViewById(R.id.gif);
    SwitchCompat album = (SwitchCompat) findViewById(R.id.album);
    SwitchCompat peek = (SwitchCompat) findViewById(R.id.peek);
    SwitchCompat shortlink = (SwitchCompat) findViewById(R.id.shortlink);
    image.setChecked(SettingValues.image);
    gif.setChecked(SettingValues.gif);
    album.setChecked(SettingValues.album);
    peek.setChecked(SettingValues.peek);
    shortlink.setChecked(!SettingValues.shareLongLink);
    image.setOnCheckedChangeListener(this);
    gif.setOnCheckedChangeListener(this);
    album.setOnCheckedChangeListener(this);
    peek.setOnCheckedChangeListener(this);
    shortlink.setOnCheckedChangeListener(this);
    if (!Reddit.videoPlugin) {
        findViewById(R.id.video).setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                try {
                    startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=ccrama.me.slideyoutubeplugin")));
                } catch (android.content.ActivityNotFoundException anfe) {
                    startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://play.google.com/store/apps/details?id=ccrama.me.slideyoutubeplugin")));
                }
            }
        });
    } else {
        findViewById(R.id.video).setVisibility(View.GONE);
    }
    ((TextView) findViewById(R.id.browser)).setText(SettingValues.firefox ? getString(R.string.firefox) : SettingValues.web ? SettingValues.reader ? getString(R.string.handling_reader_mode) : (SettingValues.customtabs ? getString(R.string.settings_link_chrome) : getString(R.string.handling_internal_browser)) : getString(R.string.handling_external_browser));
    final SwitchCompat readernight = (SwitchCompat) findViewById(R.id.readernight);
    readernight.setEnabled(SettingValues.nightMode && SettingValues.web && SettingValues.reader);
    readernight.setChecked(SettingValues.readerNight);
    readernight.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            SettingValues.readerNight = isChecked;
            SettingValues.prefs.edit().putBoolean(SettingValues.PREF_READER_NIGHT, isChecked).apply();
        }
    });
    findViewById(R.id.select_browser).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            PopupMenu popup = new PopupMenu(SettingsHandling.this, v);
            if (Reddit.firefox) {
                popup.getMenuInflater().inflate(R.menu.browser_type_firefox, popup.getMenu());
            } else {
                popup.getMenuInflater().inflate(R.menu.browser_type, popup.getMenu());
            }
            popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {

                public boolean onMenuItemClick(MenuItem item) {
                    switch(item.getItemId()) {
                        case R.id.firefox:
                            SettingValues.customtabs = false;
                            SettingValues.web = true;
                            SettingValues.reader = false;
                            SettingValues.firefox = true;
                            SettingValues.prefs.edit().putBoolean(SettingValues.PREFS_WEB, true).apply();
                            SettingValues.prefs.edit().putBoolean(SettingValues.PREF_READER, false).apply();
                            SettingValues.prefs.edit().putBoolean(SettingValues.PREF_CUSTOMTABS, false).apply();
                            SettingValues.prefs.edit().putBoolean(SettingValues.PREF_FIREFOX, true).apply();
                            break;
                        case R.id.chrome:
                            SettingValues.customtabs = true;
                            SettingValues.web = true;
                            SettingValues.reader = false;
                            SettingValues.firefox = false;
                            SettingValues.prefs.edit().putBoolean(SettingValues.PREFS_WEB, true).apply();
                            SettingValues.prefs.edit().putBoolean(SettingValues.PREF_READER, false).apply();
                            SettingValues.prefs.edit().putBoolean(SettingValues.PREF_CUSTOMTABS, true).apply();
                            SettingValues.prefs.edit().putBoolean(SettingValues.PREF_FIREFOX, true).apply();
                            break;
                        case R.id.internal:
                            SettingValues.customtabs = false;
                            SettingValues.web = true;
                            SettingValues.reader = false;
                            SettingValues.firefox = false;
                            SettingValues.prefs.edit().putBoolean(SettingValues.PREFS_WEB, true).apply();
                            SettingValues.prefs.edit().putBoolean(SettingValues.PREF_READER, false).apply();
                            SettingValues.prefs.edit().putBoolean(SettingValues.PREF_CUSTOMTABS, false).apply();
                            SettingValues.prefs.edit().putBoolean(SettingValues.PREF_FIREFOX, true).apply();
                            break;
                        case R.id.reader:
                            SettingValues.customtabs = false;
                            SettingValues.web = true;
                            SettingValues.reader = true;
                            SettingValues.firefox = false;
                            SettingValues.prefs.edit().putBoolean(SettingValues.PREFS_WEB, true).apply();
                            SettingValues.prefs.edit().putBoolean(SettingValues.PREF_READER, true).apply();
                            SettingValues.prefs.edit().putBoolean(SettingValues.PREF_CUSTOMTABS, false).apply();
                            SettingValues.prefs.edit().putBoolean(SettingValues.PREF_FIREFOX, true).apply();
                            break;
                        case R.id.external:
                            SettingValues.web = false;
                            SettingValues.reader = false;
                            SettingValues.firefox = false;
                            SettingValues.prefs.edit().putBoolean(SettingValues.PREFS_WEB, false).apply();
                            SettingValues.prefs.edit().putBoolean(SettingValues.PREF_READER, false).apply();
                            SettingValues.prefs.edit().putBoolean(SettingValues.PREF_FIREFOX, true).apply();
                            break;
                    }
                    ((TextView) findViewById(R.id.browser)).setText(SettingValues.firefox ? getString(R.string.firefox) : SettingValues.web ? SettingValues.reader ? getString(R.string.handling_reader_mode) : (SettingValues.customtabs ? getString(R.string.settings_link_chrome) : getString(R.string.handling_internal_browser)) : getString(R.string.handling_external_browser));
                    readernight.setEnabled(SettingValues.nightMode && SettingValues.web && SettingValues.reader);
                    return true;
                }
            });
            popup.show();
        }
    });
    domain = (EditText) findViewById(R.id.domain);
    domain.setOnEditorActionListener(new EditText.OnEditorActionListener() {

        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_DONE) {
                SettingValues.alwaysExternal = SettingValues.alwaysExternal + ", " + domain.getText().toString();
                domain.setText("");
                updateFilters();
            }
            return false;
        }
    });
    updateFilters();
}
Also used : EditText(android.widget.EditText) Intent(android.content.Intent) MenuItem(android.view.MenuItem) TextView(android.widget.TextView) View(android.view.View) KeyEvent(android.view.KeyEvent) TextView(android.widget.TextView) CompoundButton(android.widget.CompoundButton) SwitchCompat(android.support.v7.widget.SwitchCompat) PopupMenu(android.support.v7.widget.PopupMenu)

Example 39 with PopupMenu

use of android.support.v7.widget.PopupMenu in project MTweaks-KernelAdiutorMOD by morogoku.

the class InitdFragment method load.

private void load(List<RecyclerViewItem> items) {
    for (final String initd : Initd.list()) {
        CardView cardView = new CardView(getActivity());
        cardView.setOnMenuListener(new CardView.OnMenuListener() {

            @Override
            public void onMenuReady(CardView cardView, PopupMenu popupMenu) {
                Menu menu = popupMenu.getMenu();
                menu.add(Menu.NONE, 0, Menu.NONE, getString(R.string.edit));
                menu.add(Menu.NONE, 1, Menu.NONE, getString(R.string.delete));
                popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {

                    @Override
                    public boolean onMenuItemClick(MenuItem item) {
                        switch(item.getItemId()) {
                            case 0:
                                mEditInitd = initd;
                                Intent intent = new Intent(getActivity(), EditorActivity.class);
                                intent.putExtra(EditorActivity.TITLE_INTENT, initd);
                                intent.putExtra(EditorActivity.TEXT_INTENT, Initd.read(initd));
                                startActivityForResult(intent, 0);
                                break;
                            case 1:
                                mDeleteDialog = ViewUtils.dialogBuilder(getString(R.string.sure_question), new DialogInterface.OnClickListener() {

                                    @Override
                                    public void onClick(DialogInterface dialogInterface, int i) {
                                    }
                                }, new DialogInterface.OnClickListener() {

                                    @Override
                                    public void onClick(DialogInterface dialogInterface, int i) {
                                        Initd.delete(initd);
                                        reload();
                                    }
                                }, new DialogInterface.OnDismissListener() {

                                    @Override
                                    public void onDismiss(DialogInterface dialogInterface) {
                                        mDeleteDialog = null;
                                    }
                                }, getActivity());
                                mDeleteDialog.show();
                                break;
                        }
                        return false;
                    }
                });
            }
        });
        DescriptionView descriptionView = new DescriptionView();
        descriptionView.setSummary(initd);
        descriptionView.setOnItemClickListener(new RecyclerViewItem.OnItemClickListener() {

            @Override
            public void onClick(RecyclerViewItem item) {
                mExecuteDialog = ViewUtils.dialogBuilder(getString(R.string.exceute_question, initd), new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                    }
                }, new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        execute(initd);
                    }
                }, new DialogInterface.OnDismissListener() {

                    @Override
                    public void onDismiss(DialogInterface dialogInterface) {
                        mExecuteDialog = null;
                    }
                }, getActivity());
                mExecuteDialog.show();
            }
        });
        cardView.addItem(descriptionView);
        items.add(cardView);
    }
}
Also used : DialogInterface(android.content.DialogInterface) CardView(com.moro.mtweaks.views.recyclerview.CardView) MenuItem(android.view.MenuItem) Intent(android.content.Intent) RecyclerViewItem(com.moro.mtweaks.views.recyclerview.RecyclerViewItem) DescriptionView(com.moro.mtweaks.views.recyclerview.DescriptionView) Menu(android.view.Menu) PopupMenu(android.support.v7.widget.PopupMenu) PopupMenu(android.support.v7.widget.PopupMenu)

Example 40 with PopupMenu

use of android.support.v7.widget.PopupMenu in project MTweaks-KernelAdiutorMOD by morogoku.

the class CustomControlsFragment method getCard.

private CardView getCard(final Controls.ControlItem controlItem) {
    CardView cardView = new CardView(getActivity());
    cardView.setOnMenuListener(new CardView.OnMenuListener() {

        @Override
        public void onMenuReady(CardView cardView, PopupMenu popupMenu) {
            Menu menu = popupMenu.getMenu();
            menu.add(Menu.NONE, 0, Menu.NONE, getString(R.string.edit));
            final MenuItem onBoot = menu.add(Menu.NONE, 1, Menu.NONE, getString(R.string.on_boot)).setCheckable(true);
            onBoot.setChecked(controlItem.isOnBootEnabled());
            menu.add(Menu.NONE, 2, Menu.NONE, getString(R.string.export));
            menu.add(Menu.NONE, 3, Menu.NONE, getString(R.string.delete));
            popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {

                @Override
                public boolean onMenuItemClick(MenuItem item) {
                    switch(item.getItemId()) {
                        case 0:
                            edit(controlItem);
                            break;
                        case 1:
                            onBoot.setChecked(!onBoot.isChecked());
                            controlItem.enableOnBoot(onBoot.isChecked());
                            mControlsProvider.commit();
                            break;
                        case 2:
                            mExportItem = controlItem;
                            requestPermission(0, Manifest.permission.WRITE_EXTERNAL_STORAGE);
                            break;
                        case 3:
                            mDeleteDialog = ViewUtils.dialogBuilder(getString(R.string.sure_question), new DialogInterface.OnClickListener() {

                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                }
                            }, new DialogInterface.OnClickListener() {

                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    delete(controlItem.getUniqueId());
                                }
                            }, new DialogInterface.OnDismissListener() {

                                @Override
                                public void onDismiss(DialogInterface dialog) {
                                    mDeleteDialog = null;
                                }
                            }, getActivity()).setTitle(getString(R.string.delete));
                            mDeleteDialog.show();
                            break;
                    }
                    return false;
                }
            });
        }
    });
    return cardView;
}
Also used : DialogInterface(android.content.DialogInterface) CardView(com.moro.mtweaks.views.recyclerview.CardView) MenuItem(android.view.MenuItem) Menu(android.view.Menu) PopupMenu(android.support.v7.widget.PopupMenu) PopupMenu(android.support.v7.widget.PopupMenu)

Aggregations

PopupMenu (android.support.v7.widget.PopupMenu)142 MenuItem (android.view.MenuItem)116 View (android.view.View)86 TextView (android.widget.TextView)63 RecyclerView (android.support.v7.widget.RecyclerView)54 ImageView (android.widget.ImageView)40 Intent (android.content.Intent)32 PopupMenu (android.widget.PopupMenu)31 List (java.util.List)27 ArrayList (java.util.ArrayList)26 MenuInflater (android.view.MenuInflater)23 Menu (android.view.Menu)22 Bundle (android.os.Bundle)20 LayoutInflater (android.view.LayoutInflater)20 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)20 Context (android.content.Context)18 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)18 AdapterView (android.widget.AdapterView)17 DialogInterface (android.content.DialogInterface)16 ViewGroup (android.view.ViewGroup)15