mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-09-22 03:54:18 -04:00
Merge pull request #228 from kiwix/bottombar
Added bottombar as optional feature #165
This commit is contained in:
commit
8a3fa8153a
@ -38,7 +38,8 @@
|
||||
<activity
|
||||
android:name=".KiwixMobileActivity"
|
||||
android:configChanges="orientation|keyboardHidden|screenSize|locale"
|
||||
android:label="@string/app_name">
|
||||
android:label="@string/app_name"
|
||||
android:windowSoftInputMode="adjustPan">
|
||||
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.VIEW" />
|
||||
|
@ -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) {
|
||||
|
||||
|
56
app/src/main/java/org/kiwix/kiwixmobile/PageBottomTab.java
Normal file
56
app/src/main/java/org/kiwix/kiwixmobile/PageBottomTab.java
Normal file
@ -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();
|
||||
}
|
||||
}
|
@ -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;
|
||||
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
@ -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) {
|
||||
|
BIN
app/src/main/res/drawable-hdpi/fullscreen.png
Executable file
BIN
app/src/main/res/drawable-hdpi/fullscreen.png
Executable file
Binary file not shown.
After Width: | Height: | Size: 3.2 KiB |
BIN
app/src/main/res/drawable-mdpi/fullscreen.png
Executable file
BIN
app/src/main/res/drawable-mdpi/fullscreen.png
Executable file
Binary file not shown.
After Width: | Height: | Size: 1.7 KiB |
BIN
app/src/main/res/drawable-xhdpi/fullscreen.png
Executable file
BIN
app/src/main/res/drawable-xhdpi/fullscreen.png
Executable file
Binary file not shown.
After Width: | Height: | Size: 3.7 KiB |
BIN
app/src/main/res/drawable-xxhdpi/fullscreen.png
Executable file
BIN
app/src/main/res/drawable-xxhdpi/fullscreen.png
Executable file
Binary file not shown.
After Width: | Height: | Size: 7.2 KiB |
BIN
app/src/main/res/drawable-xxxhdpi/fullscreen.png
Executable file
BIN
app/src/main/res/drawable-xxxhdpi/fullscreen.png
Executable file
Binary file not shown.
After Width: | Height: | Size: 8.6 KiB |
BIN
app/src/main/res/drawable/fullscreen.png
Executable file
BIN
app/src/main/res/drawable/fullscreen.png
Executable file
Binary file not shown.
After Width: | Height: | Size: 8.6 KiB |
12
app/src/main/res/drawable/ic_find_in_page.xml
Normal file
12
app/src/main/res/drawable/ic_find_in_page.xml
Normal file
@ -0,0 +1,12 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:autoMirrored="true"
|
||||
android:viewportHeight="24.0"
|
||||
android:viewportWidth="24.0"
|
||||
tools:ignore="UnusedAttribute">
|
||||
<path
|
||||
android:fillColor="#FFFFFFFF"
|
||||
android:pathData="M20,19.59V8l-6,-6H6c-1.1,0 -1.99,0.9 -1.99,2L4,20c0,1.1 0.89,2 1.99,2H18c0.45,0 0.85,-0.15 1.19,-0.4l-4.43,-4.43c-0.8,0.52 -1.74,0.83 -2.76,0.83 -2.76,0 -5,-2.24 -5,-5s2.24,-5 5,-5 5,2.24 5,5c0,1.02 -0.31,1.96 -0.83,2.75L20,19.59zM9,13c0,1.66 1.34,3 3,3s3,-1.34 3,-3 -1.34,-3 -3,-3 -3,1.34 -3,3z" />
|
||||
</vector>
|
@ -1,5 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/snackbar_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
@ -99,11 +100,23 @@
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
<org.kiwix.kiwixmobile.views.PageBottomTabLayout
|
||||
android:id="@+id/page_bottom_tab_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:layout_gravity="bottom"
|
||||
android:background="@color/grey"
|
||||
android:visibility="gone"
|
||||
app:tabGravity="fill"
|
||||
app:tabIndicatorColor="@color/grey"
|
||||
app:tabSelectedTextColor="@color/grey"/>
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
<include layout="@layout/drawer_left" />
|
||||
@ -137,4 +150,4 @@
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
</android.support.design.widget.CoordinatorLayout>
|
||||
</android.support.design.widget.CoordinatorLayout>
|
||||
|
27
app/src/main/res/layout/page_bottom_tab_layout.xml
Normal file
27
app/src/main/res/layout/page_bottom_tab_layout.xml
Normal file
@ -0,0 +1,27 @@
|
||||
<merge xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
<android.support.design.widget.TabItem
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:contentDescription="@string/menu_home"
|
||||
android:icon="@drawable/action_home" />
|
||||
|
||||
<android.support.design.widget.TabItem
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:contentDescription="@string/menu_searchintext"
|
||||
android:icon="@drawable/ic_find_in_page" />
|
||||
|
||||
<android.support.design.widget.TabItem
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:contentDescription="@string/menu_fullscreen"
|
||||
android:icon="@drawable/fullscreen" />
|
||||
|
||||
<android.support.design.widget.TabItem
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:contentDescription="@string/menu_randomarticle"
|
||||
android:icon="@drawable/action_randomarticle" />
|
||||
</merge>
|
@ -175,6 +175,8 @@
|
||||
<string name="time_minute">min</string>
|
||||
<string name="time_second">s</string>
|
||||
<string name="time_left">left</string>
|
||||
<string name="pref_bottomtoolbar">Enable bottom toolbar</string>
|
||||
<string name="pref_bottomtoolbar_summary">Display a toolbar with quick actions at the bottom of the screen</string>
|
||||
<string name="pref_autonightmode_summary">Automatically switch between day and night mode.</string>
|
||||
<string name="pref_autonightmode">Automated night mode</string>
|
||||
<string name="language_count">(%1$d)</string>
|
||||
|
@ -27,6 +27,13 @@
|
||||
android:summary="@string/pref_hidetoolbar_summary"
|
||||
android:title="@string/pref_hidetoolbar"/>
|
||||
|
||||
<org.kiwix.kiwixmobile.settings.CustomSwitchPreference
|
||||
android:defaultValue="false"
|
||||
android:key="pref_bottomtoolbar"
|
||||
android:summary="@string/pref_bottomtoolbar_summary"
|
||||
android:title="@string/pref_bottomtoolbar"/>
|
||||
|
||||
|
||||
</PreferenceCategory>
|
||||
|
||||
<PreferenceCategory
|
||||
|
Loading…
x
Reference in New Issue
Block a user