Java Code Examples for android.widget.Toast.setGravity()

The following are Jave code examples for showing how to use setGravity() of the android.widget.Toast class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.

+ Save this method
Example 1
Project: ExcusePro-master View Source Vote up 6 votes
@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 2
Project: VoiceRecord-master View Source Vote up 6 votes
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 3
Project: Todayinformation-master View Source Vote up 6 votes
/**
 * ??????UI
 */
public static void showCollectionUI(Context context) {
	View view = LayoutInflater.from(context).inflate(
			R.layout.custom_collection, null);
	Toast toast = new Toast(context);
	toast.setView(view);
	toast.setGravity(Gravity.CENTER, 0, 0);
	toast.show();
}
 
Example 4
Project: sinaBlog-master View Source Vote up 6 votes
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 5
Project: SecurePhoto-master View Source Vote up 6 votes
private void onAuthenticationResult(int resultCode, Intent data) {
    switch (resultCode) {
        case Activity.RESULT_OK:
            ServerMessage serverMessage
                    = (ServerMessage) data.getSerializableExtra(ServerMessage.BUNDLE_ID);

            ServerResponse serverResponse = serverMessage.getServerResponse();
            String userMessage = null;
            int toastLength = Toast.LENGTH_SHORT;

            switch (serverResponse) {
                case AUTH_OK:
                    userMessage = getString(R.string.msg_authenticating_ok);
                    userMessage = String.format(userMessage, serverMessage.getServerName());

                    getRollButton.setEnabled(false);
                    getRollButton.setText(R.string.msg_autheticated);

                    // Starting the communication service
                    Intent serviceIntent = new Intent(this, CommunicationService.class);
                    serviceIntent.putExtra(ServerMessage.BUNDLE_ID, serverMessage);

                    startService(serviceIntent);

                    takeImgButton.setEnabled(true);

                    break;
                case AUTH_FAILED:
                    userMessage = getString(R.string.msg_authenticating_failed);
                    userMessage = String.format(userMessage, serverMessage.getServerAddress(), serverMessage.getErrorMessage());
                    toastLength = Toast.LENGTH_LONG;
                    break;
            }

            Toast t = Toast.makeText(this, userMessage, toastLength);
            t.setGravity(Gravity.CENTER, 0, 0);
            t.show();
            break;
        case Activity.RESULT_CANCELED:
            break;
        default:
            break;

    }
    if (resultCode == Activity.RESULT_OK) {


    }
}
 
Example 6
Project: NcueWifiAuth_android-master View Source Vote up 6 votes
@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 = Toast.makeText(context, mItemData.getTitle(), Toast.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 7
Project: SendContact-master View Source Vote up 6 votes
/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
//        Button pickContactButton = (Button) findViewById(R.id.pickContactButton);
//        pickContactButton.setOnClickListener(this);
        
        contentAccessor = new ContentAccessor();
        
        Intent intent = getIntent();
        Bundle extras = intent.getExtras();
        String action = intent.getAction();
        if (Intent.ACTION_SEND.equals(action)) {
        	if (extras.containsKey(Intent.EXTRA_STREAM)) {
        		// The URI returned from the Intent is 
        		// a vcard.
        		// for example
        		// content://com.android.contacts/contacts/as_vcard/0r1-5349475D454947532D472D
        		// or
        		// file:///sdcard/.blur/vcard/211.vcf
        		Uri uri = (Uri) extras.getParcelable(Intent.EXTRA_STREAM);
        		launchSMSActivity(uri);
        	}
        }
        else {
        	Context context = getApplicationContext();
        	CharSequence text = 
        		"To launch this app, go to the Contact list, select \"Menu\" then \"Share\".";
        	int duration = Toast.LENGTH_LONG;

        	Toast toast = Toast.makeText(context, text, duration);
        	toast.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL, 
        			0, 0);
        	toast.show();
        	finish();
        }
    }
 
Example 8
Project: TasksProject-master View Source Vote up 6 votes
@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 = Toast.makeText(context, mItemData.getTitle(), Toast.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 9
Project: TwAndroid-master View Source Vote up 6 votes
@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 10
Project: wpgen-master View Source Vote up 6 votes
protected void setColorWallpaper(String color) {
    // Create small solid color bitmap.
    Bitmap bitmap = createBitmap(color, 512);
    WallpaperManager wpManager = WallpaperManager.getInstance(this.getApplicationContext());
    try {
        wpManager.setBitmap(bitmap);
        String text = getString(R.string.toast_wallpaper_set_to_color);
        Toast toast = Toast.makeText(this, text, Toast.LENGTH_SHORT);
        toast.setGravity(Gravity.CENTER, 0, 0);
        toast.show();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
Example 11
Project: wally-master View Source Vote up 6 votes
@Override
public boolean onLongClick(View v) {
    final int[] screenPos = new int[2];
    getLocationOnScreen(screenPos);

    final Context context = getContext();
    final int width = getWidth();
    final int height = getHeight();
    final int screenWidth = context.getResources().getDisplayMetrics().widthPixels;

    Toast cheatSheet = Toast.makeText(context, getContentDescription(), Toast.LENGTH_SHORT);

    // Show under the tab
    cheatSheet.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL, (screenPos[0] + width / 2) - screenWidth / 2,
            height);

    cheatSheet.show();
    Log.d("TabView", "onLongClick");
    return true;
}
 
Example 12
Project: devcoin-android-master View Source Vote up 6 votes
@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 = Toast.makeText(context, mItemData.getTitle(), Toast.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 13
Project: CSipSimple-old-master View Source Vote up 6 votes
@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 = Toast.makeText(context, mItemData.getTitle(), Toast.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 14
Project: DemoProject-master View Source Vote up 6 votes
private void showOverlay() {
    // Generate a toast view with a special layout that will position itself right
    // on top of this view's interesting widgets.  Sneaky huh?
    SecureViewOverlay overlay = (SecureViewOverlay)
            getLayoutInflater().inflate(R.layout.secure_view_overlay, null);
    overlay.setActivityToSpoof(this);

    Toast toast = new Toast(getApplicationContext());
    toast.setGravity(Gravity.FILL, 0, 0);
    toast.setView(overlay);
    toast.show();
}
 
Example 15
Project: okjsp-android-master View Source Vote up 6 votes
@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 16
Project: AppLock-master View Source Vote up 6 votes
protected void onPasscodeError() {
	Toast toast = Toast.makeText(this, getString(R.string.passcode_wrong),
			Toast.LENGTH_SHORT);
	toast.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 30);
	toast.show();

	Thread thread = new Thread() {
		public void run() {
			Animation animation = AnimationUtils.loadAnimation(
					AppLockActivity.this, R.anim.shake);
			findViewById(R.id.ll_applock).startAnimation(animation);
			codeField1.setText("");
			codeField2.setText("");
			codeField3.setText("");
			codeField4.setText("");
			codeField1.requestFocus();
		}
	};
	runOnUiThread(thread);
}
 
Example 17
Project: jdroid-master View Source Vote up 6 votes
/**
 * Slightly modified code, from Jake Wharton's ABS
 */
private void showCheatsheet(Context context, View view) {
	
	final int[] screenPos = new int[2];
	final Rect displayFrame = new Rect();
	view.getLocationOnScreen(screenPos);
	view.getWindowVisibleDisplayFrame(displayFrame);
	
	final int width = view.getWidth();
	final int height = view.getHeight();
	final int midy = screenPos[1] + (height / 2);
	final int screenWidth = context.getResources().getDisplayMetrics().widthPixels;
	Toast cheatSheet = Toast.makeText(context, title, Toast.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();
}