RTL support

Closes #4916
Fixes #4714
This commit is contained in:
agrajaghh 2015-11-26 19:04:27 +01:00 committed by Moxie Marlinspike
parent 94452e7784
commit 4fa6680f83
29 changed files with 141 additions and 43 deletions

View File

@ -92,6 +92,7 @@
<application android:name=".ApplicationContext"
android:icon="@drawable/icon"
android:label="@string/app_name"
android:supportsRtl="true"
tools:replace="android:allowBackup"
android:allowBackup="false"
android:theme="@style/TextSecure.LightTheme">

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/actionbar_icon_holo_dark"
android:left="8dp"/>
</layer-list>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 848 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.6 KiB

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.8 KiB

After

Width:  |  Height:  |  Size: 2.4 KiB

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/actionbar_icon_holo_dark"
android:right="8dp"/>
</layer-list>

View File

@ -24,6 +24,7 @@
android:layout_width="0px"
android:layout_weight="1"
android:layout_marginLeft="5dp"
android:layout_marginStart="5dp"
android:hint="@string/contact_selection_activity__enter_name_or_number"
android:inputType="textPersonName"
style="@style/TextSecure.TitleTextStyle"

View File

@ -29,6 +29,6 @@
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:visibility="gone"
android:layout_gravity="right"/>
android:layout_gravity="end"/>
</FrameLayout>

View File

@ -19,6 +19,7 @@
android:cropToPadding="true"
tools:src="@color/blue_600"
android:layout_marginRight="10dp"
android:layout_marginEnd="10dp"
android:contentDescription="@string/SingleContactSelectionActivity_contact_photo" />
<LinearLayout android:layout_width="0dp"
@ -45,6 +46,7 @@
<TextView android:id="@+id/number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textDirection="ltr"
android:singleLine="true"
android:ellipsize="marquee"
android:textAppearance="?android:attr/textAppearanceSmall"
@ -56,6 +58,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="10dip"
android:paddingStart="10dip"
android:ellipsize="end"
android:singleLine="true"
android:textAppearance="?android:attr/textAppearanceSmall"

View File

@ -41,7 +41,6 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/contact_photo"
android:layout_toEndOf="@id/contact_photo"
android:layout_marginRight="35dp"
android:background="@drawable/received_bubble"
android:orientation="vertical">
@ -113,7 +112,6 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:paddingRight="4dp"
android:paddingTop="2dp"
android:src="?menu_lock_icon_small"
android:contentDescription="@string/conversation_item__secure_message_description"
@ -132,6 +130,8 @@
android:layout_height="wrap_content"
android:layout_gravity="left"
android:paddingTop="1dip"
android:paddingLeft="4dp"
android:paddingStart="4dp"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="?conversation_item_received_text_secondary_color"
android:textSize="@dimen/conversation_item_date_text_size"

View File

@ -32,7 +32,7 @@
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|right"
android:layout_gravity="bottom|end"
android:layout_margin="16dp"
android:src="@drawable/ic_create_white_24dp"
android:focusable="true"

View File

@ -12,6 +12,7 @@
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:layout_marginTop="3dp"
android:layout_marginBottom="3dp"
@ -24,9 +25,12 @@
<RelativeLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="4dip"
android:layout_marginStart="4dip"
android:layout_marginRight="8dip"
android:layout_marginEnd="8dip"
android:layout_centerVertical="true"
android:layout_toRightOf="@id/contact_photo_image"
android:layout_toEndOf="@id/contact_photo_image"
android:weightSum="1"
android:orientation="horizontal">
@ -36,7 +40,9 @@
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_toLeftOf="@+id/thumbnail"
android:layout_toStartOf="@+id/thumbnail"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="?attr/conversation_list_item_contact_color"
android:singleLine="true"
@ -50,7 +56,9 @@
android:layout_height="18dp"
android:paddingTop="2dp"
android:layout_marginRight="2dp"
android:layout_marginEnd="2dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="@id/from"
app:useSmallIcon="true"
android:visibility="gone"
@ -62,7 +70,10 @@
android:layout_height="wrap_content"
android:layout_below="@id/from"
android:layout_toRightOf="@id/indicators_parent"
android:layout_toEndOf="@id/indicators_parent"
android:layout_toLeftOf="@+id/delivery_status"
android:layout_toStartOf="@+id/delivery_status"
android:paddingRight="1dp"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="?attr/conversation_list_item_subject_color"
android:fontFamily="sans-serif-light"
@ -78,6 +89,7 @@
android:layout_marginRight="5dip"
android:layout_marginLeft="5dip"
android:layout_toLeftOf="@+id/date"
android:layout_toStartOf="@+id/date"
android:layout_alignParentTop="true"
android:layout_marginTop="5dip"
android:contentDescription="@string/conversation_activity__attachment_thumbnail"
@ -88,9 +100,11 @@
<TextView android:id="@id/date"
android:layout_marginLeft="3dip"
android:layout_marginStart="3dip"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignParentTop="true"
android:layout_above="@id/subject"
android:textAppearance="?android:attr/textAppearanceSmall"
@ -104,8 +118,10 @@
android:layout_height="wrap_content"
android:layout_below="@id/date"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignBaseline="@id/subject"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:text="@string/conversation_list_item_view__archived"
android:textColor="#ffbbbbbb"
android:background="@drawable/rounded_rectangle"
@ -118,6 +134,7 @@
android:layout_height="wrap_content"
android:layout_below="@+id/date"
android:layout_toLeftOf="@+id/archived"
android:layout_toStartOf="@+id/archived"
android:layout_alignWithParentIfMissing="true"
app:iconColor="?attr/conversation_list_item_subject_color"/>

