1 package com.intel.realsense.camera;
3 import android.app.ProgressDialog;
4 import android.content.Context;
5 import android.content.DialogInterface;
6 import android.content.Intent;
7 import android.content.SharedPreferences;
8 import android.os.AsyncTask;
9 import android.os.Bundle;
10 import androidx.core.app.ActivityCompat;
11 import androidx.core.content.ContextCompat;
12 import androidx.appcompat.app.AlertDialog;
13 import androidx.appcompat.app.AppCompatActivity;
14 import android.util.Log;
15 import android.util.Pair;
16 import android.view.View;
17 import android.widget.AdapterView;
18 import android.widget.ArrayAdapter;
19 import android.widget.ListView;
20 import android.widget.Toast;
34 import java.util.ArrayList;
35 import java.util.Collections;
36 import java.util.HashMap;
37 import java.util.List;
39 import java.util.TreeMap;
42 private static final String TAG =
"librs camera settings";
44 AppCompatActivity mContext;
63 protected void onCreate(Bundle savedInstanceState) {
64 super.onCreate(savedInstanceState);
65 setContentView(
R.layout.activity_settings);
71 getString(
R.string.realsense_folder) +
82 for(
int i = 0;
i < tries;
i++){
85 if (
devices.getDeviceCount() == 0) {
89 _device =
devices.createDevice(0);
97 Log.e(TAG,
"failed to load settings, error: " + e.getMessage());
100 Log.e(TAG,
"failed to load settings");
101 Toast.makeText(
this,
"Failed to load settings", Toast.LENGTH_LONG).show();
103 startActivity(intent);
114 final ListView listview = findViewById(
R.id.info_list_view);
115 String appVersion =
"Camera App Version: " + BuildConfig.VERSION_NAME;
118 final String[]
info = { lrsVersion, appVersion};
119 final ArrayAdapter adapter =
new ArrayAdapter<>(
this,
R.layout.files_list_view,
info);
120 listview.setAdapter(adapter);
121 adapter.notifyDataSetChanged();
125 final ListView listview = findViewById(
R.id.settings_list_view);
127 final Map<Integer,String> settingsMap =
new TreeMap<>();
128 settingsMap.put(INDEX_DEVICE_INFO,
"Device info");
132 settingsMap.put(INDEX_ADVANCE_MODE,
"Disable advanced mode");
133 settingsMap.put(INDEX_PRESETS,
"Presets");
136 settingsMap.put(INDEX_ADVANCE_MODE,
"Enable advanced mode");
141 settingsMap.put(INDEX_UPDATE,
"Firmware update");
144 settingsMap.put(INDEX_UPDATE_UNSIGNED,
"Firmware update (unsigned)");
148 if (areAdvancedFeaturesEnabled) {
149 SharedPreferences sharedPref = getSharedPreferences(getString(
R.string.app_settings), Context.MODE_PRIVATE);
150 boolean fw_logging_enabled = sharedPref.getBoolean(getString(
R.string.fw_logging),
false);
151 settingsMap.put(INDEX_FW_LOG, fw_logging_enabled ?
"Stop FW logging" :
"Start FW logging");
153 settingsMap.put(INDEX_TERMINAL,
"Terminal");
156 settingsMap.put(INDEX_CREATE_FLASH_BACKUP,
"Create FW backup");
158 final String[] settings =
new String[settingsMap.values().size()];
159 settingsMap.values().toArray(settings);
160 final ArrayAdapter adapter =
new ArrayAdapter<>(
this,
R.layout.files_list_view, settings);
161 listview.setAdapter(adapter);
163 listview.setOnItemClickListener(
new AdapterView.OnItemClickListener() {
166 public void onItemClick(AdapterView<?> parent,
final View
view,
167 int position,
long id) {
168 Object[]
keys = settingsMap.keySet().toArray();
170 switch ((
int)keys[position]){
171 case INDEX_DEVICE_INFO: {
173 startActivity(intent);
178 case INDEX_PRESETS: {
180 cd.setCancelable(
true);
181 cd.show(getFragmentManager(), null);
186 Bundle bundle =
new Bundle();
187 bundle.putBoolean(getString(
R.string.firmware_update_request),
true);
188 fud.setArguments(bundle);
189 fud.show(getFragmentManager(),
"fw_update_dialog");
192 case INDEX_UPDATE_UNSIGNED: {
194 intent.putExtra(getString(
R.string.browse_folder), getString(
R.string.realsense_folder) + File.separator +
"firmware");
195 startActivityForResult(intent, OPEN_FILE_REQUEST_CODE);
198 case INDEX_TERMINAL: {
200 startActivity(intent);
208 case INDEX_CREATE_FLASH_BACKUP: {
223 String mBackupFileName =
"fwdump.bin";
228 this.mContext = context;
241 super.onPreExecute();
243 mProgressDialog = ProgressDialog.show(mContext,
"Saving Firmware Backup",
"Please wait, this can take a few minutes");
244 mProgressDialog.setCanceledOnTouchOutside(
false);
245 mProgressDialog.setCancelable(
false);
250 super.onPostExecute(aVoid);
252 if (mProgressDialog != null) {
253 mProgressDialog.dismiss();
256 runOnUiThread(
new Runnable() {
259 new AlertDialog.Builder(mContext)
260 .setTitle(
"Firmware Backup Success")
262 .setPositiveButton(android.R.string.ok,
new DialogInterface.OnClickListener() {
264 public void onClick(DialogInterface dialog,
int which) {
277 return pid +
"_" + streamType.name() +
"_" + streamIndex;
289 Map<Integer, List<StreamProfile>> rv =
new HashMap<>();
292 List<StreamProfile>
profiles =
s.getStreamProfiles();
294 Pair<StreamType, Integer> pair =
new Pair<>(
p.getType(),
p.getIndex());
295 if(!rv.containsKey(pair.hashCode()))
296 rv.put(pair.hashCode(),
new ArrayList<StreamProfile>());
297 rv.get(pair.hashCode()).add(
p);
305 if(device == null || streamProfiles.size() == 0)
308 throw new RuntimeException(
"try to config unknown device");
315 SharedPreferences sharedPref = getSharedPreferences(getString(
R.string.app_settings), Context.MODE_PRIVATE);
316 SharedPreferences.Editor editor = sharedPref.edit();
324 ListView streamListView = findViewById(
R.id.configuration_list_view);
325 streamListView.setAdapter(adapter);
326 adapter.notifyDataSetChanged();
332 SharedPreferences sharedPref = getSharedPreferences(getString(
R.string.app_settings), Context.MODE_PRIVATE);
334 throw new RuntimeException(
"try to config unknown device");
336 List<StreamProfileSelector> lines =
new ArrayList<>();
337 for(Map.Entry
e : profilesMap.entrySet()){
338 List<StreamProfile> list = (List<StreamProfile>)
e.getValue();
345 Collections.sort(lines);
354 confidenceProfile = streamProfile;
361 if (confidenceProfile != null)
362 streamProfiles.remove(confidenceProfile);
365 void toggleFwLogging(){
366 SharedPreferences sharedPref = getSharedPreferences(getString(
R.string.app_settings), Context.MODE_PRIVATE);
367 boolean fw_logging_enabled = sharedPref.getBoolean(getString(
R.string.fw_logging),
false);
368 String fw_logging_file_path = sharedPref.getString(getString(
R.string.fw_logging_file_path),
"");
369 if(fw_logging_file_path.equals(
"")){
371 intent.putExtra(getString(
R.string.browse_folder), getString(
R.string.realsense_folder) + File.separator +
"hw");
372 startActivityForResult(intent, OPEN_FW_FILE_REQUEST_CODE);
376 SharedPreferences.Editor editor = sharedPref.edit();
377 editor.putBoolean(getString(
R.string.fw_logging), !fw_logging_enabled);
383 super.onActivityResult(requestCode, resultCode, data);
384 if (resultCode != RESULT_OK || data == null)
386 String filePath = data.getStringExtra(getString(
R.string.intent_extra_file_path));
387 switch (requestCode){
388 case OPEN_FILE_REQUEST_CODE:{
390 Bundle bundle =
new Bundle();
391 bundle.putString(getString(
R.string.firmware_update_file_path), filePath);
392 fud.setArguments(bundle);
393 fud.setCancelable(
false);
394 fud.show(getFragmentManager(), null);
397 case OPEN_FW_FILE_REQUEST_CODE: {
398 SharedPreferences sharedPref = getSharedPreferences(getString(
R.string.app_settings), Context.MODE_PRIVATE);
399 SharedPreferences.Editor editor = sharedPref.edit();
400 editor.putString(getString(
R.string.fw_logging_file_path), filePath);
static final int INDEX_DEVICE_INFO
boolean areAdvancedFeaturesEnabled
String getInfo(CameraInfo info)
::rosgraph_msgs::Log_< std::allocator< void > > Log
List< StreamProfileSelector > createSettingList(final Device device)
uvc_xu_option< int > super
static final int INDEX_UPDATE
void onActivityResult(int requestCode, int resultCode, Intent data)
boolean is(Extension extension)
static String getIndexdDeviceConfigString(String pid, StreamType streamType, int streamIndex)
void loadSettingsList(final Device device)
StreamProfile getProfile()
static Map< Integer, List< StreamProfile > > createProfilesMap(Device device)
void onCreate(Bundle savedInstanceState)
ProgressDialog mProgressDialog
::std_msgs::String_< std::allocator< void > > String
static String getDeviceConfig(String pid, StreamType streamType, int streamIndex)
void RemoveUnsupportedProfiles(List< StreamProfileSelector > streamProfiles)
def info(name, value, persistent=False)
static String getVersion()
static final int OPEN_FILE_REQUEST_CODE
void loadStreamList(Device device, List< StreamProfileSelector > streamProfiles)
static void saveFileToExternalDir(Context context, final String fileName, byte[] data)
static final int INDEX_FW_LOG
static String getExternalStorageDir(Context context)
def run(include_folder_path, addon_folder_path)
static final int INDEX_TERMINAL
GLenum GLenum GLsizei const GLuint GLboolean enabled
boolean isInAdvancedMode()
void toggleAdvancedMode(boolean enable)
static final int INDEX_PRESETS
static final int OPEN_FW_FILE_REQUEST_CODE
void onPostExecute(Void aVoid)
static String getEnabledDeviceConfigString(String pid, StreamType streamType, int streamIndex)
static final int INDEX_UPDATE_UNSIGNED
static boolean isPathEmpty(String path)
Void doInBackground(Void...voids)
static final int INDEX_ADVANCE_MODE
List< Sensor > querySensors()
static final int INDEX_CREATE_FLASH_BACKUP
DeviceList queryDevices()
FlashBackupTask(Device mDevice, Context context)
boolean supportsInfo(CameraInfo info)