committed by
bunnei
7 changed files with 41 additions and 138 deletions
-
4src/android/app/build.gradle
-
44src/android/app/src/main/java/org/yuzu/yuzu_emu/adapters/GameAdapter.kt
-
1src/android/app/src/main/java/org/yuzu/yuzu_emu/ui/main/MainActivity.kt
-
3src/android/app/src/main/java/org/yuzu/yuzu_emu/ui/platform/PlatformGamesFragment.kt
-
25src/android/app/src/main/java/org/yuzu/yuzu_emu/utils/GameIconRequestHandler.kt
-
45src/android/app/src/main/java/org/yuzu/yuzu_emu/utils/PicassoRoundedCornersTransformation.java
-
57src/android/app/src/main/java/org/yuzu/yuzu_emu/utils/PicassoUtils.java
@ -1,25 +0,0 @@ |
|||||
// SPDX-FileCopyrightText: 2023 yuzu Emulator Project |
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later |
|
||||
|
|
||||
package org.yuzu.yuzu_emu.utils |
|
||||
|
|
||||
import android.graphics.BitmapFactory |
|
||||
import com.squareup.picasso.Picasso |
|
||||
import com.squareup.picasso.Request |
|
||||
import com.squareup.picasso.RequestHandler |
|
||||
import org.yuzu.yuzu_emu.NativeLibrary |
|
||||
|
|
||||
class GameIconRequestHandler : RequestHandler() { |
|
||||
override fun canHandleRequest(data: Request): Boolean { |
|
||||
return "content" == data.uri.scheme |
|
||||
} |
|
||||
|
|
||||
override fun load(request: Request, networkPolicy: Int): Result { |
|
||||
val gamePath = request.uri.toString() |
|
||||
val data = NativeLibrary.GetIcon(gamePath) |
|
||||
val options = BitmapFactory.Options() |
|
||||
options.inMutable = true |
|
||||
val bitmap = BitmapFactory.decodeByteArray(data, 0, data.size, options) |
|
||||
return Result(bitmap, Picasso.LoadedFrom.DISK) |
|
||||
} |
|
||||
} |
|
||||
@ -1,45 +0,0 @@ |
|||||
package org.yuzu.yuzu_emu.utils; |
|
||||
|
|
||||
import android.graphics.Bitmap; |
|
||||
import android.graphics.BitmapShader; |
|
||||
import android.graphics.Canvas; |
|
||||
import android.graphics.Paint; |
|
||||
import android.graphics.Rect; |
|
||||
import android.graphics.RectF; |
|
||||
|
|
||||
import com.squareup.picasso.Transformation; |
|
||||
|
|
||||
public class PicassoRoundedCornersTransformation implements Transformation { |
|
||||
@Override |
|
||||
public Bitmap transform(Bitmap icon) { |
|
||||
final int width = icon.getWidth(); |
|
||||
final int height = icon.getHeight(); |
|
||||
final Rect rect = new Rect(0, 0, width, height); |
|
||||
final int size = Math.min(width, height); |
|
||||
final int x = (width - size) / 2; |
|
||||
final int y = (height - size) / 2; |
|
||||
|
|
||||
Bitmap squaredBitmap = Bitmap.createBitmap(icon, x, y, size, size); |
|
||||
if (squaredBitmap != icon) { |
|
||||
icon.recycle(); |
|
||||
} |
|
||||
|
|
||||
Bitmap output = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); |
|
||||
Canvas canvas = new Canvas(output); |
|
||||
BitmapShader shader = new BitmapShader(squaredBitmap, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP); |
|
||||
Paint paint = new Paint(); |
|
||||
paint.setAntiAlias(true); |
|
||||
paint.setShader(shader); |
|
||||
|
|
||||
canvas.drawRoundRect(new RectF(rect), 10, 10, paint); |
|
||||
|
|
||||
squaredBitmap.recycle(); |
|
||||
|
|
||||
return output; |
|
||||
} |
|
||||
|
|
||||
@Override |
|
||||
public String key() { |
|
||||
return "circle"; |
|
||||
} |
|
||||
} |
|
||||
@ -1,57 +0,0 @@ |
|||||
package org.yuzu.yuzu_emu.utils; |
|
||||
|
|
||||
import android.graphics.Bitmap; |
|
||||
import android.net.Uri; |
|
||||
import android.widget.ImageView; |
|
||||
|
|
||||
import com.squareup.picasso.Picasso; |
|
||||
|
|
||||
import org.yuzu.yuzu_emu.YuzuApplication; |
|
||||
import org.yuzu.yuzu_emu.R; |
|
||||
|
|
||||
import java.io.IOException; |
|
||||
|
|
||||
import androidx.annotation.Nullable; |
|
||||
|
|
||||
public class PicassoUtils { |
|
||||
private static boolean mPicassoInitialized = false; |
|
||||
|
|
||||
public static void init() { |
|
||||
if (mPicassoInitialized) { |
|
||||
return; |
|
||||
} |
|
||||
Picasso picassoInstance = new Picasso.Builder(YuzuApplication.getAppContext()) |
|
||||
.addRequestHandler(new GameIconRequestHandler()) |
|
||||
.build(); |
|
||||
|
|
||||
Picasso.setSingletonInstance(picassoInstance); |
|
||||
mPicassoInitialized = true; |
|
||||
} |
|
||||
|
|
||||
public static void loadGameIcon(ImageView imageView, String gamePath) { |
|
||||
Picasso |
|
||||
.get() |
|
||||
.load(Uri.parse(gamePath)) |
|
||||
.fit() |
|
||||
.centerInside() |
|
||||
.config(Bitmap.Config.RGB_565) |
|
||||
.error(R.drawable.no_icon) |
|
||||
.transform(new PicassoRoundedCornersTransformation()) |
|
||||
.into(imageView); |
|
||||
} |
|
||||
|
|
||||
// Blocking call. Load image from file and crop/resize it to fit in width x height. |
|
||||
@Nullable |
|
||||
public static Bitmap LoadBitmapFromFile(String uri, int width, int height) { |
|
||||
try { |
|
||||
return Picasso.get() |
|
||||
.load(Uri.parse(uri)) |
|
||||
.config(Bitmap.Config.ARGB_8888) |
|
||||
.centerCrop() |
|
||||
.resize(width, height) |
|
||||
.get(); |
|
||||
} catch (IOException e) { |
|
||||
return null; |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue