use of android.widget.Toast in project frostwire by frostwire.
the class ApolloUtils method showCheatSheet.
/**
* Display a {@link Toast} letting the user know what an item does when long
* pressed.
*
* @param view The {@link View} to copy the content description from.
*/
public static void showCheatSheet(final View view) {
// origin is device display
final int[] screenPos = new int[2];
// includes decorations (e.g.
final Rect displayFrame = new Rect();
// status bar)
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) (48 * context.getResources().getDisplayMetrics().density);
final Toast cheatSheet = Toast.makeText(context, view.getContentDescription(), Toast.LENGTH_SHORT);
final 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
cheatSheet.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, viewCenterX - screenWidth / 2, displayFrame.bottom - screenPos[1]);
}
cheatSheet.show();
}
use of android.widget.Toast in project AndroidUtilLib by SiberiaDante.
the class SDToastUtil method custom.
@CheckResult
public static Toast custom(@NonNull Context context, @NonNull String message, Drawable icon, @ColorInt int textColor, @ColorInt int tintColor, int duration, boolean withIcon, boolean shouldTint) {
if (currentToast == null) {
currentToast = new Toast(context);
}
final View toastLayout = ((LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.sd_toast_layout, null);
final ImageView toastIcon = (ImageView) toastLayout.findViewById(R.id.toast_icon);
final TextView toastTextView = (TextView) toastLayout.findViewById(R.id.toast_text);
Drawable drawableFrame;
if (shouldTint) {
drawableFrame = tint9PatchDrawableFrame(context, tintColor);
} else {
drawableFrame = getDrawable(R.drawable.toast_frame);
}
setBackground(toastLayout, drawableFrame);
if (withIcon) {
if (icon == null) {
throw new IllegalArgumentException("Avoid passing 'icon' as null if 'withIcon' is set to true");
} else {
setBackground(toastIcon, icon);
}
} else {
toastIcon.setVisibility(View.GONE);
}
toastTextView.setTextColor(textColor);
toastTextView.setText(message);
toastTextView.setTypeface(Typeface.create(TOAST_TYPEFACE, Typeface.NORMAL));
currentToast.setView(toastLayout);
currentToast.setDuration(duration);
return currentToast;
}
use of android.widget.Toast in project AdMoney by ErnestoGonAr.
the class Reporte_Ingresos method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
try {
initData();
} catch (NullPointerException e) {
Toast toast = Toast.makeText(this, "No hay Ingresos", Toast.LENGTH_SHORT);
toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
toast.show();
return;
}
setContentView(R.layout.activity_reporte__ingresos);
pieChart = (PieChart) findViewById(R.id.grafico_ingresos);
pieChart.setRotationEnabled(true);
pieChart.setHoleRadius(30f);
pieChart.setCenterTextSize(10);
pieChart.setTransparentCircleAlpha(0);
Description d = pieChart.getDescription();
d.setText("");
pieChart.setDescription(d);
pieChart.getLegend().setOrientation(Legend.LegendOrientation.VERTICAL);
pieChart.setEntryLabelTextSize(4);
pieChart.getLegend().setTextSize(12);
pieChart.getLegend().setPosition(Legend.LegendPosition.LEFT_OF_CHART);
if (xData.length == 0)
return;
addData();
pieChart.setOnChartValueSelectedListener(new OnChartValueSelectedListener() {
@Override
public void onValueSelected(Entry e, Highlight h) {
Log.d(TAG, "onValueSelected: Value selected from chart");
Log.d(TAG, e.toString());
Log.d(TAG, h.toString());
int pos1 = e.toString().indexOf("Entry, x: 0.0 y: ");
String res = e.toString().substring(pos1 + 17);
for (int i = 0; i < yData.length; i++) {
if (yData[i] == Float.parseFloat(res)) {
pos1 = i;
break;
}
}
String categoria = xData[pos1];
Toast.makeText(Reporte_Ingresos.this, "Ha obtenido $" + res + " en ingresos\n" + "por " + categoria, Toast.LENGTH_LONG).show();
}
@Override
public void onNothingSelected() {
}
});
spinner = (Spinner) findViewById(R.id.spinner_r_ingresos);
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
calendar.setText("Selecciona una fecha");
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
año = 2017;
mes = 5;
diad = 17;
calendar = (EditText) findViewById(R.id.fecha_r_ingresos);
calendar.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
// To show current date in the datepicker
final Calendar mcurrentDate = Calendar.getInstance();
mYear = mcurrentDate.get(Calendar.YEAR);
mMonth = mcurrentDate.get(Calendar.MONTH);
mDay = mcurrentDate.get(Calendar.DAY_OF_MONTH);
DatePickerDialog mDatePicker = new DatePickerDialog(Reporte_Ingresos.this, new DatePickerDialog.OnDateSetListener() {
public void onDateSet(DatePicker datepicker, int selectedyear, int selectedmonth, int selectedday) {
// TODO Auto-generated method stub
año = selectedyear;
mes = selectedmonth + 1;
diad = selectedday;
calendar.setText(selectedyear + "-" + (selectedmonth + 1) + "-" + selectedday);
}
}, mYear, mMonth, mDay);
mDatePicker.setTitle("Selecciona fecha");
mDatePicker.show();
}
});
consultar = (Button) findViewById(R.id.consultar);
consultar.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (calendar.getText().toString().equals("Selecciona una fecha")) {
calendar.requestFocus();
calendar.callOnClick();
return;
}
String[][] data;
switch(spinner.getSelectedItemPosition()) {
case 1:
data = bd.obtenerIngresos(diad + "", mes + "", año + "");
if (data == null) {
Toast toast = Toast.makeText(getApplicationContext(), "No hay registros para esta fecha", Toast.LENGTH_SHORT);
toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
toast.show();
pieChart.setVisibility(View.INVISIBLE);
break;
}
pieChart.clear();
initData(data);
addData();
pieChart.setVisibility(View.VISIBLE);
break;
case 2:
data = bd.obtenerIngresos(mes + "", año + "");
if (data == null) {
Toast toast = Toast.makeText(getApplicationContext(), "No hay registros para esta fecha", Toast.LENGTH_SHORT);
toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
toast.show();
pieChart.setVisibility(View.INVISIBLE);
break;
}
pieChart.clear();
initData(data);
addData();
pieChart.setVisibility(View.VISIBLE);
break;
case 3:
data = bd.obtenerIngresos(año + "");
if (data == null) {
Toast toast = Toast.makeText(getApplicationContext(), "No hay registros para esta fecha", Toast.LENGTH_SHORT);
toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
toast.show();
pieChart.setVisibility(View.INVISIBLE);
break;
}
pieChart.clear();
initData(data);
addData();
pieChart.setVisibility(View.VISIBLE);
break;
default:
pieChart.clear();
initData();
addData();
pieChart.setVisibility(View.VISIBLE);
break;
}
}
});
}
use of android.widget.Toast in project AdMoney by ErnestoGonAr.
the class Detalle_CategoriasIngreso method updatear.
private void updatear(String b) {
if (!validarNoRep(a, validartexto)) {
Toast toast = Toast.makeText(this, "Una categoria con el nombre, ya se ha insertado", Toast.LENGTH_SHORT);
toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
toast.show();
return;
}
if (validartexto.equals("")) {
Toast toast = Toast.makeText(this, "Escribe nombre de Categoria", Toast.LENGTH_SHORT);
toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
toast.show();
return;
}
if (b.equals("Deudas")) {
Toast toast = Toast.makeText(this, "No puedes modificar Deudas", Toast.LENGTH_SHORT);
toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
toast.show();
return;
}
bandera = true;
// bd.updateCategoriasE(mtexto.getText().toString(),itemaux.nombre);
}
use of android.widget.Toast in project MVP by yuchengren.
the class ToastHelper method initToast.
/**
* 初始化Toast的自定义布局,显示位置等
* @param message
*/
private static void initToast(String message) {
View view = View.inflate(MvpApplication.getInstance(), R.layout.toast, null);
TextView tv_toast = (TextView) view.findViewById(R.id.tv_toast);
int h = MvpApplication.getInstance().getResources().getDisplayMetrics().heightPixels;
int l = MvpApplication.getInstance().getResources().getDisplayMetrics().widthPixels;
tv_toast.setMinWidth(l / 4);
tv_toast.setText(message);
mToast = new Toast(MvpApplication.getInstance());
mToast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
mToast.setView(view);
}
Aggregations