Search in sources :

Example 1 with AspectRatio

use of com.google.android.cameraview.AspectRatio in project cameraview by google.

the class AspectRatioFragment method onCreateDialog.

@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    final Bundle args = getArguments();
    final AspectRatio[] ratios = (AspectRatio[]) args.getParcelableArray(ARG_ASPECT_RATIOS);
    if (ratios == null) {
        throw new RuntimeException("No ratios");
    }
    final AspectRatio current = args.getParcelable(ARG_CURRENT_ASPECT_RATIO);
    final AspectRatioAdapter adapter = new AspectRatioAdapter(ratios, current);
    return new AlertDialog.Builder(getActivity()).setAdapter(adapter, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int position) {
            mListener.onAspectRatioSelected(ratios[position]);
        }
    }).create();
}
Also used : AspectRatio(com.google.android.cameraview.AspectRatio) DialogInterface(android.content.DialogInterface) Bundle(android.os.Bundle) NonNull(android.support.annotation.NonNull)

Example 2 with AspectRatio

use of com.google.android.cameraview.AspectRatio in project cameraview by google.

the class MainActivity method onOptionsItemSelected.

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch(item.getItemId()) {
        case R.id.aspect_ratio:
            if (mCameraView != null) {
                final Set<AspectRatio> ratios = mCameraView.getSupportedAspectRatios();
                final AspectRatio currentRatio = mCameraView.getAspectRatio();
                AspectRatioFragment.newInstance(ratios, currentRatio).show(getSupportFragmentManager(), FRAGMENT_DIALOG);
            }
            break;
        case R.id.switch_flash:
            if (mCameraView != null) {
                mCurrentFlash = (mCurrentFlash + 1) % FLASH_OPTIONS.length;
                item.setTitle(FLASH_TITLES[mCurrentFlash]);
                item.setIcon(FLASH_ICONS[mCurrentFlash]);
                mCameraView.setFlash(FLASH_OPTIONS[mCurrentFlash]);
            }
            break;
        case R.id.switch_camera:
            if (mCameraView != null) {
                int facing = mCameraView.getFacing();
                mCameraView.setFacing(facing == CameraView.FACING_FRONT ? CameraView.FACING_BACK : CameraView.FACING_FRONT);
            }
            break;
    }
    return false;
}
Also used : AspectRatio(com.google.android.cameraview.AspectRatio)

Example 3 with AspectRatio

use of com.google.android.cameraview.AspectRatio in project cameraview by google.

the class AspectRatioFragment method newInstance.

public static AspectRatioFragment newInstance(Set<AspectRatio> ratios, AspectRatio currentRatio) {
    final AspectRatioFragment fragment = new AspectRatioFragment();
    final Bundle args = new Bundle();
    args.putParcelableArray(ARG_ASPECT_RATIOS, ratios.toArray(new AspectRatio[ratios.size()]));
    args.putParcelable(ARG_CURRENT_ASPECT_RATIO, currentRatio);
    fragment.setArguments(args);
    return fragment;
}
Also used : AspectRatio(com.google.android.cameraview.AspectRatio) Bundle(android.os.Bundle)

Aggregations

AspectRatio (com.google.android.cameraview.AspectRatio)3 Bundle (android.os.Bundle)2 DialogInterface (android.content.DialogInterface)1 NonNull (android.support.annotation.NonNull)1