Skip to content

Commit

Permalink
workaround for the hardware menu button on some buggy LG devices
Browse files Browse the repository at this point in the history
  • Loading branch information
c99koder committed Feb 19, 2015
1 parent 3dd23ac commit 0934516
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ android {
defaultConfig {
versionCode 27
versionName "1.18"
minSdkVersion 10
minSdkVersion 9
targetSdkVersion 21
applicationId "com.irccloud.android"
testApplicationId "com.irccloud.android.test"
Expand Down
43 changes: 43 additions & 0 deletions src/com/irccloud/android/activity/BaseActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import android.os.Build;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.util.Log;
import android.view.*;

import android.app.AlertDialog;
Expand All @@ -36,15 +37,34 @@
import com.irccloud.android.R;
import com.irccloud.android.data.ServersDataSource;

import java.lang.reflect.Field;

public class BaseActivity extends ActionBarActivity implements NetworkConnection.IRCEventHandler{
NetworkConnection conn;
private View dialogTextPrompt;

@Override
protected void onCreate(Bundle savedInstanceState) {
if (isMenuWorkaroundRequired()) {
forceOverflowMenu();
}
super.onCreate(savedInstanceState);
}

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
return (keyCode == KeyEvent.KEYCODE_MENU && isMenuWorkaroundRequired()) || super.onKeyDown(keyCode, event);
}

@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_MENU && isMenuWorkaroundRequired()) {
openOptionsMenu();
return true;
}
return super.onKeyUp(keyCode, event);
}

public View getDialogTextPrompt() {
if(dialogTextPrompt == null)
dialogTextPrompt = ((LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.dialog_textprompt,null);
Expand Down Expand Up @@ -376,4 +396,27 @@ public void onClick(DialogInterface dialog, int which) {
}
return super.onOptionsItemSelected(item);
}

//Work around for buggy LG devices, see https://code.google.com/p/android/issues/detail?id=78154
public static boolean isMenuWorkaroundRequired() {
return Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT &&
Build.VERSION.SDK_INT > Build.VERSION_CODES.GINGERBREAD_MR1 &&
("LGE".equalsIgnoreCase(Build.MANUFACTURER) || "E6710".equalsIgnoreCase(Build.DEVICE));
}

/**
* Modified from: http://stackoverflow.com/a/13098824
*/
public 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("IRCCloud", "Failed to force overflow menu.");
}
}
}
3 changes: 2 additions & 1 deletion src/com/irccloud/android/activity/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.lang.reflect.Field;
import java.net.HttpURLConnection;
import java.net.URI;
import java.net.URL;
Expand Down Expand Up @@ -224,7 +225,7 @@ public View getView(int position, View convertView, ViewGroup parent) {
private int greyColor = 0;

private HashMap<Integer, EventsDataSource.Event> pendingEvents = new HashMap<Integer, EventsDataSource.Event>();

@SuppressLint("NewApi")
@SuppressWarnings({ "deprecation", "unchecked" })
@Override
Expand Down

0 comments on commit 0934516

Please sign in to comment.