Last active
July 21, 2017 11:08
-
-
Save rygelouv/da2d365510b945507fd95f31ca8d9555 to your computer and use it in GitHub Desktop.
Generate random colors for ImageView placholder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.content.Context; | |
import android.graphics.drawable.Drawable; | |
import android.support.v4.graphics.drawable.DrawableCompat; | |
import com.devengine.paladin.coinafrique.R; | |
import java.util.ArrayList; | |
import java.util.Random; | |
public class ColorUtils | |
{ | |
public static final ArrayList<Integer> sColorRessources = new ArrayList() | |
{ | |
{ | |
add(R.color.pallete_grey_300); | |
add(R.color.palette_amber_300); | |
add(R.color.palette_blue_grey_300); | |
add(R.color.palette_brown_300); | |
add(R.color.palette_deep_orange_300); | |
add(R.color.palette_green_300); | |
add(R.color.palette_lime_300); | |
add(R.color.palette_light_green_300); | |
add(R.color.palette_yellow_300); | |
add(R.color.palette_orange_300); | |
add(R.color.palette_red_300); | |
add(R.color.palette_pink_300); | |
add(R.color.palette_purple_300); | |
add(R.color.palette_deep_purple_300); | |
add(R.color.palette_indigo_300); | |
add(R.color.palette_blue_300); | |
add(R.color.palette_light_blue_300); | |
add(R.color.palette_cyan_300); | |
add(R.color.palette_teal_300); | |
} | |
}; | |
public static final ArrayList<Integer> coloredDrawable = new ArrayList(){ | |
{ | |
add(R.drawable.placeholder_ad_color_1); | |
add(R.drawable.placeholder_ad_color_2); | |
add(R.drawable.placeholder_ad_color_3); | |
add(R.drawable.placeholder_ad_color_4); | |
} | |
}; | |
public static int getRandomColor() { | |
int randomColor = sColorRessources | |
.get(new Random().nextInt(sColorRessources.size())); | |
return randomColor; | |
} | |
public static int getRandomColoredDrawable() | |
{ | |
return coloredDrawable.get(new Random().nextInt(coloredDrawable.size())); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public Drawable getColoredDrawable() | |
{ | |
return mContext.getResources().getDrawable(ColorUtils.getRandomColoredDrawable()); | |
} | |
public void testMethod() | |
{ | |
imageView.setImageDrawable(getColoredDrawable()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment