Skip to content

Commit

Permalink
published on git, replaced PrintWriter with BufferedWriter in FileSav…
Browse files Browse the repository at this point in the history
…eDialog class, also JTextArea doesn't appear to be the cause of the memory leak, it occures during reading the command outputStream.
  • Loading branch information
Muhammad Hashim committed Nov 26, 2016
0 parents commit 081f057
Show file tree
Hide file tree
Showing 9 changed files with 1,305 additions and 0 deletions.
Binary file added icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
55 changes: 55 additions & 0 deletions mhashem6/sadb/Launcher.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Simple-ADB tool , a tool made to make the process of using adb/fastboot simpler, with GUI
* Copyright (C) 2016 mhashem6 > (Muhammad Hashim)
*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later
* version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*
* for additional informations you can visit the main thread of this program > http://forum.xda-developers.com/android/software/revive-simple-adb-tool-t3417155
* you can contact me @ [email protected]
* Source : https://sourceforge.net/p/sadb/
*
*/

package mhashem6.sadb;

import javax.swing.SwingUtilities;

import mhashem6.sadb.ui.MainUI;

public class Launcher {
/** main method */
public static void main(String args[]) {

try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Windows".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(MainUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(MainUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(MainUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(MainUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}

SwingUtilities.invokeLater(() -> {
new MainUI();
});
}
}
79 changes: 79 additions & 0 deletions mhashem6/sadb/SideKick.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* Simple-ADB tool , a tool made to make the process of using adb/fastboot simpler, with GUI
* Copyright (C) 2016 mhashem6 > (Muhammad Hashim)
*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later
* version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*
* for additional informations you can visit the main thread of this program > http://forum.xda-developers.com/android/software/revive-simple-adb-tool-t3417155
* you can contact me @ [email protected]
* Source : https://sourceforge.net/p/sadb/
*
*/

package mhashem6.sadb;

import java.awt.Desktop;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;

/** class that shall contain some helpful constants and methods */
public final class SideKick {

public final static String HELP_URL = "http://forum.xda-developers.com/android/software/revive-simple-adb-tool-t3417155";
public final static String SOURCE_URL = "https://sourceforge.net/projects/sadb/";
public final static String DONATE_URL = "http://forum.xda-developers.com/donatetome.php?u=5157399";

public final static String ABOUT_STRING = "Simple-ADB tool," + System.getProperty("line.separator")
+ "a program made to make the process of using adb/fastboot simpler, with GUI."
+ System.getProperty("line.separator") + "* Copyright (C) 2016 mhashem6 > (Muhammad Hashim)."
+ System.getProperty("line.separator") + System.getProperty("line.separator")
+ "This program is free software: you can redistribute it and/or modify it under"
+ System.getProperty("line.separator")
+ "the terms of the GNU General Public License as published by the Free Software"
+ System.getProperty("line.separator")
+ "Foundation, either version 3 of the License, or (at your option) any later version."
+ System.getProperty("line.separator")
+ "This program is distributed in the hope that it will be useful, but WITHOUT"
+ System.getProperty("line.separator")
+ "ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS"
+ System.getProperty("line.separator")
+ "FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details."
+ System.getProperty("line.separator")
+ "You should have received a copy of the GNU General Public License along with this program,"
+ System.getProperty("line.separator") + "If not, see <http://www.gnu.org/licenses/>."
+ System.getProperty("line.separator") + "you can contact me @ [email protected]";

/** to visit a URL address */
public static void visitAddress(String adress) {

try {
URI uri = new URI(adress);
Desktop desktop = null;
if (Desktop.isDesktopSupported()) {
desktop = Desktop.getDesktop();
}

if (desktop != null)
desktop.browse(uri);

} catch (IOException ioe) {
ioe.printStackTrace();
} catch (URISyntaxException use) {
use.printStackTrace();
}

}

}
41 changes: 41 additions & 0 deletions mhashem6/sadb/exceptions/FileFailException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Simple-ADB tool , a tool made to make the process of using adb/fastboot simpler, with GUI
* Copyright (C) 2016 mhashem6 > (Muhammad Hashim)
*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later
* version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*
* for additional informations you can visit the main thread of this program > http://forum.xda-developers.com/android/software/revive-simple-adb-tool-t3417155
* you can contact me @ [email protected]
* Source : https://sourceforge.net/p/sadb/
*
*/

package mhashem6.sadb.exceptions;

import java.io.IOException;

@SuppressWarnings("serial")
public class FileFailException extends IOException {
private String fileName;

public FileFailException(String fileName) {
this.fileName = fileName;
}

public String toString() {
return "could not cerate : " + fileName + " file";

}

}
86 changes: 86 additions & 0 deletions mhashem6/sadb/ui/CommandsBox.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
* Simple-tool , a tool made to make the process of using adb/simpler, with GUI
* Copyright (C) 2016 mhashem6 > (Muhammad Hashim)
*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later
* version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*
* for additional informations you can visit the main thread of this program > http://forum.xda-developers.com/android/software/revive-simple-adb-tool-t3417155
* you can contact me @ [email protected]
* Source : https://sourceforge.net/p/sadb/
*
*/

