From e1884a6e8eda44becde1471c839985b88c8075b2 Mon Sep 17 00:00:00 2001 From: M66B Date: Thu, 2 Jan 2020 10:37:08 +0100 Subject: [PATCH] Three column layout - proof of concept --- .../java/eu/faircode/email/ActivityView.java | 6 +- .../eu/faircode/email/DrawerLayoutEx.java | 87 +++++++++++++++++++ .../res/layout/activity_view_landscape.xml | 4 +- .../res/layout/activity_view_portrait.xml | 4 +- 4 files changed, 95 insertions(+), 6 deletions(-) create mode 100644 app/src/main/java/eu/faircode/email/DrawerLayoutEx.java diff --git a/app/src/main/java/eu/faircode/email/ActivityView.java b/app/src/main/java/eu/faircode/email/ActivityView.java index 0cb5d97471..2a85b7d570 100644 --- a/app/src/main/java/eu/faircode/email/ActivityView.java +++ b/app/src/main/java/eu/faircode/email/ActivityView.java @@ -88,7 +88,7 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB private View content_separator; private View content_pane; - private DrawerLayout drawerLayout; + private DrawerLayoutEx drawerLayout; private ActionBarDrawerToggle drawerToggle; private ScrollView drawerContainer; private RecyclerView rvAccount; @@ -154,7 +154,8 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB content_pane = findViewById(R.id.content_pane); drawerLayout = findViewById(R.id.drawer_layout); - drawerLayout.setScrimColor(Helper.resolveColor(this, R.attr.colorDrawerScrim)); + drawerLayout.setup(getResources().getConfiguration()); + // drawerLayout.setScrimColor(Helper.resolveColor(this, R.attr.colorDrawerScrim)); drawerToggle = new ActionBarDrawerToggle(this, drawerLayout, R.string.app_name, R.string.app_name) { public void onDrawerClosed(View view) { @@ -541,6 +542,7 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB @Override public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); + drawerLayout.setup(newConfig); drawerToggle.onConfigurationChanged(newConfig); } diff --git a/app/src/main/java/eu/faircode/email/DrawerLayoutEx.java b/app/src/main/java/eu/faircode/email/DrawerLayoutEx.java new file mode 100644 index 0000000000..4d5762bab7 --- /dev/null +++ b/app/src/main/java/eu/faircode/email/DrawerLayoutEx.java @@ -0,0 +1,87 @@ +package eu.faircode.email; + +/* + This file is part of FairEmail. + + FairEmail is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + FairEmail is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with FairEmail. If not, see . + + Copyright 2018-2019 by Marcel Bokhorst (M66B) +*/ + +import android.content.Context; +import android.content.res.Configuration; +import android.graphics.Color; +import android.util.AttributeSet; +import android.view.MotionEvent; +import android.view.View; +import android.view.ViewGroup; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.drawerlayout.widget.DrawerLayout; + +public class DrawerLayoutEx extends DrawerLayout { + private boolean locked; + + public DrawerLayoutEx(@NonNull Context context) { + super(context); + } + + public DrawerLayoutEx(@NonNull Context context, @Nullable AttributeSet attrs) { + super(context, attrs); + } + + public DrawerLayoutEx(@NonNull Context context, @Nullable AttributeSet attrs, int defStyle) { + super(context, attrs, defStyle); + } + + void setup(Configuration config) { + Log.i("Drawer setup orientation=" + config.orientation); + ViewGroup childContent = (ViewGroup) getChildAt(0); + ViewGroup childDrawer = (ViewGroup) getChildAt(1); + if (config.orientation == Configuration.ORIENTATION_LANDSCAPE) { + locked = true; + setDrawerLockMode(LOCK_MODE_LOCKED_OPEN); + setScrimColor(Color.TRANSPARENT); + childContent.setPaddingRelative(childDrawer.getLayoutParams().width, 0, 0, 0); + } else { + locked = false; + setDrawerLockMode(LOCK_MODE_UNLOCKED); + setScrimColor(Helper.resolveColor(getContext(), R.attr.colorDrawerScrim)); + childContent.setPaddingRelative(0, 0, 0, 0); + closeDrawers(); + } + } + + @Override + public boolean isDrawerOpen(@NonNull View drawer) { + return (!locked && super.isDrawerOpen(drawer)); + } + + @Override + public boolean isDrawerOpen(int drawerGravity) { + return (!locked && super.isDrawerOpen(drawerGravity)); + } + + @Override + public boolean onInterceptTouchEvent(final MotionEvent ev) { + return (!locked && super.onInterceptTouchEvent(ev)); + } + + @Override + public void closeDrawer(@NonNull View drawerView) { + if (!locked) + super.closeDrawer(drawerView); + } +} diff --git a/app/src/main/res/layout/activity_view_landscape.xml b/app/src/main/res/layout/activity_view_landscape.xml index d9d5bd0b45..78ae7f9d41 100644 --- a/app/src/main/res/layout/activity_view_landscape.xml +++ b/app/src/main/res/layout/activity_view_landscape.xml @@ -1,4 +1,4 @@ - - + diff --git a/app/src/main/res/layout/activity_view_portrait.xml b/app/src/main/res/layout/activity_view_portrait.xml index 4beddfd817..90f3d96e3b 100644 --- a/app/src/main/res/layout/activity_view_portrait.xml +++ b/app/src/main/res/layout/activity_view_portrait.xml @@ -1,4 +1,4 @@ - - +