List of usage examples for android.graphics ColorMatrixColorFilter ColorMatrixColorFilter
public ColorMatrixColorFilter(@NonNull float[] array)
From source file:com.aimfire.gallery.cardboard.PhotoActivity.java
public Bitmap toGrayscale(Bitmap bmpOriginal) { int width, height; height = bmpOriginal.getHeight();/*from w w w . j av a2s . com*/ width = bmpOriginal.getWidth(); Bitmap bmpGrayscale = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565); Canvas c = new Canvas(bmpGrayscale); Paint paint = new Paint(); ColorMatrix cm = new ColorMatrix(); cm.setSaturation(0); ColorMatrixColorFilter f = new ColorMatrixColorFilter(cm); paint.setColorFilter(f); c.drawBitmap(bmpOriginal, 0, 0, paint); bmpOriginal.recycle(); return bmpGrayscale; }
From source file:org.deviceconnect.android.manager.core.util.DConnectUtil.java
/** * ??Drawable??.//from w w w.ja va 2s . co m * * @param drawable ??Drawable * @return ??Drawable */ public static Drawable convertToGrayScale(final Drawable drawable) { Drawable clone = drawable.getConstantState().newDrawable().mutate(); ColorMatrix matrix = new ColorMatrix(); matrix.setSaturation(0.2f); ColorMatrixColorFilter filter = new ColorMatrixColorFilter(matrix); clone.setColorFilter(filter); return clone; }
From source file:io.plaidapp.ui.FeedAdapter.java
private void bindDribbbleShotHolder(final Shot shot, final DribbbleShotHolder holder) { final int[] imageSize = shot.images.bestSize(); Glide.with(host).load(shot.images.best()).listener(new RequestListener<String, GlideDrawable>() { @Override//www. j a v a 2 s. c o m public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) { if (!shot.hasFadedIn) { holder.image.setHasTransientState(true); final ObservableColorMatrix cm = new ObservableColorMatrix(); ObjectAnimator saturation = ObjectAnimator.ofFloat(cm, ObservableColorMatrix.SATURATION, 0f, 1f); saturation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator valueAnimator) { // just animating the color matrix does not invalidate the // drawable so need this update listener. Also have to create a // new CMCF as the matrix is immutable :( if (holder.image.getDrawable() != null) { holder.image.getDrawable().setColorFilter(new ColorMatrixColorFilter(cm)); } } }); saturation.setDuration(2000); saturation.setInterpolator( AnimationUtils.loadInterpolator(host, android.R.interpolator.fast_out_slow_in)); saturation.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { holder.image.setHasTransientState(false); } }); saturation.start(); shot.hasFadedIn = true; } return false; } @Override public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) { return false; } }).placeholder(shotLoadingPlaceholders[holder.getAdapterPosition() % shotLoadingPlaceholders.length]) .diskCacheStrategy(DiskCacheStrategy.SOURCE).fitCenter().override(imageSize[0], imageSize[1]) .into(new DribbbleTarget(holder.image, false)); }
From source file:edu.cloud.iot.reception.ocr.FaceRecognitionActivity.java
public Bitmap toGrayscale(Bitmap bmpOriginal) { int height = bmpOriginal.getHeight(); int width = bmpOriginal.getWidth(); Bitmap bmpGrayscale = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); Canvas c = new Canvas(bmpGrayscale); Paint paint = new Paint(); ColorMatrix cm = new ColorMatrix(); cm.setSaturation(0);//from www . j a v a2 s. c o m ColorMatrixColorFilter f = new ColorMatrixColorFilter(cm); paint.setColorFilter(f); c.drawBitmap(bmpOriginal, 0, 0, paint); return bmpGrayscale; }
From source file:com.hannesdorfmann.FeedAdapter.java
private void bindDribbbleShotView(final Shot shot, final DribbbleShotHolder holder, final int position) { final BadgedFourThreeImageView iv = (BadgedFourThreeImageView) holder.itemView; Glide.with(host).load(shot.images.best()).listener(new RequestListener<String, GlideDrawable>() { @Override// ww w .j av a2s.c o m public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) { if (!shot.hasFadedIn) { iv.setHasTransientState(true); final ObservableColorMatrix cm = new ObservableColorMatrix(); ObjectAnimator saturation = ObjectAnimator.ofFloat(cm, ObservableColorMatrix.SATURATION, 0f, 1f); saturation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator valueAnimator) { // just animating the color matrix does not invalidate the // drawable so need this update listener. Also have to create a // new CMCF as the matrix is immutable :( if (iv.getDrawable() != null) { iv.getDrawable().setColorFilter(new ColorMatrixColorFilter(cm)); } } }); saturation.setDuration(2000); saturation.setInterpolator( AnimationUtils.loadInterpolator(host, android.R.interpolator.fast_out_slow_in)); saturation.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { iv.setHasTransientState(false); } }); saturation.start(); shot.hasFadedIn = true; } return false; } @Override public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) { return false; } }).placeholder(shotLoadingPlaceholders[position % shotLoadingPlaceholders.length]) .diskCacheStrategy(DiskCacheStrategy.ALL).into(new DribbbleTarget(iv, false)); iv.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { iv.setTransitionName(iv.getResources().getString(R.string.transition_shot)); iv.setBackgroundColor(ContextCompat.getColor(host, R.color.background_light)); Intent intent = new Intent(); intent.setClass(host, DribbbleShot.class); intent.putExtra(DribbbleShot.EXTRA_SHOT, shot); ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(host, Pair.create(view, host.getString(R.string.transition_shot)), Pair.create(view, host.getString(R.string.transition_shot_background))); host.startActivity(intent, options.toBundle()); } }); }
From source file:com.igniva.filemanager.fragments.Main.java
@Override public void onActivityCreated(final Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); setHasOptionsMenu(false);//from www .j a v a2s . co m //MAIN_ACTIVITY = (MainActivity) getActivity(); initNoFileLayout(); utils = new Futils(); String x = PreferenceUtils .getSelectionColor(MainActivity.currentTab == 1 ? BaseActivity.skinTwo : BaseActivity.skin); skinselection = Color.parseColor(x); color = PreferenceUtils.calculatevalues(x); ColorMatrix colorMatrix = new ColorMatrix(PreferenceUtils.calculatefilter(color)); colorMatrixColorFilter = new ColorMatrixColorFilter(colorMatrix); SHOW_HIDDEN = Sp.getBoolean("showHidden", false); COLORISE_ICONS = Sp.getBoolean("coloriseIcons", true); folder = res.getDrawable(R.drawable.ic_grid_folder_new); getSortModes(); DARK_IMAGE = res.getDrawable(R.drawable.ic_doc_image_dark); DARK_VIDEO = res.getDrawable(R.drawable.ic_doc_video_dark); this.setRetainInstance(false); f = new HFile(HFile.UNKNOWN, CURRENT_PATH); f.generateMode(getActivity()); MAIN_ACTIVITY.initiatebbar(); ic = new IconHolder(getActivity(), SHOW_THUMBS, !IS_LIST); /*if (theme1 == 1) { listView.setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.holo_dark_background))); } else { if (IS_LIST) listView.setBackgroundDrawable(new ColorDrawable(getResources().getColor(android.R.color.background_light))); }*/ if (theme1 == 0 && !IS_LIST) listView.setBackgroundColor(getResources().getColor(R.color.grid_background_light)); else listView.setBackgroundDrawable(null); listView.setHasFixedSize(true); columns = Integer.parseInt(Sp.getString("columns", "-1")); if (IS_LIST) { mLayoutManager = new LinearLayoutManager(getActivity()); listView.setLayoutManager(mLayoutManager); } else { if (columns == -1 || columns == 0) mLayoutManagerGrid = new GridLayoutManager(getActivity(), 3); else mLayoutManagerGrid = new GridLayoutManager(getActivity(), columns); listView.setLayoutManager(mLayoutManagerGrid); } // use a linear layout manager footerView = getActivity().getLayoutInflater().inflate(R.layout.divider, null); dividerItemDecoration = new DividerItemDecoration(getActivity(), DividerItemDecoration.VERTICAL_LIST, false, SHOW_DIVIDERS); listView.addItemDecoration(dividerItemDecoration); mSwipeRefreshLayout.setColorSchemeColors(getResources().getColor(R.color.accent_yellow)); DefaultItemAnimator animator = new DefaultItemAnimator(); listView.setItemAnimator(animator); mToolbarContainer.getViewTreeObserver() .addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { if ((columns == 0 || columns == -1)) { int screen_width = listView.getWidth(); int dptopx = dpToPx(115); columns = screen_width / dptopx; if (columns == 0 || columns == -1) columns = 3; if (!IS_LIST) mLayoutManagerGrid.setSpanCount(columns); } if (savedInstanceState != null && !IS_LIST) retrieveFromSavedInstance(savedInstanceState); if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN) { mToolbarContainer.getViewTreeObserver().removeOnGlobalLayoutListener(this); } else { mToolbarContainer.getViewTreeObserver().removeGlobalOnLayoutListener(this); } } }); if (savedInstanceState == null) { loadlist(CURRENT_PATH, false, openMode); } else { if (IS_LIST) retrieveFromSavedInstance(savedInstanceState); } }
From source file:com.pixelpixel.pyp.MainActivity.java
public void applyEffect() { final ColorMatrixColorFilter colorFilter = new ColorMatrixColorFilter(effectMatrix); /*Bitmap cBitmap = null; if (mMemoryCache.get("current") != null) { cBitmap = (Bitmap)mMemoryCache.get("current"); }*///from w w w . jav a2 s . c om rBitmap = picture.copy(Bitmap.Config.ARGB_8888, true); Paint paint = new Paint(); paint.setColorFilter(colorFilter); Canvas myCanvas = new Canvas(rBitmap); myCanvas.drawBitmap(rBitmap, 0, 0, paint); /*cBitmap.recycle(); cBitmap = null;*/ img.setImageBitmap(rBitmap); //Caching bitmaps mMemoryCache.remove("current"); cacheBitmap("current", rBitmap); }
From source file:de.tap.easy_xkcd.utils.ThemePrefs.java
public ColorFilter getNegativeColorFilter() { float[] colorMatrix_Negative = { -1.0f, 0, 0, 0, 255, //red 0, -1.0f, 0, 0, 255, //green 0, 0, -1.0f, 0, 255, //blue 0, 0, 0, 1.0f, 0 //alpha };/*from w w w . ja v a 2s . c o m*/ return new ColorMatrixColorFilter(colorMatrix_Negative); }
From source file:io.plaidapp.core.ui.FeedAdapter.java
private void bindDribbbleShotHolder(final Shot shot, final DribbbleShotHolder holder, int position) { final Images.ImageSize imageSize = shot.getImages().bestSize(); GlideApp.with(host).load(shot.getImages().best()).listener(new RequestListener<Drawable>() { @Override// w w w . ja v a 2 s . c om public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) { if (!shot.getHasFadedIn()) { holder.image.setHasTransientState(true); final ObservableColorMatrix cm = new ObservableColorMatrix(); final ObjectAnimator saturation = ObjectAnimator.ofFloat(cm, ObservableColorMatrix.SATURATION, 0f, 1f); saturation.addUpdateListener(valueAnimator -> { // just animating the color matrix does not invalidate the // drawable so need this update listener. Also have to create a // new CMCF as the matrix is immutable :( holder.image.setColorFilter(new ColorMatrixColorFilter(cm)); }); saturation.setDuration(2000L); saturation.setInterpolator(getFastOutSlowInInterpolator(host)); saturation.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { holder.image.clearColorFilter(); holder.image.setHasTransientState(false); } }); saturation.start(); shot.setHasFadedIn(true); } return false; } @Override public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) { return false; } }).placeholder(shotLoadingPlaceholders[position % shotLoadingPlaceholders.length]) .diskCacheStrategy(DiskCacheStrategy.DATA).fitCenter() .transition(DrawableTransitionOptions.withCrossFade()) .override(imageSize.getWidth(), imageSize.getHeight()) .into(new DribbbleTarget(holder.image, false)); // need both placeholder & background to prevent seeing through shot as it fades in holder.image.setBackground(shotLoadingPlaceholders[position % shotLoadingPlaceholders.length]); holder.image.setDrawBadge(shot.getAnimated()); // need a unique transition name per shot, let's use it's url holder.image.setTransitionName(shot.getHtmlUrl()); shotPreloadSizeProvider.setView(holder.image); }
From source file:io.plaidapp.ui.FeedAdapter.java
private void bindDribbbleShotHolder(final Shot shot, final DribbbleShotHolder holder, int position) { final int[] imageSize = shot.images.bestSize(); Glide.with(host).load(shot.images.best()).listener(new RequestListener<String, GlideDrawable>() { @Override//from www .j a v a 2s . c o m public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) { if (!shot.hasFadedIn) { holder.image.setHasTransientState(true); final ObservableColorMatrix cm = new ObservableColorMatrix(); final ObjectAnimator saturation = ObjectAnimator.ofFloat(cm, ObservableColorMatrix.SATURATION, 0f, 1f); saturation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator valueAnimator) { // just animating the color matrix does not invalidate the // drawable so need this update listener. Also have to create a // new CMCF as the matrix is immutable :( holder.image.setColorFilter(new ColorMatrixColorFilter(cm)); } }); saturation.setDuration(2000L); saturation.setInterpolator(getFastOutSlowInInterpolator(host)); saturation.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { holder.image.clearColorFilter(); holder.image.setHasTransientState(false); } }); saturation.start(); shot.hasFadedIn = true; } return false; } @Override public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) { return false; } }).placeholder(shotLoadingPlaceholders[position % shotLoadingPlaceholders.length]) .diskCacheStrategy(DiskCacheStrategy.SOURCE).fitCenter().override(imageSize[0], imageSize[1]) .into(new DribbbleTarget(holder.image, false)); // need both placeholder & background to prevent seeing through shot as it fades in holder.image.setBackground(shotLoadingPlaceholders[position % shotLoadingPlaceholders.length]); holder.image.showBadge(shot.animated); // need a unique transition name per shot, let's use it's url holder.image.setTransitionName(shot.html_url); }