Example usage for android.content Intent setClassName

List of usage examples for android.content Intent setClassName

Introduction

In this page you can find the example usage for android.content Intent setClassName.

Prototype

public @NonNull Intent setClassName(@NonNull String packageName, @NonNull String className) 

Source Link

Document

Convenience for calling #setComponent with an explicit application package name and class name.

Usage

From source file:com.coact.kochzap.CaptureActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    switch (item.getItemId()) {
    case R.id.menu_start:
        intent.setClassName(this, StartActivity.class.getName());
        startActivity(intent);//from  w  w w . j a  v  a 2s .  co  m
        finish();
        return true;
    case R.id.menu_share:
        startActivity(intent);
        finish();
        return true;
    case R.id.menu_history:
        intent.setClassName(this, HistoryActivity.class.getName());
        startActivityForResult(intent, Constants.HISTORY_REQUEST_CODE);
        finish();
        return true;
    case R.id.menu_settings:
        intent.setClassName(this, PreferencesActivity.class.getName());
        startActivity(intent);
        finish();
        return true;
    case R.id.menu_help:
        intent.setClassName(this, HelpActivity.class.getName());
        startActivity(intent);
        finish();
        return true;
    default:
        return super.onOptionsItemSelected(item);
    }
}

From source file:com.owncloud.android.ui.activity.Preferences.java

private void launchDavDroidLogin()
        throws com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException,
        OperationCanceledException, AuthenticatorException, IOException {
    Account account = AccountUtils.getCurrentOwnCloudAccount(getApplicationContext());

    Intent davDroidLoginIntent = new Intent();
    davDroidLoginIntent.setClassName("at.bitfire.davdroid", "at.bitfire.davdroid.ui.setup.LoginActivity");
    if (getPackageManager().resolveActivity(davDroidLoginIntent, 0) != null) {
        // arguments
        if (mUri != null) {
            davDroidLoginIntent.putExtra("url", mUri.toString() + AccountUtils.DAV_PATH);
        }/* w ww .  j  av a2 s .  c  om*/
        davDroidLoginIntent.putExtra("username", AccountUtils.getAccountUsername(account.name));
        //loginIntent.putExtra("password", "...");
        startActivityForResult(davDroidLoginIntent, ACTION_REQUEST_CODE_DAVDROID_SETUP);
    } else {
        // DAVdroid not installed
        Intent installIntent = new Intent(Intent.ACTION_VIEW,
                Uri.parse("market://details?id=at.bitfire.davdroid"));

        // launch market(s)
        if (installIntent.resolveActivity(getPackageManager()) != null) {
            startActivity(installIntent);
        } else {
            // no f-droid market app or Play store installed --> launch browser for f-droid url
            Intent downloadIntent = new Intent(Intent.ACTION_VIEW,
                    Uri.parse("https://f-droid.org/repository/browse/?fdid=at.bitfire.davdroid"));
            startActivity(downloadIntent);

            Toast.makeText(MainApp.getAppContext(), R.string.prefs_calendar_contacts_no_store_error,
                    Toast.LENGTH_SHORT).show();
        }
    }
}

From source file:com.android.contacts.common.model.ContactLoader.java

/**
 * Posts a message to the contributing sync adapters that have opted-in, notifying them
 * that the contact has just been loaded
 *///from  w  w w.j  a v  a2 s  .  c om
private void postViewNotificationToSyncAdapter() {
    Context context = getContext();
    for (RawContact rawContact : mContact.getRawContacts()) {
        final long rawContactId = rawContact.getId();
        if (mNotifiedRawContactIds.contains(rawContactId)) {
            continue; // Already notified for this raw contact.
        }
        mNotifiedRawContactIds.add(rawContactId);
        final AccountType accountType = rawContact.getAccountType(context);
        final String serviceName = accountType.getViewContactNotifyServiceClassName();
        final String servicePackageName = accountType.getViewContactNotifyServicePackageName();
        if (!TextUtils.isEmpty(serviceName) && !TextUtils.isEmpty(servicePackageName)) {
            final Uri uri = ContentUris.withAppendedId(RawContacts.CONTENT_URI, rawContactId);
            final Intent intent = new Intent();
            intent.setClassName(servicePackageName, serviceName);
            intent.setAction(Intent.ACTION_VIEW);
            intent.setDataAndType(uri, RawContacts.CONTENT_ITEM_TYPE);
            try {
                context.startService(intent);
            } catch (Exception e) {
                Log.e(TAG, "Error sending message to source-app", e);
            }
        }
    }
}

