首页 > 解决方案 > android studio 中的 VINTF 清单是什么?有错误

问题描述

2020-04-22 16:14:49.759 1809-1809/? E/servicemanager:在 VINTF 清单中找不到 android.hardware.power.IPower/default。

这不断出现。我正在编码一个相机,当一个按钮被点击时,一个图像被裁剪。

这是我添加到片段的自定义视图。

公共类 DrawView 扩展视图 {

Point[] points = new Point[4];

/**
 * point1 and point 3 are of same group and same as point 2 and point4
 */
int groupId = -1;
private ArrayList<ColorBall> colorballs = new ArrayList<>();

private int mStrokeColor = Color.parseColor("#AADB1255");
private int mFillColor = Color.parseColor("#55DB1255");
private Rect mCropRect = new Rect();

// array that holds the balls
private int balID = 0;
// variable to know what ball is being dragged
Paint paint;

public DrawView(Context context) {
    this(context, null);
}

public DrawView(Context context, AttributeSet attrs) {
    this(context, attrs, -1);
}

public DrawView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    init();
}

private void init() {
    paint = new Paint();
    setFocusable(true); // necessary for getting the touch events
}

private void initRectangle(int X, int Y) {
    //initialize rectangle.
    points[0] = new Point();
    points[0].x = X - 200;
    points[0].y = Y - 100;

    points[1] = new Point();
    points[1].x = X;
    points[1].y = Y + 30;

    points[2] = new Point();
    points[2].x = X + 30;
    points[2].y = Y + 30;

    points[3] = new Point();
    points[3].x = X + 30;
    points[3].y = Y;

    balID = 2;
    groupId = 1;
    // declare each ball with the ColorBall class
    for (int i = 0; i < points.length; i++) {
        colorballs.add(new ColorBall(getContext(), R.drawable.gray_circle, points[i], i));
    }
}

// the method that draws the balls
@Override
protected void onDraw(Canvas canvas) {
    if(points[3]==null) {
        //point4 null when view first create
        initRectangle(getWidth() / 2, getHeight() / 2);
    }

    int left, top, right, bottom;
    left = points[0].x;
    top = points[0].y;
    right = points[0].x;
    bottom = points[0].y;
    for (int i = 1; i < points.length; i++) {
        left = left > points[i].x ? points[i].x : left;
        top = top > points[i].y ? points[i].y : top;
        right = right < points[i].x ? points[i].x : right;
        bottom = bottom < points[i].y ? points[i].y : bottom;
    }
    paint.setAntiAlias(true);
    paint.setDither(true);
    paint.setStrokeJoin(Paint.Join.ROUND);
    paint.setStrokeWidth(5);

    //draw stroke
    paint.setStyle(Paint.Style.STROKE);
    paint.setColor(mStrokeColor);
    paint.setStrokeWidth(2);

    mCropRect.left = left + colorballs.get(0).getWidthOfBall() / 2;
    mCropRect.top = top + colorballs.get(0).getWidthOfBall() / 2;
    mCropRect.right = right + colorballs.get(2).getWidthOfBall() / 2;
    mCropRect.bottom = bottom + colorballs.get(3).getWidthOfBall() / 2;
    canvas.drawRect(mCropRect, paint);

    //fill the rectangle
    paint.setStyle(Paint.Style.FILL);
    paint.setColor(mFillColor);
    paint.setStrokeWidth(0);
    canvas.drawRect(mCropRect, paint);

    // draw the balls on the canvas
    paint.setColor(Color.RED);
    paint.setTextSize(18);
    paint.setStrokeWidth(0);
    for (int i =0; i < colorballs.size(); i ++) {
        ColorBall ball = colorballs.get(i);
        canvas.drawBitmap(ball.getBitmap(), ball.getX(), ball.getY(),
                paint);

        canvas.drawText("" + (i+1), ball.getX(), ball.getY(), paint);
    }
}

