List of usage examples for android.graphics.drawable.shapes RectShape RectShape
public RectShape()
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 ww . j a v a 2s. c o 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.yoloo.android.util.ScrimUtil.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 . jav a 2s.c om*/ */ 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]; final int red = Color.red(baseColor); final int green = Color.green(baseColor); final int blue = Color.blue(baseColor); final int alpha = Color.alpha(baseColor); for (int i = 0; i < numStops; i++) { float x = i * 1f / (numStops - 1); float opacity = MathUtils.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.START: x0 = 1; x1 = 0; break; case Gravity.END: 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:gov.sfmta.sfpark.AnnotationsOverlay.java
public AnnotationsOverlay(Drawable defaultMarker, Context context) { super(boundCenterBottom(defaultMarker)); mContext = context;//from w w w . j av a 2 s . c om iconArray = new Drawable[8]; ShapeDrawable invisible = new ShapeDrawable(new RectShape()); invisible.getPaint().setColor(0x00000000); iconArray[0] = invisible; iconArray[1] = mContext.getResources().getDrawable(R.drawable.invalid_garage); iconArray[2] = mContext.getResources().getDrawable(R.drawable.garage_availability_high); iconArray[3] = mContext.getResources().getDrawable(R.drawable.garage_availability_medium); iconArray[4] = mContext.getResources().getDrawable(R.drawable.garage_availability_low); iconArray[5] = mContext.getResources().getDrawable(R.drawable.garage_price_low); iconArray[6] = mContext.getResources().getDrawable(R.drawable.garage_price_medium); iconArray[7] = mContext.getResources().getDrawable(R.drawable.garage_price_high); boundCenterBottom(iconArray[0]); boundCenterBottom(iconArray[1]); boundCenterBottom(iconArray[2]); boundCenterBottom(iconArray[3]); boundCenterBottom(iconArray[4]); boundCenterBottom(iconArray[5]); boundCenterBottom(iconArray[6]); boundCenterBottom(iconArray[7]); action = 0; last_action = 0; }
From source file:eu.trentorise.smartcampus.widget.shortcuts.StackWidgetService.java
@Override public RemoteViews getViewAt(int position) { // position will always range from 0 to getCount() - 1. // We construct a remote views item based on our widget item xml // file, and set the // text based on the position. RemoteViews rv = new RemoteViews(mContext.getPackageName(), R.layout.widget_item); ShapeDrawable sd1 = new ShapeDrawable(new RectShape()); sd1.getPaint().setColor(0xFFFFFFFF); sd1.getPaint().setStyle(Style.STROKE); sd1.getPaint().setStrokeWidth(1);//from w ww . j a v a 2s . c o m Canvas c = new Canvas(); sd1.draw(c); Bitmap b = Bitmap.createBitmap(120, 120, Bitmap.Config.ARGB_8888); c.drawBitmap(b, 0, 0, sd1.getPaint()); // Next, we set a fill-intent which will be used to fill-in the // pending intent template // which is set on the collection view in StackWidgetProvider. if (ALLPREFERENCES != null && ALLPREFERENCES[position] != null) { //ALLPREFERENCES dimensionato come le preferenze selezionate BookmarkDescriptor myDescriptor = ALLPREFERENCES[position]; // set the widgetbutton if (WidgetHelper.PARAM_TYPE.equals(myDescriptor.params.get(0).name)) { //controllare con gli input da config activity? String type = myDescriptor.params.get(0).value; if (WidgetHelper.TYPE_DT.equals(type)) { // dt -> put icons and hide text rv.setViewVisibility(R.id.text_widget_item, View.GONE); rv.setImageViewResource(R.id.image_widget_item, Integer.parseInt(myDescriptor.params.get(2).value)); rv.setInt(R.id.image_widget_item, "setBackgroundResource", R.drawable.rounded_border_dt); } else if (WidgetHelper.TYPE_JP.equals(type)) { // jp -> put text and hide icon rv.setViewVisibility(R.id.image_widget_item, View.GONE); // rv.setImageViewBitmap(R.id.text_widget_item, // getBackground(Color.parseColor("#6EB046"))); if (!("0".equals(myDescriptor.params.get(2).value))) { //bus rv.setTextViewTextSize(R.id.text_widget_item, TypedValue.COMPLEX_UNIT_DIP, 80); rv.setTextViewText(R.id.text_widget_item, RoutesHelper.getShortNameByRouteIdAndAgencyID( myDescriptor.params.get(4).value, myDescriptor.params.get(3).value)); //4,3 rv.setTextColor(R.id.text_widget_item, Integer.parseInt(myDescriptor.params.get(2).value));//rv.setInt(R.id.text_widget_item, "setBackgroundColor", //Integer.parseInt(myDescriptor.params.get(2).value)); rv.setInt(R.id.text_widget_item, "setBackgroundResource", R.drawable.rounded_border_jp); } else { //train rv.setTextViewTextSize(R.id.text_widget_item, TypedValue.COMPLEX_UNIT_DIP, 12); //controllo contesto getRouteDescriptor i vari parametri rv.setTextViewText(R.id.text_widget_item, mContext.getString( RoutesHelper.getRouteDescriptorByRouteId(myDescriptor.params.get(3).value, myDescriptor.params.get(4).value).getNameResource())); rv.setTextColor(R.id.text_widget_item, Color.BLACK);//Int(R.id.text_widget_item, "setBackgroundColor",Color.BLACK); rv.setInt(R.id.text_widget_item, "setBackgroundResource", R.drawable.rounded_border_jp); } } else if (WidgetHelper.TYPE_JP_PARKINGS.equals(type)) { // jp parcheggio -> put text and hide icon rv.setViewVisibility(R.id.text_widget_item, View.GONE); rv.setImageViewResource(R.id.image_widget_item, Integer.parseInt(myDescriptor.params.get(2).value)); rv.setInt(R.id.image_widget_item, "setBackgroundResource", R.drawable.rounded_border_jp); } BookmarkDescriptor bookmark = myDescriptor; Bundle extras = new Bundle(); extras.putString(StackWidgetProvider.EXTRA_INTENT, bookmark.getIntent()); if (bookmark.getParams() != null) { for (Param param : bookmark.getParams()) { extras.putString(param.name, param.value); } } Intent fillInIntent = new Intent(bookmark.getIntent()); fillInIntent.putExtras(extras); rv.setOnClickFillInIntent(R.id.layout, fillInIntent); } } // Return the remote views object. // AppWidgetManager manager = AppWidgetManager.getInstance(mContext); // manager.updateAppWidget(thisWidget, rv); return rv; }
From source file:com.shollmann.igcparser.ui.activity.FlightPreviewActivity.java
public PaintDrawable getColorScala() { ShapeDrawable.ShaderFactory shaderFactory = new ShapeDrawable.ShaderFactory() { @Override//from w w w . j ava 2s. c o m public Shader resize(int width, int height) { LinearGradient linearGradient = new LinearGradient(width, height, 0, 0, new int[] { getResources().getColor(R.color.altitude_0_100), getResources().getColor(R.color.altitude_100_300), getResources().getColor(R.color.altitude_300_500), getResources().getColor(R.color.altitude_500_1000), getResources().getColor(R.color.altitude_1000_1500), getResources().getColor(R.color.altitude_1500_2000), getResources().getColor(R.color.altitude_2000_2500), getResources().getColor(R.color.altitude_more_than_2500) }, new float[] { 0, 0.07f, 0.14f, 0.28f, 0.42f, 0.56f, 0.7f, 0.84f }, Shader.TileMode.REPEAT); return linearGradient; } }; PaintDrawable paint = new PaintDrawable(); paint.setShape(new RectShape()); paint.setShaderFactory(shaderFactory); return paint; }
From source file:com.vuze.android.remote.activity.LoginActivity.java
@SuppressWarnings("deprecation") private void setBackgroundGradient() { ViewGroup mainLayout = (ViewGroup) findViewById(R.id.main_loginlayout); assert mainLayout != null; int h = mainLayout.getHeight(); int w = mainLayout.getWidth(); View viewCenterOn = findViewById(R.id.login_frog_logo); assert viewCenterOn != null; RectShape shape = new RectShape(); ShapeDrawable mDrawable = new ShapeDrawable(shape); int color1 = AndroidUtilsUI.getStyleColor(this, R.attr.login_grad_color_1); int color2 = AndroidUtilsUI.getStyleColor(this, R.attr.login_grad_color_2); RadialGradient shader;// w w w . ja v a 2s .com if (w > h) { int left = viewCenterOn.getLeft() + (viewCenterOn.getWidth() / 2); int top = viewCenterOn.getTop() + (viewCenterOn.getHeight() / 2); int remaining = w - left; shader = new RadialGradient(left, top, remaining, new int[] { color1, color2 }, new float[] { 0, 1.0f }, Shader.TileMode.CLAMP); } else { int top = viewCenterOn.getTop() + (viewCenterOn.getHeight() / 2); shader = new RadialGradient(w / 2, top, w * 2 / 3, color1, color2, Shader.TileMode.CLAMP); } mDrawable.setBounds(0, 0, w, h); mDrawable.getPaint().setShader(shader); mDrawable.getPaint().setDither(true); mDrawable.getPaint().setAntiAlias(true); mDrawable.setDither(true); mainLayout.setDrawingCacheEnabled(true); mainLayout.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_HIGH); mainLayout.setAnimationCacheEnabled(false); mainLayout.setBackgroundDrawable(mDrawable); }
From source file:com.tafayor.selfcamerashot.taflib.helpers.GraphicsHelper.java
public static Drawable createRectGradient(final int direction, final int[] colors) { final ShapeDrawable shapeDrawable = new ShapeDrawable(new RectShape()); final ShapeDrawable.ShaderFactory shaderFactory = new ShapeDrawable.ShaderFactory() { @Override/* w w w. jav a 2 s . c om*/ public Shader resize(int width, int height) { int x0, y0, x1, y1; x0 = y0 = x1 = y1 = 0; if (direction == GRADIENT_DOWN) { y1 = height; } else if (direction == GRADIENT_UP) { y0 = height; } else if (direction == GRADIENT_RIGHT) { x1 = width; } else if (direction == GRADIENT_LEFT) { x0 = width; } LinearGradient lg = new LinearGradient(x0, y0, x1, y1, colors, new float[] { 0, 0.05f, 0.1f, 1 }, Shader.TileMode.REPEAT); return lg; } }; shapeDrawable.setShaderFactory(shaderFactory); return shapeDrawable; }
From source file:com.tafayor.selfcamerashot.taflib.helpers.GraphicsHelper.java
public static Drawable createRGradient(int shape, final int[] colors, final float[] positions) { ShapeDrawable shapeDrawable;//from w w w.j ava2 s. c o m if (shape == SHAPE_RECT) { shapeDrawable = new ShapeDrawable(new RectShape()); } else { shapeDrawable = new ShapeDrawable(new OvalShape()); } ShapeDrawable.ShaderFactory shaderFactory = new ShapeDrawable.ShaderFactory() { @Override public Shader resize(int width, int height) { float gradRadius = Math.max(width, height) / 2; RadialGradient rg = new RadialGradient(width / 2, height / 2, gradRadius, colors, positions, Shader.TileMode.CLAMP); return rg; } }; shapeDrawable.setShaderFactory(shaderFactory); return shapeDrawable; }
From source file:com.tafayor.selfcamerashot.taflib.helpers.GraphicsHelper.java
public static Drawable createLGradient(int shape, final int[] colors, final float[] positions) { ShapeDrawable shapeDrawable;//from w w w . ja va 2 s . c om if (shape == SHAPE_RECT) { shapeDrawable = new ShapeDrawable(new RectShape()); } else { shapeDrawable = new ShapeDrawable(new OvalShape()); } ShapeDrawable.ShaderFactory shaderFactory = new ShapeDrawable.ShaderFactory() { @Override public Shader resize(int width, int height) { LinearGradient rg = new LinearGradient(0, 0, 0, height, colors, positions, Shader.TileMode.CLAMP); return rg; } }; shapeDrawable.setShaderFactory(shaderFactory); return shapeDrawable; }
From source file:gov.sfmta.sfpark.MainScreenActivity.java
public boolean displayData(boolean progress) { if (SFparkActivity.responseString == null || SFparkActivity.responseString == "") { return false; }/*from w w w . j a v a 2 s . co m*/ // ISO8601 date SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'H:mm:ss'.'SSSZZZZ"); try { timeStamp = df.parse(timeStampXML); } catch (ParseException e) { e.printStackTrace(); } SimpleDateFormat formatter = new SimpleDateFormat("h:mma"); String now = formatter.format(timeStamp); if (showPrice) { legendImage.setImageResource(R.drawable.key_pricing); legendlabel.setText("Price as of " + now); } else { legendImage.setImageResource(R.drawable.key_availability); legendlabel.setText("Availability as of " + now); } //convert time stamp to minutes. String now is 24 hour time display. SimpleDateFormat formatter24 = new SimpleDateFormat("HH:mm"); String now24 = formatter24.format(timeStamp); String[] time2 = now24.split(":"); int hours = Integer.valueOf(time2[0]); int minutes = Integer.valueOf(time2[1]); // for price bucket calculations timeStampMinutes = (hours * 60) + minutes; if ((showPrice == true) && (pricingAnnotationsOverlay != null)) { updateMap(); return true; } if ((showPrice == false) && (availabilityAnnotationsOverlay != null)) { updateMap(); return true; } ShapeDrawable invisible = new ShapeDrawable(new RectShape()); invisible.getPaint().setColor(0x00000000); if (showPrice == true) { pricingAnnotationsOverlay = new AnnotationsOverlay(invisible, mapView.getContext()); pricingAnnotationsOverlay.loadOverlaysProgress(showPrice); } else { // NPE!! availabilityAnnotationsOverlay = new AnnotationsOverlay(invisible, mapView.getContext()); availabilityAnnotationsOverlay.loadOverlays(showPrice); updateMap(); } return true; }