Add new way to have fulle screen in Android 11

This commit is contained in:
jacques 2022-01-20 19:45:28 +01:00
parent c4514e329f
commit cd10430643

View file

@ -2,16 +2,20 @@ package net.foucry.pilldroid;
import android.content.Intent; import android.content.Intent;
import android.graphics.Color; import android.graphics.Color;
import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.Window; import android.view.Window;
import android.view.WindowInsets;
import android.view.WindowInsetsController;
import android.view.WindowManager; import android.view.WindowManager;
import android.widget.Button; import android.widget.Button;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import androidx.core.content.ContextCompat; import androidx.core.content.ContextCompat;
import androidx.viewpager.widget.PagerAdapter; import androidx.viewpager.widget.PagerAdapter;
@ -41,11 +45,10 @@ public class WelcomeActivity extends AppCompatActivity {
} }
prefManager.setFirstTimeLaunch(false); prefManager.setFirstTimeLaunch(false);
// Making notification bar transparent
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
setContentView(R.layout.activity_welcome); setContentView(R.layout.activity_welcome);
setFullScreen();
viewPager = findViewById(R.id.view_pager); viewPager = findViewById(R.id.view_pager);
dotsLayout = findViewById(R.id.layoutDots); dotsLayout = findViewById(R.id.layoutDots);
btnSkip = findViewById(R.id.btn_skip); btnSkip = findViewById(R.id.btn_skip);
@ -90,7 +93,7 @@ public class WelcomeActivity extends AppCompatActivity {
public void onClick(View v) { public void onClick(View v) {
// checking for last page // checking for last page
// if last page home screen will be launched // if last page home screen will be launched
int current = getItem(+1); int current = getItem();
if (current < layouts.length) { if (current < layouts.length) {
// move to next screen // move to next screen
viewPager.setCurrentItem(current); viewPager.setCurrentItem(current);
@ -118,8 +121,8 @@ public class WelcomeActivity extends AppCompatActivity {
dots[currentPage].setTextColor(ContextCompat.getColor(this, R.color.dot_light)); dots[currentPage].setTextColor(ContextCompat.getColor(this, R.color.dot_light));
} }
private int getItem(int i) { private int getItem() {
return viewPager.getCurrentItem() + i; return viewPager.getCurrentItem() + 1;
} }
void launchHomeScreen() { void launchHomeScreen() {
@ -167,6 +170,27 @@ public class WelcomeActivity extends AppCompatActivity {
window.setStatusBarColor(Color.TRANSPARENT); window.setStatusBarColor(Color.TRANSPARENT);
} }
private void setFullScreen(){
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
getWindow().setDecorFitsSystemWindows(false);
WindowInsetsController controller = getWindow().getInsetsController();
if(controller != null) {
controller.hide(WindowInsets.Type.statusBars() | WindowInsets.Type.navigationBars());
controller.setSystemBarsBehavior(WindowInsetsController.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE);
}
}
else {
//noinspection
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_IMMERSIVE
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
}
}
/** /**
* View pager adapter * View pager adapter
*/ */
@ -175,8 +199,9 @@ public class WelcomeActivity extends AppCompatActivity {
public MyViewPagerAdapter() { public MyViewPagerAdapter() {
} }
@NonNull
@Override @Override
public Object instantiateItem(ViewGroup container, int position) { public Object instantiateItem(@NonNull ViewGroup container, int position) {
LayoutInflater layoutInflater = getLayoutInflater(); LayoutInflater layoutInflater = getLayoutInflater();
View view = layoutInflater.inflate(layouts[position], container, false); View view = layoutInflater.inflate(layouts[position], container, false);
@ -191,13 +216,13 @@ public class WelcomeActivity extends AppCompatActivity {
} }
@Override @Override
public boolean isViewFromObject(View view, Object obj) { public boolean isViewFromObject(@NonNull View view, Object obj) {
return view == obj; return view == obj;
} }
@Override @Override
public void destroyItem(ViewGroup container, int position, Object object) { public void destroyItem(ViewGroup container, int position, @NonNull Object object) {
View view = (View) object; View view = (View) object;
container.removeView(view); container.removeView(view);
} }