Java Code Examples for android.widget.Toast.LENGTH_LONG

The following are Jave code examples for showing how to use LENGTH_LONG 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: CommonDependence   File: UIToast.java   View Source Code Vote up 6 votes
/**
 * {@link #tintDrawable(Drawable, ColorStateList)}
 * @param content content to show
 * @param longTime short or long
 * @param context context
 * @param textColor toast text color
 * @param toastBackgroundColor toast background color
 */
public static void showToast(@NonNull Context context, String content, boolean longTime,@ColorInt int toastBackgroundColor ,@ColorInt
        int textColor) {
    int type = longTime ? Toast.LENGTH_LONG : Toast.LENGTH_SHORT;
    Toast toast = Toast.makeText(context, content, type);
    View toastView = toast.getView();
    TextView textView = (TextView) toastView.findViewById(android.R.id.message);
    if (toastBackgroundColor != 0){
        Drawable toastBackgroundDrawable = tintDrawable(toastView.getBackground(), ColorStateList.valueOf(toastBackgroundColor));
        toastView.setBackgroundDrawable(toastBackgroundDrawable);
    }
    if (textColor!=0){
        textView.setTextColor(textColor);
    }
    toast.setView(toastView);
    toast.setText(content);
    toast.show();
}
 
Example 2
Project: CommonDependence   File: UIToast2.java   View Source Code Vote up 6 votes
/**
 * {@link layout/transient_notification.xml}
 * @param content content to show
 * @param longTime short or long
 * @param context context
 * @param textColor toast text color
 * @param toastBackgroundColor toast background color
 */
public static void showToast(@NonNull Context context, String content, boolean longTime, @ColorInt
        int textColor,@ColorInt int toastBackgroundColor) {
    int type = longTime ? Toast.LENGTH_LONG : Toast.LENGTH_SHORT;
    Toast toast = Toast.makeText(context, content, type);
    ViewGroup toastView = (ViewGroup) LayoutInflater.from(context).inflate(R.layout
            .layout_toast, null, false);
    if (toastBackgroundColor != 0) {
        toastView.setBackgroundDrawable(getToastBackground(context, toastBackgroundColor));
    }
    TextView textView = (TextView) toastView.findViewById(android.R.id.message);
    // 内部已经作非空判断了
    if (textColor!=0){
        textView.setTextColor(textColor);
    }
    Typeface typeface = Typeface.create("sans-serif-condensed", Typeface.NORMAL);
    textView.setTypeface(typeface);
    toast.setView(toastView);
    toast.setText(content);
    toast.show();
}
 
Example 3
Project: symmetric-android-client-demo   File: MainActivity.java   View Source Code Vote up 6 votes
public File getStorageDir(Context context, String directoryName) {
    File file =
            new File(Environment.getExternalStoragePublicDirectory("/"), directoryName);

    System.out.println("canRead " + Environment.getExternalStorageDirectory().canRead());
    System.out.println("canWrite " + Environment.getExternalStorageDirectory().canWrite());

    boolean ok = file.mkdirs(); //create folders where write files
    if (!ok) {
        CharSequence text = "Failed to create dir " + file;
        int duration = Toast.LENGTH_LONG;

        Toast toast = Toast.makeText(context, text, duration);
        toast.show();
    }
    return file;
}
 
Example 4
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 5
Project: mininoteview   File: TextEdit.java   View Source Code Vote up 6 votes
public void run()
{
	String s = aFile.getName();
	setTitleBarText(aFile.getName());


	progressDlg.dismiss();
	int duration = Toast.LENGTH_LONG;
	Toast.makeText(TextEdit.this, getString(R.string.toast_save) + ": " + s, duration).show();


	setResultForActionGetContent();

	if(closeAfterSaveFlag)
	{
		finish();
	}

	messageDigest = getMessageDigest();
}
 
Example 6
Project: LuaViewPlayground   File: ToastUtil.java   View Source Code Vote up 5 votes
/**
 * show a toast using resource Globals.getId()
 *
 * @param context
 * @param resId
 * @param isLong
 */
public static void showToast(final Context context, final int resId, final boolean isLong) {
    if (isLong) {
        LENGTH = Toast.LENGTH_LONG;
    } else {
        LENGTH = Toast.LENGTH_SHORT;
    }
    showToast(context, context.getString(resId));
}
 
