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

The following examples show how to use android.widget.Toast#setGravity() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Cardbar.java    From SimplicityBrowser with MIT License 6 votes vote down vote up
public static @CheckResult
    Toast snackBar(Context context, CharSequence message_to_show, boolean duration) {
    @SuppressLint("InflateParams")
    View view = ((LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.custom_snackbar, null);
    AppCompatTextView message = view.findViewById(R.id.message);
    message.setText(message_to_show);
    Toast toast = new Toast(context);
    toast.setView(view);
    toast.setGravity(Gravity.FILL_HORIZONTAL | Gravity.BOTTOM, 0, 0);
    if (duration) {
        toast.setDuration(Toast.LENGTH_LONG);
    } else {
        toast.setDuration(Toast.LENGTH_SHORT);
    }
    return toast;
}
 
Example 2
Source File: RefreshActionItem.java    From RefreshActionItem-Native with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onLongClick(View v) {
    if (mMenuItem == null || TextUtils.isEmpty(mMenuItem.getTitle())) {
        return true;
    }
    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, mMenuItem.getTitle(), Toast.LENGTH_SHORT);
    if (midy < displayFrame.height()) {
        cheatSheet.setGravity(Gravity.TOP | Gravity.RIGHT, screenWidth - screenPos[0] - width / 2, height);
    } else {
        cheatSheet.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, height);
    }
    cheatSheet.show();
    return true;
}
 
Example 3
Source File: BackgroundUploader.java    From sana.mobile with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void onUploadSuccess(Uri procedure) {
    Log.i(TAG, "onUploadSuccess for " + procedure);

    String procedureTitle = getProcedureTitle(procedure);
    String patientId = ""; // TODO
    String msg = "Successfully sent " + procedureTitle + " for patient "
            + patientId + "\n";

    //String msg = "Successfully sent " + procedureTitle + " procedure\nwith ID = " + savedProcedureId;
    //String msg = "Successfully sent procedure\nwith ID = " + savedProcedureId;

    int sizeOfQueue = queue.size();
    if (sizeOfQueue != 0) {
        msg += "\nThere are still " + sizeOfQueue + "\ncases to be uploaded.";
    } else {
        msg += "\nAll cases are done uploading.";
    }
    Toast toast = Toast.makeText(getApplicationContext(), msg,
            Toast.LENGTH_LONG);
    toast.setGravity(Gravity.CENTER, 0, 0);
    toast.show();
}
 
Example 4
Source File: TextToast.java    From ONE-Unofficial with Apache License 2.0 5 votes vote down vote up
public static void longShow(int resId){
    String content=context.getResources().getString(resId);
    if (context==null){
        throw new IllegalStateException("TextToast was not initialized");
    }
    Toast toast= Toast.makeText(context, content, Toast.LENGTH_LONG);
    toast.setGravity(Gravity.CENTER, 0, 0);
    toast.show();
}
 
Example 5
Source File: FaceSwapperActivity.java    From Machine-Learning-Projects-for-Mobile-Applications with MIT License 5 votes vote down vote up
/**
 * Shows a toast with information why the swap failed.
 *
 * @param text the messages to be displayed.
 */
private Toast showInfoToast(CharSequence text) {
    Context context  = getApplicationContext();
    int     duration = Toast.LENGTH_LONG;

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

    return toast;
}
 
Example 6
Source File: SpeekerToast.java    From sctalk with Apache License 2.0 5 votes vote down vote up
public static void show(Context context, CharSequence text, int duration) {
    LayoutInflater inflater = ((Activity) context).getLayoutInflater();
    View view = inflater.inflate(R.layout.tt_speeker_layout, null);
    TextView title = (TextView) view.findViewById(R.id.top_tip);
    title.setText(text);
    Toast toast = new Toast(context.getApplicationContext());
    toast.setGravity(
            Gravity.FILL_HORIZONTAL | Gravity.TOP,
            0,
            (int) context.getResources().getDimension(
                    R.dimen.top_bar_default_height));
    toast.setDuration(duration);
    toast.setView(view);
    toast.show();
}
 
