SettingsActivity.java
Go to the documentation of this file.
1 package com.introlab.rtabmap;
2 
3 import java.io.File;
4 import java.text.SimpleDateFormat;
5 import java.util.ArrayList;
6 import java.util.Arrays;
7 import java.util.Iterator;
8 import java.util.Map.Entry;
9 
10 import android.Manifest;
11 import android.app.AlertDialog;
12 import android.content.DialogInterface;
13 import android.content.SharedPreferences;
14 import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
15 import android.content.pm.PackageManager;
16 import android.os.Bundle;
17 import android.preference.CheckBoxPreference;
18 import android.preference.ListPreference;
19 import android.preference.Preference;
20 import android.preference.PreferenceActivity;
21 import android.text.InputType;
22 import android.view.WindowManager;
23 import android.view.inputmethod.EditorInfo;
24 import android.widget.EditText;
25 import android.widget.Toast;
26 
27 public class SettingsActivity extends PreferenceActivity implements OnSharedPreferenceChangeListener {
28 
29  private SettingsActivity getActivity() {return this;}
30 
31  @Override
32  public void onCreate(Bundle savedInstanceState) {
33  super.onCreate(savedInstanceState);
34  addPreferencesFromResource(R.layout.activity_settings);
35 
36  Preference buttonReset = findPreference(getString(R.string.pref_key_reset_button));
37  buttonReset.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
38  @Override
39  public boolean onPreferenceClick(Preference preference) {
40  getPreferenceScreen().getSharedPreferences().edit().clear().commit();
41 
42  recreate();
43 
44  return true;
45  }
46  });
47 
48  Preference buttonOpen = findPreference(getString(R.string.pref_key_open_button));
49  buttonOpen.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
50  @Override
51  public boolean onPreferenceClick(Preference preference) {
52  File prefsdir = new File(getApplicationInfo().dataDir,"shared_prefs");
53  if(prefsdir.exists() && prefsdir.isDirectory()){
54  ArrayList<String> filesArray = new ArrayList<String>(Arrays.asList(prefsdir.list()));
55  ArrayList<String> newList = new ArrayList<String>();
56  filesArray.remove("com.introlab.rtabmap_preferences.xml");
57  filesArray.remove("WebViewChromiumPrefs.xml");
58  for (String s : filesArray) {
59  newList.add(s.substring(0, s.length()-4)); // rip off the ".xml"
60  }
61  final String[] files = newList.toArray(new String[filesArray.size()]);
62  if(files.length > 0)
63  {
64  AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
65  builder.setTitle("Choose Presets:");
66  builder.setItems(files, new DialogInterface.OnClickListener() {
67  public void onClick(DialogInterface dialog, final int which) {
68  //sp1 is the shared pref to copy to
69  SharedPreferences.Editor ed = getPreferenceScreen().getSharedPreferences().edit();
70  SharedPreferences sp = getActivity().getSharedPreferences(files[which], MODE_PRIVATE); //The shared preferences to copy from
71  //Cycle through all the entries in the sp
72  for(Entry<String,?> entry : sp.getAll().entrySet()){
73  Object v = entry.getValue();
74  String key = entry.getKey();
75  //Now we just figure out what type it is, so we can copy it.
76  // Note that i am using Boolean and Integer instead of boolean and int.
77  // That's because the Entry class can only hold objects and int and boolean are primatives.
78  if(v instanceof Boolean)
79  // Also note that i have to cast the object to a Boolean
80  // and then use .booleanValue to get the boolean
81  ed.putBoolean(key, ((Boolean)v).booleanValue());
82  else if(v instanceof Float)
83  ed.putFloat(key, ((Float)v).floatValue());
84  else if(v instanceof Integer)
85  ed.putInt(key, ((Integer)v).intValue());
86  else if(v instanceof Long)
87  ed.putLong(key, ((Long)v).longValue());
88  else if(v instanceof String)
89  ed.putString(key, ((String)v));
90  }
91  ed.commit(); //save it.
92  recreate();
93  return;
94  }
95  });
96  builder.show();
97  }
98  }
99 
100  return true;
101  }
102  });
103 
104  Preference buttonSave = findPreference(getString(R.string.pref_key_save_button));
105  buttonSave.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
106  @Override
107  public boolean onPreferenceClick(Preference preference) {
108  AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
109  builder.setTitle("Save Presets:");
110  final EditText input = new EditText(getActivity());
111  input.setInputType(InputType.TYPE_CLASS_TEXT);
112  input.setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI);
113  builder.setView(input);
114  builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
115  @Override
116  public void onClick(DialogInterface dialog, int which)
117  {
118  final String fileName = input.getText().toString();
119  dialog.dismiss();
120  if(!fileName.isEmpty())
121  {
122  File newFile = new File(getApplicationInfo().dataDir + "/shared_prefs/" + fileName + ".xml");
123  if(newFile.exists())
124  {
125  new AlertDialog.Builder(getActivity())
126  .setTitle("Presets Already Exist")
127  .setMessage("Do you want to overwrite the existing file?")
128  .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
129  public void onClick(DialogInterface dialog, int which) {
130  saveConfig(fileName);
131  }
132  })
133  .setNegativeButton("No", new DialogInterface.OnClickListener() {
134  public void onClick(DialogInterface dialog, int which) {
135  dialog.dismiss();
136  }
137  })
138  .show();
139  }
140  else
141  {
142  saveConfig(fileName);
143  }
144  }
145  }
146  });
147  AlertDialog alertToShow = builder.create();
148  alertToShow.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
149  alertToShow.show();
150 
151  return true;
152  }
153  });
154 
155  Preference buttonRemove = findPreference(getString(R.string.pref_key_remove_button));
156  buttonRemove.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
157  @Override
158  public boolean onPreferenceClick(Preference preference) {
159  File prefsdir = new File(getApplicationInfo().dataDir,"shared_prefs");
160  if(prefsdir.exists() && prefsdir.isDirectory()){
161  ArrayList<String> filesArray = new ArrayList<String>(Arrays.asList(prefsdir.list()));
162  ArrayList<String> newList = new ArrayList<String>();
163  filesArray.remove("com.introlab.rtabmap_preferences.xml");
164  filesArray.remove("WebViewChromiumPrefs.xml");
165  for (String s : filesArray) {
166  newList.add(s.substring(0, s.length()-4)); // rip off the ".xml"
167  }
168  final String[] files = newList.toArray(new String[filesArray.size()]);
169  if(files.length > 0)
170  {
171  AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
172  builder.setTitle("Remove Presets:");
173  builder.setItems(files, new DialogInterface.OnClickListener() {
174  public void onClick(DialogInterface dialog, final int which) {
175  File file = new File(getApplicationInfo().dataDir + "/shared_prefs/" + files[which] + ".xml");
176  if(file.exists())
177  {
178  file.delete();
179  }
180  return;
181  }
182  });
183  builder.show();
184  }
185  }
186 
187  return true;
188  }
189  });
190 
191  Preference buttonGPS = findPreference(getString(R.string.pref_key_gps_saved));
192  buttonGPS.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
193  @Override
194  public boolean onPreferenceClick(Preference preference) {
195  if(((CustomSwitchPreference)preference).isChecked())
196  {
197  if (!PermissionHelper.hasPermission(getActivity(), Manifest.permission.ACCESS_FINE_LOCATION)) {
198  ((CustomSwitchPreference)preference).setChecked(false);
199  PermissionHelper.requestPermission(getActivity(), Manifest.permission.ACCESS_FINE_LOCATION);
200  return false;
201  }
202  }
203  return true;
204  }
205  });
206  if(((CustomSwitchPreference)buttonGPS).isChecked())
207  {
208  if (!PermissionHelper.hasPermission(this, Manifest.permission.ACCESS_FINE_LOCATION)) {
209  ((CustomSwitchPreference)buttonGPS).setChecked(false);
210  PermissionHelper.requestPermission(this, Manifest.permission.ACCESS_FINE_LOCATION);
211  }
212  }
213 
214 
215  ((Preference)findPreference(getString(R.string.pref_key_camera_driver))).setSummary("("+((ListPreference)findPreference(getString(R.string.pref_key_camera_driver))).getEntry() + ") "+getString(R.string.pref_summary_camera_driver));
216  ((Preference)findPreference(getString(R.string.pref_key_density))).setSummary("("+((ListPreference)findPreference(getString(R.string.pref_key_density))).getEntry() + ") "+getString(R.string.pref_summary_density));
217  ((Preference)findPreference(getString(R.string.pref_key_depth))).setSummary("("+((ListPreference)findPreference(getString(R.string.pref_key_depth))).getEntry() + ") "+getString(R.string.pref_summary_depth));
218  ((Preference)findPreference(getString(R.string.pref_key_min_depth))).setSummary("("+((ListPreference)findPreference(getString(R.string.pref_key_min_depth))).getEntry() + ") "+getString(R.string.pref_summary_min_depth));
219  ((Preference)findPreference(getString(R.string.pref_key_point_size))).setSummary("("+((ListPreference)findPreference(getString(R.string.pref_key_point_size))).getEntry() + ") "+getString(R.string.pref_summary_point_size));
220  ((Preference)findPreference(getString(R.string.pref_key_angle))).setSummary("("+((ListPreference)findPreference(getString(R.string.pref_key_angle))).getEntry() + ") "+getString(R.string.pref_summary_angle));
221  ((Preference)findPreference(getString(R.string.pref_key_triangle))).setSummary("("+((ListPreference)findPreference(getString(R.string.pref_key_triangle))).getEntry() + ") "+getString(R.string.pref_summary_triangle));
222  ((Preference)findPreference(getString(R.string.pref_key_background_color))).setSummary("("+((ListPreference)findPreference(getString(R.string.pref_key_background_color))).getEntry() + ") "+getString(R.string.pref_summary_background_color));
223  ((Preference)findPreference(getString(R.string.pref_key_rendering_texture_decimation))).setSummary("("+((ListPreference)findPreference(getString(R.string.pref_key_rendering_texture_decimation))).getEntry() + ") "+getString(R.string.pref_summary_rendering_texture_decimation));
224 
225  ((Preference)findPreference(getString(R.string.pref_key_arcore_localization_filtering_speed))).setSummary("("+((ListPreference)findPreference(getString(R.string.pref_key_arcore_localization_filtering_speed))).getEntry() + ") "+getString(R.string.pref_summary_arcore_localization_filtering_speed));
226  ((Preference)findPreference(getString(R.string.pref_key_update_rate))).setSummary("("+((ListPreference)findPreference(getString(R.string.pref_key_update_rate))).getEntry() + ") "+getString(R.string.pref_summary_update_rate));
227  ((Preference)findPreference(getString(R.string.pref_key_max_speed))).setSummary("("+((ListPreference)findPreference(getString(R.string.pref_key_max_speed))).getEntry() + ") "+getString(R.string.pref_summary_max_speed));
228  ((Preference)findPreference(getString(R.string.pref_key_time_thr))).setSummary("("+((ListPreference)findPreference(getString(R.string.pref_key_time_thr))).getEntry() + ") "+getString(R.string.pref_summary_time_thr));
229  ((Preference)findPreference(getString(R.string.pref_key_mem_thr))).setSummary("("+((ListPreference)findPreference(getString(R.string.pref_key_mem_thr))).getEntry() + ") "+getString(R.string.pref_summary_mem_thr));
230  ((Preference)findPreference(getString(R.string.pref_key_loop_thr))).setSummary("("+((ListPreference)findPreference(getString(R.string.pref_key_loop_thr))).getEntry() + ") "+getString(R.string.pref_summary_loop_thr));
231  ((Preference)findPreference(getString(R.string.pref_key_sim_thr))).setSummary("("+((ListPreference)findPreference(getString(R.string.pref_key_sim_thr))).getEntry() + ") "+getString(R.string.pref_summary_sim_thr));
232  ((Preference)findPreference(getString(R.string.pref_key_min_inliers))).setSummary("("+((ListPreference)findPreference(getString(R.string.pref_key_min_inliers))).getEntry() + ") "+getString(R.string.pref_summary_min_inliers));
233  ((Preference)findPreference(getString(R.string.pref_key_opt_error))).setSummary("("+((ListPreference)findPreference(getString(R.string.pref_key_opt_error))).getEntry() + ") "+getString(R.string.pref_summary_opt_error));
234  ((Preference)findPreference(getString(R.string.pref_key_features_voc))).setSummary("("+((ListPreference)findPreference(getString(R.string.pref_key_features_voc))).getEntry() + ") "+getString(R.string.pref_summary_features_voc));
235  ((Preference)findPreference(getString(R.string.pref_key_features))).setSummary("("+((ListPreference)findPreference(getString(R.string.pref_key_features))).getEntry() + ") "+getString(R.string.pref_summary_features));
236  ((Preference)findPreference(getString(R.string.pref_key_features_type))).setSummary("("+((ListPreference)findPreference(getString(R.string.pref_key_features_type))).getEntry() + ") "+getString(R.string.pref_summary_features_type));
237  ((Preference)findPreference(getString(R.string.pref_key_optimizer))).setSummary("("+((ListPreference)findPreference(getString(R.string.pref_key_optimizer))).getEntry() + ") "+getString(R.string.pref_summary_optimizer));
238  ((Preference)findPreference(getString(R.string.pref_key_marker_detection))).setSummary("("+((ListPreference)findPreference(getString(R.string.pref_key_marker_detection))).getEntry() + ") "+getString(R.string.pref_summary_marker_detection));
239  ((Preference)findPreference(getString(R.string.pref_key_marker_detection_depth_error))).setSummary("("+((ListPreference)findPreference(getString(R.string.pref_key_marker_detection_depth_error))).getEntry() + ") "+getString(R.string.pref_summary_marker_detection_depth_error));
240 
241  ((Preference)findPreference(getString(R.string.pref_key_cloud_voxel))).setSummary("("+((ListPreference)findPreference(getString(R.string.pref_key_cloud_voxel))).getEntry() + ") "+getString(R.string.pref_summary_cloud_voxel));
242  ((Preference)findPreference(getString(R.string.pref_key_texture_size))).setSummary("("+((ListPreference)findPreference(getString(R.string.pref_key_texture_size))).getEntry() + ") "+getString(R.string.pref_summary_texture_size));
243  ((Preference)findPreference(getString(R.string.pref_key_texture_count))).setSummary("("+((ListPreference)findPreference(getString(R.string.pref_key_texture_count))).getEntry() + ") "+getString(R.string.pref_summary_texture_count));
244  ((Preference)findPreference(getString(R.string.pref_key_normal_k))).setSummary("("+((ListPreference)findPreference(getString(R.string.pref_key_normal_k))).getEntry() + ") "+getString(R.string.pref_summary_normal_k));
245  ((Preference)findPreference(getString(R.string.pref_key_max_texture_distance))).setSummary("("+((ListPreference)findPreference(getString(R.string.pref_key_max_texture_distance))).getEntry() + ") "+getString(R.string.pref_summary_max_texture_distance));
246  ((Preference)findPreference(getString(R.string.pref_key_min_texture_cluster_size))).setSummary("("+((ListPreference)findPreference(getString(R.string.pref_key_min_texture_cluster_size))).getEntry() + ") "+getString(R.string.pref_summary_min_texture_cluster_size));
247 
248  ((Preference)findPreference(getString(R.string.pref_key_opt_depth))).setSummary("("+((ListPreference)findPreference(getString(R.string.pref_key_opt_depth))).getEntry() + ") "+getString(R.string.pref_summary_opt_depth));
249  ((Preference)findPreference(getString(R.string.pref_key_opt_color_radius))).setSummary("("+((ListPreference)findPreference(getString(R.string.pref_key_opt_color_radius))).getEntry() + ") "+getString(R.string.pref_summary_opt_color_radius));
250  ((Preference)findPreference(getString(R.string.pref_key_opt_min_cluster_size))).setSummary("("+((ListPreference)findPreference(getString(R.string.pref_key_opt_min_cluster_size))).getEntry() + ") "+getString(R.string.pref_summary_opt_min_cluster_size));
251 
252  ((Preference)findPreference(getString(R.string.pref_key_cluster_ratio))).setSummary("("+((ListPreference)findPreference(getString(R.string.pref_key_cluster_ratio))).getEntry() + ") "+getString(R.string.pref_summary_cluster_ratio));
253  ((Preference)findPreference(getString(R.string.pref_key_gain_max_radius))).setSummary("("+((ListPreference)findPreference(getString(R.string.pref_key_gain_max_radius))).getEntry() + ") "+getString(R.string.pref_summary_gain_max_radius));
254  }
255 
256  public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
257  Preference pref = findPreference(key);
258 
259  if (pref instanceof ListPreference) {
260  if(key.compareTo(getString(R.string.pref_key_camera_driver))==0) pref.setSummary("("+ ((ListPreference)pref).getEntry() + ") "+getString(R.string.pref_summary_camera_driver));
261  if(key.compareTo(getString(R.string.pref_key_density))==0) pref.setSummary("("+ ((ListPreference)pref).getEntry() + ") "+getString(R.string.pref_summary_density));
262  if(key.compareTo(getString(R.string.pref_key_depth))==0)
263  {
264  pref.setSummary("("+((ListPreference)pref).getEntry() + ") "+getString(R.string.pref_summary_depth));
265  float maxDepth = Float.parseFloat(((ListPreference)pref).getValue());
266  float minDepth = Float.parseFloat(((ListPreference)findPreference(getString(R.string.pref_key_min_depth))).getValue());
267  if(maxDepth > 0.0f && maxDepth <= minDepth)
268  {
269  ((ListPreference)findPreference(getString(R.string.pref_key_min_depth))).setValueIndex(0);
270  }
271  }
272  if(key.compareTo(getString(R.string.pref_key_min_depth))==0)
273  {
274  pref.setSummary("("+((ListPreference)pref).getEntry() + ") "+getString(R.string.pref_summary_min_depth));
275  float maxDepth = Float.parseFloat(((ListPreference)findPreference(getString(R.string.pref_key_depth))).getValue());
276  float minDepth = Float.parseFloat(((ListPreference)pref).getValue());
277  if(minDepth >= maxDepth)
278  {
279  ((ListPreference)findPreference(getString(R.string.pref_key_depth))).setValueIndex(0);
280  }
281  }
282  if(key.compareTo(getString(R.string.pref_key_point_size))==0) pref.setSummary("("+((ListPreference)pref).getEntry() + ") "+getString(R.string.pref_summary_point_size));
283  if(key.compareTo(getString(R.string.pref_key_angle))==0) pref.setSummary("("+((ListPreference)pref).getEntry() + ") "+getString(R.string.pref_summary_angle));
284  if(key.compareTo(getString(R.string.pref_key_triangle))==0) pref.setSummary("("+((ListPreference)pref).getEntry() + ") "+getString(R.string.pref_summary_triangle));
285  if(key.compareTo(getString(R.string.pref_key_background_color))==0) pref.setSummary("("+((ListPreference)pref).getEntry() + ") "+getString(R.string.pref_summary_background_color));
286  if(key.compareTo(getString(R.string.pref_key_rendering_texture_decimation))==0) pref.setSummary("("+((ListPreference)pref).getEntry() + ") "+getString(R.string.pref_summary_rendering_texture_decimation));
287 
288  if(key.compareTo(getString(R.string.pref_key_arcore_localization_filtering_speed))==0) pref.setSummary("("+((ListPreference)pref).getEntry() + ") "+getString(R.string.pref_summary_arcore_localization_filtering_speed));
289  if(key.compareTo(getString(R.string.pref_key_update_rate))==0) pref.setSummary("("+((ListPreference)pref).getEntry() + ") "+getString(R.string.pref_summary_update_rate));
290  if(key.compareTo(getString(R.string.pref_key_max_speed))==0) pref.setSummary("("+((ListPreference)pref).getEntry() + ") "+getString(R.string.pref_summary_max_speed));
291  if(key.compareTo(getString(R.string.pref_key_time_thr))==0) pref.setSummary("("+((ListPreference)pref).getEntry() + ") "+getString(R.string.pref_summary_time_thr));
292  if(key.compareTo(getString(R.string.pref_key_mem_thr))==0) pref.setSummary("("+((ListPreference)pref).getEntry() + ") "+getString(R.string.pref_summary_mem_thr));
293  if(key.compareTo(getString(R.string.pref_key_loop_thr))==0) pref.setSummary("("+((ListPreference)pref).getEntry() + ") "+getString(R.string.pref_summary_loop_thr));
294  if(key.compareTo(getString(R.string.pref_key_sim_thr))==0) pref.setSummary("("+((ListPreference)pref).getEntry() + ") "+getString(R.string.pref_summary_sim_thr));
295  if(key.compareTo(getString(R.string.pref_key_min_inliers))==0) pref.setSummary("("+((ListPreference)pref).getEntry() + ") "+getString(R.string.pref_summary_min_inliers));
296  if(key.compareTo(getString(R.string.pref_key_opt_error))==0) pref.setSummary("("+((ListPreference)pref).getEntry() + ") "+getString(R.string.pref_summary_opt_error));
297  if(key.compareTo(getString(R.string.pref_key_features_voc))==0) pref.setSummary("("+((ListPreference)pref).getEntry() + ") "+getString(R.string.pref_summary_features_voc));
298  if(key.compareTo(getString(R.string.pref_key_features))==0) pref.setSummary("("+((ListPreference)pref).getEntry() + ") "+getString(R.string.pref_summary_features));
299  if(key.compareTo(getString(R.string.pref_key_features_type))==0) pref.setSummary("("+((ListPreference)pref).getEntry() + ") "+getString(R.string.pref_summary_features_type));
300  if(key.compareTo(getString(R.string.pref_key_optimizer))==0) pref.setSummary("("+((ListPreference)pref).getEntry() + ") "+getString(R.string.pref_summary_optimizer));
301  if(key.compareTo(getString(R.string.pref_key_marker_detection))==0) pref.setSummary("("+((ListPreference)pref).getEntry() + ") "+getString(R.string.pref_summary_marker_detection));
302  if(key.compareTo(getString(R.string.pref_key_marker_detection_depth_error))==0) pref.setSummary("("+((ListPreference)pref).getEntry() + ") "+getString(R.string.pref_summary_marker_detection_depth_error));
303 
304  if(key.compareTo(getString(R.string.pref_key_cloud_voxel))==0) pref.setSummary("("+((ListPreference)pref).getEntry() + ") "+getString(R.string.pref_summary_cloud_voxel));
305  if(key.compareTo(getString(R.string.pref_key_texture_size))==0) pref.setSummary("("+((ListPreference)pref).getEntry() + ") "+getString(R.string.pref_summary_texture_size));
306  if(key.compareTo(getString(R.string.pref_key_texture_count))==0) pref.setSummary("("+((ListPreference)pref).getEntry() + ") "+getString(R.string.pref_summary_texture_count));
307  if(key.compareTo(getString(R.string.pref_key_normal_k))==0) pref.setSummary("("+((ListPreference)pref).getEntry() + ") "+getString(R.string.pref_summary_normal_k));
308  if(key.compareTo(getString(R.string.pref_key_max_texture_distance))==0) pref.setSummary("("+((ListPreference)pref).getEntry() + ") "+getString(R.string.pref_summary_max_texture_distance));
309  if(key.compareTo(getString(R.string.pref_key_min_texture_cluster_size))==0) pref.setSummary("("+((ListPreference)pref).getEntry() + ") "+getString(R.string.pref_summary_min_texture_cluster_size));
310 
311  if(key.compareTo(getString(R.string.pref_key_opt_depth))==0) pref.setSummary("("+((ListPreference)pref).getEntry() + ") "+getString(R.string.pref_summary_opt_depth));
312  if(key.compareTo(getString(R.string.pref_key_opt_color_radius))==0) pref.setSummary("("+((ListPreference)pref).getEntry() + ") "+getString(R.string.pref_summary_opt_color_radius));
313  if(key.compareTo(getString(R.string.pref_key_opt_min_cluster_size))==0) pref.setSummary("("+((ListPreference)pref).getEntry() + ") "+getString(R.string.pref_summary_opt_min_cluster_size));
314 
315  if(key.compareTo(getString(R.string.pref_key_cluster_ratio))==0) pref.setSummary("("+((ListPreference)pref).getEntry() + ") "+getString(R.string.pref_summary_cluster_ratio));
316  if(key.compareTo(getString(R.string.pref_key_gain_max_radius))==0) pref.setSummary("("+((ListPreference)pref).getEntry() + ") "+getString(R.string.pref_summary_gain_max_radius));
317 
318  }
319  }
320 
321  @Override
322  protected void onResume() {
323  super.onResume();
324  // Set up a listener whenever a key changes
325  getPreferenceScreen().getSharedPreferences()
326  .registerOnSharedPreferenceChangeListener(this);
327  }
328 
329  @Override
330  protected void onPause() {
331  super.onPause();
332  // Unregister the listener whenever a key changes
333  getPreferenceScreen().getSharedPreferences()
334  .unregisterOnSharedPreferenceChangeListener(this);
335  }
336 
337  private void saveConfig(String fileName)
338  {
339  //sp1 is the shared pref to copy to
340  SharedPreferences.Editor ed = getActivity().getSharedPreferences(fileName, MODE_PRIVATE).edit();
341  SharedPreferences sp = getPreferenceScreen().getSharedPreferences(); //The shared preferences to copy from
342  ed.clear(); // This clears the one we are copying to, but you don't necessarily need to do that.
343  //Cycle through all the entries in the sp
344  for(Entry<String,?> entry : sp.getAll().entrySet()){
345  Object v = entry.getValue();
346  String key = entry.getKey();
347  //Now we just figure out what type it is, so we can copy it.
348  // Note that i am using Boolean and Integer instead of boolean and int.
349  // That's because the Entry class can only hold objects and int and boolean are primatives.
350  if(v instanceof Boolean)
351  // Also note that i have to cast the object to a Boolean
352  // and then use .booleanValue to get the boolean
353  ed.putBoolean(key, ((Boolean)v).booleanValue());
354  else if(v instanceof Float)
355  ed.putFloat(key, ((Float)v).floatValue());
356  else if(v instanceof Integer)
357  ed.putInt(key, ((Integer)v).intValue());
358  else if(v instanceof Long)
359  ed.putLong(key, ((Long)v).longValue());
360  else if(v instanceof String)
361  ed.putString(key, ((String)v));
362  }
363  ed.commit(); //save it.
364  }
365 
366  @Override
367  public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] results) {
368 
369  switch (requestCode) {
371  // If request is cancelled, the result arrays are empty.
372  if (results.length > 0 && results[0] == PackageManager.PERMISSION_GRANTED) {
373  // permission was granted, yay! Do the
374  // contacts-related task you need to do.
375  Preference buttonGPS = findPreference(getString(R.string.pref_key_gps_saved));
376  ((CustomSwitchPreference)buttonGPS).setChecked(true);
377  } else {
378  // permission denied, boo! Disable the
379  // functionality that depends on this permission.
380  Toast.makeText(this, "Location permission is needed to use GPS functionality", Toast.LENGTH_LONG).show();
381  if (!PermissionHelper.shouldShowRequestPermissionRationale(this, Manifest.permission.ACCESS_FINE_LOCATION)) {
382  PermissionHelper.launchPermissionSettings(this); // Permission denied with checking "Do not ask again".
383  }
384  }
385  return;
386  }
387  }
388  }
389 }
com.introlab.rtabmap.SettingsActivity.onRequestPermissionsResult
void onRequestPermissionsResult(int requestCode, String[] permissions, int[] results)
Definition: SettingsActivity.java:367
com.introlab.rtabmap.SettingsActivity.onSharedPreferenceChanged
void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key)
Definition: SettingsActivity.java:256
com.introlab.rtabmap.SettingsActivity.onResume
void onResume()
Definition: SettingsActivity.java:322
com.introlab.rtabmap.PermissionHelper.shouldShowRequestPermissionRationale
static boolean shouldShowRequestPermissionRationale(Activity activity, String permission)
Definition: PermissionHelper.java:68
Long
#define Long
Object
Float
FloatingPoint< float > Float
com.introlab.rtabmap.SettingsActivity.saveConfig
void saveConfig(String fileName)
Definition: SettingsActivity.java:337
Boolean
unsigned char Boolean
Definition: ConvertUTF.h:93
com.introlab.rtabmap.PermissionHelper
Definition: PermissionHelper.java:28
com.introlab.rtabmap.PermissionHelper.launchPermissionSettings
static void launchPermissionSettings(Activity activity)
Definition: PermissionHelper.java:73
com.introlab.rtabmap.SettingsActivity.getActivity
SettingsActivity getActivity()
Definition: SettingsActivity.java:29
key
const gtsam::Symbol key( 'X', 0)
f
Point2(* f)(const Point3 &, OptionalJacobian< 2, 3 >)
com.introlab.rtabmap.SettingsActivity.onCreate
void onCreate(Bundle savedInstanceState)
Definition: SettingsActivity.java:32
com.introlab.rtabmap.SettingsActivity.onPause
void onPause()
Definition: SettingsActivity.java:330
v
Array< int, Dynamic, 1 > v
results
std::map< std::string, Array< float, 1, 8, DontAlign|RowMajor > > results
com.introlab.rtabmap.CustomSwitchPreference
Definition: CustomSwitchPreference.java:18
com.introlab.rtabmap.PermissionHelper.ACCESS_FINE_LOCATION_CODE
static final int ACCESS_FINE_LOCATION_CODE
Definition: PermissionHelper.java:34
com.introlab.rtabmap.SettingsActivity
Definition: SettingsActivity.java:27
R
R


rtabmap
Author(s): Mathieu Labbe
autogenerated on Thu Jul 25 2024 02:50:16