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.gps_project.Places.java

public void showToast(final String msg) {
    mHandler.post(new Runnable() {
        @Override/*from   www  .ja va 2 s .  c om*/
        public void run() {
            Toast toast = Toast.makeText(Places.this, msg, Toast.LENGTH_LONG);
            toast.show();
        }
    });
}

From source file:com.mobilevangelist.glass.helloworld.GetTheWeatherActivity.java

private Bitmap loadImageFromURL(String getURL) {

    try {/*from   w w  w  . j a v a  2 s  . c  o  m*/
        URL url = new URL(getURL);

        HttpGet httpRequest = null;
        httpRequest = new HttpGet(url.toURI());
        HttpClient httpclient = new DefaultHttpClient();
        HttpResponse response = (HttpResponse) httpclient.execute(httpRequest);
        HttpEntity entity = response.getEntity();
        BufferedHttpEntity b_entity = new BufferedHttpEntity(entity);
        InputStream input = b_entity.getContent();
        Bitmap bitmap = BitmapFactory.decodeStream(input);
        return bitmap;
    } catch (Exception ex) {

        Toast t2 = Toast.makeText(getApplicationContext(), "Image Loading Failed", Toast.LENGTH_LONG);
        t2.setGravity(Gravity.CENTER, 0, 0);
        t2.show();
        return null;
    }
}

From source file:com.nikolak.weatherapp.MainActivity.java

public void notifyFail(String msg) {
    msg = msg != null ? msg : "Unknown error";

    Context context = getApplicationContext();
    CharSequence text = msg;//  ww  w.  j a v  a  2  s .  c o  m
    int duration = Toast.LENGTH_SHORT;
    Toast toast = Toast.makeText(context, text, duration);
    toast.show();
}

From source file:camera.AnotherCamera.java

/**
 * Start the camera by dispatching a camera intent.
 *///from w  w w  .j ava  2s  .c om
protected void dispatchTakePictureIntent() {

    // Check if there is a camera.
    Context context = getActivity();
    PackageManager packageManager = context.getPackageManager();
    if (packageManager.hasSystemFeature(PackageManager.FEATURE_CAMERA) == false) {
        Toast.makeText(getActivity(), "This device does not have a camera.", Toast.LENGTH_SHORT).show();
        return;
    }

    // Camera exists? Then proceed...
    Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

    // Ensure that there's a camera activity to handle the intent
    CameraActivity activity = (CameraActivity) getActivity();
    if (takePictureIntent.resolveActivity(activity.getPackageManager()) != null) {
        // Create the File where the photo should go.
        // If you don't do this, you may get a crash in some devices.
        File photoFile = null;
        try {
            photoFile = createImageFile();
        } catch (IOException ex) {
            // Error occurred while creating the File
            Toast toast = Toast.makeText(activity, "There was a problem saving the photo...",
                    Toast.LENGTH_SHORT);
            toast.show();
        }
        // Continue only if the File was successfully created
        if (photoFile != null) {
            Uri fileUri = Uri.fromFile(photoFile);
            activity.setCapturedImageURI(fileUri);
            activity.setCurrentPhotoPath(fileUri.getPath());
            takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, activity.getCapturedImageURI());
            startActivityForResult(takePictureIntent, REQUEST_TAKE_PHOTO);
        }
    }
}

From source file:com.dropbox.android.dropeso.dropeso.java

private void showToast(String msg) {
    Toast error = Toast.makeText(this, msg, Toast.LENGTH_LONG);
    error.show();
}

From source file:com.radicaldynamic.groupinform.application.Collect.java

public void showCustomToast(String message) {
    LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    View view = inflater.inflate(R.layout.toast_view, null);

    // Set the text in the view
    TextView tv = (TextView) view.findViewById(R.id.message);
    tv.setText(message);/*from  ww w . j  ava2 s  .c o m*/

    Toast t = new Toast(this);
    t.setView(view);
    t.setDuration(Toast.LENGTH_SHORT);
    t.setGravity(Gravity.CENTER, 0, 0);
    t.show();
}

From source file:org.xbmc.android.remote.presentation.controller.AbstractController.java

public void onMessage(final String message) {
    mActivity.runOnUiThread(new Runnable() {
        public void run() {
            Toast toast = Toast.makeText(mActivity, message, Toast.LENGTH_LONG);
            toast.show();
        }//  ww  w  .  j a v a  2  s. c  o  m
    });
}

From source file:com.ProfessorPopTart.alternateouyastore.MainActivity.java

/**
 * This is will send a toast message./*w w  w  .ja  va 2 s .  co  m*/
 *
 * @param  msg  String message to display to the user.
 */
private void toastMessage(String msg) {
    Context context = getApplicationContext();
    int duration = Toast.LENGTH_SHORT;
    if (context != null) {
        Toast toast = Toast.makeText(context, msg, duration);
        toast.show();
    }
}

From source file:cm.aptoide.pt.webservices.login.CreateUser.java

public void signUp(View v) {
    username = username_box.getText().toString();
    password = password_box.getText().toString();
    if (username.trim().length() > 0 && password.trim().length() > 0) {
        new CreateUserTask().execute(username.trim(), password.trim());
    } else {//from   w  w  w  .ja  v a 2s  . co m
        Toast toast = Toast.makeText(context, context.getString(R.string.check_your_credentials),
                Toast.LENGTH_SHORT);
        toast.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL, 0, 30);
        toast.show();
    }

}

From source file:net.gromgull.android.bibsonomyposter.BibsonomyPosterActivity.java

/** Called with the activity is first created. */
@Override//  w ww .  j a v a  2s. co  m
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    load();

    Intent intent = getIntent();
    String action = intent.getAction();
    if (action.equalsIgnoreCase(Intent.ACTION_SEND)) {
        final String uri = intent.getStringExtra(Intent.EXTRA_TEXT);
        final String title = intent.getStringExtra(Intent.EXTRA_SUBJECT);

        final Context context = getApplicationContext();

        new AsyncTask<Void, Integer, Boolean>() {

            @Override
            protected Boolean doInBackground(Void... v) {
                try {
                    bookmark(uri, title);
                    return true;
                } catch (Exception e) {
                    Log.w(LOGTAG, "Could not bookmark: " + title + " / " + uri, e);
                    return false;
                }
            }

            protected void onPostExecute(Boolean result) {
                if (result) {
                    Toast toast = Toast.makeText(context, "Bookmarked " + title, Toast.LENGTH_SHORT);
                    toast.show();
                } else {
                    Toast toast = Toast.makeText(context, "Error bookmarking " + title, Toast.LENGTH_SHORT);
                    toast.show();
                }
            }

        }.execute();

        finish();
        return;
    }

    // Inflate our UI from its XML layout description.
    setContentView(R.layout.bibsonomyposter_activity);

    if (username != null)
        ((EditText) findViewById(R.id.username)).setText(username);
    if (apikey != null)
        ((EditText) findViewById(R.id.apikey)).setText(apikey);

    // Hook up button presses to the appropriate event handler.
    ((Button) findViewById(R.id.save)).setOnClickListener(mSaveListener);

}