"ui";//
ui.statusBarColor("#AA0000");
ui.layout(
<frame background="#AA0000">
<vertical align="top" margin="5">
<img id="img" bg="#ffffff" w="350" h="350" margin="1 0 0 0"/>
<linear>
<vertical w="170">
<text text="步数:" color="#000000" size="64"/>
<text id="分数" text="0" gravity="center" color="#ffffff" size="34"/>
</vertical>
<vertical>
<linear>
<button margin="0 0 0 60" h="60" w="60" id="up" text="上"></button>
</linear>
<linear>
<button h="60" w="60" id="left" text="左"></button>
<button h="60" w="60" id="ok" text="ok"></button>
<button h="60" w="60" id="right" text="右"></button>
</linear>
<linear>
<button margin="0 0 0 60" h="60" w="60" id="down" text="下"></button>
</linear>
</vertical>
</linear>
</vertical>
</frame>
);
importClass(android.graphics.Paint);
importClass(android.graphics.Canvas);
importClass(android.graphics.Bitmap);
importClass(android.graphics.Matrix);
importClass(android.content.Intent);
importClass(android.net.Uri);
var 分享否=0;
var sdpath =android.os.Environment.getExternalStorageDirectory();//获取跟目录
ui.ok.click(() => {
分享否=1;
});
ui.img.click(() => {
var qq群号="604847405";
app.startActivity({
action: "android.intent.action.VIEW",
data:"mqqapi://card/show_pslcard?card_type=group&uin="+qq群号,
packageName: "com.tencent.mobileqq",
});//打开qq群名片
});
threads.start(function(){
while(true){
if(分享否==1){
shareI(存图(绘大图()));
分享否=0;
}else{

}
}
});
function shareI(图) {
var imageUri = Uri.fromFile(new java.io.File(图));
var shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, imageUri);
shareIntent.setType("image/*");
context.startActivity(Intent.createChooser(shareIntent, "分享到"));
}
function 存图(bitmap){
var path0=sdpath+"/DCIM/"+new Date().getTime()+".png";
var mFile = new java.io.File(path0);
var mFileOutputStream = new java.io.FileOutputStream(mFile);
bitmap.compress(Bitmap.CompressFormat.PNG,100,mFileOutputStream);
return path0;
}

var path=sdpath+"/DCIM/1.png";
var url = "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1527552170666&di=b037be211dbc825cedc08962ded558ef&imgtype=0&src=http%3A%2F%2Fimgsrc.baidu.com%2Fimgad%2Fpic%2Fitem%2Fb90e7bec54e736d1a24f53dc91504fc2d4626982.jpg";
url="https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1527621586081&di=56704ebe9c5be8afd72b017794651c2b&imgtype=0&src=http%3A%2F%2F03.imgmini.eastday.com%2Fmobile%2F20180414%2F503ac89a3d08d6a62b11304199f3a2c3_wmk.jpeg";
threads.start(function(){
files.writeBytes(path, http.get(url).body.bytes());
});
while(!files.exists(path)){sleep(100);};

var 图片=android.graphics.BitmapFactory.decodeFile(path);
var scaleWidth =1200/图片.width;
var scaleHeight=750/ 图片.height;
// 取得想要缩放的matrix参数
var matrix = new Matrix();
matrix.postScale(scaleWidth, scaleHeight);
// 得到新的图片
var bitMap = Bitmap.createBitmap(图片, 0, 0, 图片.width, 图片.height, matrix, true);
//alert(Object.keys(图片));
var bit=new Array();
for(var i=0;i<5;i++){
bit[i]=new Array();
for(var j=0;j<8;j++){
eval("bit["+i+"]["+j+"] = Bitmap.createBitmap(bitMap,"+j150+","+i150+", 150, 150)");
}
}
bit[5]=new Array();
bit[5][0]=Bitmap.createBitmap(150,150,Bitmap.Config.ARGB_8888);
var canvas0 = new Canvas(bit[5][0]);
canvas0.drawARGB(255,255,255,255);
function 绘大图(){
var 全图=Bitmap.createBitmap(1080,1080,Bitmap.Config.ARGB_8888);
var canvas = new Canvas(全图);
canvas.drawARGB(255,155,120,90);
var paint = new Paint();
//var 宽间隔=(1080-14-(宽-1)*5)/宽;
// var 长间隔=(1080-14-(长-1)*5)/长;

for(var i=0;i<6;i++){

for(var j=0;j<8;j++){
eval('var 数图=bit['+i+']['+j+'];');
var scaleWidth =100/数图.width;
var scaleHeight=100/ 数图.height;
// 取得想要缩放的matrix参数
var matrix = new Matrix();
matrix.postScale(scaleWidth, scaleHeight);
// 得到新的图片
var 元素图= Bitmap.createBitmap(数图, 0, 0, 数图.width, 数图.height, matrix, true);
eval('canvas.drawBitmap(元素图'+','+(j*(100+5)+140)+','+(i*(100+5)+170)+',paint)');
if(i>=5){j=8;}
}}

canvas.save(Canvas.ALL_SAVE_FLAG);
canvas.restore();
return 全图;
}
var 空白x=0;
var 空白y=5;
ui.up.click(() => {
try{
var 临时图=bit[空白y+1][空白x];
bit[空白y+1][空白x]=bit[空白y][空白x];
bit[空白y][空白x]=临时图;
空白y=空白y+1;
ui.img.setImageBitmap(绘大图());

}catch(e){};

});
ui.down.click(() => {
try{
var 临时图=bit[空白y-1][空白x];
bit[空白y-1][空白x]=bit[空白y][空白x];
bit[空白y][空白x]=临时图;
空白y=空白y-1;
ui.img.setImageBitmap(绘大图());

}catch(e){};

});
ui.left.click(() => {
try{
if(bit[空白y][空白x+1]==null){bit[99][空白x-1]=0;}
//
var 临时图=bit[空白y][空白x+1];
bit[空白y][空白x+1]=bit[空白y][空白x];
bit[空白y][空白x]=临时图;
空白x=空白x+1;
ui.img.setImageBitmap(绘大图());

}catch(e){};

});
ui.right.click(() => {
try{
if(bit[空白y][空白x-1]==null){bit[99][空白x-1]=0;}
//
var 临时图=bit[空白y][空白x-1];
bit[空白y][空白x-1]=bit[空白y][空白x];
bit[空白y][空白x]=临时图;
空白x=空白x-1;
ui.img.setImageBitmap(绘大图());

}catch(e){};

});
var 大图=绘大图();
ui.img.setImageBitmap(大图);

最后由 adman 编辑