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:ch.hackzurich.migrozept.ScanditSDKSampleBarcodeActivity.java

public void showToast(String txt) {
    Context context = getApplicationContext();
    CharSequence text = txt;/*from  w ww . j  ava  2 s  . c  o  m*/
    int duration = 10;

    Toast toast = Toast.makeText(context, text, duration);
    toast.show();
}

From source file:com.example.clienttest.AbstractGreenhouseActivity.java

protected void displayNetworkError() {
    Toast toast = Toast.makeText(this,
            "A problem occurred with the network connection while attempting to communicate with Greenhouse.",
            Toast.LENGTH_LONG);//from w ww.  j  av  a2 s .  co m
    toast.setGravity(Gravity.CENTER, 0, 0);
    toast.show();
}

From source file:org.peterbaldwin.client.android.tinyurl.SendTinyUrlActivity.java

private void copy() {
    Object service = getSystemService(CLIPBOARD_SERVICE);
    ClipboardManager clipboard = (ClipboardManager) service;
    clipboard.setText(mTinyUrl);/*from  w  ww.j a  v a 2s  .  c  o  m*/

    // Let the user know that the copy was successful.
    int resId = R.string.message_copied;
    Toast toast = Toast.makeText(this, resId, Toast.LENGTH_SHORT);
    toast.show();
    finish();
}

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

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle item selection
    switch (item.getItemId()) {
    case R.id.updateMenuItem:
        if (phoneDB == null)
            phoneDB = new PhoneOpenHelper(this);
        if (database == null)
            database = phoneDB.getWritableDatabase();
        API phoneApi = new API(this);
        String[] params = { "0" };
        if (!phoneApi.callMethod(Methods.phone, this, params)) {
            Toast msg = Toast.makeText(this, "Error: Calling phone", Toast.LENGTH_LONG);
            msg.show();
        }/*w  ww .java2  s .  co m*/
        return true;
    case R.id.updateApp:
        API updateAppApi = new API(this);
        if (!updateAppApi.callMethod(Methods.checkAppVersion, this)) {
            Toast msg = Toast.makeText(this, "Error: Couldn't get app version", Toast.LENGTH_LONG);
            msg.show();
        }
    default:
        return super.onOptionsItemSelected(item);
    }
}

From source file:com.accia77.mockey.ui.PapiroActivity.java

@Override
public void onResume() {
    super.onResume();

    setTitle(MyApplication.getInstance().getMainActivityTitle());

    massimaSceltaTextView = (TextView) findViewById(R.id.massimaSceltaTextView);
    String stringaTextView = currentEntry.getUserEditedEntry();

    if (mDoShowAndPlayQuote) {
        // Custom toast con il testo della frase
        LayoutInflater inflater = getLayoutInflater();
        View layout = inflater.inflate(R.layout.papiro_toast, (ViewGroup) findViewById(R.id.toast_layout_root));

        ImageView image = (ImageView) layout.findViewById(R.id.papiro_toast_image);
        image.setImageResource(R.drawable.ic_small_monkey_head);
        TextView text = (TextView) layout.findViewById(R.id.papiro_toast_text);
        text.setText(stringaTextView);/*from ww w . j  av  a 2  s.c om*/

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

        // Playback of the quote
        if (currentEntry.getEntryType() == MySQLiteHelper.ENTRY_TYPE_PURE_TEXT) {
            MyApplication.getInstance().playSelection(currentEntry);
        } else if (currentEntry.getEntryType() == MySQLiteHelper.ENTRY_TYPE_AUDIO) {
            // No playback if the sd card is not mounted
            if (MyApplication.getInstance().isSdCardMounted(false)) {
                MyApplication.getInstance().playSelection(currentEntry);
            }
        }

        mDoShowAndPlayQuote = false;
    }

    if (MyApplication.getInstance().isDefaultPapiroLoaded()) {
        massimaSceltaTextView.setText(stringaTextView);
        massimaSceltaTextView.setVisibility(View.VISIBLE);
    } else
        massimaSceltaTextView.setVisibility(View.INVISIBLE);

}

