use of org.ethack.orwall.lib.AppRule in project orWall by EthACKdotOrg.
the class AppListAdapter method getView.
/**
* Creates the view with both lists.
*
* @param position - position in list
* @param convertView - conversion view
* @param parent - parent view group
* @return - the formatted view
*/
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) this.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
ViewHolder holder;
if (convertView == null) {
convertView = inflater.inflate(R.layout.app_row, parent, false);
holder = new ViewHolder();
holder.checkBox = (CheckBox) convertView.findViewById(R.id.id_application);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.checkBox.setTag(position);
AppRule appRule = this.apps.get(position);
ApplicationInfo applicationInfo = null;
PackageInfoData packageInfoData = null;
Drawable appIcon = null;
if (appRule.getPkgName().startsWith(Constants.SPECIAL_APPS_PREFIX)) {
packageInfoData = specialApps.get(appRule.getPkgName());
Bitmap b = BitmapFactory.decodeResource(context.getResources(), R.drawable.android_unknown_app);
appIcon = new BitmapDrawable(context.getResources(), b);
} else {
PackageManager packageManager = this.context.getPackageManager();
try {
applicationInfo = packageManager.getApplicationInfo(appRule.getPkgName(), 0);
appIcon = packageManager.getApplicationIcon(applicationInfo);
} catch (PackageManager.NameNotFoundException e) {
Log.e(TAG, "Application not found: " + appRule.getPkgName());
}
}
if (applicationInfo != null || packageInfoData != null) {
appIcon.setBounds(0, 0, 40, 40);
holder.checkBox.setCompoundDrawables(appIcon, null, null, null);
holder.checkBox.setTag(R.id.id_appTag, appRule);
if (appRule.getLabel() == null) {
if (appRule.getAppName() == null) {
String appName;
if (packageInfoData != null) {
appName = (specialApps.get(appRule.getPkgName())).getName();
} else {
appName = (String) packageManager.getApplicationLabel(applicationInfo);
}
appRule.setAppName(appName);
}
if (appRule.isStored()) {
String label = appRule.getDisplay();
holder.checkBox.setText(label);
appRule.setLabel(label);
holder.checkBox.setChecked(true);
} else {
holder.checkBox.setText(appRule.getAppName());
appRule.setLabel(appRule.getAppName());
holder.checkBox.setChecked(false);
}
} else {
holder.checkBox.setText(appRule.getLabel());
holder.checkBox.setChecked(appRule.isStored());
}
holder.checkBox.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Log.d(TAG, "Click caught!");
boolean checked = ((CheckBox) view).isChecked();
int getPosition = (Integer) view.getTag();
toggleApp(checked, getPosition);
AppRule rule = apps.get(getPosition);
CheckBox checkBox = (CheckBox) view;
checkBox.setChecked(rule.isStored());
checkBox.setText(rule.getLabel());
}
});
holder.checkBox.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View view) {
showAdvanced(view);
return true;
}
});
}
return convertView;
}
use of org.ethack.orwall.lib.AppRule in project orWall by EthACKdotOrg.
the class AppListAdapter method toggleApp.
/**
* Function called when we touch an app in the "app" tab
*
* @param checked boolean: is checkbox checked?
* @param position integer: position in apps list
*/
public void toggleApp(boolean checked, int position) {
AppRule appRule = apps.get(position);
if (checked) {
if (Util.isOrbotInstalled(this.context))
appRule.setOnionType(Constants.DB_ONION_TYPE_TOR);
else
appRule.setOnionType(Constants.DB_ONION_TYPE_BYPASS);
appRule.setLocalHost(false);
appRule.setLocalNetwork(false);
boolean success = this.natRules.addAppToRules(appRule);
if (success) {
Toast.makeText(context, context.getString(R.string.toast_new_rule), Toast.LENGTH_SHORT).show();
appRule.setStored(true);
appRule.setLabel(appRule.getDisplay());
if (Preferences.isOrwallEnabled(context))
appRule.install(context);
} else {
appRule.setOnionType(Constants.DB_ONION_TYPE_NONE);
Toast.makeText(context, String.format(context.getString(R.string.toast_error), 1), Toast.LENGTH_SHORT).show();
}
} else {
String oldType = appRule.getOnionType();
Boolean oldLocalhost = appRule.getLocalHost();
Boolean oldLocalNetwork = appRule.getLocalNetwork();
boolean success = this.natRules.removeAppFromRules(appRule.getAppUID());
if (success) {
if (Preferences.isOrwallEnabled(context))
appRule.uninstall(context);
appRule.setStored(false);
appRule.setOnionType(Constants.DB_ONION_TYPE_NONE);
appRule.setLocalHost(false);
appRule.setLocalNetwork(false);
appRule.setLabel(appRule.getAppName());
Toast.makeText(context, context.getString(R.string.toast_remove_rule), Toast.LENGTH_SHORT).show();
} else {
appRule.setOnionType(oldType);
appRule.setLocalHost(oldLocalhost);
appRule.setLocalNetwork(oldLocalNetwork);
Toast.makeText(context, String.format(context.getString(R.string.toast_error), 2), Toast.LENGTH_SHORT).show();
}
}
}
use of org.ethack.orwall.lib.AppRule in project orWall by EthACKdotOrg.
the class AppListAdapter method showAdvanced.
public void showAdvanced(final View view) {
LayoutInflater li = LayoutInflater.from(this.context);
View l_view = li.inflate(R.layout.advanced_connection, null);
// Get application information
final AppRule appRule = (AppRule) view.getTag(R.id.id_appTag);
// Add Proxy providers if available
// Is orbot installed ?
this.checkboxInternet = (CheckBox) l_view.findViewById(R.id.id_check_internet);
if (appRule.getOnionType() != null && !appRule.getOnionType().equals(Constants.DB_ONION_TYPE_NONE)) {
this.checkboxInternet.setChecked(true);
}
this.checkboxInternet.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
radioBypass.setEnabled(checkboxInternet.isChecked());
radioTor.setEnabled(checkboxInternet.isChecked() && Util.isOrbotInstalled(context));
if (!radioBypass.isChecked() && !radioTor.isChecked()) {
if (radioTor.isEnabled()) {
radioTor.setChecked(true);
} else {
radioBypass.setChecked(true);
}
}
}
});
this.radioBypass = (RadioButton) l_view.findViewById(R.id.id_radio_bypass);
if (appRule.getOnionType() != null && appRule.getOnionType().equals(Constants.DB_ONION_TYPE_BYPASS)) {
this.radioBypass.setChecked(true);
}
this.radioBypass.setEnabled(this.checkboxInternet.isChecked());
this.radioTor = (RadioButton) l_view.findViewById(R.id.id_radio_tor);
if (!Util.isOrbotInstalled(this.context)) {
radioTor.setEnabled(false);
} else {
if (appRule.getOnionType() != null && appRule.getOnionType().equals(Constants.DB_ONION_TYPE_TOR)) {
radioTor.setChecked(true);
}
this.radioTor.setEnabled(this.checkboxInternet.isChecked());
}
/*
// is i2p present? No helper for that now
PackageInfo i2p = null;
try {
i2p = this.packageManager.getPackageInfo(Constants.I2P_APP_NAME, PackageManager.GET_PERMISSIONS);
} catch (PackageManager.NameNotFoundException e) {
}
this.radioI2p = new RadioButton(this.context);
if (i2p != null) {
radioI2p.setText("i2p");
// For now we do not have support for i2p. Just teasing ;)
radioI2p.setEnabled(false);
if (appRule.getOnionType() != null && appRule.getOnionType().equals(Constants.DB_ONION_TYPE_I2P)) {
radioI2p.setChecked(true);
}
((ViewGroup) l_view.findViewById(R.id.radio_connection_providers)).addView(radioI2p);
}
*/
this.checkLocalHost = (CheckBox) l_view.findViewById(R.id.id_check_localhost);
this.checkLocalHost.setChecked(appRule.getLocalHost());
this.checkLocalNetwork = (CheckBox) l_view.findViewById(R.id.id_check_localnetwork);
this.checkLocalNetwork.setChecked(appRule.getLocalNetwork());
AlertDialog.Builder alert = new AlertDialog.Builder(context);
// Will save state and apply rules
alert.setPositiveButton(R.string.alert_save, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
saveAdvanced(appRule, view);
}
});
// Will do nothing
alert.setNegativeButton(R.string.alert_cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
dialogInterface.cancel();
}
});
// get app icon
Drawable icon = ((CheckBox) view).getCompoundDrawables()[0];
alert.setIcon(icon.getConstantState().newDrawable());
// Display alert
alert.setTitle(String.format(this.context.getString(R.string.advanced_connection_settings_title), appRule.getAppName())).setView(l_view).show();
}
Aggregations