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.wewow.BaseActivity.java

private void showCacheClearedToast() {

    LayoutInflater inflater = getLayoutInflater();
    View layout = inflater.inflate(R.layout.clear_cache_toast_view, null);

    Toast toast = new Toast(getApplicationContext());
    toast.setGravity(Gravity.CENTER, 0, 0);
    toast.setDuration(Toast.LENGTH_SHORT);
    toast.setView(layout);//from ww  w . j a  va 2 s .c o m
    toast.show();
}

From source file:TIG055st2014.mailmaster.Activities.ComposeActivity.java

/**
 * onClick for the send item in the actionbar.
 *//*from w  w  w . j av a 2 s  .c o  m*/
public void onClickSend(MenuItem m) {
    total = sizePref.getFloat("Total", (float) 0.0);
    if (total > 20480) {// The maximum attachment size to make email
        // receivable by microsoft accounts
        Toast toast = Toast.makeText(getApplicationContext(),
                getApplicationContext().getResources().getString(R.string.toast_big_size), Toast.LENGTH_SHORT);
        toast.setGravity(Gravity.TOP | Gravity.LEFT, 0, 0);
        toast.show();
    } else {
        String recipients, cc, bcc, subject, body;
        AppVariablesSingleton apv = AppVariablesSingleton.getInstance();
        if (apv.getIsReply()) {
            recipients = ((TextView) findViewById(R.id.receiveAccsReply)).getText().toString();
            cc = ((EditText) findViewById(R.id.ccAccsReply)).getText().toString();
            bcc = ((EditText) findViewById(R.id.bccAccsReply)).getText().toString();
            subject = ((TextView) findViewById(R.id.subjectReply)).getText().toString();
            body = ((EditText) findViewById(R.id.bodyReply)).getText().toString();
        } else {
            recipients = ((EditText) findViewById(R.id.receiveAccs)).getText().toString();
            cc = ((EditText) findViewById(R.id.ccAccs)).getText().toString();
            bcc = ((EditText) findViewById(R.id.bccAccs)).getText().toString();
            subject = ((EditText) findViewById(R.id.subject)).getText().toString();
            body = ((EditText) findViewById(R.id.body)).getText().toString();
        }
        if (!recipients.equals("") && !subject.equals("") && !body.equals("")) {
            try {
                MailFunctionality mf = new MailFunctionality(currentAcc, pw, (currentAcc.split("@"))[1]);
                mf.sendMail(subject, body, currentAcc, recipients, cc, bcc, attachments,
                        getApplicationContext(), this);
                startActivity(new Intent("TIG055st2014.mailmaster.Activities.MailFolderActivity"));
            } catch (Exception e) {
                e.printStackTrace();
            }
        } else {
            // Missed fields
            Toast toast = Toast.makeText(getApplicationContext(),
                    getApplicationContext().getResources().getString(R.string.toast_addacc),
                    Toast.LENGTH_SHORT);
            toast.setGravity(Gravity.TOP | Gravity.LEFT, 0, 0);
            toast.show();
        }
    }
}

From source file:com.atlas.mars.weatherradar.MainActivity.java

@Override
public void show(String txt, int gravity) {
    Toast toast = Toast.makeText(getApplicationContext(), txt, Toast.LENGTH_SHORT);
    toast.setGravity(gravity, 0, 100);
    toast.show();//  ww  w .  j  av  a  2 s  .co m
}

From source file:com.initiativaromania.hartabanilorpublici.IRUserInterface.activities.MainActivity.java