Example 7
Source File: FullscreenVlcPlayer.java    From VLC-Simple-Player-Android with MIT License 5 votes vote down vote up
/**
 * **********
 * Player
 * ***********
 */

private void createPlayer(String media) {
    releasePlayer();
    setupControls();
    try {
        if (media.length() > 0) {
            Toast toast = Toast.makeText(this, media, Toast.LENGTH_LONG);
            toast.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0,
                    0);
            toast.show();
        }

        // Create a new media player
        libvlc = LibVLC.getInstance();
        libvlc.setHardwareAcceleration(LibVLC.HW_ACCELERATION_FULL);
        libvlc.eventVideoPlayerActivityCreated(true);
        libvlc.setSubtitlesEncoding("");
        libvlc.setAout(LibVLC.AOUT_OPENSLES);
        libvlc.setTimeStretching(true);
        libvlc.setChroma("RV32");
        libvlc.setVerboseMode(true);
        LibVLC.restart(this);
        EventHandler.getInstance().addHandler(mHandler);
        holder.setFormat(PixelFormat.RGBX_8888);
        holder.setKeepScreenOn(true);
        MediaList list = libvlc.getMediaList();
        list.clear();
        list.add(new Media(libvlc, LibVLC.PathToURI(media)), false);
        libvlc.playIndex(0);
    } catch (Exception e) {
        Toast.makeText(this, "Could not create Vlc Player", Toast.LENGTH_LONG).show();
    }
}
 
