Example usage for android.accounts OnAccountsUpdateListener OnAccountsUpdateListener

List of usage examples for android.accounts OnAccountsUpdateListener OnAccountsUpdateListener

Introduction

In this page you can find the example usage for android.accounts OnAccountsUpdateListener OnAccountsUpdateListener.

Prototype

OnAccountsUpdateListener

Source Link

Usage

From source file:org.mozilla.gecko.AboutHomeContent.java

public void init() {
    Context context = getContext();
    mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    mInflater.inflate(R.layout.abouthome_content, this);

    mAccountManager = AccountManager.get(context);

    // The listener will run on the background thread (see 2nd argument)
    mAccountManager.addOnAccountsUpdatedListener(new OnAccountsUpdateListener() {
        public void onAccountsUpdated(Account[] accounts) {
            final GeckoApp.StartupMode startupMode = GeckoApp.mAppContext.getStartupMode();
            final boolean syncIsSetup = isSyncSetup();

            GeckoApp.mAppContext.mMainHandler.post(new Runnable() {
                public void run() {
                    // The listener might run before the UI is initially updated.
                    // In this case, we should simply wait for the initial setup
                    // to happen.
                    if (mTopSitesAdapter != null)
                        updateLayout(startupMode, syncIsSetup);
                }//from   w  w w . ja  v a  2 s.  co  m
            });
        }
    }, GeckoAppShell.getHandler(), false);

    mTopSitesGrid = (GridView) findViewById(R.id.top_sites_grid);
    mTopSitesGrid.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
            Cursor c = (Cursor) parent.getItemAtPosition(position);

            String spec = c.getString(c.getColumnIndex(URLColumns.URL));
            Log.i(LOGTAG, "clicked: " + spec);

            if (mUriLoadCallback != null)
                mUriLoadCallback.callback(spec);
        }
    });

    mAddonsLayout = (LinearLayout) findViewById(R.id.recommended_addons);
    mLastTabsLayout = (LinearLayout) findViewById(R.id.last_tabs);

    TextView allTopSitesText = (TextView) findViewById(R.id.all_top_sites_text);
    allTopSitesText.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            GeckoApp.mAppContext.showAwesomebar(AwesomeBar.Type.EDIT);
        }
    });

    TextView allAddonsText = (TextView) findViewById(R.id.all_addons_text);
    allAddonsText.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            if (mUriLoadCallback != null)
                mUriLoadCallback.callback("https://addons.mozilla.org/android");
        }
    });

    TextView syncTextView = (TextView) findViewById(R.id.sync_text);
    String syncText = syncTextView.getText().toString() + " \u00BB";
    String boldName = getContext().getResources().getString(R.string.abouthome_sync_bold_name);
    int styleIndex = syncText.indexOf(boldName);

    // Highlight any occurrence of "Firefox Sync" in the string
    // with a bold style.
    if (styleIndex >= 0) {
        SpannableString spannableText = new SpannableString(syncText);
        spannableText.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), styleIndex, styleIndex + 12, 0);
        syncTextView.setText(spannableText, TextView.BufferType.SPANNABLE);
    }

    RelativeLayout syncBox = (RelativeLayout) findViewById(R.id.sync_box);
    syncBox.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            Context context = v.getContext();
            Intent intent = new Intent(context, SetupSyncActivity.class);
            context.startActivity(intent);
        }
    });
}

From source file:com.owncloud.android.media.MediaService.java

/**
 * Initialize a service instance/*from  www.j av  a 2 s  .  c o  m*/
 * 
 * {@inheritDoc}
 */
@Override
public void onCreate() {
    super.onCreate();
    Log_OC.d(TAG, "Creating ownCloud media service");

    mWifiLock = ((WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE))
            .createWifiLock(WifiManager.WIFI_MODE_FULL, MEDIA_WIFI_LOCK_TAG);

    mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

    // Configure notification channel
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
        NotificationChannel mNotificationChannel;
        // The user-visible name of the channel.
        CharSequence name = getString(R.string.media_service_notification_channel_name);
        // The user-visible description of the channel.
        String description = getString(R.string.media_service_notification_channel_description);
        // Set importance low: show the notification everywhere but with no sound
        int importance = NotificationManager.IMPORTANCE_LOW;
        mNotificationChannel = new NotificationChannel(MEDIA_SERVICE_NOTIFICATION_CHANNEL_ID, name, importance);
        // Configure the notification channel.
        mNotificationChannel.setDescription(description);
        mNotificationManager.createNotificationChannel(mNotificationChannel);
    }

    mNotificationBuilder = new NotificationCompat.Builder(this);
    mNotificationBuilder.setColor(this.getResources().getColor(R.color.primary));
    mAudioManager = (AudioManager) getSystemService(AUDIO_SERVICE);
    mBinder = new MediaServiceBinder(this);

    // add AccountsUpdatedListener
    mAccountManager = AccountManager.get(this);
    mAccountManager.addOnAccountsUpdatedListener(new OnAccountsUpdateListener() {
        @Override
        public void onAccountsUpdated(Account[] accounts) {
            // stop playback if account of the played media files was removed
            if (mAccount != null && !AccountUtils.exists(mAccount.name, MediaService.this)) {
                processStopRequest(false);
            }
        }
    }, null, false);
}