Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(886)

Unified Diff: content/public/android/java/src/org/chromium/content/browser/UIResources.java

Issue 679493002: [Android] Add a native pull-to-refresh overscroll effect (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix findbugs... Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/public/android/java/src/org/chromium/content/browser/UIResources.java
diff --git a/content/public/android/java/src/org/chromium/content/browser/UIResources.java b/content/public/android/java/src/org/chromium/content/browser/UIResources.java
new file mode 100644
index 0000000000000000000000000000000000000000..f39f4d628524d799a296d526fde0c14ef6235225
--- /dev/null
+++ b/content/public/android/java/src/org/chromium/content/browser/UIResources.java
@@ -0,0 +1,84 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package org.chromium.content.browser;
+
+import android.content.Context;
+import android.content.res.Resources;
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
+
+import org.chromium.base.CalledByNative;
+import org.chromium.base.JNINamespace;
+import org.chromium.content.R;
+import org.chromium.ui.base.SystemUIResourceType;
+
+/**
+ * Helper class for retrieving both system and embedded UI-related resources.
+ */
+@JNINamespace("content")
+class UIResources {
+ private static Bitmap getResourceBitmap(Resources res, int resId, int reqWidth, int reqHeight) {
+ final BitmapFactory.Options options = new BitmapFactory.Options();
+ if (reqWidth > 0 && reqHeight > 0) {
+ options.inJustDecodeBounds = true;
+ BitmapFactory.decodeResource(res, resId, options);
+ options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);
+ }
+ options.inJustDecodeBounds = false;
+ options.inPreferredConfig = Bitmap.Config.ARGB_8888;
+ return BitmapFactory.decodeResource(res, resId, options);
+ }
+
+ // http://developer.android.com/training/displaying-bitmaps/load-bitmap.html
+ private static int calculateInSampleSize(
+ BitmapFactory.Options options, int reqWidth, int reqHeight) {
+ // Raw height and width of image
+ final int height = options.outHeight;
+ final int width = options.outWidth;
+ int inSampleSize = 1;
+
+ if (height > reqHeight || width > reqWidth) {
+ // Calculate ratios of height and width to requested height and width
+ final int heightRatio = Math.round((float) height / (float) reqHeight);
+ final int widthRatio = Math.round((float) width / (float) reqWidth);
+
+ // Choose the smallest ratio as inSampleSize value, this will guarantee
+ // a final image with both dimensions larger than or equal to the
+ // requested height and width.
+ inSampleSize = heightRatio < widthRatio ? heightRatio : widthRatio;
+ }
+
+ return inSampleSize;
+ }
+
+ @SuppressWarnings("unused")
+ @CalledByNative
+ private static Bitmap getBitmap(
+ Context context, int uiResourceId, int reqWidth, int reqHeight) {
+ Resources res = null;
+ int resId = 0;
+
+ if (uiResourceId == SystemUIResourceType.OVERSCROLL_EDGE) {
+ res = Resources.getSystem();
+ resId = res.getIdentifier("android:drawable/overscroll_edge", null, null);
+ } else if (uiResourceId == SystemUIResourceType.OVERSCROLL_GLOW) {
+ res = Resources.getSystem();
+ resId = res.getIdentifier("android:drawable/overscroll_glow", null, null);
+ } else if (uiResourceId == SystemUIResourceType.OVERSCROLL_REFRESH_IDLE) {
+ res = context.getResources();
+ resId = R.drawable.refresh_gray;
+ } else if (uiResourceId == SystemUIResourceType.OVERSCROLL_REFRESH_ACTIVE) {
+ res = context.getResources();
+ resId = R.drawable.refresh_blue;
+ } else {
+ assert false;
+ }
+
+ if (res == null) return null;
+ if (resId == 0) return null;
+
+ return getResourceBitmap(res, resId, reqWidth, reqHeight);
+ }
+}
« no previous file with comments | « content/public/android/java/res/drawable-xxxhdpi/refresh_gray.png ('k') | content/public/browser/android/content_view_core.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698