Example usage for android.widget Toast Toast

List of usage examples for android.widget Toast Toast

Introduction

In this page you can find the example usage for android.widget Toast Toast.

Prototype

public Toast(Context context) 

Source Link

Document

Construct an empty Toast object.

Usage

From source file:com.gnufabio.costituzione.DetailedActivity.java

@SuppressWarnings("static-access")
public boolean onOptionsItemSelected(MenuItem item) {
    super.onOptionsItemSelected(item);
    switch (item.getItemId()) {

    case R.id.favourite_status:
        DatabaseHandler dbh = new DatabaseHandler(this);
        dbh.open(true);/*w w  w  .  jav  a2 s  .  c o  m*/
        mEntry.setIsFavourite(!mEntry.isFavourite());
        dbh.updateFavoriteStatus(mEntry);
        dbh.close();

        new Toast(this).makeText(this, mEntry.isFavourite() ? R.string.added_to_fav : R.string.removed_from_fav,
                Toast.LENGTH_LONG).show();
        updateFavoriteButton(item);
        break;
    case R.id.menu_edit_note:
        AlertDialog.Builder alert = new AlertDialog.Builder(this);
        alert.setTitle(R.string.dialog_update_note);

        final EditText input = new EditText(this);
        String nota = mNote.getTesto();
        input.setText(nota.equalsIgnoreCase("@Null") ? "" : nota);
        alert.setView(input);

        alert.setPositiveButton(mContext.getResources().getString(android.R.string.ok),
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        int pos = vp.getCurrentItem();
                        String value = input.getText().toString();
                        NotesDatabaseHandler ndbh = new NotesDatabaseHandler(mContext);
                        ndbh.open(true);
                        mNote.setTesto(value);
                        ndbh.updateNote(mNote);
                        ndbh.close();
                        listNotes.remove(pos);
                        listNotes.add(pos, mNote);
                        DetailedFragmentAdapter adapter = (DetailedFragmentAdapter) vp.getAdapter();
                        adapter.getItem(pos).setNoteText(value);
                        adapter.updateNote(pos, mNote);
                        vp.setAdapter(adapter);
                        vp.setCurrentItem(pos, false);
                    }
                });

        alert.setNegativeButton(mContext.getResources().getString(android.R.string.cancel), null);
        alert.show();
        break;
    }
    return true;
}

From source file:io.plaidapp.ui.DribbbleLogin.java

void showLoggedInUser() {
    final Call<User> authenticatedUser = dribbblePrefs.getApi().getAuthenticatedUser();
    authenticatedUser.enqueue(new Callback<User>() {
        @Override/*from   www  . ja  v  a 2s.co  m*/
        public void onResponse(Call<User> call, Response<User> response) {
            final User user = response.body();
            dribbblePrefs.setLoggedInUser(user);
            final Toast confirmLogin = new Toast(getApplicationContext());
            final View v = LayoutInflater.from(DribbbleLogin.this)
                    .inflate(R.layout.toast_logged_in_confirmation, null, false);
            ((TextView) v.findViewById(R.id.name)).setText(user.name.toLowerCase());
            // need to use app context here as the activity will be destroyed shortly
            Glide.with(getApplicationContext()).load(user.avatar_url).placeholder(R.drawable.ic_player)
                    .transform(new CircleTransform(getApplicationContext()))
                    .into((ImageView) v.findViewById(R.id.avatar));
            v.findViewById(R.id.scrim).setBackground(ScrimUtil.makeCubicGradientScrimDrawable(
                    ContextCompat.getColor(DribbbleLogin.this, R.color.scrim), 5, Gravity.BOTTOM));
            confirmLogin.setView(v);
            confirmLogin.setGravity(Gravity.BOTTOM | Gravity.FILL_HORIZONTAL, 0, 0);
            confirmLogin.setDuration(Toast.LENGTH_LONG);
            confirmLogin.show();
        }

        @Override
        public void onFailure(Call<User> call, Throwable t) {
        }
    });
}

From source file:com.github.rutvijkumar.twittfuse.Util.java

public static void showNetworkUnavailable(Activity activity) {
    LayoutInflater inflater = activity.getLayoutInflater();
    View view = inflater.inflate(R.layout.network_not_available,
            (ViewGroup) activity.findViewById(R.id.nwunavailable));
    Toast toast = new Toast(activity);
    toast.setView(view);/*  w  ww  . j  a  va2  s  . c  om*/
    toast.setGravity(Gravity.CENTER, 0, 0);
    toast.setDuration(Toast.LENGTH_LONG);
    toast.show();

}

