1 package com.intel.realsense.camera;
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 com.google.android.material.floatingactionbutton.FloatingActionButton;
10 import androidx.appcompat.app.AppCompatActivity;
11 import android.util.Log;
12 import android.util.Pair;
13 import android.view.View;
14 import android.view.ViewGroup;
15 import android.view.WindowManager;
16 import android.widget.RelativeLayout;
17 import android.widget.TextView;
18 import android.widget.Toast;
29 import java.util.HashMap;
33 private static final String TAG =
"librs camera preview";
55 boolean keepalive =
true;
60 mGLSurfaceView.setVisibility(View.GONE);
61 mStatsView.setVisibility(View.VISIBLE);
62 mStatisticsButton.setText(
"Preview");
65 mGLSurfaceView.setVisibility(View.VISIBLE);
66 mStatsView.setVisibility(View.GONE);
67 mStatisticsButton.setText(
"Statistics");
72 protected void onCreate(Bundle savedInstanceState) {
73 super.onCreate(savedInstanceState);
74 setContentView(
R.layout.activity_preview);
78 Intent intent = this.getIntent();
80 if (intent != null && intent.getExtras() != null ) {
81 keepalive = intent.getExtras().getBoolean(
"keepalive");
84 getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
86 mGLSurfaceView = findViewById(
R.id.glSurfaceView);
87 mStatsView = findViewById(
R.id.streaming_stats_text);
88 mStartRecordFab = findViewById(
R.id.start_record_fab);
89 mPlaybackButton = findViewById(
R.id.preview_playback_button);
90 mSettingsButton = findViewById(
R.id.preview_settings_button);
91 mStatisticsButton = findViewById(
R.id.preview_stats_button);
92 m3dButton = findViewById(
R.id.preview_3d_button);
93 mControlsButton = findViewById(
R.id.controls_button);
95 mStartRecordFab.setOnClickListener(
new View.OnClickListener() {
97 public void onClick(View
view) {
99 startActivity(intent);
103 mPlaybackButton.setOnClickListener(
new View.OnClickListener() {
105 public void onClick(View
view) {
107 startActivity(intent);
110 mSettingsButton.setOnClickListener(
new View.OnClickListener() {
112 public void onClick(View
view) {
114 startActivity(intent);
117 m3dButton.setOnClickListener(
new View.OnClickListener() {
119 public void onClick(View
view) {
120 mGLSurfaceView.setVisibility(View.GONE);
121 mGLSurfaceView.
clear();
124 m3dButton.setTextColor(mShow3D ?
Color.YELLOW :
Color.WHITE);
125 mGLSurfaceView.setVisibility(View.VISIBLE);
126 SharedPreferences sharedPref = getSharedPreferences(getString(
R.string.app_settings), Context.MODE_PRIVATE);
127 SharedPreferences.Editor editor = sharedPref.edit();
128 editor.putBoolean(getString(
R.string.show_3d), mShow3D);
132 mControlsButton.setOnClickListener(
new View.OnClickListener() {
134 public void onClick(View
view) {
136 cd.setCancelable(
true);
137 cd.show(getFragmentManager(), null);
140 mStatisticsButton.setOnClickListener(
new View.OnClickListener() {
142 public void onClick(View
view) {
146 SharedPreferences sharedPref = getSharedPreferences(getString(
R.string.app_settings), Context.MODE_PRIVATE);
147 mShow3D = sharedPref.getBoolean(getString(
R.string.show_3d),
false);
148 m3dButton.setTextColor(mShow3D ?
Color.YELLOW :
Color.WHITE);
154 mGLSurfaceView.
close();
157 private synchronized Map<Integer, TextView>
createLabels(Map<Integer, Pair<String, Rect>> rects){
160 mLabels =
new HashMap<>();
162 final RelativeLayout rl = findViewById(
R.id.labels_layout);
163 for(Map.Entry<Integer, Pair<String, Rect>>
e : rects.entrySet()){
164 TextView tv =
new TextView(getApplicationContext());
165 ViewGroup.LayoutParams lp =
new RelativeLayout.LayoutParams(
166 ViewGroup.LayoutParams.WRAP_CONTENT,
167 ViewGroup.LayoutParams.WRAP_CONTENT);
168 tv.setLayoutParams(lp);
169 tv.setTextColor(
Color.parseColor(
"#ffffff"));
172 mLabels.put(
e.getKey(), tv);
177 private void printLables(
final Map<Integer, Pair<String, Rect>> rects){
180 final Map<Integer, String> lables =
new HashMap<>();
183 for(Map.Entry<Integer, Pair<String, Rect>>
e : rects.entrySet()){
184 lables.put(
e.getKey(),
e.getValue().first);
187 runOnUiThread(
new Runnable() {
190 for(Map.Entry<Integer,TextView>
e : mLabels.entrySet()){
191 Integer
uid =
e.getKey();
192 if(rects.get(uid) == null)
194 Rect
r = rects.get(uid).second;
195 TextView tv =
e.getValue();
198 tv.setText(lables.get(uid));
206 for(Map.Entry<Integer, TextView>
label : mLabels.entrySet())
207 label.getValue().setVisibility(View.GONE);
216 if(keepalive ==
false)
229 public void onFrameset(
final FrameSet frameSet) {
233 runOnUiThread(
new Runnable() {
242 mGLSurfaceView.
upload(frameSet);
243 Map<Integer, Pair<String, Rect>> rects = mGLSurfaceView.
getRectangles();
250 mGLSurfaceView.
clear();
254 if(mStreamer != null)
256 Log.e(TAG, e.getMessage());
257 Toast.makeText(
this,
"Failed to set streaming configuration ", Toast.LENGTH_LONG).show();
259 startActivity(intent);
270 if(mStreamer != null)
272 if(mGLSurfaceView != null)
273 mGLSurfaceView.
clear();
289 SharedPreferences sharedPref = getSharedPreferences(getString(
R.string.app_settings), Context.MODE_PRIVATE);
290 boolean fw_logging_enabled = sharedPref.getBoolean(getString(
R.string.fw_logging),
false);
291 String fw_logging_file_path = sharedPref.getString(getString(
R.string.fw_logging_file_path),
"");
293 if (fw_logging_enabled) {
295 if(!fw_logging_file_path.equals(
"")){
296 mFwLogsThread.
init(fw_logging_file_path);
298 mFwLogsThread.start();
299 mFwLogsRunning =
true;
305 SharedPreferences sharedPref = getSharedPreferences(getString(
R.string.app_settings), Context.MODE_PRIVATE);
306 boolean fw_logging_enabled = sharedPref.getBoolean(getString(
R.string.fw_logging),
false);
307 if (fw_logging_enabled) {
310 if(mFwLogsThread != null && mFwLogsThread.isAlive()) {
311 mFwLogsThread.interrupt();
313 mFwLogsRunning =
false;
319 super.onNewIntent(intent);
321 if (intent != null && intent.getExtras() != null ) {
322 keepalive = intent.getExtras().getBoolean(
"keepalive");
326 if(keepalive ==
false)
::rosgraph_msgs::Log_< std::allocator< void > > Log
uvc_xu_option< int > super
TextView mStatisticsButton
FloatingActionButton mStartRecordFab
::std_msgs::String_< std::allocator< void > > String
void printLables(final Map< Integer, Pair< String, Rect >> rects)
void onNewIntent(Intent intent)
synchronized void resumeFwLogger()
synchronized void pauseBackgroundTasks()
GLRsSurfaceView mGLSurfaceView
def run(include_folder_path, addon_folder_path)
StreamingStats mStreamingStats
void onFrameset(FrameSet frames)
GLuint GLsizei const GLchar * label
void onCreate(Bundle savedInstanceState)
FwLogsThread mFwLogsThread
synchronized void start()
synchronized Map< Integer, TextView > createLabels(Map< Integer, Pair< String, Rect >> rects)
synchronized void pauseFwLogger()
Map< Integer, TextView > mLabels
void init(String fw_logging_file_path)
synchronized void toggleStats()
synchronized void resumeBackgroundTasks()