@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); final Intent intent = getIntent(); final String action = intent.getAction(); if (LiveFolders.ACTION_CREATE_LIVE_FOLDER.equals(action)) { // Build the live folder intent. final Intent liveFolderIntent = new Intent(); liveFolderIntent.setData(CONTENT_URI); liveFolderIntent.putExtra(LiveFolders.EXTRA_LIVE_FOLDER_NAME, getString(R.string.live_folder_name)); liveFolderIntent.putExtra(LiveFolders.EXTRA_LIVE_FOLDER_ICON, Intent.ShortcutIconResource.fromContext(this, R.drawable.live_folder_notes)); liveFolderIntent.putExtra(LiveFolders.EXTRA_LIVE_FOLDER_DISPLAY_MODE, LiveFolders.DISPLAY_MODE_LIST); liveFolderIntent.putExtra(LiveFolders.EXTRA_LIVE_FOLDER_BASE_INTENT, new Intent(Intent.ACTION_EDIT, NOTE_URI)); // The result of this activity should be a live folder intent. setResult(RESULT_OK, liveFolderIntent); } else { setResult(RESULT_CANCELED); } finish(); }
LiveFolderAdapter(Launcher launcher, LiveFolderInfo info, Cursor cursor) { super(launcher, cursor, true); mIsList = info.displayMode == LiveFolders.DISPLAY_MODE_LIST; mInflater = LayoutInflater.from(launcher); mLauncher = launcher; mLauncher.startManagingCursor(getCursor()); }
@Override public View newView(Context context, Cursor cursor, ViewGroup parent) { View view; final ViewHolder holder = new ViewHolder(); if (!mIsList) { view = mInflater.inflate(R.layout.application_boxed, parent, false); } else { view = mInflater.inflate(R.layout.application_list, parent, false); holder.description = (TextView) view.findViewById(R.id.description); holder.icon = (ImageView) view.findViewById(R.id.icon); } holder.name = (TextView) view.findViewById(R.id.name); holder.idIndex = cursor.getColumnIndexOrThrow(BaseColumns._ID); holder.nameIndex = cursor.getColumnIndexOrThrow(LiveFolders.NAME); holder.descriptionIndex = cursor .getColumnIndex(LiveFolders.DESCRIPTION); holder.intentIndex = cursor.getColumnIndex(LiveFolders.INTENT); holder.iconBitmapIndex = cursor.getColumnIndex(LiveFolders.ICON_BITMAP); holder.iconResourceIndex = cursor .getColumnIndex(LiveFolders.ICON_RESOURCE); holder.iconPackageIndex = cursor .getColumnIndex(LiveFolders.ICON_PACKAGE); view.setTag(holder); return view; }
private static boolean isDisplayModeList(FolderInfo folderInfo) { return ((LiveFolderInfo) folderInfo).displayMode == LiveFolders.DISPLAY_MODE_LIST; }
static LiveFolderInfo addLiveFolder(Context context, Intent data, CellLayout.CellInfo cellInfo, boolean notify) { Intent baseIntent = data .getParcelableExtra(LiveFolders.EXTRA_LIVE_FOLDER_BASE_INTENT); String name = data.getStringExtra(LiveFolders.EXTRA_LIVE_FOLDER_NAME); Drawable icon = null; Intent.ShortcutIconResource iconResource = null; Parcelable extra = data .getParcelableExtra(LiveFolders.EXTRA_LIVE_FOLDER_ICON); if (extra != null && extra instanceof Intent.ShortcutIconResource) { try { iconResource = (Intent.ShortcutIconResource) extra; final PackageManager packageManager = context .getPackageManager(); Resources resources = packageManager .getResourcesForApplication(iconResource.packageName); final int id = resources.getIdentifier( iconResource.resourceName, null, null); icon = resources.getDrawable(id); } catch (Exception e) { Log.w(TAG, "Could not load live folder icon: " + extra); } } final LiveFolderInfo info = new LiveFolderInfo(); if (icon == null) { IconCache iconCache = ((LauncherApplication) context .getApplicationContext()).getIconCache(); info.icon = iconCache.getFolderLocalIcon(true); } else { info.icon = Utilities.createIconBitmap(icon, context); } info.title = name; info.iconResource = iconResource; info.uri = data.getData(); info.baseIntent = baseIntent; info.displayMode = data.getIntExtra( LiveFolders.EXTRA_LIVE_FOLDER_DISPLAY_MODE, LiveFolders.DISPLAY_MODE_GRID); LauncherModel.addItemToDatabase(context, info, Favorites.CONTAINER_DESKTOP, cellInfo.screen, cellInfo.cellX, cellInfo.cellY, notify); mFolders.put(info.id, info); return info; }
static Cursor query(Context context, LiveFolderInfo info) { return context.getContentResolver().query(info.uri, null, null, null, LiveFolders.NAME + " ASC"); }