Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Development - SmartTabLayout 2 for ViewPager2 support #2

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ apply plugin: 'com.github.ben-manes.versions'
apply plugin: 'com.github.hierynomus.license'

android {
compileSdkVersion COMPILE_SDK_VERSION as int
compileSdkVersion buildConfig.compileSdk
resourcePrefix 'stl_'

defaultConfig {
minSdkVersion 14
targetSdkVersion COMPILE_SDK_VERSION as int
versionCode VERSION_CODE as int
versionName VERSION_NAME
targetSdkVersion buildConfig.targetSdk
versionCode 1
versionName "1.0"

}
buildTypes {
Expand All @@ -22,8 +22,9 @@ android {
}

dependencies {
implementation "androidx.viewpager:viewpager:${ANDROIDX_BASE_VERSION}"
implementation "androidx.fragment:fragment:${ANDROIDX_BASE_VERSION}"
implementation deps.androidx.viewpager
implementation deps.androidx.viewpager2
implementation deps.androidx.fragment.lib
}

license {
Expand All @@ -36,6 +37,3 @@ license {
excludes(["**/*.xml"])

}

pkginfo.name = ARTIFACT_NAME
apply from: "${project.rootDir}/publish.gradle"
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public class SmartTabLayout extends HorizontalScrollView {
private static final int TAB_VIEW_TEXT_COLOR = 0xFC000000;
private static final int TAB_VIEW_TEXT_MIN_WIDTH = 0;
private static final boolean TAB_CLICKABLE = true;
private static final int NO_TEXT_STYLE = -1;

protected final SmartTabStrip tabStrip;
private int titleOffset;
Expand All @@ -86,6 +87,7 @@ public class SmartTabLayout extends HorizontalScrollView {
private InternalTabClickListener internalTabClickListener;
private OnTabClickListener onTabClickListener;
private boolean distributeEvenly;
private int textAppearance;

public SmartTabLayout(Context context) {
this(context, null);
Expand Down Expand Up @@ -116,6 +118,7 @@ public SmartTabLayout(Context context, AttributeSet attrs, int defStyle) {
int customTabTextViewId = NO_ID;
boolean clickable = TAB_CLICKABLE;
int titleOffset = (int) (TITLE_OFFSET_DIPS * density);
int textStyle = NO_TEXT_STYLE;

TypedArray a = context.obtainStyledAttributes(
attrs, R.styleable.stl_SmartTabLayout, defStyle, 0);
Expand All @@ -141,6 +144,7 @@ public SmartTabLayout(Context context, AttributeSet attrs, int defStyle) {
R.styleable.stl_SmartTabLayout_stl_clickable, clickable);
titleOffset = a.getLayoutDimension(
R.styleable.stl_SmartTabLayout_stl_titleOffset, titleOffset);
textStyle = a.getResourceId(R.styleable.stl_SmartTabLayout_stl_tabTextStyle, textStyle);
a.recycle();

this.titleOffset = titleOffset;
Expand All @@ -154,6 +158,7 @@ public SmartTabLayout(Context context, AttributeSet attrs, int defStyle) {
this.tabViewTextMinWidth = textMinWidth;
this.internalTabClickListener = clickable ? new InternalTabClickListener() : null;
this.distributeEvenly = distributeEvenly;
this.textAppearance = textStyle;

if (customTabLayoutId != NO_ID) {
setCustomTabView(customTabLayoutId, customTabTextViewId);
Expand Down Expand Up @@ -348,12 +353,22 @@ protected TextView createDefaultTabView(CharSequence title) {
TextView textView = new TextView(getContext());
textView.setGravity(Gravity.CENTER);
textView.setText(title);
textView.setTextColor(tabViewTextColors);
textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, tabViewTextSize);
textView.setTypeface(Typeface.DEFAULT_BOLD);
textView.setLayoutParams(new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.MATCH_PARENT));
if (textAppearance != NO_TEXT_STYLE) {
textView.setTextAppearance(getContext(), textAppearance);
} else {
textView.setTextColor(tabViewTextColors);
textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, tabViewTextSize);
textView.setTypeface(Typeface.DEFAULT_BOLD);

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
// If we're running on ICS or newer, enable all-caps to match the Action Bar tab style
textView.setAllCaps(tabViewTextAllCaps);
}

if (tabViewTextMinWidth > 0) {
textView.setMinWidth(tabViewTextMinWidth);
}
}
if (tabViewBackgroundResId != NO_ID) {
textView.setBackgroundResource(tabViewBackgroundResId);
} else {
Expand All @@ -364,19 +379,11 @@ protected TextView createDefaultTabView(CharSequence title) {
outValue, true);
textView.setBackgroundResource(outValue.resourceId);
}

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
// If we're running on ICS or newer, enable all-caps to match the Action Bar tab style
textView.setAllCaps(tabViewTextAllCaps);
}

textView.setPadding(
tabViewTextHorizontalPadding, 0,
tabViewTextHorizontalPadding, 0);

if (tabViewTextMinWidth > 0) {
textView.setMinWidth(tabViewTextMinWidth);
}
tabViewTextHorizontalPadding, 0,
tabViewTextHorizontalPadding, 0);
textView.setLayoutParams(new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.MATCH_PARENT));

return textView;
}
Expand Down Expand Up @@ -492,24 +499,6 @@ private void scrollToTab(int tabIndex, float positionOffset) {

}

/**
* Allows complete control over the colors drawn in the tab layout. Set with
* {@link #setCustomTabColorizer(TabColorizer)}.
*/
public interface TabColorizer {

/**
* @return return the color of the indicator used when {@code position} is selected.
*/
int getIndicatorColor(int position);

/**
* @return return the color of the divider drawn to the right of {@code position}.
*/
int getDividerColor(int position);

}

/**
* Interface definition for a callback to be invoked when the scroll position of a view changes.
*/
Expand Down
Loading