From source file:nz.co.wholemeal.christchurchmetro.PlatformActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    Intent intent = new Intent();
    switch (item.getItemId()) {
    case R.id.info:
        Log.d(TAG, "Info selected");
        showDialog(DIALOG_PLATFORM_INFO);
        return true;

    case R.id.map:
        Log.d(TAG, "Map selected");
        intent.putExtra("latitude", current_stop.getGeoPoint().getLatitudeE6());
        intent.putExtra("longitude", current_stop.getGeoPoint().getLongitudeE6());
        intent.setClassName("nz.co.wholemeal.christchurchmetro",
                "nz.co.wholemeal.christchurchmetro.MetroMapActivity");
        startActivity(intent);//  w  w w  .j  av a2  s .  c o m
        return true;

    case R.id.refresh:
        Log.d(TAG, "Refresh selected");
        new AsyncLoadArrivals().execute(current_stop);
        return true;

    case R.id.routes_for_platform:
        Log.d(TAG, "Routes for platform selected");
        intent.putExtra("platformTag", current_stop.platformTag);
        intent.setClassName("nz.co.wholemeal.christchurchmetro",
                "nz.co.wholemeal.christchurchmetro.RoutesActivity");
        startActivity(intent);
        return true;

    case R.id.preferences:
        Log.d(TAG, "Preferences selected from menu");
        intent = new Intent();
        intent.setClassName("nz.co.wholemeal.christchurchmetro",
                "nz.co.wholemeal.christchurchmetro.PreferencesActivity");
        startActivity(intent);
        return true;

    default:
        return super.onOptionsItemSelected(item);
    }
}

From source file:com.aware.Aware.java

/**
 * Stops a plugin. Expects the package name of the plugin.
 * @param context/*from w  ww .  ja v a  2 s . c om*/
 * @param package_name
 */
public static void stopPlugin(Context context, String package_name) {
    Cursor is_installed = context.getContentResolver().query(Aware_Plugins.CONTENT_URI, null,
            Aware_Plugins.PLUGIN_PACKAGE_NAME + " LIKE '" + package_name + "'", null, null);
    if (is_installed != null && is_installed.moveToFirst()) {
        //it's installed, stop it!
        Intent plugin = new Intent();
        plugin.setClassName(package_name, package_name + ".Plugin");
        context.stopService(plugin);
        if (Aware.DEBUG)
            Log.d(TAG, package_name + " stopped...");

        ContentValues rowData = new ContentValues();
        rowData.put(Aware_Plugins.PLUGIN_STATUS, Aware_Plugin.STATUS_PLUGIN_OFF);
        context.getContentResolver().update(Aware_Plugins.CONTENT_URI, rowData,
                Aware_Plugins.PLUGIN_PACKAGE_NAME + " LIKE '" + package_name + "'", null);
    }
    if (is_installed != null && !is_installed.isClosed())
        is_installed.close();
}

From source file:github.daneren2005.dsub.fragments.SettingsFragment.java

