PlaybackActivity.java
Go to the documentation of this file.
1 package com.intel.realsense.camera;
2 
3 import android.content.Context;
4 import android.content.Intent;
5 import android.content.SharedPreferences;
6 import android.graphics.Color;
7 import android.graphics.Rect;
8 import android.os.Bundle;
9 import androidx.appcompat.app.AppCompatActivity;
10 import android.util.Pair;
11 import android.view.View;
12 import android.view.ViewGroup;
13 import android.view.WindowManager;
14 import android.widget.RelativeLayout;
15 import android.widget.TextView;
16 
20 
21 import java.io.File;
22 import java.util.HashMap;
23 import java.util.Map;
24 
25 public class PlaybackActivity extends AppCompatActivity {
26  private static final String TAG = "librs camera pb";
27 
28  private static final int OPEN_FILE_REQUEST_CODE = 0;
29  private static final String FILE_PATH_KEY = "FILE_PATH_KEY";
30 
31  private String mFilePath;
34 
35  private Map<Integer, TextView> mLabels;
36 
37  private boolean mShow3D = false;
38  private TextView m3dButton;
39 
40  @Override
41  protected void onCreate(Bundle savedInstanceState) {
42  super.onCreate(savedInstanceState);
43  setContentView(R.layout.activity_playback);
44  getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
45 
46  mGLSurfaceView = findViewById(R.id.playbackGlSurfaceView);
47  m3dButton = findViewById(R.id.playback_3d_button);
48  m3dButton.setOnClickListener(new View.OnClickListener() {
49  @Override
50  public void onClick(View view) {
51  mGLSurfaceView.setVisibility(View.GONE);
52  mGLSurfaceView.clear();
53  clearLables();
54  mShow3D = !mShow3D;
55  m3dButton.setTextColor(mShow3D ? Color.YELLOW : Color.WHITE);
56  mGLSurfaceView.setVisibility(View.VISIBLE);
57  SharedPreferences sharedPref = getSharedPreferences(getString(R.string.app_settings), Context.MODE_PRIVATE);
58  SharedPreferences.Editor editor = sharedPref.edit();
59  editor.putBoolean(getString(R.string.show_3d), mShow3D);
60  editor.commit();
61  }
62  });
63  SharedPreferences sharedPref = getSharedPreferences(getString(R.string.app_settings), Context.MODE_PRIVATE);
64  mShow3D = sharedPref.getBoolean(getString(R.string.show_3d), false);
65  m3dButton.setTextColor(mShow3D ? Color.YELLOW : Color.WHITE);
66  }
67 
68  @Override
69  protected void onResume() {
70  super.onResume();
71 
72  if(mFilePath == null){
73  Intent intent = new Intent(this, FileBrowserActivity.class);
74  intent.putExtra(getString(R.string.browse_folder), getString(R.string.realsense_folder) + File.separator + "video");
75  startActivityForResult(intent, OPEN_FILE_REQUEST_CODE);
76  }
77  else{
78  mStreamer = new Streamer(this,false, new Streamer.Listener() {
79  @Override
80  public void config(Config config) {
81  config.enableAllStreams();
82  config.enableDeviceFromFile(mFilePath);
83  }
84 
85  @Override
86  public void onFrameset(FrameSet frameSet) {
87  mGLSurfaceView.showPointcloud(mShow3D);
88  mGLSurfaceView.upload(frameSet);
89  Map<Integer, Pair<String, Rect>> rects = mGLSurfaceView.getRectangles();
90  printLables(rects);
91  }
92  });
93  try {
94  mGLSurfaceView.clear();
95  mStreamer.start();
96  } catch (Exception e) {
97  finish();
98  }
99  }
100  }
101 
102  @Override
103  protected void onPause() {
104  super.onPause();
105 
106  clearLables();
107 
108  if(mStreamer != null)
109  mStreamer.stop();
110  if(mGLSurfaceView != null)
111  mGLSurfaceView.clear();
112  }
113 
114  @Override
115  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
116  super.onActivityResult(requestCode, resultCode, data);
117  if (requestCode == OPEN_FILE_REQUEST_CODE && resultCode == RESULT_OK) {
118  if (data != null) {
119  mFilePath = data.getStringExtra(getString(R.string.intent_extra_file_path));
120  }
121  }
122  else{
123  Intent intent = new Intent();
124  setResult(RESULT_OK, intent);
125  finish();
126  }
127  }
128 
129  @Override
130  protected void onSaveInstanceState(final Bundle outState) {
131  super.onSaveInstanceState(outState);
132  outState.putString(FILE_PATH_KEY, mFilePath);
133  }
134 
135  @Override
136  protected void onRestoreInstanceState(final Bundle savedInstanceState) {
137  super.onRestoreInstanceState(savedInstanceState);
138  mFilePath = savedInstanceState.getString(FILE_PATH_KEY);
139  }
140 
141  private synchronized Map<Integer, TextView> createLabels(Map<Integer, Pair<String, Rect>> rects){
142  if(rects == null)
143  return null;
144  mLabels = new HashMap<>();
145 
146  final RelativeLayout rl = findViewById(R.id.labels_layout);
147  for(Map.Entry<Integer, Pair<String, Rect>> e : rects.entrySet()){
148  TextView tv = new TextView(getApplicationContext());
149  ViewGroup.LayoutParams lp = new RelativeLayout.LayoutParams(
150  ViewGroup.LayoutParams.WRAP_CONTENT,
151  ViewGroup.LayoutParams.WRAP_CONTENT);
152  tv.setLayoutParams(lp);
153  tv.setTextColor(Color.parseColor("#ffffff"));
154  tv.setTextSize(14);
155  rl.addView(tv);
156  mLabels.put(e.getKey(), tv);
157  }
158  return mLabels;
159  }
160 
161  private void printLables(final Map<Integer, Pair<String, Rect>> rects){
162  if(rects == null)
163  return;
164  final Map<Integer, String> lables = new HashMap<>();
165  if(mLabels == null)
166  mLabels = createLabels(rects);
167  for(Map.Entry<Integer, Pair<String, Rect>> e : rects.entrySet()){
168  lables.put(e.getKey(), e.getValue().first);
169  }
170 
171  runOnUiThread(new Runnable() {
172  @Override
173  public void run() {
174  for(Map.Entry<Integer,TextView> e : mLabels.entrySet()){
175  Integer uid = e.getKey();
176  if(rects.get(uid) == null)
177  continue;
178  Rect r = rects.get(uid).second;
179  TextView tv = e.getValue();
180  tv.setX(r.left);
181  tv.setY(r.top);
182  tv.setText(lables.get(uid));
183  }
184  }
185  });
186  }
187 
188  private void clearLables(){
189  if(mLabels != null){
190  for(Map.Entry<Integer, TextView> label : mLabels.entrySet())
191  label.getValue().setVisibility(View.GONE);
192  mLabels = null;
193  }
194  }
195 }
uvc_xu_option< int > super
Definition: l500-options.h:32
void onActivityResult(int requestCode, int resultCode, Intent data)
void onRestoreInstanceState(final Bundle savedInstanceState)
void onCreate(Bundle savedInstanceState)
void enableDeviceFromFile(String filePath)
Definition: Config.java:39
e
Definition: rmse.py:177
::std_msgs::String_< std::allocator< void > > String
Definition: String.h:47
void onSaveInstanceState(final Bundle outState)
Map< Integer, Pair< String, Rect > > getRectangles()
GLdouble GLdouble r
def run(include_folder_path, addon_folder_path)
Definition: enums.py:46
def finish()
Definition: test.py:373
void printLables(final Map< Integer, Pair< String, Rect >> rects)
GLuint GLsizei const GLchar * label
Definition: parser.hpp:150
synchronized Map< Integer, TextView > createLabels(Map< Integer, Pair< String, Rect >> rects)


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