Example usage for android.content.res ColorStateList ColorStateList

List of usage examples for android.content.res ColorStateList ColorStateList

Introduction

In this page you can find the example usage for android.content.res ColorStateList ColorStateList.

Prototype

public ColorStateList(int[][] states, @ColorInt int[] colors) 

Source Link

Document

Creates a ColorStateList that returns the specified mapping from states to colors.

Usage

From source file:com.thatkawaiiguy.meleehandbook.adapter.SearchAdapter.java

private void highlightAndCut(String search, String originalText, TextView textView) {
    int startPos = originalText.toLowerCase().indexOf(search);
    int endPos = startPos + search.length();

    int wholeStart = originalText.toLowerCase().indexOf(" ", startPos - 100);
    if (wholeStart == -1)
        wholeStart = 0;/*from   w ww.j av  a2  s .c o  m*/

    if (originalText.substring(wholeStart, wholeStart + 1).equals(","))
        wholeStart += 1;

    int wholeEnd = originalText.toLowerCase().indexOf(" ",
            endPos + 100 < originalText.length() - 1 ? endPos + 100 : endPos - search.length() - 1);

    if (wholeEnd == -1)
        wholeEnd = endPos;

    originalText = originalText.substring(wholeStart, wholeEnd).trim() + " (Click for more)";

    startPos = originalText.toLowerCase().indexOf(search);
    endPos = startPos + search.length();
    // This should always be true, just a sanity check
    if (startPos != -1) {
        Spannable spannable = new SpannableString(originalText);
        ColorStateList yellowColor = new ColorStateList(new int[][] { new int[] {} },
                new int[] { ContextCompat.getColor(mContext, R.color.overscroll_color) });
        TextAppearanceSpan highlightSpan = new TextAppearanceSpan(null, Typeface.BOLD, -1, yellowColor, null);

        spannable.setSpan(highlightSpan, startPos, endPos, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        textView.setText(spannable);
    } else
        textView.setText(originalText);
}

From source file:nl.hnogames.domoticz.UI.FingerprintPasswordDialog.java

public void show() {
    mdb.title(mContext.getString(R.string.welcome_remote_server_password));
    md = mdb.build();/*  ww  w . j  a  v a 2  s .com*/
    View view = md.getCustomView();

    editPassword = (FloatingLabelEditText) view.findViewById(R.id.password);
    showPassword = (CheckBox) view.findViewById(R.id.showpassword);

    if (mSharedPrefs.darkThemeEnabled()) {
        showPassword.setTextColor(ContextCompat.getColor(mContext, R.color.white));
        editPassword.setInputWidgetTextColor(ContextCompat.getColor(mContext, R.color.white));
        int[][] states = new int[][] { new int[] { android.R.attr.state_activated },
                new int[] { -android.R.attr.state_activated } };
        int[] colors = new int[] { Color.WHITE, Color.WHITE };
        editPassword.setLabelTextColor(new ColorStateList(states, colors));
    }

    showPassword.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            // checkbox status is changed from uncheck to checked.
            if (!isChecked) {
                // show password
                editPassword.getInputWidget()
                        .setTransformationMethod(PasswordTransformationMethod.getInstance());
            } else {
                // hide password
                editPassword.getInputWidget()
                        .setTransformationMethod(HideReturnsTransformationMethod.getInstance());
            }
        }
    });

    md.show();
}

From source file:com.androidinspain.deskclock.timer.TimerSetupView.java