package mhashem6.sadb.ui;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JComboBox;

@SuppressWarnings({ "serial", "rawtypes" })
class CommandsBox extends JComboBox {

private DefaultComboBoxModel cbm;

final static String[] ADB_ITEMS = { "devices -l", "connect", "disconnect", "logcat", "install", "uninstall", "push",
"pull", "kill-all", "shell top", "shell free", "busybox df -h", "rm /data/system/gesture.key", "reboot",
"reboot recovery", "reboot download", "reboot bootloader", "reboot fastboot", "reboot sideload", "root",
"unroot", "help", "kill-server" };

final static String[] FASTBOOT_ITEMS = { "devices -l", "reboot-bootloader", "erase system", "erase data",
"erase cache", "flash", "flash recovery", "flash boot", "flash system", "flash data", "flash cache",
"flash userdata", "flash bootloader", "flash radio", "help" };

@SuppressWarnings("unchecked")
CommandsBox() {

super(ADB_ITEMS);
setFocusable(false);
clearSelectedElement();
}

@Override
public void paint(Graphics g) {
super.paint(g);
Graphics2D g2 = (Graphics2D) g;
setPreferredSize(new Dimension(292, getPreferredSize().height));
setBackground(Color.WHITE);
setForeground(Color.decode("#263238"));
setEditable(false);

if (getSelectedItem() == null)
g2.drawString("Commands List", 5, getHeight() / 2 + g2.getFontMetrics().getAscent() / 2);
}

@SuppressWarnings("unchecked")
public void setComboElements(String[] combos) {
removeAllItems();
cbm = new DefaultComboBoxModel(combos);
setModel(cbm);
clearSelectedElement();

}

void clearSelectedElement() {

try {
setSelectedItem(null);
} catch (NullPointerException ex) {

}
}

}
54 changes: 54 additions & 0 deletions mhashem6/sadb/ui/FileExplorer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Simple-ADB tool , a tool made to make the process of using adb/fastboot simpler, with GUI
* Copyright (C) 2016 mhashem6 > (Muhammad Hashim)
*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later
* version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*
* for additional informations you can visit the main thread of this program > http://forum.xda-developers.com/android/software/revive-simple-adb-tool-t3417155
* you can contact me @ [email protected]
* Source : https://sourceforge.net/p/sadb/
*
*/

package mhashem6.sadb.ui;

import javax.swing.JFileChooser;
import javax.swing.filechooser.FileNameExtensionFilter;

@SuppressWarnings("serial")
class FileExplorer extends JFileChooser {

private String fileName;

FileExplorer(MainUI frame) {

setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
setApproveButtonText("Select");
setFileFilter(new FileNameExtensionFilter("Directories,flashable files & apk's", "apk", "img", "zip"));

int filesMenu = showOpenDialog(frame);
if (filesMenu == JFileChooser.APPROVE_OPTION) {
setFileName(getSelectedFile().getPath());
}

}

public String getFileName() {
return fileName;
}

private void setFileName(String fileName) {
this.fileName = fileName;
}
}
66 changes: 66 additions & 0 deletions mhashem6/sadb/ui/FileSaveDialog.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Simple-ADB tool , a tool made to make the process of using adb/fastboot simpler, with GUI
* Copyright (C) 2016 mhashem6 > (Muhammad Hashim)
*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later
* version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*
* for additional informations you can visit the main thread of this program > http://forum.xda-developers.com/android/software/revive-simple-adb-tool-t3417155
* you can contact me @ [email protected]
* Source : https://sourceforge.net/p/sadb/
*
*/

package mhashem6.sadb.ui;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import javax.swing.JFileChooser;
import javax.swing.filechooser.FileNameExtensionFilter;

import mhashem6.sadb.exceptions.FileFailException;

@SuppressWarnings("serial")
class FileSaveDialog extends JFileChooser {

public FileSaveDialog(MainUI frame, String whatToSave) throws FileFailException {

setDialogTitle("Save AS");
setFileFilter(new FileNameExtensionFilter(".log, .txt", "log", "txt"));

int userSelection = showSaveDialog(frame);

if (userSelection == JFileChooser.APPROVE_OPTION) {

File file = getSelectedFile();

try {
file.createNewFile();
} catch (IOException e1) {
throw new FileFailException(file.getName());
}

try (BufferedWriter bw = new BufferedWriter(new FileWriter(file))) {
bw.write(whatToSave);
} catch (IOException e) {
throw new FileFailException(file.getName());

}

}

}

}
Loading

0 comments on commit 081f057

Please sign in to comment.