当前位置: 首页>>代码示例>>Java>>正文


Java SurfaceView.getLayoutParams方法代码示例

本文整理汇总了Java中android.view.SurfaceView.getLayoutParams方法的典型用法代码示例。如果您正苦于以下问题:Java SurfaceView.getLayoutParams方法的具体用法?Java SurfaceView.getLayoutParams怎么用?Java SurfaceView.getLayoutParams使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.view.SurfaceView的用法示例。


在下文中一共展示了SurfaceView.getLayoutParams方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: start

import android.view.SurfaceView; //导入方法依赖的package包/类
private void start(final boolean isCamera) {
    Log.d("ImageTakin", "StartCommand()");
    pref = getApplicationContext().getSharedPreferences("MyPref", 0);
    editor = pref.edit();
    if (mCamera != null) {
        queue.removeCallbacks(null);
        mCamera.setPreviewCallback(null);
        mCamera.stopPreview();
        mCamera.release();
        mCamera = Camera.open();
    } else
        mCamera = getCameraInstance();
    parameters = mCamera.getParameters();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH && parameters.getSupportedFocusModes().contains(
            Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE)) {
        parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE);
    } else if (parameters.getSupportedFocusModes().contains(
            Camera.Parameters.FOCUS_MODE_AUTO)) {
        parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO);
    }
    mCamera.setParameters(parameters);
    size = parameters.getPreviewSize();
    if (registeredShieldsIDs.contains(UIShield.COLOR_DETECTION_SHIELD.name()))
        mCamera.setPreviewCallback(previewCallback);
    windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);

    params = new WindowManager.LayoutParams(
            WindowManager.LayoutParams.MATCH_PARENT,
            WindowManager.LayoutParams.MATCH_PARENT,
            WindowManager.LayoutParams.TYPE_PRIORITY_PHONE, WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
            PixelFormat.RGBX_8888);
    params.gravity = Gravity.TOP | Gravity.LEFT;
    DisplayMetrics metrics = new DisplayMetrics();
    windowManager.getDefaultDisplay().getMetrics(metrics);
    int expectedHeight = metrics.heightPixels - ((int) (250 * metrics.density + .5f));
    int expectedWidth = ((expectedHeight * (size == null ? metrics.widthPixels : size.height)) / (size == null ? metrics.heightPixels : size.width));
    params.width = 1;// metrics.widthPixels - ((int) (60 * metrics.density + .5f));
    params.height = 1;
    params.x = (int) ((metrics.widthPixels / 2) - expectedWidth / 2);
    params.y = (int) (150 * metrics.density + .5f);
    params.alpha = 1;
    sv = new SurfaceView(getApplicationContext());
    windowManager.addView(sv, params);
    params = (WindowManager.LayoutParams) sv.getLayoutParams();
    sHolder = sv.getHolder();
    sHolder.addCallback(this);

    mOrientationEventListener = new OrientationEventListener(this,
            SensorManager.SENSOR_DELAY_NORMAL) {

        @Override
        public void onOrientationChanged(int orientation) {
            if (orientation == ORIENTATION_UNKNOWN) return;

            mOrientation = (orientation + 45) / 90 * 90;
        }
    };
    if (mOrientationEventListener.canDetectOrientation()) {
        mOrientationEventListener.enable();
    }
    // tells Android that this surface will have its data constantly
    // replaced
    if (Build.VERSION.SDK_INT < 11)
        sHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
}
 
开发者ID:Dnet3,项目名称:CustomAndroidOneSheeld,代码行数:66,代码来源:CameraHeadService.java


注:本文中的android.view.SurfaceView.getLayoutParams方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。