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:fr.pasteque.client.Configure.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case MENU_EXPORT_ID:
        export();//  w  w  w. j  av  a 2s .  c  o m
        break;
    case MENU_IMPORT_ID:
        // Get properties file
        // TODO: check external storage state and access
        File path = Environment.getExternalStorageDirectory();
        path = new File(path, "pasteque");
        File file = new File(path, "pasteque.properties");
        FileInputStream fis;
        try {
            fis = new FileInputStream(file);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
            Toast t = Toast.makeText(this, R.string.cfg_import_file_not_found, Toast.LENGTH_SHORT);
            t.show();
            return true;
        }
        Properties props = new Properties();
        try {
            props.load(fis);
        } catch (IOException e) {
            e.printStackTrace();
            Toast t = Toast.makeText(this, R.string.cfg_import_read_error, Toast.LENGTH_SHORT);
            t.show();
            return true;
        }
        // Load props
        String host = props.getProperty("host", DEMO_HOST);
        String machineName = props.getProperty("machine_name", null);
        String ticketsMode = props.getProperty("tickets_mode", "simple");
        String user = props.getProperty("user", null);
        String password = props.getProperty("password", null);
        String location = props.getProperty("stock_location", "");
        String printDrv = props.getProperty("printer_driver", "None");
        String printModel = props.getProperty("printer_model", "");
        String printAddr = props.getProperty("printer_address", "");
        String printCtxTry = String.valueOf(getPref("printer_connect_try", DEFAULT_PRINTER_CONNECT_TRY));
        // Save
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
        SharedPreferences.Editor edit = prefs.edit();
        edit.putString("host", host);
        edit.putString("machine_name", machineName);
        // Set tickets mode, simple by default
        switch (ticketsMode) {
        case "restaurant":
            edit.putString("tickets_mode", String.valueOf(RESTAURANT_MODE));
            break;
        case "standard":
            edit.putString("tickets_mode", String.valueOf(STANDARD_MODE));
            break;
        default:
            edit.putString("tickets_mode", String.valueOf(SIMPLE_MODE));
            break;
        }
        edit.putString("user", user);
        edit.putString("password", password);
        edit.putString("stock_location", location);
        edit.putString("printer_driver", printDrv);
        edit.putString("printer_model", printModel);
        edit.putString("printer_address", printAddr);
        edit.putString("printer_connect_try", printCtxTry);
        edit.apply();
        Toast t = Toast.makeText(this, R.string.cfg_import_done, Toast.LENGTH_SHORT);
        t.show();
        // Reset activity to reload values
        this.finish();
        Intent i = new Intent(this, Configure.class);
        this.startActivity(i);
        break;
    case MENU_DEBUG_ID:
        AlertDialog.Builder b = new AlertDialog.Builder(this);
        b.setTitle(R.string.cfg_debug_alert_title);
        b.setMessage(R.string.cfg_debug_alert_message);
        b.setIcon(android.R.drawable.ic_dialog_alert);
        b.setNegativeButton(android.R.string.cancel, null);
        b.setPositiveButton(R.string.cfg_debug_alert_continue, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
                Intent i = new Intent(Configure.this, Debug.class);
                Configure.this.startActivity(i);
            }
        });
        b.show();
        break;
    }
    return true;
}

From source file:com.zia.freshdocs.widget.adapter.CMISAdapter.java

/**
 * Send an Intent requesting for an activity to display the content.
 * //from w w w  .  j a va2  s  .c o  m
 * @param file
 * @param ref
 */
protected void viewContent(File file, NodeRef ref) {
    Context context = getContext();

    // Ask for viewer
    Uri uri = Uri.fromFile(file);
    Intent viewIntent = new Intent(Intent.ACTION_VIEW);
    viewIntent.setDataAndType(uri, ref.getContentType());
    try {
        context.startActivity(viewIntent);
    } catch (ActivityNotFoundException e) {
        deleteContent(file);
        String text = "No viewer found for " + ref.getContentType();
        int duration = Toast.LENGTH_SHORT;
        Toast toast = Toast.makeText(context, text, duration);
        toast.show();
    }
}

From source file:no.ntnu.idi.socialhitchhiking.map.MapActivityJourney.java

/**
 * sends a message to the driver of a journey
 *///from   w w w.  ja v  a2 s .c o m
