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;
}
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;
}
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);
}
}
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();
}
}
}
}
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());
}
}
Aggregations