2015-02-08 13:53:12 -08:00
|
|
|
package org.thoughtcrime.securesms;
|
|
|
|
|
2019-07-24 09:51:09 +10:00
|
|
|
import android.app.ActivityManager;
|
2019-03-25 17:23:38 -03:00
|
|
|
import android.content.Context;
|
2019-07-24 09:51:09 +10:00
|
|
|
import android.graphics.Bitmap;
|
|
|
|
import android.graphics.BitmapFactory;
|
2015-02-08 13:53:12 -08:00
|
|
|
import android.os.Build;
|
2015-02-10 15:33:57 -08:00
|
|
|
import android.os.Build.VERSION;
|
|
|
|
import android.os.Build.VERSION_CODES;
|
2020-08-19 10:06:26 +10:00
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
import androidx.fragment.app.FragmentActivity;
|
2015-02-08 13:53:12 -08:00
|
|
|
import android.view.KeyEvent;
|
|
|
|
|
2019-03-25 17:23:38 -03:00
|
|
|
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
|
|
|
import org.thoughtcrime.securesms.util.dynamiclanguage.DynamicLanguageActivityHelper;
|
|
|
|
import org.thoughtcrime.securesms.util.dynamiclanguage.DynamicLanguageContextWrapper;
|
|
|
|
|
2019-07-24 12:30:23 +10:00
|
|
|
import network.loki.messenger.R;
|
|
|
|
|
2015-02-08 13:53:12 -08:00
|
|
|
public abstract class BaseActivity extends FragmentActivity {
|
|
|
|
@Override
|
|
|
|
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
2015-02-10 15:33:57 -08:00
|
|
|
return (keyCode == KeyEvent.KEYCODE_MENU && isMenuWorkaroundRequired()) || super.onKeyDown(keyCode, event);
|
2015-02-08 13:53:12 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onKeyUp(int keyCode, @NonNull KeyEvent event) {
|
2015-02-10 15:33:57 -08:00
|
|
|
if (keyCode == KeyEvent.KEYCODE_MENU && isMenuWorkaroundRequired()) {
|
2015-02-08 13:53:12 -08:00
|
|
|
openOptionsMenu();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return super.onKeyUp(keyCode, event);
|
|
|
|
}
|
|
|
|
|
2015-02-10 15:33:57 -08:00
|
|
|
public static boolean isMenuWorkaroundRequired() {
|
2015-02-12 13:16:03 -08:00
|
|
|
return VERSION.SDK_INT < VERSION_CODES.KITKAT &&
|
|
|
|
VERSION.SDK_INT > VERSION_CODES.GINGERBREAD_MR1 &&
|
2015-02-10 15:33:57 -08:00
|
|
|
("LGE".equalsIgnoreCase(Build.MANUFACTURER) || "E6710".equalsIgnoreCase(Build.DEVICE));
|
2015-02-08 13:53:12 -08:00
|
|
|
}
|
2019-03-25 17:23:38 -03:00
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onResume() {
|
|
|
|
super.onResume();
|
|
|
|
DynamicLanguageActivityHelper.recreateIfNotInCorrectLanguage(this, TextSecurePreferences.getLanguage(this));
|
2019-09-18 15:40:18 +10:00
|
|
|
String name = getResources().getString(R.string.app_name);
|
|
|
|
Bitmap icon = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher_foreground);
|
2020-01-09 11:35:43 +11:00
|
|
|
int color = getResources().getColor(R.color.app_icon_background);
|
2019-09-18 15:40:18 +10:00
|
|
|
setTaskDescription(new ActivityManager.TaskDescription(name, icon, color));
|
2019-03-25 17:23:38 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void attachBaseContext(Context newBase) {
|
|
|
|
super.attachBaseContext(DynamicLanguageContextWrapper.updateContext(newBase, TextSecurePreferences.getLanguage(newBase)));
|
|
|
|
}
|
2015-02-08 13:53:12 -08:00
|
|
|
}
|