private void sendMessageToDriver() {

    final Dialog customDialog = new Dialog(this);
    customDialog.setContentView(R.layout.custom_dialog_layout);
    customDialog.setTitle("Message");

    final List<String> spinnerArray = new ArrayList<String>();
    spinnerArray.add("Everyone");
    if (!getApp().getSelectedJourney().getDriver().equals(getApp().getUser())) {
        spinnerArray.add(getApp().getSelectedJourney().getDriver().getFullName());
    }

    for (int i = 0; i < getApp().getSelectedJourney().getHitchhikers().size(); i++) {
        if (!getApp().getSelectedJourney().getHitchhikers().get(i).equals(getApp().getUser())) {
            spinnerArray.add(getApp().getSelectedJourney().getHitchhikers().get(i).getFullName());
        }
    }

    final Spinner spinner = (Spinner) customDialog.findViewById(R.id.spinner);
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(MapActivityJourney.this,
            android.R.layout.simple_spinner_item, spinnerArray);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner.setAdapter(adapter);

    ImageView sendBtn = (ImageView) customDialog.findViewById(R.id.sendBtn);
    final EditText input = (EditText) customDialog.findViewById(R.id.input);

    sendBtn.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            User mid = getApp().getUser();
            if (spinner.getSelectedItem().toString().equals("Everyone")) {
                if (input.getText().toString().equals("")) {
                    input.setHint("Please fill in your message");
                    Toast toast = Toast.makeText(MapActivityJourney.this, "Please fill in your message",
                            Toast.LENGTH_SHORT);
                    toast.setGravity(Gravity.BOTTOM, toast.getXOffset() / 2, toast.getYOffset() / 2);
                    toast.show();
                } else {
                    List<User> userList = new ArrayList<User>();
                    userList.add(getApp().getSelectedJourney().getDriver());
                    for (int k = 0; k < getApp().getSelectedJourney().getHitchhikers().size(); k++) {
                        userList.add(getApp().getSelectedJourney().getHitchhikers().get(k));
                    }
                    userList.remove(getApp().getUser());

                    for (int k = 0; k < userList.size(); k++) {
                        sendMessage(userList.get(k), input);
                    }

                    Toast toast = Toast.makeText(MapActivityJourney.this, "Message sent", Toast.LENGTH_SHORT);
                    toast.setGravity(Gravity.BOTTOM, toast.getXOffset() / 2, toast.getYOffset() / 2);
                    toast.show();
                    customDialog.dismiss();
                }
            } else {

                for (int j = 0; j < getApp().getSelectedJourney().getHitchhikers().size(); j++) {
                    if (spinner.getSelectedItem().toString()
                            .equals(getApp().getSelectedJourney().getHitchhikers().get(j).getFullName())) {
                        mid = getApp().getSelectedJourney().getHitchhikers().get(j);
                    }
                }

                if (spinner.getSelectedItem().toString()
                        .equals(getApp().getSelectedJourney().getDriver().getFullName())) {
                    mid = getApp().getSelectedJourney().getDriver();
                }
                if (input.getText().toString().equals("")) {
                    input.setHint("Please fill in your message");
                    Toast toast = Toast.makeText(MapActivityJourney.this, "Please fill in your message",
                            Toast.LENGTH_SHORT);
                    toast.setGravity(Gravity.BOTTOM, toast.getXOffset() / 2, toast.getYOffset() / 2);
                    toast.show();
                } else {
                    sendMessage(mid, input);
                    Toast toast = Toast.makeText(MapActivityJourney.this, "Message sent", Toast.LENGTH_SHORT);
                    toast.setGravity(Gravity.BOTTOM, toast.getXOffset() / 2, toast.getYOffset() / 2);
                    toast.show();
                    customDialog.dismiss();
                }

            }

        }

    });

    customDialog.show();

}

From source file:android.support.v7.internal.view.menu.ActionMenuItemView.java

