Example usage for android.widget Toast setGravity

List of usage examples for android.widget Toast setGravity

Introduction

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

Prototype

public void setGravity(int gravity, int xOffset, int yOffset) 

Source Link

Document

Set the location at which the notification should appear on the screen.

Usage

From source file:com.android.mail.compose.ComposeActivity.java

private void showErrorToast(String message) {
    Toast t = Toast.makeText(this, message, Toast.LENGTH_LONG);
    t.setText(message);//from  ww  w  .  ja va2s  . c o m
    t.setGravity(Gravity.CENTER_HORIZONTAL, 0,
            getResources().getDimensionPixelSize(R.dimen.attachment_toast_yoffset));
    t.show();
}

From source file:cm.aptoide.pt.MainActivity.java

protected void addStore(String uri_str, String username, String password) {

    if (uri_str.contains("http//")) {
        uri_str = uri_str.replaceFirst("http//", "http://");
    }//from w  w w . j  a  va2s .co  m

    if (uri_str.length() != 0 && uri_str.charAt(uri_str.length() - 1) != '/') {
        uri_str = uri_str + '/';
        Log.d("Aptoide-ManageRepo", "repo uri: " + uri_str);
    }
    if (!uri_str.startsWith("http://")) {
        uri_str = "http://" + uri_str;
        Log.d("Aptoide-ManageRepo", "repo uri: " + uri_str);
    }
    if (username != null && username.contains("@")) {
        try {
            password = Algorithms.computeSHA1sum(password);
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
    }
    NetworkUtils utils = new NetworkUtils();
    final int response = utils.checkServerConnection(uri_str, username, password);
    final String uri = uri_str;
    switch (response) {
    case 0:
        service.addStore(db, uri, username, password);
        break;
    case 401:
        runOnUiThread(new Runnable() {

            @Override
            public void run() {

                showAddStoreCredentialsDialog(uri);
            }
        });

        break;
    case 404:
        runOnUiThread(new Runnable() {

            @Override
            public void run() {
                Toast toast = Toast.makeText(mContext, mContext.getString(R.string.verify_store),
                        Toast.LENGTH_SHORT);
                toast.show();
                showAddStoreDialog();
            }
        });
        break;
    case -1:
        runOnUiThread(new Runnable() {

            @Override
            public void run() {
                Toast toast = Toast.makeText(mContext, mContext.getString(R.string.an_error_check_net),
                        Toast.LENGTH_SHORT);
                toast.show();
                showAddStoreDialog();
            }
        });
        break;
    default:
        runOnUiThread(new Runnable() {

            @Override
            public void run() {
                Toast toast = Toast.makeText(mContext,
                        mContext.getString(R.string.error_occured) + " " + response, Toast.LENGTH_SHORT);
                toast.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL, 0, 30);
                toast.show();
                showAddStoreDialog();
            }
        });
        break;
    }

}

From source file:com.rfo.basic.Run.java

private Toast Toaster(CharSequence msg) { // default: short, high toast
    Toast toast = Toaster(msg, Toast.LENGTH_SHORT);
    toast.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL, 0, 50);
    return toast;
}