collapsing toolbar

This commit is contained in:
veliymolfar 2020-02-24 16:34:05 +02:00
parent a28d9f84c4
commit ff570d4b81
6 changed files with 290 additions and 182 deletions

View file

@ -1,40 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:osmand="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/activity_background_basic"
android:orientation="vertical">
android:background="?attr/activity_background_basic">
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
osmand:layout_behavior="@string/appbar_scrolling_view_behavior">
<LinearLayout
android:id="@+id/toolbar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="@dimen/toolbar_height"
android:minHeight="@dimen/toolbar_height" />
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingStart="@dimen/content_padding"
android:paddingTop="@dimen/list_header_settings_top_margin"
android:paddingEnd="@dimen/content_padding"
android:paddingBottom="@dimen/list_header_settings_top_margin"
android:text="@string/shared_string_import"
android:textColor="?attr/app_bar_primary_item_color"
android:textSize="@dimen/dialog_header_text_size"
osmand:typeface="@string/font_roboto_medium" />
</LinearLayout>
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/description"
android:layout_width="match_parent"
@ -50,25 +31,35 @@
<include layout="@layout/card_bottom_divider" />
<ExpandableListView
<net.osmand.view.NonScrollExpandableList
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:divider="@null"
android:dividerHeight="0dp"
android:drawSelectorOnTop="false"
android:groupIndicator="@android:color/transparent"
android:listSelector="@android:color/transparent" />
android:listSelector="@android:color/transparent"
android:paddingBottom="@dimen/dialog_button_ex_height" />
<include layout="@layout/divider" />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
<LinearLayout
android:id="@+id/buttons_container"
android:layout_width="match_parent"
android:layout_height="@dimen/dialog_button_ex_height"
android:layout_gravity="bottom"
android:background="?attr/bg_color"
android:gravity="center"
android:orientation="vertical">
<include layout="@layout/divider" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:paddingLeft="@dimen/content_padding"
android:paddingTop="@dimen/content_padding_small"
@ -132,4 +123,35 @@
</LinearLayout>
</LinearLayout>
</LinearLayout>
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/actionModeBackground">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/toolbar_layout"
android:layout_width="match_parent"
android:layout_height="@dimen/toolbar_height_expanded"
osmand:collapsedTitleTextAppearance="@style/AppBarTitle"
osmand:expandedTitleGravity="start|bottom"
osmand:expandedTitleTextAppearance="@style/AppBarTitle"
osmand:layout_scrollFlags="scroll|exitUntilCollapsed">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="@dimen/toolbar_height"
android:minHeight="@dimen/toolbar_height"
osmand:layout_collapseMode="pin"
osmand:layout_scrollFlags="scroll|enterAlways|exitUntilCollapsed"
osmand:title="@string/shared_string_import">
</android.support.v7.widget.Toolbar>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
</android.support.design.widget.CoordinatorLayout>

View file

@ -1,38 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:osmand="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/activity_background_basic"
android:orientation="vertical">
android:background="?attr/activity_background_basic">
<android.support.v4.widget.NestedScrollView
android:id="@+id/nested_scroll"
android:layout_width="match_parent"
android:layout_height="match_parent"
osmand:layout_behavior="@string/appbar_scrolling_view_behavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="@dimen/toolbar_height"
android:minHeight="@dimen/toolbar_height" />
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingStart="@dimen/content_padding"
android:paddingTop="@dimen/list_header_settings_top_margin"
android:paddingEnd="@dimen/content_padding"
android:paddingBottom="@dimen/list_header_settings_top_margin"
android:text="@string/import_duplicates_title"
android:textColor="?attr/app_bar_primary_item_color"
android:textSize="@dimen/dialog_header_text_size"
osmand:typeface="@string/font_roboto_medium" />
</LinearLayout>
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/description"
android:layout_width="match_parent"
@ -56,12 +39,23 @@
android:layout_height="0dp"
android:layout_weight="1" />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
<LinearLayout
android:id="@+id/buttons_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="?attr/bg_color"
android:orientation="vertical">
<include layout="@layout/divider" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/bg_color"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="@dimen/content_padding">
@ -100,6 +94,39 @@
</FrameLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/actionModeBackground">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/toolbar_layout"
android:layout_width="match_parent"
android:layout_height="@dimen/toolbar_height_expanded"
osmand:collapsedTitleTextAppearance="@style/AppBarTitle"
osmand:expandedTitleGravity="start|bottom"
osmand:expandedTitleTextAppearance="@style/AppBarTitle"
osmand:layout_scrollFlags="scroll|exitUntilCollapsed">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="@dimen/toolbar_height"
android:minHeight="@dimen/toolbar_height"
osmand:layout_collapseMode="pin"
osmand:layout_scrollFlags="scroll|enterAlways|exitUntilCollapsed"
osmand:title="@string/shared_string_import">
</android.support.v7.widget.Toolbar>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
</android.support.design.widget.CoordinatorLayout>

