Advertisement
peacestorm

Could work

May 15th, 2018
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var buttonWindow;
  2. var ctx = com.mojang.minecraftpe.MainActivity.currentMainActivity.get();
  3.  
  4. var BitmapFactory = android.graphics.BitmapFactory;
  5. var BitmapDrawable = android.graphics.drawable.BitmapDrawable;
  6.  
  7. let imgSlot = new BitmapFactory.decodeFile("mnt/sdcard/download/Offhand/offhand.png");
  8. let iconSlot = new BitmapDrawable(imgSlot);
  9.  
  10. const DENSITY = ctx.getResources().getDisplayMetrics().density;
  11.  
  12. function px2dip(px){
  13.     return Math.floor(px / DENSITY);
  14. }
  15.  
  16. function newLevel() {
  17.     ctx.runOnUiThread(new java.lang.Runnable({
  18.         run: function() {
  19.             try {
  20.  
  21.                 buttonWindow = new android.widget.PopupWindow();
  22.  
  23.                 var layout = new android.widget.RelativeLayout(ctx);
  24.                 var button = new android.widget.Button(ctx);
  25.  
  26.                 button.setText("Offhand");
  27.                 button.setOnClickListener(new android.view.View.OnClickListener({
  28.  
  29.                     onClick: function(viewarg) {
  30.                         clientMessage("Block Placed");
  31.                     }
  32.  
  33.                 }));
  34.  
  35.                 layout.addView(button);
  36.  
  37.                 buttonWindow.setContentView(layout);
  38.                 buttonWindow.setWidth(110);
  39.                 buttonWindow.setHeight(110);
  40.                 buttonWindow.setBackgroundDrawable(iconSlot);
  41.                 buttonWindow.showAtLocation(ctx.getWindow().getDecorView(), android.view.Gravity.LEFT | android.view.Gravity.BOTTOM, 200, 0);
  42.  
  43.             } catch (problem) {
  44.                 print("Button could not be displayed: " + problem);
  45.             }
  46.         }
  47.     }));
  48. }
  49.  
  50. function leaveGame() {
  51.  
  52.     ctx.runOnUiThread(new java.lang.Runnable({
  53.         run: function() {
  54.  
  55.             if (buttonWindow != null) {
  56.                 buttonWindow.dismiss();
  57.                 buttonwindow = null;
  58.             }
  59.  
  60.         }
  61.     }));
  62.  
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement