Search in sources :

Example 1 with PurchaseCallback

use of com.codename1.payment.PurchaseCallback in project CodenameOne by codenameone.

the class CodenameOneActivity method getPurchaseCallback.

public PurchaseCallback getPurchaseCallback() {
    Object app = getApp();
    PurchaseCallback pc = app instanceof PurchaseCallback ? (PurchaseCallback) app : null;
    return pc;
}
Also used : PurchaseCallback(com.codename1.payment.PurchaseCallback) JSONObject(org.json.JSONObject)

Example 2 with PurchaseCallback

use of com.codename1.payment.PurchaseCallback in project CodenameOne by codenameone.

the class Executor method main.

public static void main(final String[] argv) throws Exception {
    setProxySettings();
    final Properties p = new Properties();
    String currentDir = System.getProperty("user.dir");
    File props = new File(currentDir, "codenameone_settings.properties");
    if (props.exists()) {
        FileInputStream f = null;
        try {
            f = new FileInputStream(props);
            p.load(f);
            f.close();
        } catch (Exception ex) {
        } finally {
            try {
                f.close();
            } catch (IOException ex) {
            }
        }
    }
    SwingUtilities.invokeLater(new Runnable() {

        @Override
        public void run() {
            try {
                String packageName = p.getProperty("codename1.packageName");
                String mainName = p.getProperty("codename1.mainName");
                if (argv.length > 1) {
                    if (argv[1].equalsIgnoreCase("-force") || packageName == null) {
                        c = Class.forName(argv[0]);
                    } else {
                        c = Class.forName(packageName + "." + mainName);
                    }
                } else {
                    if (packageName == null || System.getenv("FORCE_CLASS") != null) {
                        c = Class.forName(argv[0]);
                    } else {
                        c = Class.forName(packageName + "." + mainName);
                    }
                }
                try {
                    Method m = c.getDeclaredMethod("main", String[].class);
                    m.invoke(null, new Object[] { null });
                } catch (NoSuchMethodException noMain) {
                    try {
                        Method m = c.getDeclaredMethod("startApp");
                        m.invoke(c.newInstance());
                    } catch (NoSuchMethodException noStartApp) {
                        if (Display.isInitialized()) {
                            Display.deinitialize();
                        }
                        final Method m = c.getDeclaredMethod("init", Object.class);
                        if (m.getExceptionTypes() != null && m.getExceptionTypes().length > 0) {
                            System.err.println("ERROR: the init method can't declare a throws clause");
                            System.exit(1);
                        }
                        app = c.newInstance();
                        if (app instanceof PushCallback) {
                            CodenameOneImplementation.setPushCallback((PushCallback) app);
                        }
                        if (app instanceof PurchaseCallback) {
                            CodenameOneImplementation.setPurchaseCallback((PurchaseCallback) app);
                        }
                        Display.init(null);
                        Display.getInstance().callSerially(new Runnable() {

                            @Override
                            public void run() {
                                try {
                                    m.invoke(app, new Object[] { null });
                                    Method start = c.getDeclaredMethod("start", new Class[0]);
                                    if (start.getExceptionTypes() != null && start.getExceptionTypes().length > 0) {
                                        System.err.println("ERROR: the start method can't declare a throws clause");
                                        System.exit(1);
                                    }
                                    start.invoke(app, new Object[0]);
                                } catch (NoSuchMethodException err) {
                                    System.out.println("Couldn't find a main or a startup in " + argv[0]);
                                } catch (InvocationTargetException err) {
                                    err.getTargetException().printStackTrace();
                                    System.exit(1);
                                } catch (Exception err) {
                                    err.printStackTrace();
                                    System.exit(1);
                                }
                            }
                        });
                    }
                }
            } catch (Exception err) {
                err.printStackTrace();
                System.exit(1);
            }
        }
    });
}
Also used : IOException(java.io.IOException) Method(java.lang.reflect.Method) Properties(java.util.Properties) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException) PushCallback(com.codename1.push.PushCallback) PurchaseCallback(com.codename1.payment.PurchaseCallback) File(java.io.File)

Aggregations

PurchaseCallback (com.codename1.payment.PurchaseCallback)2 PushCallback (com.codename1.push.PushCallback)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 Properties (java.util.Properties)1 JSONObject (org.json.JSONObject)1