Skip to content

Commit

Permalink
fix touch detection with a cutout screen
Browse files Browse the repository at this point in the history
  • Loading branch information
laplamgor committed Oct 20, 2021
1 parent 2170b8f commit d53f4c0
Showing 1 changed file with 3 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@

import android.content.Context;
import android.graphics.Color;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.view.GravityCompat;
import androidx.drawerlayout.widget.DrawerLayout;

import com.antest1.gotobrowser.R;
Expand All @@ -37,6 +35,7 @@ public CustomDrawerLayout(@NonNull Context context, @Nullable AttributeSet attrs

@Override
public boolean dispatchTouchEvent(MotionEvent event) {

if (!this.isDrawerOpen(Gravity.LEFT)) {
return super.dispatchTouchEvent(event);
}
Expand All @@ -52,12 +51,8 @@ public boolean dispatchTouchEvent(MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_UP) {
View content = findViewById(R.id.navigation);
int[] contentLocation = new int[2];
content.getLocationOnScreen(contentLocation);
Rect rect = new Rect(contentLocation[0],
contentLocation[1],
contentLocation[0] + content.getWidth(),
contentLocation[1] + content.getHeight());
clickedOutside = !(rect.contains((int) event.getX(), (int) event.getY()));
content.getLocationInWindow(contentLocation);
clickedOutside = contentLocation[0] + content.getWidth() < (int) event.getX();
}

if (clickedOutside) {
Expand Down

0 comments on commit d53f4c0

Please sign in to comment.