From source file:fiskinfoo.no.sintef.fiskinfoo.UtilityRows.ToolLogRow.java

public ToolLogRow(Context context, final ToolEntry tool, View.OnClickListener onClickListener) {
    super(context, R.layout.utility_row_tool_log_row);

    dateHeader = (TextView) getView().findViewById(R.id.tool_log_row_latest_date_text_view);
    toolTypeTextView = (TextView) getView().findViewById(R.id.tool_log_row_tool_type_text_view);
    toolPositionTextView = (TextView) getView().findViewById(R.id.tool_log_row_tool_position_text_view);
    toolNotificationImageView = (ImageView) getView().findViewById(R.id.tool_log_row_reported_image_view);
    editToolImageView = (ImageView) getView().findViewById(R.id.tool_log_row_edit_image_view);
    relativeLayout = (RelativeLayout) getView().findViewById(R.id.tool_log_row_relative_layout);
    StringBuilder sb = new StringBuilder();

    sb.append(FiskInfoUtility.decimalToDMS((tool.getCoordinates().get(0).getLatitude())));
    sb.append(", ");
    sb.append(FiskInfoUtility.decimalToDMS((tool.getCoordinates().get(0).getLongitude())));

    String coordinateString = sb.toString();
    coordinateString = tool.getCoordinates().size() < 2 ? coordinateString : coordinateString + "\n..";

    SimpleDateFormat sdf = new SimpleDateFormat(
            context.getString(R.string.datetime_format_yyyy_mm_dd_t_hh_mm_ss), Locale.getDefault());
    Date setupDate;//from w ww .  ja va 2s  . co  m
    String setupDateTime = "";
    sdf.setTimeZone(TimeZone.getTimeZone("UTC"));

    try {
        setupDate = sdf.parse(tool.getSetupDateTime());
        sdf.setTimeZone(TimeZone.getDefault());
        setupDateTime = sdf.format(setupDate);
    } catch (ParseException e) {
        e.printStackTrace();
    }

    toolPositionTextView.setText(coordinateString);
    editToolImageView.setVisibility(View.VISIBLE);
    relativeLayout.setOnClickListener(onClickListener);
    toolTypeTextView.setText(tool.getToolType().toString());
    dateHeader.setText(setupDateTime.replace("T", " ").substring(0, 16));

    if (tool.getToolStatus() != ToolEntryStatus.STATUS_RECEIVED
            && tool.getToolStatus() != ToolEntryStatus.STATUS_REMOVED) {
        toolNotificationImageView.setVisibility(View.VISIBLE);
        toolNotificationImageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int errorMessageId = -1;
                switch (tool.getToolStatus()) {
                case STATUS_REMOVED_UNCONFIRMED:
                case STATUS_SENT_UNCONFIRMED:
                    errorMessageId = R.string.notification_tool_sent_unconfirmed_changes;
                    break;
                case STATUS_UNREPORTED:
                case STATUS_UNSENT:
                    errorMessageId = R.string.notification_tool_not_reported;
                    break;
                default:
                    break;
                }

                if (errorMessageId != -1) {
                    new Toast(v.getContext()).makeText(v.getContext(), errorMessageId, Toast.LENGTH_LONG)
                            .show();
                }
            }
        });
    }

    highlightOldTool(true);
}

From source file:cn.apputest.ctria.section2.Lucha2Activity.java

