android.graphics.LightingColorFilter Java Examples

The following examples show how to use android.graphics.LightingColorFilter. 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: ListView3d.java    From codeexamples-android with Eclipse Public License 1.0 6 votes vote down vote up
private LightingColorFilter calculateLight(final float rotation) {
	final double cosRotation = Math.cos(Math.PI * rotation / 180);
	int intensity = AMBIENT_LIGHT + (int) (DIFFUSE_LIGHT * cosRotation);
	int highlightIntensity = (int) (SPECULAR_LIGHT * Math.pow(cosRotation,
			SHININESS));
	if (intensity > MAX_INTENSITY) {
		intensity = MAX_INTENSITY;
	}
	if (highlightIntensity > MAX_INTENSITY) {
		highlightIntensity = MAX_INTENSITY;
	}
	final int light = Color.rgb(intensity, intensity, intensity);
	final int highlight = Color.rgb(highlightIntensity, highlightIntensity,
			highlightIntensity);
	return new LightingColorFilter(light, highlight);
}
 
Example #2
Source File: ListView3d.java    From codeexamples-android with Eclipse Public License 1.0 6 votes vote down vote up
private LightingColorFilter calculateLight(final float rotation) {
	final double cosRotation = Math.cos(Math.PI * rotation / 180);
	int intensity = AMBIENT_LIGHT + (int) (DIFFUSE_LIGHT * cosRotation);
	int highlightIntensity = (int) (SPECULAR_LIGHT * Math.pow(cosRotation,
			SHININESS));
	if (intensity > MAX_INTENSITY) {
		intensity = MAX_INTENSITY;
	}
	if (highlightIntensity > MAX_INTENSITY) {
		highlightIntensity = MAX_INTENSITY;
	}
	final int light = Color.rgb(intensity, intensity, intensity);
	final int highlight = Color.rgb(highlightIntensity, highlightIntensity,
			highlightIntensity);
	return new LightingColorFilter(light, highlight);
}
 
Example #3
Source File: PlayView.java    From AlbumCameraRecorder with MIT License 6 votes vote down vote up
/**
 * 初始化相关数据
 *
 * @param recordingItem      音频数据源
 * @param audioProgressColor 进度条颜色
 */
public void setData(RecordingItem recordingItem, int audioProgressColor) {
    this.mRecordingItem = recordingItem;
    // 设置进度条颜色
    ColorFilter filter = new LightingColorFilter
            (audioProgressColor, audioProgressColor);
    mViewHolder.seekbar.getProgressDrawable().setColorFilter(filter);
    mViewHolder.seekbar.getThumb().setColorFilter(filter);

    if (!TextUtils.isEmpty(mRecordingItem.getFilePath())) {
        mViewHolder.seekbar.setEnabled(true);
    } else {
        mViewHolder.seekbar.setEnabled(false);
    }

    initData();
}
 
Example #4
Source File: PhotoView.java    From soas with Apache License 2.0 6 votes vote down vote up
/**
 * Generate label background and foreground colors using Palette base on downloaded image colors.
 *
 * @param bitmap Download bitmap.
 */
@Override
public void onBitmapChange(Bitmap bitmap) {
    if (bitmap == null) { return; }

    Palette.generateAsync(bitmap, new Palette.PaletteAsyncListener() {
        @SuppressWarnings("deprecation")
        public void onGenerated(Palette palette) {
            Resources res = getResources();
            int photoNameColorBg = palette.getDarkMutedColor(res.getColor(R.color.list_item_photo_name_bg));
            int photoNameColorFg = palette.getLightMutedColor(res.getColor(R.color.view_photo_name_fg));

            ColorFilter photoNameColorFilter = new LightingColorFilter(photoNameColorBg, 1);
            Drawable photoNameDrawableBg = res.getDrawable(R.drawable.view_photo_name_bg);
            photoNameDrawableBg.setColorFilter(photoNameColorFilter);
            mPhotoName.setBackgroundDrawable(photoNameDrawableBg);

            mPhotoName.setTextColor(photoNameColorFg);
        }
    });
}
 
