android.support.v7.widget.AppCompatDrawableManager Java Examples

The following examples show how to use android.support.v7.widget.AppCompatDrawableManager. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FloatingActionMenu.java    From AppCompat-Extension-Library with Apache License 2.0 6 votes vote down vote up
private void init(Context context, AttributeSet attributeSet) {
    mButtonSpacing = getResources().getDimensionPixelSize(R.dimen.fam_spacing);
    mLabelsMargin = getResources().getDimensionPixelSize(R.dimen.fam_label_spacing);
    mLabelsVerticalOffset = 0;

    TypedArray attr = context.obtainStyledAttributes(attributeSet, R.styleable.FloatingActionMenu, 0, 0);
    mExpandDirection = attr.getInt(R.styleable.FloatingActionMenu_fabMenuExpandDirection, EXPAND_UP);
    mLabelsPosition = attr.getInt(R.styleable.FloatingActionMenu_fabMenuLabelPosition, LABELS_ON_LEFT_SIDE);
    mLabelsStyle = attr.getResourceId(R.styleable.FloatingActionMenu_fabMenuLabelStyle, 0);
    int mCloseDrawableResourceId = attr.getResourceId(R.styleable.FloatingActionMenu_fabMenuCloseIconSrc, 0);
    mCloseDrawable = mCloseDrawableResourceId == 0 ? null : AppCompatDrawableManager.get().getDrawable(getContext(), mCloseDrawableResourceId);
    mCloseAngle = attr.getFloat(R.styleable.FloatingActionMenu_fabMenuCloseIconAngle, 0);
    mButtonSpacing = attr.getDimensionPixelSize(R.styleable.FloatingActionMenu_fabMenuSpacing, mButtonSpacing);
    attr.recycle();

    if (mLabelsStyle != 0 && expandsHorizontally()) {
        throw new IllegalStateException("Action labels in horizontal expand orientation is not supported.");
    }

    // So we can catch the back button
    setFocusableInTouchMode(true);
}
 
Example #2
Source File: PickerThemeUtils.java    From AppCompat-Extension-Library with Apache License 2.0 6 votes vote down vote up
public static void setNavButtonDrawable(Context context, ImageButton left, ImageButton right,
                                        int monthTextAppearanceResId) {
    // Retrieve the previous and next drawables
    AppCompatDrawableManager dm = AppCompatDrawableManager.get();
    Drawable prevDrawable = dm.getDrawable(context, R.drawable.ic_chevron_left_black_24dp);
    Drawable nextDrawable = dm.getDrawable(context, R.drawable.ic_chevron_right_black_24dp);

    // Proxy the month text color into the previous and next drawables.
    final TypedArray ta = context.obtainStyledAttributes(null,
            new int[]{android.R.attr.textColor}, 0, monthTextAppearanceResId);
    final ColorStateList monthColor = ta.getColorStateList(0);
    if (monthColor != null) {
        DrawableCompat.setTint(DrawableCompat.wrap(prevDrawable), monthColor.getDefaultColor());
        DrawableCompat.setTint(DrawableCompat.wrap(nextDrawable), monthColor.getDefaultColor());
    }
    ta.recycle();

    // Set the previous and next drawables
    left.setImageDrawable(prevDrawable);
    right.setImageDrawable(nextDrawable);
}
 
Example #3
Source File: StickerRenderer.java    From Game-of-Thrones with Apache License 2.0 6 votes vote down vote up
@Override
public void render() {
  Message message = getContent();

  Uri sticker = ((StickerPayLoad) message.getPayload()).getSticker();
  stickerImageView.setImageURI(sticker);

  if (message.isFromMe()) {
    avatarImageView.setVisibility(View.GONE);
    rootView.setGravity(Gravity.BOTTOM | Gravity.END);
  } else {
    avatarImageView.setVisibility(View.VISIBLE);
    rootView.setGravity(Gravity.BOTTOM | Gravity.START);

    imageLoader.builder()
        .load(message.getUser().getImageUrl())
        .placeHolder(AppCompatDrawableManager.get().getDrawable(avatarImageView.getContext(),
            R.drawable.ned_head_light))
        .into(avatarImageView)
        .circle()
        .show();
  }
}
 
