List of usage examples for android.view SurfaceView SurfaceView
public SurfaceView(Context context)
From source file:at.andreasrohner.spartantimelapserec.BackgroundService.java
@SuppressWarnings("deprecation") @Override//w ww .j av a2 s . c o m public void onCreate() { created = true; settings = new RecSettings(); settings.load(getApplicationContext(), PreferenceManager.getDefaultSharedPreferences(getApplicationContext())); createNotification(NOTIFICATION_ID); if (settings.isSchedRecEnabled() && settings.getSchedRecTime() > System.currentTimeMillis() + 10000) { AlarmManager alarmMgr = (AlarmManager) getSystemService(Context.ALARM_SERVICE); Intent intent = new Intent(getApplicationContext(), ScheduleReceiver.class); PendingIntent alarmIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, intent, 0); alarmMgr.set(AlarmManager.RTC_WAKEUP, settings.getSchedRecTime(), alarmIntent); stopSelf(); return; } // Create new SurfaceView, set its size to 1x1, move // it to the top left corner and set this service as a callback WindowManager winMgr = (WindowManager) getSystemService(Context.WINDOW_SERVICE); surfaceView = new SurfaceView(this); // deprecated setting, but required on Android versions prior to 3.0 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) surfaceView.getHolder().setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); surfaceView.getHolder().addCallback(this); LayoutParams layoutParams = new WindowManager.LayoutParams(1, 1, WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY, WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH, PixelFormat.TRANSLUCENT); layoutParams.gravity = Gravity.LEFT | Gravity.TOP; winMgr.addView(surfaceView, layoutParams); PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE); wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG); wakeLock.setReferenceCounted(false); wakeLock.acquire(); }
From source file:com.googlecode.android_scripting.facade.CameraFacade.java
private FutureActivityTask<SurfaceHolder> setPreviewDisplay(Camera camera) throws IOException, InterruptedException { FutureActivityTask<SurfaceHolder> task = new FutureActivityTask<SurfaceHolder>() { @Override/*www.ja v a2s.c o m*/ public void onCreate() { super.onCreate(); final SurfaceView view = new SurfaceView(getActivity()); getActivity().setContentView(view); getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_UNCHANGED); view.getHolder().setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); view.getHolder().addCallback(new Callback() { @Override public void surfaceDestroyed(SurfaceHolder holder) { } @Override public void surfaceCreated(SurfaceHolder holder) { setResult(view.getHolder()); } @Override public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { } }); } }; FutureActivityTaskExecutor taskQueue = ((BaseApplication) mService.getApplication()).getTaskExecutor(); taskQueue.execute(task); camera.setPreviewDisplay(task.getResult()); return task; }
From source file:com.actionbarsherlock.sample.hcgallery.CameraFragment.java
Preview(Context context) { super(context); mSurfaceView = new SurfaceView(context); addView(mSurfaceView);/*www .java2s .c o m*/ // Install a SurfaceHolder.Callback so we get notified when the // underlying surface is created and destroyed. mHolder = mSurfaceView.getHolder(); mHolder.addCallback(this); mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); }
From source file:hcm.ssj.creator.main.TabHandler.java
/** * Add or remove additional tabs//from ww w . j a v a2s . c om */ private void checkAdditionalTabs() { Object[] consumers = Linker.getInstance().getAll(Linker.Type.Consumer); int counterAnno = 0; //add additional tabs for (Object object : consumers) { //annotation if (object instanceof IFileWriter) { counterAnno++; if (!annotationExists) { annotationExists = true; annotation = new Annotation(this.activity); addTabAnno(annotation.getView(), annotation.getTitle(), annotation.getIcon()); } } //signals else if (object instanceof SignalPainter) { GraphView graphView = ((SignalPainter) object).options.graphView.get(); if (graphView == null) { graphView = new GraphView(activity); ((SignalPainter) object).options.graphView.set(graphView); addTab(graphView, ((SignalPainter) object).getComponentName(), android.R.drawable.ic_menu_view); alAdditionalTabs.add(object); } } //camera else if (object instanceof CameraPainter) { SurfaceView surfaceView = ((CameraPainter) object).options.surfaceView.get(); if (surfaceView == null) { surfaceView = new SurfaceView(activity); ((CameraPainter) object).options.surfaceView.set(surfaceView); addTab(surfaceView, ((CameraPainter) object).getComponentName(), android.R.drawable.ic_menu_camera); alAdditionalTabs.add(object); } } } //remove obsolete tabs //remove annotation if (counterAnno <= 0 && annotationExists) { annotationExists = false; removeTab(FIX_TAB_NUMBER); } //remove signal and camera List list = Arrays.asList(consumers); for (int i = alAdditionalTabs.size() - 1; i >= 0; i--) { if (!list.contains(alAdditionalTabs.get(i))) { alAdditionalTabs.remove(i); removeTab(i + FIX_TAB_NUMBER + (annotationExists ? 1 : 0)); } } }
From source file:im.ene.toro.exoplayer2.ExoVideoView.java
public ExoVideoView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); // By default, TextureView is used for Android 23 and below, and SurfaceView is for the rest boolean useTextureView = context.getResources().getBoolean(R.bool.use_texture_view); if (attrs != null) { TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.ExoVideoView, 0, 0); try {// w ww . j av a2s. c o m int surfaceType = a.getInt(R.styleable.ExoVideoView_tx2_surfaceType, SURFACE_TYPE_DEFAULT); switch (surfaceType) { case SURFACE_TYPE_SURFACE_VIEW: useTextureView = false; break; case SURFACE_TYPE_TEXTURE_VIEW: useTextureView = true; break; case SURFACE_TYPE_DEFAULT: default: // Unchanged, so don't need to execute the line below // useTextureView = context.getResources().getBoolean(R.bool.use_texture_view); break; } resizeMode = a.getInt(R.styleable.ExoVideoView_tx2_resizeMode, RESIZE_MODE_FIXED_WIDTH); } finally { a.recycle(); } } View view = useTextureView ? new TextureView(context) : new SurfaceView(context); ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); view.setLayoutParams(params); surfaceView = view; addView(surfaceView, 0); shutterView = new View(context); ViewGroup.LayoutParams shutterViewParams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); shutterView.setLayoutParams(shutterViewParams); shutterView.setBackgroundColor(Color.BLACK); addView(shutterView); window = new Timeline.Window(); componentListener = new ComponentListener(); mediaDataSourceFactory = buildDataSourceFactory(true); mainHandler = new Handler(); if (CookieHandler.getDefault() != DEFAULT_COOKIE_MANAGER) { CookieHandler.setDefault(DEFAULT_COOKIE_MANAGER); } requestFocus(); }
From source file:com.TaxiDriver.jy.CameraPreview.java
Preview(Context context) { super(context); mSurfaceView = new SurfaceView(context); snap = new Button(context); addView(mSurfaceView);/*from w w w . j a va 2 s . co m*/ // Install a SurfaceHolder.Callback so we get notified when the // underlying surface is created and destroyed. mHolder = mSurfaceView.getHolder(); mHolder.addCallback(this); mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); }
From source file:net.nanocosmos.bintu.demo.encoder.activities.StreamActivity.java
@Override public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) { Surface foo = new Surface(surface); SurfaceView foo1 = new SurfaceView(this); foo = foo1.getHolder().getSurface(); GLSurfaceView foo2 = new GLSurfaceView(this); foo = foo2.getHolder().getSurface(); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { initStreamLib();/* w w w . j a va 2 s .c om*/ } else { appPermissions = new CheckAppPermissions(this); boolean needPermission = false; if (streamVideo) { needPermission |= !appPermissions.checkCameraPermissions(); } if (streamAudio) { needPermission |= !appPermissions.checkRecordAudioPermission(); } if (recordMp4) { needPermission |= !appPermissions.checkWriteExternalStoragePermission(); } if (needPermission) { appPermissions.requestMissingPermissions(); } else { initStreamLib(); } } }
From source file:com.almalence.opencam.ApplicationScreen.java
public static boolean setSurfaceHolderSize(int width, int height) { if (instance.surfaceWidth != width && instance.surfaceHeight != height) { if (instance.surfaceWidth != 0 && instance.surfaceHeight != 0) { // We can't change size of surfaceHolder. That's why, we replace the preview View with new one. ((RelativeLayout) ApplicationScreen.instance.findViewById(R.id.mainLayout2)) .removeView(ApplicationScreen.instance.preview); ApplicationScreen.instance.preview = new SurfaceView(ApplicationScreen.instance); ApplicationScreen.instance.surfaceHolder = ApplicationScreen.instance.preview.getHolder(); ApplicationScreen.instance.surfaceHolder.addCallback(ApplicationScreen.instance); ApplicationScreen.instance.preview.setVisibility(View.VISIBLE); ApplicationScreen.instance.preview.setOnClickListener(ApplicationScreen.instance); ApplicationScreen.instance.preview.setOnTouchListener(ApplicationScreen.instance); ApplicationScreen.instance.preview.setKeepScreenOn(true); ApplicationScreen.instance.preview.setId(R.id.SurfaceView01); ((RelativeLayout) ApplicationScreen.instance.findViewById(R.id.mainLayout2)) .addView(ApplicationScreen.instance.preview, 0); }/*from w ww . j av a 2 s.co m*/ if (ApplicationScreen.instance.surfaceHolder != null) { instance.surfaceWidth = width; instance.surfaceHeight = height; instance.mCameraSurface = null; instance.surfaceHolder.setFixedSize(width, height); } if (instance.glView != null) { if (instance.glView.getSurfaceTexture() != null) { instance.glView.getSurfaceTexture().setDefaultBufferSize(width, height); } } return true; } return false; }
From source file:org.mozilla.gecko.GeckoApp.java
private void initialize() { mInitialized = true;//ww w . ja va 2s. c o m Intent intent = getIntent(); String args = intent.getStringExtra("args"); if (args != null && args.contains("-profile")) { Pattern p = Pattern.compile("(?:-profile\\s*)(\\w*)(\\s*)"); Matcher m = p.matcher(args); if (m.find()) { mProfile = GeckoProfile.get(this, m.group(1)); mLastTitle = null; mLastViewport = null; mLastScreen = null; } } if (ACTION_UPDATE.equals(intent.getAction()) || args != null && args.contains("-alert update-app")) { Log.i(LOGTAG, "onCreate: Update request"); checkAndLaunchUpdate(); } mBrowserToolbar.init(); mBrowserToolbar.setTitle(mLastTitle); String passedUri = null; String uri = getURIFromIntent(intent); if (uri != null && uri.length() > 0) passedUri = mLastTitle = uri; if (passedUri == null || passedUri.equals("about:home")) { // show about:home if we aren't restoring previous session if (!getProfile().hasSession()) { mBrowserToolbar.updateTabCount(1); showAboutHome(); } } else { mBrowserToolbar.updateTabCount(1); } if (sGREDir == null) sGREDir = new File(this.getApplicationInfo().dataDir); Uri data = intent.getData(); if (data != null && "http".equals(data.getScheme()) && isHostOnPrefetchWhitelist(data.getHost())) { Intent copy = new Intent(intent); copy.setAction(ACTION_LOAD); GeckoAppShell.getHandler().post(new RedirectorRunnable(copy)); // We're going to handle this uri with the redirector, so setting // the action to MAIN and clearing the uri data prevents us from // loading it twice intent.setAction(Intent.ACTION_MAIN); intent.setData(null); passedUri = null; } sGeckoThread = new GeckoThread(intent, passedUri, mRestoreSession); if (!ACTION_DEBUG.equals(intent.getAction()) && checkAndSetLaunchState(LaunchState.Launching, LaunchState.Launched)) sGeckoThread.start(); mFavicons = new Favicons(this); Tabs.getInstance().setContentResolver(getContentResolver()); if (cameraView == null) { cameraView = new SurfaceView(this); cameraView.getHolder().setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); } if (mLayerController == null) { /* * Create a layer client so that Gecko will have a buffer to draw into, but don't hook * it up to the layer controller yet. */ mSoftwareLayerClient = new GeckoSoftwareLayerClient(this); /* * Hook a placeholder layer client up to the layer controller so that the user can pan * and zoom a cached screenshot of the previous page. This call will return null if * there is no cached screenshot; in that case, we have no choice but to display a * checkerboard. * * TODO: Fall back to a built-in screenshot of the Fennec Start page for a nice first- * run experience, perhaps? */ mLayerController = new LayerController(this); mPlaceholderLayerClient = PlaceholderLayerClient.createInstance(this); mLayerController.setLayerClient(mPlaceholderLayerClient); mGeckoLayout.addView(mLayerController.getView(), 0); } mPluginContainer = (AbsoluteLayout) findViewById(R.id.plugin_container); mDoorHangerPopup = new DoorHangerPopup(this); mAutoCompletePopup = (AutoCompletePopup) findViewById(R.id.autocomplete_popup); Log.w(LOGTAG, "zerdatime " + SystemClock.uptimeMillis() + " - UI almost up"); if (!sTryCatchAttached) { sTryCatchAttached = true; mMainHandler.post(new Runnable() { public void run() { try { Looper.loop(); } catch (Exception e) { GeckoAppShell.reportJavaCrash(e); } // resetting this is kinda pointless, but oh well sTryCatchAttached = false; } }); } //register for events GeckoAppShell.registerGeckoEventListener("DOMContentLoaded", GeckoApp.mAppContext); GeckoAppShell.registerGeckoEventListener("DOMTitleChanged", GeckoApp.mAppContext); GeckoAppShell.registerGeckoEventListener("DOMLinkAdded", GeckoApp.mAppContext); GeckoAppShell.registerGeckoEventListener("DOMWindowClose", GeckoApp.mAppContext); GeckoAppShell.registerGeckoEventListener("log", GeckoApp.mAppContext); GeckoAppShell.registerGeckoEventListener("Content:LocationChange", GeckoApp.mAppContext); GeckoAppShell.registerGeckoEventListener("Content:SecurityChange", GeckoApp.mAppContext); GeckoAppShell.registerGeckoEventListener("Content:StateChange", GeckoApp.mAppContext); GeckoAppShell.registerGeckoEventListener("Content:LoadError", GeckoApp.mAppContext); GeckoAppShell.registerGeckoEventListener("onCameraCapture", GeckoApp.mAppContext); GeckoAppShell.registerGeckoEventListener("Doorhanger:Add", GeckoApp.mAppContext); GeckoAppShell.registerGeckoEventListener("Doorhanger:Remove", GeckoApp.mAppContext); GeckoAppShell.registerGeckoEventListener("Menu:Add", GeckoApp.mAppContext); GeckoAppShell.registerGeckoEventListener("Menu:Remove", GeckoApp.mAppContext); GeckoAppShell.registerGeckoEventListener("Gecko:Ready", GeckoApp.mAppContext); GeckoAppShell.registerGeckoEventListener("Toast:Show", GeckoApp.mAppContext); GeckoAppShell.registerGeckoEventListener("DOMFullScreen:Start", GeckoApp.mAppContext); GeckoAppShell.registerGeckoEventListener("DOMFullScreen:Stop", GeckoApp.mAppContext); GeckoAppShell.registerGeckoEventListener("ToggleChrome:Hide", GeckoApp.mAppContext); GeckoAppShell.registerGeckoEventListener("ToggleChrome:Show", GeckoApp.mAppContext); GeckoAppShell.registerGeckoEventListener("FormAssist:AutoComplete", GeckoApp.mAppContext); GeckoAppShell.registerGeckoEventListener("Permissions:Data", GeckoApp.mAppContext); GeckoAppShell.registerGeckoEventListener("Downloads:Done", GeckoApp.mAppContext); GeckoAppShell.registerGeckoEventListener("CharEncoding:Data", GeckoApp.mAppContext); GeckoAppShell.registerGeckoEventListener("CharEncoding:State", GeckoApp.mAppContext); GeckoAppShell.registerGeckoEventListener("Update:Restart", GeckoApp.mAppContext); GeckoAppShell.registerGeckoEventListener("Tab:HasTouchListener", GeckoApp.mAppContext); GeckoAppShell.registerGeckoEventListener("Session:StatePurged", GeckoApp.mAppContext); GeckoAppShell.registerGeckoEventListener("Bookmark:Insert", GeckoApp.mAppContext); IntentFilter batteryFilter = new IntentFilter(); batteryFilter.addAction(Intent.ACTION_BATTERY_CHANGED); mBatteryReceiver = new GeckoBatteryManager(); registerReceiver(mBatteryReceiver, batteryFilter); if (SmsManager.getInstance() != null) { SmsManager.getInstance().start(); } GeckoNetworkManager.getInstance().init(); final GeckoApp self = this; GeckoAppShell.getHandler().postDelayed(new Runnable() { public void run() { Log.w(LOGTAG, "zerdatime " + SystemClock.uptimeMillis() + " - pre checkLaunchState"); /* XXXX see bug 635342 We want to disable this code if possible. It is about 145ms in runtime SharedPreferences settings = getPreferences(Activity.MODE_PRIVATE); String localeCode = settings.getString(getPackageName() + ".locale", ""); if (localeCode != null && localeCode.length() > 0) GeckoAppShell.setSelectedLocale(localeCode); */ if (!checkLaunchState(LaunchState.Launched)) { return; } checkMigrateProfile(); } }, 50); }