Example usage for android.widget Toast setText

List of usage examples for android.widget Toast setText

Introduction

In this page you can find the example usage for android.widget Toast setText.

Prototype

public void setText(CharSequence s) 

Source Link

Document

Update the text in a Toast that was previously created using one of the makeText() methods.

Usage

From source file:Main.java

/**
 * @param message/*  w w w  .  ja  v a  2s.c o m*/
 */
public static void showToast(int message, Toast mToast, Context context) {
    if (mToast == null) {
        mToast = Toast.makeText(context, "", Toast.LENGTH_SHORT);
    }
    mToast.setText(context.getString(message));
    mToast.show();
}

From source file:com.zerobyte.lifesync.EventDisplayActivity.java

private void showToast(String text) {
    Toast toast = Toast.makeText(getApplicationContext(), "", Toast.LENGTH_SHORT);
    toast.setGravity(Gravity.BOTTOM, 0, 0);
    toast.setText(text);

    toast.show();/*  ww  w. j a  v a 2  s. c o  m*/
}

From source file:saphion.pageindicators.FixedTabsView.java

/**
 * Initialize and add all tabs to the layout
 *///ww w.  ja  va 2 s  . c  o  m
private void initTabs() {

    removeAllViews();
    mTabs.clear();

    if (mAdapter == null)
        return;

    for (int i = 0; i < mPager.getAdapter().getCount(); i++) {

        final int index = i;

        View tab = mAdapter.getView(i);
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(0, LayoutParams.WRAP_CONTENT, 1.0f);
        tab.setLayoutParams(params);
        this.addView(tab);

        mTabs.add(tab);

        if (i != mPager.getAdapter().getCount() - 1) {
            this.addView(getSeparator());
        }

        tab.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                mPager.setCurrentItem(index);
            }
        });

        tab.setOnLongClickListener(new OnLongClickListener() {

            @Override
            public boolean onLongClick(View v) {
                //Toast t = new Toast(getContext());
                Toast t = Toast.makeText(mContext, "", Toast.LENGTH_SHORT);
                //t.setGravity(Gravity.TOP, v.getRight()/2 - v.getLeft()/2, v.getBottom());
                switch (index) {
                case 0:
                    t.setText("Power Profiles");
                    t.setGravity(Gravity.TOP | Gravity.LEFT, v.getLeft(), v.getBottom());
                    break;
                case 1:
                    t.setText("Battery Info");
                    t.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL, 0, v.getBottom());
                    break;
                case 2:
                    t.setText("Graph and Stats");
                    t.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL, 0, v.getBottom());
                    break;
                case 3:
                    t.setText("Battery Alarms");
                    t.setGravity(Gravity.TOP, v.getLeft(), v.getBottom());
                    break;

                }
                t.setDuration(Toast.LENGTH_SHORT);
                t.show();
                return true;
            }
        });

    }

    selectTab(mPager.getCurrentItem());
}

From source file:com.andrew67.ddrfinder.activity.MapViewer.java

@Override
public void showMessage(int resourceId) {
    final Toast oldToast = toasts.get(resourceId);
    if (oldToast == null) {
        final Toast newToast = Toast.makeText(this, resourceId, Toast.LENGTH_SHORT);
        toasts.put(resourceId, newToast);
        newToast.show();/*from  w w  w.j a  v a 2 s .com*/
    } else {
        oldToast.setText(resourceId);
        oldToast.show();
    }
}

From source file:hku.fyp14017.blencode.ui.fragment.ScriptFragment.java

public void updateAdapterAfterAddNewBrick(Brick brickToBeAdded) {
    int firstVisibleBrick = listView.getFirstVisiblePosition();
    int lastVisibleBrick = listView.getLastVisiblePosition();
    int position = ((1 + lastVisibleBrick - firstVisibleBrick) / 2);
    position += firstVisibleBrick;/*  w  ww . ja  v  a2  s . co  m*/

    //TODO: allow recursive userbricks if its possible
    if (adapter.getUserBrick() != null && brickToBeAdded instanceof UserBrick) {// && ((UserBrick) brickToBeAdded).getDefinitionBrick().equals(ProjectManager.getInstance().getCurrentUserBrick().getDefinitionBrick())) {
        Toast toast = null;
        if (toast == null || toast.getView().getWindowVisibility() != View.VISIBLE) {
            toast = Toast.makeText(getActivity().getApplicationContext(),
                    hku.fyp14017.blencode.R.string.recursive_user_brick_forbidden, Toast.LENGTH_LONG);
        } else {
            toast.setText(hku.fyp14017.blencode.R.string.recursive_user_brick_forbidden);
        }
        toast.show();
    } else {
        adapter.addNewBrick(position, brickToBeAdded, true);
        adapter.notifyDataSetChanged();
    }
}

From source file:biz.incomsystems.fwknop2.ConfigDetailFragment.java

