Example usage for android.widget Toast LENGTH_SHORT

List of usage examples for android.widget Toast LENGTH_SHORT

Introduction

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

Prototype

int LENGTH_SHORT

To view the source code for android.widget Toast LENGTH_SHORT.

Click Source Link

Document

Show the view or text notification for a short period of time.

Usage

From source file:com.aibasis.parent.ui.entrance.RegisterActivity.java

/**
 * // w  w  w  .  j ava 2 s .  c  om
 * 
 * @param view
 */
public void register(View view) {
    final String username = userNameEditText.getText().toString().trim();
    final String pwd = passwordEditText.getText().toString().trim();
    String confirm_pwd = confirmPwdEditText.getText().toString().trim();
    if (TextUtils.isEmpty(username)) {
        Toast.makeText(this, getResources().getString(R.string.User_name_cannot_be_empty), Toast.LENGTH_SHORT)
                .show();
        userNameEditText.requestFocus();
        return;
    } else if (TextUtils.isEmpty(pwd)) {
        Toast.makeText(this, getResources().getString(R.string.Password_cannot_be_empty), Toast.LENGTH_SHORT)
                .show();
        passwordEditText.requestFocus();
        return;
    } else if (TextUtils.isEmpty(confirm_pwd)) {
        Toast.makeText(this, getResources().getString(R.string.Confirm_password_cannot_be_empty),
                Toast.LENGTH_SHORT).show();
        confirmPwdEditText.requestFocus();
        return;
    } else if (!pwd.equals(confirm_pwd)) {
        Toast.makeText(this, getResources().getString(R.string.Two_input_password), Toast.LENGTH_SHORT).show();
        return;
    }

    if (!TextUtils.isEmpty(username) && !TextUtils.isEmpty(pwd)) {
        final ProgressDialog pd = new ProgressDialog(this);
        pd.setMessage(getResources().getString(R.string.Is_the_registered));
        pd.show();

        new Thread(new Runnable() {
            public void run() {
                //               try {
                //                  // sdk
                //                  EMChatManager.getInstance().createAccountOnServer(username, pwd);
                //                  runOnUiThread(new Runnable() {
                //                     public void run() {
                //                        if (!RegisterActivity.this.isFinishing())
                //                           pd.dismiss();
                //                        // ???
                //                        DemoApplication.getInstance().setUserName(username);
                //                        Toast.makeText(getApplicationContext(), getResources().getString(R.string.Registered_successfully), 0).show();
                //                        finish();
                //                     }
                //                  });
                //               } catch (final EaseMobException e) {
                //                  runOnUiThread(new Runnable() {
                //                     public void run() {
                //                        if (!RegisterActivity.this.isFinishing())
                //                           pd.dismiss();
                //                        int errorCode=e.getErrorCode();
                //                        if(errorCode==EMError.NONETWORK_ERROR){
                //                           Toast.makeText(getApplicationContext(), getResources().getString(R.string.network_anomalies), Toast.LENGTH_SHORT).show();
                //                        }else if(errorCode == EMError.USER_ALREADY_EXISTS){
                //                           Toast.makeText(getApplicationContext(), getResources().getString(R.string.User_already_exists), Toast.LENGTH_SHORT).show();
                //                        }else if(errorCode == EMError.UNAUTHORIZED){
                //                           Toast.makeText(getApplicationContext(), getResources().getString(R.string.registration_failed_without_permission), Toast.LENGTH_SHORT).show();
                //                        }else if(errorCode == EMError.ILLEGAL_USER_NAME){
                //                            Toast.makeText(getApplicationContext(), getResources().getString(R.string.illegal_user_name),Toast.LENGTH_SHORT).show();
                //                        }else{
                //                           Toast.makeText(getApplicationContext(), getResources().getString(R.string.Registration_failed) + e.getMessage(), Toast.LENGTH_SHORT).show();
                //                        }
                //                     }
                //                  });
                //               }
                accountAPI.register(username, pwd, new RequestListener() {
                    @Override
                    public void onComplete(String result) {
                        if (!RegisterActivity.this.isFinishing())
                            pd.dismiss();
                        try {
                            RegisterResult registerResult = RegisterResult.parse(result);
                            if (RegisterResult.SUCCESS.equals(registerResult.getResult())) {
                                DemoApplication.getInstance().setParentId(registerResult.getParentId());
                                DemoApplication.getInstance().setEaseId(registerResult.getEaseId());
                                DemoApplication.getInstance().setEasePassword(registerResult.getEasePassword());

                                SharePreferenceUtil sharePreferenceUtil = new SharePreferenceUtil(
                                        RegisterActivity.this);
                                sharePreferenceUtil.setParentId(registerResult.getParentId());
                            } else if (RegisterResult.USERNAME_EXISTS.equals(registerResult.getResult())) {
                                Toast.makeText(RegisterActivity.this,
                                        getResources().getString(R.string.User_already_exists),
                                        Toast.LENGTH_SHORT).show();
                            }

                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                        finish();
                    }

                    @Override
                    public void onAPIException(APIException exception) {
                        Log.e("jijun", exception.toString());
                    }
                });

            }
        }).start();
    }
}

From source file:MainActivity.java

@Override
public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
    switch (requestCode) {
    case REQUEST_PERMISSION_SEND_SMS: {
        if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
            Toast.makeText(MainActivity.this, "Permission Granted!", Toast.LENGTH_SHORT).show();
        } else {//from   w w  w  .j a v a 2  s .c  om
            Toast.makeText(MainActivity.this, "Permission Denied!", Toast.LENGTH_SHORT).show();
        }
        return;
    }
    }
}

