Example usage for android.widget Toast setGravity

List of usage examples for android.widget Toast setGravity

Introduction

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

Prototype

public void setGravity(int gravity, int xOffset, int yOffset) 

Source Link

Document

Set the location at which the notification should appear on the screen.

Usage

From source file:com.grass.caishi.cc.activity.SettingUserActivity.java

/**
 * ?uri??//from w  w w  .j  a va 2 s. c om
 * 
 * @param selectedImage
 */
private File Uritofile(Uri selectedImage) {
    File file = null;
    Cursor cursor = this.getContentResolver().query(selectedImage, null, null, null, null);
    if (cursor != null) {
        cursor.moveToFirst();
        int columnIndex = cursor.getColumnIndex("_data");
        String picturePath = cursor.getString(columnIndex);
        cursor.close();
        cursor = null;

        if (picturePath == null || picturePath.equals("null")) {
            Toast toast = Toast.makeText(this, "?", Toast.LENGTH_SHORT);
            toast.setGravity(Gravity.CENTER, 0, 0);
            toast.show();
            return null;
        }
        file = new File(picturePath);
        // sendPicture(picturePath);
    } else {
        file = new File(selectedImage.getPath());
        if (!file.exists()) {
            Toast toast = Toast.makeText(this, "?", Toast.LENGTH_SHORT);
            toast.setGravity(Gravity.CENTER, 0, 0);
            toast.show();
            return null;
        }

    }

    return file;

}

From source file:fm.smart.r1.activity.ItemActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ExceptionHandler.register(this);

    // could check here to see if this was suspended for login and go
    // straight to add_item ...

    setContentView(R.layout.item);//from w ww  .j a  v a 2s. co m

    /*
     * ImageView author_icon = (ImageView)
     * findViewById(R.id.item_author_icon); if (item.author_image != null){
     * author_icon.setImageBitmap(item.author_image); }
     */

    TextView cue_and_pronunciation = (TextView) findViewById(R.id.cue_and_pronunciation);
    cue_and_pronunciation.setText(item.cue_text); // TODO handle case where item is null?
    TextView cue_part_of_speech = (TextView) findViewById(R.id.cue_part_of_speech);
    if (!TextUtils.equals(item.part_of_speech, "None")) {
        cue_part_of_speech.setText(item.part_of_speech);
    } else {
        cue_part_of_speech.setVisibility(View.INVISIBLE);
    }
    /*
     * TextView author = (TextView) findViewById(R.id.item_author);
     * author.setText(item.author_name);
     */

    TextView response_and_pronunciation = (TextView) findViewById(R.id.response_and_pronunciation);
    response_and_pronunciation.setText(item.children[0][0]);
    TextView response_part_of_speech = (TextView) findViewById(R.id.response_part_of_speech);
    if (item.type != null && item.type.equals("meaning")) {
        item.type = "Translation";
    }
    response_part_of_speech.setText(item.type);
    response_part_of_speech.setVisibility(View.INVISIBLE);

    ImageView cue_sound = (ImageView) findViewById(R.id.cue_sound);
    setSound(cue_sound, item.cue_sound_url, this, R.id.cue_sound, (String) item.item_node.atts.get("id"),
            item.cue_text);

    ImageView response_sound = (ImageView) findViewById(R.id.response_sound);
    setSound(response_sound, item.response_sound_url, this, R.id.response_sound,
            (String) item.item_node.atts.get("id"), item.response_node.getFirstContents("text"));
    EfficientAdapter adapter = new EfficientAdapter(ItemActivity.this, item.sentence_vector);
    setListAdapter(adapter);
    if (adapter.getCount() == 0 && !ItemActivity.shown_toast) {
        Toast t = Toast.makeText(this, "Know a good example? Click the menu button to add one", 250);
        t.setGravity(Gravity.CENTER, 0, 0);
        t.show();
        ItemActivity.shown_toast = true;
    }
    // notify();
}

From source file:ro.ui.pttdroid.Main.java

/**
 * Reset all settings to their default value
 * /*from  www  .  j  ava 2 s  . c o  m*/
 * @return
 */
