Java Code Examples for android.widget.Toast#LENGTH_SHORT

The following examples show how to use android.widget.Toast#LENGTH_SHORT . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SetCardActivity.java    From SwipeYours with GNU General Public License v3.0 6 votes vote down vote up
public void setNewCard(View view) {
    String newSwipeData = ((EditText) findViewById(R.id.swipe_data)).getText().toString().replaceAll("\\s+","");
    boolean newDataIsValid = parseTrackData(newSwipeData);

    String toastMessage;
    int toastDuration;

    if (newDataIsValid) {
        toastMessage = "New Card Set";
        toastDuration = Toast.LENGTH_SHORT;
        storeNewSwipeData(newSwipeData);
    } else {
        toastMessage = "Invalid swipe data";
        toastDuration = Toast.LENGTH_LONG;
    }

    Toast toast = Toast.makeText(getApplicationContext(), toastMessage, toastDuration);
    toast.setGravity(Gravity.CENTER, 0, 0);
    toast.show();
}
 
Example 2
Source File: SweetToastManager.java    From SweetTips with Apache License 2.0 6 votes vote down vote up
/**
 * 将当前SweetToast实例添加到queue中
 */
protected static void show(@NonNull SweetToast current){
    try {
        if(queue.size() <= 0){
            clear();
            //队列为空,则将current添加到队列中,同时进行展示
            offer(current);
            current.handleShow();
            long delay = (current.getConfiguration().getDuration() == SweetToast.LENGTH_LONG||current.getConfiguration().getDuration() == Toast.LENGTH_LONG) ? SweetToast.LONG_DELAY : ((current.getConfiguration().getDuration() == SweetToast.LENGTH_SHORT || current.getConfiguration().getDuration() == Toast.LENGTH_SHORT)? SweetToast.SHORT_DELAY : current.getConfiguration().getDuration());
            queueHandler.postDelayed(mShowNext,delay);
        }else{
            offer(current);
        }
    }catch (Exception e){
        Log.e("幻海流心","e:"+e.getLocalizedMessage());
    }
}
 
Example 3
Source File: UploadService.java    From secureit with MIT License 6 votes vote down vote up
/**
* Called on service creation, sends a notification
*/
  @Override
  public void onCreate() {
      manager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
      prefs = new SecureItPreferences(this);
      
try {
	new BluetoothServerTask(this).start();
} catch (NoBluetoothException e) {
	Log.i("UploadService", "Background bluetooth server not started");
	CharSequence text = "Background bluetooth server not started";
	int duration = Toast.LENGTH_SHORT;
	Toast toast = Toast.makeText(this, text, duration);
	toast.show();
}
      
      showNotification();
  }
 
Example 4
Source File: SelectedSongsView.java    From ampdroid with MIT License 6 votes vote down vote up
@Override
public boolean onContextItemSelected(MenuItem item) {
	AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();

	switch (item.getItemId()) {
	case R.id.contextMenuAdd:
		controller.getPlayNow().add(controller.getSongs().get((int) info.id));
		Context context = getView().getContext();
		CharSequence text = getResources().getString(R.string.songsViewSongAdded);
		int duration = Toast.LENGTH_SHORT;
		Toast toast = Toast.makeText(context, text, duration);
		toast.show();
		return true;
	case R.id.contextMenuSongsOpen:
		controller.getPlayNow().clear();
		controller.getPlayNow().add(controller.getSongs().get((int) info.id));
		((MainActivity) getActivity()).play(0);
		return true;
	default:
		return super.onContextItemSelected(item);
	}
}
 
Example 5
Source File: SelectedAlbumsView.java    From ampdroid with MIT License 6 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
	switch (item.getItemId()) {
	case R.id.edit_add_all:
		for (Album a : controller.getSelectedAlbums()) {
			for (Song s : controller.findSongs(a)) {
				controller.getPlayNow().add(s);
			}
		}
		Context context = getView().getContext();
		CharSequence text = getResources().getString(R.string.albumsViewAlbumsAdded);
		int duration = Toast.LENGTH_SHORT;
		Toast toast = Toast.makeText(context, text, duration);
		toast.show();
		return true;
	default:
		return super.onOptionsItemSelected(item);
	}
}
 
Example 6
Source File: ToastUtil.java    From FileManager with Apache License 2.0 6 votes vote down vote up
public static void showToast(Context context, String s) {
    if (toast == null) {
        toast = Toast.makeText(context, s, Toast.LENGTH_SHORT);
        toast.show();
        oneTime = System.currentTimeMillis();
    } else {
        twoTime = System.currentTimeMillis();
        if (s.equals(oldMsg)) {
            if (twoTime - oneTime > Toast.LENGTH_SHORT) {
                toast.show();
            }
        } else {
            oldMsg = s;
            toast.setText(s);
            toast.show();
        }
    }
    oneTime = twoTime;
}
 
