Example usage for android.widget Toast show

List of usage examples for android.widget Toast show

Introduction

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

Prototype

public void show() 

Source Link

Document

Show the view for the specified duration.

Usage

From source file:cm.aptoide.pt.webservices.comments.Comments.java

public void postComment(String repo, String apkid, String version, String comment, String username) {
    if (!submitting) {
        new CommentPoster().execute(Login.getToken(context), repo, apkid, version, comment, username);
    } else {//ww  w. ja v a 2s  .  co m
        Toast toast = Toast.makeText(context, context.getString(R.string.another_comment_is_beeing_submited),
                Toast.LENGTH_SHORT);
        toast.show();
    }
}

From source file:cmput301.f13t01.editstory.EditStoryActivity.java

private void onSelectDelete() {
    GlobalManager.getLocalManager().removeStory(storyId);

    Toast toast = Toast.makeText(getApplicationContext(), getResources().getString(R.string.story_delete_toast),
            Toast.LENGTH_SHORT);//w  w w.  j  ava2s  . c o  m
    toast.show();
    finish();
}

From source file:com.ehdev.chronos.lib.Chronos.java

static public boolean getDataOnSDCard(Context context, boolean oldFormat) {
    if (getCardReadStatus() == false) {

        CharSequence text = "Could not read to SD Card!.";
        int duration = Toast.LENGTH_SHORT;

        Toast toast = Toast.makeText(context, text, duration);
        toast.show();
        return false;
    }// w ww  . j  a  v  a  2 s.  c  o  m

    //Create 1 Job
    DateTime jobMidnight = DateTime.now().withDayOfWeek(7).minusWeeks(1).toDateMidnight().toDateTime()
            .withZone(DateTimeZone.getDefault());
    Job currentJob = new Job("", 10, jobMidnight, PayPeriodDuration.TWO_WEEKS);
    currentJob.setDoubletimeThreshold(60);
    currentJob.setOvertimeThreshold(40);
    currentJob.setOvertimeOptions(OvertimeOptions.WEEK);

    List<Punch> punches = new LinkedList<Punch>();
    List<Task> tasks = new LinkedList<Task>();
    List<Note> notes = new LinkedList<Note>();

    Task newTask; //Basic element
    newTask = new Task(currentJob, 0, "Regular");
    tasks.add(newTask);
    newTask = new Task(currentJob, 1, "Lunch Break");
    newTask.setEnablePayOverride(true);
    newTask.setPayOverride(0.0f);
    tasks.add(newTask);
    newTask = new Task(currentJob, 2, "Other Break");
    newTask.setEnablePayOverride(true);
    newTask.setPayOverride(0.0f);
    tasks.add(newTask);
    newTask = new Task(currentJob, 3, "Travel");
    tasks.add(newTask);
    newTask = new Task(currentJob, 4, "Admin");
    tasks.add(newTask);
    newTask = new Task(currentJob, 5, "Sick Leave");
    tasks.add(newTask);
    newTask = new Task(currentJob, 6, "Personal Time");
    tasks.add(newTask);
    newTask = new Task(currentJob, 7, "Other");
    tasks.add(newTask);
    newTask = new Task(currentJob, 8, "Holiday Pay");
    tasks.add(newTask);

    try {
        File directory = Environment.getExternalStorageDirectory();
        File backup;
        if (!oldFormat)
            backup = new File(directory, "Chronos_Backup.csv");
        else
            backup = new File(directory, "Chronos_Backup.cvs");
        if (!backup.exists()) {
            return false;
        }

        BufferedReader br = new BufferedReader(new FileReader(backup));
        String strLine = br.readLine();

        //id,date,name,task name, date in ms, job num, task num
        //1,Sun Mar 11 2012 15:46,null,Regular,1331498803269,1,1
        while (strLine != null) {
            //Log.d(TAG, strLine);
            String[] parcedString = strLine.split(",");
            long time;
            int task;

            if (!oldFormat) {
                time = Long.parseLong(parcedString[4]);
                task = Integer.parseInt(parcedString[6]);
            } else {
                time = Long.parseLong(parcedString[1]);
                task = Integer.parseInt(parcedString[2]);
                //System.out.println(parcedString.length);

                if (parcedString.length > 4 && StringUtils.isNotBlank(parcedString[4])) {
                    String noteContent = parcedString[4];
                    Note note = new Note(Chronos.getDateFromStartOfPayPeriod(currentJob, new DateTime(time)),
                            currentJob, noteContent);
                    notes.add(note);
                }
            }

            //Job iJob, Task iPunchTask, DateTime iTime
            punches.add(new Punch(currentJob, tasks.get(task - 1), new DateTime(time)));
            strLine = br.readLine();
        }
    } catch (Exception e) {

        e.printStackTrace();
        if (e != null && e.getCause() != null) {
            Log.e(TAG, e.getCause().toString());
        }
        return false;
    }

    //Log.d(TAG, "Number of punches: " + punches.size());
    try {
        Chronos chronos = new Chronos(context);
        TableUtils.dropTable(chronos.getConnectionSource(), Punch.class, true); //Punch - Drop all
        TableUtils.dropTable(chronos.getConnectionSource(), Task.class, true); //Task - Drop all
        TableUtils.dropTable(chronos.getConnectionSource(), Job.class, true); //Job - Drop all
        TableUtils.dropTable(chronos.getConnectionSource(), Note.class, true); //Note - Drop all

        //Recreate DB
        TableUtils.createTable(chronos.getConnectionSource(), Punch.class); //Punch - Create Table
        TableUtils.createTable(chronos.getConnectionSource(), Task.class); //Task - Create Table
        TableUtils.createTable(chronos.getConnectionSource(), Job.class); //Job - Create Table
        TableUtils.createTable(chronos.getConnectionSource(), Note.class); //Task - Create Table

        //recreate entries
        Dao<Task, String> taskDAO = chronos.getTaskDao();
        Dao<Job, String> jobDAO = chronos.getJobDao();
        Dao<Punch, String> punchDOA = chronos.getPunchDao();
        Dao<Note, String> noteDOA = chronos.getNoteDao();

        jobDAO.create(currentJob);

        for (Task t : tasks) {
            taskDAO.create(t);
        }

        for (Punch p : punches) {
            punchDOA.create(p);
        }

        HashMap<DateTime, Note> merger = new HashMap<DateTime, Note>();
        for (Note n : notes) {
            merger.put(n.getTime(), n);
        }

        for (DateTime dt : merger.keySet()) {
            noteDOA.create(merger.get(dt));
        }

        chronos.close();

    } catch (Exception e) {
        Log.e(TAG, e.getMessage());
        return false;
    }

    return true;
}

