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.lucapernini.misapp.Registration.java

public void showToast(String msg) {
    Log.i(TAG, "Misa Registration, showToast: " + msg);

    Toast toast = Toast.makeText(getApplicationContext(), msg, Toast.LENGTH_SHORT);
    toast.setGravity(Gravity.CENTER, toast.getXOffset() / 2, toast.getYOffset() / 2);
    toast.show();

}

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

@Override
public void onUpdatePlayerMessage(UpdatePlayerResponse update) {
    if (mCurrentGame == null) {
        return;/*  w w  w  . j  a  v  a  2  s . c  o  m*/
    }

    Player updatedPlayer = update.getUpdatedPlayer();

    if (!mCurrentGame.getPlayers().contains(update.getUpdatedPlayer())) {
        Log.d(TAG, "onUpdatePlayerMessage(): New player");
        mCurrentGame.getPlayers().add(updatedPlayer);

        /* Show a toast message informing the user that a new player has
         * joined the game.
         */
        final String playerName = updatedPlayer.getName();

        mUIHandler.post(new Runnable() {
            @Override
            public void run() {
                String text = getString(R.string.new_player_joined, playerName);
                Toast toast = Toast.makeText(getActivity(), text, Toast.LENGTH_SHORT);
                toast.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0);
                toast.show();
            }
        });
    } else {
        Log.d(TAG, "onUpdatePlayerMessage(): Existing player");
        int i = mCurrentGame.getPlayers().indexOf(updatedPlayer);
        Player old = mCurrentGame.getPlayers().get(i);
        mMap.updateMarkerForPlayer(updatedPlayer, old);
        mCurrentGame.getPlayers().set(i, updatedPlayer);
    }

    mMap.updatePlayerMarkerPosition(updatedPlayer);
}

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

private void initialiseVideo() {

    if (mediaElement == null) {
        Toast error = Toast.makeText(getApplicationContext(), getString(R.string.video_player_error),
                Toast.LENGTH_SHORT);// w w w  .  jav a 2 s.  c om
        error.show();
    }

    // Get settings
    final SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this);

    // Initialise Stream
    restService.initialiseStream(getApplicationContext(), 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"));

                    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(getApplicationContext(),
                            getString(R.string.video_player_error), Toast.LENGTH_SHORT);
                    error.show();
                }
            });
}

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

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

    // Release player and finish activity
    releasePlayer();/*from  w ww.  ja v a2s .co m*/
    getActivity().finish();
}

From source file:com.RSMSA.policeApp.Fragments.OffenceHistoryFragment.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
    Log.d(TAG, "results received");
    com.google.zxing.integration.android.IntentResult scanningResult = IntentIntegrator
            .parseActivityResult(requestCode, resultCode, intent);

    if (resultCode == getActivity().RESULT_OK) {
        /**//  ww  w  . j a v  a2  s  . c  o m
         * getting the scanned licence number to our temporary variable
         */
        scanContent = scanningResult.getContents();

        Log.d(TAG, scanContent + " SCANNED");

        license.setText(scanContent);
    } else if (resultCode == getActivity().RESULT_CANCELED) {
        Toast toast = Toast.makeText(getActivity(), "No scan data received!", Toast.LENGTH_SHORT);
        toast.show();
    }
}

From source file:rpassmore.app.fillthathole.ViewHazardActivity.java

