本文整理汇总了Java中com.google.android.gms.drive.query.SortOrder类的典型用法代码示例。如果您正苦于以下问题:Java SortOrder类的具体用法?Java SortOrder怎么用?Java SortOrder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SortOrder类属于com.google.android.gms.drive.query包,在下文中一共展示了SortOrder类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getDriveFile
import com.google.android.gms.drive.query.SortOrder; //导入依赖的package包/类
/**
* Search for a file with the specific name and mimeType
* @return driveId for the file it if exists.
*/
private DriveId getDriveFile(String fileName, String mimeType) {
// Find the named file with the specific Mime type.
Query query = new Query.Builder()
.addFilter(Filters.and(
Filters.eq(SearchableField.TITLE, fileName),
Filters.eq(SearchableField.MIME_TYPE, mimeType)))
.setSortOrder(new SortOrder.Builder()
.addSortDescending(SortableField.MODIFIED_DATE)
.build())
.build();
MetadataBuffer buffer = null;
try {
buffer = Drive.DriveApi.getAppFolder(mGoogleApiClient)
.queryChildren(mGoogleApiClient, query).await().getMetadataBuffer();
if (buffer != null && buffer.getCount() > 0) {
LOGD(TAG, "got buffer " + buffer.getCount());
return buffer.get(0).getDriveId();
}
return null;
} finally {
if (buffer != null) {
buffer.close();
}
}
}
示例2: getBackupsFromDrive
import com.google.android.gms.drive.query.SortOrder; //导入依赖的package包/类
private void getBackupsFromDrive() {
if (mGoogleApiClient != null && mGoogleApiClient.isConnected()) {
final Activity activity = this;
SortOrder sortOrder = new SortOrder.Builder()
.addSortDescending(SortableField.MODIFIED_DATE).build();
Query query = new Query.Builder()
.addFilter(Filters.eq(SearchableField.TITLE, Constants.EXPORT_REALM_FILE_NAME))
.addFilter(Filters.eq(SearchableField.TRASHED, false))
.setSortOrder(sortOrder)
.build();
Drive.DriveApi.getAppFolder(mGoogleApiClient)
.queryChildren(mGoogleApiClient, query)
.setResultCallback(new ResultCallback<DriveApi.MetadataBufferResult>() {
private ArrayList<AutographaGoBackup> backupsArray = new ArrayList<>();
@Override
public void onResult(@NonNull DriveApi.MetadataBufferResult result) {
MetadataBuffer buffer = result.getMetadataBuffer();
int size = buffer.getCount();
for (int i = 0; i < size; i++) {
Metadata metadata = buffer.get(i);
DriveId driveId = metadata.getDriveId();
Date modifiedDate = metadata.getModifiedDate();
long backupSize = metadata.getFileSize();
backupsArray.add(new AutographaGoBackup(driveId, modifiedDate, backupSize));
}
mAdapter = new BackupAdapter(BackupActivity.this, backupsArray);
backupRecyclerView.setAdapter(mAdapter);
}
});
} else {
showConnectionError();
reinitializeGoogleApiClient(true, false, false, null);
}
}
示例3: onConnected
import com.google.android.gms.drive.query.SortOrder; //导入依赖的package包/类
@Override
public void onConnected(Bundle connectionHint) {
super.onConnected(connectionHint);
SortOrder sortOrder = new SortOrder.Builder()
.addSortAscending(SortableField.TITLE)
.build();
Query query = new Query.Builder()
.setSortOrder(sortOrder)
.build();
Drive.DriveApi.query(getGoogleApiClient(), query)
.setResultCallback(metadataCallback);
}
示例4: onDriveClientReady
import com.google.android.gms.drive.query.SortOrder; //导入依赖的package包/类
private void onDriveClientReady() {
Log.d(TAG, "Drive API is ready!");
SharedPreferences preferences = getPreferenceManager().getSharedPreferences();
String driveFileID = preferences.getString(KEY_BACKUP_FILE_DRIVE_ID_STRING, null);
if (null == driveFileID) { // This is the first time connecting to drive
// 1- Check drive contents
// 2- Ask user to choose a backup to restore if found any
mDriveResourceClient.getAppFolder()
.continueWithTask(new Continuation<DriveFolder, Task<MetadataBuffer>>() {
@Override
public Task<MetadataBuffer> then(@NonNull Task<DriveFolder> task) throws Exception {
// Get backup files from drive.
SortOrder sortOrder = new SortOrder.Builder()
.addSortDescending(SortableField.CREATED_DATE)
.build();
Query query = new Query.Builder()
.addFilter(
Filters.and(
Filters.eq(SearchableField.MIME_TYPE, "application/zip"),
Filters.eq(SearchableField.TITLE, "backup.zip")
)
)
.setSortOrder(sortOrder)
.build();
return mDriveResourceClient.queryChildren(task.getResult(), query);
}
})
.addOnSuccessListener(new OnSuccessListener<MetadataBuffer>() {
@Override
public void onSuccess(MetadataBuffer metadata) {
if (metadata.getCount() != 0) {
// Found some backup files saved in the drive.
// show user if they want to restore from any of these backups
List<DriveFileItem> files = new ArrayList<>(metadata.getCount());
for (Metadata m : metadata) {
files.add(new DriveFileItem(m));
Log.d(TAG, String.format(Locale.getDefault(), "%s %,.2fKB", m.getDriveId().encodeToString(), (m.getFileSize() / 1024f)));
}
showSelectDriveBackupDialog(files);
} else {
// No backup found.. Activate the drive backup.
setDriveFileId("");
activateBackup();
}
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Log.e(TAG, "Cannot query current backups.", e);
Toast.makeText(getContext(), R.string.pref_backup_unable_to_list_drive_backups, Toast.LENGTH_SHORT).show();
}
});
} else {
activateBackup();
}
}
示例5: sync_getFile
import com.google.android.gms.drive.query.SortOrder; //导入依赖的package包/类
/**
* Looks for the specified file name (or title).<br><br>
*
* <b>Note</b><br>
* Only returns the first found file if there is more than one file
* with the same filename/title.
*
* @param fileName The file name or title of the desired file.
* @returns DriveFile The desired file or null if there is none. See
* {@link DriveFile}.
*
*/
public synchronized DriveFile sync_getFile(String fileName) throws TBDriveException {
DriveFile driveFile = null;
//Look for a file with title/filename
SortOrder sortOrder = new SortOrder.Builder()
.addSortAscending(SortableField.TITLE)
.addSortDescending(SortableField.MODIFIED_DATE).build();
Query query = new Query.Builder().addFilter(
Filters.and(
Filters.eq(SearchableField.TITLE, fileName)
, Filters.eq(SearchableField.TRASHED, false)
//, Filters.eq(SearchableField.MIME_TYPE, "text/plain")
//, Filters.eq(customPropertyKey, "world")
)
)
.setSortOrder(sortOrder)
.build();
MetadataBufferResult result = Drive.DriveApi.query(getGoogleApiClient(), query).await();
if (!result.getStatus().isSuccess()) {
Log.e(TAG, "Problem while retrieving files: '" + result.getStatus().getStatusMessage() + "'");
result.release();
throw new TBDriveException("Problem while retrieving files: '" + result.getStatus().getStatusMessage() + "'");
}
Iterator<Metadata> iterator = result.getMetadataBuffer().iterator();
Metadata mData = null;
while(iterator.hasNext()) {
mData = iterator.next();
if(!mData.isFolder()){
driveFile = Drive.DriveApi.getFile(getGoogleApiClient(), mData.getDriveId());
if(driveFile==null) {
//Error getting Drive File from id. Should never happen
Log.e(TAG, "Problem while retrieving file with DriveId: " + mData.getDriveId());
result.release();
throw new TBDriveException("Problem while retrieving file with DriveId: " + mData.getDriveId() + ". Not found in Drive!!");
}
}
break; //Should only be one.
}
result.release();
return driveFile;
}
示例6: async_search
import com.google.android.gms.drive.query.SortOrder; //导入依赖的package包/类
/**
* Search for a file.
*
* @param fileName The filename/title to search for.
* @param callback See {@link TBDriveFileSearchCallback}
*/
public void async_search(String fileName, final TBDriveFileSearchCallback callback) {
final ResultCallback<MetadataBufferResult> metadataBufferCallback = new
ResultCallback<MetadataBufferResult>() {
@Override
public void onResult(MetadataBufferResult result) {
if (!result.getStatus().isSuccess()) {
Log.e(TAG, "Problem while retrieving files: '" + result.getStatus().getStatusMessage() + "'");
if(callback!=null) {
callback.setErrorCode(ERROR_FILE_SEARCH);
callback.setErrorMessage(ERROR_FILE_SEARCH_STRING);
callback.setErrorDetails(result.getStatus().getStatusMessage());
callback.run();
}
result.release();
return;
}
List<FileInfo> searchResults = new ArrayList<FileInfo>();
FileInfo fInfo = null;
Iterator<Metadata> iterator = result.getMetadataBuffer().iterator();
Metadata mData = null;
while(iterator.hasNext()) {
mData = iterator.next();
//Files found!
DriveFile driveFile = Drive.DriveApi.getFile(getGoogleApiClient(), mData.getDriveId());
if(driveFile!=null) {
fInfo = new FileInfo(driveFile, mData);
searchResults.add(fInfo);
}
}
if(callback!=null) {
callback.setSearchResult(searchResults);
callback.run();
}
result.release();
}
};
//Look for a file with title/filename
SortOrder sortOrder = new SortOrder.Builder()
.addSortAscending(SortableField.TITLE)
.addSortDescending(SortableField.MODIFIED_DATE).build();
Query query = new Query.Builder().addFilter(
Filters.and(
Filters.eq(SearchableField.TITLE, fileName)
, Filters.eq(SearchableField.TRASHED, false)
//, Filters.eq(SearchableField.MIME_TYPE, "text/plain")
//, Filters.eq(customPropertyKey, "world")
)
)
.setSortOrder(sortOrder)
.build();
Drive.DriveApi.query(getGoogleApiClient(), query)
.setResultCallback(metadataBufferCallback);
}
示例7: sync_search
import com.google.android.gms.drive.query.SortOrder; //导入依赖的package包/类
/**
* Search for a file.
*
* @param fileName The filename/title to search for.
* @throws TBDriveFileSearchCallback
*/
public List<FileInfo> sync_search(String fileName) throws TBDriveException {
List<FileInfo> searchResults = null;
//Look for a file with title/filename
SortOrder sortOrder = new SortOrder.Builder()
.addSortAscending(SortableField.TITLE)
.addSortDescending(SortableField.MODIFIED_DATE).build();
Query query = new Query.Builder().addFilter(
Filters.and(
Filters.eq(SearchableField.TITLE, fileName)
, Filters.eq(SearchableField.TRASHED, false)
//, Filters.eq(SearchableField.MIME_TYPE, "text/plain")
//, Filters.eq(customPropertyKey, "world")
)
)
.setSortOrder(sortOrder)
.build();
MetadataBufferResult result = Drive.DriveApi.query(getGoogleApiClient(), query).await();
if (!result.getStatus().isSuccess()) {
Log.e(TAG, "Problem while retrieving files: '" + result.getStatus().getStatusMessage() + "'");
result.release();
throw new TBDriveException("Problem while retrieving files: '" + result.getStatus().getStatusMessage() + "'");
}
searchResults = new ArrayList<FileInfo>();
DriveFile driveFile = null;
FileInfo fInfo = null;
Metadata mData = null;
Iterator<Metadata> iterator = result.getMetadataBuffer().iterator();
while(iterator.hasNext()) {
mData = iterator.next();
driveFile = Drive.DriveApi.getFile(getGoogleApiClient(), mData.getDriveId());
if(driveFile!=null) {
fInfo = new FileInfo(driveFile, mData);
searchResults.add(fInfo);
}
}
result.release();
return searchResults;
}