OSDN Git Service

Revert "Revert "First commit of dynamic home page feature""
authorRaff Tsai <rafftsai@google.com>
Fri, 29 Jun 2018 06:11:39 +0000 (06:11 +0000)
committerRaff Tsai <rafftsai@google.com>
Mon, 2 Jul 2018 08:02:26 +0000 (16:02 +0800)
This reverts commit 457f6ef14055d238ec6bd140d4e050f40507d59e.

Reason for revert: fix the color check in repohook

Test: make RunSettingsRoboTests

Change-Id: I1b466c412138dfb0f2bffc4270a8932fe3b81c94

Android.mk
AndroidManifest.xml
res/drawable/ic_list_24dp.xml [new file with mode: 0644]
res/layout/search_bar.xml [new file with mode: 0644]
res/layout/settings_homepage.xml [new file with mode: 0644]
res/layout/settings_main_dashboard.xml
res/values/dimens.xml
res/values/themes.xml
src/com/android/settings/SettingsHomepageActivity.java [new file with mode: 0644]
src/com/android/settings/core/FeatureFlags.java
src/com/android/settings/homepage/HomepageFragment.java [new file with mode: 0644]

index 96b5bef..a573378 100644 (file)
@@ -32,6 +32,7 @@ LOCAL_STATIC_ANDROID_LIBRARIES := \
     androidx.preference_preference \
     androidx.recyclerview_recyclerview \
     androidx.legacy_legacy-preference-v14 \
+    com.google.android.material_material \
 
 LOCAL_JAVA_LIBRARIES := \
     bouncycastle \
index 6a2af9e..00998a9 100644 (file)
                 android:value="true" />
         </activity>
 
+        <activity android:name=".SettingsHomepageActivity"
+                  android:taskAffinity="com.android.settings.root"
+                  android:label="@string/settings_label_launcher"
+                  android:theme="@style/Theme.Settings.Home"
+                  android:launchMode="singleTask">
+        </activity>
+
         <!-- Alias for launcher activity only, as this belongs to each profile. -->
         <activity-alias android:name="Settings"
                 android:taskAffinity="com.android.settings.root"
                 android:label="@string/settings_label_launcher"
                 android:launchMode="singleTask"
-                android:targetActivity="Settings">
+                android:targetActivity=".SettingsHomepageActivity">
             <intent-filter>
                 <action android:name="android.intent.action.MAIN" />
                 <category android:name="android.intent.category.DEFAULT" />