From source file:io.v.positioning.gae.ServletPostAsyncTask.java

@Override
protected void onPostExecute(String result) {
    Toast.makeText(mContext, result, Toast.LENGTH_SHORT).show();
}

From source file:in.codehex.arrow.LoginActivity.java

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String permissions[],
        @NonNull int grantResults[]) {
    switch (requestCode) {
    case Config.PERMISSION_READ_PHONE_STATE:
        if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
            imei = telephonyManager.getDeviceId();
        } else {/* ww  w. j av  a  2 s .  c  o  m*/
            Toast.makeText(this, "Permission request denied", Toast.LENGTH_SHORT).show();
        }
        break;
    }
}

From source file:com.manning.androidhacks.hack030.MainActivity.java

public void onPickCountryClick(View v) {
    int pos = mListView.getCheckedItemPosition();

    if (ListView.INVALID_POSITION != pos) {
        String msg = String.format(mToastFmt, mCountries.get(pos).getName());
        Toast.makeText(this, msg, Toast.LENGTH_SHORT).show();
    }/*from  www  .j  a v  a 2 s  .c  o m*/
}

From source file:MainActivity.java

public void send(View view) {
    String phoneNumber = ((EditText) findViewById(R.id.editTextNumber)).getText().toString();
    String msg = ((EditText) findViewById(R.id.editTextMsg)).getText().toString();

    if (phoneNumber == null || phoneNumber.length() == 0 || msg == null || msg.length() == 0) {
        return;//from w  ww .ja  va2s  .c  om
    }

    if (checkPermission(Manifest.permission.SEND_SMS)) {
        SmsManager smsManager = SmsManager.getDefault();
        if (msg.length() > 160) {
            ArrayList<String> messages = smsManager.divideMessage(msg);
            smsManager.sendMultipartTextMessage(phoneNumber, null, messages, null, null);
        } else {
            smsManager.sendTextMessage(phoneNumber, null, msg, null, null);
        }
    } else {
        Toast.makeText(MainActivity.this, "No Permission", Toast.LENGTH_SHORT).show();
    }
}

From source file:com.mobshep.shepherdlogin.LoggedIn.java

