SettingsActivity.java
Go to the documentation of this file.
00001 package com.introlab.rtabmap;
00002 
00003 import java.io.File;
00004 import java.text.SimpleDateFormat;
00005 import java.util.ArrayList;
00006 import java.util.Arrays;
00007 import java.util.Iterator;
00008 import java.util.Map.Entry;
00009 
00010 import android.app.AlertDialog;
00011 import android.content.DialogInterface;
00012 import android.content.SharedPreferences;
00013 import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
00014 import android.os.Bundle;
00015 import android.preference.ListPreference;
00016 import android.preference.Preference;
00017 import android.preference.PreferenceActivity;
00018 import android.text.InputType;
00019 import android.view.WindowManager;
00020 import android.view.inputmethod.EditorInfo;
00021 import android.widget.EditText;
00022 
00023 public class SettingsActivity extends PreferenceActivity implements OnSharedPreferenceChangeListener {
00024         
00025         private SettingsActivity getActivity() {return this;}
00026         
00027     @Override
00028     public void onCreate(Bundle savedInstanceState) {
00029         super.onCreate(savedInstanceState);
00030         addPreferencesFromResource(R.layout.activity_settings);
00031         
00032         Preference buttonReset = findPreference(getString(R.string.pref_key_reset_button));
00033         buttonReset.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
00034                 @Override
00035                 public boolean onPreferenceClick(Preference preference) {   
00036                         getPreferenceScreen().getSharedPreferences().edit().clear().commit();
00037                         
00038                 recreate();
00039                         
00040                         return true;
00041                 }
00042         });
00043         
00044         Preference buttonOpen = findPreference(getString(R.string.pref_key_open_button));
00045         buttonOpen.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
00046                 @Override
00047                 public boolean onPreferenceClick(Preference preference) {   
00048                         File prefsdir = new File(getApplicationInfo().dataDir,"shared_prefs");
00049                         if(prefsdir.exists() && prefsdir.isDirectory()){
00050                                 ArrayList<String> filesArray = new ArrayList<String>(Arrays.asList(prefsdir.list()));
00051                                 ArrayList<String> newList = new ArrayList<String>();
00052                                 filesArray.remove("com.introlab.rtabmap_preferences.xml");
00053                                 filesArray.remove("WebViewChromiumPrefs.xml");
00054                                 for (String s : filesArray) {
00055                                         newList.add(s.substring(0, s.length()-4)); // rip off the ".xml"
00056                                 }
00057                                 final String[] files = newList.toArray(new String[filesArray.size()]);
00058                                 if(files.length > 0)
00059                                 {
00060                                         AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
00061                                         builder.setTitle("Choose Presets:");
00062                                         builder.setItems(files, new DialogInterface.OnClickListener() {
00063                                                 public void onClick(DialogInterface dialog, final int which) {
00064                                                         //sp1 is the shared pref to copy to
00065                                                         SharedPreferences.Editor ed = getPreferenceScreen().getSharedPreferences().edit(); 
00066                                                         SharedPreferences sp = getActivity().getSharedPreferences(files[which], MODE_PRIVATE); //The shared preferences to copy from
00067                                                         //Cycle through all the entries in the sp
00068                                                         for(Entry<String,?> entry : sp.getAll().entrySet()){ 
00069                                                          Object v = entry.getValue(); 
00070                                                          String key = entry.getKey();
00071                                                          //Now we just figure out what type it is, so we can copy it.
00072                                                          // Note that i am using Boolean and Integer instead of boolean and int.
00073                                                          // That's because the Entry class can only hold objects and int and boolean are primatives.
00074                                                          if(v instanceof Boolean) 
00075                                                          // Also note that i have to cast the object to a Boolean 
00076                                                          // and then use .booleanValue to get the boolean
00077                                                             ed.putBoolean(key, ((Boolean)v).booleanValue());
00078                                                          else if(v instanceof Float)
00079                                                             ed.putFloat(key, ((Float)v).floatValue());
00080                                                          else if(v instanceof Integer)
00081                                                             ed.putInt(key, ((Integer)v).intValue());
00082                                                          else if(v instanceof Long)
00083                                                             ed.putLong(key, ((Long)v).longValue());
00084                                                          else if(v instanceof String)
00085                                                             ed.putString(key, ((String)v));         
00086                                                         }
00087                                                         ed.commit(); //save it.
00088                                                         recreate();
00089                                                         return;
00090                                                 }
00091                                         });
00092                                         builder.show();
00093                                 }   
00094                         }
00095 
00096                         return true;
00097                 }
00098         });
00099         
00100         Preference buttonSave = findPreference(getString(R.string.pref_key_save_button));
00101         buttonSave.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
00102                 @Override
00103                 public boolean onPreferenceClick(Preference preference) {   
00104                         AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
00105                         builder.setTitle("Save Presets:");
00106                         final EditText input = new EditText(getActivity());
00107                         input.setInputType(InputType.TYPE_CLASS_TEXT); 
00108                         input.setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI);
00109                         builder.setView(input);
00110                         builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
00111                                 @Override
00112                                 public void onClick(DialogInterface dialog, int which)
00113                                 {
00114                                         final String fileName = input.getText().toString();  
00115                                         dialog.dismiss();
00116                                         if(!fileName.isEmpty())
00117                                         {
00118                                                 File newFile = new File(getApplicationInfo().dataDir + "/shared_prefs/" + fileName + ".xml");
00119                                                 if(newFile.exists())
00120                                                 {
00121                                                         new AlertDialog.Builder(getActivity())
00122                                                         .setTitle("Presets Already Exist")
00123                                                         .setMessage("Do you want to overwrite the existing file?")
00124                                                         .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
00125                                                                 public void onClick(DialogInterface dialog, int which) {
00126                                                                         saveConfig(fileName);
00127                                                                 }
00128                                                         })
00129                                                         .setNegativeButton("No", new DialogInterface.OnClickListener() {
00130                                                                 public void onClick(DialogInterface dialog, int which) {
00131                                                                         dialog.dismiss();
00132                                                                 }
00133                                                         })
00134                                                         .show();
00135                                                 }
00136                                                 else
00137                                                 {
00138                                                         saveConfig(fileName);
00139                                                 }
00140                                         }
00141                                 }
00142                         });
00143                         AlertDialog alertToShow = builder.create();
00144                         alertToShow.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
00145                         alertToShow.show();
00146 
00147                         return true;
00148                 }
00149         });
00150         
00151         Preference buttonRemove = findPreference(getString(R.string.pref_key_remove_button));
00152         buttonRemove.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
00153                 @Override
00154                 public boolean onPreferenceClick(Preference preference) {   
00155                         File prefsdir = new File(getApplicationInfo().dataDir,"shared_prefs");
00156                         if(prefsdir.exists() && prefsdir.isDirectory()){
00157                                 ArrayList<String> filesArray = new ArrayList<String>(Arrays.asList(prefsdir.list()));
00158                                 ArrayList<String> newList = new ArrayList<String>();
00159                                 filesArray.remove("com.introlab.rtabmap_preferences.xml");
00160                                 filesArray.remove("WebViewChromiumPrefs.xml");
00161                                 for (String s : filesArray) {
00162                                         newList.add(s.substring(0, s.length()-4)); // rip off the ".xml"
00163                                 }
00164                                 final String[] files = newList.toArray(new String[filesArray.size()]);
00165                                 if(files.length > 0)
00166                                 {
00167                                         AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
00168                                         builder.setTitle("Remove Presets:");
00169                                         builder.setItems(files, new DialogInterface.OnClickListener() {
00170                                                 public void onClick(DialogInterface dialog, final int which) {
00171                                                         File file = new File(getApplicationInfo().dataDir + "/shared_prefs/" + files[which] + ".xml");
00172                                                         if(file.exists())
00173                                                         {
00174                                                                 file.delete();
00175                                                         }
00176                                                         return;
00177                                                 }
00178                                         });
00179                                         builder.show();
00180                                 }   
00181                         }
00182 
00183                         return true;
00184                 }
00185         });
00186         
00187         
00188         ((Preference)findPreference(getString(R.string.pref_key_density))).setSummary("("+((ListPreference)findPreference(getString(R.string.pref_key_density))).getEntry() + ") "+getString(R.string.pref_summary_density));
00189         ((Preference)findPreference(getString(R.string.pref_key_depth))).setSummary("("+((ListPreference)findPreference(getString(R.string.pref_key_depth))).getEntry() + ") "+getString(R.string.pref_summary_depth));
00190         ((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));
00191         ((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));
00192         ((Preference)findPreference(getString(R.string.pref_key_angle))).setSummary("("+((ListPreference)findPreference(getString(R.string.pref_key_angle))).getEntry() + ") "+getString(R.string.pref_summary_angle));
00193         ((Preference)findPreference(getString(R.string.pref_key_triangle))).setSummary("("+((ListPreference)findPreference(getString(R.string.pref_key_triangle))).getEntry() + ") "+getString(R.string.pref_summary_triangle));
00194         ((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));
00195         ((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));
00196           
00197         ((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));
00198         ((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));
00199         ((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));
00200         ((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));
00201         ((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));
00202         ((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));
00203         ((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));
00204         ((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));
00205         ((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));
00206         ((Preference)findPreference(getString(R.string.pref_key_features))).setSummary("("+((ListPreference)findPreference(getString(R.string.pref_key_features))).getEntry() + ") "+getString(R.string.pref_summary_features));
00207         ((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));
00208         ((Preference)findPreference(getString(R.string.pref_key_optimizer))).setSummary("("+((ListPreference)findPreference(getString(R.string.pref_key_optimizer))).getEntry() + ") "+getString(R.string.pref_summary_optimizer));
00209         
00210         ((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));
00211         ((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));
00212         ((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));
00213         ((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));
00214         ((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));
00215         ((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));
00216 
00217         ((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));
00218         ((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));
00219         ((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));
00220 
00221         ((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));
00222         ((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));
00223     }
00224     
00225     public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
00226         Preference pref = findPreference(key);
00227 
00228         if (pref instanceof ListPreference) {
00229                 if(key.compareTo(getString(R.string.pref_key_density))==0) pref.setSummary("("+ ((ListPreference)pref).getEntry() + ") "+getString(R.string.pref_summary_density));
00230                 if(key.compareTo(getString(R.string.pref_key_depth))==0) 
00231                 {
00232                         pref.setSummary("("+((ListPreference)pref).getEntry() + ") "+getString(R.string.pref_summary_depth));
00233                         float maxDepth = Float.parseFloat(((ListPreference)pref).getValue());
00234                         float minDepth = Float.parseFloat(((ListPreference)findPreference(getString(R.string.pref_key_min_depth))).getValue());
00235                         if(maxDepth > 0.0f && maxDepth <= minDepth)
00236                         {
00237                                 ((ListPreference)findPreference(getString(R.string.pref_key_min_depth))).setValueIndex(0);
00238                         }
00239                 }
00240                 if(key.compareTo(getString(R.string.pref_key_min_depth))==0) 
00241                 {
00242                         pref.setSummary("("+((ListPreference)pref).getEntry() + ") "+getString(R.string.pref_summary_min_depth));
00243                         float maxDepth = Float.parseFloat(((ListPreference)findPreference(getString(R.string.pref_key_depth))).getValue());
00244                         float minDepth = Float.parseFloat(((ListPreference)pref).getValue());
00245                         if(minDepth >= maxDepth)
00246                         {
00247                                 ((ListPreference)findPreference(getString(R.string.pref_key_depth))).setValueIndex(0);
00248                         }
00249                 }
00250                 if(key.compareTo(getString(R.string.pref_key_point_size))==0) pref.setSummary("("+((ListPreference)pref).getEntry() + ") "+getString(R.string.pref_summary_point_size));
00251                 if(key.compareTo(getString(R.string.pref_key_angle))==0) pref.setSummary("("+((ListPreference)pref).getEntry() + ") "+getString(R.string.pref_summary_angle));
00252                 if(key.compareTo(getString(R.string.pref_key_triangle))==0) pref.setSummary("("+((ListPreference)pref).getEntry() + ") "+getString(R.string.pref_summary_triangle));
00253                 if(key.compareTo(getString(R.string.pref_key_background_color))==0) pref.setSummary("("+((ListPreference)pref).getEntry() + ") "+getString(R.string.pref_summary_background_color));
00254                 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));
00255                 
00256                 if(key.compareTo(getString(R.string.pref_key_update_rate))==0) pref.setSummary("("+((ListPreference)pref).getEntry() + ") "+getString(R.string.pref_summary_update_rate));
00257                 if(key.compareTo(getString(R.string.pref_key_max_speed))==0) pref.setSummary("("+((ListPreference)pref).getEntry() + ") "+getString(R.string.pref_summary_max_speed));
00258                 if(key.compareTo(getString(R.string.pref_key_time_thr))==0) pref.setSummary("("+((ListPreference)pref).getEntry() + ") "+getString(R.string.pref_summary_time_thr));
00259                 if(key.compareTo(getString(R.string.pref_key_mem_thr))==0) pref.setSummary("("+((ListPreference)pref).getEntry() + ") "+getString(R.string.pref_summary_mem_thr));
00260                 if(key.compareTo(getString(R.string.pref_key_loop_thr))==0) pref.setSummary("("+((ListPreference)pref).getEntry() + ") "+getString(R.string.pref_summary_loop_thr));
00261                 if(key.compareTo(getString(R.string.pref_key_sim_thr))==0) pref.setSummary("("+((ListPreference)pref).getEntry() + ") "+getString(R.string.pref_summary_sim_thr));
00262                 if(key.compareTo(getString(R.string.pref_key_min_inliers))==0) pref.setSummary("("+((ListPreference)pref).getEntry() + ") "+getString(R.string.pref_summary_min_inliers));
00263                 if(key.compareTo(getString(R.string.pref_key_opt_error))==0) pref.setSummary("("+((ListPreference)pref).getEntry() + ") "+getString(R.string.pref_summary_opt_error));
00264                 if(key.compareTo(getString(R.string.pref_key_features_voc))==0) pref.setSummary("("+((ListPreference)pref).getEntry() + ") "+getString(R.string.pref_summary_features_voc));
00265                 if(key.compareTo(getString(R.string.pref_key_features))==0) pref.setSummary("("+((ListPreference)pref).getEntry() + ") "+getString(R.string.pref_summary_features));
00266                 if(key.compareTo(getString(R.string.pref_key_features_type))==0) pref.setSummary("("+((ListPreference)pref).getEntry() + ") "+getString(R.string.pref_summary_features_type));
00267                 if(key.compareTo(getString(R.string.pref_key_optimizer))==0) pref.setSummary("("+((ListPreference)pref).getEntry() + ") "+getString(R.string.pref_summary_optimizer));
00268                 
00269                 if(key.compareTo(getString(R.string.pref_key_cloud_voxel))==0) pref.setSummary("("+((ListPreference)pref).getEntry() + ") "+getString(R.string.pref_summary_cloud_voxel));
00270                 if(key.compareTo(getString(R.string.pref_key_texture_size))==0) pref.setSummary("("+((ListPreference)pref).getEntry() + ") "+getString(R.string.pref_summary_texture_size));
00271                 if(key.compareTo(getString(R.string.pref_key_texture_count))==0) pref.setSummary("("+((ListPreference)pref).getEntry() + ") "+getString(R.string.pref_summary_texture_count));
00272                 if(key.compareTo(getString(R.string.pref_key_normal_k))==0) pref.setSummary("("+((ListPreference)pref).getEntry() + ") "+getString(R.string.pref_summary_normal_k));
00273                 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));
00274                 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));
00275 
00276                 if(key.compareTo(getString(R.string.pref_key_opt_depth))==0) pref.setSummary("("+((ListPreference)pref).getEntry() + ") "+getString(R.string.pref_summary_opt_depth));
00277                 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));
00278                 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));
00279                 
00280                 if(key.compareTo(getString(R.string.pref_key_cluster_ratio))==0) pref.setSummary("("+((ListPreference)pref).getEntry() + ") "+getString(R.string.pref_summary_cluster_ratio));
00281                 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));
00282         
00283         }
00284     }
00285     
00286     @Override
00287     protected void onResume() {
00288         super.onResume();
00289         // Set up a listener whenever a key changes
00290         getPreferenceScreen().getSharedPreferences()
00291                 .registerOnSharedPreferenceChangeListener(this);
00292     }
00293 
00294     @Override
00295     protected void onPause() {
00296         super.onPause();
00297         // Unregister the listener whenever a key changes
00298         getPreferenceScreen().getSharedPreferences()
00299                 .unregisterOnSharedPreferenceChangeListener(this);
00300     }
00301     
00302     private void saveConfig(String fileName)
00303     {
00304         //sp1 is the shared pref to copy to
00305                 SharedPreferences.Editor ed = getActivity().getSharedPreferences(fileName, MODE_PRIVATE).edit(); 
00306                 SharedPreferences sp = getPreferenceScreen().getSharedPreferences(); //The shared preferences to copy from
00307                 ed.clear(); // This clears the one we are copying to, but you don't necessarily need to do that.
00308                 //Cycle through all the entries in the sp
00309                 for(Entry<String,?> entry : sp.getAll().entrySet()){ 
00310                  Object v = entry.getValue(); 
00311                  String key = entry.getKey();
00312                  //Now we just figure out what type it is, so we can copy it.
00313                  // Note that i am using Boolean and Integer instead of boolean and int.
00314                  // That's because the Entry class can only hold objects and int and boolean are primatives.
00315                  if(v instanceof Boolean) 
00316                  // Also note that i have to cast the object to a Boolean 
00317                  // and then use .booleanValue to get the boolean
00318                     ed.putBoolean(key, ((Boolean)v).booleanValue());
00319                  else if(v instanceof Float)
00320                     ed.putFloat(key, ((Float)v).floatValue());
00321                  else if(v instanceof Integer)
00322                     ed.putInt(key, ((Integer)v).intValue());
00323                  else if(v instanceof Long)
00324                     ed.putLong(key, ((Long)v).longValue());
00325                  else if(v instanceof String)
00326                     ed.putString(key, ((String)v));         
00327                 }
00328                 ed.commit(); //save it.
00329     }
00330 }


rtabmap
Author(s): Mathieu Labbe
autogenerated on Thu Jun 6 2019 21:59:22