Java Code Examples for android.widget.Toast.setGravity()

The following are Jave code examples for showing how to use setGravity() of the android.widget.Toast class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: PandwarfDefenderProject   File: ThresholdFragment.java   View Source Code Vote up 6 votes
/**
 * Update widgets and send an event "START_SEARCH_THRESHOLD" to {@link Main2Activity}
 */
private void startSearchOptimalThreshold() {
    progressBarSearchOptimalThreshold.setVisibility(View.VISIBLE);
    searchOptimalThresholdButton.setText(getString(R.string.button_threshold_text_stop));
    searchOptimalThresholdButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            stopSearchOptimalThreshold(); // behavior of searchOptimalThresholdButton changed.
        }
    });

    String frequency = frequencyEditText.getText().toString();
    if (!Tools.isValidFrequency(frequency)) { // if frequency is wrong.
        Toast toast = Toast.makeText(getContext(), "Wrong frequency", Toast.LENGTH_SHORT);
        toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
        toast.show();
        return;
    }
    HashMap<String, String> parameters = new HashMap<>();
    parameters.put(Parameter.FREQUENCY.toString(), frequency);

    EventBus.getDefault().postSticky(new ActionEvent(Action.START_SEARCH_THRESHOLD, parameters));

}
 
Example 2
Project: Hotspot-master-devp   File: ShowMessage.java   View Source Code Vote up 6 votes
public static void showToast(Context context, String str,int locStyle) {
    Toast toast=Toast.makeText(context, str, Toast.LENGTH_SHORT);
    //第一个参数:设置toast在屏幕中显示的位置。我现在的设置是居中靠顶
    //第二个参数:相对于第一个参数设置toast位置的横向X轴的偏移量,正数向右偏移,负数向左偏移
    //第三个参数:同的第二个参数道理一样
    //如果你设置的偏移量超过了屏幕的范围,toast将在屏幕内靠近超出的那个边界显示
    switch (locStyle){
        case MSG_LOCATION_CODE_CENTER:
            toast.setGravity(Gravity.CENTER, 0, 0);
            break;
        case MSG_LOCATION_CODE_TOP:
            toast.setGravity(Gravity.TOP|Gravity.CENTER, 0, 50);
            break;
        case MSG_LOCATION_CODE_BUTTOM:
            toast.setGravity(Gravity.BOTTOM|Gravity.CENTER, 0, 50);
            break;
    }
    toast.show();
}
 
Example 3
Project: RFID-Attendance   File: MainActivity.java   View Source Code Vote up 6 votes
/**
 * Display a checkmark toast to notify the user of a successful scan
 */
private void showCheckmarkToast(){
    // Inflate the toast layout
    LayoutInflater inflater = getLayoutInflater();
    View layout = inflater.inflate(R.layout.toast_checkmark,
            (ViewGroup) findViewById(R.id.toast_layout_root));
    TextView text = (TextView) layout.findViewById(R.id.toast_text);
    text.setText(R.string.scan_successful);

    // Create the toast
    Toast toast = new Toast(getApplicationContext());
    toast.setGravity(Gravity.CENTER_HORIZONTAL, 0, 0);
    toast.setDuration(Toast.LENGTH_SHORT);
    toast.setView(layout);
    toast.show();
}
 
Example 4
Project: boohee_v5.6   File: TabLayout.java   View Source Code Vote up 5 votes
public boolean onLongClick(View v) {
    int[] screenPos = new int[2];
    getLocationOnScreen(screenPos);
    Context context = getContext();
    int width = getWidth();
    int height = getHeight();
    int screenWidth = context.getResources().getDisplayMetrics().widthPixels;
    Toast cheatSheet = Toast.makeText(context, this.mTab.getContentDescription(), 0);
    cheatSheet.setGravity(49, (screenPos[0] + (width / 2)) - (screenWidth / 2), height);
    cheatSheet.show();
    return true;
}
 
Example 5
Project: GitHub   File: ToastUtil.java   View Source Code Vote up 5 votes
public Toast create() {
    View contentView = View.inflate(context, R.layout.dialog_toast, null);
    TextView tvMsg = (TextView) contentView.findViewById(R.id.tv_toast_msg);
    toast = new Toast(context);
    toast.setView(contentView);
    toast.setGravity(Gravity.CENTER, 0, 0);
    toast.setDuration(Toast.LENGTH_LONG);
    tvMsg.setText(msg);
    return toast;
}
 
