2015-02-08 13:53:12 -08:00
|
|
|
package org.thoughtcrime.securesms;
|
|
|
|
|
2015-10-19 11:23:12 -07:00
|
|
|
import android.annotation.TargetApi;
|
2019-09-18 15:40:18 +10:00
|
|
|
import android.app.ActivityManager;
|
2019-03-25 17:23:38 -03:00
|
|
|
import android.content.Context;
|
2015-06-22 09:52:46 -07:00
|
|
|
import android.content.Intent;
|
2019-09-18 15:40:18 +10:00
|
|
|
import android.graphics.Bitmap;
|
|
|
|
import android.graphics.BitmapFactory;
|
2015-06-22 09:52:46 -07:00
|
|
|
import android.os.Build;
|
2015-10-19 11:23:12 -07:00
|
|
|
import android.os.Build.VERSION_CODES;
|
2015-02-10 15:33:57 -08:00
|
|
|
import android.os.Bundle;
|
2015-02-08 13:53:12 -08:00
|
|
|
import android.support.annotation.NonNull;
|
2015-06-26 20:14:51 -07:00
|
|
|
import android.support.v4.app.ActivityCompat;
|
|
|
|
import android.support.v4.app.ActivityOptionsCompat;
|
2015-06-09 07:37:20 -07:00
|
|
|
import android.support.v7.app.AppCompatActivity;
|
2015-02-08 13:53:12 -08:00
|
|
|
import android.view.KeyEvent;
|
2015-06-22 09:52:46 -07:00
|
|
|
import android.view.View;
|
2015-02-10 15:33:57 -08:00
|
|
|
import android.view.ViewConfiguration;
|
2015-09-30 20:42:39 -03:00
|
|
|
import android.view.WindowManager;
|
2015-02-10 15:33:57 -08:00
|
|
|
|
2018-08-01 11:09:24 -04:00
|
|
|
import org.thoughtcrime.securesms.logging.Log;
|
2015-09-30 20:42:39 -03:00
|
|
|
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
2019-03-25 17:23:38 -03:00
|
|
|
import org.thoughtcrime.securesms.util.dynamiclanguage.DynamicLanguageActivityHelper;
|
|
|
|
import org.thoughtcrime.securesms.util.dynamiclanguage.DynamicLanguageContextWrapper;
|
2015-09-30 20:42:39 -03:00
|
|
|
|
2015-02-10 15:33:57 -08:00
|
|
|
import java.lang.reflect.Field;
|
2015-02-08 13:53:12 -08:00
|
|
|
|
2019-09-18 15:40:18 +10:00
|
|
|
import network.loki.messenger.R;
|
|
|
|
|
2015-02-08 13:53:12 -08:00
|
|
|
|
2015-06-09 07:37:20 -07:00
|
|
|
public abstract class BaseActionBarActivity extends AppCompatActivity {
|
2015-02-10 15:33:57 -08:00
|
|
|
private static final String TAG = BaseActionBarActivity.class.getSimpleName();
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
if (BaseActivity.isMenuWorkaroundRequired()) {
|
|
|
|
forceOverflowMenu();
|
|
|
|
}
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
}
|
|
|
|
|
2015-09-30 20:42:39 -03:00
|
|
|
@Override
|
|
|
|
protected void onResume() {
|
|
|
|
super.onResume();
|
|
|
|
initializeScreenshotSecurity();
|
2019-03-25 17:23:38 -03:00
|
|
|
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);
|
|
|
|
int color = getResources().getColor(R.color.loki_darkest_gray);
|
|
|
|
setTaskDescription(new ActivityManager.TaskDescription(name, icon, color));
|
2015-09-30 20:42:39 -03:00
|
|
|
}
|
|
|
|
|
2015-02-08 13:53:12 -08:00
|
|
|
@Override
|
|
|
|
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
2015-02-10 15:33:57 -08:00
|
|
|
return (keyCode == KeyEvent.KEYCODE_MENU && BaseActivity.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 && BaseActivity.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
|
|
|
|
2015-09-30 20:42:39 -03:00
|
|
|
private void initializeScreenshotSecurity() {
|
2019-03-20 15:09:27 -07:00
|
|
|
if (TextSecurePreferences.isScreenSecurityEnabled(this)) {
|
2015-09-30 20:42:39 -03:00
|
|
|
getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE);
|
|
|
|
} else {
|
|
|
|
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_SECURE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-10 15:33:57 -08:00
|
|
|
/**
|
|
|
|
* Modified from: http://stackoverflow.com/a/13098824
|
|
|
|
*/
|
|
|
|
private void forceOverflowMenu() {
|
|
|
|
try {
|
|
|
|
ViewConfiguration config = ViewConfiguration.get(this);
|
|
|
|
Field menuKeyField = ViewConfiguration.class.getDeclaredField("sHasPermanentMenuKey");
|
|
|
|
if(menuKeyField != null) {
|
|
|
|
menuKeyField.setAccessible(true);
|
|
|
|
menuKeyField.setBoolean(config, false);
|
|
|
|
}
|
2015-06-09 07:37:20 -07:00
|
|
|
} catch (IllegalAccessException e) {
|
|
|
|
Log.w(TAG, "Failed to force overflow menu.");
|
|
|
|
} catch (NoSuchFieldException e) {
|
2015-02-10 15:33:57 -08:00
|
|
|
Log.w(TAG, "Failed to force overflow menu.");
|
|
|
|
}
|
|
|
|
}
|
2015-06-22 09:52:46 -07:00
|
|
|
|
|
|
|
protected void startActivitySceneTransition(Intent intent, View sharedView, String transitionName) {
|
2015-06-26 20:14:51 -07:00
|
|
|
Bundle bundle = ActivityOptionsCompat.makeSceneTransitionAnimation(this, sharedView, transitionName)
|
|
|
|
.toBundle();
|
|
|
|
ActivityCompat.startActivity(this, intent, bundle);
|
2015-06-22 09:52:46 -07:00
|
|
|
}
|
2015-10-19 11:23:12 -07:00
|
|
|
|
|
|
|
@TargetApi(VERSION_CODES.LOLLIPOP)
|
|
|
|
protected void setStatusBarColor(int color) {
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
|
|
|
getWindow().setStatusBarColor(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
|
|
|
}
|