Search in sources :

Example 1 with PackageInfoData

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

Example 2 with PackageInfoData

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;
}
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)

Aggregations

AppRule (org.ethack.orwall.lib.AppRule)2 PackageInfoData (org.ethack.orwall.lib.PackageInfoData)2 ApplicationInfo (android.content.pm.ApplicationInfo)1 PackageManager (android.content.pm.PackageManager)1 Bitmap (android.graphics.Bitmap)1 BitmapDrawable (android.graphics.drawable.BitmapDrawable)1 Drawable (android.graphics.drawable.Drawable)1 LayoutInflater (android.view.LayoutInflater)1 View (android.view.View)1 CheckBox (android.widget.CheckBox)1 ArrayList (java.util.ArrayList)1