Skip to content

Commit

Permalink
Load colorscheme from individual color keys.
Browse files Browse the repository at this point in the history
Change-Id: I1e3453d178f40d871b324efebf89deec4d0d7016
  • Loading branch information
ctso authored and hyperb1iss committed Jun 24, 2010
1 parent 087051a commit f9da1cc
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 82 deletions.
32 changes: 16 additions & 16 deletions res/values/arrays.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,66 +50,66 @@
<item>Soft Blues</item>
</string-array>
<string-array name="nexus_colorscheme_ids" translatable="false">
<item>0</item>
<item>1</item>
<item>2</item>
<item>3</item>
<item>4</item>
<item>5</item>
<item>6</item>
<item>7</item>
<item>dust</item>
<item>nexus</item>
<item>sexynexus</item>
<item>cyanogenmod</item>
<item>candy</item>
<item>zion</item>
<item>red</item>
<item>softblues</item>
</string-array>

<string-array name="nexus_colorscheme_0" translatable="false">
<string-array name="nexus_colorscheme_dust" translatable="false">
<item>#232326</item>
<item>#2D3737</item>
<item>#80735F</item>
<item>#B8A07E</item>
</string-array>

<string-array name="nexus_colorscheme_1" translatable="false">
<string-array name="nexus_colorscheme_nexus" translatable="false">
<item>#FF0000</item>
<item>#009900</item>
<item>#0066CC</item>
<item>#FFCC00</item>
</string-array>

<string-array name="nexus_colorscheme_2" translatable="false">
<string-array name="nexus_colorscheme_sexynexus" translatable="false">
<item>#551A8B</item>
<item>#FF0000</item>
<item>#FF51CC</item>
<item>#ACD1E8</item>
</string-array>

<string-array name="nexus_colorscheme_3" translatable="false">
<string-array name="nexus_colorscheme_cyanogenmod" translatable="false">
<item>#16F0F1</item>
<item>#16F0F1</item>
<item>#16F0F1</item>
<item>#16F0F1</item>
</string-array>

<string-array name="nexus_colorscheme_4" translatable="false">
<string-array name="nexus_colorscheme_candy" translatable="false">
<item>#471045</item>
<item>#BD2056</item>
<item>#FFD300</item>
<item>#648C02</item>
</string-array>

<string-array name="nexus_colorscheme_5" translatable="false">
<string-array name="nexus_colorscheme_zion" translatable="false">
<item>#CC5D37</item>
<item>#FFA750</item>
<item>#182629</item>
<item>#696832</item>
</string-array>

<string-array name="nexus_colorscheme_6" translatable="false">
<string-array name="nexus_colorscheme_red" translatable="false">
<item>#E61A1A</item>
<item>#E61A1A</item>
<item>#E61A1A</item>
<item>#E61A1A</item>
</string-array>

<string-array name="nexus_colorscheme_7" translatable="false">
<string-array name="nexus_colorscheme_softblues" translatable="false">
<item>#66CCDD</item>
<item>#3366AA</item>
<item>#6699AA</item>
Expand Down
4 changes: 2 additions & 2 deletions res/xml/nexus_prefs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@
android:key="nexus_settings">

<ListPreference
android:key="colorScheme"
android:key="nexus_colorscheme"
android:title="@string/nexus_colorscheme"
android:entries="@array/nexus_colorscheme_names"
android:entryValues="@array/nexus_colorscheme_ids"
/>

<ListPreference
android:key="background"
android:key="nexus_background"
android:title="@string/nexus_background"
android:entries="@array/nexus_background_names"
android:entryValues="@array/nexus_background_ids"
Expand Down
95 changes: 32 additions & 63 deletions src/com/android/wallpaper/nexus/NexusRS.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.content.res.Resources.NotFoundException;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
Expand Down Expand Up @@ -64,10 +65,6 @@ class NexusRS extends RenderScriptScene implements

private static final String DEFAULT_BACKGROUND = "droid"; // blue droid

private static final int DEFAULT_PRESET = 7; // soft blues

private int mCurrentPreset;

private static Context mContext;

