Exemplo n.º 1
0
  // TODO: handle push (bApprovePAy in ios)
  private void onPayCancel() {
    activity.runOnUiThread(
        new Runnable() {
          public void run() {
            activity.setContentView(activity.root);
          }
        });

    activity.payMobi.bPaying = false;

    StringBuilder js = new StringBuilder();
    if (PaymentEventType.GETPAYMENTINFO.equals(this.payEvent.type)) {
      js.append(this.payEvent.params.get(1)); // error
      js.append("(");
      js.append("eval(\"({ 'cancelled':true, 'verified':false, 'payment':'{}', 'data':'{}' })\")");
      js.append(",'");
      js.append(this.payEvent.params.get(2)); // sequence
      js.append("');");
    } else if (PaymentEventType.BUYAPPLICATION.equals(this.payEvent.type)) {
      js.append(
          "var e = document.createEvent('Events');e.initEvent('appMobi.payments.buy',true,true);e.success=false;e.message='user cancelled';e.sequence='");
      js.append(this.payEvent.params.get(2)); // sequence
      js.append("';document.dispatchEvent(e);");
    }
    if (js.length() > 0) {
      if (Debug.isDebuggerConnected()) {
        Log.d("[appMobi]", js.toString());
        this.injectJS(js.toString());
      }
    }
  }
Exemplo n.º 2
0
  protected static void showTrayNotification(
      Context context, String message, String data, String badgeNumber, String userKey) {
    // get a reference to the service
    String ns = Context.NOTIFICATION_SERVICE;
    final NotificationManager mNotificationManager =
        (NotificationManager) context.getSystemService(ns);
    // parse the message for test mode
    String testModeApp = null;
    if (message.indexOf('[') == 0) {
      testModeApp = message.substring(1, message.indexOf(']'));
      message = message.substring(message.indexOf(']') + 1).trim();
    }
    if (testModeApp == null && AppMobiActivity.sharedActivity != null) {
      // check if we are running in TestAnywhere mode
      if (AppMobiActivity.sharedActivity.configData != null
          && context.getPackageName().endsWith(AppMobiActivity.sharedActivity.configData.appName)) {
        testModeApp = AppMobiActivity.sharedActivity.configData.appName;
      }
    }
    // create the notification instance
    int icon = R.drawable.icon;
    CharSequence tickerText = message;
    long when = System.currentTimeMillis();
    final Notification notification = new Notification(icon, tickerText, when);
    // initialize latest event info
    CharSequence contentTitle =
        context.getString(R.string.app_name) + ": " + badgeNumber + " unread messages.";
    CharSequence contentText = message;
    Intent notificationIntent = null;
    //    	if(MainActivity.sharedActivity!=null) {
    //    		notificationIntent = new Intent(MainActivity.sharedActivity, MainActivity.class);
    //    	} else {
    try {
      // notificationIntent = new Intent(context, getClassForPendingIntent(context));
      notificationIntent =
          new Intent(context, Class.forName(context.getPackageName() + ".MainActivity"));
    } catch (ClassNotFoundException e) {
      e.printStackTrace();
      if (Debug.isDebuggerConnected())
        Log.e(
            "[appMobi]",
            "getClassForPendingIntent returned null, unable to show tray notification");
    }
    notificationIntent.setAction(Intent.ACTION_MAIN);
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    //    	}
    // add extra so we can know we were started from tray - set value to test mode app, if any
    notificationIntent.putExtra(FROM_NOTIFICATION, testModeApp != null ? testModeApp : "");
    notificationIntent.putExtra(C2DM_USERKEY_EXTRA, userKey);

    PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
    notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
    // make notification non-cancellable
    notification.flags = notification.flags | Notification.FLAG_NO_CLEAR;
    // show in status bar
    mNotificationManager.notify(PUSH_NOTIFICATION_ID, notification);
    // this would remove notification from status bar
    // mNotificationManager.cancel(BUSY_INDICATOR);
  }
Exemplo n.º 3
0
  public ServicesData(AppMobiActivity activity) {
    this.activity = activity;
    name2Service = new HashMap<String, Service>();

    // decrypt services.xml
    String decryptedServicesDotXml = null;
    try {
      decryptedServicesDotXml = decryptServicesDotXml();
    } catch (Exception e) {
      if (Debug.isDebuggerConnected()) Log.d("[appMobi]", e.getMessage(), e);
    }
    // parse decryptedServicesDotXml
    parseServicesXml(decryptedServicesDotXml);
  }
Exemplo n.º 4
0
  public void updateApplications() {
    if (!activity.configData.hasPayments) return;

    SharedPreferences prefs =
        AppMobiActivity.sharedActivity.getSharedPreferences(
            AppInfo.APP_PREFS, Context.MODE_PRIVATE);
    String appUser = prefs.getString("payments.user", "");
    StringBuilder urlString =
        new StringBuilder(
            "https://services.appmobi.com/external/AppPurchases.apsx?cmd=getauthorizedapps&userid=");
    urlString.append(appUser);

    AMSResponse response = null;
    try {
      URL url = new URL(urlString.toString());
      XMLReader xr = SAXParserFactory.newInstance().newSAXParser().getXMLReader();
      AMSResponseHandler handler = new AMSResponseHandler();
      xr.setContentHandler(handler);
      InputStream is = url.openStream();
      xr.parse(new InputSource(is));
      response = handler.getParsedData();
      is.close();
    } catch (Exception e) {
      if (Debug.isDebuggerConnected())
        Log.e("error", "AppConfig Parsing Error w/ url: " + urlString, e);
    }

    boolean bNewPurchases = false;

    for (AMSPurchase purchase : response.purchases) {
      Bookmark bookmark = activity.getBookmarkForAppName(purchase.app);
      if (purchase.isAuthorized && !bookmark.isInstalled) {
        bookmark.isAuthorized = true;
        bNewPurchases = true;
      }
    }

    if (bNewPurchases) {
      new Thread("AppMobiPayments:updateApplications()") {
        public void run() {
          authorizeApps();
        }
      }.start();
    }
  }