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

@@ -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);
}
}
}