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.example.faisal.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
    final 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" };
    final 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  w  w .j a  v a2  s .com

    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.list_view_forecast);
    listView.setAdapter(mForecastAdapter);

    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Toast toast = Toast.makeText(getActivity(), mForecastAdapter.getItem(position), Toast.LENGTH_SHORT);
            toast.show();

            Intent detailIntent = new Intent(getActivity(), DetailActivity.class);
            detailIntent.putExtra(Intent.EXTRA_TEXT, mForecastAdapter.getItem(position));
            startActivity(detailIntent);
        }
    });

    return rootView;
}

From source file:de.appplant.cordova.plugin.notification.NotificationWrapper.java

/**
 * Show a notification as a Toast when App is runing in foreground
 * @param title Title of the notification
 * @param notification Notification to show
 *//* w  w  w  .j a  v  a2s.  c o m*/
public void showNotificationToast(Options options) {
    String title = options.getTitle();
    String message = options.getMessage();
    int duration = Toast.LENGTH_LONG;
    if (title.equals("")) {
        title = "Notification";
    }
    String text = title + " \n " + message;

    Toast notificationToast = Toast.makeText(context, text, duration);
    notificationToast.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 ww w. j  a  v  a 2 s. c o m
    toast.show();
}

From source file:com.androidquery.simplefeed.base.BaseActivity.java

public void showToast(String message) {

    if (message == null || message.length() == 0)
        return;/*from www . ja  va 2s. c om*/

    try {
        Toast toast = Toast.makeText(this, message, Toast.LENGTH_SHORT);
        toast.setGravity(Gravity.CENTER, 0, 0);
        toast.show();
    } catch (Exception e) {
        AQUtility.report(e);
    }
}

From source file:fm.smart.r1.CreateExampleActivity.java

public void onClick(View v) {
    EditText exampleInput = (EditText) findViewById(R.id.create_example_sentence);
    EditText translationInput = (EditText) findViewById(R.id.create_example_translation);
    EditText exampleTransliterationInput = (EditText) findViewById(R.id.sentence_transliteration);
    EditText translationTransliterationInput = (EditText) findViewById(R.id.translation_transliteration);
    final String example = exampleInput.getText().toString();
    final String translation = translationInput.getText().toString();
    if (TextUtils.isEmpty(example) || TextUtils.isEmpty(translation)) {
        Toast t = Toast.makeText(this, "Example and translation are required fields", 150);
        t.setGravity(Gravity.CENTER, 0, 0);
        t.show();
    } else {//from   ww  w.  j  av  a 2  s  .  c o m
        final String example_language_code = Utils.LANGUAGE_MAP.get(example_language);
        final String translation_language_code = Utils.LANGUAGE_MAP.get(translation_language);
        final String example_transliteration = exampleTransliterationInput.getText().toString();
        final String translation_transliteration = translationTransliterationInput.getText().toString();

        if (LoginActivity.isNotLoggedIn(this)) {
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setClassName(this, LoginActivity.class.getName());
            intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); // avoid
            // navigation
            // back to this?
            LoginActivity.return_to = CreateExampleActivity.class.getName();
            LoginActivity.params = new HashMap<String, String>();
            LoginActivity.params.put("goal_id", goal_id);
            LoginActivity.params.put("item_id", item_id);
            LoginActivity.params.put("example", example);
            LoginActivity.params.put("translation", translation);
            LoginActivity.params.put("example_language", example_language);
            LoginActivity.params.put("translation_language", translation_language);
            LoginActivity.params.put("example_transliteration", example_transliteration);
            LoginActivity.params.put("translation_transliteration", translation_transliteration);
            startActivity(intent);
        } else {

            final ProgressDialog myOtherProgressDialog = new ProgressDialog(this);
            myOtherProgressDialog.setTitle("Please Wait ...");
            myOtherProgressDialog.setMessage("Creating Example ...");
            myOtherProgressDialog.setIndeterminate(true);
            myOtherProgressDialog.setCancelable(true);

            final Thread create_example = new Thread() {
                public void run() {
                    // TODO make this interruptable .../*if
                    // (!this.isInterrupted())*/
                    try {
                        // TODO failures here could derail all ...
                        CreateExampleActivity.add_item_goal_result = new AddItemResult(
                                Main.lookup.addItemToGoal(Main.transport, goal_id, item_id, null));

                        Result result = null;
                        try {
                            result = Main.lookup.createExample(Main.transport, translation,
                                    translation_language_code, translation, null, null, null);
                            JSONObject json = new JSONObject(result.http_response);
                            String text = json.getString("text");
                            String translation_id = json.getString("id");
                            result = Main.lookup.createExample(Main.transport, example, example_language_code,
                                    example_transliteration, translation_id, item_id, goal_id);
                        } catch (UnsupportedEncodingException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }
                        CreateExampleActivity.create_example_result = new CreateExampleResult(result);

                    } catch (Exception e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }

                    myOtherProgressDialog.dismiss();

                }
            };
            myOtherProgressDialog.setButton("Cancel", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    create_example.interrupt();
                }
            });
            OnCancelListener ocl = new OnCancelListener() {
                public void onCancel(DialogInterface arg0) {
                    create_example.interrupt();
                }
            };
            myOtherProgressDialog.setOnCancelListener(ocl);
            myOtherProgressDialog.show();
            create_example.start();
        }
    }
}

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