void inti() {

    if (manager == null) {
        try {/*from w w  w  . jav  a 2s .c  om*/
            manager = Manager.getInstance();
        } catch (Exception e) {
            e.printStackTrace();
            // finish();
        }
    }
    openInterface();

    context = this.getParent();
    toast = new Toast(context);
    preferences = context.getSharedPreferences(Login.FILE_USER, MODE_PRIVATE);
    String DBName = preferences.getString(Login.KEY_NAME, "1");
    helper = new DBHelper(context, DBName + "_DB");
    mgr = new DBManager(helper);

    isNetworkConnected(context);
    qualificationsID = (EditText) findViewById(R.id.IDcardnum);
    driverlicenseID = (EditText) findViewById(R.id.DriverCardID);
    qualificationsID.addTextChangedListener(mTextWatcherjob);
    driverlicenseID.addTextChangedListener(mTextWatcherdriver);

    error1 = (TextView) findViewById(R.id.warning_P1);

    zheng1 = (TextView) findViewById(R.id.zheng_P1);
    zheng2 = (TextView) findViewById(R.id.zheng_P2);

    zheng1.setOnClickListener(this);
    zheng2.setOnClickListener(this);

    uploadrecordlucha = (RelativeLayout) findViewById(R.id.uploadrecordlucha);
    chancel1 = (RelativeLayout) findViewById(R.id.chancel1);

    uploadrecordlucha.setOnClickListener(this);
    chancel1.setOnClickListener(this);

    qualificationsID.setOnKeyListener(new OnKeyListener() {

        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            // TODO Auto-generated method stub
            if (keyCode == KeyEvent.KEYCODE_DEL) {
                error1.setText("");
                zheng2.setTextColor(getResources().getColor(R.color.black));
            }
            return false;
        }
    });
    driverlicenseID.setOnKeyListener(new OnKeyListener() {

        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            // TODO Auto-generated method stub
            if (keyCode == KeyEvent.KEYCODE_DEL) {

                error1.setText("");
                zheng1.setTextColor(getResources().getColor(R.color.black));

            }
            return false;
        }
    });
}

From source file:com.apptentive.android.sdk.module.engagement.interaction.fragment.SurveyFragment.java

@Override
public View onCreateView(final LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    if (interaction == null) {
        getActivity().finish();/*from ww  w .  j av  a2s .  c o  m*/
    }

    List<Question> questions = interaction.getQuestions();
    answers = new LinkedHashMap<String, Object>(questions.size());

    View v = inflater.inflate(R.layout.apptentive_survey, container, false);

    TextView description = (TextView) v.findViewById(R.id.description);
    description.setText(interaction.getDescription());

    final Button send = (Button) v.findViewById(R.id.send);

    String sendText = interaction.getSubmitText();
    if (!TextUtils.isEmpty(sendText)) {
        send.setText(sendText);
    }
    send.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Util.hideSoftKeyboard(getActivity(), view);
            boolean valid = validateAndUpdateState();
            if (valid) {
                if (interaction.isShowSuccessMessage() && !TextUtils.isEmpty(interaction.getSuccessMessage())) {
                    Toast toast = new Toast(getContext());
                    toast.setGravity(Gravity.FILL, 0, 0);
                    toast.setDuration(Toast.LENGTH_SHORT);
                    View toastView = inflater.inflate(R.layout.apptentive_survey_sent_toast,
                            (LinearLayout) getView().findViewById(R.id.survey_sent_toast_root));
                    toast.setView(toastView);
                    TextView actionTV = ((TextView) toastView.findViewById(R.id.survey_sent_action_text));
                    actionTV.setText(interaction.getSuccessMessage());
                    int actionColor = Util.getThemeColor(getContext(),
                            R.attr.apptentiveSurveySentToastActionColor);
                    if (actionColor != 0) {
                        actionTV.setTextColor(actionColor);
                        ImageView actionIcon = (ImageView) toastView.findViewById(R.id.survey_sent_action_icon);
                        actionIcon.setColorFilter(actionColor);
                    }
                    toast.show();
                }
                getActivity().finish();

                EngagementModule.engageInternal(getActivity(), interaction, EVENT_SUBMIT);

                ApptentiveInternal.getInstance().getApptentiveTaskManager()
                        .addPayload(new SurveyResponse(interaction, answers));
                ApptentiveLog.d("Survey Submitted.");
                callListener(true);
            } else {
                Toast toast = new Toast(getContext());
                toast.setGravity(Gravity.FILL_HORIZONTAL | Gravity.BOTTOM, 0, 0);
                toast.setDuration(Toast.LENGTH_SHORT);
                View toastView = inflater.inflate(R.layout.apptentive_survey_invalid_toast,
                        (LinearLayout) getView().findViewById(R.id.survey_invalid_toast_root));
                toast.setView(toastView);
                String validationText = interaction.getValidationError();
                if (!TextUtils.isEmpty(validationText)) {
                    ((TextView) toastView.findViewById(R.id.survey_invalid_toast_text)).setText(validationText);
                }
                toast.show();
            }
        }
    });

    questionsContainer = (LinearLayout) v.findViewById(R.id.questions);
    if (savedInstanceState == null) {
        questionsContainer.removeAllViews();

        // Then render all the questions
        for (int i = 0; i < questions.size(); i++) {
            Question question = questions.get(i);
            BaseSurveyQuestionView surveyQuestionView;
            if (question.getType() == Question.QUESTION_TYPE_SINGLELINE) {
                surveyQuestionView = TextSurveyQuestionView.newInstance((SinglelineQuestion) question);
            } else if (question.getType() == Question.QUESTION_TYPE_MULTICHOICE) {
                surveyQuestionView = MultichoiceSurveyQuestionView.newInstance((MultichoiceQuestion) question);

            } else if (question.getType() == Question.QUESTION_TYPE_MULTISELECT) {
                surveyQuestionView = MultiselectSurveyQuestionView.newInstance((MultiselectQuestion) question);
            } else if (question.getType() == Question.QUESTION_TYPE_RANGE) {
                surveyQuestionView = RangeSurveyQuestionView.newInstance((RangeQuestion) question);
            } else {
                surveyQuestionView = null;
            }
            if (surveyQuestionView != null) {
                surveyQuestionView.setOnSurveyQuestionAnsweredListener(this);
                getRetainedChildFragmentManager().beginTransaction()
                        .add(R.id.questions, surveyQuestionView, Integer.toString(i)).commit();
            }
        }
    } else {
        List<Fragment> fragments = getRetainedChildFragmentManager().getFragments();
        for (Fragment fragment : fragments) {
            BaseSurveyQuestionView questionFragment = (BaseSurveyQuestionView) fragment;
            questionFragment.setOnSurveyQuestionAnsweredListener(this);

        }
    }
    return v;
}

From source file:com.readystatesoftware.notificationlog.Log.java

/**
 * Initialize the NotificationLog so that subsequent calls to the various 
 * Log methods will send output to a notification in addition to the system 
 * log. If you do not call this method, this class behaves exactly as 
 * android.util.Log./*w w w .jav a 2s .c  o m*/
 * 
 * @param context your application context
 * @param icon drawable resource identifier to use as the notification icon
 */
public static void initialize(Context context, int icon) {
    sLog.mContext = context;
    sLog.mLogToast0 = new Toast(context);
    sLog.mLogToast1 = new Toast(context);
    sLog.mIcon = (icon == 0) ? context.getApplicationInfo().icon : icon;
    sLog.mLabel = context.getString(context.getApplicationInfo().labelRes);

    sLog.mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    sLog.mPrefs = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);

    sLog.mLevel = sLog.mPrefs.getInt(PREF_LEVEL, VERBOSE);
    sLog.mFilter = sLog.mPrefs.getString(PREF_FILTER, null);

    Intent intent = new Intent(context, LogActivity.class);
    sLog.mViewIntent = PendingIntent.getActivity(context, 0, intent, 0);

    Intent filterIntent = new Intent(context, LogActivity.class);
    filterIntent.putExtra(LogActivity.ARG_ACTION, LogActivity.ACTION_FILTER);
    sLog.mFilterIntent = PendingIntent.getActivity(context, 4, filterIntent, 0);

    Intent levelIntent = new Intent(context, LogActivity.class);
    levelIntent.putExtra(LogActivity.ARG_ACTION, LogActivity.ACTION_LEVEL);
    sLog.mLevelIntent = PendingIntent.getActivity(context, 2, levelIntent, 0);

    Intent clearIntent = new Intent(context, LogActivity.class);
    clearIntent.putExtra(LogActivity.ARG_ACTION, LogActivity.ACTION_CLEAR);
    sLog.mClearIntent = PendingIntent.getActivity(context, 3, clearIntent, 0);

    sLog.mActivityIntegrationAvailable = isActivityAvailable(context, LogActivity.class.getName());
}

From source file:cz.babi.android.remoteme.service.ConnectionService.java