Example #5
Source File: FourColorsImageView.java    From android-graphics-demo with Apache License 2.0 6 votes vote down vote up
private void createBitmap(Bitmap quarter) {
  bitmap = Bitmap.createBitmap(getWidth(), getHeight(), Bitmap.Config.ARGB_8888);
  Canvas canvas = new Canvas(bitmap);

  Paint paint = new Paint();

  // Top left
  paint.setColorFilter(new LightingColorFilter(Color.RED, 0));
  canvas.drawBitmap(quarter, 0, 0, paint);

  // Top right
  paint.setColorFilter(new LightingColorFilter(Color.YELLOW, 0));
  canvas.drawBitmap(quarter, getWidth() / 2, 0, paint);

  // Bottom left
  paint.setColorFilter(new LightingColorFilter(Color.BLUE, 0));
  canvas.drawBitmap(quarter, 0, getHeight()/2, paint);

  // Bottom right
  paint.setColorFilter(new LightingColorFilter(Color.GREEN, 0));
  canvas.drawBitmap(quarter, getWidth() / 2, getHeight() / 2, paint);
}
 
Example #6
Source File: BitmapProcessing.java    From Effects-Pro with MIT License 6 votes vote down vote up
public static Bitmap tint(Bitmap src, int color) {
	// image size
	int width = src.getWidth();
	int height = src.getHeight();
	// create output bitmap

	// create a mutable empty bitmap
	Bitmap bmOut = Bitmap.createBitmap(width, height, src.getConfig());

	Paint p = new Paint(Color.RED);
	ColorFilter filter = new LightingColorFilter(color, 1);
	p.setColorFilter(filter);

	Canvas c = new Canvas();
	c.setBitmap(bmOut);		
	c.drawBitmap(src, 0, 0, p);

	src.recycle();
	src = null;

	return bmOut;
}
 
Example #7
Source File: MyListView.java    From BubbleCloudView with MIT License 6 votes vote down vote up
/**
 * Calculates the lighting of the item based on rotation.
 * 
 * @param rotation The rotation of the item
 * @return A color filter to use
 */
private LightingColorFilter calculateLight(final float rotation) {
    final double cosRotation = Math.cos(Math.PI * rotation / 180);
    int intensity = AMBIENT_LIGHT + (int)(DIFFUSE_LIGHT * cosRotation);
    int highlightIntensity = (int)(SPECULAR_LIGHT * Math.pow(cosRotation, SHININESS));

    if (intensity > MAX_INTENSITY) {
        intensity = MAX_INTENSITY;
    }
    if (highlightIntensity > MAX_INTENSITY) {
        highlightIntensity = MAX_INTENSITY;
    }

    final int light = Color.rgb(intensity, intensity, intensity);
    final int highlight = Color.rgb(highlightIntensity, highlightIntensity, highlightIntensity);

    return new LightingColorFilter(light, highlight);
}
 
Example #8
Source File: CardViewActivity.java    From FrostyBackgroundTestApp with Apache License 2.0 6 votes vote down vote up
public Bitmap captureView(View view) {
  if (mBlurredBitmap != null) {
    return mBlurredBitmap;
  }
  //Find the view we are after
  //Create a Bitmap with the same dimensions
  mBlurredBitmap = Bitmap.createBitmap(view.getMeasuredWidth(),
      view.getMeasuredHeight(),
      Bitmap.Config.ARGB_4444); //reduce quality and remove opacity
  //Draw the view inside the Bitmap
  Canvas canvas = new Canvas(mBlurredBitmap);
  view.draw(canvas);

  //blur it
  ImageHelper.blurBitmapWithRenderscript(rs, mBlurredBitmap);

  //Make it frosty
  Paint paint = new Paint();
  paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
  ColorFilter filter = new LightingColorFilter(0xFFFFFFFF, 0x00222222); // lighten
  //ColorFilter filter = new LightingColorFilter(0xFF7F7F7F, 0x00000000);    // darken
  paint.setColorFilter(filter);
  canvas.drawBitmap(mBlurredBitmap, 0, 0, paint);

  return mBlurredBitmap;
}
 
