Results 1 to 13 of 13
  1. #1
    offline Maybe Modder
    Join Date
    Apr 2008
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Downloads
    0
    Uploads
    0

    Where is 'notes' from the NotePad Application being passed?

    Okay, i'm tinkering around (quite a bit now), with android. What i was doing, was trying to pass the title of the application to a text box and save it. I thought i'd fixed everything but there is still a strange error i'm encountering and i'm not sure how to go about fixing it.

    When i first started, i created a note (while the program hadn't been altered), and the contents were simply 'foo'. Well, i changed everything around, and when i type something into the 'title' textbox such as "Memphis", and hit the back button... on notes_list it shows "Memphis", but when i click on that note AGAIN, it replaces Memphis in my textbox with 'foo'. I'm not sure how, or why it does this... i even renamed the EditText to use @+id:/title so how is it still swapping my data like that? I know this is kind of a vague explanation, but hopefully someone can help me out.

  2. #2
    living_sword's Avatar
    offline Retired Moderator
    Join Date
    Oct 2006
    Location
    Mumbai
    Posts
    7,568
    Thanks
    179
    Thanked 998 Times in 758 Posts
    Downloads
    620
    Uploads
    361
    if you can post some related code, it would be easier to comment.

  3. #3
    offline Maybe Modder
    Join Date
    Apr 2008
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Downloads
    0
    Uploads
    0
    Alright, since i'm not completely sure... i'm going to post my entire noteeditor java file. It's a lot of code, but like i've said, i've gone through this code quite a bit and i can't seem to find where it's pulling the notes themselves from. (Although it may be passed from the NotesList, somewhere, but i couldn't find it there either.

    Here's the NotesEditor.java file:


    [highlight="Java"]

    /*
    * Copyright (C) 2007 Google Inc.
    *
    * Licensed under the Apache License, Version 2.0 (the "License");
    * you may not use this file except in compliance with the License.
    * You may obtain a copy of the License at
    *
    * http://www.apache.org/licenses/LICENSE-2.0
    *
    * Unless required by applicable law or agreed to in writing, software
    * distributed under the License is distributed on an "AS IS" BASIS,
    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    * See the License for the specific language governing permissions and
    * limitations under the License.
    */

    package com.google.android.notepad;

    import com.google.provider.NotePad;

    import android.app.Activity;
    import android.content.ComponentName;
    import android.content.Context;
    import android.content.Intent;
    import android.database.Cursor;
    import android.graphics.Canvas;
    import android.graphics.Paint;
    import android.graphics.Rect;
    import android.net.Uri;
    import android.os.Bundle;
    import android.util.AttributeSet;
    import android.util.Log;
    import android.view.Menu;
    import android.widget.EditText;

    import android.app.TimePickerDialog;
    import android.widget.TimePicker;
    import android.widget.Button;
    import android.view.View;
    import android.widget.CheckBox;

    import java.util.Map;

    /**
    * A generic activity for editing a note in a database. This can be used
    * either to simply view a note (Intent.VIEW_ACTION), view and edit a note
    * (Intent.EDIT_ACTION), or create a new note (Intent.INSERT_ACTION).
    */
    public class NoteEditor extends Activity {

    private static final String TAG = "Notes";

    private static final int NOTE_INDEX = 1;
    private static final int TITLE_INDEX = 2;
    private static final int MODIFIED_INDEX = 3;

    /**
    * Standard projection for the interesting columns of a normal note.
    */
    private static final String[] PROJECTION = new String[] {
    NotePad.Notes._ID, // 0
    NotePad.Notes.NOTE, // 1
    NotePad.Notes.TITLE, // 2
    NotePad.Notes.MODIFIED_DATE // 3
    **;

    // This is our state data that is stored when freezing.
    private static final String ORIGINAL_CONTENT = "origContent";

    // Identifiers for our menu items.
    private static final int REVERT_ID = Menu.FIRST;
    private static final int DISCARD_ID = Menu.FIRST + 1;
    private static final int DELETE_ID = Menu.FIRST + 2;

    // The different distinct states the activity can be run in.
    private static final int STATE_EDIT = 0;
    private static final int STATE_INSERT = 1;

    private int mState;
    private boolean mNoteOnly = false;
    private Uri mURI;
    private Cursor mCursor;
    private EditText mText;
    private String mOriginalContent;

    // date and time
    private int mHourA = 12;
    private int mMinuteA = 30;
    private int mHourB = 1;
    private int mMinuteB = 5;

    // Buttons :-)
    private Button startTime;
    private Button endTime;

    public static class MyEditText extends EditText {
    private Rect mRect;
    private Paint mPaint;

    // we need this constructor for ViewInflate
    public MyEditText(Context context, AttributeSet attrs, Map params) {
    super(context, attrs, params);

    mRect = new Rect();
    mPaint = new Paint();
    mPaint.setStyle(Paint.Style.STROKE);
    mPaint.setColor(0xFF0000FF);
    **

    @Override
    protected void onDraw(Canvas canvas) {
    /*
    int count = getLineCount();
    Rect r = mRect;
    Paint paint = mPaint;

    for (int i = 0; i < count; i++) {
    int baseline = getLineBounds(i, r);

    canvas.drawLine(r.left, baseline + 1, r.right, baseline + 1,
    paint);
    **
    */
    super.onDraw(canvas);
    **
    **

    @Override
    protected void onCreate(Bundle icicle) {
    super.onCreate(icicle);

    final Intent intent = getIntent();
    final String type = intent.resolveType(this);

    // Do some setup based on the action being performed.

    final String action = intent.getAction();
    if (action.equals(Intent.EDIT_ACTION)) {
    // Requested to edit: set that state, and the data being edited.
    mState = STATE_EDIT;
    mURI = intent.getData();

    ** else if (action.equals(Intent.INSERT_ACTION)) {
    // Requested to insert: set that state, and create a new entry
    // in the container.
    mState = STATE_INSERT;
    mURI = getContentResolver().insert(intent.getData(), null);

    // If we were unable to create a new note, then just finish
    // this activity. A RESULT_CANCELED will be sent back to the
    // original activity if they requested a result.
    if (mURI == null) {
    Log.e("Notes", "Failed to insert new note into "
    + getIntent().getData());
    finish();
    return;
    **

    // The new entry was created, so assume all will end well and
    // set the result to be returned.
    setResult(RESULT_OK, mURI.toString());

    ** else {
    // Whoops, unknown action! Bail.
    Log.e(TAG, "Unknown action, exiting");
    finish();
    return;
    **

    // Set the layout for this activity. You can find it
    // in res/layout/hello_activity.xml
    setContentView(R.layout.note_editor);

    // The text view for our note, identified by its ID in the XML file.
    mText = (EditText) findViewById(R.id.title);
    mText.setText(R.id.title);

    // Buttons
    startTime = (Button) findViewById(R.id.startTime);
    endTime = (Button) findViewById(R.id.endTime);

    // Set the text on the buttons
    updateDisplay();

    final CheckBox isAway = (CheckBox) findViewById(R.id.isAway);
    final EditText awayMessage = (EditText) findViewById(R.id.awayMessage);

    awayMessage.setEnabled(false);
    if (isAway.isChecked())
    awayMessage.setEnabled(true);
    else
    awayMessage.setEnabled(false);

    // Select Time :-)
    startTime.setOnClickListener(new View.OnClickListener() {

    public void onClick(View v) {
    new TimePickerDialog(NoteEditor.this,
    mTimeSetListenerA, "Set the time",
    mHourA, mMinuteA, false).show();
    **
    **);

    // Select Time :-)
    endTime.setOnClickListener(new View.OnClickListener() {

    public void onClick(View v) {
    new TimePickerDialog(NoteEditor.this,
    mTimeSetListenerB, "Set the time",
    mHourB, mMinuteB, false).show();
    **
    **);


    // Get the note!
    mCursor = managedQuery(mURI, PROJECTION, null, null);

    // If an instance of this activity had previously stopped, we can
    // get the original text it started with.
    if (icicle != null) {
    mOriginalContent = icicle.getString(NotePad.Notes.TITLE);
    **
    **

    private TimePicker.OnTimeSetListener mTimeSetListenerA = new TimePicker.OnTimeSetListener() {

    public void timeSet(TimePicker view, int hourOfDay, int minute) {
    mHourA = hourOfDay;
    mMinuteA = minute;
    updateDisplay();
    **
    **;

    private TimePicker.OnTimeSetListener mTimeSetListenerB = new TimePicker.OnTimeSetListener() {

    public void timeSet(TimePicker view, int hourOfDay, int minute) {
    mHourB = hourOfDay;
    mMinuteB = minute;
    updateDisplay();
    **
    **;


    @Override
    protected void onResume() {
    super.onResume();

    // If we didn't have any trouble retrieving the data, it is now
    // time to get at the stuff.
    if (mCursor != null) {
    // Make sure we are at the one and only row in the cursor.
    mCursor.first();

    // Modify our overall title depending on the mode we are running in.
    if (mState == STATE_EDIT) {
    setTitle(getText(R.string.title_edit));
    ** else if (mState == STATE_INSERT) {
    setTitle(getText(R.string.title_create));
    **

    // This is a little tricky: we may be resumed after previously being
    // paused/stopped. We want to put the new text in the text view,
    // but leave the user where they were (retain the cursor position
    // etc). This version of setText does that for us.
    String title = mCursor.getString(TITLE_INDEX);
    mText.setTextKeepState(title);

    // If we hadn't previously retrieved the original text, do so
    // now. This allows the user to revert their changes.
    if (mOriginalContent == null) {
    mOriginalContent = title;
    **

    ** else {
    setTitle(getText(R.string.error_title));
    mText.setText(getText(R.string.error_message));
    **
    **

    @Override
    protected void onFreeze(Bundle outState) {
    // Save away the original text, so we still have it if the activity
    // needs to be killed while paused.
    outState.putString(NotePad.Notes.TITLE, mCursor.getString(TITLE_INDEX));
    **

    @Override
    protected void onPause() {
    super.onPause();

    // The user is going somewhere else, so make sure their current
    // changes are safely saved away in the provider. We don't need
    // to do this if only editing.
    if (mCursor != null) {
    String text = mText.getText().toString();
    int length = text.length();

    // If this activity is finished, and there is no text, then we
    // do something a little special: simply delete the note entry.
    // Note that we do this both for editing and inserting... it
    // would be reasonable to only do it when inserting.
    if (isFinishing() && (length == 0) && !mNoteOnly) {
    setResult(RESULT_CANCELED);
    deleteNote();

    // Get out updates into the provider.
    ** else {
    /*
    // This stuff is only done when working with a full-fledged note.
    if (!mNoteOnly) {
    // Bump the modification time to now.
    mCursor.updateLong(MODIFIED_INDEX, System.currentTimeMillis());

    // If we are creating a new note, then we want to also create
    // an initial title for it.
    if (mState == STATE_INSERT) {
    String title = text.substring(0, Math.min(30, length));
    if (length > 30) {
    int lastSpace = title.lastIndexOf(' ');
    if (lastSpace > 0) {
    title = title.substring(0, lastSpace);
    **
    **
    mCursor.updateString(TITLE_INDEX, title);
    **
    **
    */

    // Write our text back into the provider.
    String title = text.substring(0, Math.min(30, length));
    if (length > 30) {
    int lastSpace = title.lastIndexOf(' ');
    if (lastSpace > 0) {
    title = title.substring(0, lastSpace);
    **
    **
    mCursor.updateString(TITLE_INDEX, title);

    // Commit all of our changes to persistent storage. Note the
    // use of managedCommitUpdates() instead of
    // mCursor.commitUpdates() -- this lets Activity take care of
    // requerying the new data if needed.
    managedCommitUpdates(mCursor);
    **
    **
    **

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);

    // Build the menus that are shown when editing.
    if (mState == STATE_EDIT) {
    menu.add(0, REVERT_ID, R.string.menu_revert).setShortcut('0', 'r');
    if (!mNoteOnly) {
    menu.add(0, DELETE_ID, R.string.menu_delete).setShortcut('1', 'd');
    **

    // Build the menus that are shown when inserting.
    ** else {
    menu.add(0, DISCARD_ID, R.string.menu_discard).setShortcut('0', 'd');
    **

    // If we are working on a real honest-to-ghod note, then append to the
    // menu items for any other activities that can do stuff with it
    // as well. This does a query on the system for any activities that
    // implement the ALTERNATIVE_ACTION for our data, adding a menu item
    // for each one that is found.
    if (!mNoteOnly) {
    Intent intent = new Intent(null, getIntent().getData());
    intent.addCategory(Intent.ALTERNATIVE_CATEGORY);
    menu.addIntentOptions(
    Menu.ALTERNATIVE, 0,
    new ComponentName(this, NoteEditor.class), null,
    intent, 0, null);
    **

    return true;
    **

    @Override
    public boolean onOptionsItemSelected(Menu.Item item) {
    // Handle all of the possible menu actions.
    switch (item.getId()) {
    case DELETE_ID:
    deleteNote();
    finish();
    break;
    case DISCARD_ID:
    cancelNote();
    break;
    case REVERT_ID:
    cancelNote();
    break;
    **
    return super.onOptionsItemSelected(item);
    **

    /**
    * Take care of cancelling work on a note. Deletes the note if we
    * had created it, otherwise reverts to the original text.
    */
    private final void cancelNote() {
    if (mCursor != null) {
    if (mState == STATE_EDIT) {
    mCursor.updateString(TITLE_INDEX, mOriginalContent);
    mCursor.commitUpdates();
    mCursor.deactivate();
    mCursor = null;
    ** else if (mState == STATE_INSERT) {
    deleteNote();
    **
    **
    setResult(RESULT_CANCELED);
    finish();
    **

    /**
    * Take care of deleting a note. Simply deletes the entry.
    */
    private final void deleteNote() {
    if (mCursor != null) {
    mText.setText("");
    mCursor.deleteRow();
    mCursor.deactivate();
    mCursor = null;
    **
    **

    private final void updateDisplay(){
    boolean hourFormatA, hourFormatB;
    String outputStringA, outputStringB;

    if(mHourA < 13){ // Android uses 1-24 not 0-23
    outputStringA = mHourA + ":";
    hourFormatA = true; // Meaning it's AM
    **
    else{
    outputStringA = mHourA - 12 + ":";
    hourFormatA = false; // Meaning it's PM
    **

    if(mHourB < 13){
    outputStringB = mHourB + ":";
    hourFormatB = true;
    **
    else{
    outputStringB = mHourB - 12 + ":";
    hourFormatB = false;
    **

    if (mMinuteA < 10)
    outputStringA += "0" + mMinuteA;
    else
    outputStringA += mMinuteA;

    if (mMinuteB < 10)
    outputStringB += "0" + mMinuteB;
    else
    outputStringB += mMinuteB;

    if (hourFormatA == false)
    outputStringA += " PM";
    else
    outputStringA += " AM";

    if (hourFormatB == false)
    outputStringB += " PM";
    else
    outputStringB += " AM";

    startTime.setText(outputStringA);
    endTime.setText(outputStringB);
    **
    **
    [/highlight]

  4. #4
    living_sword's Avatar
    offline Retired Moderator
    Join Date
    Oct 2006
    Location
    Mumbai
    Posts
    7,568
    Thanks
    179
    Thanked 998 Times in 758 Posts
    Downloads
    620
    Uploads
    361
    try replacing,

    [highlight="Java"]

    mText = (EditText) findViewById(R.id.title);
    mText.setText(R.id.title);
    [/highlight]

    with this,

    [highlight="Java"]
    mText = (EditText) findViewById(R.id.note);

    [/highlight]

  5. #5
    offline Maybe Modder
    Join Date
    Apr 2008
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Downloads
    0
    Uploads
    0
    I may have misstated my intentions... sorry.

    What i'm trying it do is have the textbox retrieve the title and NOTE the information saved from the note. It saves the 'title' that i enter into it... basically this'll happen:

    1: Note title: 'foo'
    2: I open the program, and it returns what's saved as a 'note' (which is just 'foo')
    3: I change the EditText, so it says something like "Test1"
    4: When i hit back, the NotesList screen will display Test1 as the title
    5: When i click BACK onto test1 it replaces the EditText text with 'foo' again (since the value of note wasn't changed by that box... only title was, so that data is still put there... but i don't want it to be... it want it to simply manipulate the title only... the value of the 'note' itself should never change, or be displayed in that text box, but it is...)

  6. #6
    living_sword's Avatar
    offline Retired Moderator
    Join Date
    Oct 2006
    Location
    Mumbai
    Posts
    7,568
    Thanks
    179
    Thanked 998 Times in 758 Posts
    Downloads
    620
    Uploads
    361
    so you want the text inside note and title of the note to be the same ? if so, then remove line 176 from your code in previous post. rest of the code looks fine.

  7. #7
    offline Maybe Modder
    Join Date
    Apr 2008
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Downloads
    0
    Uploads
    0
    I just want the EditText to display the title, so the title can be directly edited that way. I really don't care about the 'note' portion of the database at all, and will be removing it at some point.

    When i comment out line 176, the textbox is blank when the program loads.

  8. #8
    living_sword's Avatar
    offline Retired Moderator
    Join Date
    Oct 2006
    Location
    Mumbai
    Posts
    7,568
    Thanks
    179
    Thanked 998 Times in 758 Posts
    Downloads
    620
    Uploads
    361
    replace your onPause() method with this,


    [highlight="Java"]
    @Override
    protected void onPause()
    {
    super.onPause();

    // The user is going somewhere else, so make sure their current
    // changes are safely saved away in the provider. We don't need
    // to do this if only editing.
    if (mCursor != null)
    {
    String text = mText.getText().toString();
    int length = text.length();

    // If this activity is finished, and there is no text, then we
    // do something a little special: simply delete the note entry.
    // Note that we do this both for editing and inserting... it
    // would be reasonable to only do it when inserting.

    if (isFinishing() && (length == 0) && !mNoteOnly)
    {
    setResult(RESULT_CANCELED);
    deleteNote();

    // Get out updates into the provider.
    ** else
    {

    // Write our text back into the provider.
    mCursor.updateString(TITLE_INDEX, text);

    // Commit all of our changes to persistent storage. Note the
    // use of managedCommitUpdates() instead of
    // mCursor.commitUpdates() -- this lets Activity take care of
    // requerying the new data if needed.

    managedCommitUpdates(mCursor);

    **
    **
    **



    [/highlight]

  9. #9
    offline Maybe Modder
    Join Date
    Apr 2008
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Downloads
    0
    Uploads
    0
    No go... it still goes from displaying the title to 'foo'... i'm not sure where that data is being passed to the activity from.

    It's like...

    [UserTitle] ---- NotesList
    ['foo'] ---- Default's to this everytime you open the 'note' (i think it's displaying the value of the note itself in the EditText, rather than the title)
    [Replace 'foo' with 'Hello'] --- And then hit back (to go to the noteslist)
    ['Hello']

    If you DO NOT replace 'foo', it will change the title under noteslist to 'foo'

  10. #10
    living_sword's Avatar
    offline Retired Moderator
    Join Date
    Oct 2006
    Location
    Mumbai
    Posts
    7,568
    Thanks
    179
    Thanked 998 Times in 758 Posts
    Downloads
    620
    Uploads
    361
    attach the complete source code . i'll take a look at it.

  11. #11
    offline Maybe Modder
    Join Date
    Apr 2008
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Downloads
    0
    Uploads
    0
    h t t p://one.xthost.info/endieko/JavaFinal.zip

    thanks for all of your help so far.

  12. #12
    living_sword's Avatar
    offline Retired Moderator
    Join Date
    Oct 2006
    Location
    Mumbai
    Posts
    7,568
    Thanks
    179
    Thanked 998 Times in 758 Posts
    Downloads
    620
    Uploads
    361
    the problem i found in your code is that, once after creating a profile, when i click on the profile name in the list, the profile gets deleted. I haven't changed your code, i've modified the default Notepad app to show title in the editbox when list item is clicked. First try running the attached app without changing anything, if it solves your problem, u can build your code around it.
    Attached Files Attached Files

  13. #13
    offline Maybe Modder
    Join Date
    Apr 2008
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Downloads
    0
    Uploads
    0
    Worked well. I caught my mistake. Thank you very much.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •