use of dev.ukanth.ufirewall.util.PackageComparator in project afwall by ukanth.
the class MainActivity method filterApps.
/**
* Filter application based on app tpe
*
* @param i
*/
private void filterApps(int i) {
Set<PackageInfoData> returnList = new HashSet<>();
List<PackageInfoData> inputList;
List<PackageInfoData> allApps = Api.getApps(getApplicationContext(), null);
if (i >= 0) {
for (PackageInfoData infoData : allApps) {
if (infoData != null) {
if (infoData.appType == i) {
returnList.add(infoData);
}
}
}
inputList = new ArrayList<>(returnList);
} else {
inputList = allApps;
}
try {
Collections.sort(inputList, new PackageComparator());
} catch (Exception e) {
Log.d(Api.TAG, "Exception in filter Sorting");
}
ArrayAdapter appAdapter;
if (selectedColumns <= DEFAULT_VIEW_LIMIT) {
appAdapter = new AppListArrayAdapter(this, getApplicationContext(), inputList, true);
} else {
appAdapter = new AppListArrayAdapter(this, getApplicationContext(), inputList);
}
this.listview.setAdapter(appAdapter);
appAdapter.notifyDataSetChanged();
// restore
this.listview.setSelectionFromTop(index, top);
}
use of dev.ukanth.ufirewall.util.PackageComparator 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);
}
use of dev.ukanth.ufirewall.util.PackageComparator 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");
}
}
Aggregations