Example #9
Source File: ScrollingActivity.java    From FrostyBackgroundTestApp with Apache License 2.0 6 votes vote down vote up
public Bitmap captureView(View view) {
    //Find the view we are after
    //Create a Bitmap with the same dimensions
    Bitmap image = Bitmap.createBitmap(view.getMeasuredWidth(),
            view.getMeasuredHeight(),
            Bitmap.Config.ARGB_4444); //reduce quality and remove opacity
    //Draw the view inside the Bitmap
    Canvas canvas = new Canvas(image);
    view.draw(canvas);

    //Make it frosty
    Paint paint = new Paint();
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    ColorFilter filter = new LightingColorFilter(0xFFFFFFFF, 0x00222222); // lighten
    //ColorFilter filter = new LightingColorFilter(0xFF7F7F7F, 0x00000000);    // darken
    paint.setColorFilter(filter);
    canvas.drawBitmap(image, 0, 0, paint);

    return image;
}
 
Example #10
Source File: MainActivity.java    From APKMirror with GNU General Public License v2.0 6 votes vote down vote up
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
private void changeUIColor(Integer color) {

    ValueAnimator anim = ValueAnimator.ofArgb(previsionThemeColor, color);
    anim.setEvaluator(new ArgbEvaluator());

    anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            progressBar.getProgressDrawable().setColorFilter(new LightingColorFilter(0xFF000000, (Integer) valueAnimator.getAnimatedValue()));
            setSystemBarColor((Integer) valueAnimator.getAnimatedValue());
            navigation.setActiveTabColor((Integer) valueAnimator.getAnimatedValue());
            fabSearch.setBackgroundTintList(ColorStateList.valueOf((Integer) valueAnimator.getAnimatedValue()));

        }
    });

    anim.setDuration(getResources().getInteger(android.R.integer.config_shortAnimTime));
    anim.start();
    refreshLayout.setColorSchemeColors(color, color, color);

}
 
Example #11
Source File: Utils.java    From KUAS-AP-Material with MIT License 5 votes vote down vote up
/**
 * White colors can be transformed in to different colors.
 *
 * @param sourceBitmap The source Bitmap
 * @param color        The different color
 * @return The different color Bitmap
 */
public static Bitmap changeImageColor(Bitmap sourceBitmap, int color) {
	Bitmap resultBitmap = Bitmap.createBitmap(sourceBitmap, 0, 0, sourceBitmap.getWidth() - 1,
			sourceBitmap.getHeight() - 1);
	Paint p = new Paint();
	ColorFilter filter = new LightingColorFilter(color, 1);
	p.setColorFilter(filter);

	Canvas canvas = new Canvas(resultBitmap);
	canvas.drawBitmap(resultBitmap, 0, 0, p);
	return resultBitmap;
}
 
Example #12
Source File: LightingColorFilterPostProcessor.java    From react-native-image-filter-kit with MIT License 5 votes vote down vote up
@Override
public void process(Bitmap dst, Bitmap src) {
  super.process(dst, src);

  final Canvas canvas = new Canvas(dst);
  final Paint paint = new Paint();

  paint.setColorFilter(new LightingColorFilter(mMul, mAdd));

  canvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR);
  canvas.drawBitmap(src, 0, 0, paint);
}
 
Example #13
Source File: Utils.java    From KUAS-AP-Material with MIT License 5 votes vote down vote up
/**
 * White colors can be transformed in to different colors.
 *
 * @param sourceBitmap The source Bitmap
 * @param color        The different color
 * @return The different color Bitmap
 */
