diff --git a/app/src/main/java/com/example/tampopo_client/views/MainActivity.java b/app/src/main/java/com/example/tampopo_client/views/MainActivity.java index 237e7c0..21e3aae 100644 --- a/app/src/main/java/com/example/tampopo_client/views/MainActivity.java +++ b/app/src/main/java/com/example/tampopo_client/views/MainActivity.java @@ -14,6 +14,7 @@ import android.widget.TextView; import androidx.activity.EdgeToEdge; +import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AppCompatActivity; import androidx.core.graphics.Insets; import androidx.core.view.ViewCompat; @@ -27,7 +28,9 @@ private ImageButton sendButton; private GridView wordGroup; private LinearLayout messageList; - private String[] words = {"そろそろ会いたいね〜", "今暇だよー", "勉強しよ〜", "ごはんいこ〜"}; + //アクティビティの選択肢 + private String[] words = {"ひまnow","あそぼ!","そろそろ会いたない〜?", "勉強なう", "電話しよ~", "お風呂入ってくる~","今暇だよー!","いそがしい~!!"}; + private Button openDialogButton; @Override protected void onCreate(Bundle savedInstanceState) { @@ -67,44 +70,78 @@ // } // }); - editMessage = findViewById(R.id.editMessage); - sendButton = findViewById(R.id.sendButton); - wordGroup = findViewById(R.id.wordGroup); messageList = findViewById(R.id.messageList); + // ボタンを押すとダイアログ表示(トリガー用) + openDialogButton = findViewById(R.id.openDialogButton); + openDialogButton.setOnClickListener(v -> showInputDialog()); + + } + private void showInputDialog() { + // カスタムビュー読み込み + View dialogView = getLayoutInflater().inflate(R.layout.main_dialog, null); + EditText editTextInput = dialogView.findViewById(R.id.editTextInput); + GridView wordGrid = dialogView.findViewById(R.id.wordGrid); + ImageButton sendButton = dialogView.findViewById(R.id.sendButton); + // 語群セット ArrayAdapter adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, words); - wordGroup.setAdapter(adapter); + wordGrid.setAdapter(adapter); - editMessage.setOnFocusChangeListener((v, hasFocus) -> { - if (hasFocus) { - wordGroup.setVisibility(View.GONE); - } + // 語群クリックで入力欄にセット + wordGrid.setOnItemClickListener((parent, view, position, id) -> { + editTextInput.setText(words[position]); + // 入力欄にフォーカス&キーボード表示 + editTextInput.requestFocus(); + InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE); + imm.showSoftInput(editTextInput, InputMethodManager.SHOW_IMPLICIT); }); - // 「あそぼ!」的なトリガータップ(ここでは GridView の表示で代用) - findViewById(R.id.editMessage).setOnClickListener(v -> { - wordGroup.setVisibility(View.VISIBLE); - }); - - // 語群から選択 → 入力欄にセット - wordGroup.setOnItemClickListener((parent, view, position, id) -> { - editMessage.setText(words[position]); - wordGroup.setVisibility(View.GONE); - }); + // ダイアログ生成 + AlertDialog dialog = new AlertDialog.Builder(this) + .setView(dialogView) + .create(); // 送信ボタン処理 sendButton.setOnClickListener(v -> { - String message = editMessage.getText().toString(); + String message = editTextInput.getText().toString().trim(); + int length = message.length(); if (!message.isEmpty()) { - TextView textView = new TextView(this); - textView.setText(message); - textView.setPadding(10, 10, 10, 10); - textView.setBackgroundColor(Color.parseColor("#E0E0E0")); - messageList.addView(textView); - - editMessage.setText(""); + if(length > 20){ + openDialogButton.setTextSize(7); + }else if(length > 10){ + openDialogButton.setTextSize(10); + }else{ + openDialogButton.setTextSize(12); + } + openDialogButton.setMaxLines(10); + openDialogButton.setLineSpacing(4.0f,1.2f); + openDialogButton.setText(message); + editTextInput.setText(""); + dialog.dismiss(); // ダイアログを閉じる + }else{ + openDialogButton.setText(""); } }); + + dialog.show(); + } + + private void addMessageToHome(String message) { + TextView textView = new TextView(this); + textView.setText(message); + textView.setPadding(10, 10, 10, 10); + textView.setBackgroundColor(Color.parseColor("#E0E0E0")); + int length = message.length(); + if(length > 10){ + textView.setTextSize(5); + }else if(length > 7){ + textView.setTextSize(8); + }else{ + textView.setTextSize(10); + } + textView.setMaxLines(10); + textView.setLineSpacing(4.0f,1.2f); + messageList.addView(textView); } } \ No newline at end of file