Search in sources :

Example 16 with Toast

use of android.widget.Toast in project Douya by DreaminginCodeZH.

the class CheatSheetUtils method show.

/**
     * Internal helper method to show the cheat sheet toast.
     */
private static boolean show(View view, CharSequence text) {
    if (TextUtils.isEmpty(text)) {
        return false;
    }
    // origin is device display
    final int[] screenPos = new int[2];
    // includes decorations (e.g. status bar)
    final Rect displayFrame = new Rect();
    view.getLocationOnScreen(screenPos);
    view.getWindowVisibleDisplayFrame(displayFrame);
    final Context context = view.getContext();
    final int viewWidth = view.getWidth();
    final int viewHeight = view.getHeight();
    final int viewCenterX = screenPos[0] + viewWidth / 2;
    final int screenWidth = context.getResources().getDisplayMetrics().widthPixels;
    final int estimatedToastHeight = (int) (ESTIMATED_TOAST_HEIGHT_DIPS * context.getResources().getDisplayMetrics().density);
    Toast cheatSheet = Toast.makeText(context, text, Toast.LENGTH_SHORT);
    boolean showBelow = screenPos[1] < estimatedToastHeight;
    if (showBelow) {
        // Show below
        // Offsets are after decorations (e.g. status bar) are factored in
        cheatSheet.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL, viewCenterX - screenWidth / 2, screenPos[1] - displayFrame.top + viewHeight);
    } else {
        // Show above
        // Offsets are after decorations (e.g. status bar) are factored in
        // NOTE: We can't use Gravity.BOTTOM because when the keyboard is up
        // its height isn't factored in.
        cheatSheet.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL, viewCenterX - screenWidth / 2, screenPos[1] - displayFrame.top - estimatedToastHeight);
    }
    cheatSheet.show();
    return true;
}
Also used : Context(android.content.Context) Rect(android.graphics.Rect) Toast(android.widget.Toast)

Example 17 with Toast

use of android.widget.Toast in project AntennaPod by AntennaPod.

the class DirectoryChooserActivity method openNewFolderDialog.

/**
     * Shows a confirmation dialog that asks the user if he wants to create a
     * new folder.
     */
private void openNewFolderDialog() {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle(R.string.create_folder_label);
    builder.setMessage(String.format(getString(R.string.create_folder_msg), CREATE_DIRECTORY_NAME));
    builder.setNegativeButton(R.string.cancel_label, (dialog, which) -> dialog.dismiss());
    builder.setPositiveButton(R.string.confirm_label, (dialog, which) -> {
        dialog.dismiss();
        int msg = createFolder();
        Toast t = Toast.makeText(DirectoryChooserActivity.this, msg, Toast.LENGTH_SHORT);
        t.show();
    });
    builder.create().show();
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) Toast(android.widget.Toast)

Example 18 with Toast

use of android.widget.Toast in project AntennaPod by AntennaPod.

the class ItemFragment method onContextItemSelected.

