Skip to content

Commit

Permalink
Textures, date format, load libminecraftpe.so from official APK
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuowei committed Jan 7, 2013
1 parent 2109896 commit 2d234ea
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 22 deletions.
4 changes: 2 additions & 2 deletions AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission
android:name="android.permission.VIBRATE"/>
<application android:label="Minecraft" >
<application android:label="MCPELauncher" >
<activity android:name="com.mojang.minecraftpe.MainActivity"
android:label="Minecraft"
android:label="MCPELauncher"
android:configChanges="orientation|keyboardHidden">
<meta-data android:name="android.app.lib_name"
android:value="minecraftpe"/>
Expand Down
2 changes: 2 additions & 0 deletions ant.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@
# 'key.alias' for the name of the key to use.
# The password will be asked during the build when you use the 'release' target.

key.store=androidreleasekey.keystore
key.alias=androidreleasekey
2 changes: 1 addition & 1 deletion build.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<project name="MainActivity" default="help">
<project name="MCPELauncher" default="help">

<!-- The local.properties file is created and updated by the 'android' tool.
It contains the path to the SDK. It should *NOT* be checked into
Expand Down
112 changes: 93 additions & 19 deletions src/com/mojang/minecraftpe/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,27 @@
package com.mojang.minecraftpe;

import java.io.File;
import java.io.InputStream;

import java.text.DateFormat;

import java.util.Date;
import java.util.Locale;

import android.app.Activity;
import android.app.NativeActivity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.os.Environment;
import android.view.View;
import android.util.DisplayMetrics;

import net.zhuoweizhang.mcpelauncher.TexturePack;
import net.zhuoweizhang.mcpelauncher.ZipTexturePack;

public class MainActivity extends NativeActivity
{

Expand All @@ -22,20 +37,39 @@ public class MainActivity extends NativeActivity

protected DisplayMetrics displayMetrics;

protected TexturePack texturePack;

protected Context minecraftApkContext;

/** Called when the activity is first created. */

@Override
public void onCreate(Bundle savedInstanceState) {
System.out.println("oncreate");
try {
System.load("/data/data/com.mojang.minecraftpe/lib/libminecraftpe.so");
} catch (Exception e) {
e.printStackTrace();
}
nativeRegisterThis();
super.onCreate(savedInstanceState);

/*View contentView = this.findViewById(android.R.id.content);

displayMetrics = new DisplayMetrics();

contentView.getDisplay().getMetrics(displayMetrics);*/
getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);

super.onCreate(savedInstanceState);

try {
texturePack = new ZipTexturePack(new File(Environment.getExternalStorageDirectory(), "tex.zip"));
} catch (Exception e) {
e.printStackTrace();
}

try {
minecraftApkContext = createPackageContext("com.mojang.minecraftpe", 0);
} catch (Exception e) {
e.printStackTrace();
}
//setContentView(R.layout.main);
}

Expand Down Expand Up @@ -75,17 +109,65 @@ public void displayDialog(int dialogId) {

public String getDateString(int time) {
System.out.println("getDateString: " + time);
return Integer.toString(time);
return DateFormat.getDateInstance(DateFormat.SHORT, Locale.US).format(new Date(((long) time) * 1000));
}

public byte[] getFileDataBytes(String name) {
System.out.println("Get file data: " + name);
return null;
try {
InputStream is = getInputStreamForAsset(name);
if (is == null) return null;
byte[] retval = new byte[(int) getSizeForAsset(name)];
is.read(retval);
return retval;
} catch (Exception e) {
return null;
}
}

private InputStream getInputStreamForAsset(String name) {
try {
InputStream is = texturePack.getInputStream(name);
if (is == null) {
is = minecraftApkContext.getAssets().open(name);
}
return is;
} catch (Exception e) {
return null;
}
}

private long getSizeForAsset(String name) {
try {
long size = texturePack.getSize(name);
if (size == -1) {
size = minecraftApkContext.getAssets().openFd(name).getLength();
}
return size;
} catch (Exception e) {
return -1;
}
}

public int[] getImageData(String name) {
System.out.println("Get image data: " + name);
return null;
try {
InputStream is = getInputStreamForAsset(name);
if (is == null) return null;
Bitmap bmp = BitmapFactory.decodeStream(is);
int[] retval = new int[(bmp.getWidth() * bmp.getHeight()) + 2];
retval[0] = bmp.getWidth();
retval[1] = bmp.getHeight();
bmp.getPixels(retval, 2, bmp.getWidth(), 0, 0, bmp.getWidth(), bmp.getHeight());
is.close();

return retval;
} catch (Exception e) {
e.printStackTrace();
return null;
}
/* format: width, height, each integer a pixel */
/* 0 = white, full transparent */
}

public String[] getOptionStrings() {
Expand All @@ -95,22 +177,22 @@ public String[] getOptionStrings() {

public float getPixelsPerMillimeter() {
System.out.println("Pixels per mm");
return 1.0f;
return ((float) displayMetrics.densityDpi) / 25.4f ;
}

public String getPlatformStringVar(int a) {
System.out.println("getPlatformStrinVar: " +a);
System.out.println("getPlatformStringVar: " +a);
return "";
}

public int getScreenHeight() {
System.out.println("height");
return 100;
return displayMetrics.heightPixels;
}

public int getScreenWidth() {
System.out.println("width");
return 100;
return displayMetrics.widthPixels;
}

public int getUserInputStatus() {
Expand Down Expand Up @@ -162,12 +244,4 @@ public void vibrate(int duration) {
public static void saveScreenshot(String name, int firstInt, int secondInt, int[] thatArray) {
}

static {
try {
System.loadLibrary("minecraftpe");
} catch (Exception e) {
e.printStackTrace();
}
}

}

0 comments on commit 2d234ea

Please sign in to comment.