@Override
protected void onFinishInflate() {
    super.onFinishInflate();

    mTimeView = (TextView) findViewById(R.id.timer_setup_time);
    mDeleteView = findViewById(R.id.timer_setup_delete);
    mDividerView = findViewById(R.id.timer_setup_divider);
    mDigitViews = new TextView[] { (TextView) findViewById(R.id.timer_setup_digit_0),
            (TextView) findViewById(R.id.timer_setup_digit_1),
            (TextView) findViewById(R.id.timer_setup_digit_2),
            (TextView) findViewById(R.id.timer_setup_digit_3),
            (TextView) findViewById(R.id.timer_setup_digit_4),
            (TextView) findViewById(R.id.timer_setup_digit_5),
            (TextView) findViewById(R.id.timer_setup_digit_6),
            (TextView) findViewById(R.id.timer_setup_digit_7),
            (TextView) findViewById(R.id.timer_setup_digit_8),
            (TextView) findViewById(R.id.timer_setup_digit_9), };

    // Tint the divider to match the disabled control color by default and used the activated
    // control color when there is valid input.
    final Context dividerContext = mDividerView.getContext();
    final int colorControlActivated = ThemeUtils.resolveColor(dividerContext, R.attr.colorControlActivated);
    final int colorControlDisabled = ThemeUtils.resolveColor(dividerContext, R.attr.colorControlNormal,
            new int[] { ~android.R.attr.state_enabled });
    ViewCompat.setBackgroundTintList(mDividerView,
            new ColorStateList(new int[][] { { android.R.attr.state_activated }, {} },
                    new int[] { colorControlActivated, colorControlDisabled }));
    ViewCompat.setBackgroundTintMode(mDividerView, PorterDuff.Mode.SRC);

    // Initialize the digit buttons.
    final UiDataModel uidm = UiDataModel.getUiDataModel();
    for (final TextView digitView : mDigitViews) {
        final int digit = getDigitForId(digitView.getId());
        digitView.setText(uidm.getFormattedNumber(digit, 1));
        digitView.setOnClickListener(this);
    }/*w w  w .  j ava  2s .  c  om*/

    mDeleteView.setOnClickListener(this);
    mDeleteView.setOnLongClickListener(this);

    updateTime();
    updateDeleteAndDivider();
}

From source file:com.fa.mastodon.fragment.ComposeOptionsFragment.java

private static void setRadioButtonDrawable(Context context, RadioButton button, @DrawableRes int id) {
    ColorStateList list = new ColorStateList(
            new int[][] { new int[] { -android.R.attr.state_checked },
                    new int[] { android.R.attr.state_checked } },
            new int[] { ThemeUtils.getColor(context, R.attr.compose_image_button_tint),
                    ThemeUtils.getColor(context, R.attr.colorAccent) });
    Drawable drawable = VectorDrawableCompat.create(context.getResources(), id, context.getTheme());
    if (drawable == null) {
        return;/*from   w w w  . j  a  va2  s.co m*/
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        button.setButtonTintList(list);
    } else {
        drawable = DrawableCompat.wrap(drawable);
        DrawableCompat.setTintList(drawable, list);
    }
    button.setButtonDrawable(drawable);
}

From source file:org.opensilk.common.ui.widget.FloatingActionButton.java

protected ColorStateList createRippleStateList() {
    int[][] states = new int[1][];
    int[] colors = new int[1];
    states[0] = new int[0];
    colors[0] = mColorPressed;//from  w  w w . j  ava  2 s .  c o  m
    return new ColorStateList(states, colors);
}

From source file:org.gnucash.android.ui.report.ReportSummaryFragment.java

