Phonegap / Cordova needs much designing work in order to make screens and icons. If you use same icon to create all different sizes of icons and screens then why you have to waste your time for changing icons and screen sizes. Here it is simple way to do it.
This program was created based on phonegap-start-master project. Download this project and you can see icons at res/icon and screens at res/screen folder. Make you app icon ready.

Java Library :

For quality image scaling, I have used java-image-scaling library.

Folder copy program :

To create destination folder from source folder, I have created one Folder copy java program. Find complete explanation at http://blog.sodhanalibrary.com/2014/09/copy-file-or-folder-in-hierarchical-way.html

Java Program to create icons :

Replace destinationDir with your own destination directory Path
Replace sourceDir with your own source directory Path
Replace appIcon with your own app icon Path
Run this program
Find destination path for new Icons
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import javax.imageio.ImageIO;
import com.mortennobel.imagescaling.ResampleOp;

public class CreatePhoneGapIcons {
  static String destinationDir = "D:\\phonegap-start-master\\phonegap-start-master\\phonegap-start-master\\www\\copyOfResources\\res1";
  static String sourceDir = "D:\\phonegap-start-master\\phonegap-start-master\\phonegap-start-master\\www\\res\\icon";
  static String appIcon = "C:\\Documents and Settings\\srinivas\\My Documents\\My Pictures\\documentation\\mathTables.png";
  public static void main(String[] args) throws IOException {
      File file = new File(sourceDir);
      readFile(file, destinationDir);
  }
  
  public static void readFile(File file, String path) throws IOException {
      if(file.isDirectory()) {
          System.out.println("DIR "+ file.getAbsolutePath());
          File[] files = file.listFiles();
          String destDirPath = path + "\\" + file.getName();
          File destDir = new File(destDirPath);
          if(!destDir.exists()) {
              destDir.mkdirs();
          }
          for(int i=0; i<files.length; i++) {
              readFile(files[i],destDirPath);
          }
      } else {
          String destFilePath = path + "\\" + file.getName();
          File destFile = new File(destFilePath);
          if(!destFile.exists()) {
              destFile.createNewFile();
          }
          System.out.println("File "+ file.getAbsolutePath());
          if(file.getName().endsWith(".png")) {
              copyFileUsingStream(file, destFile);
              BufferedImage sourceFileImg = ImageIO.read(file);
              BufferedImage appIconImg = ImageIO.read(new File(appIcon));
              ResampleOp  resampleOp = new ResampleOp(sourceFileImg.getWidth(), sourceFileImg.getHeight());
              BufferedImage generatedIcon = resampleOp.filter(appIconImg, null);
              ImageIO.write(generatedIcon,"png", destFile);
          } else {
              copyFileUsingStream(file, destFile);
          }
            
      }
  }  
  
  
  private static void copyFileUsingStream(File source, File dest) throws IOException {
        InputStream is = null;
        OutputStream os = null;
        try {
            is = new FileInputStream(source);
            os = new FileOutputStream(dest);
            byte[] buffer = new byte[1024];
            int length;
            while ((length = is.read(buffer)) > 0) {
                os.write(buffer, 0, length);
            }
        } finally {
            is.close();
            os.close();
        }
    }

}

Java Program to create screens :

Replace destinationDir with your own destination directory Path
Replace sourceDir with your own source directory Path
Replace appIcon with your own app icon Path
Run this program
Find destination path for new Screens
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import javax.imageio.ImageIO;
import com.mortennobel.imagescaling.ResampleOp;

public class CreatePhoneGapScreens {
  static String destinationDir = "D:\\phonegap-start-master\\phonegap-start-master\\phonegap-start-master\\www\\copyOfResources\\res1";
  static String sourceDir = "D:\\phonegap-start-master\\phonegap-start-master\\phonegap-start-master\\www\\res\\screen";
  static String appIcon = "C:\\Documents and Settings\\srinivas\\My Documents\\My Pictures\\documentation\\mathTables.png";
  public static void main(String[] args) throws IOException {
      File file = new File(sourceDir);
      readFiles(file, destinationDir);
      //setTransparentBackground("C:\\Documents and Settings\\srinivas\\My Documents\\My Pictures\\documentation\\mathTables.png");
  }
  
