Example usage for android.widget Toast show

List of usage examples for android.widget Toast show

Introduction

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

Prototype

public void show() 

Source Link

Document

Show the view for the specified duration.

Usage

From source file:com.manning.androidhacks.hack016.MainActivity.java

public void upperLeft(View v) {
    Toast toast = Toast.makeText(this, "Upper Left!", Toast.LENGTH_SHORT);
    toast.setGravity(Gravity.TOP | Gravity.LEFT, 0, 0);
    toast.show();
}

From source file:com.manning.androidhacks.hack016.MainActivity.java

public void upperRight(View v) {
    Toast toast = Toast.makeText(this, "Upper Right!", Toast.LENGTH_SHORT);
    toast.setGravity(Gravity.TOP | Gravity.RIGHT, 0, 0);
    toast.show();
}

From source file:edu.cwru.apo.Contract.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.contract);/*from   www.  j a va 2 s  . c  o  m*/
    text = (TextView) findViewById(R.id.contractText);

    API api = new API(this);
    if (!api.callMethod(Methods.getContract, this, (String[]) null)) {
        Toast msg = Toast.makeText(getApplicationContext(), "Error: Calling getContract", Toast.LENGTH_LONG);
        msg.show();
    }
}

From source file:com.manning.androidhacks.hack016.MainActivity.java

public void bottomLeft(View v) {
    Toast toast = Toast.makeText(this, "Bottom Left!", Toast.LENGTH_SHORT);

    toast.setGravity(Gravity.BOTTOM | Gravity.LEFT, 0, 0);
    toast.show();
}

From source file:com.manning.androidhacks.hack016.MainActivity.java

public void bottomRight(View v) {
    Toast toast = Toast.makeText(this, "Bottom Right!", Toast.LENGTH_SHORT);
    toast.setGravity(Gravity.BOTTOM | Gravity.RIGHT, 0, 0);
    toast.show();
}

From source file:appathon.history.PickerActivity.java

private void onError(Exception error) {
    String text = "exception" + error.getMessage();
    Toast toast = Toast.makeText(this, text, Toast.LENGTH_SHORT);
    toast.show();
}

From source file:com.example.AllSOSservice.GcmBroadcastReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    // Explicitly specify that GcmIntentService will handle the intent.
    ComponentName comp = new ComponentName(context.getPackageName(), Activity.class.getName());
    // Start the service, keeping the device awake while it is launching.
    startWakefulService(context, (intent.setComponent(comp)));
    setResultCode(Activity.RESULT_OK);//from  w w  w. j  a  v  a  2  s. co m

    String message = intent.getStringExtra("message");
    String email = intent.getStringExtra("email");
    String latitude = intent.getStringExtra("latitude");
    String longitude = intent.getStringExtra("longitude");

    Toast toast = Toast.makeText(context, message, Toast.LENGTH_LONG);
    toast.show();

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
            .setSmallIcon(R.drawable.ic_launcher).setContentTitle("Novo Pedido de Ajuda!")
            .setContentText("Alguem precisa de um " + message);

    Intent resultIntent = null;
    try {
        if (isLoggedIn()) {
            resultIntent = new Intent(context, LoggedInActivity.class);
        } else {
            resultIntent = new Intent(context, LoginActivity.class);
        }
    } catch (InterruptedException e) {
        e.printStackTrace();
    } catch (ExecutionException e) {
        e.printStackTrace();
    } catch (TimeoutException e) {
        e.printStackTrace();
    } catch (JSONException e) {
        e.printStackTrace();
    }

    // Because clicking the notification opens a new ("special") activity, there's
    // no need to create an artificial back stack.
    PendingIntent resultPendingIntent = PendingIntent.getActivity(context, 0, resultIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    mBuilder.setContentIntent(resultPendingIntent);

    int mNotificationId = 001;
    // Gets an instance of the NotificationManager service
    NotificationManager mNotifyMgr = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    // Builds the notification and issues it.
    mNotifyMgr.notify(mNotificationId, mBuilder.build());
}

From source file:edu.cwru.apo.News.java

public void onRestRequestComplete(Methods method, JSONObject result) {
    if (method == Methods.checkCredentials) {
        if (result != null) {
            String requestStatus;
            try {
                requestStatus = result.getString("requestStatus");
                if (requestStatus.compareTo("valid") == 0) {
                    // put message here
                    Toast msg = Toast.makeText(getApplicationContext(), "Success!", Toast.LENGTH_LONG);
                    msg.show();
                } else {
                    Toast msg = Toast.makeText(getApplicationContext(), "Failure", Toast.LENGTH_LONG);
                    msg.show();//from  www  . ja  v  a  2 s  .  co  m
                }
            } catch (JSONException e) {
                // TODO Auto-generated catch block
                // put invalid JSON message here
                Toast msg = Toast.makeText(getApplicationContext(), "JSON Error: Invalid element",
                        Toast.LENGTH_LONG);
                msg.show();
                e.printStackTrace();
            }

        } else {
            Toast msg = Toast.makeText(getApplicationContext(), "Error: result is null", Toast.LENGTH_LONG);
            msg.show();
        }
    } else {
        Toast msg = Toast.makeText(getApplicationContext(), "Invalid method called", Toast.LENGTH_LONG);
        msg.show();
    }
}

From source file:edu.cwru.apo.News.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.news);/*from   w  w w  . j a va  2 s .co m*/
    text = (TextView) findViewById(R.id.newsText);

    API api = new API(this);
    if (!api.callMethod(Methods.checkCredentials, this, (String[]) null)) {
        Toast msg = Toast.makeText(getApplicationContext(), "Error: Calling checkCredentials",
                Toast.LENGTH_LONG);
        msg.show();
    }
}

From source file:eltharis.wsn.showIDActivity.java

private String executeGET(int id) throws Exception {
    HttpClient httpclient = new DefaultHttpClient(); //tutaj jest podobnie jak w showAllActivity
    HttpResponse response = httpclient//from w  w  w. java2  s . co  m
            .execute(new HttpGet("https://agile-depths-5530.herokuapp.com/usershow/" + Integer.toString(id)));
    StatusLine statusline = response.getStatusLine();
    Toast toast = Toast.makeText(getApplicationContext(),
            "HTTP Response: " + Integer.toString(statusline.getStatusCode()), Toast.LENGTH_LONG);
    toast.show();
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    response.getEntity().writeTo(out);
    String responseString = out.toString();
    out.close();
    return responseString;
}