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.music.mybarr.activities.ExampleActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.login);// www  .j a  v a 2 s .  c om

    api = new ApiController();
    barLocation.setLatitude(37.78255);
    barLocation.setLongitude(-122.39091);

    trackQueue = new LinkedList<Track>();

    // Initialize our Rdio object.  If we have cached access credentials, then use them - otherwise
    // Initialize w/ null values and the user will be prompted (if the Rdio app is installed), or
    // we'll fallback to 30s samples.
    if (rdio == null) {
        SharedPreferences settings = getPreferences(MODE_PRIVATE);
        accessToken = settings.getString(PREF_ACCESSTOKEN, null);
        accessTokenSecret = settings.getString(PREF_ACCESSTOKENSECRET, null);

        rdio = new Rdio(appKey, appSecret, accessToken, accessTokenSecret, this, this);

        if (accessToken == null || accessTokenSecret == null) {
            // If either one is null, reset both of them
            accessToken = accessTokenSecret = null;
            Intent myIntent = new Intent(ExampleActivity.this, OAuth1WebViewActivity.class);
            myIntent.putExtra(OAuth1WebViewActivity.EXTRA_CONSUMER_KEY, appKey);
            myIntent.putExtra(OAuth1WebViewActivity.EXTRA_CONSUMER_SECRET, appSecret);
            ExampleActivity.this.startActivityForResult(myIntent, 1);

        } else {
            Log.d(TAG, "Found cached credentials:");
            Log.d(TAG, "Access token: " + accessToken);
            Log.d(TAG, "Access token secret: " + accessTokenSecret);
            //rdio.prepareForPlayback();
        }

    }

    Button usrData = (Button) findViewById(R.id.getUsrData);
    usrData.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            getUserData();
        }
    });

    usrDataTxt = (TextView) findViewById(R.id.userData);

    //check if I'm there
    if (!amIThere()) {
        Toast toast = Toast.makeText(getApplicationContext(),
                "You are not in the bar, you definetly should be!", Toast.LENGTH_LONG);
        toast.show();
    } else {
        //sendMyData();
    }
    ;

    //every 10 min
    handler = new Handler();
    handler.postDelayed(new Runnable() {
        @Override
        public void run() {
            try {
                if (!amIThere()) {
                    //tell the api that I'm not there anymore
                }
            } catch (Exception e) {

            }
            handler.postDelayed(this, 600 * 1000);
        }
    }, 600 * 1000);
}

From source file:net.homelinux.penecoptero.android.citybikes.app.MainActivity.java

public void changeMode(boolean getBike) {
    this.getBike = getBike;
    mDbHelper.changeMode(this.getBike);
    this.populateList(this.view_all);
    infoLayer.update();/* w  ww. ja v  a 2 s .  c om*/
    mapView.invalidate();
    Toast toast;
    if (getBike) {
        toast = Toast.makeText(getApplicationContext(), getString(R.string.get_bike_mode), Toast.LENGTH_SHORT);
    } else {
        toast = Toast.makeText(getApplicationContext(), getString(R.string.park_bike_mode), Toast.LENGTH_SHORT);
    }
    toast.show();
}

From source file:android.support.v7.app.MediaRouteButton.java

@Override
public boolean performLongClick() {
    if (super.performLongClick()) {
        return true;
    }//from   ww  w .j av  a2 s  .  c o m

    if (!mCheatSheetEnabled) {
        return false;
    }

    final CharSequence contentDesc = getContentDescription();
    if (TextUtils.isEmpty(contentDesc)) {
        // Don't show the cheat sheet if we have no description
        return false;
    }

    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, contentDesc, Toast.LENGTH_SHORT);
    if (midy < displayFrame.height()) {
        // Show along the top; follow action buttons
        cheatSheet.setGravity(Gravity.TOP | GravityCompat.END, screenWidth - screenPos[0] - width / 2, height);
    } else {
        // Show along the bottom center
        cheatSheet.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, height);
    }
    cheatSheet.show();
    performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
    return true;
}

