Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.three_embed.com.starmenew.Fragment_Manager.PostNewFragments;
- import android.Manifest;
- import android.animation.Animator;
- import android.animation.AnimatorListenerAdapter;
- import android.animation.AnimatorSet;
- import android.animation.ObjectAnimator;
- import android.annotation.SuppressLint;
- import android.app.Activity;
- import android.content.Context;
- import android.content.Intent;
- import android.content.pm.PackageManager;
- import android.content.res.Configuration;
- import android.graphics.ImageFormat;
- import android.graphics.Matrix;
- import android.graphics.Point;
- import android.graphics.RectF;
- import android.graphics.SurfaceTexture;
- import android.hardware.camera2.CameraAccessException;
- import android.hardware.camera2.CameraCaptureSession;
- import android.hardware.camera2.CameraCharacteristics;
- import android.hardware.camera2.CameraDevice;
- import android.hardware.camera2.CameraManager;
- import android.hardware.camera2.CameraMetadata;
- import android.hardware.camera2.CaptureRequest;
- import android.hardware.camera2.CaptureResult;
- import android.hardware.camera2.TotalCaptureResult;
- import android.hardware.camera2.params.StreamConfigurationMap;
- import android.media.Image;
- import android.media.ImageReader;
- import android.media.MediaRecorder;
- import android.net.Uri;
- import android.os.Build;
- import android.os.Bundle;
- import android.os.Handler;
- import android.os.HandlerThread;
- import android.provider.Settings;
- import android.support.annotation.NonNull;
- import android.support.annotation.RequiresApi;
- import android.support.v4.app.Fragment;
- import android.support.v4.content.ContextCompat;
- import android.support.v4.view.ViewPager;
- import android.util.Size;
- import android.util.SparseIntArray;
- import android.view.LayoutInflater;
- import android.view.Surface;
- import android.view.TextureView;
- import android.view.View;
- import android.view.ViewGroup;
- import android.view.animation.AccelerateInterpolator;
- import android.view.animation.Animation;
- import android.view.animation.AnimationUtils;
- import android.view.animation.DecelerateInterpolator;
- import android.view.animation.Interpolator;
- import android.widget.Button;
- import android.widget.ImageView;
- import android.widget.ProgressBar;
- import android.widget.RelativeLayout;
- import android.widget.TextView;
- import android.widget.Toast;
- import com.three_embed.com.starmenew.Activity_Manager.PostNewActivity;
- import com.three_embed.com.starmenew.Adpater_classes.Post_view_fake_pager_adp;
- import com.three_embed.com.starmenew.Camera_handler.AutoFitTextureView;
- import com.three_embed.com.starmenew.CommonClasses.Utility;
- import com.three_embed.com.starmenew.Coustom_scroll_view.Fake_pager_scroll_view;
- import com.three_embed.com.starmenew.Interface_Manager.Camera_Flash;
- import com.three_embed.com.starmenew.Permission_Ap23.App_permission_23;
- import com.three_embed.com.starmenew.R;
- import com.three_embed.com.starmenew.Songplayer.UAudioRecorder.AudioRecordingHandler;
- import com.three_embed.com.starmenew.Songplayer.UAudioRecorder.UAudioRecorder;
- import com.three_embed.com.starmenew.Songplayer.MovieCreator.UMediaRecorder;
- import com.videocompressor.com.File_merger;
- import java.io.File;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import java.nio.ByteBuffer;
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.Collections;
- import java.util.Comparator;
- import java.util.List;
- import java.util.Locale;
- import java.util.Timer;
- import java.util.TimerTask;
- import java.util.concurrent.Semaphore;
- import java.util.concurrent.TimeUnit;
- /**
- * <h2>CameraFragment_Ap21</h2>
- * A simple {@link Fragment} subclass.
- * Use the {@link CameraFragment_Ap21#newInstance} factory method to
- * create an instance of this fragment.
- */
- @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
- public class CameraFragment_Ap21 extends Fragment implements View.OnClickListener,App_permission_23.Permission_Callback
- {
- private PostNewActivity postNewActivity;
- private Activity parentactivity;
- File tempVideo;
- private static final SparseIntArray ORIENTATIONS = new SparseIntArray();
- private static final SparseIntArray DEFAULT_ORIENTATIONS = new SparseIntArray();
- private static final SparseIntArray INVERSE_ORIENTATIONS = new SparseIntArray();
- private static final int SENSOR_ORIENTATION_DEFAULT_DEGREES = 90;
- private static final int SENSOR_ORIENTATION_INVERSE_DEGREES = 270;
- static
- {
- ORIENTATIONS.append(Surface.ROTATION_0, 90);
- ORIENTATIONS.append(Surface.ROTATION_90, 0);
- ORIENTATIONS.append(Surface.ROTATION_180, 270);
- ORIENTATIONS.append(Surface.ROTATION_270, 180);
- }
- static
- {
- DEFAULT_ORIENTATIONS.append(Surface.ROTATION_0, 90);
- DEFAULT_ORIENTATIONS.append(Surface.ROTATION_90, 0);
- DEFAULT_ORIENTATIONS.append(Surface.ROTATION_180, 270);
- DEFAULT_ORIENTATIONS.append(Surface.ROTATION_270, 180);
- }
- static
- {
- INVERSE_ORIENTATIONS.append(Surface.ROTATION_0, 270);
- INVERSE_ORIENTATIONS.append(Surface.ROTATION_90, 180);
- INVERSE_ORIENTATIONS.append(Surface.ROTATION_180, 90);
- INVERSE_ORIENTATIONS.append(Surface.ROTATION_270, 0);
- }
- private static final int STATE_PREVIEW = 0;
- private static final int STATE_WAITING_LOCK = 1;
- private static final int STATE_WAITING_PRECAPTURE = 2;
- private static final int STATE_WAITING_NON_PRECAPTURE = 3;
- private static final int STATE_PICTURE_TAKEN = 4;
- private static final int MAX_PREVIEW_WIDTH = 2960;
- private static final int MAX_PREVIEW_HEIGHT = 1440;
- private String mNextVideoAbsolutePath;
- private ProgressBar record_progressBar;
- private TextView recorded_time;
- public String CAMERA_TAG="Camera_permission";
- public String RECORDER_TAG="Recorder_permission";
- private View mShutter;
- private RelativeLayout main_Camera_container,premission_denined,bottom_layout;
- private App_permission_23 app_permission_23;
- private static final Interpolator ACCELERATE_INTERPOLATOR = new AccelerateInterpolator();
- private static final Interpolator DECELERATE_INTERPOLATOR = new DecelerateInterpolator();
- private boolean isTurn_button_click=false;
- private Fake_pager_scroll_view fake_pager;
- private boolean isVideo_active=false;
- private String mCameraId= Camera_Flash.FACING_FRONT;
- private AutoFitTextureView mTextureView;
- private CameraCaptureSession mCaptureSession;
- private CameraDevice mCameraDevice;
- private Size mPreviewSize;
- private Size mVideoSize;
- private UMediaRecorder mMediaRecorder;
- private boolean mIsRecordingVideo;
- private HandlerThread mBackgroundThread;
- private Handler mBackgroundHandler;
- private ImageReader mImageReader;
- private int previous_recorded_time=0;
- private Timer timer;
- private ArrayList<String> record_file_paths;
- private boolean isRecord_file_exist=false;
- TextView userScoreTextView;
- private AudioRecordingHandler arh;
- private CameraFragmentActionListener listener;
- UAudioRecorder audioRecorder;
- /**
- * This a callback object for the {@link ImageReader}.
- * "onImageAvailable" will be called when a
- * still image is ready to be saved.
- */
- private boolean isForCapture=false;
- private final ImageReader.OnImageAvailableListener mOnImageAvailableListener = new ImageReader.OnImageAvailableListener() {
- @Override
- public void onImageAvailable(ImageReader reader)
- {
- if(!isForCapture) {
- isForCapture=true;
- mBackgroundHandler.post(new ImageSaver(reader.acquireNextImage()));
- }
- }
- };
- private CaptureRequest.Builder mPreviewRequestBuilder;
- private CaptureRequest mPreviewRequest;
- private int mState = STATE_PREVIEW;
- private Semaphore mCameraOpenCloseLock = new Semaphore(1);
- private boolean mFlashSupported;
- private int mSensorOrientation;
- private ImageView take_photo;
- private CameraManager manager;
- File finalOutFile;
- File aacfile;
- /**
- * Shows a {@link Toast} on the UI thread.
- * @param text The message to show
- */
- private void showToast(final String text)
- {
- if (parentactivity!= null)
- {
- parentactivity.runOnUiThread(new Runnable() {
- @Override
- public void run() {
- Toast.makeText(parentactivity, text, Toast.LENGTH_SHORT).show();
- }
- });
- }
- }
- public CameraFragment_Ap21()
- {}
- /**
- * Use this factory method to create a new instance of
- * this fragment using the provided parameters.
- * @param param1 Parameter 1.
- * @param param2 Parameter 2.
- * @return A new instance of fragment CameraFragment_Ap21.
- */
- public static CameraFragment_Ap21 newInstance(String param1, String param2)
- {
- return new CameraFragment_Ap21();
- }
- @Override
- public void onCreate(Bundle savedInstanceState)
- {
- super.onCreate(savedInstanceState);
- parentactivity = getActivity();
- record_file_paths = new ArrayList<>();
- postNewActivity = (PostNewActivity) parentactivity;
- app_permission_23= App_permission_23.getInstance();
- manager = (CameraManager)parentactivity.getSystemService(Context.CAMERA_SERVICE);
- }
- @Override
- public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
- View view=inflater.inflate(R.layout.fragment_camera_fragment__ap21, container, false);
- init_xml_content(view);
- return view;
- }
- private void init_xml_content(View view)
- {
- fake_pager= view.findViewById(R.id.fake_pager);
- handel_Fake_pager();
- //main_Camera_container= view.findViewById(R.id.main_Camera_container);
- premission_denined= view.findViewById(R.id.premission_denined);
- //bottom_layout= view.findViewById(R.id.bottom_layout);
- mTextureView = view.findViewById(R.id.mCameraPhotoView);
- record_progressBar= view.findViewById(R.id.record_progressBar);
- take_photo = view.findViewById(R.id.take_photo);
- take_photo.setOnClickListener(this);
- mShutter=view.findViewById(R.id.mShutter);
- Button turn_on_button = view.findViewById(R.id.turn_on_button);
- turn_on_button.setOnClickListener(this);
- TextView sub_title = view.findViewById(R.id.sub_title);
- sub_title.setTypeface(postNewActivity.RobotoRegular);
- TextView top_title = view.findViewById(R.id.top_title);
- top_title.setTypeface(postNewActivity.RobotoBold);
- recorded_time = view.findViewById(R.id.recorded_time);
- recorded_time.setTypeface(postNewActivity.RobotoRegular);
- userScoreTextView = view.findViewById(R.id.user_score_text);
- audioRecorder = new UAudioRecorder(getContext());
- }
- /**
- * {@link TextureView.SurfaceTextureListener} handles several lifecycle events on a
- * {@link TextureView}.
- */
- private final TextureView.SurfaceTextureListener mSurfaceTextureListener = new TextureView.SurfaceTextureListener()
- {
- @Override
- public void onSurfaceTextureAvailable(SurfaceTexture texture, int width, int height)
- {
- openCamera(width, height);
- }
- @Override
- public void onSurfaceTextureSizeChanged(SurfaceTexture texture, int width, int height)
- {
- configureTransform(width, height);
- }
- @Override
- public boolean onSurfaceTextureDestroyed(SurfaceTexture texture)
- {
- return true;
- }
- @Override
- public void onSurfaceTextureUpdated(SurfaceTexture texture)
- {}
- };
- private CameraCaptureSession.CaptureCallback mCaptureCallback=new CameraCaptureSession.CaptureCallback()
- {
- private void process(CaptureResult result)
- {
- switch (mState) {
- case STATE_PREVIEW: {
- break;
- }
- case STATE_WAITING_LOCK: {
- Integer afState = result.get(CaptureResult.CONTROL_AF_STATE);
- if (afState == null) {
- captureStillPicture();
- } else if (CaptureResult.CONTROL_AF_STATE_FOCUSED_LOCKED == afState ||
- CaptureResult.CONTROL_AF_STATE_NOT_FOCUSED_LOCKED == afState)
- {
- Integer aeState = result.get(CaptureResult.CONTROL_AE_STATE);
- if (aeState == null ||
- aeState == CaptureResult.CONTROL_AE_STATE_CONVERGED) {
- mState = STATE_PICTURE_TAKEN;
- captureStillPicture();
- } else {
- runPrecaptureSequence();
- }
- }
- break;
- }
- case STATE_WAITING_PRECAPTURE:
- {
- Integer aeState = result.get(CaptureResult.CONTROL_AE_STATE);
- if (aeState == null ||
- aeState == CaptureResult.CONTROL_AE_STATE_PRECAPTURE ||
- aeState == CaptureRequest.CONTROL_AE_STATE_FLASH_REQUIRED) {
- mState = STATE_WAITING_NON_PRECAPTURE;
- }
- break;
- }
- case STATE_WAITING_NON_PRECAPTURE:
- {
- Integer aeState = result.get(CaptureResult.CONTROL_AE_STATE);
- if (aeState == null || aeState != CaptureResult.CONTROL_AE_STATE_PRECAPTURE) {
- mState = STATE_PICTURE_TAKEN;
- captureStillPicture();
- }
- break;
- }
- }
- }
- @Override
- public void onCaptureProgressed(@NonNull CameraCaptureSession session,
- @NonNull CaptureRequest request,
- @NonNull CaptureResult partialResult) {
- process(partialResult);
- }
- @Override
- public void onCaptureCompleted(@NonNull CameraCaptureSession session,
- @NonNull CaptureRequest request,
- @NonNull TotalCaptureResult result)
- {
- process(result);
- }
- };
- private final CameraDevice.StateCallback mStateCallback = new CameraDevice.StateCallback()
- {
- @Override
- public void onOpened(@NonNull CameraDevice cameraDevice)
- {
- mCameraOpenCloseLock.release();
- mCameraDevice = cameraDevice;
- createCameraPreviewSession();
- }
- @Override
- public void onDisconnected(@NonNull CameraDevice cameraDevice)
- {
- mCameraOpenCloseLock.release();
- cameraDevice.close();
- mCameraDevice = null;
- }
- @Override
- public void onError(@NonNull CameraDevice cameraDevice, int error)
- {
- mCameraOpenCloseLock.release();
- cameraDevice.close();
- mCameraDevice = null;
- if (null != parentactivity)
- {
- parentactivity.finish();
- }
- }
- };
- /**
- * Given {@code choices} of {@code Size}s supported by a camera, choose the smallest one that
- * is at least as large as the respective texture view size, and that is at most as large as the
- * respective max size, and whose aspect ratio matches with the specified value. If such size
- * doesn't exist, choose the largest one that is at most as large as the respective max size,
- * and whose aspect ratio matches with the specified value.
- *
- * @param choices The list of sizes that the camera supports for the intended output
- * class
- * @param textureViewWidth The width of the texture view relative to sensor coordinate
- * @param textureViewHeight The height of the texture view relative to sensor coordinate
- * @param maxWidth The maximum width that can be chosen
- * @param maxHeight The maximum height that can be chosen
- * @param aspectRatio The aspect ratio
- * @return The optimal {@code Size}, or an arbitrary one if none were big enough
- */
- private static Size chooseOptimalSize(Size[] choices, int textureViewWidth, int textureViewHeight, int maxWidth, int maxHeight, Size aspectRatio)
- {
- List<Size> bigEnough = new ArrayList<>();
- List<Size> notBigEnough = new ArrayList<>();
- int w = aspectRatio.getWidth();
- int h = aspectRatio.getHeight();
- for (Size option : choices) {
- if (option.getWidth() <= maxWidth && option.getHeight() <= maxHeight &&
- option.getHeight() == option.getWidth() * h / w) {
- if (option.getWidth() >= textureViewWidth &&
- option.getHeight() >= textureViewHeight) {
- bigEnough.add(option);
- } else {
- notBigEnough.add(option);
- }
- }
- }
- if (bigEnough.size() > 0)
- {
- return Collections.min(bigEnough, new CompareSizesByArea());
- } else if (notBigEnough.size() > 0)
- {
- return Collections.max(notBigEnough, new CompareSizesByArea());
- } else
- {
- return choices[0];
- }
- }
- /**
- * Given {@code choices} of {@code Size}s supported by a camera, chooses the smallest one whose
- * width and height are at least as large as the respective requested values, and whose aspect
- * ratio matches with the specified value.
- *
- * @param choices The list of sizes that the camera supports for the intended output class
- * @param width The minimum desired width
- * @param height The minimum desired height
- * @param aspectRatio The aspect ratio
- * @return The optimal {@code Size}, or an arbitrary one if none were big enough
- */
- private static Size chooseOptimalSize(Size[] choices, int width, int height, Size aspectRatio) {
- List<Size> bigEnough = new ArrayList<>();
- int w = aspectRatio.getWidth();
- int h = aspectRatio.getHeight();
- for (Size option : choices) {
- if (option.getHeight() == option.getWidth() * h / w &&
- option.getWidth() >= width && option.getHeight() >= height) {
- bigEnough.add(option);
- }
- }
- if (bigEnough.size() > 0) {
- return Collections.min(bigEnough, new CompareSizesByArea());
- } else {
- return choices[0];
- }
- }
- @Override
- public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults)
- {
- app_permission_23.onRequestPermissionsResult(requestCode,permissions,grantResults);
- }
- @Override
- public void onResume()
- {
- super.onResume();
- if (postNewActivity.isCameraPermissionGranted) {
- startBackgroundThread();
- if (mTextureView.isAvailable()) {
- openCamera(mTextureView.getWidth(), mTextureView.getHeight());
- } else {
- mTextureView.setSurfaceTextureListener(mSurfaceTextureListener);
- }
- } else {
- permission_layout_handeler(false);
- }
- }
- @Override
- public void onPause()
- {
- if (timer != null)
- {
- timer.cancel();
- }
- stopRecordingVideo();
- closeCamera();
- stopBackgroundThread();
- super.onPause();
- }
- @Override
- public void onStop()
- {
- if (timer != null) {
- timer.cancel();
- }
- stopRecordingVideo();
- closeCamera();
- stopBackgroundThread();
- super.onStop();
- }
- @Override
- public void onDestroy()
- {
- if (timer != null) {
- timer.cancel();
- }
- stopRecordingVideo();
- closeCamera();
- stopBackgroundThread();
- super.onDestroy();
- }
- @Override
- public void onDetach() {
- if (timer != null) {
- timer.cancel();
- }
- super.onDetach();
- }
- public void handel_button_Selected(boolean isSelected) {
- //take_photo.setSelected(isSelected);
- }
- public void handel_Video_view(boolean isAcive) {
- if(isAcive) {
- record_progressBar.setVisibility(View.VISIBLE);
- } else {
- record_progressBar.setVisibility(View.INVISIBLE);
- recorded_time.setVisibility(View.INVISIBLE);
- }
- }
- /**
- * <h2>permission_visibality</h2>
- * <P>
- * Handel all the layout visibality.
- * </P>
- * @param isPermission_granted contains flag that tell permission is granted or not.
- * */
- private void permission_layout_handeler(boolean isPermission_granted)
- {
- if(isPermission_granted)
- {
- postNewActivity.isCameraPermissionGranted =true;
- //main_Camera_container.setVisibility(View.VISIBLE);
- //bottom_layout.setVisibility(View.VISIBLE);
- premission_denined.setVisibility(View.GONE);
- }else
- {
- postNewActivity.isCameraPermissionGranted =false;
- //main_Camera_container.setVisibility(View.GONE);
- //bottom_layout.setVisibility(View.GONE);
- premission_denined.setVisibility(View.VISIBLE);
- }
- }
- /**
- * <h2>reopenCamera</h2>
- * <P>
- * Reopening the camera on switch of the camera.
- * </P>*/
- public void reopenCamera()
- {
- if (mTextureView.isAvailable())
- {
- openCamera(mTextureView.getWidth(), mTextureView.getHeight());
- } else
- {
- mTextureView.setSurfaceTextureListener(mSurfaceTextureListener);
- }
- }
- /**
- * <h2>askFor_Phone_Permission</h2>
- * <P>
- * Method is going to ask for phone permission .
- * it is required for the read phone state in android.
- * </P>*/
- public void askFor_Phone_Permission(String tag)
- {
- ArrayList<App_permission_23.Permission> permissions =new ArrayList<>();
- App_permission_23.askWriteExternalStoragePermission(getActivity());
- System.out.println(tag.equalsIgnoreCase(CAMERA_TAG));
- if(tag.equalsIgnoreCase(CAMERA_TAG))
- {
- permissions.add(App_permission_23.Permission.CAMERA);
- app_permission_23.getPermission_for_Sup_v4Fragment(CAMERA_TAG,permissions,parentactivity,this,this);
- }else if(tag.equalsIgnoreCase(RECORDER_TAG))
- {
- permissions.add(App_permission_23.Permission.CAMERA);
- permissions.add(App_permission_23.Permission.RECORD_AUDIO);
- permissions.add(App_permission_23.Permission.WRITE_EXTERNAL_STORAGE);
- app_permission_23.getPermission_for_Sup_v4Fragment(CAMERA_TAG,permissions,parentactivity,this,this);
- }
- }
- /**
- * Sets up member variables related to camera.
- * @param width The width of available size for camera preview
- * @param height The height of available size for camera preview
- */
- private void setUpCameraOutputs(int width, int height) {
- System.out.println("Setup camera outputs.");
- try {
- CameraCharacteristics characteristics = manager.getCameraCharacteristics(mCameraId);
- StreamConfigurationMap map = characteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
- assert map != null;
- Size largest = Collections.max(
- Arrays.asList(map.getOutputSizes(ImageFormat.JPEG)),
- new CompareSizesByArea());
- mVideoSize = chooseVideoSize(map.getOutputSizes(MediaRecorder.class)); //640x480
- mPreviewSize = chooseOptimalSize(map.getOutputSizes(SurfaceTexture.class),
- width, height, mVideoSize);
- mImageReader = ImageReader.newInstance(largest.getWidth(), largest.getHeight(),
- ImageFormat.JPEG, /*maxImages*/2);
- mImageReader.setOnImageAvailableListener(mOnImageAvailableListener, mBackgroundHandler);
- int displayRotation =parentactivity.getWindowManager().getDefaultDisplay().getRotation();
- mSensorOrientation = characteristics.get(CameraCharacteristics.SENSOR_ORIENTATION);
- boolean swappedDimensions = false;
- switch (displayRotation) {
- case Surface.ROTATION_0:
- case Surface.ROTATION_180:
- if (mSensorOrientation == 90 || mSensorOrientation == 270)
- {
- swappedDimensions = true;
- }
- break;
- case Surface.ROTATION_90:
- case Surface.ROTATION_270:
- if (mSensorOrientation == 0 || mSensorOrientation == 180)
- {
- swappedDimensions = true;
- }
- break;
- default:
- }
- Point displaySize = new Point();
- parentactivity.getWindowManager().getDefaultDisplay().getSize(displaySize);
- int rotatedPreviewWidth = width;
- int rotatedPreviewHeight = height;
- int maxPreviewWidth = displaySize.x;
- int maxPreviewHeight = displaySize.y;
- if (swappedDimensions) {
- rotatedPreviewWidth = height;
- rotatedPreviewHeight = width;
- maxPreviewWidth = displaySize.y;
- maxPreviewHeight = displaySize.x;
- }
- if (maxPreviewWidth > MAX_PREVIEW_WIDTH) {
- maxPreviewWidth = MAX_PREVIEW_WIDTH;
- }
- if (maxPreviewHeight > MAX_PREVIEW_HEIGHT) {
- maxPreviewHeight = MAX_PREVIEW_HEIGHT;
- }
- mPreviewSize = chooseOptimalSize(map.getOutputSizes(SurfaceTexture.class),
- rotatedPreviewWidth, rotatedPreviewHeight, maxPreviewWidth,
- maxPreviewHeight, mVideoSize);
- int orientation = getResources().getConfiguration().orientation;
- if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
- mTextureView.setAspectRatio(mPreviewSize.getWidth(), mPreviewSize.getHeight());
- } else {
- mTextureView.setAspectRatio(mPreviewSize.getHeight(), mPreviewSize.getWidth());
- }
- Boolean available = characteristics.get(CameraCharacteristics.FLASH_INFO_AVAILABLE);
- mFlashSupported = available == null ? false : available;
- } catch (IllegalArgumentException e) {
- e.printStackTrace();
- }
- catch (CameraAccessException | NullPointerException e) {
- e.printStackTrace();
- }
- }
- /**
- * Opens the camera specified by {@link CameraFragment_Ap21#mCameraId}.
- */
- private void openCamera(int width, int height)
- {
- if (ContextCompat.checkSelfPermission(parentactivity, Manifest.permission.CAMERA)
- != PackageManager.PERMISSION_GRANTED) {
- System.out.println("Camera rights not allowed!");
- return;
- }
- setUpCameraOutputs(width, height);
- configureTransform(width, height);
- try {
- if (!mCameraOpenCloseLock.tryAcquire(5000, TimeUnit.MILLISECONDS))
- {
- throw new RuntimeException("Time out waiting to lock camera opening.");
- }
- manager.openCamera(mCameraId, mStateCallback, mBackgroundHandler);
- } catch (CameraAccessException e) {
- e.printStackTrace();
- } catch (InterruptedException e) {
- throw new RuntimeException("Interrupted while trying to lock camera opening.", e);
- }
- }
- /*
- * handling the pager using object.*/
- public void scrollFake_pager(int position)
- {
- if(fake_pager!=null)
- {
- fake_pager.setCurrentItem(position,true);
- }
- }
- /**
- * <h2>handel_Fake_pager</h2>
- * <P>
- * Handel the camera to video tab movement in .
- * like Instagaram.
- * </P>*/
- private void handel_Fake_pager()
- {
- Post_view_fake_pager_adp fake_pager_adp = new Post_view_fake_pager_adp(getChildFragmentManager());
- fake_pager.setAdapter(fake_pager_adp);
- fake_pager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
- @Override
- public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels)
- {
- postNewActivity.handelTab_Scroll(position+1,positionOffset);
- }
- @Override
- public void onPageSelected(int position)
- {
- isVideo_active = position == 1;
- postNewActivity.page_position=position+1;
- postNewActivity.handel_Page_selection( postNewActivity.page_position);
- }
- @Override
- public void onPageScrollStateChanged(int state) {}
- });
- }
- /**
- * Closes the current {@link CameraDevice}.
- */
- private void closeCamera()
- {
- try
- {
- mCameraOpenCloseLock.acquire();
- if (null != mCaptureSession)
- {
- mCaptureSession.close();
- mCaptureSession = null;
- }
- if (null != mCameraDevice)
- {
- mCameraDevice.close();
- mCameraDevice = null;
- }
- if (null != mMediaRecorder) {
- mMediaRecorder.release();
- mMediaRecorder = null;
- }
- if (null != mImageReader)
- {
- mImageReader.close();
- mImageReader = null;
- }
- } catch (Exception e)
- {
- e.printStackTrace();
- } finally
- {
- mCameraOpenCloseLock.release();
- }
- }
- /**
- * Starts a background thread and its {@link Handler}.
- */
- private void startBackgroundThread()
- {
- mBackgroundThread = new HandlerThread("StarMeCameraBackground");
- mBackgroundThread.start();
- mBackgroundHandler = new Handler(mBackgroundThread.getLooper());
- }
- /**
- * Stops the background thread and its {@link Handler}.
- */
- private void stopBackgroundThread()
- {
- if(mBackgroundThread!=null)
- {
- mBackgroundThread.quitSafely();
- }
- try {
- if(mBackgroundThread!=null)
- mBackgroundThread.join();
- mBackgroundThread = null;
- mBackgroundHandler = null;
- } catch (Exception e) {}
- }
- /**
- * Creates a new {@link CameraCaptureSession} for camera preview.
- */
- private void createCameraPreviewSession()
- {
- if (null == mCameraDevice || !mTextureView.isAvailable() || null == mPreviewSize) {
- return;
- }
- try
- {
- closePreviewSession();
- SurfaceTexture texture = mTextureView.getSurfaceTexture();
- assert texture != null;
- texture.setDefaultBufferSize(mPreviewSize.getWidth(), mPreviewSize.getHeight());
- Surface surface = new Surface(texture);
- mPreviewRequestBuilder = mCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW);
- mPreviewRequestBuilder.addTarget(surface);
- mCameraDevice.createCaptureSession(Arrays.asList(surface, mImageReader.getSurface()),
- new CameraCaptureSession.StateCallback() {
- @Override
- public void onConfigured(@NonNull CameraCaptureSession cameraCaptureSession)
- {
- if (null == mCameraDevice) {
- return;
- }
- mCaptureSession = cameraCaptureSession;
- try {
- mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_MODE,
- CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE);
- mPreviewRequest = mPreviewRequestBuilder.build();
- mCaptureSession.setRepeatingRequest(mPreviewRequest,
- mCaptureCallback, mBackgroundHandler);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- @Override
- public void onConfigureFailed(
- @NonNull CameraCaptureSession cameraCaptureSession)
- {
- showToast("Failed to configure camera.");
- }
- }, null
- );
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- /**
- * Configures the necessary {@link Matrix} transformation to `mTextureView`.
- * This method should be called after the camera preview size is determined in
- * setUpCameraOutputs and also the size of `mTextureView` is fixed.
- * @param viewWidth The width of `mTextureView`
- * @param viewHeight The height of `mTextureView`
- */
- private void configureTransform(int viewWidth, int viewHeight) {
- if (null == mTextureView || null == mPreviewSize || null == parentactivity) {
- return;
- }
- int rotation =parentactivity.getWindowManager().getDefaultDisplay().getRotation();
- Matrix matrix = new Matrix();
- RectF viewRect = new RectF(0, 0, viewWidth, viewHeight);
- RectF bufferRect = new RectF(0, 0, mPreviewSize.getHeight(), mPreviewSize.getWidth());
- float centerX = viewRect.centerX();
- float centerY = viewRect.centerY();
- if (Surface.ROTATION_90 == rotation || Surface.ROTATION_270 == rotation) {
- bufferRect.offset(centerX - bufferRect.centerX(), centerY - bufferRect.centerY());
- matrix.setRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.FILL);
- float scale = Math.max(
- (float) viewHeight / mPreviewSize.getHeight(),
- (float) viewWidth / mPreviewSize.getWidth());
- matrix.postScale(scale, scale, centerX, centerY);
- matrix.postRotate(90 * (rotation - 2), centerX, centerY);
- } else if (Surface.ROTATION_180 == rotation) {
- matrix.postRotate(180, centerX, centerY);
- }
- mTextureView.setTransform(matrix);
- }
- /**
- * Initiate a still image capture.
- */
- private void takePicture() {
- lockFocus();
- }
- /**
- * Lock the focus as the first step for a still image capture.
- */
- private void lockFocus()
- {
- try
- {
- mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER,
- CameraMetadata.CONTROL_AF_TRIGGER_START);
- mState = STATE_WAITING_LOCK;
- if(mCameraId.equals(Camera_Flash.FACING_BACK))
- {
- mCaptureSession.capture(mPreviewRequestBuilder.build(), mCaptureCallback,
- mBackgroundHandler);
- }else
- {
- captureStillPicture();
- }
- } catch (Exception e)
- {
- e.printStackTrace();
- }
- }
- /**
- * Run the precapture sequence for capturing a still image. This method should be called when
- * we get a response in {@link #mCaptureCallback} from {@link #lockFocus()}.
- */
- private void runPrecaptureSequence() {
- try {
- // This is how to tell the camera to trigger.
- mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AE_PRECAPTURE_TRIGGER,
- CaptureRequest.CONTROL_AE_PRECAPTURE_TRIGGER_START);
- // Tell #mCaptureCallback to wait for the precapture sequence to be set.
- mState = STATE_WAITING_PRECAPTURE;
- mCaptureSession.capture(mPreviewRequestBuilder.build(), mCaptureCallback,
- mBackgroundHandler);
- } catch (CameraAccessException e) {
- e.printStackTrace();
- }
- }
- /**
- * Capture a still picture. This method should be called when we get a response in
- * {@link #mCaptureCallback} from both {@link #lockFocus()}.
- */
- private void captureStillPicture() {
- try {
- if (null == parentactivity || null == mCameraDevice) {
- return;
- }
- final CaptureRequest.Builder captureBuilder =
- mCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE);
- captureBuilder.addTarget(mImageReader.getSurface());
- captureBuilder.set(CaptureRequest.CONTROL_AF_MODE,
- CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE);
- int rotation =parentactivity.getWindowManager().getDefaultDisplay().getRotation();
- captureBuilder.set(CaptureRequest.JPEG_ORIENTATION, getOrientation(rotation));
- CameraCaptureSession.CaptureCallback CaptureCallback = new CameraCaptureSession.CaptureCallback()
- {
- @Override
- public void onCaptureCompleted(@NonNull CameraCaptureSession session,
- @NonNull CaptureRequest request,
- @NonNull TotalCaptureResult result)
- {
- unlockFocus();
- }
- };
- mCaptureSession.stopRepeating();
- mCaptureSession.capture(captureBuilder.build(),CaptureCallback, null);
- unlockFocus();
- } catch (CameraAccessException e) {
- e.printStackTrace();
- }
- }
- /**
- * Retrieves the JPEG orientation from the specified screen rotation.
- *
- * @param rotation The screen rotation.
- * @return The JPEG orientation (one of 0, 90, 270, and 360)
- */
- private int getOrientation(int rotation) {
- // Sensor orientation is 90 for most devices, or 270 for some devices (eg. Nexus 5X)
- // We have to take that into account and rotate JPEG properly.
- // For devices with orientation of 90, we simply return our mapping from ORIENTATIONS.
- // For devices with orientation of 270, we need to rotate the JPEG 180 degrees.
- return (ORIENTATIONS.get(rotation) + mSensorOrientation + 270) % 360;
- }
- /**
- * Unlock the focus. This method should be called when still image capture sequence is
- * finished.
- */
- private void unlockFocus()
- {
- try {
- mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER,
- CameraMetadata.CONTROL_AF_TRIGGER_CANCEL);
- mCaptureSession.capture(mPreviewRequestBuilder.build(), mCaptureCallback,
- mBackgroundHandler);
- mState = STATE_PREVIEW;
- mCaptureSession.setRepeatingRequest(mPreviewRequest, mCaptureCallback, mBackgroundHandler);
- } catch (Exception e)
- {
- e.printStackTrace();
- }
- }
- @Override
- public void onClick(View view) {
- switch (view.getId()) {
- case R.id.take_photo:
- toggleRecording();
- take_photo.setEnabled(false);
- new Handler().postDelayed(new Runnable() {
- @Override
- public void run() {
- take_photo.setEnabled(true);
- }
- }, 3000);
- }
- }
- private void toggleRecording() {
- System.out.println("Toggle recording video: " + !mIsRecordingVideo);
- if (!mIsRecordingVideo) {
- handel_button_Selected(true);
- startRecordingVideo();
- }
- else {
- handel_button_Selected(false);
- stopRecordingVideo();
- }
- }
- /**
- * Start recording user input and translating it into pitches, uses 'TarsosDSP'
- */
- private void startRecordingUserInput() {
- System.out.println("Start recording audio...");
- audioRecorder.record(new AudioRecordingHandler() {
- @Override
- public void handlePitch(float pitch) {
- listener.onPitchChanged(pitch);
- }
- @Override
- public void finishedRecording(File aacFile) {
- System.out.println("Encoding finished!");
- aacfile = aacFile;
- }
- });
- System.out.println("...recording audio");
- }
- public void startRecordingVideo() {
- if (null == mCameraDevice || !mTextureView.isAvailable() || null == mPreviewSize) {
- return;
- }
- try {
- System.out.println("Start recording video...");
- closePreviewSession();
- setUpMediaRecorder();
- SurfaceTexture texture = mTextureView.getSurfaceTexture();
- assert texture != null;
- texture.setDefaultBufferSize(mPreviewSize.getWidth(), mPreviewSize.getHeight());
- mPreviewRequestBuilder = mCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_RECORD);
- Surface mRecorderSurface = mMediaRecorder.getSurface();
- List<Surface> surfaces = new ArrayList<>();
- Surface previewSurface = new Surface(texture);
- surfaces.add(previewSurface);
- mPreviewRequestBuilder.addTarget(previewSurface);
- surfaces.add(mRecorderSurface);
- mPreviewRequestBuilder.addTarget(mRecorderSurface);
- take_photo.setActivated(true);
- start_Timer();
- listener.onCameraRecording(); //Send out camera recording signal
- mCameraDevice.createCaptureSession(surfaces, new CameraCaptureSession.StateCallback() {
- @Override
- public void onReady(@NonNull CameraCaptureSession session) {
- System.out.println("Ready...");
- super.onReady(session);
- }
- @Override
- public void onConfigured(@NonNull CameraCaptureSession cameraCaptureSession) {
- mCaptureSession = cameraCaptureSession;
- updatePreview();
- parentactivity.runOnUiThread(new Runnable() {
- @Override
- public void run() {
- System.out.println("Start recording on UI Thread!");
- if(mNextVideoAbsolutePath!=null) {
- record_file_paths.add(mNextVideoAbsolutePath);
- }
- mIsRecordingVideo = true;
- mMediaRecorder.start();
- startRecordingUserInput();
- recorded_time.setVisibility(View.VISIBLE);
- handel_bottom_View(false);
- }
- });
- }
- @Override
- public void onConfigureFailed(@NonNull CameraCaptureSession cameraCaptureSession) {
- if (null != parentactivity) {
- Toast.makeText(parentactivity, "Failed to configure camera.", Toast.LENGTH_SHORT).show();
- }
- }
- }, mBackgroundHandler);
- } catch (CameraAccessException | IOException e) {
- e.printStackTrace();
- }
- }
- /**
- * Setup video recorder
- * @throws IOException
- */
- private void setUpMediaRecorder() throws IOException {
- if (null == parentactivity) {
- return;
- }
- mMediaRecorder = new UMediaRecorder();
- mMediaRecorder.setStateListener(new UMediaRecorder.UMediaRecorderStateListener() {
- @Override
- public void onStop() {
- }
- });
- mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.SURFACE);
- mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
- mNextVideoAbsolutePath = getVideoFilePath();
- mMediaRecorder.setOutputFile(mNextVideoAbsolutePath);
- mMediaRecorder.setVideoFrameRate(30);
- mMediaRecorder.setVideoEncodingBitRate(500000); //Recomennded 500k
- mMediaRecorder.setVideoSize(mVideoSize.getWidth(), mVideoSize.getHeight());
- mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
- int rotation = parentactivity.getWindowManager().getDefaultDisplay().getRotation();
- switch (mSensorOrientation) {
- case SENSOR_ORIENTATION_DEFAULT_DEGREES:
- mMediaRecorder.setOrientationHint(DEFAULT_ORIENTATIONS.get(rotation));
- break;
- case SENSOR_ORIENTATION_INVERSE_DEGREES:
- mMediaRecorder.setOrientationHint(INVERSE_ORIENTATIONS.get(rotation));
- break;
- }
- try {
- mMediaRecorder.prepare();
- } catch (IllegalStateException ex) {
- ex.printStackTrace();
- }
- }
- public void stopRecordingVideo() {
- stop_record_Time();
- if(!mIsRecordingVideo) { return; }
- mIsRecordingVideo = false;
- System.out.println("Stop video recording.");
- take_photo.setActivated(false);
- try {
- audioRecorder.stop();
- mCaptureSession.stopRepeating();
- mCaptureSession.abortCaptures();
- mMediaRecorder.stop();
- mMediaRecorder.release();
- closeCamera();
- tempVideo = new File(mNextVideoAbsolutePath);
- System.out.println("Final video length: " + tempVideo.length());
- //mMediaRecorder.reset();
- listener.onCameraStop(tempVideo, aacfile, previous_recorded_time);
- } catch (Exception e) {
- System.out.println("Error stopping media recorder");
- e.printStackTrace();
- }
- mNextVideoAbsolutePath = null;
- // closeCamera();
- if (mTextureView.isAvailable()) {
- //openCamera(mTextureView.getWidth(), mTextureView.getHeight());
- } else {
- //handel else part
- }
- }
- private String getVideoFilePath() {
- File file = postNewActivity.folder_handler.createFile_for_Video();
- return file.getPath();
- }
- /**
- * Update the camera preview. {@link} needs to be called in advance.
- */
- private void updatePreview() {
- if (null == mCameraDevice) {
- return;
- }
- try {
- setUpCaptureRequestBuilder(mPreviewRequestBuilder);
- mCaptureSession.setRepeatingRequest(mPreviewRequestBuilder.build(), null, mBackgroundHandler);
- } catch (CameraAccessException e) {
- e.printStackTrace();
- }
- }
- private void setUpCaptureRequestBuilder(CaptureRequest.Builder builder) {
- builder.set(CaptureRequest.CONTROL_MODE, CameraMetadata.CONTROL_MODE_AUTO);
- }
- private void closePreviewSession() {
- if (mCaptureSession != null) {
- mCaptureSession.close();
- mCaptureSession = null;
- }
- }
- /**
- * In this sample, we choose a video size with 3x4 aspect ratio. Also, we don't use sizes
- * larger than 1080p, since MediaRecorder cannot handle such a high-resolution video.
- *
- * @param choices The list of available sizes
- * @return The video size
- */
- private static Size chooseVideoSize(Size[] choices)
- {
- for (Size size : choices) {
- if (size.getWidth() == size.getHeight() * 4 / 3 && size.getWidth() <= 720) {
- return size;
- }
- }
- return choices[choices.length - 1];
- }
- @Override
- public void onPermissionGranted(boolean isAllGranted, String tag)
- {
- if(isAllGranted&&tag.equalsIgnoreCase(CAMERA_TAG))
- {
- permission_layout_handeler(true);
- }else if(isAllGranted&&tag.equalsIgnoreCase(RECORDER_TAG))
- {
- permission_layout_handeler(true);
- }
- }
- @Override
- public void onPermissionDenied(ArrayList<String> deniedPermission, String tag)
- {
- String[] stringArray = deniedPermission.toArray(new String[0]);
- if(tag.equalsIgnoreCase(CAMERA_TAG))
- {
- app_permission_23.ask_permission_directory(stringArray);
- }else if(tag.equalsIgnoreCase(RECORDER_TAG))
- {
- app_permission_23.ask_permission_directory(stringArray);
- }
- }
- @Override
- public void onPermissionRotation(ArrayList<String> rotationPermission, String tag)
- {
- isTurn_button_click=false;
- String[] permission = rotationPermission.toArray(new String[0]);
- app_permission_23.ask_permission_rotational(permission);
- }
- @Override
- public void onPermissionPermanent_Denied(String tag)
- {
- if(tag.equalsIgnoreCase(CAMERA_TAG)||tag.equalsIgnoreCase(RECORDER_TAG))
- {
- if(isTurn_button_click)
- {
- open_Setting_dialog();
- }else
- {
- permission_layout_handeler(false);
- }
- isTurn_button_click=false;
- }
- }
- public void handel_Operation(int op_number)
- {
- switch (op_number)
- {
- case 0:
- {
- takePicture();
- break;
- }
- case 1:
- {
- isTurn_button_click=true;
- if(isVideo_active)
- {
- askFor_Phone_Permission(RECORDER_TAG);
- }else
- {
- askFor_Phone_Permission(CAMERA_TAG);
- }
- }
- }
- }
- /**
- * Saves a JPEG {@link Image} into the specified {@link File}.
- */
- private class ImageSaver implements Runnable
- {
- private final Image mImage;
- private final File mFile;
- ImageSaver(Image image) {
- mImage = image;
- mFile = postNewActivity.folder_handler.createFile_for_Image();
- }
- @Override
- public void run() {
- System.out.println("record image!");
- ByteBuffer buffer = mImage.getPlanes()[0].getBuffer();
- byte[] bytes = new byte[buffer.remaining()];
- buffer.get(bytes);
- FileOutputStream output = null;
- try {
- output = new FileOutputStream(mFile);
- output.write(bytes);
- } catch (IOException e)
- {
- e.printStackTrace();
- } finally
- {
- mImage.close();
- if (null != output)
- {
- try
- {
- output.close();
- } catch (IOException e)
- {
- e.printStackTrace();
- }}
- }
- openFilter(mFile);
- }
- }
- private void openFilter(File file) {
- isForCapture=false;
- if(file.exists()&&file.length()>10) {
- postNewActivity.nextClick(false,file.getPath());
- } else {
- Toast.makeText(parentactivity,"Unable to store Image",Toast.LENGTH_SHORT).show();
- }
- }
- /**
- * Compares two {@code Size}s based on their areas.
- */
- private static class CompareSizesByArea implements Comparator<Size> {
- @Override
- public int compare(Size lhs, Size rhs) {
- // We cast here to ensure the multiplications won't overflow
- return Long.signum((long) lhs.getWidth() * lhs.getHeight() -
- (long) rhs.getWidth() * rhs.getHeight());
- }
- }
- /**
- * Resets recording timer
- */
- private void resetRecordingTimer() {
- recorded_time.setText(String.format("0.%s", String.format(Locale.ENGLISH,"%02d", 0)));
- }
- /**
- * Starts video record timer.
- */
- private void start_Timer() {
- resetRecordingTimer();
- timer=new Timer();
- timer.schedule(new TimerTask() {
- @Override
- public void run() {
- parentactivity.runOnUiThread(new Runnable() {
- @Override
- public void run() {
- previous_recorded_time=previous_recorded_time+1;
- parentactivity.runOnUiThread(new Runnable() {
- @Override
- public void run() {
- record_progressBar.setProgress(previous_recorded_time);
- recorded_time.setText(String.format(secondsToString(previous_recorded_time)));
- }
- });
- }
- });
- }
- }, 0, 1000);
- }
- private void stop_record_Time() {
- if (timer != null) {
- timer.cancel();
- }
- }
- private String secondsToString(int pTime) {
- return String.format("%02d:%02d", pTime / 60, pTime % 60);
- }
- /*
- * deleting the video recorded file.*/
- public void delete_Recorded_file()
- {
- if(!isRecord_file_exist)
- {
- return;
- }
- for(String file_path: record_file_paths)
- {
- File file=new File(file_path);
- if(file.exists())
- {
- boolean deleted=file.delete();
- }
- }
- record_file_paths.clear();
- handel_bottom_View(true);
- }
- public void collect_Recorded_Videos()
- {
- if(record_file_paths.size()>0)
- {
- postNewActivity.circle_progress_bar_dialog.set_Progress_title("Merging file..");
- postNewActivity.circle_progress_bar_dialog.get_Circle_Progress_bar(parentactivity).show();
- String []files=record_file_paths.toArray(new String[record_file_paths.size()]);
- File_merger.getInstance().mergeMediaFiles(parentactivity,false, files,new File_merger.Merger_callback()
- {
- @Override
- public void onSuccess(String file_parh)
- {
- postNewActivity.circle_progress_bar_dialog.get_Circle_Progress_bar(parentactivity).dismiss();
- handel_bottom_View(true);
- /*
- * Loading the video frg.*/
- postNewActivity.load_fragment(2,file_parh,"");
- }
- @Override
- public void onError(String error)
- {
- postNewActivity.circle_progress_bar_dialog.get_Circle_Progress_bar(parentactivity).dismiss();
- Toast.makeText(parentactivity,error,Toast.LENGTH_SHORT).show();
- }
- });
- }
- }
- public void handel_bottom_View(boolean isVisible)
- {
- /*if(isVisible)
- {
- fake_pager.setPagingEnabled(true);
- //postNewActivity.newPost_scrollView.setPagingEnabled(true);
- postNewActivity.isVideo_Recorded=false;
- postNewActivity.next_text_layout.setVisibility(View.GONE);
- isRecord_file_exist=false;
- //postNewActivity.delete_video.setVisibility(View.GONE);
- previous_recorded_time=0;
- parentactivity.runOnUiThread(new Runnable() {
- @Override
- public void run()
- {
- record_progressBar.setProgress(1);
- recorded_time.setVisibility(View.INVISIBLE);
- }
- });
- bottom_Up_Slide();
- }else
- {
- fake_pager.setPagingEnabled(false);
- //postNewActivity.newPost_scrollView.setPagingEnabled(false);
- postNewActivity.isVideo_Recorded=true;
- postNewActivity.next_text_layout.setVisibility(View.VISIBLE);
- isRecord_file_exist=true;
- //postNewActivity.delete_video.setVisibility(View.VISIBLE);
- close_Page_Slide();
- }*/
- }
- /**
- * Showing the hidden Tab bar and using android animation class and the
- * setting the visibility of the tabb layout as Visible .
- * {@link View#VISIBLE}.
- * @see AnimationUtils#loadAnimation(Context, int) */
- private void bottom_Up_Slide()
- {
- postNewActivity.post_tab_layout.setVisibility(View.VISIBLE);
- Animation animation_bottom_out = AnimationUtils.loadAnimation(parentactivity, R.anim.bottom_in_animation);
- animation_bottom_out.setAnimationListener(new Animation.AnimationListener()
- {
- @Override
- public void onAnimationStart(Animation animation)
- {}
- @Override
- public void onAnimationEnd(Animation animation)
- {
- }
- @Override
- public void onAnimationRepeat(Animation animation)
- {}
- });
- postNewActivity.post_tab_layout.setAnimation(animation_bottom_out);
- }
- /**
- * Hiding the Tab bar and using android animation class and the
- * setting the visibility of the tabb layout as Gone .
- * {@link View#GONE}.
- * @see AnimationUtils#loadAnimation(Context, int) */
- private void close_Page_Slide()
- {
- postNewActivity.post_tab_layout.setVisibility(View.GONE);
- Animation animation_bottom_out = AnimationUtils.loadAnimation(parentactivity, R.anim.bottom_down_animation);
- animation_bottom_out.setAnimationListener(new Animation.AnimationListener()
- {
- @Override
- public void onAnimationStart(Animation animation)
- {}
- @Override
- public void onAnimationEnd(Animation animation)
- {
- }
- @Override
- public void onAnimationRepeat(Animation animation)
- {}
- });
- postNewActivity.post_tab_layout.setAnimation(animation_bottom_out);
- }
- /**
- Rotating the camera switch button by 360 degree in
- using android Animation util.
- {@link AnimationUtils#loadAnimation(Context, int)}*/
- private void rotate_Camera_Switch_view()
- {
- Animation animation_bottom_out = AnimationUtils.loadAnimation(parentactivity, R.anim.rotate_view_animation);
- animation_bottom_out.setAnimationListener(new Animation.AnimationListener()
- {
- @Override
- public void onAnimationStart(Animation animation)
- {}
- @Override
- public void onAnimationEnd(Animation animation)
- {
- }
- @Override
- public void onAnimationRepeat(Animation animation)
- {}
- });
- }
- /**
- * <h2>animateShutter</h2>
- * <P>
- * Animating a view on capture of image to show image capture.
- * </P>*/
- private void animateShutter()
- {
- mShutter.setVisibility(View.VISIBLE);
- mShutter.setAlpha(0.f);
- ObjectAnimator alphaInAnim = ObjectAnimator.ofFloat(mShutter, "alpha", 0f, 0.8f);
- alphaInAnim.setDuration(100);
- alphaInAnim.setStartDelay(100);
- alphaInAnim.setInterpolator(ACCELERATE_INTERPOLATOR);
- ObjectAnimator alphaOutAnim = ObjectAnimator.ofFloat(mShutter, "alpha", 0.8f, 0f);
- alphaOutAnim.setDuration(200);
- alphaOutAnim.setInterpolator(DECELERATE_INTERPOLATOR);
- AnimatorSet animatorSet = new AnimatorSet();
- animatorSet.playSequentially(alphaInAnim, alphaOutAnim);
- animatorSet.addListener(new AnimatorListenerAdapter() {
- @Override
- public void onAnimationEnd(Animator animation) {
- mShutter.setVisibility(View.GONE);
- }
- });
- animatorSet.start();
- }
- /**
- * <h2>open_Setting_dialog</h2>
- * <P>
- * Opening the setting page for the uer to set the permission and the
- * user can togel the permission and handel provide permission to this app.
- * </P>*/
- private void open_Setting_dialog()
- {
- /*
- * closing the key pad.*/
- Utility.close_soft_input_keypad(parentactivity);
- Context context=parentactivity;
- android.support.v7.app.AlertDialog.Builder alertDialog = new android.support.v7.app.AlertDialog.Builder(context);
- LayoutInflater inflater = parentactivity.getLayoutInflater();
- @SuppressLint("InflateParams")
- View dialogView = inflater.inflate(R.layout.permission_denined_setting_layout,null);
- alertDialog.setView(dialogView);
- TextView header_title= dialogView.findViewById(R.id.heading_text);
- header_title.setTypeface(postNewActivity.RobotoRegular);
- TextView setting_click= dialogView.findViewById(R.id.setting_click);
- setting_click.setTypeface(postNewActivity.RobotoMedium);
- setting_click.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v)
- {
- Intent intent = new Intent();
- intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
- Uri uri = Uri.fromParts("package",parentactivity.getPackageName(), null);
- intent.setData(uri);
- parentactivity.startActivity(intent);
- if(postNewActivity.alert_dialog!=null) {
- postNewActivity.alert_dialog.cancel();
- postNewActivity.alert_dialog.dismiss();
- }
- }
- });
- postNewActivity.alert_dialog = alertDialog.show();
- postNewActivity.alert_dialog.show();
- }
- public void setCameraActionListener(CameraFragmentActionListener listener) {
- this.listener = listener;
- }
- /** Interface for listener **/
- public interface CameraFragmentActionListener {
- void onCameraRecording();
- void onCameraStop(File outputFile, File aacFile, int recordingInSeconds);
- void onPitchChanged(float pitch);
- }
- public int getUserStarsForCurrentSong(){
- String tvValue = userScoreTextView.getText().toString();
- if (!tvValue.equals("")) {
- return Integer.parseInt(tvValue);
- }
- return 0;
- }
- /**
- * Change text on score text view
- * @param score
- */
- public void setSongScore(int score) {
- if (userScoreTextView != null && score > 0) {
- userScoreTextView.setText(String.valueOf(score));
- }
- }
- }
Add Comment
Please, Sign In to add comment