Example usage for android.widget Toast LENGTH_SHORT

List of usage examples for android.widget Toast LENGTH_SHORT

Introduction

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

Prototype

int LENGTH_SHORT

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

Click Source Link

Document

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

Usage

From source file:es.udc.robotcontrol.testapp.comunication.RobotCommController.java

public RobotCommController(Context ctx) {
    this.ctx = ctx;
    Log.i(Constantes.TAG_SERVICIO, "Servicio robot creado");
    comandos = new ConcurrentLinkedQueue<Comando>();
    setReadSleepTime(1000);//from ww w . j ava2s  .c  o m
    setWriteSleepTime(1000);
    Toast.makeText(ctx, R.string.robot_service_created, Toast.LENGTH_SHORT).show();
}

From source file:com.tinyhydra.botd.GoogleOperations.java

public static List<JavaShop> GetShops(Handler handler, Location currentLocation, String placesApiKey) {
    // Use google places to get all the shops within '500' (I believe meters is the default measurement they use)
    // make a list of JavaShops and pass it to the ListView adapter
    List<JavaShop> shopList = new ArrayList<JavaShop>();
    try {// ww  w .j a v  a 2s  .  co  m
        HttpClient client = new DefaultHttpClient();
        HttpGet request = new HttpGet();
        int accuracy = Math.round(currentLocation.getAccuracy());
        if (accuracy < 500)
            accuracy = 500;
        request.setURI(URI.create("https://maps.googleapis.com/maps/api/place/search/json?location="
                + currentLocation.getLatitude() + "," + currentLocation.getLongitude() + "&radius=" + accuracy
                + "&types=" + URLEncoder.encode("cafe|restaurant|food", "UTF-8")
                + "&keyword=coffee&sensor=true&key=" + placesApiKey));
        HttpResponse response = client.execute(request);
        BufferedReader in = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
        StringBuffer sb = new StringBuffer("");
        String line = "";
        while ((line = in.readLine()) != null) {
            sb.append(line);
        }

        JSONObject predictions = new JSONObject(sb.toString());
        // Google passes back a status string. if we screw up, it won't say "OK". Alert the user.
        String jstatus = predictions.getString("status");
        if (jstatus.equals("ZERO_RESULTS")) {
            Utils.PostToastMessageToHandler(handler, "No shops found in your area.", Toast.LENGTH_SHORT);
            return shopList;
        } else if (!jstatus.equals("OK")) {
            Utils.PostToastMessageToHandler(handler, "Error retrieving local shops.", Toast.LENGTH_SHORT);
            return shopList;
        }

        // This section may fail if there's no results, but we'll just display an empty list.
        //TODO: alert the user and cancel the dialog if this fails
        JSONArray ja = new JSONArray(predictions.getString("results"));

        for (int i = 0; i < ja.length(); i++) {
            JSONObject jo = (JSONObject) ja.get(i);
            shopList.add(new JavaShop(jo.getString("name"), jo.getString("id"), "", jo.getString("reference"),
                    jo.getString("vicinity")));
        }
    } catch (MalformedURLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return shopList;
}

From source file:com.futureplatforms.kirin.demo.hellokirin.activity.DumbListActivity.java

public void showToast(String key) {
    Toast.makeText(this, "You clicked on: " + key, Toast.LENGTH_SHORT).show();
}

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

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);//from w  w w.  j a v  a 2 s  .c o  m

    mTextView = (TextView) findViewById(R.id.my_text_view);

    mTextView.post(new Runnable() {

        @Override
        public void run() {
            String size = String.format("TextView's width: %d, height: %d", mTextView.getWidth(),
                    mTextView.getHeight());
            Toast.makeText(MainActivity.this, size, Toast.LENGTH_SHORT).show();

        }
    });
}

From source file:com.longle1.facedetection.TimedAsyncHttpResponseHandler.java

@Override
public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) {
    Log.e("RTT", String.format("%.1f", (System.nanoTime() - startTime) / 1e6) + " ms");
    String msg = "RTT: " + String.format("%.1f", (System.nanoTime() - startTime) / 1e6) + " ms";
    Toast mToast = Toast.makeText(mContext, msg, Toast.LENGTH_SHORT);
    mToast.setGravity(Gravity.TOP, 0, 0);
    TextView v = (TextView) mToast.getView().findViewById(android.R.id.message);
    v.setTextColor(Color.RED);//from w  w  w . jav  a  2 s .com
    mToast.show();
}

From source file:MainActivity.java

public void doSomething(View view) {
    if (!checkPermission(Manifest.permission.SEND_SMS)) {
        if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.SEND_SMS)) {
            showExplanation("Permission Needed", "Rationale", Manifest.permission.SEND_SMS,
                    REQUEST_PERMISSION_SEND_SMS);
        } else {/*from  w ww.  j a  va 2  s . c o  m*/
            requestPermission(Manifest.permission.SEND_SMS, REQUEST_PERMISSION_SEND_SMS);
        }
    } else {
        Toast.makeText(MainActivity.this, "Permission (already) Granted!", Toast.LENGTH_SHORT).show();
    }
}

From source file:my.home.lehome.asynctask.LoadAutoCompleteConfAsyncTask.java

@Override
protected void onPreExecute() {
    Toast.makeText(mContext.get(), R.string.pref_loading_auto_item, Toast.LENGTH_SHORT).show();
    BusProvider.getRestBusInstance().register(this);
    super.onPreExecute();
}

From source file:com.dedipower.portal.android.CreateTicket.java

