use of com.codename1.push.PushCallback 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);
}
}
});
}
use of com.codename1.push.PushCallback in project CodenameOne by codenameone.
the class AndroidImplementation method firePendingPushes.
public static void firePendingPushes(final PushCallback c, Context a) {
try {
if (c != null) {
InputStream i = a.openFileInput("CN1$AndroidPendingNotifications");
if (i == null) {
return;
}
DataInputStream is = new DataInputStream(i);
int count = is.readByte();
for (int iter = 0; iter < count; iter++) {
boolean hasType = is.readBoolean();
String actualType = null;
if (hasType) {
actualType = is.readUTF();
}
final String t = actualType;
final String b = is.readUTF();
long s = is.readLong();
Display.getInstance().callSerially(new Runnable() {
@Override
public void run() {
Display.getInstance().setProperty("pendingPush", "true");
Display.getInstance().setProperty("pushType", t);
if (t != null && ("3".equals(t) || "6".equals(t))) {
String[] a = b.split(";");
c.push(a[0]);
c.push(a[1]);
} else {
c.push(b);
}
Display.getInstance().setProperty("pendingPush", null);
}
});
}
a.deleteFile("CN1$AndroidPendingNotifications");
}
} catch (IOException err) {
}
}
use of com.codename1.push.PushCallback in project CodenameOne by codenameone.
the class PushNotificationService method push.
@Override
public void push(final String value) {
final PushCallback callback = getPushCallbackInstance();
if (callback != null) {
Display.getInstance().callSerially(new Runnable() {
public void run() {
callback.push(value);
}
});
} else {
NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
Intent newIntent = new Intent(this, getStubClass());
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, newIntent, PendingIntent.FLAG_CANCEL_CURRENT);
Notification.Builder builder = new Notification.Builder(this).setContentIntent(contentIntent).setSmallIcon(android.R.drawable.stat_notify_sync).setTicker(value).setAutoCancel(true).setWhen(System.currentTimeMillis()).setContentTitle(value).setDefaults(Notification.DEFAULT_ALL);
Notification notif = builder.build();
nm.notify((int) System.currentTimeMillis(), notif);
}
}
Aggregations