Skip to content

Commit

Permalink
Added preference for selecting theme.
Browse files Browse the repository at this point in the history
  • Loading branch information
hdweiss committed Sep 24, 2012
1 parent 0ecd014 commit 73b176d
Show file tree
Hide file tree
Showing 17 changed files with 84 additions and 24 deletions.
1 change: 1 addition & 0 deletions res/drawable/border.xml
Expand Up @@ -2,4 +2,5 @@
<shape android:shape="rectangle" xmlns:android="http://schemas.android.com/apk/res/android">
<stroke android:width="1dp" android:color="#ADADAD" />
<corners android:radius="5dp" />
<solid android:color="@android:color/transparent" />
</shape>
14 changes: 11 additions & 3 deletions res/drawable/outline_item_selected.xml
@@ -1,5 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<shape android:shape="rectangle" xmlns:android="http://schemas.android.com/apk/res/android">
<stroke android:width="1px" android:color="#ADADAD" />
<corners android:radius="2px" />
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >

<stroke
android:width="1px"
android:color="#ADADAD" />

<corners android:radius="2px" />

<solid android:color="@android:color/transparent" />

</shape>
5 changes: 0 additions & 5 deletions res/drawable/outline_selection.xml

This file was deleted.

6 changes: 5 additions & 1 deletion res/values/arrays.xml
Expand Up @@ -61,5 +61,9 @@
<item>3 levels of recursion</item>
<item>4 levels of recursion</item>
</string-array>
<string-array name="themes">
<item>Light</item>
<item>Dark</item>
</string-array>

</resources>
</resources>
3 changes: 1 addition & 2 deletions res/values/strings.xml
Expand Up @@ -169,8 +169,7 @@
<string name="preference_calendar_show_habits">Show habits</string>
<string name="preference_calendar_show_done_summary">Show done items in the calendar</string>
<string name="preference_calendar_show_done">Show done</string>
<string name="preference_fullscreen_title">Fullscreen</string>
<string name="preference_fullscreen_summary">Toggle fullscreen.</string>
<string name="preference_theme_title">Theme</string>
<string name="preference_capture_advanced_title">Advanced capture</string>
<string name="preference_capture_advanced">Advanced capturing mechanism that allows capturing files under arbitrary headings.</string>
<string name="edit_date_start">Start</string>
Expand Down
7 changes: 7 additions & 0 deletions res/xml/preferences.xml
Expand Up @@ -33,6 +33,13 @@
android:title="@string/title_auto_sync_interval" />
</PreferenceCategory>
<PreferenceCategory android:title="@string/preference_viewing" >
<ListPreference
android:defaultValue="Dark"
android:entries="@array/themes"
android:entryValues="@array/themes"
android:key="theme"
android:title="@string/preference_theme_title" />

<CheckBoxPreference
android:key="combineBlockAgendas"
android:summary="@string/preference_combine_block_agenda_summary"
Expand Down
1 change: 1 addition & 0 deletions src/com/matburt/mobileorg/Gui/Capture/EditActivity.java
Expand Up @@ -41,6 +41,7 @@ public class EditActivity extends SherlockFragmentActivity implements