Example #4
Source File: MessageRenderer.java    From Game-of-Thrones with Apache License 2.0 6 votes vote down vote up
private void displayPayLoad(Payload payload) {
  if (payload instanceof ImagePayload) {
    ImagePayload imagePayload = (ImagePayload) payload;
    imageLoader.builder()
        .load(imagePayload.getImageMessage())
        .placeHolder(AppCompatDrawableManager.get().getDrawable(avatarImageView.getContext(),
            R.drawable.ned_head_light))
        .into(messageImageView)
        .show();
  } else {
    messageImageView.setVisibility(View.GONE);
  }

  TextPayLoad textPayload = (TextPayLoad) payload;
  Spannable textMessage = textPayload.getTextMessage();
  messageTextView.setText(textMessage);
}
 
Example #5
Source File: MessageRenderer.java    From Game-of-Thrones with Apache License 2.0 6 votes vote down vote up
private void renderMessageFromOthers(Message message) {
  User user = message.getUser();
  rootView.setGravity(Gravity.BOTTOM | Gravity.START);
  displayNameTextView.setVisibility(View.VISIBLE);
  avatarImageView.setVisibility(View.VISIBLE);

  imageLoader.builder()
      .load(user.getImageUrl())
      .placeHolder(AppCompatDrawableManager.get().getDrawable(avatarImageView.getContext(),
          R.drawable.ned_head_light))
      .into(avatarImageView)
      .circle()
      .show();

  displayNameTextView.setText(user.getName());
  displayPayLoad(message.getPayload());
  messageContainer.setBackgroundResource(R.drawable.background_message_from_others);
}
 
Example #6
Source File: AnimatedPencil.java    From AnimatedPencil with Apache License 2.0 5 votes vote down vote up
private void init(Context context, AttributeSet attrs) {
    final TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.AnimatedPencil);
    if (typedArray != null) {
        color = typedArray.getColor(R.styleable.AnimatedPencil_pencil_color, color);
        typedArray.recycle();
    }
    imageView = new AppCompatImageView(getContext());
    addView(imageView, LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
    drawable = AppCompatDrawableManager.get().getDrawable(getContext(), R.drawable.awsb_ic_edit_animated_24);
    drawable = DrawableCompat.wrap(drawable).mutate();
    DrawableCompat.setTint(drawable, color);
    imageView.setImageDrawable(drawable);
}
 
Example #7
Source File: AccountAdapter.java    From AppCompat-Extension-Library with Apache License 2.0 5 votes vote down vote up
private static void setupCheckBox(CheckBox checkBox) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        checkBox.setButtonDrawable(R.drawable.btn_checkbox_circle);
        checkBox.setBackgroundResource(R.drawable.btn_checkbox_circle_background);
    } else {
        Context context = checkBox.getContext();
        AppCompatDrawableManager dm = AppCompatDrawableManager.get();

        StateListDrawable button = new StateListDrawable();
        button.addState(new int[]{android.R.attr.state_checked},
                dm.getDrawable(context, R.drawable.ic_checkbox_circle_checked));
        button.addState(new int[]{},
                dm.getDrawable(context, R.drawable.ic_checkbox_circle_unchecked));
        ColorStateList buttonTint = new ColorStateList(new int[][]{ // states
                new int[]{android.R.attr.state_checked},
                new int[]{} // state_default
        }, new int[]{ // colors
                ThemeUtils.getThemeAttrColor(context, R.attr.colorControlActivated),
                ThemeUtils.getThemeAttrColor(context, R.attr.colorControlNormal)
        });
        Drawable buttonCompat = DrawableCompat.wrap(button);
        DrawableCompat.setTintList(buttonCompat, buttonTint);
        checkBox.setButtonDrawable(buttonCompat);

        ShapeDrawable background = new ShapeDrawable(new OvalShape());
        int backgroundTint = ThemeUtils.getThemeAttrColor(context, android.R.attr.colorBackground);
        Drawable backgroundCompat = DrawableCompat.wrap(background);
        DrawableCompat.setTint(backgroundCompat, backgroundTint);
        ViewCompatUtils.setBackground(checkBox, backgroundCompat);
    }
}
 
Example #8
Source File: AndroidUtils.java    From iGap-Android with GNU Affero General Public License v3.0 5 votes vote down vote up
public static Drawable getDrawable(Context context, @DrawableRes int res) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        return context.getResources().getDrawable(res, context.getTheme());
    } else {
        return AppCompatDrawableManager.get().getDrawable(context, res);
    }
}
 
Example #9
Source File: CafeBarUtil.java    From cafebar with Apache License 2.0 5 votes vote down vote up
@Nullable
static Drawable getDrawable(@NonNull Context context, @DrawableRes int res) {
    try {
        Drawable drawable = AppCompatDrawableManager.get().getDrawable(context, res);
        return drawable.mutate();
    } catch (OutOfMemoryError e) {
        return null;
    }
}
 
