use of android.accounts.Account in project android by owncloud.
the class UsersAndGroupsSearchProvider method searchForUsersOrGroups.
private Cursor searchForUsersOrGroups(Uri uri) {
MatrixCursor response = null;
String userQuery = uri.getLastPathSegment().toLowerCase();
/// need to trust on the AccountUtils to get the current account since the query in the client side is not
/// directly started by our code, but from SearchView implementation
Account account = AccountUtils.getCurrentOwnCloudAccount(getContext());
/// request to the OC server about users and groups matching userQuery
GetRemoteShareesOperation searchRequest = new GetRemoteShareesOperation(userQuery, REQUESTED_PAGE, RESULTS_PER_PAGE);
RemoteOperationResult result = searchRequest.execute(account, getContext());
List<JSONObject> names = new ArrayList<JSONObject>();
if (result.isSuccess()) {
for (Object o : result.getData()) {
// Get JSonObjects from response
names.add((JSONObject) o);
}
} else {
showErrorMessage(result);
}
/// convert the responses from the OC server to the expected format
if (names.size() > 0) {
response = new MatrixCursor(COLUMNS);
Iterator<JSONObject> namesIt = names.iterator();
JSONObject item;
String displayName = null;
int icon = 0;
Uri dataUri = null;
int count = 0;
MainApp app = (MainApp) getContext().getApplicationContext();
Uri userBaseUri = new Uri.Builder().scheme(CONTENT).authority(sSuggestAuthority + DATA_USER_SUFFIX).build();
Uri groupBaseUri = new Uri.Builder().scheme(CONTENT).authority(sSuggestAuthority + DATA_GROUP_SUFFIX).build();
Uri remoteBaseUri = new Uri.Builder().scheme(CONTENT).authority(sSuggestAuthority + DATA_REMOTE_SUFFIX).build();
FileDataStorageManager manager = new FileDataStorageManager(account, getContext().getContentResolver());
boolean federatedShareAllowed = manager.getCapability(account.name).getFilesSharingFederationOutgoing().isTrue();
try {
while (namesIt.hasNext()) {
item = namesIt.next();
String userName = item.getString(GetRemoteShareesOperation.PROPERTY_LABEL);
JSONObject value = item.getJSONObject(GetRemoteShareesOperation.NODE_VALUE);
int type = value.getInt(GetRemoteShareesOperation.PROPERTY_SHARE_TYPE);
String shareWith = value.getString(GetRemoteShareesOperation.PROPERTY_SHARE_WITH);
if (ShareType.GROUP.getValue() == type) {
displayName = getContext().getString(R.string.share_group_clarification, userName);
icon = R.drawable.ic_group;
dataUri = Uri.withAppendedPath(groupBaseUri, shareWith);
} else if (ShareType.FEDERATED.getValue() == type && federatedShareAllowed) {
icon = R.drawable.ic_user;
if (userName.equals(shareWith)) {
displayName = getContext().getString(R.string.share_remote_clarification, userName);
} else {
String[] uriSplitted = shareWith.split("@");
displayName = getContext().getString(R.string.share_known_remote_clarification, userName, uriSplitted[uriSplitted.length - 1]);
}
dataUri = Uri.withAppendedPath(remoteBaseUri, shareWith);
} else if (ShareType.USER.getValue() == type) {
displayName = userName;
icon = R.drawable.ic_user;
dataUri = Uri.withAppendedPath(userBaseUri, shareWith);
}
if (displayName != null && dataUri != null) {
response.newRow().add(// BaseColumns._ID
count++).add(// SearchManager.SUGGEST_COLUMN_TEXT_1
displayName).add(// SearchManager.SUGGEST_COLUMN_ICON_1
icon).add(dataUri);
}
}
} catch (JSONException e) {
Log_OC.e(TAG, "Exception while parsing data of users/groups", e);
}
}
return response;
}
use of android.accounts.Account in project android by owncloud.
the class DocumentsStorageProvider method queryRoots.
@Override
public Cursor queryRoots(String[] projection) throws FileNotFoundException {
initiateStorageMap();
final RootCursor result = new RootCursor(projection);
for (Account account : AccountUtils.getAccounts(getContext())) result.addRoot(account, getContext());
return result;
}
use of android.accounts.Account in project android by owncloud.
the class DocumentsStorageProvider method initiateStorageMap.
private void initiateStorageMap() {
mRootIdToStorageManager = new HashMap<Long, FileDataStorageManager>();
ContentResolver contentResolver = getContext().getContentResolver();
for (Account account : AccountUtils.getAccounts(getContext())) {
final FileDataStorageManager storageManager = new FileDataStorageManager(account, contentResolver);
final OCFile rootDir = storageManager.getFileByPath("/");
mRootIdToStorageManager.put(rootDir.getFileId(), storageManager);
}
}
use of android.accounts.Account in project android by owncloud.
the class OperationsService method newOperation.
/**
* Creates a new operation, as described by operationIntent.
*
* TODO - move to ServiceHandler (probably)
*
* @param operationIntent Intent describing a new operation to queue and execute.
* @return Pair with the new operation object and the information about its
* target server.
*/
private Pair<Target, RemoteOperation> newOperation(Intent operationIntent) {
RemoteOperation operation = null;
Target target = null;
try {
if (!operationIntent.hasExtra(EXTRA_ACCOUNT) && !operationIntent.hasExtra(EXTRA_SERVER_URL)) {
Log_OC.e(TAG, "Not enough information provided in intent");
} else {
Account account = operationIntent.getParcelableExtra(EXTRA_ACCOUNT);
String serverUrl = operationIntent.getStringExtra(EXTRA_SERVER_URL);
String cookie = operationIntent.getStringExtra(EXTRA_COOKIE);
target = new Target(account, (serverUrl == null) ? null : Uri.parse(serverUrl), cookie);
String action = operationIntent.getAction();
if (action.equals(ACTION_CREATE_SHARE_VIA_LINK)) {
// Create public share via link
String remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH);
String password = operationIntent.getStringExtra(EXTRA_SHARE_PASSWORD);
if (remotePath.length() > 0) {
operation = new CreateShareViaLinkOperation(remotePath, password);
}
} else if (ACTION_UPDATE_SHARE.equals(action)) {
String remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH);
long shareId = operationIntent.getLongExtra(EXTRA_SHARE_ID, -1);
if (remotePath != null && remotePath.length() > 0) {
operation = new UpdateShareViaLinkOperation(remotePath);
String password = operationIntent.getStringExtra(EXTRA_SHARE_PASSWORD);
((UpdateShareViaLinkOperation) operation).setPassword(password);
long expirationDate = operationIntent.getLongExtra(EXTRA_SHARE_EXPIRATION_DATE_IN_MILLIS, 0);
((UpdateShareViaLinkOperation) operation).setExpirationDate(expirationDate);
if (operationIntent.hasExtra(EXTRA_SHARE_PUBLIC_UPLOAD)) {
((UpdateShareViaLinkOperation) operation).setPublicUpload(operationIntent.getBooleanExtra(EXTRA_SHARE_PUBLIC_UPLOAD, false));
}
} else if (shareId > 0) {
operation = new UpdateSharePermissionsOperation(shareId);
int permissions = operationIntent.getIntExtra(EXTRA_SHARE_PERMISSIONS, 1);
((UpdateSharePermissionsOperation) operation).setPermissions(permissions);
}
} else if (action.equals(ACTION_CREATE_SHARE_WITH_SHAREE)) {
// Create private share with user or group
String remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH);
String shareeName = operationIntent.getStringExtra(EXTRA_SHARE_WITH);
ShareType shareType = (ShareType) operationIntent.getSerializableExtra(EXTRA_SHARE_TYPE);
int permissions = operationIntent.getIntExtra(EXTRA_SHARE_PERMISSIONS, -1);
if (remotePath.length() > 0) {
operation = new CreateShareWithShareeOperation(remotePath, shareeName, shareType, permissions);
}
} else if (action.equals(ACTION_UNSHARE)) {
// Unshare file
String remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH);
ShareType shareType = (ShareType) operationIntent.getSerializableExtra(EXTRA_SHARE_TYPE);
String shareWith = operationIntent.getStringExtra(EXTRA_SHARE_WITH);
if (remotePath.length() > 0) {
operation = new UnshareOperation(remotePath, shareType, shareWith, OperationsService.this);
}
} else if (action.equals(ACTION_GET_SERVER_INFO)) {
// check OC server and get basic information from it
operation = new GetServerInfoOperation(serverUrl, OperationsService.this);
} else if (action.equals(ACTION_OAUTH2_GET_ACCESS_TOKEN)) {
/// GET ACCESS TOKEN to the OAuth server
String oauth2QueryParameters = operationIntent.getStringExtra(EXTRA_OAUTH2_QUERY_PARAMETERS);
operation = new OAuth2GetAccessToken(getString(R.string.oauth2_client_id), getString(R.string.oauth2_redirect_uri), getString(R.string.oauth2_grant_type), oauth2QueryParameters);
} else if (action.equals(ACTION_GET_USER_NAME)) {
// Get User Name
operation = new GetRemoteUserInfoOperation();
} else if (action.equals(ACTION_RENAME)) {
// Rename file or folder
String remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH);
String newName = operationIntent.getStringExtra(EXTRA_NEWNAME);
operation = new RenameFileOperation(remotePath, newName);
} else if (action.equals(ACTION_REMOVE)) {
// Remove file or folder
String remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH);
boolean onlyLocalCopy = operationIntent.getBooleanExtra(EXTRA_REMOVE_ONLY_LOCAL, false);
operation = new RemoveFileOperation(remotePath, onlyLocalCopy);
} else if (action.equals(ACTION_CREATE_FOLDER)) {
// Create Folder
String remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH);
boolean createFullPath = operationIntent.getBooleanExtra(EXTRA_CREATE_FULL_PATH, true);
operation = new CreateFolderOperation(remotePath, createFullPath);
} else if (action.equals(ACTION_SYNC_FILE)) {
// Sync file
String remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH);
operation = new SynchronizeFileOperation(remotePath, account, getApplicationContext());
} else if (action.equals(ACTION_SYNC_FOLDER)) {
// Sync folder (all its descendant files are sync'ed)
String remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH);
boolean pushOnly = operationIntent.getBooleanExtra(EXTRA_PUSH_ONLY, false);
boolean syncContentOfRegularFiles = operationIntent.getBooleanExtra(EXTRA_SYNC_REGULAR_FILES, false);
operation = new SynchronizeFolderOperation(// TODO remove this dependency from construction time
this, remotePath, account, // TODO remove this dependency from construction time
System.currentTimeMillis(), pushOnly, false, syncContentOfRegularFiles);
} else if (action.equals(ACTION_MOVE_FILE)) {
// Move file/folder
String remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH);
String newParentPath = operationIntent.getStringExtra(EXTRA_NEW_PARENT_PATH);
operation = new MoveFileOperation(remotePath, newParentPath, account);
} else if (action.equals(ACTION_COPY_FILE)) {
// Copy file/folder
String remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH);
String newParentPath = operationIntent.getStringExtra(EXTRA_NEW_PARENT_PATH);
operation = new CopyFileOperation(remotePath, newParentPath, account);
} else if (action.equals(ACTION_CHECK_CURRENT_CREDENTIALS)) {
// Check validity of currently stored credentials for a given account
operation = new CheckCurrentCredentialsOperation(account);
}
}
} catch (IllegalArgumentException e) {
Log_OC.e(TAG, "Bad information provided in intent: " + e.getMessage());
operation = null;
}
if (operation != null) {
return new Pair<Target, RemoteOperation>(target, operation);
} else {
return null;
}
}
use of android.accounts.Account in project android by owncloud.
the class DrawerActivity method populateDrawerOwnCloudAccounts.
/**
* populates the avatar drawer array with the first three ownCloud {@link Account}s while the first element is
* always the current account.
*/
private void populateDrawerOwnCloudAccounts() {
mAccountsWithAvatars = new Account[3];
Account[] accountsAll = AccountManager.get(this).getAccountsByType(MainApp.getAccountType());
Account currentAccount = AccountUtils.getCurrentOwnCloudAccount(this);
mAccountsWithAvatars[0] = currentAccount;
int j = 0;
for (int i = 1; i <= 2 && i < accountsAll.length && j < accountsAll.length; j++) {
if (!currentAccount.equals(accountsAll[j])) {
mAccountsWithAvatars[i] = accountsAll[j];
i++;
}
}
}
Aggregations