Example 6
Project: Hotspot-master-devp   File: ToastUtil.java   View Source Code Vote up 5 votes
/**
 * 与app色调一致的自定义Toast
 * @param context
 * @param msg 要展示的信息
 */
public static void showToastSavor(Context context, String msg) {
    LayoutInflater layoutInflater = LayoutInflater.from(context);
    View inflate = layoutInflater.inflate(R.layout.view_text, null);
    ((TextView) inflate.findViewById(R.id.custom_toast)).setText(msg);
    Toast toast = new Toast(context);
    toast.setGravity(Gravity.CENTER, 0, 0);
    toast.setView(inflate);
    toast.setDuration(Toast.LENGTH_SHORT);
    toast.show();
}
 
Example 7
Project: ImageEraser   File: MainActivity.java   View Source Code Vote up 5 votes
protected void onPostExecute(Boolean success) {
    Toast toast = Toast.makeText(getBaseContext(), "PNG Saved", Toast.LENGTH_LONG);
    toast.setGravity(17, 0, 0);
    toast.show();
    getWindow().clearFlags(16);

}
 
Example 8
Project: siiMobilityAppKit   File: SocialSharing.java   View Source Code Vote up 5 votes
@SuppressLint("NewApi")
private void showPasteMessage(String label) {
  if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
    return;
  }
  final Toast toast = Toast.makeText(webView.getContext(), label, Toast.LENGTH_LONG);
  toast.setGravity(Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL, 0, 0);
  toast.show();
}
 
Example 9
Project: GitHub   File: ToastUtil.java   View Source Code Vote up 5 votes
public Toast createShort() {
    View contentView = View.inflate(context, R.layout.dialog_toast, null);
    TextView tvMsg = (TextView) contentView.findViewById(R.id.tv_toast_msg);
    toast = new Toast(context);
    toast.setView(contentView);
    toast.setGravity(Gravity.CENTER, 0, 0);
    toast.setDuration(Toast.LENGTH_SHORT);
    tvMsg.setText(msg);
    return toast;
}
 
Example 10
Project: SecretTalk   File: BluetoothChatFragment.java   View Source Code Vote up 5 votes
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    switch (requestCode) {
        case REQUEST_CONNECT_DEVICE_SECURE:
            // When DeviceListActivity returns with a device to connect
            if (resultCode == Activity.RESULT_OK) {
                connectDevice(data, true);
            }
            break;
        case REQUEST_CONNECT_DEVICE_INSECURE:
            // When DeviceListActivity returns with a device to connect
            if (resultCode == Activity.RESULT_OK) {
                connectDevice(data, false);
            }
            break;
        case REQUEST_ENABLE_BT:
            // When the request to enable Bluetooth returns
            if (resultCode == Activity.RESULT_OK) {
                // Bluetooth is now enabled, so set up a chat session
                setupChat();
            } else {
                // User did not enable Bluetooth or an error occurred
                Log.d(TAG, "BT not enabled");

                Toast toast = Toast.makeText(getActivity(), R.string.bt_not_enabled_leaving,
                        Toast.LENGTH_SHORT);
                toast.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL, 0, 0);
                toast.show();

                getActivity().finish();
            }
    }
}
 
Example 11
Project: PandwarfDefenderProject   File: GuardianFragment.java   View Source Code Vote up 5 votes
/**
 * Start protection, check if frequency && decibel values are regular.
 * If not a toast will be showed.
 *
 * Otherwise an event "START_PROTECTION" will be sent to the main activity.
 */
private void startProtection() {

    if (!Tools.isValidDb(dbToleranceEditText.getText().toString()) ||
            !Tools.isValidFrequency(frequencyEditText.getText().toString())) {
        Toast toast = Toast.makeText(getContext(), "wrong parameters", Toast.LENGTH_SHORT);
        toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
        toast.show();
        return;
    }
    refreshCurrentConfiguration();
    historyLogArrayList.clear();
    resetFragment();
    showHistoryButton.setVisibility(View.VISIBLE);
    showHistoryButton.setText(getString(R.string.no_attack_detected_flat_button));
    currentState = PROTECTION_ON_RUN;
    progressBarPandwarfRunning.setVisibility(View.VISIBLE);
    startStopProtectionButton.setText(R.string.stop_protection_text_button); // change text value
    HashMap<String, String> parameters = new HashMap<>(); // parameters will contains the frequency, db, peak tolerance & margin error values.

    parameters.put(Parameter.FREQUENCY.toString(), String.valueOf(currentConfiguration.getFrequency()));
    parameters.put(Parameter.RSSI_VALUE.toString(), String.valueOf(currentConfiguration.getDbTolerance()));
    parameters.put(Parameter.PEAK_TOLERANCE.toString(), String.valueOf(currentConfiguration.getPeakTolerance()));
    parameters.put(Parameter.MARGIN_ERROR.toString(), String.valueOf(currentConfiguration.getMarginError()));
    EventBus.getDefault().postSticky(new ActionEvent(Action.START_PROTECTION, parameters));
    addLog(HistoryLog.WARNING_LEVEL.LOW, "Protection started");

}
 
