diff options
| author | Steve Kondik <shade@chemlab.org> | 2010-06-06 06:03:15 -0400 |
|---|---|---|
| committer | Steve Kondik <shade@chemlab.org> | 2010-06-06 06:03:15 -0400 |
| commit | a24419a45cbe788cf566ebd93d83f6305a6ba847 (patch) | |
| tree | 8c3130b90b80ddf54cefb48d9ed6b4c980b066e6 /apps | |
| parent | f327a4f32e9a211046eae46a20658d5467af0a12 (diff) | |
| parent | c8cc30275019facdc284a7b12db3baaf3541f9dc (diff) | |
| download | android_development-a24419a45cbe788cf566ebd93d83f6305a6ba847.tar.gz android_development-a24419a45cbe788cf566ebd93d83f6305a6ba847.tar.bz2 android_development-a24419a45cbe788cf566ebd93d83f6305a6ba847.zip | |
Merge branch 'master' of http://github.com/Wysie/development_apps_spareparts into eclair
Diffstat (limited to 'apps')
| -rw-r--r-- | apps/SpareParts/AndroidManifest.xml | 1 | ||||
| -rw-r--r-- | apps/SpareParts/res/values/strings.xml | 10 | ||||
| -rw-r--r-- | apps/SpareParts/res/xml/spare_parts.xml | 8 | ||||
| -rw-r--r-- | apps/SpareParts/src/com/android/spare_parts/SpareParts.java | 172 |
4 files changed, 175 insertions, 16 deletions
diff --git a/apps/SpareParts/AndroidManifest.xml b/apps/SpareParts/AndroidManifest.xml index 41ff577f8..6f46d8146 100644 --- a/apps/SpareParts/AndroidManifest.xml +++ b/apps/SpareParts/AndroidManifest.xml @@ -20,6 +20,7 @@ <uses-permission android:name="android.permission.CHANGE_CONFIGURATION" /> <uses-permission android:name="android.permission.WRITE_SETTINGS" /> <uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS" /> + <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <application android:label="@string/app_label" android:icon="@drawable/app_icon"> diff --git a/apps/SpareParts/res/values/strings.xml b/apps/SpareParts/res/values/strings.xml index 60287ce9e..96b56ef94 100644 --- a/apps/SpareParts/res/values/strings.xml +++ b/apps/SpareParts/res/values/strings.xml @@ -126,18 +126,26 @@ <string name="title_notifications_items_time">Items time color</string> <string name="title_reset_ui_tweaks_to_defaults">Reset UI tweaks to default</string> <string name="title_import_from_xml">Import colors from XML</string> + <string name="summary_import_from_xml">Import colors from /sdcard/spare_parts_ui.xml</string> + <string name="title_export_to_xml">Export colors to XML</string> + <string name="summary_export_to_xml">Export colors to /sdcard/spare_parts_ui.xml</string> <string name="title_dialog_ui_interface">UI interface tweaks</string> <string name="message_dialog_reset">Reset all UI interface tweaks to default? Reboot to see changes.</string> <string name="message_dialog_import">Import UI colors from XML? Reboot to see changes.</string> + <string name="message_dialog_export">Export UI colors to XML? This will overwrite the existing file.</string> <string name="title_color_picker">Pick a color</string> <string name="msg_color_picker">Tap on center color to confirm.\nPress back to cancel.</string> + <string name="reset_ui_success">UI interface tweaks reset! Reboot to see changes.</string> <!-- XML Import/Export strings --> <string name="xml_file_not_found">XML file not found!</string> <string name="xml_io_exception">Error reading file!</string> <string name="xml_parse_error">Error parsing XML!</string> <string name="xml_invalid_color">Invalid color code in XML!</string> - <string name="xml_import_success">XML import successful! Reboot to see changes.</string> + <string name="xml_import_success">XML import successful! Reboot to see changes.</string> + <string name="xml_write_error">Error writing XML!</string> + <string name="xml_export_success">XML export successful!</string> + <string name="xml_sdcard_unmounted">SD card not mounted!</string> </resources> diff --git a/apps/SpareParts/res/xml/spare_parts.xml b/apps/SpareParts/res/xml/spare_parts.xml index e6bb4e74c..3a6d18692 100644 --- a/apps/SpareParts/res/xml/spare_parts.xml +++ b/apps/SpareParts/res/xml/spare_parts.xml @@ -262,7 +262,13 @@ <Preference android:key="import_from_xml" - android:title="@string/title_import_from_xml" /> + android:title="@string/title_import_from_xml" + android:summary="@string/summary_import_from_xml" /> + + <Preference + android:key="export_to_xml" + android:title="@string/title_export_to_xml" + android:summary="@string/summary_export_to_xml" /> </PreferenceCategory> diff --git a/apps/SpareParts/src/com/android/spare_parts/SpareParts.java b/apps/SpareParts/src/com/android/spare_parts/SpareParts.java index 5c4f900cf..532904686 100644 --- a/apps/SpareParts/src/com/android/spare_parts/SpareParts.java +++ b/apps/SpareParts/src/com/android/spare_parts/SpareParts.java @@ -52,6 +52,10 @@ import java.io.IOException; import org.xmlpull.v1.XmlPullParserException; import android.graphics.Color; import android.widget.Toast; +import java.io.FileWriter; +import org.xmlpull.v1.XmlSerializer; +import android.util.Xml; +import java.util.ArrayList; public class SpareParts extends PreferenceActivity implements Preference.OnPreferenceChangeListener, @@ -95,8 +99,9 @@ public class SpareParts extends PreferenceActivity private static final String UI_NOTIF_ITEM_TIME_COLOR = "notifications_time_color"; private static final String UI_RESET_TO_DEFAULTS = "reset_ui_tweaks_to_defaults"; private static final String UI_IMPORT_FROM_XML = "import_from_xml"; + private static final String UI_EXPORT_TO_XML = "export_to_xml"; - private static final String IMPORT_FILENAME = "spare_parts_ui.xml"; + private static final String XML_FILENAME = "spare_parts_ui.xml"; private final Configuration mCurConfig = new Configuration(); @@ -133,6 +138,7 @@ public class SpareParts extends PreferenceActivity private Preference mResetToDefaults; private Preference mImportFromXML; + private Preference mExportToXML; private IWindowManager mWindowManager; @@ -224,6 +230,7 @@ public class SpareParts extends PreferenceActivity mNotifItemTimePref = prefSet.findPreference(UI_NOTIF_ITEM_TIME_COLOR); mResetToDefaults = prefSet.findPreference(UI_RESET_TO_DEFAULTS); mImportFromXML = prefSet.findPreference(UI_IMPORT_FROM_XML); + mExportToXML = prefSet.findPreference(UI_EXPORT_TO_XML); if (!isSwapEnabled()) { prefSet.removePreference(mCompcachePref); @@ -265,19 +272,19 @@ public class SpareParts extends PreferenceActivity Settings.Secure.COMPCACHE_ENABLED, 0) != 0); mShowClockPref.setChecked(Settings.System.getInt( getContentResolver(), - Settings.System.SHOW_STATUS_CLOCK, 0) != 0); + Settings.System.SHOW_STATUS_CLOCK, 1) != 0); mShowPlmnLsPref.setChecked(Settings.System.getInt( getContentResolver(), - Settings.System.SHOW_PLMN_LS, 0) != 0); + Settings.System.SHOW_PLMN_LS, 1) != 0); mShowSpnLsPref.setChecked(Settings.System.getInt( getContentResolver(), - Settings.System.SHOW_SPN_LS, 0) != 0); + Settings.System.SHOW_SPN_LS, 1) != 0); mShowPlmnSbPref.setChecked(Settings.System.getInt( getContentResolver(), - Settings.System.SHOW_PLMN_SB, 0) != 0); + Settings.System.SHOW_PLMN_SB, 1) != 0); mShowSpnSbPref.setChecked(Settings.System.getInt( getContentResolver(), - Settings.System.SHOW_SPN_SB, 0) != 0); + Settings.System.SHOW_SPN_SB, 1) != 0); } public boolean onPreferenceChange(Preference preference, Object objValue) { @@ -405,12 +412,14 @@ public class SpareParts extends PreferenceActivity AlertDialog alertDialog = new AlertDialog.Builder(this).create(); alertDialog.setTitle(getResources().getString(R.string.title_dialog_ui_interface)); alertDialog.setMessage(getResources().getString(R.string.message_dialog_reset)); - alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, getResources().getString(android.R.string.ok), new DialogInterface.OnClickListener() { + alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, getResources().getString(android.R.string.ok), + new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { resetUITweaks(); } }); - alertDialog.setButton(DialogInterface.BUTTON_NEGATIVE, getResources().getString(android.R.string.cancel), new DialogInterface.OnClickListener() { + alertDialog.setButton(DialogInterface.BUTTON_NEGATIVE, getResources().getString(android.R.string.cancel), + new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { } @@ -423,12 +432,14 @@ public class SpareParts extends PreferenceActivity AlertDialog alertDialog = new AlertDialog.Builder(this).create(); alertDialog.setTitle(getResources().getString(R.string.title_dialog_ui_interface)); alertDialog.setMessage(getResources().getString(R.string.message_dialog_import)); - alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, getResources().getString(android.R.string.ok), new DialogInterface.OnClickListener() { + alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, getResources().getString(android.R.string.ok), + new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { readUIValuesFromXML(); } }); - alertDialog.setButton(DialogInterface.BUTTON_NEGATIVE, getResources().getString(android.R.string.cancel), new DialogInterface.OnClickListener() { + alertDialog.setButton(DialogInterface.BUTTON_NEGATIVE, getResources().getString(android.R.string.cancel), + new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { } @@ -437,6 +448,26 @@ public class SpareParts extends PreferenceActivity return true; } + else if (preference == mExportToXML) { + AlertDialog alertDialog = new AlertDialog.Builder(this).create(); + alertDialog.setTitle(getResources().getString(R.string.title_dialog_ui_interface)); + alertDialog.setMessage(getResources().getString(R.string.message_dialog_export)); + alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, getResources().getString(android.R.string.ok), + new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int which) { + writeUIValuesToXML(); + } + }); + alertDialog.setButton(DialogInterface.BUTTON_NEGATIVE, getResources().getString(android.R.string.cancel), + new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int which) { + + } + }); + alertDialog.show(); + + return true; + } return false; } @@ -470,18 +501,21 @@ public class SpareParts extends PreferenceActivity mShowSpnLsPref.setChecked(true); mShowPlmnSbPref.setChecked(true); mShowSpnSbPref.setChecked(true); + + Toast.makeText(getApplicationContext(), R.string.reset_ui_success, Toast.LENGTH_SHORT).show(); } private void readUIValuesFromXML() { if (!Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) { + Toast.makeText(getApplicationContext(), R.string.xml_sdcard_unmounted, Toast.LENGTH_SHORT).show(); return; - } + } FileReader reader = null; boolean success = false; try { - reader = new FileReader(new File(Environment.getExternalStorageDirectory() + "/" + IMPORT_FILENAME)); + reader = new FileReader(new File(Environment.getExternalStorageDirectory() + "/" + XML_FILENAME)); XmlPullParserFactory factory = XmlPullParserFactory.newInstance(); XmlPullParser parser = factory.newPullParser(); parser.setInput(reader); @@ -524,9 +558,119 @@ public class SpareParts extends PreferenceActivity if (success) { Toast.makeText(getApplicationContext(), R.string.xml_import_success, Toast.LENGTH_SHORT).show(); - } + } + } + + private void writeUIValuesToXML() { + if (!Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) { + Toast.makeText(getApplicationContext(), R.string.xml_sdcard_unmounted, Toast.LENGTH_SHORT).show(); + return; + } + + FileWriter writer = null; + File outFile = new File(Environment.getExternalStorageDirectory() + "/" + "tempfile.xml"); + boolean success = false; + + try { + outFile.createNewFile(); + writer = new FileWriter(outFile); + XmlSerializer serializer = Xml.newSerializer(); + + ArrayList<String> elements = new ArrayList<String>(); + elements.add(Settings.System.BATTERY_PERCENTAGE_STATUS_COLOR); + elements.add(Settings.System.CLOCK_COLOR); + elements.add(Settings.System.DATE_COLOR); + elements.add(Settings.System.PLMN_LABEL_COLOR); + elements.add(Settings.System.SPN_LABEL_COLOR); + elements.add(Settings.System.NEW_NOTIF_TICKER_COLOR); + elements.add(Settings.System.NOTIF_COUNT_COLOR); + elements.add(Settings.System.NO_NOTIF_COLOR); + elements.add(Settings.System.CLEAR_BUTTON_LABEL_COLOR); + elements.add(Settings.System.ONGOING_NOTIF_COLOR); + elements.add(Settings.System.LATEST_NOTIF_COLOR); + elements.add(Settings.System.NOTIF_ITEM_TITLE_COLOR); + elements.add(Settings.System.NOTIF_ITEM_TEXT_COLOR); + elements.add(Settings.System.NOTIF_ITEM_TIME_COLOR); + + serializer.setOutput(writer); + serializer.startDocument("UTF-8", true); + serializer.startTag("", "spareparts"); + + int color = -1; + + for (String s : elements) { + try { + color = Settings.System.getInt(getContentResolver(), s); + } + catch (SettingNotFoundException e) { + if (s.equals(Settings.System.BATTERY_PERCENTAGE_STATUS_COLOR) || + s.equals(Settings.System.NOTIF_COUNT_COLOR) || + s.equals(Settings.System.NO_NOTIF_COLOR) || + s.equals(Settings.System.ONGOING_NOTIF_COLOR) || + s.equals(Settings.System.LATEST_NOTIF_COLOR)) { + color = -1; + } + else { + color = -16777216; + } + } + + serializer.startTag("", s); + serializer.text(convertToARGB(color)); + serializer.endTag("", s); + } - + serializer.endTag("", "spareparts"); + serializer.endDocument(); + serializer.flush(); + success = true; + } + catch (Exception e) { + android.util.Log.d("WYSIE", e.toString()); + Toast.makeText(getApplicationContext(), R.string.xml_write_error, Toast.LENGTH_SHORT).show(); + } + finally { + if (writer != null) { + try { + writer.close(); + } catch (IOException e) { + } + } + } + + if (success) { + File xmlFile = new File(Environment.getExternalStorageDirectory() + "/" + XML_FILENAME); + outFile.renameTo(xmlFile); + Toast.makeText(getApplicationContext(), R.string.xml_export_success, Toast.LENGTH_SHORT).show(); + } + + if (outFile.exists()) + outFile.delete(); + } + + private String convertToARGB(int color) { + String alpha = Integer.toHexString(Color.alpha(color)); + String red = Integer.toHexString(Color.red(color)); + String green = Integer.toHexString(Color.green(color)); + String blue = Integer.toHexString(Color.blue(color)); + + if (alpha.length() == 1) { + alpha = "0" + alpha; + } + + if (red.length() == 1) { + red = "0" + red; + } + + if (green.length() == 1) { + green = "0" + green; + } + + if (blue.length() == 1) { + blue = "0" + blue; + } + + return "#" + alpha + red + green + blue; } public void writeAnimationPreference(int which, Object objValue) { |
