Skip to content
This repository was archived by the owner on Sep 3, 2024. It is now read-only.

Commit 5d7ebb7

Browse files
authored
app/TabLayout('s): fix setEnabled (#41)
* app/oneuiexample: move setBackgroundColor inside fragments Signed-off-by: BlackMesa123 <[email protected]> * app/TabLayout(s): fix setEnabled Signed-off-by: BlackMesa123 <[email protected]>
1 parent 4c653cd commit 5d7ebb7

File tree

6 files changed

+62
-27
lines changed

6 files changed

+62
-27
lines changed

app/src/main/java/de/dlyt/yanndroid/oneuiexample/MainActivity.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,13 +197,11 @@ private void setCurrentItem() {
197197
toolbarLayout.setSubtitle("Design");
198198
toolbarLayout.setNavigationButtonVisible(true);
199199
((androidx.drawerlayout.widget.DrawerLayout) drawerLayout.getView(DRAWER_LAYOUT)).setDrawerLockMode(androidx.drawerlayout.widget.DrawerLayout.LOCK_MODE_UNLOCKED);
200-
findViewById(R.id.fragment_container).setBackgroundColor(ContextCompat.getColor(mContext, R.color.background_color));
201200
} else {
202201
// MainActivitySecondFragment
203202
toolbarLayout.setSubtitle("Preferences");
204203
toolbarLayout.setNavigationButtonVisible(false);
205204
((androidx.drawerlayout.widget.DrawerLayout) drawerLayout.getView(DRAWER_LAYOUT)).setDrawerLockMode(androidx.drawerlayout.widget.DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
206-
findViewById(R.id.fragment_container).setBackgroundColor(ContextCompat.getColor(mContext, R.color.item_background_color));
207205
}
208206

209207
}

app/src/main/java/de/dlyt/yanndroid/oneuiexample/fragments/MainActivityFirstFragment.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
3737
public void onViewCreated(View view, Bundle savedInstanceState) {
3838
super.onViewCreated(view, savedInstanceState);
3939

40+
getView().setBackgroundColor(getResources().getColor(R.color.background_color));
41+
4042
// TabLayout and ViewPager
4143
TabLayout tabLayout = mRootView.findViewById(R.id.tabLayout);
4244
SeslViewPager viewPager = mRootView.findViewById(R.id.viewPager);

app/src/main/java/de/dlyt/yanndroid/oneuiexample/fragments/MainActivitySecondFragment.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,12 @@ public void onCancelClicked(View view) {
7070
autoDarkModePref.setChecked(darkMode == ThemeColor.DARK_MODE_AUTO);
7171
}
7272

73+
@Override
74+
public void onViewCreated(View view, Bundle savedInstanceState) {
75+
super.onViewCreated(view, savedInstanceState);
76+
getView().setBackgroundColor(getResources().getColor(R.color.item_background_color));
77+
}
78+
7379
@Override
7480
public void onStart() {
7581
super.onStart();

app/src/main/java/de/dlyt/yanndroid/oneuiexample/tabs/IconsTab.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -312,8 +312,8 @@ public void setSelecting(boolean enabled) {
312312
for (Boolean b : selected.values()) if (b) count++;
313313
drawerLayout.setSelectAllCount(count);
314314
});
315-
tabLayout.setVisibility(View.INVISIBLE); //if GONE the "scroll-select" will skip one item due to the different position of the RecyclerView.
316-
bnv.setVisibility(View.GONE);
315+
tabLayout.setEnabled(false);
316+
bnv.setEnabled(false);
317317
seslViewPager.setPagingEnabled(false);
318318
onBackPressedCallback.setEnabled(true);
319319
} else {
@@ -323,8 +323,8 @@ public void setSelecting(boolean enabled) {
323323

324324
drawerLayout.setSelectAllCount(0);
325325
drawerLayout.showSelectAllMode(false);
326-
tabLayout.setVisibility(View.VISIBLE);
327-
bnv.setVisibility(View.VISIBLE);
326+
tabLayout.setEnabled(true);
327+
bnv.setEnabled(true);
328328
seslViewPager.setPagingEnabled(true);
329329
onBackPressedCallback.setEnabled(false);
330330
}

yanndroid/oneui/src/main/java/de/dlyt/yanndroid/oneui/view/BottomNavigationView.java

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,19 @@ public void onSystemUiVisibilityChange(int visibility) {
5252
}
5353
}
5454

55+
@Override
56+
public void setEnabled(boolean enabled) {
57+
super.setEnabled(enabled);
58+
59+
for (int tabPosition = 0; tabPosition < getTabCount(); tabPosition++) {
60+
ViewGroup tabView = (ViewGroup) getTabView(tabPosition);
61+
if (tabView != null) {
62+
tabView.setEnabled(enabled);
63+
tabView.setAlpha(enabled ? 1.0f : 0.4f);
64+
}
65+
}
66+
}
67+
5568
public void addTabCustomButton(Drawable icon, CustomButtonClickListener listener) {
5669
Tab tab = newTab().setIcon(icon).setIsCustomButtonView(true);
5770
addTab(tab);
@@ -62,23 +75,6 @@ public void setResumeStatus(boolean isResumed) {
6275
mIsResumed = isResumed;
6376
}
6477

65-
public void setTabLayoutEnabled(boolean enabled) {
66-
float f;
67-
setEnabled(enabled);
68-
for (int tabPosition = 0; tabPosition < getTabCount(); tabPosition++) {
69-
ViewGroup tabView = (ViewGroup) getTabView(tabPosition);
70-
if (tabView != null) {
71-
tabView.setEnabled(enabled);
72-
if (enabled) {
73-
f = 1.0f;
74-
} else {
75-
f = 0.4f;
76-
}
77-
tabView.setAlpha(f);
78-
}
79-
}
80-
}
81-
8278
public void updateWidget(Activity activity) {
8379
mActivity = activity;
8480
invalidateTabLayout();

yanndroid/oneui/src/main/java/de/dlyt/yanndroid/oneui/view/TabLayout.java

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import android.content.res.Configuration;
55
import android.util.AttributeSet;
66
import android.util.Log;
7+
import android.view.View;
78
import android.view.ViewGroup;
89
import android.widget.TextView;
910

@@ -21,6 +22,25 @@ public TabLayout(Context context, AttributeSet attrs, int defStyleAttr) {
2122
mDepthStyle = 2;
2223
}
2324

25+
@Override
26+
public void onConfigurationChanged(Configuration newConfig) {
27+
super.onConfigurationChanged(newConfig);
28+
updateWidget();
29+
}
30+
31+
@Override
32+
public void setEnabled(boolean enabled) {
33+
super.setEnabled(enabled);
34+
35+
for (int tabPosition = 0; tabPosition < getTabCount(); tabPosition++) {
36+
ViewGroup tabView = (ViewGroup) getTabView(tabPosition);
37+
if (tabView != null) {
38+
tabView.setEnabled(enabled);
39+
tabView.setAlpha(enabled ? 1.0f : 0.4f);
40+
}
41+
}
42+
}
43+
2444
public void updateWidget() {
2545
Float[] tabCount = new Float[getTabCount()];
2646
float f = 0.0f;
@@ -41,10 +61,23 @@ public final void run() {
4161
});
4262
}
4363

44-
@Override
45-
public void onConfigurationChanged(Configuration newConfig) {
46-
super.onConfigurationChanged(newConfig);
47-
updateWidget();
64+
private View getTabView(int position) {
65+
ViewGroup viewGroup = getTabViewGroup();
66+
if (viewGroup == null || viewGroup.getChildCount() <= position) {
67+
return null;
68+
}
69+
return viewGroup.getChildAt(position);
70+
}
71+
72+
private ViewGroup getTabViewGroup() {
73+
if (getChildCount() <= 0) {
74+
return null;
75+
}
76+
View view = getChildAt(0);
77+
if (view == null || !(view instanceof ViewGroup)) {
78+
return null;
79+
}
80+
return (ViewGroup) view;
4881
}
4982

5083
private void setSelectedTabScrollPosition() {

0 commit comments

Comments
 (0)