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.mobshep.shepherdlogin.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    switch (id) {

    case R.id.action_settings:

        Intent goToSettings = new Intent(this, Preferences.class);
        startActivity(goToSettings);//  ww  w  .j av a2  s  .com
        return true;

    case R.id.action_clearSession:

        storedPref = getSharedPreferences("Sessions", MODE_PRIVATE);
        toEdit = storedPref.edit();
        toEdit.clear();
        toEdit.commit();

        //delete * from sessions table
        SessionProvider.DatabaseHelper providerInstance;
        providerInstance = new SessionProvider.DatabaseHelper(this);
        providerInstance.deleteData();

        Toast valid = Toast.makeText(MainActivity.this, "Sessions cleared!", Toast.LENGTH_SHORT);
        valid.show();

    case R.id.action_exit:

        this.finish();

        break;

    default:

    }
    return super.onOptionsItemSelected(item);

}

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

public void onClick(View v) {
    switch (v.getId()) {
    case R.id.login:
        API api = new API(this);
        if (!api.callMethod(Methods.login, this, username.getText().toString(),
                password.getText().toString())) {
            Toast msg = Toast.makeText(this, "Error: You must enter both a username and password to login",
                    Toast.LENGTH_SHORT);
            msg.show();
        }/*w  w w .j  a v a 2s. c om*/
        //api.callMethod(Methods.checkAES,this, (String[])null);
        break;

    case R.id.forgot_password:
        //start forgot password activity
        Intent forgotPasswordIntent = new Intent(Login.this, ForgotPassword.class);
        Login.this.startActivity(forgotPasswordIntent);
        break;
    default:
        //something went wrong add a throw here
    }
}

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);/* w w w  . j a  va 2 s. c o  m*/
    mToast.show();
}

From source file:com.example.pawandeep.sunshine.app.ForecastFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Create some dummy data for the ListView. Here's a sample weekly forecast
    String[] data = { "Mon 6/23- Sunny - 31/17", "Tue 6/24 - Foggy - 21/8", "Wed 6/25 - Cloudy - 22/17",
            "Thurs 6/26 - Rainy - 18/11", "Fri 6/27 - Foggy - 21/10",
            "Sat 6/28 - TRAPPED IN WEATHERSTATION - 23/18", "Sun 6/29 - Sunny - 20/7" };
    List<String> weekForecast = new ArrayList<String>(Arrays.asList(data));
    // Now that we have some dummy forecast data, create an ArrayAdapter.
    // The ArrayAdapter will take data from a source (like our dummy forecast) and
    // use it to populate the ListView it's attached to.
    mForecastAdapter = new ArrayAdapter<String>(getActivity(), // The current context (this activity)
            R.layout.list_item_forecast, // The name of the layout ID.
            R.id.list_item_forecast_textview, // The ID of the textview to populate.
            weekForecast);/*from  w  ww  .  ja v a  2s.co  m*/
    View rootView = inflater.inflate(R.layout.fragment_main, container, false);
    // Get a reference to the ListView, and attach this adapter to it.
    ListView listView = (ListView) rootView.findViewById(R.id.listview_forecast);
    listView.setAdapter(mForecastAdapter);
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
            Context context = ForecastFragment.this.getActivity();
            CharSequence text = "Hello toast!";
            int duration = Toast.LENGTH_SHORT;

            Toast toast = Toast.makeText(context, text, duration);
            toast.show();
        }
    });

    return rootView;
}

From source file:com.parse.f8.model.Favorites.java

/**
 * Saves the current set of favorites to a SharedPreferences file. This
 * method returns quickly, while the saving runs asynchronously.
 *///from w  ww.ja v  a  2  s .  c o  m
private void saveLocally(final Context context) {
    final JSONObject json = toJSON();

    new AsyncTask<Void, Void, Exception>() {
        @Override
        protected Exception doInBackground(Void... unused) {
            try {
                String jsonString = json.toString();
                SharedPreferences prefs = context.getSharedPreferences("favorites.json", Context.MODE_PRIVATE);
                prefs.edit().putString("json", jsonString).commit();
            } catch (Exception e) {
                return e;
            }
            return null;
        }

        @Override
        protected void onPostExecute(Exception error) {
            if (error != null) {
                Toast toast = Toast.makeText(context, error.getMessage(), Toast.LENGTH_LONG);
                toast.show();
            }
        }
    }.execute();
}

From source file:An.stop.AnstopActivity.java

@Override
protected Dialog onCreateDialog(int id) {
    Dialog dialog;//from  w ww.  j  a v  a  2 s  .c  o  m
    switch (id) {
    case ABOUT_DIALOG:
        AlertDialog.Builder aboutBuilder = new AlertDialog.Builder(this);
        aboutBuilder.setMessage(R.string.about_dialog).setCancelable(true).setPositiveButton("Ok",
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        dialog.dismiss();
                    }
                });

        dialog = aboutBuilder.create();
        break;

    case SAVE_DIALOG:
        AlertDialog.Builder saveBuilder = new AlertDialog.Builder(this);
        saveBuilder.setTitle(R.string.save);
        saveBuilder.setMessage(R.string.save_dialog);
        final EditText input = new EditText(this);
        saveBuilder.setView(input);

        saveBuilder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {

                // TODO save!
                Toast toast = Toast.makeText(getApplicationContext(), R.string.saved_succes,
                        Toast.LENGTH_SHORT);
                toast.show();
            }

        });

        saveBuilder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {
                dialog.dismiss();
            }
        });
        saveBuilder.setCancelable(false);
        dialog = saveBuilder.create();
        break;

    default:
        dialog = null;
    }

    return dialog;
}

