1 /* 2 * Copyright (C) 2017 The Android Open Source Project 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 package com.android.launcher3.workprofile; 17 18 import android.content.Context; 19 import android.util.AttributeSet; 20 import android.widget.Button; 21 import android.widget.LinearLayout; 22 23 import androidx.annotation.NonNull; 24 import androidx.annotation.Nullable; 25 26 import com.android.launcher3.pageindicators.PageIndicator; 27 28 /** 29 * Supports two indicator colors, dedicated for personal and work tabs. 30 */ 31 public class PersonalWorkSlidingTabStrip extends LinearLayout implements PageIndicator { 32 private OnActivePageChangedListener mOnActivePageChangedListener; 33 private int mLastActivePage = 0; 34 PersonalWorkSlidingTabStrip(@onNull Context context, @Nullable AttributeSet attrs)35 public PersonalWorkSlidingTabStrip(@NonNull Context context, @Nullable AttributeSet attrs) { 36 super(context, attrs); 37 } 38 39 /** 40 * Highlights tab with index pos 41 */ updateTabTextColor(int pos)42 public void updateTabTextColor(int pos) { 43 for (int i = 0; i < getChildCount(); i++) { 44 Button tab = (Button) getChildAt(i); 45 tab.setSelected(i == pos); 46 } 47 } 48 49 @Override setScroll(int currentScroll, int totalScroll)50 public void setScroll(int currentScroll, int totalScroll) { 51 } 52 53 @Override setActiveMarker(int activePage)54 public void setActiveMarker(int activePage) { 55 updateTabTextColor(activePage); 56 if (mOnActivePageChangedListener != null && mLastActivePage != activePage) { 57 mOnActivePageChangedListener.onActivePageChanged(activePage); 58 } 59 mLastActivePage = activePage; 60 } 61 setOnActivePageChangedListener(OnActivePageChangedListener listener)62 public void setOnActivePageChangedListener(OnActivePageChangedListener listener) { 63 mOnActivePageChangedListener = listener; 64 } 65 66 @Override setMarkersCount(int numMarkers)67 public void setMarkersCount(int numMarkers) { 68 } 69 70 @Override hasOverlappingRendering()71 public boolean hasOverlappingRendering() { 72 return false; 73 } 74 75 /** 76 * Interface definition for a callback to be invoked when an active page has been changed. 77 */ 78 public interface OnActivePageChangedListener { 79 /** Called when the active page has been changed. */ onActivePageChanged(int currentActivePage)80 void onActivePageChanged(int currentActivePage); 81 } 82 } 83