View File

@ -26,8 +26,9 @@
android:layout_height="wrap_content"
android:singleLine="true"
android:ellipsize="end"
android:layout_gravity="center_vertical"
android:layout_gravity="center_vertical|start"
android:gravity="center_vertical"
android:textDirection="ltr"
style="@style/TextSecure.SubtitleTextStyle"/>
</org.thoughtcrime.securesms.ConversationTitleView>

View File

@ -74,6 +74,7 @@
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dip"
android:layout_marginEnd="10dip"
android:src="?plaintext_backup"/>
<LinearLayout android:orientation="vertical"
@ -82,11 +83,13 @@
<TextView android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="start"
style="@style/Registration.Description"
android:text="@string/export_fragment__export_plaintext_backup"/>
<TextView android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="start"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="@string/export_fragment__export_a_plaintext_backup_compatible_with"/>
</LinearLayout>

View File

@ -31,6 +31,7 @@
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dip"
android:layout_marginEnd="10dip"
android:src="?import_sms"/>
<LinearLayout android:orientation="vertical"
@ -39,11 +40,13 @@
<TextView android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="start"
style="@style/Registration.Description"
android:text="@string/import_fragment__import_system_sms_database"/>
<TextView android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="start"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="@string/import_fragment__import_the_database_from_the_default_system"/>
@ -71,6 +74,7 @@
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dip"
android:layout_marginEnd="10dip"
android:src="?encrypted_backup"/>
<LinearLayout android:orientation="vertical"
@ -79,11 +83,13 @@
<TextView android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="start"
style="@style/Registration.Description"
android:text="@string/import_fragment__restore_encrypted_backup"/>
<TextView android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="start"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="@string/import_fragment__restore_a_previously_exported_encrypted_signal_backup"/>
@ -112,6 +118,7 @@
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dip"
android:layout_marginEnd="10dip"
android:src="?plaintext_backup"/>
<LinearLayout android:orientation="vertical"
@ -120,11 +127,13 @@
<TextView android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="start"
style="@style/Registration.Description"
android:text="@string/import_fragment__import_plaintext_backup"/>
<TextView android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="start"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="@string/import_fragment__import_a_plaintext_backup_file"/>
</LinearLayout>

View File

@ -32,7 +32,8 @@
android:layout_marginBottom="30dp"
android:layout_marginTop="18dp"
android:fontFamily="sans-serif-light"
android:paddingLeft="10dp"/>
android:paddingLeft="10dp"
android:paddingStart="10dp"/>
<EditText android:id="@+id/invite_text"
android:layout_width="match_parent"
@ -40,7 +41,10 @@
android:minLines="2"
tools:text="Let's switch to Signal: http://sgnl.link/asdfdfsa"
android:background="@drawable/sent_bubble"
android:padding="10dp"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:paddingLeft="10dp"
android:paddingRight="20dp"
android:gravity="top"
android:inputType="textShortMessage|textMultiLine"
android:textColor="#ff333333"/>
@ -54,6 +58,7 @@
<Button android:id="@+id/share_button"
android:drawablePadding="10dp"
android:drawableLeft="@drawable/ic_share_black_18dp"
android:drawableStart="@drawable/ic_share_black_18dp"
android:text="@string/InviteActivity_share"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
@ -61,6 +66,7 @@
<Button android:id="@+id/sms_button"
android:drawableLeft="@drawable/ic_message_black_18dp"
android:drawableStart="@drawable/ic_message_black_18dp"
android:drawablePadding="10dp"
android:text="@string/InviteActivity_send_sms"
android:layout_width="wrap_content"
@ -95,7 +101,7 @@
<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="right"
android:gravity="end"
android:padding="10dp"
android:orientation="horizontal">

