Example usage for android.graphics.drawable GradientDrawable setColor

List of usage examples for android.graphics.drawable GradientDrawable setColor

Introduction

In this page you can find the example usage for android.graphics.drawable GradientDrawable setColor.

Prototype

public void setColor(@Nullable ColorStateList colorStateList) 

Source Link

Document

Changes this drawable to use a single color state list instead of a gradient.

Usage

From source file:com.skydoves.elasticviewsexample.ElasticVIews.ElasticLayout.java

private void setTypeArray(TypedArray typedArray) {
    GradientDrawable bgShape = (GradientDrawable) view.getBackground();

    round = typedArray.getInt(R.styleable.ElasticLayout_layout_round, round);
    bgShape.setCornerRadius(round);/*from   w ww  . ja va  2 s.c  o  m*/

    color = typedArray.getInt(R.styleable.ElasticLayout_layout_backgroundColor, color);
    bgShape.setColor(color);

    scale = typedArray.getFloat(R.styleable.ElasticLayout_layout_scale, scale);

    duration = typedArray.getInt(R.styleable.ElasticLayout_layout_duration, duration);
}

From source file:com.android.julia.todolist.adapter.TodoCursorAdapter.java

/**
 * Called by the RecyclerView to display data at a specified position in the Cursor.
 *
 * @param holder   The ViewHolder to bind Cursor data to
 * @param position The position of the data in the Cursor
 *//*from   w w w .j  a v  a 2 s .c o  m*/
@Override
public void onBindViewHolder(final TaskViewHolder holder, final int position) {

    // Indices for the _id, description, and priority columns
    int idIndex = mCursor.getColumnIndex(TaskContract.TaskEntry._ID);
    int descriptionIndex = mCursor.getColumnIndex(TaskContract.TaskEntry.COLUMN_DESCRIPTION);
    int priorityIndex = mCursor.getColumnIndex(TaskContract.TaskEntry.COLUMN_PRIORITY);

    mCursor.moveToPosition(position); // get to the right location in the cursor

    // Determine the values of the wanted data
    final int id = mCursor.getInt(idIndex);
    final String description = mCursor.getString(descriptionIndex);
    final int priority = mCursor.getInt(priorityIndex);

    // Set values
    holder.itemView.setTag(id);
    holder.taskDescriptionView.setText(description);

    // Programmatically set the text and color for the priority TextView
    String priorityString = "";
    switch (priority) {
    case 1:
        priorityString = holder.itemView.getResources().getString(R.string.high_priority);
        break;
    case 2:
        priorityString = holder.itemView.getResources().getString(R.string.med_priority);
        break;
    case 3:
        priorityString = holder.itemView.getResources().getString(R.string.low_priority);
        break;
    }
    holder.priorityView.setText(priorityString);

    GradientDrawable priorityCircle = (GradientDrawable) holder.priorityView.getBackground();
    // Get the appropriate background color based on the priority
    int priorityColor = getPriorityColor(priority);
    priorityCircle.setColor(priorityColor);

    // Add listener for item click
    holder.itemView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mListener.onTaskClick(v, (int) holder.itemView.getTag(), description, priority);
        }
    });
}

From source file:com.skydoves.elasticviewsexample.ElasticVIews.ElasticButton.java

private void setTypeArray(TypedArray typedArray) {
    GradientDrawable bgShape = (GradientDrawable) view.getBackground();

    round = typedArray.getInt(R.styleable.ElasticButton_button_round, round);
    bgShape.setCornerRadius(round);/*from w  w  w  .  j a va 2  s. c  o  m*/

    color = typedArray.getInt(R.styleable.ElasticButton_button_backgroundColor, color);
    bgShape.setColor(color);

    scale = typedArray.getFloat(R.styleable.ElasticButton_button_scale, scale);

    duration = typedArray.getInt(R.styleable.ElasticButton_button_duration, duration);

    labelText = typedArray.getString(R.styleable.ElasticButton_button_labelText);
    view.setText(labelText);

    labelColor = typedArray.getInt(R.styleable.ElasticButton_button_labelColor, labelColor);
    view.setTextColor(labelColor);

    labelSize = typedArray.getInt(R.styleable.ElasticButton_button_labelSize, labelSize);
    view.setTextSize(labelSize);

    labelStyle = typedArray.getInt(R.styleable.ElasticButton_button_labelStyle, labelStyle);

    if (labelStyle == 0)
        view.setTypeface(null, Typeface.NORMAL);
    else if (labelStyle == 1)
        view.setTypeface(null, Typeface.BOLD);
    else if (labelStyle == 2)
        view.setTypeface(null, Typeface.ITALIC);
}

