Exemple #1
1
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mDbHelper = new NotesDbAdapter(this);
    mDbHelper.open();

    setContentView(R.layout.note_edit);
    setTitle(R.string.edit_note);

    mTitleText = (EditText) findViewById(R.id.title);
    mBodyText = (EditText) findViewById(R.id.body);

    Button confirmButton = (Button) findViewById(R.id.confirm);

    mRowId =
        (savedInstanceState == null)
            ? null
            : (Long) savedInstanceState.getSerializable(NotesDbAdapter.KEY_ROWID);
    if (mRowId == null) {
      Bundle extras = getIntent().getExtras();
      mRowId = extras != null ? extras.getLong(NotesDbAdapter.KEY_ROWID) : null;
    }

    populateFields();

    confirmButton.setOnClickListener(
        new View.OnClickListener() {

          public void onClick(View view) {
            setResult(RESULT_OK);
            finish();
          }
        });
  }
Exemple #2
0
  @Override
  protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
    super.onActivityResult(requestCode, resultCode, intent);

    if (intent != null) {
      Bundle extras = intent.getExtras();
      switch (requestCode) {
        case ACTIVITY_CREATE:
          String title = extras.getString(NotesDbAdapter.KEY_TITLE);
          String body = extras.getString(NotesDbAdapter.KEY_BODY);
          mDbHelper.createNote(title, body);
          fillData();
          break;
        case ACTIVITY_EDIT:
          Long rowId = extras.getLong(NotesDbAdapter.KEY_ROWID);
          if (rowId != null) {
            String editTitle = extras.getString(NotesDbAdapter.KEY_TITLE);
            String editBody = extras.getString(NotesDbAdapter.KEY_BODY);
            mDbHelper.updateNote(rowId, editTitle, editBody);
            fillData();
          }
          break;
        default:
          break;
      }
    }
  }
  /** Set the list view to display notes from the database */
  private void fillData() {
    mDbHelper.fetchAllNotes();

    ArrayList<AppNote> notesList = mDbHelper.fetchAllNotes();
    listAdapter = new ArrayAdapter<AppNote>(this, R.layout.notes_row, notesList);
    setListAdapter(listAdapter);
  }
  private boolean updateNotes() {
    ArrayList<AppNote> changed = mDbHelper.fetchNotes(NotesDbAdapter.CHANGED_NOTES_SELECTION);
    boolean allUpdated = true;

    for (AppNote appNote : changed) {
      try {
        link.update(appNote.getNote());
        mDbHelper.updateNote(appNote.getId(), appNote.getNote(), true);
      } catch (LinkItemNotFound e) {
        e.printStackTrace();
        try {
          link.add(appNote.getNote());
          mDbHelper.updateNote(appNote.getId(), appNote.getNote(), true);
        } catch (LibOperaLinkException e1) {
          e1.printStackTrace();
          allUpdated = false;
        }
      } catch (LinkAccessDeniedException e) {
        e.printStackTrace();
        isConnected = false;
        allUpdated = false;
      } catch (LibOperaLinkException e) {
        e.printStackTrace();
        allUpdated = false;
      }
    }

    return allUpdated;
  }
Exemple #5
0
  private void saveState() {
    String title = mTitleText.getText().toString();
    String body = mBodyText.getText().toString();

    if (mRowId == null) {
      long id = mDbHelper.createNote(title, body);
      if (id > 0) {
        mRowId = id;
      }
    } else {
      mDbHelper.updateNote(mRowId, title, body);
    }
  }
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.notes_list);

    // Initialise database connection and read notes
    mDbHelper = new NotesDbAdapter(this);
    mDbHelper.open();
    fillData();

    registerForContextMenu(getListView());

    // Read preferences
    pref = getPreferences(MODE_PRIVATE);
    requestToken = pref.getString(REQUEST_TOKEN_PREF_KEY, null);
    accessToken = pref.getString(ACCESS_TOKEN_PREF_KEY, null);
    tokenSecret = pref.getString(TOKEN_SECRET_PREF_KEY, null);
    automaticSync = pref.getBoolean(getString(R.string.sync_option), true);

    // Create object for connection with Opera Link
    if (accessToken != null && tokenSecret != null) {
      isConnected = true;
      link =
          LinkClient.createFromAccessToken(consumerKey, consumerSecret, accessToken, tokenSecret);
      if (automaticSync) {
        syncItems();
      }
    } else if (requestToken != null) {
      link =
          LinkClient.createFromRequestToken(consumerKey, consumerSecret, requestToken, tokenSecret);
    } else {
      link = new LinkClient(consumerKey, consumerSecret);
    }
  }
Exemple #7
0
 private void populateFields() {
   if (mRowId != null) {
     Cursor note = mDbHelper.fetchNote(mRowId);
     startManagingCursor(note);
     mTitleText.setText(note.getString(note.getColumnIndexOrThrow(NotesDbAdapter.KEY_TITLE)));
     mBodyText.setText(note.getString(note.getColumnIndexOrThrow(NotesDbAdapter.KEY_BODY)));
   }
 }
Exemple #8
0
 @Override
 public void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   setContentView(R.layout.notepad_list);
   mDbHelper = new NotesDbAdapter(this);
   mDbHelper.open();
   fillData();
 }
 /**
  * Change notes at the server
  *
  * @return true if succeeded
  */
 private boolean uploadNewNotes() {
   ArrayList<AppNote> newNotes = mDbHelper.fetchNotes(NotesDbAdapter.NEW_NOTES_SELECTION);
   boolean allUpdated = true;
   try {
     for (AppNote appNote : newNotes) {
       link.add(appNote.getNote());
       mDbHelper.updateNote(appNote.getId(), appNote.getNote(), true);
     }
   } catch (LinkAccessDeniedException e) {
     e.printStackTrace();
     allUpdated = false;
     isConnected = false;
   } catch (LibOperaLinkException e) {
     e.printStackTrace();
     allUpdated = false;
   }
   return allUpdated;
 }