// events when touching the screen
public boolean onTouchEvent(MotionEvent event) {
    int eventAction = event.getAction();

    int X = (int) event.getX();
    int Y = (int) event.getY();

    switch (eventAction) {

        case MotionEvent.ACTION_DOWN: // touch down so check if the finger is on
            // a ball
            if (points[0] == null) {
                initRectangle(X, Y);
            } else {
                //resize rectangle
                balID = -1;
                groupId = -1;
                for (int i = colorballs.size()-1; i>=0; i--) {
                    ColorBall ball = colorballs.get(i);
                    // check if inside the bounds of the ball (circle)
                    // get the center for the ball
                    int centerX = ball.getX() + ball.getWidthOfBall();
                    int centerY = ball.getY() + ball.getHeightOfBall();
                    paint.setColor(Color.CYAN);
                    // calculate the radius from the touch to the center of the
                    // ball
                    double radCircle = Math
                            .sqrt((double) (((centerX - X) * (centerX - X)) + (centerY - Y)
                                    * (centerY - Y)));

                    if (radCircle < ball.getWidthOfBall()) {

                        balID = ball.getID();
                        if (balID == 1 || balID == 3) {
                            groupId = 2;
                        } else {
                            groupId = 1;
                        }
                        invalidate();
                        break;
                    }
                    invalidate();
                }
            }
            break;

        case MotionEvent.ACTION_MOVE: // touch drag with the ball

            if (balID > -1) {
                // move the balls the same as the finger
                colorballs.get(balID).setX(X);
                colorballs.get(balID).setY(Y);

                paint.setColor(Color.CYAN);
                if (groupId == 1) {
                    colorballs.get(1).setX(colorballs.get(0).getX());
                    colorballs.get(1).setY(colorballs.get(2).getY());
                    colorballs.get(3).setX(colorballs.get(2).getX());
                    colorballs.get(3).setY(colorballs.get(0).getY());
                } else {
                    colorballs.get(0).setX(colorballs.get(1).getX());
                    colorballs.get(0).setY(colorballs.get(3).getY());
                    colorballs.get(2).setX(colorballs.get(3).getX());
                    colorballs.get(2).setY(colorballs.get(1).getY());
                }

                invalidate();
            }

            break;

        case MotionEvent.ACTION_UP:
            // touch drop - just do things here after dropping
            break;
    }
    // redraw the canvas
    invalidate();
    return true;
}

public Drawable doTheCrop(Bitmap sourceBitmap) throws IOException {

    //Bitmap sourceBitmap = null;
    //Drawable backgroundDrawable = getBackground();
    /*
    if (backgroundDrawable instanceof BitmapDrawable) {
        BitmapDrawable bitmapDrawable = (BitmapDrawable) backgroundDrawable;
        if(bitmapDrawable.getBitmap() != null) {
            sourceBitmap = bitmapDrawable.getBitmap();
        }
    }*/
        //source bitmap was scaled, you should calculate the rate
        float widthRate = ((float) sourceBitmap.getWidth()) / getWidth();
        float heightRate =  ((float) sourceBitmap.getHeight()) / getHeight();

        //crop the source bitmap with rate value
        int left = (int) (mCropRect.left * widthRate);
        int top = (int) (mCropRect.top * heightRate);
        int right = (int) (mCropRect.right * widthRate);
        int bottom = (int) (mCropRect.bottom * heightRate);
        Bitmap croppedBitmap = Bitmap.createBitmap(sourceBitmap, left, top, right - left, bottom - top);
        Drawable drawable = new BitmapDrawable(getResources(), croppedBitmap);
        return drawable;
        /*
        setContentView(R.layout.fragment_dashboard);
        Button btn = (Button)findViewById(R.id.capture);
        if (btn == null){
            System.out.println("NULL");
        }
        try{
            btn.setText("HI");
        }
        catch (Exception e){

        }
        //setBackground(drawable);*/
        //savebitmap(croppedBitmap);
}



private File savebitmap(Bitmap bmp) throws IOException {
    ByteArrayOutputStream bytes = new ByteArrayOutputStream();
    bmp.compress(Bitmap.CompressFormat.JPEG, 60, bytes);
    File f = new File(Environment.getExternalStorageDirectory()
            + "/" + "testimage.jpg");
    Toast.makeText(getContext(), "YUP", Toast.LENGTH_LONG).show();
    f.createNewFile();
    FileOutputStream fo = new FileOutputStream(f);
    fo.write(bytes.toByteArray());
    fo.close();
    return f;
}

public static class ColorBall {

    Bitmap bitmap;
    Context mContext;
    Point point;
    int id;

    public ColorBall(Context context, int resourceId, Point point, int id) {
        this.id = id;
        bitmap = BitmapFactory.decodeResource(context.getResources(),
                resourceId);
        mContext = context;
        this.point = point;
    }

