Request SupportFeatureProvider to provide a support tab.

Bug: 28139604

In dashboard container, if supportFeatureProvider is able to provide a
tab, we display it in tabbed layout. Otherwise, display just
DashboardSummary without changing UI.

Change-Id: Ib7601ac925e1315e6b0928d020fe2d09bd389cd7
This commit is contained in:
Fan Zhang
2016-04-12 11:04:56 -07:00
parent 2fbb297be8
commit bd1c27ee1e
15 changed files with 375 additions and 5 deletions

View File

@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2016 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.0"
android:viewportHeight="24.0"
android:tint="?android:attr/colorAccent">
<path
android:fillColor="#FFFFFF"
android:pathData="M11.99,2C6.47,2 2,6.48 2,12s4.47,10 9.99,10C17.52,22 22,17.52
22,12S17.52,2 11.99,2zM12,20c-4.42,0 -8,-3.58 -8,-8s3.58,-8 8,-8 8,3.58 8,8 -3.58,8
-8,8zm3.5,-9c0.83,0 1.5,-0.67 1.5,-1.5S16.33,8 15.5,8 14,8.67 14,9.5s0.67,1.5
1.5,1.5zm-7,0c0.83,0 1.5,-0.67 1.5,-1.5S9.33,8 8.5,8 7,8.67 7,9.5 7.67,11
8.5,11zm3.5,6.5c2.33,0 4.31,-1.46 5.11,-3.5H6.89c0.8,2.04 2.78,3.5 5.11,3.5z"/>
</vector>

View File

@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2016 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.0"
android:viewportHeight="24.0"
android:tint="?android:attr/colorAccent">
<path
android:fillColor="#FFFFFFFF"
android:pathData="M21,6h-2v9H6v2c0,0.55 0.45,1 1,1h11l4,4V7c0,-0.55 -0.45,-1
-1,-1zm-4,6V3c0,-0.55 -0.45,-1 -1,-1H3c-0.55,0 -1,0.45 -1,1v14l4,-4h10c0.55,0
1,-0.45 1,-1z"/>
</vector>

View File

@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2016 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.0"
android:viewportHeight="24.0"
android:tint="?android:attr/colorAccent">
<path
android:fillColor="#FFFFFFFF"
android:pathData="M12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48
10,-10S17.52,2 12,2zm1,17h-2v-2h2v2zm2.07,-7.75l-0.9,0.92C13.45,12.9 13,13.5
13,15h-2v-0.5c0,-1.1 0.45,-2.1 1.17,-2.83l1.24,-1.26c0.37,-0.36 0.59,-0.86 0.59,-1.41
0,-1.1 -0.9,-2 -2,-2s-2,0.9 -2,2H8c0,-2.21 1.79,-4 4,-4s4,1.79 4,4c0,0.88
-0.36,1.68 -0.93,2.25z"/>
</vector>

View File

@@ -16,7 +16,7 @@
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:ellipsize="end"

View File

@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2016 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.
-->
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginBottom="16dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="16dp"
android:background="?android:attr/selectableItemBackground">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp"
android:orientation="vertical">
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="@style/TextAppearance.TileTitle"/>
<TextView
android:id="@+id/summary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="@style/TextAppearance.Small"
android:textColor="?android:attr/textColorSecondary"/>
</LinearLayout>
</android.support.v7.widget.CardView>

View File

@@ -0,0 +1,67 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2016 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.
-->
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingEnd="16dp"
android:paddingStart="16dp"
android:paddingTop="16dp"
android:text="@string/support_escalation_title"
android:textColor="@color/material_grey_900"
android:textSize="16sp"/>
<LinearLayout
android:id="@+id/escalation_options"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingEnd="8dp"
android:paddingStart="8dp">
<include
android:id="@+id/escalation_by_phone"
layout="@layout/support_escalation_card"/>
<include
android:id="@+id/escalation_by_email"
layout="@layout/support_escalation_card"/>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="?android:attr/listDivider"/>
<include
android:id="@+id/forum_tile"
layout="@layout/support_tile"/>
<include
android:id="@+id/article_tile"
layout="@layout/support_tile"/>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="?android:attr/listDivider"/>
<include
android:id="@+id/feedback_tile"
layout="@layout/support_tile"/>
</LinearLayout>
</ScrollView>

View File

