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:com.ehdev.chronos.lib.Chronos.java

static public boolean putDataOnSDCard(Context context, boolean oldFormat) {

    if (getCardWriteStatus() == false) {

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

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

    File directory = Environment.getExternalStorageDirectory();
    //File backup = new File(directory, "Chronos_Backup.csv");
    File backup;
    if (!oldFormat)
        backup = new File(directory, "Chronos_Backup.csv");
    else
        backup = new File(directory, "Chronos_Backup.cvs");
    BufferedWriter br;

    Chronos chron = new Chronos(context);
    List<Punch> punches = chron.getAllPunches();
    chron.close();
    Log.d(TAG, "Backup Size: " + punches.size());

    try {
        br = new BufferedWriter(new FileWriter(backup));

        for (Punch p : punches) {
            if (!oldFormat)
                br.write(p.toCVS(context));
            else
                br.write(p.toCVSLegacy(context));
        }
        br.close();
    } catch (IOException e) {
        Log.e(TAG, e.getMessage());
        return false;
    }
    return true;
}

From source file:cm.aptoide.pt.adapters.UpdatesAdapter.java

@Override
public void bindView(View view, final Context context, Cursor cursor) {
    ViewHolder holder = (ViewHolder) view.getTag();
    if (holder == null) {
        holder = new ViewHolder();
        holder.name = (TextView) view.findViewById(R.id.app_name);
        holder.icon = (ImageView) view.findViewById(R.id.app_icon);
        holder.vername = (TextView) view.findViewById(R.id.uptodate_versionname);
        holder.update = (ImageView) view.findViewById(R.id.app_update);

        if ((context.getResources().getConfiguration().screenLayout
                & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_LARGE
                || (context.getResources().getConfiguration().screenLayout
                        & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_XLARGE) {
            holder.ignore_update = (ImageView) view.findViewById(R.id.app_ignore_update);
        }/*from w  w  w  .  j a  va 2  s.co m*/

        //            holder.downloads= (TextView) view.findViewById(R.id.downloads);
        //            holder.rating= (RatingBar) view.findViewById(R.id.stars);
        view.setTag(holder);
    }
    final long id = cursor.getLong(0);
    final String name = cursor.getString(1);
    final String apkId = cursor.getString(7);
    final String vername = cursor.getString(2);
    final int vercode = cursor.getInt(8);
    final String md5 = cursor.getString(10);
    final String apkpath = cursor.getString(11) + cursor.getString(12);
    String iconspath = cursor.getString(9) + cursor.getString(4);
    final String hash = (cursor.getString(cursor.getColumnIndex("apkid")) + "|"
            + cursor.getString(cursor.getColumnIndex("vercode")));
    holder.name.setText(name);
    ImageLoader.getInstance().displayImage(iconspath, holder.icon);
    //       try{
    //              holder.rating.setRating(Float.parseFloat(cursor.getString(5)));
    //           }catch (Exception e) {
    //              holder.rating.setRating(0);
    //         }
    //       holder.downloads.setText(cursor.getString(6));
    holder.vername.setText(context.getString(R.string.update_to) + ": " + vername);
    holder.update.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            new GetApkWebserviceInfo(mContext, serviceDownloadManager, true).execute(id);
        }
    });
    if ((context.getResources().getConfiguration().screenLayout
            & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_LARGE
            || (context.getResources().getConfiguration().screenLayout
                    & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_XLARGE) {
        holder.ignore_update.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                ViewApk apk = Database.getInstance().getApk(id, Category.INFOXML);
                Database.getInstance().addToExcludeUpdate((int) id);
                if (loader != null)
                    loader.forceLoad();
                Toast toast = Toast.makeText(context,
                        context.getString(R.string.added_to_excluded_updates_list, apk.getName()),
                        Toast.LENGTH_SHORT);
                toast.show();
            }
        });
    }
}

From source file:app.dropbox.encryption.encryptionsetup.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.encryption_setup);

    initilizingVariables();// w w w .  ja  v a 2  s  .c om
    if (encryptKey != null) {
        if (fileToEncrypt != null)
            launchEncryption();
        else
            launchnext();
    } else {
        //         acctok=getSharedPreferences("accesstoken",0);
        //         accessToken =acctok.getString("accesstoken", null);
        //         if(accessToken==null){
        //            goback();
        //            }
        //          
        final EditText key = (EditText) findViewById(R.id.editText1);

        ImageButton encrypt = (ImageButton) findViewById(R.id.imageButton1);
        encrypt.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                encryptKey = key.getText().toString();
                if (keyValidator(encryptKey)) {
                    key.setText("");

                    setKeyToPreferences();

                    if (fileToEncrypt != null)
                        launchEncryption();
                    else
                        launchnext();
                } else {
                    Toast toast = Toast.makeText(encryptionsetup.this, "Enter key between 5 to 16 Characters",
                            2000);
                    toast.setGravity(Gravity.CENTER, 0, 0);
                    toast.show();
                }

            }

        });
    }

}