From source file:anomalyDetector.activities.MainFeaturesActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {

    if (!isServiceRunning) {
        Toast toast = Toast.makeText(getApplicationContext(), "Service not running", Toast.LENGTH_SHORT);
        toast.show();
        return false;
    }/*from w w w  .j a v  a 2  s  .  c o m*/

    switch (item.getItemId()) {
    case R.id.show_anon_pages:
        Intent intent = new Intent(this, RealTimeDataActivity.class);
        startActivity(intent);
        return true;
    default:
        return super.onOptionsItemSelected(item);
    }
}

From source file:br.ufsc.das.gtscted.shibbauth.ShibAuthenticationActivity.java

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

    setContentView(R.layout.idp_selection);
    loginButton = (Button) findViewById(R.id.loginButton);
    backButton = (Button) findViewById(R.id.backButton);
    usernameTxt = (EditText) findViewById(R.id.usernameTxt);
    passwordTxt = (EditText) findViewById(R.id.passwordTxt);
    idpSpinner = (Spinner) findViewById(R.id.idpSpinner);

    //Configura o ArrayAdapter do spinner.
    ArrayAdapter<CharSequence> spinnerArrayAdapter;
    spinnerArrayAdapter = new ArrayAdapter(this, android.R.layout.simple_spinner_item);
    spinnerArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    idpSpinner.setAdapter(spinnerArrayAdapter);

    // Obtm os parmetros passados pela Activity anterior 
    // (no caso, a pgina do WAYF como uma String e o
    // nico cookie da Connection usada anteriormente)
    Bundle bundle = this.getIntent().getExtras();
    String wayfHtml = bundle.getString("html_source");
    final String wayfLocation = bundle.getString("wayf_location");
    final SerializableCookie receivedCookie = (SerializableCookie) bundle.getSerializable("cookie");

    //Obtm todos os tags de nome "option", que correspondem
    // aos IdPs, da pgina do WAYF.
    Document wayfDocument = Jsoup.parse(wayfHtml);
    idpElements = wayfDocument.select("option");

    //Popula o spinner com os nomes dos IdPs encontrados.      
    for (Element idpElement : idpElements) {
        String idpName = idpElement.text();
        spinnerArrayAdapter.add(idpName);
    }

    // Obtm o caminho para o qual deve ser passado o IdP do usurio.
    formElements = wayfDocument.select("form");
    for (Element formElement : formElements) {
        if (formElement.attr("id").equals("IdPList")) {
            wayfActionPath = formElement.attr("action");
        }
    }

    loginButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // Obtm a URL correspondente ao idP selecionado no spinner.
            int selectedIdpPosition = idpSpinner.getSelectedItemPosition();
            Element selectedIdp = idpElements.get(selectedIdpPosition);
            selectedIdpUrl = selectedIdp.attr("value");

            try {
                // Obtm os campos "username" e "password" fornecidos
                // pelo usurio e necessrios para a autenticao.
                String username = usernameTxt.getText().toString();
                String password = passwordTxt.getText().toString();

                // Cria um novo objeto Connection, e adiciona o 
                // cookie passado pela Activity anterior.
                Connection connection = new Connection();
                BasicClientCookie newCookie = new BasicClientCookie(receivedCookie.getName(),
                        receivedCookie.getValue());
                newCookie.setDomain(receivedCookie.getDomain());
                connection.addCookie(newCookie);

                // Tenta realizar a autenticao no IdP selecionado. O resultado corresponde
                //  pgina para a qual o cliente  redirecionado em caso de autenticao 
                // bem-sucedida.
                String authResult = connection.authenticate(wayfLocation, wayfActionPath, selectedIdpUrl,
                        username, password);

                // Apenas mostra o recurso que o usurio queria acessar (neste caso, mostra a pg. de
                // "Homologao de atributos").
                Intent newIntent = new Intent(ShibAuthenticationActivity.this.getApplicationContext(),
                        TestActivity.class);
                Bundle bundle = new Bundle();
                bundle.putString("arg", authResult);
                newIntent.putExtras(bundle);
                startActivity(newIntent);

            } catch (IOException e) {
                String message = "IOException - problema na conexo";
                Toast toast = Toast.makeText(getApplicationContext(), message, Toast.LENGTH_LONG);
                toast.show();
            } catch (Exception e) {
                String message = "Exception - problema na autenticao";
                Toast toast = Toast.makeText(getApplicationContext(), message, Toast.LENGTH_LONG);
                toast.show();
            }
        }
    });

    backButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            finish();
        }
    });

}

