Search in sources :

Example 31 with Builder

use of android.support.v7.app.AlertDialog.Builder in project Synthese_2BIN by TheYoungSensei.

the class BusinessDayListActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_businessday_list);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    toolbar.setTitle(getTitle());
    View recyclerView = findViewById(R.id.businessday_list);
    assert recyclerView != null;
    setupRecyclerView((RecyclerView) recyclerView);
    if (findViewById(R.id.businessday_detail_container) != null) {
        // The detail container view will be present only in the
        // large-screen layouts (res/values-w900dp).
        // If this view is present, then the
        // activity should be in two-pane mode.
        mTwoPane = true;
    }
    DetailsContent.reinitialize();
    ConnectivityManager connMgr = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
    LastFMTask task = new LastFMTask();
    if (networkInfo != null && networkInfo.isConnected()) {
        task.execute();
    }
    this.model = ((Builder) getApplication()).getModel();
}
Also used : NetworkInfo(android.net.NetworkInfo) ConnectivityManager(android.net.ConnectivityManager) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) View(android.view.View) Toolbar(android.support.v7.widget.Toolbar)

Example 32 with Builder

use of android.support.v7.app.AlertDialog.Builder in project AntennaPod by AntennaPod.

the class FlattrUtils method showNoTokenDialogOrRedirect.

/**
     * Opens a dialog that ask the user to either connect the app with flattr or to be redirected to
     * the thing's website.
     * If no API credentials are available, the user will immediately be redirected to the thing's website.
     */
public static void showNoTokenDialogOrRedirect(final Context context, final String url) {
    if (hasAPICredentials()) {
        AlertDialog.Builder builder = new AlertDialog.Builder(context);
        builder.setTitle(R.string.no_flattr_token_title);
        builder.setMessage(R.string.no_flattr_token_msg);
        builder.setPositiveButton(R.string.authenticate_now_label, new OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                context.startActivity(ClientConfig.flattrCallbacks.getFlattrAuthenticationActivityIntent(context));
            }
        });
        builder.setNegativeButton(R.string.visit_website_label, new OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                Uri uri = Uri.parse(url);
                context.startActivity(new Intent(Intent.ACTION_VIEW, uri));
            }
        });
        builder.create().show();
    } else {
        Uri uri = Uri.parse(url);
        context.startActivity(new Intent(Intent.ACTION_VIEW, uri));
    }
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) DialogInterface(android.content.DialogInterface) OnClickListener(android.content.DialogInterface.OnClickListener) Intent(android.content.Intent) Uri(android.net.Uri)

Example 33 with Builder

use of android.support.v7.app.AlertDialog.Builder in project AntennaPod by AntennaPod.

the class FlattrUtils method showRevokeDialog.

// ------------------------------------------------ DIALOGS
public static void showRevokeDialog(final Context context) {
    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    builder.setTitle(R.string.access_revoked_title);
    builder.setMessage(R.string.access_revoked_info);
    builder.setNeutralButton(android.R.string.ok, new OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.cancel();
        }
    });
    builder.create().show();
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) DialogInterface(android.content.DialogInterface) OnClickListener(android.content.DialogInterface.OnClickListener)

Example 34 with Builder

use of android.support.v7.app.AlertDialog.Builder in project AntennaPod by AntennaPod.

the class PlaybackService method setupNotification.

/**
     * Prepares notification and starts the service in the foreground.
     */
