mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2024-11-14 21:37:52 -07:00
Merge pull request #5118 from mahdihijazi/master
[Android] Load the game banner from the ROM and use it if no screenshot is available
This commit is contained in:
commit
9b1e2c2b1e
@ -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<GameViewHolder> 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));
|
||||
|
@ -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());
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user