use of org.ethack.orwall.lib.PackageInfoData in project orWall by EthACKdotOrg.
the class AppFragment method listSpecialApps.
private List<AppRule> listSpecialApps(LongSparseArray<AppRule> index) {
List<AppRule> pkgList = new ArrayList<>();
Map<String, PackageInfoData> specialApps = PackageInfoData.specialApps();
for (PackageInfoData pkgInfo : specialApps.values()) {
if (index.indexOfKey(pkgInfo.getUid()) < 0) {
AppRule app = new AppRule(false, pkgInfo.getPkgName(), pkgInfo.getUid(), Constants.DB_ONION_TYPE_NONE, false, false);
app.setAppName(pkgInfo.getName());
pkgList.add(app);
}
}
return pkgList;
}
use of org.ethack.orwall.lib.PackageInfoData 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;
}
Aggregations