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

The following are Jave code examples for showing how to use makeText() 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: ToastUtil   File: ToastUtil.java   View Source Code Vote up 6 votes
/**
 * Show a toast.
 *
 * @param text         The text to show.
 * @param durationLong Whether the toast show for a long period of time?
 * @param mode         The display mode to use.  Either {@link Mode#NORMAL} or {@link Mode#REPLACEABLE}
 */
public static void show(CharSequence text, boolean durationLong, Mode mode) {
    final int duration = durationLong ? Toast.LENGTH_LONG : Toast.LENGTH_SHORT;

    if (mode != Mode.REPLACEABLE) {
        Toast.makeText(sContext, text, duration).show();
        return;
    }

    if (sToast == null || sDuration != duration) {
        sDuration = duration;
        sToast = Toast.makeText(sContext, text, duration);
    } else {
        try {
            sToast.setText(text);
        } catch (RuntimeException e) {
            sToast = Toast.makeText(sContext, text, duration);
        }
    }
    sToast.show();
}
 
Example 2
Project: GlobalToast   File: GlobalToast.java   View Source Code Vote up 6 votes
public static void show(Context context, String msg, boolean isLong, int gravity) {
    if (context == null || msg == null) {
        return;
    }

    if (toast == null) { // Create Toast firstly.
        toast = Toast.makeText(context.getApplicationContext(), msg,
                isLong ? Toast.LENGTH_LONG : Toast.LENGTH_SHORT);
        defGravity = toast.getGravity();
        offsetX = toast.getXOffset();
        offsetY = toast.getYOffset();
    } else {
        toast.setDuration(isLong ? Toast.LENGTH_LONG : Toast.LENGTH_SHORT);
        toast.setText(msg);
    }

    if (gravity == -1) {
        toast.setGravity(defGravity, offsetX, offsetY);
    } else {
        toast.setGravity(gravity, 0, 0);
    }

    toast.show();
}
 
Example 3
Project: ForeverLibrary   File: ToastUtils.java   View Source Code Vote up 6 votes
@SuppressLint("ShowToast")
public static void showLongCustomToast(final Context context, final String text) {

    if (Looper.myLooper() == Looper.getMainLooper()) {
        if (toast == null) {
            toast = Toast.makeText(context.getApplicationContext(), text, Toast.LENGTH_LONG);
        }
        toast.setText(text);
        toast.show();
    } else {
        HandlerUtils.getHandler().post(new Runnable() {
            @Override
            public void run() {
                if (toast == null) {
                    toast = Toast.makeText(context.getApplicationContext(), text, Toast.LENGTH_LONG);
                }
                toast.setText(text);
                toast.show();
            }
        });
    }
}
 
Example 4
Project: VR-One   File: SignInActivity.java   View Source Code Vote up 6 votes
@Override
public void onClick(View v) {
    //switch (v.getId()) {
    if (v.getId() == GoogleSignInButton){
        //case GoogleSignInButton: {
        if(isNetworkAvailable(this)) {
            signIn();
        } else {
            Toast toast = Toast.makeText(getApplicationContext(),
                    getResources().getString(R.string.network_unavailable_toast), Toast.LENGTH_SHORT);
            toast.show();
        }
            //break;
        //}
    }
    else if (v.getId() == SkipSignInButton) {
        Intent intent = new Intent(SignInActivity.this, MainActivity.class);
        startActivity(intent);
    }
}
 
Example 5
Project: CollegeDoc   File: MainActivity.java   View Source Code Vote up 6 votes
public void checkconnection()
{
    ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    android.net.NetworkInfo wifi = cm
            .getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    android.net.NetworkInfo datac = cm
            .getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
    if ((wifi != null & datac != null)
            && (wifi.isConnected() | datac.isConnected())) {
        //connection is avlilable
    }else{
        //no connection
        Toast toast = Toast.makeText(MainActivity.this, "No Internet Connection Please make Internet for Contine",
                Toast.LENGTH_SHORT);
        toast.show();
    }
}
 
Example 6
Project: rxjava2_retrofit2   File: ToastUtils.java   View Source Code Vote up 5 votes
public static void show(String text) {
    if (toast == null) {
        toast = Toast.makeText(MyApplication.getInstance(), "", Toast.LENGTH_SHORT);
        toast.setGravity(Gravity.CENTER, 0, 0);
    }
    toast.setText(text);
    toast.show();
}
 
Example 7
Project: RLibrary   File: ToastUtils.java   View Source Code Vote up 5 votes
/**
 * 显示吐司
 *
 * @param text     文本
 * @param duration 显示时长
 */
