我有一个使用Android Image Cropper库进行裁剪的活动。我一直收到此错误无法解析符号' OnGetCroppedImageCompleteListener'我花了几天试图解决没有任何成功。
以下是发生错误的MainActivity.java:
import android.Manifest;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;
import com.theartofdev.edmodo.cropper.CropImage;
import com.theartofdev.edmodo.cropper.CropImageView;
public class MainActivity extends AppCompatActivity implements CropImageView.OnGetCroppedImageCompleteListener, CropImageView.OnSetImageUriCompleteListener {
private CropImageView mCropImageView;
private View mProgressView;
private Uri mCropImageUri;
private TextView mProgressViewText;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mCropImageView = (CropImageView) findViewById(R.id.CropImageView);
mProgressView = findViewById(R.id.ProgressView);
mProgressViewText = (TextView) findViewById(R.id.ProgressViewText);
}
@Override
protected void onStart() {
super.onStart();
mCropImageView.setOnSetImageUriCompleteListener(this);
mCropImageView.setOnGetCroppedImageCompleteListener(this);
}
@Override
protected void onStop() {
super.onStop();
mCropImageView.setOnSetImageUriCompleteListener(null);
mCropImageView.setOnGetCroppedImageCompleteListener(null);
}
public void onLoadImageClick(View view) {
CropImage.startPickImageActivity(this);
}
public void onCropImageClick(View view) {
mCropImageView.getCroppedImageAsync(mCropImageView.getCropShape(), 500, 500);
mProgressViewText.setText("Cropping...");
mProgressView.setVisibility(View.VISIBLE);
}
@Override
public void onSetImageUriComplete(CropImageView cropImageView, Uri uri, Exception error) {
mProgressView.setVisibility(View.INVISIBLE);
if (error != null) {
Log.e("Crop", "Failed to load image for cropping", error);
Toast.makeText(this, "Something went wrong, try again", Toast.LENGTH_LONG).show();
}
}
@Override
public void onGetCroppedImageComplete(CropImageView view, Bitmap bitmap, Exception error) {
mProgressView.setVisibility(View.INVISIBLE);
if (error == null) {
if (bitmap != null) {
mCropImageView.setImageBitmap(bitmap);
}
} else {
Log.e("Crop", "Failed to crop image", error);
Toast.makeText(this, "Something went wrong, try again", Toast.LENGTH_LONG).show();
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == Activity.RESULT_OK) {
Uri imageUri = CropImage.getPickImageResultUri(this, data);
// For API >= 23 we need to check specifically that we have permissions to read external storage,
// but we don't know if we need to for the URI so the simplest is to try open the stream and see if we get error.
boolean requirePermissions = false;
if (CropImage.isReadExternalStoragePermissionsRequired(this, imageUri)) {
// request permissions and handle the result in onRequestPermissionsResult()
requirePermissions = true;
mCropImageUri = imageUri;
requestPermissions(new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, 0);
}
if (!requirePermissions) {
mCropImageView.setImageUriAsync(imageUri);
mProgressViewText.setText("Loading...");
mProgressView.setVisibility(View.VISIBLE);
}
}
}
@Override
public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
if (mCropImageUri != null && grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
mCropImageView.setImageUriAsync(mCropImageUri);
mProgressViewText.setText("Loading...");
mProgressView.setVisibility(View.VISIBLE);
} else {
Toast.makeText(this, "Required permissions are not granted", Toast.LENGTH_LONG).show();
}
}
}
我刚刚添加了build.gradle文件以获取更多信息:
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
buildToolsVersion "26.0.2"
defaultConfig {
applicationId "com.paigger.imagecroppercutomui"
minSdkVersion 23
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:26.+'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.theartofdev.edmodo:android-image-cropper:2.5.+'
testCompile 'junit:junit:4.12'
}
答案 0 :(得分:1)
使用scripts = driver.execute_script("""
return window.performance.getEntriesByType("resource")
.filter(e => e.initiatorType === 'script')
.map(e => e.name);
""")
print(scripts)
代替OnCropImageCompleteListener
这个库中没有这样的界面。
您可以查看视图类here