From ba935d40ba73bce84617b86b51d9ec6d85e370e1 Mon Sep 17 00:00:00 2001 From: Mahdi Hijazi Date: Tue, 21 Mar 2017 17:26:10 +0100 Subject: [PATCH] [Android] Load the game banner from the iso and use if no screenshot is available It doesn't look that good since the banners are 96x32 but it still better than nothing. --- .../dolphinemu/adapters/GameAdapter.java | 16 +------ .../dolphinemu/adapters/GameRowPresenter.java | 16 +------ .../utils/GameBannerRequestHandler.java | 31 +++++++++++++ .../dolphinemu/utils/PicassoUtils.java | 45 +++++++++++++++++++ 4 files changed, 80 insertions(+), 28 deletions(-) create mode 100644 Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/GameBannerRequestHandler.java create mode 100644 Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/PicassoUtils.java diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/adapters/GameAdapter.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/adapters/GameAdapter.java index dafe77bef0..153470df6a 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/adapters/GameAdapter.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/adapters/GameAdapter.java @@ -3,20 +3,18 @@ package org.dolphinemu.dolphinemu.adapters; import android.app.Activity; import android.database.Cursor; import android.database.DataSetObserver; -import android.graphics.Bitmap; import android.graphics.Rect; import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import com.squareup.picasso.Picasso; - import org.dolphinemu.dolphinemu.R; import org.dolphinemu.dolphinemu.activities.EmulationActivity; import org.dolphinemu.dolphinemu.dialogs.GameDetailsDialog; import org.dolphinemu.dolphinemu.model.GameDatabase; import org.dolphinemu.dolphinemu.utils.Log; +import org.dolphinemu.dolphinemu.utils.PicassoUtils; import org.dolphinemu.dolphinemu.viewholders.GameViewHolder; /** @@ -80,17 +78,7 @@ public final class GameAdapter extends RecyclerView.Adapter impl if (mCursor.moveToPosition(position)) { String screenPath = mCursor.getString(GameDatabase.GAME_COLUMN_SCREENSHOT_PATH); - - // Fill in the view contents. - Picasso.with(holder.imageScreenshot.getContext()) - .load(screenPath) - .fit() - .centerCrop() - .noFade() - .noPlaceholder() - .config(Bitmap.Config.RGB_565) - .error(R.drawable.no_banner) - .into(holder.imageScreenshot); + PicassoUtils.loadGameBanner(holder.imageScreenshot, screenPath, mCursor.getString(GameDatabase.GAME_COLUMN_PATH)); holder.textGameTitle.setText(mCursor.getString(GameDatabase.GAME_COLUMN_TITLE)); holder.textCompany.setText(mCursor.getString(GameDatabase.GAME_COLUMN_COMPANY)); diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/adapters/GameRowPresenter.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/adapters/GameRowPresenter.java index c5f6364cc1..2cfc5545af 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/adapters/GameRowPresenter.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/adapters/GameRowPresenter.java @@ -1,15 +1,13 @@ package org.dolphinemu.dolphinemu.adapters; -import android.graphics.Bitmap; import android.support.v17.leanback.widget.ImageCardView; import android.support.v17.leanback.widget.Presenter; import android.view.ViewGroup; import android.widget.ImageView; -import com.squareup.picasso.Picasso; - import org.dolphinemu.dolphinemu.R; import org.dolphinemu.dolphinemu.model.Game; +import org.dolphinemu.dolphinemu.utils.PicassoUtils; import org.dolphinemu.dolphinemu.viewholders.TvGameViewHolder; /** @@ -52,17 +50,7 @@ public final class GameRowPresenter extends Presenter String screenPath = game.getScreenshotPath(); holder.imageScreenshot.setImageDrawable(null); - - // Fill in the view contents. - Picasso.with(holder.imageScreenshot.getContext()) - .load(screenPath) - .fit() - .centerCrop() - .noFade() - .noPlaceholder() - .config(Bitmap.Config.RGB_565) - .error(R.drawable.no_banner) - .into(holder.imageScreenshot); + PicassoUtils.loadGameBanner(holder.imageScreenshot, screenPath, game.getPath()); holder.cardParent.setTitleText(game.getTitle()); holder.cardParent.setContentText(game.getCompany()); diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/GameBannerRequestHandler.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/GameBannerRequestHandler.java new file mode 100644 index 0000000000..526fb7fa2a --- /dev/null +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/GameBannerRequestHandler.java @@ -0,0 +1,31 @@ +package org.dolphinemu.dolphinemu.utils; + +import android.graphics.Bitmap; + +import com.squareup.picasso.Picasso; +import com.squareup.picasso.Request; +import com.squareup.picasso.RequestHandler; + +import org.dolphinemu.dolphinemu.NativeLibrary; + +import java.io.IOException; +import java.nio.IntBuffer; + +public class GameBannerRequestHandler extends RequestHandler { + @Override + public boolean canHandleRequest(Request data) { + return "iso".equals(data.uri.getScheme()); + } + + @Override + public Result load(Request request, int networkPolicy) throws IOException { + String url = request.uri.getHost() + request.uri.getPath(); + int[] vector = NativeLibrary.GetBanner(url); + int width = 96; + int height = 32; + Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); + bitmap.setPixels(vector, 0, width, 0, 0, width, height); + bitmap.copyPixelsFromBuffer(IntBuffer.wrap(vector)); + return new Result(bitmap, Picasso.LoadedFrom.DISK); + } +} diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/PicassoUtils.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/PicassoUtils.java new file mode 100644 index 0000000000..36a00d884d --- /dev/null +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/PicassoUtils.java @@ -0,0 +1,45 @@ +package org.dolphinemu.dolphinemu.utils; + +import android.graphics.Bitmap; +import android.net.Uri; +import android.widget.ImageView; + +import com.squareup.picasso.Picasso; + +import org.dolphinemu.dolphinemu.R; + +import java.io.File; +import java.net.URI; + +public class PicassoUtils { + public static void loadGameBanner(ImageView imageView, String screenshotPath, String gamePath) { + File file = new File(URI.create(screenshotPath)); + if (file.exists()) { + // Fill in the view contents. + Picasso.with(imageView.getContext()) + .load(screenshotPath) + .fit() + .centerCrop() + .noFade() + .noPlaceholder() + .config(Bitmap.Config.RGB_565) + .error(R.drawable.no_banner) + .into(imageView); + } else { + Picasso picassoInstance = new Picasso.Builder(imageView.getContext()) + .addRequestHandler(new GameBannerRequestHandler()) + .build(); + + picassoInstance + .load(Uri.parse("iso:/" + gamePath)) + .fit() + .noFade() + .noPlaceholder() + .config(Bitmap.Config.RGB_565) + .error(R.drawable.no_banner) + .into(imageView); + } + + + } +}