diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index e0953f257..5087ff7e6 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -38,7 +38,8 @@ + android:label="@string/app_name" + android:windowSoftInputMode="adjustPan"> diff --git a/app/src/main/java/org/kiwix/kiwixmobile/KiwixMobileActivity.java b/app/src/main/java/org/kiwix/kiwixmobile/KiwixMobileActivity.java index 2d23047f9..f3a4e3fdc 100644 --- a/app/src/main/java/org/kiwix/kiwixmobile/KiwixMobileActivity.java +++ b/app/src/main/java/org/kiwix/kiwixmobile/KiwixMobileActivity.java @@ -38,8 +38,10 @@ import android.os.Build; import android.os.Bundle; import android.os.Handler; import android.preference.PreferenceManager; +import android.support.annotation.NonNull; import android.support.design.widget.CoordinatorLayout; import android.support.design.widget.Snackbar; +import android.support.design.widget.TabLayout; import android.support.v4.app.ActivityCompat; import android.support.v4.content.ContextCompat; import android.support.v4.view.GravityCompat; @@ -265,6 +267,8 @@ public class KiwixMobileActivity extends BaseActivity implements WebViewCallback @BindView(R.id.action_forward) View tabForwardButtonContainer; + @BindView(R.id.page_bottom_tab_layout) TabLayout pageBottomTabLayout; + @Inject OkHttpClient okHttpClient; @@ -303,6 +307,52 @@ public class KiwixMobileActivity extends BaseActivity implements WebViewCallback } } + @NonNull + private final TabLayout.OnTabSelectedListener pageBottomTabListener + = new TabLayout.OnTabSelectedListener() { + @Override + public void onTabSelected(TabLayout.Tab tab) { + PageBottomTab.of(tab.getPosition()).select(pageActionTabsCallback); + } + + @Override + public void onTabUnselected(TabLayout.Tab tab) {} + + @Override + public void onTabReselected(TabLayout.Tab tab) { + onTabSelected(tab); + } + }; + + private PageBottomTab.Callback pageActionTabsCallback = new PageBottomTab.Callback() { + @Override + public void onHomeTabSelected() { + openMainPage(); + } + + @Override + public void onFindInPageTabSelected() { + compatCallback.setActive(); + compatCallback.setWebView(getCurrentWebView()); + startSupportActionMode(compatCallback); + compatCallback.showSoftInput(); + } + + @Override + public void onFullscreenTabSelected() { + if (isFullscreenOpened) { + closeFullScreen(); + } else { + openFullScreen(); + } + } + + @Override + public void onRandomArticleTabSelected() { + openRandomArticle(); + } + }; + @Override public void onCreate(Bundle savedInstanceState) { SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); @@ -430,6 +480,8 @@ public class KiwixMobileActivity extends BaseActivity implements WebViewCallback startActivity(zimFile); } + pageBottomTabLayout.addOnTabSelectedListener(pageBottomTabListener); + wasHideToolbar = isHideToolbar; } @@ -618,7 +670,7 @@ public class KiwixMobileActivity extends BaseActivity implements WebViewCallback AttributeSet attrs = StyleUtils.getAttributes(this, R.xml.webview); KiwixWebView webView; if (isHideToolbar) { - webView = new ToolbarScrollingKiwixWebView(KiwixMobileActivity.this, this, toolbarContainer, attrs); + webView = new ToolbarScrollingKiwixWebView(KiwixMobileActivity.this, this, toolbarContainer, pageBottomTabLayout , attrs); ((ToolbarScrollingKiwixWebView) webView).setOnToolbarVisibilityChangeListener( new ToolbarScrollingKiwixWebView.OnToolbarVisibilityChangeListener() { @Override @@ -811,6 +863,7 @@ public class KiwixMobileActivity extends BaseActivity implements WebViewCallback private void openFullScreen() { toolbarContainer.setVisibility(View.GONE); + pageBottomTabLayout.setVisibility(View.GONE); exitFullscreenButton.setVisibility(View.VISIBLE); int fullScreenFlag = WindowManager.LayoutParams.FLAG_FULLSCREEN; int classicScreenFlag = WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN; @@ -831,6 +884,9 @@ public class KiwixMobileActivity extends BaseActivity implements WebViewCallback private void closeFullScreen() { toolbarContainer.setVisibility(View.VISIBLE); + if (settings.getBoolean(KiwixSettingsActivity.PREF_BOTTOM_TOOLBAR, false)) { + pageBottomTabLayout.setVisibility(View.VISIBLE); + } exitFullscreenButton.setVisibility(View.INVISIBLE); int fullScreenFlag = WindowManager.LayoutParams.FLAG_FULLSCREEN; int classicScreenFlag = WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN; @@ -1132,6 +1188,12 @@ public class KiwixMobileActivity extends BaseActivity implements WebViewCallback } } + if (settings.getBoolean(KiwixSettingsActivity.PREF_BOTTOM_TOOLBAR, false)) { + pageBottomTabLayout.setVisibility(View.VISIBLE); + } else { + pageBottomTabLayout.setVisibility(View.GONE); + } + Intent intent = getIntent(); if (intent.getAction() != null) { diff --git a/app/src/main/java/org/kiwix/kiwixmobile/PageBottomTab.java b/app/src/main/java/org/kiwix/kiwixmobile/PageBottomTab.java new file mode 100644 index 000000000..23dca3ab4 --- /dev/null +++ b/app/src/main/java/org/kiwix/kiwixmobile/PageBottomTab.java @@ -0,0 +1,56 @@ +package org.kiwix.kiwixmobile; + +import android.support.annotation.NonNull; + +public enum PageBottomTab { + HOME() { + @Override + public void select(@NonNull Callback cb) { + cb.onHomeTabSelected(); + } + }, + FIND_IN_PAGE() { + @Override + public void select(@NonNull Callback cb) { + cb.onFindInPageTabSelected(); + } + }, + FULL_SCREEN() { + @Override + public void select(@NonNull Callback cb) { + cb.onFullscreenTabSelected(); + } + }, + RANDOM_ARTICLE() { + @Override + public void select(@NonNull Callback cb) { + cb.onRandomArticleTabSelected(); + } + }; + + + @NonNull + public static PageBottomTab of(int code) { + switch (code) { + case 0: + return HOME; + case 1: + return FIND_IN_PAGE; + case 2: + return FULL_SCREEN; + case 3: + return RANDOM_ARTICLE; + default: + throw new IllegalArgumentException("Tab position is: " + code); + } + } + + public abstract void select(@NonNull Callback cb); + + public interface Callback { + void onHomeTabSelected(); + void onFindInPageTabSelected(); + void onFullscreenTabSelected(); + void onRandomArticleTabSelected(); + } +} diff --git a/app/src/main/java/org/kiwix/kiwixmobile/settings/KiwixSettingsActivity.java b/app/src/main/java/org/kiwix/kiwixmobile/settings/KiwixSettingsActivity.java index 25ed25257..2bde4c5cb 100644 --- a/app/src/main/java/org/kiwix/kiwixmobile/settings/KiwixSettingsActivity.java +++ b/app/src/main/java/org/kiwix/kiwixmobile/settings/KiwixSettingsActivity.java @@ -87,6 +87,11 @@ public class KiwixSettingsActivity extends AppCompatActivity { public static final String PREF_WIFI_ONLY = "pref_wifi_only"; + + public static final String PREF_BOTTOM_TOOLBAR = "pref_bottomtoolbar"; + + public static String zimFile; + public static boolean allHistoryCleared = false; diff --git a/app/src/main/java/org/kiwix/kiwixmobile/views/PageBottomTabLayout.java b/app/src/main/java/org/kiwix/kiwixmobile/views/PageBottomTabLayout.java new file mode 100644 index 000000000..d2aff2938 --- /dev/null +++ b/app/src/main/java/org/kiwix/kiwixmobile/views/PageBottomTabLayout.java @@ -0,0 +1,26 @@ +package org.kiwix.kiwixmobile.views; + +import android.content.Context; +import android.support.design.widget.TabLayout; +import android.util.AttributeSet; + +import org.kiwix.kiwixmobile.R; + +import butterknife.ButterKnife; + +public class PageBottomTabLayout extends TabLayout { + + public PageBottomTabLayout(Context context) { + this(context, null); + } + + public PageBottomTabLayout(Context context, AttributeSet attrs) { + this(context, attrs, 0); + } + + public PageBottomTabLayout(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + inflate(getContext(), R.layout.page_bottom_tab_layout, this); + ButterKnife.bind(this); + } +} diff --git a/app/src/main/java/org/kiwix/kiwixmobile/views/web/ToolbarScrollingKiwixWebView.java b/app/src/main/java/org/kiwix/kiwixmobile/views/web/ToolbarScrollingKiwixWebView.java index 827121b37..06e3c2497 100644 --- a/app/src/main/java/org/kiwix/kiwixmobile/views/web/ToolbarScrollingKiwixWebView.java +++ b/app/src/main/java/org/kiwix/kiwixmobile/views/web/ToolbarScrollingKiwixWebView.java @@ -33,12 +33,14 @@ public class ToolbarScrollingKiwixWebView extends KiwixWebView { private final int statusBarHeight = DimenUtils.getTranslucentStatusBarHeight(getContext()); private final int toolbarHeight = DimenUtils.getToolbarHeight(getContext()); private View toolbarView; + private View bottombarView; private OnToolbarVisibilityChangeListener listener; private float startY; - public ToolbarScrollingKiwixWebView(Context context, WebViewCallback callback, View toolbarView, AttributeSet attrs) { + public ToolbarScrollingKiwixWebView(Context context, WebViewCallback callback, View toolbarView, View bottombarView, AttributeSet attrs) { super(context, callback, attrs); this.toolbarView = toolbarView; + this.bottombarView = bottombarView; } protected boolean moveToolbar(int scrollDelta) { @@ -53,6 +55,7 @@ public class ToolbarScrollingKiwixWebView extends KiwixWebView { } toolbarView.setTranslationY(newTranslation + statusBarHeight); + bottombarView.setTranslationY(newTranslation * -1 * (bottombarView.getHeight() / (float) (statusBarHeight + toolbarHeight))); this.setTranslationY(newTranslation + toolbarHeight + statusBarHeight); if (listener != null && newTranslation != originalTranslation) { if (newTranslation == -toolbarHeight -statusBarHeight) { diff --git a/app/src/main/res/drawable-hdpi/fullscreen.png b/app/src/main/res/drawable-hdpi/fullscreen.png new file mode 100755 index 000000000..5f660591d Binary files /dev/null and b/app/src/main/res/drawable-hdpi/fullscreen.png differ diff --git a/app/src/main/res/drawable-mdpi/fullscreen.png b/app/src/main/res/drawable-mdpi/fullscreen.png new file mode 100755 index 000000000..a2591f0be Binary files /dev/null and b/app/src/main/res/drawable-mdpi/fullscreen.png differ diff --git a/app/src/main/res/drawable-xhdpi/fullscreen.png b/app/src/main/res/drawable-xhdpi/fullscreen.png new file mode 100755 index 000000000..9449166b7 Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/fullscreen.png differ diff --git a/app/src/main/res/drawable-xxhdpi/fullscreen.png b/app/src/main/res/drawable-xxhdpi/fullscreen.png new file mode 100755 index 000000000..ca746a0dd Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/fullscreen.png differ diff --git a/app/src/main/res/drawable-xxxhdpi/fullscreen.png b/app/src/main/res/drawable-xxxhdpi/fullscreen.png new file mode 100755 index 000000000..f0cddedab Binary files /dev/null and b/app/src/main/res/drawable-xxxhdpi/fullscreen.png differ diff --git a/app/src/main/res/drawable/fullscreen.png b/app/src/main/res/drawable/fullscreen.png new file mode 100755 index 000000000..f0cddedab Binary files /dev/null and b/app/src/main/res/drawable/fullscreen.png differ diff --git a/app/src/main/res/drawable/ic_find_in_page.xml b/app/src/main/res/drawable/ic_find_in_page.xml new file mode 100644 index 000000000..75154c5e4 --- /dev/null +++ b/app/src/main/res/drawable/ic_find_in_page.xml @@ -0,0 +1,12 @@ + + + diff --git a/app/src/main/res/layout/main.xml b/app/src/main/res/layout/main.xml index 3782a9a36..62451fd5c 100644 --- a/app/src/main/res/layout/main.xml +++ b/app/src/main/res/layout/main.xml @@ -1,5 +1,6 @@ - + + @@ -137,4 +150,4 @@ - \ No newline at end of file + diff --git a/app/src/main/res/layout/page_bottom_tab_layout.xml b/app/src/main/res/layout/page_bottom_tab_layout.xml new file mode 100644 index 000000000..28aec6589 --- /dev/null +++ b/app/src/main/res/layout/page_bottom_tab_layout.xml @@ -0,0 +1,27 @@ + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 925ea0cc7..a9cfd9ded 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -175,6 +175,8 @@ min s left + Enable bottom toolbar + Display a toolbar with quick actions at the bottom of the screen Automatically switch between day and night mode. Automated night mode (%1$d) diff --git a/app/src/main/res/xml/preferences.xml b/app/src/main/res/xml/preferences.xml index 8a171b4e2..a22547242 100644 --- a/app/src/main/res/xml/preferences.xml +++ b/app/src/main/res/xml/preferences.xml @@ -27,6 +27,13 @@ android:summary="@string/pref_hidetoolbar_summary" android:title="@string/pref_hidetoolbar"/> + + +