From source file:com.filelocker.andy.MainActivity.java

public void browseButton_Click(View view) {
    final TextView vFileChooserText = (TextView) findViewById(R.id.fileChooserText);
    final FileChooserDialog dialog = new FileChooserDialog(this);
    dialog.show();/* ww  w .  j a va2 s .com*/
    dialog.addListener(new FileChooserDialog.OnFileSelectedListener() {
        public void onFileSelected(Dialog source, File file) {
            source.hide();
            Toast toast = Toast.makeText(source.getContext(), "File selected: " + file.getName(),
                    Toast.LENGTH_LONG);
            toast.show();
            vFileChooserText.setText(file.getAbsolutePath());
            dialog.hide();
        }

        public void onFileSelected(Dialog source, File folder, String name) {
            source.hide();
            Toast toast = Toast.makeText(source.getContext(), "File created: " + folder.getName() + "/" + name,
                    Toast.LENGTH_LONG);
            toast.show();
            dialog.hide();
        }
    });
}

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

public void onRestRequestComplete(Methods method, JSONObject result) {
    if (method == Methods.login) {
        if (result != null) {
            try {
                String requestStatus = result.getString("requestStatus");
                if (requestStatus.compareTo("valid login") == 0) {
                    Auth.loggedIn = true;
                    Auth.Hmac.setCounter(result.getInt("counter"));
                    Auth.Hmac.setIncrement(result.getInt("increment"));
                    PhoneOpenHelper db = new PhoneOpenHelper(this);
                    if (database == null)
                        database = db.getWritableDatabase();
                    API api = new API(this);
                    if (!api.callMethod(Methods.phone, this, (String[]) null)) {
                        Toast msg = Toast.makeText(this, "Error: Calling phone", Toast.LENGTH_LONG);
                        msg.show();
                    }/*from   w  w w. j av  a2 s  .c o  m*/

                } else if (requestStatus.compareTo("invalid username") == 0) {
                    Toast msg = Toast.makeText(getApplicationContext(), "Invalid username", Toast.LENGTH_LONG);
                    msg.show();
                } else if (requestStatus.compareTo("invalid login") == 0) {
                    Toast msg = Toast.makeText(getApplicationContext(), "Invalid username and/or password",
                            Toast.LENGTH_LONG);
                    msg.show();
                } else if (requestStatus.compareTo("no user") == 0) {
                    Toast msg = Toast.makeText(getApplicationContext(), "No username was provided",
                            Toast.LENGTH_LONG);
                    msg.show();
                } else {
                    Toast msg = Toast.makeText(getApplicationContext(), "Invalid requestStatus",
                            Toast.LENGTH_LONG);
                    msg.show();
                }
            } catch (JSONException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        } else {
            Toast msg = Toast.makeText(getApplicationContext(),
                    "Could not contact web server.  Please check your connection", Toast.LENGTH_LONG);
            msg.show();
        }
    } else if (method == Methods.phone) {
        if (result != null) {
            try {
                String requestStatus = result.getString("requestStatus");
                if (requestStatus.compareTo("success") == 0) {
                    SharedPreferences.Editor editor = getSharedPreferences(APO.PREF_FILE_NAME, MODE_PRIVATE)
                            .edit();
                    editor.putLong("updateTime", result.getLong("updateTime"));
                    editor.commit();
                    int numbros = result.getInt("numBros");

                    if (numbros > 0) {
                        JSONArray caseID = result.getJSONArray("caseID");
                        JSONArray first = result.getJSONArray("first");
                        JSONArray last = result.getJSONArray("last");
                        JSONArray phone = result.getJSONArray("phone");
                        JSONArray family = result.getJSONArray("family");
                        ContentValues values;
                        for (int i = 0; i < numbros; i++) {
                            values = new ContentValues();
                            values.put("_id", caseID.getString(i));
                            values.put("first", first.getString(i));
                            values.put("last", last.getString(i));
                            values.put("phone", phone.getString(i));
                            values.put("family", family.getString(i));
                            database.replace("phoneDB", null, values);
                        }
                    }
                    Intent homeIntent = new Intent(Login.this, Home.class);
                    Login.this.startActivity(homeIntent);
                    finish();
                } else if (requestStatus.compareTo("timestamp invalid") == 0) {
                    Toast msg = Toast.makeText(this, "Invalid timestamp.  Please try again.",
                            Toast.LENGTH_LONG);
                    msg.show();
                } else if (requestStatus.compareTo("HMAC invalid") == 0) {
                    Toast msg = Toast.makeText(this,
                            "You have been logged out by the server.  Please log in again.", Toast.LENGTH_LONG);
                    msg.show();
                } else {
                    Toast msg = Toast.makeText(this, "Invalid requestStatus", Toast.LENGTH_LONG);
                    msg.show();
                }
            } catch (JSONException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    } else {
        Toast msg = Toast.makeText(getApplicationContext(), "Invalid method callback", Toast.LENGTH_LONG);
        msg.show();
    }
}

From source file:net.reichholf.dreamdroid.abstivities.AbstractHttpActivity.java

/**
 * @param toastText/*  ww w.  ja  va 2  s .  co m*/
 */
protected void showToast(String toastText) {
    Toast toast = Toast.makeText(this, toastText, Toast.LENGTH_LONG);
    toast.show();
}

From source file:net.reichholf.dreamdroid.abstivities.AbstractHttpActivity.java

/**
 * @param toastText//  www . java 2 s. c om
 */
protected void showToast(CharSequence toastText) {
    Toast toast = Toast.makeText(this, toastText, Toast.LENGTH_LONG);
    toast.show();
}