package com.example.sprout.rooms; 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.TextView; import android.widget.Toast; import com.example.sprout.R; import com.example.sprout.R.id; import com.example.sprout.R.layout; import com.example.sprout.Sprout; import net.arnx.jsonic.JSON; import framework.network.CallBack; public class RoomInputKeyActivity extends Activity { private EditText key; private boolean keycheck; private RoomsConnection connection; private Sprout sprout; //最初に処理 @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(layout.activity_room_input_key); sprout = (Sprout) getApplication(); key = (EditText) findViewById(id.roomkeyinput_edittext1); String RoomName = sprout.getRoomName(); TextView textView = (TextView) findViewById(id.roomkeyinput_textView4); textView.setText(RoomName); //戻るボタン back_button(); //入室ボタン enter_button(); } //戻るボタン public void back_button() { Button backButton = (Button) findViewById(id.roomkeyinput_button1); backButton.setOnClickListener(new View.OnClickListener() { //押したらルーム一覧画面へ戻る public void onClick(View v) { Intent intent = new Intent(RoomInputKeyActivity.this, RoomListActivity.class); startActivity(intent); } }); } //入室ボタン public void enter_button() { Button createButton = (Button) findViewById(id.roomkeyinput_button2); createButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { connection = sprout.getRoomsConnection(); connection.setCallBack(new CallBack() { @Override //レスポンスが来た時に解読し実行 public void onResponse(String response) { //レスポンスを解読 RoomResponse room = JSON.decode(response, RoomResponse.class); keycheck = room.isCheck(); if (keycheck == true) { ((Sprout) RoomInputKeyActivity.this.getApplication()).setMemberId(room.getMemberId()); //押したらルーム画面へ進む Intent intent = new Intent(RoomInputKeyActivity.this, RoomMainActivity.class); startActivity(intent); } //間違っていたら else if (keycheck == false) { Toast.makeText(getBaseContext(), "パスワードが間違っているか\nルームがいっぱいです!", Toast.LENGTH_SHORT).show(); } } }); //サーバに送る int userId = ((Sprout) getApplication()).getUserId(); int roomId = ((Sprout) getApplication()).getRoomId(); connection.addFormParam("userId", String.valueOf(userId)); connection.addPathParam(String.valueOf(roomId)); key = (EditText) findViewById(id.roomkeyinput_edittext1); connection.addFormParam("key", key.getText().toString()); connection.doPut(); } }); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.room_key_input, 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); } }