Example usage for android.widget Toast Toast

List of usage examples for android.widget Toast Toast

Introduction

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

Prototype

public Toast(Context context) 

Source Link

Document

Construct an empty Toast object.

Usage

From source file:cz.babi.android.remoteme.service.ConnectionService.java

/**
 * If server is unreachable we need to stop service and notice that to user.
 *//*  ww w . ja  v a 2s.  c  om*/
private void closeConnection() {
    if (Common.DEBUG)
        Log.d(TAG_CLASS_NAME, "[closeConnection]");

    if (clientSocket != null)
        try {
            clientSocket.close();
        } catch (IOException e) {
            if (Common.ERROR)
                Log.e(TAG_CLASS_NAME, "[stopService][Can not close client " + "socket.]");
        }

    ConnectionService.server = null;
    ConnectionService.clientSocket = null;
    ConnectionService.in = null;
    ConnectionService.out = null;
    ConnectionService.needEncryptedCommunication = false;

    LayoutInflater mInflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View toastLayout = mInflater.inflate(R.layout.toast_warning, null);

    TextView text = (TextView) toastLayout.findViewById(R.id.warning_text);
    text.setText(R.string.connection_service_connection_lost_text);

    Toast toast = new Toast(this);
    toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
    toast.setDuration(Toast.LENGTH_LONG);
    toast.setView(toastLayout);
    toast.show();

    disconnectWithError = true;
}

From source file:de.tudarmstadt.informatik.secuso.phishedu2.MainActivity.java

@Override
public void displayToastScore(int score) {
    LayoutInflater inflater = getLayoutInflater();
    View layout = inflater.inflate(R.layout.fragment_toast_score,
            (ViewGroup) findViewById(R.id.toast_layout_root));

    String scoreString = Integer.toString(score);

    TextView text = (TextView) layout.findViewById(R.id.text);
    if (score < 0) {
        // red//from  www . j  a v a 2 s.co  m
        text.setTextColor(Color.rgb(135, 0, 0));
    } else {
        // green
        text.setTextColor(Color.rgb(0, 135, 0));
        scoreString = "+ " + score;
    }

    text.setText(getString(R.string.scoreString, scoreString)); // scoreString + " Punkte"
    text.setTypeface(Typeface.DEFAULT_BOLD);
    Toast toast = new Toast(getApplicationContext());
    toast.setDuration(Toast.LENGTH_SHORT);
    toast.setView(layout);
    toast.show();
}

From source file:com.danielme.muspyforandroid.activities.base.AbstractActivity.java

private void showToast(int msgID, String msg, int duration) {
    Toast toast = new Toast(this);
    LayoutInflater inflater = getLayoutInflater();
    View layout = inflater.inflate(R.layout.toast_success, (ViewGroup) findViewById(R.id.lytLayout));

    TextView txtMsg = (TextView) layout.findViewById(R.id.toastMessage);

    if (msg == null) {
        txtMsg.setText(getString(msgID));
    } else {// w w w.  jav  a2 s .  c  o  m
        txtMsg.setText(msg);
    }
    toast.setDuration(duration);
    toast.setView(layout);
    toast.show();
}

From source file:com.example.android.test.app.DemoActivity.java

public void onClick(final View view) {

    /*if (view == findViewById(R.id.send)) {
    new AsyncTask<Void, Void, String>() {
        @Override//  w  w  w. ja va  2s.  c  o  m
        protected String doInBackground(Void... params) {
            String msg = "";
            try {
                Bundle data = new Bundle();
                data.putString("my_message", "Hello World");
                data.putString("my_action", "com.google.android.gcm.demo.app.ECHO_NOW");
                String id = Integer.toString(msgId.incrementAndGet());
                gcm.send(SENDER_ID + "@gcm.googleapis.com", id, data);
                msg = "Sent message";
            } catch (IOException ex) {
                msg = "Error :" + ex.getMessage();
            }
            return msg;
        }
            
        @Override
        protected void onPostExecute(String msg) {
            Toast toast = new Toast(DemoActivity.this);
            toast.makeText(DemoActivity.this, msg,Toast.LENGTH_SHORT).show();
        }
    }.execute(null, null, null);
    } else*/
    if (view == findViewById(R.id.clear)) {
        mDisplay.setText("");
        mNotificationAdapter.clear();
        Person.deleteAll(Person.class);
        Toast toast = new Toast(DemoActivity.this);
        toast.makeText(DemoActivity.this, "Cleared All Items", Toast.LENGTH_SHORT).show();

    }
}

From source file:com.sender.team.sender.gcm.MyGcmListenerService.java