diff --git a/res/drawable/ic_list_24dp.xml b/res/drawable/ic_list_24dp.xml
new file mode 100644 (file)
index 0000000..03f4af0
--- /dev/null
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+    android:width="24dp"
+    android:height="24dp"
+    android:viewportWidth="24"
+    android:viewportHeight="24">
+  <path
+      android:fillColor="?android:attr/colorAccent"
+      android:pathData="M4,13L4,13c0.55,0 1,-0.45 1,-1v0c0,-0.55 -0.45,-1 -1,-1h0c-0.55,0 -1,0.45 -1,1v0C3,12.55 3.45,13 4,13zM4,17L4,17c0.55,0 1,-0.45 1,-1v0c0,-0.55 -0.45,-1 -1,-1h0c-0.55,0 -1,0.45 -1,1v0C3,16.55 3.45,17 4,17zM4,9L4,9c0.55,0 1,-0.45 1,-1v0c0,-0.55 -0.45,-1 -1,-1h0C3.45,7 3,7.45 3,8v0C3,8.55 3.45,9 4,9zM7,13h14v-2H7V13zM7,17h14v-2H7V17zM7,7v2h14V7H7z"/>
+</vector>
diff --git a/res/layout/search_bar.xml b/res/layout/search_bar.xml
new file mode 100644 (file)
index 0000000..cbd461b
--- /dev/null
@@ -0,0 +1,49 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+     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.
+-->
+
+<FrameLayout
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:app="http://schemas.android.com/tools"
+    android:id="@+id/search_bar_container"
+    android:layout_width="match_parent"
+    android:layout_height="wrap_content"
+    android:background="?android:attr/colorPrimary">
+    <androidx.cardview.widget.CardView
+        android:id="@+id/search_bar"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:layout_margin="@dimen/search_bar_margin"
+        app:cardCornerRadius="@dimen/search_bar_corner_radius"
+        app:cardBackgroundColor="?android:attr/colorBackground"
+        app:cardElevation="@dimen/search_bar_card_elevation">
+        <Toolbar
+            android:id="@+id/search_action_bar"
+            android:layout_width="match_parent"
+            android:layout_height="@dimen/search_bar_height"
+            android:background="?android:attr/selectableItemBackground"
+            android:contentInsetStartWithNavigation="@dimen/search_bar_content_inset"
+            android:navigationIcon="@drawable/ic_search_24dp"
+            android:theme="?android:attr/actionBarTheme">
+            <TextView
+                android:id="@+id/search_action_bar_title"
+                style="@style/TextAppearance.SearchBar"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:text="@string/search_menu"/>
+        </Toolbar>
+    </androidx.cardview.widget.CardView>
+</FrameLayout>
\ No newline at end of file
diff --git a/res/layout/settings_homepage.xml b/res/layout/settings_homepage.xml
new file mode 100644 (file)
index 0000000..c36cf8b
--- /dev/null
@@ -0,0 +1,75 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+     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.
+-->
+
+<androidx.coordinatorlayout.widget.CoordinatorLayout
+    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">
+
+    <FrameLayout
+        android:id="@id/main_content"
+        android:layout_height="match_parent"
+        android:layout_width="match_parent" />
+    <RelativeLayout
+        android:id="@+id/bottom_sheet"
+        android:layout_width="match_parent"
+        android:layout_height="match_parent"
+        android:background="?android:attr/windowBackground"
+        android:minHeight="@dimen/homepage_bottomsheet_height"
+        app:layout_behavior="@string/bottom_sheet_behavior"
+        app:behavior_peekHeight="@dimen/homepage_bottomsheet_height">
+
+        <androidx.coordinatorlayout.widget.CoordinatorLayout
+            android:id="@+id/bottom_area"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content">
+
+            <com.google.android.material.floatingactionbutton.FloatingActionButton
+                android:id="@+id/search_fab"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:src="@drawable/ic_search_24dp"
+                app:backgroundTint="@android:color/white"
+                app:layout_anchor="@id/bar" />
+
+            <com.google.android.material.bottomappbar.BottomAppBar
+                android:id="@+id/bar"
+                android:layout_width="match_parent"
+                android:layout_height="@dimen/homepage_bottombar_height"
+                android:layout_alignParentTop="true"
+                android:layout_marginTop="@dimen/homepage_bottombar_top_margin"
+                android:clickable="true"
+                app:fabAttached="true"
+                app:fabAlignmentMode="end"
+                app:fabCradleDiameter="@dimen/homepage_bottombar_fab_cradle"
+                app:navigationIcon="@drawable/ic_list_24dp"
+                style="@style/Widget.MaterialComponents.BottomAppBar" />
+        </androidx.coordinatorlayout.widget.CoordinatorLayout>
+
+        <include layout="@layout/search_bar"
+                 android:visibility="invisible" />
+
+        <FrameLayout
+            android:id="@+id/bottom_sheet_fragment"
+            android:layout_below="@id/bottom_area"
+            android:layout_width="match_parent"
+            android:layout_height="match_parent" />
+
+    </RelativeLayout>
+
+</androidx.coordinatorlayout.widget.CoordinatorLayout>
\ No newline at end of file
index b14f73e..3994092 100644 (file)
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     android:orientation="vertical">
-    <FrameLayout
-        android:id="@+id/search_bar_container"
-        android:layout_width="match_parent"
-        android:layout_height="wrap_content"
-        android:background="?android:attr/colorPrimary">
-        <androidx.cardview.widget.CardView
-            android:id="@+id/search_bar"
-            android:layout_width="match_parent"
-            android:layout_height="wrap_content"
-            android:layout_margin="@dimen/search_bar_margin"
-            app:cardCornerRadius="@dimen/search_bar_corner_radius"
-            app:cardBackgroundColor="?android:attr/colorBackground"
-            app:cardElevation="2dp">
-            <Toolbar
-                android:id="@+id/search_action_bar"
-                android:layout_width="match_parent"
-                android:layout_height="@dimen/search_bar_height"
-                android:background="?android:attr/selectableItemBackground"
-                android:contentInsetStartWithNavigation="64dp"
-                android:navigationIcon="@drawable/ic_search_24dp"
-                android:theme="?android:attr/actionBarTheme">
-                <TextView
-                    android:id="@+id/search_action_bar_title"
-                    style="@style/TextAppearance.SearchBar"
-                    android:layout_width="wrap_content"
-                    android:layout_height="wrap_content"
-                    android:text="@string/search_menu" />
-            </Toolbar>
-        </androidx.cardview.widget.CardView>
-    </FrameLayout>
+
+    <include layout="@layout/search_bar" />
+
     <FrameLayout
         android:id="@+id/main_content"
         android:layout_height="match_parent"
index 30d1e6c..981893d 100755 (executable)
     <dimen name="search_bar_height">48dp</dimen>
     <dimen name="search_bar_corner_radius">2dp</dimen>
     <dimen name="search_bar_text_size">16dp</dimen>
