@nativescript-community/ui-material-core 6.2.19 → 6.2.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +32 -0
- package/package.json +2 -2
- package/platforms/android/include.gradle +3 -3
- package/platforms/android/ui_material_core.aar +0 -0
- package/platforms/android/java/com/nativescript/material/core/BottomNavigationBar.java +0 -311
- package/platforms/android/java/com/nativescript/material/core/TabItemSpec.java +0 -15
- package/platforms/android/java/com/nativescript/material/core/TabLayout.java +0 -441
- package/platforms/android/java/com/nativescript/material/core/TabStrip.java +0 -264
- package/platforms/android/java/com/nativescript/material/core/TabViewPager.java +0 -62
- package/platforms/android/java/com/nativescript/material/core/TabsBar.java +0 -442
- package/tab-navigation-base/react/index.d.ts +0 -60
- package/tab-navigation-base/react/index.js +0 -114
- package/tab-navigation-base/react/index.js.map +0 -1
- package/tab-navigation-base/tab-content-item/index.android.d.ts +0 -14
- package/tab-navigation-base/tab-content-item/index.android.js +0 -48
- package/tab-navigation-base/tab-content-item/index.android.js.map +0 -1
- package/tab-navigation-base/tab-content-item/index.d.ts +0 -11
- package/tab-navigation-base/tab-content-item/index.ios.d.ts +0 -7
- package/tab-navigation-base/tab-content-item/index.ios.js +0 -13
- package/tab-navigation-base/tab-content-item/index.ios.js.map +0 -1
- package/tab-navigation-base/tab-content-item/tab-content-item-common.d.ts +0 -7
- package/tab-navigation-base/tab-content-item/tab-content-item-common.js +0 -24
- package/tab-navigation-base/tab-content-item/tab-content-item-common.js.map +0 -1
- package/tab-navigation-base/tab-navigation/index-common.d.ts +0 -27
- package/tab-navigation-base/tab-navigation/index-common.js +0 -58
- package/tab-navigation-base/tab-navigation/index-common.js.map +0 -1
- package/tab-navigation-base/tab-navigation/index.android.d.ts +0 -80
- package/tab-navigation-base/tab-navigation/index.android.js +0 -865
- package/tab-navigation-base/tab-navigation/index.android.js.map +0 -1
- package/tab-navigation-base/tab-navigation/index.d.ts +0 -80
- package/tab-navigation-base/tab-navigation/index.ios.d.ts +0 -93
- package/tab-navigation-base/tab-navigation/index.ios.js +0 -819
- package/tab-navigation-base/tab-navigation/index.ios.js.map +0 -1
- package/tab-navigation-base/tab-navigation-base/index.d.ts +0 -68
- package/tab-navigation-base/tab-navigation-base/index.js +0 -247
- package/tab-navigation-base/tab-navigation-base/index.js.map +0 -1
- package/tab-navigation-base/tab-strip/index.d.ts +0 -24
- package/tab-navigation-base/tab-strip/index.js +0 -153
- package/tab-navigation-base/tab-strip/index.js.map +0 -1
- package/tab-navigation-base/tab-strip-item/index.d.ts +0 -34
- package/tab-navigation-base/tab-strip-item/index.js +0 -215
- package/tab-navigation-base/tab-strip-item/index.js.map +0 -1
@@ -1,441 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
* Copyright 2014 Google Inc. All rights reserved.
|
3
|
-
*
|
4
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
-
* you may not use this file except in compliance with the License.
|
6
|
-
* You may obtain a copy of the License at
|
7
|
-
*
|
8
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
9
|
-
*
|
10
|
-
* Unless required by applicable law or agreed to in writing, software
|
11
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
-
* See the License for the specific language governing permissions and
|
14
|
-
* limitations under the License.
|
15
|
-
*/
|
16
|
-
|
17
|
-
package com.nativescript.material.core;
|
18
|
-
|
19
|
-
import android.content.Context;
|
20
|
-
import android.graphics.Typeface;
|
21
|
-
import androidx.viewpager.widget.PagerAdapter;
|
22
|
-
import androidx.viewpager.widget.ViewPager;
|
23
|
-
import android.text.TextUtils;
|
24
|
-
import android.util.AttributeSet;
|
25
|
-
import android.util.SparseArray;
|
26
|
-
import android.util.TypedValue;
|
27
|
-
import android.view.Gravity;
|
28
|
-
import android.view.View;
|
29
|
-
import android.view.ViewGroup;
|
30
|
-
import android.widget.HorizontalScrollView;
|
31
|
-
import android.widget.ImageView;
|
32
|
-
import android.widget.ImageView.ScaleType;
|
33
|
-
import android.widget.LinearLayout;
|
34
|
-
import android.widget.TextView;
|
35
|
-
|
36
|
-
/**
|
37
|
-
* To be used with ViewPager to provide a tab indicator component which give
|
38
|
-
* constant feedback as to the user's scroll progress.
|
39
|
-
* <p>
|
40
|
-
* To use the component, simply add it to your view hierarchy. Then in your
|
41
|
-
* {@link android.app.Activity} or {@link android.support.v4.app.Fragment} call
|
42
|
-
* {@link #setViewPager(ViewPager)} providing it the ViewPager this layout is
|
43
|
-
* being used for.
|
44
|
-
* <p>
|
45
|
-
* The colors can be customized in two ways. The first and simplest is to
|
46
|
-
* provide an array of colors via {@link #setSelectedIndicatorColors(int...)}.
|
47
|
-
* The alternative is via the {@link TabColorizer} interface which provides you
|
48
|
-
* complete control over which color is used for any individual position.
|
49
|
-
* <p>
|
50
|
-
*/
|
51
|
-
public class TabLayout extends HorizontalScrollView {
|
52
|
-
/**
|
53
|
-
* Allows complete control over the colors drawn in the tab layout. Set with
|
54
|
-
* {@link #setCustomTabColorizer(TabColorizer)}.
|
55
|
-
*/
|
56
|
-
public interface TabColorizer {
|
57
|
-
|
58
|
-
/**
|
59
|
-
* @return return the color of the indicator used when {@code position}
|
60
|
-
* is selected.
|
61
|
-
*/
|
62
|
-
int getIndicatorColor(int position);
|
63
|
-
|
64
|
-
}
|
65
|
-
|
66
|
-
private static final int TITLE_OFFSET_DIPS = 24;
|
67
|
-
private static final int TAB_VIEW_PADDING_DIPS = 16;
|
68
|
-
private static final int TAB_VIEW_TEXT_SIZE_SP = 12;
|
69
|
-
private static final int TEXT_MAX_WIDTH = 180;
|
70
|
-
private static final int SMALL_MIN_HEIGHT = 48;
|
71
|
-
private static final int LARGE_MIN_HEIGHT = 72;
|
72
|
-
|
73
|
-
private int mTitleOffset;
|
74
|
-
|
75
|
-
private boolean mDistributeEvenly = true;
|
76
|
-
|
77
|
-
private TabItemSpec[] mTabItems;
|
78
|
-
private ViewPager mViewPager;
|
79
|
-
private SparseArray<String> mContentDescriptions = new SparseArray<String>();
|
80
|
-
private ViewPager.OnPageChangeListener mViewPagerPageChangeListener;
|
81
|
-
|
82
|
-
private final TabStrip mTabStrip;
|
83
|
-
|
84
|
-
public TabLayout(Context context) {
|
85
|
-
this(context, null);
|
86
|
-
}
|
87
|
-
|
88
|
-
public TabLayout(Context context, AttributeSet attrs) {
|
89
|
-
this(context, attrs, 0);
|
90
|
-
}
|
91
|
-
|
92
|
-
public TabLayout(Context context, AttributeSet attrs, int defStyle) {
|
93
|
-
super(context, attrs, defStyle);
|
94
|
-
// Disable the Scroll Bar
|
95
|
-
setHorizontalScrollBarEnabled(false);
|
96
|
-
// Make sure that the Tab Strips fills this View
|
97
|
-
setFillViewport(true);
|
98
|
-
|
99
|
-
mTitleOffset = (int) (TITLE_OFFSET_DIPS * getResources().getDisplayMetrics().density);
|
100
|
-
|
101
|
-
mTabStrip = new TabStrip(context);
|
102
|
-
addView(mTabStrip, LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
|
103
|
-
}
|
104
|
-
|
105
|
-
/**
|
106
|
-
* Set the custom {@link TabColorizer} to be used.
|
107
|
-
*
|
108
|
-
* If you only require simple customisation then you can use
|
109
|
-
* {@link #setSelectedIndicatorColors(int...)} to achieve similar effects.
|
110
|
-
*/
|
111
|
-
public void setCustomTabColorizer(TabColorizer tabColorizer) {
|
112
|
-
mTabStrip.setCustomTabColorizer(tabColorizer);
|
113
|
-
}
|
114
|
-
|
115
|
-
public void setDistributeEvenly(boolean distributeEvenly) {
|
116
|
-
mDistributeEvenly = distributeEvenly;
|
117
|
-
}
|
118
|
-
|
119
|
-
/**
|
120
|
-
* Sets the colors to be used for indicating the selected tab. These colors
|
121
|
-
* are treated as a circular array. Providing one color will mean that all
|
122
|
-
* tabs are indicated with the same color.
|
123
|
-
*/
|
124
|
-
public void setSelectedIndicatorColors(int... colors) {
|
125
|
-
mTabStrip.setSelectedIndicatorColors(colors);
|
126
|
-
this.mSelectedIndicatorColors = colors;
|
127
|
-
}
|
128
|
-
|
129
|
-
private int[] mSelectedIndicatorColors;
|
130
|
-
public int[] getSelectedIndicatorColors() {
|
131
|
-
return this.mSelectedIndicatorColors;
|
132
|
-
}
|
133
|
-
|
134
|
-
public void setTabTextColor(int color){
|
135
|
-
mTabStrip.setTabTextColor(color);
|
136
|
-
}
|
137
|
-
|
138
|
-
public int getTabTextColor(){
|
139
|
-
return mTabStrip.getTabTextColor();
|
140
|
-
}
|
141
|
-
|
142
|
-
public void setSelectedTabTextColor(int color){
|
143
|
-
mTabStrip.setSelectedTabTextColor(color);
|
144
|
-
}
|
145
|
-
|
146
|
-
public int getSelectedTabTextColor(){
|
147
|
-
return mTabStrip.getSelectedTabTextColor();
|
148
|
-
}
|
149
|
-
|
150
|
-
public void setTabTextFontSize(float fontSize){
|
151
|
-
mTabStrip.setTabTextFontSize(fontSize);
|
152
|
-
}
|
153
|
-
|
154
|
-
public float getTabTextFontSize(){
|
155
|
-
return mTabStrip.getTabTextFontSize();
|
156
|
-
}
|
157
|
-
|
158
|
-
/**
|
159
|
-
* Set the {@link ViewPager.OnPageChangeListener}. When using
|
160
|
-
* {@link TabLayout} you are required to set any
|
161
|
-
* {@link ViewPager.OnPageChangeListener} through this method. This is so
|
162
|
-
* that the layout can update it's scroll position correctly.
|
163
|
-
*
|
164
|
-
* @see ViewPager#setOnPageChangeListener(ViewPager.OnPageChangeListener)
|
165
|
-
*/
|
166
|
-
public void setOnPageChangeListener(ViewPager.OnPageChangeListener listener) {
|
167
|
-
mViewPagerPageChangeListener = listener;
|
168
|
-
}
|
169
|
-
|
170
|
-
/**
|
171
|
-
* Sets the associated view pager. Note that the assumption here is that the
|
172
|
-
* pager content (number of tabs and tab titles) does not change after this
|
173
|
-
* call has been made.
|
174
|
-
*/
|
175
|
-
public void setViewPager(ViewPager viewPager) {
|
176
|
-
this.setItems(null, viewPager);
|
177
|
-
}
|
178
|
-
|
179
|
-
public void setItems(TabItemSpec[] items, ViewPager viewPager) {
|
180
|
-
mTabStrip.removeAllViews();
|
181
|
-
|
182
|
-
mViewPager = viewPager;
|
183
|
-
mTabItems = items;
|
184
|
-
if (viewPager != null) {
|
185
|
-
viewPager.addOnPageChangeListener(new InternalViewPagerListener());
|
186
|
-
populateTabStrip();
|
187
|
-
}
|
188
|
-
}
|
189
|
-
|
190
|
-
/**
|
191
|
-
* Updates the UI of an item at specified index
|
192
|
-
*/
|
193
|
-
public void updateItemAt(int position, TabItemSpec tabItem) {
|
194
|
-
LinearLayout ll = (LinearLayout)mTabStrip.getChildAt(position);
|
195
|
-
ImageView imgView = (ImageView)ll.getChildAt(0);
|
196
|
-
TextView textView = (TextView)ll.getChildAt(1);
|
197
|
-
this.setupItem(ll, textView, imgView, tabItem);
|
198
|
-
}
|
199
|
-
|
200
|
-
/**
|
201
|
-
* Gets the TextView for tab item at index
|
202
|
-
*/
|
203
|
-
public TextView getTextViewForItemAt(int index){
|
204
|
-
LinearLayout ll = this.getViewForItemAt(index);
|
205
|
-
return (ll != null) ? (TextView)ll.getChildAt(1) : null;
|
206
|
-
}
|
207
|
-
|
208
|
-
/**
|
209
|
-
* Gets the LinearLayout container for tab item at index
|
210
|
-
*/
|
211
|
-
public LinearLayout getViewForItemAt(int index){
|
212
|
-
LinearLayout result = null;
|
213
|
-
|
214
|
-
if(this.mTabStrip.getChildCount() > index){
|
215
|
-
result = (LinearLayout)this.mTabStrip.getChildAt(index);
|
216
|
-
}
|
217
|
-
|
218
|
-
return result;
|
219
|
-
}
|
220
|
-
|
221
|
-
/**
|
222
|
-
* Gets the number of realized tabs.
|
223
|
-
*/
|
224
|
-
public int getItemCount(){
|
225
|
-
return this.mTabStrip.getChildCount();
|
226
|
-
}
|
227
|
-
|
228
|
-
/**
|
229
|
-
* Create a default view to be used for tabs.
|
230
|
-
*/
|
231
|
-
protected View createDefaultTabView(Context context, TabItemSpec tabItem) {
|
232
|
-
float density = getResources().getDisplayMetrics().density;
|
233
|
-
int padding = (int) (TAB_VIEW_PADDING_DIPS * density);
|
234
|
-
|
235
|
-
LinearLayout ll = new LinearLayout(context);
|
236
|
-
ll.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT));
|
237
|
-
ll.setGravity(Gravity.CENTER);
|
238
|
-
ll.setOrientation(LinearLayout.VERTICAL);
|
239
|
-
TypedValue outValue = new TypedValue();
|
240
|
-
getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true);
|
241
|
-
ll.setBackgroundResource(outValue.resourceId);
|
242
|
-
|
243
|
-
ImageView imgView = new ImageView(context);
|
244
|
-
imgView.setScaleType(ScaleType.FIT_CENTER);
|
245
|
-
LinearLayout.LayoutParams imgLP = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
246
|
-
imgLP.gravity = Gravity.CENTER;
|
247
|
-
imgView.setLayoutParams(imgLP);
|
248
|
-
|
249
|
-
TextView textView = new TextView(context);
|
250
|
-
textView.setGravity(Gravity.CENTER);
|
251
|
-
textView.setMaxWidth((int) (TEXT_MAX_WIDTH * density));
|
252
|
-
textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP);
|
253
|
-
textView.setTypeface(Typeface.DEFAULT_BOLD);
|
254
|
-
textView.setEllipsize(TextUtils.TruncateAt.END);
|
255
|
-
textView.setAllCaps(true);
|
256
|
-
textView.setMaxLines(2);
|
257
|
-
textView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
|
258
|
-
textView.setPadding(padding, 0, padding, 0);
|
259
|
-
|
260
|
-
this.setupItem(ll, textView, imgView, tabItem);
|
261
|
-
|
262
|
-
ll.addView(imgView);
|
263
|
-
ll.addView(textView);
|
264
|
-
return ll;
|
265
|
-
}
|
266
|
-
|
267
|
-
private void setupItem(LinearLayout ll, TextView textView,ImageView imgView, TabItemSpec tabItem){
|
268
|
-
float density = getResources().getDisplayMetrics().density;
|
269
|
-
|
270
|
-
if (tabItem.iconId != 0) {
|
271
|
-
imgView.setImageResource(tabItem.iconId);
|
272
|
-
imgView.setVisibility(VISIBLE);
|
273
|
-
} else if (tabItem.iconDrawable != null) {
|
274
|
-
imgView.setImageDrawable(tabItem.iconDrawable);
|
275
|
-
imgView.setVisibility(VISIBLE);
|
276
|
-
} else {
|
277
|
-
imgView.setVisibility(GONE);
|
278
|
-
}
|
279
|
-
|
280
|
-
if (tabItem.title != null && !tabItem.title.isEmpty()) {
|
281
|
-
textView.setText(tabItem.title);
|
282
|
-
textView.setVisibility(VISIBLE);
|
283
|
-
} else {
|
284
|
-
textView.setVisibility(GONE);
|
285
|
-
}
|
286
|
-
|
287
|
-
if (tabItem.backgroundColor != 0) {
|
288
|
-
ll.setBackgroundColor(tabItem.backgroundColor);
|
289
|
-
}
|
290
|
-
|
291
|
-
if (imgView.getVisibility() == VISIBLE && textView.getVisibility() == VISIBLE) {
|
292
|
-
ll.setMinimumHeight((int) (LARGE_MIN_HEIGHT * density));
|
293
|
-
} else {
|
294
|
-
ll.setMinimumHeight((int) (SMALL_MIN_HEIGHT * density));
|
295
|
-
}
|
296
|
-
|
297
|
-
if (mDistributeEvenly) {
|
298
|
-
LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) ll.getLayoutParams();
|
299
|
-
lp.width = 0;
|
300
|
-
lp.weight = 1;
|
301
|
-
}
|
302
|
-
}
|
303
|
-
|
304
|
-
public boolean onTap(int position) {
|
305
|
-
// to be overridden in JS
|
306
|
-
return true;
|
307
|
-
}
|
308
|
-
|
309
|
-
public void onSelectedPositionChange(int position, int prevPosition) {
|
310
|
-
// to be overridden in JS
|
311
|
-
}
|
312
|
-
|
313
|
-
private void populateTabStrip() {
|
314
|
-
final PagerAdapter adapter = mViewPager.getAdapter();
|
315
|
-
final OnClickListener tabClickListener = new TabClickListener();
|
316
|
-
|
317
|
-
for (int i = 0; i < adapter.getCount(); i++) {
|
318
|
-
View tabView = null;
|
319
|
-
|
320
|
-
TabItemSpec tabItem;
|
321
|
-
if (this.mTabItems != null && this.mTabItems.length > i) {
|
322
|
-
tabItem = this.mTabItems[i];
|
323
|
-
} else {
|
324
|
-
tabItem = new TabItemSpec();
|
325
|
-
tabItem.title = adapter.getPageTitle(i).toString();
|
326
|
-
}
|
327
|
-
|
328
|
-
tabView = createDefaultTabView(getContext(), tabItem);
|
329
|
-
|
330
|
-
tabView.setOnClickListener(tabClickListener);
|
331
|
-
String desc = mContentDescriptions.get(i, null);
|
332
|
-
if (desc != null) {
|
333
|
-
tabView.setContentDescription(desc);
|
334
|
-
}
|
335
|
-
|
336
|
-
mTabStrip.addView(tabView);
|
337
|
-
if (i == mViewPager.getCurrentItem()) {
|
338
|
-
tabView.setSelected(true);
|
339
|
-
}
|
340
|
-
}
|
341
|
-
}
|
342
|
-
|
343
|
-
public void setContentDescription(int i, String desc) {
|
344
|
-
mContentDescriptions.put(i, desc);
|
345
|
-
}
|
346
|
-
|
347
|
-
@Override
|
348
|
-
protected void onAttachedToWindow() {
|
349
|
-
super.onAttachedToWindow();
|
350
|
-
|
351
|
-
if (mViewPager != null) {
|
352
|
-
scrollToTab(mViewPager.getCurrentItem(), 0);
|
353
|
-
}
|
354
|
-
}
|
355
|
-
|
356
|
-
private void scrollToTab(int tabIndex, int positionOffset) {
|
357
|
-
final int tabStripChildCount = mTabStrip.getChildCount();
|
358
|
-
if (tabStripChildCount == 0 || tabIndex < 0 || tabIndex >= tabStripChildCount) {
|
359
|
-
return;
|
360
|
-
}
|
361
|
-
|
362
|
-
View selectedChild = mTabStrip.getChildAt(tabIndex);
|
363
|
-
if (selectedChild != null) {
|
364
|
-
int targetScrollX = selectedChild.getLeft() + positionOffset;
|
365
|
-
|
366
|
-
if (tabIndex > 0 || positionOffset > 0) {
|
367
|
-
// If we're not at the first child and are mid-scroll, make sure
|
368
|
-
// we obey the offset
|
369
|
-
targetScrollX -= mTitleOffset;
|
370
|
-
}
|
371
|
-
|
372
|
-
scrollTo(targetScrollX, 0);
|
373
|
-
}
|
374
|
-
}
|
375
|
-
|
376
|
-
private class InternalViewPagerListener implements ViewPager.OnPageChangeListener {
|
377
|
-
private int mScrollState;
|
378
|
-
|
379
|
-
@Override
|
380
|
-
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
|
381
|
-
int tabStripChildCount = mTabStrip.getChildCount();
|
382
|
-
if ((tabStripChildCount == 0) || (position < 0) || (position >= tabStripChildCount)) {
|
383
|
-
return;
|
384
|
-
}
|
385
|
-
|
386
|
-
int prevPosition = mTabStrip.getSelectedPosition();
|
387
|
-
|
388
|
-
if (prevPosition != position) {
|
389
|
-
onSelectedPositionChange(position, prevPosition);
|
390
|
-
}
|
391
|
-
|
392
|
-
mTabStrip.onViewPagerPageChanged(position, positionOffset);
|
393
|
-
|
394
|
-
View selectedTitle = mTabStrip.getChildAt(position);
|
395
|
-
int extraOffset = (selectedTitle != null) ? (int) (positionOffset * selectedTitle.getWidth()) : 0;
|
396
|
-
scrollToTab(position, extraOffset);
|
397
|
-
|
398
|
-
if (mViewPagerPageChangeListener != null) {
|
399
|
-
mViewPagerPageChangeListener.onPageScrolled(position, positionOffset, positionOffsetPixels);
|
400
|
-
}
|
401
|
-
}
|
402
|
-
|
403
|
-
@Override
|
404
|
-
public void onPageScrollStateChanged(int state) {
|
405
|
-
mScrollState = state;
|
406
|
-
|
407
|
-
if (mViewPagerPageChangeListener != null) {
|
408
|
-
mViewPagerPageChangeListener.onPageScrollStateChanged(state);
|
409
|
-
}
|
410
|
-
}
|
411
|
-
|
412
|
-
@Override
|
413
|
-
public void onPageSelected(int position) {
|
414
|
-
if (mScrollState == ViewPager.SCROLL_STATE_IDLE) {
|
415
|
-
mTabStrip.onViewPagerPageChanged(position, 0f);
|
416
|
-
scrollToTab(position, 0);
|
417
|
-
}
|
418
|
-
for (int i = 0; i < mTabStrip.getChildCount(); i++) {
|
419
|
-
mTabStrip.getChildAt(i).setSelected(position == i);
|
420
|
-
}
|
421
|
-
if (mViewPagerPageChangeListener != null) {
|
422
|
-
mViewPagerPageChangeListener.onPageSelected(position);
|
423
|
-
}
|
424
|
-
}
|
425
|
-
|
426
|
-
}
|
427
|
-
|
428
|
-
private class TabClickListener implements OnClickListener {
|
429
|
-
@Override
|
430
|
-
public void onClick(View v) {
|
431
|
-
for (int i = 0; i < mTabStrip.getChildCount(); i++) {
|
432
|
-
if (v == mTabStrip.getChildAt(i)) {
|
433
|
-
if (onTap(i)) {
|
434
|
-
mViewPager.setCurrentItem(i);
|
435
|
-
}
|
436
|
-
return;
|
437
|
-
}
|
438
|
-
}
|
439
|
-
}
|
440
|
-
}
|
441
|
-
}
|
@@ -1,264 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
* Copyright 2014 Google Inc. All rights reserved.
|
3
|
-
*
|
4
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
-
* you may not use this file except in compliance with the License.
|
6
|
-
* You may obtain a copy of the License at
|
7
|
-
*
|
8
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
9
|
-
*
|
10
|
-
* Unless required by applicable law or agreed to in writing, software
|
11
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
-
* See the License for the specific language governing permissions and
|
14
|
-
* limitations under the License.
|
15
|
-
*/
|
16
|
-
|
17
|
-
package com.nativescript.material.core;
|
18
|
-
|
19
|
-
|
20
|
-
import android.content.Context;
|
21
|
-
import android.graphics.Canvas;
|
22
|
-
import android.graphics.Color;
|
23
|
-
import android.graphics.Paint;
|
24
|
-
import android.util.AttributeSet;
|
25
|
-
import android.util.TypedValue;
|
26
|
-
import android.view.View;
|
27
|
-
import android.widget.LinearLayout;
|
28
|
-
import android.widget.TextView;
|
29
|
-
|
30
|
-
class TabStrip extends LinearLayout {
|
31
|
-
|
32
|
-
private static final int DEFAULT_BOTTOM_BORDER_THICKNESS_DIPS = 0;
|
33
|
-
private static final byte DEFAULT_BOTTOM_BORDER_COLOR_ALPHA = 0x26;
|
34
|
-
private static final int SELECTED_INDICATOR_THICKNESS_DIPS = 3;
|
35
|
-
private static final int DEFAULT_SELECTED_INDICATOR_COLOR = 0xFF33B5E5;
|
36
|
-
|
37
|
-
private final int mBottomBorderThickness;
|
38
|
-
private final Paint mBottomBorderPaint;
|
39
|
-
|
40
|
-
private final int mSelectedIndicatorThickness;
|
41
|
-
private final Paint mSelectedIndicatorPaint;
|
42
|
-
|
43
|
-
private final int mDefaultBottomBorderColor;
|
44
|
-
|
45
|
-
private int mSelectedPosition;
|
46
|
-
private float mSelectionOffset;
|
47
|
-
|
48
|
-
private TabLayout.TabColorizer mCustomTabColorizer;
|
49
|
-
private final SimpleTabColorizer mDefaultTabColorizer;
|
50
|
-
|
51
|
-
private int mTabTextColor;
|
52
|
-
private int mSelectedTabTextColor;
|
53
|
-
private float mTabTextFontSize;
|
54
|
-
|
55
|
-
private boolean mShouldUpdateTabsTextColor;
|
56
|
-
|
57
|
-
TabStrip(Context context) {
|
58
|
-
this(context, null);
|
59
|
-
}
|
60
|
-
|
61
|
-
TabStrip(Context context, AttributeSet attrs) {
|
62
|
-
super(context, attrs);
|
63
|
-
|
64
|
-
setWillNotDraw(false);
|
65
|
-
|
66
|
-
final float density = getResources().getDisplayMetrics().density;
|
67
|
-
|
68
|
-
TypedValue outValue = new TypedValue();
|
69
|
-
context.getTheme().resolveAttribute(android.R.attr.colorForeground, outValue, true);
|
70
|
-
final int themeForegroundColor = outValue.data;
|
71
|
-
|
72
|
-
mDefaultBottomBorderColor = setColorAlpha(themeForegroundColor,
|
73
|
-
DEFAULT_BOTTOM_BORDER_COLOR_ALPHA);
|
74
|
-
|
75
|
-
mDefaultTabColorizer = new SimpleTabColorizer();
|
76
|
-
mDefaultTabColorizer.setIndicatorColors(DEFAULT_SELECTED_INDICATOR_COLOR);
|
77
|
-
|
78
|
-
mBottomBorderThickness = (int) (DEFAULT_BOTTOM_BORDER_THICKNESS_DIPS * density);
|
79
|
-
mBottomBorderPaint = new Paint();
|
80
|
-
mBottomBorderPaint.setColor(mDefaultBottomBorderColor);
|
81
|
-
|
82
|
-
mSelectedIndicatorThickness = (int) (SELECTED_INDICATOR_THICKNESS_DIPS * density);
|
83
|
-
mSelectedIndicatorPaint = new Paint();
|
84
|
-
|
85
|
-
TextView defaultTextView = new TextView(context);
|
86
|
-
mTabTextColor = defaultTextView.getTextColors().getDefaultColor();
|
87
|
-
mTabTextFontSize = defaultTextView.getTextSize();
|
88
|
-
|
89
|
-
// Default selected color is the same as mTabTextColor
|
90
|
-
mSelectedTabTextColor = mTabTextColor;
|
91
|
-
|
92
|
-
mShouldUpdateTabsTextColor = true;
|
93
|
-
|
94
|
-
setMeasureWithLargestChildEnabled(true);
|
95
|
-
}
|
96
|
-
|
97
|
-
void setCustomTabColorizer(TabLayout.TabColorizer customTabColorizer) {
|
98
|
-
mCustomTabColorizer = customTabColorizer;
|
99
|
-
invalidate();
|
100
|
-
}
|
101
|
-
|
102
|
-
void setSelectedIndicatorColors(int... colors) {
|
103
|
-
// Make sure that the custom colorizer is removed
|
104
|
-
mCustomTabColorizer = null;
|
105
|
-
mDefaultTabColorizer.setIndicatorColors(colors);
|
106
|
-
invalidate();
|
107
|
-
}
|
108
|
-
|
109
|
-
void setTabTextColor(int color){
|
110
|
-
mTabTextColor = color;
|
111
|
-
updateTabsTextColor();
|
112
|
-
}
|
113
|
-
|
114
|
-
int getTabTextColor(){
|
115
|
-
return mTabTextColor;
|
116
|
-
}
|
117
|
-
|
118
|
-
void setSelectedTabTextColor(int color){
|
119
|
-
mSelectedTabTextColor = color;
|
120
|
-
updateTabsTextColor();
|
121
|
-
}
|
122
|
-
|
123
|
-
int getSelectedTabTextColor(){
|
124
|
-
return mSelectedTabTextColor;
|
125
|
-
}
|
126
|
-
|
127
|
-
void setShouldUpdateTabsTextColor(boolean value) {
|
128
|
-
mShouldUpdateTabsTextColor = value;
|
129
|
-
}
|
130
|
-
|
131
|
-
private void updateTabsTextColor(){
|
132
|
-
if (mShouldUpdateTabsTextColor) {
|
133
|
-
final int childCount = getChildCount();
|
134
|
-
for (int i = 0; i < childCount; i++){
|
135
|
-
LinearLayout linearLayout = (LinearLayout)getChildAt(i);
|
136
|
-
TextView textView = (TextView)linearLayout.getChildAt(1);
|
137
|
-
if (i == mSelectedPosition){
|
138
|
-
textView.setTextColor(mSelectedTabTextColor);
|
139
|
-
}
|
140
|
-
else {
|
141
|
-
textView.setTextColor(mTabTextColor);
|
142
|
-
}
|
143
|
-
}
|
144
|
-
}
|
145
|
-
}
|
146
|
-
|
147
|
-
void setTabTextFontSize(float fontSize){
|
148
|
-
mTabTextFontSize = fontSize;
|
149
|
-
updateTabsTextFontSize();
|
150
|
-
}
|
151
|
-
|
152
|
-
float getTabTextFontSize(){
|
153
|
-
return mTabTextFontSize;
|
154
|
-
}
|
155
|
-
|
156
|
-
private void updateTabsTextFontSize(){
|
157
|
-
final int childCount = getChildCount();
|
158
|
-
for (int i = 0; i < childCount; i++){
|
159
|
-
LinearLayout linearLayout = (LinearLayout)getChildAt(i);
|
160
|
-
TextView textView = (TextView)linearLayout.getChildAt(1);
|
161
|
-
textView.setTextSize(mTabTextFontSize);
|
162
|
-
}
|
163
|
-
}
|
164
|
-
|
165
|
-
// Used by TabLayout (the 'old' tab-view control)
|
166
|
-
void onViewPagerPageChanged(int position, float positionOffset) {
|
167
|
-
mSelectedPosition = position;
|
168
|
-
mSelectionOffset = positionOffset;
|
169
|
-
invalidate();
|
170
|
-
updateTabsTextColor();
|
171
|
-
}
|
172
|
-
|
173
|
-
// Used by TabsBar
|
174
|
-
void onTabsViewPagerPageChanged(int position, float positionOffset) {
|
175
|
-
mSelectedPosition = position;
|
176
|
-
mSelectionOffset = positionOffset;
|
177
|
-
invalidate();
|
178
|
-
}
|
179
|
-
|
180
|
-
int getSelectedPosition(){
|
181
|
-
return mSelectedPosition;
|
182
|
-
}
|
183
|
-
|
184
|
-
void setSelectedPosition(int position) {
|
185
|
-
mSelectedPosition = position;
|
186
|
-
invalidate();
|
187
|
-
updateTabsTextColor();
|
188
|
-
}
|
189
|
-
|
190
|
-
@Override
|
191
|
-
protected void dispatchDraw(Canvas canvas) {
|
192
|
-
super.dispatchDraw(canvas);
|
193
|
-
|
194
|
-
final int height = getHeight();
|
195
|
-
final int childCount = getChildCount();
|
196
|
-
final TabLayout.TabColorizer tabColorizer = mCustomTabColorizer != null
|
197
|
-
? mCustomTabColorizer
|
198
|
-
: mDefaultTabColorizer;
|
199
|
-
|
200
|
-
// Thick colored underline below the current selection
|
201
|
-
if (childCount > 0 && mSelectedPosition < childCount) {
|
202
|
-
View selectedTitle = getChildAt(mSelectedPosition);
|
203
|
-
int left = selectedTitle.getLeft();
|
204
|
-
int right = selectedTitle.getRight();
|
205
|
-
int color = tabColorizer.getIndicatorColor(mSelectedPosition);
|
206
|
-
|
207
|
-
if (mSelectionOffset > 0f && mSelectedPosition < (getChildCount() - 1)) {
|
208
|
-
int nextColor = tabColorizer.getIndicatorColor(mSelectedPosition + 1);
|
209
|
-
if (color != nextColor) {
|
210
|
-
color = blendColors(nextColor, color, mSelectionOffset);
|
211
|
-
}
|
212
|
-
|
213
|
-
// Draw the selection partway between the tabs
|
214
|
-
View nextTitle = getChildAt(mSelectedPosition + 1);
|
215
|
-
left = (int) (mSelectionOffset * nextTitle.getLeft() +
|
216
|
-
(1.0f - mSelectionOffset) * left);
|
217
|
-
right = (int) (mSelectionOffset * nextTitle.getRight() +
|
218
|
-
(1.0f - mSelectionOffset) * right);
|
219
|
-
}
|
220
|
-
|
221
|
-
mSelectedIndicatorPaint.setColor(color);
|
222
|
-
|
223
|
-
canvas.drawRect(left, height - mSelectedIndicatorThickness, right,
|
224
|
-
height, mSelectedIndicatorPaint);
|
225
|
-
}
|
226
|
-
|
227
|
-
// Thin underline along the entire bottom edge
|
228
|
-
canvas.drawRect(0, height - mBottomBorderThickness, getWidth(), height, mBottomBorderPaint);
|
229
|
-
}
|
230
|
-
|
231
|
-
/**
|
232
|
-
* Set the alpha value of the {@code color} to be the given {@code alpha} value.
|
233
|
-
*/
|
234
|
-
private static int setColorAlpha(int color, byte alpha) {
|
235
|
-
return Color.argb(alpha, Color.red(color), Color.green(color), Color.blue(color));
|
236
|
-
}
|
237
|
-
|
238
|
-
/**
|
239
|
-
* Blend {@code color1} and {@code color2} using the given ratio.
|
240
|
-
*
|
241
|
-
* @param ratio of which to blend. 1.0 will return {@code color1}, 0.5 will give an even blend,
|
242
|
-
* 0.0 will return {@code color2}.
|
243
|
-
*/
|
244
|
-
private static int blendColors(int color1, int color2, float ratio) {
|
245
|
-
final float inverseRation = 1f - ratio;
|
246
|
-
float r = (Color.red(color1) * ratio) + (Color.red(color2) * inverseRation);
|
247
|
-
float g = (Color.green(color1) * ratio) + (Color.green(color2) * inverseRation);
|
248
|
-
float b = (Color.blue(color1) * ratio) + (Color.blue(color2) * inverseRation);
|
249
|
-
return Color.rgb((int) r, (int) g, (int) b);
|
250
|
-
}
|
251
|
-
|
252
|
-
private static class SimpleTabColorizer implements TabLayout.TabColorizer {
|
253
|
-
private int[] mIndicatorColors;
|
254
|
-
|
255
|
-
@Override
|
256
|
-
public final int getIndicatorColor(int position) {
|
257
|
-
return mIndicatorColors[position % mIndicatorColors.length];
|
258
|
-
}
|
259
|
-
|
260
|
-
void setIndicatorColors(int... colors) {
|
261
|
-
mIndicatorColors = colors;
|
262
|
-
}
|
263
|
-
}
|
264
|
-
}
|