Example usage for android.widget Toast LENGTH_LONG

List of usage examples for android.widget Toast LENGTH_LONG

Introduction

In this page you can find the example usage for android.widget Toast LENGTH_LONG.

Prototype

int LENGTH_LONG

To view the source code for android.widget Toast LENGTH_LONG.

Click Source Link

Document

Show the view or text notification for a long period of time.

Usage

From source file:Main.java

/**
 * Toast dialog with string//from  www  .  j  a v  a2 s.c  o  m
 */
public static void showToast(final String message, final Context context) {
    final Toast toast = Toast.makeText(context, message, Toast.LENGTH_LONG);
    toast.setGravity(Gravity.BOTTOM, 0, 0);
    toast.show();
}

From source file:Main.java

private static void showErrorInternal(final Activity activity, final String errorMessage) {
    activity.runOnUiThread(new Runnable() {
        public void run() {
            Toast.makeText(activity, errorMessage, Toast.LENGTH_LONG).show();
        }//w w w.j  a  v a  2 s .  co m
    });
}

From source file:Main.java

/**
 * Create a backup of the database.//from  w  ww .  j  a  v a2 s. c o  m
 *
 * @param context who calls the function.
 * @param dbName  Name of the database to backup. (If empty, radiomap.db is used).
 */
public static void importDb(Context context, String dbName) {
    try {
        if (dbName.equals(""))
            dbName = "radiomap.db";

        File sd = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
        File data = Environment.getDataDirectory();

        if (sd.canWrite()) {
            String currentDBPath = "//data//" + context.getApplicationContext().getPackageName()
                    + "//databases//" + dbName;
            File backupDB = new File(data, currentDBPath);
            File currentDB = new File(sd, dbName);

            FileChannel src = new FileInputStream(currentDB).getChannel();
            FileChannel dst = new FileOutputStream(backupDB).getChannel();
            dst.transferFrom(src, 0, src.size());
            src.close();
            dst.close();

            Toast.makeText(context, "Datenbank von Downloads importiert!", Toast.LENGTH_LONG).show();
        }
    } catch (Exception e) {
        Log.e("Utils", e.getMessage());
        Toast.makeText(context, "Import fehlgeschlagen!", Toast.LENGTH_LONG).show();
    }
}

From source file:Main.java

/**
 * Create a backup of the database.//from   w  w w.  java  2 s  .  c  o  m
 *
 * @param context who calls the function.
 * @param dbName  Name of the database to backup. (If empty, radiomap.db is used).
 */
public static void exportDb(Context context, String dbName) {
    try {
        if (dbName.equals(""))
            dbName = "radiomap.db";

        File sd = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
        File data = Environment.getDataDirectory();

        if (sd.canWrite()) {
            String currentDBPath = "//data//" + context.getApplicationContext().getPackageName()
                    + "//databases//" + dbName;
            File currentDB = new File(data, currentDBPath);
            File backupDB = new File(sd, dbName);

            FileChannel src = new FileInputStream(currentDB).getChannel();
            FileChannel dst = new FileOutputStream(backupDB).getChannel();
            dst.transferFrom(src, 0, src.size());
            src.close();
            dst.close();

            Toast.makeText(context, "Datenbank nach Downloads exportiert!", Toast.LENGTH_LONG).show();
        }
    } catch (Exception e) {
        Log.e("Utils", e.getMessage());
        Toast.makeText(context, "Exportieren fehlgeschlagen!", Toast.LENGTH_LONG).show();
    }
}

From source file:Main.java

public static void toast(Context context, String message, boolean shortDuration) {
    if (toast == null) {
        toast = Toast.makeText(context, message, shortDuration ? Toast.LENGTH_SHORT : Toast.LENGTH_LONG);
        toast.setGravity(Gravity.CENTER, 0, 0);
    } else {/*from   www  . j a v a  2 s.co m*/
        toast.setText(message);
        toast.setDuration(shortDuration ? Toast.LENGTH_SHORT : Toast.LENGTH_LONG);
    }
    toast.show();
}

From source file:Main.java

