List of usage examples for android.content.res Resources getDrawable
@Deprecated public Drawable getDrawable(@DrawableRes int id) throws NotFoundException
From source file:com.android.launcher3.CellLayout.java
public CellLayout(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); // A ViewGroup usually does not draw, but CellLayout needs to draw a rectangle to show // the user where a dragged item will land when dropped. setWillNotDraw(false);//from w w w .j a v a2 s . c om setClipToPadding(false); mLauncher = (Launcher) context; DeviceProfile grid = mLauncher.getDeviceProfile(); mCellWidth = mCellHeight = -1; mFixedCellWidth = mFixedCellHeight = -1; mWidthGap = mOriginalWidthGap = 0; mHeightGap = mOriginalHeightGap = 0; mMaxGap = Integer.MAX_VALUE; mCountX = (int) grid.inv.numColumns; mCountY = (int) grid.inv.numRows; mOccupied = new boolean[mCountX][mCountY]; mTmpOccupied = new boolean[mCountX][mCountY]; mPreviousReorderDirection[0] = INVALID_DIRECTION; mPreviousReorderDirection[1] = INVALID_DIRECTION; setAlwaysDrawnWithCacheEnabled(false); final Resources res = getResources(); mHotseatScale = (float) grid.hotseatIconSizePx / grid.iconSizePx; mBackground = (TransitionDrawable) res.getDrawable(R.drawable.bg_screenpanel); mBackground.setCallback(this); mBackground.setAlpha((int) (mBackgroundAlpha * 255)); mReorderPreviewAnimationMagnitude = (REORDER_PREVIEW_MAGNITUDE * grid.iconSizePx); // Initialize the data structures used for the drag visualization. mEaseOutInterpolator = new DecelerateInterpolator(2.5f); // Quint ease out mDragCell[0] = mDragCell[1] = -1; for (int i = 0; i < mDragOutlines.length; i++) { mDragOutlines[i] = new Rect(-1, -1, -1, -1); } // When dragging things around the home screens, we show a green outline of // where the item will land. The outlines gradually fade out, leaving a trail // behind the drag path. // Set up all the animations that are used to implement this fading. final int duration = res.getInteger(R.integer.config_dragOutlineFadeTime); final float fromAlphaValue = 0; final float toAlphaValue = (float) res.getInteger(R.integer.config_dragOutlineMaxAlpha); Arrays.fill(mDragOutlineAlphas, fromAlphaValue); for (int i = 0; i < mDragOutlineAnims.length; i++) { final InterruptibleInOutAnimator anim = new InterruptibleInOutAnimator(this, duration, fromAlphaValue, toAlphaValue); anim.getAnimator().setInterpolator(mEaseOutInterpolator); final int thisIndex = i; anim.getAnimator().addUpdateListener(new AnimatorUpdateListener() { public void onAnimationUpdate(ValueAnimator animation) { final Bitmap outline = (Bitmap) anim.getTag(); // If an animation is started and then stopped very quickly, we can still // get spurious updates we've cleared the tag. Guard against this. if (outline == null) { if (LOGD) { Object val = animation.getAnimatedValue(); Log.d(TAG, "anim " + thisIndex + " update: " + val + ", isStopped " + anim.isStopped()); } // Try to prevent it from continuing to run animation.cancel(); } else { mDragOutlineAlphas[thisIndex] = (Float) animation.getAnimatedValue(); CellLayout.this.invalidate(mDragOutlines[thisIndex]); } } }); // The animation holds a reference to the drag outline bitmap as long is it's // running. This way the bitmap can be GCed when the animations are complete. anim.getAnimator().addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { if ((Float) ((ValueAnimator) animation).getAnimatedValue() == 0f) { anim.setTag(null); } } }); mDragOutlineAnims[i] = anim; } mShortcutsAndWidgets = new ShortcutAndWidgetContainer(context); mShortcutsAndWidgets.setCellDimensions(mCellWidth, mCellHeight, mWidthGap, mHeightGap, mCountX, mCountY); mStylusEventHelper = new StylusEventHelper(this); mTouchFeedbackView = new ClickShadowView(context); addView(mTouchFeedbackView); addView(mShortcutsAndWidgets); }
From source file:com.klinker.android.launcher.launcher3.CellLayout.java
public CellLayout(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); // A ViewGroup usually does not draw, but CellLayout needs to draw a rectangle to show // the user where a dragged item will land when dropped. setWillNotDraw(false);/*from w w w . j a va2 s. c o m*/ setClipToPadding(false); mLauncher = (Launcher) context; DeviceProfile grid = mLauncher.getDeviceProfile(); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CellLayout, defStyle, 0); mCellWidth = mCellHeight = -1; mFixedCellWidth = mFixedCellHeight = -1; mWidthGap = mOriginalWidthGap = 0; mHeightGap = mOriginalHeightGap = 0; mMaxGap = Integer.MAX_VALUE; mCountX = (int) grid.inv.numColumns; mCountY = (int) grid.inv.numRows; mOccupied = new boolean[mCountX][mCountY]; mTmpOccupied = new boolean[mCountX][mCountY]; mPreviousReorderDirection[0] = INVALID_DIRECTION; mPreviousReorderDirection[1] = INVALID_DIRECTION; a.recycle(); setAlwaysDrawnWithCacheEnabled(false); final Resources res = getResources(); mHotseatScale = (float) grid.hotseatIconSizePx / grid.iconSizePx; mBackground = (TransitionDrawable) res.getDrawable(R.drawable.bg_screenpanel); mBackground.setCallback(this); mReorderPreviewAnimationMagnitude = (REORDER_PREVIEW_MAGNITUDE * grid.iconSizePx); // Initialize the data structures used for the drag visualization. mEaseOutInterpolator = new DecelerateInterpolator(2.5f); // Quint ease out mDragCell[0] = mDragCell[1] = -1; for (int i = 0; i < mDragOutlines.length; i++) { mDragOutlines[i] = new Rect(-1, -1, -1, -1); } // When dragging things around the home screens, we show a green outline of // where the item will land. The outlines gradually fade out, leaving a trail // behind the drag path. // Set up all the animations that are used to implement this fading. final int duration = res.getInteger(R.integer.config_dragOutlineFadeTime); final float fromAlphaValue = 0; final float toAlphaValue = (float) res.getInteger(R.integer.config_dragOutlineMaxAlpha); Arrays.fill(mDragOutlineAlphas, fromAlphaValue); for (int i = 0; i < mDragOutlineAnims.length; i++) { final InterruptibleInOutAnimator anim = new InterruptibleInOutAnimator(this, duration, fromAlphaValue, toAlphaValue); anim.getAnimator().setInterpolator(mEaseOutInterpolator); final int thisIndex = i; anim.getAnimator().addUpdateListener(new AnimatorUpdateListener() { public void onAnimationUpdate(ValueAnimator animation) { final Bitmap outline = (Bitmap) anim.getTag(); // If an animation is started and then stopped very quickly, we can still // get spurious updates we've cleared the tag. Guard against this. if (outline == null) { @SuppressWarnings("all") // suppress dead code warning final boolean debug = false; if (debug) { Object val = animation.getAnimatedValue(); Log.d(TAG, "anim " + thisIndex + " update: " + val + ", isStopped " + anim.isStopped()); } // Try to prevent it from continuing to run animation.cancel(); } else { mDragOutlineAlphas[thisIndex] = (Float) animation.getAnimatedValue(); CellLayout.this.invalidate(mDragOutlines[thisIndex]); } } }); // The animation holds a reference to the drag outline bitmap as long is it's // running. This way the bitmap can be GCed when the animations are complete. anim.getAnimator().addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { if ((Float) ((ValueAnimator) animation).getAnimatedValue() == 0f) { anim.setTag(null); } } }); mDragOutlineAnims[i] = anim; } mShortcutsAndWidgets = new ShortcutAndWidgetContainer(context); mShortcutsAndWidgets.setCellDimensions(mCellWidth, mCellHeight, mWidthGap, mHeightGap, mCountX, mCountY); mStylusEventHelper = new StylusEventHelper(this); mTouchFeedbackView = new ClickShadowView(context); addView(mTouchFeedbackView); addView(mShortcutsAndWidgets); }
From source file:com.htc.dotdesign.ToolBoxService.java
@Override public void onCreate() { Log.d(DotDesignConstants.LOG_TAG, LOG_PREFIX + "onCreate"); super.onCreate(); Resources res = getResources(); mWindowManager = (WindowManager) getSystemService(WINDOW_SERVICE); mLocalBroadcastManager = LocalBroadcastManager.getInstance(this); if (mLocalBroadcastManager != null) { IntentFilter filter = new IntentFilter(); filter.addAction(SHOW_HIDE_TOOL_BAR); filter.addAction(USER_START_DRAWING); mLocalBroadcastManager.registerReceiver(mToolBarReceiver, filter); }// ww w . jav a 2 s. c o m // Get full window size Display display = mWindowManager.getDefaultDisplay(); Point size = new Point(); display.getRealSize(size); mScreenWidth = size.x; mScreenHeight = size.y; // Get arrow width BitmapFactory.Options bitmapOptions = new BitmapFactory.Options(); bitmapOptions.inJustDecodeBounds = true; BitmapFactory.decodeResource(res, R.drawable.dot_design_popupmenu_arrow, bitmapOptions); mArrowWidth = bitmapOptions.outWidth; // Initialize LayoutParams mDragButtonParams = new WindowManager.LayoutParams(res.getDimensionPixelSize(R.dimen.drag_button_width), res.getDimensionPixelSize(R.dimen.drag_button_height), WindowManager.LayoutParams.TYPE_PHONE, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, PixelFormat.TRANSLUCENT); mDragButtonParams.gravity = Gravity.TOP | Gravity.START; mDragButtonParams.x = 0; mDragButtonParams.y = mScreenHeight / 2; mToolBarParams = new WindowManager.LayoutParams(res.getDimensionPixelSize(R.dimen.tool_bar_width), res.getDimensionPixelSize(R.dimen.tool_bar_height), WindowManager.LayoutParams.TYPE_PHONE, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, PixelFormat.TRANSLUCENT); mToolBarParams.alpha = 0.9f; mToolBarParams.gravity = Gravity.TOP | Gravity.START; mToolBarParams.x = 0; mToolBarParams.y = mDragButtonParams.y; // Initialize drag button width and height //mDragButtonWidth = res.getDimensionPixelSize(R.dimen.drag_button_width); mDragButtonHeight = res.getDimensionPixelSize(R.dimen.drag_button_height); mDragBtnColorIcon = (GradientDrawable) res.getDrawable(R.drawable.round_button); mDragBtnEraserIcon = res.getDrawable(R.drawable.dot_design_circle_shape_dark); // Inflate layout LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); mDragButton = inflater.inflate(R.layout.drag_button, null); mToolBarParent = inflater.inflate(R.layout.tool_bar, null); mPalette = inflater.inflate(R.layout.palette, null); mEraser = inflater.inflate(R.layout.eraser, null); mMenu = inflater.inflate(R.layout.menu, null); initToolBar(); initMenu(); initAnimation(); initBrushColor(); initDragButton(); mWindowManager.addView(mToolBarParent, mToolBarParams); mWindowManager.addView(mDragButton, mDragButtonParams); mToolBarParent.setVisibility(View.INVISIBLE); }
From source file:com.android.launcher2.Workspace.java
/** * Initializes various states for this workspace. *//* w w w . j a v a 2s .co m*/ protected void initWorkspace() { Context context = getContext(); mCurrentPage = mDefaultPage; Launcher.setScreen(mCurrentPage); LauncherApplication app = (LauncherApplication) context.getApplicationContext(); mIconCache = app.getIconCache(); setWillNotDraw(false); setChildrenDrawnWithCacheEnabled(true); final Resources res = getResources(); try { mBackground = res.getDrawable(R.drawable.apps_customize_bg); } catch (Resources.NotFoundException e) { // In this case, we will skip drawing background protection } mWallpaperOffset = new WallpaperOffsetInterpolator(); Display display = mLauncher.getWindowManager().getDefaultDisplay(); display.getSize(mDisplaySize); mWallpaperTravelWidth = (int) (mDisplaySize.x * wallpaperTravelToScreenWidthRatio(mDisplaySize.x, mDisplaySize.y)); mMaxDistanceForFolderCreation = (0.55f * res.getDimensionPixelSize(R.dimen.app_icon_size)); mFlingThresholdVelocity = (int) (FLING_THRESHOLD_VELOCITY * mDensity); }
From source file:com.android.launcher2.Launcher.java
private Drawable getExternalPackageToolbarIcon(ComponentName activityName, String resourceName) { try {//from w w w .j av a2 s . c om PackageManager packageManager = getPackageManager(); // Look for the toolbar icon specified in the activity meta-data Bundle metaData = packageManager.getActivityInfo(activityName, PackageManager.GET_META_DATA).metaData; if (metaData != null) { int iconResId = metaData.getInt(resourceName); if (iconResId != 0) { Resources res = packageManager.getResourcesForActivity(activityName); return res.getDrawable(iconResId); } } } catch (NameNotFoundException e) { // This can happen if the activity defines an invalid drawable Log.w(TAG, "Failed to load toolbar icon; " + activityName.flattenToShortString() + " not found", e); } catch (Resources.NotFoundException nfe) { // This can happen if the activity defines an invalid drawable Log.w(TAG, "Failed to load toolbar icon from " + activityName.flattenToShortString(), nfe); } return null; }
From source file:com.android.launcher2.Launcher.java
private Drawable.ConstantState updateTextButtonWithIconFromExternalActivity(int buttonId, ComponentName activityName, int fallbackDrawableId, String toolbarResourceName) { Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName); Resources r = getResources(); int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width); int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height); TextView button = (TextView) findViewById(buttonId); // If we were unable to find the icon via the meta-data, use a generic one if (toolbarIcon == null) { toolbarIcon = r.getDrawable(fallbackDrawableId); toolbarIcon.setBounds(0, 0, w, h); if (button != null) { button.setCompoundDrawables(toolbarIcon, null, null, null); }/*from w ww . ja v a 2 s . co m*/ return null; } else { toolbarIcon.setBounds(0, 0, w, h); if (button != null) { button.setCompoundDrawables(toolbarIcon, null, null, null); } return toolbarIcon.getConstantState(); } }
From source file:cc.flydev.launcher.Workspace.java
/** * Initializes various states for this workspace. *///from www. ja va2 s. c o m protected void initWorkspace() { Context context = getContext(); mCurrentPage = mDefaultPage; Launcher.setScreen(mCurrentPage); LauncherAppState app = LauncherAppState.getInstance(); DeviceProfile grid = app.getDynamicGrid().getDeviceProfile(); mIconCache = app.getIconCache(); setWillNotDraw(false); setClipChildren(false); setClipToPadding(false); setChildrenDrawnWithCacheEnabled(true); // This is a bit of a hack to account for the fact that we translate the workspace // up a bit, and still need to draw the background covering the whole screen. setMinScale(mOverviewModeShrinkFactor - 0.2f); setupLayoutTransition(); final Resources res = getResources(); try { mBackground = res.getDrawable(R.drawable.apps_customize_bg); } catch (Resources.NotFoundException e) { // In this case, we will skip drawing background protection } mWallpaperOffset = new WallpaperOffsetInterpolator(); Display display = mLauncher.getWindowManager().getDefaultDisplay(); display.getSize(mDisplaySize); mMaxDistanceForFolderCreation = (0.55f * grid.iconSizePx); mFlingThresholdVelocity = (int) (FLING_THRESHOLD_VELOCITY * mDensity); }
From source file:com.aidy.launcher3.ui.workspace.Workspace.java
/** * Initializes various states for this workspace. *//*from w ww .j a v a 2s . c o m*/ protected void initWorkspace() { Context context = getContext(); mCurrentPage = mDefaultPage; Launcher.setScreen(mCurrentPage); LauncherAppState app = LauncherAppState.getInstance(); DeviceProfile grid = app.getDynamicGrid().getDeviceProfile(); mIconCache = app.getIconCache(); setWillNotDraw(false); setClipChildren(false); setClipToPadding(false); setChildrenDrawnWithCacheEnabled(true); // This is a bit of a hack to account for the fact that we translate the // workspace // up a bit, and still need to draw the background covering the whole // screen. setMinScale(mOverviewModeShrinkFactor - 0.2f); setupLayoutTransition(); final Resources res = getResources(); try { mBackground = res.getDrawable(R.drawable.apps_customize_bg); } catch (Resources.NotFoundException e) { // In this case, we will skip drawing background protection } mWallpaperOffset = new WallpaperOffsetInterpolator(); Display display = mLauncher.getWindowManager().getDefaultDisplay(); display.getSize(mDisplaySize); mMaxDistanceForFolderCreation = (0.55f * grid.iconSizePx); mFlingThresholdVelocity = (int) (FLING_THRESHOLD_VELOCITY * mDensity); }
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 . j av a2 s.c om 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 ww .j a va2s. c o m*/ 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; }