Example 7
Source File: ToastUtils.java    From Bailan with Apache License 2.0 6 votes vote down vote up
/**
 * 显示Toast
 *
 * @param message
 */
public static void showToast(String message) {
    if (toast == null) {
        toast = Toast.makeText(StoreApplication.getContext(), message, Toast.LENGTH_SHORT);
        toast.show();
        oneTime = System.currentTimeMillis();
    } else {
        twoTime = System.currentTimeMillis();
        if (message.equals(oldMsg)) {
            if (twoTime - oneTime > Toast.LENGTH_SHORT) {
                toast.show();
            }
        } else {
            oldMsg = message;
            toast.setText(message);
            toast.show();
        }
    }
    oneTime = twoTime;
}
 
Example 8
Source File: BooksListViewActivity.java    From apigee-android-sdk with Apache License 2.0 5 votes vote down vote up
public void apigeeInitializationError() {
	Log.d("Books",BooksApplication.apigeeNotInitializedLogError);
	
	Context context = getApplicationContext();
	CharSequence text = "Apigee client is not initialized";
	int duration = Toast.LENGTH_SHORT;

	Toast toast = Toast.makeText(context, text, duration);
	toast.show();
}
 
Example 9
Source File: EasyToast.java    From NonViewUtils with Apache License 2.0 5 votes vote down vote up
/**
 * 显示toast
 *
 * @param length toast的显示的时间长度:{Toast.LENGTH_SHORT, Toast.LENGTH_LONG}
 */
public static void show(@NonNull Context context, String msg, @Length int length) {
    if (length == Toast.LENGTH_SHORT || length == Toast.LENGTH_LONG) {
        if (context != null) {
            Toast.makeText(context, msg, length).show();
        }
    }
}
 
Example 10
Source File: PUI.java    From PHONK with GNU General Public License v3.0 5 votes vote down vote up
@PhonkMethod
public void toast(String text, boolean length) {
    int duration = Toast.LENGTH_SHORT;
    if (length) {
        duration = Toast.LENGTH_LONG;
    }
    Toast.makeText(getContext(), text, duration).show();
}
 
Example 11
Source File: WXModalUIModule.java    From ucar-weex-core with Apache License 2.0 5 votes vote down vote up
@JSMethod(uiThread = true)
public void toast(String param) {

  String message = "";
  int duration = Toast.LENGTH_SHORT;
  if (!TextUtils.isEmpty(param)) {
    try {
      param = URLDecoder.decode(param, "utf-8");
      JSONObject jsObj = JSON.parseObject(param);
      message = jsObj.getString(MESSAGE);
      duration = jsObj.getInteger(DURATION);
    } catch (Exception e) {
      WXLogUtils.e("[WXModalUIModule] alert param parse error ", e);
    }
  }
  if (TextUtils.isEmpty(message)) {
    WXLogUtils.e("[WXModalUIModule] toast param parse is null ");
    return;
  }

  if (duration > 3) {
    duration = Toast.LENGTH_LONG;
  } else {
    duration = Toast.LENGTH_SHORT;
  }
  if (toast == null) {
    toast = Toast.makeText(mWXSDKInstance.getContext(), message, duration);
  } else {
    toast.setDuration(duration);
    toast.setText(message);
  }
  toast.setGravity(Gravity.CENTER, 0, 0);
  toast.show();
}
 
Example 12
Source File: BaseDialog.java    From AFBaseLibrary with Apache License 2.0 5 votes vote down vote up
protected void showToast(String message) {
    int during = Toast.LENGTH_SHORT;
    if (message.length() > AFConstant.TOAST_LONG_MESSAGE_LENGTH) {
        during = Toast.LENGTH_LONG;
    }
    Toast.makeText(getContext(), message, during).show();
}
 
Example 13
Source File: BaseActivity.java    From AFBaseLibrary with Apache License 2.0 5 votes vote down vote up
protected void showToast(String message) {
    if (getAFContext() == null || TextUtils.isEmpty(message)) {
        return;
    }
    int during = Toast.LENGTH_SHORT;
    if (message.length() > AFConstant.TOAST_LONG_MESSAGE_LENGTH) {
        during = Toast.LENGTH_LONG;
    }
    Toast.makeText(getAFContext(), message, during).show();
}
 
Example 14
Source File: BaseFragment.java    From AFBaseLibrary with Apache License 2.0 5 votes vote down vote up
public void showToast(String message) {
    if (getAFContext() == null || TextUtils.isEmpty(message)) {
        return;
    }
    int during = Toast.LENGTH_SHORT;
    if (message.length() > AFConstant.TOAST_LONG_MESSAGE_LENGTH) {
        during = Toast.LENGTH_LONG;
    }
    Toast.makeText(getAFContext(), message, during).show();
}
 