private void setupNotification(final PlaybackServiceMediaPlayer.PSMPInfo info) {
    final PendingIntent pIntent = PendingIntent.getActivity(this, 0, PlaybackService.getPlayerActivityIntent(this), PendingIntent.FLAG_UPDATE_CURRENT);
    if (notificationSetupThread != null) {
        notificationSetupThread.interrupt();
    }
    Runnable notificationSetupTask = new Runnable() {

        Bitmap icon = null;

        @Override
        public void run() {
            Log.d(TAG, "Starting background work");
            if (android.os.Build.VERSION.SDK_INT >= 11) {
                if (info.playable != null) {
                    int iconSize = getResources().getDimensionPixelSize(android.R.dimen.notification_large_icon_width);
                    try {
                        icon = Glide.with(PlaybackService.this).load(info.playable.getImageLocation()).asBitmap().diskCacheStrategy(ApGlideSettings.AP_DISK_CACHE_STRATEGY).centerCrop().into(iconSize, iconSize).get();
                    } catch (Throwable tr) {
                        Log.e(TAG, "Error loading the media icon for the notification", tr);
                    }
                }
            }
            if (icon == null) {
                icon = BitmapFactory.decodeResource(getApplicationContext().getResources(), ClientConfig.playbackServiceCallbacks.getNotificationIconResource(getApplicationContext()));
            }
            if (mediaPlayer == null) {
                return;
            }
            PlayerStatus playerStatus = mediaPlayer.getPlayerStatus();
            final int smallIcon = ClientConfig.playbackServiceCallbacks.getNotificationIconResource(getApplicationContext());
            if (!Thread.currentThread().isInterrupted() && started && info.playable != null) {
                String contentText = info.playable.getEpisodeTitle();
                String contentTitle = info.playable.getFeedTitle();
                Notification notification;
                // Builder is v7, even if some not overwritten methods return its parent's v4 interface
                NotificationCompat.Builder notificationBuilder = (NotificationCompat.Builder) new NotificationCompat.Builder(PlaybackService.this).setContentTitle(contentTitle).setContentText(contentText).setOngoing(false).setContentIntent(pIntent).setLargeIcon(icon).setSmallIcon(smallIcon).setWhen(// we don't need the time
                0).setPriority(// set notification priority
                UserPreferences.getNotifyPriority());
                IntList compactActionList = new IntList();
                // we start and 0 and then increment by 1 for each call to addAction
                int numActions = 0;
                if (isCasting) {
                    Intent stopCastingIntent = new Intent(PlaybackService.this, PlaybackService.class);
                    stopCastingIntent.putExtra(EXTRA_CAST_DISCONNECT, true);
                    PendingIntent stopCastingPendingIntent = PendingIntent.getService(PlaybackService.this, numActions, stopCastingIntent, PendingIntent.FLAG_UPDATE_CURRENT);
                    notificationBuilder.addAction(R.drawable.ic_media_cast_disconnect, getString(R.string.cast_disconnect_label), stopCastingPendingIntent);
                    numActions++;
                }
                // always let them rewind
                PendingIntent rewindButtonPendingIntent = getPendingIntentForMediaAction(KeyEvent.KEYCODE_MEDIA_REWIND, numActions);
                notificationBuilder.addAction(android.R.drawable.ic_media_rew, getString(R.string.rewind_label), rewindButtonPendingIntent);
                if (UserPreferences.showRewindOnCompactNotification()) {
                    compactActionList.add(numActions);
                }
                numActions++;
                if (playerStatus == PlayerStatus.PLAYING) {
                    PendingIntent pauseButtonPendingIntent = getPendingIntentForMediaAction(KeyEvent.KEYCODE_MEDIA_PAUSE, numActions);
                    //pause action
                    notificationBuilder.addAction(//pause action
                    android.R.drawable.ic_media_pause, getString(R.string.pause_label), pauseButtonPendingIntent);
                    compactActionList.add(numActions++);
                } else {
                    PendingIntent playButtonPendingIntent = getPendingIntentForMediaAction(KeyEvent.KEYCODE_MEDIA_PLAY, numActions);
                    //play action
                    notificationBuilder.addAction(//play action
                    android.R.drawable.ic_media_play, getString(R.string.play_label), playButtonPendingIntent);
                    compactActionList.add(numActions++);
                }
                // ff follows play, then we have skip (if it's present)
                PendingIntent ffButtonPendingIntent = getPendingIntentForMediaAction(KeyEvent.KEYCODE_MEDIA_FAST_FORWARD, numActions);
                notificationBuilder.addAction(android.R.drawable.ic_media_ff, getString(R.string.fast_forward_label), ffButtonPendingIntent);
                if (UserPreferences.showFastForwardOnCompactNotification()) {
                    compactActionList.add(numActions);
                }
                numActions++;
                if (UserPreferences.isFollowQueue()) {
                    PendingIntent skipButtonPendingIntent = getPendingIntentForMediaAction(KeyEvent.KEYCODE_MEDIA_NEXT, numActions);
                    notificationBuilder.addAction(android.R.drawable.ic_media_next, getString(R.string.skip_episode_label), skipButtonPendingIntent);
                    if (UserPreferences.showSkipOnCompactNotification()) {
                        compactActionList.add(numActions);
                    }
                    numActions++;
                }
                PendingIntent stopButtonPendingIntent = getPendingIntentForMediaAction(KeyEvent.KEYCODE_MEDIA_STOP, numActions);
                notificationBuilder.setStyle(new android.support.v7.app.NotificationCompat.MediaStyle().setMediaSession(mediaSession.getSessionToken()).setShowActionsInCompactView(compactActionList.toArray()).setShowCancelButton(true).setCancelButtonIntent(stopButtonPendingIntent)).setVisibility(NotificationCompat.VISIBILITY_PUBLIC).setColor(NotificationCompat.COLOR_DEFAULT);
                notification = notificationBuilder.build();
                if (playerStatus == PlayerStatus.PLAYING || playerStatus == PlayerStatus.PREPARING || playerStatus == PlayerStatus.SEEKING || isCasting) {
                    startForeground(NOTIFICATION_ID, notification);
                } else {
                    stopForeground(false);
                    NotificationManager mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
                    mNotificationManager.notify(NOTIFICATION_ID, notification);
                }
                Log.d(TAG, "Notification set up");
            }
        }
    };
    notificationSetupThread = new Thread(notificationSetupTask);
    notificationSetupThread.start();
}
Also used : NotificationManager(android.app.NotificationManager) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) Notification(android.app.Notification) IntList(de.danoeh.antennapod.core.util.IntList) Bitmap(android.graphics.Bitmap) NotificationCompat(android.support.v7.app.NotificationCompat) PendingIntent(android.app.PendingIntent)

