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

Commit a96eca5

Browse files
committed
status & navigation bar dim on drawer slide, AboutPage improvement
1 parent cf58d08 commit a96eca5

File tree

4 files changed

+24
-19
lines changed

4 files changed

+24
-19
lines changed

README.md

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -449,14 +449,9 @@ A layout that looks like and has the same functions as the about screen in any S
449449

450450
</de.dlyt.yanndroid.samsung.layout.AboutPage>
451451
```
452-
The app name and version are automatically added to the view. The info icon at the top right will redirect the user to the app info in settings. The ```app:optional_text="..."``` is the text between the version and the status text. The status text will change according to the state you set the view (see below). You can use ```style="@style/ButtonStyle.AboutPage"``` for the buttons, which are shown at the bottom.
453-
:warning: For the back button (top left) to work you need to call this methode in your activity ```aboutPage.initAboutPage(this);```
452+
The app name and version are automatically added to the view. The info icon at the top right will redirect the user to the app info in settings. The ```app:optional_text="..."``` is the text between the version and the status text. The status text will change according to the state you set the view (see below). You can use ```style="@style/ButtonStyle.AboutPage"``` for the buttons, which are shown at the bottom.
454453

455454
#### Methods
456-
Essential for the back button to work.
457-
```java
458-
public void initAboutPage(Activity activity)
459-
```
460455
Set the update state of the view to either ```AboutPage.LOADING```, ```AboutPage.NO_UPDATE``` or ```AboutPage.UPDATE_AVAILABLE```. This will change the visibility of certain views and the text of the Status.
461456
```java
462457
public void setUpdateState(@UpdateState int state)
@@ -832,6 +827,7 @@ My sample app icon for example:
832827
- fixed landscape toolbar height
833828
- improved orientation switching
834829
- button text fix
830+
- status & navigation bar dim on drawer slide
835831
- added changelog to readme
836832

837833
</details>

app/src/main/java/de/dlyt/yanndroid/samsungexample/AboutActivity.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,11 @@ protected void onCreate(Bundle savedInstanceState) {
2020
setContentView(R.layout.activity_about);
2121

2222
AboutPage about_page = findViewById(R.id.about_page);
23-
about_page.initAboutPage(this);
2423

2524
((MaterialButton) findViewById(R.id.about_btn1)).setOnClickListener(v -> about_page.setUpdateState(AboutPage.LOADING));
2625
((MaterialButton) findViewById(R.id.about_btn2)).setOnClickListener(v -> about_page.setUpdateState(AboutPage.NO_UPDATE));
2726
((MaterialButton) findViewById(R.id.about_btn3)).setOnClickListener(v -> about_page.setUpdateState(AboutPage.UPDATE_AVAILABLE));
2827

29-
3028
if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
3129
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
3230
} else {

yanndroid/samsung/src/main/java/de/dlyt/yanndroid/samsung/layout/AboutPage.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import android.app.Activity;
44
import android.content.ActivityNotFoundException;
55
import android.content.Context;
6+
import android.content.ContextWrapper;
67
import android.content.Intent;
78
import android.content.pm.PackageInfo;
89
import android.content.pm.PackageManager;
@@ -84,11 +85,18 @@ public AboutPage(Context context, @Nullable AttributeSet attrs) {
8485
} catch (PackageManager.NameNotFoundException e) {
8586
e.printStackTrace();
8687
}
87-
88+
toolbarLayout.setNavigationOnClickListener(v -> getActivity().onBackPressed());
8889
}
8990

90-
public void initAboutPage(Activity activity) {
91-
toolbarLayout.setNavigationOnClickListener(v -> activity.onBackPressed());
91+
private Activity getActivity() {
92+
Context context = getContext();
93+
while (context instanceof ContextWrapper) {
94+
if (context instanceof Activity) {
95+
return (Activity) context;
96+
}
97+
context = ((ContextWrapper) context).getBaseContext();
98+
}
99+
return null;
92100
}
93101

94102
public void setUpdateButtonOnClickListener(OnClickListener listener) {

yanndroid/samsung/src/main/java/de/dlyt/yanndroid/samsung/layout/DrawerLayout.java

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55
import android.content.ContextWrapper;
66
import android.content.res.Configuration;
77
import android.content.res.TypedArray;
8+
import android.graphics.Color;
89
import android.graphics.drawable.Drawable;
910
import android.util.AttributeSet;
1011
import android.view.LayoutInflater;
1112
import android.view.View;
1213
import android.view.ViewGroup;
14+
import android.view.Window;
1315
import android.widget.ImageView;
1416
import android.widget.LinearLayout;
1517
import android.widget.TextView;
@@ -83,6 +85,7 @@ public DrawerLayout(Context context, @Nullable AttributeSet attrs) {
8385
init();
8486

8587
Boolean isRtl = getResources().getConfiguration().getLayoutDirection() == View.LAYOUT_DIRECTION_RTL;
88+
Window window = getActivity().getWindow();
8689

8790
ActionBarDrawerToggle actionBarDrawerToggle = new ActionBarDrawerToggle(getActivity(), drawerLayout, R.string.opened, R.string.closed) {
8891
@Override
@@ -91,17 +94,17 @@ public void onDrawerSlide(View drawerView, float slideOffset) {
9194
float slideX = drawerView.getWidth() * slideOffset;
9295
if (isRtl) slideX *= -1;
9396
content.setTranslationX(slideX);
97+
98+
float[] hsv = new float[3];
99+
Color.colorToHSV(ContextCompat.getColor(getContext(), R.color.background_color), hsv);
100+
hsv[2] *= 1f - (slideOffset * 0.2f);
101+
window.setStatusBarColor(Color.HSVToColor(hsv));
102+
window.setNavigationBarColor(Color.HSVToColor(hsv));
103+
94104
}
95105
};
96106
drawerLayout.addDrawerListener(actionBarDrawerToggle);
97-
98-
toolbarLayout.setNavigationOnClickListener(new OnClickListener() {
99-
@Override
100-
public void onClick(View v) {
101-
drawerLayout.openDrawer(drawer, true);
102-
}
103-
});
104-
107+
toolbarLayout.setNavigationOnClickListener(v -> drawerLayout.openDrawer(drawer, true));
105108
}
106109

107110
private void init() {

0 commit comments

Comments
 (0)