Beispiel #1
1
  /** Put a nice border on the bitmap. */
  private static View applyFrame(
      final PhotoTable table, final BitmapFactory.Options options, Bitmap decodedPhoto) {
    LayoutInflater inflater =
        (LayoutInflater) table.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View photo = inflater.inflate(R.layout.photo, null);
    ImageView image = (ImageView) photo;
    Drawable[] layers = new Drawable[2];
    int photoWidth = options.outWidth;
    int photoHeight = options.outHeight;
    if (decodedPhoto == null || options.outWidth <= 0 || options.outHeight <= 0) {
      photo = null;
    } else {
      decodedPhoto.setHasMipMap(true);
      layers[0] = new BitmapDrawable(table.mResources, decodedPhoto);
      layers[1] = table.mResources.getDrawable(R.drawable.frame);
      LayerDrawable layerList = new LayerDrawable(layers);
      layerList.setLayerInset(0, table.mInset, table.mInset, table.mInset, table.mInset);
      image.setImageDrawable(layerList);

      photo.setTag(R.id.photo_width, Integer.valueOf(photoWidth));
      photo.setTag(R.id.photo_height, Integer.valueOf(photoHeight));

      photo.setOnTouchListener(new PhotoTouchListener(table.getContext(), table));
    }
    return photo;
  }
 /**
  * Create a layered drawable
  *
  * @param back - Background image to use when target is active
  * @param front - Front image to use for target
  * @param inset - Target inset padding
  * @param frontBlank - Whether the front image for active target should be blank
  * @return StateListDrawable
  */
 private StateListDrawable getLayeredDrawable(
     Drawable back, Drawable front, int inset, boolean frontBlank) {
   front.mutate();
   back.mutate();
   InsetDrawable[] inactivelayer = new InsetDrawable[2];
   InsetDrawable[] activelayer = new InsetDrawable[2];
   Drawable activeFront = frontBlank ? mResources.getDrawable(android.R.color.transparent) : front;
   Drawable inactiveBack =
       mResources.getDrawable(com.android.internal.R.drawable.ic_lockscreen_lock_pressed);
   inactivelayer[0] = new InsetDrawable(inactiveBack, 0, 0, 0, 0);
   inactivelayer[1] = new InsetDrawable(front, inset, inset, inset, inset);
   activelayer[0] = new InsetDrawable(back, 0, 0, 0, 0);
   activelayer[1] = new InsetDrawable(activeFront, inset, inset, inset, inset);
   StateListDrawable states = new StateListDrawable();
   LayerDrawable inactiveLayerDrawable = new LayerDrawable(inactivelayer);
   inactiveLayerDrawable.setId(0, 0);
   inactiveLayerDrawable.setId(1, 1);
   LayerDrawable activeLayerDrawable = new LayerDrawable(activelayer);
   activeLayerDrawable.setId(0, 0);
   activeLayerDrawable.setId(1, 1);
   states.addState(TargetDrawable.STATE_INACTIVE, inactiveLayerDrawable);
   states.addState(TargetDrawable.STATE_ACTIVE, activeLayerDrawable);
   states.addState(TargetDrawable.STATE_FOCUSED, activeLayerDrawable);
   return states;
 }
  private void updateAttrs(Drawable drawable) {
    if (drawable == null) {
      return;
    }

    if (drawable instanceof RoundedDrawable) {
      ((RoundedDrawable) drawable)
          .setScaleType(mScaleType)
          .setBorderWidth(mBorderWidth)
          .setBorderColor(mBorderColor)
          .setOval(mIsOval)
          .setTileModeX(mTileModeX)
          .setTileModeY(mTileModeY);

      if (mCornerRadii != null) {
        ((RoundedDrawable) drawable)
            .setCornerRadius(
                mCornerRadii[CORNER_TOP_LEFT],
                mCornerRadii[CORNER_TOP_RIGHT],
                mCornerRadii[CORNER_BOTTOM_RIGHT],
                mCornerRadii[CORNER_BOTTOM_LEFT]);
      }

      applyColorMod();
    } else if (drawable instanceof LayerDrawable) {
      // loop through layers to and set drawable attrs
      LayerDrawable ld = ((LayerDrawable) drawable);
      for (int i = 0, layers = ld.getNumberOfLayers(); i < layers; i++) {
        updateAttrs(ld.getDrawable(i));
      }
    }
  }
  public Drawable createTagDrawable() {

    GradientDrawable d = new GradientDrawable();
    TypedArray a = getActivity().getTheme().obtainStyledAttributes(new int[] {R.attr.colorAccent});
    final int accentColor = a.getColor(0, Color.WHITE);
    a.recycle();
    d.setColor(0xB3FFFFFF & accentColor);
    d.setCornerRadius(getResources().getDimension(R.dimen.dim_8dp));
    d.setShape(GradientDrawable.RECTANGLE);

    GradientDrawable d1 = new GradientDrawable();
    d1.setCornerRadius(getResources().getDimension(R.dimen.dim_8dp));
    d1.setStroke((int) getResources().getDimension(R.dimen.dim_0_5dp), 0x66FFFFFF & Color.BLACK);

    GradientDrawable d2 = new GradientDrawable();
    d2.setStroke((int) getResources().getDimension(R.dimen.dim_1dp), accentColor);
    d2.setCornerRadius(getResources().getDimension(R.dimen.dim_8dp));

    LayerDrawable layer = new LayerDrawable(new Drawable[] {d, d2, d1});

    int halfDp = (int) getResources().getDimension(R.dimen.dim_0_5dp);
    int oneDp = (int) getResources().getDimension(R.dimen.dim_1dp);
    int oneAndHalf = halfDp + oneDp;

    layer.setLayerInset(2, 0, 0, 0, 0);
    layer.setLayerInset(1, halfDp, halfDp, halfDp, halfDp);
    layer.setLayerInset(0, oneAndHalf, oneAndHalf, oneAndHalf, oneAndHalf);

    return layer;
  }
 /**
  * 改变ActionBar color
  *
  * @param newColor 颜色值
  */
 private void setActionBarcolor(int newColor) {
   // 改变ActionBar颜色如果ActionBar是可用的
   if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
     Drawable colorDrawable = new ColorDrawable(newColor);
     Drawable bottomDrawable = getResources().getDrawable(R.drawable.abc_ab_share_pack_mtrl_alpha);
     LayerDrawable ld = new LayerDrawable(new Drawable[] {colorDrawable, bottomDrawable});
     if (oldBackground == null) {
       if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
         ld.setCallback(drawableCallback);
       } else {
         getActionBar().setBackgroundDrawable(ld);
       }
     } else {
       TransitionDrawable td = new TransitionDrawable(new Drawable[] {oldBackground, ld});
       // 解决了破碎ActionBarContainer可拉的处理
       // pre-API 17 builds
       // https://github.com/android/platform_frameworks_base/commit/a7cc06d82e45918c37429a59b14545c6a57db4e4
       if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
         td.setCallback(drawableCallback);
       } else {
         getActionBar().setBackgroundDrawable(td);
       }
       td.startTransition(200);
     }
   }
 }