private void initTransparentView() {

    /* Avoid displaying infographic if the home button has been pushed */
    Intent intent = getIntent();//w w  w  .ja  v  a2 s.co  m
    displayInfographic = intent.getBooleanExtra(EXTRA_DISPLAY_INFOGRAPHIC, true);
    System.out.println("Display info " + displayInfographic);
    if (!displayInfographic) {
        LinearLayout linear = (LinearLayout) findViewById(R.id.transparentLayer);
        linear.setVisibility(View.INVISIBLE);
        return;
    }

    /* Setup the OK button */
    Button okButton = (Button) findViewById(R.id.okButton);
    if (okButton != null) {
        okButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                System.out.println("OK button pushed");

                Animation animation = AnimationUtils.loadAnimation(context, R.anim.slide_down);
                LinearLayout linear = (LinearLayout) findViewById(R.id.transparentLayer);
                linear.startAnimation(animation);
                linear.setVisibility(View.INVISIBLE);

                Toast toast = Toast.makeText(getBaseContext(), "Apasa pe simbolurile  din jurul tau",
                        Toast.LENGTH_LONG);
                toast.setGravity(Gravity.CENTER | Gravity.CENTER_HORIZONTAL, 0, 0);
                toast.show();

                /* Display initial seek bar value */
                Rect thumbRect = seekBar.getThumb().getBounds();
                seekBarValue.setX(thumbRect.exactCenterX());
                DecimalFormat dm = new DecimalFormat("###,###.###");
                seekBarValue.setText(" " + String.valueOf(dm.format(CommManager.aroundTotalSum)) + " EURO ");
                seekBarValue.setVisibility(View.VISIBLE);
                seekBarValue.startAnimation(animationFadeIn);
            }
        });
    }

    /* Send request to get the init data */
    CommManager.requestInitData(new ICommManagerResponse() {
        @Override
        public void processResponse(JSONObject response) {
            MainActivity.this.receiveInitData(response);
        }

        @Override
        public void onErrorOccurred(String errorMsg) {
            Toast.makeText(MainActivity.this, "Eroare conectare la server", Toast.LENGTH_SHORT).show();
        }
    });
}

From source file:ca.mcgill.hs.serv.LogFileUploaderService.java

/**
 * Helper method for making toasts./*from w  w w  .  ja v  a 2  s .c om*/
 * 
 * @param message
 *            The text to toast.
 * @param duration
 *            The duration of the toast.
 */
private void makeToast(final String message, final int duration) {
    final Toast slice = Toast.makeText(getBaseContext(),
            getResources().getString(R.string.uploader_appname_label) + message, duration);
    slice.setGravity(slice.getGravity(), slice.getXOffset(), slice.getYOffset() + 100);
    slice.show();
}

From source file:ch.luklanis.esscan.history.HistoryActivity.java

private Uri createDTAFile(long bankProfileId) {
    List<HistoryItem> historyItems = mHistoryManager.buildHistoryItemsForDTA(bankProfileId);
    BankProfile bankProfile = mHistoryManager.getBankProfile(bankProfileId);

    String error = dtaFileCreator.getFirstError(bankProfile, historyItems);

    if (!TextUtils.isEmpty(error)) {
        setOkAlert(error);//from w w  w  .j  ava  2s. co  m
        return null;
    }

    CharSequence dta = dtaFileCreator.buildDTA(bankProfile, historyItems);

    if (!dtaFileCreator.saveDTAFile(dta.toString())) {
        setOkAlert(R.string.msg_unmount_usb);
        return null;
    } else {
        Uri dtaFileUri = dtaFileCreator.getDTAFileUri();
        String dtaFileName = dtaFileUri.getLastPathSegment();

        new HistoryExportUpdateAsyncTask(mHistoryManager, dtaFileName)
                .execute(historyItems.toArray(new HistoryItem[historyItems.size()]));

        this.dtaFileCreator = new DTAFileCreator(getApplicationContext());

        Toast toast = Toast.makeText(this,
                getResources().getString(R.string.msg_dta_saved, dtaFileUri.getPath()), Toast.LENGTH_LONG);
        toast.setGravity(Gravity.BOTTOM, 0, 0);
        toast.show();

        return dtaFileUri;
    }
}

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

