Confused About App Icons for Android

The following source code should create an icon set for Android. Drag and drop the image that you want to use onto the window and a folder should appear on your desktop with the required icons. You will have to change the url for the desktop on your system.

import java.awt.*;
import java.awt.dnd.*;
import java.util.List;
import javax.swing.TransferHandler;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.io.File;

PFont font;
PImage img;
PImage myimg;
String imgPath = "";
String savePath = "";
String fileName = "";

void setup() {
  size(520, 520);
  surface.setTitle("Icon Maker Android");
  fill(0);
  textSize(30.0);
  textAlign(CENTER, CENTER);
  text("Drag and drop image here", 0, 100, width, 160);
  Canvas canvas = (Canvas) surface.getNative();
  canvas.setDropTarget(new DropTarget(canvas, DnDConstants.ACTION_COPY_OR_MOVE, new DropTargetListener() {

    @Override
      public void dragEnter(DropTargetDragEvent dtde) {
    }

    @Override
      public void dragOver(DropTargetDragEvent dtde) {
    }

    @Override
      public void dropActionChanged(DropTargetDragEvent dtde) {
    }
    @Override
      public void dragExit(DropTargetEvent dte) {
    }

    @Override
      public void drop(DropTargetDropEvent evt) {
      // Accept copy drops
      evt.acceptDrop(DnDConstants.ACTION_COPY);
      Transferable transferable = evt.getTransferable();
      // Get the data formats of the dropped item
      DataFlavor[] flavors = transferable.getTransferDataFlavors();
      for (DataFlavor flavor : flavors) {
        try {
          if (flavor.isFlavorJavaFileListType()) {
            // Get all of the dropped files
            List<File> files = new ArrayList<>();
            files = (List)transferable.getTransferData(flavor);
            for (File file : files) {
              imgPath = file.getPath();
              fileName = file.getName();
              // Strip extension if there is one
              if (fileName.indexOf(".") > 0) {
                fileName = fileName.substring(0, fileName.lastIndexOf("."));
              }
  *// **** Change the next line for your system **** //*
              savePath = "/Users/xxxxx/Desktop/AndroidIcons" + "_" + fileName + "/";
              println("imgPath: " + imgPath);
              img = loadImage(imgPath);
              img.resize(0, 512);
              img.save(savePath + "myimg.png"); // used for display
              img.resize(0, 192);
              img.save(savePath + "icon-192.png");
              img.resize(0, 144);
              img.save(savePath + "icon-144.png");
              img.resize(0, 96);
              img.save(savePath + "icon-96.png");
              img.resize(0, 72);
              img.save(savePath + "icon-72.png");
              img.resize(0, 48);
              img.save(savePath + "icon-48.png");
              img.resize(0, 36);
              img.save(savePath + "icon-36.png");
              myimg = loadImage(savePath + "myimg.png");
            }
          }
        }
        catch (Exception e) {
          println(e);
        }
      }
      evt.dropComplete(true);  // Inform that the drop is complete
    }
  }
  ));
}

void draw() {
  if (myimg != null) {
    image(myimg, 0, 0, width, height);
  }
}