From source file:net.nurik.roman.formwatchface.CompanionWatchFaceConfigActivity.java

private void setupThemeList() {
    mThemeUiHolders.clear();//from  ww w  . ja  v  a 2  s  .c  o  m
    mThemeItemContainer = (ViewGroup) findViewById(R.id.theme_list);
    LayoutInflater inflater = LayoutInflater.from(this);
    for (final Theme theme : Themes.THEMES) {
        ThemeUiHolder holder = new ThemeUiHolder();

        holder.theme = theme;
        holder.container = inflater.inflate(R.layout.config_theme_item, mThemeItemContainer, false);
        holder.button = (ImageButton) holder.container.findViewById(R.id.button);

        LayerDrawable bgDrawable = (LayerDrawable) getResources().getDrawable(R.drawable.theme_item_bg)
                .mutate();

        GradientDrawable gd = (GradientDrawable) bgDrawable.findDrawableByLayerId(R.id.color);
        gd.setColor(getResources().getColor(theme.midRes));
        holder.button.setBackground(bgDrawable);

        holder.button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                updateAndPersistTheme(theme);
            }
        });

        mThemeUiHolders.add(holder);
        mThemeItemContainer.addView(holder.container);
    }

    loadMuzei();
}

From source file:fr.outadev.skinswitch.DetailActivity.java

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void colorRipple(int id, int tintColor) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        FloatingActionButton buttonView = (FloatingActionButton) findViewById(id);

        RippleDrawable ripple = (RippleDrawable) buttonView.getBackground();
        GradientDrawable rippleBackground = (GradientDrawable) ripple.getDrawable(0);
        rippleBackground.setColor(getResources().getColor(R.color.colorPrimary));

        ripple.setColor(ColorStateList.valueOf(tintColor));
    }//from  w  w  w.  jav a 2 s  .  co  m
}

From source file:com.commit451.springy.CompanionWatchFaceConfigActivity.java

private void setupThemeList() {
    mThemeUiHolders.clear();//  w  ww .j  av a  2  s .  c o m
    mThemeItemContainer = (ViewGroup) findViewById(R.id.theme_list);
    LayoutInflater inflater = LayoutInflater.from(this);
    for (final Themes.Theme theme : Themes.THEMES) {
        ThemeUiHolder holder = new ThemeUiHolder();

        holder.theme = theme;
        holder.container = inflater.inflate(R.layout.config_theme_item, mThemeItemContainer, false);
        holder.button = (ImageButton) holder.container.findViewById(R.id.button);

        LayerDrawable bgDrawable = (LayerDrawable) getResources().getDrawable(R.drawable.theme_item_bg)
                .mutate();

        GradientDrawable gd = (GradientDrawable) bgDrawable.findDrawableByLayerId(R.id.color);
        gd.setColor(theme.color);
        holder.button.setBackground(bgDrawable);

        holder.button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                updateAndPersistTheme(theme);
            }
        });

        mThemeUiHolders.add(holder);
        mThemeItemContainer.addView(holder.container);
    }

    loadMuzei();
}

From source file:org.dalol.orthodoxmezmurmedia.utilities.widgets.RecyclerViewFastIndexer.java

