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:edgargtzg.popularmovies.MovieDetailsFragment.java

/**
 * Updates the content of the view based on the movie data.
 *
 * @param movieItem the current movie item.
 *//*from  w w w .j  a v a2  s  .  c o  m*/
private void updateMovieData(MovieItem movieItem) {

    if (isNetworkAvailable()) {
        FetchMovieVideosTask fetchMovieVideosTask = new FetchMovieVideosTask(movieItem);
        fetchMovieVideosTask.execute();
        FetchMovieReviewsTask fetchMovieReviewsTask = new FetchMovieReviewsTask(movieItem);
        fetchMovieReviewsTask.execute();
    } else {
        Toast toast = Toast.makeText(getActivity(), R.string.error_msg_no_network, Toast.LENGTH_LONG);
        toast.setGravity(Gravity.CENTER, 0, 0);
        toast.show();
    }
}

From source file:carsharing.starter.automotive.iot.ibm.com.mobilestarterapp.Home.CarBrowse.java

@Override
public void onMapReady(final GoogleMap googleMap) {
    mMap = googleMap;/*w  w w .ja va  2 s  .c  o  m*/

    mMap.setOnMapLongClickListener(new GoogleMap.OnMapLongClickListener() {
        @Override
        public void onMapLongClick(final LatLng latLng) {
            //System.out.println("MAP LONG CLICK " + latLng);

            final Location location = new Location("NoProvider");
            location.setLatitude(latLng.latitude);
            location.setLongitude(latLng.longitude);
            location.setTime(new Date().getTime());

            String title = "";
            if (simulatedLocation == null) {
                simulatedLocation = location;
                title = "This location is used next.";
            } else {
                simulatedLocation = null;
                title = "Real location is used next.";
            }
            ((AppCompatActivity) getActivity()).getSupportActionBar().setTitle(title);

            final Toast toast = Toast.makeText(getActivity().getApplicationContext(),
                    "Long tap toggles location setting. Go back main menu and come again for the new location!",
                    Toast.LENGTH_LONG);
            toast.show();
        }
    });

    getAccurateLocation(mMap);
}

From source file:com.scooter1556.sms.androidtv.fragment.VideoPlayerFragment.java

private void initialiseVideo() {
    // Get settings
    final SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(getActivity());

    if (mediaElement == null) {
        Toast error = Toast.makeText(getActivity(), getString(R.string.error_loading_media),
                Toast.LENGTH_SHORT);/* w ww  .  jav a2 s. c  o  m*/
        error.show();
    }

    // Initialise Stream
    restService.initialiseStream(mediaElement.getID(), null, SUPPORTED_CODECS, null, FORMAT,
            Integer.parseInt(settings.getString("pref_video_quality", "0")), MAX_SAMPLE_RATE, null, null,
            settings.getBoolean("pref_direct_play", false), new JsonHttpResponseHandler() {

                @Override
                public void onSuccess(int statusCode, cz.msebera.android.httpclient.Header[] headers,
                        JSONObject response) {
                    // Parse profile
                    Gson parser = new Gson();
                    TranscodeProfile profile = parser.fromJson(response.toString(), TranscodeProfile.class);

                    // Configure Player
                    player.setTranscodeProfile(profile);
                    player.setID(mediaElement.getID());
                    player.setQuality(settings.getString("pref_video_quality", "0"));
                    player.setMultiChannelEnabled(settings.getBoolean("pref_audio_multichannel", false));

                    if (mediaElement.getDuration() != null) {
                        player.setDuration(mediaElement.getDuration());
                    }

                    preparePlayer();
                    initialised = true;
                }

                @Override
                public void onFailure(int statusCode, cz.msebera.android.httpclient.Header[] headers,
                        String responseString, Throwable throwable) {
                    Toast error = Toast.makeText(getActivity(), getString(R.string.error_loading_media),
                            Toast.LENGTH_SHORT);
                    error.show();
                }
            });
}

