Răsfoiți Sursa

remove all warning from project

Bartek Przybylski 12 ani în urmă
părinte
comite
981bf05434

+ 22 - 0
src/com/owncloud/android/AccountUtils.java

@@ -107,5 +107,27 @@ public class AccountUtils {
         }
         return null;
     }
+    
+    /**
+     * Constructs full url to host and webdav resource basing on host version
+     * @param context
+     * @param account
+     * @return url or null on failure
+     */
+    public static String constructFullURLForAccount(Context context, Account account) {
+        try {
+            AccountManager ama = AccountManager.get(context);
+            String baseurl = ama.getUserData(account, AccountAuthenticator.KEY_OC_BASE_URL);
+            String strver  = ama.getUserData(account, AccountAuthenticator.KEY_OC_VERSION);
+            OwnCloudVersion ver = new OwnCloudVersion(strver);
+            String webdavpath = getWebdavPath(ver);
+
+            if (webdavpath == null) return null;
+            return baseurl + webdavpath;
+        } catch (Exception e) {
+            e.printStackTrace();
+            return null;
+        }
+    }
 
 }

+ 8 - 0
src/com/owncloud/android/Uploader.java

@@ -132,6 +132,7 @@ public class Uploader extends ListActivity implements OnItemClickListener, andro
             builder.setMessage(R.string.uploader_wrn_no_account_text);
             builder.setCancelable(false);
             builder.setPositiveButton(R.string.uploader_wrn_no_account_setup_btn_text, new OnClickListener() {
+                @Override
                 public void onClick(DialogInterface dialog, int which) {
                     if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.ECLAIR_MR1) {
                         // using string value since in API7 this
@@ -154,6 +155,7 @@ public class Uploader extends ListActivity implements OnItemClickListener, andro
                 }
             });
             builder.setNegativeButton(R.string.uploader_wrn_no_account_quit_btn_text, new OnClickListener() {
+                @Override
                 public void onClick(DialogInterface dialog, int which) {
                     finish();
                 }
@@ -188,6 +190,7 @@ public class Uploader extends ListActivity implements OnItemClickListener, andro
             }
             builder.setTitle(R.string.common_choose_account);
             builder.setItems(ac, new OnClickListener() {
+                @Override
                 public void onClick(DialogInterface dialog, int which) {
                     mAccount = mAccountManager.getAccountsByType(AccountAuthenticator.ACCOUNT_TYPE)[which];
                     mStorageManager = new FileDataStorageManager(mAccount, getContentResolver());
@@ -196,6 +199,7 @@ public class Uploader extends ListActivity implements OnItemClickListener, andro
             });
             builder.setCancelable(true);
             builder.setOnCancelListener(new OnCancelListener() {
+                @Override
                 public void onCancel(DialogInterface dialog) {
                     dialog.cancel();
                     finish();
@@ -208,6 +212,7 @@ public class Uploader extends ListActivity implements OnItemClickListener, andro
             builder.setMessage(R.string.uploader_wrn_no_content_text);
             builder.setCancelable(false);
             builder.setNegativeButton(R.string.common_cancel, new OnClickListener() {
+                @Override
                 public void onClick(DialogInterface dialog, int which) {
                     finish();
                 }
@@ -227,6 +232,7 @@ public class Uploader extends ListActivity implements OnItemClickListener, andro
             mDirname = dirname;
         }
 
+        @Override
         public void onClick(DialogInterface dialog, int which) {
             Uploader.this.mUploadPath = mPath + mDirname.getText().toString();
             Uploader.this.mCreateDir = true;
@@ -246,6 +252,7 @@ public class Uploader extends ListActivity implements OnItemClickListener, andro
         }
     }
 
+    @Override
     public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
         // click on folder in the list
         Log.d(TAG, "on item click");
@@ -263,6 +270,7 @@ public class Uploader extends ListActivity implements OnItemClickListener, andro
         populateDirectoryList();
     }
 
+    @Override
     public void onClick(View v) {
         // click on button
         switch (v.getId()) {

+ 2 - 0
src/com/owncloud/android/datamodel/FileDataStorageManager.java

@@ -278,6 +278,7 @@ public class FileDataStorageManager implements DataStorageManager {
         return mContentProvider;
     }
 
+    @Override
     public Vector<OCFile> getDirectoryContent(OCFile f) {
         if (f != null && f.isDirectory() && f.getFileId() != -1) {
             Vector<OCFile> ret = new Vector<OCFile>();
@@ -408,6 +409,7 @@ public class FileDataStorageManager implements DataStorageManager {
         return file;
     }
     
+    @Override
     public void removeFile(OCFile file, boolean removeLocalCopy) {
         Uri file_uri = Uri.withAppendedPath(ProviderTableMeta.CONTENT_URI_FILE, ""+file.getFileId());
         if (getContentProvider() != null) {

+ 1 - 0
src/com/owncloud/android/datamodel/OCFile.java

@@ -355,6 +355,7 @@ public class OCFile implements Parcelable, Comparable<OCFile> {
         return getRemotePath().toLowerCase().compareTo(another.getRemotePath().toLowerCase());
     }
 
+    @Override
     public boolean equals(Object o) {
         if(o instanceof OCFile){
             OCFile that = (OCFile) o;

+ 5 - 1
src/com/owncloud/android/operations/ChunkedUploadFileOperation.java

@@ -58,9 +58,11 @@ public class ChunkedUploadFileOperation extends UploadFileOperation {
         PutMethod put = null;
         FileChannel channel = null;
         FileLock lock = null;
+        RandomAccessFile raf = null;
         try {
             File file = new File(getLocalPath());
-            channel = new RandomAccessFile(file, "rw").getChannel();
+            raf = new RandomAccessFile(file, "rw");
+            channel = raf.getChannel();
             lock = channel.tryLock();
             ChunkFromFileChannelRequestEntity entity = new ChunkFromFileChannelRequestEntity(channel, getMimeType(), CHUNK_SIZE);
             entity.setOnDatatransferProgressListener(getDataTransferListener());
@@ -84,6 +86,8 @@ public class ChunkedUploadFileOperation extends UploadFileOperation {
                 lock.release();
             if (channel != null)
                 channel.close();
+            if (raf != null)
+                raf.close();
             if (put != null)
                 put.releaseConnection();    // let the connection available for other methods
         }

+ 3 - 5
src/com/owncloud/android/syncadapter/AbstractOwnCloudSyncAdapter.java

@@ -28,7 +28,7 @@ import org.apache.http.client.ClientProtocolException;
 import org.apache.http.conn.ConnectionKeepAliveStrategy;
 import org.apache.http.protocol.HttpContext;
 
-import com.owncloud.android.authenticator.AccountAuthenticator;
+import com.owncloud.android.AccountUtils;
 import com.owncloud.android.datamodel.DataStorageManager;
 import com.owncloud.android.network.OwnCloudClientUtils;
 
@@ -144,15 +144,13 @@ public abstract class AbstractOwnCloudSyncAdapter extends
     }
 
     protected Uri getUri() {
-        return Uri.parse(this.getAccountManager().getUserData(getAccount(),
-                AccountAuthenticator.KEY_OC_URL));
+        return Uri.parse(AccountUtils.constructFullURLForAccount(getContext(), getAccount()));
     }
 
     protected WebdavClient getClient() throws /*OperationCanceledException,
             AuthenticatorException,*/ IOException {
         if (mClient == null) {
-            if (this.getAccountManager().getUserData(getAccount(),
-                    AccountAuthenticator.KEY_OC_URL) == null) {
+            if (AccountUtils.constructFullURLForAccount(getContext(), getAccount()) == null) {
                 throw new UnknownHostException();
             }
             mClient = OwnCloudClientUtils.createOwnCloudClient(account, getContext());

+ 1 - 0
src/com/owncloud/android/syncadapter/ContactSyncAdapter.java

@@ -71,6 +71,7 @@ public class ContactSyncAdapter extends AbstractOwnCloudSyncAdapter {
             return mAddrBookUri;
 
         AccountManager am = getAccountManager();
+        @SuppressWarnings("deprecation")
         String uri = am.getUserData(getAccount(),
                 AccountAuthenticator.KEY_OC_URL).replace(
                 AccountUtils.WEBDAV_PATH_2_0, AccountUtils.CARDDAV_PATH_2_0);

+ 0 - 2
src/com/owncloud/android/ui/activity/AuthenticatorActivity.java

@@ -240,8 +240,6 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
                     AccountAuthenticator.ACCOUNT_TYPE);
             intent.putExtra(AccountManager.KEY_USERDATA, username);
 
-            accManager.setUserData(account, AccountAuthenticator.KEY_OC_URL,
-                    url.toString());
             accManager.setUserData(account,
                     AccountAuthenticator.KEY_OC_VERSION, mConnChkRunnable
                             .getDiscoveredVersion().toString());

+ 4 - 18
src/com/owncloud/android/ui/adapter/FileListActionListAdapter.java

@@ -20,9 +20,9 @@ package com.owncloud.android.ui.adapter;
 
 import java.io.File;
 
-import com.owncloud.android.authenticator.AccountAuthenticator;
 import com.owncloud.android.db.ProviderMeta.ProviderTableMeta;
 
+import com.owncloud.android.AccountUtils;
 import com.owncloud.android.R;
 import eu.alefzero.webdav.WebdavUtils;
 import android.accounts.Account;
@@ -63,17 +63,14 @@ public class FileListActionListAdapter implements ListAdapter {
     }
 
     public boolean areAllItemsEnabled() {
-        // TODO Auto-generated method stub
         return true;
     }
 
     public boolean isEnabled(int position) {
-        // TODO Auto-generated method stub
         return true;
     }
 
     public int getCount() {
-        // TODO Auto-generated method stub
         return 1;
     }
 
@@ -85,7 +82,7 @@ public class FileListActionListAdapter implements ListAdapter {
                 AccountManager accm = (AccountManager) mContext
                         .getSystemService(Context.ACCOUNT_SERVICE);
                 String ocurl = accm.getUserData(mAccount,
-                        AccountAuthenticator.KEY_OC_URL);
+                        AccountUtils.constructFullURLForAccount(mContext, mAccount));
                 ocurl += WebdavUtils.encodePath(mFilePath + mFilename);
                 intent.setData(Uri.parse(ocurl));
             } else {
@@ -99,12 +96,10 @@ public class FileListActionListAdapter implements ListAdapter {
     }
 
     public long getItemId(int position) {
-        // TODO Auto-generated method stub
         return 0;
     }
 
     public int getItemViewType(int position) {
-        // TODO Auto-generated method stub
         return 0;
     }
 
@@ -135,29 +130,20 @@ public class FileListActionListAdapter implements ListAdapter {
     }
 
     public int getViewTypeCount() {
-        // TODO Auto-generated method stub
         return 2;
     }
 
     public boolean hasStableIds() {
-        // TODO Auto-generated method stub
         return false;
     }
 
     public boolean isEmpty() {
-        // TODO Auto-generated method stub
         return false;
     }
 
-    public void registerDataSetObserver(DataSetObserver observer) {
-        // TODO Auto-generated method stub
+    public void registerDataSetObserver(DataSetObserver observer) { }
 
-    }
-
-    public void unregisterDataSetObserver(DataSetObserver observer) {
-        // TODO Auto-generated method stub
-
-    }
+    public void unregisterDataSetObserver(DataSetObserver observer) { }
 
     private void setActionName(TextView tv) {
         if (mFileType.matches("image/.*")) {

+ 0 - 8
src/com/owncloud/android/ui/adapter/FileListListAdapter.java

@@ -31,11 +31,9 @@ import com.owncloud.android.R;
 import android.accounts.Account;
 import android.content.Context;
 import android.database.DataSetObserver;
-import android.util.Log;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
-import android.widget.CheckedTextView;
 import android.widget.ImageView;
 import android.widget.ListAdapter;
 import android.widget.ListView;
@@ -71,7 +69,6 @@ public class FileListListAdapter implements ListAdapter {
 
     @Override
     public boolean isEnabled(int position) {
-        // TODO Auto-generated method stub
         return true;
     }
 
@@ -94,7 +91,6 @@ public class FileListListAdapter implements ListAdapter {
 
     @Override
     public int getItemViewType(int position) {
-        // TODO Auto-generated method stub
         return 0;
     }
 
@@ -190,13 +186,9 @@ public class FileListListAdapter implements ListAdapter {
 
     @Override
     public void registerDataSetObserver(DataSetObserver observer) {
-        // TODO Auto-generated method stub
-
     }
 
     @Override
     public void unregisterDataSetObserver(DataSetObserver observer) {
-        // TODO Auto-generated method stub
-
     }
 }

+ 19 - 11
src/eu/alefzero/webdav/FileRequestEntity.java

@@ -21,41 +21,48 @@ import android.util.Log;
  */
 public class FileRequestEntity implements RequestEntity {
 
-    final File file;
-    final String contentType;
-    OnDatatransferProgressListener listener;
+    final File mFile;
+    final String mContentType;
+    OnDatatransferProgressListener mListener;
 
     public FileRequestEntity(final File file, final String contentType) {
         super();
+        this.mFile = file;
+        this.mContentType = contentType;
         if (file == null) {
             throw new IllegalArgumentException("File may not be null");
         }
-        this.file = file;
-        this.contentType = contentType;
     }
     
+    @Override
     public long getContentLength() {
-        return this.file.length();
+        return mFile.length();
     }
 
+    @Override
     public String getContentType() {
-        return this.contentType;
+        return mContentType;
     }
 
+    @Override
     public boolean isRepeatable() {
         return true;
     }
     
     public void setOnDatatransferProgressListener(OnDatatransferProgressListener listener) {
-        this.listener = listener;
+        mListener = listener;
     }
     
+    @Override
     public void writeRequest(final OutputStream out) throws IOException {
         //byte[] tmp = new byte[4096];
         ByteBuffer tmp = ByteBuffer.allocate(4096);
         int i = 0;
         
-        FileChannel channel = new RandomAccessFile(this.file, "rw").getChannel();
+        // TODO(bprzybylski): each mem allocation can throw OutOfMemoryError we need to handle it
+        //                    globally in some fashionable manner
+        RandomAccessFile raf = new RandomAccessFile(mFile, "rw");
+        FileChannel channel = raf.getChannel();
         FileLock lock = channel.tryLock();
         //InputStream instream = new FileInputStream(this.file);
         
@@ -64,8 +71,8 @@ public class FileRequestEntity implements RequestEntity {
             while ((i = channel.read(tmp)) >= 0) {
                 out.write(tmp.array(), 0, i);
                 tmp.clear();
-                if (listener != null) 
-                    listener.transferProgress(i);
+                if (mListener != null) 
+                    mListener.transferProgress(i);
             }
         } catch (IOException io) {
             Log.e("FileRequestException", io.getMessage());
@@ -75,6 +82,7 @@ public class FileRequestEntity implements RequestEntity {
             //instream.close();
             lock.release();
             channel.close();
+            raf.close();
         }
     }