Example 12
Project: CircularViewPager   File: CircularTabLayoutAdapter.java   View Source Code Vote up 5 votes
@Override
public boolean onLongClick(View v) {
    final int[] screenPos = new int[2];
    getLocationOnScreen(screenPos);
    final Context context = getContext();
    final int width = getWidth();
    final int height = getHeight();
    final int screenWidth = context.getResources().getDisplayMetrics().widthPixels;
    Toast cheatSheet = Toast.makeText(context, mTab.getContentDescription(), Toast.LENGTH_SHORT);
    // display below the tab
    cheatSheet.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL, (screenPos[0] + width / 2) - screenWidth / 2, height);
    cheatSheet.show();
    return true;
}
 
Example 13
Project: sctalk   File: PinkToast.java   View Source Code Vote up 5 votes
public static Toast makeText(Context context, CharSequence text, int duration) {
    Toast result = Toast.makeText(context, text, duration);
    result.getView().setBackgroundResource(R.drawable.tt_waterfall_refresh_bg);
    result.setGravity(Gravity.CENTER, 0, 0);
    TextView tv = (TextView) ((ViewGroup) result.getView()).getChildAt(0);
    ScreenTools tools = ScreenTools.instance(context);

    tv.setPadding(tools.dip2px(5), tools.dip2px(8), tools.dip2px(5),
            tools.dip2px(8));
    tv.setShadowLayer(0, 0, 0, Color.TRANSPARENT);
    tv.setMinWidth(tools.dip2px(180));
    tv.setGravity(Gravity.CENTER);
    tv.setTextColor(context.getResources().getColor(android.R.color.white));
    return result;
}
 
Example 14
Project: SecretTalk   File: MessageActivity.java   View Source Code Vote up 5 votes
/**
 * Shows the defined keyword used
 */
private void BlueChatPress() {
    String toastText;
    if (!mKeyword.isEmpty()) {
        toastText = "Key: " + mKeyword;
    } else {
        toastText = "Empty keyword";
    }
    Toast toast = Toast.makeText(MessageActivity.this, toastText, Toast.LENGTH_SHORT);
    toast.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL, 0, 0);
    toast.show();
}
 
Example 15
Project: apps_small   File: MainActivity.java   View Source Code Vote up 5 votes
public void startOver (View startView) {

        // Do this when you want to start over
        Toast newGame = Toast.makeText(getApplicationContext(),"Okay, here's a new game!", Toast.LENGTH_SHORT);
                    newGame.setGravity(Gravity.CENTER, 0, 0);
                    newGame.show();

        // Reset all the pieces.
        ImageView p0 = (ImageView)findViewById(R.id.p0);
        ImageView p1 = (ImageView)findViewById(R.id.p1);
        ImageView p2 = (ImageView)findViewById(R.id.p2);
        ImageView p3 = (ImageView)findViewById(R.id.p3);
        ImageView p4 = (ImageView)findViewById(R.id.p4);
        ImageView p5 = (ImageView)findViewById(R.id.p5);
        ImageView p6 = (ImageView)findViewById(R.id.p6);
        ImageView p7 = (ImageView)findViewById(R.id.p7);
        ImageView p8 = (ImageView)findViewById(R.id.p8);
        p0.setImageResource(R.drawable.coin);
        p1.setImageResource(R.drawable.coin);
        p2.setImageResource(R.drawable.coin);
        p3.setImageResource(R.drawable.coin);
        p4.setImageResource(R.drawable.coin);
        p5.setImageResource(R.drawable.coin);
        p6.setImageResource(R.drawable.coin);
        p7.setImageResource(R.drawable.coin);
        p8.setImageResource(R.drawable.coin);

        // Reset all the variables.
        turn = 0;
        gameInPlay = true;

        // Reset the array.
        for (int p = 0; p < conditions.length; p++) {
            conditions[p] = 2;
        }


    }
 