@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
    // Random error I have no idea how to reproduce
    if (sharedPreferences == null) {
        return;//  w  ww  .  j a va2  s  .  c o m
    }

    update();

    if (Constants.PREFERENCES_KEY_HIDE_MEDIA.equals(key)) {
        setHideMedia(sharedPreferences.getBoolean(key, false));
    } else if (Constants.PREFERENCES_KEY_MEDIA_BUTTONS.equals(key)) {
        setMediaButtonsEnabled(sharedPreferences.getBoolean(key, true));
    } else if (Constants.PREFERENCES_KEY_CACHE_LOCATION.equals(key)) {
        setCacheLocation(sharedPreferences.getString(key, ""));
    } else if (Constants.PREFERENCES_KEY_SLEEP_TIMER_DURATION.equals(key)) {
        DownloadService downloadService = DownloadService.getInstance();
        downloadService.setSleepTimerDuration(Integer.parseInt(sharedPreferences.getString(key, "60")));
    } else if (Constants.PREFERENCES_KEY_SYNC_MOST_RECENT.equals(key)) {
        SyncUtil.removeMostRecentSyncFiles(context);
    } else if (Constants.PREFERENCES_KEY_REPLAY_GAIN.equals(key)
            || Constants.PREFERENCES_KEY_REPLAY_GAIN_BUMP.equals(key)
            || Constants.PREFERENCES_KEY_REPLAY_GAIN_UNTAGGED.equals(key)) {
        DownloadService downloadService = DownloadService.getInstance();
        if (downloadService != null) {
            downloadService.reapplyVolume();
        }
    } else if (Constants.PREFERENCES_KEY_START_ON_HEADPHONES.equals(key)) {
        Intent serviceIntent = new Intent();
        serviceIntent.setClassName(context.getPackageName(), HeadphoneListenerService.class.getName());

        if (sharedPreferences.getBoolean(key, false)) {
            context.startService(serviceIntent);
        } else {
            context.stopService(serviceIntent);
        }
    } else if (Constants.PREFERENCES_KEY_THEME.equals(key)) {
        String value = sharedPreferences.getString(key, null);
        if ("day/night".equals(value) || "day/black".equals(value)) {
            if (ContextCompat.checkSelfPermission(context,
                    Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
                ActivityCompat.requestPermissions(context,
                        new String[] { Manifest.permission.ACCESS_COARSE_LOCATION },
                        SubsonicActivity.PERMISSIONS_REQUEST_LOCATION);
            }
        }
    } else if (Constants.PREFERENCES_KEY_DLNA_CASTING_ENABLED.equals(key)) {
        DownloadService downloadService = DownloadService.getInstance();
        if (downloadService != null) {
            MediaRouteManager mediaRouter = downloadService.getMediaRouter();

            Boolean enabled = sharedPreferences.getBoolean(key, true);
            if (enabled) {
                mediaRouter.addDLNAProvider();
            } else {
                mediaRouter.removeDLNAProvider();
            }
        }
    }

    scheduleBackup();
}

From source file:com.fvd.nimbus.MainActivity.java