View File

@ -15,6 +15,7 @@
<TextView style="@style/Registration.Label"
android:layout_width="fill_parent"
android:gravity="start"
android:textAllCaps="true"
android:text="@string/registration_activity__your_country" />
@ -25,10 +26,12 @@
<TextView style="@style/Registration.Label"
android:layout_width="fill_parent"
android:gravity="start"
android:textAllCaps="true"
android:text="@string/registration_activity__your_country_code_and_phone_number" />
<LinearLayout android:orientation="horizontal"
android:layoutDirection="ltr"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
@ -62,11 +65,13 @@
android:layout_width="fill_parent"
android:layout_marginBottom="8dip"
android:layout_marginTop="16dip"
android:gravity="start"
android:text="@string/registration_activity__verify_your_number_to_connect_with_signal"/>
<TextView style="@style/Registration.Description"
android:layout_width="fill_parent"
android:layout_marginBottom="16dip"
android:gravity="start"
android:text="@string/registration_activity__registration_will_transmit_some_contact_information_to_the_server_temporariliy"/>
<LinearLayout android:layout_width="wrap_content"

View File

@ -285,6 +285,7 @@
<TextView
style="@style/Registration.Description"
android:gravity="start"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dip"
@ -480,6 +481,7 @@
<TextView
style="@style/Registration.Description"
android:gravity="start"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingLeft="5dip"
@ -498,6 +500,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:text="1:57"
android:textSize="12.0sp" />
@ -506,6 +509,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:text="@string/registration_progress_activity__waiting_for_sms_verification"
android:textAllCaps="true"
android:textSize="12.0sp"

View File

@ -38,6 +38,8 @@
<string name="ApplicationPreferencesActivity_off">off</string>
<string name="ApplicationPreferencesActivity_Off">Off</string>
<string name="ApplicationPreferencesActivity_sms_mms_summary">SMS %1$s, MMS %2$s</string>
<string name="ApplicationPreferencesActivity_privacy_summary">Passphrase %1$s, Screen security %2$s</string>
<string name="ApplicationPreferencesActivity_appearance_summary">Theme %1$s, Language %2$s</string>
<!-- AppProtectionPreferenceFragment -->
<plurals name="AppProtectionPreferenceFragment_minutes">
@ -941,10 +943,8 @@
<string name="preferences__change_passphrase">Change passphrase</string>
<string name="preferences__change_your_passphrase">Change your passphrase</string>
<string name="preferences__enable_passphrase">Enable passphrase</string>
<string name="preferences__passphrase_summary">Passphrase %s</string>
<string name="preferences__lock_signal_and_message_notifications_with_a_passphrase">Lock Signal and message notifications with a passphrase</string>
<string name="preferences__screen_security">Screen security</string>
<string name="preferences__screen_security_summary">Screen security %s</string>
<string name="preferences__disable_screen_security_to_allow_screen_shots">Block screenshots in the recents list and inside the app</string>
<string name="preferences__auto_lock_signal_after_a_specified_time_interval_of_inactivity">Auto-lock Signal after a specified time interval of inactivity</string>
<string name="preferences__inactivity_timeout_passphrase">Inactivity timeout passphrase</string>
@ -1012,10 +1012,8 @@
<string name="preferences__dark_theme">Dark</string>
<string name="preferences__appearance">Appearance</string>
<string name="preferences__theme">Theme</string>
<string name="preferences__theme_summary">Theme %s</string>
<string name="preferences__default">Default</string>
<string name="preferences__language">Language</string>
<string name="preferences__language_summary">Language %s</string>
<string name="preferences__signal_messages_and_calls">Signal messages and calls</string>
<string name="preferences__free_private_messages_and_calls">Free private messages and calls to Signal users</string>
<string name="preferences__submit_debug_log">Submit debug log</string>

View File

