Created
October 31, 2017 12:56
-
-
Save mataprasad/967f9192fbf50bb17a24d568556b78e4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//https://resizeappicon.com/ | |
/* | |
* To change this license header, choose License Headers in Project Properties. | |
* To change this template file, choose Tools | Templates | |
* and open the template in the editor. | |
*/ | |
package mobileicon; | |
import java.io.File; | |
import java.io.IOException; | |
import java.net.URISyntaxException; | |
import java.nio.file.Path; | |
import java.nio.file.Paths; | |
import java.util.logging.Level; | |
import java.util.logging.Logger; | |
import org.apache.commons.io.FileUtils; | |
/** | |
* | |
* @author mata.chauhan | |
*/ | |
public class NewJFrame extends javax.swing.JFrame { | |
/** | |
* Creates new form NewJFrame | |
*/ | |
public NewJFrame() { | |
initComponents(); | |
} | |
/** | |
* This method is called from within the constructor to initialize the form. | |
* WARNING: Do NOT modify this code. The content of this method is always | |
* regenerated by the Form Editor. | |
*/ | |
@SuppressWarnings("unchecked") | |
// <editor-fold defaultstate="collapsed" desc="Generated Code"> | |
private void initComponents() { | |
txtIconName = new javax.swing.JTextField(); | |
jLabel1 = new javax.swing.JLabel(); | |
txtSourceDirectory = new javax.swing.JTextField(); | |
jLabel2 = new javax.swing.JLabel(); | |
btnRun = new javax.swing.JButton(); | |
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); | |
jLabel1.setText("Icon Final Name"); | |
txtSourceDirectory.setText("."); | |
jLabel2.setText("Source Directory"); | |
btnRun.setText("RUN"); | |
btnRun.addActionListener(new java.awt.event.ActionListener() { | |
public void actionPerformed(java.awt.event.ActionEvent evt) { | |
btnRunActionPerformed(evt); | |
} | |
}); | |
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); | |
getContentPane().setLayout(layout); | |
layout.setHorizontalGroup( | |
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) | |
.addGroup(layout.createSequentialGroup() | |
.addContainerGap() | |
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) | |
.addComponent(jLabel1) | |
.addComponent(txtIconName, javax.swing.GroupLayout.PREFERRED_SIZE, 168, javax.swing.GroupLayout.PREFERRED_SIZE) | |
.addComponent(jLabel2) | |
.addComponent(txtSourceDirectory, javax.swing.GroupLayout.PREFERRED_SIZE, 168, javax.swing.GroupLayout.PREFERRED_SIZE)) | |
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) | |
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() | |
.addContainerGap(166, Short.MAX_VALUE) | |
.addComponent(btnRun, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE) | |
.addGap(134, 134, 134)) | |
); | |
layout.setVerticalGroup( | |
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) | |
.addGroup(layout.createSequentialGroup() | |
.addContainerGap() | |
.addComponent(jLabel1) | |
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) | |
.addComponent(txtIconName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) | |
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) | |
.addComponent(jLabel2) | |
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) | |
.addComponent(txtSourceDirectory, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) | |
.addGap(45, 45, 45) | |
.addComponent(btnRun) | |
.addContainerGap(135, Short.MAX_VALUE)) | |
); | |
pack(); | |
}// </editor-fold> | |
private void btnRunActionPerformed(java.awt.event.ActionEvent evt) { | |
String iconName = txtIconName.getText(); | |
String sourceDir = txtSourceDirectory.getText(); | |
if (sourceDir == null || !"".contentEquals(sourceDir)) { | |
if (".".contentEquals(sourceDir)) { | |
//sourceDir=NewJFrame.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath(); | |
sourceDir = NewJFrame.class.getProtectionDomain().getCodeSource().getLocation().getPath(); | |
} | |
} | |
txtSourceDirectory.setText(sourceDir); | |
File jar = new File(sourceDir); | |
File rootDir = new File(jar.getParent()); | |
//Ios Works, Starts | |
File iosDir = new File(jar.getParent(), "/ios"); | |
iosDir.mkdirs(); | |
File icon = new File(rootDir, "/Icon-Small.png"); | |
File target = new File(rootDir, "/ios/" + iconName + ".png"); | |
try { | |
FileUtils.moveFile(icon, target); | |
} catch (IOException ex) { | |
Logger.getLogger(NewJFrame.class.getName()).log(Level.SEVERE, null, ex); | |
} | |
icon = new File(rootDir, "/[email protected]"); | |
target = new File(rootDir, "/ios/" + iconName + "@2x.png"); | |
try { | |
FileUtils.moveFile(icon, target); | |
} catch (IOException ex) { | |
Logger.getLogger(NewJFrame.class.getName()).log(Level.SEVERE, null, ex); | |
} | |
icon = new File(rootDir, "/[email protected]"); | |
target = new File(rootDir, "/ios/" + iconName + "@3x.png"); | |
try { | |
FileUtils.moveFile(icon, target); | |
} catch (IOException ex) { | |
Logger.getLogger(NewJFrame.class.getName()).log(Level.SEVERE, null, ex); | |
} | |
//Ios Works, ends | |
//Android, starts | |
File androidDir = new File(jar.getParent(), "/drawable"); | |
androidDir.mkdirs(); | |
File source = null; | |
try { | |
source = new File(rootDir, "/ldpi.png"); | |
target = new File(rootDir, "/drawable/" + iconName + ".png"); | |
FileUtils.moveFile(source, target); | |
} catch (IOException ex) { | |
Logger.getLogger(NewJFrame.class.getName()).log(Level.SEVERE, null, ex); | |
} | |
androidDir = new File(jar.getParent(), "/drawable-hdpi"); | |
androidDir.mkdirs(); | |
try { | |
source = new File(rootDir, "/hdpi.png"); | |
target = new File(rootDir, "/drawable-hdpi/" + iconName + ".png"); | |
FileUtils.moveFile(source, target); | |
} catch (IOException ex) { | |
Logger.getLogger(NewJFrame.class.getName()).log(Level.SEVERE, null, ex); | |
} | |
androidDir = new File(jar.getParent(), "/drawable-mdpi"); | |
androidDir.mkdirs(); | |
try { | |
source = new File(rootDir, "/mdpi.png"); | |
target = new File(rootDir, "/drawable-mdpi/" + iconName + ".png"); | |
FileUtils.moveFile(source, target); | |
} catch (IOException ex) { | |
Logger.getLogger(NewJFrame.class.getName()).log(Level.SEVERE, null, ex); | |
} | |
androidDir = new File(jar.getParent(), "/drawable-xhdpi"); | |
androidDir.mkdirs(); | |
try { | |
source = new File(rootDir, "/xhdpi.png"); | |
target = new File(rootDir, "/drawable-xhdpi/" + iconName + ".png"); | |
FileUtils.moveFile(source, target); | |
} catch (IOException ex) { | |
Logger.getLogger(NewJFrame.class.getName()).log(Level.SEVERE, null, ex); | |
} | |
androidDir = new File(jar.getParent(), "/drawable-xxhdpi"); | |
androidDir.mkdirs(); | |
try { | |
source = new File(rootDir, "/xxhdpi.png"); | |
target = new File(rootDir, "/drawable-xxhdpi/" + iconName + ".png"); | |
FileUtils.moveFile(source, target); | |
} catch (IOException ex) { | |
Logger.getLogger(NewJFrame.class.getName()).log(Level.SEVERE, null, ex); | |
} | |
androidDir = new File(jar.getParent(), "/drawable-xxxhdpi"); | |
androidDir.mkdirs(); | |
try { | |
source = new File(rootDir, "/xxxhdpi.png"); | |
target = new File(rootDir, "/drawable-xxxhdpi/" + iconName + ".png"); | |
FileUtils.moveFile(source, target); | |
} catch (IOException ex) { | |
Logger.getLogger(NewJFrame.class.getName()).log(Level.SEVERE, null, ex); | |
} | |
//Android, ends | |
for (File f : rootDir.listFiles()) { | |
if (f.getName().endsWith(".png")) { | |
f.delete(); // may fail mysteriously - returns boolean you may want to check | |
} | |
} | |
} | |
/** | |
* @param args the command line arguments | |
*/ | |
public static void main(String args[]) { | |
/* Set the Nimbus look and feel */ | |
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) "> | |
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. | |
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html | |
*/ | |
try { | |
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { | |
if ("Nimbus".equals(info.getName())) { | |
javax.swing.UIManager.setLookAndFeel(info.getClassName()); | |
break; | |
} | |
} | |
} catch (ClassNotFoundException ex) { | |
java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); | |
} catch (InstantiationException ex) { | |
java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); | |
} catch (IllegalAccessException ex) { | |
java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); | |
} catch (javax.swing.UnsupportedLookAndFeelException ex) { | |
java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); | |
} | |
//</editor-fold> | |
/* Create and display the form */ | |
java.awt.EventQueue.invokeLater(new Runnable() { | |
public void run() { | |
new NewJFrame().setVisible(true); | |
} | |
}); | |
} | |
// Variables declaration - do not modify | |
private javax.swing.JButton btnRun; | |
private javax.swing.JLabel jLabel1; | |
private javax.swing.JLabel jLabel2; | |
private javax.swing.JTextField txtIconName; | |
private javax.swing.JTextField txtSourceDirectory; | |
// End of variables declaration | |
private Object File(String sourceDir) { | |
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment