From 90c7c664053efe0f09c971ba5ee7a63b3a57b3c6 Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Mon, 12 Aug 2019 09:26:27 +0800 Subject: Fixed nav bar icon color in dark theme. Transparent nav bar in SubredditSelectionActivity for Android version >= 8.1. --- app/src/main/AndroidManifest.xml | 3 +- .../infinityforreddit/MainActivity.java | 14 ++++- .../infinityforreddit/RulesActivity.java | 59 ++++++++++++++++++++-- .../infinityforreddit/SearchResultActivity.java | 14 ++++- .../SubredditSelectionActivity.java | 51 +++++++++++++++++++ .../SubscribedThingListingActivity.java | 17 ++++++- .../infinityforreddit/ViewPostDetailActivity.java | 17 ++++++- .../ViewSubredditDetailActivity.java | 14 ++++- .../infinityforreddit/ViewUserDetailActivity.java | 14 ++++- app/src/main/res/layout/activity_rules.xml | 34 +++++++++++-- .../res/layout/activity_subreddit_selection.xml | 20 ++++++-- 11 files changed, 231 insertions(+), 26 deletions(-) (limited to 'app') diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index ace418e0..e85143cb 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -64,7 +64,8 @@ + android:parentActivityName=".MainActivity" + android:theme="@style/AppTheme.NoActionBar" /> = Build.VERSION_CODES.O_MR1) { + Resources resources = getResources(); + + if(resources.getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT || resources.getBoolean(R.bool.isTablet)) { + Window window = getWindow(); + window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); + + boolean lightNavBar = false; + if((resources.getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) != Configuration.UI_MODE_NIGHT_YES) { + lightNavBar = true; + } + boolean finalLightNavBar = lightNavBar; + + View decorView = window.getDecorView(); + if(finalLightNavBar) { + decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR); + } + appBarLayout.addOnOffsetChangedListener(new AppBarStateChangeListener() { + @Override + void onStateChanged(AppBarLayout appBarLayout, State state) { + if(state == State.COLLAPSED) { + if(finalLightNavBar) { + decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR | View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR); + } + } else if(state == State.EXPANDED) { + if(finalLightNavBar) { + decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR); + } + } + } + }); + + int statusBarResourceId = getResources().getIdentifier("status_bar_height", "dimen", "android"); + if (statusBarResourceId > 0) { + ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) toolbar.getLayoutParams(); + params.topMargin = getResources().getDimensionPixelSize(statusBarResourceId); + toolbar.setLayoutParams(params); + } + } + } + + setSupportActionBar(toolbar); + getSupportActionBar().setDisplayHomeAsUpEnabled(true); mSubredditName = getIntent().getExtras().getString(EXTRA_SUBREDDIT_NAME); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/SearchResultActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/SearchResultActivity.java index d528488d..72b6215f 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/SearchResultActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/SearchResultActivity.java @@ -72,14 +72,24 @@ public class SearchResultActivity extends AppCompatActivity implements SearchPos Window window = getWindow(); window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); + boolean lightNavBar = false; + if((resources.getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) != Configuration.UI_MODE_NIGHT_YES) { + lightNavBar = true; + } + boolean finalLightNavBar = lightNavBar; + View decorView = window.getDecorView(); appBarLayout.addOnOffsetChangedListener(new AppBarStateChangeListener() { @Override void onStateChanged(AppBarLayout appBarLayout, State state) { if(state == State.COLLAPSED) { - decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR | View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR); + if(finalLightNavBar) { + decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR | View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR); + } } else if(state == State.EXPANDED) { - decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR); + if(finalLightNavBar) { + decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR); + } } } }); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/SubredditSelectionActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/SubredditSelectionActivity.java index 8069499c..e9f5e4db 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/SubredditSelectionActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/SubredditSelectionActivity.java @@ -2,9 +2,16 @@ package ml.docilealligator.infinityforreddit; import android.app.Activity; import android.content.Intent; +import android.content.res.Configuration; +import android.content.res.Resources; +import android.os.Build; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; +import android.view.View; +import android.view.ViewGroup; +import android.view.Window; +import android.view.WindowManager; import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -12,6 +19,8 @@ import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.widget.Toolbar; import androidx.fragment.app.Fragment; +import com.google.android.material.appbar.AppBarLayout; + import java.util.ArrayList; import javax.inject.Inject; @@ -39,6 +48,7 @@ public class SubredditSelectionActivity extends AppCompatActivity { private static final String ACCOUNT_PROFILE_IMAGE_URL = "APIU"; private static final String FRAGMENT_OUT_STATE = "FOS"; + @BindView(R.id.appbar_layout_subreddit_selection_activity) AppBarLayout appBarLayout; @BindView(R.id.toolbar_subreddit_selection_activity) Toolbar toolbar; private boolean mNullAccessToken = false; @@ -65,6 +75,47 @@ public class SubredditSelectionActivity extends AppCompatActivity { ((Infinity) getApplication()).getAppComponent().inject(this); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) { + Resources resources = getResources(); + + if(resources.getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT || resources.getBoolean(R.bool.isTablet)) { + Window window = getWindow(); + window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); + + boolean lightNavBar = false; + if((resources.getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) != Configuration.UI_MODE_NIGHT_YES) { + lightNavBar = true; + } + boolean finalLightNavBar = lightNavBar; + + View decorView = window.getDecorView(); + if(finalLightNavBar) { + decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR); + } + appBarLayout.addOnOffsetChangedListener(new AppBarStateChangeListener() { + @Override + void onStateChanged(AppBarLayout appBarLayout, State state) { + if(state == State.COLLAPSED) { + if(finalLightNavBar) { + decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR | View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR); + } + } else if(state == State.EXPANDED) { + if(finalLightNavBar) { + decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR); + } + } + } + }); + + int statusBarResourceId = getResources().getIdentifier("status_bar_height", "dimen", "android"); + if (statusBarResourceId > 0) { + ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) toolbar.getLayoutParams(); + params.topMargin = getResources().getDimensionPixelSize(statusBarResourceId); + toolbar.setLayoutParams(params); + } + } + } + setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/SubscribedThingListingActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/SubscribedThingListingActivity.java index 85ad1196..ab0c03ef 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/SubscribedThingListingActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/SubscribedThingListingActivity.java @@ -75,14 +75,27 @@ public class SubscribedThingListingActivity extends AppCompatActivity { Window window = getWindow(); window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); + boolean lightNavBar = false; + if((resources.getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) != Configuration.UI_MODE_NIGHT_YES) { + lightNavBar = true; + } + boolean finalLightNavBar = lightNavBar; + View decorView = window.getDecorView(); + if(finalLightNavBar) { + decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR); + } appBarLayout.addOnOffsetChangedListener(new AppBarStateChangeListener() { @Override void onStateChanged(AppBarLayout appBarLayout, State state) { if(state == State.COLLAPSED) { - decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR | View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR); + if(finalLightNavBar) { + decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR | View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR); + } } else if(state == State.EXPANDED) { - decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR); + if(finalLightNavBar) { + decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR); + } } } }); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java index e3bf8ee8..8ef11517 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java @@ -131,14 +131,27 @@ public class ViewPostDetailActivity extends AppCompatActivity { Window window = getWindow(); window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); + boolean lightNavBar = false; + if((resources.getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) != Configuration.UI_MODE_NIGHT_YES) { + lightNavBar = true; + } + boolean finalLightNavBar = lightNavBar; + View decorView = window.getDecorView(); + if(finalLightNavBar) { + decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR); + } appBarLayout.addOnOffsetChangedListener(new AppBarStateChangeListener() { @Override void onStateChanged(AppBarLayout appBarLayout, State state) { if (state == State.COLLAPSED) { - decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR | View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR); + if(finalLightNavBar) { + decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR | View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR); + } } else if (state == State.EXPANDED) { - decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR); + if(finalLightNavBar) { + decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR); + } } } }); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewSubredditDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewSubredditDetailActivity.java index f398fbe6..610c4a23 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewSubredditDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewSubredditDetailActivity.java @@ -113,14 +113,24 @@ public class ViewSubredditDetailActivity extends AppCompatActivity implements So Window window = getWindow(); window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); + boolean lightNavBar = false; + if((resources.getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) != Configuration.UI_MODE_NIGHT_YES) { + lightNavBar = true; + } + boolean finalLightNavBar = lightNavBar; + View decorView = window.getDecorView(); appBarLayout.addOnOffsetChangedListener(new AppBarStateChangeListener() { @Override void onStateChanged(AppBarLayout appBarLayout, State state) { if (state == State.COLLAPSED) { - decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR | View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR); + if(finalLightNavBar) { + decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR | View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR); + } } else if (state == State.EXPANDED) { - decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR); + if(finalLightNavBar) { + decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR); + } } } }); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewUserDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewUserDetailActivity.java index 61e4f5cb..670547d9 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewUserDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewUserDetailActivity.java @@ -176,17 +176,27 @@ public class ViewUserDetailActivity extends AppCompatActivity { Window window = getWindow(); window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); + boolean lightNavBar = false; + if((resources.getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) != Configuration.UI_MODE_NIGHT_YES) { + lightNavBar = true; + } + boolean finalLightNavBar = lightNavBar; + View decorView = window.getDecorView(); appBarLayout.addOnOffsetChangedListener(new AppBarStateChangeListener() { @Override void onStateChanged(AppBarLayout appBarLayout, State state) { if (state == State.COLLAPSED) { - decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR | View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR); + if(finalLightNavBar) { + decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR | View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR); + } tabLayout.setTabTextColors(collapsedTabTextColor, collapsedTabTextColor); tabLayout.setSelectedTabIndicatorColor(collapsedTabIndicatorColor); tabLayout.setBackgroundColor(collapsedTabBackgroundColor); } else if (state == State.EXPANDED) { - decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR); + if(finalLightNavBar) { + decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR); + } tabLayout.setTabTextColors(expandedTabTextColor, expandedTabTextColor); tabLayout.setSelectedTabIndicatorColor(expandedTabIndicatorColor); tabLayout.setBackgroundColor(expandedTabBackgroundColor); diff --git a/app/src/main/res/layout/activity_rules.xml b/app/src/main/res/layout/activity_rules.xml index a5764fa9..55f0ba07 100644 --- a/app/src/main/res/layout/activity_rules.xml +++ b/app/src/main/res/layout/activity_rules.xml @@ -6,22 +6,50 @@ android:layout_height="match_parent" tools:application=".RulesActivity"> + + + + + + + + + + + android:layout_gravity="center" + app:layout_behavior="@string/appbar_scrolling_view_behavior" /> + android:layout_height="match_parent" + android:clipToPadding="false" + app:layout_behavior="@string/appbar_scrolling_view_behavior" /> + android:visibility="gone" + app:layout_behavior="@string/appbar_scrolling_view_behavior" /> \ No newline at end of file diff --git a/app/src/main/res/layout/activity_subreddit_selection.xml b/app/src/main/res/layout/activity_subreddit_selection.xml index 6306a39f..92be6bbe 100644 --- a/app/src/main/res/layout/activity_subreddit_selection.xml +++ b/app/src/main/res/layout/activity_subreddit_selection.xml @@ -7,16 +7,26 @@ tools:application=".SubredditSelectionActivity"> - + android:layout_height="match_parent" + app:layout_scrollFlags="scroll|enterAlways" + app:titleEnabled="false" + app:toolbarId="@+id/toolbar_subreddit_selection_activity"> + + + + -- cgit v1.2.3