Beispiel #6
0
  private LayerDrawable createDrawable(int radius, int topColor, int bottomColor) {

    float[] outerRadius =
        new float[] {radius, radius, radius, radius, radius, radius, radius, radius};

    // Top
    RoundRectShape topRoundRect = new RoundRectShape(outerRadius, null, null);
    ShapeDrawable topShapeDrawable = new ShapeDrawable(topRoundRect);
    topShapeDrawable.getPaint().setColor(topColor);
    // Bottom
    RoundRectShape roundRectShape = new RoundRectShape(outerRadius, null, null);
    ShapeDrawable bottomShapeDrawable = new ShapeDrawable(roundRectShape);
    bottomShapeDrawable.getPaint().setColor(bottomColor);
    // Create array
    Drawable[] drawArray = {bottomShapeDrawable, topShapeDrawable};
    LayerDrawable layerDrawable = new LayerDrawable(drawArray);

    // Set shadow height
    if (isShadowEnabled && topColor != Color.TRANSPARENT) {
      // unpressed drawable
      layerDrawable.setLayerInset(0, 0, 0, 0, 0); /*index, left, top, right, bottom*/
    } else {
      // pressed drawable
      layerDrawable.setLayerInset(0, 0, mShadowHeight, 0, 0); /*index, left, top, right, bottom*/
    }
    layerDrawable.setLayerInset(1, 0, 0, 0, mShadowHeight); /*index, left, top, right, bottom*/

    return layerDrawable;
  }
  public static Drawable fromDrawable(Drawable drawable) {
    if (drawable != null) {
      if (drawable instanceof RoundedDrawable) {
        // just return if it's already a RoundedDrawable
        return drawable;
      } else if (drawable instanceof ColorDrawable) {
        // FIXME we don't support ColorDrawables yet
        return drawable;
      } else if (drawable instanceof LayerDrawable) {
        LayerDrawable ld = (LayerDrawable) drawable;
        int num = ld.getNumberOfLayers();

        // loop through layers to and change to RoundedDrawables if possible
        for (int i = 0; i < num; i++) {
          Drawable d = ld.getDrawable(i);
          ld.setDrawableByLayerId(ld.getId(i), fromDrawable(d));
        }
        return ld;
      }

      // try to get a bitmap from the drawable and
      Bitmap bm = drawableToBitmap(drawable);
      if (bm != null) {
        return new RoundedDrawable(bm);
      } else {
        Log.w(TAG, "Failed to create bitmap from drawable!");
      }
    }
    return drawable;
  }
Beispiel #8
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);
 }
Beispiel #9
0
 public void setHighlight(View photo, boolean highlighted) {
   ImageView image = (ImageView) photo;
   LayerDrawable layers = (LayerDrawable) image.getDrawable();
   if (highlighted) {
     layers.getDrawable(1).setColorFilter(mHighlightColor, PorterDuff.Mode.SRC_IN);
   } else {
     layers.getDrawable(1).clearColorFilter();
   }
 }
  private void shiftLayer(LayerDrawable pieceDrawable, int level) {

    int l = level * shiftSize;
    int r = 0;
    int t = 0;
    int b = 0;
    pieceDrawable.setLayerInset(level, l, t, r, b);
    ((BitmapDrawable) pieceDrawable.getDrawable(level)).setGravity(Gravity.LEFT | Gravity.TOP);
  }
  @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]);
  }
  // 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);
  }
 private LayerDrawable makeClusterBackground() {
   mColoredCircleBackground = new ShapeDrawable(new OvalShape());
   ShapeDrawable outline = new ShapeDrawable(new OvalShape());
   outline.getPaint().setColor(0x80ffffff); // Transparent white.
   LayerDrawable background =
       new LayerDrawable(new Drawable[] {outline, mColoredCircleBackground});
   int strokeWidth = (int) (mDensity * 3);
   background.setLayerInset(1, strokeWidth, strokeWidth, strokeWidth, strokeWidth);
   return background;
 }
Beispiel #14
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);
   }
 }
Beispiel #15
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);
   }
 }
Beispiel #16
0
 /**
  * Notifies the drawable that it's displayed state has changed.
  *
  * @param drawable
  * @param isDisplayed
  */
 private static void notifyDrawable(Drawable drawable, final boolean isDisplayed) {
   if (drawable instanceof RecyclingBitmapDrawable) {
     // The drawable is a CountingBitmapDrawable, so notify it
     ((RecyclingBitmapDrawable) drawable).setIsDisplayed(isDisplayed);
   } else if (drawable instanceof LayerDrawable) {
     // The drawable is a LayerDrawable, so recurse on each layer
     LayerDrawable layerDrawable = (LayerDrawable) drawable;
     for (int i = 0, z = layerDrawable.getNumberOfLayers(); i < z; i++) {
       notifyDrawable(layerDrawable.getDrawable(i), isDisplayed);
     }
   }
 }
 {
     int k = layerdrawable1.getId(i);
     Drawable drawable2 = layerdrawable1.getDrawable(i);
     if (k == 0x102000d || k == 0x102000f)
     {
         flag = true;
     } else
     {
         flag = false;
     }
     drawable[i] = tileify(drawable2, flag);
     i++;
 }
 private void fixRatingsViewColorScheme() {
   LayerDrawable stars = (LayerDrawable) mMovieRatingsView.getProgressDrawable();
   stars
       .getDrawable(2)
       .setColorFilter(
           getResources().getColor(R.color.starFullySelected), PorterDuff.Mode.SRC_ATOP);
   stars
       .getDrawable(1)
       .setColorFilter(
           getResources().getColor(R.color.starPartiallySelected), PorterDuff.Mode.SRC_ATOP);
   stars
       .getDrawable(0)
       .setColorFilter(getResources().getColor(R.color.starNotSelected), PorterDuff.Mode.SRC_ATOP);
 }
