moving from eu.alefzero.eu to com.owncloud.android
[pub/Android/ownCloud.git] / src / eu / alefzero / owncloud / ui / activity / FileDisplayActivity.java
diff --git a/src/eu/alefzero/owncloud/ui/activity/FileDisplayActivity.java b/src/eu/alefzero/owncloud/ui/activity/FileDisplayActivity.java
deleted file mode 100644 (file)
index cec268b..0000000
+++ /dev/null
@@ -1,428 +0,0 @@
-/* ownCloud Android client application\r
- *   Copyright (C) 2011  Bartek Przybylski\r
- *\r
- *   This program is free software: you can redistribute it and/or modify\r
- *   it under the terms of the GNU General Public License as published by\r
- *   the Free Software Foundation, either version 3 of the License, or\r
- *   (at your option) any later version.\r
- *\r
- *   This program is distributed in the hope that it will be useful,\r
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
- *   GNU General Public License for more details.\r
- *\r
- *   You should have received a copy of the GNU General Public License\r
- *   along with this program.  If not, see <http://www.gnu.org/licenses/>.\r
- *\r
- */\r
-\r
-package eu.alefzero.owncloud.ui.activity;\r
-\r
-import android.accounts.Account;\r
-import android.accounts.AccountManager;\r
-import android.app.AlertDialog;\r
-import android.app.AlertDialog.Builder;\r
-import android.app.Dialog;\r
-import android.content.Context;\r
-import android.content.DialogInterface;\r
-import android.content.DialogInterface.OnClickListener;\r
-import android.content.BroadcastReceiver;\r
-import android.content.ContentResolver;\r
-import android.content.Intent;\r
-import android.content.IntentFilter;\r
-import android.database.Cursor;\r
-import android.net.Uri;\r
-import android.os.Bundle;\r
-import android.provider.MediaStore;\r
-import android.util.Log;\r
-import android.view.View;\r
-import android.view.ViewGroup;\r
-import android.widget.ArrayAdapter;\r
-import android.widget.EditText;\r
-import android.widget.TextView;\r
-\r
-import com.actionbarsherlock.app.ActionBar;\r
-import com.actionbarsherlock.app.ActionBar.OnNavigationListener;\r
-import com.actionbarsherlock.app.SherlockFragmentActivity;\r
-import com.actionbarsherlock.view.Menu;\r
-import com.actionbarsherlock.view.MenuInflater;\r
-import com.actionbarsherlock.view.MenuItem;\r
-import com.actionbarsherlock.view.Window;\r
-\r
-import eu.alefzero.owncloud.AccountUtils;\r
-import eu.alefzero.owncloud.R;\r
-import eu.alefzero.owncloud.authenticator.AccountAuthenticator;\r
-import eu.alefzero.owncloud.datamodel.DataStorageManager;\r
-import eu.alefzero.owncloud.datamodel.FileDataStorageManager;\r
-import eu.alefzero.owncloud.datamodel.OCFile;\r
-import eu.alefzero.owncloud.syncadapter.FileSyncService;\r
-import eu.alefzero.owncloud.ui.fragment.FileListFragment;\r
-import eu.alefzero.webdav.WebdavClient;\r
-\r
-/**\r
- * Displays, what files the user has available in his ownCloud.\r
- * \r
- * @author Bartek Przybylski\r
- * \r
- */\r
-\r
-public class FileDisplayActivity extends SherlockFragmentActivity implements\r
-               OnNavigationListener, OnClickListener {\r
-       private ArrayAdapter<String> mDirectories;\r
-       private DataStorageManager mStorageManager;\r
-\r
-       private BR  b;\r
-       \r
-       private static final int DIALOG_SETUP_ACCOUNT = 0;\r
-       private static final int DIALOG_CREATE_DIR = 1;\r
-       \r
-       private static final int REQUEST_ACCOUNT_SETUP = 0;\r
-       private static final int ACTION_SELECT_FILE = 1;\r
-\r
-       public void pushPath(String path) {\r
-               mDirectories.insert(path, 0);\r
-       }\r
-\r
-       public boolean popPath() {\r
-               mDirectories.remove(mDirectories.getItem(0));\r
-               return !mDirectories.isEmpty();\r
-       }\r
-\r
-       @Override\r
-  protected Dialog onCreateDialog(int id) {\r
-    Dialog dialog;\r
-    AlertDialog.Builder builder;\r
-    switch(id){\r
-    case DIALOG_SETUP_ACCOUNT:\r
-      builder = new AlertDialog.Builder(this);\r
-      builder.setTitle(R.string.main_tit_accsetup);\r
-      builder.setMessage(R.string.main_wrn_accsetup);\r
-      builder.setCancelable(false);\r
-      builder.setPositiveButton(android.R.string.ok, this);\r
-      builder.setNegativeButton(android.R.string.cancel, this);\r
-      dialog = builder.create();\r
-      break;\r
-    case DIALOG_CREATE_DIR:\r
-    {\r
-      builder = new Builder(this);\r
-      final EditText dirName = new EditText(getBaseContext());\r
-      final Account a = AccountUtils.getCurrentOwnCloudAccount(this);\r
-      builder.setView(dirName);\r
-      builder.setTitle(R.string.uploader_info_dirname);\r
-      int typed_color = getResources().getColor(R.color.setup_text_typed);\r
-      dirName.setTextColor(typed_color);\r
-\r
-      builder.setPositiveButton(android.R.string.ok, new OnClickListener() {\r
-        public void onClick(DialogInterface dialog, int which) {\r
-          String s = dirName.getText().toString();\r
-          if (s.trim().length() == 0) {\r
-            dialog.cancel();\r
-            return;\r
-          }\r
-\r
-          String path = "";\r
-          for (int i = mDirectories.getCount() - 2; i >= 0; --i) {\r
-            path += "/" + mDirectories.getItem(i);\r
-          }\r
-          OCFile parent = mStorageManager.getFileByPath(path + "/");\r
-          path += s + "/";\r
-          Thread thread = new Thread(new DirectoryCreator(path, a));\r
-          thread.start();\r
-          \r
-          OCFile new_file = new OCFile(path);\r
-          new_file.setMimetype("DIR");\r
-          new_file.setParentId(parent.getParentId());\r
-          mStorageManager.saveFile(new_file);\r
-\r
-          dialog.dismiss();\r
-        }\r
-      });\r
-      builder.setNegativeButton(R.string.common_cancel,\r
-          new OnClickListener() {\r
-            public void onClick(DialogInterface dialog, int which) {\r
-              dialog.cancel();\r
-            }\r
-          });\r
-      dialog = builder.create();\r
-      break;\r
-    }\r
-    default: \r
-      dialog = null;\r
-    }\r
-      \r
-    return dialog;\r
-  }\r
-\r
-       @Override\r
-       public void onCreate(Bundle savedInstanceState) {\r
-               super.onCreate(savedInstanceState);\r
-\r
-               if(!accountsAreSetup()){\r
-      showDialog(DIALOG_SETUP_ACCOUNT);\r
-      return;\r
-    }\r
-               \r
-               requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);\r
-    setProgressBarIndeterminateVisibility(false);\r
-       }\r
-\r
-       @Override\r
-       public boolean onOptionsItemSelected(MenuItem item) {\r
-         boolean retval = true;\r
-               switch (item.getItemId()) {\r
-               case R.id.settingsItem: {\r
-                       Intent i = new Intent(this, Preferences.class);\r
-                       startActivity(i);\r
-                       break;\r
-               }\r
-               case R.id.createDirectoryItem: {\r
-                       showDialog(DIALOG_CREATE_DIR);\r
-                       break;\r
-               }\r
-               case R.id.startSync: {\r
-                 Bundle bundle = new Bundle();\r
-      bundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);\r
-      ContentResolver.requestSync(AccountUtils.getCurrentOwnCloudAccount(this),\r
-                     "org.owncloud",\r
-                     bundle);\r
-      break;\r
-               }\r
-               case R.id.action_upload: {\r
-                 Intent action = new Intent(Intent.ACTION_GET_CONTENT);  \r
-                 action = action.setType("*/*").addCategory(Intent.CATEGORY_OPENABLE);  \r
-                 startActivityForResult(Intent.createChooser(action, "Upload file from..."), ACTION_SELECT_FILE);\r
-                 break;\r
-               }\r
-                 \r
-               case android.R.id.home: {\r
-                 Intent i = new Intent(this, AccountSelectActivity.class);\r
-                 startActivity(i);\r
-                 finish();\r
-                       break;\r
-               }\r
-                       default:\r
-                         retval = false;\r
-               }\r
-               return retval;\r
-       }\r
-       \r
-       @Override\r
-       public void onBackPressed(){\r
-               if(mDirectories.getCount() == 1) {\r
-                 finish();\r
-                       return;\r
-               }\r
-               popPath();\r
-               ((FileListFragment) getSupportFragmentManager().findFragmentById(R.id.fileList))\r
-                               .onNavigateUp();\r
-       }\r
-\r
-       @Override\r
-       public boolean onCreateOptionsMenu(Menu menu) {\r
-               MenuInflater inflater = getSherlock().getMenuInflater();\r
-               inflater.inflate(R.menu.menu, menu);\r
-               return true;\r
-       }\r
-\r
-        @Override\r
-         protected void onRestoreInstanceState(Bundle savedInstanceState) {\r
-           super.onRestoreInstanceState(savedInstanceState);\r
-           // Check, if there are ownCloud accounts\r
-           if(!accountsAreSetup()){\r
-             showDialog(DIALOG_SETUP_ACCOUNT);\r
-           }\r
-         }\r
-\r
-           \r
-        @Override\r
-       protected void onResume() {\r
-         super.onResume();\r
-         if(!accountsAreSetup()){\r
-      showDialog(DIALOG_SETUP_ACCOUNT);\r
-      return;\r
-    }\r
-         \r
-          IntentFilter f = new IntentFilter(FileSyncService.SYNC_MESSAGE);\r
-          b = new  BR();\r
-          registerReceiver(b, f);\r
-          if (getSupportFragmentManager().findFragmentById(R.id.fileList) == null)\r
-            setContentView(R.layout.files);\r
-          \r
-          mDirectories = new CustomArrayAdapter<String>(this,\r
-               R.layout.sherlock_spinner_dropdown_item);\r
-           mDirectories.add("/");\r
-           \r
-           mStorageManager = new FileDataStorageManager(AccountUtils.getCurrentOwnCloudAccount(this), getContentResolver());\r
-           ActionBar action_bar = getSupportActionBar();\r
-           action_bar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);\r
-           action_bar.setDisplayShowTitleEnabled(false);\r
-           action_bar.setListNavigationCallbacks(mDirectories, this);\r
-           action_bar.setDisplayHomeAsUpEnabled(true);\r
-       }\r
-           \r
-        public void onActivityResult(int requestCode, int resultCode, Intent data) {\r
-     if (resultCode == RESULT_OK) {\r
-         if (requestCode == ACTION_SELECT_FILE) {\r
-             Uri selectedImageUri = data.getData();\r
-\r
-             String filemanagerstring = selectedImageUri.getPath();\r
-\r
-             String selectedImagePath = getPath(selectedImageUri);\r
-\r
-             //DEBUG PURPOSE - you can delete this if you want\r
-             if(selectedImagePath!=null)\r
-                 System.out.println(selectedImagePath);\r
-             else System.out.println("selectedImagePath is null");\r
-             if(filemanagerstring!=null)\r
-                 System.out.println(filemanagerstring);\r
-             else System.out.println("filemanagerstring is null");\r
-\r
-             //NOW WE HAVE OUR WANTED STRING\r
-             if(selectedImagePath!=null)\r
-                 System.out.println("selectedImagePath is the right one for you!");\r
-             else\r
-                 System.out.println("filemanagerstring is the right one for you!");\r
-         }\r
-     }\r
-        }\r
-        \r
-     public String getPath(Uri uri) {\r
-       String[] projection = { MediaStore.Images.Media.DATA };\r
-       Cursor cursor = managedQuery(uri, projection, null, null, null);\r
-       if(cursor!=null)\r
-       {\r
-           //HERE YOU WILL GET A NULLPOINTER IF CURSOR IS NULL\r
-           //THIS CAN BE, IF YOU USED OI FILE MANAGER FOR PICKING THE MEDIA\r
-           int column_index = cursor\r
-           .getColumnIndexOrThrow(MediaStore.Images.Media.DATA);\r
-           cursor.moveToFirst();\r
-           return cursor.getString(column_index);\r
-       }\r
-       else return null;\r
-   }\r
-     \r
-        @Override\r
-       protected void onPause() {\r
-         super.onPause();\r
-         if (b != null) {\r
-           unregisterReceiver(b);\r
-           b = null;\r
-         }\r
-         \r
-       }\r
-        \r
-       @Override\r
-       public boolean onNavigationItemSelected(int itemPosition, long itemId) {\r
-               int i = itemPosition;\r
-               while (i-- != 0) {\r
-                       onBackPressed();\r
-               }\r
-               return true;\r
-       }\r
-\r
-       private class DirectoryCreator implements Runnable {\r
-               private String mTargetPath;\r
-               private Account mAccount;\r
-               private AccountManager mAm;\r
-\r
-               public DirectoryCreator(String targetPath, Account account) {\r
-                       mTargetPath = targetPath;\r
-                       mAccount = account;\r
-                       mAm = (AccountManager) getSystemService(ACCOUNT_SERVICE);\r
-               }\r
-\r
-               @Override\r
-               public void run() {\r
-                       WebdavClient wdc = new WebdavClient(Uri.parse(mAm.getUserData(\r
-                                       mAccount, AccountAuthenticator.KEY_OC_URL)));\r
-\r
-                       String username = mAccount.name.substring(0,\r
-                                       mAccount.name.lastIndexOf('@'));\r
-                       String password = mAm.getPassword(mAccount);\r
-\r
-                       wdc.setCredentials(username, password);\r
-                       wdc.allowUnsignedCertificates();\r
-                       wdc.createDirectory(mTargetPath);\r
-               }\r
-\r
-       }\r
-\r
-       // Custom array adapter to override text colors\r
-       private class CustomArrayAdapter<T> extends ArrayAdapter<T> {\r
-               \r
-               public CustomArrayAdapter(FileDisplayActivity ctx,\r
-                               int view) {\r
-                       super(ctx, view);\r
-               }\r
-\r
-               public View getView(int position, View convertView,\r
-                ViewGroup parent) {\r
-            View v = super.getView(position, convertView, parent);\r
-\r
-            ((TextView) v).setTextColor(\r
-                    getResources()\r
-                    .getColorStateList(android.R.color.white));\r
-            return v;\r
-        }\r
-               \r
-               public View getDropDownView(int position, View convertView,\r
-                ViewGroup parent) {\r
-            View v = super.getDropDownView(position, convertView,\r
-                    parent);\r
-\r
-            ((TextView) v).setTextColor(getResources().getColorStateList(\r
-                            android.R.color.white));\r
-\r
-            return v;\r
-        }\r
-\r
-\r
-               \r
-       }\r
-       \r
-        public void onClick(DialogInterface dialog, int which) {\r
-           // In any case - we won't need it anymore\r
-           dialog.dismiss();\r
-           switch(which){\r
-           case DialogInterface.BUTTON_POSITIVE:\r
-             Intent intent = new Intent("android.settings.ADD_ACCOUNT_SETTINGS");\r
-             intent.putExtra("authorities",\r
-                 new String[] { AccountAuthenticator.AUTH_TOKEN_TYPE });\r
-             startActivity(intent);\r
-             break;\r
-           case DialogInterface.BUTTON_NEGATIVE:\r
-             finish();\r
-           }\r
-           \r
-         }\r
-       \r
-       /**\r
-   * Checks, whether or not there are any ownCloud accounts \r
-   * setup. \r
-   *  \r
-   * @return true, if there is at least one account.\r
-   */\r
-  private boolean accountsAreSetup() {\r
-    AccountManager accMan = AccountManager.get(this);\r
-    Account[] accounts = accMan\r
-        .getAccountsByType(AccountAuthenticator.ACCOUNT_TYPE); \r
-    return accounts.length > 0;\r
-  }\r
-  \r
-  private class BR extends BroadcastReceiver {\r
-    @Override\r
-    public void onReceive(Context context, Intent intent) {\r
-      boolean in_progress = intent.getBooleanExtra(FileSyncService.IN_PROGRESS, false);\r
-      String account_name = intent.getStringExtra(FileSyncService.ACCOUNT_NAME);\r
-      Log.d("FileDisplay", "sync of account " + account_name + " is in_progress: " + in_progress);\r
-      setProgressBarIndeterminateVisibility(in_progress);\r
-      if (!in_progress) {\r
-        FileListFragment f = (FileListFragment) getSupportFragmentManager().findFragmentById(R.id.fileList);\r
-        if (f != null)\r
-          f.populateFileList();\r
-      }\r
-    }\r
-    \r
-  }\r
-  \r
-}