Exemple #10
0
  private void fillData() {
    // Get all of the notes from the database and create the item list
    Cursor c = mDbHelper.fetchAllNotes();
    startManagingCursor(c);

    String[] from = new String[] {NotesDbAdapter.KEY_TITLE};
    int[] to = new int[] {R.id.text1};

    // Now create an array adapter and set it to display using our row
    SimpleCursorAdapter notes = new SimpleCursorAdapter(this, R.layout.notes_row, c, from, to);
    setListAdapter(notes);
  }
  /**
   * Get new notes and updates from Opera Link server and insert them into database
   *
   * @return true if operation succeeded
   */
  private boolean getServerNotes() {
    ArrayList<NoteFolderEntry> notes = null;
    try {
      notes = link.getRootNotes(true);
    } catch (LinkAccessDeniedException e) {
      e.printStackTrace();
      isConnected = false;
      return false;
    } catch (LibOperaLinkException e) {
      e.printStackTrace();
      return false;
    }
    int newNotes = 0;
    ArrayList<Note> allNotes = new ArrayList<Note>();
    flattenNoteFolders(notes, allNotes);

    for (Note note : allNotes) {
      // try to get note from the database
      AppNote appNote = mDbHelper.fetchOperaNote(note.getId());
      if (appNote == null) { // no such note in database, add a new one
        ++newNotes;
        mDbHelper.importAndAddNote(note);
      } else if (!appNote.getNote().content.equals(note.content)) {
        // update already added note
        if (appNote.isSynced()) {
          mDbHelper.updateNote(appNote.getId(), note, true);
        } else { // note content conflicted, add new note leaving the
          // old one
          mDbHelper.createNote(note);
          // set that the old one is synchronised
          mDbHelper.updateNote(appNote.getId(), appNote.getNote(), true);
        }
      }
    }

    showToast(String.valueOf(newNotes) + " " + getString(R.string.got_notes));
    return true;
  }
  /**
   * Delete notes which were marked as those to be deleted, delete them also from the Opera Link
   * server
   *
   * @return true if deleting notes at the server succeeded
   */
  private boolean deleteNotes() {
    ArrayList<AppNote> toDelete = mDbHelper.fetchNotes(NotesDbAdapter.TO_DELETE_SELECTION);
    boolean allDeleted = true;
    for (AppNote appNote : toDelete) {
      try {
        if (appNote.getOpera_id() != null) {
          link.delete(appNote.getNote());
        }
        mDbHelper.deleteNote(appNote.getId());
      } catch (LinkItemNotFound e) {
        e.printStackTrace();
        mDbHelper.deleteNote(appNote.getId());
      } catch (LinkAccessDeniedException e) {
        e.printStackTrace();
        isConnected = false;
        allDeleted = false;
      } catch (LibOperaLinkException e) {
        e.printStackTrace();
        allDeleted = false;
      }
    }

    return allDeleted;
  }
Exemple #13
0
  private void fillData() {
    // Get all of the rows from the database and create the item list
    mNotesCursor = mDbHelper.fetchAllNotes();
    startManagingCursor(mNotesCursor);

    // Create an array to specify the fields we want to display in the list (only TITLE)
    String[] from = new String[] {NotesDbAdapter.KEY_TITLE};

    // and an array of the fields we want to bind those fields to (in this case just text1)
    int[] to = new int[] {R.id.text1};

    // Now create a simple cursor adapter and set it to display
    SimpleCursorAdapter notes =
        new SimpleCursorAdapter(this, R.layout.notes_row, mNotesCursor, from, to);
    setListAdapter(notes);
  }
 @Override
 public boolean onContextItemSelected(MenuItem item) {
   switch (item.getItemId()) {
     case DELETE_MENU_ITEM:
       // Mark the selected note to be deleted and send changes to the
       // server
       AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
       AppNote note = listAdapter.getItem((int) info.id);
       mDbHelper.markToDelete(note.getId());
       if (note.getOpera_id() != null) {
         notesDeleted = true;
         if (automaticSync) {
           sendChanges();
         }
       }
       fillData();
       return true;
   }
   return super.onContextItemSelected(item);
 }
Exemple #15
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.subjectslist);
    mDbHelper = new SubjectDbAdapter(this);
    mDbHelper.open();
    nDbHelper = new NotesDbAdapter(this);
    nDbHelper.open();
    fillData();

    if (mDbHelper.countSubjects() < 1) {
      Toast.makeText(getApplicationContext(), "No subject(s)", Toast.LENGTH_SHORT).show();
    }

    ListView list = getListView();

    list.setOnItemLongClickListener(
        new OnItemLongClickListener() {

          @Override
          public boolean onItemLongClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
            Pair temp = (Pair) arg1.getTag();
            delete_id = temp.getId();
            showDeleteDialog();
            // TODO Auto-generated method stub
            return false;
          }
        });

    Button addsubject = (Button) findViewById(R.id.addbuttonsubj);

    addsubject.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            addsubject();
          }
        });
  }
Exemple #16
0
 private void createNote() {
   String noteName = "Note " + mNoteNumber++;
   mDbHelper.createNote(noteName, "");
   fillData();
 }
Exemple #17
0
 private void deleteNote(long id) {
   mDbHelper.deleteNote(id);
   fillData();
 }