OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.ui.resources; | 5 package org.chromium.ui.resources; |
6 | 6 |
7 import android.graphics.Rect; | 7 import android.graphics.Rect; |
8 import android.graphics.RectF; | 8 import android.graphics.RectF; |
9 | 9 |
| 10 import org.chromium.ui.resources.statics.NinePatchData; |
| 11 |
10 /** | 12 /** |
11 * A resource that provides sizing information for layouts. | 13 * A resource that provides sizing information for layouts. |
12 */ | 14 */ |
13 public class LayoutResource { | 15 public class LayoutResource { |
14 private final RectF mPadding; | 16 private final RectF mPadding; |
15 private final RectF mBitmapSize; | 17 private final RectF mBitmapSize; |
16 private final RectF mAperture; | 18 private final RectF mAperture; |
17 | 19 |
18 public LayoutResource(float pxToDp, Resource resource) { | 20 public LayoutResource(float pxToDp, Resource resource) { |
19 Rect padding = resource.getPadding(); | 21 Rect padding = new Rect(); |
| 22 Rect aperture = new Rect(); |
| 23 NinePatchData ninePatchData = resource.getNinePatchData(); |
| 24 if (ninePatchData != null) { |
| 25 padding = ninePatchData.getPadding(); |
| 26 aperture = ninePatchData.getAperture(); |
| 27 } |
20 Rect bitmapSize = resource.getBitmapSize(); | 28 Rect bitmapSize = resource.getBitmapSize(); |
21 Rect aperture = resource.getAperture(); | |
22 | 29 |
23 mPadding = new RectF(padding.left * pxToDp, padding.top * pxToDp, paddin
g.right * pxToDp, | 30 mPadding = new RectF(padding.left * pxToDp, padding.top * pxToDp, paddin
g.right * pxToDp, |
24 padding.bottom * pxToDp); | 31 padding.bottom * pxToDp); |
25 | 32 |
26 mBitmapSize = new RectF(bitmapSize.left * pxToDp, bitmapSize.top * pxToD
p, | 33 mBitmapSize = new RectF(bitmapSize.left * pxToDp, bitmapSize.top * pxToD
p, |
27 bitmapSize.right * pxToDp, bitmapSize.bottom * pxToDp); | 34 bitmapSize.right * pxToDp, bitmapSize.bottom * pxToDp); |
28 | 35 |
29 mAperture = new RectF(aperture.left * pxToDp, aperture.top * pxToDp, | 36 mAperture = new RectF(aperture.left * pxToDp, aperture.top * pxToDp, |
30 aperture.right * pxToDp, aperture.bottom * pxToDp); | 37 aperture.right * pxToDp, aperture.bottom * pxToDp); |
31 } | 38 } |
32 | 39 |
33 /** | 40 /** |
34 * @return The padded content area of this resource in dp. For 9-patches th
is will represent | 41 * @return The padded content area of this resource in dp. For 9-patches th
is will represent |
35 * the valid content of the 9-patch. It can mean other things for o
ther Resources | 42 * the valid content of the 9-patch. In all other cases, it will be
an empty rect. |
36 * though. | |
37 */ | 43 */ |
38 public RectF getPadding() { | 44 public RectF getPadding() { |
39 return mPadding; | 45 return mPadding; |
40 } | 46 } |
41 | 47 |
42 /** | 48 /** |
43 * @return The size of the bitmap in dp; | 49 * @return The size of the bitmap in dp; |
44 */ | 50 */ |
45 public RectF getBitmapSize() { | 51 public RectF getBitmapSize() { |
46 return mBitmapSize; | 52 return mBitmapSize; |
47 } | 53 } |
48 | 54 |
49 /** | 55 /** |
50 * @return The aperture of this resource in dp. For 9-patches this will rep
resent the area of | 56 * @return The aperture of this resource in dp. For 9-patches this will rep
resent the area of |
51 * the {@link Bitmap} that should not be stretched. It can mean oth
er things for other | 57 * the {@link Bitmap} that should not be stretched. In all other cas
es, it will be an |
52 * Resources though. | 58 * empty rect. |
53 */ | 59 */ |
54 public RectF getAperture() { | 60 public RectF getAperture() { |
55 return mAperture; | 61 return mAperture; |
56 } | 62 } |
57 } | 63 } |
OLD | NEW |