public void submitClicked(View v) {

    String apiKey = "thisIsTheAPIKey";

    ArrayList<NameValuePair> postParameters = new ArrayList<NameValuePair>();
    postParameters.add(new BasicNameValuePair("mobileKey", apiKey));

    try {//from w  ww  . j a  v a2s  .c om

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

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

        JSONObject jObject = new JSONObject(res.toString());

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

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

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

        if (res != null) {
            storedPref = getSharedPreferences("Sessions", MODE_PRIVATE);
            toEdit = storedPref.edit();
            toEdit.putString("LEVELKEY", response);
            toEdit.commit();

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

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

}

From source file:net.redwarp.android.app.githubcount.ProjectDetailFragment.java

@Override
public void onStart() {
    super.onStart();

    String user = getArguments().getString("user");
    String repository = getArguments().getString("repository");

    JsonArrayRequest request = new JsonArrayRequest(
            "https://api.github.com/repos/" + user + "/" + repository + "/releases",
            new Response.Listener<JSONArray>() {
                @Override// w w w  .  java 2s .c o  m
                public void onResponse(JSONArray jsonArray) {
                    mTitleLabel.setText("Class = " + jsonArray.getClass());
                    parseReleases(jsonArray);
                }

            }, new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError volleyError) {
                    Toast.makeText(getActivity(), "Request error", Toast.LENGTH_SHORT).show();
                    mTitleLabel.setText("Request failed");
                }
            });
    request.setRetryPolicy(new DefaultRetryPolicy(5000, DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
            DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
    request.setTag(this);

    MyApplication.getRequestQueue().add(request);
}

From source file:com.dedipower.portal.android.Launcher.java

/** Called when the activity is first created. */
@Override/*w w w.  j  av a2s .  c o m*/
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.launcher);

    dialog = new ProgressDialog(this);
    dialog.setMessage("Logging in.....");

    //Get our settings
    settings = getSharedPreferences("Dedipower", 0);
    ManageSettings();

    handler = new Handler() {
        public void handleMessage(Message msg) {
            dialog.dismiss();
            //Apparantly stopping threads is no longer supported
            //peformLogin.stop();

            if (APIResponse == "true") {
                //Tell the user
                Toast.makeText(Launcher.this, "Login Successful", Toast.LENGTH_SHORT).show();

                //Check the "remember details checkbox"
                CheckBox Remember = (CheckBox) findViewById(R.id.RememberDetailsCheckBox);

                SharedPreferences.Editor editor = settings.edit();
                if (Remember.isChecked() == true) {
                    editor.putString("AcctCode", AcctCode);
                    editor.putString("Email", Email);
                    editor.putString("Password", Password);
                    editor.putBoolean("Remember", true);
                    editor.commit();
                } else {
                    editor.putString("AcctCode", "");
                    editor.putString("Email", "");
                    editor.putString("Password", "");
                    editor.putBoolean("Remember", false);
                    editor.commit();
                }

                //Do extent stuff
                Intent LauncherIntent = new Intent(Launcher.this, PortalLanding.class);
                LauncherIntent.putExtra("sessionid", API.SessionID);
                Launcher.this.startActivity(LauncherIntent);
                finish();
            } else {
                Toast.makeText(Launcher.this, "Login Failed: " + APIResponse, Toast.LENGTH_SHORT).show();
            }
        }
    };

    Button LoginButton = (Button) findViewById(R.id.LoginButton);
    LoginButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            dialog.show();
            EditText AcctCodeEditText = (EditText) findViewById(R.id.AcctCodeInput);
            EditText EmailEditText = (EditText) findViewById(R.id.EmailInput);
            EditText PasswordEditText = (EditText) findViewById(R.id.PasswordInput);
            AcctCode = AcctCodeEditText.getText().toString();
            Email = EmailEditText.getText().toString();
            Password = PasswordEditText.getText().toString();

            Credentials.add(new BasicNameValuePair("account", AcctCode));
            Credentials.add(new BasicNameValuePair("username", Email));
            Credentials.add(new BasicNameValuePair("password", Password));
            CreateThread();
            peformLogin.start();

            /*String APIResponse = API.Login(Credentials);
            if(APIResponse == "true")
            {
              //Tell the user
              Toast.makeText(Launcher.this, "Login Successful", Toast.LENGTH_SHORT).show();
                      
              //Check the "remember details checkbox"
              CheckBox Remember = (CheckBox) findViewById(R.id.RememberDetailsCheckBox);
                      
              SharedPreferences.Editor editor = settings.edit();
              if(Remember.isChecked() == true)
              {
                editor.putString("AcctCode", AcctCodeEditText.getText().toString());
                editor.putString("Email", EmailEditText.getText().toString());
                editor.putString("Password", PasswordEditText.getText().toString());
                editor.putBoolean("Remember", true);
                editor.commit();
              }
              else
              {
                editor.putString("AcctCode", "");
                editor.putString("Email", "");
                editor.putString("Password", "");
                editor.putBoolean("Remember", false);
                editor.commit();
              }
                      
              //Do extent stuff
              Intent LauncherIntent = new Intent(Launcher.this, PortalLanding.class);
              LauncherIntent.putExtra("sessionid", API.SessionID);
              Launcher.this.startActivity(LauncherIntent);
              finish();
            }
            else
            {
              Toast.makeText(Launcher.this, "Login Failed: " + APIResponse, Toast.LENGTH_SHORT).show();
            }*/
        }
    });
}

From source file:com.example.android.toyvpn.ToyVpnService.java

@Override
public boolean handleMessage(Message message) {
    if (message != null) {
        Toast.makeText(this, message.what, Toast.LENGTH_SHORT).show();
    }/* w  w w. ja v  a  2 s  .com*/
    return true;
}