Merge "Request SupportFeatureProvider to provide a support tab."

This commit is contained in:
Fan Zhang
2016-04-19 17:13:15 +00:00
committed by Android (Google) Code Review
15 changed files with 375 additions and 5 deletions

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();
final Activity activity = getActivity();
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 {
}