コード例 #1
0
ファイル: NetworkReceiver.java プロジェクト: GeoODK/collect
 @Override
 public void authRequest(Uri url, HashMap<String, String> doneSoFar) {
   // if we get an auth request, just fail
   if (mInstanceUploaderTask != null) {
     mInstanceUploaderTask.setUploaderListener(null);
   }
   //        if (mGoogleMapsEngineUploadTask != null) {
   //            mGoogleMapsEngineUploadTask.setUploaderListener(null);
   //        }
   running = false;
 }
コード例 #2
0
ファイル: NetworkReceiver.java プロジェクト: GeoODK/collect
  private void uploadForms(Context context) {
    if (!running) {
      running = true;

      String selection = InstanceColumns.STATUS + "=? or " + InstanceColumns.STATUS + "=?";
      String selectionArgs[] = {
        InstanceProviderAPI.STATUS_COMPLETE, InstanceProviderAPI.STATUS_SUBMISSION_FAILED
      };

      ArrayList<Long> toUpload = new ArrayList<Long>();
      Cursor c =
          context
              .getContentResolver()
              .query(InstanceColumns.CONTENT_URI, null, selection, selectionArgs, null);
      try {
        if (c != null && c.getCount() > 0) {
          c.move(-1);
          while (c.moveToNext()) {
            Long l = c.getLong(c.getColumnIndex(InstanceColumns._ID));
            toUpload.add(Long.valueOf(l));
          }
        }
      } finally {
        if (c != null) {
          c.close();
        }
      }

      if (toUpload.size() < 1) {
        running = false;
        return;
      }

      Long[] toSendArray = new Long[toUpload.size()];
      toUpload.toArray(toSendArray);

      SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context);

      String protocol =
          settings.getString(
              PreferencesActivity.KEY_PROTOCOL, context.getString(R.string.protocol_odk_default));

      if (protocol.equals(context.getString(R.string.protocol_google_maps_engine))) {

        String googleUsername =
            settings.getString(PreferencesActivity.KEY_SELECTED_GOOGLE_ACCOUNT, null);
        if (googleUsername == null || googleUsername.equalsIgnoreCase("")) {
          // just quit if there's no username
          running = false;
          return;
        }
        // mGoogleMapsEngineUploadTask.setUserName(googleUsername);
        // mGoogleMapsEngineUploadTask.setUploaderListener(this);
        // mGoogleMapsEngineUploadTask.execute(toSendArray);

      } else {
        // get the username, password, and server from preferences

        String storedUsername = settings.getString(PreferencesActivity.KEY_USERNAME, null);
        String storedPassword = settings.getString(PreferencesActivity.KEY_PASSWORD, null);
        String server =
            settings.getString(
                PreferencesActivity.KEY_SERVER_URL, context.getString(R.string.default_server_url));
        String url =
            server
                + settings.getString(
                    PreferencesActivity.KEY_FORMLIST_URL,
                    context.getString(R.string.default_odk_formlist));

        Uri u = Uri.parse(url);
        WebUtils.addCredentials(storedUsername, storedPassword, u.getHost());

        mInstanceUploaderTask = new InstanceUploaderTask();
        mInstanceUploaderTask.setUploaderListener(this);

        mInstanceUploaderTask.execute(toSendArray);
      }
    }
  }
コード例 #3
0
ファイル: NetworkReceiver.java プロジェクト: GeoODK/collect
  @Override
  public void uploadingComplete(HashMap<String, String> result) {
    // task is done
    if (mInstanceUploaderTask != null) {
      mInstanceUploaderTask.setUploaderListener(null);
    }
    //        if (mGoogleMapsEngineUploadTask != null) {
    //            mGoogleMapsEngineUploadTask.setUploaderListener(null);
    //        }
    running = false;

    StringBuilder message = new StringBuilder();
    message.append(Collect.getInstance().getString(R.string.odk_auto_note) + " :: \n\n");

    if (result == null) {
      message.append(Collect.getInstance().getString(R.string.odk_auth_auth_fail));
    } else {

      StringBuilder selection = new StringBuilder();
      Set<String> keys = result.keySet();
      Iterator<String> it = keys.iterator();

      String[] selectionArgs = new String[keys.size()];
      int i = 0;
      while (it.hasNext()) {
        String id = it.next();
        selection.append(InstanceColumns._ID + "=?");
        selectionArgs[i++] = id;
        if (i != keys.size()) {
          selection.append(" or ");
        }
      }

      {
        Cursor results = null;
        try {
          results =
              Collect.getInstance()
                  .getContentResolver()
                  .query(
                      InstanceColumns.CONTENT_URI, null, selection.toString(), selectionArgs, null);
          if (results.getCount() > 0) {
            results.moveToPosition(-1);
            while (results.moveToNext()) {
              String name = results.getString(results.getColumnIndex(InstanceColumns.DISPLAY_NAME));
              String id = results.getString(results.getColumnIndex(InstanceColumns._ID));
              message.append(name + " - " + result.get(id) + "\n\n");
            }
          }
        } finally {
          if (results != null) {
            results.close();
          }
        }
      }
    }

    Intent notifyIntent = new Intent(Collect.getInstance(), NotificationActivity.class);
    notifyIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    notifyIntent.putExtra(NotificationActivity.NOTIFICATION_KEY, message.toString().trim());

    PendingIntent pendingNotify =
        PendingIntent.getActivity(
            Collect.getInstance(), 0, notifyIntent, PendingIntent.FLAG_UPDATE_CURRENT);

    NotificationCompat.Builder mBuilder =
        new NotificationCompat.Builder(Collect.getInstance())
            .setSmallIcon(R.drawable.notes)
            .setContentTitle(Collect.getInstance().getString(R.string.odk_auto_note))
            .setContentIntent(pendingNotify)
            .setContentText(message.toString().trim())
            .setAutoCancel(true)
            .setLargeIcon(
                BitmapFactory.decodeResource(
                    Collect.getInstance().getResources(), android.R.drawable.ic_dialog_info));

    NotificationManager mNotificationManager =
        (NotificationManager) Collect.getInstance().getSystemService(Context.NOTIFICATION_SERVICE);
    mNotificationManager.notify(1328974928, mBuilder.build());
  }