From 30bb2aeae4538e0f19b51b9e760b6e640559c973 Mon Sep 17 00:00:00 2001 From: "oskar.wiksten" Date: Tue, 22 May 2012 17:04:25 +0000 Subject: [PATCH] Make sure that conversation phrases are not focused when using keyboard navigation, since the focus marker interferes with the reply seletion, and makes the text be displayed in the same color as the background. git-svn-id: https://andors-trail.googlecode.com/svn/trunk@249 08aca716-68be-ccc6-4d58-36f5abd142ac --- .../activity/ConversationActivity.java | 42 ++++++++++++++++--- 1 file changed, 37 insertions(+), 5 deletions(-) diff --git a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/activity/ConversationActivity.java b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/activity/ConversationActivity.java index b6d64b7..f9d9b34 100644 --- a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/activity/ConversationActivity.java +++ b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/activity/ConversationActivity.java @@ -78,7 +78,7 @@ public final class ConversationActivity extends Activity implements OnKeyListene this.npc = Dialogs.getMonsterFromIntent(getIntent(), world); displayActors = (npc != null); - String phraseID = uri.getLastPathSegment().toString(); + phraseID = uri.getLastPathSegment().toString(); if (savedInstanceState != null) { phraseID = savedInstanceState.getString("phraseID"); conversationHistory = savedInstanceState.getParcelableArrayList("conversationHistory"); @@ -122,13 +122,23 @@ public final class ConversationActivity extends Activity implements OnKeyListene nextButtonClicked(); } }); - - setPhrase(phraseID); statementList.setOnKeyListener(this); + + statementList.setSelected(false); + statementList.setFocusable(false); + statementList.setFocusableInTouchMode(false); } - private int getSelectedReplyIndex() { + @Override + protected void onResume() { + super.onResume(); + + setPhrase(phraseID); + nextButton.requestFocus(); + } + + private int getSelectedReplyIndex() { for (int i = 0; i < phrase.replies.length; ++i) { final View v = replyGroup.getChildAt(i); if (v == null) continue; @@ -150,11 +160,20 @@ public final class ConversationActivity extends Activity implements OnKeyListene rb.setChecked(true); } + @Override + public boolean onKeyDown(int keyCode, KeyEvent event) { + if (handleKeypress(keyCode, event)) return true; + else return super.onKeyDown(keyCode, event); + } + @Override public boolean onKey(View arg0, int keyCode, KeyEvent event) { if (event.getAction() != KeyEvent.ACTION_DOWN) return false; + return handleKeypress(keyCode, event); + } + + public boolean handleKeypress(int keyCode, KeyEvent event) { int selectedReplyIndex = getSelectedReplyIndex(); - switch (keyCode) { case KeyEvent.KEYCODE_DPAD_UP: --selectedReplyIndex; @@ -265,6 +284,8 @@ public final class ConversationActivity extends Activity implements OnKeyListene rb.setOnCheckedChangeListener(radioButtonListener); rb.setTag(r); rb.setShadowLayer(1, 1, 1, Color.BLACK); + rb.setFocusable(false); + rb.setFocusableInTouchMode(false); replyGroup.addView(rb, layoutParams); } @@ -317,6 +338,7 @@ public final class ConversationActivity extends Activity implements OnKeyListene s.color = color; s.isPlayerActor = actor != null ? actor.isPlayer : false; conversationHistory.add(s); + statementList.clearFocus(); listAdapter.notifyDataSetChanged(); statementList.requestLayout(); } @@ -413,5 +435,15 @@ public final class ConversationActivity extends Activity implements OnKeyListene return result; } + + @Override + public boolean areAllItemsEnabled() { + return false; + } + + @Override + public boolean isEnabled(int position) { + return false; + } } } -- 2.49.0