    public int getWidthOfBall() {
        return bitmap.getWidth();
    }

    public int getHeightOfBall() {
        return bitmap.getHeight();
    }

    public Bitmap getBitmap() {
        return bitmap;
    }

    public int getX() {
        return point.x;
    }

    public int getY() {
        return point.y;
    }

    public int getID() {
        return id;
    }

    public void setX(int x) {
        point.x = x;
    }

    public void setY(int y) {
        point.y = y;
    }
}

}

这是我添加相机的片段,基本上是我正在处理的应用程序的主要部分。

public class DashboardFragment extends Fragment {

private DashboardViewModel dashboardViewModel;

//All my constants
private DrawView mDrawView;
private Drawable imgDraw;
private TextureView txtView;
private static final SparseIntArray ORIENTATIONS = new SparseIntArray();

static{
    ORIENTATIONS.append(Surface.ROTATION_0, 90);
    ORIENTATIONS.append(Surface.ROTATION_90, 0);
    ORIENTATIONS.append(Surface.ROTATION_180, 180);
    ORIENTATIONS.append(Surface.ROTATION_270, 180);
}

private String cameraID;
private String pathway;
CameraDevice cameraDevice;
CameraCaptureSession cameraCaptureSession;
CaptureRequest captureRequest;
CaptureRequest.Builder captureRequestBuilder;
private Size imageDimensions;
private ImageReader imageReader;
private File file;
Handler mBackgroundHandler;
HandlerThread mBackgroundThread;

public View onCreateView(@NonNull LayoutInflater inflater,
                         ViewGroup container, Bundle savedInstanceState) {
    dashboardViewModel =
            ViewModelProviders.of(this).get(DashboardViewModel.class);

    View root = inflater.inflate(R.layout.fragment_dashboard, container, false);

    try{
        txtView = (TextureView)root.findViewById(R.id.textureView);
        txtView.setSurfaceTextureListener(textureListener);
        mDrawView = root.findViewById(draw_view);
        Button cap = (Button)root.findViewById(R.id.capture);
        cap.setClickable(true);
        cap.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                try {
                    Log.i("HOLA","HOLA");
                    takePicture();
                } catch (CameraAccessException e) {
                    e.printStackTrace();
                }
            }
        });
    }
    catch (Exception e){
        Log.i("HI",e.toString());
    }
    /*
    txtView = (TextureView)root.findViewById(R.id.textureView);
    txtView.setSurfaceTextureListener(textureListener);
    mDrawView = root.findViewById(R.id.draw_view);
    Button cap = (Button)root.findViewById(R.id.capture);
    cap.setClickable(true);
    cap.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            try {
                Log.i("HOLA","HOLA");
                takePicture();
            } catch (CameraAccessException e) {
                e.printStackTrace();
            }
        }
    });*/
    return root;
}

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults){
    if (requestCode == 101){
        if (grantResults[0] == PackageManager.PERMISSION_DENIED){
            Toast.makeText(getActivity().getApplicationContext(), "Permission is required",Toast.LENGTH_LONG);
        }
    }
}
TextureView.SurfaceTextureListener textureListener = new TextureView.SurfaceTextureListener() {
    @Override
    public void onSurfaceTextureAvailable(SurfaceTexture surfaceTexture, int i, int i1) {

        try {
            openCamera();
        } catch (CameraAccessException e) {
            e.printStackTrace();
        }
    }

    @Override
    public void onSurfaceTextureSizeChanged(SurfaceTexture surfaceTexture, int i, int i1) {

    }

    @Override
    public boolean onSurfaceTextureDestroyed(SurfaceTexture surfaceTexture) {
        return false;
    }

    @Override
    public void onSurfaceTextureUpdated(SurfaceTexture surfaceTexture) {

    }
};

private final CameraDevice.StateCallback stateCallback = new CameraDevice.StateCallback() {
    @Override
    public void onOpened(@NonNull CameraDevice camera) {
        cameraDevice = camera;
        try {
            createCameraPreview();
        } catch (CameraAccessException e) {
            e.printStackTrace();
        }
    }

    @Override
    public void onDisconnected(@NonNull CameraDevice cameraDevice) {
        cameraDevice.close();

    }

    @Override
    public void onError(@NonNull CameraDevice cameraDevice, int i) {
        cameraDevice.close();
        cameraDevice = null;

    }
};