@SuppressLint("NewApi")
@Override/*from   ww w  .  j  a  va  2  s. co  m*/
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == TAKE_PHOTO) {
        if (resultCode == -1) {
            try {
                if (data != null) {
                    if (data.hasExtra("data")) {
                        Bitmap bm = data.getParcelableExtra("data");
                        photoFileName = appSettings.saveTempBitmap(bm);
                        bm.recycle();
                    }
                } else {
                    if (outputFileUri != null)
                        photoFileName = outputFileUri.getPath();
                    else
                        photoFileName = getImagePath();
                }

                if (appSettings.isFileExists(photoFileName)) {
                    Intent iPaint = new Intent();
                    iPaint.putExtra("temp", true);
                    iPaint.putExtra("path", photoFileName);
                    iPaint.setClassName("com.fvd.nimbus", "com.fvd.nimbus.PaintActivity");
                    startActivity(iPaint);
                }
                showProgress(false);
            } catch (Exception e) {
                appSettings.appendLog("main:onActivityResult: exception -  " + e.getMessage());
                showProgress(false);
            }
        } else
            showProgress(false);
    } else if (requestCode == TAKE_PICTURE) {
        if (resultCode == -1 && data != null) {
            boolean temp = false;

            try {
                Uri resultUri = data.getData();
                String drawString = resultUri.getPath();
                String galleryString = getGalleryPath(resultUri);
                if (galleryString != null && galleryString.length() > 0) {
                    drawString = galleryString;
                } else {
                    try {
                        InputStream input = getApplicationContext().getContentResolver()
                                .openInputStream(resultUri);
                        Bitmap bm = BitmapFactory.decodeStream(input);
                        drawString = appSettings.saveTempBitmap(bm);
                        bm.recycle();
                        temp = true;

                    } catch (Exception e) {
                        drawString = "";
                        showProgress(false);
                    }
                }

                if (drawString.length() > 0 && drawString.indexOf("/exposed_content/") == -1) {
                    try {
                        Intent iPaint = new Intent();
                        iPaint.putExtra("temp", temp);
                        iPaint.putExtra("path", drawString);
                        iPaint.setClassName("com.fvd.nimbus", "com.fvd.nimbus.PaintActivity");
                        startActivity(iPaint);
                    } catch (Exception e) {

                    }
                }
                showProgress(false);

            } catch (Exception e) {
                appSettings.appendLog("main:onActivityResult  " + e.getMessage());
                showProgress(false);
            }
        } else
            showProgress(false);
    } else if (requestCode == 5) {
        if (resultCode == RESULT_OK) {
            userMail = data.getStringExtra("userMail");
            userPass = data.getStringExtra("userPass");
            serverHelper.getInstance().sendOldRequest("user_register", String.format(
                    "{\"action\": \"user_register\",\"email\":\"%s\",\"password\":\"%s\",\"_client_software\": \"ff_addon\"}",
                    userMail, userPass), "");
        }
    } else if (requestCode == 6) {
        showLogin();
    } else if (requestCode == SHOW_SETTINGS) {
        switch (resultCode) {
        case RESULT_FIRST_USER + 1:
            Intent i = new Intent(getApplicationContext(), PrefsActivity.class);
            startActivity(i);
            //overridePendingTransition( R.anim.slide_in_up, R.anim.slide_out_up );
            overridePendingTransition(R.anim.carbon_slide_in, R.anim.carbon_slide_out);
            break;
        case RESULT_FIRST_USER + 2:
            if (appSettings.sessionId.length() == 0)
                showLogin();
            else {
                if (true || appSettings.service == "") {
                    appSettings.sessionId = "";
                    Editor e = prefs.edit();
                    e.putString("userMail", userMail);
                    e.putString("userPass", "");
                    e.putString("sessionId", appSettings.sessionId);
                    e.commit();
                    showLogin();
                } else {
                    i = new Intent(getApplicationContext(), loginWithActivity.class);
                    i.putExtra("logout", "true");
                    i.putExtra("service", appSettings.service);
                    startActivity(i);
                    overridePendingTransition(R.anim.carbon_slide_in, R.anim.carbon_slide_out);
                }
            }
            break;
        case RESULT_FIRST_USER + 3:
            try {
                startActivity(new Intent(Intent.ACTION_VIEW,
                        Uri.parse("market://details?id=" + getApplicationInfo().packageName)));
            } catch (Exception e) {
            }
        case RESULT_FIRST_USER + 4:
            Uri uri = Uri.parse(
                    "http://help.everhelper.me/customer/portal/articles/1376820-nimbus-clipper-for-android---quick-guide");
            Intent it = new Intent(Intent.ACTION_VIEW, uri);
            startActivity(it);
            //overridePendingTransition( R.anim.slide_in_up, R.anim.slide_out_up );
            overridePendingTransition(R.anim.carbon_slide_in, R.anim.carbon_slide_out);
            break;
        case RESULT_FIRST_USER + 5:
            final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this,
                    AlertDialog.THEME_DEVICE_DEFAULT_LIGHT);
            alertDialogBuilder.setMessage(getScriptContent("license.txt")).setCancelable(false)
                    .setPositiveButton("OK", new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int id) {
                            // no alert dialog shown
                            //alertDialogShown = null;
                            // canceled
                            setResult(RESULT_CANCELED);
                            // and finish
                            //finish();
                        }
                    });
            // create alert dialog
            final AlertDialog alertDialog = alertDialogBuilder.create();
            alertDialog.setTitle(getString(R.string.license_title));

            // and show
            //alertDialogShown = alertDialog;
            try {
                alertDialog.show();
            } catch (final java.lang.Exception e) {
                // nothing to do
            } catch (final java.lang.Error e) {
                // nothing to do
            }
            break;
        default:
            break;
        }
    }
}

From source file:com.fastbootmobile.encore.app.fragments.ListenNowFragment.java

