}\r
return null;\r
}\r
+ \r
+ /**\r
+ * Constructs full url to host and webdav resource basing on host version\r
+ * @param context\r
+ * @param account\r
+ * @return url or null on failure\r
+ */\r
+ public static String constructFullURLForAccount(Context context, Account account) {\r
+ try {\r
+ AccountManager ama = AccountManager.get(context);\r
+ String baseurl = ama.getUserData(account, AccountAuthenticator.KEY_OC_BASE_URL);\r
+ String strver = ama.getUserData(account, AccountAuthenticator.KEY_OC_VERSION);\r
+ OwnCloudVersion ver = new OwnCloudVersion(strver);\r
+ String webdavpath = getWebdavPath(ver);\r
+\r
+ if (webdavpath == null) return null;\r
+ return baseurl + webdavpath;\r
+ } catch (Exception e) {\r
+ e.printStackTrace();\r
+ return null;\r
+ }\r
+ }\r
\r
}\r
builder.setMessage(R.string.uploader_wrn_no_account_text);\r
builder.setCancelable(false);\r
builder.setPositiveButton(R.string.uploader_wrn_no_account_setup_btn_text, new OnClickListener() {\r
+ @Override\r
public void onClick(DialogInterface dialog, int which) {\r
if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.ECLAIR_MR1) {\r
// using string value since in API7 this\r
}\r
});\r
builder.setNegativeButton(R.string.uploader_wrn_no_account_quit_btn_text, new OnClickListener() {\r
+ @Override\r
public void onClick(DialogInterface dialog, int which) {\r
finish();\r
}\r
}\r
builder.setTitle(R.string.common_choose_account);\r
builder.setItems(ac, new OnClickListener() {\r
+ @Override\r
public void onClick(DialogInterface dialog, int which) {\r
mAccount = mAccountManager.getAccountsByType(AccountAuthenticator.ACCOUNT_TYPE)[which];\r
mStorageManager = new FileDataStorageManager(mAccount, getContentResolver());\r
});\r
builder.setCancelable(true);\r
builder.setOnCancelListener(new OnCancelListener() {\r
+ @Override\r
public void onCancel(DialogInterface dialog) {\r
dialog.cancel();\r
finish();\r
builder.setMessage(R.string.uploader_wrn_no_content_text);\r
builder.setCancelable(false);\r
builder.setNegativeButton(R.string.common_cancel, new OnClickListener() {\r
+ @Override\r
public void onClick(DialogInterface dialog, int which) {\r
finish();\r
}\r
mDirname = dirname;\r
}\r
\r
+ @Override\r
public void onClick(DialogInterface dialog, int which) {\r
Uploader.this.mUploadPath = mPath + mDirname.getText().toString();\r
Uploader.this.mCreateDir = true;\r
}\r
}\r
\r
+ @Override\r
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {\r
// click on folder in the list\r
Log.d(TAG, "on item click");\r
populateDirectoryList();\r
}\r
\r
+ @Override\r
public void onClick(View v) {\r
// click on button\r
switch (v.getId()) {\r
return mContentProvider;
}
+ @Override
public Vector<OCFile> getDirectoryContent(OCFile f) {
if (f != null && f.isDirectory() && f.getFileId() != -1) {
Vector<OCFile> ret = new Vector<OCFile>();
return file;
}
+ @Override
public void removeFile(OCFile file, boolean removeLocalCopy) {
Uri file_uri = Uri.withAppendedPath(ProviderTableMeta.CONTENT_URI_FILE, ""+file.getFileId());
if (getContentProvider() != null) {
return getRemotePath().toLowerCase().compareTo(another.getRemotePath().toLowerCase());
}
+ @Override
public boolean equals(Object o) {
if(o instanceof OCFile){
OCFile that = (OCFile) o;
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());
lock.release();
if (channel != null)
channel.close();
+ if (raf != null)
+ raf.close();
if (put != null)
put.releaseConnection(); // let the connection available for other methods
}
import org.apache.http.conn.ConnectionKeepAliveStrategy;\r
import org.apache.http.protocol.HttpContext;\r
\r
-import com.owncloud.android.authenticator.AccountAuthenticator;\r
+import com.owncloud.android.AccountUtils;\r
import com.owncloud.android.datamodel.DataStorageManager;\r
import com.owncloud.android.network.OwnCloudClientUtils;\r
\r
}\r
\r
protected Uri getUri() {\r
- return Uri.parse(this.getAccountManager().getUserData(getAccount(),\r
- AccountAuthenticator.KEY_OC_URL));\r
+ return Uri.parse(AccountUtils.constructFullURLForAccount(getContext(), getAccount()));\r
}\r
\r
protected WebdavClient getClient() throws /*OperationCanceledException,\r
AuthenticatorException,*/ IOException {\r
if (mClient == null) {\r
- if (this.getAccountManager().getUserData(getAccount(),\r
- AccountAuthenticator.KEY_OC_URL) == null) {\r
+ if (AccountUtils.constructFullURLForAccount(getContext(), getAccount()) == null) {\r
throw new UnknownHostException();\r
}\r
mClient = OwnCloudClientUtils.createOwnCloudClient(account, getContext());\r
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);
AccountAuthenticator.ACCOUNT_TYPE);\r
intent.putExtra(AccountManager.KEY_USERDATA, username);\r
\r
- accManager.setUserData(account, AccountAuthenticator.KEY_OC_URL,\r
- url.toString());\r
accManager.setUserData(account,\r
AccountAuthenticator.KEY_OC_VERSION, mConnChkRunnable\r
.getDiscoveredVersion().toString());\r
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;
}
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;
}
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 {
}
public long getItemId(int position) {
- // TODO Auto-generated method stub
return 0;
}
public int getItemViewType(int position) {
- // TODO Auto-generated method stub
return 0;
}
}
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/.*")) {
import android.accounts.Account;\r
import android.content.Context;\r
import android.database.DataSetObserver;\r
-import android.util.Log;\r
import android.view.LayoutInflater;\r
import android.view.View;\r
import android.view.ViewGroup;\r
-import android.widget.CheckedTextView;\r
import android.widget.ImageView;\r
import android.widget.ListAdapter;\r
import android.widget.ListView;\r
\r
@Override\r
public boolean isEnabled(int position) {\r
- // TODO Auto-generated method stub\r
return true;\r
}\r
\r
\r
@Override\r
public int getItemViewType(int position) {\r
- // TODO Auto-generated method stub\r
return 0;\r
}\r
\r
\r
@Override\r
public void registerDataSetObserver(DataSetObserver observer) {\r
- // TODO Auto-generated method stub\r
-\r
}\r
\r
@Override\r
public void unregisterDataSetObserver(DataSetObserver observer) {\r
- // TODO Auto-generated method stub\r
-\r
}\r
}\r
*/
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);
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());
//instream.close();
lock.release();
channel.close();
+ raf.close();
}
}