View file

@ -319,6 +319,7 @@
<dimen name="coords_input_keyboard_item_height">56dp</dimen>
<dimen name="toolbar_height">56dp</dimen>
<dimen name="toolbar_height_expanded">112dp</dimen>
<dimen name="wikivoyage_search_list_header_height">36dp</dimen>
<dimen name="wikivoyage_article_card_icon_size">80dp</dimen>

View file

@ -749,4 +749,9 @@
<item name="colorControlHighlight">?attr/app_bar_primary_item_color</item>
</style>
<style name="AppBarTitle" parent="TextAppearance.AppCompat.Title">
<item name="android:textColor">?attr/app_bar_primary_item_color</item>
<item name="android:textSize">@dimen/dialog_header_text_size</item>
</style>
</resources>

View file

@ -1,16 +1,20 @@
package net.osmand.plus.settings;
import android.app.Dialog;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.FragmentManager;
import android.support.v4.widget.NestedScrollView;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.widget.LinearLayout;
import net.osmand.map.ITileSource;
import net.osmand.plus.AppInitializer;
@ -38,9 +42,10 @@ public class ImportDuplicatesFragment extends BaseOsmAndDialogFragment implement
public static final String TAG = ImportSettingsFragment.class.getSimpleName();
private OsmandApplication app;
private RecyclerView list;
private LinearLayout buttonsContainer;
private NestedScrollView nestedScroll;
private List<? super Object> duplicatesList;
private List<SettingsItem> settingsItems;
private DuplicatesSettingsAdapter adapter;
private File file;
private boolean nightMode;
@ -82,6 +87,8 @@ public class ImportDuplicatesFragment extends BaseOsmAndDialogFragment implement
setupToolbar((Toolbar) root.findViewById(R.id.toolbar));
ComplexButton replaceAllBtn = root.findViewById(R.id.replace_all_btn);
ComplexButton keepBothBtn = root.findViewById(R.id.keep_both_btn);
buttonsContainer = root.findViewById(R.id.buttons_container);
nestedScroll = root.findViewById(R.id.nested_scroll);
keepBothBtn.setIcon(getPaintedContentIcon(R.drawable.ic_action_keep_both,
nightMode
? getResources().getColor(R.color.icon_color_active_dark)
@ -95,6 +102,22 @@ public class ImportDuplicatesFragment extends BaseOsmAndDialogFragment implement
keepBothBtn.setOnClickListener(this);
replaceAllBtn.setOnClickListener(this);
list = root.findViewById(R.id.list);
ViewTreeObserver treeObserver = buttonsContainer.getViewTreeObserver();
treeObserver.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
if (buttonsContainer != null) {
ViewTreeObserver vts = buttonsContainer.getViewTreeObserver();
int height = buttonsContainer.getMeasuredHeight();
nestedScroll.setPadding(0, 0, 0, height);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
vts.removeOnGlobalLayoutListener(this);
} else {
vts.removeGlobalOnLayoutListener(this);
}
}
}
});
return root;
}
@ -117,7 +140,7 @@ public class ImportDuplicatesFragment extends BaseOsmAndDialogFragment implement
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
adapter = new DuplicatesSettingsAdapter(getMyApplication(), prepareDuplicates(), nightMode);
DuplicatesSettingsAdapter adapter = new DuplicatesSettingsAdapter(getMyApplication(), prepareDuplicates(), nightMode);
list.setLayoutManager(new LinearLayoutManager(getMyApplication()));
list.setAdapter(adapter);
}
@ -236,6 +259,7 @@ public class ImportDuplicatesFragment extends BaseOsmAndDialogFragment implement
dismiss();
}
});
toolbar.setTitle(getString(R.string.import_duplicates_title));
}
public void setDuplicatesList(List<? super Object> duplicatesList) {

View file

@ -0,0 +1,29 @@
package net.osmand.view;
import android.content.Context;
import android.util.AttributeSet;
import android.view.ViewGroup;
import android.widget.ExpandableListView;
public class NonScrollExpandableList extends ExpandableListView {
public NonScrollExpandableList(Context context) {
super(context);
}
public NonScrollExpandableList(Context context, AttributeSet attrs) {
super(context, attrs);
}
public NonScrollExpandableList(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Override
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int heightMeasureSpec_custom = MeasureSpec.makeMeasureSpec(
Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);
super.onMeasure(widthMeasureSpec, heightMeasureSpec_custom);
ViewGroup.LayoutParams params = getLayoutParams();
params.height = getMeasuredHeight();
}
}