List of usage examples for android.view Gravity START
int START
To view the source code for android.view Gravity START.
Click Source Link
From source file:android.support.v17.leanback.app.GuidedStepFragment.java
/** * Called by Constructor to provide fragment transitions. The default implementation assigns * transitions based on {@link #getUiStyle()}: * <ul>/*from w ww . j a v a 2s .c o m*/ * <li> {@link #UI_STYLE_REPLACE} Slide from/to end(right) for enter transition, slide from/to * start(left) for exit transition, shared element enter transition is set to ChangeBounds. * <li> {@link #UI_STYLE_ENTRANCE} Enter transition is set to slide from both sides, exit * transition is same as {@link #UI_STYLE_REPLACE}, no shared element enter transition. * <li> {@link #UI_STYLE_ACTIVITY_ROOT} Enter transition is set to null and app should rely on * activity transition, exit transition is same as {@link #UI_STYLE_REPLACE}, no shared element * enter transition. * </ul> * <p> * The default implementation heavily relies on {@link GuidedActionsStylist} and * {@link GuidanceStylist} layout, app may override this method when modifying the default * layout of {@link GuidedActionsStylist} or {@link GuidanceStylist}. * <p> * TIP: because the fragment view is removed during fragment transition, in general app cannot * use two Visibility transition together. Workaround is to create your own Visibility * transition that controls multiple animators (e.g. slide and fade animation in one Transition * class). */ protected void onProvideFragmentTransitions() { if (Build.VERSION.SDK_INT >= 21) { final int uiStyle = getUiStyle(); if (uiStyle == UI_STYLE_REPLACE) { Object enterTransition = TransitionHelper.createFadeAndShortSlide(Gravity.END); TransitionHelper.exclude(enterTransition, R.id.guidedstep_background, true); TransitionHelper.setEnterTransition(this, enterTransition); Object changeBounds = TransitionHelper.createChangeBounds(false); TransitionHelper.setSharedElementEnterTransition(this, changeBounds); } else if (uiStyle == UI_STYLE_ENTRANCE) { if (entranceTransitionType == SLIDE_FROM_SIDE) { Object fade = TransitionHelper .createFadeTransition(TransitionHelper.FADE_IN | TransitionHelper.FADE_OUT); TransitionHelper.include(fade, R.id.guidedstep_background); Object slideFromSide = TransitionHelper.createFadeAndShortSlide(Gravity.END | Gravity.START); TransitionHelper.include(slideFromSide, R.id.content_fragment); TransitionHelper.include(slideFromSide, R.id.action_fragment_root); Object enterTransition = TransitionHelper.createTransitionSet(false); TransitionHelper.addTransition(enterTransition, fade); TransitionHelper.addTransition(enterTransition, slideFromSide); TransitionHelper.setEnterTransition(this, enterTransition); } else { Object slideFromBottom = TransitionHelper.createFadeAndShortSlide(Gravity.BOTTOM); TransitionHelper.include(slideFromBottom, R.id.guidedstep_background_view_root); Object enterTransition = TransitionHelper.createTransitionSet(false); TransitionHelper.addTransition(enterTransition, slideFromBottom); TransitionHelper.setEnterTransition(this, enterTransition); } // No shared element transition TransitionHelper.setSharedElementEnterTransition(this, null); } else if (uiStyle == UI_STYLE_ACTIVITY_ROOT) { // for Activity root, we dont need enter transition, use activity transition TransitionHelper.setEnterTransition(this, null); // No shared element transition TransitionHelper.setSharedElementEnterTransition(this, null); } // exitTransition is same for all style Object exitTransition = TransitionHelper.createFadeAndShortSlide(Gravity.START); TransitionHelper.exclude(exitTransition, R.id.guidedstep_background, true); TransitionHelper.setExitTransition(this, exitTransition); } }
From source file:com.rbware.github.androidcouchpotato.app.GuidedStepFragment.java
/** * Called by Constructor to provide fragment transitions. The default implementation assigns * transitions based on {@link #getUiStyle()}: * <ul>/*w w w . j ava 2 s . c o m*/ * <li> {@link #UI_STYLE_REPLACE} Slide from/to end(right) for enter transition, slide from/to * start(left) for exit transition, shared element enter transition is set to ChangeBounds. * <li> {@link #UI_STYLE_ENTRANCE} Enter transition is set to slide from both sides, exit * transition is same as {@link #UI_STYLE_REPLACE}, no shared element enter transition. * <li> {@link #UI_STYLE_ACTIVITY_ROOT} Enter transition is set to null and app should rely on * activity transition, exit transition is same as {@link #UI_STYLE_REPLACE}, no shared element * enter transition. * </ul> * <p> * The default implementation heavily relies on {@link GuidedActionsStylist} and * {@link GuidanceStylist} layout, app may override this method when modifying the default * layout of {@link GuidedActionsStylist} or {@link GuidanceStylist}. * <p> * TIP: because the fragment view is removed during fragment transition, in general app cannot * use two Visibility transition together. Workaround is to create your own Visibility * transition that controls multiple animators (e.g. slide and fade animation in one Transition * class). */ protected void onProvideFragmentTransitions() { if (Build.VERSION.SDK_INT >= 21) { final int uiStyle = getUiStyle(); if (uiStyle == UI_STYLE_REPLACE) { Object enterTransition = TransitionHelper.createFadeAndShortSlide(Gravity.END); TransitionHelper.exclude(enterTransition, R.id.guidedstep_background, true); TransitionHelper.exclude(enterTransition, R.id.guidedactions_sub_list_background, true); TransitionHelper.setEnterTransition(this, enterTransition); Object fade = TransitionHelper .createFadeTransition(TransitionHelper.FADE_IN | TransitionHelper.FADE_OUT); TransitionHelper.include(fade, R.id.guidedactions_sub_list_background); Object changeBounds = TransitionHelper.createChangeBounds(false); Object sharedElementTransition = TransitionHelper.createTransitionSet(false); TransitionHelper.addTransition(sharedElementTransition, fade); TransitionHelper.addTransition(sharedElementTransition, changeBounds); TransitionHelper.setSharedElementEnterTransition(this, sharedElementTransition); } else if (uiStyle == UI_STYLE_ENTRANCE) { if (entranceTransitionType == SLIDE_FROM_SIDE) { Object fade = TransitionHelper .createFadeTransition(TransitionHelper.FADE_IN | TransitionHelper.FADE_OUT); TransitionHelper.include(fade, R.id.guidedstep_background); Object slideFromSide = TransitionHelper.createFadeAndShortSlide(Gravity.END | Gravity.START); TransitionHelper.include(slideFromSide, R.id.content_fragment); TransitionHelper.include(slideFromSide, R.id.action_fragment_root); Object enterTransition = TransitionHelper.createTransitionSet(false); TransitionHelper.addTransition(enterTransition, fade); TransitionHelper.addTransition(enterTransition, slideFromSide); TransitionHelper.setEnterTransition(this, enterTransition); } else { Object slideFromBottom = TransitionHelper.createFadeAndShortSlide(Gravity.BOTTOM); TransitionHelper.include(slideFromBottom, R.id.guidedstep_background_view_root); Object enterTransition = TransitionHelper.createTransitionSet(false); TransitionHelper.addTransition(enterTransition, slideFromBottom); TransitionHelper.setEnterTransition(this, enterTransition); } // No shared element transition TransitionHelper.setSharedElementEnterTransition(this, null); } else if (uiStyle == UI_STYLE_ACTIVITY_ROOT) { // for Activity root, we don't need enter transition, use activity transition TransitionHelper.setEnterTransition(this, null); // No shared element transition TransitionHelper.setSharedElementEnterTransition(this, null); } // exitTransition is same for all style Object exitTransition = TransitionHelper.createFadeAndShortSlide(Gravity.START); TransitionHelper.exclude(exitTransition, R.id.guidedstep_background, true); TransitionHelper.exclude(exitTransition, R.id.guidedactions_sub_list_background, true); TransitionHelper.setExitTransition(this, exitTransition); } }
From source file:com.daiv.android.twitter.ui.drawer_activities.DrawerActivity.java
@Override public boolean onPrepareOptionsMenu(Menu menu) { final int DISMISS = 0; final int SEARCH = 1; final int COMPOSE = 2; final int NOTIFICATIONS = 3; final int DM = 4; final int SETTINGS = 5; final int TOFIRST = 6; final int TWEETMARKER = 7; try {/*from ww w . java 2 s . c o m*/ searchItem = menu.findItem(R.id.menu_search); } catch (Exception e) { searchItem = null; } menu.getItem(TWEETMARKER).setVisible(false); if (mDrawerLayout.isDrawerOpen(Gravity.RIGHT) || sharedPrefs.getBoolean("open_interactions", false)) { menu.getItem(DISMISS).setVisible(true); menu.getItem(SEARCH).setVisible(false); menu.getItem(COMPOSE).setVisible(false); menu.getItem(DM).setVisible(false); menu.getItem(TOFIRST).setVisible(false); if (settings.pushNotifications && settings.useInteractionDrawer) { menu.getItem(NOTIFICATIONS).setVisible(true); } else { menu.getItem(NOTIFICATIONS).setVisible(false); } } else { menu.getItem(DISMISS).setVisible(false); menu.getItem(SEARCH).setVisible(true); menu.getItem(COMPOSE).setVisible(true); menu.getItem(DM).setVisible(true); if (!settings.pushNotifications || !settings.useInteractionDrawer) { menu.getItem(NOTIFICATIONS).setVisible(false); } else { if (settings.floatingCompose || getResources().getBoolean(R.bool.isTablet)) { menu.getItem(NOTIFICATIONS).setVisible(true); } else { menu.getItem(NOTIFICATIONS).setVisible(false); } } } // to first button in overflow instead of the toast if (MainDrawerArrayAdapter.current > adapter.pageTypes.size() || (settings.uiExtras && settings.useToast)) { menu.getItem(TOFIRST).setVisible(false); } else { menu.getItem(TOFIRST).setVisible(true); } if (MainActivity.isPopup) { menu.getItem(SETTINGS).setVisible(false); // hide the settings button if the popup is up menu.getItem(SEARCH).setVisible(false); // hide the search button in popup // disable the left drawer so they can't switch activities in the popup. // causes problems with the layouts mDrawerLayout.setDrawerLockMode(NotificationDrawerLayout.LOCK_MODE_LOCKED_CLOSED, Gravity.START); actionBar.setDisplayShowHomeEnabled(false); actionBar.setDisplayHomeAsUpEnabled(false); actionBar.setHomeButtonEnabled(false); } noti = menu.getItem(NOTIFICATIONS); if (InteractionsDataSource.getInstance(context).getUnreadCount(settings.currentAccount) > 0) { setNotificationFilled(true); } else { setNotificationFilled(false); } return true; }
From source file:com.klinker.android.twitter.ui.drawer_activities.DrawerActivity.java
@Override public boolean onPrepareOptionsMenu(Menu menu) { final int DISMISS = 0; final int SEARCH = 1; final int COMPOSE = 2; final int NOTIFICATIONS = 3; final int DM = 4; final int SETTINGS = 5; final int TOFIRST = 6; final int TWEETMARKER = 7; try {/*from ww w . j a v a 2s . co m*/ searchItem = menu.findItem(R.id.menu_search); } catch (Exception e) { searchItem = null; } menu.getItem(TWEETMARKER).setVisible(false); if (mDrawerLayout.isDrawerOpen(Gravity.RIGHT) || sharedPrefs.getBoolean("open_interactions", false)) { menu.getItem(DISMISS).setVisible(true); menu.getItem(SEARCH).setVisible(false); menu.getItem(COMPOSE).setVisible(false); menu.getItem(DM).setVisible(false); menu.getItem(TOFIRST).setVisible(false); if (settings.pushNotifications) { menu.getItem(NOTIFICATIONS).setVisible(true); } else { menu.getItem(NOTIFICATIONS).setVisible(false); } } else { menu.getItem(DISMISS).setVisible(false); menu.getItem(SEARCH).setVisible(true); menu.getItem(COMPOSE).setVisible(true); menu.getItem(DM).setVisible(true); if (!settings.pushNotifications) { menu.getItem(NOTIFICATIONS).setVisible(false); } else { if (settings.floatingCompose || getResources().getBoolean(R.bool.isTablet)) { menu.getItem(NOTIFICATIONS).setVisible(true); } else { menu.getItem(NOTIFICATIONS).setVisible(false); } } } // to first button in overflow instead of the toast if (MainDrawerArrayAdapter.current > 2 || (settings.uiExtras && settings.useToast)) { menu.getItem(TOFIRST).setVisible(false); } else { menu.getItem(TOFIRST).setVisible(true); } if (MainActivity.isPopup) { menu.getItem(SETTINGS).setVisible(false); // hide the settings button if the popup is up menu.getItem(SEARCH).setVisible(false); // hide the search button in popup // disable the left drawer so they can't switch activities in the popup. // causes problems with the layouts mDrawerLayout.setDrawerLockMode(NotificationDrawerLayout.LOCK_MODE_LOCKED_CLOSED, Gravity.START); actionBar.setDisplayShowHomeEnabled(false); actionBar.setDisplayHomeAsUpEnabled(false); actionBar.setHomeButtonEnabled(false); } noti = menu.getItem(NOTIFICATIONS); if (InteractionsDataSource.getInstance(context).getUnreadCount(settings.currentAccount) > 0) { setNotificationFilled(true); } else { setNotificationFilled(false); } return true; }
From source file:com.maskyn.fileeditorpro.activity.MainActivity.java
public void OpenSettings(View view) { mDrawerLayout.closeDrawer(Gravity.START); mDrawerLayout.openDrawer(Gravity.END); }
From source file:com.phonemetra.turbo.launcher.AsyncTaskCallback.java
public void syncWidgetPageItems(final int page, final boolean immediate) { int numItemsPerPage = mWidgetCountX * mWidgetCountY; // Calculate the dimensions of each cell we are giving to each widget final ArrayList<Object> items = new ArrayList<Object>(); int contentWidth = mContentWidth; final int cellWidth = ((contentWidth - mPageLayoutPaddingLeft - mPageLayoutPaddingRight - ((mWidgetCountX - 1) * mWidgetWidthGap)) / mWidgetCountX); int contentHeight = mContentHeight; final int cellHeight = ((contentHeight - mPageLayoutPaddingTop - mPageLayoutPaddingBottom - ((mWidgetCountY - 1) * mWidgetHeightGap)) / mWidgetCountY); // Prepare the set of widgets to load previews for in the background int offset = page * numItemsPerPage; for (int i = offset; i < Math.min(offset + numItemsPerPage, mFilteredWidgets.size()); ++i) { items.add(mFilteredWidgets.get(i)); }//from www . ja v a2s . com // Prepopulate the pages with the other widget info, and fill in the previews later final PagedViewGridLayout layout = (PagedViewGridLayout) getPageAt(page); layout.setColumnCount(layout.getCellCountX()); for (int i = 0; i < items.size(); ++i) { Object rawInfo = items.get(i); PendingAddItemInfo createItemInfo = null; PagedViewWidget widget = (PagedViewWidget) mLayoutInflater.inflate(R.layout.apps_customize_widget, layout, false); if (rawInfo instanceof AppWidgetProviderInfo) { // Fill in the widget information AppWidgetProviderInfo info = (AppWidgetProviderInfo) rawInfo; createItemInfo = new PendingAddWidgetInfo(info, null, null); // Determine the widget spans and min resize spans. int[] spanXY = Launcher.getSpanForWidget(mLauncher, info); createItemInfo.spanX = spanXY[0]; createItemInfo.spanY = spanXY[1]; int[] minSpanXY = Launcher.getMinSpanForWidget(mLauncher, info); createItemInfo.minSpanX = minSpanXY[0]; createItemInfo.minSpanY = minSpanXY[1]; widget.applyFromAppWidgetProviderInfo(info, -1, spanXY, getWidgetPreviewLoader()); widget.setTag(createItemInfo); widget.setShortPressListener(this); } else if (rawInfo instanceof ResolveInfo) { // Fill in the shortcuts information ResolveInfo info = (ResolveInfo) rawInfo; createItemInfo = new PendingAddShortcutInfo(info.activityInfo); createItemInfo.itemType = LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT; createItemInfo.componentName = new ComponentName(info.activityInfo.packageName, info.activityInfo.name); widget.applyFromResolveInfo(mPackageManager, info, getWidgetPreviewLoader()); widget.setTag(createItemInfo); } widget.setOnClickListener(this); widget.setOnLongClickListener(this); widget.setOnTouchListener(this); widget.setOnKeyListener(this); // Layout each widget int ix = i % mWidgetCountX; int iy = i / mWidgetCountX; GridLayout.LayoutParams lp = new GridLayout.LayoutParams(GridLayout.spec(iy, GridLayout.START), GridLayout.spec(ix, GridLayout.TOP)); lp.width = cellWidth; lp.height = cellHeight; lp.setGravity(Gravity.TOP | Gravity.START); if (ix > 0) lp.leftMargin = mWidgetWidthGap; if (iy > 0) lp.topMargin = mWidgetHeightGap; layout.addView(widget, lp); } // wait until a call on onLayout to start loading, because // PagedViewWidget.getPreviewSize() will return 0 if it hasn't been laid out // TODO: can we do a measure/layout immediately? layout.setOnLayoutListener(new Runnable() { public void run() { // Load the widget previews int maxPreviewWidth = cellWidth; int maxPreviewHeight = cellHeight; if (layout.getChildCount() > 0) { PagedViewWidget w = (PagedViewWidget) layout.getChildAt(0); int[] maxSize = w.getPreviewSize(); maxPreviewWidth = maxSize[0]; maxPreviewHeight = maxSize[1]; } getWidgetPreviewLoader().setPreviewSize(maxPreviewWidth, maxPreviewHeight, mWidgetSpacingLayout); if (immediate) { AsyncTaskPageData data = new AsyncTaskPageData(page, items, maxPreviewWidth, maxPreviewHeight, null, null, getWidgetPreviewLoader()); loadWidgetPreviewsInBackground(null, data); onSyncWidgetPageItems(data, immediate); } else { if (mInTransition) { mDeferredPrepareLoadWidgetPreviewsTasks.add(this); } else { prepareLoadWidgetPreviewsTask(page, items, maxPreviewWidth, maxPreviewHeight, mWidgetCountX); } } layout.setOnLayoutListener(null); } }); }
From source file:com.yek.keyboard.keyboards.views.AnyKeyboardViewBase.java
@CallSuper protected void onBufferDraw(Canvas canvas, final Paint paint) { if (mKeyboardChanged) { invalidateAllKeys();/*from w w w . j a v a2s. co m*/ mKeyboardChanged = false; } canvas.getClipBounds(mDirtyRect); if (mKeyboard == null) return; final boolean drawKeyboardNameText = (mKeyboardNameTextSize > 1f) && AnyApplication.getConfig().getShowKeyboardNameText(); final boolean drawHintText = (mHintTextSize > 1) && AnyApplication.getConfig().getShowHintTextOnKeys(); final boolean useCustomKeyTextColor = false; // TODO: final boolean useCustomKeyTextColor = // AnyApplication.getConfig().getUseCustomTextColorOnKeys(); final ColorStateList keyTextColor = useCustomKeyTextColor ? new ColorStateList(new int[][] { { 0 } }, new int[] { 0xFF6666FF }) : mKeyTextColor; final boolean useCustomHintColor = drawHintText && false; // TODO: final boolean useCustomHintColor = drawHintText && final ColorStateList hintColor = useCustomHintColor ? new ColorStateList(new int[][] { { 0 } }, new int[] { 0xFFFF6666 }) : mHintTextColor; // allow preferences to override theme settings for hint text position final boolean useCustomHintAlign = drawHintText && AnyApplication.getConfig().getUseCustomHintAlign(); final int hintAlign = useCustomHintAlign ? AnyApplication.getConfig().getCustomHintAlign() : mHintLabelAlign; final int hintVAlign = useCustomHintAlign ? AnyApplication.getConfig().getCustomHintVAlign() : mHintLabelVAlign; final Drawable keyBackground = mKeyBackground; final Rect clipRegion = mClipRegion; final int kbdPaddingLeft = getPaddingLeft(); final int kbdPaddingTop = getPaddingTop(); final Keyboard.Key[] keys = mKeys; final Keyboard.Key invalidKey = mInvalidatedKey; boolean drawSingleKey = false; if (invalidKey != null && canvas.getClipBounds(clipRegion)) { // TODO we should use Rect.inset and Rect.contains here. // Is clipRegion completely contained within the invalidated key? if (invalidKey.x + kbdPaddingLeft - 1 <= clipRegion.left && invalidKey.y + kbdPaddingTop - 1 <= clipRegion.top && invalidKey.x + invalidKey.width + kbdPaddingLeft + 1 >= clipRegion.right && invalidKey.y + invalidKey.height + kbdPaddingTop + 1 >= clipRegion.bottom) { drawSingleKey = true; } } for (Keyboard.Key keyBase : keys) { final AnyKeyboard.AnyKey key = (AnyKeyboard.AnyKey) keyBase; final boolean keyIsSpace = isSpaceKey(key); if (drawSingleKey && (invalidKey != key)) { continue; } if (!mDirtyRect.intersects(key.x + kbdPaddingLeft, key.y + kbdPaddingTop, key.x + key.width + kbdPaddingLeft, key.y + key.height + kbdPaddingTop)) { continue; } int[] drawableState = key.getCurrentDrawableState(mDrawableStatesProvider); if (keyIsSpace) paint.setColor(mKeyboardNameTextColor); else paint.setColor(keyTextColor.getColorForState(drawableState, 0xFF000000)); keyBackground.setState(drawableState); // Switch the character to uppercase if shift is pressed CharSequence label = key.label == null ? null : adjustLabelToShiftState(key); final Rect bounds = keyBackground.getBounds(); if ((key.width != bounds.right) || (key.height != bounds.bottom)) { keyBackground.setBounds(0, 0, key.width, key.height); } canvas.translate(key.x + kbdPaddingLeft, key.y + kbdPaddingTop); keyBackground.draw(canvas); if (TextUtils.isEmpty(label)) { Drawable iconToDraw = getIconToDrawForKey(key, false); if (iconToDraw != null/* && shouldDrawIcon */) { //http://developer.android.com/reference/android/graphics/drawable/Drawable.html#getCurrent() //http://stackoverflow.com/a/103600/1324235 final boolean is9Patch = iconToDraw.getCurrent() instanceof NinePatchDrawable; // Special handing for the upper-right number hint icons final int drawableWidth; final int drawableHeight; final int drawableX; final int drawableY; drawableWidth = is9Patch ? key.width : iconToDraw.getIntrinsicWidth(); drawableHeight = is9Patch ? key.height : iconToDraw.getIntrinsicHeight(); drawableX = (key.width + mKeyBackgroundPadding.left - mKeyBackgroundPadding.right - drawableWidth) / 2; drawableY = (key.height + mKeyBackgroundPadding.top - mKeyBackgroundPadding.bottom - drawableHeight) / 2; canvas.translate(drawableX, drawableY); iconToDraw.setBounds(0, 0, drawableWidth, drawableHeight); iconToDraw.draw(canvas); canvas.translate(-drawableX, -drawableY); if (keyIsSpace && drawKeyboardNameText) { // now a little hack, I'll set the label now, so it get // drawn. label = mKeyboardName; } } else { // ho... no icon. // I'll try to guess the text label = guessLabelForKey(key.getPrimaryCode()); } } if (label != null) { // For characters, use large font. For labels like "Done", use // small font. final FontMetrics fm; if (keyIsSpace) { paint.setTextSize(mKeyboardNameTextSize); paint.setTypeface(Typeface.DEFAULT_BOLD); if (mKeyboardNameFM == null) mKeyboardNameFM = paint.getFontMetrics(); fm = mKeyboardNameFM; } else if (label.length() > 1 && key.getCodesCount() < 2) { setPaintForLabelText(paint); if (mLabelFM == null) mLabelFM = paint.getFontMetrics(); fm = mLabelFM; } else { setPaintToKeyText(paint); if (mTextFM == null) mTextFM = paint.getFontMetrics(); fm = mTextFM; } if (isLabelOfPictographic(label)) { paint.setTextSize(2f * paint.getTextSize()); } final float labelHeight = -fm.top; // Draw a drop shadow for the text paint.setShadowLayer(mShadowRadius, mShadowOffsetX, mShadowOffsetY, mShadowColor); final float textWidth = adjustTextSizeForLabel(paint, label, key.width); // the center of the drawable space, which is value used // previously for vertically // positioning the key label final float centerY = mKeyBackgroundPadding.top + ((key.height - mKeyBackgroundPadding.top - mKeyBackgroundPadding.bottom) / (keyIsSpace ? 3 : 2));// the label on the space is a bit higher // the X coordinate for the center of the main label text is // unaffected by the hints final float textX = mKeyBackgroundPadding.left + (key.width - mKeyBackgroundPadding.left - mKeyBackgroundPadding.right) / 2; final float textY; // Some devices (mostly pre-Honeycomb, have issues with RTL text // drawing. // Of course, there is no issue with a single character :) // so, we'll use the RTL secured drawing (via StaticLayout) for // labels. if (label.length() > 1 && !AnyApplication.getConfig().workaround_alwaysUseDrawText()) { // calculate Y coordinate of top of text based on center // location textY = centerY - ((labelHeight - paint.descent()) / 2); canvas.translate(textX, textY); // RTL fix. But it costs, let do it when in need (more than // 1 character) StaticLayout labelText = new StaticLayout(label, new TextPaint(paint), (int) textWidth, Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false); labelText.draw(canvas); } else { // to get Y coordinate of baseline from center of text, // first add half the height (to get to // bottom of text), then subtract the part below the // baseline. Note that fm.top is negative. textY = centerY + ((labelHeight - paint.descent()) / 2); canvas.translate(textX, textY); canvas.drawText(label, 0, label.length(), 0, 0, paint); } canvas.translate(-textX, -textY); // (-) // Turn off drop shadow paint.setShadowLayer(0, 0, 0, 0); } if (drawHintText) { if ((key.popupCharacters != null && key.popupCharacters.length() > 0) || (key.popupResId != 0) || (key.longPressCode != 0)) { Align oldAlign = paint.getTextAlign(); String hintText = null; if (key.hintLabel != null && key.hintLabel.length() > 0) { hintText = key.hintLabel.toString(); // it is the responsibility of the keyboard layout // designer to ensure that they do // not put too many characters in the hint label... } else if (key.longPressCode != 0) { if (Character.isLetterOrDigit(key.longPressCode)) hintText = Character.toString((char) key.longPressCode); } else if (key.popupCharacters != null) { final String hintString = key.popupCharacters.toString(); final int hintLength = hintString.length(); if (hintLength <= 3) hintText = hintString; } // if hintText is still null, it means it didn't fit one of // the above // cases, so we should provide the hint using the default if (hintText == null) { if (mHintOverflowLabel != null) hintText = mHintOverflowLabel; else { // theme does not provide a defaultHintLabel // use if hints are above, ... if hints are // below // (to avoid being too close to main label/icon) if (hintVAlign == Gravity.TOP) hintText = ""; else hintText = "..."; } } if (mKeyboard.isShifted()) hintText = hintText.toUpperCase(getKeyboard().getLocale()); // now draw hint paint.setTypeface(Typeface.DEFAULT); paint.setColor(hintColor.getColorForState(drawableState, 0xFF000000)); paint.setTextSize(mHintTextSize); // get the hint text font metrics so that we know the size // of the hint when // we try to position the main label (to try to make sure // they don't overlap) if (mHintTextFM == null) { mHintTextFM = paint.getFontMetrics(); } final float hintX; final float hintY; // the (float) 0.5 value is added or subtracted to just give // a little more room // in case the theme designer didn't account for the hint // label location if (hintAlign == Gravity.START) { // left paint.setTextAlign(Align.LEFT); hintX = mKeyBackgroundPadding.left + 0.5f; } else if (hintAlign == Gravity.CENTER) { // center paint.setTextAlign(Align.CENTER); hintX = mKeyBackgroundPadding.left + (key.width - mKeyBackgroundPadding.left - mKeyBackgroundPadding.right) / 2; } else { // right paint.setTextAlign(Align.RIGHT); hintX = key.width - mKeyBackgroundPadding.right - 0.5f; } if (hintVAlign == Gravity.TOP) { // above hintY = mKeyBackgroundPadding.top - mHintTextFM.top + 0.5f; } else { // below hintY = key.height - mKeyBackgroundPadding.bottom - mHintTextFM.bottom - 0.5f; } canvas.drawText(hintText, hintX, hintY, paint); paint.setTextAlign(oldAlign); } } canvas.translate(-key.x - kbdPaddingLeft, -key.y - kbdPaddingTop); } mInvalidatedKey = null; mDirtyRect.setEmpty(); }
From source file:com.anysoftkeyboard.keyboards.views.AnyKeyboardViewBase.java
@CallSuper protected void onBufferDraw(Canvas canvas, final Paint paint) { if (mKeyboardChanged) { invalidateAllKeys();// w ww.j av a2 s . c om mKeyboardChanged = false; } canvas.getClipBounds(mDirtyRect); if (mKeyboard == null) return; final boolean drawKeyboardNameText = (mKeyboardNameTextSize > 1f) && AnyApplication.getConfig().getShowKeyboardNameText(); final boolean drawHintText = (mHintTextSize > 1) && AnyApplication.getConfig().getShowHintTextOnKeys(); final boolean useCustomKeyTextColor = false; // TODO: final boolean useCustomKeyTextColor = // AnyApplication.getConfig().getUseCustomTextColorOnKeys(); final ColorStateList keyTextColor = useCustomKeyTextColor ? new ColorStateList(new int[][] { { 0 } }, new int[] { 0xFF6666FF }) : mKeyTextColor; final boolean useCustomHintColor = drawHintText && false; // TODO: final boolean useCustomHintColor = drawHintText && final ColorStateList hintColor = useCustomHintColor ? new ColorStateList(new int[][] { { 0 } }, new int[] { 0xFFFF6666 }) : mHintTextColor; // allow preferences to override theme settings for hint text position final boolean useCustomHintAlign = drawHintText && AnyApplication.getConfig().getUseCustomHintAlign(); final int hintAlign = useCustomHintAlign ? AnyApplication.getConfig().getCustomHintAlign() : mHintLabelAlign; final int hintVAlign = useCustomHintAlign ? AnyApplication.getConfig().getCustomHintVAlign() : mHintLabelVAlign; final Drawable keyBackground = mKeyBackground; final Rect clipRegion = mClipRegion; final int kbdPaddingLeft = getPaddingLeft(); final int kbdPaddingTop = getPaddingTop(); final Key[] keys = mKeys; final Key invalidKey = mInvalidatedKey; boolean drawSingleKey = false; if (invalidKey != null && canvas.getClipBounds(clipRegion)) { // TODO we should use Rect.inset and Rect.contains here. // Is clipRegion completely contained within the invalidated key? if (invalidKey.x + kbdPaddingLeft - 1 <= clipRegion.left && invalidKey.y + kbdPaddingTop - 1 <= clipRegion.top && invalidKey.x + invalidKey.width + kbdPaddingLeft + 1 >= clipRegion.right && invalidKey.y + invalidKey.height + kbdPaddingTop + 1 >= clipRegion.bottom) { drawSingleKey = true; } } for (Key keyBase : keys) { final AnyKey key = (AnyKey) keyBase; final boolean keyIsSpace = isSpaceKey(key); if (drawSingleKey && (invalidKey != key)) { continue; } if (!mDirtyRect.intersects(key.x + kbdPaddingLeft, key.y + kbdPaddingTop, key.x + key.width + kbdPaddingLeft, key.y + key.height + kbdPaddingTop)) { continue; } int[] drawableState = key.getCurrentDrawableState(mDrawableStatesProvider); if (keyIsSpace) paint.setColor(mKeyboardNameTextColor); else paint.setColor(keyTextColor.getColorForState(drawableState, 0xFF000000)); keyBackground.setState(drawableState); // Switch the character to uppercase if shift is pressed CharSequence label = key.label == null ? null : adjustLabelToShiftState(key); final Rect bounds = keyBackground.getBounds(); if ((key.width != bounds.right) || (key.height != bounds.bottom)) { keyBackground.setBounds(0, 0, key.width, key.height); } canvas.translate(key.x + kbdPaddingLeft, key.y + kbdPaddingTop); keyBackground.draw(canvas); if (TextUtils.isEmpty(label)) { Drawable iconToDraw = getIconToDrawForKey(key, false); if (iconToDraw != null/* && shouldDrawIcon */) { //http://developer.android.com/reference/android/graphics/drawable/Drawable.html#getCurrent() //http://stackoverflow.com/a/103600/1324235 final boolean is9Patch = iconToDraw.getCurrent() instanceof NinePatchDrawable; // Special handing for the upper-right number hint icons final int drawableWidth; final int drawableHeight; final int drawableX; final int drawableY; drawableWidth = is9Patch ? key.width : iconToDraw.getIntrinsicWidth(); drawableHeight = is9Patch ? key.height : iconToDraw.getIntrinsicHeight(); drawableX = (key.width + mKeyBackgroundPadding.left - mKeyBackgroundPadding.right - drawableWidth) / 2; drawableY = (key.height + mKeyBackgroundPadding.top - mKeyBackgroundPadding.bottom - drawableHeight) / 2; canvas.translate(drawableX, drawableY); iconToDraw.setBounds(0, 0, drawableWidth, drawableHeight); iconToDraw.draw(canvas); canvas.translate(-drawableX, -drawableY); if (keyIsSpace && drawKeyboardNameText) { // now a little hack, I'll set the label now, so it get // drawn. label = mKeyboardName; } } else { // ho... no icon. // I'll try to guess the text label = guessLabelForKey(key.getPrimaryCode()); } } if (label != null) { // For characters, use large font. For labels like "Done", use // small font. final FontMetrics fm; if (keyIsSpace) { paint.setTextSize(mKeyboardNameTextSize); paint.setTypeface(Typeface.DEFAULT_BOLD); if (mKeyboardNameFontMetrics == null) mKeyboardNameFontMetrics = paint.getFontMetrics(); fm = mKeyboardNameFontMetrics; } else if (label.length() > 1 && key.getCodesCount() < 2) { setPaintForLabelText(paint); if (mLabelFontMetrics == null) mLabelFontMetrics = paint.getFontMetrics(); fm = mLabelFontMetrics; } else { setPaintToKeyText(paint); if (mTextFontMetrics == null) mTextFontMetrics = paint.getFontMetrics(); fm = mTextFontMetrics; } if (isLabelOfPictographic(label)) { paint.setTextSize(2f * paint.getTextSize()); } final float labelHeight = -fm.top; // Draw a drop shadow for the text paint.setShadowLayer(mShadowRadius, mShadowOffsetX, mShadowOffsetY, mShadowColor); final float textWidth = adjustTextSizeForLabel(paint, label, key.width); // the center of the drawable space, which is value used // previously for vertically // positioning the key label final float centerY = mKeyBackgroundPadding.top + ((key.height - mKeyBackgroundPadding.top - mKeyBackgroundPadding.bottom) / (keyIsSpace ? 3 : 2));// the label on the space is a bit higher // the X coordinate for the center of the main label text is // unaffected by the hints final float textX = mKeyBackgroundPadding.left + (key.width - mKeyBackgroundPadding.left - mKeyBackgroundPadding.right) / 2; final float textY; // Some devices (mostly pre-Honeycomb, have issues with RTL text // drawing. // Of course, there is no issue with a single character :) // so, we'll use the RTL secured drawing (via StaticLayout) for // labels. if (label.length() > 1 && !AnyApplication.getConfig().workaround_alwaysUseDrawText()) { // calculate Y coordinate of top of text based on center // location textY = centerY - ((labelHeight - paint.descent()) / 2); canvas.translate(textX, textY); // RTL fix. But it costs, let do it when in need (more than // 1 character) StaticLayout labelText = new StaticLayout(label, new TextPaint(paint), (int) textWidth, Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false); labelText.draw(canvas); } else { // to get Y coordinate of baseline from center of text, // first add half the height (to get to // bottom of text), then subtract the part below the // baseline. Note that fm.top is negative. textY = centerY + ((labelHeight - paint.descent()) / 2); canvas.translate(textX, textY); canvas.drawText(label, 0, label.length(), 0, 0, paint); } canvas.translate(-textX, -textY); // (-) // Turn off drop shadow paint.setShadowLayer(0, 0, 0, 0); } if (drawHintText) { if ((key.popupCharacters != null && key.popupCharacters.length() > 0) || (key.popupResId != 0) || (key.longPressCode != 0)) { Align oldAlign = paint.getTextAlign(); String hintText = null; if (key.hintLabel != null && key.hintLabel.length() > 0) { hintText = key.hintLabel.toString(); // it is the responsibility of the keyboard layout // designer to ensure that they do // not put too many characters in the hint label... } else if (key.longPressCode != 0) { if (Character.isLetterOrDigit(key.longPressCode)) hintText = Character.toString((char) key.longPressCode); } else if (key.popupCharacters != null) { final String hintString = key.popupCharacters.toString(); final int hintLength = hintString.length(); if (hintLength <= 3) hintText = hintString; } // if hintText is still null, it means it didn't fit one of // the above // cases, so we should provide the hint using the default if (hintText == null) { if (mHintOverflowLabel != null) hintText = mHintOverflowLabel; else { // theme does not provide a defaultHintLabel // use if hints are above, ... if hints are // below // (to avoid being too close to main label/icon) if (hintVAlign == Gravity.TOP) hintText = ""; else hintText = "..."; } } if (mKeyboard.isShifted()) hintText = hintText.toUpperCase(getKeyboard().getLocale()); // now draw hint paint.setTypeface(Typeface.DEFAULT); paint.setColor(hintColor.getColorForState(drawableState, 0xFF000000)); paint.setTextSize(mHintTextSize); // get the hint text font metrics so that we know the size // of the hint when // we try to position the main label (to try to make sure // they don't overlap) if (mHintTextFontMetrics == null) { mHintTextFontMetrics = paint.getFontMetrics(); } final float hintX; final float hintY; // the (float) 0.5 value is added or subtracted to just give // a little more room // in case the theme designer didn't account for the hint // label location if (hintAlign == Gravity.START) { // left paint.setTextAlign(Align.LEFT); hintX = mKeyBackgroundPadding.left + 0.5f; } else if (hintAlign == Gravity.CENTER) { // center paint.setTextAlign(Align.CENTER); hintX = mKeyBackgroundPadding.left + (key.width - mKeyBackgroundPadding.left - mKeyBackgroundPadding.right) / 2; } else { // right paint.setTextAlign(Align.RIGHT); hintX = key.width - mKeyBackgroundPadding.right - 0.5f; } if (hintVAlign == Gravity.TOP) { // above hintY = mKeyBackgroundPadding.top - mHintTextFontMetrics.top + 0.5f; } else { // below hintY = key.height - mKeyBackgroundPadding.bottom - mHintTextFontMetrics.bottom - 0.5f; } canvas.drawText(hintText, hintX, hintY, paint); paint.setTextAlign(oldAlign); } } canvas.translate(-key.x - kbdPaddingLeft, -key.y - kbdPaddingTop); } mInvalidatedKey = null; mDirtyRect.setEmpty(); }
From source file:com.chen.mail.ui.AbstractActivityController.java
/** * The application can be started from the following entry points: * <ul>/* w w w .j a v a2 s. c om*/ * <li>Launcher: you tap on the Gmail icon in the launcher. This is what most users think of * as Starting the app?.</li> * <li>Shortcut: Users can make a shortcut to take them directly to a label.</li> * <li>Widget: Shows the contents of a synced label, and allows: * <ul> * <li>Viewing the list (tapping on the title)</li> * <li>Composing a new message (tapping on the new message icon in the title. This * launches the {@link ComposeActivity}. * </li> * <li>Viewing a single message (tapping on a list element)</li> * </ul> * * </li> * <li>Tapping on a notification: * <ul> * <li>Shows message list if more than one message</li> * <li>Shows the conversation if the notification is for a single message</li> * </ul> * </li> * <li>...and most importantly, the activity life cycle can tear down the application and * restart it: * <ul> * <li>Rotate the application: it is destroyed and recreated.</li> * <li>Navigate away, and return from recent applications.</li> * </ul> * </li> * <li>Add a new account: fires off an intent to add an account, * and returns in {@link #onActivityResult(int, int, android.content.Intent)} .</li> * <li>Re-authenticate your account: again returns in onActivityResult().</li> * <li>Composing can happen from many entry points: third party applications fire off an * intent to compose email, and launch directly into the {@link ComposeActivity} * .</li> * </ul> * {@inheritDoc} */ @Override public boolean onCreate(Bundle savedState) { initializeActionBar(); initializeDevLoggingService(); // Allow shortcut keys to function for the ActionBar and menus. mActivity.setDefaultKeyMode(Activity.DEFAULT_KEYS_SHORTCUT); mResolver = mActivity.getContentResolver(); mNewEmailReceiver = new SuppressNotificationReceiver(); mRecentFolderList.initialize(mActivity); mVeiledMatcher.initialize(this); // the "open drawer description" argument is for when the drawer is open // so tell the user that interacting will cause the drawer to close // and vice versa for the "close drawer description" argument mDrawerToggle = new ActionBarDrawerToggle((Activity) mActivity, mDrawerContainer, R.drawable.ic_drawer, R.string.drawer_close, R.string.drawer_open); mDrawerListener = new MailDrawerListener(); mDrawerContainer.setDrawerListener(mDrawerListener); mDrawerContainer.setDrawerShadow(mContext.getResources().getDrawable(R.drawable.drawer_shadow), Gravity.START); mDrawerToggle.setDrawerIndicatorEnabled(isDrawerEnabled()); // All the individual UI components listen for ViewMode changes. This // simplifies the amount of logic in the AbstractActivityController, but increases the // possibility of timing-related bugs. mViewMode.addListener(this); mPagerController = new ConversationPagerController(mActivity, this); mToastBar = (ActionableToastBar) mActivity.findViewById(R.id.toast_bar); attachActionBar(); FolderSelectionDialog.setDialogDismissed(); mDrawIdler.setRootView(mActivity.getWindow().getDecorView()); final Intent intent = mActivity.getIntent(); // Immediately handle a clean launch with intent, and any state restoration // that does not rely on restored fragments or loader data // any state restoration that relies on those can be done later in // onRestoreInstanceState, once fragments are up and loader data is re-delivered if (savedState != null) { if (savedState.containsKey(SAVED_ACCOUNT)) { setAccount((Account) savedState.getParcelable(SAVED_ACCOUNT)); } if (savedState.containsKey(SAVED_FOLDER)) { final Folder folder = savedState.getParcelable(SAVED_FOLDER); final String query = savedState.getString(SAVED_QUERY, null); setListContext(folder, query); } if (savedState.containsKey(SAVED_ACTION)) { mDialogAction = savedState.getInt(SAVED_ACTION); } mDialogFromSelectedSet = savedState.getBoolean(SAVED_ACTION_FROM_SELECTED, false); mViewMode.handleRestore(savedState); } else if (intent != null) { handleIntent(intent); } // Create the accounts loader; this loads the account switch spinner. mActivity.getLoaderManager().initLoader(LOADER_ACCOUNT_CURSOR, Bundle.EMPTY, mAccountCallbacks); return true; }
From source file:com.zyk.launcher.AsyncTaskCallback.java
/** * Widget// ww w . j a v a2 s . c o m * @param page * @param immediate */ public void syncWidgetPageItems(final int page, final boolean immediate) { int numItemsPerPage = mWidgetCountX * mWidgetCountY; final PagedViewGridLayout layout = (PagedViewGridLayout) getPageAt(page); // Calculate the dimensions of each cell we are giving to each widget final ArrayList<Object> items = new ArrayList<Object>(); int contentWidth = mContentWidth - layout.getPaddingLeft() - layout.getPaddingRight(); final int cellWidth = contentWidth / mWidgetCountX; int contentHeight = mContentHeight - layout.getPaddingTop() - layout.getPaddingBottom(); final int cellHeight = contentHeight / mWidgetCountY; // Prepare the set of widgets to load previews for in the background int offset = page * numItemsPerPage; for (int i = offset; i < Math.min(offset + numItemsPerPage, mWidgets.size()); ++i) { items.add(mWidgets.get(i)); } // Prepopulate the pages with the other widget info, and fill in the previews later layout.setColumnCount(layout.getCellCountX()); for (int i = 0; i < items.size(); ++i) { Object rawInfo = items.get(i); PendingAddItemInfo createItemInfo = null; PagedViewWidget widget = (PagedViewWidget) mLayoutInflater.inflate(R.layout.apps_customize_widget, layout, false); if (rawInfo instanceof AppWidgetProviderInfo) { // Fill in the widget information AppWidgetProviderInfo info = (AppWidgetProviderInfo) rawInfo; createItemInfo = new PendingAddWidgetInfo(info, null, null); // Determine the widget spans and min resize spans. int[] spanXY = Launcher.getSpanForWidget(mLauncher, info); createItemInfo.spanX = spanXY[0]; createItemInfo.spanY = spanXY[1]; int[] minSpanXY = Launcher.getMinSpanForWidget(mLauncher, info); createItemInfo.minSpanX = minSpanXY[0]; createItemInfo.minSpanY = minSpanXY[1]; widget.applyFromAppWidgetProviderInfo(info, -1, spanXY, getWidgetPreviewLoader()); widget.setTag(createItemInfo); widget.setShortPressListener(this); } else if (rawInfo instanceof ResolveInfo) { // Fill in the shortcuts information ResolveInfo info = (ResolveInfo) rawInfo; createItemInfo = new PendingAddShortcutInfo(info.activityInfo); createItemInfo.itemType = LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT; createItemInfo.componentName = new ComponentName(info.activityInfo.packageName, info.activityInfo.name); widget.applyFromResolveInfo(mPackageManager, info, getWidgetPreviewLoader()); widget.setTag(createItemInfo); } widget.setOnClickListener(this); widget.setOnLongClickListener(this); widget.setOnTouchListener(this); widget.setOnKeyListener(this); // Layout each widget int ix = i % mWidgetCountX; int iy = i / mWidgetCountX; if (ix > 0) { View border = widget.findViewById(R.id.left_border); border.setVisibility(View.VISIBLE); } if (ix < mWidgetCountX - 1) { View border = widget.findViewById(R.id.right_border); border.setVisibility(View.VISIBLE); } GridLayout.LayoutParams lp = new GridLayout.LayoutParams(GridLayout.spec(iy, GridLayout.START), GridLayout.spec(ix, GridLayout.TOP)); lp.width = cellWidth; lp.height = cellHeight; lp.setGravity(Gravity.TOP | Gravity.START); layout.addView(widget, lp); } // wait until a call on onLayout to start loading, because // PagedViewWidget.getPreviewSize() will return 0 if it hasn't been laid out // TODO: can we do a measure/layout immediately? layout.setOnLayoutListener(new Runnable() { public void run() { // Load the widget previews int maxPreviewWidth = cellWidth; int maxPreviewHeight = cellHeight; if (layout.getChildCount() > 0) { PagedViewWidget w = (PagedViewWidget) layout.getChildAt(0); int[] maxSize = w.getPreviewSize(); maxPreviewWidth = maxSize[0]; maxPreviewHeight = maxSize[1]; } getWidgetPreviewLoader().setPreviewSize(maxPreviewWidth, maxPreviewHeight, mWidgetSpacingLayout); if (immediate) { AsyncTaskPageData data = new AsyncTaskPageData(page, items, maxPreviewWidth, maxPreviewHeight, null, null, getWidgetPreviewLoader()); loadWidgetPreviewsInBackground(null, data); onSyncWidgetPageItems(data, immediate); } else { if (mInTransition) { mDeferredPrepareLoadWidgetPreviewsTasks.add(this); } else { prepareLoadWidgetPreviewsTask(page, items, maxPreviewWidth, maxPreviewHeight, mWidgetCountX); } } layout.setOnLayoutListener(null); } }); }