mirror of
https://github.com/TonyJiangWJ/Auto.js.git
synced 2026-06-21 21:01:43 +08:00
fix: dialogs.rawInput() keeps blocking when canceled
This commit is contained in:
parent
a51b9c24ed
commit
13aa6ed341
@ -75,7 +75,10 @@ public class ImageWrapper {
|
||||
int rowPadding = plane.getRowStride() - pixelStride * image.getWidth();
|
||||
Bitmap bitmap = Bitmap.createBitmap(image.getWidth() + rowPadding / pixelStride, image.getHeight(), Bitmap.Config.ARGB_8888);
|
||||
bitmap.copyPixelsFromBuffer(buffer);
|
||||
return bitmap;
|
||||
if(rowPadding == 0){
|
||||
return bitmap;
|
||||
}
|
||||
return Bitmap.createBitmap(bitmap, 0, 0, image.getWidth(), image.getHeight());
|
||||
}
|
||||
|
||||
public int getWidth() {
|
||||
|
||||
@ -13,7 +13,6 @@ import android.media.projection.MediaProjectionManager;
|
||||
import android.os.Build;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.annotation.RequiresApi;
|
||||
import android.util.Log;
|
||||
@ -63,7 +62,7 @@ public class ScreenCapturer {
|
||||
private void initVirtualDisplay(MediaProjectionManager manager, Intent data, int screenWidth, int screenHeight, int screenDensity) {
|
||||
mImageReader = ImageReader.newInstance(screenWidth, screenHeight, PixelFormat.RGBA_8888, 2);
|
||||
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,
|
||||
mImageReader.getSurface(), null, null);
|
||||
}
|
||||
@ -83,20 +82,22 @@ public class ScreenCapturer {
|
||||
|
||||
private void setImageListener(Handler handler) {
|
||||
mImageReader.setOnImageAvailableListener(reader -> {
|
||||
synchronized (mCachedImageLock) {
|
||||
if (mCachedImage != null) {
|
||||
mCachedImage.close();
|
||||
}
|
||||
mCachedImage = reader.acquireLatestImage();
|
||||
if (mCachedImage != null) {
|
||||
if (mCachedImage != null) {
|
||||
synchronized (mCachedImageLock) {
|
||||
if (mCachedImage != null) {
|
||||
mCachedImage.close();
|
||||
}
|
||||
mCachedImage = reader.acquireLatestImage();
|
||||
mImageAvailable = true;
|
||||
mCachedImageLock.notify();
|
||||
return;
|
||||
}
|
||||
}
|
||||
mCachedImage = reader.acquireLatestImage();
|
||||
}, handler);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Nullable
|
||||
public Image capture() {
|
||||
if (!mImageAvailable) {
|
||||
waitForImageAvailable();
|
||||
@ -167,4 +168,4 @@ public class ScreenCapturer {
|
||||
super.finalize();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -3,6 +3,7 @@ package com.stardust.autojs.core.ui;
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.ContextWrapper;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Looper;
|
||||
import android.support.annotation.Nullable;
|
||||
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) {
|
||||
super.input(hint, prefill, allowEmptyInput, (dialog, input) -> setAndNotify(input.toString()));
|
||||
cancelListener(dialog -> setAndNotify(null));
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@ -20,7 +20,7 @@ public class ScreenMetrics {
|
||||
public static void initIfNeeded(Activity activity) {
|
||||
if (!initialized) {
|
||||
DisplayMetrics metrics = new DisplayMetrics();
|
||||
activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);
|
||||
activity.getWindowManager().getDefaultDisplay().getRealMetrics(metrics);
|
||||
deviceScreenHeight = metrics.heightPixels;
|
||||
deviceScreenWidth = metrics.widthPixels;
|
||||
deviceScreenDensity = metrics.densityDpi;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user