summaryrefslogtreecommitdiffstats
path: root/tests/DpiTest
diff options
context:
space:
mode:
authorDianne Hackborn <hackbod@google.com>2009-07-22 21:48:55 -0700
committerDianne Hackborn <hackbod@google.com>2009-07-24 10:47:15 -0700
commit11ea33471e1a14a8594f0b2cd012d86340dd3bd8 (patch)
treebb73c079d8bb21c19fa913b8fd9c587a9089ea84 /tests/DpiTest
parent3b99e64e5899030b5d6f8201cb56cd149c80b24d (diff)
downloadframeworks_base-11ea33471e1a14a8594f0b2cd012d86340dd3bd8.zip
frameworks_base-11ea33471e1a14a8594f0b2cd012d86340dd3bd8.tar.gz
frameworks_base-11ea33471e1a14a8594f0b2cd012d86340dd3bd8.tar.bz2
Allow for screen density drawables in compatibility mode.
This change allows us to use drawables that match the current screen density even when being loaded in compatibility mode. In this case, the bitmap is loaded in the screen density, and the bitmap and nine-patch drawables take care of accounting for the density difference. This should be safe for existing applications, for the most part, since they shouldn't really be pulling the bitmap out of the drawable. For the small rare chance of them breaking, it worth getting the correct graphics. Also this will only happen when there is actually a resource of the matching density, and no existing apps should have resources for anything besides the default density (though of course all of the framework resources will be available in the native density). As part of this, the bitmap density API has been changed to a single integer provider the DPI unit density.
Diffstat (limited to 'tests/DpiTest')
-rw-r--r--tests/DpiTest/res/drawable-hdpi/npatch240dpi.9.pngbin0 -> 17331 bytes
-rw-r--r--tests/DpiTest/res/drawable-hdpi/smlnpatch240dpi.9.pngbin0 -> 946 bytes
-rw-r--r--tests/DpiTest/res/drawable-ldpi/npatch120dpi.9.pngbin0 -> 6299 bytes
-rw-r--r--tests/DpiTest/res/drawable-ldpi/smlnpatch120dpi.9.pngbin0 -> 804 bytes
-rw-r--r--tests/DpiTest/res/drawable/npatch160dpi.9.pngbin0 -> 9978 bytes
-rw-r--r--tests/DpiTest/res/drawable/smlnpatch160dpi.9.pngbin0 -> 855 bytes
-rw-r--r--tests/DpiTest/src/com/google/android/test/dpi/DpiTestActivity.java25
7 files changed, 23 insertions, 2 deletions
diff --git a/tests/DpiTest/res/drawable-hdpi/npatch240dpi.9.png b/tests/DpiTest/res/drawable-hdpi/npatch240dpi.9.png
new file mode 100644
index 0000000..a362b0f
--- /dev/null
+++ b/tests/DpiTest/res/drawable-hdpi/npatch240dpi.9.png
Binary files differ
diff --git a/tests/DpiTest/res/drawable-hdpi/smlnpatch240dpi.9.png b/tests/DpiTest/res/drawable-hdpi/smlnpatch240dpi.9.png
new file mode 100644
index 0000000..84bdcb0
--- /dev/null
+++ b/tests/DpiTest/res/drawable-hdpi/smlnpatch240dpi.9.png
Binary files differ
diff --git a/tests/DpiTest/res/drawable-ldpi/npatch120dpi.9.png b/tests/DpiTest/res/drawable-ldpi/npatch120dpi.9.png
new file mode 100644
index 0000000..0d8115b
--- /dev/null
+++ b/tests/DpiTest/res/drawable-ldpi/npatch120dpi.9.png
Binary files differ
diff --git a/tests/DpiTest/res/drawable-ldpi/smlnpatch120dpi.9.png b/tests/DpiTest/res/drawable-ldpi/smlnpatch120dpi.9.png
new file mode 100644
index 0000000..de8d607
--- /dev/null
+++ b/tests/DpiTest/res/drawable-ldpi/smlnpatch120dpi.9.png
Binary files differ
diff --git a/tests/DpiTest/res/drawable/npatch160dpi.9.png b/tests/DpiTest/res/drawable/npatch160dpi.9.png
new file mode 100644
index 0000000..44d89a9
--- /dev/null
+++ b/tests/DpiTest/res/drawable/npatch160dpi.9.png
Binary files differ
diff --git a/tests/DpiTest/res/drawable/smlnpatch160dpi.9.png b/tests/DpiTest/res/drawable/smlnpatch160dpi.9.png
new file mode 100644
index 0000000..76c4ae8
--- /dev/null
+++ b/tests/DpiTest/res/drawable/smlnpatch160dpi.9.png
Binary files differ
diff --git a/tests/DpiTest/src/com/google/android/test/dpi/DpiTestActivity.java b/tests/DpiTest/src/com/google/android/test/dpi/DpiTestActivity.java
index dd4fae3..68220a1 100644
--- a/tests/DpiTest/src/com/google/android/test/dpi/DpiTestActivity.java
+++ b/tests/DpiTest/src/com/google/android/test/dpi/DpiTestActivity.java
@@ -34,6 +34,7 @@ import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.res.CompatibilityInfo;
import android.util.DisplayMetrics;
+import android.util.Log;
public class DpiTestActivity extends Activity {
public DpiTestActivity() {
@@ -116,6 +117,13 @@ public class DpiTestActivity extends Activity {
addLabelToRoot(root, "No-dpi resource drawable");
addChildToRoot(root, layout);
+ layout = new LinearLayout(this);
+ addNinePatchResourceDrawable(layout, R.drawable.smlnpatch120dpi);
+ addNinePatchResourceDrawable(layout, R.drawable.smlnpatch160dpi);
+ addNinePatchResourceDrawable(layout, R.drawable.smlnpatch240dpi);
+ addLabelToRoot(root, "Prescaled 9-patch resource drawable");
+ addChildToRoot(root, layout);
+
setContentView(scrollWrap(root));
}
@@ -144,8 +152,8 @@ public class DpiTestActivity extends Activity {
View view = new View(this);
- final BitmapDrawable d = new BitmapDrawable(bitmap);
- if (!scale) d.setDensityScale(getResources().getDisplayMetrics());
+ final BitmapDrawable d = new BitmapDrawable(getResources(), bitmap);
+ if (!scale) d.setTargetDensity(getResources().getDisplayMetrics());
view.setBackgroundDrawable(d);
view.setLayoutParams(new LinearLayout.LayoutParams(d.getIntrinsicWidth(),
@@ -175,6 +183,19 @@ public class DpiTestActivity extends Activity {
layout.addView(view);
}
+ private void addNinePatchResourceDrawable(LinearLayout layout, int resource) {
+ View view = new View(this);
+
+ final Drawable d = getResources().getDrawable(resource);
+ view.setBackgroundDrawable(d);
+
+ Log.i("foo", "9-patch #" + Integer.toHexString(resource)
+ + " w=" + d.getIntrinsicWidth() + " h=" + d.getIntrinsicHeight());
+ view.setLayoutParams(new LinearLayout.LayoutParams(
+ d.getIntrinsicWidth()*2, d.getIntrinsicHeight()*2));
+ layout.addView(view);
+ }
+
private Bitmap loadAndPrintDpi(int id, boolean scale) {
Bitmap bitmap;
if (scale) {