From 638314657c2732740c392c27c0b4601cdd3b9130 Mon Sep 17 00:00:00 2001 From: Jeff Martin Date: Sun, 18 Jan 2015 10:02:26 -0500 Subject: [PATCH] fix shortcut bar duplicating --- .../java/me/writeily/pro/NoteActivity.java | 38 ++++++++++--------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/me/writeily/pro/NoteActivity.java b/app/src/main/java/me/writeily/pro/NoteActivity.java index a139498..10bb2cb 100644 --- a/app/src/main/java/me/writeily/pro/NoteActivity.java +++ b/app/src/main/java/me/writeily/pro/NoteActivity.java @@ -202,25 +202,27 @@ protected void onPause() { } private void setupKeyboardBar() { - for (String shortcut : Constants.KEYBOARD_SHORTCUTS) { - Button shortcutButton = new Button(this); - shortcutButton.setText(shortcut); - shortcutButton.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.MATCH_PARENT)); - - shortcutButton.setTextSize(18); - shortcutButton.setTypeface(null, Typeface.BOLD); - shortcutButton.setBackground(getResources().getDrawable(R.drawable.keyboard_shortcut_button)); - shortcutButton.setOnClickListener(new KeyboardBarListener()); - - String theme = PreferenceManager.getDefaultSharedPreferences(this).getString(getString(R.string.pref_theme_key), ""); - - if (theme.equals(getString(R.string.theme_dark))) { - shortcutButton.setTextColor(getResources().getColor(android.R.color.white)); - } else { - shortcutButton.setTextColor(getResources().getColor(R.color.grey)); - } + if (keyboardBarView.getChildCount() == 0) { + for (String shortcut : Constants.KEYBOARD_SHORTCUTS) { + Button shortcutButton = new Button(this); + shortcutButton.setText(shortcut); + shortcutButton.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.MATCH_PARENT)); + + shortcutButton.setTextSize(18); + shortcutButton.setTypeface(null, Typeface.BOLD); + shortcutButton.setBackground(getResources().getDrawable(R.drawable.keyboard_shortcut_button)); + shortcutButton.setOnClickListener(new KeyboardBarListener()); + + String theme = PreferenceManager.getDefaultSharedPreferences(this).getString(getString(R.string.pref_theme_key), ""); + + if (theme.equals(getString(R.string.theme_dark))) { + shortcutButton.setTextColor(getResources().getColor(android.R.color.white)); + } else { + shortcutButton.setTextColor(getResources().getColor(R.color.grey)); + } - keyboardBarView.addView(shortcutButton); + keyboardBarView.addView(shortcutButton); + } } }