Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 36b7b5b4 authored by Ivan Chiang's avatar Ivan Chiang
Browse files

Fix the issue of select file fail when in split screen mode

The RawX and RawY of motion event are based on all screen. The
rectangle returned from getGlobalVisibleRect is based on current
window. Use getLocationOnScreen to create a new rectangle to instead.

Change-Id: Ibbb55d61df50220ca7e642491f026ff9f3b01a5e
Fix: 113354083
Test: manual, enter split screen mode and click the mime-type icon
parent 65bbe793
Loading
Loading
Loading
Loading
+16 −0
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.documentsui.dirlist;

import android.content.Context;
import android.database.Cursor;
import android.graphics.Rect;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.MotionEvent;
@@ -39,6 +40,8 @@ public abstract class DocumentHolder
        extends RecyclerView.ViewHolder implements View.OnKeyListener {

    static final float DISABLED_ALPHA = 0.3f;
    private static final int[] sCoord = new int[2];
    private static final Rect sViewRect = new Rect();

    protected final Context mContext;

@@ -151,4 +154,17 @@ public abstract class DocumentHolder
    static ViewPropertyAnimator fade(ImageView view, float alpha) {
        return view.animate().setDuration(Shared.CHECK_ANIMATION_DURATION).alpha(alpha);
    }

    static boolean isTouchInViewRegion(View view, MotionEvent event) {
        if (view == null || event == null || !view.isAttachedToWindow()) {
            return false;
        }

        view.getLocationOnScreen(sCoord);

        sViewRect.set(sCoord[0], sCoord[1], sCoord[0] + view.getMeasuredWidth(),
                sCoord[1] + view.getMeasuredHeight());

        return sViewRect.contains((int) event.getRawX(), (int) event.getRawY());
    }
}
+1 −4
Original line number Diff line number Diff line
@@ -69,10 +69,7 @@ final class GridDirectoryHolder extends DocumentHolder {

    @Override
    public boolean inSelectRegion(MotionEvent event) {
        Rect iconRect = new Rect();
        mIconLayout.getGlobalVisibleRect(iconRect);

        return iconRect.contains((int) event.getRawX(), (int) event.getRawY());
        return DocumentHolder.isTouchInViewRegion(mIconLayout, event);
    }

    /**
+1 −4
Original line number Diff line number Diff line
@@ -120,10 +120,7 @@ final class GridDocumentHolder extends DocumentHolder {

    @Override
    public boolean inSelectRegion(MotionEvent event) {
        Rect iconRect = new Rect();
        mIconLayout.getGlobalVisibleRect(iconRect);

        return iconRect.contains((int) event.getRawX(), (int) event.getRawY());
        return DocumentHolder.isTouchInViewRegion(mIconLayout, event);
    }

    /**
+1 −4
Original line number Diff line number Diff line
@@ -140,10 +140,7 @@ final class ListDocumentHolder extends DocumentHolder {

    @Override
    public boolean inSelectRegion(MotionEvent event) {
        Rect iconRect = new Rect();
        mIconLayout.getGlobalVisibleRect(iconRect);

        return iconRect.contains((int) event.getRawX(), (int) event.getRawY());
        return DocumentHolder.isTouchInViewRegion(mIconLayout, event);
    }

    /**