List of usage examples for android.content.pm PackageManager getResourcesForApplication
public abstract Resources getResourcesForApplication(String appPackageName) throws NameNotFoundException;
From source file:com.ayogo.cordova.notification.ScheduledNotificationManager.java
public void showNotification(ScheduledNotification scheduledNotification) { LOG.v(NotificationPlugin.TAG, "showNotification: " + scheduledNotification.toString()); NotificationManager nManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); NotificationCompat.Builder builder = new NotificationCompat.Builder(context); // Build the notification options builder.setDefaults(Notification.DEFAULT_ALL).setTicker(scheduledNotification.body) .setPriority(Notification.PRIORITY_HIGH).setAutoCancel(true); // TODO: add sound support // if (scheduledNotification.sound != null) { // builder.setSound(sound); // }//from w ww . j a v a 2s. c om if (scheduledNotification.body != null) { builder.setContentTitle(scheduledNotification.title); builder.setContentText(scheduledNotification.body); builder.setStyle(new NotificationCompat.BigTextStyle().bigText(scheduledNotification.body)); } else { //Default the title to the app name try { PackageManager pm = context.getPackageManager(); ApplicationInfo applicationInfo = pm.getApplicationInfo(context.getPackageName(), PackageManager.GET_META_DATA); String appName = applicationInfo.loadLabel(pm).toString(); builder.setContentTitle(appName); builder.setContentText(scheduledNotification.title); builder.setStyle(new NotificationCompat.BigTextStyle().bigText(scheduledNotification.title)); } catch (NameNotFoundException e) { LOG.v(NotificationPlugin.TAG, "Failed to set title for notification!"); return; } } if (scheduledNotification.badge != null) { LOG.v(NotificationPlugin.TAG, "showNotification: has a badge!"); builder.setSmallIcon(getResIdForDrawable(scheduledNotification.badge)); } else { LOG.v(NotificationPlugin.TAG, "showNotification: has no badge, use app icon!"); try { PackageManager pm = context.getPackageManager(); ApplicationInfo applicationInfo = pm.getApplicationInfo(context.getPackageName(), PackageManager.GET_META_DATA); Resources resources = pm.getResourcesForApplication(applicationInfo); builder.setSmallIcon(applicationInfo.icon); } catch (NameNotFoundException e) { LOG.v(NotificationPlugin.TAG, "Failed to set badge for notification!"); return; } } if (scheduledNotification.icon != null) { LOG.v(NotificationPlugin.TAG, "showNotification: has an icon!"); builder.setLargeIcon(getIconFromUri(scheduledNotification.icon)); } else { LOG.v(NotificationPlugin.TAG, "showNotification: has no icon, use app icon!"); try { PackageManager pm = context.getPackageManager(); ApplicationInfo applicationInfo = pm.getApplicationInfo(context.getPackageName(), PackageManager.GET_META_DATA); Resources resources = pm.getResourcesForApplication(applicationInfo); Bitmap appIconBitmap = BitmapFactory.decodeResource(resources, applicationInfo.icon); builder.setLargeIcon(appIconBitmap); } catch (NameNotFoundException e) { LOG.v(NotificationPlugin.TAG, "Failed to set icon for notification!"); return; } } Intent launchIntent = context.getPackageManager().getLaunchIntentForPackage(context.getPackageName()); launchIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); launchIntent.setAction("notification"); PendingIntent contentIntent = PendingIntent.getActivity(context, 0, launchIntent, PendingIntent.FLAG_UPDATE_CURRENT); builder.setContentIntent(contentIntent); Notification notification = builder.build(); NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); LOG.v(NotificationPlugin.TAG, "notify!"); notificationManager.notify(scheduledNotification.tag.hashCode(), notification); }
From source file:com.DGSD.Teexter.UI.Recipient.BaseRecipientAdapter.java
private List<DirectorySearchParams> setupOtherDirectories(Cursor directoryCursor) { final PackageManager packageManager = mContext.getPackageManager(); final List<DirectorySearchParams> paramsList = new ArrayList<DirectorySearchParams>(); DirectorySearchParams preferredDirectory = null; while (directoryCursor.moveToNext()) { final long id = directoryCursor.getLong(DirectoryListQuery.ID); // Skip the local invisible directory, because the default directory already includes // all local results. if (id == Directory.LOCAL_INVISIBLE) { continue; }//from ww w .j av a 2 s . co m final DirectorySearchParams params = new DirectorySearchParams(); final String packageName = directoryCursor.getString(DirectoryListQuery.PACKAGE_NAME); final int resourceId = directoryCursor.getInt(DirectoryListQuery.TYPE_RESOURCE_ID); params.directoryId = id; params.displayName = directoryCursor.getString(DirectoryListQuery.DISPLAY_NAME); params.accountName = directoryCursor.getString(DirectoryListQuery.ACCOUNT_NAME); params.accountType = directoryCursor.getString(DirectoryListQuery.ACCOUNT_TYPE); if (packageName != null && resourceId != 0) { try { final Resources resources = packageManager.getResourcesForApplication(packageName); params.directoryType = resources.getString(resourceId); if (params.directoryType == null) { Log.e(TAG, "Cannot resolve directory name: " + resourceId + "@" + packageName); } } catch (NameNotFoundException e) { Log.e(TAG, "Cannot resolve directory name: " + resourceId + "@" + packageName, e); } } // If an account has been provided and we found a directory that // corresponds to that account, place that directory second, directly // underneath the local contacts. if (mAccount != null && mAccount.name.equals(params.accountName) && mAccount.type.equals(params.accountType)) { preferredDirectory = params; } else { paramsList.add(params); } } if (preferredDirectory != null) { paramsList.add(1, preferredDirectory); } return paramsList; }
From source file:com.androzic.Androzic.java
public void initializePlugins() { PackageManager packageManager = getPackageManager(); List<ResolveInfo> plugins; Intent initializationIntent = new Intent("com.androzic.plugins.action.INITIALIZE"); // enumerate initializable plugins plugins = packageManager.queryBroadcastReceivers(initializationIntent, 0); for (ResolveInfo plugin : plugins) { // send initialization broadcast, we send it directly instead of sending // one broadcast for all plugins to wake up stopped plugins: // http://developer.android.com/about/versions/android-3.1.html#launchcontrols Intent intent = new Intent(); intent.setClassName(plugin.activityInfo.packageName, plugin.activityInfo.name); intent.setAction(initializationIntent.getAction()); sendBroadcast(intent);// w w w . ja v a 2 s . com } // enumerate plugins with preferences plugins = packageManager.queryIntentActivities(new Intent("com.androzic.plugins.preferences"), 0); for (ResolveInfo plugin : plugins) { Intent intent = new Intent(); intent.setClassName(plugin.activityInfo.packageName, plugin.activityInfo.name); pluginPreferences.put(plugin.activityInfo.loadLabel(packageManager).toString(), intent); } // enumerate plugins with views plugins = packageManager.queryIntentActivities(new Intent("com.androzic.plugins.view"), 0); for (ResolveInfo plugin : plugins) { // get menu icon Drawable icon = null; try { Resources resources = packageManager .getResourcesForApplication(plugin.activityInfo.applicationInfo); int id = resources.getIdentifier("ic_menu_view", "drawable", plugin.activityInfo.packageName); if (id != 0) icon = resources.getDrawable(id); } catch (Resources.NotFoundException e) { e.printStackTrace(); } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } Intent intent = new Intent(); intent.setClassName(plugin.activityInfo.packageName, plugin.activityInfo.name); Pair<Drawable, Intent> pair = new Pair<>(icon, intent); pluginViews.put(plugin.activityInfo.loadLabel(packageManager).toString(), pair); } }
From source file:org.openintents.notepad.NoteEditor.java
private boolean setRemoteStyle(String styleName, int size) { if (TextUtils.isEmpty(styleName)) { if (DEBUG) { Log.e(TAG, "Empty style name: " + styleName); }/*from w ww.j a v a 2s .c o m*/ return false; } PackageManager pm = getPackageManager(); String packageName = ThemeUtils.getPackageNameFromStyle(styleName); if (packageName == null) { Log.e(TAG, "Invalid style name: " + styleName); return false; } Context c = null; try { c = createPackageContext(packageName, 0); } catch (NameNotFoundException e) { Log.e(TAG, "Package for style not found: " + packageName + ", " + styleName); return false; } Resources res = c.getResources(); int themeid = res.getIdentifier(styleName, null, null); if (DEBUG) { Log.d(TAG, "Retrieving theme: " + styleName + ", " + themeid); } if (themeid == 0) { Log.e(TAG, "Theme name not found: " + styleName); return false; } try { ThemeAttributes ta = new ThemeAttributes(c, packageName, themeid); mTextTypeface = ta.getString(ThemeNotepad.TEXT_TYPEFACE); if (DEBUG) { Log.d(TAG, "textTypeface: " + mTextTypeface); } mCurrentTypeface = null; // Look for special cases: if ("monospace".equals(mTextTypeface)) { mCurrentTypeface = Typeface.create(Typeface.MONOSPACE, Typeface.NORMAL); } else if ("sans".equals(mTextTypeface)) { mCurrentTypeface = Typeface.create(Typeface.SANS_SERIF, Typeface.NORMAL); } else if ("serif".equals(mTextTypeface)) { mCurrentTypeface = Typeface.create(Typeface.SERIF, Typeface.NORMAL); } else if (!TextUtils.isEmpty(mTextTypeface)) { try { if (DEBUG) { Log.d(TAG, "Reading typeface: package: " + packageName + ", typeface: " + mTextTypeface); } Resources remoteRes = pm.getResourcesForApplication(packageName); mCurrentTypeface = Typeface.createFromAsset(remoteRes.getAssets(), mTextTypeface); if (DEBUG) { Log.d(TAG, "Result: " + mCurrentTypeface); } } catch (NameNotFoundException e) { Log.e(TAG, "Package not found for Typeface", e); } } mTextUpperCaseFont = ta.getBoolean(ThemeNotepad.TEXT_UPPER_CASE_FONT, false); mTextColor = ta.getColor(ThemeNotepad.TEXT_COLOR, android.R.color.white); if (DEBUG) { Log.d(TAG, "textColor: " + mTextColor); } if (size == 0) { mTextSize = getTextSizeTiny(ta); } else if (size == 1) { mTextSize = getTextSizeSmall(ta); } else if (size == 2) { mTextSize = getTextSizeMedium(ta); } else { mTextSize = getTextSizeLarge(ta); } if (DEBUG) { Log.d(TAG, "textSize: " + mTextSize); } if (mText != null) { mBackgroundPadding = ta.getDimensionPixelOffset(ThemeNotepad.BACKGROUND_PADDING, -1); int backgroundPaddingLeft = ta.getDimensionPixelOffset(ThemeNotepad.BACKGROUND_PADDING_LEFT, mBackgroundPadding); int backgroundPaddingTop = ta.getDimensionPixelOffset(ThemeNotepad.BACKGROUND_PADDING_TOP, mBackgroundPadding); int backgroundPaddingRight = ta.getDimensionPixelOffset(ThemeNotepad.BACKGROUND_PADDING_RIGHT, mBackgroundPadding); int backgroundPaddingBottom = ta.getDimensionPixelOffset(ThemeNotepad.BACKGROUND_PADDING_BOTTOM, mBackgroundPadding); if (DEBUG) { Log.d(TAG, "Padding: " + mBackgroundPadding + "; " + backgroundPaddingLeft + "; " + backgroundPaddingTop + "; " + backgroundPaddingRight + "; " + backgroundPaddingBottom + "; "); } try { Resources remoteRes = pm.getResourcesForApplication(packageName); int resid = ta.getResourceId(ThemeNotepad.BACKGROUND, 0); if (resid != 0) { Drawable d = remoteRes.getDrawable(resid); mText.setBackgroundDrawable(d); } else { // remove background mText.setBackgroundResource(0); } } catch (NameNotFoundException e) { Log.e(TAG, "Package not found for Theme background.", e); } catch (Resources.NotFoundException e) { Log.e(TAG, "Resource not found for Theme background.", e); } // Apply padding if (mBackgroundPadding >= 0 || backgroundPaddingLeft >= 0 || backgroundPaddingTop >= 0 || backgroundPaddingRight >= 0 || backgroundPaddingBottom >= 0) { mText.setPadding(backgroundPaddingLeft, backgroundPaddingTop, backgroundPaddingRight, backgroundPaddingBottom); } else { // 9-patches do the padding automatically // todo clear padding } } mLinesMode = ta.getInteger(ThemeNotepad.LINE_MODE, 2); mLinesColor = ta.getColor(ThemeNotepad.LINE_COLOR, 0xFF000080); if (DEBUG) { Log.d(TAG, "line color: " + mLinesColor); } return true; } catch (UnsupportedOperationException e) { // This exception is thrown e.g. if one attempts // to read an integer attribute as dimension. Log.e(TAG, "UnsupportedOperationException", e); return false; } catch (NumberFormatException e) { // This exception is thrown e.g. if one attempts // to read a string as integer. Log.e(TAG, "NumberFormatException", e); return false; } }
From source file:com.cognizant.trumobi.PersonaLauncher.java
static PersonaLiveFolderInfo addLiveFolder(Context context, Intent data, PersonaCellLayout.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;// ww w . ja v a 2 s . com boolean filtered = false; 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) { PersonaLog.w(LOG_TAG, "Could not load live folder icon: " + extra); } } if (icon == null) { icon = context.getResources().getDrawable(R.drawable.pr_ic_launcher_folder); } final PersonaLiveFolderInfo info = new PersonaLiveFolderInfo(); info.icon = icon; info.filtered = filtered; 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); PersonaLauncherModel.addItemToDatabase(context, info, PersonaLauncherSettings.Favorites.CONTAINER_DESKTOP, cellInfo.screen, cellInfo.cellX, cellInfo.cellY, notify); sModel.addFolder(info); return info; }
From source file:com.cognizant.trumobi.PersonaLauncher.java
private static PersonaApplicationInfo infoFromShortcutIntent(Context context, Intent data) { Intent intent = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_INTENT); String name = data.getStringExtra(Intent.EXTRA_SHORTCUT_NAME); Bitmap bitmap = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON); Drawable icon = null;/*w w w .ja v a 2 s .com*/ boolean filtered = false; boolean customIcon = false; ShortcutIconResource iconResource = null; if (bitmap != null) { icon = new PersonaFastBitmapDrawable(PersonaUtilities.createBitmapThumbnail(bitmap, context)); filtered = true; customIcon = true; } else { Parcelable extra = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE); if (extra != null && extra instanceof ShortcutIconResource) { try { iconResource = (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) { PersonaLog.w(LOG_TAG, "Could not load shortcut icon: " + extra); } } } if (icon == null) { icon = context.getPackageManager().getDefaultActivityIcon(); } final PersonaApplicationInfo info = new PersonaApplicationInfo(); info.icon = icon; info.filtered = filtered; info.title = name; info.intent = intent; info.customIcon = customIcon; info.iconResource = iconResource; return info; }
From source file:com.cognizant.trumobi.PersonaLauncher.java
private void completeEditShirtcut(Intent data) { if (!data.hasExtra(PersonaCustomShirtcutActivity.EXTRA_APPLICATIONINFO)) return;/*from w w w .j ava 2 s .com*/ long appInfoId = data.getLongExtra(PersonaCustomShirtcutActivity.EXTRA_APPLICATIONINFO, 0); PersonaApplicationInfo info = PersonaLauncherModel.loadApplicationInfoById(this, appInfoId); if (info != null) { Bitmap bitmap = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON); Drawable icon = null; boolean customIcon = false; ShortcutIconResource iconResource = null; if (bitmap != null) { icon = new PersonaFastBitmapDrawable(PersonaUtilities.createBitmapThumbnail(bitmap, this)); customIcon = true; } else { Parcelable extra = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE); if (extra != null && extra instanceof ShortcutIconResource) { try { iconResource = (ShortcutIconResource) extra; final PackageManager packageManager = getPackageManager(); Resources resources = packageManager.getResourcesForApplication(iconResource.packageName); final int id = resources.getIdentifier(iconResource.resourceName, null, null); icon = resources.getDrawable(id); } catch (Exception e) { PersonaLog.w(LOG_TAG, "Could not load shortcut icon: " + extra); } } } if (icon != null) { info.icon = icon; info.customIcon = customIcon; info.iconResource = iconResource; } info.itemType = PersonaLauncherSettings.Favorites.ITEM_TYPE_SHORTCUT; info.title = data.getStringExtra(Intent.EXTRA_SHORTCUT_NAME); info.intent = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_INTENT); PersonaLauncherModel.updateItemInDatabase(this, info); if (info.container == PersonaLauncherSettings.Favorites.CONTAINER_MAB) mHandleView.UpdateLaunchInfo(info); else if (info.container == PersonaLauncherSettings.Favorites.CONTAINER_LAB) mLAB.UpdateLaunchInfo(info); else if (info.container == PersonaLauncherSettings.Favorites.CONTAINER_LAB2) mLAB2.UpdateLaunchInfo(info); else if (info.container == PersonaLauncherSettings.Favorites.CONTAINER_RAB) mRAB.UpdateLaunchInfo(info); else if (info.container == PersonaLauncherSettings.Favorites.CONTAINER_RAB2) mRAB2.UpdateLaunchInfo(info); mWorkspace.updateShortcutFromApplicationInfo(info); } }
From source file:com.cognizant.trumobi.PersonaLauncher.java
/** * Finds all the views we need and configure them properly. *//*from ww w . j a v a2 s. com*/ private void setupViews() { //CERTIFICATE layout = (LinearLayout) findViewById(R.id.launcher_parent_layout); /* if(!PersonaMainActivity.isRovaPoliciesOn) layout.setBackgroundResource(R.drawable.pr_bg);*/ mDragLayer = (PersonaDragLayer) findViewById(R.id.drag_layer); final PersonaDragLayer personaDragLayer = mDragLayer; mWorkspace = (PersonaWorkspace) personaDragLayer.findViewById(R.id.workspace); final PersonaWorkspace personaWorkspace = mWorkspace; // ADW: The app drawer is now a ViewStub and we load the resource // depending on custom settings ViewStub tmp = (ViewStub) personaDragLayer.findViewById(R.id.stub_drawer); int drawerStyle = PersonaAlmostNexusSettingsHelper.getDrawerStyle(this); tmp.setLayoutResource(mDrawerStyles[drawerStyle]); mAllAppsGrid = (PersonaDrawer) tmp.inflate(); mDeleteZone = (PersonaDeleteZone) personaDragLayer.findViewById(R.id.delete_zone); mHandleView = (PersonaActionButton) personaDragLayer.findViewById(R.id.btn_mab); mHandleView.setFocusable(true); mHandleView.setLauncher(this); mHandleView.setOnClickListener(this); personaDragLayer.addDragListener(mHandleView); /* * mHandleView.setOnTriggerListener(new OnTriggerListener() { public * void onTrigger(View v, int whichHandle) { mDockBar.open(); } public * void onGrabbedStateChange(View v, boolean grabbedState) { } public * void onClick(View v) { if (allAppsOpen) { closeAllApps(true); } else * { showAllApps(true, null); } } }); */ mAllAppsGrid.setTextFilterEnabled(false); mAllAppsGrid.setDragger(personaDragLayer); mAllAppsGrid.setLauncher(this); personaWorkspace.setOnLongClickListener(this); personaWorkspace.setDragger(personaDragLayer); personaWorkspace.setLauncher(this); mDeleteZone.setLauncher(this); mDeleteZone.setDragController(personaDragLayer); personaDragLayer.setIgnoredDropTarget((View) mAllAppsGrid); personaDragLayer.setDragScoller(personaWorkspace); personaDragLayer.addDragListener(mDeleteZone); // ADW: Dockbar inner icon viewgroup (PersonaMiniLauncher.java) mMiniLauncher = (PersonaMiniLauncher) personaDragLayer.findViewById(R.id.mini_content); mMiniLauncher.setLauncher(this); mMiniLauncher.setOnLongClickListener(this); mMiniLauncher.setDragger(personaDragLayer); personaDragLayer.addDragListener(mMiniLauncher); // ADW: Action Buttons (LAB/RAB) mLAB = (PersonaActionButton) personaDragLayer.findViewById(R.id.btn_lab); PersonaLog.d("personalauncher", "lab rab componenets initialized"); mLAB.setLauncher(this); mLAB.setSpecialIcon(R.drawable.pr_arrow_left); mLAB.setSpecialAction(ACTION_CATALOG_PREV); personaDragLayer.addDragListener(mLAB); mRAB = (PersonaActionButton) personaDragLayer.findViewById(R.id.btn_rab); mRAB.setLauncher(this); mRAB.setSpecialIcon(R.drawable.pr_arrow_right); mRAB.setSpecialAction(ACTION_CATALOG_NEXT); personaDragLayer.addDragListener(mRAB); mLAB.setOnClickListener(this); mRAB.setOnClickListener(this); // ADW: secondary aActionButtons mLAB2 = (PersonaActionButton) personaDragLayer.findViewById(R.id.btn_lab2); mLAB2.setLauncher(this); personaDragLayer.addDragListener(mLAB2); mRAB2 = (PersonaActionButton) personaDragLayer.findViewById(R.id.btn_rab2); mRAB2.setLauncher(this); personaDragLayer.addDragListener(mRAB2); mLAB2.setOnClickListener(this); mRAB2.setOnClickListener(this); // ADW: Dots ImageViews mPreviousView = (ImageView) findViewById(R.id.btn_scroll_left); mNextView = (ImageView) findViewById(R.id.btn_scroll_right); mPreviousView.setOnLongClickListener(this); mNextView.setOnLongClickListener(this); // ADW: ActionButtons swipe gestures mHandleView.setSwipeListener(this); mLAB.setSwipeListener(this); mLAB2.setSwipeListener(this); mRAB.setSwipeListener(this); mRAB2.setSwipeListener(this); // mHandleView.setDragger(dragLayer); // mLAB.setDragger(dragLayer); // mRAB.setDragger(dragLayer); mRAB2.setDragger(personaDragLayer); mLAB2.setDragger(personaDragLayer); // ADW linearlayout with apptray, lab and rab mDrawerToolbar = findViewById(R.id.drawer_toolbar); mHandleView.setNextFocusUpId(R.id.drag_layer); mHandleView.setNextFocusLeftId(R.id.drag_layer); mLAB.setNextFocusUpId(R.id.drag_layer); mLAB.setNextFocusLeftId(R.id.drag_layer); mRAB.setNextFocusUpId(R.id.drag_layer); mRAB.setNextFocusLeftId(R.id.drag_layer); mLAB2.setNextFocusUpId(R.id.drag_layer); mLAB2.setNextFocusLeftId(R.id.drag_layer); mRAB2.setNextFocusUpId(R.id.drag_layer); mRAB2.setNextFocusLeftId(R.id.drag_layer); // ADW add a listener to the dockbar to show/hide the app-drawer-button // and the dots mDockBar = (PersonaDockBar) findViewById(R.id.dockbar); mDockBar.setDockBarListener(new DockBarListener() { public void onOpen() { mDrawerToolbar.setVisibility(View.GONE); if (mNextView.getVisibility() == View.VISIBLE) { mNextView.setVisibility(View.INVISIBLE); mPreviousView.setVisibility(View.INVISIBLE); } } public void onClose() { if (mDockStyle != DOCK_STYLE_NONE) mDrawerToolbar.setVisibility(View.VISIBLE); if (showDots && !isAllAppsVisible()) { mNextView.setVisibility(View.VISIBLE); mPreviousView.setVisibility(View.VISIBLE); } } }); if (PersonaAlmostNexusSettingsHelper.getDesktopIndicator(this)) { mDesktopIndicator = (PersonaDesktopIndicator) (findViewById(R.id.desktop_indicator)); } // ADW: Add focusability to screen items mLAB.setFocusable(true); mRAB.setFocusable(true); mLAB2.setFocusable(true); mRAB2.setFocusable(true); mPreviousView.setFocusable(true); mNextView.setFocusable(true); // ADW: Load the specified theme String themePackage = PersonaAlmostNexusSettingsHelper.getThemePackageName(this, THEME_DEFAULT); PackageManager pm = getPackageManager(); Resources themeResources = null; if (!themePackage.equals(THEME_DEFAULT)) { try { themeResources = pm.getResourcesForApplication(themePackage); } catch (NameNotFoundException e) { // ADW The saved theme was uninstalled so we save the default // one PersonaAlmostNexusSettingsHelper.setThemePackageName(this, PersonaLauncher.THEME_DEFAULT); } } if (themeResources != null) { // Action Buttons loadThemeResource(themeResources, themePackage, "lab_bg", mLAB, THEME_ITEM_BACKGROUND); loadThemeResource(themeResources, themePackage, "rab_bg", mRAB, THEME_ITEM_BACKGROUND); loadThemeResource(themeResources, themePackage, "lab2_bg", mLAB2, THEME_ITEM_BACKGROUND); loadThemeResource(themeResources, themePackage, "rab2_bg", mRAB2, THEME_ITEM_BACKGROUND); loadThemeResource(themeResources, themePackage, "mab_bg", mHandleView, THEME_ITEM_BACKGROUND); // App drawer button // loadThemeResource(themeResources,themePackage,"handle_icon",mHandleView,THEME_ITEM_FOREGROUND); // View appsBg=findViewById(R.id.appsBg); // loadThemeResource(themeResources,themePackage,"handle",appsBg,THEME_ITEM_BACKGROUND); // Deletezone loadThemeResource(themeResources, themePackage, "ic_delete", mDeleteZone, THEME_ITEM_FOREGROUND); loadThemeResource(themeResources, themePackage, "delete_zone_selector", mDeleteZone, THEME_ITEM_BACKGROUND); loadThemeResource(themeResources, themePackage, "home_arrows_left", mPreviousView, THEME_ITEM_FOREGROUND); loadThemeResource(themeResources, themePackage, "home_arrows_right", mNextView, THEME_ITEM_FOREGROUND); // Dockbar loadThemeResource(themeResources, themePackage, "dockbar_bg", mMiniLauncher, THEME_ITEM_BACKGROUND); try { themeFont = Typeface.createFromAsset(themeResources.getAssets(), "themefont.ttf"); } catch (RuntimeException e) { // TODO: handle exception } } Drawable previous = mPreviousView.getDrawable(); Drawable next = mNextView.getDrawable(); mWorkspace.setIndicators(previous, next); // ADW: EOF Themes updateAlmostNexusUI(); }
From source file:g7.bluesky.launcher3.Launcher.java
public void loadIconPack(List<ShortcutInfo> shortcuts) { //theming vars----------------------------------------------- PackageManager pm = getPackageManager(); final int ICONSIZE = Tools.numtodp(128, Launcher.this); Resources themeRes = null;//from w ww .ja va2 s .c om String resPacName = defaultSharedPref.getString(SettingConstants.ICON_THEME_PREF_KEY, ""); String iconResource = null; int intres = 0; int intresiconback = 0; int intresiconfront = 0; int intresiconmask = 0; float scaleFactor = 1.0f; Paint p = new Paint(Paint.FILTER_BITMAP_FLAG); p.setAntiAlias(true); Paint origP = new Paint(Paint.FILTER_BITMAP_FLAG); origP.setAntiAlias(true); Paint maskp = new Paint(Paint.FILTER_BITMAP_FLAG); maskp.setAntiAlias(true); maskp.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_OUT)); if (resPacName.compareTo("") != 0) { try { themeRes = pm.getResourcesForApplication(resPacName); } catch (Exception e) { } ; if (themeRes != null) { String[] backAndMaskAndFront = ThemeTools.getIconBackAndMaskResourceName(themeRes, resPacName); if (backAndMaskAndFront[0] != null) intresiconback = themeRes.getIdentifier(backAndMaskAndFront[0], "drawable", resPacName); if (backAndMaskAndFront[1] != null) intresiconmask = themeRes.getIdentifier(backAndMaskAndFront[1], "drawable", resPacName); if (backAndMaskAndFront[2] != null) intresiconfront = themeRes.getIdentifier(backAndMaskAndFront[2], "drawable", resPacName); } } BitmapFactory.Options uniformOptions = new BitmapFactory.Options(); uniformOptions.inScaled = false; uniformOptions.inDither = false; uniformOptions.inPreferredConfig = Bitmap.Config.ARGB_8888; Canvas origCanv; Canvas canvas; scaleFactor = ThemeTools.getScaleFactor(themeRes, resPacName); Bitmap back = null; Bitmap mask = null; Bitmap front = null; Bitmap scaledBitmap = null; Bitmap scaledOrig = null; Bitmap orig = null; if (resPacName.compareTo("") != 0 && themeRes != null) { try { if (intresiconback != 0) back = BitmapFactory.decodeResource(themeRes, intresiconback, uniformOptions); } catch (Exception e) { } try { if (intresiconmask != 0) mask = BitmapFactory.decodeResource(themeRes, intresiconmask, uniformOptions); } catch (Exception e) { } try { if (intresiconfront != 0) front = BitmapFactory.decodeResource(themeRes, intresiconfront, uniformOptions); } catch (Exception e) { } } //theming vars----------------------------------------------- BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = false; options.inPreferredConfig = Bitmap.Config.RGB_565; options.inDither = true; for (int i = 0; i < shortcuts.size(); i++) { if (themeRes != null) { iconResource = null; intres = 0; iconResource = ThemeTools.getResourceName(themeRes, resPacName, shortcuts.get(i).getTargetComponent().toString()); if (iconResource != null) { intres = themeRes.getIdentifier(iconResource, "drawable", resPacName); } if (intres != 0) {//has single drawable for app shortcuts.get(i).setIcon(BitmapFactory.decodeResource(themeRes, intres, uniformOptions)); } else { Drawable drawable = Utilities.createIconDrawable(shortcuts.get(i).getIcon(mIconCache)); orig = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888); drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight()); drawable.draw(new Canvas(orig)); scaledOrig = Bitmap.createBitmap(ICONSIZE, ICONSIZE, Bitmap.Config.ARGB_8888); scaledBitmap = Bitmap.createBitmap(ICONSIZE, ICONSIZE, Bitmap.Config.ARGB_8888); canvas = new Canvas(scaledBitmap); if (back != null) { canvas.drawBitmap(back, Tools.getResizedMatrix(back, ICONSIZE, ICONSIZE), p); } origCanv = new Canvas(scaledOrig); orig = Tools.getResizedBitmap(orig, ((int) (ICONSIZE * scaleFactor)), ((int) (ICONSIZE * scaleFactor))); origCanv.drawBitmap(orig, scaledOrig.getWidth() - (orig.getWidth() / 2) - scaledOrig.getWidth() / 2, scaledOrig.getWidth() - (orig.getWidth() / 2) - scaledOrig.getWidth() / 2, origP); if (mask != null) { origCanv.drawBitmap(mask, Tools.getResizedMatrix(mask, ICONSIZE, ICONSIZE), maskp); } if (back != null) { canvas.drawBitmap(Tools.getResizedBitmap(scaledOrig, ICONSIZE, ICONSIZE), 0, 0, p); } else canvas.drawBitmap(Tools.getResizedBitmap(scaledOrig, ICONSIZE, ICONSIZE), 0, 0, p); if (front != null) canvas.drawBitmap(front, Tools.getResizedMatrix(front, ICONSIZE, ICONSIZE), p); shortcuts.get(i).setIcon(scaledBitmap); } } } }
From source file:g7.bluesky.launcher3.Launcher.java
public void loadIconPack() { //theming vars----------------------------------------------- PackageManager pm = getPackageManager(); final int ICONSIZE = Tools.numtodp(64, Launcher.this); Resources themeRes = null;//from ww w . j a v a 2s. co m String resPacName = defaultSharedPref.getString(SettingConstants.ICON_THEME_PREF_KEY, ""); String iconResource = null; int intres = 0; int intresiconback = 0; int intresiconfront = 0; int intresiconmask = 0; float scaleFactor = 1.0f; Paint p = new Paint(Paint.FILTER_BITMAP_FLAG); p.setAntiAlias(true); Paint origP = new Paint(Paint.FILTER_BITMAP_FLAG); origP.setAntiAlias(true); Paint maskp = new Paint(Paint.FILTER_BITMAP_FLAG); maskp.setAntiAlias(true); maskp.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_OUT)); if (resPacName.compareTo("") != 0) { try { themeRes = pm.getResourcesForApplication(resPacName); } catch (Exception e) { } ; if (themeRes != null) { String[] backAndMaskAndFront = ThemeTools.getIconBackAndMaskResourceName(themeRes, resPacName); if (backAndMaskAndFront[0] != null) intresiconback = themeRes.getIdentifier(backAndMaskAndFront[0], "drawable", resPacName); if (backAndMaskAndFront[1] != null) intresiconmask = themeRes.getIdentifier(backAndMaskAndFront[1], "drawable", resPacName); if (backAndMaskAndFront[2] != null) intresiconfront = themeRes.getIdentifier(backAndMaskAndFront[2], "drawable", resPacName); } } BitmapFactory.Options uniformOptions = new BitmapFactory.Options(); uniformOptions.inScaled = false; uniformOptions.inDither = false; uniformOptions.inPreferredConfig = Bitmap.Config.ARGB_8888; Canvas origCanv; Canvas canvas; scaleFactor = ThemeTools.getScaleFactor(themeRes, resPacName); Bitmap back = null; Bitmap mask = null; Bitmap front = null; Bitmap scaledBitmap = null; Bitmap scaledOrig = null; Bitmap orig = null; if (resPacName.compareTo("") != 0 && themeRes != null) { try { if (intresiconback != 0) back = BitmapFactory.decodeResource(themeRes, intresiconback, uniformOptions); } catch (Exception e) { } try { if (intresiconmask != 0) mask = BitmapFactory.decodeResource(themeRes, intresiconmask, uniformOptions); } catch (Exception e) { } try { if (intresiconfront != 0) front = BitmapFactory.decodeResource(themeRes, intresiconfront, uniformOptions); } catch (Exception e) { } } //theming vars----------------------------------------------- BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = false; options.inPreferredConfig = Bitmap.Config.RGB_565; options.inDither = true; for (int i = 0; i < listApps.size(); i++) { if (themeRes != null) { iconResource = null; intres = 0; iconResource = ThemeTools.getResourceName(themeRes, resPacName, listApps.get(i).getComponentName().toString()); if (iconResource != null) { intres = themeRes.getIdentifier(iconResource, "drawable", resPacName); } if (intres != 0) {//has single drawable for app listApps.get(i).setIconBitmap(BitmapFactory.decodeResource(themeRes, intres, uniformOptions)); } else { Drawable drawable = listApps.get(i).getIconDrawable(); if (drawable == null) { drawable = Utilities.createIconDrawable(listApps.get(i).getIconBitmap()); } orig = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888); drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight()); drawable.draw(new Canvas(orig)); scaledOrig = Bitmap.createBitmap(ICONSIZE, ICONSIZE, Bitmap.Config.ARGB_8888); scaledBitmap = Bitmap.createBitmap(ICONSIZE, ICONSIZE, Bitmap.Config.ARGB_8888); canvas = new Canvas(scaledBitmap); if (back != null) { canvas.drawBitmap(back, Tools.getResizedMatrix(back, ICONSIZE, ICONSIZE), p); } origCanv = new Canvas(scaledOrig); orig = Tools.getResizedBitmap(orig, ((int) (ICONSIZE * scaleFactor)), ((int) (ICONSIZE * scaleFactor))); origCanv.drawBitmap(orig, scaledOrig.getWidth() - (orig.getWidth() / 2) - scaledOrig.getWidth() / 2, scaledOrig.getWidth() - (orig.getWidth() / 2) - scaledOrig.getWidth() / 2, origP); if (mask != null) { origCanv.drawBitmap(mask, Tools.getResizedMatrix(mask, ICONSIZE, ICONSIZE), maskp); } if (back != null) { canvas.drawBitmap(Tools.getResizedBitmap(scaledOrig, ICONSIZE, ICONSIZE), 0, 0, p); } else canvas.drawBitmap(Tools.getResizedBitmap(scaledOrig, ICONSIZE, ICONSIZE), 0, 0, p); if (front != null) canvas.drawBitmap(front, Tools.getResizedMatrix(front, ICONSIZE, ICONSIZE), p); listApps.get(i).setIconBitmap(scaledBitmap); } } } }