+    <dimen name="search_bar_card_elevation">2dp</dimen>
+    <dimen name="search_bar_content_inset">64dp</dimen>
 
     <!-- Dimensions for Wifi Assistant Card -->
     <dimen name="wifi_assistant_padding_top_bottom">16dp</dimen>
     <dimen name="reset_checkbox_title_text_size">18sp</dimen>
     <dimen name="reset_checkbox_summary_text_size">14sp</dimen>
 
+    <!-- Bottombar size and padding -->
+    <dimen name="homepage_bottomsheet_height">90dp</dimen>
+    <dimen name="homepage_bottombar_height">56dp</dimen>
+    <dimen name="homepage_bottombar_top_margin">34dp</dimen>
+    <dimen name="homepage_bottombar_fab_cradle">68dp</dimen>
+
 </resources>
index 8c38649..5d36367 100644 (file)
         <item name="android:windowNoTitle">true</item>
     </style>
 
+    <style name="Theme.Settings.Home" parent="Theme.AppCompat.Light.NoActionBar">
+        <!-- copied from frameworks/base/core/res/res/values/themes_device_defaults.xml -->
+        <item name="colorPrimary">@*android:color/primary_device_default_settings_light</item>
+        <item name="colorPrimaryDark">@*android:color/primary_dark_device_default_settings_light</item>
+    </style>
+
 </resources>
diff --git a/src/com/android/settings/SettingsHomepageActivity.java b/src/com/android/settings/SettingsHomepageActivity.java
new file mode 100644 (file)
index 0000000..eed3a7f
--- /dev/null
@@ -0,0 +1,61 @@
+/*
+ * 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;
+
+import android.app.Activity;
+import android.app.Fragment;
+import android.app.FragmentManager;
+import android.content.Context;
+import android.content.Intent;
+import android.os.Bundle;
+import android.util.FeatureFlagUtils;
+
+import com.android.settings.core.FeatureFlags;
+import com.android.settings.core.SettingsBaseActivity;
+import com.android.settings.homepage.HomepageFragment;
+
+public class SettingsHomepageActivity extends SettingsBaseActivity {
+
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+
+        if (!isDynamicHomepageEnabled(this)) {
+            final Intent settings = new Intent();
+            settings.setAction("android.settings.SETTINGS");
+            startActivity(settings);
+            finish();
+        }
+        setContentView(R.layout.settings_homepage);
+        switchToFragment(this, R.id.main_content, HomepageFragment.class.getName());
+    }
+
+    public static boolean isDynamicHomepageEnabled(Context context) {
+        return FeatureFlagUtils.isEnabled(context, FeatureFlags.DYNAMIC_HOMEPAGE);
+    }
+
+    /**
+     * Switch to a specific Fragment
+     */
+    public static void switchToFragment(Activity activity, int id, String fragmentName) {
+        final Fragment f = Fragment.instantiate(activity, fragmentName, null /* args */);
+
+        FragmentManager manager = activity.getFragmentManager();
+        manager.beginTransaction().replace(id, f).commitAllowingStateLoss();
+        manager.executePendingTransactions();
+    }
+}
\ No newline at end of file
index 006bd70..08e4de5 100644 (file)
@@ -23,4 +23,5 @@ public class FeatureFlags {
     public static final String BATTERY_DISPLAY_APP_LIST = "settings_battery_display_app_list";
     public static final String BLUETOOTH_WHILE_DRIVING = "settings_bluetooth_while_driving";
     public static final String AUDIO_SWITCHER_SETTINGS = "settings_audio_switcher";
+    public static final String DYNAMIC_HOMEPAGE = "settings_dynamic_homepage";
 }