public static void showSingleToast(Context ctx, String msg, int duration) {
    int showDuration = duration <= Toast.LENGTH_SHORT ? Toast.LENGTH_LONG : Toast.LENGTH_SHORT;
    if (null == toast) {
        toast = Toast.makeText(ctx.getApplicationContext(), msg, showDuration);
        toast.show();// ww  w  .  j  ava 2  s  . c  o  m
        oneTime = System.currentTimeMillis();
    } else {
        twoTime = System.currentTimeMillis();
        if (msg.equals(oldMsg)) {
            if (twoTime - oneTime > showDuration) {
                toast.show();
            }
        } else {
            oldMsg = msg;
            toast.setText(msg);
            toast.show();
        }
    }
    oneTime = twoTime;
}

From source file:Main.java

/**
 * Method for sending a text message to the sms-oracle
 * //from   w  w  w .j a  v a2 s  .c  o m
 * @param phoneNumber
 * @param message
 * @param context
 */
public static void sendSMS(String phoneNumber, String message, Context context) {

    SmsManager sms = SmsManager.getDefault();

    try {
        sms.sendTextMessage(phoneNumber, null, message, null, null);
    } catch (Exception e) {
        Toast.makeText(context, "Meding ikke sendt", Toast.LENGTH_LONG).show();
    }
}

From source file:Main.java

/**
 * Long toast message//from w  w w  .ja va 2  s.co m
 * (Predefined in AOS to 3500 ms = 3.5 sec)
 *
 * @param context Application Context
 * @param msg     Message to send
 */
public static void msgLong(final Context context, final String msg) {
    if (context != null && msg != null) {
        new Handler(context.getMainLooper()).post(new Runnable() {
            @Override
            public void run() {
                Toast.makeText(context, msg.trim(), Toast.LENGTH_LONG).show();
            }
        });
    }
}

From source file:Main.java

public static void addToCalendar(Activity context, Long beginTime, String title) {
    ContentResolver cr = context.getContentResolver();

    Uri.Builder builder = Uri.parse("content://com.android.calendar/instances/when").buildUpon();
    Long time = new Date(beginTime).getTime();
    ContentUris.appendId(builder, time - 10 * 60 * 1000);
    ContentUris.appendId(builder, time + 10 * 60 * 1000);

    String[] projection = new String[] { "title", "begin" };
    Cursor cursor = cr.query(builder.build(), projection, null, null, null);

    boolean exists = false;
    if (cursor != null) {
        while (cursor.moveToNext()) {
            if ((time == cursor.getLong(1)) && title.equals(cursor.getString(0))) {
                exists = true;/*  www.  j a  v a  2 s  . c o  m*/
            }
        }
    }

    if (!exists) {
        Intent intent = new Intent(Intent.ACTION_EDIT);
        intent.setType("vnd.android.cursor.item/event");
        intent.putExtra("beginTime", time);
        intent.putExtra("allDay", false);
        intent.putExtra("endTime", time + 60 * 60 * 1000);
        intent.putExtra("title", title);
        context.startActivity(intent);
    } else {
        Toast.makeText(context, "Event already exist!", Toast.LENGTH_LONG).show();
    }
}

From source file:Main.java

public static void saveDBInSdcard(Context pContext, String pDatabaseName) {
    try {//w  w  w  .j  ava  2 s .  c om
        File sd = Environment.getExternalStorageDirectory();
        File data = Environment.getDataDirectory();

        if (sd.canWrite()) {
            String currentDBPath = "//data//" + pContext.getPackageName() + "//databases//" + pDatabaseName;
            String backupDBPath = pDatabaseName;
            File currentDB = new File(data, currentDBPath);
            File backupDB = new File(sd, backupDBPath);

            FileChannel src = new FileInputStream(currentDB).getChannel();
            FileChannel dst = new FileOutputStream(backupDB).getChannel();
            dst.transferFrom(src, 0, src.size());
            src.close();
            dst.close();
            Toast.makeText(pContext, backupDB.toString(), Toast.LENGTH_LONG).show();
        }
    } catch (Exception e) {
        Toast.makeText(pContext, e.toString(), Toast.LENGTH_LONG).show();
    }
}