From source file:autobahn.demo.com.autobahndemo.EchoClientActivity.java

private void alert(String message) {
    Toast toast = Toast.makeText(getApplicationContext(), message, Toast.LENGTH_SHORT);
    toast.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL, 0, 0);
    toast.show();
}

From source file:com.zytan.sdpn.droid.SimpleSDPPeer.java

@Override
protected void onReceivedJSONMsg(JSONObject jsonMsg, Address sender) {
    super.onReceivedJSONMsg(jsonMsg, sender);

    try {//from   w  w w  .java2 s.co  m

        JSONObject params = jsonMsg.getJSONObject("payload").getJSONObject("params");

        if (jsonMsg.get("type").equals(PeerListMessage.MSG_PEER_LIST)) {

            PeerActivity.handler.post(new Runnable() {
                public void run() {
                    Toast toast = Toast.makeText(peerActivity.getBaseContext(),
                            "Received: " + PeerListMessage.MSG_PEER_LIST, Toast.LENGTH_LONG);
                    toast.show();
                    //((PeerActivity)peerActivity).peerListChanged();
                }
            });

        }

    } catch (JSONException e) {

        e.printStackTrace();
    }

}

From source file:eu.cyberkat.h2owirelessbalancecheck.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.action_about:
        PackageInfo pInfo = null;//  w  ww .j a va2  s  .  c o  m
        try {
            pInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
        } catch (NameNotFoundException e) {
            pInfo = null;
        }
        if (pInfo == null) {
            return false;
        }
        String version = pInfo.versionName;
        int versionCode = pInfo.versionCode;
        Context aboutToastContext = getApplicationContext();
        CharSequence aboutToastText = "H2O Data Balance v" + version + ", (" + ordinal(versionCode)
                + " Revision)\nCopyright (c) 2014, Dylan J. Morrison <insidious@cyberkat.eu>, Licensed under the ISC license.";
        int aboutToastDuration = Toast.LENGTH_LONG;
        Toast aboutToast = Toast.makeText(aboutToastContext, aboutToastText, aboutToastDuration);
        aboutToast.show();
        return true;
    case R.id.action_grabnum:
        TelephonyManager tMgr = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);
        String mPhoneNumber = tMgr.getLine1Number();
        if (mPhoneNumber == null) {
            Context numberErrorContext = getApplicationContext();
            CharSequence numberErrorText = "Unable to get device phone number.";
            int numberErrorDuration = Toast.LENGTH_SHORT;
            Toast toast = Toast.makeText(numberErrorContext, numberErrorText, numberErrorDuration);
            toast.show();
        } else {
            EditText textbox = (EditText) this.findViewById(R.id.editText2);
            mPhoneNumber = mPhoneNumber.replaceAll("[^\\d]", "");
            textbox.setText(mPhoneNumber);
        }
        return true;
    default:
        return super.onOptionsItemSelected(item);
    }
}

From source file:codepath.watsiapp.activities.BaseFragmentActivity.java

private void showThankYouNote() {
    LayoutInflater inflater = this.getLayoutInflater();
    View view = inflater.inflate(R.layout.toast_thanks_for_donation,
            (ViewGroup) this.findViewById(R.id.thanks_note));
    Toast toast = new Toast(this);
    toast.setView(view);//  w w  w .  j  a v  a2 s . c o  m
    toast.setGravity(Gravity.CENTER, 0, 0);
    toast.setDuration(Toast.LENGTH_LONG);
    toast.show();

}

From source file:edu.cwru.apo.Directory.java

