List of usage examples for android.view Gravity TOP
int TOP
To view the source code for android.view Gravity TOP.
Click Source Link
From source file:android.support.wear.widget.drawer.WearableDrawerLayout.java
/** * Closes drawer after {@code delayMs} milliseconds. *//*from www . j a v a 2s .c om*/ private void closeDrawerDelayed(final int gravity, long delayMs) { switch (gravity) { case Gravity.TOP: mMainThreadHandler.removeCallbacks(mCloseTopPeekRunnable); mMainThreadHandler.postDelayed(mCloseTopPeekRunnable, delayMs); break; case Gravity.BOTTOM: mMainThreadHandler.removeCallbacks(mCloseBottomPeekRunnable); mMainThreadHandler.postDelayed(mCloseBottomPeekRunnable, delayMs); break; default: Log.w(TAG, "Invoked a delayed drawer close with an invalid gravity: " + gravity); } }
From source file:com.hippo.nimingban.ui.ListActivity.java
private void showToolbarGuide() { new GuideHelper.Builder(this).setColor(ResourcesUtils.getAttrColor(this, R.attr.colorPrimary)) .setPadding(LayoutUtils.dp2pix(this, 16)).setMessagePosition(Gravity.TOP) .setMessage(getString(R.string.double_click_toolbar_refresh)).setButton(getString(R.string.get_it)) .setBackgroundColor(0x73000000).setOnDissmisListener(new View.OnClickListener() { @Override//w w w . j av a 2s . c o m public void onClick(View v) { Settings.putGuideListActivity(false); } }).show(); }
From source file:android.support.design.widget.CollapsingTextHelper.java
private void calculateBaseOffsets() { final float currentTextSize = mCurrentTextSize; // We then calculate the collapsed text size, using the same logic calculateUsingTextSize(mCollapsedTextSize); float width = mTextToDraw != null ? mTextPaint.measureText(mTextToDraw, 0, mTextToDraw.length()) : 0; final int collapsedAbsGravity = GravityCompat.getAbsoluteGravity(mCollapsedTextGravity, mIsRtl ? ViewCompat.LAYOUT_DIRECTION_RTL : ViewCompat.LAYOUT_DIRECTION_LTR); switch (collapsedAbsGravity & Gravity.VERTICAL_GRAVITY_MASK) { case Gravity.BOTTOM: mCollapsedDrawY = mCollapsedBounds.bottom; break;//from w w w . java 2 s . com case Gravity.TOP: mCollapsedDrawY = mCollapsedBounds.top - mTextPaint.ascent(); break; case Gravity.CENTER_VERTICAL: default: float textHeight = mTextPaint.descent() - mTextPaint.ascent(); float textOffset = (textHeight / 2) - mTextPaint.descent(); mCollapsedDrawY = mCollapsedBounds.centerY() + textOffset; break; } switch (collapsedAbsGravity & GravityCompat.RELATIVE_HORIZONTAL_GRAVITY_MASK) { case Gravity.CENTER_HORIZONTAL: mCollapsedDrawX = mCollapsedBounds.centerX() - (width / 2); break; case Gravity.RIGHT: mCollapsedDrawX = mCollapsedBounds.right - width; break; case Gravity.LEFT: default: mCollapsedDrawX = mCollapsedBounds.left; break; } calculateUsingTextSize(mExpandedTextSize); width = mTextToDraw != null ? mTextPaint.measureText(mTextToDraw, 0, mTextToDraw.length()) : 0; final int expandedAbsGravity = GravityCompat.getAbsoluteGravity(mExpandedTextGravity, mIsRtl ? ViewCompat.LAYOUT_DIRECTION_RTL : ViewCompat.LAYOUT_DIRECTION_LTR); switch (expandedAbsGravity & Gravity.VERTICAL_GRAVITY_MASK) { case Gravity.BOTTOM: mExpandedDrawY = mExpandedBounds.bottom; break; case Gravity.TOP: mExpandedDrawY = mExpandedBounds.top - mTextPaint.ascent(); break; case Gravity.CENTER_VERTICAL: default: float textHeight = mTextPaint.descent() - mTextPaint.ascent(); float textOffset = (textHeight / 2) - mTextPaint.descent(); mExpandedDrawY = mExpandedBounds.centerY() + textOffset; break; } switch (expandedAbsGravity & GravityCompat.RELATIVE_HORIZONTAL_GRAVITY_MASK) { case Gravity.CENTER_HORIZONTAL: mExpandedDrawX = mExpandedBounds.centerX() - (width / 2); break; case Gravity.RIGHT: mExpandedDrawX = mExpandedBounds.right - width; break; case Gravity.LEFT: default: mExpandedDrawX = mExpandedBounds.left; break; } // The bounds have changed so we need to clear the texture clearTexture(); // Now reset the text size back to the original setInterpolatedTextSize(currentTextSize); }
From source file:com.sonvp.tooltip.Tooltip.java
@Override public boolean onPreDraw() { container.getViewTreeObserver().removeOnPreDrawListener(this); Context context = container.getContext(); if (!(context instanceof Activity)) { return false; }//from w w w . j a v a2s .com DisplayMetrics displayMetrics = new DisplayMetrics(); ((Activity) context).getWindowManager().getDefaultDisplay().getMetrics(displayMetrics); int displayWidth = displayMetrics.widthPixels; int displayHeight = displayMetrics.heightPixels; int displayTop = getStatusBarHeight(); int anchorTop = rectAnchorView.top; int anchorLeft = rectAnchorView.left; int anchorWidth = anchorView.getWidth(); int anchorHeight = anchorView.getHeight(); int textWidth = viewTooltip.getWidth(); //default height 1 line int textHeight = viewTooltip.getHeight(); int arrowWidth = arrow.getWidth(); int arrowHeight = arrow.getHeight(); int widthMeasureSpec = View.MeasureSpec.makeMeasureSpec(displayWidth, View.MeasureSpec.AT_MOST); int heightMeasureSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED); if (gravity == Gravity.TOP || gravity == Gravity.BOTTOM) { int width = Math.max(textWidth, arrowWidth); int height = textHeight + arrowHeight; int leftPadding; int topPadding; if (gravity == Gravity.TOP) { topPadding = anchorTop - height; } else { // gravity == Gravity.BOTTOM topPadding = anchorTop + anchorHeight; } int anchorHorizontalCenter = anchorLeft + anchorWidth / 2; int left = anchorHorizontalCenter - width / 2; int right = left + width; leftPadding = Math.max(0, right > displayWidth ? displayWidth - width : left); ViewGroup.MarginLayoutParams layoutParams = (ViewGroup.MarginLayoutParams) arrow.getLayoutParams(); layoutParams.leftMargin = anchorHorizontalCenter - leftPadding - arrowWidth / 2; arrow.setLayoutParams(layoutParams); popupWindow.update(leftPadding, topPadding, container.getWidth(), container.getHeight()); pivotX = width / 2; pivotY = gravity == Gravity.TOP ? height : 0; } else { // gravity == Gravity.LEFT || gravity == Gravity.RIGHT int width = textWidth + arrowWidth; int leftPadding; int topPadding; int rightPadding = 0; if (gravity == Gravity.LEFT) { leftPadding = Math.max(0, anchorLeft - width); leftPadding += (int) builder.toolTipMargin; rightPadding = displayWidth - anchorLeft; } else { // gravity == Gravity.RIGHT leftPadding = anchorLeft + anchorWidth; rightPadding = (int) builder.toolTipMargin; } if (viewTooltip instanceof TextView) { TextView text = (TextView) viewTooltip; text.setMaxWidth(displayWidth - rightPadding - leftPadding - arrowWidth); viewTooltip.measure(widthMeasureSpec, heightMeasureSpec); textHeight = viewTooltip.getMeasuredHeight(); // height multi line } int height = Math.max(textHeight, arrowHeight); int anchorVerticalCenter = anchorTop + anchorHeight / 2; int top = anchorVerticalCenter - height / 2; int bottom = top + height; if (builder.arrowGravity == Gravity.TOP) { top = anchorTop; bottom = anchorTop + height; } else if (builder.arrowGravity == Gravity.BOTTOM) { top = anchorTop + anchorHeight - height; } topPadding = Math.max(0, bottom > displayHeight ? displayHeight - height - (int) builder.toolTipMargin : top); topPadding = Math.max(0, topPadding < displayTop ? displayTop + (int) builder.toolTipMargin : topPadding); container.measure(widthMeasureSpec, heightMeasureSpec); int popupWidth = container.getMeasuredWidth(); int popupHeight = container.getMeasuredHeight(); popupWindow.update(leftPadding, topPadding, popupWidth, popupHeight); ViewGroup.MarginLayoutParams layoutParams = (ViewGroup.MarginLayoutParams) arrow.getLayoutParams(); layoutParams.topMargin = anchorVerticalCenter - topPadding - arrowHeight / 2; arrow.setLayoutParams(layoutParams); pivotX = gravity == Gravity.LEFT ? popupWidth : 0; pivotY = anchorVerticalCenter - topPadding; } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR1) { container.setAlpha(0.0F); container.setPivotX(pivotX); container.setPivotY(pivotY); container.setScaleX(0.0F); container.setScaleY(0.0F); container.animate().setDuration(ANIMATION_DURATION).scaleX(1.0F).scaleY(1.0F).alpha(1.0F); } else { AnimationSet animationSet = new AnimationSet(true); animationSet.setDuration(ANIMATION_DURATION); animationSet.addAnimation(new AlphaAnimation(0.0F, 1.0F)); animationSet.addAnimation(new ScaleAnimation(0.0F, 1.0F, 0.0F, 1.0F, pivotX, pivotY)); container.startAnimation(animationSet); } return false; }
From source file:com.aries.ui.view.title.util.CollapsingTextHelper.java
private void calculateBaseOffsets() { final float currentTextSize = mCurrentTextSize; // We then calculate the collapsed text size, using the same logic calculateUsingTextSize(mCollapsedTextSize); float width = mTextToDraw != null ? mTextPaint.measureText(mTextToDraw, 0, mTextToDraw.length()) : 0; final int collapsedAbsGravity = GravityCompat.getAbsoluteGravity(mCollapsedTextGravity, mIsRtl ? ViewCompat.LAYOUT_DIRECTION_RTL : ViewCompat.LAYOUT_DIRECTION_LTR); switch (collapsedAbsGravity & Gravity.VERTICAL_GRAVITY_MASK) { case Gravity.BOTTOM: mCollapsedDrawY = mCollapsedBounds.bottom - mTextPaint.descent(); break;/*w w w . ja va 2s .c om*/ case Gravity.TOP: mCollapsedDrawY = mCollapsedBounds.top - mTextPaint.ascent(); break; case Gravity.CENTER_VERTICAL: default: float textHeight = mTextPaint.descent() - mTextPaint.ascent(); float textOffset = (textHeight / 2) - mTextPaint.descent(); mCollapsedDrawY = mCollapsedBounds.centerY() + textOffset; break; } switch (collapsedAbsGravity & GravityCompat.RELATIVE_HORIZONTAL_GRAVITY_MASK) { case Gravity.CENTER_HORIZONTAL: mCollapsedDrawX = mCollapsedBounds.centerX() - (width / 2); break; case Gravity.RIGHT: mCollapsedDrawX = mCollapsedBounds.right - width; break; case Gravity.LEFT: default: mCollapsedDrawX = mCollapsedBounds.left; break; } calculateUsingTextSize(mExpandedTextSize); width = mTextToDraw != null ? mTextPaint.measureText(mTextToDraw, 0, mTextToDraw.length()) : 0; final int expandedAbsGravity = GravityCompat.getAbsoluteGravity(mExpandedTextGravity, mIsRtl ? ViewCompat.LAYOUT_DIRECTION_RTL : ViewCompat.LAYOUT_DIRECTION_LTR); switch (expandedAbsGravity & Gravity.VERTICAL_GRAVITY_MASK) { case Gravity.BOTTOM: mExpandedDrawY = mExpandedBounds.bottom - mTextPaint.descent(); break; case Gravity.TOP: mExpandedDrawY = mExpandedBounds.top - mTextPaint.ascent(); break; case Gravity.CENTER_VERTICAL: default: float textHeight = mTextPaint.descent() - mTextPaint.ascent(); float textOffset = (textHeight / 2) - mTextPaint.descent(); mExpandedDrawY = mExpandedBounds.centerY() + textOffset; break; } switch (expandedAbsGravity & GravityCompat.RELATIVE_HORIZONTAL_GRAVITY_MASK) { case Gravity.CENTER_HORIZONTAL: mExpandedDrawX = mExpandedBounds.centerX() - (width / 2); break; case Gravity.RIGHT: mExpandedDrawX = mExpandedBounds.right - width; break; case Gravity.LEFT: default: mExpandedDrawX = mExpandedBounds.left; break; } // The bounds have changed so we need to clear the texture clearTexture(); // Now reset the text size back to the original setInterpolatedTextSize(currentTextSize); }
From source file:com.jakewharton.behavior.drawer.BehaviorDelegate.java
boolean onLayoutChild() { int width = parent.getMeasuredWidth(); int height = parent.getMeasuredHeight(); int childWidth = child.getMeasuredWidth(); int childHeight = child.getMeasuredHeight(); int childLeft; float newOffset; if (isLeft) { childLeft = -childWidth + (int) (childWidth * onScreen); newOffset = (float) (childWidth + childLeft) / childWidth; } else {/*from ww w .j a v a 2 s. c o m*/ childLeft = width - (int) (childWidth * onScreen); newOffset = (float) (width - childLeft) / childWidth; } boolean changeOffset = newOffset != onScreen; CoordinatorLayout.LayoutParams lp = (CoordinatorLayout.LayoutParams) child.getLayoutParams(); int vgrav = lp.gravity & Gravity.VERTICAL_GRAVITY_MASK; switch (vgrav) { default: case Gravity.TOP: { child.layout(childLeft, lp.topMargin, childLeft + childWidth, lp.topMargin + childHeight); break; } case Gravity.BOTTOM: { child.layout(childLeft, height - lp.bottomMargin - child.getMeasuredHeight(), childLeft + childWidth, height - lp.bottomMargin); break; } case Gravity.CENTER_VERTICAL: { int childTop = (height - childHeight) / 2; // Offset for margins. If things don't fit right because of // bad measurement before, oh well. if (childTop < lp.topMargin) { childTop = lp.topMargin; } else if (childTop + childHeight > height - lp.bottomMargin) { childTop = height - lp.bottomMargin - childHeight; } child.layout(childLeft, childTop, childLeft + childWidth, childTop + childHeight); break; } } if (changeOffset) { setDrawerViewOffset(newOffset); } int newVisibility = onScreen > 0 ? VISIBLE : INVISIBLE; if (child.getVisibility() != newVisibility) { child.setVisibility(newVisibility); } return true; }
From source file:android.support.design.widget.TextInputLayout.java
private void setEditText(EditText editText) { // If we already have an EditText, throw an exception if (mEditText != null) { throw new IllegalArgumentException("We already have an EditText, can only have one"); }/* w ww . j a v a 2 s .c om*/ if (!(editText instanceof TextInputEditText)) { Log.i(LOG_TAG, "EditText added is not a TextInputEditText. Please switch to using that" + " class instead."); } mEditText = editText; final boolean hasPasswordTransformation = hasPasswordTransformation(); // Use the EditText's typeface, and it's text size for our expanded text if (!hasPasswordTransformation) { // We don't want a monospace font just because we have a password field mCollapsingTextHelper.setTypefaces(mEditText.getTypeface()); } mCollapsingTextHelper.setExpandedTextSize(mEditText.getTextSize()); final int editTextGravity = mEditText.getGravity(); mCollapsingTextHelper .setCollapsedTextGravity(Gravity.TOP | (editTextGravity & ~Gravity.VERTICAL_GRAVITY_MASK)); mCollapsingTextHelper.setExpandedTextGravity(editTextGravity); // Add a TextWatcher so that we know when the text input has changed mEditText.addTextChangedListener(new TextWatcher() { @Override public void afterTextChanged(Editable s) { updateLabelState(!mRestoringSavedState); if (mCounterEnabled) { updateCounter(s.length()); } } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } }); // Use the EditText's hint colors if we don't have one set if (mDefaultTextColor == null) { mDefaultTextColor = mEditText.getHintTextColors(); } // If we do not have a valid hint, try and retrieve it from the EditText, if enabled if (mHintEnabled && TextUtils.isEmpty(mHint)) { setHint(mEditText.getHint()); // Clear the EditText's hint as we will display it ourselves mEditText.setHint(null); } if (mCounterView != null) { updateCounter(mEditText.getText().length()); } if (mIndicatorArea != null) { adjustIndicatorPadding(); } updatePasswordToggleView(); // Update the label visibility with no animation, but force a state change updateLabelState(false, true); }
From source file:com.qa.perf.emmageeplus.service.EmmageeService.java
/** * create a floating window to show real-time data. *//*www . j a v a 2 s. c o m*/ private void createFloatingWindow() { getSharedPreferences("float_flag", Activity.MODE_PRIVATE).edit().putInt("float", 1).apply(); windowManager = (WindowManager) getApplicationContext().getSystemService(Context.WINDOW_SERVICE); wmParams = ((MyApplication) getApplication()).getMywmParams(); wmParams.type = WindowManager.LayoutParams.TYPE_PHONE; wmParams.flags |= 8; wmParams.gravity = Gravity.START | Gravity.TOP; wmParams.x = 0; wmParams.y = 0; wmParams.width = WindowManager.LayoutParams.WRAP_CONTENT; wmParams.height = WindowManager.LayoutParams.WRAP_CONTENT; wmParams.format = 1; windowManager.addView(viFloatingWindow, wmParams); viFloatingWindow.setOnTouchListener(new OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { x = event.getRawX(); y = event.getRawY() - statusBarHeight; switch (event.getAction()) { case MotionEvent.ACTION_DOWN: mTouchStartX = event.getX(); mTouchStartY = event.getY(); break; case MotionEvent.ACTION_MOVE: updateViewPosition(); break; case MotionEvent.ACTION_UP: updateViewPosition(); mTouchStartX = mTouchStartY = 0; break; } return true; } }); btnWifi.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { try { btnWifi = (Button) viFloatingWindow.findViewById(R.id.wifi); String buttonText = (String) btnWifi.getText(); String wifiText = getResources().getString(R.string.open_wifi); if (buttonText.equals(wifiText)) { wifiManager.setWifiEnabled(true); btnWifi.setText(R.string.close_wifi); } else { wifiManager.setWifiEnabled(false); btnWifi.setText(R.string.open_wifi); } } catch (Exception e) { Toast.makeText(viFloatingWindow.getContext(), getString(R.string.wifi_fail_toast), Toast.LENGTH_LONG).show(); Log.e(LOG_TAG, e.toString()); } } }); }
From source file:com.aidy.bottomdrawerlayout.AllDrawerLayout.java
/** * Enable or disable interaction with all drawers. * /*from www.jav a 2 s.c om*/ * <p> * This allows the application to restrict the user's ability to open or * close any drawer within this layout. DrawerLayout will still respond to * calls to {@link #openDrawer(int)}, {@link #closeDrawer(int)} and friends * if a drawer is locked. * </p> * * <p> * Locking drawers open or closed will implicitly open or close any drawers * as appropriate. * </p> * * @param lockMode * The new lock mode for the given drawer. One of * {@link #LOCK_MODE_UNLOCKED}, {@link #LOCK_MODE_LOCKED_CLOSED} * or {@link #LOCK_MODE_LOCKED_OPEN}. */ public void setDrawerLockMode(int lockMode) { setDrawerLockMode(lockMode, Gravity.LEFT); setDrawerLockMode(lockMode, Gravity.RIGHT); setDrawerLockMode(lockMode, Gravity.TOP); setDrawerLockMode(lockMode, Gravity.BOTTOM); }
From source file:com.example.verticaldrawerlayout.VerticalDrawerLayout.java
/** * Enable or disable interaction with the given drawer. * /* w w w . ja v a 2s. c o m*/ * <p> * This allows the application to restrict the user's ability to open or * close the given drawer. DrawerLayout will still respond to calls to * {@link #openDrawer(int)}, {@link #closeDrawer(int)} and friends if a * drawer is locked. * </p> * * <p> * Locking a drawer open or closed will implicitly open or close that drawer * as appropriate. * </p> * * @param lockMode * The new lock mode for the given drawer. One of * {@link #LOCK_MODE_UNLOCKED}, {@link #LOCK_MODE_LOCKED_CLOSED} * or {@link #LOCK_MODE_LOCKED_OPEN}. * @param edgeGravity * Gravity.LEFT, RIGHT, START or END. * Expresses which drawer to change the mode for. * * @see #LOCK_MODE_UNLOCKED * @see #LOCK_MODE_LOCKED_CLOSED * @see #LOCK_MODE_LOCKED_OPEN */ public void setDrawerLockMode(int lockMode, int edgeGravity) { final int absGravity = GravityCompat.getAbsoluteGravity(edgeGravity, ViewCompat.getLayoutDirection(this)); if (absGravity == Gravity.TOP) { mLockModeTop = lockMode; } else if (absGravity == Gravity.BOTTOM) { mLockModeBottom = lockMode; } if (lockMode != LOCK_MODE_UNLOCKED) { // Cancel interaction in progress final ViewDragHelper helper = absGravity == Gravity.TOP ? mTopDragger : mBottomDragger; helper.cancel(); } switch (lockMode) { case LOCK_MODE_LOCKED_OPEN: final View toOpen = findDrawerWithGravity(absGravity); if (toOpen != null) { openDrawer(toOpen); } break; case LOCK_MODE_LOCKED_CLOSED: final View toClose = findDrawerWithGravity(absGravity); if (toClose != null) { closeDrawer(toClose); } break; // default: do nothing } }