protected void init(Context context) {
    if (isInitialized)
        return;//  w  w  w  .  ja  v a  2 s .  c o m
    isInitialized = true;
    setOrientation(HORIZONTAL);
    setClipChildren(false);
    setWillNotDraw(false);

    bubble = new TextView(context);
    bubble.setTextColor(Color.WHITE);
    bubble.setTextSize(48);

    GradientDrawable bubbleDrawable = new GradientDrawable();
    bubbleDrawable.setColor(0xFFce891e);
    bubbleDrawable.setSize(getCustomSize(88), getCustomSize(88));
    bubbleDrawable.setCornerRadii(new float[] { getCustomSize(44), getCustomSize(44), getCustomSize(44),
            getCustomSize(44), 0, 0, getCustomSize(44), getCustomSize(44) });

    bubble.setBackgroundDrawable(bubbleDrawable);

    //bubble.setBackgroundResource(R.drawable.recycler_view_fast_scroller__bubble);
    bubble.setGravity(Gravity.CENTER);

    LayoutParams params = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    params.gravity = Gravity.RIGHT | Gravity.END;

    addView(bubble, params);

    if (bubble != null)
        bubble.setVisibility(INVISIBLE);

    handle = new ImageView(context);
    //handle.setBackgroundResource(R.drawable.recycler_view_fast_scroller__handle);

    GradientDrawable drawable = new GradientDrawable();
    drawable.setShape(GradientDrawable.RECTANGLE);
    drawable.setSize(getCustomSize(4), getCustomSize(35));
    drawable.setColor(0xFFce891e);
    drawable.setCornerRadius(getCustomSize(5));

    GradientDrawable drawable2 = new GradientDrawable();
    drawable2.setShape(GradientDrawable.RECTANGLE);
    drawable2.setSize(getCustomSize(4), getCustomSize(35));
    drawable2.setColor(0xFFf3a124);
    drawable2.setCornerRadius(getCustomSize(5));

    StateListDrawable states = new StateListDrawable();
    states.addState(new int[] { android.R.attr.state_selected }, drawable);
    states.addState(new int[] {}, drawable2);

    handle.setBackgroundDrawable(states);

    LayoutParams params2 = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);

    int dimension = getCustomSize(3);

    int doubleDimension = dimension * 2;
    params2.leftMargin = doubleDimension;
    params2.rightMargin = doubleDimension;

    handle.setPadding(dimension, 0, dimension, 0);
    handle.setOnFocusChangeListener(new OnFocusChangeListener() {
        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if (hasFocus) {
                v.setBackgroundColor(Color.parseColor("#00891e"));
            } else {
                v.setBackgroundColor(Color.parseColor("#44891e"));
            }
        }
    });

    addView(handle, params2);

}

From source file:com.odoo.addons.customers.CustomerDetails.java

private void setColor(int color) {
    FrameLayout frameLayout = (FrameLayout) findViewById(R.id.parallax_view);
    frameLayout.setBackgroundColor(color);
    parallaxScrollView.setParallaxOverLayColor(color);
    parallaxScrollView.setBackgroundColor(color);
    mForm.setIconTintColor(color);/*  ww w  .j a v  a  2s  .  com*/
    findViewById(R.id.parallax_view).setBackgroundColor(color);
    findViewById(R.id.parallax_view_edit).setBackgroundColor(color);
    findViewById(R.id.customerScrollViewEdit).setBackgroundColor(color);
    if (captureImage != null) {
        GradientDrawable shapeDrawable = (GradientDrawable) getResources()
                .getDrawable(R.drawable.circle_mask_primary);
        shapeDrawable.setColor(color);
        captureImage.setBackgroundDrawable(shapeDrawable);
    }
}

From source file:ro.expectations.expenses.ui.transactions.TransactionsAdapter.java

