public class TextureView extends View
A TextureView can be used to display a content stream. Such a content stream can for instance be a video or an OpenGL scene. The content stream can come from the application's process as well as a remote process.
TextureView can only be used in a hardware accelerated window. When rendered in software, TextureView will draw nothing.
Unlike SurfaceView
, TextureView does not create a separate
window but behaves as a regular View. This key difference allows a
TextureView to be moved, transformed, animated, etc. For instance, you
can make a TextureView semi-translucent by calling
myView.setAlpha(0.5f)
.
Using a TextureView is simple: all you need to do is get its
SurfaceTexture
. The SurfaceTexture
can then be used to
render content. The following example demonstrates how to render the
camera preview into a TextureView:
public class LiveCameraActivity extends Activity implements TextureView.SurfaceTextureListener { private Camera mCamera; private TextureView mTextureView; protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mTextureView = new TextureView(this); mTextureView.setSurfaceTextureListener(this); setContentView(mTextureView); } public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) { mCamera = Camera.open(); try { mCamera.setPreviewTexture(surface); mCamera.startPreview(); } catch (IOException ioe) { // Something bad happened } } public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) { // Ignored, Camera does all the work for us } public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) { mCamera.stopPreview(); mCamera.release(); return true; } public void onSurfaceTextureUpdated(SurfaceTexture surface) { // Invoked every time there's a new Camera preview frame } }
A TextureView's SurfaceTexture can be obtained either by invoking
getSurfaceTexture()
or by using a TextureView.SurfaceTextureListener
.
It is important to know that a SurfaceTexture is available only after the
TextureView is attached to a window (and onAttachedToWindow()
has
been invoked.) It is therefore highly recommended you use a listener to
be notified when the SurfaceTexture becomes available.
It is important to note that only one producer can use the TextureView.
For instance, if you use a TextureView to display the camera preview, you
cannot use lockCanvas()
to draw onto the TextureView at the same
time.
SurfaceView
,
SurfaceTexture
Modifier and Type | Class and Description |
---|---|
static interface |
TextureView.SurfaceTextureListener
This listener can be used to be notified when the surface texture
associated with this texture view is available.
|
View.AccessibilityDelegate, View.BaseSavedState, View.DragShadowBuilder, View.DrawingCacheQuality, View.FindViewFlags, View.FocusableMode, View.FocusDirection, View.FocusRealDirection, View.LayoutDir, View.MeasureSpec, View.OnApplyWindowInsetsListener, View.OnAttachStateChangeListener, View.OnClickListener, View.OnContextClickListener, View.OnCreateContextMenuListener, View.OnDragListener, View.OnFocusChangeListener, View.OnGenericMotionListener, View.OnHoverListener, View.OnKeyListener, View.OnLayoutChangeListener, View.OnLongClickListener, View.OnScrollChangeListener, View.OnSystemUiVisibilityChangeListener, View.OnTouchListener, View.ResolvedLayoutDir, View.ScrollBarStyle, View.ScrollIndicators, View.TextAlignment, View.Visibility
ACCESSIBILITY_CURSOR_POSITION_UNDEFINED, ACCESSIBILITY_LIVE_REGION_ASSERTIVE, ACCESSIBILITY_LIVE_REGION_NONE, ACCESSIBILITY_LIVE_REGION_POLITE, ALPHA, DEBUG_LAYOUT_PROPERTY, DRAG_FLAG_GLOBAL, DRAG_FLAG_GLOBAL_PERSISTABLE_URI_PERMISSION, DRAG_FLAG_GLOBAL_PREFIX_URI_PERMISSION, DRAG_FLAG_GLOBAL_URI_READ, DRAG_FLAG_GLOBAL_URI_WRITE, DRAG_FLAG_OPAQUE, DRAWING_CACHE_QUALITY_AUTO, DRAWING_CACHE_QUALITY_HIGH, DRAWING_CACHE_QUALITY_LOW, EMPTY_STATE_SET, ENABLED_FOCUSED_SELECTED_STATE_SET, ENABLED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET, ENABLED_FOCUSED_STATE_SET, ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET, ENABLED_SELECTED_STATE_SET, ENABLED_SELECTED_WINDOW_FOCUSED_STATE_SET, ENABLED_STATE_SET, ENABLED_WINDOW_FOCUSED_STATE_SET, FIND_VIEWS_WITH_ACCESSIBILITY_NODE_PROVIDERS, FIND_VIEWS_WITH_CONTENT_DESCRIPTION, FIND_VIEWS_WITH_TEXT, FOCUS_BACKWARD, FOCUS_DOWN, FOCUS_FORWARD, FOCUS_LEFT, FOCUS_RIGHT, FOCUS_UP, FOCUSABLES_ALL, FOCUSABLES_TOUCH_MODE, FOCUSED_SELECTED_STATE_SET, FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET, FOCUSED_STATE_SET, FOCUSED_WINDOW_FOCUSED_STATE_SET, GONE, HAPTIC_FEEDBACK_ENABLED, IMPORTANT_FOR_ACCESSIBILITY_AUTO, IMPORTANT_FOR_ACCESSIBILITY_NO, IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS, IMPORTANT_FOR_ACCESSIBILITY_YES, INVISIBLE, KEEP_SCREEN_ON, LAYER_TYPE_HARDWARE, LAYER_TYPE_NONE, LAYER_TYPE_SOFTWARE, LAYOUT_DIRECTION_INHERIT, LAYOUT_DIRECTION_LOCALE, LAYOUT_DIRECTION_LTR, LAYOUT_DIRECTION_RTL, LAYOUT_DIRECTION_UNDEFINED, mAttributes, mBottom, mCachingFailed, mContext, mCurrentAnimation, mDebugViewAttributes, MEASURED_HEIGHT_STATE_SHIFT, MEASURED_SIZE_MASK, MEASURED_STATE_MASK, MEASURED_STATE_TOO_SMALL, mInputEventConsistencyVerifier, mLayoutParams, mLeft, mPaddingBottom, mPaddingLeft, mPaddingRight, mPaddingTop, mParent, mRight, mScrollX, mScrollY, mTag, mTop, mUserPaddingBottom, mUserPaddingLeft, mUserPaddingRight, NAVIGATION_BAR_TRANSIENT, NAVIGATION_BAR_TRANSLUCENT, NAVIGATION_BAR_TRANSPARENT, NAVIGATION_BAR_UNHIDE, NO_ID, OVER_SCROLL_ALWAYS, OVER_SCROLL_IF_CONTENT_SCROLLS, OVER_SCROLL_NEVER, PRESSED_ENABLED_FOCUSED_SELECTED_STATE_SET, PRESSED_ENABLED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET, PRESSED_ENABLED_FOCUSED_STATE_SET, PRESSED_ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET, PRESSED_ENABLED_SELECTED_STATE_SET, PRESSED_ENABLED_SELECTED_WINDOW_FOCUSED_STATE_SET, PRESSED_ENABLED_STATE_SET, PRESSED_ENABLED_WINDOW_FOCUSED_STATE_SET, PRESSED_FOCUSED_SELECTED_STATE_SET, PRESSED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET, PRESSED_FOCUSED_STATE_SET, PRESSED_FOCUSED_WINDOW_FOCUSED_STATE_SET, PRESSED_SELECTED_STATE_SET, PRESSED_SELECTED_WINDOW_FOCUSED_STATE_SET, PRESSED_STATE_SET, PRESSED_WINDOW_FOCUSED_STATE_SET, PUBLIC_STATUS_BAR_VISIBILITY_MASK, ROTATION, ROTATION_X, ROTATION_Y, SCALE_X, SCALE_Y, SCREEN_STATE_OFF, SCREEN_STATE_ON, SCROLL_AXIS_HORIZONTAL, SCROLL_AXIS_NONE, SCROLL_AXIS_VERTICAL, SCROLL_INDICATOR_BOTTOM, SCROLL_INDICATOR_END, SCROLL_INDICATOR_LEFT, SCROLL_INDICATOR_RIGHT, SCROLL_INDICATOR_START, SCROLL_INDICATOR_TOP, SCROLLBAR_POSITION_DEFAULT, SCROLLBAR_POSITION_LEFT, SCROLLBAR_POSITION_RIGHT, SCROLLBARS_INSIDE_INSET, SCROLLBARS_INSIDE_OVERLAY, SCROLLBARS_OUTSIDE_INSET, SCROLLBARS_OUTSIDE_OVERLAY, SELECTED_STATE_SET, SELECTED_WINDOW_FOCUSED_STATE_SET, SOUND_EFFECTS_ENABLED, sPreserveMarginParamsInLayoutParamConversion, STATUS_BAR_DISABLE_BACK, STATUS_BAR_DISABLE_CLOCK, STATUS_BAR_DISABLE_EXPAND, STATUS_BAR_DISABLE_HOME, STATUS_BAR_DISABLE_NOTIFICATION_ALERTS, STATUS_BAR_DISABLE_NOTIFICATION_ICONS, STATUS_BAR_DISABLE_NOTIFICATION_TICKER, STATUS_BAR_DISABLE_RECENT, STATUS_BAR_DISABLE_SEARCH, STATUS_BAR_DISABLE_SYSTEM_INFO, STATUS_BAR_HIDDEN, STATUS_BAR_TRANSIENT, STATUS_BAR_TRANSLUCENT, STATUS_BAR_TRANSPARENT, STATUS_BAR_UNHIDE, STATUS_BAR_VISIBLE, SYSTEM_UI_CLEARABLE_FLAGS, SYSTEM_UI_FLAG_FULLSCREEN, SYSTEM_UI_FLAG_HIDE_NAVIGATION, SYSTEM_UI_FLAG_IMMERSIVE, SYSTEM_UI_FLAG_IMMERSIVE_STICKY, SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN, SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION, SYSTEM_UI_FLAG_LAYOUT_STABLE, SYSTEM_UI_FLAG_LIGHT_STATUS_BAR, SYSTEM_UI_FLAG_LOW_PROFILE, SYSTEM_UI_FLAG_VISIBLE, SYSTEM_UI_LAYOUT_FLAGS, SYSTEM_UI_TRANSPARENT, TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_GRAVITY, TEXT_ALIGNMENT_INHERIT, TEXT_ALIGNMENT_TEXT_END, TEXT_ALIGNMENT_TEXT_START, TEXT_ALIGNMENT_VIEW_END, TEXT_ALIGNMENT_VIEW_START, TEXT_DIRECTION_ANY_RTL, TEXT_DIRECTION_FIRST_STRONG, TEXT_DIRECTION_FIRST_STRONG_LTR, TEXT_DIRECTION_FIRST_STRONG_RTL, TEXT_DIRECTION_INHERIT, TEXT_DIRECTION_LOCALE, TEXT_DIRECTION_LTR, TEXT_DIRECTION_RTL, TRANSLATION_X, TRANSLATION_Y, TRANSLATION_Z, VIEW_LOG_TAG, VISIBLE, WINDOW_FOCUSED_STATE_SET, X, Y, Z
Constructor and Description |
---|
TextureView(Context context)
Creates a new TextureView.
|
TextureView(Context context,
AttributeSet attrs)
Creates a new TextureView.
|
TextureView(Context context,
AttributeSet attrs,
int defStyleAttr)
Creates a new TextureView.
|
TextureView(Context context,
AttributeSet attrs,
int defStyleAttr,
int defStyleRes)
Creates a new TextureView.
|
Modifier and Type | Method and Description |
---|---|
void |
buildLayer()
Calling this method has no effect.
|
protected void |
destroyHardwareResources()
Destroys all hardware rendering resources.
|
void |
draw(Canvas canvas)
Subclasses of TextureView cannot do their own rendering
with the
Canvas object. |
Bitmap |
getBitmap()
Returns a
Bitmap representation of the content
of the associated surface texture. |
Bitmap |
getBitmap(Bitmap bitmap)
Copies the content of this view's surface texture into the specified
bitmap.
|
Bitmap |
getBitmap(int width,
int height)
Returns a
Bitmap representation of the content
of the associated surface texture. |
int |
getLayerType()
Always returns
View.LAYER_TYPE_HARDWARE . |
SurfaceTexture |
getSurfaceTexture()
Returns the
SurfaceTexture used by this view. |
TextureView.SurfaceTextureListener |
getSurfaceTextureListener()
Returns the
TextureView.SurfaceTextureListener currently associated with this
texture view. |
Matrix |
getTransform(Matrix transform)
Returns the transform associated with this texture view.
|
boolean |
isAvailable()
Returns true if the
SurfaceTexture associated with this
TextureView is available for rendering. |
boolean |
isOpaque()
Indicates whether this View is opaque.
|
Canvas |
lockCanvas()
Start editing the pixels in the surface.
|
Canvas |
lockCanvas(Rect dirty)
Just like
lockCanvas() but allows specification of a dirty
rectangle. |
protected void |
onAttachedToWindow()
This is called when the view is attached to a window.
|
protected void |
onDetachedFromWindowInternal()
This is a framework-internal mirror of onDetachedFromWindow() that's called
after onDetachedFromWindow().
|
protected void |
onDraw(Canvas canvas)
Subclasses of TextureView cannot do their own rendering
with the
Canvas object. |
protected void |
onSizeChanged(int w,
int h,
int oldw,
int oldh)
This is called during layout when the size of this view has changed.
|
protected void |
onVisibilityChanged(View changedView,
int visibility)
Called when the visibility of the view or an ancestor of the view has
changed.
|
void |
setBackgroundDrawable(Drawable background) |
void |
setForeground(Drawable foreground)
Supply a Drawable that is to be rendered on top of all of the content in the view.
|
void |
setLayerPaint(Paint paint)
Updates the
Paint object used with the current layer (used only if the current
layer type is not set to View.LAYER_TYPE_NONE ). |
void |
setLayerType(int layerType,
Paint paint)
The layer type of a TextureView is ignored since a TextureView is always
considered to act as a hardware layer.
|
void |
setOpaque(boolean opaque)
Indicates whether the content of this TextureView is opaque.
|
void |
setSurfaceTexture(SurfaceTexture surfaceTexture)
Set the
SurfaceTexture for this view to use. |
void |
setSurfaceTextureListener(TextureView.SurfaceTextureListener listener)
Sets the
TextureView.SurfaceTextureListener used to listen to surface
texture events. |
void |
setTransform(Matrix transform)
Sets the transform to associate with this texture view.
|
void |
unlockCanvasAndPost(Canvas canvas)
Finish editing pixels in the surface.
|
addChildrenForAccessibility, addFocusables, addFocusables, addFrameMetricsListener, addOnAttachStateChangeListener, addOnLayoutChangeListener, addTouchables, animate, announceForAccessibility, applyDrawableToTransparentRegion, awakenScrollBars, awakenScrollBars, awakenScrollBars, bringToFront, buildDrawingCache, buildDrawingCache, callOnClick, cancelDragAndDrop, cancelLongPress, cancelPendingInputEvents, canHaveDisplayList, canResolveLayoutDirection, canResolveTextAlignment, canResolveTextDirection, canScrollHorizontally, canScrollVertically, captureTransitioningViews, checkInputConnectionProxy, clearAccessibilityFocus, clearAnimation, clearFocus, combineMeasuredStates, computeFitSystemWindows, computeHorizontalScrollExtent, computeHorizontalScrollOffset, computeHorizontalScrollRange, computeOpaqueFlags, computeScroll, computeSystemWindowInsets, computeVerticalScrollExtent, computeVerticalScrollOffset, computeVerticalScrollRange, createAccessibilityNodeInfo, createAccessibilityNodeInfoInternal, createContextMenu, createSnapshot, damageInParent, debug, debug, debugIndent, destroyDrawingCache, dispatchActivityResult, dispatchApplyWindowInsets, dispatchConfigurationChanged, dispatchDisplayHint, dispatchDragEvent, dispatchDraw, dispatchDrawableHotspotChanged, dispatchFinishTemporaryDetach, dispatchGenericFocusedEvent, dispatchGenericMotionEvent, dispatchGenericPointerEvent, dispatchGetDisplayList, dispatchHoverEvent, dispatchKeyEvent, dispatchKeyEventPreIme, dispatchKeyShortcutEvent, dispatchNestedFling, dispatchNestedPreFling, dispatchNestedPrePerformAccessibilityAction, dispatchNestedPreScroll, dispatchNestedScroll, dispatchPointerEvent, dispatchPopulateAccessibilityEvent, dispatchPopulateAccessibilityEventInternal, dispatchProvideStructure, dispatchRestoreInstanceState, dispatchSaveInstanceState, dispatchSetActivated, dispatchSetPressed, dispatchSetSelected, dispatchStartTemporaryDetach, dispatchSystemUiVisibilityChanged, dispatchTouchEvent, dispatchTrackballEvent, dispatchUnhandledMove, dispatchVisibilityChanged, dispatchWindowFocusChanged, dispatchWindowSystemUiVisiblityChanged, dispatchWindowVisibilityChanged, drawableHotspotChanged, drawableStateChanged, encode, encodeProperties, findFocus, findNamedViews, findViewByAccessibilityIdTraversal, findViewById, findViewByPredicate, findViewByPredicateInsideOut, findViewByPredicateTraversal, findViewsWithText, findViewTraversal, findViewWithTag, findViewWithTagTraversal, fitsSystemWindows, fitSystemWindows, focusSearch, forceHasOverlappingRendering, forceLayout, gatherTransparentRegion, generateViewId, getAccessibilityClassName, getAccessibilityDelegate, getAccessibilityLiveRegion, getAccessibilityNodeProvider, getAccessibilitySelectionEnd, getAccessibilitySelectionStart, getAccessibilityTraversalAfter, getAccessibilityTraversalBefore, getAccessibilityViewId, getAccessibilityWindowId, getAlpha, getAnimation, getApplicationWindowToken, getBackground, getBackgroundTintList, getBackgroundTintMode, getBaseline, getBottom, getBottomFadingEdgeStrength, getBottomPaddingOffset, getBoundsOnScreen, getBoundsOnScreen, getCameraDistance, getClipBounds, getClipBounds, getClipToOutline, getContentDescription, getContext, getContextMenuInfo, getDefaultSize, getDisplay, getDrawableState, getDrawingCache, getDrawingCache, getDrawingCacheBackgroundColor, getDrawingCacheQuality, getDrawingRect, getDrawingTime, getElevation, getFadeHeight, getFadeTop, getFilterTouchesWhenObscured, getFitsSystemWindows, getFocusables, getFocusedRect, getForeground, getForegroundGravity, getForegroundTintList, getForegroundTintMode, getGlobalVisibleRect, getGlobalVisibleRect, getHandler, getHardwareRenderer, getHasOverlappingRendering, getHeight, getHitRect, getHorizontalFadingEdgeLength, getHorizontalScrollbarHeight, getHorizontalScrollFactor, getHotspotBounds, getId, getImportantForAccessibility, getInverseMatrix, getIterableTextForAccessibility, getIteratorForGranularity, getKeepScreenOn, getKeyDispatcherState, getLabelFor, getLayoutDirection, getLayoutParams, getLeft, getLeftFadingEdgeStrength, getLeftPaddingOffset, getLocalVisibleRect, getLocationInSurface, getLocationInWindow, getLocationOnScreen, getLocationOnScreen, getMatrix, getMeasuredHeight, getMeasuredHeightAndState, getMeasuredState, getMeasuredWidth, getMeasuredWidthAndState, getMinimumHeight, getMinimumWidth, getNextFocusDownId, getNextFocusForwardId, getNextFocusLeftId, getNextFocusRightId, getNextFocusUpId, getOnFocusChangeListener, getOpticalInsets, getOutlineProvider, getOutsets, getOverlay, getOverScrollMode, getPaddingBottom, getPaddingEnd, getPaddingLeft, getPaddingRight, getPaddingStart, getPaddingTop, getParent, getParentForAccessibility, getPivotX, getPivotY, getPointerIcon, getRawLayoutDirection, getRawTextAlignment, getRawTextDirection, getResources, getRevealOnFocusHint, getRight, getRightFadingEdgeStrength, getRightPaddingOffset, getRootView, getRootWindowInsets, getRotation, getRotationX, getRotationY, getScaleX, getScaleY, getScrollBarDefaultDelayBeforeFade, getScrollBarFadeDuration, getScrollBarSize, getScrollBarStyle, getScrollIndicators, getScrollX, getScrollY, getSolidColor, getStateListAnimator, getSuggestedMinimumHeight, getSuggestedMinimumWidth, getSystemUiVisibility, getTag, getTag, getTextAlignment, getTextDirection, getTop, getTopFadingEdgeStrength, getTopPaddingOffset, getTouchables, getTouchDelegate, getTransitionAlpha, getTransitionName, getTranslationX, getTranslationY, getTranslationZ, getVerticalFadingEdgeLength, getVerticalScrollbarPosition, getVerticalScrollbarWidth, getVerticalScrollFactor, getViewRootImpl, getViewTreeObserver, getVisibility, getWidth, getWindowAttachCount, getWindowDisplayFrame, getWindowId, getWindowSystemUiVisibility, getWindowToken, getWindowVisibility, getWindowVisibleDisplayFrame, getX, getY, getZ, handleScrollBarDragging, hasFocus, hasFocusable, hasHoveredChild, hasNestedScrollingParent, hasOnClickListeners, hasOpaqueScrollbars, hasOverlappingRendering, hasShadow, hasTransientState, hasWindowFocus, includeForAccessibility, inflate, initializeFadingEdge, initializeFadingEdgeInternal, initializeScrollbars, initializeScrollbarsInternal, internalSetPadding, invalidate, invalidate, invalidate, invalidateDrawable, invalidateOutline, invalidateParentCaches, invalidateParentIfNeeded, invalidateParentIfNeededAndWasQuickRejected, isAccessibilityFocused, isAccessibilitySelectionExtendable, isActionableForAccessibility, isActivated, isAssistBlocked, isAttachedToWindow, isClickable, isContextClickable, isDirty, isDrawingCacheEnabled, isDuplicateParentStateEnabled, isEnabled, isFocusable, isFocusableInTouchMode, isFocused, isForegroundInsidePadding, isHapticFeedbackEnabled, isHardwareAccelerated, isHorizontalFadingEdgeEnabled, isHorizontalScrollBarEnabled, isHovered, isImportantForAccessibility, isInEditMode, isInLayout, isInScrollingContainer, isInTouchMode, isLaidOut, isLayoutDirectionInherited, isLayoutDirectionResolved, isLayoutModeOptical, isLayoutRequested, isLayoutRtl, isLongClickable, isNestedScrollingEnabled, isPaddingOffsetRequired, isPaddingRelative, isPressed, isRootNamespace, isSaveEnabled, isSaveFromParentEnabled, isScrollbarFadingEnabled, isScrollContainer, isSelected, isShown, isSoundEffectsEnabled, isTemporarilyDetached, isTextAlignmentInherited, isTextAlignmentResolved, isTextDirectionInherited, isTextDirectionResolved, isVerticalFadingEdgeEnabled, isVerticalScrollBarEnabled, isVerticalScrollBarHidden, isVisibleToUser, isVisibleToUser, jumpDrawablesToCurrentState, layout, makeOptionalFitsSystemWindows, measure, mergeDrawableStates, notifySubtreeAccessibilityStateChangedIfNeeded, notifyViewAccessibilityStateChangedIfNeeded, offsetLeftAndRight, offsetTopAndBottom, onActivityResult, onAnimationEnd, onAnimationStart, onApplyWindowInsets, onCancelPendingInputEvents, onCheckIsTextEditor, onCloseSystemDialogs, onConfigurationChanged, onCreateContextMenu, onCreateDrawableState, onCreateInputConnection, onDetachedFromWindow, onDisplayHint, onDragEvent, onDrawForeground, onDrawHorizontalScrollBar, onDrawScrollBars, onDrawVerticalScrollBar, onFilterTouchEventForSecurity, onFinishInflate, onFinishTemporaryDetach, onFocusChanged, onFocusLost, onGenericMotionEvent, onHoverChanged, onHoverEvent, onInitializeAccessibilityEvent, onInitializeAccessibilityEventInternal, onInitializeAccessibilityNodeInfo, onInitializeAccessibilityNodeInfoInternal, onKeyDown, onKeyLongPress, onKeyMultiple, onKeyPreIme, onKeyShortcut, onKeyUp, onLayout, onMeasure, onOverScrolled, onPopulateAccessibilityEvent, onPopulateAccessibilityEventInternal, onProvideStructure, onProvideVirtualStructure, onRenderNodeDetached, onResolveDrawables, onResolvePointerIcon, onRestoreInstanceState, onRtlPropertiesChanged, onSaveInstanceState, onScreenStateChanged, onScrollChanged, onSetAlpha, onStartTemporaryDetach, onTouchEvent, onTrackballEvent, onVisibilityAggregated, onWindowFocusChanged, onWindowSystemUiVisibilityChanged, onWindowVisibilityChanged, outputDirtyFlags, overScrollBy, performAccessibilityAction, performAccessibilityActionInternal, performButtonActionOnTouchDown, performClick, performContextClick, performContextClick, performHapticFeedback, performHapticFeedback, performLongClick, performLongClick, playSoundEffect, pointInView, post, postDelayed, postInvalidate, postInvalidate, postInvalidateDelayed, postInvalidateDelayed, postInvalidateOnAnimation, postInvalidateOnAnimation, postOnAnimation, postOnAnimationDelayed, recomputePadding, refreshDrawableState, removeCallbacks, removeFrameMetricsListener, removeOnAttachStateChangeListener, removeOnLayoutChangeListener, requestAccessibilityFocus, requestApplyInsets, requestFitSystemWindows, requestFocus, requestFocus, requestFocus, requestFocusFromTouch, requestKeyboardShortcuts, requestLayout, requestRectangleOnScreen, requestRectangleOnScreen, requestUnbufferedDispatch, resetPaddingToInitialValues, resetResolvedDrawables, resetResolvedLayoutDirection, resetResolvedPadding, resetResolvedTextAlignment, resetResolvedTextDirection, resetRtlProperties, resolveDrawables, resolveLayoutDirection, resolveLayoutParams, resolvePadding, resolveRtlPropertiesIfNeeded, resolveSize, resolveSizeAndState, resolveTextAlignment, resolveTextDirection, restoreHierarchyState, saveHierarchyState, scheduleDrawable, scrollBy, scrollTo, sendAccessibilityEvent, sendAccessibilityEventInternal, sendAccessibilityEventUnchecked, sendAccessibilityEventUncheckedInternal, setAccessibilityDelegate, setAccessibilityLiveRegion, setAccessibilitySelection, setAccessibilityTraversalAfter, setAccessibilityTraversalBefore, setActivated, setAlpha, setAnimation, setAnimationMatrix, setAssistBlocked, setBackground, setBackgroundColor, setBackgroundResource, setBackgroundTintList, setBackgroundTintMode, setBottom, setCameraDistance, setClickable, setClipBounds, setClipToOutline, setContentDescription, setContextClickable, setDisabledSystemUiVisibility, setDrawingCacheBackgroundColor, setDrawingCacheEnabled, setDrawingCacheQuality, setDuplicateParentStateEnabled, setElevation, setEnabled, setFadingEdgeLength, setFilterTouchesWhenObscured, setFitsSystemWindows, setFocusable, setFocusableInTouchMode, setForegroundGravity, setForegroundTintList, setForegroundTintMode, setFrame, setHapticFeedbackEnabled, setHasTransientState, setHorizontalFadingEdgeEnabled, setHorizontalScrollBarEnabled, setHovered, setId, setImportantForAccessibility, setIsRootNamespace, setKeepScreenOn, setLabelFor, setLayoutDirection, setLayoutParams, setLeft, setLeftTopRightBottom, setLongClickable, setMeasuredDimension, setMinimumHeight, setMinimumWidth, setNestedScrollingEnabled, setNextFocusDownId, setNextFocusForwardId, setNextFocusLeftId, setNextFocusRightId, setNextFocusUpId, setOnApplyWindowInsetsListener, setOnClickListener, setOnContextClickListener, setOnCreateContextMenuListener, setOnDragListener, setOnFocusChangeListener, setOnGenericMotionListener, setOnHoverListener, setOnKeyListener, setOnLongClickListener, setOnScrollChangeListener, setOnSystemUiVisibilityChangeListener, setOnTouchListener, setOpticalInsets, setOutlineProvider, setOverScrollMode, setPadding, setPaddingRelative, setPivotX, setPivotY, setPointerIcon, setPressed, setRevealClip, setRevealOnFocusHint, setRight, setRotation, setRotationX, setRotationY, setSaveEnabled, setSaveFromParentEnabled, setScaleX, setScaleY, setScrollBarDefaultDelayBeforeFade, setScrollBarFadeDuration, setScrollbarFadingEnabled, setScrollBarSize, setScrollBarStyle, setScrollContainer, setScrollIndicators, setScrollIndicators, setScrollX, setScrollY, setSelected, setSoundEffectsEnabled, setStateListAnimator, setSystemUiVisibility, setTag, setTag, setTagInternal, setTextAlignment, setTextDirection, setTop, setTouchDelegate, setTransitionAlpha, setTransitionName, setTransitionVisibility, setTranslationX, setTranslationY, setTranslationZ, setVerticalFadingEdgeEnabled, setVerticalScrollBarEnabled, setVerticalScrollbarPosition, setVisibility, setWillNotCacheDrawing, setWillNotDraw, setX, setY, setZ, showContextMenu, showContextMenu, startActionMode, startActionMode, startActivityForResult, startAnimation, startDrag, startDragAndDrop, startMovingTask, startNestedScroll, stopNestedScroll, toGlobalMotionEvent, toLocalMotionEvent, toString, transformFromViewToWindowSpace, transformMatrixToGlobal, transformMatrixToLocal, unscheduleDrawable, unscheduleDrawable, updateDisplayListIfDirty, updateDragShadow, verifyDrawable, willNotCacheDrawing, willNotDraw
public TextureView(Context context)
context
- The context to associate this view with.public TextureView(Context context, AttributeSet attrs)
context
- The context to associate this view with.attrs
- The attributes of the XML tag that is inflating the view.public TextureView(Context context, AttributeSet attrs, int defStyleAttr)
context
- The context to associate this view with.attrs
- The attributes of the XML tag that is inflating the view.defStyleAttr
- An attribute in the current theme that contains a
reference to a style resource that supplies default values for
the view. Can be 0 to not look for defaults.public TextureView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes)
context
- The context to associate this view with.attrs
- The attributes of the XML tag that is inflating the view.defStyleAttr
- An attribute in the current theme that contains a
reference to a style resource that supplies default values for
the view. Can be 0 to not look for defaults.defStyleRes
- A resource identifier of a style resource that
supplies default values for the view, used only if
defStyleAttr is 0 or can not be found in the theme. Can be 0
to not look for defaults.public boolean isOpaque()
public void setOpaque(boolean opaque)
opaque
- True if the content of this TextureView is opaque,
false otherwiseprotected void onAttachedToWindow()
View
View.onDraw(android.graphics.Canvas)
,
however it may be called any time before the first onDraw -- including
before or after View.onMeasure(int, int)
.onAttachedToWindow
in class View
View.onDetachedFromWindow()
protected void onDetachedFromWindowInternal()
View
onDetachedFromWindowInternal
in class View
protected void destroyHardwareResources()
View
super.destroyHardwareResources()
when overriding
this method.destroyHardwareResources
in class View
public void setLayerType(int layerType, Paint paint)
setLayerType
in class View
layerType
- The type of layer to use with this view, must be one of
View.LAYER_TYPE_NONE
, View.LAYER_TYPE_SOFTWARE
or
View.LAYER_TYPE_HARDWARE
paint
- The paint used to compose the layer. This argument is optional
and can be null. It is ignored when the layer type is
View.LAYER_TYPE_NONE
View.getLayerType()
,
View.LAYER_TYPE_NONE
,
View.LAYER_TYPE_SOFTWARE
,
View.LAYER_TYPE_HARDWARE
,
View.setAlpha(float)
public void setLayerPaint(Paint paint)
View
Paint
object used with the current layer (used only if the current
layer type is not set to View.LAYER_TYPE_NONE
). Changed properties of the Paint
provided to View.setLayerType(int, android.graphics.Paint)
will be used the next time
the View is redrawn, but View.setLayerPaint(android.graphics.Paint)
must be called to
ensure that the view gets redrawn immediately.
A layer is associated with an optional Paint
instance that controls how the layer is composed on screen. The following
properties of the paint are taken into account when composing the layer:
If this view has an alpha value set to < 1.0 by calling View.setAlpha(float)
, the
alpha value of the layer's paint is superseded by this view's alpha value.
setLayerPaint
in class View
paint
- The paint used to compose the layer. This argument is optional
and can be null. It is ignored when the layer type is
View.LAYER_TYPE_NONE
View.setLayerType(int, android.graphics.Paint)
public int getLayerType()
View.LAYER_TYPE_HARDWARE
.getLayerType
in class View
View.LAYER_TYPE_NONE
, View.LAYER_TYPE_SOFTWARE
or
View.LAYER_TYPE_HARDWARE
View.setLayerType(int, android.graphics.Paint)
,
View.buildLayer()
,
View.LAYER_TYPE_NONE
,
View.LAYER_TYPE_SOFTWARE
,
View.LAYER_TYPE_HARDWARE
public void buildLayer()
buildLayer
in class View
View.setLayerType(int, android.graphics.Paint)
public void setForeground(Drawable foreground)
View
setForeground
in class View
foreground
- the Drawable to be drawn on top of the childrenpublic void setBackgroundDrawable(Drawable background)
setBackgroundDrawable
in class View
public final void draw(Canvas canvas)
Canvas
object.protected final void onDraw(Canvas canvas)
Canvas
object.protected void onSizeChanged(int w, int h, int oldw, int oldh)
View
onSizeChanged
in class View
w
- Current width of this view.h
- Current height of this view.oldw
- Old width of this view.oldh
- Old height of this view.protected void onVisibilityChanged(View changedView, int visibility)
View
onVisibilityChanged
in class View
changedView
- The view whose visibility changed. May be
this
or an ancestor view.visibility
- The new visibility, one of View.VISIBLE
,
View.INVISIBLE
or View.GONE
.public void setTransform(Matrix transform)
Sets the transform to associate with this texture view. The specified transform applies to the underlying surface texture and does not affect the size or position of the view itself, only of its content.
Some transforms might prevent the content from drawing all the pixels contained within this view's bounds. In such situations, make sure this texture view is not marked opaque.
transform
- The transform to apply to the content of
this view.getTransform(android.graphics.Matrix)
,
isOpaque()
,
setOpaque(boolean)
public Matrix getTransform(Matrix transform)
transform
- The Matrix
in which to copy the current
transform. Can be null.Matrix
instance otherwise.setTransform(android.graphics.Matrix)
public Bitmap getBitmap()
Returns a Bitmap
representation of the content
of the associated surface texture. If the surface texture is not available,
this method returns null.
The bitmap returned by this method uses the Bitmap.Config#ARGB_8888
pixel format and its dimensions are the same as this view's.
Do not invoke this method from a drawing method
(onDraw(android.graphics.Canvas)
for instance).
If an error occurs during the copy, an empty bitmap will be returned.
Bitmap.Config#ARGB_8888
bitmap, or null if the surface
texture is not available or the width <= 0 or the height <= 0isAvailable()
,
getBitmap(android.graphics.Bitmap)
,
getBitmap(int, int)
public Bitmap getBitmap(int width, int height)
Returns a Bitmap
representation of the content
of the associated surface texture. If the surface texture is not available,
this method returns null.
The bitmap returned by this method uses the Bitmap.Config#ARGB_8888
pixel format.
Do not invoke this method from a drawing method
(onDraw(android.graphics.Canvas)
for instance).
If an error occurs during the copy, an empty bitmap will be returned.
width
- The width of the bitmap to createheight
- The height of the bitmap to createBitmap.Config#ARGB_8888
bitmap, or null if the surface
texture is not available or width is <= 0 or height is <= 0isAvailable()
,
getBitmap(android.graphics.Bitmap)
,
getBitmap()
public Bitmap getBitmap(Bitmap bitmap)
Copies the content of this view's surface texture into the specified bitmap. If the surface texture is not available, the copy is not executed. The content of the surface texture will be scaled to fit exactly inside the specified bitmap.
Do not invoke this method from a drawing method
(onDraw(android.graphics.Canvas)
for instance).
If an error occurs, the bitmap is left unchanged.
bitmap
- The bitmap to copy the content of the surface texture into,
cannot be null, all configurations are supportedIllegalStateException
- if the hardware rendering context cannot be
acquired to capture the bitmapisAvailable()
,
getBitmap(int, int)
,
getBitmap()
public boolean isAvailable()
SurfaceTexture
associated with this
TextureView is available for rendering. When this method returns
true, getSurfaceTexture()
returns a valid surface texture.public Canvas lockCanvas()
Start editing the pixels in the surface. The returned Canvas can be used
to draw into the surface's bitmap. A null is returned if the surface has
not been created or otherwise cannot be edited. You will usually need
to implement
TextureView.SurfaceTextureListener.onSurfaceTextureAvailable(android.graphics.SurfaceTexture, int, int)
to find out when the Surface is available for use.
The content of the Surface is never preserved between unlockCanvas() and lockCanvas(), for this reason, every pixel within the Surface area must be written. The only exception to this rule is when a dirty rectangle is specified, in which case, non-dirty pixels will be preserved.
This method can only be used if the underlying surface is not already owned by another producer. For instance, if the TextureView is being used to render the camera's preview you cannot invoke this method.
lockCanvas(android.graphics.Rect)
,
unlockCanvasAndPost(android.graphics.Canvas)
public Canvas lockCanvas(Rect dirty)
lockCanvas()
but allows specification of a dirty
rectangle. Every pixel within that rectangle must be written; however
pixels outside the dirty rectangle will be preserved by the next call
to lockCanvas().
This method can return null if the underlying surface texture is not
available (see isAvailable()
or if the surface texture is
already connected to an image producer (for instance: the camera,
OpenGL, a media player, etc.)dirty
- Area of the surface that will be modified.lockCanvas()
,
unlockCanvasAndPost(android.graphics.Canvas)
,
isAvailable()
public void unlockCanvasAndPost(Canvas canvas)
canvas
- The Canvas previously returned by lockCanvas()lockCanvas()
,
lockCanvas(android.graphics.Rect)
public SurfaceTexture getSurfaceTexture()
SurfaceTexture
used by this view. This method
may return null if the view is not attached to a window or if the surface
texture has not been initialized yet.isAvailable()
public void setSurfaceTexture(SurfaceTexture surfaceTexture)
SurfaceTexture
for this view to use. If a SurfaceTexture
is already being used by this view, it is immediately
released and not usable any more. The TextureView.SurfaceTextureListener.onSurfaceTextureDestroyed(android.graphics.SurfaceTexture)
callback is not
called for the previous SurfaceTexture
. Similarly, the TextureView.SurfaceTextureListener.onSurfaceTextureAvailable(android.graphics.SurfaceTexture, int, int)
callback is not
called for the SurfaceTexture
passed to setSurfaceTexture.
The SurfaceTexture
object must be detached from all OpenGL ES
contexts prior to calling this method.surfaceTexture
- The SurfaceTexture
that the view should use.SurfaceTexture.detachFromGLContext()
public TextureView.SurfaceTextureListener getSurfaceTextureListener()
TextureView.SurfaceTextureListener
currently associated with this
texture view.public void setSurfaceTextureListener(TextureView.SurfaceTextureListener listener)
TextureView.SurfaceTextureListener
used to listen to surface
texture events.