Example 8
Source File: ActionMenuItemView.java    From CSipSimple with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onLongClick(View v) {
    if (hasText()) {
        // Don't show the cheat sheet for items that already show text.
        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 = IcsToast.makeText(context, mItemData.getTitle(), IcsToast.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();
    return true;
}
 
Example 9
Source File: ToastHelper.java    From mobikul-standalone-pos with MIT License 5 votes vote down vote up
public static void showToast(@NonNull Context context, @NonNull String msg, int duration, int icon) {
    if (!msg.isEmpty()) {
        CustomToastBinding customToastBinding = CustomToastBinding.inflate(LayoutInflater.from(context));
        customToastBinding.setMessage(Html.fromHtml(msg).toString());
        Toast toast = new Toast(context);
        toast.setGravity(Gravity.BOTTOM, 0, 150);
        toast.setView(customToastBinding.getRoot());
        toast.setDuration(duration);
        toast.show();
    }
}
 
Example 10
Source File: GameActivity.java    From AndroidLinkup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 重排按钮按下时的处理
 * 
 * @param v
 */
public void refresh(View v) {
    if (LevelCfg.globalCfg.getRefreshNum() > 0) {
        game.refresh();
    } else {
        // 没有可用道具时给出提示
        Toast toast = ToastUtil.getToast(this, R.string.tool_no_refresh);
        toast.setGravity(Gravity.BOTTOM | Gravity.CENTER, 0, 160);
        toast.show();
    }
}
 
Example 11
Source File: SecureView.java    From codeexamples-android with Eclipse Public License 1.0 5 votes vote down vote up
private void showOverlay() {
    // Generate a toast view with a special layout that will position itself right
    // on top of this view's interesting widgets.  Sneaky huh?
    SecureViewOverlay overlay = (SecureViewOverlay)
            getLayoutInflater().inflate(R.layout.secure_view_overlay, null);
    overlay.setActivityToSpoof(this);

    Toast toast = new Toast(getApplicationContext());
    toast.setGravity(Gravity.FILL, 0, 0);
    toast.setView(overlay);
    toast.show();
}
 
Example 12
Source File: CircularTabLayoutAdapter.java    From CircularViewPager with MIT License 5 votes vote down vote up
@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
Source File: HintedImageBtn.java    From android-discourse with Apache License 2.0 5 votes vote down vote up
private void handleLongClick() {
    String contentDesc = getContentDescription().toString();
    if (!TextUtils.isEmpty(contentDesc)) {
        int[] pos = new int[2];
        getLocationInWindow(pos);

        Toast t = Toast.makeText(mContext, contentDesc, Toast.LENGTH_SHORT);
        t.setGravity(Gravity.TOP | Gravity.LEFT, pos[0] - ((contentDesc.length() / 2) * 12), pos[1] - 128);
        t.show();
    }
}
 
Example 14
Source File: HintedImageView.java    From octoandroid with GNU General Public License v3.0 5 votes vote down vote up
private void handleLongClick() {
    String contentDesc = getContentDescription().toString();
    if (!TextUtils.isEmpty(contentDesc)) {
        int[] pos = new int[2];
        getLocationInWindow(pos);

        Toast t = Toast.makeText(getContext(), contentDesc, Toast.LENGTH_SHORT);
        t.setGravity(Gravity.TOP | Gravity.START, pos[0] - ((contentDesc.length() / 2) * 12), pos[1] - 256);
        t.show();
    }
}
 
Example 15
Source File: MainActivity.java    From Stock-Hawk with Apache License 2.0 5 votes vote down vote up
@Override
public void showStockDoesNotExist() {
    Toast toast = Toast.makeText(this, getResources().getString(R.string.stock_does_not_exist),
            Toast.LENGTH_LONG);
    toast.setGravity(Gravity.CENTER, Gravity.CENTER, 0);
    toast.show();
}
 
Example 16
Source File: GameActivity.java    From AndroidLinkup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 提示按钮按下时的处理
 * 
 * @param v
 */
public void prompt(View v) {
    if (LevelCfg.globalCfg.getPromptNum() > 0) {
        game.prompt();
    } else {
        // 没有可用道具时给出提示
        Toast toast = ToastUtil.getToast(this, R.string.tool_no_prompt);
        toast.setGravity(Gravity.BOTTOM | Gravity.CENTER, 0, 160);
        toast.show();
    }
}
 
Example 17
Source File: BaseFUDialogFrag.java    From sealrtc-android with MIT License 5 votes vote down vote up
public void showDescription(int res) {
    if (res == 0) return;
    TextView view = new TextView(getActivity());
    view.setText(res);
    view.setTextColor(Color.WHITE);
    view.setTextSize(33);
    view.setPadding(20, 20, 20, 20);
    view.setBackgroundResource(R.color.blink_transparent);
    Toast toast = new Toast(getActivity());
    toast.setGravity(Gravity.CENTER, 0, 100);
    toast.setDuration(Toast.LENGTH_SHORT);
    toast.setView(view);
    toast.show();
}
 
Example 18
Source File: ToastUtils.java    From A-week-to-develop-android-app-plan with Apache License 2.0 4 votes vote down vote up
public static void showCenterToast(Context context, String msg) {
	Toast toast = Toast.makeText(context, msg,  Toast.LENGTH_SHORT);
	toast.setGravity(Gravity.CENTER, 0, 0); 
	toast.show();
}
 
Example 19
Source File: ConversationUIService.java    From Applozic-Android-SDK with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
void showToastMessage(final String messageToShow) {
    Toast toast = Toast.makeText(fragmentActivity, messageToShow, Toast.LENGTH_SHORT);
    toast.setGravity(Gravity.CENTER, 0, 0);
    toast.show();
}
 
Example 20
Source File: ToastUtil.java    From AndroidLinkup with GNU General Public License v2.0 3 votes vote down vote up
/**
 * 根据字符串获取toast
 * 
 * @param ctx
 *            上下文
 * @param msg
 *            字符串
 * @return Toast对象
 */
public static Toast getToast(Context ctx, String msg) {
    Toast mToast = Toast.makeText(ctx, msg, Toast.LENGTH_SHORT);
    mToast.setText(msg);
    mToast.setGravity(Gravity.BOTTOM | Gravity.CENTER, 0, 20);
    mToast.setDuration(Toast.LENGTH_SHORT);
    return mToast;
}