public static Bitmap changeImageColor(Bitmap sourceBitmap, int color) {
	Bitmap resultBitmap = Bitmap.createBitmap(sourceBitmap, 0, 0, sourceBitmap.getWidth() - 1,
			sourceBitmap.getHeight() - 1);
	Paint p = new Paint();
	ColorFilter filter = new LightingColorFilter(color, 1);
	p.setColorFilter(filter);

	Canvas canvas = new Canvas(resultBitmap);
	canvas.drawBitmap(resultBitmap, 0, 0, p);
	return resultBitmap;
}
 
Example #14
Source File: BackgroundLinearLayout.java    From Noyze with Apache License 2.0 5 votes vote down vote up
public void setCustomBackground(Drawable d) {
    mCustomBackground = d;
    if (d != null && d instanceof BitmapDrawable) {
        // This is to add a tint of the background color to the image.
        // It prevents overly exposed or bright backgrounds from ruining the ambiance.
        BitmapDrawable bd = (BitmapDrawable) d;
        bd.getPaint().setColor(backgroundColor);
        ColorFilter filter = new LightingColorFilter(backgroundColor, 1);
        bd.setColorFilter(filter);
    }
    setBackground(mBackgroundDrawable);
    computeCustomBackgroundBounds();
    invalidate();
}
 
Example #15
Source File: SuntimesUtils.java    From SuntimesWidget with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates a tinted copy of the supplied bitmap.
 * @param b a bitmap image
 * @param color a color
 * @return a bitmap tinted to color
 */
public static Bitmap tintBitmap(Bitmap b, int color)
{
    Bitmap tinted = Bitmap.createBitmap(b.getWidth(), b.getHeight(), b.getConfig());
    Canvas c = new Canvas(tinted);
    Paint p = new Paint();
    p.setColorFilter(new LightingColorFilter(color, 0));
    c.drawBitmap(b, 0, 0, p);
    return tinted;
}
 
Example #16
Source File: TintedBitmapDrawable.java    From ChatMessageView with Apache License 2.0 5 votes vote down vote up
@Override
public void draw(final Canvas canvas) {
    final Paint paint = getPaint();
    if (paint.getColorFilter() == null) {
        paint.setColorFilter(new LightingColorFilter(tint, 0));
        paint.setAlpha(alpha);
    }
    super.draw(canvas);
}
 
Example #17
Source File: LightingColorFilterView.java    From AndroidDemo with Apache License 2.0 5 votes vote down vote up
public LightingColorFilterView(Context context, AttributeSet attrs) {
    super(context, attrs);

    mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mPaint.setColorFilter(new LightingColorFilter(0xFFFFFFFF, 0x00FF00FF));
    bitmap = BitmapFactory.decodeResource(context.getResources(), R.mipmap.ic_launcher);

}
 
Example #18
Source File: FinishedView.java    From AnimatedCircleLoadingView with Apache License 2.0 5 votes vote down vote up
private void drawCheckedMark(Canvas canvas) {
  Paint paint = new Paint();
  paint.setColorFilter(new LightingColorFilter(getDrawableTintColor(), 0));

  Bitmap bitmap = Bitmap.createScaledBitmap(originalFinishedBitmap, imageSize, imageSize, true);
  canvas.drawBitmap(bitmap, parentCenter - bitmap.getWidth() / 2,
      parentCenter - bitmap.getHeight() / 2, paint);
}
 
Example #19
Source File: UnitUtilWrapper.java    From bither-android with Apache License 2.0 5 votes vote down vote up
public static Bitmap changeBitmapColor(Bitmap bmp, int color) {
    Bitmap result = Bitmap.createBitmap(bmp.getWidth(), bmp.getHeight(), bmp.getConfig());
    Canvas c = new Canvas(result);
    Paint paint = new Paint();
    ColorFilter filter = new LightingColorFilter(color, 1);
    paint.setColorFilter(filter);
    c.drawBitmap(bmp, 0, 0, paint);
    return result;
}
 
