Skip to content

Commit

Permalink
优化了一点命名
Browse files Browse the repository at this point in the history
  • Loading branch information
liuchengcheng committed Nov 10, 2020
1 parent c380d6a commit fceaa40
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,20 @@ public void takePhoto() {
TAKE_PIC_RESULT_CODE);
}

/**
* 取消调用
*/
public void cancel() {
if (valueCallbacks != null) {
valueCallbacks.onReceiveValue(null);
valueCallbacks = null;
}
if (uriValueCallback != null) {
uriValueCallback.onReceiveValue(null);
uriValueCallback = null;
}
}

/**
* 跳转选择相册界面
*/
Expand Down Expand Up @@ -165,42 +179,5 @@ public static void update(Uri[] uris) {
}
}

public void cancle() {
if (valueCallbacks != null) {
valueCallbacks.onReceiveValue(null);
valueCallbacks = null;
}
if (uriValueCallback != null) {
uriValueCallback.onReceiveValue(null);
uriValueCallback = null;
}
}
// /**
// * 跳转哪个选择
// */
// public void select() {
// AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);
// dialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
// @Override
// public void onCancel(DialogInterface dialog) {
// cancle();
// }
// });
// dialog.setTitle("相册还是拍照");
// dialog.setNegativeButton("相册", new DialogInterface.OnClickListener() {
// @Override
// public void onClick(DialogInterface dialogInterface, int i) {
//
// }
// });
// dialog.setPositiveButton("拍照", new DialogInterface.OnClickListener() {
// @Override
// public void onClick(DialogInterface dialogInterface, int i) {
//
//
// }
// });
// dialog.show();
//
// }

}
39 changes: 39 additions & 0 deletions app/src/main/java/com/example/awebview/WebViewImlActivity.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.example.awebview;

import android.content.DialogInterface;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
Expand All @@ -13,8 +14,11 @@

import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;

import com.example.a_webview.components.PhotoWebChromeClient;
import com.example.a_webview.inter.onPhotoDialogListener;
import com.example.a_webview.web.AWebView;
import com.example.a_webview.web.AWebViewWrapper;
import com.example.a_webview.bean.InterBean;
Expand Down Expand Up @@ -72,6 +76,12 @@ public void onTitle(String title) {
mTitle.setText(title);
}
})
.setPhotoDialogListener(new onPhotoDialogListener() {
@Override
public void showPhotoDialog(PhotoWebChromeClient mClient) {
select(mClient);
}
})
.setReShouldOverrideUrlLoading(new ReShouldOverrideUrlLoadListener() {
@Override
public void interceptProcess(WebView wv, String url) {
Expand All @@ -84,6 +94,35 @@ public void interceptProcess(WebView wv, String url) {

}

/**
* 跳转哪个选择
*/
public void select(final PhotoWebChromeClient mClient) {
AlertDialog.Builder dialog = new AlertDialog.Builder(this);
dialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
mClient.cancel();
}
});
dialog.setTitle("相册还是拍照");
dialog.setNegativeButton("相册", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
mClient.openAlbum();
}
});
dialog.setPositiveButton("拍照", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
mClient.takePhoto();

}
});
dialog.show();

}

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK && mAWebView.canGoBack()) {
Expand Down

0 comments on commit fceaa40

Please sign in to comment.