package com.example.sprout.accounts; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.Toast; import com.example.sprout.R; import com.example.sprout.Sprout; import com.example.sprout.battles.BattleActivity; import com.example.sprout.rooms.RoomListActivity; import net.arnx.jsonic.JSON; import framework.network.CallBack; public class RegistrationActivity extends Activity { private EditText userName; private AccountsConnection connection; private Sprout sprout; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_registration); sprout = (Sprout) getApplication(); userName = (EditText) findViewById(R.id.Registration_editText1); if (sprout.getUserId() != -1) { Intent intent = new Intent(RegistrationActivity.this, RoomListActivity.class); startActivity(intent); finish(); } /*バトルのテスト用ボタン*/ Button battleButton = (Button) findViewById(R.id.button1); battleButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { BattleActivity.BATTLE_TEST_MODE = true; Intent intent = new Intent(RegistrationActivity.this, BattleActivity.class); startActivity(intent); finish(); } }); ////ここまで Button okButton = (Button) findViewById(R.id.Registration_button1); okButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { // 名前の入力確認 if (userName.getText().toString().isEmpty()) { Toast.makeText(getBaseContext(), "名前を入れてください", Toast.LENGTH_SHORT).show(); } else { connection = sprout.getAccountsConnection(); connection.setCallBack(new CallBack() { @Override public void onResponse(String response) { Account ac = JSON.decode(response, Account.class); sprout.setUserId(ac.getUserID()); Intent intent = new Intent(RegistrationActivity.this, RoomListActivity.class); startActivity(intent); finish(); } }); connection.addFormParam("userName", userName.getText().toString()); connection.doPost(); } } }); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.registration, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } }