-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Games: Improve the archive, achievements, and ranking functions (#2576)
Co-authored-by: Marvin W <[email protected]>
- Loading branch information
1 parent
76f1aba
commit 6cae97d
Showing
60 changed files
with
5,047 additions
and
29 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
33 changes: 33 additions & 0 deletions
33
play-services-base/core/src/main/kotlin/org/microg/gms/utils/BitmapUtils.kt
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,33 @@ | ||
/** | ||
* SPDX-FileCopyrightText: 2024 microG Project Team | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.microg.gms.utils | ||
|
||
import android.graphics.Bitmap | ||
import kotlin.math.sqrt | ||
|
||
object BitmapUtils { | ||
|
||
fun getBitmapSize(bitmap: Bitmap?): Int { | ||
if (bitmap != null) { | ||
return bitmap.height * bitmap.rowBytes | ||
} | ||
return 0 | ||
} | ||
|
||
fun scaledBitmap(bitmap: Bitmap, maxSize: Float): Bitmap { | ||
val height: Int = bitmap.getHeight() | ||
val width: Int = bitmap.getWidth() | ||
val sqrt = | ||
sqrt(((maxSize) / ((width.toFloat()) / (height.toFloat()) * ((bitmap.getRowBytes() / width).toFloat()))).toDouble()) | ||
.toInt() | ||
return Bitmap.createScaledBitmap( | ||
bitmap, | ||
(((sqrt.toFloat()) / (height.toFloat()) * (width.toFloat())).toInt()), | ||
sqrt, | ||
true | ||
) | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
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
101 changes: 101 additions & 0 deletions
101
play-services-base/src/main/java/com/google/android/gms/common/util/IOUtils.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,101 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2024 microG Project Team | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
package com.google.android.gms.common.util; | ||
|
||
import android.os.ParcelFileDescriptor; | ||
|
||
import androidx.annotation.NonNull; | ||
|
||
import java.io.ByteArrayOutputStream; | ||
import java.io.Closeable; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.OutputStream; | ||
|
||
public final class IOUtils { | ||
private IOUtils() { | ||
} | ||
|
||
public static void closeQuietly(ParcelFileDescriptor parcelFileDescriptor) { | ||
if (parcelFileDescriptor != null) { | ||
try { | ||
parcelFileDescriptor.close(); | ||
} catch (IOException unused) { | ||
} | ||
} | ||
} | ||
|
||
public static long copyStream(@NonNull InputStream inputStream, @NonNull OutputStream outputStream) throws IOException { | ||
return copyStream(inputStream, outputStream, false, 1024); | ||
} | ||
|
||
public static boolean isGzipByteBuffer(@NonNull byte[] bArr) { | ||
if (bArr.length > 1) { | ||
if ((((bArr[1] & 255) << 8) | (bArr[0] & 255)) == 35615) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
public static byte[] readInputStreamFully(@NonNull InputStream inputStream) throws IOException { | ||
return readInputStreamFully(inputStream, true); | ||
} | ||
|
||
public static byte[] toByteArray(@NonNull InputStream inputStream) throws IOException { | ||
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); | ||
byte[] bArr = new byte[4096]; | ||
while (true) { | ||
int read = inputStream.read(bArr); | ||
if (read == -1) { | ||
return byteArrayOutputStream.toByteArray(); | ||
} | ||
byteArrayOutputStream.write(bArr, 0, read); | ||
} | ||
} | ||
|
||
|
||
public static void closeQuietly(Closeable closeable) { | ||
if (closeable != null) { | ||
try { | ||
closeable.close(); | ||
} catch (IOException unused) { | ||
} | ||
} | ||
} | ||
|
||
public static long copyStream(@NonNull InputStream inputStream, @NonNull OutputStream outputStream, boolean z, int i) throws IOException { | ||
byte[] bArr = new byte[i]; | ||
long j = 0; | ||
while (true) { | ||
try { | ||
int read = inputStream.read(bArr, 0, i); | ||
if (read == -1) { | ||
break; | ||
} | ||
j += read; | ||
outputStream.write(bArr, 0, read); | ||
} catch (Throwable th) { | ||
if (z) { | ||
closeQuietly(inputStream); | ||
closeQuietly(outputStream); | ||
} | ||
throw th; | ||
} | ||
} | ||
if (z) { | ||
closeQuietly(inputStream); | ||
closeQuietly(outputStream); | ||
} | ||
return j; | ||
} | ||
|
||
public static byte[] readInputStreamFully(@NonNull InputStream inputStream, boolean z) throws IOException { | ||
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); | ||
copyStream(inputStream, byteArrayOutputStream, z, 1024); | ||
return byteArrayOutputStream.toByteArray(); | ||
} | ||
|
||
} |
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
Oops, something went wrong.