package com.prgguru.example;
import android.app.Activity;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
/**
* When Button "@+id/button1" is clicked
* @param v
*/
public void showToastTopLeft(View v) {
EditText e1 = (EditText) findViewById(R.id.editText1);
EditText e2 = (EditText) findViewById(R.id.editText2);
if (e1.getText().toString().trim().length() > 0
&& e2.getText().toString().trim().length() > 0) {
String editText1 = e1.getText().toString();
String editText2 = e2.getText().toString();
int xOffset = Integer.parseInt(editText1);
int yOffset = Integer.parseInt(editText2);
Toast toast = Toast.makeText(getApplicationContext(), "Hello toast!", Toast.LENGTH_SHORT);
toast.setGravity(Gravity.TOP | Gravity.LEFT, xOffset, yOffset);
toast.show();
} else {
Toast.makeText(getApplicationContext(),
"Please enter value for X-Offset and/or Y-Offset", Toast.LENGTH_SHORT)
.show();
}
}
/**
* When Button "@+id/button2" is clicked
* @param v
*/
public void showToastTopRight(View v) {
EditText e1 = (EditText) findViewById(R.id.editText1);
EditText e2 = (EditText) findViewById(R.id.editText2);
if (e1.getText().toString().trim().length() > 0
&& e2.getText().toString().trim().length() > 0) {
String editText1 = e1.getText().toString();
String editText2 = e2.getText().toString();
int xOffset = Integer.parseInt(editText1);
int yOffset = Integer.parseInt(editText2);
Toast toast = Toast.makeText(getApplicationContext(), "Hello toast!", Toast.LENGTH_SHORT);
toast.setGravity(Gravity.TOP | Gravity.RIGHT, xOffset, yOffset);
toast.show();
} else {
Toast.makeText(getApplicationContext(),
"Please enter value for X-Offset and/or Y-Offset", Toast.LENGTH_SHORT)
.show();
}
}
/**
* When Button "@+id/button3" is clicked
* @param v
*/
public void showToastBottomLeft(View v) {
EditText e1 = (EditText) findViewById(R.id.editText1);
EditText e2 = (EditText) findViewById(R.id.editText2);
if (e1.getText().toString().trim().length() > 0
&& e2.getText().toString().trim().length() > 0) {
String editText1 = e1.getText().toString();
String editText2 = e2.getText().toString();
int xOffset = Integer.parseInt(editText1);
int yOffset = Integer.parseInt(editText2);
Toast toast = Toast.makeText(getApplicationContext(), "Hello toast!", Toast.LENGTH_SHORT);
toast.setGravity(Gravity.BOTTOM | Gravity.LEFT, xOffset, yOffset);
toast.show();
} else {
Toast.makeText(getApplicationContext(),
"Please enter value for X-Offset and/or Y-Offset", Toast.LENGTH_SHORT)
.show();
}
}
/**
* When Button "@+id/button4" is clicked
* @param v
*/
public void showToastBottomRight(View v) {
EditText e1 = (EditText) findViewById(R.id.editText1);
EditText e2 = (EditText) findViewById(R.id.editText2);
if (e1.getText().toString().trim().length() > 0
&& e2.getText().toString().trim().length() > 0) {
String editText1 = e1.getText().toString();
String editText2 = e2.getText().toString();
int xOffset = Integer.parseInt(editText1);
int yOffset = Integer.parseInt(editText2);
Toast toast = Toast.makeText(getApplicationContext(), "Hello toast!", Toast.LENGTH_SHORT);
toast.setGravity(Gravity.BOTTOM | Gravity.RIGHT, xOffset, yOffset);
toast.show();
} else {
Toast.makeText(getApplicationContext(), "Please enter value for X-Offset and/or Y-Offset", Toast.LENGTH_SHORT).show();
}
}
}