Example 16
Project: CartCounter   File: CartCounterActionView.java   View Source Code Vote up 5 votes
@SuppressLint("RtlHardcoded")
@Override
public boolean performLongClick() {
    boolean performed = super.performLongClick();
    if (mItemData != null && !performed) {
        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, mItemData.getTitle(), Toast.LENGTH_SHORT);
        if (midy < displayFrame.height()) {
            // Show along the top; follow action buttons
            cheatSheet.setGravity(Gravity.TOP | Gravity.RIGHT, screenWidth - screenPos[0] - width / 2, height);
        } else {
            // Show along the bottom center
            cheatSheet.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, height);
        }
        cheatSheet.show();
        performed = true;
    }

    return performed;
}
 
Example 17
Project: ITSM   File: ToastUtils.java   View Source Code Vote up 5 votes
/**
 * 显示吐司
 *
 * @param text     文本
 * @param duration 显示时长
 */
private static void show(CharSequence text, int duration) {
    cancel();
    if (customView != null) {
        sToast = new Toast(App.app);
        sToast.setView(customView);
        sToast.setDuration(duration);
    } else {
        sToast = Toast.makeText(App.app, text, duration);
    }
    sToast.setGravity(gravity, xOffset, yOffset);
    sToast.show();
}
 
Example 18
Project: Android_AutoSignInTool   File: Utils.java   View Source Code Vote up 4 votes
public static void showToast(String text, Context context) {
    Toast toast = Toast.makeText(context,
            text, Toast.LENGTH_SHORT);
    toast.setGravity(Gravity.CENTER, 0, 0);
    toast.show();
}
 
Example 19
Project: TootApp   File: ToastMaker.java   View Source Code Vote up 4 votes
public static Toast buildToasty(Context ctx, String s) {
    Toast t = Toasty.info(ctx, s, Toast.LENGTH_SHORT, true);
    t.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.TOP, 0, 0);
    return t;
}
 
Example 20
Project: Customerly-Android-SDK   File: IBR_DownloadBroadcastReceiver.java   View Source Code Vote up 4 votes
@Override
public void onReceive(Context context, Intent intent) {
    Cursor c = null;
    try {
        final DownloadManager dm = (DownloadManager) context.getSystemService(DOWNLOAD_SERVICE);
        if (DownloadManager.ACTION_DOWNLOAD_COMPLETE.equals(intent.getAction())) {
            long downloadID = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1);
            if(downloadID != -1 && IBR_DownloadBroadcastReceiver.checkAndRemove(downloadID)) {
                String filename = null;
                c = dm.query(new DownloadManager.Query().setFilterById(downloadID));
                if (c.moveToFirst() && DownloadManager.STATUS_SUCCESSFUL == c.getInt(c.getColumnIndex(DownloadManager.COLUMN_STATUS))) {
                    filename = new File(Uri.parse(c.getString(c.getColumnIndex(DownloadManager.COLUMN_LOCAL_URI))).getPath()).getName();
                }

                if(filename != null) {
                    File file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), filename);
                    if(file.exists()) {
                        ((NotificationManager) context.getSystemService(NOTIFICATION_SERVICE))
                                .notify((int) downloadID, new NotificationCompat.Builder(context)
                                        .setSmallIcon(R.drawable.ic_file_download)
                                        .setContentTitle(context.getString(R.string.io_customerly__download_complete))
                                        .setContentText(filename)
                                        .setAutoCancel(true)
                                        .setContentIntent(
                                                PendingIntent.getActivity(
                                                        context,
                                                        0,
                                                        new Intent(context, IAct_OpenDownloadedFileActivity.class)
                                                                .setData(
                                                                        IU_CustomerlyFileProvider.getUriForFile(context, String.format("io.customerly.provider.%s", context.getPackageName()), file)
                                                                ),
                                                        PendingIntent.FLAG_UPDATE_CURRENT
                                                )).build());

                        Toast toast = Toast.makeText(context, R.string.io_customerly__download_complete, Toast.LENGTH_SHORT);
                        toast.setGravity(Gravity.TOP, 25, 400);
                        toast.show();
                    }
                }
            }
        }
    } catch (Exception ignored) { } finally {
        if(c != null) {
            c.close();
        }
    }
}