Example #20
Source File: TickColor.java    From tickmate with GNU General Public License v3.0 5 votes vote down vote up
public static Drawable getTickedButtonDrawable(Context context, int tickButtonColor) {
    // Prepare the layers & color filter for the LayerDrawable
    ColorFilter cf = new LightingColorFilter(tickButtonColor, 0);
    //ColorDrawable buttonCenterDrawable = new ColorDrawable(0xFF000000 + tickButtonColor);
    Drawable buttonCenterDrawable = ContextCompat.getDrawable(context, R.drawable.mask_64);
    Drawable buttonBorderDrawable = ContextCompat.getDrawable(context, R.drawable.on_64);
    buttonCenterDrawable.setColorFilter(cf);
    sTickedButton = new LayerDrawable(new Drawable[]{buttonCenterDrawable, buttonBorderDrawable});
    return sTickedButton;
}
 
Example #21
Source File: NotificationHelper.java    From NotificationPeekPort with Apache License 2.0 5 votes vote down vote up
public static View.OnTouchListener getHighlightTouchListener(final int color) {
    return new View.OnTouchListener() {
        @Override
        public boolean onTouch(View view, MotionEvent event) {
            Drawable drawable = ((ImageView) view).getDrawable();
            switch (event.getAction()) {
                case MotionEvent.ACTION_DOWN:
                    LightingColorFilter lighten = new LightingColorFilter(color, color);
                    drawable.setColorFilter(lighten);
                    break;
                case MotionEvent.ACTION_UP:
                    drawable.clearColorFilter();
                    break;
                case MotionEvent.ACTION_MOVE:
                    Rect rect = new Rect();
                    view.getLocalVisibleRect(rect);
                    if (!rect.contains((int) event.getX(), (int) event.getY())) {
                        drawable.clearColorFilter();
                    }
                    break;
                case MotionEvent.ACTION_OUTSIDE:
                case MotionEvent.ACTION_CANCEL:
                    drawable.clearColorFilter();
                    break;
            }
            return false;
        }
    };
}
 
Example #22
Source File: BackgroundLinearLayout.java    From Noyze with Apache License 2.0 5 votes vote down vote up
public void setCustomBackground(Drawable d) {
    mCustomBackground = d;
    if (d != null && d instanceof BitmapDrawable) {
        // This is to add a tint of the background color to the image.
        // It prevents overly exposed or bright backgrounds from ruining the ambiance.
        BitmapDrawable bd = (BitmapDrawable) d;
        bd.getPaint().setColor(backgroundColor);
        ColorFilter filter = new LightingColorFilter(backgroundColor, 1);
        bd.setColorFilter(filter);
    }
    setBackground(mBackgroundDrawable);
    computeCustomBackgroundBounds();
    invalidate();
}
 
Example #23
Source File: SelectInstalledAppsActivity.java    From fdroidclient with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuItem menuItem = menu.add(R.string.menu_select_for_wipe);
    menuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
    checkId = menuItem.getItemId();
    if (FDroidApp.isAppThemeLight()) {
        Resources resources = getResources();
        Drawable icon = resources.getDrawable(R.drawable.check);
        icon.setColorFilter(new LightingColorFilter(0xffffffff, resources.getColor(android.R.color.white)));
        menuItem.setIcon(icon);
    } else {
        menuItem.setIcon(R.drawable.check);
    }
    return true;
}
 
Example #24
Source File: ImageUtil.java    From Augendiagnose with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Utility method to change a bitmap colour.
 *
 * @param sourceBitmap The original bitmap
 * @param color        The target color
 * @return the bitmap with the target color.
 */
public static Bitmap changeBitmapColor(@NonNull final Bitmap sourceBitmap, final int color) {
	Bitmap ret = Bitmap.createBitmap(sourceBitmap.getWidth(), sourceBitmap.getHeight(), sourceBitmap.getConfig());

	Paint p = new Paint();
	ColorFilter filter = new LightingColorFilter(0, color);
	p.setAlpha(color >>> 24); // MAGIC_NUMBER
	p.setColorFilter(filter);
	Canvas canvas = new Canvas(ret);
	canvas.drawBitmap(sourceBitmap, 0, 0, p);
	return ret;
}
 
