Skip to content

Commit

Permalink
Add preference to disable auto-hiding the top action bar; fixes uberg…
Browse files Browse the repository at this point in the history
  • Loading branch information
zopieux committed Dec 8, 2016
1 parent 583b0ef commit cd9e5c4
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public static void init(@NonNull Context context) {
///////////////////////////////////////////////////////////////////////////////////////////// ui

public static boolean sortBuffers, showTitle, filterBuffers, optimizeTraffic;
public static boolean filterLines;
public static boolean filterLines, autoHideActionbar;
public static int maxWidth;
public static boolean encloseNick, dimDownNonHumanLines;
public static @Nullable DateFormat dateFormat;
Expand All @@ -85,6 +85,7 @@ public static void loadUIPreferences() {

// buffer-wide preferences
filterLines = p.getBoolean(PREF_FILTER_LINES, PREF_FILTER_LINES_D);
autoHideActionbar = p.getBoolean(PREF_AUTO_HIDE_ACTIONBAR, PREF_AUTO_HIDE_ACTIONBAR_D);
maxWidth = Integer.parseInt(p.getString(PREF_MAX_WIDTH, PREF_MAX_WIDTH_D));
encloseNick = p.getBoolean(PREF_ENCLOSE_NICK, PREF_ENCLOSE_NICK_D);
dimDownNonHumanLines = p.getBoolean(PREF_DIM_DOWN, PREF_DIM_DOWN_D);
Expand Down Expand Up @@ -182,6 +183,7 @@ public static void loadConnectionPreferences() {
case PREF_SORT_BUFFERS: sortBuffers = p.getBoolean(key, PREF_SORT_BUFFERS_D); break;
case PREF_SHOW_BUFFER_TITLES: showTitle = p.getBoolean(key, PREF_SHOW_BUFFER_TITLES_D); break;
case PREF_FILTER_NONHUMAN_BUFFERS: filterBuffers = p.getBoolean(key, PREF_FILTER_NONHUMAN_BUFFERS_D); break;
case PREF_AUTO_HIDE_ACTIONBAR: autoHideActionbar = p.getBoolean(key, PREF_AUTO_HIDE_ACTIONBAR_D); break;

// buffer-wide preferences
case PREF_FILTER_LINES: filterLines = p.getBoolean(key, PREF_FILTER_LINES_D); break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public class Constants {
// look & feel
final static public String PREF_LOOKFEEL_GROUP = "lookfeel_group";
public static final String PREF_TEXT_SIZE = "text_size"; final public static String PREF_TEXT_SIZE_D = "12";
public static final String PREF_AUTO_HIDE_ACTIONBAR = "auto_hide_actionbar"; public static final boolean PREF_AUTO_HIDE_ACTIONBAR_D = true;
public static final String PREF_FILTER_LINES = "chatview_filters"; final public static boolean PREF_FILTER_LINES_D = true;
public static final String PREF_PREFIX_ALIGN = "prefix_align"; final public static String PREF_PREFIX_ALIGN_D = "right";
final static public String PREF_MAX_WIDTH = "prefix_max_width"; final public static String PREF_MAX_WIDTH_D = "7";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import android.view.animation.DecelerateInterpolator;

import com.ubergeek42.WeechatAndroid.R;
import com.ubergeek42.WeechatAndroid.service.P;

public class ToolbarController implements ViewTreeObserver.OnGlobalLayoutListener {
final Toolbar toolbar;
Expand All @@ -26,6 +27,7 @@ public ToolbarController(AppCompatActivity activity) {
}

public void onUserScroll(int bottomHidden, int prevBottomHidden) {
if (!canAutoHide()) return;
if (bottomHidden > prevBottomHidden) hide();
else if (bottomHidden < prevBottomHidden) show();
}
Expand All @@ -35,15 +37,22 @@ public void onPageChangedOrSelected() {
}

public void onSoftwareKeyboardStateChanged(boolean visible) {
if (!canAutoHide()) return;
if (keyboardVisible == visible) return;
keyboardVisible = visible;
if (visible) hide();
else show();
}

private boolean canAutoHide() {
if (P.autoHideActionbar)
return true;
show();
return false;
}

private void show() {
if (shown || keyboardVisible) return;
if (shown) return;
shown = true;
if (android.os.Build.VERSION.SDK_INT >= 14)
toolbar.animate().translationY(0).setInterpolator(new DecelerateInterpolator()).start();
Expand All @@ -63,6 +72,7 @@ private void hide() {
////////////////////////////////////////////////////////////////////////////////////////////////

@Override public void onGlobalLayout() {
if (!canAutoHide()) return;
// if more than 300 pixels, its probably a keyboard...
int heightDiff = root.getRootView().getHeight() - root.getHeight();
if (heightDiff > 300)
Expand Down
2 changes: 2 additions & 0 deletions weechat-android/src/main/res/values-fr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -179,4 +179,6 @@
<string name="pref_prefix_align_none">Non aligné</string>
<string name="pref_prefix_align_right">Aligné à droite</string>
<string name="pref_prefix_align_timestamp">Aligné sur l\'heure</string>
<string name="pref_auto_hide_actionbar">Cacher la barre d\'action</string>
<string name="pref_auto_hide_actionbar_summary">Cacher la barre d\'action lorsque le clavier est affiché ou lors du défilement vers le haut</string>
</resources>
2 changes: 2 additions & 0 deletions weechat-android/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@

<string name="pref_lookfeel_group">Look &amp; feel</string>
<string name="pref_text_size">Text Size</string>
<string name="pref_auto_hide_actionbar">Hide action bar</string>
<string name="pref_auto_hide_actionbar_summary">Hide the top action bar when the keyboard is open or when scrolling up</string>
<string name="pref_chatview_filters">Filter messages</string>
<string name="pref_chatview_filters_summary">Hide messages filtered by WeeChat (e.g. irc_smart_filter)</string>
<string name="pref_prefix_align">Prefix alignment</string>
Expand Down
1 change: 1 addition & 0 deletions weechat-android/src/main/res/xml/preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@

<PreferenceScreen android:key="lookfeel_group" android:title="@string/pref_lookfeel_group">
<EditTextPreferenceFix android:key="text_size" android:title="@string/pref_text_size" android:summary="%s" android:defaultValue="12" android:numeric="integer" />
<CheckBoxPreference android:key="auto_hide_actionbar" android:title="@string/pref_auto_hide_actionbar" android:summary="@string/pref_auto_hide_actionbar_summary" android:defaultValue="true"/>
<CheckBoxPreference android:key="chatview_filters" android:title="@string/pref_chatview_filters" android:summary="@string/pref_chatview_filters_summary" android:defaultValue="true" />
<ListPreference android:key="prefix_align" android:title="@string/pref_prefix_align" android:summary="%s" android:defaultValue="right" android:entries="@array/pref_prefix_align_names" android:entryValues="@array/settings_prefix_alignment_values" />
<EditTextPreferenceFix android:key="prefix_max_width" android:title="@string/pref_max_width" android:summary="@string/pref_max_width_summary" android:numeric="integer" android:defaultValue="7" />
Expand Down

0 comments on commit cd9e5c4

Please sign in to comment.