Skip to content
This repository has been archived by the owner on Feb 25, 2022. It is now read-only.

Commit

Permalink
Only Translucent for KK
Browse files Browse the repository at this point in the history
  • Loading branch information
seven332 committed Oct 5, 2015
1 parent 94b446f commit a2664e0
Show file tree
Hide file tree
Showing 17 changed files with 157 additions and 78 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ android {
applicationId "com.hippo.nimingban"
minSdkVersion 14
targetSdkVersion 23
versionCode 17
versionName "1.2.3"
versionCode 18
versionName "1.2.4"
resConfigs "zh", "zh-rCN"
}

Expand Down
22 changes: 11 additions & 11 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

<activity
android:name="com.hippo.nimingban.ui.ListActivity"
android:theme="@style/AppTheme.NoActionBar.Translucent.Status"
android:theme="@style/ListActivity"
android:configChanges="screenSize|uiMode|orientation"
android:screenOrientation="unspecified">

Expand All @@ -45,7 +45,7 @@

<activity
android:name="com.hippo.nimingban.ui.PostActivity"
android:theme="@style/AppTheme.NoActionBar.Translucent.Transparent"
android:theme="@style/SwipeActivity"
android:configChanges="screenSize|uiMode|orientation"
android:screenOrientation="unspecified">

Expand All @@ -65,13 +65,13 @@
<activity
android:name="com.hippo.nimingban.ui.GalleryActivity2"
android:label="@string/gallery"
android:theme="@style/AppTheme.NoActionBar.Translucent.Transparent"
android:theme="@style/SwipeActivity"
android:configChanges="screenSize|uiMode|orientation"
android:screenOrientation="unspecified"/>

<activity
android:name="com.hippo.nimingban.ui.TypeSendActivity"
android:theme="@style/AppTheme.NoActionBar.Translucent"
android:theme="@style/NormalActivity"
android:configChanges="screenSize|uiMode|orientation"
android:screenOrientation="unspecified"
android:windowSoftInputMode="stateVisible|adjustResize">
Expand All @@ -93,21 +93,21 @@
<activity
android:name="com.hippo.nimingban.ui.DoodleActivity"
android:label="@string/doodle"
android:theme="@style/AppTheme.NoActionBar.Translucent"
android:theme="@style/NormalActivity"
android:configChanges="screenSize|uiMode|orientation"
android:screenOrientation="unspecified"/>

<activity
android:name="com.hippo.nimingban.ui.DraftActivity"
android:label="@string/draft"
android:theme="@style/AppTheme.NoActionBar.Translucent"
android:theme="@style/NormalActivity"
android:configChanges="screenSize|uiMode|orientation"
android:screenOrientation="unspecified"/>

<activity
android:name="com.hippo.nimingban.ui.FeedActivity"
android:label="@string/feed"
android:theme="@style/AppTheme.NoActionBar.Translucent"
android:theme="@style/NormalActivity"
android:configChanges="screenSize|uiMode|orientation"
android:screenOrientation="unspecified"/>

Expand All @@ -121,28 +121,28 @@
<activity
android:name="com.hippo.nimingban.ui.DirPickerActivity"
android:label="@string/dir_picker"
android:theme="@style/AppTheme.NoActionBar.Translucent"
android:theme="@style/NormalActivity"
android:configChanges="screenSize|uiMode|orientation"
android:screenOrientation="unspecified"/>

<activity
android:name="com.hippo.nimingban.ui.SortForumsActivity"
android:label="@string/sort_forums"
android:theme="@style/AppTheme.NoActionBar.Translucent"
android:theme="@style/NormalActivity"
android:configChanges="screenSize|uiMode|orientation"
android:screenOrientation="unspecified"/>

<activity
android:name="com.hippo.nimingban.ui.SearchActivity"
android:label="@string/search"
android:theme="@style/AppTheme.NoActionBar.Translucent"
android:theme="@style/NormalActivity"
android:configChanges="screenSize|uiMode|orientation"
android:screenOrientation="unspecified"/>

<activity
android:name="com.hippo.nimingban.ui.RecordActivity"
android:label="@string/record"
android:theme="@style/AppTheme.NoActionBar.Translucent"
android:theme="@style/NormalActivity"
android:configChanges="screenSize|uiMode|orientation"
android:screenOrientation="unspecified"/>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ public class DirPickerActivity extends TranslucentActivity implements View.OnCli

@Override
protected int getLightThemeResId() {
return R.style.AppTheme_NoActionBar_Translucent;
return R.style.NormalActivity;
}

@Override
protected int getDarkThemeResId() {
return R.style.AppTheme_Dark_NoActionBar_Translucent;
return R.style.NormalActivity_Dark;
}