Example #10
Source File: ButtonProgressBar.java    From ButtonProgressBar with Apache License 2.0 5 votes vote down vote up
/**
 * Get mTickBitmap image from vector drawable defined in xml
 * @param context - context to load drawable from resources
 * @param drawableId - drawable id of the vector drawable
 * @return - mTickBitmap image
 */
private Bitmap getBitmapFromVectorDrawable(Context context, int drawableId) {
    Drawable drawable = AppCompatDrawableManager.get().getDrawable(context, drawableId);
    if (Build.VERSION.SDK_INT < API_LEVEL_LOLLIPOP) {
        drawable = (DrawableCompat.wrap(drawable)).mutate();
    }
    Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(),
            drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    drawable.setBounds(topX, topY, canvas.getWidth(), canvas.getHeight());
    drawable.draw(canvas);
    return bitmap;
}
 
Example #11
Source File: WaterView.java    From KotlinMVPRxJava2Dagger2GreenDaoRetrofitDemo with Apache License 2.0 5 votes vote down vote up
private Bitmap getBitmapFromVectorDrawable(Context context, int drawableId) {
    Drawable drawable = AppCompatDrawableManager.get().getDrawable(context, drawableId);
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        drawable = (DrawableCompat.wrap(drawable)).mutate();
    }

    Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(),
            drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
    drawable.draw(canvas);

    return bitmap;
}
 
Example #12
Source File: HomeActivity.java    From Game-of-Thrones with Apache License 2.0 4 votes vote down vote up
private View getCustomIcon(int resId, int alpha) {
  return getCustomIcon(AppCompatDrawableManager.get().getDrawable(tabLayout.getContext(), resId), alpha);
}
 
Example #13
Source File: HomeActivity.java    From Game-of-Thrones with Apache License 2.0 4 votes vote down vote up
private View getCustomIcon(int resId) {
  return getCustomIcon(AppCompatDrawableManager.get().getDrawable(tabLayout.getContext(), resId), 255);
}
 
Example #14
Source File: PlaceholderDrawable.java    From AppCompat-Extension-Library with Apache License 2.0 4 votes vote down vote up
public Builder setPlaceholderImage(@DrawableRes int resId) {
    return setPlaceholderImage(AppCompatDrawableManager.get().getDrawable(mContext, resId));
}
 
Example #15
Source File: SampleActivity.java    From CompositionAvatar with MIT License 4 votes vote down vote up
private void vector(CompositionAvatarView view) {
    AppCompatDrawableManager drawableManager = AppCompatDrawableManager.get();
    view.addDrawable(drawableManager.getDrawable(this, R.drawable.cloud_circle));
    view.addDrawable(drawableManager.getDrawable(this, R.drawable.album));
    view.addDrawable(drawableManager.getDrawable(this, R.drawable.group_work));
}
 
Example #16
Source File: ResourceUtil.java    From ExoMedia with Apache License 2.0 3 votes vote down vote up
/**
 * Retrieves the drawable specified with the <code>resourceId</code>.  This
 * is a helper method to deal with the API differences for retrieving drawables
 *
 * @param context The context to use when retrieving the drawable
 * @param drawableResourceId The id for the drawable to retrieve
 * @return The drawable associated with <code>resourceId</code>
 */
public static Drawable getDrawable(Context context, @DrawableRes int drawableResourceId) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        return context.getResources().getDrawable(drawableResourceId, context.getTheme());
    }

    return AppCompatDrawableManager.get().getDrawable(context, drawableResourceId);
}
 
Example #17
Source File: CircleImageView.java    From AppCompat-Extension-Library with Apache License 2.0 2 votes vote down vote up
/**
 * Set a placeholder with an image. This will use the default circle color.
 *
 * @param resId The resource id of the placeholder drawable
 */
public void setPlaceholder(@DrawableRes int resId) {
    setPlaceholder(AppCompatDrawableManager.get().getDrawable(getContext(), resId), mPlaceholderCircleDefaultColor);
}
 
Example #18
Source File: CircleImageView.java    From AppCompat-Extension-Library with Apache License 2.0 2 votes vote down vote up
/**
 * Set a placeholder with an image and circle color.
 *
 * @param resId       The resource id of the placeholder drawable
 * @param circleColor Color to use for the circle
 */
public void setPlaceholder(@DrawableRes int resId, @ColorInt int circleColor) {
    setPlaceholder(AppCompatDrawableManager.get().getDrawable(getContext(), resId), circleColor);
}