@Override
public boolean onLongClick(View v) {
    if (hasText()) {
        // Don't show the cheat sheet for items that already show text.
        return false;
    }/*from w ww. jav a  2  s. co m*/

    final int[] screenPos = new int[2];
    final Rect displayFrame = new Rect();
    getLocationOnScreen(screenPos);
    getWindowVisibleDisplayFrame(displayFrame);

    final Context context = getContext();
    final int width = getWidth();
    final int height = getHeight();
    final int midy = screenPos[1] + height / 2;
    int referenceX = screenPos[0] + width / 2;
    if (ViewCompat.getLayoutDirection(v) == ViewCompat.LAYOUT_DIRECTION_LTR) {
        final int screenWidth = context.getResources().getDisplayMetrics().widthPixels;
        referenceX = screenWidth - referenceX; // mirror
    }
    Toast cheatSheet = Toast.makeText(context, mItemData.getTitle(), Toast.LENGTH_SHORT);
    if (midy < displayFrame.height()) {
        // Show along the top; follow action buttons
        cheatSheet.setGravity(Gravity.TOP | GravityCompat.END, referenceX, height);
    } else {
        // Show along the bottom center
        cheatSheet.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, height);
    }
    cheatSheet.show();
    return true;
}

From source file:br.com.GUI.avaliacoes.AvaliarPerimetria.java

private void cortar(int requestCode) {
     try {/*from  w  ww .  j av a 2s. c  o m*/
         //call the standard crop action intent (the user device may not support it)
         Intent cropIntent = new Intent("com.android.camera.action.CROP");
         //indicate image type and Uri
         cropIntent.setDataAndType(selectedImageUri, "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
         startActivityForResult(cropIntent, requestCode + 2);
     }
     //respond to users whose devices do not support the crop action
     catch (ActivityNotFoundException anfe) {
         //display an error message
         String errorMessage = "Whoops - your device doesn't support the crop action!";
         Toast toast = Toast.makeText(getActivity(), errorMessage, Toast.LENGTH_SHORT);
         toast.show();
     }
 }

From source file:applab.search.client.SynchronizationManager.java

/**
 * Our two background processes (downloading and parsing) communicate with us through Android messaging on the UI
 * thread (so we can react by manipulating UI)
 *//*from  w w  w.  j  av a2  s.c o m*/
void handleBackgroundThreadMessage(Message message) {
    switch (message.what) {
    case GlobalConstants.KEYWORD_DOWNLOAD_STARTING:
        // TODO: Can we do this on the UI thread before we offload the process into the background?
        // it would cleanup the code, allow us to easily thread in Global.SETUP_DIALOG when Storage is empty,
        // and avoid a few extra thread switches
        if (!this.launchedFromTimer) {
            ProgressDialogManager.displayProgressDialog(GlobalConstants.UPDATE_DIALOG, this.currentContext);
        }
        break;
    case GlobalConstants.CONNECTION_ERROR:
        ProgressDialogManager.tryDestroyProgressDialog();
        if (!this.launchedFromTimer) {
            showErrorDialog(R.string.connection_error_message);
        }
        break;
    case GlobalConstants.KEYWORD_DOWNLOAD_SUCCESS:
        // TODO: do we want to update the progress dialog here?
        // download complete, start parsing
        // NOTE: we do not dismiss the dialog, so that it shows until we receive
        // the Global.KEYWORD_PARSE_GOT_NODE_TOTAL signal
        break;
    case GlobalConstants.KEYWORD_DOWNLOAD_FAILURE:
        ProgressDialogManager.tryDestroyProgressDialog(); // Dialog may still be launched in background process
                                                          // as a side-effect
        if (!this.launchedFromTimer) {
            showErrorDialog(R.string.incomplete_keyword_response_error);
        }
        break;
    case GlobalConstants.KEYWORD_PARSE_GOT_NODE_TOTAL:
        int nodeCount = message.getData().getInt("nodeCount");
        if (!this.launchedFromTimer) {
            ProgressDialogManager.displayProgressDialog(GlobalConstants.PARSE_DIALOG, this.currentContext,
                    nodeCount);
        }
        break;
    case GlobalConstants.KEYWORD_PARSE_SUCCESS:
        ProgressDialogManager.tryDestroyProgressDialog();
        Toast updateToast = Toast.makeText(this.currentContext,
                this.currentContext.getString(R.string.refreshed), Toast.LENGTH_LONG);
        updateToast.show();
        // TODO: Decide whether to check for image updates here right after the keyword update and before
        // releasing the synchronization lock.
        // in the error case, this is updated on click of the error dialog "OK" button. On success
        // it should hit this path
        SynchronizationManager.completeSynchronization();
        break;
    case GlobalConstants.KEYWORD_PARSE_ERROR:
        ProgressDialogManager.tryDestroyProgressDialog();
        if (!this.launchedFromTimer) {
            showErrorDialog(R.string.keyword_parse_error);
        }
        break;
    case GlobalConstants.DISMISS_WAIT_DIALOG:
        ProgressDialogManager.tryDestroyProgressDialog();
        break;
    }

    if (this.completionCallback != null) {
        this.completionCallback.sendEmptyMessage(message.what);
    }
}

From source file:com.nijie.samples.facebookfoo.FacebookFooMainActivity.java

private void showPickerFragment(PickerFragment<?> fragment) {
    fragment.setOnErrorListener(new PickerFragment.OnErrorListener() {
        @Override//from w w w  .j av  a2  s .  c o m
        public void onError(PickerFragment<?> pickerFragment, FacebookException error) {
            String text = getString(R.string.exception, error.getMessage());
            Toast toast = Toast.makeText(FacebookFooMainActivity.this, text, Toast.LENGTH_SHORT);
            toast.show();
        }
    });

    FragmentManager fm = getSupportFragmentManager();
    fm.beginTransaction().replace(R.id.fragment_container, fragment).addToBackStack(null).commit();

    controlsContainer.setVisibility(View.GONE);

    // We want the fragment fully created so we can use it immediately.
    fm.executePendingTransactions();

    fragment.loadData(true);
}

From source file:org.ewicom.pps.unitinfo.TabAddressFragment.java

public void openUnitWebsite(View view) {

    Toast noWwwToast = Toast.makeText(getActivity().getApplicationContext(), R.string.no_www_app,
            Toast.LENGTH_LONG);/*from   w  w  w. j  av a 2 s. co m*/
    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(unit.getLink()));

    if (PPSAddressBook.isIntentAvailable(getActivity(), intent)) {
        startActivity(intent);
    } else {
        noWwwToast.show();
    }
}

