Android Open Source - WhichFuel Toast Control






From Project

Back to project page WhichFuel.

License

The source code is released under:

MIT License

If you think the Android project WhichFuel listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package essential;
/*  w  w  w  .j a v a 2 s .  c  o m*/
import android.content.Context;
import android.util.Log;
import android.widget.Toast;

public class ToastControl {
  private final String LOG_FILTER = "ESSENTIAL"; // To see all this class
                          // method use this filter
                          // name at LogCat
  private final Context context;
  private Toast toast;

  public ToastControl(Context context) {
    this.context = context;
  }

  public boolean setToast(String text, int duration) {
    try {
      destroyToast();
      toast = Toast.makeText(context, text, duration);
      toast.show();
    } catch (NullPointerException e) {
      Log.e(LOG_FILTER, "On SetToast => Error at setToast! 1a");
      return false; // Error on this method
    }
    return true;
  }

  public boolean setToast(String text, int duration, int gravity, int x, int y) {
    try {
      destroyToast();
      toast.setGravity(gravity, x, y);
      toast = Toast.makeText(context, text, duration);
      toast.show();
    } catch (NullPointerException e) {
      Log.e(LOG_FILTER, "On SetToast => Error at setToast! 1b");
      return false; // Error on this method
    }
    return true; // Method executed with success
  }

  public boolean createToast(Context context) {
    Log.d(LOG_FILTER, "createToast Called...");
    if (isToastAlreadyCreated()) {
      Log.i(LOG_FILTER, "Toast is already created !");
      return false;
    }

    if (context == null) {
      Log.e(LOG_FILTER, "createToast => <params> context is null...");
      return false;
    }

    toast = new Toast(context);
    Log.i(LOG_FILTER, "Toast created.");
    return true;
  }

  private boolean isToastAlreadyCreated() {
    return toast != null;
  }

  public void destroyToast() {
    Log.d(LOG_FILTER, "destroyToast called !");

    try {
      toast.cancel();
    } catch (NullPointerException e) {
      Log.i(LOG_FILTER, "Erro at destroyToast...");
    }
  }
}




Java Source Code List

.Premium.java
com.android.fuel.MainActivity.java
com.android.fuel.SecondActivity.java
com.android.fuel.SettingsActivity.java
control.Control.java
control.Control.java
dev.android.combustivel.BuildConfig.java
dev.android.combustivel.MainActivity.java
dev.android.combustivel.MyActivity.java
dev.android.combustivel.SettingsActivity.java
essential.ToastControl.java