@ -28,10 +28,10 @@
<!-- ActionBar styles -->
<style name="TextSecure.DarkActionBar"
parent="@style/Widget.AppCompat.ActionBar">
<item name="android:icon">@drawable/actionbar_icon_holo_dark</item>
<item name="icon">@drawable/actionbar_icon_holo_dark</item>
<item name="android:icon">@drawable/actionbar_icon</item>
<item name="icon">@drawable/actionbar_icon</item>
<item name="background">@color/gray95</item>
<item name="logo">@drawable/actionbar_icon_holo_dark</item>
<item name="logo">@drawable/actionbar_icon</item>
<item name="android:popupTheme">@style/ThemeOverlay.AppCompat.Dark</item>
<item name="popupTheme">@style/ThemeOverlay.AppCompat.Dark</item>
<item name="titleTextStyle">@style/TextSecure.TitleTextStyle</item>
@ -42,8 +42,8 @@
parent="@style/Widget.AppCompat.ActionBar">
<item name="background">@color/textsecure_primary</item>
<item name="elevation">2dp</item>
<item name="logo">@drawable/actionbar_icon_holo_dark</item>
<item name="icon">@drawable/actionbar_icon_holo_dark</item>
<item name="logo">@drawable/actionbar_icon</item>
<item name="icon">@drawable/actionbar_icon</item>
<item name="popupTheme">@style/ThemeOverlay.AppCompat.Light</item>
<item name="titleTextStyle">@style/TextSecure.TitleTextStyle</item>
<item name="subtitleTextStyle">@style/TextSecure.SubtitleTextStyle</item>

View File

