use of com.android.launcher3.views.Snackbar in project android_packages_apps_Launcher3 by crdroidandroid.
the class Snackbar method show.
public static void show(BaseDraggingActivity activity, int labelStringResId, int actionStringResId, Runnable onDismissed, Runnable onActionClicked) {
closeOpenViews(activity, true, TYPE_SNACKBAR);
Snackbar snackbar = new Snackbar(activity, null);
// Set some properties here since inflated xml only contains the children.
snackbar.setOrientation(HORIZONTAL);
snackbar.setGravity(Gravity.CENTER_VERTICAL);
Resources res = activity.getResources();
snackbar.setElevation(res.getDimension(R.dimen.snackbar_elevation));
int padding = res.getDimensionPixelSize(R.dimen.snackbar_padding);
snackbar.setPadding(padding, padding, padding, padding);
snackbar.setBackgroundResource(R.drawable.round_rect_primary);
snackbar.mIsOpen = true;
BaseDragLayer dragLayer = activity.getDragLayer();
dragLayer.addView(snackbar);
DragLayer.LayoutParams params = (DragLayer.LayoutParams) snackbar.getLayoutParams();
params.gravity = Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM;
params.height = res.getDimensionPixelSize(R.dimen.snackbar_height);
int maxMarginLeftRight = res.getDimensionPixelSize(R.dimen.snackbar_max_margin_left_right);
int minMarginLeftRight = res.getDimensionPixelSize(R.dimen.snackbar_min_margin_left_right);
int marginBottom = res.getDimensionPixelSize(R.dimen.snackbar_margin_bottom);
Rect insets = activity.getDeviceProfile().getInsets();
int maxWidth = dragLayer.getWidth() - minMarginLeftRight * 2 - insets.left - insets.right;
int minWidth = dragLayer.getWidth() - maxMarginLeftRight * 2 - insets.left - insets.right;
params.width = minWidth;
params.setMargins(0, 0, 0, marginBottom + insets.bottom);
TextView labelView = snackbar.findViewById(R.id.label);
TextView actionView = snackbar.findViewById(R.id.action);
String labelText = res.getString(labelStringResId);
String actionText = res.getString(actionStringResId);
int totalContentWidth = (int) (labelView.getPaint().measureText(labelText) + actionView.getPaint().measureText(actionText)) + labelView.getPaddingRight() + labelView.getPaddingLeft() + actionView.getPaddingRight() + actionView.getPaddingLeft() + padding * 2;
if (totalContentWidth > params.width) {
// The text doesn't fit in our standard width so update width to accommodate.
if (totalContentWidth <= maxWidth) {
params.width = totalContentWidth;
} else {
// One line will be cut off, fallback to 2 lines and smaller font. (This should only
// happen in some languages if system display and font size are set to largest.)
int textHeight = res.getDimensionPixelSize(R.dimen.snackbar_content_height);
float textSizePx = res.getDimension(R.dimen.snackbar_min_text_size);
labelView.setLines(2);
labelView.getLayoutParams().height = textHeight * 2;
actionView.getLayoutParams().height = textHeight * 2;
labelView.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSizePx);
actionView.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSizePx);
params.height += textHeight;
params.width = maxWidth;
}
}
labelView.setText(labelText);
actionView.setText(actionText);
actionView.setOnClickListener(v -> {
if (onActionClicked != null) {
onActionClicked.run();
}
snackbar.mOnDismissed = null;
snackbar.close(true);
});
snackbar.mOnDismissed = onDismissed;
snackbar.setAlpha(0);
snackbar.setScaleX(0.8f);
snackbar.setScaleY(0.8f);
snackbar.animate().alpha(1f).withLayer().scaleX(1).scaleY(1).setDuration(SHOW_DURATION_MS).setInterpolator(Interpolators.ACCEL_DEACCEL).start();
int timeout = AccessibilityManagerCompat.getRecommendedTimeoutMillis(activity, TIMEOUT_DURATION_MS, FLAG_CONTENT_TEXT | FLAG_CONTENT_CONTROLS);
snackbar.postDelayed(() -> snackbar.close(true), timeout);
}
use of com.android.launcher3.views.Snackbar in project android_packages_apps_Trebuchet by LineageOS.
the class Snackbar method show.
public static void show(BaseDraggingActivity activity, int labelStringResId, int actionStringResId, Runnable onDismissed, Runnable onActionClicked) {
closeOpenViews(activity, true, TYPE_SNACKBAR);
Snackbar snackbar = new Snackbar(activity, null);
// Set some properties here since inflated xml only contains the children.
snackbar.setOrientation(HORIZONTAL);
snackbar.setGravity(Gravity.CENTER_VERTICAL);
Resources res = activity.getResources();
snackbar.setElevation(res.getDimension(R.dimen.snackbar_elevation));
int padding = res.getDimensionPixelSize(R.dimen.snackbar_padding);
snackbar.setPadding(padding, padding, padding, padding);
snackbar.setBackgroundResource(R.drawable.round_rect_primary);
snackbar.mIsOpen = true;
BaseDragLayer dragLayer = activity.getDragLayer();
dragLayer.addView(snackbar);
DragLayer.LayoutParams params = (DragLayer.LayoutParams) snackbar.getLayoutParams();
params.gravity = Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM;
params.height = res.getDimensionPixelSize(R.dimen.snackbar_height);
int maxMarginLeftRight = res.getDimensionPixelSize(R.dimen.snackbar_max_margin_left_right);
int minMarginLeftRight = res.getDimensionPixelSize(R.dimen.snackbar_min_margin_left_right);
int marginBottom = res.getDimensionPixelSize(R.dimen.snackbar_margin_bottom);
Rect insets = activity.getDeviceProfile().getInsets();
int maxWidth = dragLayer.getWidth() - minMarginLeftRight * 2 - insets.left - insets.right;
int minWidth = dragLayer.getWidth() - maxMarginLeftRight * 2 - insets.left - insets.right;
params.width = minWidth;
params.setMargins(0, 0, 0, marginBottom + insets.bottom);
TextView labelView = snackbar.findViewById(R.id.label);
TextView actionView = snackbar.findViewById(R.id.action);
String labelText = res.getString(labelStringResId);
String actionText = res.getString(actionStringResId);
int totalContentWidth = (int) (labelView.getPaint().measureText(labelText) + actionView.getPaint().measureText(actionText)) + labelView.getPaddingRight() + labelView.getPaddingLeft() + actionView.getPaddingRight() + actionView.getPaddingLeft() + padding * 2;
if (totalContentWidth > params.width) {
// The text doesn't fit in our standard width so update width to accommodate.
if (totalContentWidth <= maxWidth) {
params.width = totalContentWidth;
} else {
// One line will be cut off, fallback to 2 lines and smaller font. (This should only
// happen in some languages if system display and font size are set to largest.)
int textHeight = res.getDimensionPixelSize(R.dimen.snackbar_content_height);
float textSizePx = res.getDimension(R.dimen.snackbar_min_text_size);
labelView.setLines(2);
labelView.getLayoutParams().height = textHeight * 2;
actionView.getLayoutParams().height = textHeight * 2;
labelView.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSizePx);
actionView.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSizePx);
params.height += textHeight;
params.width = maxWidth;
}
}
labelView.setText(labelText);
actionView.setText(actionText);
actionView.setOnClickListener(v -> {
if (onActionClicked != null) {
onActionClicked.run();
}
snackbar.mOnDismissed = null;
snackbar.close(true);
});
snackbar.mOnDismissed = onDismissed;
snackbar.setAlpha(0);
snackbar.setScaleX(0.8f);
snackbar.setScaleY(0.8f);
snackbar.animate().alpha(1f).withLayer().scaleX(1).scaleY(1).setDuration(SHOW_DURATION_MS).setInterpolator(Interpolators.ACCEL_DEACCEL).start();
int timeout = AccessibilityManagerCompat.getRecommendedTimeoutMillis(activity, TIMEOUT_DURATION_MS, FLAG_CONTENT_TEXT | FLAG_CONTENT_CONTROLS);
snackbar.postDelayed(() -> snackbar.close(true), timeout);
}
use of com.android.launcher3.views.Snackbar in project Neo-Launcher by NeoApplications.
the class Snackbar method show.
public static void show(Launcher launcher, int labelStringResId, int actionStringResId, Runnable onDismissed, Runnable onActionClicked) {
closeOpenViews(launcher, true, TYPE_SNACKBAR);
Snackbar snackbar = new Snackbar(launcher, null);
// Set some properties here since inflated xml only contains the children.
snackbar.setOrientation(HORIZONTAL);
snackbar.setGravity(Gravity.CENTER_VERTICAL);
Resources res = launcher.getResources();
snackbar.setElevation(res.getDimension(R.dimen.snackbar_elevation));
int padding = res.getDimensionPixelSize(R.dimen.snackbar_padding);
snackbar.setPadding(padding, padding, padding, padding);
snackbar.setBackgroundResource(R.drawable.round_rect_primary);
snackbar.mIsOpen = true;
DragLayer dragLayer = launcher.getDragLayer();
dragLayer.addView(snackbar);
DragLayer.LayoutParams params = (DragLayer.LayoutParams) snackbar.getLayoutParams();
params.gravity = Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM;
params.height = res.getDimensionPixelSize(R.dimen.snackbar_height);
int maxMarginLeftRight = res.getDimensionPixelSize(R.dimen.snackbar_max_margin_left_right);
int minMarginLeftRight = res.getDimensionPixelSize(R.dimen.snackbar_min_margin_left_right);
int marginBottom = res.getDimensionPixelSize(R.dimen.snackbar_margin_bottom);
Rect insets = launcher.getDeviceProfile().getInsets();
int maxWidth = dragLayer.getWidth() - minMarginLeftRight * 2 - insets.left - insets.right;
int minWidth = dragLayer.getWidth() - maxMarginLeftRight * 2 - insets.left - insets.right;
params.width = minWidth;
params.setMargins(0, 0, 0, marginBottom + insets.bottom);
TextView labelView = snackbar.findViewById(R.id.label);
TextView actionView = snackbar.findViewById(R.id.action);
String labelText = res.getString(labelStringResId);
String actionText = res.getString(actionStringResId);
int totalContentWidth = (int) (labelView.getPaint().measureText(labelText) + actionView.getPaint().measureText(actionText)) + labelView.getPaddingRight() + labelView.getPaddingLeft() + actionView.getPaddingRight() + actionView.getPaddingLeft() + padding * 2;
if (totalContentWidth > params.width) {
// The text doesn't fit in our standard width so update width to accommodate.
if (totalContentWidth <= maxWidth) {
params.width = totalContentWidth;
} else {
// One line will be cut off, fallback to 2 lines and smaller font. (This should only
// happen in some languages if system display and font size are set to largest.)
int textHeight = res.getDimensionPixelSize(R.dimen.snackbar_content_height);
float textSizePx = res.getDimension(R.dimen.snackbar_min_text_size);
labelView.setLines(2);
labelView.getLayoutParams().height = textHeight * 2;
actionView.getLayoutParams().height = textHeight * 2;
labelView.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSizePx);
actionView.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSizePx);
params.height += textHeight;
params.width = maxWidth;
}
}
labelView.setText(labelText);
actionView.setText(actionText);
actionView.setOnClickListener(v -> {
if (onActionClicked != null) {
onActionClicked.run();
}
snackbar.mOnDismissed = null;
snackbar.close(true);
});
snackbar.mOnDismissed = onDismissed;
snackbar.setAlpha(0);
snackbar.setScaleX(0.8f);
snackbar.setScaleY(0.8f);
snackbar.animate().alpha(1f).withLayer().scaleX(1).scaleY(1).setDuration(SHOW_DURATION_MS).setInterpolator(Interpolators.ACCEL_DEACCEL).start();
int timeout = AccessibilityManagerCompat.getRecommendedTimeoutMillis(launcher, TIMEOUT_DURATION_MS, FLAG_CONTENT_TEXT | FLAG_CONTENT_CONTROLS);
snackbar.postDelayed(() -> snackbar.close(true), timeout);
}
use of com.android.launcher3.views.Snackbar in project android_packages_apps_Launcher3 by ArrowOS.
the class Snackbar method show.
/**
* Show a snackbar with a label and action.
*/
public static <T extends Context & ActivityContext> void show(T activity, int labelStringResId, int actionStringResId, Runnable onDismissed, @Nullable Runnable onActionClicked) {
closeOpenViews(activity, true, TYPE_SNACKBAR);
Snackbar snackbar = new Snackbar(activity, null);
// Set some properties here since inflated xml only contains the children.
snackbar.setOrientation(HORIZONTAL);
snackbar.setGravity(Gravity.CENTER_VERTICAL);
Resources res = activity.getResources();
snackbar.setElevation(res.getDimension(R.dimen.snackbar_elevation));
int padding = res.getDimensionPixelSize(R.dimen.snackbar_padding);
snackbar.setPadding(padding, padding, padding, padding);
snackbar.setBackgroundResource(R.drawable.round_rect_primary);
snackbar.mIsOpen = true;
BaseDragLayer dragLayer = activity.getDragLayer();
dragLayer.addView(snackbar);
DragLayer.LayoutParams params = (DragLayer.LayoutParams) snackbar.getLayoutParams();
params.gravity = Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM;
params.height = res.getDimensionPixelSize(R.dimen.snackbar_height);
int maxMarginLeftRight = res.getDimensionPixelSize(R.dimen.snackbar_max_margin_left_right);
int minMarginLeftRight = res.getDimensionPixelSize(R.dimen.snackbar_min_margin_left_right);
int marginBottom = res.getDimensionPixelSize(R.dimen.snackbar_margin_bottom);
int absoluteMaxWidth = res.getDimensionPixelSize(R.dimen.snackbar_max_width);
Rect insets = activity.getDeviceProfile().getInsets();
int maxWidth = Math.min(dragLayer.getWidth() - minMarginLeftRight * 2 - insets.left - insets.right, absoluteMaxWidth);
int minWidth = Math.min(dragLayer.getWidth() - maxMarginLeftRight * 2 - insets.left - insets.right, absoluteMaxWidth);
params.width = minWidth;
params.setMargins(0, 0, 0, marginBottom + insets.bottom);
TextView labelView = snackbar.findViewById(R.id.label);
String labelText = res.getString(labelStringResId);
labelView.setText(labelText);
TextView actionView = snackbar.findViewById(R.id.action);
float actionWidth;
if (actionStringResId != NO_ID) {
String actionText = res.getString(actionStringResId);
actionWidth = actionView.getPaint().measureText(actionText) + actionView.getPaddingRight() + actionView.getPaddingLeft();
actionView.setText(actionText);
actionView.setOnClickListener(v -> {
if (onActionClicked != null) {
onActionClicked.run();
}
snackbar.mOnDismissed = null;
snackbar.close(true);
});
} else {
actionWidth = 0;
actionView.setVisibility(GONE);
}
int totalContentWidth = (int) (labelView.getPaint().measureText(labelText) + actionWidth) + labelView.getPaddingRight() + labelView.getPaddingLeft() + padding * 2;
if (totalContentWidth > params.width) {
// The text doesn't fit in our standard width so update width to accommodate.
if (totalContentWidth <= maxWidth) {
params.width = totalContentWidth;
} else {
// One line will be cut off, fallback to 2 lines and smaller font. (This should only
// happen in some languages if system display and font size are set to largest.)
int textHeight = res.getDimensionPixelSize(R.dimen.snackbar_content_height);
float textSizePx = res.getDimension(R.dimen.snackbar_min_text_size);
labelView.setLines(2);
labelView.getLayoutParams().height = textHeight * 2;
actionView.getLayoutParams().height = textHeight * 2;
labelView.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSizePx);
actionView.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSizePx);
params.height += textHeight;
params.width = maxWidth;
}
}
snackbar.mOnDismissed = onDismissed;
snackbar.setAlpha(0);
snackbar.setScaleX(0.8f);
snackbar.setScaleY(0.8f);
snackbar.animate().alpha(1f).withLayer().scaleX(1).scaleY(1).setDuration(SHOW_DURATION_MS).setInterpolator(Interpolators.ACCEL_DEACCEL).start();
int timeout = AccessibilityManagerCompat.getRecommendedTimeoutMillis(activity, TIMEOUT_DURATION_MS, FLAG_CONTENT_TEXT | FLAG_CONTENT_CONTROLS);
snackbar.postDelayed(() -> snackbar.close(true), timeout);
}
use of com.android.launcher3.views.Snackbar in project android_packages_apps_404Launcher by P-404.
the class Snackbar method show.
/**
* Show a snackbar with a label and action.
*/
public static <T extends Context & ActivityContext> void show(T activity, int labelStringResId, int actionStringResId, Runnable onDismissed, @Nullable Runnable onActionClicked) {
closeOpenViews(activity, true, TYPE_SNACKBAR);
Snackbar snackbar = new Snackbar(activity, null);
// Set some properties here since inflated xml only contains the children.
snackbar.setOrientation(HORIZONTAL);
snackbar.setGravity(Gravity.CENTER_VERTICAL);
Resources res = activity.getResources();
snackbar.setElevation(res.getDimension(R.dimen.snackbar_elevation));
int padding = res.getDimensionPixelSize(R.dimen.snackbar_padding);
snackbar.setPadding(padding, padding, padding, padding);
snackbar.setBackgroundResource(R.drawable.round_rect_primary);
snackbar.mIsOpen = true;
BaseDragLayer dragLayer = activity.getDragLayer();
dragLayer.addView(snackbar);
DragLayer.LayoutParams params = (DragLayer.LayoutParams) snackbar.getLayoutParams();
params.gravity = Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM;
params.height = res.getDimensionPixelSize(R.dimen.snackbar_height);
int maxMarginLeftRight = res.getDimensionPixelSize(R.dimen.snackbar_max_margin_left_right);
int minMarginLeftRight = res.getDimensionPixelSize(R.dimen.snackbar_min_margin_left_right);
int marginBottom = res.getDimensionPixelSize(R.dimen.snackbar_margin_bottom);
int absoluteMaxWidth = res.getDimensionPixelSize(R.dimen.snackbar_max_width);
Rect insets = activity.getDeviceProfile().getInsets();
int maxWidth = Math.min(dragLayer.getWidth() - minMarginLeftRight * 2 - insets.left - insets.right, absoluteMaxWidth);
int minWidth = Math.min(dragLayer.getWidth() - maxMarginLeftRight * 2 - insets.left - insets.right, absoluteMaxWidth);
params.width = minWidth;
params.setMargins(0, 0, 0, marginBottom + insets.bottom);
TextView labelView = snackbar.findViewById(R.id.label);
String labelText = res.getString(labelStringResId);
labelView.setText(labelText);
TextView actionView = snackbar.findViewById(R.id.action);
float actionWidth;
if (actionStringResId != NO_ID) {
String actionText = res.getString(actionStringResId);
actionWidth = actionView.getPaint().measureText(actionText) + actionView.getPaddingRight() + actionView.getPaddingLeft();
actionView.setText(actionText);
actionView.setOnClickListener(v -> {
if (onActionClicked != null) {
onActionClicked.run();
}
snackbar.mOnDismissed = null;
snackbar.close(true);
});
} else {
actionWidth = 0;
actionView.setVisibility(GONE);
}
int totalContentWidth = (int) (labelView.getPaint().measureText(labelText) + actionWidth) + labelView.getPaddingRight() + labelView.getPaddingLeft() + padding * 2;
if (totalContentWidth > params.width) {
// The text doesn't fit in our standard width so update width to accommodate.
if (totalContentWidth <= maxWidth) {
params.width = totalContentWidth;
} else {
// One line will be cut off, fallback to 2 lines and smaller font. (This should only
// happen in some languages if system display and font size are set to largest.)
int textHeight = res.getDimensionPixelSize(R.dimen.snackbar_content_height);
float textSizePx = res.getDimension(R.dimen.snackbar_min_text_size);
labelView.setLines(2);
labelView.getLayoutParams().height = textHeight * 2;
actionView.getLayoutParams().height = textHeight * 2;
labelView.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSizePx);
actionView.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSizePx);
params.height += textHeight;
params.width = maxWidth;
}
}
snackbar.mOnDismissed = onDismissed;
snackbar.setAlpha(0);
snackbar.setScaleX(0.8f);
snackbar.setScaleY(0.8f);
snackbar.animate().alpha(1f).withLayer().scaleX(1).scaleY(1).setDuration(SHOW_DURATION_MS).setInterpolator(Interpolators.ACCEL_DEACCEL).start();
int timeout = AccessibilityManagerCompat.getRecommendedTimeoutMillis(activity, TIMEOUT_DURATION_MS, FLAG_CONTENT_TEXT | FLAG_CONTENT_CONTROLS);
snackbar.postDelayed(() -> snackbar.close(true), timeout);
}