From source file:net.mypapit.mobile.myrepeater.RepeaterListActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {

    Intent intent;/*from w  ww . ja v  a  2s  . c  o  m*/
    switch (item.getItemId()) {
    case R.id.show_map:
        intent = new Intent(getApplicationContext(), DisplayMap.class);
        intent.putExtra("LatLong", new LatLng(xlocation.getLatitude(), xlocation.getLongitude()));

        startActivity(intent);

        return true;
    case R.id.manual_settings:
        if (!this.isLocationEnabled(this)) {
            intent = new Intent(getApplicationContext(), StaticLocationActivity.class);
            startActivity(intent);
        } else {
            this.showAlertDialog();
        }
        return true;

    case R.id.action_about:
        try {
            showDialog();
        } catch (NameNotFoundException ex) {
            Toast toast = Toast.makeText(this, ex.toString(), Toast.LENGTH_SHORT);
            toast.show();

        }

        return true;
    case R.id.action_suggest:

        intent = new Intent(getApplicationContext(), SuggestRepeaterStartActivity.class);
        this.startActivity(intent);

        return true;

    case R.id.action_contrib:
        intent = new Intent();
        intent.setClassName(getApplicationContext(), "net.mypapit.mobile.myrepeater.ContribActivity");
        startActivity(intent);

        return true;

    case R.id.action_settings:
        intent = new Intent(getApplicationContext(), SettingsActivity.class);
        mrefresh = true;
        startActivity(intent);

        return true;

    case R.id.search:
        if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB) {
            Toast.makeText(this, "Search is unavailable for Gingerbread (2.3.7) and below", Toast.LENGTH_LONG)
                    .show();
        }

        return true;

    case R.id.action_simplex:
        intent = new Intent(getApplicationContext(), SimplexActivity.class);
        startActivity(intent);
        return true;

    }

    return false;
}

From source file:br.com.bioscada.apps.biotracks.TrackListActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    Intent intent;//  w  w  w. j ava 2  s  . co  m
    switch (item.getItemId()) {
    case R.id.track_list_search:
        return ApiAdapterFactory.getApiAdapter().handleSearchMenuSelection(this);
    case R.id.track_list_start_gps:
        MyTracksLocationManager myTracksLocationManager = new MyTracksLocationManager(this, Looper.myLooper(),
                false);
        if (!myTracksLocationManager.isGpsProviderEnabled()) {
            intent = GoogleLocationUtils.newLocationSettingsIntent(TrackListActivity.this);
            startActivity(intent);
        } else {
            startGps = !TrackRecordingServiceConnectionUtils.isRecordingServiceRunning(this);

            // Show toast
            Toast toast = Toast.makeText(this, startGps ? R.string.gps_starting : R.string.gps_stopping,
                    Toast.LENGTH_SHORT);
            toast.setGravity(Gravity.CENTER, 0, 0);
            toast.show();

            // Invoke trackRecordingService
            if (startGps) {
                trackRecordingServiceConnection.startAndBind();
                bindChangedCallback.run();
            } else {
                ITrackRecordingService trackRecordingService = trackRecordingServiceConnection
                        .getServiceIfBound();
                if (trackRecordingService != null) {
                    try {
                        trackRecordingService.stopGps();
                    } catch (RemoteException e) {
                        Log.e(TAG, "Unable to stop gps.", e);
                    }
                }
                trackRecordingServiceConnection.unbindAndStop();
            }

            // Update menu after starting or stopping gps
            ApiAdapterFactory.getApiAdapter().invalidMenu(this);
        }
        myTracksLocationManager.close();
        return true;
    case R.id.track_list_play_mutliple:
        PlayMultipleDialogFragment.newInstance(-1L).show(getSupportFragmentManager(),
                PlayMultipleDialogFragment.PLAY_MULTIPLE_DIALOG_TAG);
        return true;
    case R.id.track_list_sync_now:
        if (driveSync) {
            SyncUtils.syncNow(this);
        } else {
            new ChooseAccountDialogFragment().show(getSupportFragmentManager(),
                    ChooseAccountDialogFragment.CHOOSE_ACCOUNT_DIALOG_TAG);
        }
        return true;
    case R.id.track_list_aggregated_statistics:
        intent = IntentUtils.newIntent(this, AggregatedStatsActivity.class);
        startActivity(intent);
        return true;
    case R.id.track_list_export_all:
        FileTypeDialogFragment.newInstance(R.id.track_list_export_all, R.string.export_all_title,
                R.string.export_all_option, 4)
                .show(getSupportFragmentManager(), FileTypeDialogFragment.FILE_TYPE_DIALOG_TAG);
        return true;
    case R.id.track_list_import_all:
        FileTypeDialogFragment
                .newInstance(R.id.track_list_import_all, R.string.import_selection_title,
                        R.string.import_selection_option, 2)
                .show(getSupportFragmentManager(), FileTypeDialogFragment.FILE_TYPE_DIALOG_TAG);
        return true;
    case R.id.track_list_delete_all:
        deleteTracks(new long[] { -1L });
        return true;
    case R.id.track_list_settings:
        intent = IntentUtils.newIntent(this, SettingsActivity.class);
        startActivity(intent);
        return true;
    case R.id.track_list_help_feedback:
        intent = IntentUtils.newIntent(this, HelpActivity.class);
        startActivity(intent);
        return true;
    default:
        return super.onOptionsItemSelected(item);
    }
}

