Fix lint and test issues

pull/493/head
Alex Baker 9 years ago
parent c8fef50fc8
commit 17d3c420b8

@ -9,7 +9,9 @@ package com.todoroo.andlib.test;
import android.content.res.Configuration; import android.content.res.Configuration;
import android.content.res.Resources; import android.content.res.Resources;
import android.support.test.runner.AndroidJUnit4; import android.support.test.runner.AndroidJUnit4;
import android.util.DisplayMetrics; import android.support.v4.text.TextUtilsCompat;
import com.todoroo.andlib.data.Callback;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
@ -21,6 +23,7 @@ import java.util.List;
import java.util.Locale; import java.util.Locale;
import static android.support.test.InstrumentationRegistry.getTargetContext; import static android.support.test.InstrumentationRegistry.getTargetContext;
import static android.support.v4.view.ViewCompat.LAYOUT_DIRECTION_LTR;
import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertFalse; import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertTrue; import static junit.framework.Assert.assertTrue;
@ -36,29 +39,23 @@ import static junit.framework.Assert.assertTrue;
@RunWith(AndroidJUnit4.class) @RunWith(AndroidJUnit4.class)
public class TranslationTests { public class TranslationTests {
/**
* Sets locale
*/
private void setLocale(Locale locale) {
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
DisplayMetrics metrics = getTargetContext().getResources().getDisplayMetrics();
getTargetContext().getResources().updateConfiguration(config, metrics);
}
/** /**
* Loop through each locale and call runnable * Loop through each locale and call runnable
*/ */
private void forEachLocale(Runnable r) { private void forEachLocale(Callback<Resources> callback) {
Locale[] locales = Locale.getAvailableLocales(); Locale[] locales = Locale.getAvailableLocales();
for(Locale locale : locales) { for(Locale locale : locales) {
setLocale(locale); callback.apply(getResourcesForLocale(locale));
r.run();
} }
} }
private Resources getResourcesForLocale(Locale locale) {
Resources resources = getTargetContext().getResources();
Configuration configuration = new Configuration(resources.getConfiguration());
configuration.locale = locale;
return new Resources(resources.getAssets(), resources.getDisplayMetrics(), configuration);
}
private static final class FormatStringData { private static final class FormatStringData {
private static final char[] scratch = new char[10]; private static final char[] scratch = new char[10];
@ -157,7 +154,7 @@ public class TranslationTests {
*/ */
@Test @Test
public void testFormatStringsMatch() throws Exception { public void testFormatStringsMatch() throws Exception {
final Resources r = getTargetContext().getResources(); final Resources resources = getTargetContext().getResources();
final int[] strings = getResourceIds(R.string.class); final int[] strings = getResourceIds(R.string.class);
final FormatStringData[] formatStrings = new FormatStringData[strings.length]; final FormatStringData[] formatStrings = new FormatStringData[strings.length];
@ -165,16 +162,16 @@ public class TranslationTests {
for(int i = 0; i < strings.length; i++) { for(int i = 0; i < strings.length; i++) {
try { try {
String string = r.getString(strings[i]); String string = resources.getString(strings[i]);
formatStrings[i] = new FormatStringData(string); formatStrings[i] = new FormatStringData(string);
} catch (Exception e) { } catch (Exception e) {
String name = r.getResourceName(strings[i]); String name = resources.getResourceName(strings[i]);
failures.append(String.format("error opening %s: %s\n", failures.append(String.format("error opening %s: %s\n",
name, e.getMessage())); name, e.getMessage()));
} }
} }
forEachLocale(() -> { forEachLocale(r -> {
Locale locale = r.getConfiguration().locale; Locale locale = r.getConfiguration().locale;
for(int i = 0; i < strings.length; i++) { for(int i = 0; i < strings.length; i++) {
try { try {
@ -203,15 +200,15 @@ public class TranslationTests {
/** /**
* check if string contains contains substrings * check if string contains contains substrings
*/ */
private void contains(Resources r, int resource, StringBuilder failures, String... contains) { private void contains(Resources r, int resource, StringBuilder failures, String expected) {
String string = r.getString(resource); String base = getTargetContext().getResources().getString(resource);
for(String contain : contains) String translation = r.getString(resource);
if(!string.contains(contain)) { if(!base.equals(translation) && !translation.contains(expected)) {
Locale locale = r.getConfiguration().locale; Locale locale = r.getConfiguration().locale;
String name = r.getResourceName(resource); String name = r.getResourceName(resource);
failures.append(String.format("%s: %s did not contain: %s\n", failures.append(String.format("%s: %s did not contain: %s\n",
locale.toString(), name, contain)); locale.toString(), name, expected));
} }
} }
/** /**
@ -219,13 +216,16 @@ public class TranslationTests {
*/ */
@Test @Test
public void testSpecialStringsMatch() throws Exception { public void testSpecialStringsMatch() throws Exception {
final Resources r = getTargetContext().getResources();
final StringBuilder failures = new StringBuilder(); final StringBuilder failures = new StringBuilder();
forEachLocale(() -> { forEachLocale(r -> {
contains(r, R.string.CFC_tag_text, failures, "?"); int layoutDirection = TextUtilsCompat.getLayoutDirectionFromLocale(Locale.getDefault());
contains(r, R.string.CFC_title_contains_text, failures, "?"); String expected = layoutDirection == LAYOUT_DIRECTION_LTR ? "?" : "؟";
contains(r, R.string.CFC_dueBefore_text, failures, "?"); contains(r, R.string.CFC_tag_text, failures, expected);
contains(r, R.string.CFC_title_contains_text, failures, expected);
contains(r, R.string.CFC_dueBefore_text, failures, expected);
contains(r, R.string.CFC_tag_contains_text, failures, expected);
contains(r, R.string.CFC_gtasks_list_text, failures, expected);
}); });
assertEquals(failures.toString(), 0, assertEquals(failures.toString(), 0,

@ -5,6 +5,7 @@
*/ */
package com.todoroo.astrid.activity; package com.todoroo.astrid.activity;
import android.annotation.SuppressLint;
import android.content.ContentValues; import android.content.ContentValues;
import android.content.Intent; import android.content.Intent;
import android.content.IntentFilter; import android.content.IntentFilter;
@ -514,6 +515,7 @@ public class TaskListActivity extends InjectingAppCompatActivity implements
} }
@Override @Override
@SuppressLint("NewApi")
public void onSupportActionModeFinished(@NonNull ActionMode mode) { public void onSupportActionModeFinished(@NonNull ActionMode mode) {
super.onSupportActionModeFinished(mode); super.onSupportActionModeFinished(mode);

@ -68,6 +68,7 @@ public class ThemeColor {
} }
} }
@SuppressLint("NewApi")
public void setStatusBarColor(Activity activity) { public void setStatusBarColor(Activity activity) {
if (atLeastLollipop()) { if (atLeastLollipop()) {
activity.getWindow().setStatusBarColor(getColorPrimaryDark()); activity.getWindow().setStatusBarColor(getColorPrimaryDark());

@ -29,11 +29,9 @@
<string name="SSD_sort_due">بحسب تاريخ الإستحقاق</string> <string name="SSD_sort_due">بحسب تاريخ الإستحقاق</string>
<string name="SSD_sort_importance">بحسب الأولوية</string> <string name="SSD_sort_importance">بحسب الأولوية</string>
<string name="SSD_sort_modified">بواسطة التعديل الأخير</string> <string name="SSD_sort_modified">بواسطة التعديل الأخير</string>
<string name="FLA_search_filter">مطابقة %</string>
<string name="TEA_title_hint">اسم المهمة</string> <string name="TEA_title_hint">اسم المهمة</string>
<string name="TEA_importance_label">الأولوية</string> <string name="TEA_importance_label">الأولوية</string>
<string name="TEA_hideUntil_label">إخفاء حتى...</string> <string name="TEA_hideUntil_label">إخفاء حتى...</string>
<string name="TEA_hideUntil_display">إخفاء حتى</string>
<string name="TEA_note_label">وصف</string> <string name="TEA_note_label">وصف</string>
<string name="TEA_estimatedDuration_label">كم من الوقت ستأخذ؟</string> <string name="TEA_estimatedDuration_label">كم من الوقت ستأخذ؟</string>
<string name="TEA_elapsedDuration_label">الوقت المنقضي</string> <string name="TEA_elapsedDuration_label">الوقت المنقضي</string>
@ -81,7 +79,6 @@
<string name="CFA_type_add">أو</string> <string name="CFA_type_add">أو</string>
<string name="CFA_type_subtract">ليس</string> <string name="CFA_type_subtract">ليس</string>
<string name="CFA_type_intersect">أيضا</string> <string name="CFA_type_intersect">أيضا</string>
<string name="CFA_context_chain">% لديه معايير</string>
<string name="CFA_context_delete">حذف الصف</string> <string name="CFA_context_delete">حذف الصف</string>
<string name="CFA_help">ضغط مطول على الموضوع من أجل خيارات إضافية</string> <string name="CFA_help">ضغط مطول على الموضوع من أجل خيارات إضافية</string>
<string name="CFA_button_add">إضافة معايير</string> <string name="CFA_button_add">إضافة معايير</string>
@ -89,10 +86,9 @@
<string name="next_month">الشهر القادم</string> <string name="next_month">الشهر القادم</string>
<string name="CFC_importance_text">أولوية على الأقل</string> <string name="CFC_importance_text">أولوية على الأقل</string>
<string name="CFC_title_contains_name">العنوان يحتوي على..</string> <string name="CFC_title_contains_name">العنوان يحتوي على..</string>
<string name="CFC_title_contains_text">العنوان يحتوي على....</string> <string name="CFC_title_contains_text">العنوان يحتوي على</string>
<string name="gcal_TEA_addToCalendar_label">أضف إلى التقويم</string> <string name="gcal_TEA_addToCalendar_label">أضف إلى التقويم</string>
<string name="gcal_TEA_showCalendar_label">إفتح أحداث التقويم</string> <string name="gcal_TEA_showCalendar_label">إفتح أحداث التقويم</string>
<string name="gcal_completed_title">المكتملة%</string>
<string name="CFC_gtasks_list_text">في القائمة:؟</string> <string name="CFC_gtasks_list_text">في القائمة:؟</string>
<string name="gtasks_GTA_clear_completed">انتهاء الحذف</string> <string name="gtasks_GTA_clear_completed">انتهاء الحذف</string>
<string name="gtasks_GLA_noaccounts">لا يوجد حساب قوقل للتزامن مع.</string> <string name="gtasks_GLA_noaccounts">لا يوجد حساب قوقل للتزامن مع.</string>
@ -120,7 +116,6 @@
<string name="default_random_reminder_bi_weekly">مرتين في الاسبوع</string> <string name="default_random_reminder_bi_weekly">مرتين في الاسبوع</string>
<string name="default_random_reminder_monthly">شهري</string> <string name="default_random_reminder_monthly">شهري</string>
<string name="default_random_reminder_bi_monthly">مرتين في الشهر</string> <string name="default_random_reminder_bi_monthly">مرتين في الشهر</string>
<string name="repeat_every">كل كم يوم</string>
<string name="repeat_interval_prompt">مجال التكرار</string> <string name="repeat_interval_prompt">مجال التكرار</string>
<string name="repeat_never">لا تتكرر</string> <string name="repeat_never">لا تتكرر</string>
<string name="repeat_interval_day">أيام</string> <string name="repeat_interval_day">أيام</string>
@ -131,9 +126,7 @@
<string name="repeat_interval_year">سنين</string> <string name="repeat_interval_year">سنين</string>
<string name="repeat_type_due">من تاريخ الموعد</string> <string name="repeat_type_due">من تاريخ الموعد</string>
<string name="repeat_type_completion">من تاريخ الاتمام</string> <string name="repeat_type_completion">من تاريخ الاتمام</string>
<string name="repeat_detail_duedate">كل كم؟</string>
<string name="repeat_forever">تكرار دائم</string> <string name="repeat_forever">تكرار دائم</string>
<string name="repeat_until">تكرار حتى ....</string>
<string name="tag_FEx_untagged">غير مصنف</string> <string name="tag_FEx_untagged">غير مصنف</string>
<string name="TEA_timer_controls">مؤقت</string> <string name="TEA_timer_controls">مؤقت</string>
<string name="TEA_timer_comment_started">بدء هذه المهمة:</string> <string name="TEA_timer_comment_started">بدء هذه المهمة:</string>

Loading…
Cancel
Save