public void onRestRequestComplete(Methods method, JSONObject result) {
    if (method == Methods.phone) {
        if (result != null) {
            try {
                String requestStatus = result.getString("requestStatus");
                if (requestStatus.compareTo("success") == 0) {
                    SharedPreferences.Editor editor = getSharedPreferences(APO.PREF_FILE_NAME, MODE_PRIVATE)
                            .edit();/*  ww  w .  j  a  va  2 s. c  om*/
                    editor.putLong("updateTime", result.getLong("updateTime"));
                    editor.commit();
                    int numbros = result.getInt("numBros");
                    JSONArray caseID = result.getJSONArray("caseID");
                    JSONArray first = result.getJSONArray("first");
                    JSONArray last = result.getJSONArray("last");
                    JSONArray phone = result.getJSONArray("phone");
                    JSONArray family = result.getJSONArray("family");
                    ContentValues values;
                    for (int i = 0; i < numbros; i++) {
                        values = new ContentValues();
                        values.put("_id", caseID.getString(i));
                        values.put("first", first.getString(i));
                        values.put("last", last.getString(i));
                        values.put("phone", phone.getString(i));
                        values.put("family", family.getString(i));
                        database.replace("phoneDB", null, values);
                    }
                    loadTable();
                } else if (requestStatus.compareTo("timestamp invalid") == 0) {
                    Toast msg = Toast.makeText(this, "Invalid timestamp.  Please try again.",
                            Toast.LENGTH_LONG);
                    msg.show();
                } else if (requestStatus.compareTo("HMAC invalid") == 0) {
                    Auth.loggedIn = false;
                    Toast msg = Toast.makeText(this,
                            "You have been logged out by the server.  Please log in again.", Toast.LENGTH_LONG);
                    msg.show();
                    finish();
                } else {
                    Toast msg = Toast.makeText(this, "Invalid requestStatus", Toast.LENGTH_LONG);
                    msg.show();
                }
            } catch (JSONException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }
}

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

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

    android.util.Log.w(getClass().getSimpleName(), searchString);
    try {/*  ww  w  .j  av  a 2 s  .  c om*/
        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 from Movies where Title = ?;",
                    new String[] { searchString });

            //Movie Already present hence disabling the Add Button
            btn.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);
        }

        //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"));

                //Ratings field is of type Spinner class with field values (PG, PG-13, R rated)
                ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.Ratings,
                        android.R.layout.simple_spinner_item);
                adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
                dropdown.setAdapter(adapter);

                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);
            }
            //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.mobshep.shepherdlogin.MainActivity.java

public void submitClicked(View v) {

    if (username.getText().toString().equals("") || password.getText().toString().equals("")) {
        Toast blank = Toast.makeText(MainActivity.this, "Blank Fields Detected!", Toast.LENGTH_SHORT);
        blank.show();
        return;/*  ww  w. ja  v  a 2s.  co  m*/
    }

    ArrayList<NameValuePair> postParameters = new ArrayList<NameValuePair>();
    postParameters.add(new BasicNameValuePair("login", username.getText().toString()));
    postParameters.add(new BasicNameValuePair("pwd", password.getText().toString()));

    try {

        SharedPreferences SP = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
        String address = SP.getString("server_preference", "NA");

        String res = CustomHttpClient.executeHttpPost(address + "/mobileLogin", postParameters);

        JSONObject jObject = new JSONObject(res);

        String response = jObject.getString("JSESSIONID");

        System.out.println("SessionId: " + response);

        response = response.replaceAll("\\s+", "");

        Toast responseError = Toast.makeText(MainActivity.this, response, Toast.LENGTH_SHORT);
        responseError.show();

        Log.i(TAG, "Server Response:" + response);

        if (response.contains(" ERROR ")) {
            tvResponse.setText("Invalid username or password");
        }

        if (res != null) {
            Toast valid = Toast.makeText(MainActivity.this, "Logged In!", Toast.LENGTH_SHORT);
            valid.show();

            storedPref = getSharedPreferences("Sessions", MODE_PRIVATE);
            toEdit = storedPref.edit();
            toEdit.putString("sessionId", response);
            toEdit.commit();

            //store the session in content provider
            ContentValues values = new ContentValues();
            values.put(SessionProvider.sessionValue, response);

            // Provides access to other applications Content Providers
            Uri uri = getContentResolver().insert(SessionProvider.CONTENT_URL, values);

            Intent intent = new Intent(MainActivity.this, LoggedIn.class);
            startActivity(intent);

        } else {
            Toast.makeText(getBaseContext(), "Invalid Credentials!", Toast.LENGTH_SHORT).show();
        }
    } catch (Exception e) {

        if (e.toString().contains("ERROR")) {
            tvResponse.setText("Invalid Credentials");
        }

        else {

            Toast responseError = Toast.makeText(MainActivity.this, e.toString(), Toast.LENGTH_LONG);
            responseError.show();

            tvResponse.setText(e.toString());
        }
    }

}