private boolean resetAllSettings() {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);

    Editor editor = prefs.edit();
    editor.clear();
    editor.commit();

    Toast toast = Toast.makeText(this, getString(R.string.setting_reset_all_confirm), Toast.LENGTH_SHORT);
    toast.setGravity(Gravity.CENTER, 0, 0);
    toast.show();

    return true;
}

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();//from  w ww. j av  a 2  s. co m
        }
    });
}

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

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    Intent intent;// w  ww  .ja  va  2s  .c  o 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:org.cowboycoders.cyclisimo.TrackListActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    Intent intent;//from  w  w w  .jav  a2 s  .c  o  m
    switch (item.getItemId()) {
    case R.id.track_list_search:
        return ApiAdapterFactory.getApiAdapter().handleSearchMenuSelection(this);
    case R.id.track_list_start_gps:
        if (!trackDataHub.isGpsProviderEnabled()) {
            intent = GoogleLocationUtils.isAvailable(TrackListActivity.this)
                    ? new Intent(GoogleLocationUtils.ACTION_GOOGLE_LOCATION_SETTINGS)
                    : new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(intent);
            return true;
        }
        startGps = !startGps;
        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();
        handleStartGps();
        updateMenuItems(recordingTrackId != PreferencesUtils.RECORDING_TRACK_ID_DEFAULT);
        return true;
    case R.id.track_list_import:
        AnalyticsUtils.sendPageViews(this, "/action/import");
        intent = IntentUtils.newIntent(this, ImportActivity.class).putExtra(ImportActivity.EXTRA_IMPORT_ALL,
                true);
        startActivity(intent);
        return true;
    case R.id.track_list_save_all_gpx:
        startSaveActivity(TrackFileFormat.GPX);
        return true;
    case R.id.track_list_save_all_kml:
        startSaveActivity(TrackFileFormat.KML);
        return true;
    case R.id.track_list_save_all_csv:
        startSaveActivity(TrackFileFormat.CSV);
        return true;
    case R.id.track_list_save_all_tcx:
        startSaveActivity(TrackFileFormat.TCX);
        return true;
    case R.id.track_list_delete_all:
        new DeleteAllTrackDialogFragment().show(getSupportFragmentManager(),
                DeleteAllTrackDialogFragment.DELETE_ALL_TRACK_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_settings:
        intent = IntentUtils.newIntent(this, SettingsActivity.class);
        startActivity(intent);
        return true;
    case R.id.track_list_help:
        intent = IntentUtils.newIntent(this, HelpActivity.class);
        startActivity(intent);
        return true;
    default:
        return super.onOptionsItemSelected(item);
    }
}

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

