Skip to content

Commit

Permalink
Add preference for full screen navigation drawer (ankidroid#9015)
Browse files Browse the repository at this point in the history
  • Loading branch information
ShridharGoel committed Jun 2, 2021
1 parent a5363a2 commit d0d1edd
Show file tree
Hide file tree
Showing 14 changed files with 287 additions and 338 deletions.
Expand Up @@ -26,10 +26,13 @@
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;

import com.drakeet.drawer.FullDraggableContainer;
import com.google.android.material.navigation.NavigationView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.core.app.TaskStackBuilder;
import androidx.core.content.ContextCompat;
import androidx.core.view.GravityCompat;
Expand All @@ -38,6 +41,7 @@
import androidx.appcompat.widget.Toolbar;

import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
Expand Down Expand Up @@ -73,12 +77,35 @@ public abstract class NavigationDrawerActivity extends AnkiActivity implements N
public static final int REQUEST_BROWSE_CARDS = 101;
public static final int REQUEST_STATISTICS = 102;
private static final String NIGHT_MODE_PREFERENCE = "invertedColors";
public static final String FULL_SCREEN_NAVIGATION_DRAWER = "gestureFullScreenNavigationDrawer";

/**
* runnable that will be executed after the drawer has been closed.
*/
private Runnable mPendingRunnable;

@Override
public void setContentView(int layoutResID) {
SharedPreferences preferences = AnkiDroidApp.getSharedPrefs(getBaseContext());

// Using ClosableDrawerLayout as a parent view.
ClosableDrawerLayout closableDrawerLayout = (ClosableDrawerLayout) LayoutInflater.from(this).inflate(R.layout.navigation_drawer_layout, null, false);
// Get CoordinatorLayout using resource ID
CoordinatorLayout coordinatorLayout = (CoordinatorLayout) LayoutInflater.from(this).inflate(layoutResID, closableDrawerLayout, false);
if (preferences.getBoolean(FULL_SCREEN_NAVIGATION_DRAWER, false)) {
// If full screen navigation drawer is needed, then add FullDraggableContainer as a child view of closableDrawerLayout.
// Then add coordinatorLayout as a child view of fullDraggableContainer.
FullDraggableContainer fullDraggableContainer = new FullDraggableContainer(this);
fullDraggableContainer.addView(coordinatorLayout);
closableDrawerLayout.addView(fullDraggableContainer, 0);
} else {
// If full screen navigation drawer is not needed, then directly add coordinatorLayout as the child view.
closableDrawerLayout.addView(coordinatorLayout, 0);
}

setContentView(closableDrawerLayout);
}

// Navigation drawer initialisation
protected void initNavigationDrawer(View mainView) {
// Create inherited navigation drawer layout here so that it can be used by parent class
Expand Down
Expand Up @@ -46,7 +46,7 @@ protected void onCreate(Bundle savedInstanceState) {
// to android.R.id.content when an action bar is used in Android 2.1 (and potentially
// higher) with the appcompat package.
View mainView = getLayoutInflater().inflate(R.layout.studyoptions, null);
setContentView(mainView);
setContentView(R.layout.studyoptions);
// create inherited navigation drawer layout here so that it can be used by parent class
initNavigationDrawer(mainView);
if (savedInstanceState == null) {
Expand Down
114 changes: 50 additions & 64 deletions AnkiDroid/src/main/res/layout-television/reviewer.xml
Expand Up @@ -15,75 +15,61 @@
~ this program. If not, see <http://www.gnu.org/licenses/>.
-->

<androidx.drawerlayout.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fitsSystemWindows="true"
android:focusable="false" >
<!-- First child of DrawerLayout assumed to be main content, others are drawers.
We use a Coordinator layout as root View for main content as it allows snackbars
to be swiped off screen. Other behaviors can also be added in the future if necessary -->
<com.drakeet.drawer.FullDraggableContainer
<!-- First child of DrawerLayout assumed to be main content, others are drawers.
We use a Coordinator layout as root View for main content as it allows snackbars
to be swiped off screen. Other behaviors can also be added in the future if necessary -->
<androidx.coordinatorlayout.widget.CoordinatorLayout android:id="@+id/root_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Bring in each component from separate files as we have fullscreen versions of reviewer -->
<RelativeLayout
android:id="@+id/front_frame"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:id="@+id/root_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<!-- Bring in each component from separate files as we have fullscreen versions of reviewer -->
<RelativeLayout
android:id="@+id/front_frame"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include layout="@layout/toolbar"
android:focusable="false" />
<include layout="@layout/toolbar"
android:focusable="false" />

<include
layout="@layout/reviewer_topbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/toolbar"
android:focusable="false" />
<include
layout="@layout/reviewer_topbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/toolbar"
android:focusable="false" />

<include
layout="@layout/reviewer_mic_tool_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/top_bar"
android:focusable="false"/>
<include
layout="@layout/reviewer_mic_tool_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/top_bar"
android:focusable="false"/>

<include
layout="@layout/reviewer_flashcard"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/mic_tool_bar_layer"
android:focusable="false" />
<include
layout="@layout/reviewer_flashcard"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/mic_tool_bar_layer"
android:focusable="false" />

<include
android:id="@+id/reviewer_whiteboard_pen_color_layout"
layout="@layout/reviewer_whiteboard_editor"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_above="@+id/bottom_area_layout"
android:focusable="true" />
<include
android:id="@+id/reviewer_whiteboard_pen_color_layout"
layout="@layout/reviewer_whiteboard_editor"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_above="@+id/bottom_area_layout"
android:focusable="true" />

<!-- Move this to AnkiActivity -->
<com.ichi2.ui.TvNavigationElement
android:id="@+id/tv_nav_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusable="true"/>
<!-- Move this to AnkiActivity -->
<com.ichi2.ui.TvNavigationElement
android:id="@+id/tv_nav_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusable="true"/>

<include layout="@layout/reviewer_answer_buttons"
android:focusable="true" >
<requestFocus />
</include>
</RelativeLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
</com.drakeet.drawer.FullDraggableContainer>
<!-- Left navigation drawer -->
<include layout="@layout/navigation_drawer" />
</androidx.drawerlayout.widget.DrawerLayout>
<include layout="@layout/reviewer_answer_buttons"
android:focusable="true" >
<requestFocus />
</include>
</RelativeLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
11 changes: 2 additions & 9 deletions AnkiDroid/src/main/res/layout-xlarge/homescreen.xml
@@ -1,13 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.widget.ClosableDrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?android:attr/colorBackground"
android:fitsSystemWindows="true">
<com.drakeet.drawer.FullDraggableContainer
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/deckpicker_view"
android:layout_width="fill_parent"
Expand All @@ -24,7 +19,5 @@
android:layout_width="1dip"
android:layout_height="fill_parent"/>
</LinearLayout>
</com.drakeet.drawer.FullDraggableContainer>
<include layout="@layout/navigation_drawer" />
</androidx.drawerlayout.widget.ClosableDrawerLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>

62 changes: 25 additions & 37 deletions AnkiDroid/src/main/res/layout/activity_anki_stats.xml
@@ -1,40 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.widget.ClosableDrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<com.drakeet.drawer.FullDraggableContainer
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:id="@+id/root_layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<androidx.coordinatorlayout.widget.CoordinatorLayout android:id="@+id/root_layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<LinearLayout android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<include layout="@layout/toolbar" />
<include layout="@layout/toolbar" />

<com.google.android.material.tabs.TabLayout
android:id="@+id/sliding_tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabIndicatorHeight="8dp"
app:tabIndicatorColor="@color/theme_light_primary"
app:tabMode="scrollable"/>
<androidx.viewpager2.widget.ViewPager2
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Statistics"/>
</LinearLayout>
<include layout="@layout/anki_progress"/>
</androidx.coordinatorlayout.widget.CoordinatorLayout>

</com.drakeet.drawer.FullDraggableContainer>
<include layout="@layout/navigation_drawer" />
</androidx.drawerlayout.widget.ClosableDrawerLayout>
<com.google.android.material.tabs.TabLayout
android:id="@+id/sliding_tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabIndicatorHeight="8dp"
app:tabIndicatorColor="@color/theme_light_primary"
app:tabMode="scrollable"/>
<androidx.viewpager2.widget.ViewPager2
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Statistics"/>
</LinearLayout>
<include layout="@layout/anki_progress"/>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
108 changes: 49 additions & 59 deletions AnkiDroid/src/main/res/layout/card_browser.xml
@@ -1,61 +1,51 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.widget.ClosableDrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<com.drakeet.drawer.FullDraggableContainer
android:layout_width="match_parent"
android:layout_height="match_parent">

<androidx.coordinatorlayout.widget.CoordinatorLayout
android:id="@+id/root_layout"

<androidx.coordinatorlayout.widget.CoordinatorLayout
android:id="@+id/root_layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<include layout="@layout/toolbar" />

<LinearLayout
android:layout_width="match_parent"
android:background="?android:attr/colorBackground"
android:orientation="horizontal"
style="@style/card_browser_spinner_layout">

<Spinner
android:id="@+id/browser_column1_spinner"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
app:popupTheme="@style/ActionBar.Popup" />

<Spinner
android:id="@+id/browser_column2_spinner"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
app:popupTheme="@style/ActionBar.Popup" />
</LinearLayout>

<ListView
android:id="@+id/card_browser_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<include layout="@layout/toolbar" />

<LinearLayout
android:layout_width="match_parent"
android:background="?android:attr/colorBackground"
android:orientation="horizontal"
style="@style/card_browser_spinner_layout">

<Spinner
android:id="@+id/browser_column1_spinner"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
app:popupTheme="@style/ActionBar.Popup" />

<Spinner
android:id="@+id/browser_column2_spinner"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
app:popupTheme="@style/ActionBar.Popup" />
</LinearLayout>

<ListView
android:id="@+id/card_browser_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="?android:attr/colorBackground"
android:divider="?attr/cardBrowserDivider"
android:overScrollFooter="@color/transparent"
android:dividerHeight="0.5dp"
android:drawSelectorOnTop="true"
android:fastScrollEnabled="true" />

</LinearLayout>
<include layout="@layout/anki_progress"/>
</androidx.coordinatorlayout.widget.CoordinatorLayout>

</com.drakeet.drawer.FullDraggableContainer>
<include layout="@layout/navigation_drawer" />
</androidx.drawerlayout.widget.ClosableDrawerLayout>
android:layout_height="fill_parent"
android:background="?android:attr/colorBackground"
android:divider="?attr/cardBrowserDivider"
android:overScrollFooter="@color/transparent"
android:dividerHeight="0.5dp"
android:drawSelectorOnTop="true"
android:fastScrollEnabled="true" />

</LinearLayout>
<include layout="@layout/anki_progress"/>
</androidx.coordinatorlayout.widget.CoordinatorLayout>

0 comments on commit d0d1edd

Please sign in to comment.