Search in sources :

Example 6 with PackageInfoData

use of dev.ukanth.ufirewall.Api.PackageInfoData in project afwall by ukanth.

the class MainActivity method showApplications.

/**
 * Show the list of applications
 */
private void showApplications(final String searchStr, int flag, boolean showAll) {
    setDirty(false);
    List<PackageInfoData> searchApp = new ArrayList<>();
    HashSet<Integer> unique = new HashSet<>();
    final List<PackageInfoData> apps = Api.getApps(this, null);
    boolean isResultsFound = false;
    if (searchStr != null && searchStr.length() > 1) {
        for (PackageInfoData app : apps) {
            for (String str : app.names) {
                if (str != null && searchStr != null) {
                    if (str.contains(searchStr.toLowerCase()) || str.toLowerCase().contains(searchStr.toLowerCase()) && !searchApp.contains(app) || (G.showUid() && (str + " " + app.uid).contains(searchStr) && !unique.contains(app.uid))) {
                        searchApp.add(app);
                        unique.add(app.uid);
                        isResultsFound = true;
                    }
                }
            }
        }
    } else if (flag > -1) {
        switch(flag) {
            case 0:
                for (PackageInfoData app : apps) {
                    if (app.pkgName.startsWith("dev.afwall.special")) {
                        searchApp.add(app);
                    }
                }
                break;
            case 1:
                for (PackageInfoData app : apps) {
                    if (app.appinfo != null && (app.appinfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
                        searchApp.add(app);
                    }
                }
                break;
            case 2:
                for (PackageInfoData app : apps) {
                    if (app.appinfo != null && (app.appinfo.flags & ApplicationInfo.FLAG_SYSTEM) == 0) {
                        searchApp.add(app);
                    }
                }
                break;
        }
    }
    List<PackageInfoData> apps2;
    if (showAll || (searchStr != null && searchStr.equals(""))) {
        apps2 = apps;
    } else if (isResultsFound || searchApp.size() > 0) {
        apps2 = searchApp;
    } else {
        apps2 = new ArrayList<PackageInfoData>();
    }
    synchronized (apps2) {
        // Sort applications - selected first, then alphabetically
        try {
            Collections.sort(apps2, new PackageComparator());
        } catch (IllegalArgumentException e) {
            Log.d(Api.TAG, "IllegalArgumentException on Sort");
        }
    }
    this.listview.setAdapter(new AppListArrayAdapter(this, getApplicationContext(), apps2));
    // restore
    this.listview.setSelectionFromTop(index, top);
}
Also used : PackageInfoData(dev.ukanth.ufirewall.Api.PackageInfoData) PackageComparator(dev.ukanth.ufirewall.util.PackageComparator) ArrayList(java.util.ArrayList) AppListArrayAdapter(dev.ukanth.ufirewall.util.AppListArrayAdapter) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 7 with PackageInfoData

use of dev.ukanth.ufirewall.Api.PackageInfoData in project afwall by ukanth.

the class MainActivity method copyColumns.

private void copyColumns(int which, int which2) {
    if (this.listview == null) {
        this.listview = this.findViewById(R.id.listview);
    }
    ListAdapter adapter = listview.getAdapter();
    if (adapter != null) {
        int count = adapter.getCount(), item;
        for (item = 0; item < count; item++) {
            PackageInfoData data = (PackageInfoData) adapter.getItem(item);
            if (data.uid != Api.SPECIAL_UID_ANY) {
                switch(which) {
                    case 0:
                        switch(which2) {
                            case 0:
                                break;
                            case 1:
                                data.selected_wifi = data.selected_lan;
                                break;
                            case 2:
                                data.selected_3g = data.selected_lan;
                                break;
                            case 3:
                                data.selected_vpn = data.selected_lan;
                                break;
                            case 4:
                                data.selected_roam = data.selected_lan;
                                break;
                            case 5:
                                data.selected_tether = data.selected_lan;
                                break;
                            case 6:
                                data.selected_tor = data.selected_lan;
                                break;
                        }
                        break;
                    case 1:
                        switch(which2) {
                            case 0:
                                data.selected_lan = data.selected_wifi;
                                break;
                            case 1:
                                break;
                            case 2:
                                data.selected_3g = data.selected_wifi;
                                break;
                            case 3:
                                data.selected_vpn = data.selected_wifi;
                                break;
                            case 4:
                                data.selected_roam = data.selected_wifi;
                                break;
                            case 5:
                                data.selected_tether = data.selected_wifi;
                                break;
                            case 6:
                                data.selected_tor = data.selected_wifi;
                                break;
                        }
                        break;
                    case 2:
                        switch(which2) {
                            case 0:
                                data.selected_lan = data.selected_3g;
                                break;
                            case 1:
                                data.selected_wifi = data.selected_3g;
                                break;
                            case 2:
                                break;
                            case 3:
                                data.selected_vpn = data.selected_3g;
                                break;
                            case 4:
                                data.selected_roam = data.selected_3g;
                                break;
                            case 5:
                                data.selected_tether = data.selected_3g;
                                break;
                            case 6:
                                data.selected_tor = data.selected_3g;
                                break;
                        }
                        break;
                    case 3:
                        switch(which2) {
                            case 0:
                                data.selected_lan = data.selected_vpn;
                                break;
                            case 1:
                                data.selected_wifi = data.selected_vpn;
                                break;
                            case 2:
                                data.selected_3g = data.selected_vpn;
                                break;
                            case 3:
                                break;
                            case 4:
                                data.selected_roam = data.selected_vpn;
                                break;
                            case 5:
                                data.selected_tether = data.selected_vpn;
                                break;
                            case 6:
                                data.selected_tor = data.selected_vpn;
                                break;
                        }
                        break;
                    case 4:
                        switch(which2) {
                            case 0:
                                data.selected_lan = data.selected_roam;
                                break;
                            case 1:
                                data.selected_wifi = data.selected_roam;
                                break;
                            case 2:
                                data.selected_3g = data.selected_roam;
                                break;
                            case 3:
                                data.selected_vpn = data.selected_roam;
                                break;
                            case 4:
                                break;
                            case 5:
                                data.selected_tether = data.selected_roam;
                                break;
                            case 6:
                                data.selected_tor = data.selected_roam;
                                break;
                        }
                        break;
                    case 5:
                        switch(which2) {
                            case 0:
                                data.selected_lan = data.selected_tether;
                                break;
                            case 1:
                                data.selected_wifi = data.selected_tether;
                                break;
                            case 2:
                                data.selected_3g = data.selected_tether;
                                break;
                            case 3:
                                data.selected_vpn = data.selected_tether;
                                break;
                            case 4:
                                data.selected_roam = data.selected_tether;
                                break;
                            case 5:
                                break;
                            case 6:
                                data.selected_tor = data.selected_tether;
                                break;
                        }
                        break;
                    case 6:
                        switch(which2) {
                            case 0:
                                data.selected_lan = data.selected_tor;
                                break;
                            case 1:
                                data.selected_wifi = data.selected_tor;
                                break;
                            case 2:
                                data.selected_3g = data.selected_tor;
                                break;
                            case 3:
                                data.selected_vpn = data.selected_tor;
                                break;
                            case 4:
                                data.selected_roam = data.selected_tor;
                                break;
                            case 5:
                                data.selected_tether = data.selected_tor;
                                break;
                            case 6:
                                break;
                        }
                        break;
                }
            }
            setDirty(true);
        }
        ((BaseAdapter) adapter).notifyDataSetChanged();
    }
}
Also used : PackageInfoData(dev.ukanth.ufirewall.Api.PackageInfoData) BaseAdapter(android.widget.BaseAdapter) ListAdapter(android.widget.ListAdapter)

Example 8 with PackageInfoData

use of dev.ukanth.ufirewall.Api.PackageInfoData in project afwall by ukanth.

the class MainActivity method showApplications.

/**
 * Show the list of applications
 */
private void showApplications(final String searchStr) {
    setDirty(false);
    List<PackageInfoData> searchApp = new ArrayList<>();
    HashSet<Integer> unique = new HashSet<>();
    final List<PackageInfoData> apps = Api.getApps(this, null);
    boolean isResultsFound = false;
    if (searchStr != null && searchStr.length() > 1) {
        for (PackageInfoData app : apps) {
            for (String str : app.names) {
                if (str != null && searchStr != null) {
                    if (str.contains(searchStr.toLowerCase()) || str.toLowerCase().contains(searchStr.toLowerCase()) && !searchApp.contains(app) || (G.showUid() && (str + " " + app.uid).contains(searchStr) && !unique.contains(app.uid))) {
                        searchApp.add(app);
                        unique.add(app.uid);
                        isResultsFound = true;
                    }
                }
            }
        }
    }
    List<PackageInfoData> apps2 = null;
    if (searchStr != null && searchStr.equals("")) {
        apps2 = apps;
    } else if (isResultsFound || searchApp.size() > 0) {
        apps2 = searchApp;
    }
    // Sort applications - selected first, then alphabetically
    try {
        if (apps2 != null) {
            Collections.sort(apps2, new PackageComparator());
            ArrayAdapter appAdapter;
            if (selectedColumns <= DEFAULT_VIEW_LIMIT) {
                appAdapter = new AppListArrayAdapter(this, getApplicationContext(), apps2, true);
            } else {
                appAdapter = new AppListArrayAdapter(this, getApplicationContext(), apps2);
            }
            this.listview.setAdapter(appAdapter);
            // restore
            this.listview.setSelectionFromTop(index, top);
        }
    } catch (Exception e) {
        Log.d(Api.TAG, "Exception on Sorting");
    }
}
Also used : PackageInfoData(dev.ukanth.ufirewall.Api.PackageInfoData) PackageComparator(dev.ukanth.ufirewall.util.PackageComparator) ArrayList(java.util.ArrayList) AppListArrayAdapter(dev.ukanth.ufirewall.util.AppListArrayAdapter) AppListArrayAdapter(dev.ukanth.ufirewall.util.AppListArrayAdapter) ArrayAdapter(android.widget.ArrayAdapter) ActivityNotFoundException(android.content.ActivityNotFoundException) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 9 with PackageInfoData

use of dev.ukanth.ufirewall.Api.PackageInfoData in project afwall by ukanth.

the class MainActivity method selectAllRoam.

private void selectAllRoam(boolean flag) {
    if (this.listview == null) {
        this.listview = this.findViewById(R.id.listview);
    }
    ListAdapter adapter = listview.getAdapter();
    if (adapter != null) {
        int count = adapter.getCount(), item;
        for (item = 0; item < count; item++) {
            PackageInfoData data = (PackageInfoData) adapter.getItem(item);
            if (data.uid != Api.SPECIAL_UID_ANY) {
                data.selected_roam = flag;
            // addToQueue(data);
            }
            setDirty(true);
        }
        ((BaseAdapter) adapter).notifyDataSetChanged();
    }
}
Also used : PackageInfoData(dev.ukanth.ufirewall.Api.PackageInfoData) BaseAdapter(android.widget.BaseAdapter) ListAdapter(android.widget.ListAdapter)

Example 10 with PackageInfoData

use of dev.ukanth.ufirewall.Api.PackageInfoData in project afwall by ukanth.

the class MainActivity method selectAlltether.

private void selectAlltether(boolean flag) {
    if (this.listview == null) {
        this.listview = this.findViewById(R.id.listview);
    }
    ListAdapter adapter = listview.getAdapter();
    if (adapter != null) {
        int count = adapter.getCount(), item;
        for (item = 0; item < count; item++) {
            PackageInfoData data = (PackageInfoData) adapter.getItem(item);
            if (data.uid != Api.SPECIAL_UID_ANY) {
                data.selected_tether = flag;
            // addToQueue(data);
            }
            setDirty(true);
        }
        ((BaseAdapter) adapter).notifyDataSetChanged();
    }
}
Also used : PackageInfoData(dev.ukanth.ufirewall.Api.PackageInfoData) BaseAdapter(android.widget.BaseAdapter) ListAdapter(android.widget.ListAdapter)

Aggregations

PackageInfoData (dev.ukanth.ufirewall.Api.PackageInfoData)16 BaseAdapter (android.widget.BaseAdapter)11 ListAdapter (android.widget.ListAdapter)11 AppListArrayAdapter (dev.ukanth.ufirewall.util.AppListArrayAdapter)3 PackageComparator (dev.ukanth.ufirewall.util.PackageComparator)3 HashSet (java.util.HashSet)3 LinkedHashSet (java.util.LinkedHashSet)3 ActivityNotFoundException (android.content.ActivityNotFoundException)2 ArrayAdapter (android.widget.ArrayAdapter)2 ArrayList (java.util.ArrayList)2 SparseArray (android.util.SparseArray)1 HashMap (java.util.HashMap)1