Search in sources :

Example 6 with AppRule

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;
}
Also used : ApplicationInfo(android.content.pm.ApplicationInfo) Drawable(android.graphics.drawable.Drawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) View(android.view.View) Bitmap(android.graphics.Bitmap) PackageManager(android.content.pm.PackageManager) PackageInfoData(org.ethack.orwall.lib.PackageInfoData) CheckBox(android.widget.CheckBox) LayoutInflater(android.view.LayoutInflater) AppRule(org.ethack.orwall.lib.AppRule)

Example 7 with AppRule

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();
        }
    }
}
Also used : AppRule(org.ethack.orwall.lib.AppRule)

Example 8 with AppRule

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();
}
Also used : AlertDialog(android.app.AlertDialog) DialogInterface(android.content.DialogInterface) LayoutInflater(android.view.LayoutInflater) AppRule(org.ethack.orwall.lib.AppRule) Drawable(android.graphics.drawable.Drawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) View(android.view.View)

Aggregations

AppRule (org.ethack.orwall.lib.AppRule)8 View (android.view.View)3 PackageManager (android.content.pm.PackageManager)2 BitmapDrawable (android.graphics.drawable.BitmapDrawable)2 Drawable (android.graphics.drawable.Drawable)2 LayoutInflater (android.view.LayoutInflater)2 CheckBox (android.widget.CheckBox)2 ArrayList (java.util.ArrayList)2 NatRules (org.ethack.orwall.lib.NatRules)2 PackageInfoData (org.ethack.orwall.lib.PackageInfoData)2 AlertDialog (android.app.AlertDialog)1 DialogInterface (android.content.DialogInterface)1 ApplicationInfo (android.content.pm.ApplicationInfo)1 PackageInfo (android.content.pm.PackageInfo)1 Bitmap (android.graphics.Bitmap)1 Uri (android.net.Uri)1 LongSparseArray (android.support.v4.util.LongSparseArray)1 ListView (android.widget.ListView)1 AppListAdapter (org.ethack.orwall.adapter.AppListAdapter)1 AppRuleComparator (org.ethack.orwall.lib.AppRuleComparator)1