private void sendToast(final ChattingReceiveData data, final ChattingReceiveMessage c) {
    handler.post(new Runnable() {
        @Override//  w  w w. j  a v a2s. c om
        public void run() {
            View view = LayoutInflater.from(getApplicationContext()).inflate(R.layout.toast_notify, null);
            ImageView imageProfile = (ImageView) view.findViewById(R.id.imageProfile);
            TextView textName = (TextView) view.findViewById(R.id.textName);
            TextView textMessage = (TextView) view.findViewById(R.id.textMessage);
            Glide.with(getApplicationContext()).load(data.getSender().getFileUrl()).into(imageProfile);
            if (!TextUtils.isEmpty(data.getSender().getName())) {
                textName.setText(data.getSender().getName());
            }
            if (!TextUtils.isEmpty(c.getMessage())) {
                textMessage.setText(c.getMessage());
            } else {
                textMessage.setText("");
            }

            Toast toast = new Toast(getApplicationContext());
            float dp = 65;
            int pixel = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp,
                    getResources().getDisplayMetrics());
            toast.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.TOP, 0, pixel);
            toast.setDuration(Toast.LENGTH_LONG);
            toast.setView(view);
            toast.show();
        }
    });
}

From source file:org.xingjitong.InCallActivity.java

private void toastdsp(String str) {

    LayoutInflater inflater = getLayoutInflater();
    //LayoutInflater inflater = LayoutInflater.from(getContext());
    View layout = inflater.inflate(R.layout.customtoast, (ViewGroup) findViewById(R.id.llcustomtoast));

    //ImageView image = (ImageView) layout.findViewById(R.id.customtoast_img);
    //image.setImageResource(R.drawable.status_green); //yypp

    TextView text = (TextView) layout.findViewById(R.id.customtoast_text);
    text.setText(str);/* w  w  w . j a v  a 2 s. com*/
    Toast toast = new Toast(getApplicationContext());
    //Toast toast = new Toast(getContext());
    toast.setGravity(Gravity.CENTER, 0, 60);
    //toast.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL, 0, 0);
    toast.setDuration(Toast.LENGTH_LONG);
    toast.setView(layout);
    toast.show();

}

From source file:org.wahtod.wififixer.utility.NotifUtil.java

public static void showToast(Context context, String message, int delay) {

    LayoutInflater inflater = (LayoutInflater) context.getSystemService(Service.LAYOUT_INFLATER_SERVICE);
    View layout = inflater.inflate(R.layout.toast, null);
    ImageView image = (ImageView) layout.findViewById(R.id.icon);
    image.setImageResource(R.drawable.icon);
    TextView text = (TextView) layout.findViewById(R.id.text);
    text.setText(message);/*from  w  w  w . j a  v  a  2  s. com*/
    Toast toast = new Toast(context.getApplicationContext());
    toast.setGravity(Gravity.BOTTOM | Gravity.CENTER, 0, 0);
    toast.setDuration(delay);
    toast.setView(layout);
    toast.show();

}

From source file:com.woodblockwithoutco.quickcontroldock.ui.ControlService.java

public void attachTemporaryView(Drawable icon, String appName) {
    LinearLayout l = new LinearLayout(getApplicationContext());
    l.setGravity(Gravity.CENTER_VERTICAL);
    l.setOrientation(LinearLayout.HORIZONTAL);
    l.setPadding(NOTIFICATION_TOAST_PADDING_PX, NOTIFICATION_TOAST_PADDING_PX, NOTIFICATION_TOAST_PADDING_PX,
            NOTIFICATION_TOAST_PADDING_PX);

    l.setBackgroundResource(R.drawable.notification_toast_bg);

    TextView tv = new TextView(getApplicationContext());
    tv.setGravity(Gravity.CENTER);/*from   www.j av  a2  s  . co  m*/
    tv.setCompoundDrawablePadding(COMPOUND_DRAWABLE_PADDING_PX);
    tv.setCompoundDrawablesWithIntrinsicBounds(icon, null, null, null);

    String notificationText = getString(R.string.notification_from) + "\n" + appName;
    tv.setText(notificationText);
    tv.setTextColor(COLOR_WHITE);

    l.addView(tv);

    Toast toast = new Toast(getApplicationContext());
    toast.setView(l);
    toast.show();
}

From source file:net.mypapit.mobile.callsignview.MainActivity.java

private void showToast(String message) {
    Context context = getApplicationContext();
    LayoutInflater inflater = getLayoutInflater();

    View customToastroot = inflater.inflate(R.layout.custom_toast, null);
    TextView tvToast = (TextView) customToastroot.findViewById(R.id.tvToast);
    tvToast.setText(message);/* w  w  w . j  a  va  2 s  .  c om*/

    Toast customtoast = new Toast(context);

    customtoast.setView(customToastroot);
    customtoast.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL, 0, 0);
    customtoast.setDuration(Toast.LENGTH_SHORT);
    customtoast.show();

}

From source file:com.scoreloop.android.coreui.BaseActivity.java

void showToast(final String message) {
    final View view = getLayoutInflater().inflate(R.layout.sl_dialog_custom, null);
    ((TextView) view.findViewById(R.id.message)).setText(message);
    final Toast toast = new Toast(getApplicationContext());
    toast.setDuration(Toast.LENGTH_SHORT);
    toast.setView(view);//from   w  ww  . jav  a  2  s . com
    toast.show();
}