public void onCreate(Bundle savedInstanceState) {
    API.SessionID = getIntent().getStringExtra("sessionid");
    dialog = new ProgressDialog(this);
    dialog.setMessage("Loading...");

    super.onCreate(savedInstanceState);
    setContentView(R.layout.createticket);

    final Handler handler = new Handler() {
        public void handleMessage(Message msg) {
            dialog.dismiss();//w  w  w  .  j  a v  a 2  s. c om
            if (TicketID == 0) {
                Toast.makeText(CreateTicket.this,
                        "Ticket Creation Failed. Please try again later or email request@dedipower.com",
                        Toast.LENGTH_LONG).show();
            } else {
                Toast.makeText(CreateTicket.this, "Ticket Created! Returning to main screen...",
                        Toast.LENGTH_SHORT).show();
                finish();
            }
        }
    };

    final Thread submitTicket = new Thread() {
        public void run() {
            try {
                TicketID = API.CreateTicket(Subject, Message);
            } catch (JSONException e) {
                TicketID = 0;
            }

            handler.sendEmptyMessage(0);
        }
    };

    Button CreateTicketButton = (Button) findViewById(R.id.CreateTicketButton);
    CreateTicketButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            dialog.show();
            EditText SubjectET = (EditText) findViewById(R.id.Subject);
            EditText MessageET = (EditText) findViewById(R.id.Message);
            Subject = SubjectET.getText().toString();
            Message = MessageET.getText().toString();

            submitTicket.start();
            /*EditText Subject = (EditText) findViewById(R.id.Subject);
            EditText Message = (EditText) findViewById(R.id.Message);
                    
            try 
            {
            TicketID = API.CreateTicket(Subject.getText().toString() , Message.getText().toString());
            } 
            catch (JSONException e) 
            {
               Toast.makeText(CreateTicket.this, "Ticket Creation Failed. Please try again later or email request@dedipower.com", Toast.LENGTH_LONG).show();
            }
                    
                    
            if(TicketID == 0)
            {
               Toast.makeText(CreateTicket.this, "Ticket Creation Failed. Please try again later or email request@dedipower.com", Toast.LENGTH_LONG).show();
            }
            else
            {
               Toast.makeText(CreateTicket.this, "Ticket Created! Returning to main screen...", Toast.LENGTH_SHORT).show();
               finish();
            }*/
        }
    });
}

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

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.login);//from   ww  w  .  j a va  2 s  . co  m

    Bundle extras = getIntent().getExtras();
    if (extras.get("msg") != null) {
        Toast message = Toast.makeText(getApplicationContext(), extras.getString("msg"), Toast.LENGTH_SHORT);
        message.show();
    }
    // map the login button to the layout
    login_btn = (Button) findViewById(R.id.login);
    login_btn.setOnClickListener(this);
    // map the forgot password button to the layout
    forgot_btn = (Button) findViewById(R.id.forgot_password);
    forgot_btn.setOnClickListener(this);

    username = (EditText) findViewById(R.id.username);
    password = (EditText) findViewById(R.id.password);

}

From source file:net.networksaremadeofstring.pulsant.portal.CreateTicket.java

public void onCreate(Bundle savedInstanceState) {
    API.SessionID = getIntent().getStringExtra("sessionid");
    dialog = new ProgressDialog(this);
    dialog.setMessage("Loading...");

    super.onCreate(savedInstanceState);
    setContentView(R.layout.createticket);

    final Handler handler = new Handler() {
        public void handleMessage(Message msg) {
            dialog.dismiss();//  w w  w  . j av a 2  s.  c o  m
            if (TicketID == 0) {
                Toast.makeText(CreateTicket.this,
                        "Ticket Creation Failed. Please try again later or email request@Pulsant.com",
                        Toast.LENGTH_LONG).show();
            } else {
                Toast.makeText(CreateTicket.this, "Ticket Created! Returning to main screen...",
                        Toast.LENGTH_SHORT).show();
                finish();
            }
        }
    };

    final Thread submitTicket = new Thread() {
        public void run() {
            try {
                TicketID = API.CreateTicket(Subject, Message);
            } catch (JSONException e) {
                TicketID = 0;
            }

            handler.sendEmptyMessage(0);
        }
    };

    Button CreateTicketButton = (Button) findViewById(R.id.CreateTicketButton);
    CreateTicketButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            dialog.show();
            EditText SubjectET = (EditText) findViewById(R.id.Subject);
            EditText MessageET = (EditText) findViewById(R.id.Message);
            Subject = SubjectET.getText().toString();
            Message = MessageET.getText().toString();

            submitTicket.start();
            /*EditText Subject = (EditText) findViewById(R.id.Subject);
            EditText Message = (EditText) findViewById(R.id.Message);
                    
            try 
            {
            TicketID = API.CreateTicket(Subject.getText().toString() , Message.getText().toString());
            } 
            catch (JSONException e) 
            {
               Toast.makeText(CreateTicket.this, "Ticket Creation Failed. Please try again later or email request@Pulsant.com", Toast.LENGTH_LONG).show();
            }
                    
                    
            if(TicketID == 0)
            {
               Toast.makeText(CreateTicket.this, "Ticket Creation Failed. Please try again later or email request@Pulsant.com", Toast.LENGTH_LONG).show();
            }
            else
            {
               Toast.makeText(CreateTicket.this, "Ticket Created! Returning to main screen...", Toast.LENGTH_SHORT).show();
               finish();
            }*/
        }
    });
}