public void onDeleteAction() { // both list and editor should be notified NotesListFragment list = (NotesListFragment) getFragmentManager().findFragmentById(R.id.noteslistfragment); NotesEditorFragment editor = (NotesEditorFragment) getFragmentManager().findFragmentById(R.id.editor_container); if (editor != null) editor.setSelfAction(); // delete note if (list != null) list.onDelete(); }
@Override public boolean onNavigationItemSelected(int itemPosition, long itemId) { if (UI_DEBUG_PRINTS) Log.d(TAG, "onNavigationItemSelected pos: " + itemPosition + " id: " + itemId); // Change the active list currentListId = itemId; currentListPos = itemPosition; // Display list' if (list != null) { list.showList(itemId); } return true; }
@Override protected void onCreate(Bundle savedInstanceState) { // Must set theme before this super.onCreate(savedInstanceState); Log.d(TAG, "onCreate"); LANDSCAPE_MODE = getResources().getBoolean(R.bool.useLandscapeView); AT_LEAST_ICS = getResources().getBoolean(R.bool.atLeastIceCreamSandwich); AT_LEAST_HC = getResources().getBoolean(R.bool.atLeastHoneycomb); if (savedInstanceState != null) { if (UI_DEBUG_PRINTS) Log.d(TAG, "Reloading state"); currentListId = savedInstanceState.getLong(CURRENT_LIST_ID); currentListPos = savedInstanceState.getInt(CURRENT_LIST_POS); } // Setting theme here readAndSetSettings(); // Set up dropdown navigation ActionBar actionBar = getActionBar(); actionBar.setDisplayShowTitleEnabled(false); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST); // Will set cursor in Loader // mSpinnerAdapter = new ExtrasCursorAdapter(this, // R.layout.actionbar_dropdown_item, null, // new String[] { NotePad.Lists.COLUMN_NAME_TITLE }, // new int[] { android.R.id.text1 }, new int[] { -9, -8 }, // new int[] { R.string.show_from_all_lists, R.string.error_title }); mSpinnerAdapter = new ExtrasCursorAdapter( this, R.layout.actionbar_dropdown_item, null, new String[] {NotePad.Lists.COLUMN_NAME_TITLE}, new int[] {android.R.id.text1}, new int[] {ALL_NOTES_ID}, new int[] {R.string.show_from_all_lists}); mSpinnerAdapter.setDropDownViewResource(R.layout.actionbar_dropdown_item); // This will listen for navigation callbacks actionBar.setListNavigationCallbacks(mSpinnerAdapter, this); // XML makes sure notes list is displayed. And editor too in landscape // if (lightTheme) // setContentView(R.layout.fragment_layout_light); // else setContentView(R.layout.fragment_layout); // Set this as delete listener NotesListFragment list = (NotesListFragment) getFragmentManager().findFragmentById(R.id.noteslistfragment); list.setOnDeleteListener(this); this.list = list; // So editor can access it ONDELETELISTENER = this; // Set a default list to open if one is set listIdToSelect = PreferenceManager.getDefaultSharedPreferences(this).getLong(DEFAULTLIST, -1); // Handle the intent first, so we know what to possibly select once the // loader is finished beforeBoot = true; onNewIntent(getIntent()); getLoaderManager().initLoader(0, null, this); }
@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); } } } } }