package me.jaxbot.wear.leafstatus;

import android.content.Context;
import android.content.SharedPreferences;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.SeekBar;
import android.widget.TextView;
import android.widget.Toast;

public class MyActivity extends ActionBarActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my);

        final Context context = this;

        final Button button = (Button) findViewById(R.id.button);
        button.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                SharedPreferences settings = getSharedPreferences("U", 0);
                SharedPreferences.Editor editor = settings.edit();

                String username = ((EditText) findViewById(R.id.txtUsername)).getText().toString();
                String password = ((EditText) findViewById(R.id.txtPassword)).getText().toString();
                int interval = ((SeekBar) findViewById(R.id.seekBar)).getProgress();

                editor.putString("username", username);
                editor.putString("password", password);
                editor.putInt("interval", interval);

                editor.commit();

                AlarmSetter.setAlarm(context);

                button.setEnabled(false);

                showToast("Saved, updating vehicle status...");
            }
        });

        SharedPreferences settings = getSharedPreferences("U", 0);

        int interval = settings.getInt("interval", 30);
        ((EditText) findViewById(R.id.txtUsername)).setText(settings.getString("username", ""));
        ((EditText) findViewById(R.id.txtPassword)).setText(settings.getString("password", ""));
        ((SeekBar) findViewById(R.id.seekBar)).setProgress(interval);
        setProgressText(interval);

        ((SeekBar) findViewById(R.id.seekBar)).setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
                setProgressText(i);
                ((Button) findViewById(R.id.button)).setEnabled(true);
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {

            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {

            }
        });
    }

    private void setProgressText(int interval) {
        ((TextView) findViewById(R.id.txtMinutes)).setText("Update every " + (interval + 15) + " minutes");
    }

    void showToast(String text)
    {
        int duration = Toast.LENGTH_SHORT;

        Toast toast = Toast.makeText(this, text, duration);
        toast.show();
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        InputMethodManager imm = (InputMethodManager)getSystemService(Context.
            INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
        return true;
    }
}


@@ -178,16 +178,109 @@
 Bundle;%0A
+import android.text.Editable;%0Aimport android.text.TextWatcher;%0Aimport android.view.KeyEvent;%0A
 import a
@@ -1908,38 +1908,218 @@
     
-((EditText) findViewById(R.id.
+EditText txtUsername = (EditText)findViewById(R.id.txtUsername);%0A        EditText txtPassword = (EditText)findViewById(R.id.txtPassword);%0A        SeekBar seekbar = (SeekBar)findViewById(R.id.seekBar);%0A%0A        
 txtU
@@ -2125,18 +2125,16 @@
 Username
-))
 .setText
@@ -2183,38 +2183,8 @@
     
-((EditText) findViewById(R.id.
 txtP
@@ -2190,18 +2190,16 @@
 Password
-))
 .setText
@@ -2248,46 +2248,15 @@
     
-((SeekBar) findViewById(R.id.
 seek
-B
+b
 ar
-))
 .set
@@ -2323,46 +2323,602 @@
     
-((SeekBar) findViewById(R.id.seekBar))
+TextWatcher watcher = new TextWatcher() %7B%0A            @Override%0A            public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) %7B%0A%0A            %7D%0A%0A            @Override%0A            public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) %7B%0A%0A            %7D%0A%0A            @Override%0A            public void afterTextChanged(Editable editable) %7B%0A                findViewById(R.id.button).setEnabled(true);%0A            %7D%0A        %7D;%0A%0A        txtUsername.addTextChangedListener(watcher);%0A        txtPassword.addTextChangedListener(watcher);%0A%0A        seekbar
 .set
@@ -3137,18 +3137,8 @@
     
- ((Button)
  fin
@@ -3159,17 +3159,16 @@
 .button)
-)
 .setEnab

Make it possible to save by editing username/password