private void setupItems() {
    mItemsSetupThread = new Thread() {
        public void run() {
            final Context context = getActivity();

            if (context == null) {
                Log.e(TAG, "Invalid context when generating Listen Now items!");
                return;
            }/*from  www .  ja  v  a 2  s .co  m*/

            final List<ListenNowAdapter.ListenNowItem> items = new ArrayList<>();
            final ProviderAggregator aggregator = ProviderAggregator.getDefault();
            final PluginsLookup plugins = PluginsLookup.getDefault();
            final List<Playlist> playlists = aggregator.getAllPlaylists();
            final List<Song> songs = new ArrayList<>();

            // Put a card to notify of sound effects
            final SharedPreferences prefs = context.getSharedPreferences(PREFS, 0);
            if (!prefs.getBoolean(LANDCARD_SOUND_EFFECTS, false)) {
                // Show the "You have no custom providers" card
                final ListenNowAdapter.CardItem item = new ListenNowAdapter.CardItem(
                        getString(R.string.ln_landcard_sfx_title), getString(R.string.ln_landcard_sfx_body),
                        getString(R.string.browse), new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                prefs.edit().putBoolean(LANDCARD_SOUND_EFFECTS, true).apply();
                                v.getContext()
                                        .startActivity(new Intent(v.getContext(), SettingsActivity.class));
                            }
                        }, getString(R.string.ln_landcard_dismiss), new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                prefs.edit().putBoolean(LANDCARD_SOUND_EFFECTS, true).apply();
                                // This item must always be the first of the list
                                mAdapter.removeItem((ListenNowAdapter.ListenNowItem) v.getTag());
                                mAdapter.notifyDataSetChanged();
                            }
                        });
                mAdapter.addItem(item);
            }

            // Put cards for new providers
            Set<ProviderConnection> newPlugins = PluginsLookup.getDefault().getNewPlugins();
            if (newPlugins != null) {
                for (final ProviderConnection plugin : newPlugins) {
                    final ListenNowAdapter.CardItem item;
                    if (plugin.getConfigurationActivity() == null) {
                        item = new ListenNowAdapter.CardItem(
                                String.format(getString(R.string.ln_landcard_plugin_installed_title),
                                        plugin.getProviderName()),
                                getString(R.string.ln_landcard_plugin_installed_body),
                                getString(R.string.ln_landcard_dismiss), new View.OnClickListener() {
                                    @Override
                                    public void onClick(View v) {
                                        prefs.edit().putBoolean(LANDCARD_SOUND_EFFECTS, true).apply();
                                        // This item must always be the first of the list
                                        mAdapter.removeItem((ListenNowAdapter.ListenNowItem) v.getTag());
                                        mAdapter.notifyDataSetChanged();
                                    }
                                });
                    } else {
                        item = new ListenNowAdapter.CardItem(
                                String.format(getString(R.string.ln_landcard_plugin_installed_title),
                                        plugin.getProviderName()),
                                getString(R.string.ln_landcard_plugin_installed_body_configure),
                                getString(R.string.ln_landcard_dismiss), new View.OnClickListener() {
                                    @Override
                                    public void onClick(View v) {
                                        prefs.edit().putBoolean(LANDCARD_SOUND_EFFECTS, true).apply();
                                        // This item must always be the first of the list
                                        mAdapter.removeItem((ListenNowAdapter.ListenNowItem) v.getTag());
                                        mAdapter.notifyDataSetChanged();
                                    }
                                }, getString(R.string.configure), new View.OnClickListener() {
                                    @Override
                                    public void onClick(View v) {
                                        mAdapter.removeItem((ListenNowAdapter.ListenNowItem) v.getTag());
                                        mAdapter.notifyDataSetChanged();

                                        Intent intent = new Intent();
                                        intent.setClassName(plugin.getPackage(),
                                                plugin.getConfigurationActivity());
                                        startActivity(intent);
                                    }
                                });
                    }
                    mAdapter.addItem(item);
                }
                PluginsLookup.getDefault().resetNewPlugins();
            }

            // Get the list of songs first
            final List<ProviderConnection> providers = plugins.getAvailableProviders();
            for (ProviderConnection provider : providers) {
                int limit = 50;
                int offset = 0;

                while (!isInterrupted()) {
                    try {
                        List<Song> providerSongs = provider.getBinder().getSongs(offset, limit);

                        if (providerSongs != null) {
                            songs.addAll(providerSongs);
                            offset += providerSongs.size();

                            if (providerSongs.size() < limit) {
                                if (DEBUG)
                                    Log.d(TAG, "Got " + providerSongs.size() + " instead of " + limit
                                            + ", assuming end of list");
                                break;
                            }
                        } else {
                            break;
                        }
                    } catch (TransactionTooLargeException e) {
                        limit -= 5;
                        if (limit <= 0) {
                            Log.e(TAG, "Error getting songs from " + provider.getProviderName()
                                    + ": transaction too large even with limit = 5");
                            break;
                        }
                    } catch (Exception e) {
                        Log.e(TAG, "Error getting songs from " + provider.getProviderName() + ": "
                                + e.getMessage());
                        break;
                    }
                }
            }

            if (isInterrupted() || isDetached())
                return;

            // Add a card if we have local music, but no cloud providers
            if (providers.size() <= PluginsLookup.BUNDLED_PROVIDERS_COUNT && songs.size() > 0) {
                if (!prefs.getBoolean(LANDCARD_NO_CUSTOM_PROVIDERS, false)) {
                    // Show the "You have no custom providers" card
                    final ListenNowAdapter.CardItem item = new ListenNowAdapter.CardItem(
                            getString(R.string.ln_landcard_nocustomprovider_title),
                            getString(R.string.ln_landcard_nocustomprovider_body), getString(R.string.browse),
                            new View.OnClickListener() {
                                @Override
                                public void onClick(View v) {
                                    ProviderDownloadDialog.newInstance(false).show(getFragmentManager(),
                                            "DOWN");
                                }
                            }, getString(R.string.ln_landcard_dismiss), new View.OnClickListener() {
                                @Override
                                public void onClick(View v) {
                                    prefs.edit().putBoolean(LANDCARD_NO_CUSTOM_PROVIDERS, true).apply();
                                    // This item must always be the first of the list
                                    mAdapter.removeItem((ListenNowAdapter.ListenNowItem) v.getTag());
                                    mAdapter.notifyDataSetChanged();
                                }
                            });

                    items.add(item);
                }
            }

            if (isInterrupted() || isDetached())
                return;

            // Add a card if there's no music at all (no songs and no playlists)
            if (providers.size() <= PluginsLookup.BUNDLED_PROVIDERS_COUNT && songs.size() == 0
                    && playlists.size() == 0) {
                items.add(new ListenNowAdapter.CardItem(getString(R.string.ln_card_nothing_title),
                        getString(R.string.ln_card_nothing_body), getString(R.string.browse),
                        new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                ProviderDownloadDialog.newInstance(false).show(getFragmentManager(), "DOWN");
                            }
                        }, getString(R.string.configure), new View.OnClickListener() {
                            public void onClick(View v) {
                                ((MainActivity) context).openSection(MainActivity.SECTION_SETTINGS);
                            }
                        }));

                items.add(new ListenNowAdapter.CardItem(getString(R.string.ln_card_nothinghint_title),
                        getString(R.string.ln_card_nothinghint_body), null, null));
            }

            if (isInterrupted() || isDetached())
                return;

            // Add the "Recently played" section if we have recent tracks
            final ListenLogger logger = new ListenLogger(context);
            List<ListenLogger.LogEntry> logEntries = logger.getEntries(50);

            if (logEntries.size() > 0 && !isDetached()) {
                items.add(new ListenNowAdapter.SectionHeaderItem(getString(R.string.ln_section_recents),
                        R.drawable.ic_nav_history_active, getString(R.string.more), new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                ((MainActivity) context).openSection(MainActivity.SECTION_HISTORY);
                            }
                        }));

                int i = 0;
                List<ListenNowAdapter.ItemCardItem> itemsCouple = new ArrayList<>();

                for (ListenLogger.LogEntry entry : logEntries) {
                    if (i == 4) {
                        // Stop here, add remaining item
                        if (itemsCouple.size() > 0) {
                            for (ListenNowAdapter.ItemCardItem item : itemsCouple) {
                                items.add(item);
                            }
                        }
                        break;
                    }

                    Song song = aggregator.retrieveSong(entry.getReference(), entry.getIdentifier());
                    if (song != null) {
                        int type = Utils.getRandom(2);
                        if (song.getAlbum() != null && (type == 0 || type == 1 && song.getArtist() == null)) {
                            Album album = aggregator.retrieveAlbum(song.getAlbum(), song.getProvider());

                            if (album != null) {
                                itemsCouple.add(new ListenNowAdapter.ItemCardItem(album));
                                ++i;
                            }
                        } else if (song.getArtist() != null) {
                            Artist artist = aggregator.retrieveArtist(song.getArtist(), song.getProvider());

                            if (artist != null) {
                                itemsCouple.add(new ListenNowAdapter.ItemCardItem(artist));
                                ++i;
                            }
                        }
                    }

                    if (itemsCouple.size() == 2) {
                        ListenNowAdapter.CardRowItem row = new ListenNowAdapter.CardRowItem(itemsCouple.get(0),
                                itemsCouple.get(1));
                        items.add(row);
                        itemsCouple.clear();
                    }
                }
            }

            if (isInterrupted() || isDetached())
                return;

            // Add playlists section
            items.add(new ListenNowAdapter.SectionHeaderItem(getString(R.string.ln_section_playlists),
                    R.drawable.ic_nav_playlist_active, getString(R.string.browse), new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            ((MainActivity) context).openSection(MainActivity.SECTION_PLAYLISTS);
                        }
                    }));

            if (playlists != null && playlists.size() > 0) {
                int i = 0;
                List<ListenNowAdapter.ItemCardItem> itemsCouple = new ArrayList<>();

                for (Playlist playlist : playlists) {
                    if (i == 4) {
                        // Stop here, add remaining item
                        if (itemsCouple.size() > 0) {
                            for (ListenNowAdapter.ItemCardItem item : itemsCouple) {
                                items.add(item);
                            }
                        }
                        break;
                    }

                    if (playlist != null) {
                        ListenNowAdapter.ItemCardItem item = new ListenNowAdapter.ItemCardItem(playlist);
                        itemsCouple.add(item);
                        ++i;
                    }

                    if (itemsCouple.size() == 2) {
                        ListenNowAdapter.CardRowItem row = new ListenNowAdapter.CardRowItem(itemsCouple.get(0),
                                itemsCouple.get(1));
                        items.add(row);
                        itemsCouple.clear();
                    }
                }
            }

            if (isInterrupted() || isDetached())
                return;

            // Add automix section
            items.add(new ListenNowAdapter.SectionHeaderItem(getString(R.string.lb_section_automixes),
                    R.drawable.ic_nav_automix_active, getString(R.string.create), new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            ((MainActivity) context).openSection(MainActivity.SECTION_AUTOMIX);
                        }
                    }));

            List<AutoMixBucket> buckets = AutoMixManager.getDefault().getBuckets();
            if (buckets == null || buckets.size() == 0) {
                items.add(new ListenNowAdapter.GetStartedItem(getString(R.string.ln_automix_getstarted_body),
                        getString(R.string.ln_action_getstarted), new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                ((MainActivity) context)
                                        .onNavigationDrawerItemSelected(MainActivity.SECTION_AUTOMIX);
                            }
                        }));
            } else {
                for (final AutoMixBucket bucket : buckets) {
                    items.add(new ListenNowAdapter.SimpleItem(bucket.getName(), new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            new Thread() {
                                public void run() {
                                    AutoMixManager.getDefault().startPlay(bucket);
                                }
                            }.start();
                        }
                    }));
                }
            }

            if (isInterrupted() || isDetached())
                return;

            mHandler.post(new Runnable() {
                public void run() {
                    for (ListenNowAdapter.ListenNowItem item : items) {
                        mAdapter.addItem(item);
                    }
                    mAdapter.notifyDataSetChanged();
                }
            });
        }
    };

    mItemsSetupThread.start();
}

From source file:com.charabia.SmsViewActivity.java

public void buttonOptions(View view) {
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
    intent.setClassName(this, PreferencesActivity.class.getName());
    startActivity(intent);/*ww  w.j av a  2 s  . co  m*/
}

From source file:com.charabia.SmsViewActivity.java

public void buttonHelp(View view) {
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
    intent.setClassName(this, WebViewActivity.class.getName());
    intent.setData(Uri.parse(WebViewActivity.getBaseUrl(this, "/help", "index.html")));
    startActivity(intent);//w ww . ja  va 2s .c om
}