mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 20:33:53 +01:00
Make thumbnails load faster by loading smaller Thumbnails
GitHub: https://github.com/wikimedia/apps-android-commons/pull/25 Change-Id: I0af540a1d84348a7a3e67c6037cd509b88b84b21
This commit is contained in:
parent
35736733c3
commit
81e79cf096
3 changed files with 22 additions and 0 deletions
|
|
@ -1,6 +1,7 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:custom="http://schemas.android.com/apk/res/org.wikimedia.commons"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
|
|
@ -20,6 +21,7 @@
|
|||
android:layout_width="fill_parent"
|
||||
android:layout_height="240dp"
|
||||
android:scaleType="centerCrop"
|
||||
custom:isThumbnail="true"
|
||||
/>
|
||||
|
||||
<LinearLayout
|
||||
|
|
|
|||
6
commons/res/values/views.xml
Normal file
6
commons/res/values/views.xml
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<declare-styleable name="MediaWikiImageView">
|
||||
<attr name="isThumbnail" format="boolean" />
|
||||
</declare-styleable>
|
||||
</resources>
|
||||
|
|
@ -16,6 +16,7 @@
|
|||
package org.wikimedia.commons;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.drawable.BitmapDrawable;
|
||||
import android.text.TextUtils;
|
||||
import android.util.AttributeSet;
|
||||
|
|
@ -41,12 +42,16 @@ public class MediaWikiImageView extends ImageView {
|
|||
|
||||
private View loadingView;
|
||||
|
||||
private boolean isThumbnail;
|
||||
|
||||
public MediaWikiImageView(Context context) {
|
||||
this(context, null);
|
||||
}
|
||||
|
||||
public MediaWikiImageView(Context context, AttributeSet attrs) {
|
||||
this(context, attrs, 0);
|
||||
TypedArray actualAttrs = context.getTheme().obtainStyledAttributes(attrs, R.styleable.MediaWikiImageView, 0, 0);
|
||||
isThumbnail = actualAttrs.getBoolean(0, false);
|
||||
}
|
||||
|
||||
public MediaWikiImageView(Context context, AttributeSet attrs, int defStyle) {
|
||||
|
|
@ -84,6 +89,15 @@ public class MediaWikiImageView extends ImageView {
|
|||
return;
|
||||
}
|
||||
|
||||
|
||||
// Do not count for density when loading thumbnails.
|
||||
// FIXME: Use another 'algorithm' that doesn't punish low res devices
|
||||
if(isThumbnail) {
|
||||
float dpFactor = Math.max(getResources().getDisplayMetrics().density, 1.0f);
|
||||
width = (int) (width / dpFactor);
|
||||
height = (int) (height / dpFactor);
|
||||
}
|
||||
|
||||
final String mUrl;
|
||||
if(tryOriginal) {
|
||||
mUrl = mMedia.getImageUrl();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue