Example usage for android.view SurfaceHolder getSurface

List of usage examples for android.view SurfaceHolder getSurface

Introduction

In this page you can find the example usage for android.view SurfaceHolder getSurface.

Prototype

public Surface getSurface();

Source Link

Document

Direct access to the surface object.

Usage

From source file:Main.java

static boolean validSurface(SurfaceHolder holder) {
    if (holder.getSurface() != null) {
        Rect r = holder.getSurfaceFrame();
        System.out.println("ExoVlcUtil.validSurface() r = " + r);
        return (r.width() * r.height()) > 0;
    }//from ww w. ja  va 2s . c om
    return false;
}

From source file:meizhi.meizhi.malin.utils.DestroyCleanUtil.java

@SuppressLint("ObsoleteSdkInt")
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
public static void unBindView(View view) {
    if (view == null)
        return;/*from  www  .  jav  a 2 s .c  o  m*/
    Drawable drawable;
    int i;
    //1.
    try {
        view.setOnClickListener(null);
    } catch (Throwable e) {
        CrashReport.postCatchedException(e);
    }

    //2.
    try {
        view.setOnCreateContextMenuListener(null);
    } catch (Throwable e) {
        CrashReport.postCatchedException(e);
    }

    //3.
    try {
        view.setOnFocusChangeListener(null);
    } catch (Throwable e) {
        CrashReport.postCatchedException(e);
    }

    //4.
    try {
        view.setOnKeyListener(null);
    } catch (Throwable e) {
        CrashReport.postCatchedException(e);
    }

    //5.
    try {
        view.setOnLongClickListener(null);
    } catch (Throwable e) {
        CrashReport.postCatchedException(e);
    }

    //6.
    try {
        view.setOnTouchListener(null);
    } catch (Throwable e) {
        CrashReport.postCatchedException(e);
    }

    //7.
    try {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) {
            view.setOnApplyWindowInsetsListener(null);
        }
    } catch (Throwable e) {
        CrashReport.postCatchedException(e);
    }

    //8.
    try {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            view.setOnContextClickListener(null);
        }
    } catch (Throwable e) {
        CrashReport.postCatchedException(e);
    }

    //9.
    try {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            view.setOnScrollChangeListener(null);
        }
    } catch (Throwable e) {
        CrashReport.postCatchedException(e);
    }

    //10.
    try {
        view.setOnDragListener(null);
    } catch (Throwable e) {
        CrashReport.postCatchedException(e);
    }

    //11.
    try {
        view.setOnGenericMotionListener(null);
    } catch (Throwable e) {
        CrashReport.postCatchedException(e);
    }

    //12.
    try {
        if (Build.VERSION.SDK_INT > Build.VERSION_CODES.HONEYCOMB_MR2) {//13
            view.setOnHoverListener(null);
        }
    } catch (Throwable e) {
        CrashReport.postCatchedException(e);
    }

    //13.
    try {
        view.setOnSystemUiVisibilityChangeListener(null);
    } catch (Throwable e) {
        CrashReport.postCatchedException(e);
    }

    /**
     * @see SwipeRefreshLayout#onDetachedFromWindow()
     */
    if (view.getBackground() != null && !view.getClass().getName().equals(CIRCLE_CLASS)) {
        try {
            view.getBackground().setCallback(null);
            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {//16
                view.setBackgroundDrawable(null);
            } else {
                view.setBackground(null);
            }
        } catch (Throwable e) {
            CrashReport.postCatchedException(e);
        }
    }

    //ImageView
    if (view instanceof ImageView) {
        try {
            ImageView imageView = (ImageView) view;
            drawable = imageView.getDrawable();
            if (drawable != null) {
                drawable.setCallback(null);
            }
            imageView.setImageDrawable(null);
            imageView.setImageBitmap(null);
        } catch (Throwable e) {
            CrashReport.postCatchedException(e);
        }
    }

    //TextView
    if (view instanceof TextView) {
        try {
            TextView textView = (TextView) view;
            textView.setCompoundDrawables(null, null, null, null);
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
                textView.setCompoundDrawablesRelative(null, null, null, null);
            }
            textView.setCursorVisible(false);
        } catch (Throwable e) {
            CrashReport.postCatchedException(e);
        }
    }

    //ImageButton
    if (view instanceof ImageButton) {
        try {
            ImageButton imageButton = (ImageButton) view;
            drawable = imageButton.getDrawable();
            if (drawable != null) {
                drawable.setCallback(null);
            }
            imageButton.setImageDrawable(null);
            imageButton.setImageBitmap(null);
        } catch (Throwable e) {
            CrashReport.postCatchedException(e);
        }
    }

    //ListView
    if (view instanceof ListView) {
        ListView listView = (ListView) view;

        try {
            listView.setAdapter(null);
        } catch (Throwable e) {
            CrashReport.postCatchedException(e);
        }

        try {
            listView.setOnScrollListener(null);
        } catch (Throwable e) {
            CrashReport.postCatchedException(e);
        }

        try {
            listView.setOnItemClickListener(null);
        } catch (Throwable e) {
            CrashReport.postCatchedException(e);
        }

        try {
            listView.setOnItemLongClickListener(null);
        } catch (Throwable e) {
            CrashReport.postCatchedException(e);
        }

        try {
            listView.setOnItemSelectedListener(null);
        } catch (Throwable e) {
            CrashReport.postCatchedException(e);
        }
    }

    //RecyclerView
    if (view instanceof RecyclerView) {
        try {
            RecyclerView recyclerView = (RecyclerView) view;
            recyclerView.setAdapter(null);
            recyclerView.setChildDrawingOrderCallback(null);
            recyclerView.setOnScrollListener(null);
            recyclerView.addOnScrollListener(null);
            recyclerView.removeOnScrollListener(null);
            recyclerView.setRecyclerListener(null);
        } catch (Throwable e) {
            CrashReport.postCatchedException(e);
        }
    }

    //WebView
    if (view instanceof WebView) {

        WebView webView = (WebView) view;
        try {
            webView.stopLoading();
        } catch (Throwable ignored) {
            CrashReport.postCatchedException(ignored);
        }

        try {
            webView.removeAllViews();
        } catch (Throwable ignored) {
            CrashReport.postCatchedException(ignored);
        }

        try {
            webView.setWebChromeClient(null);
        } catch (Throwable ignored) {
            CrashReport.postCatchedException(ignored);
        }

        try {
            webView.setWebViewClient(null);
        } catch (Throwable ignored) {
            CrashReport.postCatchedException(ignored);
        }

        try {
            webView.destroy();
        } catch (Throwable ignored) {
            CrashReport.postCatchedException(ignored);
        }

        try {
            if (null != view.getParent() && view.getParent() instanceof ViewGroup) {
                ((ViewGroup) view.getParent()).removeView(view);
            }
        } catch (Throwable ignored) {
            CrashReport.postCatchedException(ignored);
        }

    }

    //SurfaceView
    if (view instanceof SurfaceView) {
        try {
            SurfaceView surfaceView = (SurfaceView) view;
            SurfaceHolder holder = surfaceView.getHolder();
            if (holder != null) {
                Surface surface = holder.getSurface();
                if (surface != null) {
                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
                        surface.release();
                    }
                }
            }
        } catch (Throwable ignored) {
            CrashReport.postCatchedException(ignored);
        }
    }

    view.destroyDrawingCache();
    view.clearAnimation();

    if (view instanceof ViewGroup) {
        ViewGroup viewGroup = (ViewGroup) view;
        int childCount = (viewGroup).getChildCount();
        for (i = 0; i < childCount; i++) {
            unBindView((viewGroup).getChildAt(i));
        }
    }
}

From source file:org.skia.viewer.ViewerActivity.java

@Override
public void surfaceCreated(SurfaceHolder holder) {
    if (mApplication.getNativeHandle() != 0) {
        onSurfaceCreated(mApplication.getNativeHandle(), holder.getSurface());
    }//from  w w w.ja va 2  s  .  c  o  m
}

From source file:org.freedesktop.nativecamera2.NativeCamera2.java

@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    setContentView(R.layout.main);//from   w w w . j av  a  2s  . c  o  m

    if (ContextCompat.checkSelfPermission(this,
            Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {

        ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.CAMERA },
                PERMISSION_REQUEST_CAMERA);
        return;
    }

    surfaceView = (SurfaceView) findViewById(R.id.surfaceview);
    surfaceHolder = surfaceView.getHolder();

    surfaceHolder.addCallback(new SurfaceHolder.Callback() {
        @Override
        public void surfaceCreated(SurfaceHolder holder) {

            Log.v(TAG, "surface created.");
            startPreview(holder.getSurface());
        }

        @Override
        public void surfaceDestroyed(SurfaceHolder holder) {
            stopPreview();
        }

        @Override
        public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
            Log.v(TAG, "format=" + format + " w/h : (" + width + ", " + height + ")");
        }
    });

    extraViewLayoutInflater = LayoutInflater.from(getBaseContext());

    View view = extraViewLayoutInflater.inflate(R.layout.extraviewlayout, null);
    ViewGroup.LayoutParams layoutParamsControl = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);

    this.addContentView(view, layoutParamsControl);

    extraView = (SurfaceView) findViewById(R.id.extraview);
    extraView.setVisibility(View.INVISIBLE);

    extraViewHolder = extraView.getHolder();
    extraViewHolder.addCallback(new SurfaceHolder.Callback() {
        @Override
        public void surfaceCreated(SurfaceHolder holder) {
            startExtraView(extraViewHolder.getSurface());

        }

        @Override
        public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {

        }

        @Override
        public void surfaceDestroyed(SurfaceHolder holder) {
            stopExtraView();
        }
    });

    surfaceView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            isBurstModeOn = !isBurstModeOn;

            if (isBurstModeOn) {
                extraView.setVisibility(View.VISIBLE);
            } else {
                extraView.setVisibility(View.INVISIBLE);
            }
        }
    });
}

