Example #1
0
  @Override
  public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
    mSpinnerAdapter.swapCursor(data);

    if (listIdToSelect > -1 || listIdToSelect == ALL_NOTES_ID) {
      int position = getPosOfId(listIdToSelect);
      if (position > -1) {
        currentListPos = position;
        currentListId = listIdToSelect;
        getActionBar().setSelectedNavigationItem(position);
      }
      listIdToSelect = -1;
    }

    if (optionsMenu != null) {
      MenuItem createNote = optionsMenu.findItem(R.id.menu_add);
      if (createNote != null) {
        // Only show this button if there is a list to create notes in
        if (mSpinnerAdapter.getCount() == 0) {
          createNote.setVisible(false);
        } else {
          createNote.setVisible(true);
        }
      }
    }
    beforeBoot = false; // Need to do it here
  }
Example #2
0
  @Override
  public boolean onPrepareOptionsMenu(Menu menu) {
    MenuItem deleteList = menu.findItem(R.id.menu_deletelist);
    if (deleteList != null) {
      // Only show this button if there is a list to create it in
      if (mSpinnerAdapter.getCount() == 0 || currentListId < 0) {
        deleteList.setVisible(false);
      } else {
        deleteList.setVisible(true);
      }
    }
    MenuItem renameList = menu.findItem(R.id.menu_renamelist);
    if (renameList != null) {
      // Only show this button if there is a list to create it in
      if (mSpinnerAdapter.getCount() == 0 || currentListId < 0) {
        renameList.setVisible(false);
      } else {
        renameList.setVisible(true);
      }
    }
    MenuItem defaultList = menu.findItem(R.id.menu_setdefaultlist);
    if (defaultList != null) {
      // Only show this button if there is a proper list showing
      if (mSpinnerAdapter.getCount() == 0 || currentListId < 0) {
        defaultList.setVisible(false);
      } else {
        defaultList.setVisible(true);
      }
    }

    return super.onPrepareOptionsMenu(menu);
  }
Example #3
0
 private int getPosOfId(long id) {
   int length = mSpinnerAdapter.getCount();
   int position;
   for (position = 0; position < length; position++) {
     if (id == mSpinnerAdapter.getItemId(position)) {
       break;
     }
   }
   if (position == length) {
     // Happens both if list is empty
     // and if id is -1
     position = -1;
   }
   return position;
 }
Example #4
0
 @Override
 public void onLoaderReset(Loader<Cursor> loader) {
   mSpinnerAdapter.swapCursor(null);
 }
Example #5
0
  @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);
  }