2015-02-08 21:53:12 +00:00
|
|
|
package org.thoughtcrime.securesms;
|
|
|
|
|
2015-02-10 23:33:57 +00:00
|
|
|
import android.os.Bundle;
|
2015-02-08 21:53:12 +00:00
|
|
|
import android.support.annotation.NonNull;
|
|
|
|
import android.support.v7.app.ActionBarActivity;
|
2015-02-10 23:33:57 +00:00
|
|
|
import android.util.Log;
|
2015-02-08 21:53:12 +00:00
|
|
|
import android.view.KeyEvent;
|
2015-02-10 23:33:57 +00:00
|
|
|
import android.view.ViewConfiguration;
|
|
|
|
|
|
|
|
import java.lang.reflect.Field;
|
2015-02-08 21:53:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
public abstract class BaseActionBarActivity extends ActionBarActivity {
|
2015-02-10 23:33:57 +00:00
|
|
|
private static final String TAG = BaseActionBarActivity.class.getSimpleName();
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
if (BaseActivity.isMenuWorkaroundRequired()) {
|
|
|
|
forceOverflowMenu();
|
|
|
|
}
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
}
|
|
|
|
|
2015-02-08 21:53:12 +00:00
|
|
|
@Override
|
|
|
|
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
2015-02-10 23:33:57 +00:00
|
|
|
return (keyCode == KeyEvent.KEYCODE_MENU && BaseActivity.isMenuWorkaroundRequired()) || super.onKeyDown(keyCode, event);
|
2015-02-08 21:53:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onKeyUp(int keyCode, @NonNull KeyEvent event) {
|
2015-02-10 23:33:57 +00:00
|
|
|
if (keyCode == KeyEvent.KEYCODE_MENU && BaseActivity.isMenuWorkaroundRequired()) {
|
2015-02-08 21:53:12 +00:00
|
|
|
openOptionsMenu();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return super.onKeyUp(keyCode, event);
|
|
|
|
}
|
2015-02-10 23:33:57 +00: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);
|
|
|
|
}
|
|
|
|
} catch (IllegalAccessException | NoSuchFieldException e) {
|
|
|
|
Log.w(TAG, "Failed to force overflow menu.");
|
|
|
|
}
|
|
|
|
}
|
2015-02-08 21:53:12 +00:00
|
|
|
}
|