Example 7
Project: weex-3d-map   File: WXModalUIModule.java   View Source Code Vote up 5 votes
@WXModuleAnno
public void toast(String param) {

  String message = "";
  int duration = Toast.LENGTH_SHORT;
  if (!TextUtils.isEmpty(param)) {
    try {
      param = URLDecoder.decode(param, "utf-8");
      JSONObject jsObj = new JSONObject(param);
      message = jsObj.optString(MESSAGE);
      duration = jsObj.optInt(DURATION);
    } catch (Exception e) {
      WXLogUtils.e("[WXModalUIModule] alert param parse error ", e);
    }
  }
  if (TextUtils.isEmpty(message)) {
    WXLogUtils.e("[WXModalUIModule] toast param parse is null ");
    return;
  }

  if (duration > 3) {
    duration = Toast.LENGTH_LONG;
  } else {
    duration = Toast.LENGTH_SHORT;
  }
  if(toast== null){
    toast =Toast.makeText(mWXSDKInstance.getContext(), message, duration);
  } else {
    toast.setDuration(duration);
    toast.setText(message);
  }
  toast.setGravity(Gravity.CENTER, 0, 0);
  toast.show();
}
 
Example 8
Project: ucar-weex-core   File: WXModalUIModule.java   View Source Code Vote up 5 votes
@JSMethod(uiThread = true)
public void toast(String param) {

  String message = "";
  int duration = Toast.LENGTH_SHORT;
  if (!TextUtils.isEmpty(param)) {
    try {
      param = URLDecoder.decode(param, "utf-8");
      JSONObject jsObj = JSON.parseObject(param);
      message = jsObj.getString(MESSAGE);
      duration = jsObj.getInteger(DURATION);
    } catch (Exception e) {
      WXLogUtils.e("[WXModalUIModule] alert param parse error ", e);
    }
  }
  if (TextUtils.isEmpty(message)) {
    WXLogUtils.e("[WXModalUIModule] toast param parse is null ");
    return;
  }

  if (duration > 3) {
    duration = Toast.LENGTH_LONG;
  } else {
    duration = Toast.LENGTH_SHORT;
  }
  if (toast == null) {
    toast = Toast.makeText(mWXSDKInstance.getContext(), message, duration);
  } else {
    toast.setDuration(duration);
    toast.setText(message);
  }
  toast.setGravity(Gravity.CENTER, 0, 0);
  toast.show();
}
 
Example 9
Project: BlackList   File: Permissions.java   View Source Code Vote up 5 votes
/**
 * Checks for permissions and notifies the user if they aren't granted
 **/
public static void notifyIfNotGranted(@NonNull Context context) {
    StringBuilder sb = new StringBuilder();
    int count = 0;
    for (String permission : PERMISSIONS) {
        if (!isGranted(context, permission)) {
            if (count > 0) {
                sb.append("\n");
            }
            String info = getPermissionInfo(context, permission);
            sb.append(info);
            sb.append(";");
            count++;
        }
    }

    if (count > 0) {
        int duration;
        String message = context.getString(R.string.app_name) + " ";
        if (count == 1) {
            duration = Toast.LENGTH_SHORT;
            message += context.getString(R.string.needs_permission) + ":\n" + sb.toString();
        } else {
            duration = Toast.LENGTH_LONG;
            message += context.getString(R.string.needs_permissions) + ":\n" + sb.toString();
        }
        Utils.showToast(context, message, duration);
    }
}
 
Example 10
Project: mobiletailchanger   File: MainActivity.java   View Source Code Vote up 5 votes
void toastText(String text, Boolean isLong)
{
	int i;
	if (isLong)
		i = Toast.LENGTH_LONG;
	else
		i = Toast.LENGTH_SHORT;
	Toast.makeText(getApplicationContext(), text, i).show();
}
 
Example 11
Project: ToastCompat   File: CustomToast.java   View Source Code Vote up 5 votes
@Override
public IBuilder setDuration(long durationMillis) {
    if (durationMillis < 0) {
        mBuilderDurationMillis = 0;
    }
    if (durationMillis == Toast.LENGTH_SHORT) {
        mBuilderDurationMillis = 2000;
    } else if (durationMillis == Toast.LENGTH_LONG) {
        mBuilderDurationMillis = 3500;
    } else {
        mBuilderDurationMillis = durationMillis;
    }
    return this;
}
 