private void createCameraPreview() throws CameraAccessException {
    SurfaceTexture texture = txtView.getSurfaceTexture(); //?
    texture.setDefaultBufferSize(imageDimensions.getWidth(), imageDimensions.getHeight());
    Surface surface = new Surface(texture);
    captureRequestBuilder = cameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW);
    captureRequestBuilder.addTarget(surface);
    cameraDevice.createCaptureSession(Arrays.asList(surface), new CameraCaptureSession.StateCallback() {
        @Override
        public void onConfigured(@NonNull CameraCaptureSession session) {
            if (cameraDevice == null){
                return;
            }
            cameraCaptureSession = session;
            try {
                updatePreview();
            } catch (CameraAccessException e) {
                e.printStackTrace();
            }
        }

        @Override
        public void onConfigureFailed(@NonNull CameraCaptureSession cameraCaptureSession) {
            Toast.makeText(getActivity().getApplicationContext(), "CONFIGURATION", Toast.LENGTH_LONG);
        }
    }, null);
}

private void updatePreview() throws CameraAccessException {
    if (cameraDevice == null){
        return;
    }
    captureRequestBuilder.set(CaptureRequest.CONTROL_MODE, CameraMetadata.CONTROL_MODE_AUTO);
    cameraCaptureSession.setRepeatingRequest(captureRequestBuilder.build(), null, mBackgroundHandler);
}

private void openCamera() throws CameraAccessException {

    CameraManager manager = (CameraManager) getActivity().getSystemService(Context.CAMERA_SERVICE);
    cameraID = manager.getCameraIdList()[0];
    CameraCharacteristics characteristics = manager.getCameraCharacteristics(cameraID);
    StreamConfigurationMap map = characteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
    imageDimensions = map.getOutputSizes(SurfaceTexture.class)[0];
    if (ActivityCompat.checkSelfPermission(getActivity().getApplicationContext(), Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED
            && ActivityCompat.checkSelfPermission(getActivity().getApplicationContext(), Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED){
        ActivityCompat.requestPermissions(getActivity(), new String[]{Manifest.permission.CAMERA, Manifest.permission.WRITE_EXTERNAL_STORAGE}, 101);
        return;
    }
    manager.openCamera(cameraID, stateCallback, null);
}

private void takePicture() throws CameraAccessException {

    if (cameraDevice == null) {
        Log.i("NOt working", "hi");
        return;
    }
    CameraManager manager = (CameraManager) getActivity().getSystemService(Context.CAMERA_SERVICE);
    CameraCharacteristics characteristics = manager.getCameraCharacteristics(cameraDevice.getId());
    Size[] jpegSizes = null;
    jpegSizes = characteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP).getOutputSizes(ImageFormat.JPEG);
    int width = 640;
    int height = 480;
    if (jpegSizes != null && jpegSizes.length > 0) {
        width = jpegSizes[0].getWidth();
        height = jpegSizes[0].getHeight();
    }
    final ImageReader reader = ImageReader.newInstance(width, height, ImageFormat.JPEG, 1);
    List<Surface> outputSurfaces = new ArrayList<>(2);
    outputSurfaces.add(reader.getSurface());
    outputSurfaces.add(new Surface(txtView.getSurfaceTexture()));
    final CaptureRequest.Builder captureBuilder = cameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE);
    captureBuilder.addTarget(reader.getSurface());
    captureBuilder.set(CaptureRequest.CONTROL_MODE, CameraMetadata.CONTROL_MODE_AUTO);
    int rotation = getActivity().getWindowManager().getDefaultDisplay().getRotation();
    captureBuilder.set(CaptureRequest.JPEG_ORIENTATION, ORIENTATIONS.get(rotation));
    Long tsLong = System.currentTimeMillis() / 1000;
    String ts = tsLong.toString();
    file = new File(Environment.getExternalStorageDirectory() + "/" + ts + ".jpg");
    pathway = Environment.getExternalStorageDirectory() + "/" + ts + ".jpg";
    //cameraDevice.close();


    ImageReader.OnImageAvailableListener readerListener = new ImageReader.OnImageAvailableListener() {
        @Override
        public void onImageAvailable(ImageReader imageReader) {
            Image image = null;

            //image = reader.acquireLatestImage();
            image = reader.acquireNextImage();
            ByteBuffer buffer = image.getPlanes()[0].getBuffer();
            byte[] bytes = new byte[buffer.capacity()];
            buffer.get(bytes);
            Bitmap bitmap = BitmapFactory.decodeByteArray(bytes , 0, bytes.length);
            try {
                Drawable back = mDrawView.doTheCrop(bitmap);
                Button btn = (Button)getView().findViewById(R.id.capture);
                btn.setBackground(back);
            } catch (IOException e) {
                e.printStackTrace();
            }
            /*
            try {
                save(bytes);
            } catch (IOException e) {
                e.printStackTrace();
            } finally {
                if (image != null){
                    image.close();
                }

            }*/


        }

    };

    reader.setOnImageAvailableListener(readerListener, mBackgroundHandler);
    final CameraCaptureSession.CaptureCallback captureListener = new CameraCaptureSession.CaptureCallback(){
        @Override
        public void onCaptureCompleted(CameraCaptureSession session, CaptureRequest request, TotalCaptureResult result){
            super.onCaptureCompleted(session, request, result);
            try {
                createCameraPreview();
            } catch (CameraAccessException e) {
                e.printStackTrace();
            }
        }
    };

    cameraDevice.createCaptureSession(outputSurfaces, new CameraCaptureSession.StateCallback() {
        @Override
        public void onConfigured(@NonNull CameraCaptureSession session) {
            try {
                session.capture(captureBuilder.build(), captureListener, mBackgroundHandler);
            } catch (CameraAccessException e) {
                e.printStackTrace();
            }
        }

        @Override
        public void onConfigureFailed(@NonNull CameraCaptureSession cameraCaptureSession) {

        }
    }, mBackgroundHandler);

}