@Override
public boolean performLongClick() {
    if (super.performLongClick()) {
        return true;
    }//from  w ww  .  ja  v  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:com.amazon.appstream.sampleclient.SampleClientActivity.java

@Override
public void onErrorMessage(final boolean fatal, final String message) {
    runOnUiThread(new Runnable() {
        @Override//from   w ww . j  a  va2  s . c  o m
        public void run() {
            if (mStopped) {
                Log.i(TAG, "Ignoring error during stopped state :" + (fatal ? "fatal" : "non fatal") + ":"
                        + message);
                return; // ignore errors if we're stopped.
            }
            if (fatal) {
                // Tell the app it needs to pause.
                AppStreamInterface.pause(true);
                ErrorDialogFragment dialog = new ErrorDialogFragment();
                dialog.setMessage(message);
                dialog.show(getSupportFragmentManager(), "ErrorDialogFragment");

                // And finally stop AppStream; kill the interfaces to give us a clean slate.
                stopAppStream();
            } else {
                if (mConnectDialog != null) {
                    openConnectDialog(message);
                } else {
                    Toast toast = Toast.makeText(SampleClientActivity.this, message, Toast.LENGTH_LONG);
                    toast.setGravity(Gravity.RIGHT | Gravity.BOTTOM, 10, 10);
                    toast.show();
                }
            }
        }
    });
}

From source file:com.sam_chordas.android.stockhawk.ui.MyStocksActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mContext = this;
    ConnectivityManager cm = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);

    setContentView(R.layout.activity_my_stocks);
    // The intent service is for executing immediate pulls from the Yahoo API
    // GCMTaskService can only schedule tasks, they cannot execute immediately
    mServiceIntent = new Intent(this, StockIntentService.class);
    if (savedInstanceState == null) {
        // Run the initialize task service so that some stocks appear upon an empty database
        mServiceIntent.putExtra("tag", "init");
        if (Utils.isNetworkAvailable(mContext)) {
            startService(mServiceIntent);
        } else {//www  . jav  a 2s . c o m
            networkToast();
        }
    }
    RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recycler_view);

    recyclerView.setLayoutManager(new LinearLayoutManager(this));

    getLoaderManager().initLoader(CURSOR_LOADER_ID, null, this);

    mCursorAdapter = new QuoteCursorAdapter(this, null);
    recyclerView.addOnItemTouchListener(
            new RecyclerViewItemClickListener(this, new RecyclerViewItemClickListener.OnItemClickListener() {
                @Override
                public void onItemClick(View v, int position) {
                    // CursorAdapter returns a cursor at the correct position for getItem(), or null
                    // if it cannot seek to that position.
                    Intent intent = new Intent(getApplicationContext(), LineGraphActivity.class);
                    intent.putExtra(STOCK_ITEM, mCursorAdapter.getItemSymbol(position));
                    startActivity(intent);
                }
            }));
    recyclerView.setAdapter(mCursorAdapter);

    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.attachToRecyclerView(recyclerView);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (Utils.isNetworkAvailable(mContext)) {
                new MaterialDialog.Builder(mContext).title(R.string.symbol_search)
                        .content(R.string.content_test).inputType(InputType.TYPE_CLASS_TEXT)
                        .input(R.string.input_hint, R.string.input_prefill, new MaterialDialog.InputCallback() {
                            @Override
                            public void onInput(MaterialDialog dialog, CharSequence input) {
                                // On FAB click, receive user input. Make sure the stock doesn't already exist
                                // in the DB and proceed accordingly
                                Cursor c = getContentResolver().query(QuoteProvider.Quotes.CONTENT_URI,
                                        new String[] { QuoteColumns.SYMBOL }, QuoteColumns.SYMBOL + "= ?",
                                        new String[] { input.toString() }, null);
                                if (c.getCount() != 0) {
                                    Toast toast = Toast.makeText(MyStocksActivity.this,
                                            "This stock is already saved!", Toast.LENGTH_LONG);
                                    toast.setGravity(Gravity.CENTER, Gravity.CENTER, 0);
                                    toast.show();
                                    return;
                                } else {
                                    // Add the stock to DB
                                    mServiceIntent.putExtra("tag", "add");
                                    mServiceIntent.putExtra("symbol", input.toString());
                                    startService(mServiceIntent);

                                }
                            }
                        }).show();
            } else {
                networkToast();
            }

        }
    });

    ItemTouchHelper.Callback callback = new SimpleItemTouchHelperCallback(mCursorAdapter);
    mItemTouchHelper = new ItemTouchHelper(callback);
    mItemTouchHelper.attachToRecyclerView(recyclerView);

    mTitle = getTitle();
    if (Utils.isNetworkAvailable(mContext)) {
        long period = 30L;
        long flex = 10L;
        String periodicTag = "periodic";

        // create a periodic task to pull stocks once every hour after the app has been opened. This
        // is so Widget data stays up to date.
        PeriodicTask periodicTask = new PeriodicTask.Builder().setService(StockTaskService.class)
                .setPeriod(period).setFlex(flex).setTag(periodicTag)
                .setRequiredNetwork(Task.NETWORK_STATE_CONNECTED).setRequiresCharging(false).build();
        // Schedule task with tag "periodic." This ensure that only the stocks present in the DB
        // are updated.
        GcmNetworkManager.getInstance(this).schedule(periodicTask);
    }

    if (!Utils.isNetworkAvailable(getApplicationContext())) {
        networkToast();
    }
}

From source file:org.thbz.hanguldrill.MainActivity.java

private void toastError(final String text) {
    runOnUiThread(new Runnable() {
        public void run() {
            Context context = getApplicationContext();
            Toast toast = Toast.makeText(context, text, Toast.LENGTH_SHORT);
            toast.setGravity(Gravity.CENTER, 0, 0);
            toast.show();/*from   w  w w  .  j a  va 2s  .  c  om*/
        }
    });
}