aboutsummaryrefslogtreecommitdiffstats
path: root/app/src/fil/libre/repwifiapp/activities/MenuEnabledActivity.java
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/fil/libre/repwifiapp/activities/MenuEnabledActivity.java')
-rw-r--r--app/src/fil/libre/repwifiapp/activities/MenuEnabledActivity.java88
1 files changed, 87 insertions, 1 deletions
diff --git a/app/src/fil/libre/repwifiapp/activities/MenuEnabledActivity.java b/app/src/fil/libre/repwifiapp/activities/MenuEnabledActivity.java
index 0edfcf0..f5c8516 100644
--- a/app/src/fil/libre/repwifiapp/activities/MenuEnabledActivity.java
+++ b/app/src/fil/libre/repwifiapp/activities/MenuEnabledActivity.java
@@ -1,20 +1,60 @@
+//
+// Copyright 2017 Filippo "Fil" Bergamo <fil.bergamo@riseup.net>
+//
+// This file is part of RepWifiApp.
+//
+// RepWifiApp is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// RepWifiApp is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with RepWifiApp. If not, see <http://www.gnu.org/licenses/>.
+//
+// ********************************************************************
+
package fil.libre.repwifiapp.activities;
+import java.lang.reflect.Field;
+import fil.libre.repwifiapp.Commons;
import fil.libre.repwifiapp.R;
+import fil.libre.repwifiapp.helpers.RootCommand;
import android.app.Activity;
+import android.app.AlertDialog;
+import android.content.DialogInterface;
import android.content.Intent;
import android.view.Menu;
import android.view.MenuItem;
+import android.view.ViewConfiguration;
public class MenuEnabledActivity extends Activity {
@Override
+ protected void onCreate(android.os.Bundle savedInstanceState) {
+ try {
+ ViewConfiguration config = ViewConfiguration.get(this);
+ Field menuKeyField = ViewConfiguration.class.getDeclaredField("sHasPermanentMenuKey");
+ if (menuKeyField != null) {
+ menuKeyField.setAccessible(true);
+ menuKeyField.setBoolean(config, false);
+ }
+ } catch (Exception ignored) {
+ }
+ super.onCreate(savedInstanceState);
+ };
+
+ @Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
-
+
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection
@@ -27,6 +67,10 @@ public class MenuEnabledActivity extends Activity {
case R.id.menu_config:
launchSettingsActivity();
break;
+
+ case R.id.menu_btn_closeapp:
+ CloseApplication(false);
+ break;
default:
break;
@@ -46,4 +90,46 @@ public class MenuEnabledActivity extends Activity {
// intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
startActivity(intent);
}
+
+ protected void CloseApplication(boolean silent) {
+
+ if (silent) {
+
+ Commons.connectionEngine.disconnect();
+ Commons.killBackEnd(this, true);
+ super.onDestroy();
+ RootCommand.executeRootCmd("am force-stop " + getPackageName());
+
+ } else {
+
+ String msg = getString(R.string.confirm_exit_app);
+ AlertDialog.Builder dlgAlert = new AlertDialog.Builder(this,
+ R.style.Theme_RepWifiDialogTheme);
+ dlgAlert.setMessage(msg);
+ dlgAlert.setPositiveButton(this.getString(android.R.string.ok),
+ new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int whichButton) {
+ CloseApplication(true);
+ return;
+ }
+ });
+ dlgAlert.setNegativeButton(getString(android.R.string.cancel),
+ new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int whichButton) {
+ return;
+ }
+ });
+
+ dlgAlert.setCancelable(false);
+ AlertDialog diag = dlgAlert.create();
+
+ diag.show();
+ return;
+
+ }
+
+ }
+
}