@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/hippo/nimingban/ui/DoodleActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,12 @@ public final class DoodleActivity extends TranslucentActivity implements View.On

@Override
protected int getLightThemeResId() {
return R.style.AppTheme_NoActionBar_Translucent;
return R.style.NormalActivity;
}

@Override
protected int getDarkThemeResId() {
return R.style.AppTheme_Dark_NoActionBar_Translucent;
return R.style.NormalActivity_Dark;
}

@Override
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/hippo/nimingban/ui/DraftActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@ public final class DraftActivity extends TranslucentActivity implements EasyRecy

@Override
protected int getLightThemeResId() {
return R.style.AppTheme_NoActionBar_Translucent;
return R.style.NormalActivity;
}

@Override
protected int getDarkThemeResId() {
return R.style.AppTheme_Dark_NoActionBar_Translucent;
return R.style.NormalActivity_Dark;
}

@Override
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/hippo/nimingban/ui/FeedActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,12 @@ public final class FeedActivity extends TranslucentActivity implements EasyRecyc

@Override
protected int getLightThemeResId() {
return R.style.AppTheme_NoActionBar_Translucent;
return R.style.NormalActivity;
}

@Override
protected int getDarkThemeResId() {
return R.style.AppTheme_Dark_NoActionBar_Translucent;
return R.style.NormalActivity_Dark;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,12 @@ private boolean handlerIntent(Intent intent) {

@Override
protected int getLightThemeResId() {
return R.style.AppTheme_NoActionBar_Translucent_Transparent;
return R.style.SwipeActivity;
}

@Override
protected int getDarkThemeResId() {
return R.style.AppTheme_Dark_NoActionBar_Translucent_Transparent;
return R.style.SwipeActivity_Dark;
}

@SuppressWarnings("deprecation")
Expand Down
8 changes: 3 additions & 5 deletions app/src/main/java/com/hippo/nimingban/ui/ListActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,12 @@ public final class ListActivity extends AbsActivity

@Override
protected int getLightThemeResId() {
return R.style.AppTheme_NoActionBar_Translucent_Status;
return R.style.ListActivity;
}

@Override
protected int getDarkThemeResId() {
return R.style.AppTheme_Dark_NoActionBar_Translucent_Status;
return R.style.ListActivity_Dark;
}

@Override
Expand Down Expand Up @@ -244,9 +244,7 @@ public void onDrawerOpened(View view) {

mSlidingDrawerLayout.setDrawerShadow(ContextCompat.getDrawable(this, R.drawable.drawer_shadow_left), Gravity.LEFT);
mSlidingDrawerLayout.setDrawerShadow(ContextCompat.getDrawable(this, R.drawable.drawer_shadow_right), Gravity.RIGHT);
mSlidingDrawerLayout.setStatusBarColor(
TranslucentHelper.getColorForTranslucent(
ResourcesUtils.getAttrColor(this, R.attr.colorPrimaryDark)));
mSlidingDrawerLayout.setStatusBarColor(ResourcesUtils.getAttrColor(this, R.attr.colorPrimaryDark));

mPostHelper = new PostHelper();
mPostHelper.setEmptyString(getString(R.string.no_post));
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/hippo/nimingban/ui/PostActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,12 @@ private boolean handlerIntent(Intent intent) {

@Override
protected int getLightThemeResId() {
return R.style.AppTheme_NoActionBar_Translucent_Transparent;
return R.style.SwipeActivity;
}

@Override
protected int getDarkThemeResId() {
return R.style.AppTheme_Dark_NoActionBar_Translucent_Transparent;
return R.style.SwipeActivity_Dark;
}

@Override
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/hippo/nimingban/ui/RecordActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,12 @@ public final class RecordActivity extends TranslucentActivity

@Override
protected int getLightThemeResId() {
return R.style.AppTheme_NoActionBar_Translucent;
return R.style.NormalActivity;
}

@Override
protected int getDarkThemeResId() {
return R.style.AppTheme_Dark_NoActionBar_Translucent;
return R.style.NormalActivity_Dark;
}

@SuppressWarnings("deprecation")
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/hippo/nimingban/ui/SearchActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@ public class SearchActivity extends TranslucentActivity implements EasyRecyclerV

@Override
protected int getLightThemeResId() {
return R.style.AppTheme_NoActionBar_Translucent;
return R.style.NormalActivity;
}

@Override
protected int getDarkThemeResId() {
return R.style.AppTheme_Dark_NoActionBar_Translucent;
return R.style.NormalActivity_Dark;
}

// false for error
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,12 @@ private boolean handlerIntent(Intent intent) {

@Override
protected int getLightThemeResId() {
return R.style.AppTheme_NoActionBar_Translucent;
return R.style.NormalActivity;
}

@Override
protected int getDarkThemeResId() {
return R.style.AppTheme_Dark_NoActionBar_Translucent;
return R.style.NormalActivity_Dark;
}

@Override
Expand Down
74 changes: 34 additions & 40 deletions app/src/main/java/com/hippo/nimingban/ui/TranslucentHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@

public class TranslucentHelper {

private static final boolean VALID = Build.VERSION.SDK_INT == Build.VERSION_CODES.KITKAT;

private int mStatusBarColor = Color.BLACK;
private int mNavigationBarColor = Color.BLACK;

Expand All @@ -37,65 +39,57 @@ public class TranslucentHelper {

private TranslucentLayout mTranslucentLayout;

/**
* windowTranslucentStatus make status bar translucent, so the status bar background looks draker.
* Lighter color is needed for status bar.
* It work fine in AOSP.
*/
public static int getColorForTranslucent(int color) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
return Color.argb(
Color.alpha(color),
Math.min(Color.red(color) * 5 / 3, 0xff),
Math.min(Color.green(color) * 5 / 3, 0xff),
Math.min(Color.blue(color) * 5 / 3, 0xff));
} else {
return color;
}
}

public void handleContentView(Activity activity) {
ViewGroup decor = (ViewGroup) activity.getWindow().getDecorView();
ViewGroup decorChild = (ViewGroup) decor.getChildAt(0);
decor.removeView(decorChild);
mTranslucentLayout = new TranslucentLayout(activity);
mTranslucentLayout.setShowStatusBar(mShowStatusBar);
mTranslucentLayout.setShowNavigationBar(mShowNavigationBar);
mTranslucentLayout.setStatusBarColor(mStatusBarColor);
mTranslucentLayout.setNavigationBarColor(mNavigationBarColor);
mTranslucentLayout.addView(decorChild);
decor.addView(mTranslucentLayout);
if (VALID) {
ViewGroup decor = (ViewGroup) activity.getWindow().getDecorView();
ViewGroup decorChild = (ViewGroup) decor.getChildAt(0);
decor.removeView(decorChild);
mTranslucentLayout = new TranslucentLayout(activity);
mTranslucentLayout.setShowStatusBar(mShowStatusBar);
mTranslucentLayout.setShowNavigationBar(mShowNavigationBar);
mTranslucentLayout.setStatusBarColor(mStatusBarColor);
mTranslucentLayout.setNavigationBarColor(mNavigationBarColor);
mTranslucentLayout.addView(decorChild);
decor.addView(mTranslucentLayout);
}
}

public void setStatusBarColor(int color) {
mStatusBarColor = getColorForTranslucent(color);
if (mTranslucentLayout != null) {
mTranslucentLayout.setStatusBarColor(color);
if (VALID) {
mStatusBarColor = color;
if (mTranslucentLayout != null) {
mTranslucentLayout.setStatusBarColor(color);
}
}
}

public void setNavigationBarColor(int color) {
mNavigationBarColor = getColorForTranslucent(color);
if (mTranslucentLayout != null) {
mTranslucentLayout.setNavigationBarColor(color);
if (VALID) {
mNavigationBarColor = color;
if (mTranslucentLayout != null) {
mTranslucentLayout.setNavigationBarColor(color);
}
}
}

public void setShowStatusBar(boolean showStatusBar) {
mShowStatusBar = showStatusBar;
if (mTranslucentLayout != null) {
mTranslucentLayout.setShowStatusBar(showStatusBar);
if (VALID) {
mShowStatusBar = showStatusBar;
if (mTranslucentLayout != null) {
mTranslucentLayout.setShowStatusBar(showStatusBar);
}
}
}

public void setShowNavigationBar(boolean showNavigationBar) {
mShowNavigationBar = showNavigationBar;
if (mTranslucentLayout != null) {
mTranslucentLayout.setShowNavigationBar(showNavigationBar);
if (VALID) {
mShowNavigationBar = showNavigationBar;
if (mTranslucentLayout != null) {
mTranslucentLayout.setShowNavigationBar(showNavigationBar);
}
}
}


private static class TranslucentLayout extends ViewGroup {

private Paint mStatusBarPaint;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,12 +212,12 @@ private boolean handlerIntent(Intent intent) {

@Override
protected int getLightThemeResId() {
return R.style.AppTheme_NoActionBar_Translucent;
return R.style.NormalActivity;
}

@Override
protected int getDarkThemeResId() {
return R.style.AppTheme_Dark_NoActionBar_Translucent;
return R.style.NormalActivity_Dark;
}

@SuppressWarnings("deprecation")
Expand Down
Loading

0 comments on commit a2664e0

Please sign in to comment.