Java Code Examples for android.widget.Toast

The following are top voted examples for showing how to use android.widget.Toast. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to product more good examples.

Example 1
Project: BLEConnect   File: DeviceScanActivity.java View source code 6 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getActionBar().setTitle(R.string.title_devices);
    mHandler = new Handler();

    // Use this check to determine whether BLE is supported on the device.  Then you can
    // selectively disable BLE-related features.
    if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) {
        Toast.makeText(this, R.string.ble_not_supported, Toast.LENGTH_SHORT).show();
        finish();
    }

    // Initializes a Bluetooth adapter.  For API level 18 and above, get a reference to
    // BluetoothAdapter through BluetoothManager.
    final BluetoothManager bluetoothManager =
            (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
    mBluetoothAdapter = bluetoothManager.getAdapter();

    // Checks if Bluetooth is supported on the device.
    if (mBluetoothAdapter == null) {
        Toast.makeText(this, R.string.error_bluetooth_not_supported, Toast.LENGTH_SHORT).show();
        finish();
        return;
    }
}
 
Example 2
Project: Grinnell-DB-Android   File: DetailedSearchFragment.java View source code 6 votes vote down vote up
public void sendDetailedQuery() {

		String theURL = "https://itwebapps.grinnell.edu/classic/asp/campusdirectory/GCdefault.asp?transmit=true&blackboardref=true&LastName="
				+ mActivity.cleanString(lastNameText.getText().toString())
				+ "&LNameSearch=startswith&FirstName="
				+ mActivity.cleanString(firstNameText.getText().toString())
				+ "&FNameSearch=startswith&email="
				+ mActivity.cleanString(usernameText.getText().toString())
				+ "&campusphonenumber="
				+ mActivity.cleanString(phoneText.getText().toString())
				+ "&campusquery="
				+ mActivity.cleanString(campusAddressText.getText().toString())
				+ "&Homequery="
				+ mActivity.cleanString(homeAddressText.getText().toString())
				+ "&Department="
				+ mActivity.cleanString(facDeptSpinner.getSelectedItem()
						.toString())
				+ "&Major="
				+ mActivity.cleanString(studentMajorSpinner.getSelectedItem()
						.toString())
				+ "&conc="
				+ mActivity.cleanString(concentrationSpinner.getSelectedItem()
						.toString())
				+ "&SGA="
				+ mActivity
						.cleanString(sgaSpinner.getSelectedItem().toString())
				+ "&Hiatus="
				+ mActivity.cleanHiatus(hiatusSpinner.getSelectedItem()
						.toString())
				+ "&Gyear="
				+ mActivity.cleanString(studentClassSpinner.getSelectedItem()
						.toString()) + "&submit_search=Search";

		if (mActivity.inGrinnell)
			new RequestTask(mActivity).execute(theURL);
		else {
			Toast toast = Toast
					.makeText(mActivity,
							"Connect to Grinnell College Student Network for Detailed Search",
							Toast.LENGTH_LONG);
			toast.show();
		}
	}
 
Example 3
Project: ExcusePro   File: ActionMenuItemView.java View source code 6 votes vote down vote up
@Override
public boolean onLongClick(View v) {
    if (hasText()) {
        // Don't show the cheat sheet for items that already show text.
        return false;
    }

    final int[] screenPos = new int[2];
    final Rect displayFrame = new Rect();
    getLocationOnScreen(screenPos);
    getWindowVisibleDisplayFrame(displayFrame);

    final Context context = getContext();
    final int width = getWidth();
    final int height = getHeight();
    final int midy = screenPos[1] + height / 2;
    final int screenWidth = context.getResources().getDisplayMetrics().widthPixels;

    Toast cheatSheet = IcsToast.makeText(context, mItemData.getTitle(), IcsToast.LENGTH_SHORT);
    if (midy < displayFrame.height()) {
        // Show along the top; follow action buttons
        cheatSheet.setGravity(Gravity.TOP | Gravity.RIGHT,
                screenWidth - screenPos[0] - width / 2, height);
    } else {
        // Show along the bottom center
        cheatSheet.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, height);
    }
    cheatSheet.show();
    return true;
}
 
Example 4
Project: VoiceRecord   File: RecordButton.java View source code 6 votes vote down vote up
private void showWarnToast(String toastText) {
    Toast toast = new Toast(mContext);
    View warnView = LayoutInflater.from(mContext).inflate(
            R.layout.toast_warn, null);
    toast.setView(warnView);
    toast.setGravity(Gravity.CENTER, 0, 0);// ???????
    toast.show();
}
 
Example 5
Project: sinaBlog   File: CustomToast.java View source code 6 votes vote down vote up
public static Toast makeText(Context context, CharSequence text,
		int duration) {
	Toast result = new Toast(context);

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

	TextView textView = (TextView) layout.findViewById(R.id.toast);
	DisplayMetrics dm2 = context.getResources().getDisplayMetrics();
	textView.setWidth(dm2.widthPixels);
	textView.setText(text);

	result.setView(layout);
	result.setGravity(Gravity.CENTER, 0, 0);
	result.setDuration(duration);

	return result;
}
 
Example 6
Project: my-ministry-assistant   File: DailyBackupService.java View source code 6 votes vote down vote up
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
	File intDB = getApplicationContext().getDatabasePath(MinistryDatabase.DATABASE_NAME);
	File extDB = FileUtils.getExternalDBFile(getApplicationContext(), "auto-daily.db");
	
	try {
		if(extDB != null) {
			if(!extDB.exists())
				extDB.createNewFile();
			
			FileUtils.copyFile(intDB, extDB);
		}
	} catch (IOException e) {
		Toast.makeText(getApplicationContext(), "Error during daily backup", Toast.LENGTH_LONG).show();
	}
	
	return Service.START_NOT_STICKY;
}
 
Example 7
Project: Tofu-Notes   File: Say.java View source code 6 votes vote down vote up
private static void clean() {
	Iterator<Toast> i = toasts.iterator();
	while(i.hasNext()) {
		Toast t = i.next();
		t.cancel();
	}
	
	toasts = new ArrayList<Toast>();
}
 
Example 8
Project: ABPlayer   File: ToastUtils.java View source code 6 votes vote down vote up
public static void showToast(Context ctx, int duration, String text) {
	Toast toast = Toast.makeText(ctx, text, duration);
	View mNextView = toast.getView();
	if (mNextView != null)
		mNextView.setBackgroundResource(R.drawable.toast_frame);
	toast.show();
	// Toast.makeText(ctx, text, duration).show();
}
 
Example 9
Project: MUtils   File: UICore.java View source code 6 votes vote down vote up
public static void toast(IToastOwner owner, CharSequence s) {
	if (!isEnabled(owner)) {
		return;
	}
	Toast t = owner.getToast();
	if (s == null) {
		t.cancel();
	} else {
		if (s.equals("")) {
			t.cancel();
		} else {
			t.setText(s);
			t.show();
		}
	}
}