@Override
public void onCreate(Bundle savedInstanceState) {
OrgUtils.setTheme(this);
super.onCreate(savedInstanceState);
setContentView(R.layout.edit);
getSupportActionBar().setTitle(R.string.menu_capture);
Expand Down
Expand Up @@ -10,6 +10,7 @@
import android.widget.TextView;

import com.matburt.mobileorg.R;
import com.matburt.mobileorg.util.OrgUtils;

public class CertificateConflictActivity extends Activity {

Expand All @@ -19,6 +20,7 @@ public class CertificateConflictActivity extends Activity {
private Button deny_button;

public void onCreate(Bundle savedInstanceState) {
OrgUtils.setTheme(this);
super.onCreate(savedInstanceState);
setContentView(R.layout.certconflict);

Expand Down
1 change: 1 addition & 0 deletions src/com/matburt/mobileorg/Gui/Outline/OutlineActivity.java
Expand Up @@ -40,6 +40,7 @@ public class OutlineActivity extends SherlockActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
OrgUtils.setTheme(this);
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_PROGRESS);
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
Expand Down
4 changes: 2 additions & 2 deletions src/com/matburt/mobileorg/Gui/Outline/OutlineItem.java
Expand Up @@ -166,9 +166,9 @@ public boolean isChecked() {
@Override
public void setChecked(boolean checked) {
if(checked)
setBackgroundResource(R.drawable.outline_selection);
setBackgroundResource(R.drawable.outline_item_selected);
else
setBackgroundResource(android.R.color.transparent);
setBackgroundResource(0);
}

@Override
Expand Down
2 changes: 2 additions & 0 deletions src/com/matburt/mobileorg/Gui/SearchActivity.java
Expand Up @@ -13,6 +13,7 @@
import com.matburt.mobileorg.Gui.Outline.OutlineListView;
import com.matburt.mobileorg.OrgData.OrgNode;
import com.matburt.mobileorg.OrgData.OrgProviderUtils;
import com.matburt.mobileorg.util.OrgUtils;

public class SearchActivity extends SherlockActivity {

Expand All @@ -21,6 +22,7 @@ public class SearchActivity extends SherlockActivity {

@Override
public void onCreate(Bundle savedInstanceState) {
OrgUtils.setTheme(this);
super.onCreate(savedInstanceState);
setContentView(R.layout.search);

Expand Down
1 change: 1 addition & 0 deletions src/com/matburt/mobileorg/Gui/ViewActivity.java
Expand Up @@ -24,6 +24,7 @@ public class ViewActivity extends SherlockFragmentActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
OrgUtils.setTheme(this);
super.onCreate(savedInstanceState);

setContentView(R.layout.view);
Expand Down
11 changes: 9 additions & 2 deletions src/com/matburt/mobileorg/Gui/ViewFragment.java
Expand Up @@ -62,13 +62,20 @@ public void displayPayload(OrgNode node) {

public void display(OrgNode node, int levelOfRecursion, ContentResolver resolver) {
OrgNode2Html htmlNode = new OrgNode2Html(resolver);
htmlNode.setupConfig(getActivity());
htmlNode.setupConfig(getActivity(), getFontColor());
String html = htmlNode.toHTML(node, levelOfRecursion);
displayHtml(html);
}

private String getFontColor() {
if(OrgUtils.isThemeLight(getActivity()))
return "black";
else
return "white";
}

public void displayError() {
String html = "<html><body><font color='white'>"
String html = "<html><body><font color='" + getFontColor() + "'>"
+ getString(R.string.node_view_error_loading_node)
+ "</font></body></html>";
displayHtml(html);
Expand Down
1 change: 1 addition & 0 deletions src/com/matburt/mobileorg/Settings/SettingsActivity.java
Expand Up @@ -42,6 +42,7 @@ public class SettingsActivity extends SherlockPreferenceActivity implements

@Override
protected void onCreate(Bundle savedInstanceState) {
OrgUtils.setTheme(this);
super.onCreate(savedInstanceState);

Intent prefsIntent = getIntent();
Expand Down
2 changes: 2 additions & 0 deletions src/com/matburt/mobileorg/Settings/WizardActivity.java
Expand Up @@ -39,6 +39,7 @@
import com.matburt.mobileorg.Synchronizers.UbuntuOneSynchronizer;
import com.matburt.mobileorg.Synchronizers.WebDAVSynchronizer;
import com.matburt.mobileorg.Views.PageFlipView;
import com.matburt.mobileorg.util.OrgUtils;

public class WizardActivity extends Activity {

Expand Down Expand Up @@ -120,6 +121,7 @@ public void handleMessage(Message msg)
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
OrgUtils.setTheme(this);
super.onCreate(savedInstanceState);
setContentView(R.layout.wizard);
wizard = (PageFlipView) findViewById(R.id.wizard_parent);
Expand Down
12 changes: 8 additions & 4 deletions src/com/matburt/mobileorg/util/OrgNode2Html.java
Expand Up @@ -16,15 +16,19 @@ public class OrgNode2Html {
public boolean wrapLines = false;
public boolean viewApplyFormating = true;

private String fontColor = "white";

public OrgNode2Html(ContentResolver resolver) {
this.resolver = resolver;
}

public void setupConfig(Context context) {
public void setupConfig(Context context, String fontColor) {
this.wrapLines = PreferenceManager.getDefaultSharedPreferences(context)
.getBoolean("viewWrapLines", false);
this.viewApplyFormating = PreferenceManager.getDefaultSharedPreferences(context).getBoolean(
"viewApplyFormating", true);

this.fontColor = fontColor;
}

public String toHTML(OrgNode node) {
Expand All @@ -46,7 +50,7 @@ public String payloadToHTML(OrgNode node) {

private String convertToHTML(String text) {
if(text == null || text.trim().equals(""))
return "<html><body><font color='white'><pre>" + text + "</pre></font></body></html>";
return "<html><body><font color='" + fontColor + "'><pre>" + text + "</pre></font></body></html>";

text = convertLinks(text);

Expand All @@ -58,10 +62,10 @@ private String convertToHTML(String text) {

text = text.replaceAll("((\\s*\\|[^\\n]*\\|\\s*(?:<br/>)?\\n)+)", "<pre>$1</pre>");

text = "<html><body><font color='white'>" + text + "</font></body></html>";
text = "<html><body><font color='" + fontColor + "'>" + text + "</font></body></html>";
} else {
text = text.replaceAll("\\n", "<br/>\n");
text = "<html><body><font color='white'><pre>" + text + "</pre></font></body></html>";
text = "<html><body><font color='" + fontColor + "'><pre>" + text + "</pre></font></body></html>";
}

return text;
Expand Down
35 changes: 30 additions & 5 deletions src/com/matburt/mobileorg/util/OrgUtils.java
Expand Up @@ -9,11 +9,7 @@
import java.util.Comparator;
import java.util.Date;

import com.matburt.mobileorg.R;
import com.matburt.mobileorg.OrgData.OrgFile;
import com.matburt.mobileorg.OrgData.OrgNode;
import com.matburt.mobileorg.Synchronizers.Synchronizer;

import android.app.Activity;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
Expand All @@ -24,6 +20,11 @@
import android.widget.ArrayAdapter;
import android.widget.Spinner;

import com.matburt.mobileorg.R;
import com.matburt.mobileorg.OrgData.OrgFile;
import com.matburt.mobileorg.OrgData.OrgNode;
import com.matburt.mobileorg.Synchronizers.Synchronizer;

public class OrgUtils {

public static String getTimestamp() {
Expand Down Expand Up @@ -185,4 +186,28 @@ public int compare(Object o1, Object o2) {
return s1.toLowerCase().compareTo(s2.toLowerCase());
}
}

public static String getThemeName(Context context) {
SharedPreferences appSettings =
PreferenceManager.getDefaultSharedPreferences(context);
return appSettings.getString("theme", "Dark");
}

public static void setTheme(Activity activity) {
String themeName = getThemeName(activity);

if(themeName.equals("Light"))
activity.setTheme(R.style.Theme_MobileOrg_Light);
else
activity.setTheme(R.style.Theme_MobileOrg_Dark);
}

public static boolean isThemeLight(Context context) {
String themeName = getThemeName(context);

if(themeName.equals("Light"))
return true;
else
return false;
}
}

0 comments on commit 73b176d

Please sign in to comment.