From source file:com.mobshep.shepherdlogin.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    referenceXML();/*from   w  w w.  j  a v  a 2  s . c  om*/

    logPrefSession();
    logProviderSession();

    if (checkSession()) {
        Intent intent = new Intent(MainActivity.this, LoggedIn.class);
        startActivity(intent);
    }

    //TODO
    //Remove this and replace with AsyncTask
    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
    StrictMode.setThreadPolicy(policy);
    //end remove

    SharedPreferences SP = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
    String address = SP.getString("server_preference", "NA");

    Toast addressTest = Toast.makeText(MainActivity.this, "Server Address : " + address, Toast.LENGTH_LONG);
    addressTest.show();

}

From source file:com.hayageek.QRAuth.MainActivity.java

private void showText(String message) {
    Toast toast = Toast.makeText(getApplicationContext(), message, Toast.LENGTH_SHORT);
    toast.show();
}

From source file:com.mobshep.insufficienttls.MainActivity.java

public void submitClicked(View v) {

    if (username.getText().toString().equals("") || password.getText().toString().equals("")) {
        Toast blank = Toast.makeText(MainActivity.this, "Blank Fields Detected!", Toast.LENGTH_SHORT);
        blank.show();
        return;//from www .j a  va2 s .c  om
    }

    ArrayList<NameValuePair> postParameters = new ArrayList<NameValuePair>();
    postParameters.add(new BasicNameValuePair("login", username.getText().toString()));
    postParameters.add(new BasicNameValuePair("pwd", password.getText().toString()));

    try {

        SharedPreferences SP = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
        String address = SP.getString("server_preference", "NA");

        String res = CustomHttpClient.executeHttpPost(address + "/mobileLogin", postParameters);

        JSONObject jObject = new JSONObject(res);

        String response = jObject.getString("JSESSIONID");

        System.out.println("SessionId: " + response);

        response = response.replaceAll("\\s+", "");

        Toast responseError = Toast.makeText(MainActivity.this, response, Toast.LENGTH_SHORT);
        responseError.show();

        Log.i(TAG, "Server Response:" + response);

        if (response.contains(" ERROR ")) {
            tvResponse.setText("Invalid username or password");
        }

        if (res != null) {
            Toast valid = Toast.makeText(MainActivity.this, "Logged In!", Toast.LENGTH_SHORT);
            valid.show();

            storedPref = getSharedPreferences("Sessions", MODE_PRIVATE);
            toEdit = storedPref.edit();
            toEdit.putString("sessionId", response);
            toEdit.commit();

            //Intent intent = new Intent(MainActivity.this, LoggedIn.class);
            //startActivity(intent);

        } else {
            Toast.makeText(getBaseContext(), "Invalid Credentials!", Toast.LENGTH_SHORT).show();
        }
    } catch (Exception e) {

        if (e.toString().contains("ERROR")) {
            tvResponse.setText("Invalid Credentials");
        }

        else {

            Toast responseError = Toast.makeText(MainActivity.this, e.toString(), Toast.LENGTH_LONG);
            responseError.show();

            tvResponse.setText(e.toString());
        }
    }

}