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.robertszkutak.androidexamples.imgurexample.ImgurExampleActivity.java

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

    if (auth == false) {
        if (browser == true)
            browser2 = true;//  w  w  w . j a  v  a2s.  c om

        if (browser == false) {
            browser = true;
            newIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(authURL));
            startActivity(newIntent);
        }

        if (browser2 == true) {
            Uri uri = getIntent().getData();
            uripath = uri.toString();

            if (uri != null && uripath.startsWith(OAUTH_CALLBACK_URL)) {
                String verifier = uri.getQueryParameter(OAuth.OAUTH_VERIFIER);
                try {

                    provider.retrieveAccessToken(consumer, verifier);

                    token = consumer.getToken();
                    secret = consumer.getTokenSecret();

                    final Editor editor = pref.edit();
                    editor.putString("IMGUR_OAUTH_TOKEN", token);
                    editor.putString("IMGUR_OAUTH_TOKEN_SECRET", secret);
                    editor.commit();

                    auth = true;
                    loggedin = true;

                } catch (OAuthMessageSignerException e) {
                    e.printStackTrace();
                } catch (OAuthNotAuthorizedException e) {
                    e.printStackTrace();
                } catch (OAuthExpectationFailedException e) {
                    e.printStackTrace();
                } catch (OAuthCommunicationException e) {
                    e.printStackTrace();
                }
            }
        }
    }

    if (auth == true) {
        setContentView(R.layout.main);

        path = (EditText) findViewById(R.id.imagepath);
        debugStatus = (TextView) findViewById(R.id.debug_status);
        upload = (Button) findViewById(R.id.upload);
        loginorout = (Button) findViewById(R.id.loginout);

        debug = "Access Token: " + token + "\n\nAccess Token Secret: " + secret;
        debugStatus.setText(debug);

        upload.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                if (isAuthenticated()) {
                    uploadImage();
                } else {
                    Toast toast = Toast.makeText(getApplicationContext(), "You are not logged into Imgur",
                            Toast.LENGTH_SHORT);
                    toast.show();
                }
            }
        });

        loginorout.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                LogInOrOut();
            }
        });

        updateLoginStatus();
    }

    if (auth == false && browser2 == true)
        finish();
}

From source file:com.nokia.example.capturetheflag.Controller.java

/**
 * Displays the connection status using a toast message.
 *///from  w  ww.j  a  va2 s .com
@Override
public void onNetworkStateChange(final boolean isConnected, final NetworkClient client) {
    Log.d(TAG, "onNetworkStateChange(): " + (isConnected ? "Online" : "Offline"));

    mUIHandler.post(new Runnable() {
        @Override
        public void run() {
            boolean showToast = false;

            if (mIsConnected == -1 || (isConnected && mIsConnected == 0)
                    || (!isConnected && mIsConnected == 1)) {
                showToast = true;
            }

            Activity activity = getActivity();

            if (showToast && activity != null) {
                final int toastTextId = isConnected ? R.string.connected_to_server
                        : R.string.not_connected_to_server;

                Toast toast = Toast.makeText(activity, getString(toastTextId), Toast.LENGTH_SHORT);
                toast.show();
                mIsConnected = isConnected ? 1 : 0;
            }

            // Hide the progress bar from game menu fragment, if visible
            GameMenuFragment gameMenuFragment = (GameMenuFragment) getFragmentManager()
                    .findFragmentByTag(GameMenuFragment.FRAGMENT_TAG);

            if (gameMenuFragment != null && gameMenuFragment.isVisible()) {
                gameMenuFragment.setProgressBarVisibility(false);
            }
        }
    });
}

From source file:com.scooter1556.sms.android.activity.VideoPlayerActivity.java

@Override
public void onError(Exception e) {
    // Display error message
    Toast warning = Toast.makeText(this, getString(R.string.error_media_playback), Toast.LENGTH_SHORT);
    warning.show();

    // Release player and finish activity
    releasePlayer();//from  w  ww. ja  v a 2 s .c om
    finish();
}

From source file:gr.rambou.secheader.MainActivity.java

