Fixed nav bar icon color in dark theme. Transparent nav bar in SubredditSelectionActivity for Android version >= 8.1.

This commit is contained in:
Alex Ning
2019-08-12 09:26:27 +08:00
parent 002fa44d8a
commit 90c7c66405
11 changed files with 231 additions and 26 deletions

View File

@@ -134,14 +134,24 @@ public class MainActivity extends AppCompatActivity implements SortTypeBottomShe
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);
}
}
}
});

View File

@@ -1,19 +1,26 @@
package ml.docilealligator.infinityforreddit;
import android.graphics.drawable.Drawable;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ProgressBar;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.google.android.material.appbar.AppBarLayout;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
@@ -34,6 +41,8 @@ public class RulesActivity extends AppCompatActivity {
static final String EXTRA_SUBREDDIT_NAME = "ESN";
@BindView(R.id.appbar_rules_activity) AppBarLayout appBarLayout;
@BindView(R.id.toolbar_rules_activity) Toolbar toolbar;
@BindView(R.id.progress_bar_rules_activity) ProgressBar progressBar;
@BindView(R.id.recycler_view_rules_activity) RecyclerView recyclerView;
@BindView(R.id.error_text_view_rules_activity) TextView errorTextView;
@@ -55,9 +64,49 @@ public class RulesActivity extends AppCompatActivity {
((Infinity) getApplication()).getAppComponent().inject(this);
ActionBar actionBar = getSupportActionBar();
Drawable upArrow = getResources().getDrawable(R.drawable.ic_arrow_back_white_24dp);
actionBar.setHomeAsUpIndicator(upArrow);
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);
mSubredditName = getIntent().getExtras().getString(EXTRA_SUBREDDIT_NAME);

View File

@@ -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);
}
}
}
});

View File

@@ -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);

View File

@@ -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);
}
}
}
});

View File

@@ -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);
}
}
}
});

View File

@@ -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);
}
}
}
});

View File

@@ -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);