package com.simplenote.android.ui;

import java.util.HashMap;

import android.app.Activity;
import android.graphics.PixelFormat;
import android.os.Bundle;
import android.text.Editable;
import android.text.method.PasswordTransformationMethod;
import android.util.Log;
import android.widget.EditText;

import com.simplenote.android.Constants;
import com.simplenote.android.Preferences;
import com.simplenote.android.R;
import com.simplenote.android.net.Api.Response;
import com.simplenote.android.net.HttpCallback;
import com.simplenote.android.view.TextAsLabelFocusChangeListener;
import com.simplenote.android.widget.LoginActionListener;

/**
 * Main Activity for SimpleNote application
 * @author bryanjswift
 */
public class SimpleNoteSplash extends Activity {
	private static final String LOGGING_TAG = Constants.TAG + "SimpleNoteSplash";
	/**
	 * @see android.app.Activity#onCreate(android.os.Bundle)
	 */
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		HashMap<String,String> credentials = Preferences.getLoginPreferences(this);
		getWindow().setFormat(PixelFormat.RGBA_8888);
		setContentView(R.layout.splash);
		if (credentials.containsKey(Preferences.EMAIL) &&
				(credentials.containsKey(Preferences.TOKEN) || credentials.containsKey(Preferences.PASSWORD))) {
			// valid token stored
			Log.d(LOGGING_TAG, "Auth information stored, going to list");
			FireIntent.SimpleNoteList(this);
			this.finish();
		} else {
			// set up events for the splash screen
			Log.d(LOGGING_TAG, "Need to get credentials, setup events for the splash screen");
			setupSplashFields();
		}
	}
	/**
	 * Attach focus event listeners to the EditTexts in the layout
	 */
	private void setupSplashFields() {
		final EditText email = (EditText) findViewById(R.id.splash_email);
		final EditText password = (EditText) findViewById(R.id.splash_password);
		final TextAsLabelFocusChangeListener passwordFocusChangeListener =
			new TextAsLabelFocusChangeListener(password, getString(R.string.password)) {
				/**
				 * @see com.simplenote.android.view.TextAsLabelFocusChangeListener#onFocus()
				 */
				@Override
				protected void onFocus() {
					super.onFocus();
					field.setTransformationMethod(new PasswordTransformationMethod());
				}
				/**
				 * @see com.simplenote.android.view.TextAsLabelFocusChangeListener#onBlur()
				 */
				@Override
				protected void onBlur() {
					super.onBlur();
					Editable value = field.getText();
					if (value.toString().equals(initial)) {
						field.setTransformationMethod(null);
					}
				}
			};
		email.setOnFocusChangeListener(new TextAsLabelFocusChangeListener(email, getString(R.string.email)));
		password.setOnFocusChangeListener(passwordFocusChangeListener);
		password.setOnEditorActionListener(new LoginActionListener(this, email, password, new HttpCallback() {
			/**
			 * @see com.simplenote.android.net.HttpCallback#on200(com.simplenote.android.net.Api.Response)
			 */
			@Override
			public void on200(Response response) {
				FireIntent.SimpleNoteList(SimpleNoteSplash.this);
				SimpleNoteSplash.this.finish();
			}
		}));
	}
}

@@ -141,104 +141,51 @@
 oid.
-os.Bundle;%0Aimport android.text.Editable;%0Aimport android.text.method.PasswordTransformationMethod
+graphics.Typeface;%0Aimport android.os.Bundle
 ;%0Aim
@@ -238,16 +238,48 @@
 ditText;
+%0Aimport android.widget.TextView;
 %0A%0Aimport
@@ -489,75 +489,8 @@
 ck;%0A
-import com.simplenote.android.view.TextAsLabelFocusChangeListener;%0A
 impo
@@ -1079,16 +1079,187 @@
 plash);%0A
+%09%09Typeface helveticaBold = Typeface.createFromAsset(getAssets(), %22fonts/HelveticaNeueBold.ttf%22);%0A%09%09((TextView) findViewById(R.id.splashLabel)).setTypeface(helveticaBold);%0A
 %09%09if (cr
@@ -1896,16 +1896,16 @@
 email);%0A
+
 %09%09final 
@@ -1975,876 +1975,8 @@
 d);%0A
-%09%09final TextAsLabelFocusChangeListener passwordFocusChangeListener =%0A%09%09%09new TextAsLabelFocusChangeListener(password, getString(R.string.password)) %7B%0A%09%09%09%09/**%0A%09%09%09%09 * @see com.simplenote.android.view.TextAsLabelFocusChangeListener#onFocus()%0A%09%09%09%09 */%0A%09%09%09%09@Override%0A%09%09%09%09protected void onFocus() %7B%0A%09%09%09%09%09super.onFocus();%0A%09%09%09%09%09field.setTransformationMethod(new PasswordTransformationMethod());%0A%09%09%09%09%7D%0A%09%09%09%09/**%0A%09%09%09%09 * @see com.simplenote.android.view.TextAsLabelFocusChangeListener#onBlur()%0A%09%09%09%09 */%0A%09%09%09%09@Override%0A%09%09%09%09protected void onBlur() %7B%0A%09%09%09%09%09super.onBlur();%0A%09%09%09%09%09Editable value = field.getText();%0A%09%09%09%09%09if (value.toString().equals(initial)) %7B%0A%09%09%09%09%09%09field.setTransformationMethod(null);%0A%09%09%09%09%09%7D%0A%09%09%09%09%7D%0A%09%09%09%7D;%0A%09%09email.setOnFocusChangeListener(new TextAsLabelFocusChangeListener(email, getString(R.string.email)));%0A%09%09password.setOnFocusChangeListener(passwordFocusChangeListener);%0A
 %09%09pa

Set the splash header to use Bold Helvetica Neue