diff options
author | Roman Romanov <rromanov@65gb.net> | 2016-12-16 15:23:26 +0300 |
---|---|---|
committer | Roman Romanov <rromanov@65gb.net> | 2016-12-30 08:05:45 +0300 |
commit | f9bd8e5bbd84a9cf1c85ab5eb10a3525fb9da3c5 (patch) | |
tree | b32455dccdc0f3d29dc4e1091dad46740840219d /android | |
parent | 722549559edc5de094c9759a879ab1fe89d1df51 (diff) |
[android] Placeholders refactoring
Diffstat (limited to 'android')
35 files changed, 257 insertions, 56 deletions
diff --git a/android/AndroidManifest.xml b/android/AndroidManifest.xml index af1a0b02e9..3a652ef716 100644 --- a/android/AndroidManifest.xml +++ b/android/AndroidManifest.xml @@ -188,7 +188,8 @@ android:name="com.mapswithme.maps.downloader.DownloaderActivity" android:configChanges="orientation|screenLayout|screenSize" android:label="@string/download_maps" - android:parentActivityName="com.mapswithme.maps.MwmActivity"> + android:parentActivityName="com.mapswithme.maps.MwmActivity" + android:windowSoftInputMode="adjustResize"> <!-- The meta-data element is needed for versions lower than 4.1 --> <meta-data android:name="android.support.PARENT_ACTIVITY" @@ -200,7 +201,7 @@ android:configChanges="orientation|screenLayout|screenSize" android:label="@string/search_map" android:parentActivityName="com.mapswithme.maps.MwmActivity" - android:windowSoftInputMode="stateVisible|adjustNothing"> + android:windowSoftInputMode="stateVisible|adjustResize"> <!-- The meta-data element is needed for versions lower than 4.1 --> <meta-data android:name="android.support.PARENT_ACTIVITY" @@ -222,7 +223,8 @@ android:name="com.mapswithme.maps.bookmarks.BookmarkCategoriesActivity" android:configChanges="orientation|screenLayout|screenSize" android:label="@string/bookmark_sets" - android:parentActivityName="com.mapswithme.maps.MwmActivity"> + android:parentActivityName="com.mapswithme.maps.MwmActivity" + android:windowSoftInputMode="adjustResize"> <!-- The meta-data element is needed for versions lower than 4.1 --> <meta-data android:name="android.support.PARENT_ACTIVITY" @@ -233,7 +235,8 @@ android:name="com.mapswithme.maps.bookmarks.BookmarkListActivity" android:configChanges="orientation|screenLayout|screenSize" android:label="@string/bookmarks" - android:parentActivityName="com.mapswithme.maps.bookmarks.BookmarkCategoriesActivity"> + android:parentActivityName="com.mapswithme.maps.bookmarks.BookmarkCategoriesActivity" + android:windowSoftInputMode="adjustResize"> <!-- The meta-data element is needed for versions lower than 4.1 --> <meta-data android:name="android.support.PARENT_ACTIVITY" diff --git a/android/res/drawable-hdpi/img_bookmarks.png b/android/res/drawable-hdpi/img_bookmarks.png Binary files differnew file mode 100644 index 0000000000..2c5859d205 --- /dev/null +++ b/android/res/drawable-hdpi/img_bookmarks.png diff --git a/android/res/drawable-hdpi/img_search_empty_history_light.png b/android/res/drawable-hdpi/img_search_empty_history_light.png Binary files differindex fb60113e80..b1446c048c 100644 --- a/android/res/drawable-hdpi/img_search_empty_history_light.png +++ b/android/res/drawable-hdpi/img_search_empty_history_light.png diff --git a/android/res/drawable-hdpi/img_search_no_maps.png b/android/res/drawable-hdpi/img_search_no_maps.png Binary files differindex 4e6de48c9f..963a1f5292 100644 --- a/android/res/drawable-hdpi/img_search_no_maps.png +++ b/android/res/drawable-hdpi/img_search_no_maps.png diff --git a/android/res/drawable-hdpi/img_search_nothing_found_light.png b/android/res/drawable-hdpi/img_search_nothing_found_light.png Binary files differindex e17d61ddc7..ecc6bb8d51 100644 --- a/android/res/drawable-hdpi/img_search_nothing_found_light.png +++ b/android/res/drawable-hdpi/img_search_nothing_found_light.png diff --git a/android/res/drawable-mdpi/img_bookmarks.png b/android/res/drawable-mdpi/img_bookmarks.png Binary files differnew file mode 100644 index 0000000000..d13272cf3b --- /dev/null +++ b/android/res/drawable-mdpi/img_bookmarks.png diff --git a/android/res/drawable-mdpi/img_search_empty_history_light.png b/android/res/drawable-mdpi/img_search_empty_history_light.png Binary files differindex 2bc91a7e9d..51cb38de69 100644 --- a/android/res/drawable-mdpi/img_search_empty_history_light.png +++ b/android/res/drawable-mdpi/img_search_empty_history_light.png diff --git a/android/res/drawable-mdpi/img_search_no_maps.png b/android/res/drawable-mdpi/img_search_no_maps.png Binary files differindex 0cd215ade8..86c37b9083 100644 --- a/android/res/drawable-mdpi/img_search_no_maps.png +++ b/android/res/drawable-mdpi/img_search_no_maps.png diff --git a/android/res/drawable-mdpi/img_search_nothing_found_light.png b/android/res/drawable-mdpi/img_search_nothing_found_light.png Binary files differindex 8d7a400526..2a5db2792a 100644 --- a/android/res/drawable-mdpi/img_search_nothing_found_light.png +++ b/android/res/drawable-mdpi/img_search_nothing_found_light.png diff --git a/android/res/drawable-xhdpi/img_bookmarks.png b/android/res/drawable-xhdpi/img_bookmarks.png Binary files differnew file mode 100644 index 0000000000..60a7e1a292 --- /dev/null +++ b/android/res/drawable-xhdpi/img_bookmarks.png diff --git a/android/res/drawable-xhdpi/img_search_empty_history_light.png b/android/res/drawable-xhdpi/img_search_empty_history_light.png Binary files differindex 0753c50296..6cff2039a5 100644 --- a/android/res/drawable-xhdpi/img_search_empty_history_light.png +++ b/android/res/drawable-xhdpi/img_search_empty_history_light.png diff --git a/android/res/drawable-xhdpi/img_search_no_maps.png b/android/res/drawable-xhdpi/img_search_no_maps.png Binary files differindex f1247391e2..73ec795350 100644 --- a/android/res/drawable-xhdpi/img_search_no_maps.png +++ b/android/res/drawable-xhdpi/img_search_no_maps.png diff --git a/android/res/drawable-xhdpi/img_search_nothing_found_light.png b/android/res/drawable-xhdpi/img_search_nothing_found_light.png Binary files differindex 1f47051a99..dacd25877d 100644 --- a/android/res/drawable-xhdpi/img_search_nothing_found_light.png +++ b/android/res/drawable-xhdpi/img_search_nothing_found_light.png diff --git a/android/res/drawable-xxhdpi/img_bookmarks.png b/android/res/drawable-xxhdpi/img_bookmarks.png Binary files differnew file mode 100644 index 0000000000..c31d335f51 --- /dev/null +++ b/android/res/drawable-xxhdpi/img_bookmarks.png diff --git a/android/res/drawable-xxhdpi/img_search_empty_history_light.png b/android/res/drawable-xxhdpi/img_search_empty_history_light.png Binary files differindex a75dae2858..fbaa250935 100644 --- a/android/res/drawable-xxhdpi/img_search_empty_history_light.png +++ b/android/res/drawable-xxhdpi/img_search_empty_history_light.png diff --git a/android/res/drawable-xxhdpi/img_search_no_maps.png b/android/res/drawable-xxhdpi/img_search_no_maps.png Binary files differindex 576c7ce7b9..5914f4a614 100644 --- a/android/res/drawable-xxhdpi/img_search_no_maps.png +++ b/android/res/drawable-xxhdpi/img_search_no_maps.png diff --git a/android/res/drawable-xxhdpi/img_search_nothing_found_light.png b/android/res/drawable-xxhdpi/img_search_nothing_found_light.png Binary files differindex 7c37f2b3a7..e499063c2d 100644 --- a/android/res/drawable-xxhdpi/img_search_nothing_found_light.png +++ b/android/res/drawable-xxhdpi/img_search_nothing_found_light.png diff --git a/android/res/drawable-xxxhdpi/img_bookmarks.png b/android/res/drawable-xxxhdpi/img_bookmarks.png Binary files differnew file mode 100644 index 0000000000..17a3c27cca --- /dev/null +++ b/android/res/drawable-xxxhdpi/img_bookmarks.png diff --git a/android/res/drawable-xxxhdpi/img_search_empty_history_light.png b/android/res/drawable-xxxhdpi/img_search_empty_history_light.png Binary files differindex 28dbbe58e9..cd9edf3bf4 100644 --- a/android/res/drawable-xxxhdpi/img_search_empty_history_light.png +++ b/android/res/drawable-xxxhdpi/img_search_empty_history_light.png diff --git a/android/res/drawable-xxxhdpi/img_search_no_maps.png b/android/res/drawable-xxxhdpi/img_search_no_maps.png Binary files differindex b58caf0ac4..8ba681b8d1 100644 --- a/android/res/drawable-xxxhdpi/img_search_no_maps.png +++ b/android/res/drawable-xxxhdpi/img_search_no_maps.png diff --git a/android/res/drawable-xxxhdpi/img_search_nothing_found_light.png b/android/res/drawable-xxxhdpi/img_search_nothing_found_light.png Binary files differindex ed5f1ec380..c871030d33 100644 --- a/android/res/drawable-xxxhdpi/img_search_nothing_found_light.png +++ b/android/res/drawable-xxxhdpi/img_search_nothing_found_light.png diff --git a/android/res/layout/fragment_downloader.xml b/android/res/layout/fragment_downloader.xml index 47a3e3f0ac..53cf3d5eea 100644 --- a/android/res/layout/fragment_downloader.xml +++ b/android/res/layout/fragment_downloader.xml @@ -38,10 +38,15 @@ android:layout_marginBottom="@dimen/margin_base" android:src="?fabAdd"/> - <include - layout="@layout/placeholder" + <com.mapswithme.maps.widget.PlaceholderView + android:id="@+id/placeholder" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_below="@id/toolbar" - android:layout_above="@id/action"/> + android:layout_above="@id/action" + android:paddingLeft="@dimen/margin_double_and_half" + android:paddingRight="@dimen/margin_double_and_half" + android:paddingTop="@dimen/placeholder_margin_top" + android:visibility="gone" + tools:visibility="visible"/> </RelativeLayout> diff --git a/android/res/layout/fragment_search.xml b/android/res/layout/fragment_search.xml index fbbae56c08..ede639ea1f 100644 --- a/android/res/layout/fragment_search.xml +++ b/android/res/layout/fragment_search.xml @@ -57,7 +57,15 @@ android:background="?windowBackgroundForced"> <include layout="@layout/recycler_default"/> - <include layout="@layout/placeholder"/> + <com.mapswithme.maps.widget.PlaceholderView + android:id="@+id/placeholder" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:paddingLeft="@dimen/margin_double_and_half" + android:paddingRight="@dimen/margin_double_and_half" + android:paddingTop="@dimen/placeholder_margin_top" + android:visibility="gone" + tools:visibility="visible"/> </FrameLayout> <!-- Country download suggest fragment --> diff --git a/android/res/layout/fragment_search_base.xml b/android/res/layout/fragment_search_base.xml new file mode 100644 index 0000000000..a58a8d59a6 --- /dev/null +++ b/android/res/layout/fragment_search_base.xml @@ -0,0 +1,18 @@ +<?xml version="1.0" encoding="utf-8"?> +<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:tools="http://schemas.android.com/tools" + style="@style/MwmWidget.FrameLayout.Elevation" + android:layout_width="match_parent" + android:layout_height="match_parent"> + <include layout="@layout/recycler_default"/> + + <com.mapswithme.maps.widget.PlaceholderView + android:id="@+id/placeholder" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:paddingLeft="@dimen/margin_double_and_half" + android:paddingRight="@dimen/margin_double_and_half" + android:paddingTop="@dimen/placeholder_margin_top" + android:visibility="gone" + tools:visibility="visible"/> +</FrameLayout> diff --git a/android/res/layout/item_bookmark_hint.xml b/android/res/layout/item_bookmark_hint.xml index dc3c58d564..6bd587fbf0 100644 --- a/android/res/layout/item_bookmark_hint.xml +++ b/android/res/layout/item_bookmark_hint.xml @@ -9,5 +9,4 @@ android:paddingLeft="@dimen/margin_double_plus" android:paddingRight="@dimen/margin_double_plus" android:paddingTop="@dimen/margin_base" - android:text="@string/bookmarks_usage_hint" android:textAppearance="@style/MwmTextAppearance.Body2"/> diff --git a/android/res/layout/placeholder.xml b/android/res/layout/placeholder.xml index 6418eeb5ef..a4040473c2 100644 --- a/android/res/layout/placeholder.xml +++ b/android/res/layout/placeholder.xml @@ -1,36 +1,27 @@ <?xml version="1.0" encoding="utf-8"?> -<com.mapswithme.maps.widget.HeightLimitedFrameLayout +<merge xmlns:android="http://schemas.android.com/apk/res/android" - xmlns:tools="http://schemas.android.com/tools" - android:id="@+id/placeholder" - android:layout_width="match_parent" - android:layout_height="match_parent" - android:paddingLeft="@dimen/margin_half" - android:paddingRight="@dimen/margin_half" - android:visibility="gone" - tools:visibility="visible"> + xmlns:tools="http://schemas.android.com/tools"> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:minWidth="@dimen/placeholder_size" android:orientation="vertical" - android:layout_marginTop="@dimen/margin_double" android:layout_gravity="center_horizontal" android:gravity="center"> <ImageView android:id="@+id/image" android:layout_width="@dimen/placeholder_size" android:layout_height="@dimen/placeholder_size" - android:layout_marginBottom="@dimen/margin_base_plus" - android:tag="@string/tag_height_limited" + android:layout_marginBottom="@dimen/margin_half_plus" tools:src="@drawable/img_search_empty_history_light"/> <TextView android:id="@+id/title" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_marginBottom="@dimen/margin_base" - android:textAppearance="@style/MwmTextAppearance.Title" + android:layout_marginBottom="@dimen/margin_half_plus" + android:textAppearance="@style/MwmTextAppearance.Title.Toolbar" android:gravity="center_horizontal" tools:text="Some long long long placeholder title"/> @@ -38,8 +29,8 @@ android:id="@+id/subtitle" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:textAppearance="@style/MwmTextAppearance.Body2" + android:textAppearance="@style/MwmTextAppearance.Body3" android:gravity="center_horizontal" tools:text="Some placeholder text"/> </LinearLayout> -</com.mapswithme.maps.widget.HeightLimitedFrameLayout> +</merge> diff --git a/android/res/values/dimens.xml b/android/res/values/dimens.xml index b1480b7778..3366c797fc 100644 --- a/android/res/values/dimens.xml +++ b/android/res/values/dimens.xml @@ -45,6 +45,7 @@ <dimen name="panel_width">360dp</dimen> <dimen name="button_width">240dp</dimen> <dimen name="placeholder_size">200dp</dimen> + <dimen name="placeholder_size_small">160dp</dimen> <dimen name="width_dialog_base">300dp</dimen> @@ -170,4 +171,8 @@ <dimen name="placepage_taxi_button_min_width">96dp</dimen> <dimen name="placepage_taxi_padding_vert">14dp</dimen> <dimen name="placepage_taxi_button_padding_vert">10dp</dimen> + + <!-- Placeholder--> + <dimen name="placeholder_margin_top">20dp</dimen> + <dimen name="placeholder_margin_top_no_image">80dp</dimen> </resources> diff --git a/android/res/values/styles-text.xml b/android/res/values/styles-text.xml index 4786559b79..818deeb645 100644 --- a/android/res/values/styles-text.xml +++ b/android/res/values/styles-text.xml @@ -16,6 +16,11 @@ <item name="android:textColor">?android:textColorPrimary</item> </style> + <style name="MwmTextAppearance.Title.Toolbar"> + <item name="android:textSize">@dimen/text_size_toolbar</item> + <item name="android:fontFamily" tools:targetApi="jelly_bean">@string/robotoMedium</item> + </style> + <style name="MwmTextAppearance.Headline"> <item name="android:textSize">@dimen/text_size_headline</item> <item name="android:textColor">?android:textColorPrimary</item> diff --git a/android/src/com/mapswithme/maps/base/BaseMwmRecyclerFragment.java b/android/src/com/mapswithme/maps/base/BaseMwmRecyclerFragment.java index 6fb13643e1..4c8d0ec4ab 100644 --- a/android/src/com/mapswithme/maps/base/BaseMwmRecyclerFragment.java +++ b/android/src/com/mapswithme/maps/base/BaseMwmRecyclerFragment.java @@ -11,6 +11,7 @@ import android.view.View; import android.view.ViewGroup; import com.mapswithme.maps.R; +import com.mapswithme.maps.widget.PlaceholderView; import com.mapswithme.util.UiUtils; import com.mapswithme.util.Utils; @@ -18,7 +19,7 @@ public abstract class BaseMwmRecyclerFragment extends Fragment { private Toolbar mToolbar; private RecyclerView mRecycler; - private View mPlaceholder; + private PlaceholderView mPlaceholder; protected abstract RecyclerView.Adapter createAdapter(); @@ -66,7 +67,7 @@ public abstract class BaseMwmRecyclerFragment extends Fragment mRecycler.setLayoutManager(manager); mRecycler.setAdapter(createAdapter()); - mPlaceholder = view.findViewById(R.id.placeholder); + mPlaceholder = (PlaceholderView) view.findViewById(R.id.placeholder); setupPlaceholder(mPlaceholder); } @@ -95,7 +96,7 @@ public abstract class BaseMwmRecyclerFragment extends Fragment org.alohalytics.Statistics.logEvent("$onPause", this.getClass().getSimpleName()); } - protected void setupPlaceholder(View placeholder) {} + protected void setupPlaceholder(PlaceholderView placeholder) {} public void setupPlaceholder() { diff --git a/android/src/com/mapswithme/maps/bookmarks/BookmarkCategoriesFragment.java b/android/src/com/mapswithme/maps/bookmarks/BookmarkCategoriesFragment.java index 78754517d6..987efc8a9e 100644 --- a/android/src/com/mapswithme/maps/bookmarks/BookmarkCategoriesFragment.java +++ b/android/src/com/mapswithme/maps/bookmarks/BookmarkCategoriesFragment.java @@ -12,6 +12,7 @@ import com.mapswithme.maps.base.BaseMwmRecyclerFragment; import com.mapswithme.maps.bookmarks.data.BookmarkCategory; import com.mapswithme.maps.bookmarks.data.BookmarkManager; import com.mapswithme.maps.dialog.EditTextDialogFragment; +import com.mapswithme.maps.widget.PlaceholderView; import com.mapswithme.maps.widget.recycler.RecyclerClickListener; import com.mapswithme.maps.widget.recycler.RecyclerLongClickListener; import com.mapswithme.util.BottomSheetHelper; @@ -28,7 +29,7 @@ public class BookmarkCategoriesFragment extends BaseMwmRecyclerFragment @Override protected @LayoutRes int getLayoutRes() { - return R.layout.recycler_default; + return R.layout.fragment_search_base; } @Override @@ -50,6 +51,19 @@ public class BookmarkCategoriesFragment extends BaseMwmRecyclerFragment getAdapter().setOnClickListener(this); getAdapter().setOnLongClickListener(this); + getAdapter().registerAdapterDataObserver(new RecyclerView.AdapterDataObserver() + { + @Override + public void onChanged() + { + updateResultsPlaceholder(); + } + }); + } + + private void updateResultsPlaceholder() + { + showPlaceholder(getAdapter().getItemCount() == 1); } @Override @@ -126,4 +140,10 @@ public class BookmarkCategoriesFragment extends BaseMwmRecyclerFragment startActivity(new Intent(getActivity(), BookmarkListActivity.class) .putExtra(ChooseBookmarkCategoryFragment.CATEGORY_ID, position)); } + + @Override + protected void setupPlaceholder(PlaceholderView placeholder) + { + placeholder.setContent(R.drawable.img_bookmarks, R.string.bookmarks_empty_title, R.string.bookmarks_usage_hint); + } } diff --git a/android/src/com/mapswithme/maps/downloader/DownloaderFragment.java b/android/src/com/mapswithme/maps/downloader/DownloaderFragment.java index bed0dcb445..8be7992d7c 100644 --- a/android/src/com/mapswithme/maps/downloader/DownloaderFragment.java +++ b/android/src/com/mapswithme/maps/downloader/DownloaderFragment.java @@ -14,6 +14,7 @@ import com.mapswithme.maps.base.BaseMwmRecyclerFragment; import com.mapswithme.maps.base.OnBackPressListener; import com.mapswithme.maps.search.NativeMapSearchListener; import com.mapswithme.maps.search.SearchEngine; +import com.mapswithme.maps.widget.PlaceholderView; import com.mapswithme.util.UiUtils; public class DownloaderFragment extends BaseMwmRecyclerFragment @@ -205,13 +206,13 @@ public class DownloaderFragment extends BaseMwmRecyclerFragment } @Override - protected void setupPlaceholder(View placeholder) + protected void setupPlaceholder(PlaceholderView placeholder) { if (mAdapter.isSearchResultsMode()) - UiUtils.setupPlaceholder(placeholder, R.drawable.img_search_nothing_found_light, - R.string.search_not_found, R.string.search_not_found_query); + placeholder.setContent(R.drawable.img_search_nothing_found_light, + R.string.search_not_found, R.string.search_not_found_query); else - UiUtils.setupPlaceholder(placeholder, R.drawable.img_search_no_maps, - R.string.downloader_no_downloaded_maps_title, R.string.downloader_no_downloaded_maps_message); + placeholder.setContent(R.drawable.img_search_no_maps, + R.string.downloader_no_downloaded_maps_title, R.string.downloader_no_downloaded_maps_message); } } diff --git a/android/src/com/mapswithme/maps/search/SearchFragment.java b/android/src/com/mapswithme/maps/search/SearchFragment.java index 7dd1297e6e..423812203a 100644 --- a/android/src/com/mapswithme/maps/search/SearchFragment.java +++ b/android/src/com/mapswithme/maps/search/SearchFragment.java @@ -31,6 +31,7 @@ import com.mapswithme.maps.downloader.MapManager; import com.mapswithme.maps.location.LocationHelper; import com.mapswithme.maps.location.LocationListener; import com.mapswithme.maps.routing.RoutingController; +import com.mapswithme.maps.widget.PlaceholderView; import com.mapswithme.maps.widget.SearchToolbarController; import com.mapswithme.util.UiUtils; import com.mapswithme.util.Utils; @@ -122,7 +123,7 @@ public class SearchFragment extends BaseMwmFragment private View mTabFrame; private View mResultsFrame; - private View mResultsPlaceholder; + private PlaceholderView mResultsPlaceholder; private SearchToolbarController mToolbarController; @@ -232,8 +233,9 @@ public class SearchFragment extends BaseMwmFragment mResultsFrame = root.findViewById(R.id.results_frame); RecyclerView results = (RecyclerView) mResultsFrame.findViewById(R.id.recycler); setRecyclerScrollListener(results); - mResultsPlaceholder = mResultsFrame.findViewById(R.id.placeholder); - UiUtils.setupPlaceholder(mResultsPlaceholder, R.drawable.img_search_nothing_found_light, R.string.search_not_found, R.string.search_not_found_query); + mResultsPlaceholder = (PlaceholderView) mResultsFrame.findViewById(R.id.placeholder); + mResultsPlaceholder.setContent(R.drawable.img_search_nothing_found_light, + R.string.search_not_found, R.string.search_not_found_query); if (mSearchAdapter == null) { diff --git a/android/src/com/mapswithme/maps/search/SearchHistoryFragment.java b/android/src/com/mapswithme/maps/search/SearchHistoryFragment.java index ab88d93983..2c481d4423 100644 --- a/android/src/com/mapswithme/maps/search/SearchHistoryFragment.java +++ b/android/src/com/mapswithme/maps/search/SearchHistoryFragment.java @@ -7,12 +7,13 @@ import android.support.v7.widget.RecyclerView; import android.view.View; import com.mapswithme.maps.R; import com.mapswithme.maps.base.BaseMwmRecyclerFragment; +import com.mapswithme.maps.widget.PlaceholderView; import com.mapswithme.maps.widget.SearchToolbarController; import com.mapswithme.util.UiUtils; public class SearchHistoryFragment extends BaseMwmRecyclerFragment { - private View mPlaceHolder; + private PlaceholderView mPlaceHolder; private void updatePlaceholder() { @@ -28,15 +29,16 @@ public class SearchHistoryFragment extends BaseMwmRecyclerFragment @Override protected @LayoutRes int getLayoutRes() { - return R.layout.fragment_search_recent; + return R.layout.fragment_search_base; } @Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); - mPlaceHolder = view.findViewById(R.id.placeholder); - UiUtils.setupPlaceholder(mPlaceHolder, R.drawable.img_search_empty_history_light, R.string.search_history_title, R.string.search_history_text); + mPlaceHolder = (PlaceholderView) view.findViewById(R.id.placeholder); + mPlaceHolder.setContent(R.drawable.img_search_empty_history_light, + R.string.search_history_title, R.string.search_history_text); getAdapter().registerAdapterDataObserver(new RecyclerView.AdapterDataObserver() { diff --git a/android/src/com/mapswithme/maps/widget/PlaceholderView.java b/android/src/com/mapswithme/maps/widget/PlaceholderView.java new file mode 100644 index 0000000000..f2e132794f --- /dev/null +++ b/android/src/com/mapswithme/maps/widget/PlaceholderView.java @@ -0,0 +1,156 @@ +package com.mapswithme.maps.widget; + +import android.annotation.TargetApi; +import android.content.Context; +import android.content.res.Configuration; +import android.content.res.Resources; +import android.os.Build; +import android.support.annotation.DrawableRes; +import android.support.annotation.Nullable; +import android.support.annotation.StringRes; +import android.support.v4.view.ViewCompat; +import android.support.v4.view.WindowInsetsCompat; +import android.util.AttributeSet; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.FrameLayout; +import android.widget.ImageView; +import android.widget.TextView; + +import com.mapswithme.maps.R; +import com.mapswithme.util.UiUtils; + +public class PlaceholderView extends FrameLayout +{ + @Nullable + private ImageView mImage; + @Nullable + private TextView mTitle; + @Nullable + private TextView mSubtitle; + + private final float mImageSizeFull; + private final float mImageSizeSmall; + private final float mPaddingImage; + private final float mPaddingNoImage; + private final float mScreenHeight; + private final float mScreenWidth; + + private int mOrientation; + + public PlaceholderView(Context context) + { + this(context, null, 0, 0); + } + + public PlaceholderView(Context context, @Nullable AttributeSet attrs) + { + this(context, attrs, 0, 0); + } + + public PlaceholderView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) + { + this(context, attrs, defStyleAttr, 0); + } + + @TargetApi(Build.VERSION_CODES.LOLLIPOP) + public PlaceholderView(Context context, @Nullable AttributeSet attrs, int defStyleAttr, + int defStyleRes) + { + super(context, attrs, defStyleAttr, defStyleRes); + + Resources res = getResources(); + mImageSizeFull = res.getDimension(R.dimen.placeholder_size); + mImageSizeSmall = res.getDimension(R.dimen.placeholder_size_small); + mPaddingImage = res.getDimension(R.dimen.placeholder_margin_top); + mPaddingNoImage = res.getDimension(R.dimen.placeholder_margin_top_no_image); + mScreenHeight = res.getDisplayMetrics().heightPixels; + mScreenWidth = res.getDisplayMetrics().widthPixels; + LayoutInflater.from(context).inflate(R.layout.placeholder, this, true); + } + + @Override + protected void onFinishInflate() + { + super.onFinishInflate(); + + mImage = (ImageView) findViewById(R.id.image); + mTitle = (TextView) findViewById(R.id.title); + mSubtitle = (TextView) findViewById(R.id.subtitle); + + ViewCompat.setOnApplyWindowInsetsListener(this, new android.support.v4.view.OnApplyWindowInsetsListener() + { + @Override + public WindowInsetsCompat onApplyWindowInsets(View v, WindowInsetsCompat insets) + { + int height = (int) (mOrientation == Configuration.ORIENTATION_LANDSCAPE + ? mScreenWidth : mScreenHeight); + int[] location = new int[2]; + getLocationOnScreen(location); + ViewGroup.LayoutParams lp = getLayoutParams(); + lp.height = height - insets.getSystemWindowInsetBottom() - location[1]; + setLayoutParams(lp); + return insets; + } + }); + } + + @Override + protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) + { + if (isInEditMode() || mImage == null) + { + super.onMeasure(widthMeasureSpec, heightMeasureSpec); + return; + } + + if (mOrientation == Configuration.ORIENTATION_LANDSCAPE) + { + UiUtils.hide(mImage); + setPadding(getPaddingLeft(), (int) mPaddingNoImage, getPaddingRight(), getPaddingBottom()); + super.onMeasure(widthMeasureSpec, heightMeasureSpec); + return; + } + + setPadding(getPaddingLeft(), (int) mPaddingImage, getPaddingRight(), getPaddingBottom()); + UiUtils.show(mImage); + ViewGroup.LayoutParams lp = mImage.getLayoutParams(); + lp.width = (int) mImageSizeFull; + lp.height = (int) mImageSizeFull; + mImage.setLayoutParams(lp); + + super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)); + if (getMeasuredHeight() > MeasureSpec.getSize(heightMeasureSpec)) + { + lp.width = (int) mImageSizeSmall; + lp.height = (int) mImageSizeSmall; + mImage.setLayoutParams(lp); + super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)); + if (getMeasuredHeight() > MeasureSpec.getSize(heightMeasureSpec)) + { + UiUtils.hide(mImage); + setPadding(getPaddingLeft(), (int) mPaddingNoImage, getPaddingRight(), getPaddingBottom()); + } + } + + super.onMeasure(widthMeasureSpec, heightMeasureSpec); + } + + @Override + protected void onConfigurationChanged(Configuration newConfig) + { + mOrientation = newConfig.orientation; + } + + public void setContent(@DrawableRes int imageRes, @StringRes int titleRes, + @StringRes int subtitleRes) + { + if (mImage != null) + mImage.setImageResource(imageRes); + if (mTitle !=null) + mTitle.setText(titleRes); + if (mSubtitle != null) + mSubtitle.setText(subtitleRes); + } +} diff --git a/android/src/com/mapswithme/util/UiUtils.java b/android/src/com/mapswithme/util/UiUtils.java index ab1fa558fa..f0690bdc84 100644 --- a/android/src/com/mapswithme/util/UiUtils.java +++ b/android/src/com/mapswithme/util/UiUtils.java @@ -13,7 +13,6 @@ import android.net.Uri; import android.os.Build; import android.support.annotation.AnyRes; import android.support.annotation.DimenRes; -import android.support.annotation.DrawableRes; import android.support.annotation.IdRes; import android.support.annotation.NonNull; import android.support.annotation.StringRes; @@ -32,12 +31,10 @@ import android.view.animation.Animation; import android.view.animation.Animation.AnimationListener; import android.widget.Button; import android.widget.FrameLayout; -import android.widget.ImageView; import android.widget.TextView; import com.mapswithme.maps.MwmApplication; import com.mapswithme.maps.R; -import com.mapswithme.maps.routing.RoutingController; public final class UiUtils { @@ -315,18 +312,6 @@ public final class UiUtils : R.attr.accentButtonTextColorDisabled)); } - public static void setupPlaceholder(View frame, @DrawableRes int imageRes, @StringRes int titleRes, @StringRes int subtitleRes) - { - ImageView image = (ImageView) frame.findViewById(R.id.image); - image.setImageResource(imageRes); - - TextView title = (TextView) frame.findViewById(R.id.title); - title.setText(titleRes); - - TextView subtitle = (TextView) frame.findViewById(R.id.subtitle); - subtitle.setText(subtitleRes); - } - public static Uri getUriToResId(@NonNull Context context, @AnyRes int resId) { final Resources resources = context.getResources(); |