Refactoring: Added comments to every class, as well as a copyright
[pub/Android/ownCloud.git] / src / eu / alefzero / owncloud / FileDownloader.java
index 7d3605e..121e147 100644 (file)
@@ -1,76 +1,77 @@
-package eu.alefzero.owncloud;
-
-import java.io.File;
-
-import android.accounts.Account;
-import android.accounts.AccountManager;
-import android.app.Notification;
-import android.app.NotificationManager;
-import android.app.PendingIntent;
-import android.app.Service;
-import android.content.Intent;
-import android.net.Uri;
-import android.os.Environment;
-import android.os.IBinder;
-import android.util.Log;
-import eu.alefzero.owncloud.authenticator.AccountAuthenticator;
-import eu.alefzero.owncloud.ui.FileDisplayActivity;
-
-public class FileDownloader extends Service {
-  static final String EXTRA_ACCOUNT = "ACCOUNT";
-  static final String EXTRA_FILE_PATH = "FILE_PATH";
-  static final String TAG = "OC_FileDownloader";
-  
-  NotificationManager nm;
-  
-  @Override
-  public IBinder onBind(Intent arg0) {
-    return null;
-  }
-  
-  @Override
-  public int onStartCommand(Intent intent, int flags, int startId) {
-    if (!intent.hasExtra(EXTRA_ACCOUNT) && !intent.hasExtra(EXTRA_FILE_PATH)) {
-      Log.e(TAG, "Not enough information provided in intent");
-      return START_NOT_STICKY;
-    }
-    
-    nm = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
-    
-    Account account = intent.getParcelableExtra(EXTRA_ACCOUNT);
-    String file_path = intent.getStringExtra(EXTRA_FILE_PATH);
-    AccountManager am = (AccountManager)getSystemService(ACCOUNT_SERVICE);
-    Uri oc_url = Uri.parse(am.getUserData(account, AccountAuthenticator.KEY_OC_URL));
-
-    WebdavClient wdc = new WebdavClient(oc_url);
-    
-    String username = account.name.split("@")[0];
-    String password = "";
-    try {
-      password = am.blockingGetAuthToken(account, AccountAuthenticator.AUTH_TOKEN_TYPE, true);
-    } catch (Exception e) {
-      // TODO Auto-generated catch block
-      e.printStackTrace();
-      return START_NOT_STICKY;
-    }
-    
-    wdc.setCredentials(username, password);
-    wdc.allowUnsignedCertificates();
-
-    Notification n = new Notification(R.drawable.icon, "Downloading file", System.currentTimeMillis());
-    PendingIntent pi = PendingIntent.getActivity(this, 1, new Intent(this, FileDisplayActivity.class), 0);
-    n.setLatestEventInfo(this, "A", "B", pi);
-    nm.notify(1, n);
-
-    File sdCard = Environment.getExternalStorageDirectory();
-    File dir = new File (sdCard.getAbsolutePath() + "/owncloud");
-    dir.mkdirs();
-    File file = new File(dir, file_path.replace('/', '.'));
-    
-    wdc.downloadFile(file_path, file);
-    
-    return START_NOT_STICKY;
-  }
-  
-  
-}
+package eu.alefzero.owncloud;\r
+\r
+import java.io.File;\r
+\r
+import android.accounts.Account;\r
+import android.accounts.AccountManager;\r
+import android.app.Notification;\r
+import android.app.NotificationManager;\r
+import android.app.PendingIntent;\r
+import android.app.Service;\r
+import android.content.Intent;\r
+import android.net.Uri;\r
+import android.os.Environment;\r
+import android.os.IBinder;\r
+import android.util.Log;\r
+import eu.alefzero.owncloud.authenticator.AccountAuthenticator;\r
+import eu.alefzero.owncloud.ui.activity.FileDisplayActivity;\r
+import eu.alefzero.webdav.WebdavClient;\r
+\r
+public class FileDownloader extends Service {\r
+  static final String EXTRA_ACCOUNT = "ACCOUNT";\r
+  static final String EXTRA_FILE_PATH = "FILE_PATH";\r
+  static final String TAG = "OC_FileDownloader";\r
+  \r
+  NotificationManager nm;\r
+  \r
+  @Override\r
+  public IBinder onBind(Intent arg0) {\r
+    return null;\r
+  }\r
+  \r
+  @Override\r
+  public int onStartCommand(Intent intent, int flags, int startId) {\r
+    if (!intent.hasExtra(EXTRA_ACCOUNT) && !intent.hasExtra(EXTRA_FILE_PATH)) {\r
+      Log.e(TAG, "Not enough information provided in intent");\r
+      return START_NOT_STICKY;\r
+    }\r
+    \r
+    nm = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);\r
+    \r
+    Account account = intent.getParcelableExtra(EXTRA_ACCOUNT);\r
+    String file_path = intent.getStringExtra(EXTRA_FILE_PATH);\r
+    AccountManager am = (AccountManager)getSystemService(ACCOUNT_SERVICE);\r
+    Uri oc_url = Uri.parse(am.getUserData(account, AccountAuthenticator.KEY_OC_URL));\r
+\r
+    WebdavClient wdc = new WebdavClient(oc_url);\r
+    \r
+    String username = account.name.split("@")[0];\r
+    String password = "";\r
+    try {\r
+      password = am.blockingGetAuthToken(account, AccountAuthenticator.AUTH_TOKEN_TYPE, true);\r
+    } catch (Exception e) {\r
+      // TODO Auto-generated catch block\r
+      e.printStackTrace();\r
+      return START_NOT_STICKY;\r
+    }\r
+    \r
+    wdc.setCredentials(username, password);\r
+    wdc.allowUnsignedCertificates();\r
+\r
+    Notification n = new Notification(R.drawable.icon, "Downloading file", System.currentTimeMillis());\r
+    PendingIntent pi = PendingIntent.getActivity(this, 1, new Intent(this, FileDisplayActivity.class), 0);\r
+    n.setLatestEventInfo(this, "A", "B", pi);\r
+    nm.notify(1, n);\r
+\r
+    File sdCard = Environment.getExternalStorageDirectory();\r
+    File dir = new File (sdCard.getAbsolutePath() + "/owncloud");\r
+    dir.mkdirs();\r
+    File file = new File(dir, file_path.replace('/', '.'));\r
+    \r
+    wdc.downloadFile(file_path, file);\r
+    \r
+    return START_NOT_STICKY;\r
+  }\r
+  \r
+  \r
+}\r