/** * Returns a miniature-sized icon associated with the category These icons are used for the map * overlays and dialog windows. * * @param category The top-level category * @return If no icon is found, return the default Android icon. otherwise, return the appropriate * category icon. */ public static Integer getIcon(String category, Context context) { SQLiteDatabase db = new FINDatabase(context).getReadableDatabase(); Cursor cursor = db.query("categories", null, "full_name = '" + category + "'", null, null, null, null); cursor.moveToFirst(); int parent = cursor.getInt(cursor.getColumnIndex("parent")); if (parent != 0) { cursor = db.query("categories", null, "cat_id = " + parent, null, null, null, null); cursor.moveToFirst(); category = cursor.getString(cursor.getColumnIndex("full_name")); } cursor.close(); db.close(); if (!category.equals("")) { int icon = context .getResources() .getIdentifier( "drawable/" + FINUtil.sendCategory(category, context), null, context.getPackageName()); if (icon != 0) { return icon; } } return R.drawable.android; }
/** * Returns a map from categories to icons (icons must be the same lower-case string as the * category) Populates the HashMap with both small icons and bigger icons. Key for small icons: * "<category>" Key for big icons: "<category>-big" */ public HashMap<String, Integer> createIconsMap(ArrayList<String> categories) { HashMap<String, Integer> iconsMap = new HashMap<String, Integer>(); // Loop over each category and map it to the icon file associated with it for (String str : categories) { iconsMap.put( str, getResources() .getIdentifier( "drawable/" + FINUtil.sendCategory(str, getBaseContext()), null, getPackageName())); iconsMap.put( str + "-big", getResources() .getIdentifier( "drawable/" + FINUtil.sendCategory(str, getBaseContext()) + "_big", null, getPackageName())); } return iconsMap; }