@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    setHasOptionsMenu(true);/*from   w w  w.j  av  a 2  s .  c om*/

    mChart.setCenterTextSize(PieChartFragment.CENTER_TEXT_SIZE);
    mChart.setDescription("");
    mChart.getLegend().setEnabled(true);
    mChart.getLegend().setPosition(Legend.LegendPosition.RIGHT_OF_CHART_CENTER);
    mChart.getLegend().setTextSize(LEGEND_TEXT_SIZE);

    ColorStateList csl = new ColorStateList(new int[][] { new int[0] },
            new int[] { getResources().getColor(R.color.account_green) });
    setButtonTint(mPieChartButton, csl);
    csl = new ColorStateList(new int[][] { new int[0] },
            new int[] { getResources().getColor(R.color.account_red) });
    setButtonTint(mBarChartButton, csl);
    csl = new ColorStateList(new int[][] { new int[0] },
            new int[] { getResources().getColor(R.color.account_blue) });
    setButtonTint(mLineChartButton, csl);
    csl = new ColorStateList(new int[][] { new int[0] },
            new int[] { getResources().getColor(R.color.account_purple) });
    setButtonTint(mBalanceSheetButton, csl);

    List<AccountType> accountTypes = new ArrayList<>();
    accountTypes.add(AccountType.ASSET);
    accountTypes.add(AccountType.CASH);
    accountTypes.add(AccountType.BANK);
    Money assetsBalance = mAccountsDbAdapter.getAccountBalance(accountTypes, -1, System.currentTimeMillis());

    accountTypes.clear();
    accountTypes.add(AccountType.LIABILITY);
    accountTypes.add(AccountType.CREDIT);
    Money liabilitiesBalance = mAccountsDbAdapter.getAccountBalance(accountTypes, -1,
            System.currentTimeMillis());

    TransactionsActivity.displayBalance(mTotalAssets, assetsBalance);
    TransactionsActivity.displayBalance(mTotalLiabilities, liabilitiesBalance);
    TransactionsActivity.displayBalance(mNetWorth, assetsBalance.subtract(liabilitiesBalance));

    displayChart();
}

From source file:com.doctoror.fuckoffmusicplayer.presentation.util.BindingAdapters.java

@NonNull
private static ColorStateList activatedTint(@NonNull final Context context, @ColorInt final int tintNormal) {

    final int[][] states = new int[][] { new int[] { android.R.attr.state_activated }, new int[0] };

    final int[] colors = new int[] { ThemeUtils.getColor(context.getTheme(), R.attr.colorAccent), tintNormal };

    return new ColorStateList(states, colors);
}

From source file:com.owncloud.android.ui.activity.FingerprintActivity.java

private void startFingerprint() {
    TextView fingerprintTextView = (TextView) findViewById(R.id.scanfingerprinttext);

    FingerprintManager fingerprintManager = (FingerprintManager) MainApp.getAppContext()
            .getSystemService(Context.FINGERPRINT_SERVICE);

    if (ActivityCompat.checkSelfPermission(this,
            Manifest.permission.USE_FINGERPRINT) != PackageManager.PERMISSION_GRANTED) {
        return;//from w  ww.j  a  va 2s .c  o m
    }
    KeyguardManager keyguardManager = (KeyguardManager) getSystemService(KEYGUARD_SERVICE);

    if (!keyguardManager.isKeyguardSecure()) {
        return;
    } else {
        generateKey();

        if (cipherInit()) {
            cryptoObject = new FingerprintManager.CryptoObject(cipher);
            FingerprintHandler.Callback callback = new FingerprintHandler.Callback() {
                @Override
                public void onAuthenticated() {
                    fingerprintResult(true);
                }

                @Override
                public void onFailed(String error) {
                    Toast.makeText(MainApp.getAppContext(), error, Toast.LENGTH_LONG).show();
                    ImageView imageView = (ImageView) findViewById(R.id.fingerprinticon);
                    int[][] states = new int[][] { new int[] { android.R.attr.state_activated },
                            new int[] { -android.R.attr.state_activated } };
                    int[] colors = new int[] { Color.parseColor("#FF0000"), Color.RED };
                    ColorStateList csl = new ColorStateList(states, colors);
                    Drawable drawable = DrawableCompat.wrap(imageView.getDrawable());
                    DrawableCompat.setTintList(drawable, csl);
                    imageView.setImageDrawable(drawable);
                }
            };

            helper = new FingerprintHandler(fingerprintTextView, callback);
            cancellationSignal = new CancellationSignal();
            if (ActivityCompat.checkSelfPermission(MainApp.getAppContext(),
                    Manifest.permission.USE_FINGERPRINT) != PackageManager.PERMISSION_GRANTED) {
                return;
            }
            fingerprintManager.authenticate(cryptoObject, cancellationSignal, 0, helper, null);
        }
    }
}

