--- /dev/null
+<?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.
+-->
+
+<com.android.settings.widget.SlidingTabLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:app="http://schemas.android.com/apk/res-auto"
+ android:id="@+id/sliding_tabs"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:background="?android:attr/colorPrimary"/>
--- /dev/null
+<?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.
+-->
+
+<FrameLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:orientation="vertical"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"/>
\ No newline at end of file
--- /dev/null
+<?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.
+-->
+
+<View
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/sliding_tab_selected_indicator"
+ android:layout_width="wrap_content"
+ android:layout_height="@dimen/pager_tabs_selected_indicator_height"
+ android:background="?android:attr/colorAccent"/>
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2016 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.
+-->
+
+<TextView
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="wrap_content"
+ android:layout_weight="1"
+ android:layout_height="wrap_content"
+ android:ellipsize="end"
+ android:maxLines="1"
+ android:textColor="@android:color/white"
+ android:gravity="center"
+ android:background="?android:attr/selectableItemBackground"
+ android:textAllCaps="true"
+ android:padding="@dimen/pager_tabs_title_padding"/>
\ No newline at end of file
<dimen name="appwidget_min_height">40dip</dimen>
<dimen name="pager_tabs_padding">0dp</dimen>
+ <dimen name="pager_tabs_title_padding">16dp</dimen>
+ <dimen name="pager_tabs_selected_indicator_height">3dp</dimen>
<!-- Minimum width for the popup for updating a user's photo. -->
<dimen name="update_user_photo_popup_min_width">300dip</dimen>
<string name="notification_suggestion_title">Control lock screen notifications</string>
<!-- Summary of notification suggestion during optional steps of setup. [CHAR_LIMIT=80] -->
<string name="notification_suggestion_summary">Show or hide notification content</string>
+ <!-- Setting tab title for general status. [CHAR LIMIT=20] -->
+ <string name="page_tab_title_status">Status</string>
+ <!-- Setting tab title for all setting options. [CHAR LIMIT=20] -->
+ <string name="page_tab_title_summary">All</string>
</resources>
public static final int DASHBOARD_CONTAINER = UNDECLARED + 1;
// 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 DASHBOARD_STATUS = UNDECLARED + 3;
/**
* Declare the view of this category.
if (current != null && current instanceof SearchResultsSummary) {
mSearchResultsFragment = (SearchResultsSummary) current;
} else {
+ setContentHeaderView(null);
mSearchResultsFragment = (SearchResultsSummary) switchToFragment(
SearchResultsSummary.class.getName(), null, false, true,
R.string.search_results_title, null, true);
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 com.android.settings.InstrumentedFragment;
import com.android.settings.R;
+import com.android.settings.widget.SlidingTabLayout;
+import com.android.settingslib.drawer.SettingsDrawerActivity;
/**
* Container for Dashboard fragments.
*/
public final class DashboardContainerFragment extends InstrumentedFragment {
+ private static final int INDEX_BRIEF_FRAGMENT = 0;
+ private static final int INDEX_SUMMARY_FRAGMENT = 1;
+
private ViewPager mViewPager;
+ private View mHeaderView;
private DashboardViewPagerAdapter mPagerAdapter;
@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(getChildFragmentManager());
+ 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();
+ final Activity activity = getActivity();
+ if (activity instanceof SettingsDrawerActivity) {
+ ((SettingsDrawerActivity) getActivity()).setContentHeaderView(mHeaderView);
+ }
+ }
+
private static final class DashboardViewPagerAdapter extends FragmentPagerAdapter {
+ private final Context mContext;
- public DashboardViewPagerAdapter(FragmentManager fragmentManager) {
+ public DashboardViewPagerAdapter(Context context, FragmentManager fragmentManager) {
super(fragmentManager);
+ mContext = context;
+ }
+
+ @Override
+ public CharSequence getPageTitle(int position) {
+ switch (position) {
+ case INDEX_BRIEF_FRAGMENT:
+ return mContext.getString(R.string.page_tab_title_status);
+ case INDEX_SUMMARY_FRAGMENT:
+ return mContext.getString(R.string.page_tab_title_summary);
+ }
+ return super.getPageTitle(position);
}
@Override
public Fragment getItem(int position) {
switch (position) {
- case 0:
+ case INDEX_BRIEF_FRAGMENT:
+ return new DashboardStatusFragment();
+ case INDEX_SUMMARY_FRAGMENT:
return new DashboardSummary();
default:
throw new IllegalArgumentException(
@Override
public int getCount() {
- return 1;
+ return 2;
}
}
}
--- /dev/null
+/*
+ * 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.os.Bundle;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+
+import com.android.settings.InstrumentedFragment;
+import com.android.settings.R;
+
+/**
+ * Dashboard fragment for showing status and suggestions.
+ */
+public final class DashboardStatusFragment extends InstrumentedFragment {
+
+ @Override
+ protected int getMetricsCategory() {
+ return DASHBOARD_STATUS;
+ }
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) {
+ return inflater.inflate(R.layout.dashboard_status, parent, false);
+ }
+}
--- /dev/null
+/*
+ * 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.widget;
+
+import android.content.Context;
+import android.support.v4.view.PagerAdapter;
+import android.support.v4.view.ViewPager;
+import android.util.AttributeSet;
+import android.view.Gravity;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.widget.FrameLayout;
+import android.widget.LinearLayout;
+import android.widget.TextView;
+
+import com.android.settings.R;
+
+/**
+ * To be used with ViewPager to provide a tab indicator component which give constant feedback as
+ * to the user's scroll progress.
+ */
+public final class SlidingTabLayout extends FrameLayout implements View.OnClickListener {
+
+ private final LinearLayout mTitleView;
+ private final View mIndicatorView;
+ private final LayoutInflater mLayoutInflater;
+
+ private ViewPager mViewPager;
+ private int mSelectedPosition;
+ private float mSelectionOffset;
+
+ public SlidingTabLayout(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ mLayoutInflater = LayoutInflater.from(context);
+ mTitleView = new LinearLayout(context);
+ mTitleView.setGravity(Gravity.CENTER_HORIZONTAL);
+ mIndicatorView = mLayoutInflater.inflate(R.layout.sliding_tab_indicator_view, this, false);
+
+ addView(mTitleView, LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
+ addView(mIndicatorView, mIndicatorView.getLayoutParams());
+ }
+
+ /**
+ * Sets the associated view pager. Note that the assumption here is that the pager content
+ * (number of tabs and tab titles) does not change after this call has been made.
+ */
+ public void setViewPager(ViewPager viewPager) {
+ mTitleView.removeAllViews();
+
+ mViewPager = viewPager;
+ if (viewPager != null) {
+ viewPager.addOnPageChangeListener(new InternalViewPagerListener());
+ populateTabStrip();
+ }
+ }
+
+ @Override
+ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
+ super.onMeasure(widthMeasureSpec, heightMeasureSpec);
+ final int titleCount = mTitleView.getChildCount();
+ if (titleCount > 0) {
+ final int width = MeasureSpec.makeMeasureSpec(
+ mTitleView.getMeasuredWidth() / titleCount, MeasureSpec.EXACTLY);
+ final int height = MeasureSpec.makeMeasureSpec(
+ mIndicatorView.getMeasuredHeight(), MeasureSpec.EXACTLY);
+ mIndicatorView.measure(width, height);
+ }
+ }
+
+ @Override
+ protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
+ if (mTitleView.getChildCount() > 0) {
+ mTitleView.layout(0, 0, mTitleView.getMeasuredWidth(), mTitleView.getMeasuredHeight());
+ final int indicatorBottom = getMeasuredHeight();
+ final int indicatorHeight = mIndicatorView.getMeasuredHeight();
+ mIndicatorView.layout(0, indicatorBottom - indicatorHeight,
+ mIndicatorView.getMeasuredWidth(), indicatorBottom);
+ }
+ }
+
+ @Override
+ public void onClick(View v) {
+ final int titleCount = mTitleView.getChildCount();
+ for (int i = 0; i < titleCount; i++) {
+ if (v == mTitleView.getChildAt(i)) {
+ mViewPager.setCurrentItem(i);
+ return;
+ }
+ }
+ }
+
+ private void onViewPagerPageChanged(int position, float positionOffset) {
+ mSelectedPosition = position;
+ mSelectionOffset = positionOffset;
+ mIndicatorView.setTranslationX(getIndicatorLeft());
+ }
+
+ private void populateTabStrip() {
+ final PagerAdapter adapter = mViewPager.getAdapter();
+
+ for (int i = 0; i < adapter.getCount(); i++) {
+ final TextView tabTitleView = (TextView) mLayoutInflater.inflate(
+ R.layout.sliding_tab_title_view, mTitleView, false);
+
+ tabTitleView.setText(adapter.getPageTitle(i));
+ tabTitleView.setOnClickListener(this);
+
+ mTitleView.addView(tabTitleView);
+ if (i == mViewPager.getCurrentItem()) {
+ tabTitleView.setSelected(true);
+ }
+ }
+ }
+
+ private int getIndicatorLeft() {
+ View selectedTitle = mTitleView.getChildAt(mSelectedPosition);
+ int left = selectedTitle.getLeft();
+ if (mSelectionOffset > 0f && mSelectedPosition < (getChildCount() - 1)) {
+ View nextTitle = mTitleView.getChildAt(mSelectedPosition + 1);
+ left = (int) (mSelectionOffset * nextTitle.getLeft()
+ + (1.0f - mSelectionOffset) * left);
+ }
+ return left;
+ }
+
+ private final class InternalViewPagerListener implements ViewPager.OnPageChangeListener {
+ private int mScrollState;
+
+ @Override
+ public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
+ final int titleCount = mTitleView.getChildCount();
+ if ((titleCount == 0) || (position < 0) || (position >= titleCount)) {
+ return;
+ }
+ onViewPagerPageChanged(position, positionOffset);
+ }
+
+ @Override
+ public void onPageScrollStateChanged(int state) {
+ mScrollState = state;
+ }
+
+ @Override
+ public void onPageSelected(int position) {
+ if (mScrollState == ViewPager.SCROLL_STATE_IDLE) {
+ onViewPagerPageChanged(position, 0f);
+ }
+ final int titleCount = getChildCount();
+ for (int i = 0; i < titleCount; i++) {
+ getChildAt(i).setSelected(position == i);
+ }
+ }
+ }
+}