package org.thoughtcrime.securesms; import android.app.ActivityManager; import android.content.Context; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.os.Build; import android.os.Build.VERSION; import android.os.Build.VERSION_CODES; import android.support.annotation.NonNull; import android.support.v4.app.FragmentActivity; import android.view.KeyEvent; import org.thoughtcrime.securesms.util.TextSecurePreferences; import org.thoughtcrime.securesms.util.dynamiclanguage.DynamicLanguageActivityHelper; import org.thoughtcrime.securesms.util.dynamiclanguage.DynamicLanguageContextWrapper; import network.loki.messenger.R; public abstract class BaseActivity extends FragmentActivity { @Override public boolean onKeyDown(int keyCode, KeyEvent event) { return (keyCode == KeyEvent.KEYCODE_MENU && isMenuWorkaroundRequired()) || super.onKeyDown(keyCode, event); } @Override public boolean onKeyUp(int keyCode, @NonNull KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_MENU && isMenuWorkaroundRequired()) { openOptionsMenu(); return true; } return super.onKeyUp(keyCode, event); } public static boolean isMenuWorkaroundRequired() { return VERSION.SDK_INT < VERSION_CODES.KITKAT && VERSION.SDK_INT > VERSION_CODES.GINGERBREAD_MR1 && ("LGE".equalsIgnoreCase(Build.MANUFACTURER) || "E6710".equalsIgnoreCase(Build.DEVICE)); } @Override protected void onResume() { super.onResume(); DynamicLanguageActivityHelper.recreateIfNotInCorrectLanguage(this, TextSecurePreferences.getLanguage(this)); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { String name = getResources().getString(R.string.app_name); Bitmap icon = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher_foreground); int color = getResources().getColor(R.color.loki_darkest_gray); setTaskDescription(new ActivityManager.TaskDescription(name, icon, color)); } } @Override protected void attachBaseContext(Context newBase) { super.attachBaseContext(DynamicLanguageContextWrapper.updateContext(newBase, TextSecurePreferences.getLanguage(newBase))); } }