Android Open Source - bnote Edit Activity






From Project

Back to project page bnote.

License

The source code is released under:

MIT License

If you think the Android project bnote listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.rd.bnote;
/*from   w  w w. j av a  2  s .co m*/
import java.util.Date;

import android.app.Activity;
import android.database.Cursor;
import android.os.Bundle;
import android.view.Menu;
import android.widget.EditText;

public class EditActivity extends Activity {
  
  private DBManager mDbManager;
  private EditText mEditText;
  private Note mNote;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.note_edit);
    findViews();
    mDbManager = new DBManager(this);
    mNote = null;
    fillEdittext(savedInstanceState);
  }
  
  public void findViews() {
    mEditText = (EditText) findViewById(R.id.text_note);
  }
  
  public void fillEdittext(Bundle bundle) {
    int _id = 0;
    if (null == bundle) {
      Bundle extras = getIntent().getExtras();
      if (null != extras) {
        _id = extras.getInt(Note.FIELD__ID);
      }
    } else {
      _id = bundle.getInt(Note.FIELD__ID);
    }
    if (0 != _id) {
      mNote = new Note(_id);
      Cursor cursor = mDbManager.query(mNote);
      if (cursor.moveToNext()) {
        String content = cursor.getString(cursor.getColumnIndex(Note.FIELD_CONTENT));
        mEditText.setText(content);
        mEditText.setSelection(content.length());
        Long date = Long.parseLong(cursor.getString(cursor.getColumnIndex(Note.FIELD_PUB_DATE)));
        setTitle(DateSimpleCursorAdapter.GetDate(date, "yyyy?MM?dd?"));
      }
    } else {
      Date date = new Date();
      setTitle(DateSimpleCursorAdapter.GetDate(date.getTime(), "yyyy?MM?dd?"));
    }
  }
  
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.edit, menu);
    return true;
  }
  
  @Override
  protected void onPause() {
    String content = mEditText.getText().toString();
    if (null == mNote) {
      if (null != content && !("".equals(content))) {
        mNote = new Note(content);
        mDbManager.add(mNote);
      }
    } else {
      mNote.setContent(content);
      mDbManager.update(mNote);
    }
    setResult(RESULT_OK);
    super.onPause();
  }

}




Java Source Code List

com.rd.bnote.DBHelper.java
com.rd.bnote.DBManager.java
com.rd.bnote.DateSimpleCursorAdapter.java
com.rd.bnote.EditActivity.java
com.rd.bnote.JSONParser.java
com.rd.bnote.ListActivity.java
com.rd.bnote.Note.java
com.rd.bnote.SearchableActivity.java