public void onRestRequestComplete(Methods method, JSONObject result) {
    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();/*from   w ww  .  j  a  va  2s  .c o m*/
                    editor.putLong("updateTime", result.getLong("updateTime"));
                    editor.commit();
                    int numbros = result.getInt("numBros");
                    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);
                    }
                } 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) {
                    Auth.loggedIn = false;
                    Toast msg = Toast.makeText(this,
                            "You have been logged out by the server.  Please log in again.", Toast.LENGTH_LONG);
                    msg.show();
                    finish();
                } else {
                    Toast msg = Toast.makeText(this, "Invalid requestStatus", Toast.LENGTH_LONG);
                    msg.show();
                }
            } catch (JSONException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    } else if (method == Methods.checkAppVersion) {
        if (result != null) {
            try {
                String requestStatus = result.getString("requestStatus");
                if (requestStatus.compareTo("success") == 0) {
                    String appVersion = result.getString("version");
                    String appDate = result.getString("date");
                    final String appUrl = result.getString("url");
                    PackageInfo pinfo = this.getPackageManager().getPackageInfo(getPackageName(), 0);
                    ;
                    if (appVersion.compareTo(pinfo.versionName) != 0) {
                        AlertDialog.Builder builder = new AlertDialog.Builder(this);
                        builder.setTitle("Upgrade");
                        builder.setMessage("Update available, ready to upgrade?");
                        builder.setIcon(R.drawable.icon);
                        builder.setCancelable(false);
                        builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int which) {
                                Intent promptInstall = new Intent("android.intent.action.VIEW",
                                        Uri.parse("https://apo.case.edu:8090/app/" + appUrl));
                                startActivity(promptInstall);
                            }
                        });
                        builder.setNegativeButton("No", new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int which) {
                                dialog.cancel();
                            }
                        });
                        AlertDialog alert = builder.create();
                        alert.show();
                    } else {
                        Toast msg = Toast.makeText(this, "No updates found", Toast.LENGTH_LONG);
                        msg.show();
                    }
                }
            } catch (JSONException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (NameNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }
}

From source file:cmput301.f13t01.editstory.EditStoryActivity.java

private void onSelectPublish() {
    // Check the status of the ESManager
    ESManager esManager = GlobalManager.getESManager();
    if (esManager.isBusy()) {
        Toast toast = Toast.makeText(getApplicationContext(), "Online Connection Busy", Toast.LENGTH_SHORT);
        toast.show();
    } else {/*from  w w  w . j  a v  a2s  .  c  om*/
        EditText title = (EditText) findViewById(R.id.edit_story_title);
        EditText author = (EditText) findViewById(R.id.edit_story_author);
        EditText desc = (EditText) findViewById(R.id.edit_story_description);

        manager.setTitle(title.getText().toString());
        manager.setAuthor(author.getText().toString());
        manager.setDescription(desc.getText().toString());

        PublishStoryTask task = new PublishStoryTask();
        task.execute(storyId);

        // Block while publishing
        Toast startPublishToast = Toast.makeText(getApplicationContext(), "Publishing, please wait...",
                Toast.LENGTH_LONG);
        startPublishToast.show();
        // Wait to allow ESManager to set state
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        // Block
        while (esManager.isBusy()) {
        }
        // Finished Publishing
        Toast endPublishToast = Toast.makeText(getApplicationContext(), "Finished Publishing.",
                Toast.LENGTH_SHORT);
        endPublishToast.show();
    }
}

From source file:com.example.util.Utils.java

/**
 * Show toast information//from ww w .j av  a2s  .c  o  m
 * 
 * @param context
 *            application context
 * @param text
 *            the information which you want to show
 * @return show toast dialog
 */
public static void makeEventToast(Context context, String text, boolean isLongToast) {

    Toast toast = null;
    if (isLongToast) {
        toast = Toast.makeText(context, "", Toast.LENGTH_LONG);
    } else {
        toast = Toast.makeText(context, "", Toast.LENGTH_SHORT);
    }
    View v = LayoutInflater.from(context).inflate(R.layout.toast_view, null);
    TextView textView = (TextView) v.findViewById(R.id.text);
    textView.setText(text);
    toast.setView(v);
    toast.show();
}

From source file:tm.veriloft.mapsplayground.MapsActivity.java

public void showCenteredToast(String string) {
    if (string == null || string.equals(""))
        string = "null";
    Toast toast = Toast.makeText(this.getApplicationContext(), string, Toast.LENGTH_LONG);
    toast.setGravity(Gravity.CENTER, 0, 0);
    toast.show();
}

From source file:cmput301.f13t01.editstory.EditStoryActivity.java

private void onSelectCancel() {
    if (isNew) {/*from  ww w  .  j  av  a 2  s. c o m*/
        GlobalManager.getLocalManager().removeStory(storyId);
    }
    Toast toast = Toast.makeText(getApplicationContext(), getResources().getString(R.string.cancel_toast),
            Toast.LENGTH_SHORT);
    toast.show();
    finish();
}