本文整理汇总了Java中com.dropbox.core.android.Auth类的典型用法代码示例。如果您正苦于以下问题:Java Auth类的具体用法?Java Auth怎么用?Java Auth使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Auth类属于com.dropbox.core.android包,在下文中一共展示了Auth类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: finishAuthentication
import com.dropbox.core.android.Auth; //导入依赖的package包/类
public boolean finishAuthentication() {
if (dbxClient == null && tryLinking) {
String accessToken = loadToken();
if (accessToken == null) {
accessToken = Auth.getOAuth2Token();
if (accessToken != null) {
saveToken(accessToken);
}
}
if (accessToken != null) {
dbxClient = getDbxClient(accessToken);
return true;
}
}
return false;
}
示例2: authentication
import com.dropbox.core.android.Auth; //导入依赖的package包/类
@Override
public boolean authentication() {
String accessToken = PreferencesUtil.getInstance().getDropboxAccessToken();
if (TextUtils.isEmpty(accessToken)) {
accessToken = Auth.getOAuth2Token();
if (accessToken != null) {
PreferencesUtil.getInstance().setDropboxAccessToken(accessToken);
initData(accessToken);
return true;
}
} else {
initData(accessToken);
return true;
}
return false;
}
示例3: syncWorldToDropbox
import com.dropbox.core.android.Auth; //导入依赖的package包/类
/**
* Syncs the current World's files to the user's Dropbox account.
*
* <p>
* If the user has not yet linked a Dropbox account, they will be asked to authenticate
* their account.
* </p>
*
* <p>
* If an error occurs while syncing files, a message will be displayed.
* </p>
*/
private void syncWorldToDropbox() {
if (!(AppPreferences.dropboxAccessTokenExists(this))) {
Auth.startOAuth2Authentication(getApplicationContext(), DROPBOX_APP_KEY);
// Since the Authentication Activity interrupts the flow of this method,
// the actual syncing should occur when the user returns to this Activity after
// authentication.
syncWorldToDropboxOnResume = true;
} else {
new AlertDialog.Builder(this)
.setTitle(this.getString(R.string.confirmBackupToDropboxTitle, worldName))
.setMessage(this.getString(R.string.confirmBackupToDropbox, worldName))
.setIcon(android.R.drawable.ic_dialog_alert)
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
String accessToken = getDropboxAccessToken();
DbxClientV2 client = getDropboxClient(accessToken);
File worldDirectory = FileRetriever.getWorldDirectory(worldName);
new UploadToDropboxTask(client, worldDirectory, ArticleListActivity.this).execute();
}})
.setNegativeButton(android.R.string.no, null).show();
}
}
示例4: onCreate
import com.dropbox.core.android.Auth; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (savedInstanceState == null) {
// Toggle link/unlink depending on current state
if (preferences.contains(DropboxSyncController.ACCESS_TOKEN)) {
// Show confirmation dialog, action occurs in call-back implementations below
final ConfirmSyncUnlinkFragment dialog = new ConfirmSyncUnlinkFragment();
dialog.setController(ControllerImpl.DROPBOX);
dialog.show(getFragmentManager(), null);
} else
Auth.startOAuth2Authentication(this, getString(R.string.dropbox_appkey));
}
}
示例5: onResume
import com.dropbox.core.android.Auth; //导入依赖的package包/类
@Override
protected void onResume() {
super.onResume();
SharedPreferences prefs = getSharedPreferences("dropbox-sample", MODE_PRIVATE);
String accessToken = prefs.getString("access-token", null);
if (accessToken == null) {
accessToken = Auth.getOAuth2Token();
if (accessToken != null) {
prefs.edit().putString("access-token", accessToken).apply();
initAndLoadData(accessToken);
}
} else {
initAndLoadData(accessToken);
}
String uid = Auth.getUid();
String storedUid = prefs.getString("user-id", null);
if (uid != null && !uid.equals(storedUid)) {
prefs.edit().putString("user-id", uid).apply();
}
}
示例6: loadData
import com.dropbox.core.android.Auth; //导入依赖的package包/类
@Override
protected void loadData() {
try {
String uid = Auth.getUid();
if (uid == null) {
SharedPreferences prefs = getSharedPreferences("dropbox-sample", MODE_PRIVATE);
uid = prefs.getString("user-id", null);
}
this.mDoac = new DbxOfficialAppConnector(uid);
} catch (DropboxUidNotInitializedException e) {
e.printStackTrace();
return;
}
handleFakeOpenWithIntent(getIntent());
}
示例7: resumeGetAuthToken
import com.dropbox.core.android.Auth; //导入依赖的package包/类
private void resumeGetAuthToken(FileStorageSetupActivity activity) {
FileStorageSetupActivity storageSetupAct = activity;
if (storageSetupAct.getState().containsKey("hasStartedAuth")) {
Log.d("KP2AJ", "auth started");
String v2Token = Auth.getOAuth2Token();
if (v2Token != null) {
Log.d("KP2AJ", "auth successful");
try {
storeKey(v2Token);
buildSession();
finishActivityWithSuccess(activity);
return;
} catch (Exception e) {
Log.d("KP2AJ", "finish with error: " + e.toString());
finishWithError(activity, e);
return;
}
}
Log.i(TAG, "authenticating not succesful");
Intent data = new Intent();
data.putExtra(EXTRA_ERROR_MESSAGE, "authenticating not succesful");
((Activity) activity).setResult(Activity.RESULT_CANCELED, data);
((Activity) activity).finish();
} else {
Log.d("KP2AJ", "Starting auth");
Auth.startOAuth2Authentication((Activity) activity, appInfo.getKey());
storageSetupAct.getState().putBoolean("hasStartedAuth", true);
}
}
示例8: onResume
import com.dropbox.core.android.Auth; //导入依赖的package包/类
protected void onResume() {
super.onResume();
Log.d(TAG, "onResume() called");
String accessToken = Auth.getOAuth2Token(); //generate Access Token
Log.d(TAG, "onResume: accessToken = " + accessToken);
if (accessToken != null) {
//Store accessToken in SharedPreferences
Prefs.saveToPrefs(getApplicationContext(), "accessToken", accessToken);
parent.setVisibility(View.VISIBLE);
String backupDate = Prefs.getString(getApplicationContext(), "backup_date", "no");
if (!backupDate.equals("no")) {
textViewLastBackup.setText("Last backup: " + DateUtils.getFullTime(Long.valueOf(backupDate)));
textViewLastBackupStatus.setText("Click to back up anytime");
} else {
textViewLastBackup.setText("Click to backup");
textViewLastBackupStatus.setText("Your data will be backed up on Dropbox");
}
String restoredDate = Prefs.getString(getApplicationContext(), "restoredDate", "no");
if (!restoredDate.equals("no")) {
textViewLastRestored.setText("Last restored: " + DateUtils.getFullTime(Long.valueOf(restoredDate)));
textViewLastRestoredStatus.setText("Click to restore anytime");
} else {
textViewLastRestored.setText("Click to restore");
textViewLastRestoredStatus.setText("Your data will be restored from Dropbox");
}
buttonAuth.setVisibility(View.GONE);
} else {
accessToken = Prefs.getString(getApplicationContext(), "accessToken", "no");
if (accessToken.equals("no")) {
parent.setVisibility(View.GONE);
buttonAuth.setVisibility(View.VISIBLE);
}
}
}
示例9: completeAuth
import com.dropbox.core.android.Auth; //导入依赖的package包/类
public void completeAuth() {
try {
String authToken = Auth.getOAuth2Token();
if (startedAuth && authToken != null) {
try {
MyPreferences.storeDropboxKeys(context, authToken);
} catch (IllegalStateException e) {
Log.i("Financisto", "Error authenticating Dropbox", e);
}
}
} finally {
startedAuth = false;
}
}
示例10: getAuthenticationToken
import com.dropbox.core.android.Auth; //导入依赖的package包/类
private String getAuthenticationToken() {
String accessToken = this.settings.getDropboxAccessToken();
if (accessToken == null) {
accessToken = Auth.getOAuth2Token();
if (accessToken != null) {
this.settings.setDropboxAccessToken(accessToken);
}
}
return accessToken;
}
示例11: login
import com.dropbox.core.android.Auth; //导入依赖的package包/类
@Override
public void login() {
Logger.info(this, "login()");
if (!this.isAuthenticated()) {
Logger.verbose(this, "login():!Authenticated");
Auth.startOAuth2Authentication(serviceManager.getContext(), appKey());
}
}
示例12: startAuth
import com.dropbox.core.android.Auth; //导入依赖的package包/类
/**
* start the authentication process. If the user is already
* logged in, the method returns immediately. If not,
* a dropbox activity is launched and the caller will need
* to call {@ref finishAuth} in its onResume.
*
* @param callingActivity the calling activity
* @return true (immediate) if already authentified, won't
* return but will launch the OAuth process otherwise.
*/
public boolean startAuth(Context callingActivity) {
String accessToken = getAccessToken();
if (accessToken == null) {
Auth.startOAuth2Authentication(this, getString(R.string.app_key));
return false;
} else {
initializeClient(accessToken);
return true;
}
}
示例13: finishAuth
import com.dropbox.core.android.Auth; //导入依赖的package包/类
/**
* finish the authentication process. Must be called in the
* onResume method of the caller. See {@link ch.derlin.mybooks.views.StartActivity}
* for an example.
*/
public void finishAuth() {
String accessToken = Auth.getOAuth2Token(); //generate Access Token
if (accessToken != null) {
//Store accessToken in SharedPreferences
storeAccessToken(accessToken);
initializeClient(accessToken);
} else {
Log.i("DbAuthLog", "Error authenticating");
}
}
示例14: storeDropboxAccessToken
import com.dropbox.core.android.Auth; //导入依赖的package包/类
/**
* Stores a user access token generated from Dropbox's servers into SharedPreferences,
* if the user has authenticated their account and an access token has not already been stored.
* <p>
* Otherwise, SharedPreferences will not be modified.
* </p>
*/
private void storeDropboxAccessToken() {
if (!(AppPreferences.dropboxAccessTokenExists(this))) {
String accessToken = Auth.getOAuth2Token();
if (accessToken != null) {
SharedPreferences preferences = getSharedPreferences(
AppPreferences.PREFERENCES_FILE_NAME, MODE_PRIVATE);
preferences.edit().putString(
AppPreferences.DROPBOX_ACCESS_TOKEN, accessToken).apply();
}
}
}
示例15: getToken
import com.dropbox.core.android.Auth; //导入依赖的package包/类
public static String getToken(Context context) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
String accessToken = prefs.getString("dropbox-access-token", null);
if (accessToken != null) {
return accessToken;
}
accessToken = Auth.getOAuth2Token();
if (accessToken != null) {
prefs.edit().putString("dropbox-access-token", accessToken).commit();
}
return accessToken;
}