Home | History | Annotate | Download | only in notepad3
      1 /*
      2  * Copyright (C) 2008 Google Inc.
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package com.android.demo.notepad3;
     18 
     19 import android.app.Activity;
     20 import android.content.Intent;
     21 import android.os.Bundle;
     22 import android.view.View;
     23 import android.widget.Button;
     24 import android.widget.EditText;
     25 
     26 public class NoteEdit extends Activity {
     27 
     28     private EditText mTitleText;
     29     private EditText mBodyText;
     30     private Long mRowId;
     31 
     32     @Override
     33     protected void onCreate(Bundle savedInstanceState) {
     34         super.onCreate(savedInstanceState);
     35         setContentView(R.layout.note_edit);
     36         setTitle(R.string.edit_note);
     37 
     38         mTitleText = (EditText) findViewById(R.id.title);
     39         mBodyText = (EditText) findViewById(R.id.body);
     40 
     41         Button confirmButton = (Button) findViewById(R.id.confirm);
     42 
     43         mRowId = null;
     44         Bundle extras = getIntent().getExtras();
     45         if (extras != null) {
     46             String title = extras.getString(NotesDbAdapter.KEY_TITLE);
     47             String body = extras.getString(NotesDbAdapter.KEY_BODY);
     48             mRowId = extras.getLong(NotesDbAdapter.KEY_ROWID);
     49 
     50             if (title != null) {
     51                 mTitleText.setText(title);
     52             }
     53             if (body != null) {
     54                 mBodyText.setText(body);
     55             }
     56         }
     57 
     58         confirmButton.setOnClickListener(new View.OnClickListener() {
     59 
     60             public void onClick(View view) {
     61                 Bundle bundle = new Bundle();
     62 
     63                 bundle.putString(NotesDbAdapter.KEY_TITLE, mTitleText.getText().toString());
     64                 bundle.putString(NotesDbAdapter.KEY_BODY, mBodyText.getText().toString());
     65                 if (mRowId != null) {
     66                     bundle.putLong(NotesDbAdapter.KEY_ROWID, mRowId);
     67                 }
     68 
     69                 Intent mIntent = new Intent();
     70                 mIntent.putExtras(bundle);
     71                 setResult(RESULT_OK, mIntent);
     72                 finish();
     73             }
     74 
     75         });
     76     }
     77 }
     78