mirror of
https://github.com/owncloud/android-library.git
synced 2026-08-11 16:33:03 +00:00
apply codestyle everywhere
This commit is contained in:
@@ -19,7 +19,7 @@ android {
|
||||
packagingOptions {
|
||||
exclude 'META-INF/LICENSE.txt'
|
||||
}
|
||||
|
||||
|
||||
compileOptions {
|
||||
sourceCompatibility JavaVersion.VERSION_1_8
|
||||
targetCompatibility JavaVersion.VERSION_1_8
|
||||
|
||||
@@ -23,12 +23,12 @@
|
||||
|
||||
-->
|
||||
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.owncloud.android.lib.sampleclient"
|
||||
android:versionCode="1"
|
||||
android:versionName="1.0">
|
||||
<manifest package="com.owncloud.android.lib.sampleclient"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:versionCode="1"
|
||||
android:versionName="1.0">
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET"/>
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<application
|
||||
android:icon="@drawable/ic_launcher"
|
||||
android:label="@string/app_name">
|
||||
@@ -39,8 +39,8 @@
|
||||
android:screenOrientation="portrait"
|
||||
>
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN"/>
|
||||
<category android:name="android.intent.category.LAUNCHER"/>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
</application>
|
||||
|
||||
+18
-18
@@ -1,22 +1,22 @@
|
||||
/* ownCloud Android Library is available under MIT license
|
||||
* Copyright (C) 2016 ownCloud GmbH.
|
||||
*
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
||||
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
||||
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
||||
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
||||
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
@@ -32,15 +32,15 @@ import android.widget.TextView;
|
||||
import com.owncloud.android.lib.resources.files.RemoteFile;
|
||||
|
||||
public class FilesArrayAdapter extends ArrayAdapter<RemoteFile> {
|
||||
|
||||
public FilesArrayAdapter(Context context, int resource) {
|
||||
super(context, resource);
|
||||
}
|
||||
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
TextView textView = (TextView)super.getView(position, convertView, parent);
|
||||
textView.setText(getItem(position).getRemotePath());
|
||||
return textView;
|
||||
}
|
||||
|
||||
public FilesArrayAdapter(Context context, int resource) {
|
||||
super(context, resource);
|
||||
}
|
||||
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
TextView textView = (TextView) super.getView(position, convertView, parent);
|
||||
textView.setText(getItem(position).getRemotePath());
|
||||
return textView;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+203
-203
@@ -1,22 +1,22 @@
|
||||
/* ownCloud Android Library is available under MIT license
|
||||
* Copyright (C) 2018 ownCloud GmbH.
|
||||
*
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
||||
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
||||
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
||||
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
||||
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
@@ -66,245 +66,245 @@ import java.util.List;
|
||||
import static android.content.ContentValues.TAG;
|
||||
|
||||
public class MainActivity extends Activity implements OnRemoteOperationListener, OnDatatransferProgressListener {
|
||||
|
||||
private static String LOG_TAG = MainActivity.class.getCanonicalName();
|
||||
|
||||
private Handler mHandler;
|
||||
private OwnCloudClient mClient;
|
||||
private FilesArrayAdapter mFilesAdapter;
|
||||
private View mFrame;
|
||||
|
||||
/** Called when the activity is first created. */
|
||||
|
||||
private static String LOG_TAG = MainActivity.class.getCanonicalName();
|
||||
|
||||
private Handler mHandler;
|
||||
private OwnCloudClient mClient;
|
||||
private FilesArrayAdapter mFilesAdapter;
|
||||
private View mFrame;
|
||||
|
||||
/**
|
||||
* Called when the activity is first created.
|
||||
*/
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.main);
|
||||
|
||||
|
||||
mHandler = new Handler();
|
||||
|
||||
final Uri serverUri = Uri.parse(getString(R.string.server_base_url));
|
||||
|
||||
OwnCloudClientManagerFactory.setUserAgent(getUserAgent());
|
||||
mClient = OwnCloudClientFactory.createOwnCloudClient(serverUri, this, true);
|
||||
final Uri serverUri = Uri.parse(getString(R.string.server_base_url));
|
||||
|
||||
mClient.setCredentials(
|
||||
OwnCloudCredentialsFactory.newBasicCredentials(
|
||||
getString(R.string.username),
|
||||
getString(R.string.password)
|
||||
)
|
||||
);
|
||||
|
||||
mFilesAdapter = new FilesArrayAdapter(this, R.layout.file_in_list);
|
||||
((ListView)findViewById(R.id.list_view)).setAdapter(mFilesAdapter);
|
||||
|
||||
// TODO move to background thread or task
|
||||
AssetManager assets = getAssets();
|
||||
try {
|
||||
String sampleFileName = getString(R.string.sample_file_name);
|
||||
File upFolder = new File(getCacheDir(), getString(R.string.upload_folder_path));
|
||||
upFolder.mkdir();
|
||||
File upFile = new File(upFolder, sampleFileName);
|
||||
FileOutputStream fos = new FileOutputStream(upFile);
|
||||
InputStream is = assets.open(sampleFileName);
|
||||
int count = 0;
|
||||
byte[] buffer = new byte[1024];
|
||||
while ((count = is.read(buffer, 0, buffer.length)) >= 0) {
|
||||
fos.write(buffer, 0, count);
|
||||
}
|
||||
is.close();
|
||||
fos.close();
|
||||
} catch (IOException e) {
|
||||
Toast.makeText(this, R.string.error_copying_sample_file, Toast.LENGTH_SHORT).show();
|
||||
Log.e(LOG_TAG, getString(R.string.error_copying_sample_file), e);
|
||||
}
|
||||
|
||||
mFrame = findViewById(R.id.frame);
|
||||
OwnCloudClientManagerFactory.setUserAgent(getUserAgent());
|
||||
mClient = OwnCloudClientFactory.createOwnCloudClient(serverUri, this, true);
|
||||
|
||||
mClient.setCredentials(
|
||||
OwnCloudCredentialsFactory.newBasicCredentials(
|
||||
getString(R.string.username),
|
||||
getString(R.string.password)
|
||||
)
|
||||
);
|
||||
|
||||
mFilesAdapter = new FilesArrayAdapter(this, R.layout.file_in_list);
|
||||
((ListView) findViewById(R.id.list_view)).setAdapter(mFilesAdapter);
|
||||
|
||||
// TODO move to background thread or task
|
||||
AssetManager assets = getAssets();
|
||||
try {
|
||||
String sampleFileName = getString(R.string.sample_file_name);
|
||||
File upFolder = new File(getCacheDir(), getString(R.string.upload_folder_path));
|
||||
upFolder.mkdir();
|
||||
File upFile = new File(upFolder, sampleFileName);
|
||||
FileOutputStream fos = new FileOutputStream(upFile);
|
||||
InputStream is = assets.open(sampleFileName);
|
||||
int count = 0;
|
||||
byte[] buffer = new byte[1024];
|
||||
while ((count = is.read(buffer, 0, buffer.length)) >= 0) {
|
||||
fos.write(buffer, 0, count);
|
||||
}
|
||||
is.close();
|
||||
fos.close();
|
||||
} catch (IOException e) {
|
||||
Toast.makeText(this, R.string.error_copying_sample_file, Toast.LENGTH_SHORT).show();
|
||||
Log.e(LOG_TAG, getString(R.string.error_copying_sample_file), e);
|
||||
}
|
||||
|
||||
mFrame = findViewById(R.id.frame);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
File upFolder = new File(getCacheDir(), getString(R.string.upload_folder_path));
|
||||
File upFile = upFolder.listFiles()[0];
|
||||
upFile.delete();
|
||||
upFolder.delete();
|
||||
super.onDestroy();
|
||||
File upFolder = new File(getCacheDir(), getString(R.string.upload_folder_path));
|
||||
File upFile = upFolder.listFiles()[0];
|
||||
upFile.delete();
|
||||
upFolder.delete();
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void onClickHandler(View button) {
|
||||
switch (button.getId()) {
|
||||
case R.id.button_refresh:
|
||||
startRefresh();
|
||||
break;
|
||||
case R.id.button_upload:
|
||||
startUpload();
|
||||
break;
|
||||
case R.id.button_delete_remote:
|
||||
startRemoteDeletion();
|
||||
break;
|
||||
case R.id.button_download:
|
||||
startDownload();
|
||||
break;
|
||||
case R.id.button_delete_local:
|
||||
startLocalDeletion();
|
||||
break;
|
||||
default:
|
||||
Toast.makeText(this, R.string.youre_doing_it_wrong, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
switch (button.getId()) {
|
||||
case R.id.button_refresh:
|
||||
startRefresh();
|
||||
break;
|
||||
case R.id.button_upload:
|
||||
startUpload();
|
||||
break;
|
||||
case R.id.button_delete_remote:
|
||||
startRemoteDeletion();
|
||||
break;
|
||||
case R.id.button_download:
|
||||
startDownload();
|
||||
break;
|
||||
case R.id.button_delete_local:
|
||||
startLocalDeletion();
|
||||
break;
|
||||
default:
|
||||
Toast.makeText(this, R.string.youre_doing_it_wrong, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
private void startRefresh() {
|
||||
ReadRemoteFolderOperation refreshOperation = new ReadRemoteFolderOperation(FileUtils.PATH_SEPARATOR);
|
||||
refreshOperation.execute(mClient, this, mHandler);
|
||||
ReadRemoteFolderOperation refreshOperation = new ReadRemoteFolderOperation(FileUtils.PATH_SEPARATOR);
|
||||
refreshOperation.execute(mClient, this, mHandler);
|
||||
}
|
||||
|
||||
|
||||
private void startUpload() {
|
||||
File upFolder = new File(getCacheDir(), getString(R.string.upload_folder_path));
|
||||
File fileToUpload = upFolder.listFiles()[0];
|
||||
String remotePath = FileUtils.PATH_SEPARATOR + fileToUpload.getName();
|
||||
String mimeType = getString(R.string.sample_file_mimetype);
|
||||
File upFolder = new File(getCacheDir(), getString(R.string.upload_folder_path));
|
||||
File fileToUpload = upFolder.listFiles()[0];
|
||||
String remotePath = FileUtils.PATH_SEPARATOR + fileToUpload.getName();
|
||||
String mimeType = getString(R.string.sample_file_mimetype);
|
||||
|
||||
// Get the last modification date of the file from the file system
|
||||
Long timeStampLong = fileToUpload.lastModified()/1000;
|
||||
String timeStamp = timeStampLong.toString();
|
||||
// Get the last modification date of the file from the file system
|
||||
Long timeStampLong = fileToUpload.lastModified() / 1000;
|
||||
String timeStamp = timeStampLong.toString();
|
||||
|
||||
UploadRemoteFileOperation uploadOperation = new UploadRemoteFileOperation(fileToUpload.getAbsolutePath(),
|
||||
remotePath, mimeType, timeStamp);
|
||||
uploadOperation.addDatatransferProgressListener(this);
|
||||
uploadOperation.execute(mClient, this, mHandler);
|
||||
UploadRemoteFileOperation uploadOperation = new UploadRemoteFileOperation(fileToUpload.getAbsolutePath(),
|
||||
remotePath, mimeType, timeStamp);
|
||||
uploadOperation.addDatatransferProgressListener(this);
|
||||
uploadOperation.execute(mClient, this, mHandler);
|
||||
}
|
||||
|
||||
private void startRemoteDeletion() {
|
||||
File upFolder = new File(getCacheDir(), getString(R.string.upload_folder_path));
|
||||
File fileToUpload = upFolder.listFiles()[0];
|
||||
String remotePath = FileUtils.PATH_SEPARATOR + fileToUpload.getName();
|
||||
File upFolder = new File(getCacheDir(), getString(R.string.upload_folder_path));
|
||||
File fileToUpload = upFolder.listFiles()[0];
|
||||
String remotePath = FileUtils.PATH_SEPARATOR + fileToUpload.getName();
|
||||
|
||||
RemoveRemoteFileOperation removeOperation = new RemoveRemoteFileOperation(remotePath);
|
||||
removeOperation.execute(mClient, this, mHandler);
|
||||
RemoveRemoteFileOperation removeOperation = new RemoveRemoteFileOperation(remotePath);
|
||||
removeOperation.execute(mClient, this, mHandler);
|
||||
}
|
||||
|
||||
private void startDownload() {
|
||||
File downFolder = new File(getCacheDir(), getString(R.string.download_folder_path));
|
||||
downFolder.mkdir();
|
||||
File upFolder = new File(getCacheDir(), getString(R.string.upload_folder_path));
|
||||
File fileToUpload = upFolder.listFiles()[0];
|
||||
String remotePath = FileUtils.PATH_SEPARATOR + fileToUpload.getName();
|
||||
File downFolder = new File(getCacheDir(), getString(R.string.download_folder_path));
|
||||
downFolder.mkdir();
|
||||
File upFolder = new File(getCacheDir(), getString(R.string.upload_folder_path));
|
||||
File fileToUpload = upFolder.listFiles()[0];
|
||||
String remotePath = FileUtils.PATH_SEPARATOR + fileToUpload.getName();
|
||||
|
||||
DownloadRemoteFileOperation downloadOperation = new DownloadRemoteFileOperation(remotePath,
|
||||
downFolder.getAbsolutePath());
|
||||
downloadOperation.addDatatransferProgressListener(this);
|
||||
downloadOperation.execute(mClient, this, mHandler);
|
||||
DownloadRemoteFileOperation downloadOperation = new DownloadRemoteFileOperation(remotePath,
|
||||
downFolder.getAbsolutePath());
|
||||
downloadOperation.addDatatransferProgressListener(this);
|
||||
downloadOperation.execute(mClient, this, mHandler);
|
||||
}
|
||||
|
||||
private void startLocalDeletion() {
|
||||
File downFolder = new File(getCacheDir(), getString(R.string.download_folder_path));
|
||||
File downloadedFile = downFolder.listFiles()[0];
|
||||
if (!downloadedFile.delete() && downloadedFile.exists()) {
|
||||
Toast.makeText(this, R.string.error_deleting_local_file, Toast.LENGTH_SHORT).show();
|
||||
} else {
|
||||
((TextView) findViewById(R.id.download_progress)).setText("0%");
|
||||
findViewById(R.id.frame).setBackgroundDrawable(null);
|
||||
}
|
||||
private void startLocalDeletion() {
|
||||
File downFolder = new File(getCacheDir(), getString(R.string.download_folder_path));
|
||||
File downloadedFile = downFolder.listFiles()[0];
|
||||
if (!downloadedFile.delete() && downloadedFile.exists()) {
|
||||
Toast.makeText(this, R.string.error_deleting_local_file, Toast.LENGTH_SHORT).show();
|
||||
} else {
|
||||
((TextView) findViewById(R.id.download_progress)).setText("0%");
|
||||
findViewById(R.id.frame).setBackgroundDrawable(null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRemoteOperationFinish(RemoteOperation operation, RemoteOperationResult result) {
|
||||
if (!result.isSuccess()) {
|
||||
Toast.makeText(this, R.string.todo_operation_finished_in_fail, Toast.LENGTH_SHORT).show();
|
||||
Log.e(LOG_TAG, result.getLogMessage(), result.getException());
|
||||
|
||||
} else if (operation instanceof ReadRemoteFolderOperation) {
|
||||
onSuccessfulRefresh((ReadRemoteFolderOperation)operation, result);
|
||||
|
||||
} else if (operation instanceof com.owncloud.android.lib.resources.files.UploadRemoteFileOperation) {
|
||||
onSuccessfulUpload((com.owncloud.android.lib.resources.files.UploadRemoteFileOperation)operation, result);
|
||||
|
||||
} else if (operation instanceof RemoveRemoteFileOperation ) {
|
||||
onSuccessfulRemoteDeletion((RemoveRemoteFileOperation)operation, result);
|
||||
@Override
|
||||
public void onRemoteOperationFinish(RemoteOperation operation, RemoteOperationResult result) {
|
||||
if (!result.isSuccess()) {
|
||||
Toast.makeText(this, R.string.todo_operation_finished_in_fail, Toast.LENGTH_SHORT).show();
|
||||
Log.e(LOG_TAG, result.getLogMessage(), result.getException());
|
||||
|
||||
} else if (operation instanceof DownloadRemoteFileOperation ) {
|
||||
onSuccessfulDownload();
|
||||
|
||||
} else {
|
||||
Toast.makeText(this, R.string.todo_operation_finished_in_success, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
} else if (operation instanceof ReadRemoteFolderOperation) {
|
||||
onSuccessfulRefresh((ReadRemoteFolderOperation) operation, result);
|
||||
|
||||
private void onSuccessfulRefresh(ReadRemoteFolderOperation operation, RemoteOperationResult result) {
|
||||
mFilesAdapter.clear();
|
||||
List<RemoteFile> files = new ArrayList<>();
|
||||
for(RemoteFile remoteFile: (List<RemoteFile>) result.getData()) {
|
||||
} else if (operation instanceof com.owncloud.android.lib.resources.files.UploadRemoteFileOperation) {
|
||||
onSuccessfulUpload((com.owncloud.android.lib.resources.files.UploadRemoteFileOperation) operation, result);
|
||||
|
||||
} else if (operation instanceof RemoveRemoteFileOperation) {
|
||||
onSuccessfulRemoteDeletion((RemoveRemoteFileOperation) operation, result);
|
||||
|
||||
} else if (operation instanceof DownloadRemoteFileOperation) {
|
||||
onSuccessfulDownload();
|
||||
|
||||
} else {
|
||||
Toast.makeText(this, R.string.todo_operation_finished_in_success, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
private void onSuccessfulRefresh(ReadRemoteFolderOperation operation, RemoteOperationResult result) {
|
||||
mFilesAdapter.clear();
|
||||
List<RemoteFile> files = new ArrayList<>();
|
||||
for (RemoteFile remoteFile : (List<RemoteFile>) result.getData()) {
|
||||
files.add(remoteFile);
|
||||
}
|
||||
if (files != null) {
|
||||
Iterator<RemoteFile> it = files.iterator();
|
||||
while (it.hasNext()) {
|
||||
mFilesAdapter.add(it.next());
|
||||
}
|
||||
mFilesAdapter.remove(mFilesAdapter.getItem(0));
|
||||
}
|
||||
mFilesAdapter.notifyDataSetChanged();
|
||||
}
|
||||
if (files != null) {
|
||||
Iterator<RemoteFile> it = files.iterator();
|
||||
while (it.hasNext()) {
|
||||
mFilesAdapter.add(it.next());
|
||||
}
|
||||
mFilesAdapter.remove(mFilesAdapter.getItem(0));
|
||||
}
|
||||
mFilesAdapter.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
private void onSuccessfulUpload(com.owncloud.android.lib.resources.files.UploadRemoteFileOperation operation, RemoteOperationResult result) {
|
||||
startRefresh();
|
||||
}
|
||||
private void onSuccessfulUpload(com.owncloud.android.lib.resources.files.UploadRemoteFileOperation operation, RemoteOperationResult result) {
|
||||
startRefresh();
|
||||
}
|
||||
|
||||
private void onSuccessfulRemoteDeletion(RemoveRemoteFileOperation operation, RemoteOperationResult result) {
|
||||
startRefresh();
|
||||
TextView progressView = (TextView) findViewById(R.id.upload_progress);
|
||||
if (progressView != null) {
|
||||
progressView.setText("0%");
|
||||
}
|
||||
}
|
||||
private void onSuccessfulRemoteDeletion(RemoveRemoteFileOperation operation, RemoteOperationResult result) {
|
||||
startRefresh();
|
||||
TextView progressView = (TextView) findViewById(R.id.upload_progress);
|
||||
if (progressView != null) {
|
||||
progressView.setText("0%");
|
||||
}
|
||||
}
|
||||
|
||||
private void onSuccessfulDownload() {
|
||||
File downFolder = new File(getCacheDir(), getString(R.string.download_folder_path));
|
||||
File downloadedFile = downFolder.listFiles()[0];
|
||||
BitmapDrawable bDraw = new BitmapDrawable(getResources(), downloadedFile.getAbsolutePath());
|
||||
mFrame.setBackgroundDrawable(bDraw);
|
||||
}
|
||||
private void onSuccessfulDownload() {
|
||||
File downFolder = new File(getCacheDir(), getString(R.string.download_folder_path));
|
||||
File downloadedFile = downFolder.listFiles()[0];
|
||||
BitmapDrawable bDraw = new BitmapDrawable(getResources(), downloadedFile.getAbsolutePath());
|
||||
mFrame.setBackgroundDrawable(bDraw);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTransferProgress(long progressRate, long totalTransferredSoFar, long totalToTransfer, String fileName) {
|
||||
final long percentage = (totalToTransfer > 0 ? totalTransferredSoFar * 100 / totalToTransfer : 0);
|
||||
final boolean upload = fileName.contains(getString(R.string.upload_folder_path));
|
||||
Log.d(LOG_TAG, "progressRate " + percentage);
|
||||
mHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void onTransferProgress(long progressRate, long totalTransferredSoFar, long totalToTransfer, String fileName) {
|
||||
final long percentage = (totalToTransfer > 0 ? totalTransferredSoFar * 100 / totalToTransfer : 0);
|
||||
final boolean upload = fileName.contains(getString(R.string.upload_folder_path));
|
||||
Log.d(LOG_TAG, "progressRate " + percentage);
|
||||
mHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
TextView progressView = null;
|
||||
if (upload) {
|
||||
progressView = findViewById(R.id.upload_progress);
|
||||
} else {
|
||||
progressView = findViewById(R.id.download_progress);
|
||||
}
|
||||
if (progressView != null) {
|
||||
progressView.setText(Long.toString(percentage) + "%");
|
||||
}
|
||||
TextView progressView = null;
|
||||
if (upload) {
|
||||
progressView = findViewById(R.id.upload_progress);
|
||||
} else {
|
||||
progressView = findViewById(R.id.download_progress);
|
||||
}
|
||||
if (progressView != null) {
|
||||
progressView.setText(Long.toString(percentage) + "%");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// user agent
|
||||
@SuppressLint("StringFormatInvalid")
|
||||
private String getUserAgent() {
|
||||
String appString = getResources().getString(R.string.user_agent);
|
||||
String packageName = getPackageName();
|
||||
String version = "";
|
||||
// user agent
|
||||
@SuppressLint("StringFormatInvalid")
|
||||
private String getUserAgent() {
|
||||
String appString = getResources().getString(R.string.user_agent);
|
||||
String packageName = getPackageName();
|
||||
String version = "";
|
||||
|
||||
PackageInfo pInfo;
|
||||
try {
|
||||
pInfo = getPackageManager().getPackageInfo(packageName, 0);
|
||||
if (pInfo != null) {
|
||||
version = pInfo.versionName;
|
||||
}
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
Log_OC.e(TAG, "Trying to get packageName", e.getCause());
|
||||
}
|
||||
PackageInfo pInfo;
|
||||
try {
|
||||
pInfo = getPackageManager().getPackageInfo(packageName, 0);
|
||||
if (pInfo != null) {
|
||||
version = pInfo.versionName;
|
||||
}
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
Log_OC.e(TAG, "Trying to get packageName", e.getCause());
|
||||
}
|
||||
|
||||
// Mozilla/5.0 (Android) ownCloud-android/1.7.0
|
||||
return String.format(appString, version);
|
||||
}
|
||||
// Mozilla/5.0 (Android) ownCloud-android/1.7.0
|
||||
return String.format(appString, version);
|
||||
}
|
||||
}
|
||||
@@ -22,8 +22,8 @@
|
||||
THE SOFTWARE.
|
||||
|
||||
-->
|
||||
|
||||
|
||||
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
/>
|
||||
android:layout_height="wrap_content"
|
||||
/>
|
||||
|
||||
@@ -33,58 +33,58 @@
|
||||
style="@style/ButtonStyle"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_alignParentTop="true"
|
||||
android:text="@string/refresh"
|
||||
android:onClick="onClickHandler"
|
||||
android:text="@string/refresh"
|
||||
/>
|
||||
|
||||
<ListView
|
||||
android:id="@+id/list_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/button_refresh"
|
||||
android:layout_above="@+id/button_upload"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_below="@+id/button_refresh"
|
||||
>
|
||||
</ListView>
|
||||
|
||||
<Button
|
||||
android:id="@+id/button_upload"
|
||||
style="@style/ButtonStyle"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_above="@+id/frame"
|
||||
android:text="@string/upload"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:onClick="onClickHandler"
|
||||
android:text="@string/upload"
|
||||
/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/upload_progress"
|
||||
style="@style/ProgressStyle"
|
||||
android:layout_below="@id/list_view"
|
||||
android:layout_above="@id/frame"
|
||||
android:layout_toRightOf="@id/button_upload"
|
||||
android:layout_below="@id/list_view"
|
||||
android:layout_toLeftOf="@+id/button_delete_remote"
|
||||
android:layout_toRightOf="@id/button_upload"
|
||||
android:gravity="center"
|
||||
android:textSize="14sp"
|
||||
android:text="0%"
|
||||
android:textSize="14sp"
|
||||
/>
|
||||
|
||||
<Button
|
||||
android:id="@id/button_delete_remote"
|
||||
style="@style/ButtonStyle"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_above="@id/frame"
|
||||
android:text="@string/delete_remote_file"
|
||||
android:layout_alignParentRight="true"
|
||||
android:onClick="onClickHandler"
|
||||
android:text="@string/delete_remote_file"
|
||||
/>
|
||||
|
||||
<FrameLayout
|
||||
android:id="@id/frame"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/frame_height"
|
||||
android:layout_above="@+id/button_download"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_above="@+id/button_download"
|
||||
>
|
||||
</FrameLayout>
|
||||
|
||||
@@ -93,20 +93,20 @@
|
||||
style="@style/ButtonStyle"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:text="@string/download"
|
||||
android:onClick="onClickHandler"
|
||||
android:text="@string/download"
|
||||
/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/download_progress"
|
||||
style="@style/ProgressStyle"
|
||||
android:layout_below="@id/frame"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_toRightOf="@id/button_download"
|
||||
android:layout_below="@id/frame"
|
||||
android:layout_toLeftOf="@+id/button_delete_local"
|
||||
android:layout_toRightOf="@id/button_download"
|
||||
android:gravity="center"
|
||||
android:textSize="14sp"
|
||||
android:text="0%"
|
||||
android:textSize="14sp"
|
||||
/>
|
||||
|
||||
<Button
|
||||
@@ -114,8 +114,8 @@
|
||||
style="@style/ButtonStyle"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_alignParentRight="true"
|
||||
android:text="@string/delete_local_file"
|
||||
android:onClick="onClickHandler"
|
||||
android:text="@string/delete_local_file"
|
||||
/>
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
@@ -22,13 +22,15 @@
|
||||
THE SOFTWARE.
|
||||
|
||||
-->
|
||||
|
||||
|
||||
<resources xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<style name="ButtonStyle" parent="@android:style/Widget.Holo.Button">
|
||||
<item name="android:layout_width">120dp</item>
|
||||
<item name="android:layout_height">wrap_content</item>
|
||||
<item name="android:textSize">12sp</item>
|
||||
</style>
|
||||
|
||||
<style name="ProgressStyle" parent="@android:style/Widget.Holo.TextView">
|
||||
<item name="android:layout_width">wrap_content</item>
|
||||
<item name="android:layout_height">wrap_content</item>
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
THE SOFTWARE.
|
||||
|
||||
-->
|
||||
|
||||
|
||||
<resources>
|
||||
<dimen name="frame_height">120dp</dimen>
|
||||
</resources>
|
||||
@@ -26,5 +26,5 @@
|
||||
<string name="server_base_url"></string>
|
||||
<string name="username"></string>
|
||||
<string name="password"></string>
|
||||
<string name ="user_agent">Mozilla/5.0 (Android) ownCloud sample </string>
|
||||
<string name="user_agent">Mozilla/5.0 (Android) ownCloud sample </string>
|
||||
</resources>
|
||||
@@ -22,7 +22,7 @@
|
||||
THE SOFTWARE.
|
||||
|
||||
-->
|
||||
|
||||
|
||||
<resources>
|
||||
<string name="app_name">ownCloud Sample Client</string>
|
||||
<string name="refresh">Refresh</string>
|
||||
@@ -31,17 +31,17 @@
|
||||
<string name="download">Download</string>
|
||||
<string name="delete_local_file">Delete local file</string>
|
||||
<string name="youre_doing_it_wrong">You\'re doing it wrong</string>
|
||||
<string name="todo_start_refresh">TODO: start refresh</string>
|
||||
<string name="todo_start_upload">TODO: start upload</string>
|
||||
<string name="todo_start_remote_deletion">TODO: start remote deletion</string>
|
||||
<string name="todo_start_download">TODO: start download</string>
|
||||
<string name="todo_start_refresh">TODO: start refresh</string>
|
||||
<string name="todo_start_upload">TODO: start upload</string>
|
||||
<string name="todo_start_remote_deletion">TODO: start remote deletion</string>
|
||||
<string name="todo_start_download">TODO: start download</string>
|
||||
<string name="todo_start_local_deletion">TODO: start local deletion</string>
|
||||
<string name="todo_operation_finished_in_success">TODO: operation finished in success</string>
|
||||
<string name="todo_operation_finished_in_success">TODO: operation finished in success</string>
|
||||
<string name="todo_operation_finished_in_fail">TODO: operation finished in fail</string>
|
||||
<string name="upload_folder_path">to_upload</string>
|
||||
<string name="download_folder_path">downloaded</string>
|
||||
<string name="error_copying_sample_file">Sample file could not be saved in temporal folder; upload will not work</string>
|
||||
<string name="sample_file_name">oc_sample.png</string>
|
||||
<string name="sample_file_mimetype">image/png</string>
|
||||
<string name="error_deleting_local_file">Downloaded file could not be deleted</string>
|
||||
<string name="error_deleting_local_file">Downloaded file could not be deleted</string>
|
||||
</resources>
|
||||
|
||||
@@ -22,13 +22,15 @@
|
||||
THE SOFTWARE.
|
||||
|
||||
-->
|
||||
|
||||
|
||||
<resources xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<style name="ButtonStyle" parent="@android:style/Widget.Button">
|
||||
<item name="android:layout_width">120dp</item>
|
||||
<item name="android:layout_height">wrap_content</item>
|
||||
<item name="android:textSize">12sp</item>
|
||||
</style>
|
||||
|
||||
<style name="ProgressStyle" parent="@android:style/Widget.TextView">
|
||||
<item name="android:layout_width">wrap_content</item>
|
||||
<item name="android:layout_height">wrap_content</item>
|
||||
|
||||
Reference in New Issue
Block a user