Back to project page unknown-pleasures.
The source code is released under:
Creative Commons Attribution NonCommercial NoDerivs (CC-NC-ND) THE WORK (AS DEFINED BELOW) IS PROVIDED UNDER THE TERMS OF THIS CREATIVE COMMONS PUBLIC LICENSE ("CCPL" OR "LICENSE"). THE WORK IS PROTE...
If you think the Android project unknown-pleasures listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
/** * PaletteFactory.java/* www .j a v a2s .c o m*/ * Author: marek.brodziak@gmail.com * Created: May 6, 2014 * Copyright 2014 by miniti */ package pl.miniti.android.pleasures.palette; import android.util.Log; /** * Factory of the {@see Palette} implementations */ public class PaletteFactory { /** * Tag name for the logger */ private static final String T = PaletteFactory.class.getSimpleName(); /** * Enumeration of available implementations */ private enum Impl { /** * Default implementation for this factory */ DEFAULT(WhitePalette.class), /** * White on black */ WHITE(WhitePalette.class), /** * Black on white */ BLACK(BlackPalette.class), /** * Retro palette #1 */ RETRO1(Retro1Palette.class), /** * Retro palette #2 */ RETRO2(Retro2Palette.class), /** * Retro blue on white background */ BLUE(BluePalette.class), /** * Sundown palette on black background */ SUNDOWN(PinkPalette.class); private Class<? extends Palette> paletteClass; private Impl(Class<? extends Palette> ac) { if (ac == null) { throw new IllegalArgumentException( "null is not a valid Palette implementation"); } paletteClass = ac; } } /** * Construct a new instance based on the configuration * * @param value * configuration value * @return object instance */ public static Palette newInstance(String value) { Log.d(T, String.format("Searching for Palette %s", value)); try { if (value == null) { Log.d(T, String.format( "Constructing a default Palette implementation %s", Impl.DEFAULT.paletteClass.getSimpleName())); return Impl.DEFAULT.paletteClass.newInstance(); } for (Impl a : Impl.values()) { if (a.paletteClass.getName().equals(value)) { Log.d(T, "Match found"); return a.paletteClass.newInstance(); } } Log.w(T, String.format("%s is not a registered Animator", value)); Log.d(T, String.format( "Constructing a default Palette implementation %s", Impl.DEFAULT.paletteClass.getSimpleName())); return Impl.DEFAULT.paletteClass.newInstance(); } catch (InstantiationException e) { Log.e(T, "Error while creating a Palette", e); } catch (IllegalAccessException e) { Log.e(T, "Error raised while creating a Palette", e); } Log.d(T, "Fall back to constructing from code"); return new WhitePalette(); } }