From source file:cmput301.f13t01.editstory.EditStoryActivity.java

/**
 * Define Back behaviour// w  w w. ja  v  a  2  s.co m
 */
public void onBackPressed() {

    EditText title = (EditText) findViewById(R.id.edit_story_title);
    EditText author = (EditText) findViewById(R.id.edit_story_author);
    EditText desc = (EditText) findViewById(R.id.edit_story_description);

    manager.setTitle(title.getText().toString());
    manager.setAuthor(author.getText().toString());
    manager.setDescription(desc.getText().toString());

    GlobalManager.saveStory(storyId);

    Toast toast = Toast.makeText(getApplicationContext(), getResources().getString(R.string.story_save_toast),
            Toast.LENGTH_SHORT);
    toast.show();
    finish();
}

From source file:com.example.Android.LoginActivity.java

private void InitializePXI() {
    try {/*from  www  .j ava  2  s. c o  m*/
        /*context = getApplicationContext();
        // Check device for Play Services APK. If check succeeds, proceed with GCM registration.
        if (checkPlayServices())
        {
            // Add some delay
            for (int i = 0; i < 3; i++)
            {
                Log.i(TAG, "Working... " + (i + 1)
                        + "/5 @ " + SystemClock.elapsedRealtime());
                try
                {
                    Thread.sleep(500);
                }
                catch (InterruptedException e)
                {
                }
            }
            mDisplay.append("Registering with GCM... ");
            gcm = GoogleCloudMessaging.getInstance(this);
            regid = getRegistrationId(context);
                
            Constants.RegistrationId = regid;
                
            if (regid.isEmpty())
            {
                RegisterWithGCMServerInBackground();
            }
            else
            {
                mDisplay.append("Already Registered" + "\n");
                RegisterWithPXIServer();
            }
        }
        else
        {
            Log.i(TAG, "No valid Google Play Services APK found.");
            CharSequence text = "Failed : " + "No valid Google Play Services APK found.";
            int duration = Toast.LENGTH_SHORT;
            Toast toast = Toast.makeText(context, text, duration);
            toast.show();
        }*/

        ///////////////////////////////
        RegisterWithPXIServer();
    } catch (Exception ex) {
        CharSequence text = "Failed : " + ex.getMessage();
        int duration = Toast.LENGTH_SHORT;
        Toast toast = Toast.makeText(context, text, duration);
        toast.show();
    }
}

