private void lazyInit() {
    if (mLayerDrawable != null) {
      return;
    }

    mLayerDrawable = (LayerDrawable) mContext.getResources().getDrawable(R.drawable.lb_background);
    mBgView.setBackground(mLayerDrawable);

    mLayerDrawable.setDrawableByLayerId(R.id.background_imageout, createEmptyDrawable());

    mDimWrapper = new DrawableWrapper(mLayerDrawable.findDrawableByLayerId(R.id.background_dim));

    mLayerWrapper = new DrawableWrapper(mLayerDrawable);

    mColorWrapper =
        new DrawableWrapper(mLayerDrawable.findDrawableByLayerId(R.id.background_color));
  }
Пример #2
0
 private void changeBackgroundColor(int color) {
   LayerDrawable layer = (LayerDrawable) getBackground();
   GradientDrawable shape = (GradientDrawable) layer.findDrawableByLayerId(R.id.shape_bacground);
   if (isInEditMode()) {
     return;
   }
   shape.setColor(color);
 }
  // Set color of background
  public void setBackgroundColor(int color) {
    this.backgroundColor = color;
    if (isEnabled()) beforeBackground = backgroundColor;
    LayerDrawable layer = (LayerDrawable) progressView.getBackground();
    GradientDrawable shape =
        (GradientDrawable) layer.findDrawableByLayerId(R.id.layer_angel_material_progress_bar_back);

    shape.setColor(color);
  }
  @Override
  public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
    SampleViewHolder viewHolder = (SampleViewHolder) holder;

    LayerDrawable bgDrawable = (LayerDrawable) viewHolder.mMainLayout.getBackground();
    GradientDrawable shape =
        (GradientDrawable) bgDrawable.findDrawableByLayerId(R.id.background_shape);
    shape.setColor(mColors[position]);
  }
Пример #5
0
 public void changeBackground() {
   if (check) {
     setBackgroundResource(R.drawable.background_checkbox_check);
     LayerDrawable layer = (LayerDrawable) getBackground();
     GradientDrawable shape =
         (GradientDrawable) layer.findDrawableByLayerId(R.id.shape_bacground);
     shape.setColor(backgroundColor);
   } else {
     setBackgroundResource(R.drawable.background_checkbox_uncheck);
   }
 }
Пример #6
0
 // Set color of background
 public void setBackgroundColor(int color) {
   this.backgroundColor = color;
   if (isEnabled()) {
     beforeBackground = backgroundColor;
   }
   GradientDrawable shape = null;
   if (!isInEditMode()) {
     LayerDrawable layer = (LayerDrawable) getBackground();
     shape = (GradientDrawable) layer.findDrawableByLayerId(R.id.shape_bacground);
     shape.setColor(backgroundColor);
   }
 }
Пример #7
0
 /**
  * 设置对话框的颜色 三角形的图片是layer-list里面嵌套一个RotateDrawable,在设置颜色的时候需要特别处理
  * http://stackoverflow.com/questions/24492000/set-color-of-triangle-on-run-time
  * http://stackoverflow.com/questions/16636412/change-shape-solid-color-at-runtime-inside-drawable-xml-used-as-background
  */
 public EasyDialog setBackgroundColor(int color) {
   backgroundColor = color;
   LayerDrawable drawableTriangle = (LayerDrawable) ivTriangle.getBackground();
   GradientDrawable shapeTriangle =
       (GradientDrawable)
           (((RotateDrawable) drawableTriangle.findDrawableByLayerId(R.id.shape_id))
               .getDrawable());
   if (shapeTriangle != null) {
     shapeTriangle.setColor(color);
   } else {
     Toast.makeText(context, "shape is null", Toast.LENGTH_SHORT).show();
   }
   GradientDrawable drawableRound = (GradientDrawable) llContent.getBackground();
   if (drawableRound != null) {
     drawableRound.setColor(color);
   }
   return this;
 }
Пример #8
0
  // View inflater
  @SuppressWarnings("deprecation")
  @Override
  public View getView(final int position, View convertView, ViewGroup parent) {
    // Inflate custom note view if null
    if (convertView == null)
      convertView = this.inflater.inflate(R.layout.list_view_note, parent, false);

    // Initialize layout items
    RelativeLayout relativeLayout = (RelativeLayout) convertView.findViewById(R.id.relativeLayout);
    LayerDrawable roundedCard =
        (LayerDrawable) context.getResources().getDrawable(R.drawable.rounded_card);
    TextView titleView = (TextView) convertView.findViewById(R.id.titleView);
    TextView bodyView = (TextView) convertView.findViewById(R.id.bodyView);
    ImageButton favourite = (ImageButton) convertView.findViewById(R.id.favourite);

    // Get Note object at position
    JSONObject noteObject = getItem(position);

    if (noteObject != null) {
      // If noteObject not empty -> initialize variables
      String title = context.getString(R.string.note_title);
      String body = context.getString(R.string.note_body);
      String colour = String.valueOf(context.getResources().getColor(R.color.white));
      int fontSize = 18;
      Boolean hideBody = false;
      Boolean favoured = false;

      try {
        // Get noteObject data and store in variables
        title = noteObject.getString(NOTE_TITLE);
        body = noteObject.getString(NOTE_BODY);
        colour = noteObject.getString(NOTE_COLOR);

        if (noteObject.has(NOTE_FONT_SIZE)) fontSize = noteObject.getInt(NOTE_FONT_SIZE);

        if (noteObject.has(NOTE_HIDE_BODY)) hideBody = noteObject.getBoolean(NOTE_HIDE_BODY);

        favoured = noteObject.getBoolean(NOTE_FAVOURED);

      } catch (JSONException e) {
        e.printStackTrace();
      }

      // Set favourite image resource
      if (favoured) favourite.setImageResource(R.drawable.ic_fav);
      else favourite.setImageResource(R.drawable.ic_unfav);

      // If search or delete modes are active -> hide favourite button; Show otherwise
      if (searchActive || deleteActive) favourite.setVisibility(View.INVISIBLE);
      else favourite.setVisibility(View.VISIBLE);

      titleView.setText(title);

      // If hidBody is true -> hide body of note
      if (hideBody) bodyView.setVisibility(View.GONE);

      // Else -> set visible note body, text to normal and set text size to 'fontSize' as sp
      else {
        bodyView.setVisibility(View.VISIBLE);
        bodyView.setText(body);
        bodyView.setTextSize(TypedValue.COMPLEX_UNIT_SP, fontSize);
      }

      // If current note is selected for deletion -> highlight
      if (checkedArray.contains(position)) {
        ((GradientDrawable) roundedCard.findDrawableByLayerId(R.id.card))
            .setColor(context.getResources().getColor(R.color.theme_primary));
      }

      // If current note is not selected -> set background colour to normal
      else {
        ((GradientDrawable) roundedCard.findDrawableByLayerId(R.id.card))
            .setColor(Color.parseColor(colour));
      }

      // Set note background style to rounded card
      relativeLayout.setBackground(roundedCard);

      final Boolean finalFavoured = favoured;
      favourite.setOnClickListener(
          new View.OnClickListener() {
            // If favourite button was clicked -> change that note to favourite or un-favourite
            @Override
            public void onClick(View v) {
              setFavourite(context, !finalFavoured, position);
            }
          });
    }

    return convertView;
  }