public static StateListDrawable createBlueButtonDrawable(Context context) {

    float corner =
        TypedValue.applyDimension(
            TypedValue.COMPLEX_UNIT_DIP, 2, context.getResources().getDisplayMetrics());

    float[] corners = new float[] {corner, corner, corner, corner, corner, corner, corner, corner};

    ShapeDrawable shapeDrawable = new ShapeDrawable();
    shapeDrawable.getPaint().setColor(TgR.color.blue_color);
    Shape rrs = new RoundRectShape(corners, null, null);
    shapeDrawable.setShape(rrs);

    ShapeDrawable shapeDrawablePressed = new ShapeDrawable();
    //        shapeDrawablePressed.getPaint().setColor((TgR.color.blue_color & 0x00FFFFFF) | (0xCC
    // << 24));
    shapeDrawablePressed.getPaint().setColor(TgR.color.main_theme_color);
    Shape rrsPressed = new RoundRectShape(corners, null, null);
    shapeDrawablePressed.setShape(rrsPressed);

    ShapeDrawable shapeDrawableDisable = new ShapeDrawable();
    shapeDrawableDisable.getPaint().setColor(0xFFD1D1D1);
    Shape rrsDisable = new RoundRectShape(corners, null, null);
    shapeDrawableDisable.setShape(rrsDisable);

    StateListDrawable sld = new StateListDrawable();
    sld.addState(new int[] {-android.R.attr.state_enabled}, shapeDrawableDisable);
    sld.addState(new int[] {android.R.attr.state_pressed}, shapeDrawablePressed);
    sld.addState(new int[] {android.R.attr.state_enabled}, shapeDrawable);

    return sld;
  }
Esempio n. 2
0
 // Throw IllegalArgumentException if shape has illegal value.
 private void setShape() {
   ShapeDrawable drawable = new ShapeDrawable();
   // Set color of drawable.
   drawable
       .getPaint()
       .setColor(
           (backgroundColor == Component.COLOR_DEFAULT)
               ? SHAPED_DEFAULT_BACKGROUND_COLOR
               : backgroundColor);
   // Set shape of drawable.
   switch (shape) {
     case Component.BUTTON_SHAPE_ROUNDED:
       drawable.setShape(new RoundRectShape(ROUNDED_CORNERS_ARRAY, null, null));
       break;
     case Component.BUTTON_SHAPE_RECT:
       drawable.setShape(new RectShape());
       break;
     case Component.BUTTON_SHAPE_OVAL:
       drawable.setShape(new OvalShape());
       break;
     default:
       throw new IllegalArgumentException();
   }
   // Set drawable to the background of the button.
   view.setBackgroundDrawable(drawable);
   view.invalidate();
 }
Esempio n. 3
0
  /**
   * Generates bitmap used for drawing button.
   *
   * @param radius Radius of button in pixels.
   */
  @Override
  void generateBitmap() {
    super.generateBitmap();
    // Size and shape
    buttonShape.setShape(new OvalShape());
    buttonShape.setBounds(
        new Rect(PADDING, PADDING, (int) radius * 2 - PADDING, (int) radius * 2 - PADDING));

    // Create button bitmap and render shape
    buttonBitmap = Bitmap.createBitmap((int) radius * 2, (int) radius * 2, Bitmap.Config.ARGB_4444);
    Canvas handleCanvas = new Canvas(buttonBitmap);
    buttonShape.getPaint().set(parent.fillPaint);
    buttonShape.draw(handleCanvas);

    // Set text style
    textPaint.setStyle(Paint.Style.FILL);
    textPaint.setTypeface(Typeface.DEFAULT_BOLD);
    textPaint.setTextAlign(Paint.Align.CENTER);
    textPaint.setColor(Color.BLACK);
    // Set size (one character has a standard design, more has dynamic size)
    if (label.length() == 1) textPaint.setTextSize(radius);
    else textPaint.setTextSize(radius / label.length() * 2.5f);

    // Set paint to clear text from button
    textPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));

    // Render the button
    handleCanvas.drawText(label, radius, radius + (textPaint.getTextSize() * .33333f), textPaint);
  }
Esempio n. 4
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    SharedPreferences prefs =
        getSharedPreferences(
            "test.prefs",
            MODE_MULTI_PROCESS + MODE_APPEND + MODE_WORLD_WRITEABLE + MODE_WORLD_READABLE);
    boolean result = prefs.edit().putString("key", " key values---------").commit();
    System.out.println("key writer----" + result);
    System.out.println(prefs.getString("other", "other default"));
    ShapeDrawable shapeDrawable = new ShapeDrawable();
    shapeDrawable.setShape(new BarShape());
  }