From source file:edgargtzg.popularmovies.DiscoverMoviesFragment.java

/**
 * Updates the content of the view based on the selected sort by
 * option by the User.// ww  w.  j  a va2 s .  c  o  m
 *
 * @param sortById id of the action to sort the movies
 *                 (for example: most popular, highest-rated)
 */
private void updateMovies(String sortById) {

    if (isNetworkAvailable()) {
        FetchMoviesTask fetchMoviesTask = new FetchMoviesTask();
        fetchMoviesTask.execute(sortById);
    } else {
        Toast toast = Toast.makeText(getActivity(), R.string.error_msg_no_network, Toast.LENGTH_LONG);
        toast.setGravity(Gravity.CENTER, 0, 0);
        toast.show();
    }
}

From source file:blackman.matt.boardlist.BoardListActivity.java

/**
 * Interface to favorite a board when the user hits the favorite button.
 *
 * @param boardLink Link of the board to be favorited.
 * @param isChecked If the user just checked it true or false.
 *//*from   www .j av  a2 s.c o m*/
@Override
public void favoriteBoard(String boardLink, Boolean isChecked) {
    CharSequence text;
    int duration = Toast.LENGTH_SHORT;

    if (isChecked) {
        text = "Added Board " + boardLink;
    } else {
        text = "Removed Board " + boardLink;
    }

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

    list_db.favoriteBoard(boardLink, isChecked);

    Cursor mCursor = list_db.getSortedSearch(mCurFilter, mDBSortBy, mDBOrderBy);

    mAdapter.swapCursor(mCursor);
    mAdapter.notifyDataSetChanged();
}

From source file:com.xargsgrep.portknocker.activity.EditHostActivity.java

private boolean validateAndDisplayErrors(Host host) {
    //      boolean validHostname = HOSTNAME_PATTERN.matcher(host.getHostname()).matches();
    //      boolean validIP = InetAddressUtils.isIPv4Address(host.getHostname());

    String errorText = "";
    if (StringUtils.isBlank(host.getLabel())) {
        errorText = getString(R.string.toast_msg_enter_label);
    } else if (StringUtils.isBlank(host.getHostname())) {
        errorText = getString(R.string.toast_msg_enter_hostname);
    }//from  ww  w.j  ava  2 s .c  o m
    //      else if (!validHostname && !validIP) {
    //         errorText = getString(R.string.toast_msg_invalid_hostname);
    //      }
    else if (host.getPorts() == null || host.getPorts().size() == 0) {
        errorText = getString(R.string.toast_msg_enter_port);
    } else if (host.getDelay() > MAX_DELAY_VALUE) {
        errorText = getString(R.string.toast_msg_delay_max_value) + MAX_DELAY_VALUE;
    } else {
        for (Port port : host.getPorts()) {
            if (port.getPort() > MAX_PORT_VALUE) {
                errorText = getString(R.string.toast_msg_invalid_port) + port.getPort();
                break;
            }
        }
    }

    if (StringUtils.isNotBlank(errorText)) {
        Toast toast = Toast.makeText(this, errorText, Toast.LENGTH_SHORT);
        toast.setGravity(Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL, 0, 0);
        toast.show();
        return false;
    }

    return true;
}

From source file:edu.asu.msse.sgowdru.moviemediaplayerrpc.SearchMovie.java

