diff options
author | linuxx <io.nolinuxnoparty@gmail.com> | 2014-12-10 18:25:02 +0100 |
---|---|---|
committer | Steve Kondik <shade@chemlab.org> | 2014-12-27 12:30:57 +0000 |
commit | 81e13fbe95084ce894f5d196c73532ff202b9532 (patch) | |
tree | 41a4eb117f16b4ffb072445af0012bbc43df0528 /src/com/cyanogenmod/eleven/widgets | |
parent | dc144e3c1f422dba925b0a62cbb87b7c024ef1b7 (diff) | |
download | android_packages_apps_Eleven-81e13fbe95084ce894f5d196c73532ff202b9532.tar.gz android_packages_apps_Eleven-81e13fbe95084ce894f5d196c73532ff202b9532.tar.bz2 android_packages_apps_Eleven-81e13fbe95084ce894f5d196c73532ff202b9532.zip |
Eleven: materialize
-Material Ui theme
-New launcher icon
-Better tabs
Change-Id: I712ac2eb5256841cf89d198eed775ce8afe9d09c
Diffstat (limited to 'src/com/cyanogenmod/eleven/widgets')
7 files changed, 334 insertions, 87 deletions
diff --git a/src/com/cyanogenmod/eleven/widgets/AudioButton.java b/src/com/cyanogenmod/eleven/widgets/AudioButton.java index 1f5f70f..1e05e81 100644 --- a/src/com/cyanogenmod/eleven/widgets/AudioButton.java +++ b/src/com/cyanogenmod/eleven/widgets/AudioButton.java @@ -8,8 +8,8 @@ import android.view.View.OnClickListener; import android.view.View.OnLongClickListener; import android.widget.ImageButton; +import com.cyanogenmod.eleven.R; import com.cyanogenmod.eleven.utils.ApolloUtils; -import com.cyanogenmod.eleven.widgets.theme.HoloSelector; public abstract class AudioButton extends ImageButton implements OnClickListener, OnLongClickListener { public static float ACTIVE_ALPHA = 1.0f; @@ -18,9 +18,8 @@ public abstract class AudioButton extends ImageButton implements OnClickListener @SuppressWarnings("deprecation") public AudioButton(final Context context, final AttributeSet attrs) { super(context, attrs); - // Theme the selector setPadding(0, 0, 0, 0); - setBackgroundDrawable(new HoloSelector(context)); + setBackground(getResources().getDrawable(R.drawable.selectable_background)); // Control playback (cycle shuffle) setOnClickListener(this); // Show the cheat sheet @@ -36,4 +35,4 @@ public abstract class AudioButton extends ImageButton implements OnClickListener return true; } } -}
\ No newline at end of file +} diff --git a/src/com/cyanogenmod/eleven/widgets/PlayPauseButton.java b/src/com/cyanogenmod/eleven/widgets/PlayPauseButton.java index 1b8e988..2b68d02 100644 --- a/src/com/cyanogenmod/eleven/widgets/PlayPauseButton.java +++ b/src/com/cyanogenmod/eleven/widgets/PlayPauseButton.java @@ -24,11 +24,10 @@ import android.widget.ImageButton; import com.cyanogenmod.eleven.R; import com.cyanogenmod.eleven.utils.ApolloUtils; import com.cyanogenmod.eleven.utils.MusicUtils; -import com.cyanogenmod.eleven.widgets.theme.HoloSelector; /** * A custom {@link ImageButton} that represents the "play and pause" button. - * + * * @author Andrew Neal (andrewdneal@gmail.com) */ public class PlayPauseButton extends ImageButton implements OnClickListener, OnLongClickListener { @@ -50,8 +49,7 @@ public class PlayPauseButton extends ImageButton implements OnClickListener, OnL @SuppressWarnings("deprecation") public PlayPauseButton(final Context context, final AttributeSet attrs) { super(context, attrs); - // Theme the selector - setBackgroundDrawable(new HoloSelector(context)); + setBackground(getResources().getDrawable(R.drawable.selectable_background)); // Control playback (play/pause) setOnClickListener(this); // Show the cheat sheet diff --git a/src/com/cyanogenmod/eleven/widgets/PopupMenuButton.java b/src/com/cyanogenmod/eleven/widgets/PopupMenuButton.java index f45bb47..c23ef35 100644 --- a/src/com/cyanogenmod/eleven/widgets/PopupMenuButton.java +++ b/src/com/cyanogenmod/eleven/widgets/PopupMenuButton.java @@ -21,6 +21,8 @@ import android.util.AttributeSet; import android.view.View; import android.widget.ImageView; +import com.cyanogenmod.eleven.R; + public class PopupMenuButton extends ImageView implements IPopupMenuCallback, View.OnClickListener { protected int mPosition = -1; @@ -29,6 +31,7 @@ public class PopupMenuButton extends ImageView implements IPopupMenuCallback, public PopupMenuButton(Context context, AttributeSet attrs) { super(context, attrs); + setBackground(getResources().getDrawable(R.drawable.selectable_background_light)); setOnClickListener(this); } diff --git a/src/com/cyanogenmod/eleven/widgets/RepeatingImageButton.java b/src/com/cyanogenmod/eleven/widgets/RepeatingImageButton.java index 9fb6758..d51154b 100644 --- a/src/com/cyanogenmod/eleven/widgets/RepeatingImageButton.java +++ b/src/com/cyanogenmod/eleven/widgets/RepeatingImageButton.java @@ -23,7 +23,6 @@ import android.widget.ImageButton; import com.cyanogenmod.eleven.R; import com.cyanogenmod.eleven.utils.ApolloUtils; import com.cyanogenmod.eleven.utils.MusicUtils; -import com.cyanogenmod.eleven.widgets.theme.HoloSelector; /** * A {@link ImageButton} that will repeatedly call a 'listener' method as long @@ -47,9 +46,8 @@ public class RepeatingImageButton extends ImageButton implements OnClickListener @SuppressWarnings("deprecation") public RepeatingImageButton(final Context context, final AttributeSet attrs) { super(context, attrs); - // Theme the selector setPadding(0, 0, 0, 0); - setBackgroundDrawable(new HoloSelector(context)); + setBackground(getResources().getDrawable(R.drawable.selectable_background)); setFocusable(true); setLongClickable(true); setOnClickListener(this); diff --git a/src/com/cyanogenmod/eleven/widgets/ViewPagerTabStrip.java b/src/com/cyanogenmod/eleven/widgets/ViewPagerTabStrip.java new file mode 100644 index 0000000..d1ef9c3 --- /dev/null +++ b/src/com/cyanogenmod/eleven/widgets/ViewPagerTabStrip.java @@ -0,0 +1,101 @@ +/* + * 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.cyanogenmod.eleven.widgets; + +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.cyanogenmod.eleven.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.header_action_bar_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(); + } + + @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(); + final boolean isRtl = isRtl(); + final boolean hasNextTab = isRtl ? mIndexForSelection > 0 + : (mIndexForSelection < (getChildCount() - 1)); + if ((mSelectionOffset > 0.0f) && hasNextTab) { + // Draw the selection partway between the tabs + View nextTitle = getChildAt(mIndexForSelection + (isRtl ? -1 : 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); + } + } + + private boolean isRtl() { + return getLayoutDirection() == View.LAYOUT_DIRECTION_RTL; + } +} diff --git a/src/com/cyanogenmod/eleven/widgets/ViewPagerTabs.java b/src/com/cyanogenmod/eleven/widgets/ViewPagerTabs.java new file mode 100644 index 0000000..c02926d --- /dev/null +++ b/src/com/cyanogenmod/eleven/widgets/ViewPagerTabs.java @@ -0,0 +1,224 @@ +/* + * 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.cyanogenmod.eleven.widgets; + +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.cyanogenmod.eleven.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(getRtlPosition(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) { + position = getRtlPosition(position); + int tabStripChildCount = mTabStrip.getChildCount(); + if ((tabStripChildCount == 0) || (position < 0) || (position >= tabStripChildCount)) { + return; + } + + mTabStrip.onPageScrolled(position, positionOffset, positionOffsetPixels); + } + + @Override + public void onPageSelected(int position) { + position = getRtlPosition(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) { + } + + private int getRtlPosition(int position) { + if (getLayoutDirection() == View.LAYOUT_DIRECTION_RTL) { + return mTabStrip.getChildCount() - 1 - position; + } + return position; + } +} + diff --git a/src/com/cyanogenmod/eleven/widgets/theme/HoloSelector.java b/src/com/cyanogenmod/eleven/widgets/theme/HoloSelector.java deleted file mode 100644 index 2ec6348..0000000 --- a/src/com/cyanogenmod/eleven/widgets/theme/HoloSelector.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright (C) 2012 Andrew Neal - * Copyright (C) 2014 The CyanogenMod 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.cyanogenmod.eleven.widgets.theme; - -import android.annotation.SuppressLint; -import android.content.Context; -import android.graphics.Color; -import android.graphics.drawable.ColorDrawable; -import android.graphics.drawable.StateListDrawable; - -import com.cyanogenmod.eleven.R; - -import java.lang.ref.WeakReference; - -/** - * A themeable {@link StateListDrawable}. - * - * @author Andrew Neal (andrewdneal@gmail.com) - */ -public class HoloSelector extends StateListDrawable { - - /** - * Used to theme the touched and focused colors - */ - private static final String RESOURCE_NAME = "holo_selector"; - - /** - * Focused state - */ - private static final int FOCUSED = android.R.attr.state_focused; - - /** - * Pressed state - */ - private static final int PRESSED = android.R.attr.state_pressed; - - /** - * Constructor for <code>HoloSelector</code> - * - * @param context The {@link Context} to use. - */ - @SuppressLint("NewApi") - public HoloSelector(final Context context) { - final int themeColor = context.getResources().getColor(R.color.holo_blue_light); - // Focused - addState(new int[] { - FOCUSED - }, makeColorDrawable(themeColor)); - // Pressed - addState(new int[] { - PRESSED - }, makeColorDrawable(themeColor)); - // Default - addState(new int[] {}, makeColorDrawable(Color.TRANSPARENT)); - setExitFadeDuration(400); - } - - /** - * @param color The color to use. - * @return A new {@link ColorDrawable}. - */ - private static final ColorDrawable makeColorDrawable(final int color) { - return new WeakReference<ColorDrawable>(new ColorDrawable(color)).get(); - } -} |