<commit_before>package com.bryanjswift.simplenote.ui;

import java.util.Date;

import android.app.Activity;
import android.content.Intent;
import android.graphics.PixelFormat;
import android.os.Bundle;
import android.provider.BaseColumns;
import android.util.Log;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.TextView;

import com.bryanjswift.simplenote.Constants;
import com.bryanjswift.simplenote.R;
import com.bryanjswift.simplenote.model.Note;
import com.bryanjswift.simplenote.persistence.SimpleNoteDao;
import com.bryanjswift.simplenote.widget.NotesAdapter;

/**
 * Handle the note editing
 * @author bryanjswift
 */
public class SimpleNoteEdit extends Activity {
	private static final String LOGGING_TAG = Constants.TAG + "SimpleNoteEdit";
	// Final variables
	private final SimpleNoteDao dao;
	// Mutable instance variables
	private long mNoteId = 0L;
	private String mOriginalBody = "";
	private boolean mActivityStateSaved = false;
	private boolean mNoteSaved = false;
	/**
	 * Default constructor to setup final fields
	 */
	public SimpleNoteEdit() {
		this.dao = new SimpleNoteDao(this);
	}
	/**
	 * @see android.app.Activity#onCreate(android.os.Bundle)
	 */
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		Log.d(LOGGING_TAG, "Running creating new SimpleNoteEdit Activity");
		getWindow().setFormat(PixelFormat.RGBA_8888);
		setContentView(R.layout.edit_note);
		if (savedInstanceState == null) {
			Bundle extras = getIntent().getExtras();
			mNoteId = extras.getLong(BaseColumns._ID);
			mOriginalBody = extras.getString(SimpleNoteDao.BODY);
		} else {
			mNoteId = savedInstanceState.getLong(BaseColumns._ID);
		}
		final Note dbNote = dao.retrieve(mNoteId);
		if (savedInstanceState == null && mOriginalBody == null) {
			mOriginalBody = dbNote.getBody();
		} else if (savedInstanceState != null && mOriginalBody == null) {
			mOriginalBody = savedInstanceState.getString(SimpleNoteDao.BODY);
		}
		final String title;
		if (dbNote != null) {
			title = dbNote.getTitle();
			((EditText) findViewById(R.id.note_body)).setText(dbNote.getBody());
		} else {
			title = getString(R.string.new_note);
		}
		((TextView) findViewById(R.id.note_title)).setText(NotesAdapter.ellipsizeTitle(this, title));
        ImageButton trash = (ImageButton) findViewById(R.id.note_delete);
        trash.setOnClickListener(new View.OnClickListener() {
            /**
             * Perform deletion of the note
             * @param view being clicked
             */
            public void onClick(View view) {
                Log.d(LOGGING_TAG, "OnClick firing for trash icon");
                delete();
            }
        });
        trash.setOnTouchListener(new View.OnTouchListener() {
            /**
             * Handle special events when touching the trash button
             * @param view being touched
             * @param motionEvent information about touch event
             * @return whether or not the event was handled (it wasn't)
             */
            public boolean onTouch(View view, MotionEvent motionEvent) {
                Log.d(LOGGING_TAG, "OnTouch firing for trash icon");
                View titleRow = findViewById(R.id.note_title_row);
                if (motionEvent.getAction() == MotionEvent.ACTION_UP) {
                    titleRow.setPressed(false);
                } else {
                    titleRow.setPressed(true);
                }
                return false;
            }
        });
	}
	/**
	 * @see android.app.Activity#onResume()
	 */
	@Override
	protected void onResume() {
		super.onResume();
		Log.d(LOGGING_TAG, "Resuming SimpleNoteEdit");
		mActivityStateSaved = false;
	}
	/**
	 * Called before on pause, save data here so SimpleEditNote can be relaunched
	 * @see android.app.Activity#onSaveInstanceState(android.os.Bundle)
	 */
	@Override
	protected void onSaveInstanceState(Bundle outState) {
		super.onSaveInstanceState(outState);
		Log.d(LOGGING_TAG, "Saving instance state");
		mActivityStateSaved = true;
		// Make sure the note id is set in the saved state
		outState.putLong(BaseColumns._ID, mNoteId);
		outState.putString(SimpleNoteDao.BODY, mOriginalBody);<commit_msg>Use switch in onTouch method<commit_after>package com.bryanjswift.simplenote.ui;

import java.util.Date;

import android.app.Activity;
import android.content.Intent;
import android.graphics.PixelFormat;
import android.os.Bundle;
import android.provider.BaseColumns;
import android.util.Log;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.TextView;

import com.bryanjswift.simplenote.Constants;
import com.bryanjswift.simplenote.R;
import com.bryanjswift.simplenote.model.Note;
import com.bryanjswift.simplenote.persistence.SimpleNoteDao;
import com.bryanjswift.simplenote.widget.NotesAdapter;

/**
 * Handle the note editing
 * @author bryanjswift
 */
public class SimpleNoteEdit extends Activity {
	private static final String LOGGING_TAG = Constants.TAG + "SimpleNoteEdit";
	// Final variables
	private final SimpleNoteDao dao;
	// Mutable instance variables
	private long mNoteId = 0L;
	private String mOriginalBody = "";
	private boolean mActivityStateSaved = false;
	private boolean mNoteSaved = false;
	/**
	 * Default constructor to setup final fields
	 */
	public SimpleNoteEdit() {
		this.dao = new SimpleNoteDao(this);
	}
	/**
	 * @see android.app.Activity#onCreate(android.os.Bundle)
	 */
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		Log.d(LOGGING_TAG, "Running creating new SimpleNoteEdit Activity");
		getWindow().setFormat(PixelFormat.RGBA_8888);
		setContentView(R.layout.edit_note);
		if (savedInstanceState == null) {
			Bundle extras = getIntent().getExtras();
			mNoteId = extras.getLong(BaseColumns._ID);
			mOriginalBody = extras.getString(SimpleNoteDao.BODY);
		} else {
			mNoteId = savedInstanceState.getLong(BaseColumns._ID);
		}
		final Note dbNote = dao.retrieve(mNoteId);
		if (savedInstanceState == null && mOriginalBody == null) {
			mOriginalBody = dbNote.getBody();
		} else if (savedInstanceState != null && mOriginalBody == null) {
			mOriginalBody = savedInstanceState.getString(SimpleNoteDao.BODY);
		}
		final String title;
		if (dbNote != null) {
			title = dbNote.getTitle();
			((EditText) findViewById(R.id.note_body)).setText(dbNote.getBody());
		} else {
			title = getString(R.string.new_note);
		}
		((TextView) findViewById(R.id.note_title)).setText(NotesAdapter.ellipsizeTitle(this, title));
        ImageButton trash = (ImageButton) findViewById(R.id.note_delete);
        trash.setOnClickListener(new View.OnClickListener() {
            /**
             * Perform deletion of the note
             * @param view being clicked
             */
            public void onClick(View view) {
                Log.d(LOGGING_TAG, "OnClick firing for trash icon");
                delete();
            }
        });
        trash.setOnTouchListener(new View.OnTouchListener() {
            /**
             * Handle special events when touching the trash button
             * @param view being touched
             * @param motionEvent information about touch event
             * @return whether or not the event was handled (it wasn't)
             */
            public boolean onTouch(View view, MotionEvent motionEvent) {
                Log.d(LOGGING_TAG, "OnTouch firing for trash icon");
                View titleRow = findViewById(R.id.note_title_row);
                switch (motionEvent.getAction()) {
                    case MotionEvent.ACTION_UP:
                    case MotionEvent.ACTION_OUTSIDE:
                    case MotionEvent.ACTION_CANCEL:
                        titleRow.setPressed(false);
                        break;
                    case MotionEvent.ACTION_DOWN:
                        titleRow.setPressed(true);
                        break;
                }
                return false;
            }
        });
	}
	/**
	 * @see android.app.Activity#onResume()
	 */
	@Override
	protected void onResume() {
		super.onResume();
		Log.d(LOGGING_TAG, "Resuming SimpleNoteEdit");
		mActivityStateSaved = false;
	}
	/**
	 * Called before on pause, save data here so SimpleEditNote can be relaunched
	 * @see android.app.Activity#onSaveInstanceState(android.os.Bundle)
	 */
	@Override
	protected void onSaveInstanceState(Bundle outState) {
		super.onSaveInstanceState(outState);
		Log.d(LOGGING_TAG, "Saving instance state");
		mActivityStateSaved = true;
		// Make sure the note id is set in the saved state
		outState.putLong(BaseColumns._ID, mNoteId);
		outState.putString(SimpleNoteDao.BODY, mOriginalBody);
{'fraction_non_alphanumeric': 0.1025049439683586, 'fraction_numerical': 0.001098659635245001, 'mean_word_length': 3.1547238703788225, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '411637', 'n_tokens_mistral': 2815, 'n_tokens_neox': 2600, 'n_words': 597}