本文整理汇总了Java中com.google.samples.apps.iosched.util.AccountUtils.hasActiveAccount方法的典型用法代码示例。如果您正苦于以下问题:Java AccountUtils.hasActiveAccount方法的具体用法?Java AccountUtils.hasActiveAccount怎么用?Java AccountUtils.hasActiveAccount使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.samples.apps.iosched.util.AccountUtils
的用法示例。
在下文中一共展示了AccountUtils.hasActiveAccount方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onActivityCreated
import com.google.samples.apps.iosched.util.AccountUtils; //导入方法依赖的package包/类
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
Activity activity = getActivity();
if (!activity.isFinishing()) {
// Start loading data
LoaderManager loaderManager = getLoaderManager();
loaderManager.restartLoader(PeopleIveMetQuery.TOKEN, null, this);
loaderManager.restartLoader(PeopleIveMetSubQuery.TOKEN, null, this);
// Set up the API client
GoogleApiClient.Builder builder = new GoogleApiClient.Builder(activity, this, this)
.addApi(Plus.API)
.addScope(Plus.SCOPE_PLUS_LOGIN);
if (AccountUtils.hasActiveAccount(activity)) {
builder.setAccountName(AccountUtils.getActiveAccountName(activity));
}
mApiClient = builder.build();
}
}
示例2: onStart
import com.google.samples.apps.iosched.util.AccountUtils; //导入方法依赖的package包/类
@Override
protected void onStart() {
super.onStart();
// We don't want to keep hitting RTDB needlessly, so we throttle how often we attach
// a listener to get the server time offset.
if (SyncUtils.serverTimeOffsetNeverSet(this) ||
(new Date().getTime() - SyncUtils.SERVER_TIME_OFFSET_INTERVAL) >=
SyncUtils.getServerTimeOffsetSetAt(this)) {
mDatabaseReference.addValueEventListener(mValueEventListener);
}
// Check if an earlier attempt to get the user's registration status failed
// (or somehow never occured), and reattempt if necessary.
//
// We'll also periodically re-run this, in case the user's status has changed.
long timeSinceLastRegCheck = RegistrationUtils.timeSinceLastRegCheck(this);
LOGI(TAG, "Time since last reg check:" + timeSinceLastRegCheck);
LOGI(TAG, "Status:" + RegistrationUtils.isRegisteredAttendee(this));
if (AccountUtils.hasActiveAccount(this) && (
timeSinceLastRegCheck > REG_CHECK_REFRESH_PERIOD ||
RegistrationUtils.isRegisteredAttendee(this) == RegistrationUtils.REGSTATUS_UNKNOWN)) {
RegistrationStatusService.updateRegStatusInBackground(this);
}
}
示例3: onTokenRefresh
import com.google.samples.apps.iosched.util.AccountUtils; //导入方法依赖的package包/类
@Override
public void onTokenRefresh() {
LOGV(TAG, "Set registered to false");
ServerUtilities.setRegisteredOnServer(this, false, ServerUtilities.getDeviceId(this), null);
// Get the correct FCM key for the user. FCM key is a somewhat non-standard
// approach we use in this app. For more about this, check FCM.md.
final String fcmKey = AccountUtils.hasActiveAccount(this) ?
AccountUtils.getActiveAccountId(this) : null;
// Unregister on server.
ServerUtilities.unregister(this, ServerUtilities.getDeviceId(this));
// Register for a new InstanceID token. This token is sent to the server to be paired with
// the current user's FCM key.
if(FirebaseInstanceId.getInstance().getToken() != null) {
sendRegistrationToServer(FirebaseInstanceId.getInstance().getToken(), fcmKey);
subscribeTopics(ConfMessageCardUtils.isConfMessageCardsEnabled(this),
RegistrationUtils.isRegisteredAttendee(this) ==
RegistrationUtils.REGSTATUS_REGISTERED);
}
}
示例4: unregister
import com.google.samples.apps.iosched.util.AccountUtils; //导入方法依赖的package包/类
/**
* Unregister this account/device pair within the server.
*
* @param deviceId The InstanceID token for this application instance.
*/
public static void unregister(final Context context, final String deviceId) {
if (!checkFcmEnabled()) {
return;
}
LOGI(TAG, "unregistering device (deviceId = " + deviceId + ")");
if (AccountUtils.hasActiveAccount(context) && deviceId != null) {
try {
getFcmHandler(context).fcmRegistrationEndpoint().unregister(deviceId).execute();
} catch (IOException e) {
e.printStackTrace();
LOGD(TAG, "Unable to unregister from application server", e);
}
} else {
LOGD(TAG, "User must be signed in to unregister device and device ID must be non null");
}
}
示例5: populateNavDrawer
import com.google.samples.apps.iosched.util.AccountUtils; //导入方法依赖的package包/类
/**
* Defines the Navigation Drawer items to display by updating {@code mNavDrawerItems} then
* forces the Navigation Drawer to redraw itself.
*/
private void populateNavDrawer() {
boolean attendeeAtVenue = SettingsUtils.isAttendeeAtVenue(this);
boolean conferenceInProgress = TimeUtils.isConferenceInProgress(this);
mNavDrawerItems.clear();
// decide which items will appear in the nav drawer
if (AccountUtils.hasActiveAccount(this)) {
// Only logged-in users can save sessions, so if there is no active account,
// there is no My Schedule
mNavDrawerItems.add(NAVDRAWER_ITEM_MY_SCHEDULE);
} else {
// If no active account, show Sign In
mNavDrawerItems.add(NAVDRAWER_ITEM_SIGN_IN);
}
// Explore is always shown.
mNavDrawerItems.add(NAVDRAWER_ITEM_EXPLORE);
// If the attendee is on-site, show Map on the nav drawer
if (attendeeAtVenue) {
mNavDrawerItems.add(NAVDRAWER_ITEM_MAP);
}
mNavDrawerItems.add(NAVDRAWER_ITEM_SEPARATOR);
// Other items that are always in the nav drawer.
mNavDrawerItems.add(NAVDRAWER_ITEM_SOCIAL);
mNavDrawerItems.add(NAVDRAWER_ITEM_VIDEO_LIBRARY);
mNavDrawerItems.add(NAVDRAWER_ITEM_SEPARATOR_SPECIAL);
mNavDrawerItems.add(NAVDRAWER_ITEM_SETTINGS);
mNavDrawerItems.add(NAVDRAWER_ITEM_ABOUT);
// Debug menu only on debug builds.
if (BuildConfig.DEBUG) {
mNavDrawerItems.add(NAVDRAWER_ITEM_DEBUG);
}
createNavDrawerItems();
}
示例6: getCount
import com.google.samples.apps.iosched.util.AccountUtils; //导入方法依赖的package包/类
public int getCount() {
if (mScheduleItems == null || !AccountUtils.hasActiveAccount(mContext)) {
return 0;
}
if (mScheduleItems.size() < 10) {
init();
}
return mScheduleItems.size();
}
示例7: onUpdate
import com.google.samples.apps.iosched.util.AccountUtils; //导入方法依赖的package包/类
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
LOGD(TAG, "updating app widget");
final boolean isAuthenticated = AccountUtils.hasActiveAccount(context);
for (int appWidgetId : appWidgetIds) {
// Specify the service to provide data for the collection widget. Note that we need to
// embed the appWidgetId via the data otherwise it will be ignored.
final Intent intent = new Intent(context, ScheduleWidgetRemoteViewsService.class)
.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME)));
final RemoteViews rv = new RemoteViews(context.getPackageName(), R.layout.widget);
rv.setRemoteAdapter(R.id.widget_schedule_list, intent);
// Set the empty view to be displayed if the collection is empty. It must be a sibling
// view of the collection view.
rv.setEmptyView(R.id.widget_schedule_list, android.R.id.empty);
LOGD(TAG, "setting widget empty view");
rv.setTextViewText(android.R.id.empty, context.getResources().getString(isAuthenticated
? R.string.empty_widget_text
: R.string.empty_widget_text_signed_out));
final PendingIntent refreshPendingIntent = PendingIntent.getBroadcast(context, 0,
getRefreshBroadcastIntent(context, true), PendingIntent.FLAG_UPDATE_CURRENT);
rv.setOnClickPendingIntent(R.id.widget_refresh_button, refreshPendingIntent);
final Intent onClickIntent = TaskStackBuilderProxyActivity.getTemplate(context);
final PendingIntent onClickPendingIntent = PendingIntent.getActivity(context, 0,
onClickIntent, PendingIntent.FLAG_UPDATE_CURRENT);
rv.setPendingIntentTemplate(R.id.widget_schedule_list, onClickPendingIntent);
final Intent openAppIntent = new Intent(context, MyScheduleActivity.class)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
final PendingIntent openAppPendingIntent = PendingIntent.getActivity(context, 0,
openAppIntent, PendingIntent.FLAG_UPDATE_CURRENT);
rv.setOnClickPendingIntent(R.id.widget_logo, openAppPendingIntent);
appWidgetManager.updateAppWidget(appWidgetId, rv);
}
super.onUpdate(context, appWidgetManager, appWidgetIds);
}
示例8: populateNavDrawer
import com.google.samples.apps.iosched.util.AccountUtils; //导入方法依赖的package包/类
/** Populates the navigation drawer with the appropriate items. */
private void populateNavDrawer() {
boolean attendeeAtVenue = PrefUtils.isAttendeeAtVenue(this);
mNavDrawerItems.clear();
// decide which items will appear in the nav drawer
if (AccountUtils.hasActiveAccount(this)) {
// Only logged-in users can save sessions, so if there is no active account,
// there is no My Schedule
mNavDrawerItems.add(NAVDRAWER_ITEM_MY_SCHEDULE);
} else {
// If no active account, show Sign In
mNavDrawerItems.add(NAVDRAWER_ITEM_SIGN_IN);
}
// Explore is always shown
mNavDrawerItems.add(NAVDRAWER_ITEM_EXPLORE);
// If the attendee is on-site, show Map on the nav drawer
// mNavDrawerItems.add(NAVDRAWER_ITEM_SEPARATOR);
// If attendee is on-site, show the People I've Met item
// if (attendeeAtVenue) {
// mNavDrawerItems.add(NAVDRAWER_ITEM_PEOPLE_IVE_MET);
// }
// If the experts directory hasn't expired, show it
if (!Config.hasExpertsDirectoryExpired()) {
mNavDrawerItems.add(NAVDRAWER_ITEM_EXPERTS_DIRECTORY);
}
// Other items that are always in the nav drawer irrespective of whether the
// attendee is on-site or remote:
mNavDrawerItems.add(NAVDRAWER_ITEM_SOCIAL);
// mNavDrawerItems.add(NAVDRAWER_ITEM_VIDEO_LIBRARY);
mNavDrawerItems.add(NAVDRAWER_ITEM_SEPARATOR_SPECIAL);
mNavDrawerItems.add(NAVDRAWER_ITEM_SETTINGS);
createNavDrawerItems();
}
示例9: onPrepareOptionsMenu
import com.google.samples.apps.iosched.util.AccountUtils; //导入方法依赖的package包/类
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
mAvatar = menu.findItem(R.id.menu_avatar);
if (AccountUtils.hasActiveAccount(this)) {
showAvatar();
}
return super.onPrepareOptionsMenu(menu);
}
示例10: 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 (!checkFcmEnabled()) {
return;
}
LOGI(TAG, "Notifying FCM that user data changed");
try {
if (AccountUtils.hasActiveAccount(context)) {
getPingHandler(context).sendSelfSync().execute();
}
} catch (IOException e) {
LOGE(TAG, "Unable to notify FCM about user data change", e);
}
}
示例11: getGoogleAccountCredential
import com.google.samples.apps.iosched.util.AccountUtils; //导入方法依赖的package包/类
/**
* Retrieve the Google account credentials of the currently signed in user.
*
* @param context Current context.
* @return Google account credential if user is signed in null otherwise.
*/
private static GoogleAccountCredential getGoogleAccountCredential(Context context) {
if (AccountUtils.hasActiveAccount(context)) {
GoogleAccountCredential credential =
GoogleAccountCredential
.usingOAuth2(context, Arrays.asList(AccountUtils.AUTH_SCOPES));
credential.setSelectedAccount(AccountUtils.getActiveAccount(context));
return credential;
} else {
return null;
}
}
示例12: getFcmHandler
import com.google.samples.apps.iosched.util.AccountUtils; //导入方法依赖的package包/类
/**
* Construct a Fcm object that can be used to register the device's ID with the server.
*
* @param context Current context.
* @return Fcm object with user credential if user is signed in Fcm object with no user
* credential if the user is not signed in.
*/
private static Fcm getFcmHandler(Context context) {
if (AccountUtils.hasActiveAccount(context)) {
return new Fcm.Builder(new NetHttpTransport(),
new AndroidJsonFactory(), getGoogleAccountCredential(context)).build();
} else {
return new Fcm.Builder(new NetHttpTransport(),
new AndroidJsonFactory(), null).build();
}
}
示例13: getPingHandler
import com.google.samples.apps.iosched.util.AccountUtils; //导入方法依赖的package包/类
/**
* Construct a Ping object that can be used to initiate syncs of user data.
*
* @param context Current context.
* @return Ping object with user credential if user is signed in Ping object with no user
* credential if the user is not signed in.
*/
private static Ping getPingHandler(Context context) {
if (AccountUtils.hasActiveAccount(context)) {
return new Ping.Builder(new NetHttpTransport(),
new AndroidJsonFactory(), getGoogleAccountCredential(context)).build();
} else {
return new Ping.Builder(new NetHttpTransport(),
new AndroidJsonFactory(), null).build();
}
}
示例14: registerGCMClient
import com.google.samples.apps.iosched.util.AccountUtils; //导入方法依赖的package包/类
/**
* Registers device on the GCM server, if necessary.
* <p/>
* This check is done in BaseActivity (as opposed to {@link AppApplication}) in order to make sure
* that this is always run after a user switch.
* <p/>
* As a future improvement, this code could be manually invoked by the app after a user
* switch occurs, which would allow moving this code to {@link AppApplication}.
*/
private void registerGCMClient() {
GCMRegistrar.checkDevice(this);
GCMRegistrar.checkManifest(this);
final String regId = GCMRegistrar.getRegistrationId(this);
if (TextUtils.isEmpty(regId)) {
// Automatically registers application on startup.
GCMRegistrar.register(this, BuildConfig.GCM_SENDER_ID);
} else {
// Get the correct GCM key for the user. GCM key is a somewhat non-standard
// approach we use in this app. For more about this, check GCM.TXT.
final String gcmKey = AccountUtils.hasActiveAccount(this) ?
AccountUtils.getGcmKey(this, AccountUtils.getActiveAccountName(this)) : null;
// Device is already registered on GCM, needs to check if it is
// registered on our server as well.
if (ServerUtilities.isRegisteredOnServer(this, gcmKey)) {
// Skips registration.
LOGI(TAG, "Already registered on the GCM server with right GCM key.");
} else {
// Try to register again, but not in the UI thread.
// It's also necessary to cancel the thread onDestroy(),
// hence the use of AsyncTask instead of a raw thread.
mGCMRegisterTask = new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
LOGI(TAG, "Registering on the GCM server with GCM key: "
+ AccountUtils.sanitizeGcmKey(gcmKey));
boolean registered = ServerUtilities.register(BaseActivity.this,
regId, gcmKey);
// At this point all attempts to register with the app
// server failed, so we need to unregister the device
// from GCM - the app will try to register again when
// it is restarted. Note that GCM will send an
// unregistered callback upon completion, but
// GCMIntentService.onUnregistered() will ignore it.
if (!registered) {
LOGI(TAG, "GCM registration failed.");
GCMRegistrar.unregister(BaseActivity.this);
} else {
LOGI(TAG, "GCM registration successful.");
}
return null;
}
@Override
protected void onPostExecute(Void result) {
mGCMRegisterTask = null;
}
};
mGCMRegisterTask.execute(null, null, null);
}
}
}
示例15: registerGCMClient
import com.google.samples.apps.iosched.util.AccountUtils; //导入方法依赖的package包/类
/** Registers device on the GCM server, if necessary. */
private void registerGCMClient() {
GCMRegistrar.checkDevice(this);
GCMRegistrar.checkManifest(this);
final String regId = GCMRegistrar.getRegistrationId(this);
if (TextUtils.isEmpty(regId)) {
// Automatically registers application on startup.
GCMRegistrar.register(this, Config.GCM_SENDER_ID);
} else {
// Get the correct GCM key for the user. GCM key is a somewhat non-standard
// approach we use in this app. For more about this, check GCM.TXT.
final String gcmKey = AccountUtils.hasActiveAccount(this) ?
AccountUtils.getGcmKey(this, AccountUtils.getActiveAccountName(this)) : null;
// Device is already registered on GCM, needs to check if it is
// registered on our server as well.
if (ServerUtilities.isRegisteredOnServer(this, gcmKey)) {
// Skips registration.
LOGI(TAG, "Already registered on the GCM server with right GCM key.");
} else {
// Try to register again, but not in the UI thread.
// It's also necessary to cancel the thread onDestroy(),
// hence the use of AsyncTask instead of a raw thread.
mGCMRegisterTask = new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
LOGI(TAG, "Registering on the GCM server with GCM key: "
+ AccountUtils.sanitizeGcmKey(gcmKey));
boolean registered = ServerUtilities.register(BaseActivity.this,
regId, gcmKey);
// At this point all attempts to register with the app
// server failed, so we need to unregister the device
// from GCM - the app will try to register again when
// it is restarted. Note that GCM will send an
// unregistered callback upon completion, but
// GCMIntentService.onUnregistered() will ignore it.
if (!registered) {
LOGI(TAG, "GCM registration failed.");
GCMRegistrar.unregister(BaseActivity.this);
} else {
LOGI(TAG, "GCM registration successful.");
}
return null;
}
@Override
protected void onPostExecute(Void result) {
mGCMRegisterTask = null;
}
};
mGCMRegisterTask.execute(null, null, null);
}
}
}