Example 15
Source File: MainActivity.java    From Wrox-ProfessionalAndroid-4E with Apache License 2.0 5 votes vote down vote up
private void listing13_26() {
  // Listing 13-26: Displaying a Toast
  Context context = this;
  String msg = "To health and happiness!";
  int duration = Toast.LENGTH_SHORT;
  Toast toast = Toast.makeText(context, msg, duration);

  // Remember, you must *always* call show()
  toast.show();
}
 
Example 16
Source File: BaseFragment.java    From FileManager with Apache License 2.0 5 votes vote down vote up
public void showToast(int resId, int duration) {
    if (duration == Toast.LENGTH_SHORT || duration == Toast.LENGTH_LONG) {
        ToastUtils.show(this.getActivity(), resId, duration);
    } else {
        ToastUtils.show(this.getActivity(), resId, ToastUtils.LENGTH_SHORT);
    }
}
 
Example 17
Source File: WXModalUIModule.java    From weex-uikit with MIT License 5 votes vote down vote up
@JSMethod(uiThread = true)
public void toast(String param) {

  String message = "";
  int duration = Toast.LENGTH_SHORT;
  if (!TextUtils.isEmpty(param)) {
    try {
      param = URLDecoder.decode(param, "utf-8");
      JSONObject jsObj = JSON.parseObject(param);
      message = jsObj.getString(MESSAGE);
      duration = jsObj.getInteger(DURATION);
    } catch (Exception e) {
      WXLogUtils.e("[WXModalUIModule] alert param parse error ", e);
    }
  }
  if (TextUtils.isEmpty(message)) {
    WXLogUtils.e("[WXModalUIModule] toast param parse is null ");
    return;
  }

  if (duration > 3) {
    duration = Toast.LENGTH_LONG;
  } else {
    duration = Toast.LENGTH_SHORT;
  }
  if (toast == null) {
    toast = Toast.makeText(mWXSDKInstance.getContext(), message, duration);
  } else {
    toast.setDuration(duration);
    toast.setText(message);
  }
  toast.setGravity(Gravity.CENTER, 0, 0);
  toast.show();
}
 
Example 18
Source File: ContactAdderFragment.java    From ETSMobile-Android2 with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a contact entry from the current UI values in the account named
 * by mSelectedAccount.
 */
protected void createContactEntry() {
	// Get values from UI
	final String name = mContactNameEditText.getText().toString();
	final String phone = mContactPhoneEditText.getText().toString();
	final String email = mContactEmailEditText.getText().toString();
	final int phoneType = mContactPhoneTypes.get(mContactPhoneTypeSpinner
			.getSelectedItemPosition());
	final int emailType = mContactEmailTypes.get(mContactEmailTypeSpinner
			.getSelectedItemPosition());

	// Prepare contact creation request
	//
	// Note: We use RawContacts because this data must be associated with a
	// particular account.
	// The system will aggregate this with any other data for this contact
	// and create a
	// coresponding entry in the ContactsContract.Contacts provider for us.
	final ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();
	ops.add(ContentProviderOperation
			.newInsert(ContactsContract.RawContacts.CONTENT_URI)
			.withValue(ContactsContract.RawContacts.ACCOUNT_TYPE,
					mSelectedAccount.getType())
			.withValue(ContactsContract.RawContacts.ACCOUNT_NAME,
					mSelectedAccount.getName()).build());
	ops.add(ContentProviderOperation
			.newInsert(ContactsContract.Data.CONTENT_URI)
			.withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0)
			.withValue(
					ContactsContract.Data.MIMETYPE,
					ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE)
			.withValue(
					ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME,
					name)
			// .withValue(ContactsContract.CommonDataKinds.StructuredName.FAMILY_NAME,name)
			// .withValue(ContactsContract.CommonDataKinds.StructuredName.GIVEN_NAME,prenom)
			.build());
	ops.add(ContentProviderOperation
			.newInsert(ContactsContract.Data.CONTENT_URI)
			.withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0)
			.withValue(
					ContactsContract.Data.MIMETYPE,
					ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE)
			.withValue(ContactsContract.CommonDataKinds.Phone.NUMBER, phone)
			.withValue(ContactsContract.CommonDataKinds.Phone.TYPE,
					phoneType).build());
	ops.add(ContentProviderOperation
			.newInsert(ContactsContract.Data.CONTENT_URI)
			.withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0)
			.withValue(
					ContactsContract.Data.MIMETYPE,
					ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE)
			.withValue(ContactsContract.CommonDataKinds.Email.DATA, email)
			.withValue(ContactsContract.CommonDataKinds.Email.TYPE,
					emailType).build());
	ops.add(ContentProviderOperation
			.newInsert(ContactsContract.Data.CONTENT_URI)
			.withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0)
			.withValue(
					ContactsContract.Data.MIMETYPE,
					ContactsContract.CommonDataKinds.Organization.CONTENT_ITEM_TYPE)
			.withValue(
					ContactsContract.CommonDataKinds.Organization.COMPANY,
					"École de technologie supérieure")
			.withValue(
					ContactsContract.CommonDataKinds.Organization.DEPARTMENT,
					service)
			.withValue(ContactsContract.CommonDataKinds.Organization.TITLE,
					titre).build());
	ops.add(ContentProviderOperation
			.newInsert(ContactsContract.Data.CONTENT_URI)
			.withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0)
			.withValue(
					ContactsContract.Data.MIMETYPE,
					ContactsContract.CommonDataKinds.StructuredPostal.CONTENT_ITEM_TYPE)
			.withValue(
					ContactsContract.CommonDataKinds.StructuredPostal.DATA,
					empl).build());

	// Ask the Contact provider to create a new contact
	Log.i(TAG, "Selected account: " + mSelectedAccount.getName() + " ("
			+ mSelectedAccount.getType() + ")");
	Log.i(TAG, "Creating contact: " + name);
	try {
		getActivity().getContentResolver().applyBatch(
				ContactsContract.AUTHORITY, ops);
	} catch (final Exception e) {
		// Display warning
		final Context ctx = getActivity();
		final CharSequence txt = getString(R.string.contact_creation_failed);
		final int duration = Toast.LENGTH_SHORT;
		final Toast toast = Toast.makeText(ctx, txt, duration);
		toast.show();

		// Log exception
		Log.e(TAG, "Exceptoin encoutered while inserting contact: " + e);
	}
}
 
