android.view.SurfaceView#getHolder ( )源码实例Demo

下面列出了android.view.SurfaceView#getHolder ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: moVirt   文件: CameraActivity.java
@Override
protected void onPause() {
    if (handler != null) {
        handler.quitSynchronously();
        handler = null;
    }
    cameraManager.closeDriver();
    beepManager.close();
    inactivityTimer.onPause();
    ambientLightManager.stop();
    if (!hasSurface) {
        SurfaceView surfaceView = (SurfaceView) findViewById(R.id.camera_preview);
        SurfaceHolder surfaceHolder = surfaceView.getHolder();
        surfaceHolder.removeCallback(this);
    }
    super.onPause();
}
 
源代码2 项目: CameraV   文件: VideoViewerActivity.java
/**
* 
* Called when the activity is first created.
*/
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);

//prevent screenshots
		getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE,
				WindowManager.LayoutParams.FLAG_SECURE);
		
		
setContentView(R.layout.videoview);
mPreview = (SurfaceView) findViewById(R.id.surface_video);
holder = mPreview.getHolder();
holder.addCallback(this);
holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
extras = getIntent().getExtras();

}
 
源代码3 项目: CameraV   文件: SurfaceGrabberActivity.java
@SuppressWarnings("deprecation")
@Override
public void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(getLayout());

	button = (Button) findViewById(R.id.surface_grabber_button);
	button.setOnClickListener(this);
	
	progress = (TextView) findViewById(R.id.surface_grabber_progress);
	progress.setText(String.valueOf(baseImages.size()));

	view = (SurfaceView) findViewById(R.id.surface_grabber_holder);
	view.setOnClickListener(this);
	
	holder = view.getHolder();
	holder.addCallback(this);
	holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);		
}
 
源代码4 项目: vinci   文件: CaptureFragment.java
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

    Bundle bundle = getArguments();
    View view = null;
    if (bundle != null) {
        int layoutId = bundle.getInt(CodeUtils.LAYOUT_ID);
        if (layoutId != -1) {
            view = inflater.inflate(layoutId, null);
        }
    }

    if (view == null) {
        view = inflater.inflate(R.layout.vinci_frag_capture, null);
    }

    viewfinderView = (ViewfinderView) view.findViewById(R.id.viewfinder_view);
    surfaceView = (SurfaceView) view.findViewById(R.id.preview_view);
    surfaceHolder = surfaceView.getHolder();

    return view;
}
 
源代码5 项目: weex   文件: CaptureActivity.java
@Override
protected void onPause() {
	if (handler != null) {
		handler.quitSynchronously();
		handler = null;
	}
	inactivityTimer.onPause();
	ambientLightManager.stop();
	beepManager.close();
	cameraManager.closeDriver();
	// historyManager = null; // Keep for onActivityResult
	if (!hasSurface) {
		SurfaceView surfaceView = (SurfaceView) findViewById(R.id.preview_view);
		SurfaceHolder surfaceHolder = surfaceView.getHolder();
		surfaceHolder.removeCallback(this);
	}
	super.onPause();
}
 
源代码6 项目: AndroidWebServ   文件: CaptureActivity.java
@Override
protected void onPause() {
    if (handler != null) {
        handler.quitSynchronously();
        handler = null;
    }
    inactivityTimer.onPause();
    ambientLightManager.stop();
    cameraManager.closeDriver();
    if (!hasSurface) {
        SurfaceView surfaceView = (SurfaceView) findViewById(R.id.preview_view);
        SurfaceHolder surfaceHolder = surfaceView.getHolder();
        surfaceHolder.removeCallback(this);
    }
    super.onPause();
}
 
源代码7 项目: media-samples   文件: OverlayDisplayWindow.java
@Override
public void show() {
    if (!mWindowVisible) {
        mSurfaceView = new SurfaceView(mContext);

        Display display = mWindowManager.getDefaultDisplay();

        WindowManager.LayoutParams params = new WindowManager.LayoutParams(
                WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
        params.flags |= WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
                | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS
                | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
                | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
                | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
        params.alpha = WINDOW_ALPHA;
        params.gravity = Gravity.LEFT | Gravity.BOTTOM;
        params.setTitle(mName);

        int width = (int)(display.getWidth() * INITIAL_SCALE);
        int height = (int)(display.getHeight() * INITIAL_SCALE);
        if (mWidth > mHeight) {
            height = mHeight * width / mWidth;
        } else {
            width = mWidth * height / mHeight;
        }
        params.width = width;
        params.height = height;

        mWindowManager.addView(mSurfaceView, params);
        mWindowVisible = true;

        SurfaceHolder holder = mSurfaceView.getHolder();
        holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
        mListener.onWindowCreated(holder);
    }
}
 
源代码8 项目: droidel   文件: MainActivity.java
@Override
   protected void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.main);