public void searchButtonClicked(View view) {
    String searchString = info[0].getText().toString();

    android.util.Log.w(getClass().getSimpleName(), searchString);

    //Check if the movie name is available in RPC server
    boolean isInRPC = isMovieInRPC(searchString);
    //If the movie name is available retrieve its detail
    //Set the video player visibility to VISIBLE
    if (isInRPC) {
        System.out.println(searchString + " Movie in RPC!");
        //Movie not present in local DB, raise a toast message
        text = " being retrieved from RPC Server now.";
        Toast toast = Toast.makeText(context, "Movie " + searchString + text, duration);
        toast.show();

        playButton.setVisibility(view.VISIBLE);

        getMovieDetails(searchString);//from  www  . j  a va 2 s  . c om
    } else {
        try {
            cur = crsDB.rawQuery("select Title from Movies where Title='" + searchString + "';",
                    new String[] {});
            android.util.Log.w(getClass().getSimpleName(), searchString);

            //If the Movie Exists in the Local Database, we will retrieve it from the Local DB
            if (cur.getCount() != 0) {
                //Raise toast message that the movie is already present in local DB
                text = " already present in DB, Retrieving..";
                Toast toast = Toast.makeText(context, "Movie " + searchString + text, duration);
                toast.show();

                //Retrieving the Movie since we know that the movie exists in DB
                cur = crsDB.rawQuery(
                        "select Title, Genre, Years, Rated, Actors, VideoFile from Movies where Title = ?;",
                        new String[] { searchString });

                //Movie Already present hence disabling the Add Button
                addButton.setEnabled(false);

                //Move the Cursor and set the Fields
                cur.moveToNext();
                info[1].setText(cur.getString(0));
                info[2].setText(cur.getString(1));
                info[3].setText(cur.getString(2));
                info[4].setText(cur.getString(4));

                //Set the Ratings dropdown
                if (cur.getString(3).equals("PG"))
                    dropdown.setSelection(0);
                else if (cur.getString(3).equals("PG-13"))
                    dropdown.setSelection(1);
                else if (cur.getString(3).equals("R"))
                    dropdown.setSelection(2);

                String video = cur.getString(5);
                if (video != null) {
                    playButton.setVisibility(view.VISIBLE);
                }

            }

            //If the Movie Does not exist in the Local Database, we will retrieve it from the OMDB
            else {
                //Movie not present in local DB, raise a toast message
                text = " being retrieved from OMDB now.";
                Toast toast = Toast.makeText(context, "Movie " + searchString + text, duration);
                toast.show();

                //Encode the search string to be appropriate to be placed in a url
                String encodedUrl = null;
                try {
                    encodedUrl = URLEncoder.encode(searchString, "UTF-8");
                } catch (UnsupportedEncodingException e) {
                    android.util.Log.e(getClass().getSimpleName(), e.getMessage());
                }

                //ASync thread running the query from OMDB and retrieving the movie details as JSON
                JSONObject result = new MovieGetInfoAsync()
                        .execute("http://www.omdbapi.com/?t=\"" + encodedUrl + "\"&r=json").get();

                //Check if the Movie query was successful
                if (result.getString("Response").equals("True")) {
                    info[1].setText(result.getString("Title"));
                    info[2].setText(result.getString("Genre"));
                    info[3].setText(result.getString("Year"));
                    info[4].setText(result.getString("Actors"));

                    if (result.getString("Rated").equals("PG"))
                        dropdown.setSelection(0);
                    else if (result.getString("Rated").equals("PG-13"))
                        dropdown.setSelection(1);
                    else if (result.getString("Rated").equals("R"))
                        dropdown.setSelection(2);

                    if (result.has("Filename")) {
                        videoFile = result.getString("Filename");
                    } else {
                        playButton.setVisibility(View.GONE);
                        videoFile = null;
                    }
                }
                //Search query was unsuccessful in getting movie with such a name
                else if (result.getString("Response").equals("False")) {
                    //Raise a toast message
                    text = " not present in OMDB, You can add it manually!";
                    toast = Toast.makeText(context, "Movie " + searchString + text, duration);
                    toast.show();
                }
            }
        } catch (Exception e) {
            android.util.Log.w(getClass().getSimpleName(), e.getMessage());
        }
    }
}

From source file:com.google.samples.quickstart.signin.MainActivity.java

private void onSignInClicked() {
    // User clicked the sign-in button, so begin the sign-in process and automatically
    // attempt to resolve any errors that occur.
    ConnectivityManager connMgr = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
    if (networkInfo != null && networkInfo.isConnected()) {
        mShouldResolve = true;// w w w . j  a v a  2 s  .  c  o m
        mGoogleApiClient.connect();

        // Show a message to the user that we are signing in.
        mStatus.setText(R.string.signing_in);

    } else {
        Context context = getApplicationContext();
        CharSequence text = "Please check your Network Connection";
        int duration = Toast.LENGTH_LONG;

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

}