Search in sources :

Example 1 with OpacityBar

use of com.larswerkman.holocolorpicker.OpacityBar in project Xposed-Tinted-Status-Bar by MohammadAG.

the class ColorPickerActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Bundle bundle = getIntent().getExtras();
    String prefTitle = bundle.getString("title");
    prefKey = bundle.getString("key");
    prefColor = bundle.getString("color");
    prefEnabled = bundle.getBoolean("enabled");
    setTitle(prefTitle);
    if (Utils.hasActionBar())
        getActionBar().setDisplayHomeAsUpEnabled(true);
    setContentView(R.layout.activity_color_picker);
    final ColorPicker picker = (ColorPicker) findViewById(R.id.picker);
    OpacityBar opacityBar = (OpacityBar) findViewById(R.id.opacitybar);
    SaturationBar saturationBar = (SaturationBar) findViewById(R.id.saturationbar);
    ValueBar valueBar = (ValueBar) findViewById(R.id.valuebar);
    picker.addOpacityBar(opacityBar);
    picker.addSaturationBar(saturationBar);
    picker.addValueBar(valueBar);
    editText = (EditText) findViewById(R.id.edittext);
    picker.setOldCenterColor(Color.parseColor("#ff33b5e5"));
    picker.setOnColorChangedListener(this);
    picker.setColor(Color.parseColor(Utils.addHashIfNeeded(prefColor)));
    Button bPreview = (Button) findViewById(R.id.bPreviewColor);
    bPreview.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            try {
                String textEditString = editText.getText().toString();
                int colourHex;
                if (isFullyTransparent(textEditString)) {
                    colourHex = Color.parseColor("#00000000");
                } else {
                    colourHex = Color.parseColor(Utils.addHashIfNeeded(textEditString));
                    picker.setColor(colourHex);
                }
                ColorDrawable previewDrawable = new ColorDrawable(colourHex);
                if (SettingsKeys.STATUS_BAR_TINT.equals(prefKey) && Utils.hasActionBar()) {
                    getActionBar().setBackgroundDrawable(previewDrawable);
                    /* Workaround, there's no invalidate() method that would redraw the
						 * action bar, and setting the drawable at runtime simply does nothing.
						 */
                    getActionBar().setDisplayShowTitleEnabled(false);
                    getActionBar().setDisplayShowTitleEnabled(true);
                }
                String previewKey;
                Intent intent = new Intent(StatusBarTintApi.INTENT_CHANGE_COLOR_NAME);
                if (SettingsKeys.DEFAULT_NAV_BAR_IM_TINT.equals(prefKey) || SettingsKeys.DEFAULT_NAV_BAR_TINT.equals(prefKey)) {
                    previewKey = SettingsKeys.NAVIGATION_BAR_TINT;
                } else if (SettingsKeys.DEFAULT_STATUS_BAR_TINT.equals(prefKey)) {
                    previewKey = SettingsKeys.STATUS_BAR_TINT;
                } else if (SettingsKeys.DEFAULT_NAV_BAR_ICON_TINT.equals(prefKey) || SettingsKeys.DEFAULT_NAV_BAR_ICON_IM_TINT.equals(prefKey)) {
                    previewKey = SettingsKeys.NAVIGATION_BAR_ICON_TINT;
                } else if (SettingsKeys.DEFAULT_STATUS_BAR_ICON_TINT.equals(prefKey) || SettingsKeys.DEFAULT_STATUS_BAR_INVERTED_ICON_TINT.equals(prefKey)) {
                    if (SettingsKeys.DEFAULT_STATUS_BAR_INVERTED_ICON_TINT.equals(prefKey))
                        intent.putExtra(SettingsKeys.STATUS_BAR_TINT, Color.WHITE);
                    previewKey = SettingsKeys.STATUS_BAR_ICON_TINT;
                } else {
                    previewKey = prefKey;
                }
                intent.putExtra(previewKey, colourHex);
                sendOrderedBroadcast(intent, null);
            } catch (IllegalArgumentException e) {
                Toast.makeText(getApplicationContext(), R.string.invalid_color, Toast.LENGTH_SHORT).show();
            }
        }
    });
    Button bApply = (Button) findViewById(R.id.bApplyColor);
    bApply.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            try {
                Color.parseColor(Utils.addHashIfNeeded(editText.getText().toString()));
                returnResults();
            } catch (IllegalArgumentException e) {
                Toast.makeText(getApplicationContext(), R.string.invalid_color, Toast.LENGTH_SHORT).show();
            }
        }
    });
}
Also used : ColorPicker(com.larswerkman.holocolorpicker.ColorPicker) Bundle(android.os.Bundle) Intent(android.content.Intent) View(android.view.View) ValueBar(com.larswerkman.holocolorpicker.ValueBar) OpacityBar(com.larswerkman.holocolorpicker.OpacityBar) ColorDrawable(android.graphics.drawable.ColorDrawable) Button(android.widget.Button) SaturationBar(com.larswerkman.holocolorpicker.SaturationBar) OnClickListener(android.view.View.OnClickListener)

Aggregations

Intent (android.content.Intent)1 ColorDrawable (android.graphics.drawable.ColorDrawable)1 Bundle (android.os.Bundle)1 View (android.view.View)1 OnClickListener (android.view.View.OnClickListener)1 Button (android.widget.Button)1 ColorPicker (com.larswerkman.holocolorpicker.ColorPicker)1 OpacityBar (com.larswerkman.holocolorpicker.OpacityBar)1 SaturationBar (com.larswerkman.holocolorpicker.SaturationBar)1 ValueBar (com.larswerkman.holocolorpicker.ValueBar)1