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:Main.java
/** * This helper method creates a 'nice' scrim or background protection for layering text over * an image. This non-linear scrim is less noticable than a linear or constant one. * * Borrowed from github.com/romannurik/muzei * * Creates an approximated cubic gradient using a multi-stop linear gradient. See * <a href="https://plus.google.com/+RomanNurik/posts/2QvHVFWrHZf">this post</a> for more * details.//from ww w. j av a 2 s.c o m */ public static Drawable makeCubicGradientScrimDrawable(int baseColor, int numStops, int gravity) { numStops = Math.max(numStops, 2); PaintDrawable paintDrawable = new PaintDrawable(); paintDrawable.setShape(new RectShape()); final int[] stopColors = new int[numStops]; int alpha = Color.alpha(baseColor); for (int i = 0; i < numStops; i++) { double x = i * 1f / (numStops - 1); double opacity = Math.max(0, Math.min(1, Math.pow(x, 3))); stopColors[i] = (baseColor & 0x00ffffff) | ((int) (alpha * opacity) << 24); } final float x0, x1, y0, y1; switch (gravity & Gravity.HORIZONTAL_GRAVITY_MASK) { case Gravity.LEFT: x0 = 1; x1 = 0; break; case Gravity.RIGHT: x0 = 0; x1 = 1; break; default: x0 = 0; x1 = 0; break; } switch (gravity & Gravity.VERTICAL_GRAVITY_MASK) { case Gravity.TOP: y0 = 1; y1 = 0; break; case Gravity.BOTTOM: y0 = 0; y1 = 1; break; default: y0 = 0; y1 = 0; break; } paintDrawable.setShaderFactory(new ShapeDrawable.ShaderFactory() { @Override public Shader resize(int width, int height) { LinearGradient linearGradient = new LinearGradient(width * x0, height * y0, width * x1, height * y1, stopColors, null, Shader.TileMode.CLAMP); return linearGradient; } }); return paintDrawable; }
From source file:com.paad.wifi4us.ShareActionProvider.java
@Override public void onPrepareSubMenu(SubMenu subMenu) { //mContext.getMenuInflater().inflate(R.menu.actionbar_meau, subMenu); subMenu.add(0, 0, 0, "back").setIcon(R.drawable.ic_back) .setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { @Override//from w w w. j a v a 2s . c o m public boolean onMenuItemClick(MenuItem item) { Toast toast = Toast.makeText(mContext, "click back sub-menu", Toast.LENGTH_SHORT); toast.setGravity(Gravity.TOP, 0, 0); toast.show(); return true; } }); subMenu.add(0, 0, 0, "more").setIcon(R.drawable.ic_more) .setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { Toast toast = Toast.makeText(mContext, "click more sub-menu", Toast.LENGTH_SHORT); toast.setGravity(Gravity.TOP, 0, 0); toast.show(); return true; } }); super.onPrepareSubMenu(subMenu); }
From source file:com.andryr.musicplayer.utils.ToolbarDrawerToggle.java
private void init(final Context context, DrawerLayout drawerLayout, Toolbar toolbar, int[] gravities) { mDrawerLayout = drawerLayout;/*from ww w . j a v a 2 s .c om*/ mArrowDrawable = new DrawerArrowDrawable(context); mToolbar = toolbar; if (gravities == null) { mGravities = new int[] { Gravity.LEFT, Gravity.TOP, Gravity.RIGHT, Gravity.BOTTOM }; } else { mGravities = gravities; } mToolbar.setNavigationIcon(mArrowDrawable); mToolbar.setNavigationOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { toggleDrawers(); } }); }
From source file:Main.java
/** * Creates an approximated cubic gradient using a multi-stop linear gradient. */// ww w. j a v a 2 s . co m public static Drawable makeCubicGradientScrimDrawable(int baseColor, int numStops, int gravity) { // Generate a cache key by hashing together the inputs, based on the method described in the Effective Java book int cacheKeyHash = baseColor; cacheKeyHash = 31 * cacheKeyHash + numStops; cacheKeyHash = 31 * cacheKeyHash + gravity; Drawable cachedGradient = cubicGradientScrimCache.get(cacheKeyHash); if (cachedGradient != null) { return cachedGradient; } numStops = Math.max(numStops, 2); PaintDrawable paintDrawable = new PaintDrawable(); paintDrawable.setShape(new RectShape()); final int[] stopColors = new int[numStops]; int red = Color.red(baseColor); int green = Color.green(baseColor); int blue = Color.blue(baseColor); int alpha = Color.alpha(baseColor); for (int i = 0; i < numStops; i++) { float x = i * 1f / (numStops - 1); float opacity = constrain(0, 1, (float) Math.pow(x, 3)); stopColors[i] = Color.argb((int) (alpha * opacity), red, green, blue); } final float x0, x1, y0, y1; switch (gravity & Gravity.HORIZONTAL_GRAVITY_MASK) { case Gravity.LEFT: x0 = 1; x1 = 0; break; case Gravity.RIGHT: x0 = 0; x1 = 1; break; default: x0 = 0; x1 = 0; break; } switch (gravity & Gravity.VERTICAL_GRAVITY_MASK) { case Gravity.TOP: y0 = 1; y1 = 0; break; case Gravity.BOTTOM: y0 = 0; y1 = 1; break; default: y0 = 0; y1 = 0; break; } paintDrawable.setShaderFactory(new ShapeDrawable.ShaderFactory() { @Override public Shader resize(int width, int height) { LinearGradient linearGradient = new LinearGradient(width * x0, height * y0, width * x1, height * y1, stopColors, null, Shader.TileMode.CLAMP); return linearGradient; } }); cubicGradientScrimCache.put(cacheKeyHash, paintDrawable); return paintDrawable; }
From source file:com.manning.androidhacks.hack016.MainActivity.java
public void upperLeft(View v) { Toast toast = Toast.makeText(this, "Upper Left!", Toast.LENGTH_SHORT); toast.setGravity(Gravity.TOP | Gravity.LEFT, 0, 0); toast.show();//from w ww . j ava 2 s .c o m }
From source file:Main.java
/** * Creates an approximated cubic gradient using a multi-stop linear gradient. See * <a href="https://plus.google.com/+RomanNurik/posts/2QvHVFWrHZf">this post</a> for more * details.//from w w w. ja v a2 s .co m */ public static Drawable makeCubicGradientScrimDrawable(int baseColor, int numStops, int gravity) { numStops = Math.max(numStops, 2); PaintDrawable paintDrawable = new PaintDrawable(); paintDrawable.setShape(new RectShape()); final int[] stopColors = new int[numStops]; int red = Color.red(baseColor); int green = Color.green(baseColor); int blue = Color.blue(baseColor); int alpha = Color.alpha(baseColor); for (int i = 0; i < numStops; i++) { float x = i * 1f / (numStops - 1); float opacity = (float) Math.max(0, Math.min(1, Math.pow(x, 3))); stopColors[i] = Color.argb((int) (alpha * opacity), red, green, blue); } final float x0, x1, y0, y1; switch (gravity & Gravity.HORIZONTAL_GRAVITY_MASK) { case Gravity.LEFT: x0 = 1; x1 = 0; break; case Gravity.RIGHT: x0 = 0; x1 = 1; break; default: x0 = 0; x1 = 0; break; } switch (gravity & Gravity.VERTICAL_GRAVITY_MASK) { case Gravity.TOP: y0 = 1; y1 = 0; break; case Gravity.BOTTOM: y0 = 0; y1 = 1; break; default: y0 = 0; y1 = 0; break; } paintDrawable.setShaderFactory(new ShapeDrawable.ShaderFactory() { @Override public Shader resize(int width, int height) { LinearGradient linearGradient = new LinearGradient(width * x0, height * y0, width * x1, height * y1, stopColors, null, Shader.TileMode.CLAMP); return linearGradient; } }); return paintDrawable; }
From source file:Main.java
/** * Creates an approximated cubic gradient using a multi-stop linear gradient. See * <a href="https://plus.google.com/+RomanNurik/posts/2QvHVFWrHZf">this post</a> for more * details./* w w w . ja v a 2 s . co m*/ */ public static Drawable makeCubicGradientScrimDrawable(int baseColor, int numStops, int gravity) { // Generate a cache key by hashing together the inputs, based on the method described in the Effective Java book int cacheKeyHash = baseColor; cacheKeyHash = 31 * cacheKeyHash + numStops; cacheKeyHash = 31 * cacheKeyHash + gravity; Drawable cachedGradient = cubicGradientScrimCache.get(cacheKeyHash); if (cachedGradient != null) { return cachedGradient; } numStops = Math.max(numStops, 2); PaintDrawable paintDrawable = new PaintDrawable(); paintDrawable.setShape(new RectShape()); final int[] stopColors = new int[numStops]; int red = Color.red(baseColor); int green = Color.green(baseColor); int blue = Color.blue(baseColor); int alpha = Color.alpha(baseColor); for (int i = 0; i < numStops; i++) { float x = i * 1f / (numStops - 1); float opacity = constrain(0, 1, (float) Math.pow(x, 3)); stopColors[i] = Color.argb((int) (alpha * opacity), red, green, blue); } final float x0, x1, y0, y1; switch (gravity & Gravity.HORIZONTAL_GRAVITY_MASK) { case Gravity.LEFT: x0 = 1; x1 = 0; break; case Gravity.RIGHT: x0 = 0; x1 = 1; break; default: x0 = 0; x1 = 0; break; } switch (gravity & Gravity.VERTICAL_GRAVITY_MASK) { case Gravity.TOP: y0 = 1; y1 = 0; break; case Gravity.BOTTOM: y0 = 0; y1 = 1; break; default: y0 = 0; y1 = 0; break; } paintDrawable.setShaderFactory(new ShapeDrawable.ShaderFactory() { @Override public Shader resize(int width, int height) { return new LinearGradient(width * x0, height * y0, width * x1, height * y1, stopColors, null, Shader.TileMode.CLAMP); } }); cubicGradientScrimCache.put(cacheKeyHash, paintDrawable); return paintDrawable; }
From source file:com.sinyuk.jianyi.utils.list.SlideInItemAnimator.java
@Override public boolean animateAdd(RecyclerView.ViewHolder holder) { holder.itemView.setAlpha(0f);/*from w w w .j a v a 2s. c om*/ switch (slideFromEdge) { case Gravity.LEFT: holder.itemView.setTranslationX(-holder.itemView.getWidth() / 3); break; case Gravity.TOP: holder.itemView.setTranslationY(-holder.itemView.getHeight() / 3); break; case Gravity.RIGHT: holder.itemView.setTranslationX(holder.itemView.getWidth() / 3); break; default: // Gravity.BOTTOM holder.itemView.setTranslationY(holder.itemView.getHeight() / 3); } pendingAdds.add(holder); return true; }
From source file:biz.easymenu.easymenung.ErrorFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = li.inflate(R.layout.errordialog, container, false); ((TextView) v.findViewById(R.id.txtErrDlg)).setText(err); WindowManager.LayoutParams WMLP = this.getDialog().getWindow().getAttributes(); WMLP.y = 100; //y position WMLP.gravity = Gravity.TOP; WMLP.windowAnimations = R.style.PauseDialogAnimation; this.getDialog().getWindow().setAttributes(WMLP); this.getDialog().requestWindowFeature(Window.FEATURE_NO_TITLE); btnOk = (Button) v.findViewById(R.id.btnErrDlg); btnOk.setOnClickListener(new View.OnClickListener() { @Override/*from ww w .ja v a 2 s . co m*/ public void onClick(View v) { dismiss(); } }); return v; }
From source file:com.manning.androidhacks.hack016.MainActivity.java
public void upperRight(View v) { Toast toast = Toast.makeText(this, "Upper Right!", Toast.LENGTH_SHORT); toast.setGravity(Gravity.TOP | Gravity.RIGHT, 0, 0); toast.show();/* w w w. j a v a 2s .c o m*/ }