@Override
public boolean onContextItemSelected(MenuItem item) {
    boolean handled = selectedURL != null;
    if (selectedURL != null) {
        switch(item.getItemId()) {
            case R.id.open_in_browser_item:
                Uri uri = Uri.parse(selectedURL);
                final Intent intent = new Intent(Intent.ACTION_VIEW, uri);
                if (IntentUtils.isCallable(getActivity(), intent)) {
                    getActivity().startActivity(intent);
                }
                break;
            case R.id.share_url_item:
                ShareUtils.shareLink(getActivity(), selectedURL);
                break;
            case R.id.copy_url_item:
                if (android.os.Build.VERSION.SDK_INT >= 11) {
                    ClipData clipData = ClipData.newPlainText(selectedURL, selectedURL);
                    android.content.ClipboardManager cm = (android.content.ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
                    cm.setPrimaryClip(clipData);
                } else {
                    android.text.ClipboardManager cm = (android.text.ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
                    cm.setText(selectedURL);
                }
                Toast t = Toast.makeText(getActivity(), R.string.copied_url_msg, Toast.LENGTH_SHORT);
                t.show();
                break;
            default:
                handled = false;
                break;
        }
        selectedURL = null;
    }
    return handled;
}
Also used : Toast(android.widget.Toast) Intent(android.content.Intent) Context(android.content.Context) Uri(android.net.Uri) ClipData(android.content.ClipData)

Example 19 with Toast

use of android.widget.Toast in project AntennaPod by AntennaPod.

the class ItemDescriptionFragment method onContextItemSelected.

@SuppressWarnings("deprecation")
@SuppressLint("NewApi")
@Override
public boolean onContextItemSelected(MenuItem item) {
    boolean handled = selectedURL != null;
    if (selectedURL != null) {
        switch(item.getItemId()) {
            case R.id.open_in_browser_item:
                Uri uri = Uri.parse(selectedURL);
                final Intent intent = new Intent(Intent.ACTION_VIEW, uri);
                if (IntentUtils.isCallable(getActivity(), intent)) {
                    getActivity().startActivity(intent);
                }
                break;
            case R.id.share_url_item:
                ShareUtils.shareLink(getActivity(), selectedURL);
                break;
            case R.id.copy_url_item:
                if (android.os.Build.VERSION.SDK_INT >= 11) {
                    ClipData clipData = ClipData.newPlainText(selectedURL, selectedURL);
                    android.content.ClipboardManager cm = (android.content.ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
                    cm.setPrimaryClip(clipData);
                } else {
                    android.text.ClipboardManager cm = (android.text.ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
                    cm.setText(selectedURL);
                }
                Toast t = Toast.makeText(getActivity(), R.string.copied_url_msg, Toast.LENGTH_SHORT);
                t.show();
                break;
            case R.id.go_to_position_item:
                if (Timeline.isTimecodeLink(selectedURL)) {
                    onTimecodeLinkSelected(selectedURL);
                } else {
                    Log.e(TAG, "Selected go_to_position_item, but URL was no timecode link: " + selectedURL);
                }
                break;
            default:
                handled = false;
                break;
        }
        selectedURL = null;
    }
    return handled;
}
Also used : Toast(android.widget.Toast) Intent(android.content.Intent) Context(android.content.Context) Uri(android.net.Uri) ClipData(android.content.ClipData) SuppressLint(android.annotation.SuppressLint)

Example 20 with Toast

use of android.widget.Toast in project AntennaPod by AntennaPod.

the class PreferenceController method onCreate.

public void onCreate() {
    final Activity activity = ui.getActivity();
    if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
        // disable expanded notification option on unsupported android versions
        ui.findPreference(PreferenceController.PREF_EXPANDED_NOTIFICATION).setEnabled(false);
        ui.findPreference(PreferenceController.PREF_EXPANDED_NOTIFICATION).setOnPreferenceClickListener(preference -> {
            Toast toast = Toast.makeText(activity, R.string.pref_expand_notify_unsupport_toast, Toast.LENGTH_SHORT);
            toast.show();
            return true;
        });
    }
    ui.findPreference(PreferenceController.PREF_FLATTR_REVOKE).setOnPreferenceClickListener(preference -> {
        FlattrUtils.revokeAccessToken(activity);
        checkItemVisibility();
        return true;
    });
    ui.findPreference(PreferenceController.PREF_ABOUT).setOnPreferenceClickListener(preference -> {
        activity.startActivity(new Intent(activity, AboutActivity.class));
        return true;
    });
    ui.findPreference(PreferenceController.STATISTICS).setOnPreferenceClickListener(preference -> {
        activity.startActivity(new Intent(activity, StatisticsActivity.class));
        return true;
    });
    ui.findPreference(PreferenceController.PREF_OPML_EXPORT).setOnPreferenceClickListener(preference -> export(new OpmlWriter()));
    ui.findPreference(PreferenceController.PREF_HTML_EXPORT).setOnPreferenceClickListener(preference -> export(new HtmlWriter()));
    ui.findPreference(PreferenceController.PREF_CHOOSE_DATA_DIR).setOnPreferenceClickListener(preference -> {
        if (Build.VERSION_CODES.KITKAT <= Build.VERSION.SDK_INT && Build.VERSION.SDK_INT <= Build.VERSION_CODES.LOLLIPOP_MR1) {
            showChooseDataFolderDialog();
        } else {
            int readPermission = ActivityCompat.checkSelfPermission(activity, Manifest.permission.READ_EXTERNAL_STORAGE);
            int writePermission = ActivityCompat.checkSelfPermission(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE);
            if (readPermission == PackageManager.PERMISSION_GRANTED && writePermission == PackageManager.PERMISSION_GRANTED) {
                openDirectoryChooser();
            } else {
                requestPermission();
            }
        }
        return true;
    });
    ui.findPreference(PreferenceController.PREF_CHOOSE_DATA_DIR).setOnPreferenceClickListener(preference -> {
        if (Build.VERSION.SDK_INT >= 19) {
            showChooseDataFolderDialog();
        } else {
            Intent intent = new Intent(activity, DirectoryChooserActivity.class);
            activity.startActivityForResult(intent, DirectoryChooserActivity.RESULT_CODE_DIR_SELECTED);
        }
        return true;
    });
    ui.findPreference(UserPreferences.PREF_THEME).setOnPreferenceChangeListener((preference, newValue) -> {
        Intent i = new Intent(activity, MainActivity.class);
        i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
        activity.finish();
        activity.startActivity(i);
        return true;
    });
    ui.findPreference(UserPreferences.PREF_HIDDEN_DRAWER_ITEMS).setOnPreferenceClickListener(preference -> {
        showDrawerPreferencesDialog();
        return true;
    });
    ui.findPreference(UserPreferences.PREF_COMPACT_NOTIFICATION_BUTTONS).setOnPreferenceClickListener(preference -> {
        showNotificationButtonsDialog();
        return true;
    });
    ui.findPreference(UserPreferences.PREF_UPDATE_INTERVAL).setOnPreferenceClickListener(preference -> {
        showUpdateIntervalTimePreferencesDialog();
        return true;
    });
    ui.findPreference(UserPreferences.PREF_ENABLE_AUTODL).setOnPreferenceChangeListener((preference, newValue) -> {
        if (newValue instanceof Boolean) {
            boolean enabled = (Boolean) newValue;
            ui.findPreference(UserPreferences.PREF_EPISODE_CACHE_SIZE).setEnabled(enabled);
            ui.findPreference(UserPreferences.PREF_ENABLE_AUTODL_ON_BATTERY).setEnabled(enabled);
            ui.findPreference(UserPreferences.PREF_ENABLE_AUTODL_WIFI_FILTER).setEnabled(enabled);
            setSelectedNetworksEnabled(enabled && UserPreferences.isEnableAutodownloadWifiFilter());
        }
        return true;
    });
    ui.findPreference(UserPreferences.PREF_ENABLE_AUTODL_WIFI_FILTER).setOnPreferenceChangeListener((preference, newValue) -> {
        if (newValue instanceof Boolean) {
            setSelectedNetworksEnabled((Boolean) newValue);
            return true;
        } else {
            return false;
        }
    });
    ui.findPreference(UserPreferences.PREF_PARALLEL_DOWNLOADS).setOnPreferenceChangeListener((preference, o) -> {
        if (o instanceof String) {
            try {
                int value = Integer.parseInt((String) o);
                if (1 <= value && value <= 50) {
                    setParallelDownloadsText(value);
                    return true;
                }
            } catch (NumberFormatException e) {
                return false;
            }
        }
        return false;
    });
    // validate and set correct value: number of downloads between 1 and 50 (inclusive)
    final EditText ev = ((EditTextPreference) ui.findPreference(UserPreferences.PREF_PARALLEL_DOWNLOADS)).getEditText();
    ev.addTextChangedListener(new TextWatcher() {

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }

        @Override
        public void afterTextChanged(Editable s) {
            if (s.length() > 0) {
                try {
                    int value = Integer.parseInt(s.toString());
                    if (value <= 0) {
                        ev.setText("1");
                    } else if (value > 50) {
                        ev.setText("50");
                    }
                } catch (NumberFormatException e) {
                    ev.setText("6");
                }
                ev.setSelection(ev.getText().length());
            }
        }
    });
    ui.findPreference(UserPreferences.PREF_EPISODE_CACHE_SIZE).setOnPreferenceChangeListener((preference, o) -> {
        if (o instanceof String) {
            setEpisodeCacheSizeText(UserPreferences.readEpisodeCacheSize((String) o));
        }
        return true;
    });
    ui.findPreference(PreferenceController.PREF_PLAYBACK_SPEED_LAUNCHER).setOnPreferenceClickListener(preference -> {
        VariableSpeedDialog.showDialog(activity);
        return true;
    });
    ui.findPreference(PreferenceController.PREF_GPODNET_SETLOGIN_INFORMATION).setOnPreferenceClickListener(preference -> {
        AuthenticationDialog dialog = new AuthenticationDialog(activity, R.string.pref_gpodnet_setlogin_information_title, false, false, GpodnetPreferences.getUsername(), null) {

            @Override
            protected void onConfirmed(String username, String password, boolean saveUsernamePassword) {
                GpodnetPreferences.setPassword(password);
            }
        };
        dialog.show();
        return true;
    });
    ui.findPreference(PreferenceController.PREF_GPODNET_SYNC).setOnPreferenceClickListener(preference -> {
        GpodnetSyncService.sendSyncIntent(ui.getActivity().getApplicationContext());
        Toast toast = Toast.makeText(ui.getActivity(), R.string.pref_gpodnet_sync_started, Toast.LENGTH_SHORT);
        toast.show();
        return true;
    });
    ui.findPreference(PreferenceController.PREF_GPODNET_FORCE_FULL_SYNC).setOnPreferenceClickListener(preference -> {
        GpodnetPreferences.setLastSubscriptionSyncTimestamp(0L);
        GpodnetPreferences.setLastEpisodeActionsSyncTimestamp(0L);
        GpodnetPreferences.setLastSyncAttempt(false, 0);
        updateLastGpodnetSyncReport(false, 0);
        GpodnetSyncService.sendSyncIntent(ui.getActivity().getApplicationContext());
        Toast toast = Toast.makeText(ui.getActivity(), R.string.pref_gpodnet_sync_started, Toast.LENGTH_SHORT);
        toast.show();
        return true;
    });
    ui.findPreference(PreferenceController.PREF_GPODNET_LOGOUT).setOnPreferenceClickListener(preference -> {
        GpodnetPreferences.logout();
        Toast toast = Toast.makeText(activity, R.string.pref_gpodnet_logout_toast, Toast.LENGTH_SHORT);
        toast.show();
        updateGpodnetPreferenceScreen();
        return true;
    });
    ui.findPreference(PreferenceController.PREF_GPODNET_HOSTNAME).setOnPreferenceClickListener(preference -> {
        GpodnetSetHostnameDialog.createDialog(activity).setOnDismissListener(dialog -> updateGpodnetPreferenceScreen());
        return true;
    });
    ui.findPreference(PreferenceController.PREF_AUTO_FLATTR_PREFS).setOnPreferenceClickListener(preference -> {
        AutoFlattrPreferenceDialog.newAutoFlattrPreferenceDialog(activity, new AutoFlattrPreferenceDialog.AutoFlattrPreferenceDialogInterface() {

            @Override
            public void onCancelled() {
            }

            @Override
            public void onConfirmed(boolean autoFlattrEnabled, float autoFlattrValue) {
                UserPreferences.setAutoFlattrSettings(autoFlattrEnabled, autoFlattrValue);
                checkItemVisibility();
            }
        });
        return true;
    });
    ui.findPreference(UserPreferences.PREF_IMAGE_CACHE_SIZE).setOnPreferenceChangeListener((preference, o) -> {
        if (o instanceof String) {
            int newValue = Integer.parseInt((String) o) * 1024 * 1024;
            if (newValue != UserPreferences.getImageCacheSize()) {
                AlertDialog.Builder dialog = new AlertDialog.Builder(ui.getActivity());
                dialog.setTitle(android.R.string.dialog_alert_title);
                dialog.setMessage(R.string.pref_restart_required);
                dialog.setPositiveButton(android.R.string.ok, null);
                dialog.show();
            }
            return true;
        }
        return false;
    });
    ui.findPreference(PREF_PROXY).setOnPreferenceClickListener(preference -> {
        ProxyDialog dialog = new ProxyDialog(ui.getActivity());
        dialog.createDialog().show();
        return true;
    });
    ui.findPreference(PREF_KNOWN_ISSUES).setOnPreferenceClickListener(preference -> {
        openInBrowser("https://github.com/AntennaPod/AntennaPod/labels/bug");
        return true;
    });
    ui.findPreference(PREF_FAQ).setOnPreferenceClickListener(preference -> {
        openInBrowser("http://antennapod.org/faq.html");
        return true;
    });
    ui.findPreference(PREF_SEND_CRASH_REPORT).setOnPreferenceClickListener(preference -> {
        Intent emailIntent = new Intent(Intent.ACTION_SEND);
        emailIntent.setType("text/plain");
        emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[] { "Martin.Fietz@gmail.com" });
        emailIntent.putExtra(Intent.EXTRA_SUBJECT, "AntennaPod Crash Report");
        emailIntent.putExtra(Intent.EXTRA_TEXT, "Please describe what you were doing when the app crashed");
        emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(CrashReportWriter.getFile()));
        String intentTitle = ui.getActivity().getString(R.string.send_email);
        ui.getActivity().startActivity(Intent.createChooser(emailIntent, intentTitle));
        return true;
    });
    PreferenceControllerFlavorHelper.setupFlavoredUI(ui);
    buildEpisodeCleanupPreference();
    buildSmartMarkAsPlayedPreference();
    buildAutodownloadSelectedNetworsPreference();
    setSelectedNetworksEnabled(UserPreferences.isEnableAutodownloadWifiFilter());
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) ProxyDialog(de.danoeh.antennapod.dialog.ProxyDialog) AutoFlattrPreferenceDialog(de.danoeh.antennapod.dialog.AutoFlattrPreferenceDialog) HtmlWriter(de.danoeh.antennapod.core.export.html.HtmlWriter) MainActivity(de.danoeh.antennapod.activity.MainActivity) AboutActivity(de.danoeh.antennapod.activity.AboutActivity) StatisticsActivity(de.danoeh.antennapod.activity.StatisticsActivity) PreferenceActivity(de.danoeh.antennapod.activity.PreferenceActivity) DirectoryChooserActivity(de.danoeh.antennapod.activity.DirectoryChooserActivity) Activity(android.app.Activity) StatisticsActivity(de.danoeh.antennapod.activity.StatisticsActivity) Toast(android.widget.Toast) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) EditText(android.widget.EditText) AuthenticationDialog(de.danoeh.antennapod.dialog.AuthenticationDialog) Intent(android.content.Intent) EditTextPreference(android.preference.EditTextPreference) SuppressLint(android.annotation.SuppressLint) AboutActivity(de.danoeh.antennapod.activity.AboutActivity) OpmlWriter(de.danoeh.antennapod.core.export.opml.OpmlWriter)

Aggregations

Toast (android.widget.Toast)485 Context (android.content.Context)89 View (android.view.View)86 TextView (android.widget.TextView)74 Intent (android.content.Intent)55 Rect (android.graphics.Rect)34 LayoutInflater (android.view.LayoutInflater)31 SuppressLint (android.annotation.SuppressLint)30 JSONObject (org.json.JSONObject)23 ImageView (android.widget.ImageView)21 RequestQueue (com.android.volley.RequestQueue)20 Response (com.android.volley.Response)20 EditText (android.widget.EditText)19 JSONException (org.json.JSONException)18 VolleyError (com.android.volley.VolleyError)17 JsonObjectRequest (com.android.volley.toolbox.JsonObjectRequest)17 User (model.User)16 PendingIntent (android.app.PendingIntent)15 File (java.io.File)15 HashMap (java.util.HashMap)15