Example 12
Project: CXJPadProject   File: ToastUtil.java   View Source Code Vote up 5 votes
public static void showToast(Context context, String msg) {
    if (msg == null || "".equals(msg)) {
        return;
    }
    int duration = msg.length() > 15 ? Toast.LENGTH_LONG : Toast.LENGTH_SHORT;
    if (mToast == null) {
        mToast = Toast.makeText(context, msg, duration);
    } else {
        mToast.setText(msg);
        mToast.setDuration(duration);
    }
    mToast.show();
}
 
Example 13
Project: OSchina_resources_android   File: SimplexToast.java   View Source Code Vote up 5 votes
public static void show(Context context, String content, int gravity, int duration) {
    long current = System.currentTimeMillis();
    //if (current < nextTimeMillis) return;
    if (mToast == null) init(context.getApplicationContext());
    mToast.setText(content);
    mToast.setDuration(duration);
    mToast.setGravity(gravity, 0, yOffset);
    nextTimeMillis = current + (duration == Toast.LENGTH_LONG ? 3500 : 2000);
    mToast.show();
}
 
Example 14
Project: AndroidToolbox   File: GNSSLocationService.java   View Source Code Vote up 5 votes
/**
 * Show message to user if needed
 * @param message
 */
protected void showMessage(String message) {
    Context context = getApplicationContext();
    int duration = Toast.LENGTH_LONG;

    Toast toast = Toast.makeText(context, message, duration);
    toast.show();
}
 
Example 15
Project: weex-uikit   File: WXModalUIModule.java   View Source Code Vote up 5 votes
@JSMethod(uiThread = true)
public void toast(String param) {

  String message = "";
  int duration = Toast.LENGTH_SHORT;
  if (!TextUtils.isEmpty(param)) {
    try {
      param = URLDecoder.decode(param, "utf-8");
      JSONObject jsObj = JSON.parseObject(param);
      message = jsObj.getString(MESSAGE);
      duration = jsObj.getInteger(DURATION);
    } catch (Exception e) {
      WXLogUtils.e("[WXModalUIModule] alert param parse error ", e);
    }
  }
  if (TextUtils.isEmpty(message)) {
    WXLogUtils.e("[WXModalUIModule] toast param parse is null ");
    return;
  }

  if (duration > 3) {
    duration = Toast.LENGTH_LONG;
  } else {
    duration = Toast.LENGTH_SHORT;
  }
  if (toast == null) {
    toast = Toast.makeText(mWXSDKInstance.getContext(), message, duration);
  } else {
    toast.setDuration(duration);
    toast.setText(message);
  }
  toast.setGravity(Gravity.CENTER, 0, 0);
  toast.show();
}
 
Example 16
Project: My-Sheep   File: AddKid.java   View Source Code Vote up 4 votes
public void toaster(String message, @NonNull String duration){
    int toastDuration;
    if (duration.equals("s")){toastDuration = Toast.LENGTH_SHORT;}
    else{toastDuration = Toast.LENGTH_LONG;}
    Toast.makeText(getApplicationContext(),message,toastDuration).show();
}
 
Example 17
Project: My-Sheep   File: MainActivity.java   View Source Code Vote up 4 votes
public void toaster(String message, @NonNull String duration){
    int toastDuration;
    if (duration.equals("s")){toastDuration = Toast.LENGTH_SHORT;}
    else{toastDuration = Toast.LENGTH_LONG;}
    Toast.makeText(getApplicationContext(),message,toastDuration).show();
}
 
Example 18
Project: U   File: Ut.java   View Source Code Vote up 4 votes
public Ut lengthLong() {
    length = Toast.LENGTH_LONG;
    return this;
}
 
Example 19
Project: Udacity_Gradle   File: MainActivity.java   View Source Code Vote up 3 votes
public void tellJoke(View view) {

        Context context = this;
        CharSequence text = this.getString(R.string.toast_text);
        int duration = Toast.LENGTH_LONG;

        Toast toast = Toast.makeText(context, text, duration);
        toast.show();


    }
 
Example 20
Project: Udacity_Gradle   File: MainActivity.java   View Source Code Vote up 3 votes
public void tellJoke(View view) {

        Context context = this;
        CharSequence text = this.getString(R.string.toast_text);
        int duration = Toast.LENGTH_LONG;

        Toast toast = Toast.makeText(context, text, duration);
        toast.show();


    }