Two Files 1)Texplay.java 2)textplay.xaml
1)TextPlay.java
package myapplication.example1.com.hackonlycom;
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.text.InputType;
import android.view.Gravity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.ToggleButton;
import java.util.Random;
public class TextPlay extends Activity implements View.OnClickListener {
Button bt;
TextView tv;
ToggleButton tb;
EditText et;
private void initialize() {
// TODO Auto-generated method stub bt = (Button) findViewById(R.id.b1);
tv = (TextView) findViewById(R.id.tv1);
tb = (ToggleButton) findViewById(R.id.tb1);
et = (EditText) findViewById(R.id.et);
}
@Override protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub super.onCreate(savedInstanceState);
setContentView(R.layout.textplay);
initialize();
tb.setOnClickListener(this);
bt.setOnClickListener(this);
}
@Override public void onClick(View view) {
// TODO Auto-generated method stub switch (view.getId()) {
case R.id.tb1:
if (tb.isChecked()) {
et.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
} else {
et.setInputType(InputType.TYPE_CLASS_TEXT);
}
break;
case R.id.b1:
String value = et.getText().toString();
if (value.contentEquals("left")) {
tv.setGravity(Gravity.LEFT);
} else if (value.contentEquals("right")) {
tv.setGravity(Gravity.RIGHT);
} else if (value.contentEquals("center")) {
tv.setGravity(Gravity.CENTER);
} else if (value.contentEquals("blue")) {
tv.setTextColor(Color.BLUE);
} else if (value.contentEquals("Hackonly")) {
tv.setText("Hackonly");
Random crazy = new Random();
tv.setTextSize(crazy.nextInt(75));
tv.setTextColor(Color.rgb(crazy.nextInt(255), crazy.nextInt(255), crazy.nextInt(255)));
switch (crazy.nextInt(3)) {
case 0:
tv.setGravity(Gravity.LEFT);
break;
case 1:
tv.setGravity(Gravity.CENTER);
break;
case 2:
tv.setGravity(Gravity.RIGHT);
break;
}
} else {
tv.setTextColor(Color.RED);
tv.setText("Invalid");
tv.setGravity(Gravity.CENTER);
}
break;
}
}
}
2) textplay.xml
xml version= "1.0" encoding ="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width= "match_parent" android:layout_height= "match_parent" android:orientation= "vertical" android:padding= "25dp">
<EditText android:id="@+id/et" android:layout_width="match_parent" android:layout_height= "wrap_content" android:hint= "Type a command"
/>
<LinearLayout android:weightSum= "100" android:layout_width="fill_parent" android:layout_height= "wrap_content" android:orientation= "horizontal" android:paddingBottom= "10dp" >
<Button android:layout_weight="25" android:id="@+id/b1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Button" />
<ToggleButton android:layout_weight="70" android:id="@+id/tb1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="ToggleButton" />
</LinearLayout >
<TextView android:id="@+id/tv1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="TextView" />
</LinearLayout>
0 comments:
Post a Comment