From source file:cm.aptoide.pt.ScheduledDownloads.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {

    Builder dialogBuilder = new AlertDialog.Builder(this);
    final AlertDialog scheduleDialog = dialogBuilder.create();

    //      AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
    switch (item.getItemId()) {
    case 0:/*  ww w  .  ja  v a2 s. co m*/
        for (String scheduledDownload : scheduledDownloadsHashMap.keySet()) {
            scheduledDownloadsHashMap.get(scheduledDownload).toggleChecked();
        }
        adapter.notifyDataSetInvalidated();
        break;
    case 1:
        if (isAllChecked()) {
            scheduleDialog.setTitle(getText(R.string.schDwnBtn));
            scheduleDialog.setIcon(android.R.drawable.ic_menu_close_clear_cancel);
            scheduleDialog.setCancelable(false);
            scheduleDialog.setMessage(getText(R.string.schDown_sureremove));
            scheduleDialog.setButton(Dialog.BUTTON_POSITIVE, getString(android.R.string.yes),
                    new Dialog.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface arg0, int arg1) {
                            for (String scheduledDownload : scheduledDownloadsHashMap.keySet()) {
                                if (scheduledDownloadsHashMap.get(scheduledDownload).checked) {
                                    db.deleteScheduledDownload(scheduledDownload);
                                }
                            }
                            getSupportLoaderManager().restartLoader(0, null, ScheduledDownloads.this);
                            return;
                        }
                    });
            scheduleDialog.setButton(Dialog.BUTTON_NEGATIVE, getString(android.R.string.no),
                    new Dialog.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int arg1) {
                            dialog.cancel();
                        }
                    });
            scheduleDialog.show();
        } else {
            Toast toast = Toast.makeText(this, getString(R.string.schDown_nodownloadselect),
                    Toast.LENGTH_SHORT);
            toast.show();
        }
        break;

    default:
        break;
    }
    return true;
}

From source file:cm.aptoide.ptdev.ScheduledDownloadsActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {

    int i = item.getItemId();

    if (i == android.R.id.home) {
        finish();/*from www. j a va  2 s. c o m*/
    } else if (i == R.id.home) {
        finish();
    } else if (i == R.id.menu_install) {

        if (isAllChecked()) {
            for (Long scheduledDownload : scheduledDownloadsHashMap.keySet()) {
                if (scheduledDownloadsHashMap.get(scheduledDownload).checked) {
                    final ScheduledDownload schDown = scheduledDownloadsHashMap.get(scheduledDownload);

                    GetApkInfoRequestFromMd5 requestFromMd5 = new GetApkInfoRequestFromMd5(
                            Aptoide.getContext());
                    requestFromMd5.setRepoName(schDown.getRepoName());
                    requestFromMd5.setMd5Sum(schDown.getMd5());

                    spiceManager.execute(requestFromMd5, new RequestListener<GetApkInfoJson>() {
                        @Override
                        public void onRequestFailure(SpiceException spiceException) {

                        }

                        @Override
                        public void onRequestSuccess(GetApkInfoJson getApkInfoJson) {

                            if (getApkInfoJson != null) {
                                Download download = new Download();
                                download.setId(schDown.getMd5().hashCode());
                                download.setName(schDown.getName());
                                download.setVersion(schDown.getVername());
                                download.setIcon(schDown.getIconPath());
                                download.setPackageName(schDown.getApkid());
                                download.setMd5(schDown.getMd5());
                                downloadService.startDownloadFromJson(getApkInfoJson, schDown.getId(),
                                        download);
                                Toast.makeText(getApplicationContext(),
                                        getApplicationContext().getString(R.string.starting_download),
                                        Toast.LENGTH_LONG).show();
                                if (Build.VERSION.SDK_INT >= 10)
                                    FlurryAgent.logEvent("Scheduled_Downloads_Installed_Apps");
                            }

                        }
                    });
                }
            }

        } else {
            Toast toast = Toast.makeText(Aptoide.getContext(), R.string.schDown_nodownloadselect,
                    Toast.LENGTH_SHORT);
            toast.show();
        }
    } else if (i == R.id.menu_remove) {
        Log.d("ScheduledDownloadsActivity-onOptionsItemSelected", "remove");
        if (isAllChecked()) {
            for (Long scheduledDownload : scheduledDownloadsHashMap.keySet()) {
                if (scheduledDownloadsHashMap.get(scheduledDownload).checked) {
                    db.deleteScheduledDownload(scheduledDownloadsHashMap.get(scheduledDownload).md5);
                    if (Build.VERSION.SDK_INT >= 10)
                        FlurryAgent.logEvent("Scheduled_Downloads_Removed_Apps");
                }
            }
            getSupportLoaderManager().restartLoader(0, null, this);
        } else {
            Toast toast = Toast.makeText(Aptoide.getContext(), R.string.schDown_nodownloadselect,
                    Toast.LENGTH_SHORT);
            toast.show();
        }
    } else if (i == R.id.menu_invert) {
        if (Build.VERSION.SDK_INT >= 10)
            FlurryAgent.logEvent("Scheduled_Downloads_Inverted_Apps");
        for (Long scheduledDownload : scheduledDownloadsHashMap.keySet()) {
            scheduledDownloadsHashMap
                    .get(scheduledDownload).checked = !scheduledDownloadsHashMap.get(scheduledDownload).checked;
        }
        adapter.notifyDataSetChanged();
    } else if (i == R.id.menu_SendFeedBack) {
        FeedBackActivity.screenshot(this);
        startActivity(new Intent(this, FeedBackActivity.class));
    }

    return super.onOptionsItemSelected(item);
}