From source file:org.skia.viewer.ViewerActivity.java

@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
    if (mApplication.getNativeHandle() != 0) {
        onSurfaceChanged(mApplication.getNativeHandle(), holder.getSurface());
    }// w  w w.ja  va2 s  .c o m
}

From source file:com.c77.androidstreamingclient.lib.RtpMediaDecoder.java

@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
    if (playerThread == null) {
        playerThread = new PlayerThread(holder.getSurface());
        playerThread.start();/*from w ww.jav a  2s.c om*/
    }
}

From source file:uk.ac.horizon.artcodes.camera.CameraView.java

private void init() {
    getHolder().addCallback(new SurfaceHolder.Callback() {
        @Override/*from w ww .java2  s . co  m*/
        public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
            if (holder.getSurface() == null) {
                Log.i("scanner", "No surface?");
                return;
            }
            surface = holder;
            stopCamera();
            surfaceWidth = width;
            surfaceHeight = height;
            startCamera();
        }

        @Override
        public void surfaceCreated(SurfaceHolder holder) {
        }

        @Override
        public void surfaceDestroyed(SurfaceHolder holder) {
            stopCamera();
        }
    });
}

From source file:com.c77.androidstreamingclient.lib.rtp.RtpMediaDecoder.java

/**
 * Starts playing video when surface view is ready
 *
 * @param holder//  w  w  w . jav a2  s  .  c om
 * @param format
 * @param width
 * @param height
 */
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
    if (playerThread == null) {
        playerThread = new PlayerThread(holder.getSurface());
        playerThread.start();
    }
}

From source file:br.com.skylane.voicer.rtp.RtpMediaDecoder.java

/**
 * Starts playing video when surface view is ready
 *
 * @param holder// w  w w.j a  va  2 s. com
 * @param format
 * @param width
 * @param height
 */
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
    if (playerThread == null) {
        playerThread = new PlayerThread(holder.getSurface());
        playerThread.setName("Received Video Thread");
        playerThread.start();
    }
}

From source file:wseemann.media.demo.FMMRFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    // Give some text to display if there is no data.  In a real
    // application this would come from a resource.
    setEmptyText(getString(R.string.no_metadata));

    View header = getLayoutInflater(savedInstanceState).inflate(R.layout.header, null);
    mImage = (ImageView) header.findViewById(R.id.image);

    // set up the Surface video sink
    mmSurfaceView = (SurfaceView) header.findViewById(R.id.surfaceview);
    mSurfaceHolder = mmSurfaceView.getHolder();

    mSurfaceHolder.addCallback(new SurfaceHolder.Callback() {

        public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
            Log.v("TAG", "surfaceChanged format=" + format + ", width=" + width + ", height=" + height);
        }/*from   w  w  w.  j av a 2 s  .  c o m*/

        public void surfaceCreated(SurfaceHolder holder) {
            mFinalSurface = holder.getSurface();

            final EditText uriText = (EditText) getView().findViewById(R.id.uri);

            // Clear the error message
            uriText.setError(null);

            // Hide the keyboard
            InputMethodManager imm = (InputMethodManager) FMMRFragment.this.getActivity()
                    .getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(uriText.getWindowToken(), 0);

            String uri = uriText.getText().toString();

            if (uri.equals("")) {
                uriText.setError(getString(R.string.uri_error));
                return;
            }

            String view = PreferenceManager.getDefaultSharedPreferences(getActivity())
                    .getString("pref_displaytype", "ImageView");

            // Start out with a progress indicator.
            setListShown(false);

            String uriString = uriText.getText().toString();

            Bundle bundle = new Bundle();
            try {
                bundle.putString("uri", URLDecoder.decode(uriString, "UTF-8"));
                mId++;
                //FMMRFragment.this.getLoaderManager().initLoader(mId, bundle, FMMRFragment.this);
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
        }

        public void surfaceDestroyed(SurfaceHolder holder) {
            Log.v("TAG", "surfaceDestroyed");
        }

    });

    getListView().addHeaderView(header);

    if (mAdapter == null) {
        // Create an empty adapter we will use to display the loaded data.
        mAdapter = new MetadataListAdapter(getActivity());
        setListAdapter(mAdapter);
    } else {
        setListAdapter(mAdapter);

        // Start out with a progress indicator.
        setListShown(false);

        // Prepare the loader.  Either re-connect with an existing one,
        // or start a new one.
        getLoaderManager().initLoader(mId, new Bundle(), this);
    }
}