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.quran.labs.androidquran.widgets.SlidingUpPanelLayout.java
public SlidingUpPanelLayout(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); if (isInEditMode()) { mShadowDrawable = null;//from w w w . java 2 s .co m mScrollTouchSlop = 0; mDragHelper = null; return; } if (attrs != null) { TypedArray defAttrs = context.obtainStyledAttributes(attrs, DEFAULT_ATTRS); if (defAttrs != null) { int gravity = defAttrs.getInt(0, Gravity.NO_GRAVITY); if (gravity != Gravity.TOP && gravity != Gravity.BOTTOM) { throw new IllegalArgumentException("gravity must be set to either top or bottom"); } mIsSlidingUp = gravity == Gravity.BOTTOM; } defAttrs.recycle(); TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.SlidingUpPanelLayout); if (ta != null) { mPanelHeight = ta.getDimensionPixelSize(R.styleable.SlidingUpPanelLayout_panelHeight, -1); mShadowHeight = ta.getDimensionPixelSize(R.styleable.SlidingUpPanelLayout_shadowHeight, -1); mParallaxOffset = ta.getDimensionPixelSize(R.styleable.SlidingUpPanelLayout_parallaxOffset, -1); mMinFlingVelocity = ta.getInt(R.styleable.SlidingUpPanelLayout_flingVelocity, DEFAULT_MIN_FLING_VELOCITY); mCoveredFadeColor = ta.getColor(R.styleable.SlidingUpPanelLayout_fadeColor, DEFAULT_FADE_COLOR); mDragViewResId = ta.getResourceId(R.styleable.SlidingUpPanelLayout_dragView, -1); mOverlayContent = ta.getBoolean(R.styleable.SlidingUpPanelLayout_overlay, DEFAULT_OVERLAY_FLAG); mArbitraryPositionEnabled = ta.getBoolean(R.styleable.SlidingUpPanelLayout_arbitraryPosition, DEFAULT_ARBITRARY_POS_FLAG); } ta.recycle(); } final float density = context.getResources().getDisplayMetrics().density; if (mPanelHeight == -1) { mPanelHeight = (int) (DEFAULT_PANEL_HEIGHT * density + 0.5f); } if (mShadowHeight == -1) { mShadowHeight = (int) (DEFAULT_SHADOW_HEIGHT * density + 0.5f); } if (mParallaxOffset == -1) { mParallaxOffset = (int) (DEFAULT_PARALLAX_OFFSET * density); } // If the shadow height is zero, don't show the shadow if (mShadowHeight > 0) { if (mIsSlidingUp) { mShadowDrawable = ContextCompat.getDrawable(context, R.drawable.sliding_panel_above_shadow); } else { mShadowDrawable = ContextCompat.getDrawable(context, R.drawable.sliding_panel_below_shadow); } } else { mShadowDrawable = null; } setWillNotDraw(false); mDragHelper = ViewDragHelper.create(this, 1.0f, new DragHelperCallback()); mDragHelper.setMinVelocity(mMinFlingVelocity * density); mCanSlide = true; mIsSlidingEnabled = true; ViewConfiguration vc = ViewConfiguration.get(context); mScrollTouchSlop = vc.getScaledTouchSlop(); }
From source file:com.easemob.easeui.widget.viewpagerindicator.PagerSlidingTabStrip.java
private void addTextTab(final int position, String title) { TextView tab = new TextView(getContext()); tab.setText(title);// ww w .j av a2 s . c o m tab.setSingleLine(); tab.setTextColor(tabTextColor); tab.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL); tab.setTextSize(TypedValue.COMPLEX_UNIT_PX, tabTextSize); addTab(position, tab); }
From source file:com.example.carlitos.swipeitemrecycler.view.animation.swipe_item.swipeable.ItemSlidingAnimator.java
@SuppressLint("RtlHardcoded") private static boolean slideInternalPreHoneycomb(RecyclerView.ViewHolder holder, boolean horizontal, int translationX, int translationY) { if (!(holder instanceof SwipeableItemViewHolder)) { return false; }//from ww w .j a v a 2 s . c o m final View containerView = ((SwipeableItemViewHolder) holder).getSwipeableContainerView(); final ViewGroup.LayoutParams lp = containerView.getLayoutParams(); if (lp instanceof ViewGroup.MarginLayoutParams) { final ViewGroup.MarginLayoutParams mlp = (ViewGroup.MarginLayoutParams) lp; mlp.leftMargin = translationX; mlp.rightMargin = -translationX; mlp.topMargin = translationY; mlp.bottomMargin = -translationY; if (lp instanceof FrameLayout.LayoutParams) { ((FrameLayout.LayoutParams) lp).gravity = Gravity.TOP | Gravity.LEFT; } containerView.setLayoutParams(mlp); } else { Log.w(TAG, "should use MarginLayoutParams supported view for compatibility on Android 2.3"); } return false; }
From source file:com.test.hwautotest.emmagee.service.EmmageeService.java
/** * create a floating window to show real-time data. *//* www . java2s. c o m*/ private void createFloatingWindow() { SharedPreferences shared = getSharedPreferences("float_flag", Activity.MODE_PRIVATE); SharedPreferences.Editor editor = shared.edit(); editor.putInt("float", 1); editor.commit(); windowManager = (WindowManager) getApplicationContext().getSystemService("window"); wmParams = ((MyApplication) getApplication()).getMywmParams(); wmParams.type = 2002; wmParams.flags |= 8; wmParams.gravity = Gravity.LEFT | 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(); switch (event.getAction()) { case MotionEvent.ACTION_DOWN: // state = MotionEvent.ACTION_DOWN; startX = x; startY = y; mTouchStartX = event.getX(); mTouchStartY = event.getY(); Log.d("startP", "startX" + mTouchStartX + "====startY" + mTouchStartY); break; case MotionEvent.ACTION_MOVE: // state = MotionEvent.ACTION_MOVE; updateViewPosition(); break; case MotionEvent.ACTION_UP: // state = MotionEvent.ACTION_UP; updateViewPosition(); // showImg();//? 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.openwifi); // if (buttonText.equals(wifiText)) { // wifiManager.setWifiEnabled(true); // btnWifi.setText(R.string.closewifi); // } else { // wifiManager.setWifiEnabled(false); // btnWifi.setText(R.string.openwifi); // } // } catch (Exception e) { // Toast.makeText(viFloatingWindow.getContext(), "?wifi", // Toast.LENGTH_LONG).show(); // Log.e(LOG_TAG, e.toString()); // } // } // }); //? imgClose.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { // TODO Auto-generated method stub showMemi(); } }); }
From source file:com.github.shareme.gwsmaterialuikit.library.advancerv.swipeable.ItemSlidingAnimator.java
@SuppressLint("RtlHardcoded") private static boolean slideInternalPreHoneycomb(RecyclerView.ViewHolder holder, boolean horizontal, int translationX, int translationY) { if (!(holder instanceof SwipeableItemViewHolder)) { return false; }/* w w w . ja va 2s.c o m*/ final View containerView = ((SwipeableItemViewHolder) holder).getSwipeableContainerView(); final ViewGroup.LayoutParams lp = containerView.getLayoutParams(); if (lp instanceof ViewGroup.MarginLayoutParams) { final ViewGroup.MarginLayoutParams mlp = (ViewGroup.MarginLayoutParams) lp; mlp.leftMargin = translationX; mlp.rightMargin = -translationX; mlp.topMargin = translationY; mlp.bottomMargin = -translationY; if (lp instanceof FrameLayout.LayoutParams) { ((FrameLayout.LayoutParams) lp).gravity = Gravity.TOP | Gravity.LEFT; } containerView.setLayoutParams(mlp); } else { Timber.w("should use MarginLayoutParams supported view for compatibility on Android 2.3"); } return false; }
From source file:com.actionbarsherlock.custom.widget.VerticalDrawerLayout.java
/** * Set a simple drawable used for the left or right shadow. * The drawable provided must have a nonzero intrinsic width. * * @param shadowDrawable Shadow drawable to use at the edge of a drawer * @param gravity Which drawer the shadow should apply to */// w w w. j a v a 2 s .c om public void setDrawerShadow(Drawable shadowDrawable, int gravity) { /* * TODO Someone someday might want to set more complex drawables here. * They're probably nuts, but we might want to consider registering callbacks, * setting states, etc. properly. */ final int absGravity = GravityCompat.getAbsoluteGravity(gravity, ViewCompat.getLayoutDirection(this)); if ((absGravity & Gravity.TOP) == Gravity.TOP) { mShadowTop = shadowDrawable; invalidate(); } if ((absGravity & Gravity.BOTTOM) == Gravity.BOTTOM) { mShadowBottom = shadowDrawable; invalidate(); } }
From source file:com.duy.pascal.ui.debug.activities.DebugActivity.java
@WorkerThread private void showPopupAt(final LineNumber lineNumber, final String msg) { mHandler.post(new Runnable() { @Override/*from www . ja v a 2 s .co m*/ public void run() { if (isFinishing()) return; //get relative position of expression at edittext Point position = mCodeView.getDebugPosition(lineNumber.getLine(), lineNumber.getColumn(), Gravity.TOP); DLog.d(TAG, "generate: " + position); dismissPopup(); //create new popup PopupWindow window = new PopupWindow(DebugActivity.this); LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE); View container = inflater.inflate(R.layout.popup_expr_result, null); container.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED), View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED)); int windowHeight = container.getMeasuredHeight(); int windowWidth = container.getMeasuredWidth(); window.setContentView(container); window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); window.setTouchable(true); window.setSplitTouchEnabled(true); window.setOutsideTouchable(true); window.showAtLocation(mCodeView, Gravity.NO_GRAVITY, position.x - windowWidth / 3, position.y + toolbar.getHeight() - windowHeight); TextView txtResult = container.findViewById(R.id.txt_result); txtResult.setText(msg); AlphaAnimation alphaAnimation = new AlphaAnimation(1.0f, 0.5f); alphaAnimation.setDuration(1000); alphaAnimation.setRepeatMode(Animation.REVERSE); alphaAnimation.setRepeatCount(Animation.INFINITE); txtResult.startAnimation(alphaAnimation); DebugActivity.this.mPopupWindow = window; } }); }
From source file:com.jaredrummler.android.colorpicker.ColorPanelView.java
/** * Show a toast message with the hex color code below the view. *///w w w. j a v a 2 s . c o m public void showHint() { final int[] screenPos = new int[2]; final Rect displayFrame = new Rect(); getLocationOnScreen(screenPos); getWindowVisibleDisplayFrame(displayFrame); final Context context = getContext(); final int width = getWidth(); final int height = getHeight(); final int midy = screenPos[1] + height / 2; int referenceX = screenPos[0] + width / 2; if (ViewCompat.getLayoutDirection(this) == ViewCompat.LAYOUT_DIRECTION_LTR) { final int screenWidth = context.getResources().getDisplayMetrics().widthPixels; referenceX = screenWidth - referenceX; // mirror } StringBuilder hint = new StringBuilder("#"); if (Color.alpha(color) != 255) { hint.append(Integer.toHexString(color).toUpperCase(Locale.ENGLISH)); } else { hint.append(String.format("%06X", 0xFFFFFF & color).toUpperCase(Locale.ENGLISH)); } Toast cheatSheet = Toast.makeText(context, hint.toString(), Toast.LENGTH_SHORT); if (midy < displayFrame.height()) { // Show along the top; follow action buttons cheatSheet.setGravity(Gravity.TOP | GravityCompat.END, referenceX, screenPos[1] + height - displayFrame.top); } else { // Show along the bottom center cheatSheet.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, height); } cheatSheet.show(); }
From source file:com.example.view.astuetz.PagerSlidingTabStrip.java
@SuppressLint("NewApi") private void addIconTab(int position, int resId, String notification) { FrameLayout tabItemCon = new FrameLayout(getContext()); ImageView tab = new ImageView(getContext()); tab.setImageResource(resId);//from ww w .j a v a2 s.c o m tabItemCon.addView(tab); tabIconlist.put(position, tab); ImageView notiSymbol = new ImageView(getContext()); notiSymbol.setImageResource(R.drawable.badge_background); BadgeView noti = new BadgeView(getContext()); noti.setText(notification); tabItemCon.addView(noti); tabItemCon.addView(notiSymbol); if (notification != null && !notification.equals("")) { noti.setVisibility(View.VISIBLE); notiSymbol.setVisibility(View.GONE); } else if (notification != null && notification.equals("")) { noti.setVisibility(View.GONE); notiSymbol.setVisibility(View.VISIBLE); } else { notiSymbol.setVisibility(View.GONE); noti.setVisibility(View.GONE); } int notiSySize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 20, getResources().getDisplayMetrics()); noti.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, Gravity.RIGHT | Gravity.TOP)); notiSymbol.setLayoutParams(new LayoutParams(notiSySize, notiSySize, Gravity.RIGHT | Gravity.TOP)); FrameLayout tabItem = new FrameLayout(getContext()); tabItem.addView(tabItemCon); tabItemCon.setLayoutParams( new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, Gravity.CENTER)); addTab(position, tabItem); }
From source file:com.cooltechworks.views.ScratchTextView.java
private int[] getTextBounds(float scale) { int paddingLeft = getPaddingLeft(); int paddingTop = getPaddingTop(); int paddingRight = getPaddingRight(); int paddingBottom = getPaddingBottom(); int vwidth = getWidth(); int vheight = getHeight(); int centerX = vwidth / 2; int centerY = vheight / 2; TextPaint paint = getPaint();/*ww w . j av a 2 s . com*/ String text = getText().toString(); int[] dimens = getTextDimens(text, paint); int width = dimens[0]; int height = dimens[1]; int lines = getLineCount(); height = height * lines; width = width / lines; int left = 0; int top = 0; if (height > vheight) { height = vheight - (paddingBottom + paddingTop); } else { height = (int) (height * scale); } if (width > vwidth) { width = vwidth - (paddingLeft + paddingRight); } else { width = (int) (width * scale); } int gravity = getGravity(); //todo Gravity.START if ((gravity & Gravity.LEFT) == Gravity.LEFT) { left = paddingLeft; } //todo Gravity.END else if ((gravity & Gravity.RIGHT) == Gravity.RIGHT) { left = (vwidth - paddingRight) - width; } else if ((gravity & Gravity.CENTER_HORIZONTAL) == Gravity.CENTER_HORIZONTAL) { left = centerX - width / 2; } if ((gravity & Gravity.TOP) == Gravity.TOP) { top = paddingTop; } else if ((gravity & Gravity.BOTTOM) == Gravity.BOTTOM) { top = (vheight - paddingBottom) - height; } else if ((gravity & Gravity.CENTER_VERTICAL) == Gravity.CENTER_VERTICAL) { top = centerY - height / 2; } return new int[] { left, top, left + width, top + height }; }