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:com.edible.ocr.CaptureActivity.java
/** * Displays information relating to the result of OCR, and requests a translation if necessary. * /*from w ww . ja va 2 s.c o m*/ * @param ocrResult Object representing successful OCR results * @return True if a non-null result was received for OCR */ boolean handleOcrDecode(OcrResult ocrResult) { lastResult = ocrResult; // Test whether the result is null if (ocrResult.getText() == null || ocrResult.getText().equals("")) { Toast toast = Toast.makeText(this, "OCR failed. Please try again.", Toast.LENGTH_SHORT); toast.setGravity(Gravity.TOP, 0, 0); toast.show(); return false; } // Turn off capture-related UI elements shutterButton.setVisibility(View.GONE); statusViewBottom.setVisibility(View.GONE); statusViewTop.setVisibility(View.GONE); cameraButtonView.setVisibility(View.GONE); viewfinderView.setVisibility(View.GONE); resultView.setVisibility(View.VISIBLE); ImageView bitmapImageView = (ImageView) findViewById(R.id.image_view); lastBitmap = ocrResult.getBitmap(); if (lastBitmap == null) { bitmapImageView.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher)); } else { bitmapImageView.setImageBitmap(lastBitmap); } // Display the recognized text TextView sourceLanguageTextView = (TextView) findViewById(R.id.source_language_text_view); sourceLanguageTextView.setText(sourceLanguageReadable); TextView ocrResultTextView = (TextView) findViewById(R.id.ocr_result_text_view); ocrResultTextView.setText(stripNoise(ocrResult.getText())); // Crudely scale betweeen 22 and 32 -- bigger font for shorter text int scaledSize = Math.max(22, 32 - ocrResult.getText().length() / 4); ocrResultTextView.setTextSize(TypedValue.COMPLEX_UNIT_SP, scaledSize); TextView translationLanguageLabelTextView = (TextView) findViewById( R.id.translation_language_label_text_view); TextView translationLanguageTextView = (TextView) findViewById(R.id.translation_language_text_view); TextView translationTextView = (TextView) findViewById(R.id.translation_text_view); if (isTranslationActive) { // Handle translation text fields translationLanguageLabelTextView.setVisibility(View.VISIBLE); translationLanguageTextView.setText(targetLanguageReadable); translationLanguageTextView.setTypeface(Typeface.defaultFromStyle(Typeface.NORMAL), Typeface.NORMAL); translationLanguageTextView.setVisibility(View.VISIBLE); // Activate/re-activate the indeterminate progress indicator translationTextView.setVisibility(View.GONE); progressView.setVisibility(View.VISIBLE); setProgressBarVisibility(true); // Get the translation asynchronously new TranslateAsyncTask(this, sourceLanguageCodeTranslation, targetLanguageCodeTranslation, stripNoise(ocrResult.getText())).execute(); } else { translationLanguageLabelTextView.setVisibility(View.GONE); translationLanguageTextView.setVisibility(View.GONE); translationTextView.setVisibility(View.GONE); progressView.setVisibility(View.GONE); setProgressBarVisibility(false); } return true; }
From source file:com.actionbarsherlock.custom.widget.VerticalDrawerLayout.java
/** * Close the specified drawer view by animating it into view. * * @param drawerView Drawer view to close *///from ww w .j a v a 2 s . c om public void closeDrawer(View drawerView) { if (!isDrawerView(drawerView)) { throw new IllegalArgumentException("View " + drawerView + " is not a sliding drawer"); } if (mFirstLayout) { final LayoutParams lp = (LayoutParams) drawerView.getLayoutParams(); lp.onScreen = 0.f; lp.knownOpen = false; } else { if (checkDrawerViewGravity(drawerView, Gravity.TOP)) { mTopDragger.smoothSlideViewTo(drawerView, drawerView.getLeft(), -drawerView.getHeight()); } else { mBottomDragger.smoothSlideViewTo(drawerView, drawerView.getLeft(), getHeight()); } } invalidate(); }
From source file:com.aidy.bottomdrawerlayout.AllDrawerLayout.java
@Override protected boolean drawChild(Canvas canvas, View child, long drawingTime) { Log.i(TAG, "drawChild()"); final int height = getHeight(); final boolean drawingContent = isContentView(child); int clipLeft = 0, clipRight = getWidth(); int clipTop = 0, clipBottom = getHeight(); final int restoreCount = canvas.save(); if (drawingContent) { final int childCount = getChildCount(); for (int i = 0; i < childCount; i++) { final View v = getChildAt(i); if (v == child || v.getVisibility() != VISIBLE || !hasOpaqueBackground(v) || !isDrawerView(v) || v.getHeight() < height) { Log.i(TAG, "drawChild() -- 0"); continue; }//from w w w. jav a2 s . c o m switch (getDrawerViewAbsoluteGravity(v)) { case Gravity.LEFT: Log.i(TAG, "drawChild() -- 1"); if (checkDrawerViewAbsoluteGravity(v, Gravity.LEFT)) { final int vright = v.getRight(); if (vright > clipLeft) clipLeft = vright; } break; case Gravity.RIGHT: Log.i(TAG, "drawChild() -- 2"); if (checkDrawerViewAbsoluteGravity(v, Gravity.RIGHT)) { final int vleft = v.getLeft(); if (vleft < clipRight) clipRight = vleft; } break; case Gravity.TOP: Log.i(TAG, "drawChild() -- 3"); if (checkDrawerViewAbsoluteGravity(v, Gravity.TOP)) { final int vbottom = v.getBottom(); if (vbottom > clipTop) { clipTop = vbottom; } } break; case Gravity.BOTTOM: Log.i(TAG, "drawChild() -- 4"); if (checkDrawerViewAbsoluteGravity(v, Gravity.BOTTOM)) { final int vtop = v.getTop(); if (vtop < clipBottom) { clipBottom = vtop; } } break; default: Log.i(TAG, "drawChild() -- 5"); final int vtop = v.getTop(); if (vtop < clipBottom) { clipBottom = vtop; } break; } } canvas.clipRect(clipLeft, clipTop, clipRight, clipBottom); } final boolean result = super.drawChild(canvas, child, drawingTime); canvas.restoreToCount(restoreCount); if (mScrimOpacity > 0 && drawingContent) { Log.i(TAG, "drawChild() -- drawingContent"); final int baseAlpha = (mScrimColor & 0xff000000) >>> 24; final int imag = (int) (baseAlpha * mScrimOpacity); final int color = imag << 24 | (mScrimColor & 0xffffff); mScrimPaint.setColor(color); canvas.drawRect(clipLeft, clipTop, clipRight, clipBottom, mScrimPaint); } else if (mShadowLeft != null && checkDrawerViewAbsoluteGravity(child, Gravity.LEFT)) { Log.i(TAG, "drawChild() -- LEFT"); final int shadowWidth = mShadowLeft.getIntrinsicWidth(); final int childRight = child.getRight(); final int drawerPeekDistance = mLeftDragger.getEdgeSize(); final float alpha = Math.max(0, Math.min((float) childRight / drawerPeekDistance, 1.f)); mShadowLeft.setBounds(childRight, child.getTop(), childRight + shadowWidth, child.getBottom()); mShadowLeft.setAlpha((int) (0xff * alpha)); mShadowLeft.draw(canvas); } else if (mShadowRight != null && checkDrawerViewAbsoluteGravity(child, Gravity.RIGHT)) { Log.i(TAG, "drawChild() -- Gravity.RIGHT"); final int shadowWidth = mShadowRight.getIntrinsicWidth(); final int childLeft = child.getLeft(); final int showing = getWidth() - childLeft; final int drawerPeekDistance = mRightDragger.getEdgeSize(); final float alpha = Math.max(0, Math.min((float) showing / drawerPeekDistance, 1.f)); mShadowRight.setBounds(childLeft - shadowWidth, child.getTop(), childLeft, child.getBottom()); mShadowRight.setAlpha((int) (0xff * alpha)); mShadowRight.draw(canvas); } else if (mShadowTop != null && checkDrawerViewAbsoluteGravity(child, Gravity.TOP)) { Log.i(TAG, "drawChild() -- Gravity.TOP"); final int shadowHeight = mShadowTop.getIntrinsicHeight(); final int childBottom = child.getBottom(); final int drawerPeekDistance = mTopDragger.getEdgeSize(); final float alpha = Math.max(0, Math.min((float) childBottom / drawerPeekDistance, 1.f)); mShadowTop.setBounds(child.getLeft(), childBottom, child.getRight(), childBottom + shadowHeight); mShadowTop.setAlpha((int) (0xff * alpha)); mShadowTop.draw(canvas); } else if (mShadowBottom != null && checkDrawerViewAbsoluteGravity(child, Gravity.BOTTOM)) { Log.i(TAG, "drawChild() -- Gravity.BOTTOM"); final int shadowHeight = mShadowBottom.getIntrinsicWidth(); final int childTop = child.getTop(); final int showing = getHeight() - childTop; final int drawerPeekDistance = mBottomDragger.getEdgeSize(); final float alpha = Math.max(0, Math.min((float) showing / drawerPeekDistance, 1.f)); mShadowRight.setBounds(child.getLeft(), childTop - shadowHeight, child.getRight(), childTop); mShadowRight.setAlpha((int) (0xff * alpha)); mShadowRight.draw(canvas); } return result; }
From source file:apps.junkuvo.alertapptowalksafely.MainActivity.java
public void setRadioGroupInLayout(View layout) { RadioGroup radioGroup = (RadioGroup) layout.findViewById(R.id.radiogroup); RadioButton radioButtonTop = (RadioButton) layout.findViewById(R.id.radiobutton_top); RadioButton radioButtonCenter = (RadioButton) layout.findViewById(R.id.radiobutton_center); RadioButton radioButtonButton = (RadioButton) layout.findViewById(R.id.radiobutton_bottom); switch (mToastPosition) { case Gravity.TOP: radioButtonTop.setChecked(true); break;/* w w w . j ava 2 s . c o m*/ case Gravity.CENTER: radioButtonCenter.setChecked(true); break; case Gravity.BOTTOM: radioButtonButton.setChecked(true); break; } radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup group, int checkedId) { switch (checkedId) { case R.id.radiobutton_top: mToastPosition = Gravity.TOP; break; case R.id.radiobutton_center: mToastPosition = Gravity.CENTER; if (mAlertService != null) { mAlertService.setToastPosition(Gravity.CENTER); } break; case R.id.radiobutton_bottom: mToastPosition = Gravity.BOTTOM; break; } if (mAlertService != null && mAlertService.isBoundService()) { mAlertService.setToastPosition(mToastPosition); } } }); }
From source file:com.android.incallui.widget.multiwaveview.GlowPadView.java
private void computeInsets(int dx, int dy) { final int layoutDirection = getLayoutDirection(); final int absoluteGravity = Gravity.getAbsoluteGravity(mGravity, layoutDirection); switch (absoluteGravity & Gravity.HORIZONTAL_GRAVITY_MASK) { case Gravity.LEFT: mHorizontalInset = 0;//from ww w . j ava 2 s . c o m break; case Gravity.RIGHT: mHorizontalInset = dx; break; case Gravity.CENTER_HORIZONTAL: default: mHorizontalInset = dx / 2; break; } switch (absoluteGravity & Gravity.VERTICAL_GRAVITY_MASK) { case Gravity.TOP: mVerticalInset = 0; break; case Gravity.BOTTOM: mVerticalInset = dy; break; case Gravity.CENTER_VERTICAL: default: mVerticalInset = dy / 2; break; } }
From source file:android.support.design.widget.CoordinatorLayout.java
private void getDesiredAnchoredChildRectWithoutConstraints(View child, int layoutDirection, Rect anchorRect, Rect out, LayoutParams lp, int childWidth, int childHeight) { final int absGravity = GravityCompat.getAbsoluteGravity(resolveAnchoredChildGravity(lp.gravity), layoutDirection);/* w w w.j av a 2s .c o m*/ final int absAnchorGravity = GravityCompat.getAbsoluteGravity(resolveGravity(lp.anchorGravity), layoutDirection); final int hgrav = absGravity & Gravity.HORIZONTAL_GRAVITY_MASK; final int vgrav = absGravity & Gravity.VERTICAL_GRAVITY_MASK; final int anchorHgrav = absAnchorGravity & Gravity.HORIZONTAL_GRAVITY_MASK; final int anchorVgrav = absAnchorGravity & Gravity.VERTICAL_GRAVITY_MASK; int left; int top; // Align to the anchor. This puts us in an assumed right/bottom child view gravity. // If this is not the case we will subtract out the appropriate portion of // the child size below. switch (anchorHgrav) { default: case Gravity.LEFT: left = anchorRect.left; break; case Gravity.RIGHT: left = anchorRect.right; break; case Gravity.CENTER_HORIZONTAL: left = anchorRect.left + anchorRect.width() / 2; break; } switch (anchorVgrav) { default: case Gravity.TOP: top = anchorRect.top; break; case Gravity.BOTTOM: top = anchorRect.bottom; break; case Gravity.CENTER_VERTICAL: top = anchorRect.top + anchorRect.height() / 2; break; } // Offset by the child view's gravity itself. The above assumed right/bottom gravity. switch (hgrav) { default: case Gravity.LEFT: left -= childWidth; break; case Gravity.RIGHT: // Do nothing, we're already in position. break; case Gravity.CENTER_HORIZONTAL: left -= childWidth / 2; break; } switch (vgrav) { default: case Gravity.TOP: top -= childHeight; break; case Gravity.BOTTOM: // Do nothing, we're already in position. break; case Gravity.CENTER_VERTICAL: top -= childHeight / 2; break; } out.set(left, top, left + childWidth, top + childHeight); }
From source file:com.hb.hkm.slidinglayer.SlidLayer.java
private void adjustLayoutParams() { ViewGroup.LayoutParams baseParams = getLayoutParams(); if (baseParams instanceof LayoutParams) { LayoutParams layoutParams = (LayoutParams) baseParams; switch (mScreenSide) { case STICK_TO_BOTTOM: layoutParams.gravity = Gravity.BOTTOM; break; case STICK_TO_LEFT: layoutParams.gravity = Gravity.LEFT; break; case STICK_TO_RIGHT: layoutParams.gravity = Gravity.RIGHT; break; case STICK_TO_TOP: layoutParams.gravity = Gravity.TOP; break; }/*from w w w . j a v a 2 s . co m*/ setLayoutParams(baseParams); } else if (baseParams instanceof RelativeLayout.LayoutParams) { RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) baseParams; switch (mScreenSide) { case STICK_TO_BOTTOM: layoutParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); break; case STICK_TO_LEFT: layoutParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT); break; case STICK_TO_RIGHT: layoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); break; case STICK_TO_TOP: layoutParams.addRule(RelativeLayout.ALIGN_PARENT_TOP); break; } } }
From source file:com.android.incallui.widget.multiwaveview.GlowPadView.java
/** * Given the desired width and height of the ring and the allocated width and height, compute * how much we need to scale the ring./*from w w w .ja va 2 s . com*/ */ private float computeScaleFactor(int desiredWidth, int desiredHeight, int actualWidth, int actualHeight) { // Return unity if scaling is not allowed. if (!mAllowScaling) return 1f; final int layoutDirection = getLayoutDirection(); final int absoluteGravity = Gravity.getAbsoluteGravity(mGravity, layoutDirection); float scaleX = 1f; float scaleY = 1f; // We use the gravity as a cue for whether we want to scale on a particular axis. // We only scale to fit horizontally if we're not pinned to the left or right. Likewise, // we only scale to fit vertically if we're not pinned to the top or bottom. In these // cases, we want the ring to hang off the side or top/bottom, respectively. switch (absoluteGravity & Gravity.HORIZONTAL_GRAVITY_MASK) { case Gravity.LEFT: case Gravity.RIGHT: break; case Gravity.CENTER_HORIZONTAL: default: if (desiredWidth > actualWidth) { scaleX = (1f * actualWidth - mMaxTargetWidth) / (desiredWidth - mMaxTargetWidth); } break; } switch (absoluteGravity & Gravity.VERTICAL_GRAVITY_MASK) { case Gravity.TOP: case Gravity.BOTTOM: break; case Gravity.CENTER_VERTICAL: default: if (desiredHeight > actualHeight) { scaleY = (1f * actualHeight - mMaxTargetHeight) / (desiredHeight - mMaxTargetHeight); } break; } return Math.min(scaleX, scaleY); }
From source file:administrator.example.com.myscrollview.VerticalViewPager.java
@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { // For simple implementation, or internal size is always 0. // We depend on the container to specify the layout size of // our view. We can't really know what it is since we will be // adding and removing different arbitrary views and do not // want the layout to change as this happens. setMeasuredDimension(getDefaultSize(0, widthMeasureSpec), getDefaultSize(0, heightMeasureSpec)); // Children are just made to fill our space. int childWidthSize = getMeasuredWidth() - getPaddingLeft() - getPaddingRight(); int childHeightSize = getMeasuredHeight() - getPaddingTop() - getPaddingBottom(); /*/*w ww. j a va 2 s . com*/ * Make sure all children have been properly measured. Decor views first. * Right now we cheat and make this less complicated by assuming decor * views won't intersect. We will pin to edges based on gravity. */ int size = getChildCount(); for (int i = 0; i < size; ++i) { final View child = getChildAt(i); if (child.getVisibility() != GONE) { final LayoutParams lp = (LayoutParams) child.getLayoutParams(); if (lp != null && lp.isDecor) { final int hgrav = lp.gravity & Gravity.HORIZONTAL_GRAVITY_MASK; final int vgrav = lp.gravity & Gravity.VERTICAL_GRAVITY_MASK; Log.d(TAG, "gravity: " + lp.gravity + " hgrav: " + hgrav + " vgrav: " + vgrav); int widthMode = MeasureSpec.AT_MOST; int heightMode = MeasureSpec.AT_MOST; boolean consumeVertical = vgrav == Gravity.TOP || vgrav == Gravity.BOTTOM; boolean consumeHorizontal = hgrav == Gravity.LEFT || hgrav == Gravity.RIGHT; if (consumeVertical) { widthMode = MeasureSpec.EXACTLY; } else if (consumeHorizontal) { heightMode = MeasureSpec.EXACTLY; } /* end of if */ final int widthSpec = MeasureSpec.makeMeasureSpec(childWidthSize, widthMode); final int heightSpec = MeasureSpec.makeMeasureSpec(childHeightSize, heightMode); child.measure(widthSpec, heightSpec); if (consumeVertical) { childHeightSize -= child.getMeasuredHeight(); } else if (consumeHorizontal) { childWidthSize -= child.getMeasuredWidth(); } /* end of if */ } /* end of if */ } /* end of if */ } /* end of for */ mChildWidthMeasureSpec = MeasureSpec.makeMeasureSpec(childWidthSize, MeasureSpec.EXACTLY); mChildHeightMeasureSpec = MeasureSpec.makeMeasureSpec(childHeightSize, MeasureSpec.EXACTLY); // Make sure we have created all fragments that we need to have shown. mInLayout = true; populate(); mInLayout = false; // Page views next. size = getChildCount(); for (int i = 0; i < size; ++i) { final View child = getChildAt(i); if (child.getVisibility() != GONE) { if (DEBUG) Log.v(TAG, "Measuring #" + i + " " + child + ": " + mChildWidthMeasureSpec); final LayoutParams lp = (LayoutParams) child.getLayoutParams(); if (lp == null || !lp.isDecor) { child.measure(mChildWidthMeasureSpec, mChildHeightMeasureSpec); } /* end of if */ } /* end of if */ } /* end of for */ }