public LatLng getDestinationCoordinates(String picID) {

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

    try {/*  ww  w  . j a v a  2  s.  c  om*/
        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:com.ccxt.whl.activity.SettingsFragmentCopy.java

/**
 * ?uri?/*ww  w .j  a  v a  2s.c o m*/
 * 
 * @param selectedImage
 */
private void sendPicByUri(Uri selectedImage) {
    // String[] filePathColumn = { MediaStore.Images.Media.DATA };
    Cursor cursor = getActivity().getContentResolver().query(selectedImage, null, null, null, null);
    if (cursor != null) {
        cursor.moveToFirst();
        int columnIndex = cursor.getColumnIndex("_data");
        String picturePath = cursor.getString(columnIndex);
        cursor.close();
        cursor = null;

        if (picturePath == null || picturePath.equals("null")) {
            Toast toast = Toast.makeText(getActivity(), "?", Toast.LENGTH_SHORT);
            toast.setGravity(Gravity.CENTER, 0, 0);
            toast.show();
            return;
        }
        copyFile(picturePath, imageUri.getPath());
        cropImageUri(imageUri, 150, 150, USERPIC_REQUEST_CODE_CUT);
        //sendPicture(picturePath);
    } else {
        File file = new File(selectedImage.getPath());
        if (!file.exists()) {
            Toast toast = Toast.makeText(getActivity(), "?", Toast.LENGTH_SHORT);
            toast.setGravity(Gravity.CENTER, 0, 0);
            toast.show();
            return;

        }
        copyFile(selectedImage.getPath(), imageUri.getPath());
        cropImageUri(imageUri, 150, 150, USERPIC_REQUEST_CODE_CUT);
        //sendPicture(file.getAbsolutePath());
    }
    /*if(getpathfromUri(uri)!=null&&getpathfromUri(imageUri)!=null){
        copyFile(getpathfromUri(uri),getpathfromUri(imageUri));
       }else{
    return;
       }*/
    //cropImageUri(selectedImage, 150, 150, USERPIC_REQUEST_CODE_CUT);

}

From source file:io.plaidapp.ui.DribbbleLogin.java

void showLoggedInUser() {
    final Call<User> authenticatedUser = dribbblePrefs.getApi().getAuthenticatedUser();
    authenticatedUser.enqueue(new Callback<User>() {
        @Override// ww w.jav a2  s. c  o  m
        public void onResponse(Call<User> call, Response<User> response) {
            final User user = response.body();
            dribbblePrefs.setLoggedInUser(user);
            final Toast confirmLogin = new Toast(getApplicationContext());
            final View v = LayoutInflater.from(DribbbleLogin.this)
                    .inflate(R.layout.toast_logged_in_confirmation, null, false);
            ((TextView) v.findViewById(R.id.name)).setText(user.name.toLowerCase());
            // need to use app context here as the activity will be destroyed shortly
            Glide.with(getApplicationContext()).load(user.avatar_url).placeholder(R.drawable.ic_player)
                    .transform(new CircleTransform(getApplicationContext()))
                    .into((ImageView) v.findViewById(R.id.avatar));
            v.findViewById(R.id.scrim).setBackground(ScrimUtil.makeCubicGradientScrimDrawable(
                    ContextCompat.getColor(DribbbleLogin.this, R.color.scrim), 5, Gravity.BOTTOM));
            confirmLogin.setView(v);
            confirmLogin.setGravity(Gravity.BOTTOM | Gravity.FILL_HORIZONTAL, 0, 0);
            confirmLogin.setDuration(Toast.LENGTH_LONG);
            confirmLogin.show();
        }

        @Override
        public void onFailure(Call<User> call, Throwable t) {
        }
    });
}

From source file:com.ccxt.whl.activity.SettingsFragmentC_0815.java

/**
 * ?uri?//from  ww w .  j av a 2 s.  com
 * 
 * @param selectedImage
 */
private void sendPicByUri(Uri selectedImage) {
    // String[] filePathColumn = { MediaStore.Images.Media.DATA };
    Cursor cursor = getActivity().getContentResolver().query(selectedImage, null, null, null, null);
    if (cursor != null) {
        cursor.moveToFirst();
        int columnIndex = cursor.getColumnIndex("_data");
        String picturePath = cursor.getString(columnIndex);
        cursor.close();
        cursor = null;

        if (picturePath == null || picturePath.equals("null")) {
            Toast toast = Toast.makeText(getActivity(), "?", Toast.LENGTH_SHORT);
            toast.setGravity(Gravity.CENTER, 0, 0);
            toast.show();
            return;
        }
        //copyFile(picturePath,imageUri.getPath());
        cropImageUri(selectedImage, 200, 200, USERPIC_REQUEST_CODE_CUT);
        //sendPicture(picturePath);
    } else {
        File file = new File(selectedImage.getPath());
        if (!file.exists()) {
            Toast toast = Toast.makeText(getActivity(), "?", Toast.LENGTH_SHORT);
            toast.setGravity(Gravity.CENTER, 0, 0);
            toast.show();
            return;

        }
        //copyFile(selectedImage.getPath(),imageUri.getPath());
        cropImageUri(selectedImage, 200, 200, USERPIC_REQUEST_CODE_CUT);
        //sendPicture(file.getAbsolutePath());
    }
    /*if(getpathfromUri(uri)!=null&&getpathfromUri(imageUri)!=null){
        copyFile(getpathfromUri(uri),getpathfromUri(imageUri));
       }else{
    return;
       }*/
    //cropImageUri(selectedImage, 150, 150, USERPIC_REQUEST_CODE_CUT);

}