@Override
public void onBindViewHolder(ViewHolder holder, int position) {
    mCursor.moveToPosition(position);//from  w ww.  j a  v  a 2  s  . c  o  m

    long fromAccountId = mCursor.getLong(TransactionsFragment.COLUMN_FROM_ACCOUNT_ID);
    long toAccountId = mCursor.getLong(TransactionsFragment.COLUMN_TO_ACCOUNT_ID);

    if (fromAccountId > 0 && toAccountId > 0) {
        processTransfer(holder, position);
    } else {
        if (fromAccountId > 0) {
            processDebit(holder, position);
        } else {
            processCredit(holder, position);
        }
    }

    // Set the row background
    ListHelper.setItemBackground(mContext, holder.itemView, isItemSelected(position),
            holder.mTransactionIconBackground, holder.mSelectedIconBackground);

    // Set the description
    StringBuilder description = new StringBuilder();
    long categoryId = mCursor.getLong(TransactionsFragment.COLUMN_CATEGORY_ID);
    if (categoryId == -1) {
        description.append(mContext.getString(R.string.multiple_categories));
    } else {
        String category = mCursor.getString(TransactionsFragment.COLUMN_CATEGORY_NAME);
        if (category != null && !category.isEmpty()) {
            description.append(category);
        }
    }
    String parentCategory = mCursor.getString(TransactionsFragment.COLUMN_PARENT_CATEGORY_NAME);
    if (parentCategory != null && !parentCategory.isEmpty()) {
        description.insert(0, "  ");
        description.insert(0, parentCategory);
    }

    StringBuilder additionalDescription = new StringBuilder();
    String payeeName = mCursor.getString(TransactionsFragment.COLUMN_PAYEE_NAME);
    if (payeeName != null && !payeeName.isEmpty()) {
        additionalDescription.append(payeeName);
    }
    String note = mCursor.getString(TransactionsFragment.COLUMN_NOTE);
    if (note != null && !note.isEmpty()) {
        if (additionalDescription.length() > 0) {
            additionalDescription.append(": ");
        }
        additionalDescription.append(note);
    }
    if (description.length() > 0 && additionalDescription.length() > 0) {
        additionalDescription.insert(0, " (");
        additionalDescription.append(")");
    }
    if (additionalDescription.length() > 0) {
        description.append(additionalDescription.toString());
    }
    if (description.length() == 0) {
        if (fromAccountId > 0 && toAccountId > 0) {
            description.append(mContext.getString(R.string.default_transfer_description));
        } else {
            long fromAmount = mCursor.getLong(TransactionsFragment.COLUMN_FROM_AMOUNT);
            if (fromAmount > 0) {
                description.append(mContext.getString(R.string.default_debit_description));
            } else {
                description.append(mContext.getString(R.string.default_credit_description));
            }
        }
    }
    holder.mDescription.setText(description.toString());

    // Set the transaction date
    long transactionDate = mCursor.getLong(TransactionsFragment.COLUMN_OCCURED_AT);
    if (transactionDate == 0) {
        transactionDate = mCursor.getLong(TransactionsFragment.COLUMN_CREATED_AT);
    }
    holder.mDate.setText(DateUtils.getRelativeTimeSpanString(transactionDate, System.currentTimeMillis(),
            DateUtils.DAY_IN_MILLIS));

    // Set the icon
    if (fromAccountId > 0 && toAccountId > 0) {
        holder.mTransactionIcon.setImageDrawable(
                DrawableHelper.tint(mContext, R.drawable.ic_transfer_black_24dp, R.color.colorWhite));
    } else {
        holder.mTransactionIcon.setImageDrawable(
                DrawableHelper.tint(mContext, R.drawable.ic_question_mark_black_24dp, R.color.colorWhite));
    }
    GradientDrawable bgShape = (GradientDrawable) holder.mTransactionIconBackground.getBackground();
    bgShape.setColor(0xFF000000 | ContextCompat.getColor(mContext, R.color.colorPrimary));
}

From source file:im.vector.adapters.RoomViewHolder.java

/**
 * Refresh the holder layout/*from   w  w w.  j a  v a  2  s  .co  m*/
 *
 * @param room                   the room
 * @param isDirectChat           true when the room is a direct chat one
 * @param isInvitation           true when the room is an invitation one
 * @param moreRoomActionListener
 */
