Display setting and support in a tab layout - DO NOT MERGE

Bug: 28269035
Bug: 28139604
This commit is contained in:
Fan Zhang
2016-03-23 15:31:08 -07:00
parent 18bf2fbdac
commit 2869157ba9
21 changed files with 782 additions and 22 deletions

View File

@@ -0,0 +1,136 @@
/*
* 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.app.Activity;
import android.app.Fragment;
import android.app.FragmentManager;
import android.content.Context;
import android.os.Bundle;
import android.support.v13.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.View;
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.drawer.SettingsDrawerActivity;
import com.android.settingslib.HelpUtils;
/**
* Container for Dashboard fragments.
*/
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;
private DashboardViewPagerAdapter mPagerAdapter;
@Override
protected int getMetricsCategory() {
return DASHBOARD_CONTAINER;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setHasOptionsMenu(true);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) {
final View content = inflater.inflate(R.layout.dashboard_container, parent, false);
mViewPager = (ViewPager) content.findViewById(R.id.pager);
mPagerAdapter = new DashboardViewPagerAdapter(getContext(), getChildFragmentManager());
mViewPager.setAdapter(mPagerAdapter);
mHeaderView = inflater.inflate(R.layout.dashboard_container_header, parent, false);
((SlidingTabLayout) mHeaderView).setViewPager(mViewPager);
return content;
}
@Override
public void onResume() {
super.onResume();
if (mPagerAdapter.getCount() > 1) {
final Activity activity = getActivity();
if (activity instanceof SettingsDrawerActivity) {
((SettingsDrawerActivity) getActivity()).setContentHeaderView(mHeaderView);
}
}
}
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater);
if (getActivity() == null) return;
HelpUtils.prepareHelpMenuItem(getActivity(), menu, R.string.help_uri_dashboard,
getClass().getName());
}
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
public CharSequence getPageTitle(int position) {
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);
}
@Override
public Fragment getItem(int position) {
switch (position) {
case INDEX_SUMMARY_FRAGMENT:
return new DashboardSummary();
case INDEX_SUPPORT_FRAGMENT:
return new SupportFragment();
default:
throw new IllegalArgumentException(
String.format(
"Position %d does not map to a valid dashboard fragment",
position));
}
}
@Override
public int getCount() {
return mSupportFeatureProvider == null ? 1 : 2;
}
}
}

View File

@@ -21,13 +21,11 @@ import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.View;
import android.view.ViewGroup;
import com.android.internal.logging.MetricsLogger;
import com.android.internal.logging.MetricsProto.MetricsEvent;
import com.android.settingslib.HelpUtils;
import com.android.settings.InstrumentedFragment;
import com.android.settings.R;
import com.android.settings.Settings;
@@ -83,7 +81,6 @@ public class DashboardSummary extends InstrumentedFragment
List<DashboardCategory> categories =
((SettingsActivity) getActivity()).getDashboardCategories();
mSummaryLoader = new SummaryLoader(getActivity(), categories);
setHasOptionsMenu(true);
Context context = getContext();
mConditionManager = ConditionManager.get(context);
mSuggestionParser = new SuggestionParser(context,
@@ -98,14 +95,6 @@ public class DashboardSummary extends InstrumentedFragment
super.onDestroy();
}
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater);
if (getActivity() == null) return;
HelpUtils.prepareHelpMenuItem(getActivity(), menu, R.string.help_uri_dashboard,
getClass().getName());
}
@Override
public void onResume() {
long startTime = System.currentTimeMillis();

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);
}
}