fix: dialogs.rawInput() keeps blocking when canceled
This commit is contained in:
@@ -75,8 +75,11 @@ public class ImageWrapper {
|
|||||||
int rowPadding = plane.getRowStride() - pixelStride * image.getWidth();
|
int rowPadding = plane.getRowStride() - pixelStride * image.getWidth();
|
||||||
Bitmap bitmap = Bitmap.createBitmap(image.getWidth() + rowPadding / pixelStride, image.getHeight(), Bitmap.Config.ARGB_8888);
|
Bitmap bitmap = Bitmap.createBitmap(image.getWidth() + rowPadding / pixelStride, image.getHeight(), Bitmap.Config.ARGB_8888);
|
||||||
bitmap.copyPixelsFromBuffer(buffer);
|
bitmap.copyPixelsFromBuffer(buffer);
|
||||||
|
if(rowPadding == 0){
|
||||||
return bitmap;
|
return bitmap;
|
||||||
}
|
}
|
||||||
|
return Bitmap.createBitmap(bitmap, 0, 0, image.getWidth(), image.getHeight());
|
||||||
|
}
|
||||||
|
|
||||||
public int getWidth() {
|
public int getWidth() {
|
||||||
return mWidth;
|
return mWidth;
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ import android.media.projection.MediaProjectionManager;
|
|||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
import android.support.annotation.NonNull;
|
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import android.support.annotation.RequiresApi;
|
import android.support.annotation.RequiresApi;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
@@ -63,7 +62,7 @@ public class ScreenCapturer {
|
|||||||
private void initVirtualDisplay(MediaProjectionManager manager, Intent data, int screenWidth, int screenHeight, int screenDensity) {
|
private void initVirtualDisplay(MediaProjectionManager manager, Intent data, int screenWidth, int screenHeight, int screenDensity) {
|
||||||
mImageReader = ImageReader.newInstance(screenWidth, screenHeight, PixelFormat.RGBA_8888, 2);
|
mImageReader = ImageReader.newInstance(screenWidth, screenHeight, PixelFormat.RGBA_8888, 2);
|
||||||
mMediaProjection = manager.getMediaProjection(Activity.RESULT_OK, data);
|
mMediaProjection = manager.getMediaProjection(Activity.RESULT_OK, data);
|
||||||
mVirtualDisplay = mMediaProjection.createVirtualDisplay("screen-mirror",
|
mVirtualDisplay = mMediaProjection.createVirtualDisplay(LOG_TAG,
|
||||||
screenWidth, screenHeight, screenDensity, DisplayManager.VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR,
|
screenWidth, screenHeight, screenDensity, DisplayManager.VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR,
|
||||||
mImageReader.getSurface(), null, null);
|
mImageReader.getSurface(), null, null);
|
||||||
}
|
}
|
||||||
@@ -83,20 +82,22 @@ public class ScreenCapturer {
|
|||||||
|
|
||||||
private void setImageListener(Handler handler) {
|
private void setImageListener(Handler handler) {
|
||||||
mImageReader.setOnImageAvailableListener(reader -> {
|
mImageReader.setOnImageAvailableListener(reader -> {
|
||||||
|
if (mCachedImage != null) {
|
||||||
synchronized (mCachedImageLock) {
|
synchronized (mCachedImageLock) {
|
||||||
if (mCachedImage != null) {
|
if (mCachedImage != null) {
|
||||||
mCachedImage.close();
|
mCachedImage.close();
|
||||||
}
|
}
|
||||||
mCachedImage = reader.acquireLatestImage();
|
mCachedImage = reader.acquireLatestImage();
|
||||||
if (mCachedImage != null) {
|
|
||||||
mImageAvailable = true;
|
mImageAvailable = true;
|
||||||
mCachedImageLock.notify();
|
mCachedImageLock.notify();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
mCachedImage = reader.acquireLatestImage();
|
||||||
}, handler);
|
}, handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@Nullable
|
||||||
public Image capture() {
|
public Image capture() {
|
||||||
if (!mImageAvailable) {
|
if (!mImageAvailable) {
|
||||||
waitForImageAvailable();
|
waitForImageAvailable();
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package com.stardust.autojs.core.ui;
|
|||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.ContextWrapper;
|
import android.content.ContextWrapper;
|
||||||
|
import android.content.DialogInterface;
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
@@ -71,6 +72,7 @@ public class BlockedMaterialDialog extends MaterialDialog {
|
|||||||
|
|
||||||
public MaterialDialog.Builder input(@Nullable CharSequence hint, @Nullable CharSequence prefill, boolean allowEmptyInput) {
|
public MaterialDialog.Builder input(@Nullable CharSequence hint, @Nullable CharSequence prefill, boolean allowEmptyInput) {
|
||||||
super.input(hint, prefill, allowEmptyInput, (dialog, input) -> setAndNotify(input.toString()));
|
super.input(hint, prefill, allowEmptyInput, (dialog, input) -> setAndNotify(input.toString()));
|
||||||
|
cancelListener(dialog -> setAndNotify(null));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ public class ScreenMetrics {
|
|||||||
public static void initIfNeeded(Activity activity) {
|
public static void initIfNeeded(Activity activity) {
|
||||||
if (!initialized) {
|
if (!initialized) {
|
||||||
DisplayMetrics metrics = new DisplayMetrics();
|
DisplayMetrics metrics = new DisplayMetrics();
|
||||||
activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);
|
activity.getWindowManager().getDefaultDisplay().getRealMetrics(metrics);
|
||||||
deviceScreenHeight = metrics.heightPixels;
|
deviceScreenHeight = metrics.heightPixels;
|
||||||
deviceScreenWidth = metrics.widthPixels;
|
deviceScreenWidth = metrics.widthPixels;
|
||||||
deviceScreenDensity = metrics.densityDpi;
|
deviceScreenDensity = metrics.densityDpi;
|
||||||
|
|||||||
Reference in New Issue
Block a user