From source file:at.alladin.rmbt.android.about.RMBTAboutFragment.java

private View createView(View view, LayoutInflater inflater) {
    activity = getActivity();/*from ww  w .ja v  a2  s. c o m*/

    getAppInfo(activity);

    final String clientUUID = String.format("U%s", ConfigHelper.getUUID(activity.getApplicationContext()));

    final String controlServerVersion = ConfigHelper.getControlServerVersion(activity);

    final ListView listView = (ListView) view.findViewById(R.id.aboutList);

    final ArrayList<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>();

    HashMap<String, String> item;
    item = new HashMap<String, String>();
    item.put("title", clientName);
    item.put("text1", this.getString(R.string.about_rtr_line1));
    list.add(item);
    item = new HashMap<String, String>();
    item.put("title", this.getString(R.string.about_version_title));
    item.put("text1", clientVersion);
    item.put("text2", "");
    list.add(item);
    item = new HashMap<String, String>();
    item.put("title", getString(R.string.about_clientid_title));
    item.put("text1", clientUUID);
    item.put("text2", "");
    list.add(item);
    item = new HashMap<String, String>();
    item.put("title", getString(R.string.about_web_title));
    item.put("text1", getString(R.string.about_web_line1));
    item.put("text2", "");
    list.add(item);
    item = new HashMap<String, String>();
    item.put("title", getString(R.string.about_email_title));
    item.put("text1", getString(R.string.about_email_line1));
    item.put("text2", "");
    list.add(item);
    item = new HashMap<String, String>();
    item.put("title", getString(R.string.about_terms_title));
    item.put("text1", getString(R.string.about_terms_line1));
    item.put("text2", "");
    list.add(item);
    item = new HashMap<String, String>();
    item.put("title", getString(R.string.about_git_title));
    item.put("text1", getString(R.string.about_git_line1));
    item.put("text2", "");
    list.add(item);
    item = new HashMap<String, String>();
    item.put("title", getString(R.string.about_dev_title));
    item.put("text1", getString(R.string.about_dev_line1));
    item.put("text2", getString(R.string.about_dev_line2));
    list.add(item);

    final String openSourceSoftwareLicenseInfo = GooglePlayServicesUtil
            .getOpenSourceSoftwareLicenseInfo(getActivity());

    if (openSourceSoftwareLicenseInfo != null) {
        item = new HashMap<String, String>();
        item.put("title", getString(R.string.about_gms_legal_title));
        item.put("text1", getString(R.string.about_gms_legal_line1));
        item.put("text2", "");
        list.add(item);
    }

    if (ConfigHelper.isDevEnabled(getActivity())) {
        item = new HashMap<String, String>();
        item.put("title", getString(R.string.about_test_counter_title));
        item.put("text1", Integer.toString(ConfigHelper.getTestCounter(getActivity())));
        item.put("text2", "");
        list.add(item);
    }

    item = new HashMap<String, String>();
    item.put("title", getString(R.string.about_control_server_version));
    item.put("text1", controlServerVersion != null ? controlServerVersion : "---");
    item.put("text2", "");
    list.add(item);

    sa = new RMBTAboutAdapter(getActivity(), list, R.layout.about_item,
            new String[] { "title", "text1", "text2" }, new int[] { R.id.title, R.id.text1, R.id.text2 });

    listView.setAdapter(sa);

    listView.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(final AdapterView<?> l, final View v, final int position, final long id) {

            switch (position) {

            case 1:
                handleHiddenCode();
                break;

            case 2:
                final android.content.ClipboardManager clipBoard = (android.content.ClipboardManager) getActivity()
                        .getSystemService(Context.CLIPBOARD_SERVICE);
                ClipData clip = ClipData.newPlainText("client_uuid", clientUUID);
                clipBoard.setPrimaryClip(clip);
                final Toast toast = Toast.makeText(getActivity(), R.string.about_clientid_toast,
                        Toast.LENGTH_LONG);
                toast.show();
                break;

            case 3:
                startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(getString(R.string.about_web_link))));
                break;

            case 4:
                /* Create the Intent */
                final Intent emailIntent = new Intent(Intent.ACTION_SEND);

                /* Fill it with Data */
                emailIntent.setType("plain/text");
                emailIntent.putExtra(Intent.EXTRA_EMAIL,
                        new String[] { getString(R.string.about_email_email) });
                emailIntent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.about_email_subject));
                emailIntent.putExtra(Intent.EXTRA_TEXT, "");

                /* Send it off to the Activity-Chooser */
                startActivity(Intent.createChooser(emailIntent, getString(R.string.about_email_sending)));

                break;

            case 5:
                final FragmentManager fm = activity.getSupportFragmentManager();
                FragmentTransaction ft;
                ft = fm.beginTransaction();
                ft.replace(R.id.fragment_content, new RMBTTermsFragment(), "terms");
                ft.addToBackStack("terms");
                ft.commit();
                break;

            case 6:
                startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(getString(R.string.about_git_link))));
                break;

            case 7:
                startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(getString(R.string.about_dev_link))));
                break;

            case 8:
                final String licenseInfo = GooglePlayServicesUtil
                        .getOpenSourceSoftwareLicenseInfo(getActivity());
                AlertDialog.Builder licenseDialog = new AlertDialog.Builder(getActivity());
                licenseDialog.setMessage(licenseInfo);
                licenseDialog.show();
                break;

            default:
                break;
            }
        }

    });

    return view;
}