@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2016 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.
-->
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:attr/selectableItemBackground"
android:gravity="center_vertical"
android:minHeight="@dimen/dashboard_tile_minimum_height"
android:orientation="horizontal">
<ImageView
android:id="@android:id/icon"
android:layout_width="@dimen/dashboard_tile_image_size"
android:layout_height="@dimen/dashboard_tile_image_size"
android:scaleType="centerInside"
android:layout_marginStart="@dimen/dashboard_tile_image_margin_start"
android:layout_marginEnd="@dimen/dashboard_tile_image_margin_end"/>
<TextView
android:id="@android:id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:textAppearance="@style/TextAppearance.TileTitle"
android:ellipsize="end"
android:fadingEdge="horizontal"/>
</LinearLayout>

View File

@@ -7393,6 +7393,8 @@
<string name="notification_suggestion_summary">Show or hide notification content</string>
<!-- Setting tab title for all setting options. [CHAR LIMIT=20] -->
<string name="page_tab_title_summary">All</string>
<!-- Setting tab title for support setting options. [CHAR LIMIT=20] -->
<string name="page_tab_title_support">Support</string>
<!-- Summary of developer options to set the smallest width of the screen [CHAR LIMIT=60]-->
<string name="developer_density_summary"><xliff:g name="count" example="320">%d</xliff:g> dp</string>
@@ -7428,4 +7430,21 @@
<!-- Button which clears out storage in the deletion helper. [CHAR LIMIT=60]-->
<string name="deletion_helper_free_button">Free up <xliff:g id="freeable" example="1.2GB">%1$s</xliff:g></string>
<!-- Title text for calling or emailing customer support [CHAR LIMIT=80]-->
<string name="support_escalation_title">24/7 support</string>
<!-- Button label for contacting customer support by phone [CHAR LIMIT=20]-->
<string name="support_escalation_by_phone">Phone</string>
<!-- Button label for contacting customer support by email [CHAR LIMIT=20]-->
<string name="support_escalation_by_email">Email</string>
<!-- Button label for visiting help forum [CHAR LIMIT=60]-->
<string name="support_forum_title">Help forum</string>
<!-- Button label for visiting help articles [CHAR LIMIT=60]-->
<string name="support_articles_title">Help articles</string>
<!-- Button label for sending user feedback [CHAR LIMIT=60]-->
<string name="support_feedback_title">Send feedback</string>
</resources>

View File

