Skip to content

Commit

Permalink
Merge pull request #7302 from zackhow/covers
Browse files Browse the repository at this point in the history
Android: Update mobile and TV to use game covers
  • Loading branch information
degasus committed Aug 13, 2018
2 parents 84c2451 + 3f21975 commit 3f96f96
Show file tree
Hide file tree
Showing 17 changed files with 223 additions and 111 deletions.
Expand Up @@ -37,7 +37,7 @@ public ViewHolder onCreateViewHolder(ViewGroup parent)
ImageCardView gameCard = new ImageCardView(parent.getContext());

gameCard.setMainImageAdjustViewBounds(true);
gameCard.setMainImageDimensions(480, 320);
gameCard.setMainImageDimensions(240, 336);
gameCard.setMainImageScaleType(ImageView.ScaleType.CENTER_CROP);

gameCard.setFocusable(true);
Expand Down
Expand Up @@ -199,6 +199,7 @@ private void addConfigSettings(ArrayList<SettingsItem> sl)

sl.add(new SubmenuSetting(null, null, R.string.gamecube_submenu, 0, MenuTag.CONFIG_GAME_CUBE));
sl.add(new SubmenuSetting(null, null, R.string.wii_submenu, 0, MenuTag.CONFIG_WII));
sl.add(new HeaderSetting(null, null, R.string.gametdb_thanks, 0));
}

private void addGeneralSettings(ArrayList<SettingsItem> sl)
Expand Down
@@ -1,7 +1,11 @@
package org.dolphinemu.dolphinemu.model;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Environment;

import org.dolphinemu.dolphinemu.utils.CoverHelper;

public class GameFile
{
private long mPointer; // Do not rename or move without editing the native code
Expand All @@ -19,12 +23,24 @@ private GameFile(long pointer)
public native String getDescription();
public native String getCompany();
public native int getCountry();
public native int getRegion();
public native String getPath();
public native String getGameId();
public native int[] getBanner();
public native int getBannerWidth();
public native int getBannerHeight();

public String getCoverPath()
{
return Environment.getExternalStorageDirectory().getPath() +
"/dolphin-emu/Cache/GameCovers/" + getGameId() + ".png";
}

public String getCustomCoverPath()
{
return getPath().substring(0, getPath().lastIndexOf(".")) + ".cover.png";
}

public String getScreenshotPath()
{
String gameId = getGameId();
Expand Down
Expand Up @@ -12,8 +12,6 @@
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.concurrent.atomic.AtomicReference;

Expand Down
Expand Up @@ -154,6 +154,7 @@ private PreviewProgram buildProgram(long channelId, GameFile game)
.setTitle(game.getTitle())
.setDescription(game.getDescription())
.setPosterArtUri(banner)
.setPosterArtAspectRatio(TvContractCompat.PreviewPrograms.ASPECT_RATIO_2_3)
.setIntentUri(appLinkUri);
return builder.build();
}
Expand Down
Expand Up @@ -2,7 +2,6 @@

import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Bundle;
import android.support.v17.leanback.app.BrowseFragment;
import android.support.v17.leanback.app.BrowseSupportFragment;
Expand Down Expand Up @@ -197,8 +196,6 @@ private void buildRowsAdapter()
GameFileCacheService.startLoad(this);
}

mRowsAdapter.add(buildSettingsRow());

for (Platform platform : Platform.values())
{
ListRow row = buildGamesRow(platform, GameFileCacheService.getGameFilesForPlatform(platform));
Expand All @@ -210,6 +207,8 @@ private void buildRowsAdapter()
}
}

mRowsAdapter.add(buildSettingsRow());

mBrowseFragment.setAdapter(mRowsAdapter);
}

Expand Down
@@ -0,0 +1,81 @@
package org.dolphinemu.dolphinemu.utils;

import android.graphics.Bitmap;

import org.dolphinemu.dolphinemu.model.GameFile;
import org.dolphinemu.dolphinemu.ui.platform.Platform;

import java.io.FileOutputStream;

