本文整理汇总了Java中com.google.samples.apps.iosched.util.AccountUtils类的典型用法代码示例。如果您正苦于以下问题:Java AccountUtils类的具体用法?Java AccountUtils怎么用?Java AccountUtils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AccountUtils类属于com.google.samples.apps.iosched.util包,在下文中一共展示了AccountUtils类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: run
import com.google.samples.apps.iosched.util.AccountUtils; //导入依赖的package包/类
@Override
public void run(final Context context, final Callback callback) {
ConferenceDataHandler.resetDataTimestamp(context);
final Bundle bundle = new Bundle();
bundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);
new AsyncTask<Context, Void, Void>() {
@Override
protected Void doInBackground(Context... contexts) {
Account account = AccountUtils.getActiveAccount(context);
if (account == null) {
callback.done(false, "Cannot sync if there is no active account.");
} else {
new SyncHelper(contexts[0]).performSync(new SyncResult(),
AccountUtils.getActiveAccount(context), bundle);
}
return null;
}
}.execute(context);
}
示例2: run
import com.google.samples.apps.iosched.util.AccountUtils; //导入依赖的package包/类
@Override
public void run(final Context context, final Callback callback) {
new AsyncTask<Context, Void, Void>() {
@Override
protected Void doInBackground(Context... params) {
final AbstractUserDataSyncHelper syncer = UserDataSyncHelperFactory.buildSyncHelper(
context, AccountUtils.getActiveAccountName(context));
syncer.sync();
return null;
}
@Override
protected void onPostExecute(Void aVoid) {
callback.done(true, "Sync done");
}
}.execute(context);
}
示例3: onResume
import com.google.samples.apps.iosched.util.AccountUtils; //导入依赖的package包/类
@Override
protected void onResume() {
super.onResume();
// Perform one-time bootstrap setup, if needed
DataBootstrapService.startDataBootstrapIfNecessary(this);
// Check to ensure a Google Account is active for the app. Placing the check here ensures
// it is run again in the case where a Google Account wasn't present on the device and a
// picker had to be started.
if (!AccountUtils.enforceActiveGoogleAccount(this, SELECT_GOOGLE_ACCOUNT_RESULT)) {
LOGD(TAG, "EnforceActiveGoogleAccount returned false");
return;
}
// Watch for sync state changes
mSyncStatusObserver.onStatusChanged(0);
final int mask = ContentResolver.SYNC_OBSERVER_TYPE_PENDING |
ContentResolver.SYNC_OBSERVER_TYPE_ACTIVE;
mSyncObserverHandle = ContentResolver.addStatusChangeListener(mask, mSyncStatusObserver);
startLoginProcess();
}
示例4: onActivityResult
import com.google.samples.apps.iosched.util.AccountUtils; //导入依赖的package包/类
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// Handle the select {@code startActivityForResult} from
// {@code enforceActiveGoogleAccount()} when a Google Account wasn't present on the device.
if (requestCode == SELECT_GOOGLE_ACCOUNT_RESULT) {
if (resultCode == RESULT_OK) {
// Set selected GoogleAccount as active.
String accountName = data.getStringExtra(AccountManager.KEY_ACCOUNT_NAME);
AccountUtils.setActiveAccount(this, accountName);
onAuthSuccess(accountName, true);
} else {
LOGW(TAG, "A Google Account is required to use this application.");
// This application requires a Google Account to be selected.
finish();
}
return;
}
if (mLoginAndAuthHelper == null || !mLoginAndAuthHelper.onActivityResult(requestCode,
resultCode, data)) {
super.onActivityResult(requestCode, resultCode, data);
}
}
示例5: onStatusChanged
import com.google.samples.apps.iosched.util.AccountUtils; //导入依赖的package包/类
@Override
public void onStatusChanged(int which) {
runOnUiThread(new Runnable() {
@Override
public void run() {
String accountName = AccountUtils.getActiveAccountName(BaseActivity.this);
if (TextUtils.isEmpty(accountName)) {
onRefreshingStateChanged(false);
mManualSyncRequest = false;
return;
}
Account account = new Account(accountName, GoogleAuthUtil.GOOGLE_ACCOUNT_TYPE);
boolean syncActive = ContentResolver.isSyncActive(
account, ScheduleContract.CONTENT_AUTHORITY);
boolean syncPending = ContentResolver.isSyncPending(
account, ScheduleContract.CONTENT_AUTHORITY);
if (!syncActive && !syncPending) {
mManualSyncRequest = false;
}
onRefreshingStateChanged(syncActive || mManualSyncRequest);
}
});
}
示例6: dump
import com.google.samples.apps.iosched.util.AccountUtils; //导入依赖的package包/类
/**
* Providing important state information to be included in bug reports.
*
* !!! Remember !!! Any important data logged to {@code writer} shouldn't contain personally
* identifiable information as it can be seen in bugreports.
*/
@Override
public void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Context context = getContext();
// Using try/catch block in case there are issues retrieving information to log.
try {
// Calling append in multiple calls is typically better than creating net new strings to
// pass to method invocations.
writer.print("Last sync attempted: ");
writer.println(new java.util.Date(SettingsUtils.getLastSyncAttemptedTime(context)));
writer.print("Last sync successful: ");
writer.println(new java.util.Date(SettingsUtils.getLastSyncSucceededTime(context)));
writer.print("Current sync interval: ");
writer.println(SettingsUtils.getCurSyncInterval(context));
writer.print("Is an account active: ");
writer.println(AccountUtils.hasActiveAccount(context));
boolean canGetAuthToken = !TextUtils.isEmpty(AccountUtils.getAuthToken(context));
writer.print("Can an auth token be retrieved: ");
writer.println(canGetAuthToken);
} catch (Exception exception) {
writer.append("Exception while dumping state: ");
exception.printStackTrace(writer);
}
}
示例7: onReceive
import com.google.samples.apps.iosched.util.AccountUtils; //导入依赖的package包/类
@Override
public void onReceive(final Context context, Intent widgetIntent) {
final String action = widgetIntent.getAction();
if (REFRESH_ACTION.equals(action)) {
LOGD(TAG, "received REFRESH_ACTION from widget");
final boolean shouldSync = widgetIntent.getBooleanExtra(EXTRA_PERFORM_SYNC, false);
// Trigger sync
Account chosenAccount = AccountUtils.getActiveAccount(context);
if (shouldSync && chosenAccount != null) {
SyncHelper.requestManualSync(chosenAccount);
}
// Notify the widget that the list view needs to be updated.
final AppWidgetManager mgr = AppWidgetManager.getInstance(context);
final ComponentName cn = new ComponentName(context, ScheduleWidgetProvider.class);
mgr.notifyAppWidgetViewDataChanged(mgr.getAppWidgetIds(cn),
R.id.widget_schedule_list);
}
super.onReceive(context, widgetIntent);
}
示例8: onReceive
import com.google.samples.apps.iosched.util.AccountUtils; //导入依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
String accountName = AccountUtils.getActiveAccountName(context);
if (TextUtils.isEmpty(accountName)) {
return;
}
Account account = AccountUtils.getActiveAccount(context);
if (account != null) {
if (intent.getBooleanExtra(EXTRA_USER_DATA_SYNC_ONLY, false) ) {
// this is a request to sync user data only, so do a manual sync right now
// with the userDataOnly == true.
SyncHelper.requestManualSync(account, true);
} else {
// this is a request to sync everything
ContentResolver.requestSync(account, ScheduleContract.CONTENT_AUTHORITY, new Bundle());
}
}
}
示例9: notifyUserDataChanged
import com.google.samples.apps.iosched.util.AccountUtils; //导入依赖的package包/类
/**
* Request user data sync.
*
* @param context Current context
*/
public static void notifyUserDataChanged(final Context context) {
if (!checkGcmEnabled()) {
return;
}
LOGI(TAG, "Notifying GCM that user data changed");
String serverUrl = BuildConfig.GCM_SERVER_URL + "/send/self/sync_user";
try {
String gcmKey = AccountUtils.getGcmKey(context, AccountUtils.getActiveAccountName(context));
if (gcmKey != null) {
post(serverUrl, new HashMap<String, String>(), gcmKey);
}
} catch (IOException e) {
LOGE(TAG, "Unable to notify GCM about user data change", e);
}
}
示例10: setRegisteredOnServer
import com.google.samples.apps.iosched.util.AccountUtils; //导入依赖的package包/类
/**
* Sets whether the device was successfully registered in the server side.
*
* @param context Current context
* @param flag True if registration was successful, false otherwise
* @param gcmId True if registration was successful, false otherwise
*/
private static void setRegisteredOnServer(Context context, boolean flag, String gcmId, String gcmKey) {
final SharedPreferences prefs = context.getSharedPreferences(
PREFERENCES, Context.MODE_PRIVATE);
LOGD(TAG, "Setting registered on server status as: " + flag + ", gcmKey="
+ AccountUtils.sanitizeGcmKey(gcmKey));
Editor editor = prefs.edit();
if (flag) {
editor.putLong(PROPERTY_REGISTERED_TS, new Date().getTime());
editor.putString(PROPERTY_GCM_KEY, gcmKey == null ? "" : gcmKey);
editor.putString(PROPERTY_REG_ID, gcmId);
} else {
editor.remove(PROPERTY_REG_ID);
}
editor.apply();
}