@Override public void onClick(View v) { if (v.getId() == R.id.enableFirewall) { if (Api.applySavedIptablesRules(getApplicationContext(), false)) { Toast.makeText(getApplicationContext(), R.string.toast_enabled, Toast.LENGTH_SHORT).show(); Api.setEnabled(getApplicationContext(), true); } else { Toast.makeText(getApplicationContext(), R.string.toast_error_enabling, Toast.LENGTH_SHORT) .show(); } finish(); } if (v.getId() == R.id.disableFirewall) { final SharedPreferences prefs = getApplicationContext().getSharedPreferences(Api.PREFS_NAME, 0); final boolean enabled = !prefs.getBoolean(Api.PREF_ENABLED, true); SharedPreferences prefs2 = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); final String pwd = prefs2.getString("password", ""); if (!enabled && pwd.length() != 0) { Toast.makeText(getApplicationContext(), R.string.widget_fail, Toast.LENGTH_SHORT).show(); } else { if (Api.purgeIptables(getApplicationContext(), false)) { Toast.makeText(getApplicationContext(), R.string.toast_disabled, Toast.LENGTH_SHORT) .show(); Api.setEnabled(getApplicationContext(), false); } else { Toast.makeText( getApplicationContext(), R.string.toast_error_disabling, Toast.LENGTH_SHORT) .show(); } } finish(); } if (v.getId() == R.id.DefaultProfile) { SharedPreferences prefs = getApplicationContext().getSharedPreferences(Api.PREFS_NAME, Context.MODE_PRIVATE); final SharedPreferences prefs2 = getApplicationContext().getSharedPreferences(Api.PREF_PROFILE, Context.MODE_PRIVATE); SharedPreferences prefs3 = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); SharedPreferences.Editor editor = prefs3.edit(); final Editor editRules = prefs.edit(); editRules.clear(); for (Entry<String, ?> entry : prefs2.getAll().entrySet()) { Object rule = entry.getValue(); String keys = entry.getKey(); if (rule instanceof Boolean) editRules.putBoolean(keys, ((Boolean) rule).booleanValue()); else if (rule instanceof Float) editRules.putFloat(keys, ((Float) rule).floatValue()); else if (rule instanceof String) editRules.putString(keys, ((String) rule)); else if (rule instanceof Long) editRules.putLong(keys, ((Long) rule).longValue()); else if (rule instanceof Integer) editRules.putInt(keys, ((Integer) rule).intValue()); } editRules.commit(); Api.applications = null; editor.putInt("itemPosition", 0); editor.commit(); toggleUserSettings(getApplicationContext()); boolean enabled = prefs.getBoolean(Api.PREF_ENABLED, false); final String pwd = prefs3.getString("password", ""); if (enabled) { Api.applyIptablesRules(getApplicationContext(), true); Api.setEnabled(getApplicationContext(), true); } if (!enabled) { if (pwd.length() != 0) { Toast.makeText(getApplicationContext(), R.string.widget_fail, Toast.LENGTH_SHORT).show(); } else { Api.saveRules(getApplicationContext()); Api.purgeIptables(getApplicationContext(), true); Api.setEnabled(getApplicationContext(), false); } } finish(); } if (v.getId() == R.id.Profile1) { SharedPreferences prefs = getApplicationContext().getSharedPreferences(Api.PREFS_NAME, Context.MODE_PRIVATE); final SharedPreferences prefs2 = getApplicationContext().getSharedPreferences(Api.PREF_PROFILE1, Context.MODE_PRIVATE); SharedPreferences prefs3 = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); SharedPreferences.Editor editor = prefs3.edit(); final Editor editRules = prefs.edit(); editRules.clear(); for (Entry<String, ?> entry : prefs2.getAll().entrySet()) { Object rule = entry.getValue(); String keys = entry.getKey(); if (rule instanceof Boolean) editRules.putBoolean(keys, ((Boolean) rule).booleanValue()); else if (rule instanceof Float) editRules.putFloat(keys, ((Float) rule).floatValue()); else if (rule instanceof String) editRules.putString(keys, ((String) rule)); else if (rule instanceof Long) editRules.putLong(keys, ((Long) rule).longValue()); else if (rule instanceof Integer) editRules.putInt(keys, ((Integer) rule).intValue()); } editRules.commit(); Api.applications = null; editor.putInt("itemPosition", 1); editor.commit(); toggleUserSettings(getApplicationContext()); boolean enabled = prefs.getBoolean(Api.PREF_ENABLED, false); final String pwd = prefs3.getString("password", ""); if (enabled) { Api.applyIptablesRules(getApplicationContext(), true); Api.setEnabled(getApplicationContext(), true); } if (!enabled) { if (pwd.length() != 0) { Toast.makeText(getApplicationContext(), R.string.widget_fail, Toast.LENGTH_SHORT).show(); } else { Api.saveRules(getApplicationContext()); Api.purgeIptables(getApplicationContext(), true); Api.setEnabled(getApplicationContext(), false); } } finish(); } if (v.getId() == R.id.Profile2) { SharedPreferences prefs = getApplicationContext().getSharedPreferences(Api.PREFS_NAME, Context.MODE_PRIVATE); final SharedPreferences prefs2 = getApplicationContext().getSharedPreferences(Api.PREF_PROFILE2, Context.MODE_PRIVATE); SharedPreferences prefs3 = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); SharedPreferences.Editor editor = prefs3.edit(); final Editor editRules = prefs.edit(); editRules.clear(); for (Entry<String, ?> entry : prefs2.getAll().entrySet()) { Object rule = entry.getValue(); String keys = entry.getKey(); if (rule instanceof Boolean) editRules.putBoolean(keys, ((Boolean) rule).booleanValue()); else if (rule instanceof Float) editRules.putFloat(keys, ((Float) rule).floatValue()); else if (rule instanceof String) editRules.putString(keys, ((String) rule)); else if (rule instanceof Long) editRules.putLong(keys, ((Long) rule).longValue()); else if (rule instanceof Integer) editRules.putInt(keys, ((Integer) rule).intValue()); } editRules.commit(); Api.applications = null; editor.putInt("itemPosition", 2); editor.commit(); toggleUserSettings(getApplicationContext()); boolean enabled = prefs.getBoolean(Api.PREF_ENABLED, false); final String pwd = prefs3.getString("password", ""); if (enabled) { Api.applyIptablesRules(getApplicationContext(), true); Api.setEnabled(getApplicationContext(), true); } if (!enabled) { if (pwd.length() != 0) { Toast.makeText(getApplicationContext(), R.string.widget_fail, Toast.LENGTH_SHORT).show(); } else { Api.saveRules(getApplicationContext()); Api.purgeIptables(getApplicationContext(), true); Api.setEnabled(getApplicationContext(), false); } } finish(); } if (v.getId() == R.id.Profile3) { SharedPreferences prefs = getApplicationContext().getSharedPreferences(Api.PREFS_NAME, Context.MODE_PRIVATE); final SharedPreferences prefs2 = getApplicationContext().getSharedPreferences(Api.PREF_PROFILE3, Context.MODE_PRIVATE); SharedPreferences prefs3 = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); SharedPreferences.Editor editor = prefs3.edit(); final Editor editRules = prefs.edit(); editRules.clear(); for (Entry<String, ?> entry : prefs2.getAll().entrySet()) { Object rule = entry.getValue(); String keys = entry.getKey(); if (rule instanceof Boolean) editRules.putBoolean(keys, ((Boolean) rule).booleanValue()); else if (rule instanceof Float) editRules.putFloat(keys, ((Float) rule).floatValue()); else if (rule instanceof String) editRules.putString(keys, ((String) rule)); else if (rule instanceof Long) editRules.putLong(keys, ((Long) rule).longValue()); else if (rule instanceof Integer) editRules.putInt(keys, ((Integer) rule).intValue()); } editRules.commit(); Api.applications = null; editor.putInt("itemPosition", 3); editor.commit(); toggleUserSettings(getApplicationContext()); boolean enabled = prefs.getBoolean(Api.PREF_ENABLED, false); final String pwd = prefs3.getString("password", ""); if (enabled) { Api.applyIptablesRules(getApplicationContext(), true); Api.setEnabled(getApplicationContext(), true); } if (!enabled) { if (pwd.length() != 0) { Toast.makeText(getApplicationContext(), R.string.widget_fail, Toast.LENGTH_SHORT).show(); } else { Api.saveRules(getApplicationContext()); Api.purgeIptables(getApplicationContext(), true); Api.setEnabled(getApplicationContext(), false); } } finish(); } if (v.getId() == R.id.Profile4) { SharedPreferences prefs = getApplicationContext().getSharedPreferences(Api.PREFS_NAME, Context.MODE_PRIVATE); final SharedPreferences prefs2 = getApplicationContext().getSharedPreferences(Api.PREF_PROFILE4, Context.MODE_PRIVATE); SharedPreferences prefs3 = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); SharedPreferences.Editor editor = prefs3.edit(); final Editor editRules = prefs.edit(); editRules.clear(); for (Entry<String, ?> entry : prefs2.getAll().entrySet()) { Object rule = entry.getValue(); String keys = entry.getKey(); if (rule instanceof Boolean) editRules.putBoolean(keys, ((Boolean) rule).booleanValue()); else if (rule instanceof Float) editRules.putFloat(keys, ((Float) rule).floatValue()); else if (rule instanceof String) editRules.putString(keys, ((String) rule)); else if (rule instanceof Long) editRules.putLong(keys, ((Long) rule).longValue()); else if (rule instanceof Integer) editRules.putInt(keys, ((Integer) rule).intValue()); } editRules.commit(); Api.applications = null; editor.putInt("itemPosition", 4); editor.commit(); toggleUserSettings(getApplicationContext()); boolean enabled = prefs.getBoolean(Api.PREF_ENABLED, false); final String pwd = prefs3.getString("password", ""); if (enabled) { Api.applyIptablesRules(getApplicationContext(), true); Api.setEnabled(getApplicationContext(), true); } if (!enabled) { if (pwd.length() != 0) { Toast.makeText(getApplicationContext(), R.string.widget_fail, Toast.LENGTH_SHORT).show(); } else { Api.saveRules(getApplicationContext()); Api.purgeIptables(getApplicationContext(), true); Api.setEnabled(getApplicationContext(), false); } } finish(); } if (v.getId() == R.id.Profile5) { SharedPreferences prefs = getApplicationContext().getSharedPreferences(Api.PREFS_NAME, Context.MODE_PRIVATE); final SharedPreferences prefs2 = getApplicationContext().getSharedPreferences(Api.PREF_PROFILE5, Context.MODE_PRIVATE); SharedPreferences prefs3 = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); SharedPreferences.Editor editor = prefs3.edit(); final Editor editRules = prefs.edit(); editRules.clear(); for (Entry<String, ?> entry : prefs2.getAll().entrySet()) { Object rule = entry.getValue(); String keys = entry.getKey(); if (rule instanceof Boolean) editRules.putBoolean(keys, ((Boolean) rule).booleanValue()); else if (rule instanceof Float) editRules.putFloat(keys, ((Float) rule).floatValue()); else if (rule instanceof String) editRules.putString(keys, ((String) rule)); else if (rule instanceof Long) editRules.putLong(keys, ((Long) rule).longValue()); else if (rule instanceof Integer) editRules.putInt(keys, ((Integer) rule).intValue()); } editRules.commit(); Api.applications = null; editor.putInt("itemPosition", 5); editor.commit(); toggleUserSettings(getApplicationContext()); boolean enabled = prefs.getBoolean(Api.PREF_ENABLED, false); final String pwd = prefs3.getString("password", ""); if (enabled) { Api.applyIptablesRules(getApplicationContext(), true); Api.setEnabled(getApplicationContext(), true); } if (!enabled) { if (pwd.length() != 0) { Toast.makeText(getApplicationContext(), R.string.widget_fail, Toast.LENGTH_SHORT).show(); } else { Api.saveRules(getApplicationContext()); Api.purgeIptables(getApplicationContext(), true); Api.setEnabled(getApplicationContext(), false); } } finish(); } }