From source file:com.actionbarsherlock.internal.view.menu.ActionMenuItemView.java

@Override
public boolean onLongClick(View v) {
    if (hasText()) {
        // Don't show the cheat sheet for items that already show text.
        return false;
    }//from   w w  w.  j a v a 2s.  co m

    final int[] screenPos = new int[2];
    final Rect displayFrame = new Rect();
    getLocationOnScreen(screenPos);
    getWindowVisibleDisplayFrame(displayFrame);

    final Context context = getContext();
    final int width = getWidth();
    final int height = getHeight();
    final int midy = screenPos[1] + height / 2;
    final int screenWidth = context.getResources().getDisplayMetrics().widthPixels;

    Toast cheatSheet = Toast.makeText(context, mItemData.getTitle(), Toast.LENGTH_SHORT);
    if (midy < displayFrame.height()) {
        // Show along the top; follow action buttons
        cheatSheet.setGravity(Gravity.TOP | Gravity.RIGHT, screenWidth - screenPos[0] - width / 2, height);
    } else {
        // Show along the bottom center
        cheatSheet.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, height);
    }
    cheatSheet.show();
    return true;
}

From source file:ch.luklanis.esscan.history.HistoryActivity.java

private Uri createDTAFile(long bankProfileId) {
    List<HistoryItem> historyItems = mHistoryManager.buildHistoryItemsForDTA(bankProfileId);
    BankProfile bankProfile = mHistoryManager.getBankProfile(bankProfileId);

    String error = dtaFileCreator.getFirstError(bankProfile, historyItems);

    if (!TextUtils.isEmpty(error)) {
        setOkAlert(error);/*  ww  w  .ja va2  s  . c om*/
        return null;
    }

    CharSequence dta = dtaFileCreator.buildDTA(bankProfile, historyItems);

    if (!dtaFileCreator.saveDTAFile(dta.toString())) {
        setOkAlert(R.string.msg_unmount_usb);
        return null;
    } else {
        Uri dtaFileUri = dtaFileCreator.getDTAFileUri();
        String dtaFileName = dtaFileUri.getLastPathSegment();

        new HistoryExportUpdateAsyncTask(mHistoryManager, dtaFileName)
                .execute(historyItems.toArray(new HistoryItem[historyItems.size()]));

        this.dtaFileCreator = new DTAFileCreator(getApplicationContext());

        Toast toast = Toast.makeText(this,
                getResources().getString(R.string.msg_dta_saved, dtaFileUri.getPath()), Toast.LENGTH_LONG);
        toast.setGravity(Gravity.BOTTOM, 0, 0);
        toast.show();

        return dtaFileUri;
    }
}