Beispiel #19
0
 public Drawable getFaviconDrawable(Bitmap icon) {
   Drawable[] array = new Drawable[3];
   array[0] = new PaintDrawable(Color.BLACK);
   PaintDrawable p = new PaintDrawable(Color.WHITE);
   array[1] = p;
   if (icon == null) {
     array[2] = mGenericFavicon;
   } else {
     array[2] = new BitmapDrawable(icon);
   }
   LayerDrawable d = new LayerDrawable(array);
   d.setLayerInset(1, 1, 1, 1, 1);
   d.setLayerInset(2, 2, 2, 2, 2);
   return d;
 }
Beispiel #20
0
 private Bitmap getBitmap(View photo) {
   if (photo == null) {
     return null;
   }
   ImageView image = (ImageView) photo;
   LayerDrawable layers = (LayerDrawable) image.getDrawable();
   if (layers == null) {
     return null;
   }
   BitmapDrawable bitmap = (BitmapDrawable) layers.getDrawable(0);
   if (bitmap == null) {
     return null;
   }
   return bitmap.getBitmap();
 }
Beispiel #21
0
 private void tintSeekBar(SeekBar sb) {
   if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
     Drawable thumb = getResources().getDrawable(R.drawable.thumb);
     LayerDrawable progress = (LayerDrawable) getResources().getDrawable(R.drawable.progress);
     progress
         .getDrawable(0)
         .setColorFilter(C.ThemedColors[C.colorIconNormal], PorterDuff.Mode.SRC_ATOP);
     progress
         .getDrawable(1)
         .setColorFilter(C.ThemedColors[C.colorAccent], PorterDuff.Mode.SRC_ATOP);
     sb.setProgressDrawable(progress);
     thumb.setColorFilter(C.ThemedColors[C.colorAccent], PorterDuff.Mode.SRC_ATOP);
     sb.setThumb(thumb);
   }
 }
