diff options
-rw-r--r-- | res/drawable/view_pager_tab_background.xml | 22 | ||||
-rw-r--r-- | res/layout/call_log_activity.xml | 2 | ||||
-rw-r--r-- | res/layout/lists_fragment.xml | 2 | ||||
-rw-r--r-- | res/values/colors.xml | 3 | ||||
-rw-r--r-- | res/values/dimens.xml | 1 | ||||
-rw-r--r-- | src/com/android/dialer/calllog/CallLogActivity.java | 2 | ||||
-rw-r--r-- | src/com/android/dialer/list/ListsFragment.java | 1 | ||||
-rw-r--r-- | src/com/android/dialer/list/ViewPagerTabStrip.java | 105 | ||||
-rw-r--r-- | src/com/android/dialer/list/ViewPagerTabs.java | 201 |
9 files changed, 4 insertions, 335 deletions
diff --git a/res/drawable/view_pager_tab_background.xml b/res/drawable/view_pager_tab_background.xml deleted file mode 100644 index 1ba6c57e0..000000000 --- a/res/drawable/view_pager_tab_background.xml +++ /dev/null @@ -1,22 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<!-- - ~ Copyright (C) 2014 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 - --> -<ripple xmlns:android="http://schemas.android.com/apk/res/android" - android:color="@color/tab_ripple_color"> - <item android:id="@android:id/mask"> - <color android:color="@android:color/white" /> - </item> -</ripple>
\ No newline at end of file diff --git a/res/layout/call_log_activity.xml b/res/layout/call_log_activity.xml index 3b7609fae..0109df7d6 100644 --- a/res/layout/call_log_activity.xml +++ b/res/layout/call_log_activity.xml @@ -19,7 +19,7 @@ android:layout_height="match_parent" android:id="@+id/calllog_frame" android:orientation="vertical"> - <com.android.dialer.list.ViewPagerTabs + <com.android.contacts.common.list.ViewPagerTabs android:id="@+id/viewpager_header" android:layout_width="match_parent" android:layout_height="@dimen/tab_height" diff --git a/res/layout/lists_fragment.xml b/res/layout/lists_fragment.xml index 1de8364b7..987c61f99 100644 --- a/res/layout/lists_fragment.xml +++ b/res/layout/lists_fragment.xml @@ -40,7 +40,7 @@ android:layout_height="match_parent" android:orientation="vertical"> - <com.android.dialer.list.ViewPagerTabs + <com.android.contacts.common.list.ViewPagerTabs android:id="@+id/lists_pager_header" android:layout_width="match_parent" android:layout_height="@dimen/tab_height" diff --git a/res/values/colors.xml b/res/values/colors.xml index 0b75de5d0..d7a929fda 100644 --- a/res/values/colors.xml +++ b/res/values/colors.xml @@ -93,7 +93,4 @@ <color name="actionbar_icon_color">#ffffff</color> <color name="dialer_dialpad_touch_tint">#331dc7db</color> - - <color name="tab_ripple_color">@color/dialer_accent_color</color> - <color name="tab_selected_underline_color">@color/dialer_accent_color</color> </resources> diff --git a/res/values/dimens.xml b/res/values/dimens.xml index cdeff85bd..b7aceef28 100644 --- a/res/values/dimens.xml +++ b/res/values/dimens.xml @@ -84,7 +84,6 @@ room to the search box--> <dimen name="action_bar_height">64dp</dimen> <dimen name="tab_height">43dp</dimen> - <dimen name="tab_elevation">2dp</dimen> <!-- actionbar height + tab height --> <dimen name="actionbar_and_tab_height">107dp</dimen> diff --git a/src/com/android/dialer/calllog/CallLogActivity.java b/src/com/android/dialer/calllog/CallLogActivity.java index f743f7ab5..4e969e189 100644 --- a/src/com/android/dialer/calllog/CallLogActivity.java +++ b/src/com/android/dialer/calllog/CallLogActivity.java @@ -31,7 +31,7 @@ import android.view.MenuItem; import com.android.dialer.DialtactsActivity; import com.android.dialer.R; -import com.android.dialer.list.ViewPagerTabs; +import com.android.contacts.common.list.ViewPagerTabs; import com.android.dialer.voicemail.VoicemailStatusHelper; import com.android.dialer.voicemail.VoicemailStatusHelperImpl; diff --git a/src/com/android/dialer/list/ListsFragment.java b/src/com/android/dialer/list/ListsFragment.java index 103eef780..847edd9a0 100644 --- a/src/com/android/dialer/list/ListsFragment.java +++ b/src/com/android/dialer/list/ListsFragment.java @@ -24,6 +24,7 @@ import android.view.ViewGroup; import android.widget.ListView; import com.android.contacts.common.GeoUtil; +import com.android.contacts.common.list.ViewPagerTabs; import com.android.dialer.DialtactsActivity; import android.view.View.OnClickListener; diff --git a/src/com/android/dialer/list/ViewPagerTabStrip.java b/src/com/android/dialer/list/ViewPagerTabStrip.java deleted file mode 100644 index ac16694b3..000000000 --- a/src/com/android/dialer/list/ViewPagerTabStrip.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright (C) 2014 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.dialer.list; - -import android.content.Context; -import android.content.res.Resources; -import android.graphics.Canvas; -import android.graphics.Paint; -import android.util.AttributeSet; -import android.view.View; -import android.widget.LinearLayout; - -import com.android.dialer.R; - -public class ViewPagerTabStrip extends LinearLayout { - private int mSelectedUnderlineThickness; - private final Paint mSelectedUnderlinePaint; - - private int mIndexForSelection; - private float mSelectionOffset; - - public ViewPagerTabStrip(Context context) { - this(context, null); - } - - public ViewPagerTabStrip(Context context, AttributeSet attrs) { - super(context, attrs); - - final Resources res = context.getResources(); - - mSelectedUnderlineThickness = - res.getDimensionPixelSize(R.dimen.tab_selected_underline_height); - int underlineColor = res.getColor(R.color.tab_selected_underline_color); - int backgroundColor = res.getColor(R.color.actionbar_background_color); - - mSelectedUnderlinePaint = new Paint(); - mSelectedUnderlinePaint.setColor(underlineColor); - - setBackgroundColor(backgroundColor); - setWillNotDraw(false); - } - - /** - * Notifies this view that view pager has been scrolled. We save the tab index - * and selection offset for interpolating the position and width of selection - * underline. - */ - void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { - mIndexForSelection = position; - mSelectionOffset = positionOffset; - invalidate(); - } - - /** - * Notifies this view that a new page has been selected in the view pager. We save the tab - * index and reset the selection offset to 0. - */ - void onPageSelected(int position) { - mIndexForSelection = position; - mSelectionOffset = 0; - invalidate(); - } - - @Override - protected void onDraw(Canvas canvas) { - int childCount = getChildCount(); - - // Thick colored underline below the current selection - if (childCount > 0) { - View selectedTitle = getChildAt(mIndexForSelection); - int selectedLeft = selectedTitle.getLeft(); - int selectedRight = selectedTitle.getRight(); - if ((mSelectionOffset > 0.0f) && - (mIndexForSelection < (getChildCount() - 1))) { - // Draw the selection partway between the tabs - View nextTitle = getChildAt(mIndexForSelection + 1); - int nextLeft = nextTitle.getLeft(); - int nextRight = nextTitle.getRight(); - - selectedLeft = (int) (mSelectionOffset * nextLeft + - (1.0f - mSelectionOffset) * selectedLeft); - selectedRight = (int) (mSelectionOffset * nextRight + - (1.0f - mSelectionOffset) * selectedRight); - } - - int height = getHeight(); - canvas.drawRect(selectedLeft, height - mSelectedUnderlineThickness, - selectedRight, height, mSelectedUnderlinePaint); - } - } -}
\ No newline at end of file diff --git a/src/com/android/dialer/list/ViewPagerTabs.java b/src/com/android/dialer/list/ViewPagerTabs.java deleted file mode 100644 index 3717369a2..000000000 --- a/src/com/android/dialer/list/ViewPagerTabs.java +++ /dev/null @@ -1,201 +0,0 @@ -package com.android.dialer.list; - -import android.content.Context; -import android.content.res.ColorStateList; -import android.content.res.TypedArray; -import android.graphics.Outline; -import android.support.v4.view.PagerAdapter; -import android.support.v4.view.ViewPager; -import android.util.AttributeSet; -import android.util.TypedValue; -import android.view.Gravity; -import android.view.View; -import android.view.ViewOutlineProvider; -import android.widget.FrameLayout; -import android.widget.HorizontalScrollView; -import android.widget.LinearLayout; -import android.widget.TextView; -import android.widget.Toast; - -import com.android.dialer.R; - -/** - * Lightweight implementation of ViewPager tabs. This looks similar to traditional actionBar tabs, - * but allows for the view containing the tabs to be placed anywhere on screen. Text-related - * attributes can also be assigned in XML - these will get propogated to the child TextViews - * automatically. - */ -public class ViewPagerTabs extends HorizontalScrollView implements ViewPager.OnPageChangeListener { - - ViewPager mPager; - private ViewPagerTabStrip mTabStrip; - - /** - * Linearlayout that will contain the TextViews serving as tabs. This is the only child - * of the parent HorizontalScrollView. - */ - final int mTextStyle; - final ColorStateList mTextColor; - final int mTextSize; - final boolean mTextAllCaps; - int mPrevSelected = -1; - int mSidePadding; - - private static final ViewOutlineProvider VIEW_BOUNDS_OUTLINE_PROVIDER = - new ViewOutlineProvider() { - @Override - public void getOutline(View view, Outline outline) { - outline.setRect(0, 0, view.getWidth(), view.getHeight()); - } - }; - - private static final int TAB_SIDE_PADDING_IN_DPS = 10; - - // TODO: This should use <declare-styleable> in the future - private static final int[] ATTRS = new int[] { - android.R.attr.textSize, - android.R.attr.textStyle, - android.R.attr.textColor, - android.R.attr.textAllCaps - }; - - /** - * Simulates actionbar tab behavior by showing a toast with the tab title when long clicked. - */ - private class OnTabLongClickListener implements OnLongClickListener { - final int mPosition; - - public OnTabLongClickListener(int position) { - mPosition = position; - } - - @Override - public boolean onLongClick(View v) { - final int[] screenPos = new int[2]; - getLocationOnScreen(screenPos); - - final Context context = getContext(); - final int width = getWidth(); - final int height = getHeight(); - final int screenWidth = context.getResources().getDisplayMetrics().widthPixels; - - Toast toast = Toast.makeText(context, mPager.getAdapter().getPageTitle(mPosition), - Toast.LENGTH_SHORT); - - // Show the toast under the tab - toast.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL, - (screenPos[0] + width / 2) - screenWidth / 2, screenPos[1] + height); - - toast.show(); - return true; - } - } - - public ViewPagerTabs(Context context) { - this(context, null); - } - - public ViewPagerTabs(Context context, AttributeSet attrs) { - this(context, attrs, 0); - } - - public ViewPagerTabs(Context context, AttributeSet attrs, int defStyle) { - super(context, attrs, defStyle); - setFillViewport(true); - - mSidePadding = (int) (getResources().getDisplayMetrics().density * TAB_SIDE_PADDING_IN_DPS); - - final TypedArray a = context.obtainStyledAttributes(attrs, ATTRS); - mTextSize = a.getDimensionPixelSize(0, 0); - mTextStyle = a.getInt(1, 0); - mTextColor = a.getColorStateList(2); - mTextAllCaps = a.getBoolean(3, false); - - mTabStrip = new ViewPagerTabStrip(context); - addView(mTabStrip, - new FrameLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT)); - a.recycle(); - - // enable shadow casting from view bounds - setOutlineProvider(VIEW_BOUNDS_OUTLINE_PROVIDER); - } - - public void setViewPager(ViewPager viewPager) { - mPager = viewPager; - addTabs(mPager.getAdapter()); - } - - private void addTabs(PagerAdapter adapter) { - mTabStrip.removeAllViews(); - - final int count = adapter.getCount(); - for (int i = 0; i < count; i++) { - addTab(adapter.getPageTitle(i), i); - } - } - - private void addTab(CharSequence tabTitle, final int position) { - final TextView textView = new TextView(getContext()); - textView.setText(tabTitle); - textView.setBackgroundResource(R.drawable.view_pager_tab_background); - textView.setGravity(Gravity.CENTER); - textView.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { - mPager.setCurrentItem(position); - } - }); - - textView.setOnLongClickListener(new OnTabLongClickListener(position)); - - // Assign various text appearance related attributes to child views. - if (mTextStyle > 0) { - textView.setTypeface(textView.getTypeface(), mTextStyle); - } - if (mTextSize > 0) { - textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTextSize); - } - if (mTextColor != null) { - textView.setTextColor(mTextColor); - } - textView.setAllCaps(mTextAllCaps); - textView.setPadding(mSidePadding, 0, mSidePadding, 0); - mTabStrip.addView(textView, new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, - LayoutParams.MATCH_PARENT, 1)); - // Default to the first child being selected - if (position == 0) { - mPrevSelected = 0; - textView.setSelected(true); - } - } - - @Override - public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { - int tabStripChildCount = mTabStrip.getChildCount(); - if ((tabStripChildCount == 0) || (position < 0) || (position >= tabStripChildCount)) { - return; - } - - mTabStrip.onPageScrolled(position, positionOffset, positionOffsetPixels); - smoothScrollTo(position, 0); - } - - @Override - public void onPageSelected(int position) { - if (mPrevSelected >= 0) { - mTabStrip.getChildAt(mPrevSelected).setSelected(false); - } - final View selectedChild = mTabStrip.getChildAt(position); - selectedChild.setSelected(true); - - // Update scroll position - final int scrollPos = selectedChild.getLeft() - (getWidth() - selectedChild.getWidth()) / 2; - smoothScrollTo(scrollPos, 0); - mPrevSelected = position; - } - - @Override - public void onPageScrollStateChanged(int state) { - } -} - |