Search in sources :

Example 51 with Snackbar

use of com.google.android.material.snackbar.Snackbar in project SeriesGuide by UweTrottmann.

the class BaseTopActivity method onLastAutoBackupFailed.

@Override
protected void onLastAutoBackupFailed() {
    if (snackbar != null && snackbar.isShown()) {
        Timber.d("NOT showing auto backup failed message: existing snackbar.");
        return;
    }
    Snackbar newSnackbar = Snackbar.make(getSnackbarParentView(), R.string.autobackup_failed, Snackbar.LENGTH_INDEFINITE);
    // Manually increase max lines.
    TextView textView = newSnackbar.getView().findViewById(com.google.android.material.R.id.snackbar_text);
    textView.setMaxLines(5);
    newSnackbar.addCallback(new Snackbar.Callback() {

        @Override
        public void onDismissed(Snackbar transientBottomBar, int event) {
            if (event == Snackbar.Callback.DISMISS_EVENT_ACTION || event == Snackbar.Callback.DISMISS_EVENT_SWIPE) {
                Timber.i("Has seen last auto backup failed.");
                BackupSettings.setHasSeenLastAutoBackupFailed(BaseTopActivity.this);
            }
        }
    }).setAction(R.string.preferences, v -> startActivity(DataLiberationActivity.intentToShowAutoBackup(this))).show();
    snackbar = newSnackbar;
}
Also used : Utils(com.battlelancer.seriesguide.util.Utils) SgApp(com.battlelancer.seriesguide.SgApp) CloudSetupActivity(com.battlelancer.seriesguide.backend.CloudSetupActivity) Intent(android.content.Intent) StatsActivity(com.battlelancer.seriesguide.ui.stats.StatsActivity) MenuItem(android.view.MenuItem) AnimationUtils(android.view.animation.AnimationUtils) ActionBar(androidx.appcompat.app.ActionBar) BuildConfig(com.battlelancer.seriesguide.BuildConfig) ContentResolver(android.content.ContentResolver) AccountUtils(com.battlelancer.seriesguide.sync.AccountUtils) SyncStatusObserver(android.content.SyncStatusObserver) Menu(android.view.Menu) BackupSettings(com.battlelancer.seriesguide.dataliberation.BackupSettings) View(android.view.View) HexagonTools(com.battlelancer.seriesguide.backend.HexagonTools) BottomNavigationView(com.google.android.material.bottomnavigation.BottomNavigationView) HexagonSettings(com.battlelancer.seriesguide.backend.settings.HexagonSettings) SupportTheDev(com.battlelancer.seriesguide.util.SupportTheDev) Account(android.accounts.Account) AppCompatDelegate(androidx.appcompat.app.AppCompatDelegate) Timber(timber.log.Timber) IdRes(androidx.annotation.IdRes) TextView(android.widget.TextView) MoreOptionsActivity(com.battlelancer.seriesguide.ui.preferences.MoreOptionsActivity) R(com.battlelancer.seriesguide.R) Snackbar(com.google.android.material.snackbar.Snackbar) DataLiberationActivity(com.battlelancer.seriesguide.dataliberation.DataLiberationActivity) TextView(android.widget.TextView) Snackbar(com.google.android.material.snackbar.Snackbar)

Example 52 with Snackbar

use of com.google.android.material.snackbar.Snackbar in project AndroidUtilCode by Blankj.

the class SnackbarUtils method show.

/**
 * Show the snackbar.
 *
 * @param isShowTop True to show the snack bar on the top, false otherwise.
 */
public Snackbar show(boolean isShowTop) {
    View view = this.view;
    if (view == null)
        return null;
    if (isShowTop) {
        ViewGroup suitableParent = findSuitableParentCopyFromSnackbar(view);
        View topSnackBarContainer = suitableParent.findViewWithTag("topSnackBarCoordinatorLayout");
        if (topSnackBarContainer == null) {
            CoordinatorLayout topSnackBarCoordinatorLayout = new CoordinatorLayout(view.getContext());
            topSnackBarCoordinatorLayout.setTag("topSnackBarCoordinatorLayout");
            topSnackBarCoordinatorLayout.setRotation(180);
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                // bring to front
                topSnackBarCoordinatorLayout.setElevation(100);
            }
            suitableParent.addView(topSnackBarCoordinatorLayout, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
            topSnackBarContainer = topSnackBarCoordinatorLayout;
        }
        view = topSnackBarContainer;
    }
    if (messageColor != COLOR_DEFAULT) {
        SpannableString spannableString = new SpannableString(message);
        ForegroundColorSpan colorSpan = new ForegroundColorSpan(messageColor);
        spannableString.setSpan(colorSpan, 0, spannableString.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        sWeakSnackbar = new WeakReference<>(Snackbar.make(view, spannableString, duration));
    } else {
        sWeakSnackbar = new WeakReference<>(Snackbar.make(view, message, duration));
    }
    final Snackbar snackbar = sWeakSnackbar.get();
    final Snackbar.SnackbarLayout snackbarView = (Snackbar.SnackbarLayout) snackbar.getView();
    if (isShowTop) {
        for (int i = 0; i < snackbarView.getChildCount(); i++) {
            View child = snackbarView.getChildAt(i);
            child.setRotation(180);
        }
    }
    if (bgResource != -1) {
        snackbarView.setBackgroundResource(bgResource);
    } else if (bgColor != COLOR_DEFAULT) {
        snackbarView.setBackgroundColor(bgColor);
    }
    if (bottomMargin != 0) {
        ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) snackbarView.getLayoutParams();
        params.bottomMargin = bottomMargin;
    }
    if (actionText.length() > 0 && actionListener != null) {
        if (actionTextColor != COLOR_DEFAULT) {
            snackbar.setActionTextColor(actionTextColor);
        }
        snackbar.setAction(actionText, actionListener);
    }
    snackbar.show();
    return snackbar;
}
Also used : CoordinatorLayout(androidx.coordinatorlayout.widget.CoordinatorLayout) SpannableString(android.text.SpannableString) ForegroundColorSpan(android.text.style.ForegroundColorSpan) ViewGroup(android.view.ViewGroup) View(android.view.View) Snackbar(com.google.android.material.snackbar.Snackbar)

