Uncluttered code by reordering methods. Method code is untouched
authorLennart Rosam <lennart@familie-rosam.de>
Thu, 24 May 2012 21:52:21 +0000 (23:52 +0200)
committerLennart Rosam <lennart@familie-rosam.de>
Thu, 24 May 2012 21:52:21 +0000 (23:52 +0200)
src/eu/alefzero/owncloud/ui/activity/FileDisplayActivity.java

index a38f39b..fb3106c 100644 (file)
@@ -85,82 +85,6 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements
     private static final int DIALOG_CREATE_DIR = 1;\r
     private static final int ACTION_SELECT_FILE = 1;\r
 \r
     private static final int DIALOG_CREATE_DIR = 1;\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
-            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,\r
-                    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
-                                    + "/");\r
-                            path += s + "/";\r
-                            Thread thread = new Thread(new DirectoryCreator(\r
-                                    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
     @Override\r
     public void onCreate(Bundle savedInstanceState) {\r
         super.onCreate(savedInstanceState);\r
@@ -178,6 +102,13 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements
     }\r
 \r
     @Override\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
     public boolean onOptionsItemSelected(MenuItem item) {\r
         boolean retval = true;\r
         switch (item.getItemId()) {\r
     public boolean onOptionsItemSelected(MenuItem item) {\r
         boolean retval = true;\r
         switch (item.getItemId()) {\r
@@ -216,6 +147,54 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements
     }\r
 \r
     @Override\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
+    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
+                String selectedImagePath = getPath(selectedImageUri);\r
+                String filepath;\r
+    \r
+                if (selectedImagePath != null)\r
+                    filepath = selectedImagePath;\r
+                else\r
+                    filepath = filemanagerstring;\r
+    \r
+                if (filepath == null) {\r
+                    Log.e("FileDisplay", "Couldnt resolve path to file");\r
+                    return;\r
+                }\r
+    \r
+                Intent i = new Intent(this, FileUploader.class);\r
+                i.putExtra(FileUploader.KEY_ACCOUNT,\r
+                        AccountUtils.getCurrentOwnCloudAccount(this));\r
+                String remotepath = new String();\r
+                for (int j = mDirectories.getCount() - 2; j >= 0; --j) {\r
+                    remotepath += "/" + URLEncoder.encode(mDirectories.getItem(j));\r
+                }\r
+                if (!remotepath.endsWith("/"))\r
+                    remotepath += "/";\r
+                remotepath += URLEncoder.encode(new File(filepath).getName());\r
+                Log.e("ASD", remotepath + "");\r
+    \r
+                i.putExtra(FileUploader.KEY_LOCAL_FILE, filepath);\r
+                i.putExtra(FileUploader.KEY_REMOTE_FILE, remotepath);\r
+                i.putExtra(FileUploader.KEY_UPLOAD_TYPE, FileUploader.UPLOAD_SINGLE_FILE);\r
+                startService(i);\r
+            }\r
+        }\r
+    }\r
+\r
+    @Override\r
     public void onBackPressed() {\r
         if (mDirectories.getCount() == 1) {\r
             finish();\r
     public void onBackPressed() {\r
         if (mDirectories.getCount() == 1) {\r
             finish();\r
@@ -227,13 +206,6 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements
     }\r
 \r
     @Override\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
     protected void onRestoreInstanceState(Bundle savedInstanceState) {\r
         super.onRestoreInstanceState(savedInstanceState);\r
         // Check, if there are ownCloud accounts\r
@@ -291,43 +263,97 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements
         action_bar.setDisplayHomeAsUpEnabled(true);\r
     }\r
 \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
-                String selectedImagePath = getPath(selectedImageUri);\r
-                String filepath;\r
-\r
-                if (selectedImagePath != null)\r
-                    filepath = selectedImagePath;\r
-                else\r
-                    filepath = filemanagerstring;\r
-\r
-                if (filepath == null) {\r
-                    Log.e("FileDisplay", "Couldnt resolve path to file");\r
-                    return;\r
-                }\r
+    @Override\r
+    protected void onPause() {\r
+        super.onPause();\r
+        if (syncBroadcastRevceiver != null) {\r
+            unregisterReceiver(syncBroadcastRevceiver);\r
+            syncBroadcastRevceiver = null;\r
+        }\r
+    \r
+    }\r
 \r
 \r
-                Intent i = new Intent(this, FileUploader.class);\r
-                i.putExtra(FileUploader.KEY_ACCOUNT,\r
-                        AccountUtils.getCurrentOwnCloudAccount(this));\r
-                String remotepath = new String();\r
-                for (int j = mDirectories.getCount() - 2; j >= 0; --j) {\r
-                    remotepath += "/" + URLEncoder.encode(mDirectories.getItem(j));\r
-                }\r
-                if (!remotepath.endsWith("/"))\r
-                    remotepath += "/";\r
-                remotepath += URLEncoder.encode(new File(filepath).getName());\r
-                Log.e("ASD", remotepath + "");\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
+            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,\r
+                    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
+                                    + "/");\r
+                            path += s + "/";\r
+                            Thread thread = new Thread(new DirectoryCreator(\r
+                                    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
 \r
-                i.putExtra(FileUploader.KEY_LOCAL_FILE, filepath);\r
-                i.putExtra(FileUploader.KEY_REMOTE_FILE, remotepath);\r
-                i.putExtra(FileUploader.KEY_UPLOAD_TYPE, FileUploader.UPLOAD_SINGLE_FILE);\r
-                startService(i);\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
     public String getPath(Uri uri) {\r
     }\r
 \r
     public String getPath(Uri uri) {\r
@@ -342,105 +368,79 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements
             return null;\r
     }\r
 \r
             return null;\r
     }\r
 \r
-    @Override\r
-    protected void onPause() {\r
-        super.onPause();\r
-        if (syncBroadcastRevceiver != null) {\r
-            unregisterReceiver(syncBroadcastRevceiver);\r
-            syncBroadcastRevceiver = null;\r
-        }\r
+    public void pushPath(String path) {\r
+        mDirectories.insert(path, 0);\r
+    }\r
 \r
 \r
+    public boolean popPath() {\r
+        mDirectories.remove(mDirectories.getItem(0));\r
+        return !mDirectories.isEmpty();\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
+     * Checks, whether or not there are any ownCloud accounts 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 DirectoryCreator implements Runnable {\r
         private String mTargetPath;\r
         private Account mAccount;\r
         private AccountManager mAm;\r
     }\r
 \r
     private class DirectoryCreator implements Runnable {\r
         private String mTargetPath;\r
         private Account mAccount;\r
         private AccountManager mAm;\r
-\r
+    \r
         public DirectoryCreator(String targetPath, Account account) {\r
             mTargetPath = targetPath;\r
             mAccount = account;\r
             mAm = (AccountManager) getSystemService(ACCOUNT_SERVICE);\r
         }\r
         public DirectoryCreator(String targetPath, Account account) {\r
             mTargetPath = targetPath;\r
             mAccount = account;\r
             mAm = (AccountManager) getSystemService(ACCOUNT_SERVICE);\r
         }\r
-\r
+    \r
         @Override\r
         public void run() {\r
             WebdavClient wdc = new WebdavClient(Uri.parse(mAm.getUserData(\r
                     mAccount, AccountAuthenticator.KEY_OC_URL)));\r
         @Override\r
         public void run() {\r
             WebdavClient wdc = new WebdavClient(Uri.parse(mAm.getUserData(\r
                     mAccount, AccountAuthenticator.KEY_OC_URL)));\r
-\r
+    \r
             String username = mAccount.name.substring(0,\r
                     mAccount.name.lastIndexOf('@'));\r
             String password = mAm.getPassword(mAccount);\r
             String username = mAccount.name.substring(0,\r
                     mAccount.name.lastIndexOf('@'));\r
             String password = mAm.getPassword(mAccount);\r
-\r
+    \r
             wdc.setCredentials(username, password);\r
             wdc.allowUnsignedCertificates();\r
             wdc.createDirectory(mTargetPath);\r
         }\r
             wdc.setCredentials(username, password);\r
             wdc.allowUnsignedCertificates();\r
             wdc.createDirectory(mTargetPath);\r
         }\r
-\r
+    \r
     }\r
 \r
     // Custom array adapter to override text colors\r
     private class CustomArrayAdapter<T> extends ArrayAdapter<T> {\r
     }\r
 \r
     // Custom array adapter to override text colors\r
     private class CustomArrayAdapter<T> extends ArrayAdapter<T> {\r
-\r
+    \r
         public CustomArrayAdapter(FileDisplayActivity ctx, int view) {\r
             super(ctx, view);\r
         }\r
         public CustomArrayAdapter(FileDisplayActivity ctx, int view) {\r
             super(ctx, view);\r
         }\r
-\r
+    \r
         public View getView(int position, View convertView, ViewGroup parent) {\r
             View v = super.getView(position, convertView, parent);\r
         public View getView(int position, View convertView, ViewGroup parent) {\r
             View v = super.getView(position, convertView, parent);\r
-\r
+    \r
             ((TextView) v).setTextColor(getResources().getColorStateList(\r
                     android.R.color.white));\r
             return v;\r
         }\r
             ((TextView) v).setTextColor(getResources().getColorStateList(\r
                     android.R.color.white));\r
             return v;\r
         }\r
-\r
+    \r
         public View getDropDownView(int position, View convertView,\r
                 ViewGroup parent) {\r
             View v = super.getDropDownView(position, convertView, parent);\r
         public View getDropDownView(int position, View convertView,\r
                 ViewGroup parent) {\r
             View v = super.getDropDownView(position, convertView, parent);\r
-\r
+    \r
             ((TextView) v).setTextColor(getResources().getColorStateList(\r
                     android.R.color.white));\r
             ((TextView) v).setTextColor(getResources().getColorStateList(\r
                     android.R.color.white));\r
-\r
+    \r
             return v;\r
         }\r
             return v;\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 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
 \r
     private class SyncBroadcastReceiver extends BroadcastReceiver {\r
     }\r
 \r
     private class SyncBroadcastReceiver extends BroadcastReceiver {\r