Beispiel #22
0
  public BlockView(
      Context context,
      String blockId,
      String title,
      long startTime,
      long endTime,
      boolean containsStarred,
      int column) {
    super(context);

    mBlockId = blockId;
    mTitle = title;
    mStartTime = startTime;
    mEndTime = endTime;
    mContainsStarred = containsStarred;
    mColumn = column;

    setText(mTitle);

    // TODO: turn into color state list with layers?
    int textColor = -1;
    int accentColor = -1;
    switch (mColumn) {
      case 0:
        // blue
        textColor = Color.WHITE;
        accentColor = Color.parseColor("#18b6e6");
        break;
      case 1:
        // red
        textColor = Color.WHITE;
        accentColor = Color.parseColor("#df1831");
        break;
      case 2:
        // green
        textColor = Color.WHITE;
        accentColor = Color.parseColor("#00a549");
        break;
    }

    LayerDrawable buttonDrawable =
        (LayerDrawable) context.getResources().getDrawable(R.drawable.btn_block);
    buttonDrawable.getDrawable(0).setColorFilter(accentColor, PorterDuff.Mode.SRC_ATOP);
    buttonDrawable.getDrawable(1).setAlpha(mContainsStarred ? 255 : 0);

    setTextColor(textColor);
    setBackgroundDrawable(buttonDrawable);
  }
 @Override
 public Drawable getFaviconDrawable(Bitmap icon) {
   if (ENABLE_BORDER_AROUND_FAVICON) {
     Drawable[] array = new Drawable[2];
     array[0] = getFaviconBackground();
     if (icon == null) {
       array[1] = getGenericFavicon();
     } else {
       array[1] = new BitmapDrawable(mActivity.getResources(), icon);
     }
     LayerDrawable d = new LayerDrawable(array);
     d.setLayerInset(1, 2, 2, 2, 2);
     return d;
   }
   return icon == null ? getGenericFavicon() : new BitmapDrawable(mActivity.getResources(), icon);
 }
  private void applyBackgroundChanges() {
    if (!mAttached || mLayerWrapper == null) {
      return;
    }

    if (DEBUG) Log.v(TAG, "applyBackgroundChanges drawable " + mBackgroundDrawable);

    int dimAlpha = 0;

    if (mImageOutWrapper != null && mImageOutWrapper.isAnimationPending()) {
      if (DEBUG) Log.v(TAG, "mImageOutWrapper animation starting");
      mImageOutWrapper.startAnimation();
      mImageOutWrapper = null;
      dimAlpha = DIM_ALPHA_ON_SOLID;
    }

    if (mImageInWrapper == null && mBackgroundDrawable != null) {
      if (DEBUG) Log.v(TAG, "creating new imagein drawable");
      mImageInWrapper = new DrawableWrapper(mBackgroundDrawable);
      mLayerDrawable.setDrawableByLayerId(R.id.background_imagein, mBackgroundDrawable);
      if (DEBUG) Log.v(TAG, "mImageInWrapper animation starting");
      mImageInWrapper.setAlpha(0);
      mImageInWrapper.fadeIn(FADE_DURATION_SLOW, 0);
      mImageInWrapper.startAnimation();
      dimAlpha = FULL_ALPHA;
    }

    if (mDimWrapper != null && dimAlpha != 0) {
      if (DEBUG) Log.v(TAG, "dimwrapper animation starting to " + dimAlpha);
      mDimWrapper.fade(FADE_DURATION_SLOW, 0, dimAlpha);
      mDimWrapper.startAnimation();
    }
  }
 @Override
 public void draw(Canvas canvas) {
   canvas.save();
   canvas.rotate(mRotation, getBounds().centerX(), getBounds().centerY());
   super.draw(canvas);
   canvas.restore();
 }
 public void a(int paramInt) {
   int i = FeedUtils.a(this.b, paramInt);
   Resources localResources = this.b.getResources();
   int j = i - localResources.getDimensionPixelSize(2131230788);
   int k = localResources.getDimensionPixelSize(2131230789);
   Drawable localDrawable = getBackground();
   if (localDrawable != null) ((LayerDrawable) localDrawable).setLayerInset(0, j, k, j, k);
 }
 @Override
 public void draw(Canvas canvas) {
   Rect bounds = getBounds();
   canvas.saveLayerAlpha(
       bounds.left, bounds.top, bounds.right, bounds.bottom, mAlpha, Canvas.ALL_SAVE_FLAG);
   super.draw(canvas);
   canvas.restore();
 }
  private Drawable createDrawable(int color) {
    OvalShape ovalShape = new OvalShape();
    ShapeDrawable shapeDrawable = new ShapeDrawable(ovalShape);
    shapeDrawable.getPaint().setColor(color);

    if (mShadow && !hasLollipopApi()) {
      Drawable shadowDrawable =
          getResources()
              .getDrawable(mType == TYPE_NORMAL ? R.drawable.shadow : R.drawable.shadow_mini);
      LayerDrawable layerDrawable =
          new LayerDrawable(new Drawable[] {shadowDrawable, shapeDrawable});
      layerDrawable.setLayerInset(1, mShadowSize, mShadowSize, mShadowSize, mShadowSize);
      return layerDrawable;
    } else {
      return shapeDrawable;
    }
  }
  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));
  }
    @Override
    public void onDataReceived(long timestamp, float[] values) {
      HromatkaLog.getInstance().enter(TAG);
      wPitchText.setText(String.format(Locale.getDefault(), "%2.0f" + CHAR_DEGREE, values[0]));
      wRollText.setText(
          String.format(Locale.getDefault(), "%2.0f" + CHAR_DEGREE, Math.abs(values[1])));

      LayerDrawable lvPitch = (LayerDrawable) wPitchCompass.getDrawable();
      RotateDrawable pitchLayer = (RotateDrawable) lvPitch.getDrawable(1);
      pitchLayer.setLevel((int) (values[0] * DEG_TO_LEVEL));

      LayerDrawable lvRoll = (LayerDrawable) wRollCompass.getDrawable();
      RotateDrawable rollLayer = (RotateDrawable) lvRoll.getDrawable(1);
      rollLayer.setLevel((int) (values[1] * DEG_TO_LEVEL));

      HromatkaLog.getInstance().exit(TAG);
    }