Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7302 from zackhow/covers
Android: Update mobile and TV to use game covers
- Loading branch information
Showing
17 changed files
with
223 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/CoverHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
} | ||
} |
36 changes: 0 additions & 36 deletions
36
...e/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/GameBannerRequestHandler.java
This file was deleted.
Oops, something went wrong.
126 changes: 97 additions & 29 deletions
126
Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/PicassoUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() | ||
{ | ||
} | ||
}); | ||
} | ||
}); | ||
} | ||
}); | ||
} | ||
|
||
|
||
} | ||
} |
Oops, something went wrong.