Sofi Software's blog

To content | To menu | To search

Tuesday 1 November 2011

Time Machine full restore... and Dropbox... equals oops

Am hoping this saves someone some time...

I had a catastrophic drive failure last Friday. Fortunately Time Machine worked perfectly. However, after I restored onto a new boot drive, someone I work with noted that Dropbox says I deleted a file. I didn't, so I was confused, until I made the connection. Somehow the TM restore didn't restore the file (possibly it was damaged and so not backed up), and so DB thought I deleted it.

You may wish to set TM to not back up your Dropbox folder, or at least shared Dropbox folders, or if you go through this pain, review the files in DB carefully.

Wednesday 5 October 2011

Android Library projects and Jars

Android Library projects are really great for code reuse. But sometimes you want to create a library, that has resources in it, but you don't want to ship source code with it. It's possible to do this, but a little tricky.

This article has a great overview of how to use an Ant build.xml file to create a jar. But it leaves one with the impression that an Android Library project requires you to ship source with the library.

AndParcel has some really detailed information on Android Libraries and the issues involved in using a JAR file to distribute object code, and the relationship to resources. For example, the article on JAR files suggests users of your library will need to unpack resources into their projects:

The people reusing your code will need to not only add the JAR to their projects, but also unpack those shipped resources (in their respective resource sets) and put them in their projects as well.

Neither of these mentions another easy way to distribute Android Library projects with a JAR file, and resources. That is:

  1. Create an Android Library project that contains only resources. Users add the resources with the Android properties panel Library reference panel.
  2. Create an Android project that contains only code, and whose end product is a JAR. Users just add the JAR to their project build path.

If the code in the JAR references the resources, the best solution is to use context.getResources().getIdentifier() to look up the resource ids. This is slower than a direct reference to the id, but it prevents issues where the number of the id in the library's version of R.java is different than the number of the id in the application's version of R.java.

Thursday 29 September 2011

Android: Display Preference value in Preference screen

This blog entry describes how to use the summary field in a ListPreference to show its value. This works well. The same technique is also needed for an EditTextPreference, where the value is entered in a dialog.</p>

This can be done by adding keys for the additional preferences to the array of preference keys.

   private ArrayList<Preference> mPreferences = new ArrayList<Preference>();
   private String mPreferenceKeys = new String {
       "listPreferenceKey",
       "editTextPreferenceKey"
   };
   private OnSharedPreferenceChangeListener mListener;

The listener that updates the summary area in the Preference needs to distinguish between ListPreference and a string EditTextPreference. This is done simply using the instanceof operator.

   @Override
   protected void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       addPreferencesFromResource(R.xml.filter_preference_screen);
       mListener = new OnSharedPreferenceChangeListener() {
           @Override
           public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
               for (Preference pref : mPreferences) {
                   if (pref.getKey().equals(key)) {
                       if (pref instanceof ListPreference) {
                           pref.setSummary;
                       } else {
                           pref.setSummary(sharedPreferences.getString(key, "<None>"));
                       }
                       break;
                   }
               }
           }
       };
       SharedPreferences prefs = getPreferenceManager().getSharedPreferences();
       prefs.registerOnSharedPreferenceChangeListener(mListener);
       for (String prefKey : mPreferenceKeys) {
           Preference pref = (Preference) getPreferenceManager().findPreference(prefKey);
           mPreferences.add(pref);
           mListener.onSharedPreferenceChanged(prefs, prefKey);
       }
   }

Additionally, the preference listener needs to be unregistered when the activity is destroyed.

   @Override
   protected void onDestroy() {
       SharedPreferences prefs = getPreferenceManager().getSharedPreferences();
       prefs.unregisterOnSharedPreferenceChangeListener(mListener);
       super.onDestroy();
   }

Tuesday 20 September 2011

New web site

Our new web site is operational! There's not much to comment about, just go check it out...

Tuesday 12 July 2011

App available on iTunes

Sofi Software's first app, an interactive exploration of artist Paul Madonna's work, is now available as a free download on iTunes! Check it out and let us know what you think.

We're very excited about this. It took awhile to go through the app review process, but it is finally done...

Wednesday 1 June 2011

First app in review

Sofi Software's first app is now in review in the Apple iTunes store! I'm obviously very excited about this. When the app is approved, we'll publish more details. Stay tuned!

Friday 20 May 2011

Follow us on Twitter!

Follow Sofi Software on twitter: @sofisoftware

Wednesday 24 November 2010

About Sofi Software

Sofi Software is a consulting firm, specializing in iOS, Android, Mac OS X, and Windows development. We are located in the San Francisco Bay Area.