Esempio n. 1
0
  @Override
  protected void onNewIntent(Intent intent) {
    if (UI_DEBUG_PRINTS) Log.d("FragmentLayout", "On New Intent");

    // Search
    if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
      String query = intent.getStringExtra(SearchManager.QUERY);
      // list.onQueryTextChange(query);
      if (list != null && list.mSearchView != null) {
        list.mSearchView.setQuery(query, false);
      } else if (list != null) {
        list.onQueryTextSubmit(query);
      }
      // Edit or View a list or a note.
    } else if (Intent.ACTION_EDIT.equals(intent.getAction())
        || Intent.ACTION_VIEW.equals(intent.getAction())) {
      if (UI_DEBUG_PRINTS) Log.d("FragmentLayout", "On New Intent EDIT");
      // First, if we should display a list
      if (intent.getData() != null
          && intent.getData().getPath().startsWith(NotePad.Lists.PATH_VISIBLE_LIST_ID)) {
        // Get id to display
        String newId = intent.getData().getPathSegments().get(NotePad.Lists.ID_PATH_POSITION);
        long listId = Long.parseLong(newId);
        // Handle it differently depending on if the app has already
        // loaded or not.
        openListFromIntent(listId);
      } else if (intent.getData() != null
          && intent.getData().getPath().startsWith(NotePad.Notes.PATH_VISIBLE_NOTE_ID)) {
        if (list != null) {
          long listId = ALL_NOTES_ID;
          if (intent.getExtras() != null) {
            listId = intent.getExtras().getLong(NotePad.Notes.COLUMN_NAME_LIST, ALL_NOTES_ID);
          }
          // Open the containing list if we have to. No need to change
          // lists
          // if we are already displaying all notes.
          if (listId != -1 && currentListId != ALL_NOTES_ID && currentListId != listId) {
            openListFromIntent(listId);
          }
          if (listId != -1) {
            list.handleNoteIntent(intent);
          }
        }
      }
    } else if (Intent.ACTION_INSERT.equals(intent.getAction())) {
      if (UI_DEBUG_PRINTS) Log.d("FragmentLayout", "On New Intent INSERT");
      if (intent.getType() != null && intent.getType().equals(NotePad.Lists.CONTENT_TYPE)
          || intent.getData() != null
              && intent.getData().equals(NotePad.Lists.CONTENT_VISIBLE_URI)) {
        // get Title
        if (intent.getExtras() != null) {
          String title = intent.getExtras().getString(NotePad.Lists.COLUMN_NAME_TITLE, "");
          createList(title);
        }
      } else if (intent.getType() != null && intent.getType().equals(NotePad.Notes.CONTENT_TYPE)
          || intent.getData() != null
              && intent.getData().equals(NotePad.Notes.CONTENT_VISIBLE_URI)) {
        Log.d("FragmentLayout", "INSERT NOTE");
        if (list != null) {
          long listId = ALL_NOTES_ID;
          if (intent.getExtras() != null) {
            listId = intent.getExtras().getLong(NotePad.Notes.COLUMN_NAME_LIST, ALL_NOTES_ID);
          }

          // Open the containing list if we have to. No need to change
          // lists
          // if we are already displaying all notes.
          if (listId != -1 && currentListId != ALL_NOTES_ID && currentListId != listId) {
            openListFromIntent(listId);
          }
          if (listId != -1) {
            list.handleNoteIntent(intent);
          }
        }
      }
    }
  }