From source file:com.google.fpl.voltair.VoltAirActivity.java

private void showAchievementToast(final String prefix, final String achievementName) {
    runOnUiThread(new Runnable() {
        public void run() {
            Toast toast = Toast.makeText(VoltAirActivity.this,
                    String.format("%s: %s", prefix, getAchievementTitle(achievementName)), Toast.LENGTH_LONG);
            toast.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL, 0, 0);
            toast.show();
        }/*www.  j a v  a2 s  . co m*/
    });
}

From source file:com.example.shoe.DirectionsTest.java

public LatLng getDestinationCoordinates(String picID) {

    // call DB method
    DatabaseHandler mDB = new DatabaseHandler(this);

    try {/* w w w  . j ava2  s .com*/
        mDB.createDatabase();
    } catch (IOException ioe) {
        throw new Error("Unable to create database");
    }
    try {
        mDB.openDatabase();
    } catch (SQLException sqle) {
        throw sqle;
    }

    double mLat = 0;
    double mLon = 0;
    String place = null;

    Cursor mPlaces = mDB.fetchPicforId(picID);
    if (mPlaces != null) {
        mPlaces.moveToFirst();
        // misnamed the columns ... FIX
        int mLatCol = mPlaces.getColumnIndex("longitude");
        mLat = mPlaces.getDouble(mLatCol);
        // misnamed the columns ... FIX
        int mLonCol = mPlaces.getColumnIndex("latitude");
        mLon = mPlaces.getDouble(mLonCol);
        int placeCol = mPlaces.getColumnIndex("name");
        place = mPlaces.getString(placeCol);
    }

    mDB.close();

    // get lat
    //double lat_value = Double.parseDouble(mLat);
    // get lon
    //double lon_value = Double.parseDouble(mLon);

    LatLng mDestination = new LatLng(mLat, mLon);
    //mDestination.latitude = 45.123456;

    Context context = getApplicationContext();
    CharSequence text = "Your place is " + mDestination.latitude + " , " + mDestination.longitude + "\n"
            + "Place : " + place;
    int duration = Toast.LENGTH_LONG;

    Toast toast = Toast.makeText(context, text, duration);
    toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
    toast.show();

    //getLocation();
    //mMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.mapFrag)).getMap();
    //LatLng destMarker = new LatLng(mDestination.latitude, mDestination.longitude); 

    return mDestination;

}

From source file:edu.cmu.mpcs.dashboard.TagViewer.java