private void getHeader(String url) {
    //Create a Listener for our requests
    Response.Listener listener = new Response.Listener<JSONObject>() {
        @Override//from   w w w . jav a 2 s. com
        public void onResponse(JSONObject newjson) {
            //Check if we need to save into database
            CheckBox cb = (CheckBox) findViewById(R.id.checkbox_save);
            if (cb.isChecked()) {
                //We open/create our sqlite database
                DatabaseHandler mydb = new DatabaseHandler(getApplicationContext());

                //Loop over all results
                for (int i = 0; i < newjson.names().length(); i++) {
                    try {
                        //Check if the value is URL and don't insert it into db
                        String value = newjson.names().getString(i).toString();
                        if (!value.equals("URL"))
                            //Add result into database
                            mydb.addResult(newjson.getString("URL"), value,
                                    (newjson.get(newjson.names().getString(i)).equals("Secure")) ? 1 : 0);
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }
            }
            /*
            for (int i = 0; i < newjson.names().length(); i++) {
            try {
                Log.wtf("LOL", "key = " + newjson.names().getString(i) + " value = " + newjson.get(newjson.names().getString(i)));
            } catch (JSONException e) {
                e.printStackTrace();
            }
            }*/

            //decrease requests value;
            requests--;

            //Update progressBar
            int max = ((ProgressBar) findViewById(R.id.progressBar)).getMax();
            ((ProgressBar) findViewById(R.id.progressBar)).setProgress(max - requests);

            //Check if we finished
            if (requests == 1) {
                //Sending a toast to the user that we got all headers
                Context context = getApplicationContext();
                CharSequence text = "We Got all Headers!!!";
                int duration = Toast.LENGTH_SHORT;
                Toast toast = Toast.makeText(context, text, duration);
                toast.setGravity(Gravity.CENTER | Gravity.CENTER, 0, 0);
                toast.show();
                //Re-Enable Buttons functionality
                (findViewById(R.id.button_scan)).setEnabled(true);
                (findViewById(R.id.checkbox_save)).setEnabled(true);
            }

        }
    };
    //Create an Error Listener for our requests
    Response.ErrorListener errorListener = new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            if (error.networkResponse != null) {
                Log.v("Error Response code", String.valueOf(error.networkResponse.statusCode));
            }
        }
    };

    // Request a string response from the provided URL.
    JsonObjectRequest stringRequest = new JsonObjectRequest(Request.Method.HEAD, //We only want the headers, although it's similar with GET.
            url, //our url
            listener, //our listener, handling our findings
            errorListener) { //Error Listener to handle errors in requests

        @Override
        protected Response<JSONObject> parseNetworkResponse(NetworkResponse response) {
            try {
                //We create a JSONObject and add the url address to it.
                org.json.JSONObject f = new JSONObject(response.headers).put("URL", this.getUrl());

                /*We return the headers as a JSONObject which,
                we filter the headers and return the security ones*/
                return Response.success(FilterHeaders(f), HttpHeaderParser.parseCacheHeaders(response));
            } catch (JSONException e) {
                return Response.error(new ParseError(e));
            }
        }

    };

    // Add the request to the RequestQueue.
    queue.add(stringRequest);

}

From source file:io.openkit.leaderboards.OKScoresFragment.java

private void showError() {
    if (this.getActivity() != null) {
        Toast toast = Toast.makeText(this.getActivity(), "Couldn't connect to server to get leaderboards",
                Toast.LENGTH_LONG);//from w  ww  .j av a 2  s. c o m
        toast.show();
    }
}

From source file:org.silena.main.RegistrationOld.java