mSurfaceView = (SurfaceView) findViewById(R.id.mySurfaceView);
mSurfaceHolder = mSurfaceView.getHolder();
mController = new Controller(this);
   }
 
private void init(Context context) {
  SurfaceView surfaceView = new SurfaceView(context);
  addView(surfaceView);
  surfaceHolder = surfaceView.getHolder();
  surfaceHolder.addCallback(new SurfaceHolderCallback());
  surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
  bufferingPreviewCallback = new BufferingPreviewCallback();
}
 
源代码10 项目: BluetoothCameraAndroid   文件: CameraActivity.java
@Override
public void initViews() {
    mSurfaceView = (SurfaceView) findViewById(R.id.activity_camera_surface);
    mSurfaceHolder = mSurfaceView.getHolder();
    mSurfaceHolder.addCallback(this);
    mSurfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);

    mRecordbutton = findViewById(R.id.record);
    mRecordbutton.setOnClickListener(this);

    findViewById(R.id.camera).setOnClickListener(this);
}
 
源代码11 项目: barterli_android   文件: ScanIsbnActivity.java
/**
 * Initialize the camera and start scanning for a barcode
 */
private void startScanningForBarcode() {
    // CameraManager must be initialized here, not in onCreate().
    if (mCameraManager == null) {
        mCameraManager = new CameraManager(getApplication());
    }

    if (mViewFinderView == null) {
        mViewFinderView = (ViewfinderView) findViewById(R.id.viewfinder_view);
        mViewFinderView.setCameraManager(mCameraManager);
    }

    showScanner();

    final SurfaceView surfaceView = (SurfaceView) findViewById(R.id.preview_view);
    final SurfaceHolder surfaceHolder = surfaceView.getHolder();
    if (mHasSurface) {
        // The activity was paused but not stopped, so the surface still
        // exists. Therefore
        // surfaceCreated() won't be called, so init the camera here.
        initCamera(surfaceHolder);
    } else {
        // Install the callback and wait for surfaceCreated() to init the
        // camera.
        surfaceHolder.addCallback(this);
    }

}
 
源代码12 项目: android-MediaRouter   文件: LocalPlayer.java
@Override
protected void onCreate(Bundle savedInstanceState) {
    // Be sure to call the super class.
    super.onCreate(savedInstanceState);

    // Inflate the layout.
    setContentView(R.layout.sample_media_router_presentation);

    // Set up the surface view.
    mPresentationSurfaceView = (SurfaceView)findViewById(R.id.surface_view);
    SurfaceHolder holder = mPresentationSurfaceView.getHolder();
    holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
    holder.addCallback(SurfaceViewPlayer.this);
    Log.i(TAG, "Presentation created");
}
 
源代码13 项目: Smartlab   文件: MainActivity.java
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.activity_main);

	surfaceView = (SurfaceView) findViewById(R.id.surfaceView1);
	surfaceHolder = surfaceView.getHolder();
	surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
	surfaceHolder.addCallback(this);
}
 
源代码14 项目: GreenBits   文件: ScanActivity.java
@Override
protected void onResume()
{
    super.onResume();

    cameraThread = new HandlerThread("cameraThread", Process.THREAD_PRIORITY_BACKGROUND);
    cameraThread.start();
    cameraHandler = new Handler(cameraThread.getLooper());

    final SurfaceView surfaceView = (SurfaceView) findViewById(R.id.scan_activity_preview);
    surfaceHolder = surfaceView.getHolder();
    surfaceHolder.addCallback(this);
    surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
}
 
源代码15 项目: augmentedreality   文件: MainActivity.java
@Override
protected void onCreate(Bundle savedInstanceState) {
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    //display setup stuff
    tv_alt = (TextView) findViewById(R.id.altitudeValue);
    tv_lat = (TextView) findViewById(R.id.latitudeValue);
    tv_long = (TextView) findViewById(R.id.longitudeValue);

    tv_head = (TextView) findViewById(R.id.headingValue);
    tv_pitch = (TextView) findViewById(R.id.pitchValue);
    tv_roll = (TextView) findViewById(R.id.rollValue);

    tv_x = (TextView) findViewById(R.id.xAxisValue);
    tv_y = (TextView) findViewById(R.id.yAxisValue);
    tv_z = (TextView) findViewById(R.id.zAxisValue);

    //we need the sensor manager and the gps manager, the
    //registration is all in onpause and onresume;
    mgr = (SensorManager) this.getSystemService(SENSOR_SERVICE);
    //orientation
    orient = mgr.getDefaultSensor(Sensor.TYPE_ORIENTATION);
    //acceleraometer
    accel = mgr.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
    //gps location information
    myL = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    //setup the location listener.


    //all the camera preivew information
    inPreview = false;
    cameraPreview = (SurfaceView) findViewById(R.id.cameraPreview);
    previewHolder = cameraPreview.getHolder();
    previewHolder.addCallback(this);
    previewHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);

}
 
