Disable change log; to remove in future
[pub/Android/ownCloud.git] / src / com / owncloud / android / ui / activity / AccountSelectActivity.java
index 50f7625..31b59d4 100644 (file)
@@ -1,3 +1,22 @@
+/* ownCloud Android client application
+ *   Copyright (C) 2012 Bartek Przybylski
+ *   Copyright (C) 2012-2013 ownCloud Inc.
+ *
+ *   This program is free software: you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation, either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
 package com.owncloud.android.ui.activity;
 
 import java.util.HashMap;
@@ -19,9 +38,7 @@ import android.view.ContextMenu;
 import android.view.View;
 import android.view.ViewGroup;
 import android.view.ContextMenu.ContextMenuInfo;
-import android.widget.AdapterView;
 import android.widget.AdapterView.AdapterContextMenuInfo;
-import android.widget.AdapterView.OnItemLongClickListener;
 import android.widget.CheckedTextView;
 import android.widget.ListView;
 import android.widget.SimpleAdapter;
@@ -40,6 +57,8 @@ import com.owncloud.android.R;
 public class AccountSelectActivity extends SherlockListActivity implements
         AccountManagerCallback<Boolean> {
 
+    private static final String  TAG = "AccountSelectActivity";
+    
     private static final String PREVIOUS_ACCOUNT_KEY = "ACCOUNT";
     
     private final Handler mHandler = new Handler();
@@ -124,13 +143,20 @@ public class AccountSelectActivity extends SherlockListActivity implements
         return false;
     }
 
+    @SuppressWarnings("unchecked")
     @Override
     public boolean onContextItemSelected(android.view.MenuItem item) {
         AdapterContextMenuInfo info = (AdapterContextMenuInfo) item
                 .getMenuInfo();
         int index = info.position;
-        HashMap<String, String> map = (HashMap<String, String>) getListAdapter()
-                .getItem(index);
+        HashMap<String, String> map = null;
+        try {
+            map = (HashMap<String, String>) getListAdapter().getItem(index);
+        } catch (ClassCastException e) {
+            Log.wtf(TAG, "getitem(index) from list adapter did not return hashmap, bailing out");
+            return false;
+        }
+        
         String accountName = map.get("NAME");
         AccountManager am = (AccountManager) getSystemService(ACCOUNT_SERVICE);
         Account accounts[] = am
@@ -141,7 +167,7 @@ public class AccountSelectActivity extends SherlockListActivity implements
             }
         }
 
-        return false;
+        return true;
     }
 
     private void populateAccountList() {