public void populateViews(final Context context, final MXSession session, final Room room,
        final boolean isDirectChat, final boolean isInvitation,
        final AbsAdapter.MoreRoomActionListener moreRoomActionListener) {
    // sanity check
    if (null == room) {
        Log.e(LOG_TAG, "## populateViews() : null room");
        return;
    }

    if (null == session) {
        Log.e(LOG_TAG, "## populateViews() : null session");
        return;
    }

    if (null == session.getDataHandler()) {
        Log.e(LOG_TAG, "## populateViews() : null dataHandler");
        return;
    }

    IMXStore store = session.getDataHandler().getStore(room.getRoomId());

    if (null == store) {
        Log.e(LOG_TAG, "## populateViews() : null Store");
        return;
    }

    final RoomSummary roomSummary = store.getSummary(room.getRoomId());

    if (null == roomSummary) {
        Log.e(LOG_TAG, "## populateViews() : null roomSummary");
        return;
    }

    int unreadMsgCount = roomSummary.getUnreadEventsCount();
    int highlightCount;
    int notificationCount;

    // Setup colors
    int mFuchsiaColor = ContextCompat.getColor(context, R.color.vector_fuchsia_color);
    int mGreenColor = ContextCompat.getColor(context, R.color.vector_green_color);
    int mSilverColor = ContextCompat.getColor(context, R.color.vector_silver_color);

    highlightCount = roomSummary.getHighlightCount();
    notificationCount = roomSummary.getNotificationCount();

    // fix a crash reported by GA
    if ((null != room.getDataHandler())
            && room.getDataHandler().getBingRulesManager().isRoomMentionOnly(room.getRoomId())) {
        notificationCount = highlightCount;
    }

    int bingUnreadColor;
    if (isInvitation || (0 != highlightCount)) {
        bingUnreadColor = mFuchsiaColor;
    } else if (0 != notificationCount) {
        bingUnreadColor = mGreenColor;
    } else if (0 != unreadMsgCount) {
        bingUnreadColor = mSilverColor;
    } else {
        bingUnreadColor = Color.TRANSPARENT;
    }

    if (isInvitation || (notificationCount > 0)) {
        vRoomUnreadCount.setText(isInvitation ? "!" : RoomUtils.formatUnreadMessagesCounter(notificationCount));
        vRoomUnreadCount.setTypeface(null, Typeface.BOLD);
        GradientDrawable shape = new GradientDrawable();
        shape.setShape(GradientDrawable.RECTANGLE);
        shape.setCornerRadius(100);
        shape.setColor(bingUnreadColor);
        vRoomUnreadCount.setBackground(shape);
        vRoomUnreadCount.setVisibility(View.VISIBLE);
    } else {
        vRoomUnreadCount.setVisibility(View.GONE);
    }

    String roomName = VectorUtils.getRoomDisplayName(context, session, room);
    if (vRoomNameServer != null) {
        // This view holder is for the home page, we have up to two lines to display the name
        if (MXSession.isRoomAlias(roomName)) {
            // Room alias, split to display the server name on second line
            final String[] roomAliasSplitted = roomName.split(":");
            final String firstLine = roomAliasSplitted[0] + ":";
            final String secondLine = roomAliasSplitted[1];
            vRoomName.setLines(1);
            vRoomName.setText(firstLine);
            vRoomNameServer.setText(secondLine);
            vRoomNameServer.setVisibility(View.VISIBLE);
            vRoomNameServer.setTypeface(null, (0 != unreadMsgCount) ? Typeface.BOLD : Typeface.NORMAL);
        } else {
            // Allow the name to take two lines
            vRoomName.setLines(2);
            vRoomNameServer.setVisibility(View.GONE);
            vRoomName.setText(roomName);
        }
    } else {
        vRoomName.setText(roomName);
    }
    vRoomName.setTypeface(null, (0 != unreadMsgCount) ? Typeface.BOLD : Typeface.NORMAL);

    VectorUtils.loadRoomAvatar(context, session, vRoomAvatar, room);

    // get last message to be displayed
    if (vRoomLastMessage != null) {
        CharSequence lastMsgToDisplay = RoomUtils.getRoomMessageToDisplay(context, session, roomSummary);
        vRoomLastMessage.setText(lastMsgToDisplay);
    }

    if (mDirectChatIndicator != null) {
        mDirectChatIndicator.setVisibility(isDirectChat ? View.VISIBLE : View.INVISIBLE);
    }
    vRoomEncryptedIcon.setVisibility(room.isEncrypted() ? View.VISIBLE : View.INVISIBLE);

    if (vRoomUnreadIndicator != null) {
        // set bing view background colour
        vRoomUnreadIndicator.setBackgroundColor(bingUnreadColor);
        vRoomUnreadIndicator.setVisibility(roomSummary.isInvited() ? View.INVISIBLE : View.VISIBLE);
    }

    if (vRoomTimestamp != null) {
        vRoomTimestamp.setText(RoomUtils.getRoomTimestamp(context, roomSummary.getLatestReceivedEvent()));
    }

    if (vRoomMoreActionClickArea != null && vRoomMoreActionAnchor != null) {
        vRoomMoreActionClickArea.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (null != moreRoomActionListener) {
                    moreRoomActionListener.onMoreActionClick(vRoomMoreActionAnchor, room);
                }
            }
        });
    }
}