Example 53 with Snackbar

use of com.google.android.material.snackbar.Snackbar in project AndroidUtilCode by Blankj.

the class SnackbarUtils method addView.

/**
 * Add view to the snackbar.
 * <p>Call it after {@link #show()}</p>
 *
 * @param layoutId The id of layout.
 * @param params   The params.
 */
public static void addView(@LayoutRes final int layoutId, @NonNull final ViewGroup.LayoutParams params) {
    final View view = getView();
    if (view != null) {
        view.setPadding(0, 0, 0, 0);
        Snackbar.SnackbarLayout layout = (Snackbar.SnackbarLayout) view;
        View child = LayoutInflater.from(view.getContext()).inflate(layoutId, null);
        layout.addView(child, -1, params);
    }
}
Also used : View(android.view.View) Snackbar(com.google.android.material.snackbar.Snackbar)

Example 54 with Snackbar

use of com.google.android.material.snackbar.Snackbar in project MiMangaNu by raulhaag.

the class MainActivity method executeServerUpdates.

private void executeServerUpdates() {
    for (final ServerBase s : ServerBase.getServers(getApplicationContext())) {
        final String id = "server_version_" + s.getServerID();
        if (pm.getInt(id, 1) < s.getServerVersion()) {
            if (Database.getMangasCondition(getApplicationContext(), Database.COL_SERVER_ID + " = " + s.getServerID(), Database.COL_SERVER_ID, true).size() > 0) {
                String serverUpdateText = s.getServerName() + " " + getString(R.string.update_server_information);
                Snackbar snackbar = Snackbar.make(mainFragment.getView(), serverUpdateText, Snackbar.LENGTH_INDEFINITE);
                TextView textView = snackbar.getView().findViewById(com.google.android.material.R.id.snackbar_text);
                textView.setMaxLines(5);
                if (MainActivity.colors != null)
                    snackbar.getView().setBackgroundColor(MainActivity.colors[0]);
                snackbar.setAction(android.R.string.ok, new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                    }
                });
                snackbar.show();
                new Thread(new Runnable() {

                    @Override
                    public void run() {
                        if (s.updateServerVersion()) {
                            pm.edit().putInt(id, s.getServerVersion()).apply();
                            Util.getInstance().showTimeSnackBar(getString(R.string.server_update_process_finished), mainFragment.getView(), getApplicationContext(), Snackbar.LENGTH_INDEFINITE);
                        }
                    }
                }).start();
            } else {
                pm.edit().putInt(id, s.getServerVersion()).apply();
            }
        }
    }
}
Also used : ServerBase(ar.rulosoft.mimanganu.servers.ServerBase) TextView(android.widget.TextView) View(android.view.View) TextView(android.widget.TextView) Snackbar(com.google.android.material.snackbar.Snackbar)

Example 55 with Snackbar

use of com.google.android.material.snackbar.Snackbar in project MiMangaNu by raulhaag.

the class PreferencesFragment method restorePreferences.

private void restorePreferences() {
    File to = new File(getContext().getApplicationInfo().dataDir + "/shared_prefs/");
    String dir = prefs.getString("directorio", Environment.getExternalStorageDirectory().getAbsolutePath()) + "/MiMangaNu/shared_prefs_backup";
    File from = new File(dir);
    if (!from.exists()) {
        Snackbar snackbar = Snackbar.make(getView(), getText(R.string.backup_dont_found), Snackbar.LENGTH_LONG).setActionTextColor(Color.WHITE);
        if (MainActivity.colors != null)
            snackbar.getView().setBackgroundColor(MainActivity.colors[0]);
        snackbar.show();
    } else {
        Util.getInstance().deleteRecursive(to);
        to.mkdirs();
        if (from.list() != null && from.list().length == 0) {
            Util.getInstance().showFastSnackBar(getString(R.string.preferences_backup_not_found), getView(), getContext());
            return;
        }
        for (String f : from.list()) {
            try {
                File toFile = new File(to.getPath() + "/" + f);
                Util.getInstance().copyFile(new File(from.getPath() + "/" + f), toFile);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        Util.getInstance().restartApp(getContext());
    }
}
Also used : IOException(java.io.IOException) File(java.io.File) Snackbar(com.google.android.material.snackbar.Snackbar)

Aggregations

Snackbar (com.google.android.material.snackbar.Snackbar)110 View (android.view.View)61 Intent (android.content.Intent)46 TextView (android.widget.TextView)41 AlertDialog (androidx.appcompat.app.AlertDialog)29 Context (android.content.Context)28 ImageView (android.widget.ImageView)28 LayoutInflater (android.view.LayoutInflater)24 ArrayList (java.util.ArrayList)23 RecyclerView (androidx.recyclerview.widget.RecyclerView)22 Bundle (android.os.Bundle)20 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)20 DialogInterface (android.content.DialogInterface)19 List (java.util.List)19 CreateCardView (me.ccrama.redditslide.Views.CreateCardView)18 Submission (net.dean.jraw.models.Submission)18 SubredditView (me.ccrama.redditslide.Activities.SubredditView)17 ApiException (net.dean.jraw.ApiException)17 Activity (android.app.Activity)16 OnSingleClickListener (me.ccrama.redditslide.util.OnSingleClickListener)16