源代码16 项目: Vitamio-Cordova-Plugin   文件: VitamioMedia.java
@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    if (!io.vov.vitamio.LibsChecker.checkVitamioLibs(this))
        return;

    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    extras = getIntent().getExtras();

    // handle extras
    if (extras == null) {
        wrapItUp(RESULT_CANCELED, "Error: No options provided");
    } else {
        if (extras.containsKey("isStreaming")) {
           isStreaming = extras.getBoolean("isStreaming");
        }

        if (extras.containsKey("shouldAutoClose")) {
            mShouldAutoClose = extras.getBoolean("shouldAutoClose");
        }

        mMediaType = extras.getString("type");
        if (mMediaType == null) mMediaType = MEDIA_TYPE_VIDEO;

        mMediaPlayer = new MediaPlayer(this);
        mMediaController = new MediaController(this, !isStreaming);
        mMediaController.setMediaPlayer(this);
        mMediaPlayer.setOnBufferingUpdateListener(this);
        mMediaPlayer.setOnCompletionListener(this);
        mMediaPlayer.setOnErrorListener(this);
        mMediaPlayer.setOnPreparedListener(this);
        mMediaPlayer.setOnVideoSizeChangedListener(this);
        setVolumeControlStream(AudioManager.STREAM_MUSIC);

        RelativeLayout relLayout = new RelativeLayout(this);

        if (extras.containsKey("bgColor")) {
            try {
                bgColor = Color.parseColor(extras.getString("bgColor"));
            } catch (Exception e) {
                Log.v(TAG, "Error parsing color");
                Log.e(TAG, e.toString());
                bgColor = DEFAULT_BG_COLOR;
            }
        }
        relLayout.setBackgroundColor(bgColor);

        RelativeLayout.LayoutParams relLayoutParam = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT);
        relLayoutParam.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);
        mMediaView = new SurfaceView(this);
        mMediaView.setLayoutParams(relLayoutParam);
        relLayout.addView(mMediaView);

        mProgressBar = new ProgressBar(this);
        mProgressBar.setIndeterminate(true);
        mProgressBar.setVisibility(View.VISIBLE);
        RelativeLayout.LayoutParams pblp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
        pblp.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);
        mProgressBar.setLayoutParams(pblp);
        relLayout.addView(mProgressBar);
        mProgressBar.bringToFront();

        mMediaController.setAnchorView(relLayout);
        mMediaController.setEnabled(true);
        if (mMediaType.equalsIgnoreCase(MEDIA_TYPE_AUDIO)) {
            mMediaView.setBackgroundColor(bgColor);
            if (extras.containsKey("bgImage")) {
                if (extras.containsKey("bgImageScaleType")) {
                    String scaleType = extras.getString("bgImageScaleType");
                    if (scaleType.equalsIgnoreCase("fit")) {
                        bgImageScaleType = ImageView.ScaleType.FIT_CENTER;
                    } else if (scaleType.equalsIgnoreCase("stretch")) {
                        bgImageScaleType = ImageView.ScaleType.FIT_XY;
                    } else {
                        bgImageScaleType = ImageView.ScaleType.CENTER;
                    }
                }
                bgImage = new ImageView(this);
                new ImageLoadTask(extras.getString("bgImage"), this).execute(null, null);
                RelativeLayout.LayoutParams bgImageLayoutParam = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT);
                bgImageLayoutParam.addRule(RelativeLayout.CENTER_IN_PARENT);
                bgImage.setLayoutParams(bgImageLayoutParam);
                bgImage.setScaleType(bgImageScaleType);
                relLayout.addView(bgImage);
            }
        }
        setContentView(relLayout, relLayoutParam);
        holder = mMediaView.getHolder();
        holder.addCallback(this);
        holder.setFormat(PixelFormat.RGBA_8888);
    }
}
 
