mirror of
https://github.com/MatomoCamp/matomocamp-companion-android.git
synced 2024-09-19 16:13:46 +02:00
Moved SlidingTabLayout to the main widgets package; merged some of its files
This commit is contained in:
parent
9faca330bf
commit
10bd2a7108
8 changed files with 73 additions and 104 deletions
|
@ -10,7 +10,7 @@ import android.view.LayoutInflater;
|
|||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.example.android.common.view.SlidingTabLayout;
|
||||
import be.digitalia.fosdem.widgets.SlidingTabLayout;
|
||||
|
||||
import be.digitalia.fosdem.R;
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ import android.view.LayoutInflater;
|
|||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.example.android.common.view.SlidingTabLayout;
|
||||
import be.digitalia.fosdem.widgets.SlidingTabLayout;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
|
|
@ -15,12 +15,14 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.example.android.common.view;
|
||||
package be.digitalia.fosdem.widgets;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.ColorStateList;
|
||||
import android.content.res.TypedArray;
|
||||
import android.database.DataSetObserver;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.Typeface;
|
||||
import android.os.Build;
|
||||
import android.support.annotation.ColorInt;
|
||||
|
@ -327,4 +329,61 @@ public class SlidingTabLayout extends HorizontalScrollView {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class SlidingTabStrip extends LinearLayout {
|
||||
|
||||
private int mSelectedIndicatorHeight;
|
||||
private final Paint mSelectedIndicatorPaint;
|
||||
|
||||
private int mSelectedPosition;
|
||||
private float mSelectionOffset;
|
||||
|
||||
SlidingTabStrip(Context context) {
|
||||
super(context);
|
||||
setWillNotDraw(false);
|
||||
mSelectedIndicatorPaint = new Paint();
|
||||
}
|
||||
|
||||
void setSelectedIndicatorColor(@ColorInt int color) {
|
||||
mSelectedIndicatorPaint.setColor(color);
|
||||
invalidate();
|
||||
}
|
||||
|
||||
void setSelectedIndicatorHeight(int height) {
|
||||
mSelectedIndicatorHeight = height;
|
||||
invalidate();
|
||||
}
|
||||
|
||||
void onViewPagerPageChanged(int position, float positionOffset) {
|
||||
mSelectedPosition = position;
|
||||
mSelectionOffset = positionOffset;
|
||||
invalidate();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDraw(Canvas canvas) {
|
||||
final int height = getHeight();
|
||||
final int childCount = getChildCount();
|
||||
|
||||
// Thick colored underline below the current selection
|
||||
if (childCount > 0) {
|
||||
View selectedTitle = getChildAt(mSelectedPosition);
|
||||
int left = selectedTitle.getLeft();
|
||||
int right = selectedTitle.getRight();
|
||||
|
||||
if (mSelectionOffset > 0f && mSelectedPosition < (getChildCount() - 1)) {
|
||||
// Draw the selection partway between the tabs
|
||||
View nextTitle = getChildAt(mSelectedPosition + 1);
|
||||
left = (int) (mSelectionOffset * nextTitle.getLeft() +
|
||||
(1.0f - mSelectionOffset) * left);
|
||||
right = (int) (mSelectionOffset * nextTitle.getRight() +
|
||||
(1.0f - mSelectionOffset) * right);
|
||||
}
|
||||
|
||||
canvas.drawRect(left, height - mSelectedIndicatorHeight, right,
|
||||
height, mSelectedIndicatorPaint);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,86 +0,0 @@
|
|||
/*
|
||||
* Copyright 2014 Chris Banes
|
||||
*
|
||||
* 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.example.android.common.view;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
import android.support.annotation.ColorInt;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
class SlidingTabStrip extends LinearLayout {
|
||||
|
||||
private int mSelectedIndicatorHeight;
|
||||
private final Paint mSelectedIndicatorPaint;
|
||||
|
||||
private int mSelectedPosition;
|
||||
private float mSelectionOffset;
|
||||
|
||||
SlidingTabStrip(Context context) {
|
||||
this(context, null);
|
||||
}
|
||||
|
||||
SlidingTabStrip(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
setWillNotDraw(false);
|
||||
mSelectedIndicatorPaint = new Paint();
|
||||
}
|
||||
|
||||
void setSelectedIndicatorColor(@ColorInt int color) {
|
||||
mSelectedIndicatorPaint.setColor(color);
|
||||
invalidate();
|
||||
}
|
||||
|
||||
void setSelectedIndicatorHeight(int height) {
|
||||
mSelectedIndicatorHeight = height;
|
||||
invalidate();
|
||||
}
|
||||
|
||||
void onViewPagerPageChanged(int position, float positionOffset) {
|
||||
mSelectedPosition = position;
|
||||
mSelectionOffset = positionOffset;
|
||||
invalidate();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDraw(Canvas canvas) {
|
||||
final int height = getHeight();
|
||||
final int childCount = getChildCount();
|
||||
|
||||
// Thick colored underline below the current selection
|
||||
if (childCount > 0) {
|
||||
View selectedTitle = getChildAt(mSelectedPosition);
|
||||
int left = selectedTitle.getLeft();
|
||||
int right = selectedTitle.getRight();
|
||||
|
||||
if (mSelectionOffset > 0f && mSelectedPosition < (getChildCount() - 1)) {
|
||||
// Draw the selection partway between the tabs
|
||||
View nextTitle = getChildAt(mSelectedPosition + 1);
|
||||
left = (int) (mSelectionOffset * nextTitle.getLeft() +
|
||||
(1.0f - mSelectionOffset) * left);
|
||||
right = (int) (mSelectionOffset * nextTitle.getRight() +
|
||||
(1.0f - mSelectionOffset) * right);
|
||||
}
|
||||
|
||||
canvas.drawRect(left, height - mSelectedIndicatorHeight, right,
|
||||
height, mSelectedIndicatorPaint);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -5,7 +5,7 @@
|
|||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<com.example.android.common.view.SlidingTabLayout
|
||||
<be.digitalia.fosdem.widgets.SlidingTabLayout
|
||||
android:id="@+id/sliding_tabs"
|
||||
style="@style/SlidingTabs"
|
||||
android:layout_width="match_parent"
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<com.example.android.common.view.SlidingTabLayout
|
||||
<be.digitalia.fosdem.widgets.SlidingTabLayout
|
||||
android:id="@+id/sliding_tabs"
|
||||
style="@style/SlidingTabs"
|
||||
android:layout_width="match_parent"
|
||||
|
|
|
@ -13,6 +13,15 @@
|
|||
<attr name="distributeEvenly" format="boolean"/>
|
||||
</declare-styleable>
|
||||
|
||||
<style name="SlidingTabLayout" parent="android:Widget">
|
||||
<item name="indicatorColor">?attr/colorAccent</item>
|
||||
<item name="indicatorHeight">2dp</item>
|
||||
<item name="textColor">?android:textColorSecondary</item>
|
||||
<item name="selectedTextColor">?android:textColorPrimary</item>
|
||||
<item name="contentInsetStart">24dp</item>
|
||||
<item name="distributeEvenly">false</item>
|
||||
</style>
|
||||
|
||||
<declare-styleable name="ScrimInsetsFrameLayout">
|
||||
<attr name="insetForeground" format="color|reference"/>
|
||||
</declare-styleable>
|
||||
|
|
|
@ -1,13 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
|
||||
<style name="SlidingTabLayout" parent="android:Widget">
|
||||
<item name="indicatorColor">?attr/colorAccent</item>
|
||||
<item name="indicatorHeight">2dp</item>
|
||||
<item name="textColor">?android:textColorSecondary</item>
|
||||
<item name="selectedTextColor">?android:textColorPrimary</item>
|
||||
<item name="contentInsetStart">24dp</item>
|
||||
<item name="distributeEvenly">false</item>
|
||||
</style>
|
||||
|
||||
</resources>
|
Loading…
Reference in a new issue