public final class CoverHelper
{
private static String baseUrl = "https://art.gametdb.com/wii/cover/%s/%s.png";

public static String buildGameTDBUrl(GameFile game, String region)
{
String gameId = game.getGameId();
if(game.getPlatform() == 2) // WiiWare
gameId = gameId.substring(0,4);
return String.format(baseUrl, region, gameId);
}

public static String getRegion(GameFile game)
{
String region;
switch(game.getRegion())
{
case 0: // NTSC_J
region = "JA";
break;
case 1: // NTSC_U
region = "US";
break;
case 4: // NTSC_K
region = "KO";
break;
case 2: // PAL
switch (game.getCountry())
{
case 2: // German
region = "DE";
break;
case 3: // French
region = "FR";
break;
case 4: // Spanish
region = "ES";
break;
case 5: // Italian
region = "IT";
break;
case 6: // Dutch
region = "NL";
break;
case 1: // English
default:
region = "EN";
break;
}
break;
case 3: // Unknown
default:
region = "EN";
break;
}
return region;
}

public static void saveCover(Bitmap cover, String path)
{
try
{
FileOutputStream out = new FileOutputStream(path);
cover.compress(Bitmap.CompressFormat.PNG, 100, out);
out.close();
}
catch (Exception e)
{
// Do nothing
}
}
}

This file was deleted.

@@ -1,46 +1,114 @@
package org.dolphinemu.dolphinemu.utils;

import android.graphics.Bitmap;
import android.net.Uri;
import android.graphics.drawable.BitmapDrawable;
import android.widget.ImageView;

import com.squareup.picasso.Callback;
import com.squareup.picasso.Picasso;

import org.dolphinemu.dolphinemu.R;
import org.dolphinemu.dolphinemu.model.GameFile;

import java.io.File;
import java.net.URI;

public class PicassoUtils {
public static void loadGameBanner(ImageView imageView, GameFile gameFile) {
File screenshotFile = new File(URI.create(gameFile.getScreenshotPath()));
if (screenshotFile.exists()) {
// Fill in the view contents.
public static void loadGameBanner(ImageView imageView, GameFile gameFile)
{
File cover = new File(gameFile.getCustomCoverPath());
if (cover.exists())
{
Picasso.with(imageView.getContext())
.load(gameFile.getScreenshotPath())
.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(gameFile))
.build();

picassoInstance
.load(Uri.parse("iso:/" + gameFile.getPath()))
.fit()
.noFade()
.noPlaceholder()
.config(Bitmap.Config.RGB_565)
.error(R.drawable.no_banner)
.into(imageView);
.load(cover)
.fit()
.centerCrop()
.noFade()
.noPlaceholder()
.config(Bitmap.Config.ARGB_8888)
.error(R.drawable.no_banner)
.into(imageView);
}
else if ((cover = new File(gameFile.getCoverPath())).exists())
{
Picasso.with(imageView.getContext())
.load(cover)
.fit()
.centerCrop()
.noFade()
.noPlaceholder()
.config(Bitmap.Config.ARGB_8888)
.error(R.drawable.no_banner)
.into(imageView);
}
/**
* GameTDB has a pretty close to complete collection for US/EN covers. First pass at getting
* the cover will be by the disk's region, second will be the US cover, and third EN.
*/
else
{
Picasso.with(imageView.getContext())
.load(CoverHelper.buildGameTDBUrl(gameFile, CoverHelper.getRegion(gameFile)))
.fit()
.centerCrop()
.noFade()
.noPlaceholder()
.config(Bitmap.Config.ARGB_8888)
.error(R.drawable.no_banner)
.into(imageView, new Callback()
{
@Override
public void onSuccess()
{
CoverHelper.saveCover(((BitmapDrawable) imageView.getDrawable()).getBitmap(),
gameFile.getCoverPath());
}
@Override
public void onError() // Second pass using US region
{
Picasso.with(imageView.getContext())
.load(CoverHelper.buildGameTDBUrl(gameFile, "US"))
.fit()
.centerCrop()
.noFade()
.noPlaceholder()
.config(Bitmap.Config.ARGB_8888)
.error(R.drawable.no_banner)
.into(imageView, new Callback()
{
@Override
public void onSuccess()
{
CoverHelper.saveCover(((BitmapDrawable) imageView.getDrawable()).getBitmap(),
gameFile.getCoverPath());
}
@Override
public void onError() // Third and last pass using EN region
{
Picasso.with(imageView.getContext())
.load(CoverHelper.buildGameTDBUrl(gameFile, "EN"))
.fit()
.centerCrop()
.noFade()
.noPlaceholder()
.config(Bitmap.Config.ARGB_8888)
.error(R.drawable.no_banner)
.into(imageView, new Callback()
{
@Override
public void onSuccess()
{
CoverHelper.saveCover(((BitmapDrawable) imageView.getDrawable()).getBitmap(),
gameFile.getCoverPath());
}
@Override
public void onError()
{
}
});
}
});
}
});
}


}
}

0 comments on commit 3f96f96

Please sign in to comment.