源代码17 项目: android-apps   文件: CaptureActivity.java
@Override
protected void onResume() {
  super.onResume();

  // CameraManager must be initialized here, not in onCreate(). This is necessary because we don't
  // want to open the camera driver and measure the screen size if we're going to show the help on
  // first launch. That led to bugs where the scanning rectangle was the wrong size and partially
  // off screen.
  cameraManager = new CameraManager(getApplication());

  viewfinderView = (ViewfinderView) findViewById(R.id.viewfinder_view);
  viewfinderView.setCameraManager(cameraManager);

  resultView = findViewById(R.id.result_view);
  statusView = (TextView) findViewById(R.id.status_view);

  handler = null;
  lastResult = null;

  resetStatusView();

  SurfaceView surfaceView = (SurfaceView) findViewById(R.id.preview_view);
  SurfaceHolder surfaceHolder = surfaceView.getHolder();
  if (hasSurface) {
    // The activity was paused but not stopped, so the surface still exists. Therefore
    // surfaceCreated() won't be called, so init the camera here.
    initCamera(surfaceHolder);
  } else {
    // Install the callback and wait for surfaceCreated() to init the camera.
    surfaceHolder.addCallback(this);
    surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
  }

  beepManager.updatePrefs();

  inactivityTimer.onResume();

  Intent intent = getIntent();

  SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
  copyToClipboard = prefs.getBoolean(PreferencesActivity.KEY_COPY_TO_CLIPBOARD, true)
      && (intent == null || intent.getBooleanExtra(Intents.Scan.SAVE_HISTORY, true));

  source = IntentSource.NONE;
  decodeFormats = null;
  characterSet = null;

  if (intent != null) {

    String action = intent.getAction();
    String dataString = intent.getDataString();

    if (Intents.Scan.ACTION.equals(action)) {

      // Scan the formats the intent requested, and return the result to the calling activity.
      source = IntentSource.NATIVE_APP_INTENT;
      decodeFormats = DecodeFormatManager.parseDecodeFormats(intent);

      if (intent.hasExtra(Intents.Scan.WIDTH) && intent.hasExtra(Intents.Scan.HEIGHT)) {
        int width = intent.getIntExtra(Intents.Scan.WIDTH, 0);
        int height = intent.getIntExtra(Intents.Scan.HEIGHT, 0);
        if (width > 0 && height > 0) {
          cameraManager.setManualFramingRect(width, height);
        }
      }
      
      String customPromptMessage = intent.getStringExtra(Intents.Scan.PROMPT_MESSAGE);
      if (customPromptMessage != null) {
        statusView.setText(customPromptMessage);
      }

    } else if (dataString != null &&
               dataString.contains(PRODUCT_SEARCH_URL_PREFIX) &&
               dataString.contains(PRODUCT_SEARCH_URL_SUFFIX)) {

      // Scan only products and send the result to mobile Product Search.
      source = IntentSource.PRODUCT_SEARCH_LINK;
      sourceUrl = dataString;
      decodeFormats = DecodeFormatManager.PRODUCT_FORMATS;

    } else if (isZXingURL(dataString)) {

      // Scan formats requested in query string (all formats if none specified).
      // If a return URL is specified, send the results there. Otherwise, handle it ourselves.
      source = IntentSource.ZXING_LINK;
      sourceUrl = dataString;
      Uri inputUri = Uri.parse(sourceUrl);
      returnUrlTemplate = inputUri.getQueryParameter(RETURN_URL_PARAM);
      decodeFormats = DecodeFormatManager.parseDecodeFormats(inputUri);

    }

    characterSet = intent.getStringExtra(Intents.Scan.CHARACTER_SET);

  }
}
 
源代码18 项目: CodeScaner   文件: CaptureActivity.java
@Override
protected void onResume() {
    super.onResume();

    // historyManager must be initialized here to update the history preference

    // CameraManager must be initialized here, not in onCreate(). This is necessary because
    // we don't
    // want to open the camera driver and measure the screen size if we're going to show the
    // help on
    // first launch. That led to bugs where the scanning rectangle was the wrong size and
    // partially
    // off screen.
    cameraManager = new CameraManager(getApplication());

    viewfinderView = (ViewfinderView) findViewById(R.id.viewfinder_view);
    viewfinderView.setCameraManager(cameraManager);

    handler = null;

    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT);

    beepManager.updatePrefs();
    ambientLightManager.start(cameraManager);

    inactivityTimer.onResume();

    decodeFormats = EnumSet.noneOf(BarcodeFormat.class);
    decodeFormats.addAll(DecodeFormatManager.QR_CODE_FORMATS);
    decodeFormats.addAll(DecodeFormatManager.ONE_D_FORMATS);
    characterSet = null;

    SurfaceView surfaceView = (SurfaceView) findViewById(R.id.preview_view);
    SurfaceHolder surfaceHolder = surfaceView.getHolder();
    if (hasSurface) {
        // The activity was paused but not stopped, so the surface still exists. Therefore
        // surfaceCreated() won't be called, so init the camera here.
        initCamera(surfaceHolder);
    } else {
        // Install the callback and wait for surfaceCreated() to init the camera.
        surfaceHolder.addCallback(this);
    }
}
 
源代码19 项目: webrtc-app-mono   文件: ViESurfaceRenderer.java
public ViESurfaceRenderer(SurfaceView view) {
    surfaceHolder = view.getHolder();
    if(surfaceHolder == null)
        return;
    surfaceHolder.addCallback(this);
}
 
Renderer(SurfaceView sh){
    mSurfaceHolder = sh.getHolder();
    mPaint = new Paint();
}