Example 19
Source File: Permission.java    From soundcom with Apache License 2.0 4 votes vote down vote up
public void initTransmit() {
        final Context context = getApplicationContext();

        CharSequence text = "Transmitter Mode Activated";
        int duration = Toast.LENGTH_SHORT;

        long free = Runtime.getRuntime().freeMemory();
//        generate(context);

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

        setContentView(R.layout.activity_transmitter);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
                this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
        toggle.syncState();

        NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
        navigationView.setNavigationItemSelectedListener(this);
        navigationView.setCheckedItem(R.id.transmit);


        gen = (Button) findViewById(R.id.generate);
        gen.setOnClickListener(this);
        mEdit = (EditText) findViewById(R.id.transmitString);


        fab_trans = (FloatingActionButton) findViewById(R.id.fab);
        fab_trans.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Snackbar.make(view, "Transmitting Modulated Waveform", Snackbar.LENGTH_LONG)
                        .setAction("Action", null).show();

                mediaplayer = new MediaPlayer();


                String root = Environment.getExternalStorageDirectory().toString();
                File dir = new File(root, "RedTooth");
                if (!dir.exists()) {
                    dir.mkdir();
                }

                try {
                    mediaplayer.setDataSource(dir + File.separator + "FSK.wav");
                    mediaplayer.prepare();
                    mediaplayer.start();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
        fab_trans.hide();


    }
 
Example 20
Source File: MainActivity.java    From soundcom with Apache License 2.0 4 votes vote down vote up
public void initTransmit() {
        final Context context = getApplicationContext();

        CharSequence text = "Transmitter Mode Activated";
        int duration = Toast.LENGTH_SHORT;

        long free = Runtime.getRuntime().freeMemory();
//        generate(context);

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

        setContentView(R.layout.activity_transmitter);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
                this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
        toggle.syncState();

        NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
        navigationView.setNavigationItemSelectedListener(this);
        navigationView.setCheckedItem(R.id.transmit);


        gen = (Button) findViewById(R.id.generate);
        mEdit = (EditText) findViewById(R.id.transmitString);
        gen.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                clickHelper(context,mEdit,v);
            }

        });


        fab_trans = (FloatingActionButton) findViewById(R.id.fab);
        fab_trans.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {  //playing the wav file
                Snackbar.make(view, "Transmitting Modulated Waveform", Snackbar.LENGTH_LONG)
                        .setAction("Action", null).show();

                mediaplayer = new MediaPlayer();

                String root = Environment.getExternalStorageDirectory().toString();
                File dir = new File(root, "Soundcom");
                if (!dir.exists()) {
                    dir.mkdir();
                }

                try {
                    mediaplayer.setDataSource(dir + File.separator + "FSK.wav");
                    mediaplayer.prepare();
                    mediaplayer.start();
                    MemberData data = new MemberData(a, getRandomColor());
                    boolean belongsToCurrentUser=true;
                    final Message message = new Message(src, data, belongsToCurrentUser);
                    printmessage(message);  //add transmitted message to chat

                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
        fab_trans.hide();
    }