@Override
public void onDestroy() {
    if (Common.DEBUG)
        Log.d(TAG_CLASS_NAME, "[onDestroy]");

    /* Cancel the persistent notification. */
    if (isNotificationVisible)
        notificationManager.cancel(NOTIFICATION_ID);

    /* If Wi-Fi is locked we need to unlock it. */
    if (wifiLock.isHeld())
        unlockWifi();/*from w  w w.  j  a  v a 2  s. c om*/

    /* If there was no error we send 'bye bye' message to server and show toast to user. */
    if (!disconnectWithError) {
        /* Just tell to server that we are disconnecting. */
        SimpleMessage byeBye = Message.BYE_BYE;

        String message = byeBye.toString();
        if (needEncryptedCommunication)
            message = AES128_DEFAULT.encryptText(byeBye.toString());

        out.println(message);
        out.flush();

        /* Tell the user we stopped. */
        LayoutInflater mInflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View toastLayout = mInflater.inflate(R.layout.toast_normal, null);

        TextView text = (TextView) toastLayout.findViewById(R.id.normal_text);
        text.setText(R.string.connection_service_disconnected_text);

        Toast toast = new Toast(this);
        toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
        toast.setDuration(Toast.LENGTH_LONG);
        toast.setView(toastLayout);
        toast.show();
    }
}

From source file:com.geomoby.geodeals.DemoService.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.geomoby_main);
    mContext = this;

    mToggle = (CompoundButton) findViewById(R.id.togglebutton);

    spref = getSharedPreferences(PREF_NAME, MODE_PRIVATE);
    isCheckedStatus = spref.getBoolean("check", false); //default is false

    /*//from  w  w  w . j  a va2s.  co  m
     * Set up toggle status
     */
    if (!isCheckedStatus)
        mToggle.setChecked(false);
    else
        mToggle.setChecked(true);

    /*
     *  Save the tags in the GeoMoby shared preferences in private mode for the user. These tags will be used
     *  to segment your audience when creating your proximity alerts. Please make sure that they match with
     *  the ones configured in your dashboard when you create an alert.
     *  Ex: 'test' is the default tag so make sure that it is set up in your Account page
     */
    SharedPreferences mySharedPreferences = getSharedPreferences(PREF, MODE_PRIVATE);

    // Build the string of tags - empty for testing. Make sure that you create your first geofences with no tags in your dashboard.
    // Add your own logic here: "male,vip,monday"...
    String tags = "";

    // Commit the string
    SharedPreferences.Editor prefEditor = mySharedPreferences.edit();
    prefEditor.putString(SETTING_TAGS, tags);
    prefEditor.commit();

    /*
     *  Monitor the toggle - Our SDK will ensure that all services are running/stopping properly
     */
    mToggle.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {

            if (isChecked == false) {

                mToggle.setPressed(false);

                // Stop the GeoMoby tracking service
                startService(new Intent(DemoService.this, GeomobyStopService.class));

                SharedPreferences.Editor editor = spref.edit();
                editor.putBoolean("check", false);
                editor.commit();

            } else {

                mToggle.setPressed(true);

                // Start the GeoMoby tracking service
                startService(new Intent(DemoService.this, GeomobyStartService.class));

                SharedPreferences.Editor editor = spref.edit();
                editor.putBoolean("check", true);
                editor.commit();

                LayoutInflater inflater = getLayoutInflater();
                // Inflate the Layout
                View layout = inflater.inflate(R.layout.geomoby_toast,
                        (ViewGroup) findViewById(R.id.custom_toast_layout));

                // Set the Text to show in TextView
                TextView text = (TextView) layout.findViewById(R.id.textToShow);
                text.setText("GREAT! YOU ARE READY TO RECEIVE REAL-TIME NOTIFICATIONS!");
                Typeface face;
                face = Typeface.createFromAsset(getAssets(), "Bitter-Bold.otf");
                text.setTypeface(face);

                Toast toast = new Toast(getApplicationContext());
                toast.setGravity(Gravity.BOTTOM, 0, 50);
                toast.setDuration(Toast.LENGTH_LONG);
                toast.setView(layout);
                toast.show();
            }
        }
    });

    // Initialise GeoMoby Notification Listener
    GeomobyNotificationsReceiver receiver = new GeomobyNotificationsReceiver();
    receiver.setNotificationListener(this);
}

From source file:com.mb.kids_mind.GcmIntentService.java

public void ToastAll(Context context, String msg) {

    LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View layout = inflater.inflate(R.layout.toast_layout, null);

    Toast mToast = new Toast(context.getApplicationContext());

    mToast.setGravity(Gravity.CENTER_VERTICAL, 0, 2);
    mToast.setDuration(Toast.LENGTH_SHORT);
    mToast.setView(layout);//from w  w w  .  j av a 2s  .c o m
    if (flag == false) {
        flag = true;
        mToast.show();
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                flag = false;
            }
        }, 2000);//  ?    ?? 2   .
    } else {
        Log.e("", " ?");
    }

}