private SharedPreferences mPrefs;
Expand Down Expand Up @@ -104,7 +101,7 @@ class NexusRS extends RenderScriptScene implements

private Allocation[] mTextures = new Allocation[TEXTURES_COUNT];

public static Preset[] mPreset;
public Preset mPreset;

public NexusRS(Context context, int width, int height) {
super(width, height);
Expand Down Expand Up @@ -161,15 +158,15 @@ public Preset(String[] values) {
* @author Chris Soyars / Steve Kondik
* @return Array of Preset instances.
*/
private static Preset[] buildColors() {

private Preset buildColors() {
final Resources res = mContext.getResources();
final String[] presetIds = res.getStringArray(R.array.nexus_colorscheme_ids);
final Preset[] preset = new Preset[presetIds.length];
for (String presetId : presetIds) {
preset[Integer.valueOf(presetId)] = new Preset(res.getStringArray(res.getIdentifier(
"nexus_colorscheme_" + presetId, "array", "com.android.wallpaper")));
}
String colors[] = new String[] {
mPrefs.getString("color0","#66CCDD"),
mPrefs.getString("color1","#3366AA"),
mPrefs.getString("color2","#6699AA"),
mPrefs.getString("color3","#AABBBB")
};
final Preset preset = new Preset(colors);
return preset;
}

Expand Down Expand Up @@ -281,47 +278,23 @@ private void makeNewState() {
mWorldState.rotate = mWidth > mHeight ? 1 : 0;
mWorldState.isPreview = isPreview() ? 1 : 0;

mWorldState.color0r = mPreset[mCurrentPreset].color0r;
mWorldState.color0g = mPreset[mCurrentPreset].color0g;
mWorldState.color0b = mPreset[mCurrentPreset].color0b;
mWorldState.color1r = mPreset[mCurrentPreset].color1r;
mWorldState.color1g = mPreset[mCurrentPreset].color1g;
mWorldState.color1b = mPreset[mCurrentPreset].color1b;
mWorldState.color2r = mPreset[mCurrentPreset].color2r;
mWorldState.color2g = mPreset[mCurrentPreset].color2g;
mWorldState.color2b = mPreset[mCurrentPreset].color2b;
mWorldState.color3r = mPreset[mCurrentPreset].color3r;
mWorldState.color3g = mPreset[mCurrentPreset].color3g;
mWorldState.color3b = mPreset[mCurrentPreset].color3b;
mWorldState.color0r = mPreset.color0r;
mWorldState.color0g = mPreset.color0g;
mWorldState.color0b = mPreset.color0b;
mWorldState.color1r = mPreset.color1r;
mWorldState.color1g = mPreset.color1g;
mWorldState.color1b = mPreset.color1b;
mWorldState.color2r = mPreset.color2r;
mWorldState.color2g = mPreset.color2g;
mWorldState.color2b = mPreset.color2b;
mWorldState.color3r = mPreset.color3r;
mWorldState.color3g = mPreset.color3g;
mWorldState.color3b = mPreset.color3b;
}

private void createState() {
mWorldState = new WorldState();

/* Try to load a user-specified colorscheme */

try {
mCurrentPreset = Integer.valueOf(mPrefs.getString("colorScheme", "-1"));
} catch (NumberFormatException e) {
mCurrentPreset = -1; // We check this again later.
}

try {
mWorldState.mode = mResources.getInteger(R.integer.nexus_mode);
} catch (Resources.NotFoundException exc) {
mWorldState.mode = 0; // standard nexus mode
}

/*
* Sholes devices may specify nexus_mode=1 which means they want to use
* the "sholes red" colorscheme.
*/
if (mWorldState.mode == 1 && mCurrentPreset == -1) {
mCurrentPreset = 6; // Sholes Red
} else if (mWorldState.mode == 0 && mCurrentPreset == -1) {
mCurrentPreset = DEFAULT_PRESET;
}

mWorldState.mode = 0; // standard nexus mode
makeNewState();

mStateType = Type.createFromClass(mRS, WorldState.class, 1, "WorldState");
Expand Down Expand Up @@ -349,7 +322,7 @@ private void loadTextures() {
mTextures[i].uploadToTexture(0);
}

setBackground(mPrefs.getString("background", DEFAULT_BACKGROUND));
setBackground(mPrefs.getString("nexus_background", DEFAULT_BACKGROUND));

}

Expand Down Expand Up @@ -438,9 +411,9 @@ public Bundle onCommand(String action, int x, int y, int z, Bundle extras,
IHardwareService hardware = IHardwareService.Stub.asInterface(ServiceManager.getService("hardware"));

// Get the colors from the preset
int colorR = (int) (mPreset[mCurrentPreset].color0r * 255.0);
int colorG = (int) (mPreset[mCurrentPreset].color0g * 255.0);
int colorB = (int) (mPreset[mCurrentPreset].color0b * 255.0);
int colorR = (int) (mPreset.color0r * 255.0);
int colorG = (int) (mPreset.color0g * 255.0);
int colorB = (int) (mPreset.color0b * 255.0);

int colorValue = Color.rgb(colorR, colorG, colorB);

Expand All @@ -467,15 +440,11 @@ private void sendCommand(int command, int x, int y) {

public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {

if (key.equals("colorScheme")) {
int newPreset = Integer.valueOf(sharedPreferences.getString(key, "0"));
if (newPreset != mCurrentPreset) {
mCurrentPreset = newPreset;
makeNewState();
mState.data(mWorldState);
}

} else if (key.equals("background")) {
if (key.equals("nexus_colorscheme")) {
mPreset = buildColors();
makeNewState();
mState.data(mWorldState);
} else if (key.equals("nexus_background")) {
setDirty(true);
}
}
Expand Down
37 changes: 36 additions & 1 deletion src/com/android/wallpaper/nexus/NexusSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,28 @@
import com.android.wallpaper.R;

import android.content.SharedPreferences;
import android.content.res.Resources;
import android.os.Bundle;
import android.preference.PreferenceGroup;
import android.service.wallpaper.WallpaperSettingsActivity;
import android.util.Log;

public class NexusSettings extends WallpaperSettingsActivity {
public class NexusSettings extends WallpaperSettingsActivity
implements SharedPreferences.OnSharedPreferenceChangeListener {

public static final String COLORSCHEME_PREF = "nexus_colorscheme";
private static final String COLOR0_PREF = "color0";
private static final String COLOR1_PREF = "color1";
private static final String COLOR2_PREF = "color2";
private static final String COLOR3_PREF = "color3";

protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
getPreferenceManager().setSharedPreferencesName(
NexusWallpaper.SHARED_PREFS_NAME);
addPreferencesFromResource(R.xml.nexus_prefs);
final PreferenceGroup parentPreference = getPreferenceScreen();
parentPreference.getSharedPreferences().registerOnSharedPreferenceChangeListener(this);
}

protected void onResume() {
Expand All @@ -38,4 +50,27 @@ protected void onResume() {
protected void onDestroy() {
super.onDestroy();
}

public void onSharedPreferenceChanged(SharedPreferences preferences, String key) {
if (COLORSCHEME_PREF.equals(key)) {
final Resources res = this.getResources();
final String[] colorscheme = res.getStringArray(res.getIdentifier("nexus_colorscheme_" +
preferences.getString(key, "softblues"), "array", "com.android.wallpaper"));

SharedPreferences.Editor editor = preferences.edit();
editor.putString(COLOR0_PREF, colorscheme[0]);
editor.putString(COLOR1_PREF, colorscheme[1]);
editor.putString(COLOR2_PREF, colorscheme[2]);
editor.putString(COLOR3_PREF, colorscheme[3]);
editor.commit();

Log.d("Nexus LWP", "colorScheme="+preferences.getString(key, "none"));

Log.d("Nexus LWP", "color0="+colorscheme[0]);
Log.d("Nexus LWP", "color1="+colorscheme[1]);
Log.d("Nexus LWP", "color2="+colorscheme[2]);
Log.d("Nexus LWP", "color3="+colorscheme[3]);
}
}

}

0 comments on commit f9da1cc

Please sign in to comment.