@ -106,6 +106,9 @@ public class ConversationListItem extends RelativeLayout
this.thumbnailView = (ThumbnailView) findViewById(R.id.thumbnail);
this.archivedView = ViewUtil.findById(this, R.id.archived);
thumbnailView.setClickable(false);
ViewUtil.setTextViewGravityStart(this.fromView, getContext());
ViewUtil.setTextViewGravityStart(this.subjectView, getContext());
}
public void bind(@NonNull MasterSecret masterSecret, @NonNull ThreadRecord thread,

View File

@ -10,6 +10,7 @@ import android.widget.TextView;
import org.thoughtcrime.securesms.recipients.Recipient;
import org.thoughtcrime.securesms.recipients.Recipients;
import org.thoughtcrime.securesms.util.ViewUtil;
public class ConversationTitleView extends LinearLayout {
@ -33,8 +34,10 @@ public class ConversationTitleView extends LinearLayout {
this.title = (TextView) findViewById(R.id.title);
this.subtitle = (TextView) findViewById(R.id.subtitle);
}
ViewUtil.setTextViewGravityStart(this.title, getContext());
ViewUtil.setTextViewGravityStart(this.subtitle, getContext());
}
public void setTitle(@Nullable Recipients recipients) {
if (recipients == null) setComposeTitle();

View File

@ -9,6 +9,7 @@ import org.thoughtcrime.securesms.TransportOption;
import org.thoughtcrime.securesms.TransportOptions;
import org.thoughtcrime.securesms.TransportOptions.OnTransportChangedListener;
import org.thoughtcrime.securesms.TransportOptionsPopup;
import org.thoughtcrime.securesms.util.ViewUtil;
import org.whispersystems.libaxolotl.util.guava.Optional;
public class SendButton extends ImageButton
@ -25,18 +26,21 @@ public class SendButton extends ImageButton
public SendButton(Context context) {
super(context);
this.transportOptions = initializeTransportOptions(false);
ViewUtil.mirrorIfRtl(this, getContext());
}
@SuppressWarnings("unused")
public SendButton(Context context, AttributeSet attrs) {
super(context, attrs);
this.transportOptions = initializeTransportOptions(false);
ViewUtil.mirrorIfRtl(this, getContext());
}
@SuppressWarnings("unused")
public SendButton(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
this.transportOptions = initializeTransportOptions(false);
ViewUtil.mirrorIfRtl(this, getContext());
}
private TransportOptions initializeTransportOptions(boolean media) {

View File

@ -13,6 +13,7 @@ import org.thoughtcrime.securesms.components.AvatarImageView;
import org.thoughtcrime.securesms.recipients.Recipient;
import org.thoughtcrime.securesms.recipients.RecipientFactory;
import org.thoughtcrime.securesms.recipients.Recipients;
import org.thoughtcrime.securesms.util.ViewUtil;
public class ContactSelectionListItem extends LinearLayout implements Recipients.RecipientsModifiedListener {
@ -42,6 +43,8 @@ public class ContactSelectionListItem extends LinearLayout implements Recipients
this.labelView = (TextView) findViewById(R.id.label);
this.nameView = (TextView) findViewById(R.id.name);
this.checkBox = (CheckBox) findViewById(R.id.check_box);
ViewUtil.setTextViewGravityStart(this.nameView, getContext());
}
public void set(long id, int type, String name, String number, String label, int color, boolean multiSelect) {

View File

@ -166,31 +166,23 @@ public class AppProtectionPreferenceFragment extends PreferenceFragment {
}
}
private static CharSequence getPassphraseSummary(Context context) {
final int passphraseResId = R.string.preferences__passphrase_summary;
final String onRes = context.getString(R.string.ApplicationPreferencesActivity_on);
final String offRes = context.getString(R.string.ApplicationPreferencesActivity_off);
if (TextSecurePreferences.isPasswordDisabled(context)) {
return context.getString(passphraseResId, offRes);
} else {
return context.getString(passphraseResId, onRes);
}
}
private static CharSequence getScreenSecuritySummary(Context context) {
final int screenSecurityResId = R.string.preferences__screen_security_summary;
public static CharSequence getSummary(Context context) {
final int privacySummaryResId = R.string.ApplicationPreferencesActivity_privacy_summary;
final String onRes = context.getString(R.string.ApplicationPreferencesActivity_on);
final String offRes = context.getString(R.string.ApplicationPreferencesActivity_off);
if (TextSecurePreferences.isScreenSecurityEnabled(context)) {
return context.getString(screenSecurityResId, onRes);
if (TextSecurePreferences.isPasswordDisabled(context)) {
if (TextSecurePreferences.isScreenSecurityEnabled(context)) {
return context.getString(privacySummaryResId, offRes, onRes);
} else {
return context.getString(privacySummaryResId, offRes, offRes);
}
} else {
return context.getString(screenSecurityResId, offRes);
if (TextSecurePreferences.isScreenSecurityEnabled(context)) {
return context.getString(privacySummaryResId, onRes, onRes);
} else {
return context.getString(privacySummaryResId, onRes, offRes);
}
}
}
public static CharSequence getSummary(Context context) {
return getPassphraseSummary(context) + ", " + getScreenSecuritySummary(context);
}
}

View File

@ -53,7 +53,8 @@ public class AppearancePreferenceFragment extends ListSummaryPreferenceFragment
if (langIndex == -1) langIndex = 0;
if (themeIndex == -1) themeIndex = 0;
return context.getString(R.string.preferences__theme_summary, themeEntries[themeIndex]) + ", " +
context.getString(R.string.preferences__language_summary, languageEntries[langIndex]);
return context.getString(R.string.ApplicationPreferencesActivity_appearance_summary,
themeEntries[themeIndex],
languageEntries[langIndex]);
}
}

View File

@ -1,10 +1,13 @@
package org.thoughtcrime.securesms.util;
import android.annotation.TargetApi;
import android.app.Activity;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.content.res.Configuration;
import android.os.Build.VERSION;
import android.os.Build.VERSION_CODES;
import android.text.TextUtils;
import java.util.Locale;
@ -39,13 +42,22 @@ public class DynamicLanguage {
return currentLocale;
}
@TargetApi(VERSION_CODES.JELLY_BEAN_MR1)
public static int getLayoutDirection(Context context) {
Configuration configuration = context.getResources().getConfiguration();
return configuration.getLayoutDirection();
}
private static void setContextLocale(Context context, Locale selectedLocale) {
Configuration configuration = context.getResources().getConfiguration();
if (!configuration.locale.equals(selectedLocale)) {
configuration.locale = selectedLocale;
if (VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN_MR1) {
configuration.setLayoutDirection(selectedLocale);
}
context.getResources().updateConfiguration(configuration,
context.getResources().getDisplayMetrics());
context.getResources().getDisplayMetrics());
}
}
@ -70,5 +82,4 @@ public class DynamicLanguage {
activity.overridePendingTransition(0, 0);
}
}
}

View File

@ -16,7 +16,9 @@
*/
package org.thoughtcrime.securesms.util;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.os.Build.VERSION;
import android.os.Build.VERSION_CODES;
@ -28,6 +30,7 @@ import android.support.v4.view.ViewCompat;
import android.support.v4.view.animation.FastOutSlowInInterpolator;
import android.text.TextUtils;
import android.text.TextUtils.TruncateAt;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -180,4 +183,22 @@ public class ViewUtil {
{
return (T)(inflater.inflate(layoutResId, parent, false));
}
@SuppressLint("RtlHardcoded")
public static void setTextViewGravityStart(final @NonNull TextView textView, @NonNull Context context) {
if (VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN_MR1) {
if (DynamicLanguage.getLayoutDirection(context) == View.LAYOUT_DIRECTION_RTL) {
textView.setGravity(Gravity.RIGHT);
} else {
textView.setGravity(Gravity.LEFT);
}
}
}
public static void mirrorIfRtl(View view, Context context) {
if (VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN_MR1 &&
DynamicLanguage.getLayoutDirection(context) == View.LAYOUT_DIRECTION_RTL) {
view.setScaleX(-1.0f);
}
}
}