private static void showToast(CharSequence text, int duration) {
    if (isJumpWhenMore) cancelToast();
    if (sToast == null) {
        sToast = Toast.makeText(Utils.getContext(), text, duration);
    } else {
        sToast.setText(text);
        sToast.setDuration(duration);
    }
    sToast.show();
}
 
Example 8
Project: Supreme   File: ToastUtil.java   View Source Code Vote up 5 votes
/**
 * 弹出多个toast时, 不会一个一个的弹, 后面一个要显示的内容直接显示在当前的toast上
 */
public static void single(Context context,String msg) {
    if (toast == null) {
        toast = Toast.makeText(context, msg, Toast.LENGTH_SHORT);
    } else {
        toast.setText(msg);
    }
    toast.show();
}
 
Example 9
Project: TableView   File: TableViewListener.java   View Source Code Vote up 5 votes
private void showToast(String p_strMessage) {
    if (m_jToast == null) {
        m_jToast = Toast.makeText(m_jContext, "", Toast.LENGTH_SHORT);
    }

    m_jToast.setText(p_strMessage);
    m_jToast.show();
}
 
Example 10
Project: ServiceDownLoadApp-master   File: GetToast.java   View Source Code Vote up 5 votes
public static Toast setToastPosition(Context context, String string ,int grivity,int xOffset, int yOffset){
	if (context == null)
		return null;
	if(toast == null){
		toast = Toast.makeText(context,string,Toast.LENGTH_SHORT);
	}else{
		toast.setText(string);
	}
	toast.setGravity(grivity,xOffset, yOffset);
	return toast;
}
 
Example 11
Project: QNewsDemo   File: ActivityUtils.java   View Source Code Vote up 5 votes
public void showToast(CharSequence msg) {
    Activity activity = getActivity();
    if (activity != null) {
        if (toast == null) toast = Toast.makeText(activity, msg, Toast.LENGTH_SHORT);
        toast.setText(msg);
        toast.show();
    }
}
 
Example 12
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 13
Project: ThunderMusic   File: MediaPlaybackCarModeActivity.java   View Source Code Vote up 5 votes
private void showToast(int resid) {
    if (mToast == null) {
        mToast = Toast.makeText(this, "", Toast.LENGTH_SHORT);
    }
    mToast.setText(resid);
    mToast.show();
}
 
Example 14
Project: sctalk   File: MessageActivity.java   View Source Code Vote up 5 votes
public void showToast(int resId) {
    String text = getResources().getString(resId);
    if (mToast == null) {
        mToast = Toast.makeText(MessageActivity.this, text, Toast.LENGTH_SHORT);
    } else {
        mToast.setText(text);
        mToast.setDuration(Toast.LENGTH_SHORT);
    }
    mToast.setGravity(Gravity.CENTER, 0, 0);
    mToast.show();
}
 
Example 15
Project: Closet   File: HintUtils.java   View Source Code Vote up 5 votes
public void displayShortToast(Context context,String msg){
    if(context == null){
        return;
    }
    if(mToast == null){
        mToast = Toast.makeText(context, msg, Toast.LENGTH_SHORT);
    }
    mToast.setText(msg);
    mToast.show();
}
 
Example 16
Project: TextReader   File: ToastUtils.java   View Source Code Vote up 5 votes
public static Toast getSingleToast(String text, int duration) {
    if (mToast == null) {
        mToast = Toast.makeText(context, text, duration);
    } else {
        mToast.setText(text);
    }
    return mToast;
}
 
Example 17
Project: MegviiFacepp-Android-SDK   File: ConUtil.java   View Source Code Vote up 5 votes
/**
 * 输出toast
 */
public static void showToast(Context context, String str) {
	if (context != null) {
		Toast toast = Toast.makeText(context, str, Toast.LENGTH_SHORT);
		// 可以控制toast显示的位置
		toast.setGravity(Gravity.TOP, 0, 30);
		toast.show();
	}
}
 
Example 18
Project: LQRWeChat-master   File: UIUtils.java   View Source Code Vote up 5 votes
public static void showToast(String msg, int duration) {
    if (mToast == null) {
        mToast = Toast.makeText(getContext(), "", duration);
    }
    mToast.setText(msg);
    mToast.show();
}
 
Example 19
Project: DailyStudy   File: Utility.java   View Source Code Vote up 5 votes
public static void showToast(Context context, String desc) {
    if (toast == null) {
        toast = Toast.makeText(context, desc, Toast.LENGTH_SHORT);
    } else {
        toast.setText(desc);
    }
    toast.show();
}
 
Example 20
Project: Cybernet-VPN   File: MyService.java   View Source Code Vote up 4 votes
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    Toast.makeText(getApplicationContext(), "I've been started", Toast.LENGTH_LONG);
    return super.onStartCommand(intent, flags, startId);
}