AI2 Component  (Version nb184)
PaintUtil.java
Go to the documentation of this file.
1 // -*- mode: java; c-basic-offset: 2; -*-
2 // Copyright 2009-2011 Google, All Rights reserved
3 // Copyright 2011-2017 MIT, All rights reserved
4 // Released under the Apache License, Version 2.0
5 // http://www.apache.org/licenses/LICENSE-2.0
6 
7 package com.google.appinventor.components.runtime.util;
8 
9 import android.graphics.Paint;
10 import android.graphics.PorterDuffXfermode;
11 
17 public class PaintUtil {
18  private PaintUtil() {}
19 
27  public static void changePaint(Paint paint, int argb) {
28  // TODO(user): can the following two lines can be replaced by:
29  // paint.setColor(argb)?
30  paint.setColor(argb & 0x00FFFFFF);
31  paint.setAlpha((argb >> 24) & 0xFF);
32  paint.setXfermode(null);
33  }
34 
40  public static void changePaintTransparent(Paint paint) {
41  paint.setAlpha(0x00);
42  paint.setXfermode(new PorterDuffXfermode(android.graphics.PorterDuff.Mode.CLEAR));
43  }
44 
45  public static int hexStringToInt(String argb) {
46  String unprefixed = argb;
47  if (argb.startsWith("#x") || argb.startsWith("&H")) {
48  unprefixed = argb.substring(2);
49  }
50  // Integer.parseInt will throw
51  long l = Long.parseLong(unprefixed, 16);
52  if (l > Integer.MAX_VALUE) {
53  l += 2 * Integer.MIN_VALUE;
54  }
55  return (int) l;
56  }
57 }
com.google.appinventor.components.runtime.util.PaintUtil.changePaint
static void changePaint(Paint paint, int argb)
Definition: PaintUtil.java:27
com.google.appinventor.components.runtime.util.PaintUtil
Definition: PaintUtil.java:17
com.google.appinventor.components.runtime.util.PaintUtil.changePaintTransparent
static void changePaintTransparent(Paint paint)
Definition: PaintUtil.java:40
com.google.appinventor.components.runtime.util.PaintUtil.hexStringToInt
static int hexStringToInt(String argb)
Definition: PaintUtil.java:45