public void submitClickHandler(View view) {
    switch (view.getId()) {
    case R.id.submit:

        String error = null;/*ww w .java  2s .c om*/
        try {
            WebSiteComms.submit(hazard);
        } catch (WebSiteCommsException e) {
            Log.e(getPackageName(), "Error submitting hazard", e);
            error = e.getMessage();
        }

        persistHazard();

        // TODO        
        // if photo has been submitted successfully set hasPhoto true
        /*
                String error = null;
                try {                            
                  HttpClient client = new DefaultHttpClient();  
                  String postURL = "http://www.fillthathole.org.uk/services/submit_hazard";
                  HttpPost post = new HttpPost(postURL); 
                  //hopefully dont need to set user agent
                  //post.setHeader("User-Agent", "Fill%20That%20Hole/1.11 CFNetwork/485.12.7 Darwin/10.4.0");      
                  ByteArrayEntity ent = new ByteArrayEntity(hazard.createSubmitStr().getBytes("UTF8"));          
                  ent.setContentType("application/x-www-form-urlencoded");       
                  post.setEntity(ent);          
                  HttpResponse responsePOST = client.execute(post);  
                  HttpEntity resEntity = responsePOST.getEntity();            
                  if (resEntity != null) {    
                    String result = EntityUtils.toString(resEntity);
                
                    JSONObject json = new JSONObject(result);
                    if(json != null) {
                      String hazard_id = json.getString("hazard_id");
                      String reporter_key = json.getString("reporter_key");
                      if(hazard_id == null || reporter_key == null) {
        //somekind of error occured try and get an error string
        error = json.getString("error");              
        Log.e(getPackageName(), "Error submitting hazard: " + error);
                      } else {
        //store the returned hazard key
        hazard.setHazardId(hazard_id);
        hazard.setReporterKey(reporter_key);
        hazard.setState(Hazard.State.SUBMITTED);
                
        persistHazard();
                      }
                    } else {
                      error = "Unreconised response from web server";              
                      Log.e(getPackageName(), "Error submitting hazard: empty response");
                    }
                  }
                } catch (Exception e) {          
                  error = "Web server could not contacted";
                  Log.e(getPackageName(), "Error submitting hazard", e);
                }            
        */
        //display any error to the user
        if (error != null) {
            Toast toast = Toast.makeText(getApplicationContext(), error, Toast.LENGTH_LONG);
            toast.show();
        } else {
            if (hazard.getPhoto() != null) {
                //submit the attached photo
                submitPhoto();
            }

            //inform user submission complete
            Toast toast = Toast.makeText(getApplicationContext(), "Hazard submitted successfully",
                    Toast.LENGTH_SHORT);
            toast.show();
        }
        break;
    }
    finish();
}

From source file:yulei.android.client.AndroidMobilePushApp.java

private String getMessage(int numOfMissedMessages) {
    String message = "";
    String linesOfMessageCount = getString(R.string.lines_of_message_count);
    if (numOfMissedMessages > 0) {
        String plural = numOfMissedMessages > 1 ? "s" : "";
        Log.i("onResume", "missed " + numOfMissedMessages + " message" + plural);
        tView.append("You missed " + numOfMissedMessages + " message" + plural + ". Your most recent was:\n");
        for (int i = 0; i < savedValues.getInt(linesOfMessageCount, 0); i++) {
            String line = "***" + savedValues.getString("MessageLine" + i, "") + "&&&&";
            message += (line + "\n");
        }//from   w w  w.  j  av a2s. c om
        NotificationManager mNotification = (NotificationManager) getSystemService(
                Context.NOTIFICATION_SERVICE);
        mNotification.cancel(R.string.notification_number);
        SharedPreferences.Editor editor = savedValues.edit();
        editor.putInt(this.numOfMissedMessages, 0);
        editor.putInt(linesOfMessageCount, 0);
        editor.commit();
    } else {
        Log.i("onResume", "no missed messages");
        Intent intent = getIntent();
        if (intent != null) {
            Bundle extras = intent.getExtras();
            if (extras != null) {

                String realData = extras.getString("default");
                // message += "___" +realData +"___";
                if (realData != null && realData.length() > 2) {
                    //addMarker(decodeJSONforLat(realData),decodeJSONforLon(realData));

                    if (realData.length() > 2) {
                        Log.e("here", realData);
                        try {

                            Toast toast = Toast.makeText(getApplicationContext(),
                                    decodeJSONforName(realData) + decodeJSONforTime(realData),
                                    Toast.LENGTH_SHORT);
                            toast.show();
                            Log.e("heres", "sssss");
                            //addMarker(decodeJSONforLat(realData),decodeJSONforLon(realData));
                            addMarker(decodeJSONforLat(realData), decodeJSONforLon(realData),
                                    decodeJSONforName(realData), decodeJSONforSentiment(realData),
                                    decodeJSONforScore(realData));
                            message = "\n" + decodeJSONforName(realData) + "\n" + decodeJSONforContent(realData)
                                    + "\n";
                            addHeatMap(decodeJSONforLat(realData), decodeJSONforLon(realData));
                            //addMarker((Double)decodeObj.get("latitute"),(Double)decodeObj.get("longitude"),(String)decodeObj.get("time"),(String)decodeObj.get("userName"));
                        } catch (Exception e) {
                            Log.e("exception", "Exception throwed");
                        }
                    }
                }
            }
        }
    }
    message += "\n";
    return message;
}

