Exemplo n.º 1
0
 public void handleExtraButtonClick(View v) {
   if (focusedPlace == null) {
     return;
   }
   Intent intent;
   if (focusedBookmarkIds.isEmpty()) {
     intent = new Intent(this, AddBookmarkActivity.class);
     intent.putExtra(BookmarksActivity.PLACE_ID, focusedPlace.getId());
   } else {
     if (focusedBookmarkIds.size() == 1) {
       intent = new Intent(this, EditBookmarkActivity.class);
       intent.putExtra(BookmarksActivity.BOOKMARK_ID, focusedBookmarkIds.get(0));
     } else {
       Bookmark[] bookmarks = new Bookmark[focusedBookmarkIds.size()];
       for (int i = 0; i < focusedBookmarkIds.size(); i++) {
         bookmarks[i] = Bookmark.getBookmark(this, focusedBookmarkIds.get(i));
       }
       Bundle data = new Bundle();
       data.putParcelableArray(BOOKMARKS, bookmarks);
       removeDialog(DIALOG_MULTIPLE_BOOKMARKS);
       showDialog(DIALOG_MULTIPLE_BOOKMARKS, data);
       return;
     }
   }
   startActivityForResult(intent, ADD_EDIT_BOOKMARK_RESULT);
 }
Exemplo n.º 2
0
  @Override
  protected Dialog onCreateDialog(final int id) {
    Dialog dialog;
    switch (id) {
      case DIALOG_MULTIPLE_BOOKMARKS:
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle("Multiple bookmarks found!");
        String[] items = new String[focusedBookmarkIds.size()];
        for (int i = 0; i < focusedBookmarkIds.size(); i++) {
          long bookmarkId = focusedBookmarkIds.get(i);
          items[i] = Bookmark.getBookmark(this, bookmarkId).getCustomName();
        }

        builder.setItems(
            items,
            new DialogInterface.OnClickListener() {
              public void onClick(DialogInterface dialog, int item) {
                Intent intent = new Intent(PtolemyMapActivity.this, EditBookmarkActivity.class);
                intent.putExtra(BookmarksActivity.BOOKMARK_ID, focusedBookmarkIds.get(item));
                startActivityForResult(intent, ADD_EDIT_BOOKMARK_RESULT);
              }
            });
        dialog = builder.create();
        break;
      default:
        dialog = null;
        break;
    }
    return dialog;
  }
Exemplo n.º 3
0
 private void setExtraButton() {
   focusedBookmarkIds = Bookmark.findInBookmarks(this, focusedPlace);
   ImageButton extraBtn = ((ImageButton) findViewById(R.id.place_extra_button));
   if (focusedBookmarkIds.isEmpty()) {
     extraBtn.setImageDrawable(getResources().getDrawable(R.drawable.ic_menu_bookmark_add));
   } else {
     extraBtn.setImageDrawable(getResources().getDrawable(R.drawable.ic_menu_edit));
   }
 }