Example #25
Source File: ButtonClickListener.java    From BluetoothHidEmu with Apache License 2.0 5 votes vote down vote up
/**
 * Set properties for the button to be drawn as normal or "on hold".
 * @param view
 * @param isHold
 */
private void drawButton(View view, boolean isHold) {
    ImageView imgView = (ImageView) view;
    if (isHold) {
        imgView.setColorFilter(new LightingColorFilter(0xff4a6c9b, 0xff000055));
    } else {
        imgView.clearColorFilter();
    }
}
 
Example #26
Source File: BitmapUtils.java    From PracticeDemo with Apache License 2.0 5 votes vote down vote up
/**
 * 给bitmap着色
 * @param sourceBitmap
 * @param color  rgb
 * @return
 */
public static Bitmap changeBitmapColor(@NonNull Bitmap sourceBitmap, @IntegerRes int color) {

    Bitmap resultBitmap = Bitmap.createBitmap(sourceBitmap, 0, 0,
            sourceBitmap.getWidth() - 1, sourceBitmap.getHeight() - 1);
    Paint p = new Paint();
    ColorFilter filter = new LightingColorFilter(color, 1);
    p.setColorFilter(filter);

    Canvas canvas = new Canvas(resultBitmap);
    canvas.drawBitmap(resultBitmap, 0, 0, p);
    return resultBitmap;
}
 
Example #27
Source File: RecyclerViewFragment.java    From kernel_adiutor with Apache License 2.0 5 votes vote down vote up
public void setProgressBar(ProgressBar progressBar) {
    progressBar.getIndeterminateDrawable().setColorFilter(new LightingColorFilter(0xFF000000,
            getResources().getColor(android.R.color.white)));
    ActionBar actionBar;
    if ((actionBar = getActionBar()) != null) {
        actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM, ActionBar.DISPLAY_SHOW_CUSTOM);
        actionBar.setCustomView(progressBar, new ActionBar.LayoutParams(ActionBar.LayoutParams.WRAP_CONTENT,
                ActionBar.LayoutParams.WRAP_CONTENT, Gravity.CENTER_VERTICAL | Gravity.END));
    }
}
 
Example #28
Source File: TintedBitmapDrawable.java    From droidddle with Apache License 2.0 5 votes vote down vote up
@Override
public void draw(final Canvas canvas) {
    final Paint paint = getPaint();
    if (paint.getColorFilter() == null) {
        paint.setColorFilter(new LightingColorFilter(tint, 0));
        paint.setAlpha(alpha);
    }
    super.draw(canvas);
}
 
Example #29
Source File: StarRatingView.java    From AndroidStudyDemo with GNU General Public License v2.0 5 votes vote down vote up
private void init() {
	starBitmap = BitmapFactory.decodeResource(getContext().getResources(), R.mipmap.star);
	
	goldPaint = new Paint();
	goldPaint.setFilterBitmap(true);
	
	grayPaint = new Paint();
	grayPaint.setColorFilter(new LightingColorFilter(0xff111122, 0xffcccccc));
	grayPaint.setFilterBitmap(true);
	
	setModel(new StarRatingModel());
}
 
Example #30
Source File: RecyclerViewFragment.java    From KA27 with Apache License 2.0 5 votes vote down vote up
public void setProgressBar(ProgressBar progressBar) {
    progressBar.getIndeterminateDrawable().setColorFilter(new LightingColorFilter(0xFF000000,
        ContextCompat.getColor(getActivity(), android.R.color.white)));
    ActionBar actionBar;
    if ((actionBar = getActionBar()) != null) {
        actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM, ActionBar.DISPLAY_SHOW_CUSTOM);
        actionBar.setCustomView(progressBar, new ActionBar.LayoutParams(ActionBar.LayoutParams.WRAP_CONTENT,
            ActionBar.LayoutParams.WRAP_CONTENT, Gravity.CENTER_VERTICAL | Gravity.END));
    }
}