Skip to content

Commit

Permalink
1. Implemented "Huge" font size setting feature request (Issue #115).
Browse files Browse the repository at this point in the history
2. Added Android Testing Framework project to the main project.
3. Wrote unit tests using JUnit to unit test changes for Issue #115.
  • Loading branch information
yuri-danilchenko committed Apr 15, 2011
1 parent b302eaa commit 82e6620
Show file tree
Hide file tree
Showing 13 changed files with 230 additions and 10 deletions.
2 changes: 2 additions & 0 deletions res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,13 @@
<item>Medium</item>
<item>Large</item>
<item>Larger</item>
<item>Huge</item>
</string-array>
<string-array name="pref_text_size_values" translatable="false">
<item>TEXT_SIZE_MEDIUM</item>
<item>TEXT_SIZE_LARGE</item>
<item>TEXT_SIZE_LARGER</item>
<item>TEXT_SIZE_HUGE</item>
</string-array>

<string name="pref_show_comment_guide_lines">Comment guide lines</string>
Expand Down
27 changes: 27 additions & 0 deletions res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,28 @@
<item name="android:textAppearanceLarge">@style/TextAppearance_Larger.Large</item>
</style>

<style name="Reddit_Light_Huge" parent="@android:style/Theme.Light">
<item name="android:listSelector">@drawable/list_selector_blue</item>
<item name="android:cacheColorHint">@color/white</item>
<item name="android:textAppearanceSmall">@style/TextAppearance_Huge.Small</item>
<item name="android:textAppearanceMedium">@style/TextAppearance_Huge.Medium</item>
<item name="android:textAppearanceLarge">@style/TextAppearance_Huge.Large</item>
</style>

<style name="Reddit_Dark_Larger" parent="@android:style/Theme">
<item name="android:textAppearanceSmall">@style/TextAppearance_Larger.Small</item>
<item name="android:textAppearanceMedium">@style/TextAppearance_Larger.Medium</item>
<item name="android:textAppearanceLarge">@style/TextAppearance_Larger.Large</item>
<item name="android:windowBackground">@color/black</item>
</style>

<style name="Reddit_Dark_Huge" parent="@android:style/Theme">
<item name="android:textAppearanceSmall">@style/TextAppearance_Huge.Small</item>
<item name="android:textAppearanceMedium">@style/TextAppearance_Huge.Medium</item>
<item name="android:textAppearanceLarge">@style/TextAppearance_Huge.Large</item>
<item name="android:windowBackground">@color/black</item>
</style>

<!-- TextAppearance for different font size settings -->
<style name="TextAppearance_Medium.Small" parent="@android:style/TextAppearance.Small">
<item name="android:textSize">10sp</item>
Expand All @@ -90,6 +105,7 @@
<style name="TextAppearance_Medium.Large" parent="@android:style/TextAppearance.Large">
<item name="android:textSize">14sp</item>
</style>

<style name="TextAppearance_Large.Small" parent="@android:style/TextAppearance.Small">
<item name="android:textSize">12sp</item>
</style>
Expand All @@ -99,6 +115,7 @@
<style name="TextAppearance_Large.Large" parent="@android:style/TextAppearance.Large">
<item name="android:textSize">14sp</item>
</style>

<style name="TextAppearance_Larger.Small" parent="@android:style/TextAppearance.Small">
<item name="android:textSize">14sp</item>
</style>
Expand All @@ -109,5 +126,15 @@
<item name="android:textSize">16sp</item>
</style>

<style name="TextAppearance_Huge.Small" parent="@android:style/TextAppearance.Small">
<item name="android:textSize">18sp</item>
</style>
<style name="TextAppearance_Huge.Medium" parent="@android:style/TextAppearance.Medium">
<item name="android:textSize">20sp</item>
</style>
<style name="TextAppearance_Huge.Large" parent="@android:style/TextAppearance.Large">
<item name="android:textSize">22sp</item>
</style>

</resources>

5 changes: 3 additions & 2 deletions src/com/andrewshu/android/reddit/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -282,12 +282,13 @@ static final class CommentsSort {
static final String PREF_ALWAYS_SHOW_NEXT_PREVIOUS = "always_show_next_previous";
static final String PREF_COMMENTS_SORT_BY_URL = "sort_by_url";
static final String PREF_THEME = "theme";
static final String PREF_THEME_LIGHT = "THEME_LIGHT";
static final String PREF_THEME_DARK = "THEME_DARK";
public static final String PREF_THEME_LIGHT = "THEME_LIGHT";
public static final String PREF_THEME_DARK = "THEME_DARK";
static final String PREF_TEXT_SIZE = "text_size";
static final String PREF_TEXT_SIZE_MEDIUM = "TEXT_SIZE_MEDIUM";
static final String PREF_TEXT_SIZE_LARGE = "TEXT_SIZE_LARGE";
static final String PREF_TEXT_SIZE_LARGER = "TEXT_SIZE_LARGER";
public static final String PREF_TEXT_SIZE_HUGE = "TEXT_SIZE_HUGE";
static final String PREF_SHOW_COMMENT_GUIDE_LINES = "show_comment_guide_lines";
static final String PREF_ROTATION = "rotation";
static final String PREF_ROTATION_UNSPECIFIED = "ROTATION_UNSPECIFIED";
Expand Down
40 changes: 32 additions & 8 deletions src/com/andrewshu/android/reddit/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -176,75 +176,87 @@ public static boolean isHttpStatusOK(HttpResponse response) {
// Theme
// ===============

static boolean isLightTheme(int theme) {
return theme == R.style.Reddit_Light_Medium || theme == R.style.Reddit_Light_Large || theme == R.style.Reddit_Light_Larger;
public static boolean isLightTheme(int theme) {
return theme == R.style.Reddit_Light_Medium || theme == R.style.Reddit_Light_Large || theme == R.style.Reddit_Light_Larger || theme == R.style.Reddit_Light_Huge;
}

static boolean isDarkTheme(int theme) {
return theme == R.style.Reddit_Dark_Medium || theme == R.style.Reddit_Dark_Large || theme == R.style.Reddit_Dark_Larger;
public static boolean isDarkTheme(int theme) {
return theme == R.style.Reddit_Dark_Medium || theme == R.style.Reddit_Dark_Large || theme == R.style.Reddit_Dark_Larger || theme == R.style.Reddit_Dark_Huge;
}

static int getInvertedTheme(int theme) {
public static int getInvertedTheme(int theme) {
switch (theme) {
case R.style.Reddit_Light_Medium:
return R.style.Reddit_Dark_Medium;
case R.style.Reddit_Light_Large:
return R.style.Reddit_Dark_Large;
case R.style.Reddit_Light_Larger:
return R.style.Reddit_Dark_Larger;
case R.style.Reddit_Light_Huge:
return R.style.Reddit_Dark_Huge;
case R.style.Reddit_Dark_Medium:
return R.style.Reddit_Light_Medium;
case R.style.Reddit_Dark_Large:
return R.style.Reddit_Light_Large;
case R.style.Reddit_Dark_Larger:
return R.style.Reddit_Light_Larger;
case R.style.Reddit_Dark_Huge:
return R.style.Reddit_Light_Huge;
default:
return R.style.Reddit_Light_Medium;
}
}

static int getThemeResourceFromPrefs(String themePref, String textSizePref) {
public static int getThemeResourceFromPrefs(String themePref, String textSizePref) {
if (Constants.PREF_THEME_LIGHT.equals(themePref)) {
if (Constants.PREF_TEXT_SIZE_MEDIUM.equals(textSizePref))
return R.style.Reddit_Light_Medium;
else if (Constants.PREF_TEXT_SIZE_LARGE.equals(textSizePref))
return R.style.Reddit_Light_Large;
else if (Constants.PREF_TEXT_SIZE_LARGER.equals(textSizePref))
return R.style.Reddit_Light_Larger;
else if (Constants.PREF_TEXT_SIZE_HUGE.equals(textSizePref))
return R.style.Reddit_Light_Huge;
} else /* if (Constants.PREF_THEME_DARK.equals(themePref)) */ {
if (Constants.PREF_TEXT_SIZE_MEDIUM.equals(textSizePref))
return R.style.Reddit_Dark_Medium;
else if (Constants.PREF_TEXT_SIZE_LARGE.equals(textSizePref))
return R.style.Reddit_Dark_Large;
else if (Constants.PREF_TEXT_SIZE_LARGER.equals(textSizePref))
return R.style.Reddit_Dark_Larger;
else if (Constants.PREF_TEXT_SIZE_HUGE.equals(textSizePref))
return R.style.Reddit_Dark_Huge;
}
return R.style.Reddit_Light_Medium;
}

/**
* Return the theme and textSize String prefs
*/
static String[] getPrefsFromThemeResource(int theme) {
public static String[] getPrefsFromThemeResource(int theme) {
switch (theme) {
case R.style.Reddit_Light_Medium:
return new String[] { Constants.PREF_THEME_LIGHT, Constants.PREF_TEXT_SIZE_MEDIUM };
case R.style.Reddit_Light_Large:
return new String[] { Constants.PREF_THEME_LIGHT, Constants.PREF_TEXT_SIZE_LARGE };
case R.style.Reddit_Light_Larger:
return new String[] { Constants.PREF_THEME_LIGHT, Constants.PREF_TEXT_SIZE_LARGER };
case R.style.Reddit_Light_Huge:
return new String[] { Constants.PREF_THEME_LIGHT, Constants.PREF_TEXT_SIZE_HUGE };
case R.style.Reddit_Dark_Medium:
return new String[] { Constants.PREF_THEME_DARK, Constants.PREF_TEXT_SIZE_MEDIUM };
case R.style.Reddit_Dark_Large:
return new String[] { Constants.PREF_THEME_DARK, Constants.PREF_TEXT_SIZE_LARGE };
case R.style.Reddit_Dark_Larger:
return new String[] { Constants.PREF_THEME_DARK, Constants.PREF_TEXT_SIZE_LARGER };
case R.style.Reddit_Dark_Huge:
return new String[] { Constants.PREF_THEME_DARK, Constants.PREF_TEXT_SIZE_HUGE };
default:
return new String[] { Constants.PREF_THEME_LIGHT, Constants.PREF_TEXT_SIZE_MEDIUM };
}
}

static int getTextAppearanceResource(int themeResource, int androidTextAppearanceStyle) {
public static int getTextAppearanceResource(int themeResource, int androidTextAppearanceStyle) {
switch (themeResource) {
case R.style.Reddit_Light_Medium:
case R.style.Reddit_Dark_Medium:
Expand Down Expand Up @@ -282,6 +294,18 @@ static int getTextAppearanceResource(int themeResource, int androidTextAppearanc
default:
return R.style.TextAppearance_Larger_Medium;
}
case R.style.Reddit_Light_Huge:
case R.style.Reddit_Dark_Huge:
switch (androidTextAppearanceStyle) {
case android.R.style.TextAppearance_Small:
return R.style.TextAppearance_Huge_Small;
case android.R.style.TextAppearance_Medium:
return R.style.TextAppearance_Huge_Medium;
case android.R.style.TextAppearance_Large:
return R.style.TextAppearance_Huge_Large;
default:
return R.style.TextAppearance_Huge_Medium;
}
default:
return R.style.TextAppearance_Medium_Medium;
}
Expand Down
12 changes: 12 additions & 0 deletions tests/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.andrewshu.android.reddit.test"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="4" />
<instrumentation android:targetPackage="com.andrewshu.android.reddit" android:name="android.test.InstrumentationTestRunner" />
<application android:icon="@drawable/icon" android:label="@string/app_name">

<uses-library android:name="android.test.runner" />
</application>
</manifest>
11 changes: 11 additions & 0 deletions tests/default.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# This file is automatically generated by Android Tools.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file must be checked in Version Control Systems.
#
# To customize properties used by the Ant build system use,
# "build.properties", and override values to adapt the script to your
# project structure.

# Project target.
target=android-7
36 changes: 36 additions & 0 deletions tests/proguard.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontpreverify
-verbose
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*

-keep public class * extends android.app.Activity
-keep public class * extends android.app.Application
-keep public class * extends android.app.Service
-keep public class * extends android.content.BroadcastReceiver
-keep public class * extends android.content.ContentProvider
-keep public class * extends android.app.backup.BackupAgentHelper
-keep public class * extends android.preference.Preference
-keep public class com.android.vending.licensing.ILicensingService

-keepclasseswithmembernames class * {
native <methods>;
}

-keepclasseswithmembernames class * {
public <init>(android.content.Context, android.util.AttributeSet);
}

-keepclasseswithmembernames class * {
public <init>(android.content.Context, android.util.AttributeSet, int);
}

-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}

-keep class * implements android.os.Parcelable {
public static final android.os.Parcelable$Creator *;
}
Binary file added tests/res/drawable-hdpi/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/res/drawable-ldpi/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/res/drawable-mdpi/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions tests/res/layout/main.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
</LinearLayout>
5 changes: 5 additions & 0 deletions tests/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello">Hello World!</string>
<string name="app_name">reddit is funTest</string>
</resources>
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package com.andrewshu.android.reddit.test;

import java.lang.reflect.Array;
import java.util.Arrays;

import com.andrewshu.android.reddit.Constants;
import com.andrewshu.android.reddit.Util;
import com.andrewshu.android.reddit.R;

import junit.framework.TestCase;

public class RedditIsFunUtilTest extends TestCase {

public void testIsLightTheme()
{

boolean result = Util.isLightTheme(R.style.Reddit_Light_Medium) &&
Util.isLightTheme(R.style.Reddit_Light_Large) &&
Util.isLightTheme(R.style.Reddit_Light_Larger) &&
Util.isLightTheme(R.style.Reddit_Light_Huge);

assertTrue(result);

}

public void testIsDarkTheme()
{

boolean result = Util.isDarkTheme(R.style.Reddit_Dark_Medium) &&
Util.isDarkTheme(R.style.Reddit_Dark_Large) &&
Util.isDarkTheme(R.style.Reddit_Dark_Larger) &&
Util.isDarkTheme(R.style.Reddit_Dark_Huge);

assertTrue(result);

}

public void testGetInvertedTheme()
{

assertEquals("GetInvertedTheme From Dark to Light Failed", R.style.Reddit_Dark_Huge, Util.getInvertedTheme(R.style.Reddit_Light_Huge));

assertEquals("GetInvertedTheme From Light to Dark Failed", R.style.Reddit_Light_Huge, Util.getInvertedTheme(R.style.Reddit_Dark_Huge));

}

public void testGetThemeResourceFromPrefs()
{

assertEquals("GetThemeResourceFromPrefs for Dark Theme Failed", R.style.Reddit_Dark_Huge, Util.getThemeResourceFromPrefs(Constants.PREF_THEME_DARK, Constants.PREF_TEXT_SIZE_HUGE));

assertEquals("GetThemeResourceFromPrefs for Light Theme Failed", R.style.Reddit_Light_Huge, Util.getThemeResourceFromPrefs(Constants.PREF_THEME_LIGHT, Constants.PREF_TEXT_SIZE_HUGE));

}

public void testGetPrefsFromThemeResource()
{

boolean blnResultForDarkTheme;
boolean blnResultForLightTheme;

String [] astrDarkHugePrefs = new String[] { Constants.PREF_THEME_DARK, Constants.PREF_TEXT_SIZE_HUGE };
String [] astrLightHugePrefs = new String[] { Constants.PREF_THEME_LIGHT, Constants.PREF_TEXT_SIZE_HUGE };

blnResultForDarkTheme = Arrays.equals(astrDarkHugePrefs, Util.getPrefsFromThemeResource(R.style.Reddit_Dark_Huge));
blnResultForLightTheme = Arrays.equals(astrLightHugePrefs, Util.getPrefsFromThemeResource(R.style.Reddit_Light_Huge));

assertTrue(blnResultForDarkTheme && blnResultForLightTheme);

}

public void testGetTextAppearanceResource()
{

assertEquals("GetTextAppearanceResource for Dark Theme Small Text Failed", R.style.TextAppearance_Huge_Small, Util.getTextAppearanceResource(R.style.Reddit_Dark_Huge, android.R.style.TextAppearance_Small));

assertEquals("GetTextAppearanceResource for Dark Theme Medium Text Failed", R.style.TextAppearance_Huge_Medium, Util.getTextAppearanceResource(R.style.Reddit_Dark_Huge, android.R.style.TextAppearance_Medium));

assertEquals("GetTextAppearanceResource for Dark Theme Large Text Failed", R.style.TextAppearance_Huge_Large, Util.getTextAppearanceResource(R.style.Reddit_Dark_Huge, android.R.style.TextAppearance_Large));

assertEquals("GetTextAppearanceResource for Light Theme Small Text Failed", R.style.TextAppearance_Huge_Small, Util.getTextAppearanceResource(R.style.Reddit_Light_Huge, android.R.style.TextAppearance_Small));

assertEquals("GetTextAppearanceResource for Light Theme Medium Text Failed", R.style.TextAppearance_Huge_Medium, Util.getTextAppearanceResource(R.style.Reddit_Light_Huge, android.R.style.TextAppearance_Medium));

assertEquals("GetTextAppearanceResource for Light Theme Large Text Failed", R.style.TextAppearance_Huge_Large, Util.getTextAppearanceResource(R.style.Reddit_Light_Huge, android.R.style.TextAppearance_Large));


}

}

0 comments on commit 82e6620

Please sign in to comment.