diff --git a/src/com/android/settings/homepage/HomepageFragment.java b/src/com/android/settings/homepage/HomepageFragment.java
new file mode 100644 (file)
index 0000000..3b0ca2b
--- /dev/null
@@ -0,0 +1,150 @@
+/*
+ * 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 android.app.ActionBar;
+import android.app.Activity;
+import android.content.Intent;
+import android.os.Bundle;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.Toolbar;
+
+import androidx.annotation.NonNull;
+
+import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
+import com.android.settings.R;
+import com.android.settings.SettingsHomepageActivity;
+import com.android.settings.Utils;
+import com.android.settings.core.InstrumentedFragment;
+import com.android.settings.dashboard.DashboardSummary;
+import com.android.settings.overlay.FeatureFactory;
+import com.android.settings.search.SearchFeatureProvider;
+
+import com.google.android.material.bottomappbar.BottomAppBar;
+import com.google.android.material.bottomsheet.BottomSheetBehavior;
+import com.google.android.material.floatingactionbutton.FloatingActionButton;
+
+public class HomepageFragment extends InstrumentedFragment {
+
+    private static final String TAG = "HomepageFragment";
+
+    private FloatingActionButton mSearchButton;
+    private BottomSheetBehavior mBottomSheetBehavior;
+    private boolean mBottomFragmentLoaded = false;
+
+    @Override
+    public View onCreateView(LayoutInflater inflater, ViewGroup container,
+            Bundle savedInstanceState) {
+        final View rootView = inflater.inflate(R.layout.dashboard, container, false);
+        return rootView;
+    }
+
+    @Override
+    public void onActivityCreated(Bundle savedInstanceState) {
+        super.onActivityCreated(savedInstanceState);
+        setupBottomBar();
+        setupSearchBar();
+    }
+
+    @Override
+    public int getMetricsCategory() {
+        return MetricsEvent.SETTINGS_HOMEPAGE;
+    }
+
+    private void setupBottomBar() {
+        final Activity activity = getActivity();
+        mSearchButton = (FloatingActionButton) activity.findViewById(R.id.search_fab);
+
+        mSearchButton.setOnClickListener(v -> {
+            final Intent intent = SearchFeatureProvider.SEARCH_UI_INTENT;
+            intent.setPackage(FeatureFactory.getFactory(activity)
+                    .getSearchFeatureProvider().getSettingsIntelligencePkgName());
+            startActivityForResult(intent, 0 /* requestCode */);
+        });
+        mBottomSheetBehavior = BottomSheetBehavior.from(activity.findViewById(R.id.bottom_sheet));
+        final BottomAppBar bottomBar = (BottomAppBar) activity.findViewById(R.id.bar);
+        bottomBar.setOnClickListener(v -> {
+            mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
+        });
+
+        final int screenWidthpx = getResources().getDisplayMetrics().widthPixels;
+        final View searchbar = activity.findViewById(R.id.search_bar_container);
+        final View bottombar = activity.findViewById(R.id.bar);
+
+
+        mBottomSheetBehavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
+            @Override
+            public void onStateChanged(@NonNull View bottomSheet, int newState) {
+                if (!mBottomFragmentLoaded) {
+                    SettingsHomepageActivity.switchToFragment(getActivity(),
+                            R.id.bottom_sheet_fragment, DashboardSummary.class.getName());
+                    mBottomFragmentLoaded = true;
+                }
+                if (newState == BottomSheetBehavior.STATE_EXPANDED) {
+                    bottombar.setVisibility(View.INVISIBLE);
+                    searchbar.setVisibility(View.VISIBLE);
+                    mSearchButton.setVisibility(View.GONE);
+                } else if (newState == BottomSheetBehavior.STATE_COLLAPSED) {
+                    bottombar.setVisibility(View.VISIBLE);
+                    searchbar.setVisibility(View.INVISIBLE);
+                    mSearchButton.setVisibility(View.VISIBLE);
+                } else if (newState == BottomSheetBehavior.STATE_SETTLING) {
+                    bottombar.setVisibility(View.VISIBLE);
+                    searchbar.setVisibility(View.VISIBLE);
+                    mSearchButton.setVisibility(View.VISIBLE);
+                }
+            }
+
+            @Override
+            public void onSlide(@NonNull View bottomSheet, float slideOffset) {
+                bottombar.setAlpha(1 - slideOffset);
+                mSearchButton.setAlpha(1 - slideOffset);
+                searchbar.setAlpha(slideOffset);
+                searchbar.setPadding((int) (screenWidthpx * (1 - slideOffset)), 0, 0, 0);
+            }
+        });
+    }
+
+    //TODO(110767984), copied from settingsActivity. We have to merge them
+    private void setupSearchBar() {
+        final Activity activity = getActivity();
+        final Toolbar toolbar = activity.findViewById(R.id.search_action_bar);
+        FeatureFactory.getFactory(activity).getSearchFeatureProvider()
+                .initSearchToolbar(activity, toolbar);
+        activity.setActionBar(toolbar);
+
+        // Please forgive me for what I am about to do.
+        //
+        // Need to make the navigation icon non-clickable so that the entire card is clickable
+        // and goes to the search UI. Also set the background to null so there's no ripple.
+        final View navView = toolbar.getNavigationView();
+        navView.setClickable(false);
+        navView.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO);
+        navView.setBackground(null);
+
+        final ActionBar actionBar = activity.getActionBar();
+        if (actionBar != null) {
+            boolean deviceProvisioned = Utils.isDeviceProvisioned(activity);
+            actionBar.setDisplayHomeAsUpEnabled(deviceProvisioned);
+            actionBar.setHomeButtonEnabled(deviceProvisioned);
+            actionBar.setDisplayShowTitleEnabled(false);
+        }
+    }
+}