Improve RTL support

pull/437/head
Alex Baker 8 years ago
parent be7b8732b9
commit 984596d7da

@ -37,7 +37,7 @@ public class GoogleTaskListSelectionDialog extends InjectingDialogFragment {
}
});
return dialogBuilder.newDialog()
.setItems(listNames.toArray(new String[listNames.size()]), new DialogInterface.OnClickListener() {
.setItems(listNames, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
handler.selectedList(lists.get(which));

@ -39,7 +39,7 @@ public class AccountSelectionDialog extends InjectingDialogFragment {
return dialogBuilder.newDialog()
.setTitle(R.string.choose_google_account)
.setItems(accounts.toArray(new String[accounts.size()]), new DialogInterface.OnClickListener() {
.setItems(accounts, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
handler.accountSelected(accounts.get(which));

@ -42,13 +42,13 @@ public class BasicPreferences extends BaseBasicPreferences implements PurchaseHe
getPref(R.string.TLA_menu_donate).setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
final String[] donationValues = getDonationValues();
final List<String> donationValues = getDonationValues();
dialogBuilder.newDialog()
.setTitle(R.string.select_amount)
.setItems(donationValues, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
String value = donationValues[which];
String value = donationValues.get(which);
Pattern pattern = Pattern.compile("\\$(\\d+) USD");
Matcher matcher = pattern.matcher(value);
//noinspection ResultOfMethodCallIgnored
@ -178,12 +178,12 @@ public class BasicPreferences extends BaseBasicPreferences implements PurchaseHe
}
}
private String[] getDonationValues() {
private List<String> getDonationValues() {
List<String> values = new ArrayList<>();
for (int i = 1 ; i <= 100 ; i++) {
values.add(String.format("$%s USD", Integer.toString(i)));
}
return values.toArray(new String[values.size()]);
return values;
}
@Override

@ -110,8 +110,6 @@ public class CustomFilterAdapter extends ArrayAdapter<CriterionInstance> {
if(item.criterion instanceof MultipleSelectCriterion) {
MultipleSelectCriterion multiSelectCriterion = (MultipleSelectCriterion) item.criterion;
final String[] titles = multiSelectCriterion.entryTitles;
ArrayAdapter<String> adapter = new ArrayAdapter<>(activity,
android.R.layout.simple_spinner_dropdown_item, titles);
DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface click, int which) {
@ -121,7 +119,7 @@ public class CustomFilterAdapter extends ArrayAdapter<CriterionInstance> {
}
}
};
dialog.setAdapter(adapter, listener);
dialog.setItems(titles, listener);
} else if(item.criterion instanceof TextInputCriterion) {
TextInputCriterion textInCriterion = (TextInputCriterion) item.criterion;
FrameLayout frameLayout = new FrameLayout(activity);

@ -6,10 +6,13 @@
package com.todoroo.astrid.ui;
import android.content.Context;
import android.os.Bundle;
import android.preference.ListPreference;
import android.util.AttributeSet;
import android.view.View;
import org.tasks.locale.LocaleUtils;
import timber.log.Timber;
public class MultilineListPreference extends ListPreference {
@ -29,6 +32,12 @@ public class MultilineListPreference extends ListPreference {
MultilineHelper.makeMultiline(view);
}
@Override
protected void showDialog(Bundle state) {
super.showDialog(state);
LocaleUtils.fixDialogButtons(getDialog());
}
@Override
public void setValue(String value) {
super.setValue(value);

@ -45,7 +45,7 @@ public class CalendarSelectionDialog extends InjectingDialogFragment {
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
final List<AndroidCalendar> calendars = calendarProvider. getCalendars();
final List<AndroidCalendar> calendars = calendarProvider.getCalendars();
List<String> calendarNames = transform(calendars, new Function<AndroidCalendar, String>() {
@Override
public String apply(AndroidCalendar androidCalendar) {
@ -54,7 +54,7 @@ public class CalendarSelectionDialog extends InjectingDialogFragment {
});
AlertDialogBuilder builder = dialogBuilder.newDialog()
.setItems(calendarNames.toArray(new String[calendarNames.size()]), new DialogInterface.OnClickListener() {
.setItems(calendarNames, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
handler.selectedCalendar(calendars.get(which));

@ -75,7 +75,7 @@ public class AddAttachmentDialog extends InjectingDialogFragment {
}
});
return dialogBuilder.newDialog()
.setItems(entries.toArray(new String[entries.size()]), new DialogInterface.OnClickListener() {
.setItems(entries, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
actions.get(which).run();

@ -7,8 +7,13 @@ import android.view.ContextThemeWrapper;
import android.view.View;
import android.widget.ListAdapter;
import org.tasks.locale.LocaleUtils;
import org.tasks.themes.Theme;
import java.util.List;
import static com.todoroo.andlib.utility.AndroidUtilities.atLeastJellybeanMR1;
public class AlertDialogBuilder {
private final AlertDialog.Builder builder;
@ -47,8 +52,12 @@ public class AlertDialogBuilder {
return this;
}
public AlertDialogBuilder setItems(List<String> strings, DialogInterface.OnClickListener onClickListener) {
return setItems(strings.toArray(new String[strings.size()]), onClickListener);
}
public AlertDialogBuilder setItems(String[] strings, DialogInterface.OnClickListener onClickListener) {
builder.setItems(strings, onClickListener);
builder.setItems(addDirectionality(strings), onClickListener);
return this;
}
@ -67,11 +76,21 @@ public class AlertDialogBuilder {
return this;
}
public AlertDialogBuilder setSingleChoiceItems(String[] strings, int selectedIndex, DialogInterface.OnClickListener onClickListener) {
builder.setSingleChoiceItems(strings, selectedIndex, onClickListener);
public AlertDialogBuilder setSingleChoiceItems(List<String> strings, int selectedIndex, DialogInterface.OnClickListener onClickListener) {
builder.setSingleChoiceItems(addDirectionality(strings.toArray(new String[strings.size()])), selectedIndex, onClickListener);
return this;
}
private String[] addDirectionality(String[] strings) {
if (atLeastJellybeanMR1()) {
final char directionalityMark = LocaleUtils.getDirectionalityMark();
for (int i = 0 ; i < strings.length ; i++) {
strings[i] = directionalityMark + strings[i];
}
}
return strings;
}
public AlertDialogBuilder setSingleChoiceItems(ListAdapter adapter, int selectedIndex, DialogInterface.OnClickListener onClickListener) {
builder.setSingleChoiceItems(adapter, selectedIndex, onClickListener);
return this;
@ -107,12 +126,14 @@ public class AlertDialogBuilder {
AlertDialog dialog = create();
theme.applyToContext(dialog.getListView().getContext());
dialog.show();
LocaleUtils.fixDialogButtons(dialog);
return dialog;
}
public AlertDialog show() {
AlertDialog dialog = create();
dialog.show();
LocaleUtils.fixDialogButtons(dialog);
return dialog;
}
}

@ -79,7 +79,7 @@ public class SortDialog extends InjectingDialogFragment {
}
alertDialog = dialogBuilder.newDialog()
.setSingleChoiceItems(items.toArray(new String[items.size()]), selectedIndex, new DialogInterface.OnClickListener() {
.setSingleChoiceItems(items, selectedIndex, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
selectedIndex = which;

@ -276,9 +276,6 @@ public class CommentBarFragment extends TaskEditControlFragment {
if (runnables.size() == 1) {
runnables.get(0).run();
} else {
ArrayAdapter<String> adapter = new ArrayAdapter<>(activity,
android.R.layout.simple_spinner_dropdown_item, options.toArray(new String[options.size()]));
DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface d, int which) {
@ -289,7 +286,7 @@ public class CommentBarFragment extends TaskEditControlFragment {
// show a menu of available options
dialogBuilder.newDialog()
.setAdapter(adapter, listener)
.setItems(options, listener)
.show().setOwnerActivity(activity);
}
}

@ -8,11 +8,7 @@ import org.tasks.ErrorReportingSingleThreadExecutor;
import org.tasks.R;
import org.tasks.analytics.Tracker;
import org.tasks.locale.LocaleUtils;
import org.tasks.preferences.Preferences;
import org.tasks.themes.ThemeAccent;
import org.tasks.themes.ThemeBase;
import org.tasks.themes.ThemeCache;
import org.tasks.themes.ThemeColor;
import org.tasks.ui.CheckBoxes;
import org.tasks.ui.WidgetCheckBoxes;
@ -35,7 +31,7 @@ public class ApplicationModule {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
String language = prefs.getString(context.getString(R.string.p_language), null);
LocaleUtils.setLocale(language);
this.context = LocaleUtils.withLocale(context.getApplicationContext());
this.context = LocaleUtils.createConfigurationContext(context.getApplicationContext());
}
@Provides

@ -14,7 +14,7 @@ public abstract class InjectingAppCompatActivity extends AppCompatActivity imple
@Inject Tracker tracker;
public InjectingAppCompatActivity() {
LocaleUtils.updateConfig(this);
LocaleUtils.applyOverrideConfiguration(this);
}
@Override

@ -32,7 +32,7 @@ public abstract class InjectingPreferenceActivity extends AppCompatPreferenceAct
@Inject Tracker tracker;
public InjectingPreferenceActivity() {
LocaleUtils.updateConfig(this);
LocaleUtils.applyOverrideConfiguration(this);
}
@Override

@ -16,11 +16,11 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import javax.inject.Inject;
import static com.google.common.collect.Iterables.toArray;
import static org.tasks.locale.LocaleUtils.localeFromString;
@ -43,12 +43,13 @@ public class LocalePickerDialog extends InjectingDialogFragment {
public Dialog onCreateDialog(Bundle savedInstanceState) {
final Map<String, String> translations = new HashMap<>();
for (String translation : getResources().getStringArray(R.array.localization)) {
translations.put(localeFromString(translation).getDisplayName(), translation);
Locale locale = localeFromString(translation);
translations.put(locale.getDisplayName(locale), translation);
}
final List<String> display = new ArrayList<>(translations.keySet());
Collections.sort(display);
return dialogBuilder.newDialog()
.setItems(toArray(display, String.class), new DialogInterface.OnClickListener() {
.setItems(display, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
dialogInterface.dismiss();

@ -1,10 +1,14 @@
package org.tasks.locale;
import android.app.Dialog;
import android.content.Context;
import android.content.res.Configuration;
import android.text.TextUtils;
import android.view.ContextThemeWrapper;
import android.view.View;
import android.view.ViewParent;
import com.google.api.client.repackaged.com.google.common.base.Strings;
import com.google.common.base.Strings;
import java.util.Locale;
@ -25,6 +29,9 @@ public class LocaleUtils {
throw new RuntimeException();
}
private static final int[] sDialogButtons = new int[] { android.R.id.button1, android.R.id.button2, android.R.id.button3 };
private static final char LEFT_TO_RIGHT_MARK = '\u200e';
private static final char RIGHT_TO_LEFT_MARK = '\u200f';
private static String sLocaleString;
private static Locale sLocale;
@ -32,6 +39,12 @@ public class LocaleUtils {
return sLocale == null ? Locale.getDefault() : sLocale;
}
public static char getDirectionalityMark() {
return TextUtils.getLayoutDirectionFromLocale(getLocale()) == View.LAYOUT_DIRECTION_LTR
? LEFT_TO_RIGHT_MARK
: RIGHT_TO_LEFT_MARK;
}
public static String getsLocaleString() {
return sLocaleString;
}
@ -44,13 +57,27 @@ public class LocaleUtils {
}
}
public static void updateConfig(ContextThemeWrapper wrapper) {
public static void fixDialogButtons(Dialog dialog) {
if (sLocale != null) {
int layoutDirectionFromLocale = TextUtils.getLayoutDirectionFromLocale(sLocale);
for (int id : sDialogButtons) {
ViewParent parent = dialog.findViewById(id).getParent();
setDirection((View) parent, layoutDirectionFromLocale);
}
}
}
private static void setDirection(View view, int direction) {
view.setLayoutDirection(direction);
}
public static void applyOverrideConfiguration(ContextThemeWrapper wrapper) {
if (sLocale != null && atLeastJellybeanMR1()) {
wrapper.applyOverrideConfiguration(getLocaleConfiguration());
}
}
public static Context withLocale(Context context) {
public static Context createConfigurationContext(Context context) {
return sLocale == null ? context : context.createConfigurationContext(getLocaleConfiguration());
}

@ -27,6 +27,8 @@ import org.tasks.themes.ThemeAccent;
import org.tasks.themes.ThemeBase;
import org.tasks.themes.ThemeColor;
import java.util.Locale;
import javax.inject.Inject;
import static com.todoroo.andlib.utility.AndroidUtilities.atLeastJellybeanMR1;
@ -205,10 +207,11 @@ public abstract class BaseBasicPreferences extends InjectingPreferenceActivity i
private void updateLocale() {
Preference languagePreference = findPreference(getString(R.string.p_language));
String locale = preferences.getStringValue(R.string.p_language);
languagePreference.setSummary(Strings.isNullOrEmpty(locale)
String preference = preferences.getStringValue(R.string.p_language);
Locale locale = localeFromString(preference);
languagePreference.setSummary(locale == null
? getString(R.string.default_value)
: localeFromString(locale).getDisplayName());
: locale.getDisplayName(locale));
}
@Override

@ -49,7 +49,7 @@ public class MissedCallDialog extends InjectingDialogFragment {
return dialogBuilder.newDialog()
.setTitle(title)
.setItems(actions.toArray(new String[actions.size()]), new DialogInterface.OnClickListener() {
.setItems(actions, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
switch (which) {

@ -50,7 +50,7 @@ public class NotificationDialog extends InjectingDialogFragment {
return dialogBuilder.newDialog()
.setTitle(title)
.setItems(items.toArray(new String[items.size()]), new DialogInterface.OnClickListener() {
.setItems(items, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
switch (which) {

@ -46,7 +46,7 @@ public class SnoozeDialog extends InjectingDialogFragment {
return dialogBuilder.newDialog()
.setTitle(R.string.rmd_NoA_snooze)
.setItems(items.toArray(new String[items.size()]), new DialogInterface.OnClickListener() {
.setItems(items, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
switch (which) {

@ -52,7 +52,7 @@ public class ScrollableWidgetUpdateService extends InjectingRemoteViewsService {
String filterId = (String) extras.get(FILTER_ID);
int widgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID);
ThemeBase themeBase = themeCache.getThemeBase(preferences.getInt(WidgetConfigActivity.PREF_THEME + widgetId, 0));
return new ScrollableViewsFactory(subtasksHelper, preferences, LocaleUtils.withLocale(getApplicationContext()), filterId,
return new ScrollableViewsFactory(subtasksHelper, preferences, LocaleUtils.createConfigurationContext(getApplicationContext()), filterId,
themeBase.getTextColor(), widgetId, database, taskService, defaultFilterProvider, widgetCheckBoxes);
}

@ -19,6 +19,7 @@
android:layout_height="wrap_content"
android:drawablePadding="@dimen/keyline_second"
android:gravity="center_vertical"
android:textAlignment="viewStart"
android:minHeight="?android:attr/listPreferredItemHeightSmall"
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
android:paddingLeft="?android:attr/listPreferredItemPaddingStart"

@ -25,6 +25,7 @@
<TextView
style="@style/TaskEditTextHint"
android:id="@+id/add_attachment"
android:textAlignment="viewStart"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/add_attachment"/>

@ -8,22 +8,15 @@
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
<TextView
android:id="@+id/calendar_display_which"
style="@style/TaskEditTextPrimary"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_weight="100">
<TextView
android:id="@+id/calendar_display_which"
style="@style/TaskEditTextPrimary"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAlignment="viewStart"
android:layout_gravity="top"
android:gravity="start"/>
</LinearLayout>
android:layout_gravity="top"
android:layout_weight="100"
android:gravity="start"
android:textAlignment="viewStart" />
<include layout="@layout/control_set_clear_button" />

@ -6,4 +6,5 @@
android:layout_height="wrap_content"
android:layout_gravity="top"
android:gravity="start"
android:text="@string/default_value" />
android:text="@string/default_value"
android:textAlignment="viewStart" />

@ -20,6 +20,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:textAlignment="viewStart"
android:gravity="start"/>
</LinearLayout>

@ -2,6 +2,8 @@
<resources>
<style name="task_list_container">
<item name="android:clipToPadding">false</item>
<item name="android:paddingLeft">0dp</item>
<item name="android:paddingStart">0dp</item>
<item name="android:paddingRight">@dimen/elevation_padding</item>
<item name="android:paddingEnd">@dimen/elevation_padding</item>
</style>

Loading…
Cancel
Save