Ejemplo n.º 1
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_nearby);
    // Show the Up button in the action bar.
    setupActionBar();

    mFoundMe = false;
    mNoteManager = new NoteManager(App.getDatabaseSource(this));
    mMarkerNotes = new HashMap<String, Long>();

    setUpMapIfNeeded();
  }
  @Override
  public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == REQUEST_PICK_ID) {
      if (resultCode == RESULT_OK) {
        ArrayList<String> names = data.getStringArrayListExtra("names");
        ArrayList<String> types = data.getStringArrayListExtra("types");
        ArrayList<String> hashes = data.getStringArrayListExtra("principal_hashes");
        Log.d(TAG, "Names: " + names);
        Log.d(TAG, "Types: " + types);
        Log.d(TAG, "Hashes: " + hashes);
        // TODO: use the first returned account

        int i;
        for (i = 0; i < types.size(); i++) {
          if (types.get(i).equals(ACCOUNT_TYPE_STANFORD)) {
            break;
          }
        }
        if (i == types.size()) {
          i = 0;
        }

        for (int j = 0; j < names.size(); j++) {
          Util.saveAccount(this, names.get(j), hashes.get(j), types.get(j));
        }

        Util.setPickedAccount(this, names.get(i), types.get(i), hashes.get(i));

        if (Musubi.isMusubiInstalled(this)) {
          new CreateFeedsTask().execute(App.getDatabaseSource(this));
        }
      }
    } else if (requestCode == REQUEST_CREATE_FEED) {
      if (resultCode == RESULT_OK) {
        Log.d(TAG, "got a feed start result");
        Uri feedUri = data.getData();
        if (feedUri != null) {
          // Single feed
          Log.d(TAG, "Feed URI: " + feedUri);
        } else if (data.getStringArrayListExtra("uris") != null
            && data.getStringArrayListExtra("principals") != null) {
          // Multiple feeds
          ArrayList<String> array = data.getStringArrayListExtra("uris");
          ArrayList<String> principals = data.getStringArrayListExtra("principals");
          LocationManager lm = new LocationManager(App.getDatabaseSource(this));
          for (int i = 0; i < array.size(); i++) {
            Log.d(TAG, "Principal: " + principals.get(i));
            List<MLocation> locs = lm.getLocationWithDuplicates(principals.get(i));
            for (MLocation loc : locs) {
              if (loc != null) {
                loc.feedUri = Uri.parse(array.get(i));
                Log.i(TAG, loc.feedUri.toString());
                lm.updateLocation(loc);
              }
            }
          }
        }
      }
    }
  }