Created
November 26, 2020 07:32
-
-
Save edward1986/d33bbfa235249ded8414312f19a5d72d to your computer and use it in GitHub Desktop.
MainActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import androidx.appcompat.app.AppCompatActivity; | |
import androidx.core.view.GestureDetectorCompat; | |
import android.os.Bundle; | |
import android.view.GestureDetector; | |
import android.view.MotionEvent; | |
import android.view.View; | |
public class MainActivity extends AppCompatActivity { | |
private GestureDetectorCompat mGestureDetector; | |
private class GestureListener extends GestureDetector.SimpleOnGestureListener { | |
@Override | |
public boolean onDown(MotionEvent event) { | |
return true; | |
} | |
@Override | |
public boolean onFling(MotionEvent event1, MotionEvent event2, | |
float velocityX, float velocityY) { | |
return true; | |
} | |
@Override | |
public boolean onSingleTapUp(MotionEvent e) { | |
if (getSupportActionBar() != null && getSupportActionBar().isShowing()) { | |
hideSystemUi(); | |
} else { | |
showSystemUI(); | |
} | |
return true; | |
} | |
} | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
mGestureDetector = new GestureDetectorCompat(this, new GestureListener()); | |
hideSystemUi(); | |
} | |
private void hideSystemUi() { | |
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_IMMERSIVE | | |
View.SYSTEM_UI_FLAG_FULLSCREEN | | |
View.SYSTEM_UI_FLAG_LAYOUT_STABLE | | |
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | | |
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | | |
View.SYSTEM_UI_FLAG_HIDE_NAVIGATION); | |
} | |
private void showSystemUI() { | |
getWindow().getDecorView().setSystemUiVisibility( | |
View.SYSTEM_UI_FLAG_LAYOUT_STABLE | | |
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | | |
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN); | |
} | |
@Override | |
public boolean onTouchEvent(MotionEvent event) { | |
mGestureDetector.onTouchEvent(event); | |
return super.onTouchEvent(event); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment