RecordingActivity.java
Go to the documentation of this file.
1 package com.intel.realsense.camera;
2 
3 import android.Manifest;
4 import android.content.Intent;
5 import android.content.pm.PackageManager;
6 import android.os.Bundle;
7 import com.google.android.material.floatingactionbutton.FloatingActionButton;
8 import androidx.core.app.ActivityCompat;
9 import androidx.core.content.ContextCompat;
10 import androidx.appcompat.app.AppCompatActivity;
11 import android.view.View;
12 import android.view.WindowManager;
13 
17 
18 import java.io.File;
19 import java.text.SimpleDateFormat;
20 import java.util.Date;
21 
22 public class RecordingActivity extends AppCompatActivity {
23  private static final String TAG = "librs camera rec";
24 
27 
28  private boolean mPermissionsGranted = false;
29 
30  private FloatingActionButton mStopRecordFab;
31 
32  @Override
33  protected void onCreate(Bundle savedInstanceState) {
34  super.onCreate(savedInstanceState);
35  setContentView(R.layout.activity_recording);
36  getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
37 
38  mGLSurfaceView = findViewById(R.id.recordingGlSurfaceView);
39 
40  mStopRecordFab = findViewById(R.id.stopRecordFab);
41  mStopRecordFab.setOnClickListener(new View.OnClickListener() {
42  @Override
43  public void onClick(View view) {
44  Intent intent = new Intent(RecordingActivity.this, PreviewActivity.class);
45  startActivity(intent);
46  finish();
47  }
48  });
49 
50  if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
51  ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, PermissionsUtils.PERMISSIONS_REQUEST_WRITE);
52  return;
53  }
54 
55  mPermissionsGranted = true;
56  }
57 
58  @Override
59  public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
60  if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
61  ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, PermissionsUtils.PERMISSIONS_REQUEST_WRITE);
62  return;
63  }
64 
65  mPermissionsGranted = true;
66  }
67 
68  @Override
69  protected void onResume() {
70  super.onResume();
71 
72  if(mPermissionsGranted){
73  mStreamer = new Streamer(this,true, new Streamer.Listener() {
74  @Override
75  public void config(Config config) {
77  }
78 
79  @Override
80  public void onFrameset(FrameSet frameSet) {
81  mGLSurfaceView.upload(frameSet);
82  }
83  });
84  try {
85  mGLSurfaceView.clear();
86  mStreamer.start();
87  } catch (Exception e) {
88  finish();
89  }
90  }
91  }
92 
93  @Override
94  protected void onPause() {
95  super.onPause();
96 
97  if(mStreamer != null)
98  mStreamer.stop();
99  if(mGLSurfaceView != null)
100  mGLSurfaceView.clear();
101  }
102 
103  private String getFilePath(){
104  File rsFolder = new File(getExternalFilesDir(null).getAbsolutePath() +
105  File.separator + getString(R.string.realsense_folder));
106  rsFolder.mkdir();
107  File folder = new File(getExternalFilesDir(null).getAbsolutePath() +
108  File.separator + getString(R.string.realsense_folder) + File.separator + "video");
109  folder.mkdir();
110  SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd_HHmmss");
111  String currentDateAndTime = sdf.format(new Date());
112  File file = new File(folder, currentDateAndTime + ".bag");
113  return file.getAbsolutePath();
114  }
115 }
uvc_xu_option< int > super
Definition: l500-options.h:32
void enableRecordToFile(String filePath)
Definition: Config.java:35
e
Definition: rmse.py:177
::std_msgs::String_< std::allocator< void > > String
Definition: String.h:47
void onCreate(Bundle savedInstanceState)
def finish()
Definition: test.py:373
void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults)


librealsense2
Author(s): Sergey Dorodnicov , Doron Hirshberg , Mark Horn , Reagan Lopez , Itay Carpis
autogenerated on Mon May 3 2021 02:47:39