From source file:com.paramedic.mobshaman.fragments.AccionesDetalleServicioFragment.java

/**
 * Start the camera by dispatching a camera intent.
 *//*from ww  w  .  j  a v  a 2  s  . co m*/
protected void dispatchTakePictureIntent(boolean isFinishingService) {

    // Check if there is a camera.
    Context context = getActivity();
    PackageManager packageManager = context.getPackageManager();
    if (packageManager.hasSystemFeature(PackageManager.FEATURE_CAMERA) == false) {
        Toast.makeText(getActivity(), "This device does not have a camera.", Toast.LENGTH_SHORT).show();
        return;
    }

    // Camera exists? Then proceed...
    Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

    // Ensure that there's a camera activity to handle the intent
    DetalleServicioActivity activity = (DetalleServicioActivity) getActivity();
    if (takePictureIntent.resolveActivity(activity.getPackageManager()) != null) {
        // Create the File where the photo should go.
        // If you don't do this, you may get a crash in some devices.
        File photoFile = null;
        try {
            photoFile = createImageFile();
        } catch (IOException ex) {
            // Error occurred while creating the File
            Toast toast = Toast.makeText(activity, "There was a problem saving the photo...",
                    Toast.LENGTH_SHORT);
            toast.show();
        }
        // Continue only if the File was successfully created
        if (photoFile != null) {
            Uri fileUri = Uri.fromFile(photoFile);
            activity.setCapturedImageURI(fileUri);
            activity.setCurrentPhotoPath(fileUri.getPath());
            activity.setIsFinishingService(isFinishingService);
            takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, activity.getCapturedImageURI());

            startActivityForResult(takePictureIntent, REQUEST_TAKE_PHOTO);
        }
    }
}

From source file:com.tarsoft.openlibra.ollista.java

private void loadData(boolean refresh) {

    //If internet available
    if (checkConexion) {
        //initial load of OpenLibra
        //if refresh access to OpenLibra else access to BBDD
        if (refresh) {
            new consultaOL().execute();
        } else {//ww  w  . j  a v  a 2 s .co  m
            new consultaBBDDOL().execute();
        }
    } else {
        Context context = getApplicationContext();
        int duration = Toast.LENGTH_SHORT;
        Toast toast = Toast.makeText(context, getApplicationContext().getString(R.string.NoInternet), duration);
        toast.show();
    }

}

From source file:com.example.castCambot.MainActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == REQUEST_CODE && resultCode == RESULT_OK) {
        ArrayList<String> matches = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
        if (matches.size() > 0) {
            Log.d(TAG, matches.get(0));/*from  www  .jav a2 s.com*/
            //sendMessage(matches.get(0));
            Context context = getApplicationContext();
            int duration = Toast.LENGTH_SHORT;
            String text = matches.get(0);

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

            String goForward = "forward";
            String turnLeft = "left";
            String turnRight = "right";
            String goBackwards = "backward";

            if (text.contains(goForward)) {
                myHttpPost("go_forward");
                mySleep(1000);
                myHttpPost("stop");
            }

            if (text.contains(turnLeft)) {
                myHttpPost("turn_left");
                mySleep(500);
                myHttpPost("stop");

            }

            if (text.contains(turnRight)) {
                myHttpPost("turn_right");
                mySleep(500);
                myHttpPost("stop");

            }

            if (text.contains(goBackwards)) {
                myHttpPost("go_backward");
                mySleep(1000);
                myHttpPost("stop");

            }

            //auto trigger voiceButton on click
            //Button voiceButton = (Button) findViewById(R.id.voiceButton);
            //voiceButton.performClick();
        }
    }
    super.onActivityResult(requestCode, resultCode, data);
}