package net.micode.notes.ui;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

import net.micode.notes.R;
import net.micode.notes.gtask.remote.Network;

//editText.getText().toString();
public class Addaccount extends Activity {

    final int ADDACOUNTNUMBER = 2;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_addaccount);
        findViewById(R.id.alreadyMember).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(Addaccount.this, LoginActivity.class);
                startActivity(intent);
                finish();
            }
        });
        findViewById(R.id.create).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                EditText editText1 =(EditText) findViewById (R.id.userName);
                String outputuser = editText1.getText().toString();
                EditText editText2 =(EditText) findViewById (R.id.Password);
                String outputkey = editText2.getText().toString();
                Network add = new Network(ADDACOUNTNUMBER,outputuser,outputkey);
                try {
                    Thread thread1 = new Thread(add,"add");
                    thread1.start();
                    thread1.join();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                String returnvalue = add.getInTemp();

                if(returnvalue.equals("success")){
                    showMessage("注册成功");
                    Intent intent = new Intent(Addaccount.this, LoginActivity.class);
                    startActivity(intent);
                    finish();
                }
                else{
                    showMessage("timeout");
                }


            }
        });
    }
    private void showMessage(final String msg) {
        if (TextUtils.isEmpty(msg))
            return;

        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                Toast.makeText(getBaseContext(), msg, Toast.LENGTH_SHORT).show();//暂时提示
            }
        });
    }

}