Example 35 with Builder

use of android.support.v7.app.AlertDialog.Builder in project AntennaPod by AntennaPod.

the class PreferenceController method showDrawerPreferencesDialog.

private void showDrawerPreferencesDialog() {
    final Context context = ui.getActivity();
    final List<String> hiddenDrawerItems = UserPreferences.getHiddenDrawerItems();
    final String[] navTitles = context.getResources().getStringArray(R.array.nav_drawer_titles);
    final String[] NAV_DRAWER_TAGS = MainActivity.NAV_DRAWER_TAGS;
    boolean[] checked = new boolean[MainActivity.NAV_DRAWER_TAGS.length];
    for (int i = 0; i < NAV_DRAWER_TAGS.length; i++) {
        String tag = NAV_DRAWER_TAGS[i];
        if (!hiddenDrawerItems.contains(tag)) {
            checked[i] = true;
        }
    }
    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    builder.setTitle(R.string.drawer_preferences);
    builder.setMultiChoiceItems(navTitles, checked, (dialog, which, isChecked) -> {
        if (isChecked) {
            hiddenDrawerItems.remove(NAV_DRAWER_TAGS[which]);
        } else {
            hiddenDrawerItems.add(NAV_DRAWER_TAGS[which]);
        }
    });
    builder.setPositiveButton(R.string.confirm_label, (dialog, which) -> UserPreferences.setHiddenDrawerItems(hiddenDrawerItems));
    builder.setNegativeButton(R.string.cancel_label, null);
    builder.create().show();
}
Also used : Context(android.content.Context) AlertDialog(android.support.v7.app.AlertDialog) SuppressLint(android.annotation.SuppressLint)

Aggregations

AlertDialog (android.support.v7.app.AlertDialog)114 DialogInterface (android.content.DialogInterface)76 View (android.view.View)67 TextView (android.widget.TextView)48 Intent (android.content.Intent)36 RecyclerView (android.support.v7.widget.RecyclerView)27 ListView (android.widget.ListView)23 Dialog (android.app.Dialog)22 LayoutInflater (android.view.LayoutInflater)20 ImageView (android.widget.ImageView)20 EditText (android.widget.EditText)18 SuppressLint (android.annotation.SuppressLint)17 Context (android.content.Context)17 Bundle (android.os.Bundle)15 NonNull (android.support.annotation.NonNull)14 Button (android.widget.Button)13 ArrayList (java.util.ArrayList)12 BrowserDialog (acr.browser.lightning.dialog.BrowserDialog)10 OnClickListener (android.content.DialogInterface.OnClickListener)10 ScrollView (android.widget.ScrollView)10