  public static void readFiles(File file, String path) throws IOException {
      if(file.isDirectory()) {
          System.out.println("DIR "+ file.getAbsolutePath());
          File[] files = file.listFiles();
          String destDirPath = path + "\\" + file.getName();
          File destDir = new File(destDirPath);
          if(!destDir.exists()) {
              destDir.mkdirs();
          }
          for(int i=0; i<files.length; i++) {
              readFiles(files[i],destDirPath);
          }
      } else {
          String destFilePath = path + "\\" + file.getName();
          File destFile = new File(destFilePath);
          if(!destFile.exists()) {
              destFile.createNewFile();
          }
          System.out.println("File "+ file.getAbsolutePath());
          if(file.getName().endsWith(".png")) {
              copyFileUsingStream(file, destFile);
              BufferedImage sourceScreenImage = ImageIO.read(file);
              BufferedImage appIconImg = ImageIO.read(new File(appIcon));
              BufferedImage generatedScreen =  createScreenImage(appIconImg,sourceScreenImage.getWidth(), sourceScreenImage.getHeight());
              ImageIO.write(generatedScreen,"png", destFile);
          } else if(file.getName().equals("Thumbs.db")) {
              
          } else {
              copyFileUsingStream(file, destFile);
          }
            
      }
  }  
  
  private static BufferedImage createScreenImage(BufferedImage appIconImg, int width, int height) throws IOException {
      int type = appIconImg.getType() == 0? BufferedImage.TYPE_INT_ARGB : appIconImg.getType();
      BufferedImage newPGScreen = new BufferedImage(width, height, type);
      Graphics2D g = newPGScreen.createGraphics();
      g.setColor(new Color(255,255,255));
      g.fillRect(0, 0, width, height);
      double minSize = 0, tw = (double)width, th = (double)height;
      if(tw < th) {
          minSize = tw;
      } else {
          minSize = th;
      }
      minSize = minSize / 4;
      ResampleOp  resampleOp = new ResampleOp((int)(minSize*2), (int)(minSize*2));
      BufferedImage resizedIcon = resampleOp.filter(appIconImg, null);
      g.drawImage(resizedIcon, (int)((tw/2) - minSize), (int)((th/2) - minSize) , null);
      g.dispose();
      return newPGScreen;
  }


  private static void copyFileUsingStream(File source, File dest) throws IOException {
        InputStream is = null;
        OutputStream os = null;
        try {
            is = new FileInputStream(source);
            os = new FileOutputStream(dest);
            byte[] buffer = new byte[1024];
            int length;
            while ((length = is.read(buffer)) > 0) {
                os.write(buffer, 0, length);
            }
        } finally {
            is.close();
            os.close();
        }
    }
  
}

4 comments:

  1. The scholarship application essays and admission essays are discussed in our writing service. The online writers are providing excellent way of writing and given professional writing tricks to the college students. You can get more types of writing tips and effective range of information from online.

    best essay writing service

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete
  3. Apache Cordova is nothing more than a framework for developing cross - platform apps using web technologies. It enables you to encapsulate a collection of HTML files (including CSS and JavaScript) in a box, which would be a standalone browser. Not only that, but you'd be aware that mobile applications require access to native device functions such as the cameras, Memory card, or contacts list, to mention a few. Cordova includes a set of APIs that allow users to access native features from Javascript.


    click here: https://www.contentserviceprovider.com/blog/pubg-are-players-getting-absolute-cross-platform-gameplay-soon/

    ReplyDelete
  4. Don’t panic about the expenses of hiring argument writing a professional writer for help. We offer cheap assignment writing service that will not dent your budget.

    ReplyDelete

Blogroll

Popular Posts