1 package com.intel.realsense.camera;
3 import android.content.Context;
4 import android.content.Intent;
5 import android.content.SharedPreferences;
6 import android.os.Bundle;
7 import androidx.appcompat.app.AppCompatActivity;
8 import android.util.Log;
9 import android.view.KeyEvent;
10 import android.view.View;
11 import android.widget.ArrayAdapter;
12 import android.widget.AutoCompleteTextView;
13 import android.widget.Button;
14 import android.widget.CompoundButton;
15 import android.widget.EditText;
16 import android.widget.Switch;
17 import android.widget.Toast;
31 private static final String TAG =
"librs camera terminal";
46 protected void onCreate(Bundle savedInstanceState) {
47 super.onCreate(savedInstanceState);
48 setContentView(
R.layout.activity_terminal);
50 mSendButton = findViewById(
R.id.terminal_send_button);
51 mSendButton.setOnClickListener(
new View.OnClickListener() {
53 public void onClick(View
view) {
58 mClearButton = findViewById(
R.id.terminal_clear_button);
59 mClearButton.setOnClickListener(
new View.OnClickListener() {
61 public void onClick(View
view) {
62 mInputText.setText(
"");
65 mInputText = findViewById(
R.id.terminal_input_edit_text);
66 mInputText.setOnKeyListener(
new View.OnKeyListener() {
67 public boolean onKey(View
v,
int keyCode, KeyEvent
event) {
68 if ((event.getAction() == KeyEvent.ACTION_DOWN) &&
69 (keyCode == KeyEvent.KEYCODE_ENTER)) {
76 mOutputText = findViewById(
R.id.terminal_output_edit_text);
77 mAutoComplete = findViewById(
R.id.terminal_input_auto_complete);
78 mAutoComplete.setOnCheckedChangeListener(
new CompoundButton.OnCheckedChangeListener() {
80 public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
81 SharedPreferences sharedPref = getSharedPreferences(getString(
R.string.app_settings), Context.MODE_PRIVATE);
82 SharedPreferences.Editor editor = sharedPref.edit();
83 editor.putBoolean(getString(
R.string.terminal_auto_complete), isChecked);
89 mStreaming = findViewById(
R.id.terminal_stream);
90 mStreaming.setOnCheckedChangeListener(
new CompoundButton.OnCheckedChangeListener() {
92 public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
103 mStreamingThread.interrupt();
105 mStreamingThread.join(1000);
106 }
catch (InterruptedException
e) {
107 Log.e(TAG,
"stopStreaming, error: " + e.getMessage());
115 if(mStreaming.isChecked()){
121 mStreamingThread =
new Thread(
new Runnable() {
126 while(!mStreamingThread.isInterrupted()){
130 }
catch (Exception
e) {
131 mOutputText.setText(
"streaming error: " + e.getMessage());
135 mStreamingThread.start();
141 if(
devices.getDeviceCount() == 0)
143 Log.e(TAG,
"getDeviceCount returned zero");
144 Toast.makeText(
this,
"Connect a camera", Toast.LENGTH_LONG).show();
149 String content = mInputText.getText().toString();
150 String res =
dp.SendAndReceiveRawData(mFilePath, content);
151 mOutputText.setText(
"command: " + mInputText.getText() +
"\n\n" +
res);
152 mInputText.setText(
"");
156 mOutputText.setText(
"Error: " + e.getMessage());
168 if(mAutoComplete.isChecked()) {
170 ArrayAdapter<String> adapter =
new ArrayAdapter<>(
this,
171 android.R.layout.simple_dropdown_item_1line, spArray);
172 mInputText.setAdapter(adapter);
174 mInputText.setAdapter(null);
177 Log.e(TAG, e.getMessage());
178 mOutputText.setText(
"Error: " + e.getMessage());
183 SharedPreferences sharedPref = getSharedPreferences(getString(
R.string.app_settings), Context.MODE_PRIVATE);
184 mFilePath = sharedPref.getString(getString(
R.string.terminal_commands_file),
"");
185 mAutoComplete.setChecked(sharedPref.getBoolean(getString(
R.string.terminal_auto_complete),
false));
187 if(mFilePath == null || !(
new File(mFilePath).exists())){
189 intent.putExtra(getString(
R.string.browse_folder), getString(
R.string.realsense_folder) + File.separator +
"hw");
190 startActivityForResult(intent, OPEN_FILE_REQUEST_CODE);
198 super.onActivityResult(requestCode, resultCode, data);
199 if (requestCode == OPEN_FILE_REQUEST_CODE && resultCode == RESULT_OK) {
201 mFilePath = data.getStringExtra(getString(
R.string.intent_extra_file_path));
202 SharedPreferences sharedPref = getSharedPreferences(getString(
R.string.app_settings), Context.MODE_PRIVATE);
203 SharedPreferences.Editor editor = sharedPref.edit();
204 editor.putString(getString(
R.string.terminal_commands_file), mFilePath);
210 Intent intent =
new Intent();
211 setResult(RESULT_OK, intent);
void onCreate(Bundle savedInstanceState)
::rosgraph_msgs::Log_< std::allocator< void > > Log
uvc_xu_option< int > super
AutoCompleteTextView mInputText
::std_msgs::String_< std::allocator< void > > String
static final int OPEN_FILE_REQUEST_CODE
void onActivityResult(int requestCode, int resultCode, Intent data)
def run(include_folder_path, addon_folder_path)
IMGUI_API bool Button(const char *label, const ImVec2 &size=ImVec2(0, 0))
void setupAutoCompleteTextView()
DeviceList queryDevices()
static String[] getCommands(String commands_file_path)