@Override
public void onNewIntent(Intent intent) {
    setIntent(intent);//from   ww w. j av  a 2s  .c  o  m
    Log.d("TAG_VIEWER", "on new intent actually fired ");
    if (!mWriteMode && NfcAdapter.ACTION_NDEF_DISCOVERED.equals(intent.getAction())) {

        resolveIntent(intent);
    }

    // Tag writing mode
    if (writeContent != null && NfcAdapter.ACTION_NDEF_DISCOVERED.equals(intent.getAction())) {
        Log.d("TAG_VIEWER", "in Oncreate Before writing");

        // new AlertDialog.Builder(TagViewer.this)
        // .setTitle("Touch tag to write")
        // .setOnCancelListener(
        // new DialogInterface.OnCancelListener() {
        // public void onCancel(DialogInterface dialog) {
        // disableTagWriteMode();
        //
        // }
        // }).create().show();

        Tag detectedTag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
        try {
            WriteToTag.write(detectedTag, writeContent);
            Context context = getApplicationContext();
            CharSequence text = "Tag sucessfully written!!";
            int duration = Toast.LENGTH_LONG;
            Toast toast = Toast.makeText(context, text, duration);
            toast.show();

            Log.d("TAG_VIEWER", "Before calling dialog.cancel");
            dialog.dismiss();
            finish();

        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (FormatException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        Log.d("TAG_VIEWER", "in on create, writing to tag");
    }
    //
    // // Tag writing mode
    // if (mWriteMode
    // &&
    // NfcAdapter.ACTION_NDEF_DISCOVERED.equals(intent.getAction()))
    // {
    // Tag detectedTag =
    // intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
    // try {
    // WriteToTag.write(detectedTag);
    // } catch (IOException e) {
    // // TODO Auto-generated catch block
    // e.printStackTrace();
    // } catch (FormatException e) {
    // // TODO Auto-generated catch block
    // e.printStackTrace();
    // }
    // Log.d("TAG_VIEWER", "in on new intent, writing to tag");
    // }
}

From source file:net.homelinux.penecoptero.android.citybikes.donation.app.MainActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);//from www .j a v a2  s .co  m
    PreferenceManager.setDefaultValues(this, R.xml.preferences, false);
    mapView = (MapView) findViewById(R.id.mapview);
    mSlidingDrawer = (StationSlidingDrawer) findViewById(R.id.drawer);
    infoLayer = (InfoLayer) findViewById(R.id.info_layer);
    scale = getResources().getDisplayMetrics().density;
    //Log.i("CityBikes","ON CREATEEEEEEEEE!!!!!");
    infoLayerPopulator = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            if (msg.what == InfoLayer.POPULATE) {
                infoLayer.inflateStation(stations.getCurrent());

            }
            if (msg.what == CityBikes.BOOKMARK_CHANGE) {
                int id = msg.arg1;
                boolean bookmarked;
                if (msg.arg2 == 0) {
                    bookmarked = false;
                } else {
                    bookmarked = true;
                }
                StationOverlay station = stations.getById(id);
                try {
                    BookmarkManager bm = new BookmarkManager(getApplicationContext());
                    bm.setBookmarked(station.getStation(), !bookmarked);
                } catch (Exception e) {
                    Log.i("CityBikes", "Error bookmarking station");
                    e.printStackTrace();
                }

                if (!view_all) {
                    view_near();
                }
                mapView.postInvalidate();
            }
        }
    };

    infoLayer.setHandler(infoLayerPopulator);
    RelativeLayout.LayoutParams zoomControlsLayoutParams = new RelativeLayout.LayoutParams(
            android.view.ViewGroup.LayoutParams.WRAP_CONTENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT);
    zoomControlsLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
    zoomControlsLayoutParams.addRule(RelativeLayout.CENTER_HORIZONTAL);

    mapView.addView(mapView.getZoomControls(), zoomControlsLayoutParams);

    modeButton = (ToggleButton) findViewById(R.id.mode_button);

    modeButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            changeMode(!getBike);
        }

    });

    applyMapViewLongPressListener(mapView);

    settings = getSharedPreferences(CityBikes.PREFERENCES_NAME, 0);

    List<Overlay> mapOverlays = mapView.getOverlays();

    locator = new Locator(this, new Handler() {
        @Override
        public void handleMessage(Message msg) {
            if (msg.what == Locator.LOCATION_CHANGED) {
                GeoPoint point = new GeoPoint(msg.arg1, msg.arg2);
                hOverlay.moveCenter(point);
                mapView.getController().animateTo(point);
                mDbHelper.setCenter(point);
                // Location has changed
                try {
                    mDbHelper.updateDistances(point);
                    infoLayer.update();
                    if (!view_all) {
                        view_near();
                    }
                } catch (Exception e) {

                }
                ;
            }
        }
    });

    hOverlay = new HomeOverlay(locator.getCurrentGeoPoint(), new Handler() {
        @Override
        public void handleMessage(Message msg) {
            if (msg.what == HomeOverlay.MOTION_CIRCLE_STOP) {
                try {
                    if (!view_all) {
                        view_near();
                    }
                    mapView.postInvalidate();
                } catch (Exception e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        }
    });

    stations = new StationOverlayList(mapOverlays, new Handler() {
        @Override
        public void handleMessage(Message msg) {
            //Log.i("CityBikes","Message: "+Integer.toString(msg.what)+" "+Integer.toString(msg.arg1));
            if (msg.what == StationOverlay.TOUCHED && msg.arg1 != -1) {
                // One station has been touched
                stations.setCurrent(msg.arg1, getBike);
                infoLayer.inflateStation(stations.getCurrent());
                //Log.i("CityBikes","Station touched: "+Integer.toString(msg.arg1));
            }
        }
    });

    stations.addOverlay(hOverlay);

    mNDBAdapter = new NetworksDBAdapter(getApplicationContext());

    mDbHelper = new StationsDBAdapter(this, mapView, new Handler() {
        @Override
        public void handleMessage(Message msg) {
            switch (msg.what) {
            case StationsDBAdapter.FETCH:
                break;
            case StationsDBAdapter.UPDATE_MAP:
                progressDialog.dismiss();
                SharedPreferences.Editor editor = settings.edit();
                editor.putBoolean("reload_network", false);
                editor.commit();
            case StationsDBAdapter.UPDATE_DATABASE:
                StationOverlay current = stations.getCurrent();
                if (current == null) {
                    infoLayer.inflateMessage(getString(R.string.no_bikes_around));
                }
                if (current != null) {
                    current.setSelected(true, getBike);
                    infoLayer.inflateStation(current);
                    if (view_all)
                        view_all();
                    else
                        view_near();
                } else {

                }
                mapView.invalidate();
                infoLayer.update();
                ////Log.i("openBicing", "Database updated");
                break;
            case StationsDBAdapter.NETWORK_ERROR:
                ////Log.i("openBicing", "Network error, last update from " + mDbHelper.getLastUpdated());
                Toast toast = Toast.makeText(getApplicationContext(),
                        getString(R.string.network_error) + " " + mDbHelper.getLastUpdated(),
                        Toast.LENGTH_LONG);
                toast.show();
                break;
            }
        }
    }, stations);

    mDbHelper.setCenter(locator.getCurrentGeoPoint());

    mSlidingDrawer.setHandler(new Handler() {
        @Override
        public void handleMessage(Message msg) {
            switch (msg.what) {
            case StationSlidingDrawer.ITEMCLICKED:
                StationOverlay clicked = (StationOverlay) msg.obj;
                stations.setCurrent(msg.arg1, getBike);
                Message tmp = new Message();
                tmp.what = InfoLayer.POPULATE;
                tmp.arg1 = msg.arg1;
                infoLayerPopulator.dispatchMessage(tmp);
                mapView.getController().animateTo(clicked.getCenter());
            }
        }
    });

    if (savedInstanceState != null) {
        locator.unlockCenter();
        hOverlay.setRadius(savedInstanceState.getInt("homeRadius"));
        this.view_all = savedInstanceState.getBoolean("view_all");
    } else {
        updateHome();
    }

    try {
        mDbHelper.loadStations();
        if (savedInstanceState == null) {
            String strUpdated = mDbHelper.getLastUpdated();

            Boolean dirty = settings.getBoolean("reload_network", false);

            if (strUpdated == null || dirty) {
                this.fillData(view_all);
            } else {
                Toast toast = Toast.makeText(this.getApplicationContext(),
                        "Last Updated: " + mDbHelper.getLastUpdated(), Toast.LENGTH_LONG);
                toast.show();
                Calendar cal = Calendar.getInstance();
                long now = cal.getTime().getTime();
                if (Math.abs(now - mDbHelper.getLastUpdatedTime()) > 60000 * 5)
                    this.fillData(view_all);
            }
        }

    } catch (Exception e) {
        ////Log.i("openBicing", "SHIT ... SUCKS");
    }
    ;

    if (view_all)
        view_all();
    else
        view_near();
    ////Log.i("openBicing", "CREATE!");
}