@@ -32,6 +32,8 @@ public abstract class InstrumentedFragment extends PreferenceFragment {
// Used by PreferenceActivity for the dummy fragment it adds, no useful data here.
public static final int PREFERENCE_ACTIVITY_FRAGMENT = UNDECLARED + 2;
public static final int SUPPORT_FRAGMENT = UNDECLARED + 3;
/**
* Declare the view of this category.
*

View File

@@ -103,7 +103,6 @@ import com.android.settings.notification.ZenModePrioritySettings;
import com.android.settings.notification.ZenModeScheduleRuleSettings;
import com.android.settings.notification.ZenModeSettings;
import com.android.settings.notification.ZenModeVisualInterruptionSettings;
import com.android.settings.overlay.FeatureFactory;
import com.android.settings.print.PrintJobSettingsFragment;
import com.android.settings.print.PrintSettingsFragment;
import com.android.settings.search.DynamicIndexableContentMonitor;

View File

@@ -31,8 +31,11 @@ import android.view.ViewGroup;
import com.android.settings.InstrumentedFragment;
import com.android.settings.R;
import com.android.settings.overlay.FeatureFactory;
import com.android.settings.overlay.SupportFeatureProvider;
import com.android.settings.widget.SlidingTabLayout;
import com.android.settingslib.HelpUtils;
import com.android.settingslib.drawer.SettingsDrawerActivity;
/**
* Container for Dashboard fragments.
@@ -40,6 +43,7 @@ import com.android.settingslib.HelpUtils;
public final class DashboardContainerFragment extends InstrumentedFragment {
private static final int INDEX_SUMMARY_FRAGMENT = 0;
private static final int INDEX_SUPPORT_FRAGMENT = 1;
private ViewPager mViewPager;
private View mHeaderView;
@@ -70,7 +74,12 @@ public final class DashboardContainerFragment extends InstrumentedFragment {
@Override
public void onResume() {
super.onResume();
if (mPagerAdapter.getCount() > 1) {
final Activity activity = getActivity();
if (activity instanceof SettingsDrawerActivity) {
((SettingsDrawerActivity) getActivity()).setContentHeaderView(mHeaderView);
}
}
}
@Override
@@ -84,10 +93,13 @@ public final class DashboardContainerFragment extends InstrumentedFragment {
private static final class DashboardViewPagerAdapter extends FragmentPagerAdapter {
private final Context mContext;
private final SupportFeatureProvider mSupportFeatureProvider;
public DashboardViewPagerAdapter(Context context, FragmentManager fragmentManager) {
super(fragmentManager);
mContext = context;
mSupportFeatureProvider =
FeatureFactory.getFactory(context).getSupportFeatureProvider();
}
@Override
@@ -95,6 +107,8 @@ public final class DashboardContainerFragment extends InstrumentedFragment {
switch (position) {
case INDEX_SUMMARY_FRAGMENT:
return mContext.getString(R.string.page_tab_title_summary);
case INDEX_SUPPORT_FRAGMENT:
return mContext.getString(R.string.page_tab_title_support);
}
return super.getPageTitle(position);
}
@@ -104,6 +118,8 @@ public final class DashboardContainerFragment extends InstrumentedFragment {
switch (position) {
case INDEX_SUMMARY_FRAGMENT:
return new DashboardSummary();
case INDEX_SUPPORT_FRAGMENT:
return new SupportFragment();
default:
throw new IllegalArgumentException(
String.format(
@@ -114,7 +130,7 @@ public final class DashboardContainerFragment extends InstrumentedFragment {
@Override
public int getCount() {
return 1;
return mSupportFeatureProvider == null ? 1 : 2;
}
}
}

View File

@@ -0,0 +1,71 @@
/*
* Copyright (C) 2016 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.dashboard;
import android.annotation.DrawableRes;
import android.annotation.IdRes;
import android.annotation.StringRes;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import com.android.settings.InstrumentedFragment;
import com.android.settings.R;
/**
* Fragment for support tab in SettingsGoogle.
*/
public final class SupportFragment extends InstrumentedFragment {
private View mContent;
@Override
protected int getMetricsCategory() {
return SUPPORT_FRAGMENT;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
mContent = inflater.inflate(R.layout.support_fragment, container, false);
// Update escalation items.
updateEscalationCard(R.id.escalation_by_phone, R.string.support_escalation_by_phone);
updateEscalationCard(R.id.escalation_by_email, R.string.support_escalation_by_email);
// Update other support items.
updateSupportTile(R.id.forum_tile, R.drawable.ic_forum_24dp, R.string.support_forum_title);
updateSupportTile(R.id.article_tile, R.drawable.ic_help_24dp,
R.string.support_articles_title);
// Update feedback item.
updateSupportTile(R.id.feedback_tile, R.drawable.ic_feedback_24dp,
R.string.support_feedback_title);
return mContent;
}
private void updateEscalationCard(@IdRes int cardId, @StringRes int title) {
final View card = mContent.findViewById(cardId);
((TextView) card.findViewById(R.id.title)).setText(title);
}
private void updateSupportTile(@IdRes int tileId, @DrawableRes int icon, @StringRes int title) {
final View tile = mContent.findViewById(tileId);
((ImageView) tile.findViewById(android.R.id.icon)).setImageResource(icon);
((TextView) tile.findViewById(android.R.id.title)).setText(title);
}
}

View File

@@ -59,6 +59,8 @@ public abstract class FeatureFactory {
return sFactory;
}
public abstract SupportFeatureProvider getSupportFeatureProvider();
public static final class FactoryNotFoundException extends RuntimeException {
public FactoryNotFoundException(Throwable throwable) {
super("Unable to create factory. Did you misconfigure Proguard?", throwable);

View File

@@ -19,5 +19,11 @@ package com.android.settings.overlay;
/**
* {@link FeatureFactory} implementation for AOSP Settings.
*/
public class FeatureFactoryImpl extends FeatureFactory {
public final class FeatureFactoryImpl extends FeatureFactory {
@Override
public SupportFeatureProvider getSupportFeatureProvider() {
return null;
}
}

View File

@@ -0,0 +1,8 @@
package com.android.settings.overlay;
/**
* Feature provider for support tab.
*/
public interface SupportFeatureProvider {
}