private void RenderError(String massage) {

    LayoutInflater inflater = getLayoutInflater();
    View layout = inflater.inflate(R.layout.toast_error, (ViewGroup) findViewById(R.id.toast_layout_root));

    TextView text = (TextView) layout.findViewById(R.id.text);
    text.setText(massage);/*ww  w.java  2  s.c  o  m*/

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

From source file:com.photon.phresco.nativeapp.eshop.activity.PhrescoActivity.java

/**
 * Make a standard toast that just contains a text view with the text from a
 * resource.//from ww  w . j  a  v a2  s  .c  o  m
 *
 * @param str
 *            The resource id of the string resource to use. Can be
 *            formatted text.
 * @param length
 *            How long to display the message. Either LENGTH_SHORT or
 *            LENGTH_LONG
 */
public void toast(int str, int length) {
    Toast toast = Toast.makeText(this, str, length);
    toast.setGravity(LinearLayout.VERTICAL, 0, 0);
    toast.show();
}

From source file:com.cubic9.android.droidglove.Main.java

/**
 * show short message by Toast/*w ww .  j  a  v  a  2 s.  c  om*/
 * @param code message code
 */
private void showToast(int code) {
    Toast toast = Toast.makeText(Main.this, getString(code), Toast.LENGTH_SHORT);
    toast.setGravity(Gravity.CENTER, 0, 0);
    toast.show();
}

From source file:net.stefanopallicca.android.awsmonitor.MainActivity.java

/**
 * Registers the application with GCM servers asynchronously.
 * <p>//w  w w  .ja  v  a2  s.c  o  m
 * Stores the registration ID and the app versionCode in the application's
 * shared preferences.
 * @return 
 */
private void registerInBackground() {
    new AsyncTask<Void, Void, String>() {

        ProgressDialog pd;

        @Override
        protected void onPreExecute() {
            pd = new ProgressDialog(MainActivity.this);
            pd.setTitle("Processing...");
            pd.setMessage("Please wait.");
            pd.setCancelable(false);
            pd.setIndeterminate(true);
            pd.show();
        }

        @Override
        protected String doInBackground(Void... params) {
            String msg = "";
            try {
                if (gcm == null) {
                    gcm = GoogleCloudMessaging.getInstance(context);
                }
                regid = gcm.register(SENDER_ID);
                //msg = "Device registered, registration ID=" + regid;

                // Persist the regID - no need to register again.

                storeRegistrationId(context, regid);
                /**
                 * Send regid to GSN server
                 */
                try {
                    if (server.sendRegistrationIdToBackend(regid))
                        msg = "ok";
                    else
                        msg = "ko";
                } catch (HttpException e) {
                    msg = "ko";
                }
            } catch (IOException ex) {
                msg = "ko";
            }
            return msg;
        }

        @Override
        protected void onPostExecute(String msg) {
            //mDisplay.append(msg + "\n");
            if (msg == "ok") {
                Context context = getApplicationContext();
                CharSequence text = getString(R.string.device_registered) + " "
                        + MainActivity.this._sharedPref.getString("pref_server_url", "") + ":"
                        + MainActivity.this._sharedPref.getString("pref_server_port", "");
                int duration = Toast.LENGTH_LONG;

                Toast toast = Toast.makeText(context, text, duration);
                toast.show();
            } else {
                Context context = getApplicationContext();
                CharSequence text = getString(R.string.error_connecting) + " "
                        + MainActivity.this._sharedPref.getString("pref_server_url", "") + ":"
                        + MainActivity.this._sharedPref.getString("pref_server_port", "");
                int duration = Toast.LENGTH_LONG;

                Toast toast = Toast.makeText(context, text, duration);
                toast.show();
            }
            pd.cancel();
            launchMainApp();
        }
    }.execute(null, null, null);
}

From source file:no.ntnu.idi.socialhitchhiking.Main.java

/**
 * Method to show connection settings. E.g if you're connected
 * to the internet or not./*from  w  w  w . j ava 2 s.c o  m*/
 */
public void checkSettings() {
    try {
        SettingsManager s = getApp().getSettings();

        if (s.isCheckSettings() && !getApp().isKey("main")) {
            if (s.isWifi() && s.isOnline()) {
                Toast msg = Toast.makeText(getApp(), "Connected", 1);
                msg.show();
            }
            if (s.isWifi() && !s.isOnline()) {
                Toast msg = Toast.makeText(getApp(),
                        "WiFi is enabled but you're not connected to the internet.", 1);
                msg.show();
            }
            if (!s.isWifi()) {
                Toast msg = Toast.makeText(getApp(), "WiFi is disabled!", 1);
                msg.show();
            }
            if (!s.isBackgroundData()) {
                Toast msg = Toast.makeText(getApp(), "BackgroundData is disabled!", 1);
                msg.show();
            }
        }
    } catch (NullPointerException e) {

    }

}