private void save (byte[] bytes) throws IOException {

    OutputStream outputStream = null;
    outputStream = new FileOutputStream(file);
    outputStream.write(bytes);
    Toast.makeText(getActivity().getApplicationContext(),pathway,Toast.LENGTH_LONG).show();
    outputStream.close();

    imgDraw = Drawable.createFromPath(pathway);
    //mDrawView.doTheCrop(imgDraw);
}


@Override
public void onResume(){
    super.onResume();

    startBackgroundThread();
    if (txtView.isAvailable()){
        try {
            openCamera();
        } catch (CameraAccessException e) {
            e.printStackTrace();
        }
    }
    else{
        txtView.setSurfaceTextureListener(textureListener);
    }
}

private void startBackgroundThread() {

    mBackgroundThread = new HandlerThread("Camera Background");
    mBackgroundThread.start();
    mBackgroundHandler = new Handler(mBackgroundThread.getLooper());
}

protected void stopBackgroundThread() throws InterruptedException{
    mBackgroundThread.quitSafely();
    mBackgroundThread.join();
    mBackgroundThread = null;
    mBackgroundHandler = null;
}

@Override
public void onPause(){
    try {
        stopBackgroundThread();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    super.onPause();
}

}

这是该片段的 xml 文件。

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.dashboard.DashboardFragment">

<TextureView
    android:id = "@+id/textureView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>

<com.PeavlerDevelopment.OpinionMinion.ui.dashboard.DrawView
    android:id="@+id/draw_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>

<Button
    android:id="@+id/capture"
    android:layout_width="100dp"
    android:layout_height="200dp"
    android:clickable="true"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintLeft_toLeftOf="parent"></Button>



</androidx.constraintlayout.widget.ConstraintLayout>

问题似乎出在 DrawView 类的 doCrop 方法中。

如果还有其他可以帮助使问题更清楚的方法,请告诉我!我很乐意与您分享 github 存储库。

谢谢你。

标签: javaandroid

解决方案


正如您在Android 设计文档中看到的那样,VINTF 代表供应商接口,它是一种用于从设备聚合数据的清单结构。该特定日志意味着您的清单缺少如下内容:

     <hal>
        <name>android.hardware.power</name>
        <transport>hwbinder</transport>
        <version>1.1</version>
        <interface>
            <name>IPower</name>
            <instance>default</instance>
        </interface>
     </hal>

这基本上是硬件电源信息。我认为这与您尝试做的事情无关,但我需要比该日志更多的信息。


推荐阅读