Android Open Source - SpeechWriter Edit Text Activity






From Project

Back to project page SpeechWriter.

License

The source code is released under:

MIT License

If you think the Android project SpeechWriter 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 edu.psu.rcy5017.speechwriter.activity;
//  w w w. j  a  va  2  s. c  om
import edu.psu.rcy5017.speechwriter.R;
import edu.psu.rcy5017.speechwriter.constant.DefaultValues;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.MenuItem;
import android.view.inputmethod.EditorInfo;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.TextView.OnEditorActionListener;

/**
 * An Activity used to edit the text of some database column which is presented in a ListActivity.
 * Ex: A speech title, or a note's text.
 * @author Ryan Yosua
 *
 */
public class EditTextActivity extends Activity {
    
    private static final String TAG = "EditTextActivity";
    
    private int position;
    private long id;
    private String retrievedText;
    
    private EditText textField;
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.edit_text_activity);
        getActionBar().setDisplayHomeAsUpEnabled(true);

        textField = (EditText) findViewById(R.id.edit_text_speech_title);
        
        // Create a speech object from data passed from list activity.
        final Intent intent = this.getIntent();
        
        // Get the variables passed as extras.
        position = intent.getIntExtra("position", DefaultValues.DEFAULT_INT_VALUE);
        id = intent.getLongExtra("id", DefaultValues.DEFAULT_LONG_VALUE);
        retrievedText = intent.getStringExtra("text");
        
        // Populate the text field with the speech data.
        textField.setText(retrievedText);
        textField.setSelection(retrievedText.length());
        
        // Add the done button listener.
        textField.setOnEditorActionListener(new OnEditorActionListener() {
            @Override
            public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                if ((event != null && (event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) || 
                        (actionId == EditorInfo.IME_ACTION_DONE)) {
                    saveAndFinish(textField, position);
                }    
                return false;
            }
        });
    }
    
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        if (item.getItemId() == android.R.id.home) {
            saveAndFinish(textField, position);
        }
        
        return false;
    }
    
    @Override
    public void onBackPressed() {
        saveAndFinish(textField, position);
    }
    
    private void saveAndFinish(EditText textField, int position) {
        final String editedText = textField.getText().toString();
        
        final Intent intent = new Intent();
        intent.putExtra("position", position);
        intent.putExtra("id", id);
        intent.putExtra("text", editedText);
                
        setResult(RESULT_OK, intent);
        finish();
    }
    
}




Java Source Code List

com.ericharlow.DragNDrop.DragListener.java
com.ericharlow.DragNDrop.DragNDropAdapter.java
com.ericharlow.DragNDrop.DragNDropListView.java
com.ericharlow.DragNDrop.DropListener.java
com.ericharlow.DragNDrop.RemoveListener.java
edu.psu.rcy5017.speechwriter.DatabaseHelper.java
edu.psu.rcy5017.speechwriter.activity.EditTextActivity.java
edu.psu.rcy5017.speechwriter.activity.MainActivity.java
edu.psu.rcy5017.speechwriter.activity.NoteCardListActivity.java
edu.psu.rcy5017.speechwriter.activity.NoteListActivity.java
edu.psu.rcy5017.speechwriter.activity.OptionsActivity.java
edu.psu.rcy5017.speechwriter.activity.SpeechListActivity.java
edu.psu.rcy5017.speechwriter.activity.SpeechRecordingListActivity.java
edu.psu.rcy5017.speechwriter.activity.SplashScreenActivity.java
edu.psu.rcy5017.speechwriter.adapter.TabsPagerAdapter.java
edu.psu.rcy5017.speechwriter.constant.DefaultValues.java
edu.psu.rcy5017.speechwriter.constant.MiscConstants.java
edu.psu.rcy5017.speechwriter.constant.RequestCodes.java
edu.psu.rcy5017.speechwriter.controller.AudioCntl.java
edu.psu.rcy5017.speechwriter.controller.OptionsCntl.java
edu.psu.rcy5017.speechwriter.datasource.DataSource.java
edu.psu.rcy5017.speechwriter.datasource.NoteCardDataSource.java
edu.psu.rcy5017.speechwriter.datasource.NoteDataSource.java
edu.psu.rcy5017.speechwriter.datasource.SpeechDataSource.java
edu.psu.rcy5017.speechwriter.datasource.SpeechRecordingDataSource.java
edu.psu.rcy5017.speechwriter.fragment.NoteCardFragement.java
edu.psu.rcy5017.speechwriter.listener.ChangeFontSizeListener.java
edu.psu.rcy5017.speechwriter.listener.DragListenerImpl.java
edu.psu.rcy5017.speechwriter.listener.DropListenerImpl.java
edu.psu.rcy5017.speechwriter.listener.DropReorderListener.java
edu.psu.rcy5017.speechwriter.listener.RemoveListenerImpl.java
edu.psu.rcy5017.speechwriter.model.NoteCard.java
edu.psu.rcy5017.speechwriter.model.Note.java
edu.psu.rcy5017.speechwriter.model.SpeechRecording.java
edu.psu.rcy5017.speechwriter.model.Speech.java
edu.psu.rcy5017.speechwriter.task.ChangeNoteTextTask.java
edu.psu.rcy5017.speechwriter.task.CreateNoteCardTask.java
edu.psu.rcy5017.speechwriter.task.CreateNoteTask.java
edu.psu.rcy5017.speechwriter.task.CreateSpeechRecordingTask.java
edu.psu.rcy5017.speechwriter.task.CreateSpeechTask.java
edu.psu.rcy5017.speechwriter.task.DeleteTask.java
edu.psu.rcy5017.speechwriter.task.GetAllTask.java
edu.psu.rcy5017.speechwriter.task.NoteCardTask.java
edu.psu.rcy5017.speechwriter.task.NoteTask.java
edu.psu.rcy5017.speechwriter.task.RenameNoteCardTask.java
edu.psu.rcy5017.speechwriter.task.RenameSpeechRecordingTask.java
edu.psu.rcy5017.speechwriter.task.RenameSpeechTask.java
edu.psu.rcy5017.speechwriter.task.SpeechRecordingTask.java
edu.psu.rcy5017.speechwriter.task.SpeechTask.java
edu.psu.rcy5017.speechwriter.task.UpdateOrderTask.java