From source file:com.game.simple.Game3.java

public void cropImage(Uri pic) {

    if (pic == null) {
        return;// w  ww .j  a  v  a  2 s. c o  m
    }
    try {
        Intent cropIntent = new Intent("com.android.camera.action.CROP");
        //indicate image type and Uri
        cropIntent.setDataAndType(pic, "image/*");
        //set crop properties
        cropIntent.putExtra("crop", "true");
        //indicate aspect of desired crop
        cropIntent.putExtra("aspectX", 1);
        cropIntent.putExtra("aspectY", 1);
        //indicate output X and Y
        cropIntent.putExtra("outputX", 256);
        cropIntent.putExtra("outputY", 256);
        //retrieve data on return
        cropIntent.putExtra("return-data", true);
        //start the activity - we handle returning in onActivityResult
        self.startActivityForResult(cropIntent, PIC_CROP);

    } catch (ActivityNotFoundException anfe) {
        //display an error message
        String errorMessage = "?in thoi khng h tr !";
        Toast toast = Toast.makeText(this, errorMessage, Toast.LENGTH_SHORT);
        toast.show();
    }

}

From source file:org.madmatrix.zxing.android.CaptureActivity.java

public void showMyToast(String content) {
    LayoutInflater inflater = getLayoutInflater();
    View layout = inflater.inflate(R.layout.toast_layout, (ViewGroup) findViewById(R.id.toast_layout));

    TextView toast_content = (TextView) layout.findViewById(R.id.toast_content);

    toast_content.setText(content);//from   w  w  w  .j  a  va2 s.c  o  m

    Toast toast = new Toast(getApplicationContext());
    toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
    toast.setDuration(Toast.LENGTH_SHORT);
    toast.setView(layout);
    toast.show();
}

From source file:com.adamas.client.android.ui.ConnectorsFragment.java

private void toast(String msg, ToastType toastType) {
    LayoutInflater inflater = getActivity().getLayoutInflater();
    // Inflate the Layout
    View layout = inflater.inflate(R.layout.custom_toast,
            (ViewGroup) getActivity().findViewById(R.id.custom_toast_layout));
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        if (toastType.equals(ToastType.error)) {
            layout.setBackground(getActivity().getDrawable(R.drawable.toast_error));
        } else if (toastType.equals(ToastType.info)) {
            layout.setBackground(getActivity().getDrawable(R.drawable.toast_info));
        } else if (toastType.equals(ToastType.warning)) {
            layout.setBackground(getActivity().getDrawable(R.drawable.toast_warning));
        } else {/*from   w w w.j a v  a  2 s  . c  o  m*/
            layout.setBackground(getActivity().getDrawable(R.drawable.toast_info));
        }
    }
    TextView text = (TextView) layout.findViewById(R.id.textToShow);
    // Set the Text to show in TextView
    text.setText(msg);

    Toast toast = new Toast(getActivity().getApplicationContext());
    toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
    toast.setDuration(Toast.LENGTH_SHORT);
    toast.setView(layout);
    toast.show();
}

From source file:com.wishlist.Wishlist.java

public void showToast(final String msg) {
    mHandler.post(new Runnable() {
        public void run() {
            Toast toast = Toast.makeText(Wishlist.this, msg, Toast.LENGTH_LONG);
            toast.show();
        }/*  w  w  w.java 2s . c  o m*/
    });
}