Use MCHeads for avatar head with layers

Idea suggested by @Syjalo 1 month ago 😂
This commit is contained in:
khanhduytran0 2021-03-01 15:50:56 +07:00
parent ed0b2b8798
commit c9359dc2c5
4 changed files with 24 additions and 37 deletions

View File

@ -1,9 +1,9 @@
%s (Minecraft Java Launcher for Android), version %s by Tran Khanh Duy (based on "Boardwalk" app)<br>
* License:<br>
• This application is licensed under <a href="https://github.com/khanhduytran0/PojavLauncher/blob/master/LICENSE">GNU GPLv3</a>.<br>
• This application is licensed under <a href="https://github.com/PojavLauncherTeam/PojavLauncher/blob/master/LICENSE">GNU GPLv3</a>.<br>
* Third party components and their licenses:<br>
* Credits / Third party components and their licenses:<br>
• Apache Commons Compress (unknown or Apache License 2.0).<br>
• exp4j: <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache License 2.0</a>.<br>
• GL4ES: <a href="https://github.com/ptitSeb/gl4es/blob/master/LICENSE">MIT License</a>.<br>
@ -11,9 +11,12 @@
• OpenJDK: <a href="https://openjdk.java.net/legal/gplv2+ce.html">GNU GPLv2 License</a>.<br>
• LWJGL: <a href="http://legacy.lwjgl.org/license.php.html">LWJGL 2's License</a>.<br><br>
• pro-gradle: <a href="https://github.com/pro-grade/pro-grade/blob/master/LICENSE.txt">Apache License 2.0</a>.<br>
• <a href="https://github.com/PojavLauncherTeam/PojavLauncher#credits--third-party-components-and-their-licenses">More (check at GitHub)</a>.
• <a href="https://raw.githubusercontent.com/PojavLauncherTeam/PojavLauncher/v3_openjdk/GPLAY_PRIVACY_POLICY">Privacy policy</a>.
• Thanks to <a href="https://mc-heads.net">MCHeads</a> for providing Minecraft avatars.
* Notes:<br>
- This app is under development and will not be stable.<br>
- This app is under development and might not be stable.<br>
- This app is not affiliated with Minecraft, Mojang or Microsoft.<br><br>
* Translators can be found at <a href="https://crowdin.com/project/pojavlauncher">Crowdin</a>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 308 B

View File

@ -136,7 +136,6 @@ public class PojavLoginActivity extends BaseActivity
Thread.sleep(2000);
} catch (InterruptedException e) {}
publishProgress("visible");
while (Build.VERSION.SDK_INT >= 23 && !isStorageAllowed()){
@ -655,22 +654,12 @@ public class PojavLoginActivity extends BaseActivity
String accNameStr = s.substring(0, s.length() - 5);
String skinFaceBase64 = MinecraftAccount.load(accNameStr).skinFaceBase64;
Bitmap bitmap = Bitmap.createBitmap(8, 8, Bitmap.Config.ARGB_8888);
if (skinFaceBase64 != null) {
byte[] faceIconBytes = Base64.decode(skinFaceBase64, Base64.DEFAULT);
bitmap = BitmapFactory.decodeByteArray(faceIconBytes, 0, faceIconBytes.length);
} else {
try {
bitmap = BitmapFactory.decodeStream(getAssets().open("ic_steve.png"));
} catch (IOException e) {
// Should never happen
e.printStackTrace();
}
}
accountName.setCompoundDrawablesWithIntrinsicBounds(new BitmapDrawable(getResources(),
Bitmap.createScaledBitmap(bitmap, 80, 80, false)),
null, null, null);
byte[] faceIconBytes = Base64.decode(skinFaceBase64, Base64.DEFAULT);
Bitmap bitmap = BitmapFactory.decodeByteArray(faceIconBytes, 0, faceIconBytes.length);
accountName.setCompoundDrawablesWithIntrinsicBounds(new BitmapDrawable(getResources(),
bitmap),
null, null, null);
accountName.setText(accNameStr);
accountListLayout.addView(child);

View File

@ -6,36 +6,24 @@ import java.io.*;
import com.google.gson.*;
import android.graphics.Bitmap;
import android.util.Base64;
import org.apache.commons.io.IOUtils;
public class MinecraftAccount
{
public String accessToken = "0"; // access token
public String clientToken = "0"; // clientID: refresh and invalidate
public String profileId = "0"; // authenticate UUID
public String profileId = "0"; // profile UUID, for obtaining skin
public String username = "Steve";
public String selectedVersion = "1.7.10";
public boolean isMicrosoft = false;
public String msaRefreshToken = "0";
public String skinFaceBase64;
public void updateSkinFace() {
void updateSkinFace(String uuid) {
try {
Bitmap bSkin = AccountSkin.getSkin(profileId);
if (bSkin.getWidth() != 64 || bSkin.getHeight() != 64) {
Log.w("SkinLoader", "Only skin size 64x64 is currently supported, this skin is " + bSkin.getWidth() + "x" + bSkin.getHeight());
return;
}
int[] pixels = new int[8 * 8];
bSkin.getPixels(pixels, 0, 8, 8, 8, 8, 8);
bSkin.recycle();
ByteArrayOutputStream outByteArr = new ByteArrayOutputStream();
Bitmap bFace = Bitmap.createBitmap(pixels, 8, 8, Bitmap.Config.ARGB_8888);
bFace.compress(Bitmap.CompressFormat.PNG, 100, outByteArr);
bFace.recycle();
skinFaceBase64 = Base64.encodeToString(outByteArr.toByteArray(), Base64.DEFAULT);
outByteArr.close();
File skinFile = File.createTempFile("skin", ".png", new File(Tools.DIR_DATA, "cache"));
Tools.downloadFile("https://mc-heads.net/head/" + uuid + "/100", skinFile.getAbsolutePath());
skinFaceBase64 = Base64.encodeToString(IOUtils.toByteArray(new FileInputStream(skinFile)), Base64.DEFAULT);
Log.i("SkinLoader", "Update skin face success");
} catch (IOException e) {
@ -45,6 +33,10 @@ public class MinecraftAccount
}
}
public void updateSkinFace() {
updateSkinFace(profileId);
}
public String save(String outPath) throws IOException {
Tools.write(outPath, Tools.GLOBAL_GSON.toJson(this));
return username;
@ -79,6 +71,9 @@ public class MinecraftAccount
if (acc.msaRefreshToken == null) {
acc.msaRefreshToken = "0";
}
if (acc.skinFaceBase64 == null) {
acc.updateSkinFace("MHF_Steve");
}
return acc;
} catch(IOException e) {
Log.e(MinecraftAccount.class.getName(), "Caught an exception while loading the profile",e);