public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();
    if (id == R.id.detail_help) {
        Intent detailIntent = new Intent(getActivity(), HelpActivity.class);
        startActivity(detailIntent);/*from  www  .  j  a v  a  2  s. c o  m*/
    } else if (id == R.id.qr_code) {
        try {
            Intent intent = new Intent("com.google.zxing.client.android.SCAN");
            intent.putExtra("SCAN_MODE", "QR_CODE_MODE"); // "PRODUCT_MODE for bar codes
            startActivityForResult(intent, 0);
        } catch (Exception e) { // This is where the play store is called if the app is not installed
            Uri marketUri = Uri.parse("market://details?id=com.google.zxing.client.android");
            Intent marketIntent = new Intent(Intent.ACTION_VIEW, marketUri);
            startActivity(marketIntent);
        }
    } else if (id == R.id.save) {
        InetAddressValidator ipValidate = new InetAddressValidator();
        Context context = getActivity(); // We know we will use a toast, so set it up now
        int duration = Toast.LENGTH_LONG;
        CharSequence text = "Saving config";
        Toast toast = Toast.makeText(context, text, duration);
        toast.setGravity(Gravity.CENTER, 0, 0);
        LinearLayout toastLayout = (LinearLayout) toast.getView();
        TextView toastTV = (TextView) toastLayout.getChildAt(0);
        toastTV.setTextSize(30);

        //The following is all input validation

        try {
            if ((Integer.parseInt(txt_server_port.getText().toString()) > 0)
                    && (Integer.parseInt(txt_server_port.getText().toString()) < 65535)) { // check for valid port
                txt_server_port.setText(String.valueOf(Integer.parseInt(txt_server_port.getText().toString())));
            } else {
                txt_server_port.setText(String.valueOf(62201));
            }
        } catch (NumberFormatException ex) {
            txt_server_port.setText(String.valueOf(62201));
        }
        if (txt_NickName.getText().toString().equalsIgnoreCase("")) { // Need to create a new Nick
            toast.setText("You Must choose a unique Nickname."); // choosing a used nick will just overwrite it. So really
            toast.show();
        } else if (chkb64hmac.isChecked() && txt_HMAC.getText().toString().length() % 4 != 0) { // base64 must have a multiple of 4 length
            toast.setText("Hmac is not a valid Base64, not a multiple of 4.");
            toast.show();
        } else if (chkb64hmac.isChecked()
                && !(txt_HMAC.getText().toString().matches("^[A-Za-z0-9+/]+={0,2}$"))) { // looks for disallowed b64 characters
            toast.setText("Hmac is not a valid Base64, Contains disallowed characters.");
            toast.show();
        } else if (chkb64key.isChecked() && txt_KEY.getText().toString().length() % 4 != 0) {
            toast.setText("Key is not a valid Base64, not a multiple of 4.");
            toast.show();
        } else if (chkb64key.isChecked() && !(txt_KEY.getText().toString().matches("^[A-Za-z0-9+/]+={0,2}$"))) { // looks for disallowed b64 characters
            toast.setText("Key is not a valid Base64, Contains disallowed characters.");
            toast.show();
        } else if (!(txt_ports.getText().toString().matches("tcp/\\d.*")
                || txt_ports.getText().toString().matches("udp/\\d.*"))) {
            toast.setText("Access ports must be in the form of 'tcp/22'");
            toast.show();
        } else if (spn_allowip.getSelectedItem().toString().equalsIgnoreCase("Allow IP")
                && (!ipValidate.isValid(txt_allowIP.getText().toString()))) { //Have to have a valid ip to allow, if using allow ip
            toast.setText("You Must supply a valid IP address to 'Allow IP'.");
            toast.show();
        } else if (!ipValidate.isValid(txt_server_ip.getText().toString())
                && !DomainValidator.getInstance().isValid(txt_server_ip.getText().toString())) { // check server entry. Must be a valid url or ip.
            toast.setText("You Must supply a valid server address.");
            toast.show();
        } else if (txt_KEY.getText().toString().equalsIgnoreCase("")) {
            toast.setText("You Must supply a Rijndael key.");
            toast.show();
        } else if (spn_ssh.getSelectedItem().toString().equalsIgnoreCase("Juicessh")
                && juice_adapt.getConnectionName(spn_juice.getSelectedItemPosition()) == null) {
            toast.setText("A connection must be saved in Juicessh before being used here.");
            toast.show();
            //            //end input validation, actual saving below
        } else {
            toast.show();
            if (configtype.equalsIgnoreCase("Open Port")) {
                config.PORTS = txt_ports.getText().toString();
                config.SERVER_TIMEOUT = txt_server_time.getText().toString();
            } else {
                config.PORTS = "";
                config.SERVER_TIMEOUT = "";
            }
            if (configtype.equalsIgnoreCase("Nat Access")) {
                config.NAT_IP = txt_nat_ip.getText().toString();
                config.NAT_PORT = txt_nat_port.getText().toString();
                config.PORTS = txt_ports.getText().toString();
                config.SERVER_TIMEOUT = txt_server_time.getText().toString();
            } else {
                config.NAT_IP = "";
                config.NAT_PORT = "";
            }
            if (configtype.equalsIgnoreCase("Server Command")) {
                config.SERVER_CMD = txt_server_cmd.getText().toString();
            } else {
                config.SERVER_CMD = "";
            }
            if (spn_allowip.getSelectedItem().toString().equalsIgnoreCase("Resolve IP")) {
                config.ACCESS_IP = spn_allowip.getSelectedItem().toString();
            } else if (spn_allowip.getSelectedItem().toString().equalsIgnoreCase("Source IP")) {
                config.ACCESS_IP = "0.0.0.0";
            } else {
                config.ACCESS_IP = txt_allowIP.getText().toString();
            }
            config.NICK_NAME = txt_NickName.getText().toString();
            config.SERVER_IP = txt_server_ip.getText().toString();
            config.SERVER_PORT = txt_server_port.getText().toString();
            config.SSH_CMD = "";
            if (spn_ssh.getSelectedItem().toString().equalsIgnoreCase("SSH Uri")) {
                config.SSH_CMD = txt_ssh_cmd.getText().toString();
                config.juice_uuid = UUID.fromString("00000000-0000-0000-0000-000000000000");
            } else if (spn_ssh.getSelectedItem().toString().equalsIgnoreCase("Juicessh")) {
                config.SSH_CMD = "juice:" + juice_adapt.getConnectionName(spn_juice.getSelectedItemPosition());
                config.juice_uuid = juice_adapt.getConnectionId(spn_juice.getSelectedItemPosition());
            } else {
                config.juice_uuid = UUID.fromString("00000000-0000-0000-0000-000000000000");
                config.SSH_CMD = "";
            }
            config.KEY = txt_KEY.getText().toString(); //key
            config.KEY_BASE64 = chkb64key.isChecked(); //is key b64
            config.HMAC = txt_HMAC.getText().toString(); // hmac key
            config.HMAC_BASE64 = chkb64hmac.isChecked(); //is hmac base64
            mydb.updateConfig(context, config);

            //this updates the list for one panel mode
            Activity activity = getActivity();
            if (activity instanceof ConfigListActivity) {
                ConfigListActivity myactivity = (ConfigListActivity) activity;
                myactivity.onItemSaved();

            } else {
                ConfigDetailActivity myactivity = (ConfigDetailActivity) activity;
                myactivity.onBackPressed();
            }
        }
    } else {
        return false;
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.devwang.logcabin.LogCabinMainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    Intent serverIntent = null;/*  w  w w  . ja  va  2  s  .  co m*/
    Toast toast = Toast.makeText(LogCabinMainActivity.this, "", Toast.LENGTH_LONG);
    toast.setGravity(Gravity.CENTER, 0, 0);
    switch (item.getItemId()) {
    case R.id.secure_connect_scan:// 
        // Launch the DeviceListActivity to see devices and do scan
        serverIntent = new Intent(this, DeviceListActivity.class);
        startActivityForResult(serverIntent, REQUEST_CONNECT_DEVICE_SECURE);
        return true;
    case R.id.insecure_connect_scan:// 
        // Launch the DeviceListActivity to see devices and do scan
        serverIntent = new Intent(this, DeviceListActivity.class);
        startActivityForResult(serverIntent, REQUEST_CONNECT_DEVICE_INSECURE);
        return true;
    case R.id.app_developer:
        toastDisplay(LogCabinMainActivity.this,
                ":   \n\nQQ:1120341494\n:dongleixiaxue314\n :http://www.devwang.com",
                Gravity.CENTER, R.drawable.hutview, Toast.LENGTH_SHORT);
        return true;
    case R.id.app_cmd_what:
    case R.id.app_voice_what:
        toast.setText(
                "\n\n\n\n...");
        toast.show();
        return true;
    case R.id.app_college:
        toast.setText(R.string.str_college);
        toast.show();
        return true;
    case R.id.app_web_url:
        toastDisplay(LogCabinMainActivity.this,
                getString(R.string.http_devwang_sinaapp_com_logcabin_logcabin_web_php), Gravity.CENTER, 0,
                Toast.LENGTH_SHORT);
        return true;
    case R.id.app_update:

        android.app.AlertDialog.Builder dialog = new AlertDialog.Builder(LogCabinMainActivity.this);
        LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        LinearLayout layout = (LinearLayout) inflater.inflate(R.layout.dialogview_appupdate, null);
        dialog.setView(layout);
        appUpdateEditText = (EditText) layout.findViewById(R.id.et_appupdate);
        dialog.setPositiveButton(R.string.str_app_update_sure, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                String appUpdateEditTextString = appUpdateEditText.getText().toString();
                if ("devwang".equals(appUpdateEditTextString.toString())) {
                    AppUpdate = true;
                    Toast.makeText(getApplicationContext(), R.string.str_app_update_pass_toast,
                            Toast.LENGTH_SHORT).show();
                }
            }
        });
        dialog.show();
        return true;
    }
    return false;
}

From source file:com.android.mail.compose.ComposeActivity.java

private void showErrorToast(String message) {
    Toast t = Toast.makeText(this, message, Toast.LENGTH_LONG);
    t.setText(message);
    t.setGravity(Gravity.CENTER_HORIZONTAL, 0,
            getResources().getDimensionPixelSize(R.dimen.attachment_toast_yoffset));
    t.show();/*from   www  .  ja  va 2  s .  c  o  m*/
}