From source file:nl.hnogames.domoticz.UI.SecurityPanelDialog.java

public void show() {
    mdb.title(panelInfo.getName());/* www  .  jav a  2s  .c  om*/
    md = mdb.build();
    View view = md.getCustomView();

    if (view != null) {
        editPinCode = (FloatingLabelEditText) view.findViewById(R.id.securitypin);
        editPinCode.getInputWidget().setTransformationMethod(PasswordTransformationMethod.getInstance());

        btnDisarm = (Button) view.findViewById(R.id.disarm);
        btnArmHome = (Button) view.findViewById(R.id.armhome);
        btnArmAway = (Button) view.findViewById(R.id.armaway);
        txtCountDown = (TextView) view.findViewById(R.id.countdown);

        if (mSharedPrefs.darkThemeEnabled()) {
            btnDisarm.setBackground(ContextCompat.getDrawable(mContext, R.drawable.button_status_dark));
            btnArmHome.setBackground(ContextCompat.getDrawable(mContext, R.drawable.button_status_dark));
            btnArmAway.setBackground(ContextCompat.getDrawable(mContext, R.drawable.button_status_dark));
            editPinCode.setInputWidgetTextColor(ContextCompat.getColor(mContext, R.color.white));

            int[][] states = new int[][] { new int[] { android.R.attr.state_activated },
                    new int[] { -android.R.attr.state_activated } };
            int[] colors = new int[] { Color.WHITE, Color.WHITE };
            editPinCode.setLabelTextColor(new ColorStateList(states, colors));
        }
    }
    domoticz.getSettings(new SettingsReceiver() {
        @Override
        public void onReceiveSettings(SettingsInfo settings) {
            mSettings = settings;
            md.show();
        }

        @Override
        public void onError(Exception error) {
            Log.e(TAG, domoticz.getErrorMessage(error));
            md.dismiss();
        }
    });

    btnDisarm.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            processRequest(DomoticzValues.Security.Status.DISARM);
        }
    });
    btnArmAway.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            processRequest(DomoticzValues.Security.Status.ARMAWAY);
        }
    });
    btnArmHome.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            processRequest(DomoticzValues.Security.Status.ARMHOME);
        }
    });
}

From source file:org.opensilk.common.ui.util.ThemeUtils.java

public static ColorStateList getDefaultColorStateList(Context context) {
    /**/*from   w w  w .  j av a2s.  c  om*/
     * Generate the default color state list which uses the colorControl attributes.
     * Order is important here. The default enabled state needs to go at the bottom.
     */

    final int colorControlNormal = getThemeAttrColor(context, R.attr.colorControlNormal);
    final int colorControlActivated = getThemeAttrColor(context, R.attr.colorControlActivated);

    final int[][] states = new int[7][];
    final int[] colors = new int[7];
    int i = 0;

    // Disabled state
    states[i] = new int[] { -android.R.attr.state_enabled };
    colors[i] = getDisabledThemeAttrColor(context, R.attr.colorControlNormal);
    i++;

    states[i] = new int[] { android.R.attr.state_focused };
    colors[i] = colorControlActivated;
    i++;

    states[i] = new int[] { android.R.attr.state_activated };
    colors[i] = colorControlActivated;
    i++;

    states[i] = new int[] { android.R.attr.state_pressed };
    colors[i] = colorControlActivated;
    i++;

    states[i] = new int[] { android.R.attr.state_checked };
    colors[i] = colorControlActivated;
    i++;

    states[i] = new int[] { android.R.attr.state_selected };
    colors[i] = colorControlActivated;
    i++;

    // Default enabled state
    states[i] = new int[0];
    colors[i] = colorControlNormal;
    i++;
    return new ColorStateList(states, colors);
}