Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import android.content.Context;
import android.util.DisplayMetrics;
import android.view.Gravity;
import android.widget.Toast;

public class Main {
    public static void longToast(int string, Context ctx) {
        Toast t = new Toast(ctx).makeText(ctx, string, Toast.LENGTH_LONG);
        t.setGravity(Gravity.TOP, 0, dpToPx(55, ctx));
        t.show();
    }

    public static int dpToPx(int dp, Context ctx) {
        DisplayMetrics displayMetrics = ctx.getResources().getDisplayMetrics();
        int px = Math.round(dp * (displayMetrics.xdpi / DisplayMetrics.DENSITY_DEFAULT));
        return px;
    }
}