Change homepage layout
- merge PersonalSettingsFragment and TopLevelSettings together
Bug: 118224579
Test: manual
Change-Id: Ieee50a22babb25023e2a1767793e220862a38363
diff --git a/res/layout/condition_header.xml b/res/layout/condition_header.xml
index f214319..e33157e 100644
--- a/res/layout/condition_header.xml
+++ b/res/layout/condition_header.xml
@@ -26,7 +26,7 @@
<RelativeLayout
android:layout_width="match_parent"
- android:layout_height="36dp"
+ android:layout_height="@dimen/condition_header_height"
android:layout_centerHorizontal="true">
<FrameLayout
diff --git a/res/layout/condition_tile.xml b/res/layout/condition_tile.xml
index dd87be5..1ca5839 100644
--- a/res/layout/condition_tile.xml
+++ b/res/layout/condition_tile.xml
@@ -25,7 +25,7 @@
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
- android:minHeight="36dp"
+ android:minHeight="@dimen/condition_header_height"
android:background="?android:attr/selectableItemBackground"
android:orientation="horizontal">
diff --git a/res/layout/settings_homepage.xml b/res/layout/settings_homepage.xml
index 83c771c..0ba3609 100644
--- a/res/layout/settings_homepage.xml
+++ b/res/layout/settings_homepage.xml
@@ -15,8 +15,43 @@
limitations under the License.
-->
-<androidx.recyclerview.widget.RecyclerView
+<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
- android:id="@+id/card_container"
android:layout_width="match_parent"
- android:layout_height="match_parent" />
+ android:layout_height="wrap_content"
+ android:orientation="vertical">
+
+ <androidx.recyclerview.widget.RecyclerView
+ android:id="@+id/card_container"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"/>
+
+ <RelativeLayout
+ android:id="@+id/suggestion_footer"
+ android:layout_width="match_parent"
+ android:layout_height="@dimen/condition_header_height"
+ android:layout_centerHorizontal="true">
+
+ <ImageView
+ android:id="@+id/expand_indicator"
+ android:layout_width="wrap_content"
+ android:layout_height="match_parent"
+ android:layout_alignParentEnd="true"
+ android:paddingTop="4dp"
+ android:paddingStart="16dp"
+ android:paddingEnd="16dp"/>
+
+ <TextView
+ android:id="@+id/expand_summary"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginStart="8dp"
+ android:layout_toStartOf="@id/expand_indicator"
+ android:layout_centerVertical="true"
+ android:gravity="end"
+ android:textAppearance="@style/TextAppearance.SuggestionTitle"
+ android:textColor="?android:attr/colorAccent"/>
+
+ </RelativeLayout>
+ <include layout="@layout/horizontal_divider"/>
+</LinearLayout>
diff --git a/res/layout/settings_homepage_container.xml b/res/layout/settings_homepage_container.xml
index ba8b48a..78ec39f 100644
--- a/res/layout/settings_homepage_container.xml
+++ b/res/layout/settings_homepage_container.xml
@@ -15,44 +15,28 @@
limitations under the License.
-->
-<LinearLayout
+<androidx.core.widget.NestedScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="vertical">
+ android:layout_height="match_parent">
- <androidx.coordinatorlayout.widget.CoordinatorLayout
- android:layout_width="match_parent"
- android:layout_height="0dp"
- android:layout_weight="1">
-
- <com.google.android.material.appbar.AppBarLayout
- android:id="@+id/homepage_appbar"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- app:elevation="0dp">
-
- <include layout="@layout/search_bar"/>
-
- </com.google.android.material.appbar.AppBarLayout>
-
- <FrameLayout
- android:id="@id/main_content"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
- </androidx.coordinatorlayout.widget.CoordinatorLayout>
-
- <com.google.android.material.bottomnavigation.BottomNavigationView
- android:id="@+id/bottom_nav"
+ <LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
- android:layout_marginEnd="0dp"
- android:layout_marginStart="0dp"
- android:background="?android:attr/windowBackground"
- app:itemIconTint="@color/bottom_navigation_colors"
- app:itemTextColor="@color/bottom_navigation_colors"
- app:menu="@menu/home_bottom_navigation"/>
+ android:orientation="vertical"
+ android:descendantFocusability="blocksDescendants">
-</LinearLayout>
+ <include layout="@layout/search_bar"/>
+
+ <FrameLayout
+ android:id="@+id/suggestion_content"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"/>
+
+ <FrameLayout
+ android:id="@+id/main_content"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"/>
+
+ </LinearLayout>
+</androidx.core.widget.NestedScrollView>
diff --git a/res/values/dimens.xml b/res/values/dimens.xml
index edece3c..dc39475 100755
--- a/res/values/dimens.xml
+++ b/res/values/dimens.xml
@@ -311,6 +311,7 @@
<!-- Suggestion/condition header padding -->
<dimen name="suggestion_condition_header_padding_collapsed">10dp</dimen>
<dimen name="suggestion_condition_header_padding_expanded">5dp</dimen>
+ <dimen name="condition_header_height">36dp</dimen>
<!-- Suggestion cards size and padding -->
<dimen name="suggestion_card_icon_size">24dp</dimen>
@@ -357,4 +358,6 @@
<!-- Signal icon in NetworkSelectSetting -->
<dimen name="signal_strength_icon_size">24dp</dimen>
+
+
</resources>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index c81920e..a842d36 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -10271,4 +10271,9 @@
<!-- Used for EmergencyInfoSlice slice helper class -->
<string name="emergency_info_contextual_card_summary" translatable="false">Medical info, emergency contacts</string>
+
+ <!-- See more items in contextual homepage [CHAR LIMIT=30]-->
+ <string name="see_more">See more</string>
+ <!-- See less items in contextual homepage [CHAR LIMIT=30]-->
+ <string name="see_less">See less</string>
</resources>
diff --git a/src/com/android/settings/homepage/ContextualCardsAdapter.java b/src/com/android/settings/homepage/ContextualCardsAdapter.java
index 8e6f805..4144d4d 100644
--- a/src/com/android/settings/homepage/ContextualCardsAdapter.java
+++ b/src/com/android/settings/homepage/ContextualCardsAdapter.java
@@ -17,7 +17,6 @@
package com.android.settings.homepage;
import android.content.Context;
-import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
diff --git a/src/com/android/settings/homepage/SettingsHomepageActivity.java b/src/com/android/settings/homepage/SettingsHomepageActivity.java
index bfd8c4d..c6040f6 100644
--- a/src/com/android/settings/homepage/SettingsHomepageActivity.java
+++ b/src/com/android/settings/homepage/SettingsHomepageActivity.java
@@ -22,7 +22,6 @@
import android.util.FeatureFlagUtils;
import android.widget.Toolbar;
-import androidx.annotation.VisibleForTesting;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;
@@ -32,13 +31,10 @@
import com.android.settings.core.SettingsBaseActivity;
import com.android.settings.overlay.FeatureFactory;
-import com.google.android.material.bottomnavigation.BottomNavigationView;
-
public class SettingsHomepageActivity extends SettingsBaseActivity {
- @VisibleForTesting
- static final String PERSONAL_SETTINGS_TAG = "personal_settings";
- private static final String ALL_SETTINGS_TAG = "all_settings";
+ private static final String SUGGESTION_TAG = "suggestion";
+ private static final String MAIN_TAG = "main";
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -58,49 +54,18 @@
FeatureFactory.getFactory(this).getSearchFeatureProvider()
.initSearchToolbar(this, toolbar);
- final BottomNavigationView navigation = findViewById(R.id.bottom_nav);
- navigation.setOnNavigationItemSelectedListener(item -> {
- switch (item.getItemId()) {
- case R.id.homepage_personal_settings:
- switchFragment(new PersonalSettingsFragment(), PERSONAL_SETTINGS_TAG,
- ALL_SETTINGS_TAG);
- return true;
-
- case R.id.homepage_all_settings:
- switchFragment(new TopLevelSettings(), ALL_SETTINGS_TAG,
- PERSONAL_SETTINGS_TAG);
- return true;
- }
- return false;
- });
-
- if (savedInstanceState == null) {
- // savedInstanceState is null, this is first load.
- // Default to open contextual cards.
- switchFragment(new PersonalSettingsFragment(), PERSONAL_SETTINGS_TAG,
- ALL_SETTINGS_TAG);
- }
+ showFragment(new PersonalSettingsFragment(), R.id.suggestion_content, SUGGESTION_TAG);
+ showFragment(new TopLevelSettings(), R.id.main_content, MAIN_TAG);
}
public static boolean isDynamicHomepageEnabled(Context context) {
return FeatureFlagUtils.isEnabled(context, FeatureFlags.DYNAMIC_HOMEPAGE);
}
- private void switchFragment(Fragment fragment, String showFragmentTag, String hideFragmentTag) {
+ private void showFragment(Fragment fragment, int id, String tag) {
final FragmentManager fragmentManager = getSupportFragmentManager();
final FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
-
- final Fragment hideFragment = fragmentManager.findFragmentByTag(hideFragmentTag);
- if (hideFragment != null) {
- fragmentTransaction.hide(hideFragment);
- }
-
- Fragment showFragment = fragmentManager.findFragmentByTag(showFragmentTag);
- if (showFragment == null) {
- fragmentTransaction.add(R.id.main_content, fragment, showFragmentTag);
- } else {
- fragmentTransaction.show(showFragment);
- }
+ fragmentTransaction.add(id, fragment, tag);
fragmentTransaction.commit();
}
}
\ No newline at end of file
diff --git a/tests/unit/src/com/android/settings/homepage/SettingsHomepageActivityTest.java b/tests/unit/src/com/android/settings/homepage/SettingsHomepageActivityTest.java
deleted file mode 100644
index 89ec476..0000000
--- a/tests/unit/src/com/android/settings/homepage/SettingsHomepageActivityTest.java
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * Copyright (C) 2018 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.settings.homepage;
-
-import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK;
-
-import static com.android.settings.homepage.SettingsHomepageActivity.PERSONAL_SETTINGS_TAG;
-
-import static com.google.common.truth.Truth.assertThat;
-
-import android.content.Context;
-import android.content.Intent;
-import android.support.test.InstrumentationRegistry;
-import android.support.test.runner.AndroidJUnit4;
-import android.util.FeatureFlagUtils;
-
-import androidx.fragment.app.Fragment;
-
-import com.android.settings.core.FeatureFlags;
-
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
-@RunWith(AndroidJUnit4.class)
-public class SettingsHomepageActivityTest {
-
- private Context mContext;
- private SettingsHomepageActivity mActivity;
-
- @Before
- public void setUp() {
- mContext = InstrumentationRegistry.getTargetContext();
- FeatureFlagUtils.setEnabled(mContext, FeatureFlags.DYNAMIC_HOMEPAGE, true);
- }
-
- @After
- public void tearDown() {
- FeatureFlagUtils.setEnabled(mContext, FeatureFlags.DYNAMIC_HOMEPAGE, false);
- }
-
- @Test
- public void launchHomepage_shouldOpenPersonalSettings() {
- final Intent intent = new Intent().setClass(mContext, SettingsHomepageActivity.class)
- .addFlags(FLAG_ACTIVITY_NEW_TASK);
-
- mActivity = (SettingsHomepageActivity) InstrumentationRegistry.getInstrumentation()
- .startActivitySync(intent);
-
- final Fragment fragment = mActivity.getSupportFragmentManager()
- .findFragmentByTag(PERSONAL_SETTINGS_TAG);
-
- assertThat(fragment).isInstanceOf(PersonalSettingsFragment.class);
- }
-
-}