virtualFiles) {
String filePath = virtualFiles.get(0).getPath();
// the file was selected so add it to the text field
File file = new File(filePath) ;
if(!file.exists() || filePath.toLowerCase().indexOf(".apk")<0 ) {
filePath = "";
}
apkAbsolutePath = filePath;
apkPath.setText(splitPath(filePath));
binary.initPath(apkAbsolutePath);
// save the file path
KeysManager.instance().setApkFilePath(filePath);
updateBuildVersionFields();
}
}); }
});
shortLink.addMouseListener(new MouseListener() {
@Override
public void mouseClicked(MouseEvent mouseEvent) {
//To change body of implemented methods use File | Settings | File Templates.
browserUrl(Main.getInstance().shortLink.getText());
}
@Override
public void mousePressed(MouseEvent mouseEvent) {
//To change body of implemented methods use File | Settings | File Templates.
}
@Override
public void mouseReleased(MouseEvent mouseEvent) {
//To change body of implemented methods use File | Settings | File Templates.
}
@Override
public void mouseEntered(MouseEvent mouseEvent) {
//To change body of implemented methods use File | Settings | File Templates.
}
@Override
public void mouseExited(MouseEvent mouseEvent) {
//To change body of implemented methods use File | Settings | File Templates.
}
});
qrCodeLabel.addMouseListener(new MouseListener() {
@Override
public void mouseClicked(MouseEvent mouseEvent) {
//To change body of implemented methods use File | Settings | File Templates.
if (!shortLink.getText().isEmpty()){
qrCode.show();
}
}
@Override
public void mousePressed(MouseEvent mouseEvent) {
//To change body of implemented methods use File | Settings | File Templates.
}
@Override
public void mouseReleased(MouseEvent mouseEvent) {
//To change body of implemented methods use File | Settings | File Templates.
}
@Override
public void mouseEntered(MouseEvent mouseEvent) {
//To change body of implemented methods use File | Settings | File Templates.
}
@Override
public void mouseExited(MouseEvent mouseEvent) {
//To change body of implemented methods use File | Settings | File Templates.
}
});
formHelp.addMouseListener(new MouseListener() {
@Override
public void mouseClicked(MouseEvent mouseEvent) {
//To change body of implemented methods use File | Settings | File Templates.
try {
Desktop desktop = Desktop.getDesktop();
String message = "mailto:yh@fir.im?subject=firuploader";
URI uri = URI.create(message);
desktop.mail(uri);
} catch (IOException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
Utils.postErrorNoticeTOSlack(e);
}
}
@Override
public void mousePressed(MouseEvent mouseEvent) {
//To change body of implemented methods use File | Settings | File Templates.
}
@Override
public void mouseReleased(MouseEvent mouseEvent) {
//To change body of implemented methods use File | Settings | File Templates.
}
@Override
public void mouseEntered(MouseEvent mouseEvent) {
//To change body of implemented methods use File | Settings | File Templates.
}
@Override
public void mouseExited(MouseEvent mouseEvent) {
//To change body of implemented methods use File | Settings | File Templates.
}
});
timerScan = new TimerScan();
this.formTipCB.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
//To change body of implemented methods use File | Settings | File Templates.
if(formTipCB.isSelected()){
KeysManager.instance().setFlag("");
}else{
KeysManager.instance().setFlag("cancel");
}
}
});
this.formUploadCB.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
//To change body of implemented methods use File | Settings | File Templates.
if(formUploadCB.isSelected()){
KeysManager.instance().setUploadFlag("yes");
}else{
KeysManager.instance().setUploadFlag("cancel");
}
}
});
}
public String splitPath(String filep){
String rt = "";
if(filep == null){
filep = "";
}
if(filep.length()>30){
filep ="..."+filep.substring(filep.length()-30,filep.length());
}
return filep ;
}
public void setShortLink (String sh){
this.appShort = sh;
shortLink.setText(sh);
shortLink.repaint();
qrCode.setUri(sh);
}
public static Main getInstance(){
return m;
}
/**
* Updates the build version(code and name) fields
*/
public void updateBuildVersionFields() {
Module module = ModulesManager.instance().getModuleByName((String) projectCombo.getSelectedItem());
// update the code and name text fields manifest build version code and name values
String[] apk = new String[3];
if(apkAbsolutePath != null){
binary.initPath(apkAbsolutePath);
}
}
public void setTips(String content){
Main.getInstance().tips.setText(content);
}
/**
* Performs validation before uploading the build to test flight, if everything is in order, the build is sent
*/
public void performUploadValidation() {
String mm = apkPath.getText();
if (KeysManager.instance().getApiKey() == null) {
Messages.showErrorDialog("请设置fir.im的api token",
"api token 不合法");
} else if (apkAbsolutePath == null || apkAbsolutePath.length() < 3) {
Messages.showErrorDialog("工程没有发现apk文件请单击设置来设置apk路径",
"apk文件不合法");
} else if(binary.name == null){
binary.name = Messages.showInputDialog(ProjectManager.getInstance().getOpenProjects()[0],
"请设置apk应用名称",
"apk的名称", null, "", null);
} else {
uploadBuild();
}
}
/**
* Uploads the build to test flight, it updates also the UI
*/
public void uploadBuild() {
Main.getInstance().binary.initPath(apkAbsolutePath);
progressBar.setValue(0);
progressBar.setVisible(true);
uploadBtn.setEnabled(false);
tips.setVisible(true);
uploadBtn.setText("uploading...");
tips.setText("uploading....");
cancelUploadButton.setVisible(true);
// upload the build
uploadService.sendBuild(null, apkAbsolutePath, KeysManager.instance().getApiKey(),
binary,
changeLogTa.getText(),
Main.this);
}
public void setTest(String text){
//logContent.setText(text+"\n"+logContent.getText() );
}
/**
* Set the default or previously saved values on the UI components
*/
public void setupValuesOnUI() {
Module previouslySelectedModule;
// if the apk file path was not saved previously by the user, set the saved module apk file path or the best matching module
previouslySelectedModule = ModulesManager.instance().getModuleByName(KeysManager.instance().getSelectedModuleName());
if (previouslySelectedModule != null) {
String filePath = ModulesManager.instance().getAndroidApkPath(previouslySelectedModule);
if(filePath == null)
filePath = "";
// the file was selected so add it to the text field
File file = new File(filePath) ;
if(!file.exists() || filePath.toLowerCase().indexOf(".apk") < 0) {
filePath = "";
}
apkAbsolutePath = filePath;
apkPath.setText(splitPath(filePath));
binary.initPath(apkAbsolutePath);
} else {
// get the best matching module for this project and set it's file path
previouslySelectedModule = ModulesManager.instance().getMostImportantModule();
String filePath = ModulesManager.instance().getAndroidApkPath(previouslySelectedModule);
// the file was selected so add it to the text field
if(filePath == null)
filePath = "";
File file = new File(filePath) ;
if(!file.exists()) {
filePath = "";
}
apkAbsolutePath = filePath;
apkPath.setText(splitPath(filePath));
binary.initPath(apkAbsolutePath);
}
// set the model of the modules
projectCombo.setModel(new DefaultComboBoxModel(ModulesManager.instance().getAllModuleNames()));
// set the selection
projectCombo.setSelectedIndex(ModulesManager.instance().getSelectedModuleIndex(previouslySelectedModule.getName()));
updateBuildVersionFields();
}
@Override
public void createToolWindowContent(Project project, ToolWindow toolWindow) {
//To change body of implemented methods use File | Settings | File Templates.
ContentFactory contentFactory = ContentFactory.SERVICE.getInstance();
Content content = contentFactory.createContent(panel1, "", false);
toolWindow.getContentManager().addContent(content);
this.toolWindow = toolWindow;
ProjectManager.getInstance().addProjectManagerListener(new ProjectManagerListener() {
@Override
public void projectOpened(Project project) {
// get the best matching module for this project and set it's file path
Module previouslySelectedModule = ModulesManager.instance().getMostImportantModule();
String filePath = previouslySelectedModule.getModuleFilePath();
if(filePath == null)
filePath = "";
File file = new File(filePath) ;
if(!file.exists() || filePath.toLowerCase().indexOf(".apk")< 0) {
filePath = "";
}
apkAbsolutePath = filePath;
binary.initPath(apkAbsolutePath);
apkPath.setText(splitPath(filePath));
KeysManager.instance().setSelectedModuleName(previouslySelectedModule.getName());
String[] modules = ModulesManager.instance().getAllModuleNames();
if (modules != null) {
// set the model of the modules
projectCombo.setModel(new DefaultComboBoxModel(ModulesManager.instance().getAllModuleNames()));
}
// set the selection
projectCombo.setSelectedIndex(ModulesManager.instance().getSelectedModuleIndex(previouslySelectedModule.getName()));
}
@Override
public boolean canCloseProject(Project project) {
return true;
}
@Override
public void projectClosed(Project project) {
}
@Override
public void projectClosing(Project project) {
}
});
}
@Override
public void onUploadFinished(final boolean finishedSuccessful) {
// upload is now finished, run some UI updates on the UI thread
SwingUtilities.invokeLater(new Runnable() {
public void run() {
cancelUploadButton.setVisible(false);
if (!finishedSuccessful) {
Messages.showErrorDialog("上传失败!有问题请联系dev@fir.im", "上传失败!有问题请联系dev@fir.im");
progressBar.setVisible(false);
uploadBtn.setEnabled(true);
uploadBtn.setText(document.uploadBtn);
changeLogTa.setText("");
Main.getInstance().tips.setVisible(false);
Main.getInstance().tips.repaint();
return;
}
progressBar.setVisible(false);
uploadBtn.setEnabled(true);
uploadBtn.setText(document.uploadBtn);
Main.getInstance().tips.setText("File upload success");
KeysManager.instance().setMd5(Utils.getMd5(Main.getInstance().binary.filePath));
changeLogTa.setText("");
uploadFinishNotice();
Thread th = new Thread(new Runnable() {
@Override
public void run() {
//To change body of implemented methods use File | Settings | File Templates.
try {
// thread to sleep for 1000 milliseconds
Thread.sleep(2000);
Main.getInstance().tips.setVisible(false);
Main.getInstance().tips.repaint();
Utils.postSuccessNoticeToSlack("#" + Main.getInstance().binary.name + "#" + Main.getInstance().appShort);
} catch (Exception e) {
Utils.postErrorNoticeTOSlack(e);
System.out.println(e);
}
}
});
th.start();
}
});
}
@Override
public void onPackageSizeComputed(final long totalSize) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
progressBar.setMaximum((int) totalSize);
}
});
}
@Override
public void onProgressChanged(final long progress) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
progressBar.setValue((int) progress);
}
});
}
public void uploadFinishNotice(){
StatusBar statusBar = WindowManager.getInstance()
.getStatusBar(ProjectManager.getInstance().getOpenProjects()[0]);
JComponent component = statusBar.getComponent();
final Rectangle rect = component.getVisibleRect();
final Point p = new Point(rect.x + rect.width - 30, rect.y - 30);
final RelativePoint point = new RelativePoint(component, p);
JBPopupFactory.getInstance()
.createHtmlTextBalloonBuilder("fir.im上传成功Y(^_^)Y
"+shortLink.getText()+" 打开链接去查看.
",
MessageType.INFO, new HyperlinkListener() {
@Override
public void hyperlinkUpdate(HyperlinkEvent e) {
if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
// ToolWindowManager.getInstance(ProjectManager.getInstance().getOpenProjects()[0]).getToolWindow("FIR.im").show(null);
browserUrl(Main.getInstance().shortLink.getText()) ;
}
}
})
.setFadeoutTime(10000)
.setCloseButtonEnabled(true)
.createBalloon()
.show(point,
Balloon.Position.atRight);
}
public void browserUrl(String url){
try {
Desktop.getDesktop().browse(new URI( url));
} catch (IOException e1) {
e1.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
Utils.postErrorNoticeTOSlack(e1);
} catch (URISyntaxException e1) {
e1.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
Utils.postErrorNoticeTOSlack(e1);
}
}
public void initComponent(){
document = new ro.catalin.prata.firuploader.Model.Document();
this.formHeader.setText(document.formHeader);
this.formLink.setText(document.formLink);
this.formLog.setText(document.formLog);
this.formPath.setText(document.formPath);
this.formToken.setText(document.formToken);
this.formProject.setText(document.formProject);
this.settingBtn.setText(document.settingBtn);
this.setTokenBtn.setText(document.setTokenBtn);
this.uploadBtn.setText(document.uploadBtn);
this.formTip.setText(document.formTip);
this.languageLabel.setText(document.languageLabel);
this.cancelUploadButton.setText(document.cancelUpload);
this.chinese.setText(document.chineseBtn);
this.english.setText(document.englishBtn);
if("cancel".equals(KeysManager.instance().getFlag())){
this.formTipCB.setSelected(false);
}else{
this.formTipCB.setSelected(true);
}
if("cancel".equals(KeysManager.instance().getUploadFlag())) {
this.formUploadCB.setSelected(false);
}else if("yes".equals(KeysManager.instance().getUploadFlag())){
this.formUploadCB.setSelected(true);
}else{
this.formUploadCB.setSelected(false);
KeysManager.instance().setUploadFlag("cancel");
}
this.formUpload.setText(document.formUpload);
}
}
================================================
FILE: src/ro/catalin/prata/firuploader/view/QrCodeJDialog.java
================================================
package ro.catalin.prata.firuploader.view;
import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.*;
import java.io.IOException;
import java.net.URL;
/**
* Created with IntelliJ IDEA.
* User: will
* Date: 15/8/24
* Time: 下午4:39
* To change this template use File | Settings | File Templates.
*/
public class QrCodeJDialog extends JDialog {
public String uri = "";
JPanel panel;
int screenWidth;
int screenHeight;
public QrCodeJDialog(){
super();
getScreen();
this.setLocation((screenWidth-200)/2,(screenHeight-200)/2);
initPanel();
}
public void setUri(String uri){
this.uri = uri;
initPanel();
}
public void initPanel(){
new Thread(new Runnable() {
@Override
public void run() {
System.out.print("............"+QrCodeJDialog.this.uri);
QrCodeJDialog.this.setSize(200,200);
Image image = null;
try {
URL url = new URL("http://qr.liantu.com/api.php?w=200&text="+QrCodeJDialog.this.uri);
image = ImageIO.read(url);
} catch (IOException e) {
e.printStackTrace();
}
ImageIcon im = new ImageIcon(image);
JLabel label = new JLabel("", im, JLabel.CENTER);
if(panel != null)
QrCodeJDialog.this.remove(panel);
panel = new JPanel(new BorderLayout());
panel.add( label, BorderLayout.CENTER );
QrCodeJDialog.this.add(panel) ;
}
}).start();
}
public void getScreen(){
screenWidth=((int)java.awt.Toolkit.getDefaultToolkit().getScreenSize().width);
screenHeight = ((int)java.awt.Toolkit.getDefaultToolkit().getScreenSize().height);
System.out.println(screenWidth+""+screenHeight);
}
}