ToggleButton – Password hiding in Android
ToggleButton – Password hiding in Android
Eine App, die mit dem ToogleButton unser Password anzeigt oder es versteckt.


main.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" android:padding="40dp" > <EditText android:id="@+id/etPass" android:layout_width="fill_parent" android:layout_height="wrap_content" android:hint="Type the password" android:password="true" /> <ToggleButton android:id="@+id/tbPassword" android:layout_width="fill_parent" android:layout_height="wrap_content" android:checked="true" android:paddingBottom="10dp" android:text="ToggleButton" android:textOff="Showing password" android:textOn="Hiding password" /> <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:weightSum="100" > <TextView android:id="@+id/tvPass" android:layout_width="fill_parent" android:gravity="center" android:layout_height="match_parent" android:layout_weight="30" android:text="..." /> <Button android:id="@+id/button1" android:layout_width="fill_parent" android:layout_height="match_parent" android:layout_weight="70" android:text="Check" /> </LinearLayout> </LinearLayout>

Unser Java Code:
package de.worldling;
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.text.InputType;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.ToggleButton;
public class PassProjectActivity extends Activity implements View.OnClickListener {
EditText editText;
Button button;
ToggleButton toggleButton;
TextView textView;
String string;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
initStuff();
}
private void initStuff() {
editText = (EditText) findViewById(R.id.etPass);
button = (Button) findViewById(R.id.button1);
toggleButton = (ToggleButton) findViewById(R.id.tbPassword);
textView = (TextView) findViewById(R.id.tvPass);
button.setOnClickListener(this);
toggleButton.setOnClickListener(this);
}
public void onClick(View v) {
switch (v.getId()){
case R.id.tbPassword:
if (toggleButton.isChecked()){
editText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
} else{
editText.setInputType(InputType.TYPE_CLASS_TEXT);
}
break;
case R.id.button1:
string = editText.getText().toString();
if(string.equals("pass")){
textView.setText(string);
textView.setTextColor(Color.GREEN);
}else{
textView.setText("WRONG");
textView.setTextColor(Color.RED);
}
break;
}
}
}
Android GraphicsView – einen Gradient Background setzen und Circles Malen
Android GraphicsView – einen Gradient Background setzen und Circles Malen
Heute machen wir mall so etwas in Android:

background.xml
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" > <gradient android:angle="270" android:endColor="#000000" android:startColor="#FFFFFF" /> </shape>
Die Activity:
package com.example;
import android.app.Activity;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.Path.Direction;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
public class Start1 extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(new GraphicsView(this));
}
static public class GraphicsView extends View {
public GraphicsView(Context context) {
super(context);
setBackgroundResource(R.drawable.background);
}
@Override
protected void onDraw(Canvas canvas) {
Paint paint1 = new Paint();
Paint paint2 = new Paint();
paint1.setColor(Color.WHITE);
paint2.setColor(Color.BLACK);
Path circle = new Path();
Path circle2 = new Path();
Path circle3 = new Path();
circle.addCircle(300, 300, 200, Direction.CW);
canvas.drawPath(circle, paint1);
circle2.addCircle(300, 300, 50, Direction.CW);
canvas.drawPath(circle2, paint2);
circle3.addCircle(300, 300, 10, Direction.CW);
canvas.drawPath(circle3, paint1);
}
}
}
Ein Android Splash Screen Tutorial (mit mp3 Sound)
Ein Android Splash Screen Tutorial (mit mp3 Sound)
Es ist immer gut, wenn eine Android App uns mit einen Splash Screen begrüßt. Hier ein Tutorial dafür:
Der splash.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:background="@drawable/back" > </LinearLayout>

Der Manifest:
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="de.worldling" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="8" /> <application android:icon="@drawable/ic_launcher" android:label="@string/app_name" > <activity android:name=".Splash" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".Sound1" android:label="@string/app_name" > <intent-filter> <action android:name="de.worldling.SOUND1" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> </activity> </application> </manifest>
Und die Java Classe, splash.java:
package de.worldling;
import java.io.IOException;
import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
public class Splash extends Activity {
MediaPlayer mp;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
mp = MediaPlayer.create(Splash.this, R.raw.sound1);
mp.start();
Thread timer = new Thread() {
public void run() {
try {
sleep(5000);// 5 seconds
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
Intent openStartingPoint = new Intent("de.worldling.SOUND1");
startActivity(openStartingPoint);
}
}
};
timer.start();
}
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
mp.release();
finish();
}
}
Android Tutorial – Mp3 Sounds mit Button abspielen
Android Tutorial - Mp3 Sounds mit Button abspielen
Eine einfache App, mit der man einen Mp3 Sound abspielen kann.

main.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <Button android:id="@+id/bAudio" android:layout_width="250dp" android:layout_height="wrap_content" android:layout_gravity="center" android:layout_marginTop="50dp" android:text="Audio 1" android:textSize="20dp" /> <Button android:id="@+id/bAudio2" android:layout_width="250dp" android:layout_height="wrap_content" android:layout_gravity="center" android:text="Audio 2" android:textSize="20dp" /> </LinearLayout>
Unsere Activity
package de.worldling;
import android.app.Activity;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class Sound1 extends Activity {
public MediaPlayer mp;
Button audio1, audio2;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
audio1 = (Button) findViewById(R.id.bAudio);
audio2 = (Button) findViewById(R.id.bAudio2);
audio1.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
mp = MediaPlayer.create(getApplicationContext(), R.raw.sound1);
mp.start();
}
});
audio2.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
mp = MediaPlayer.create(getApplicationContext(), R.raw.sound2);
mp.start();
}
});
}
}

Einfache Android App – Dialog Theme und ein Exit Button
Einfache Android App – Dialog Theme und ein Exit Button
Wir schreiben ein Android App, die einen TextVeiw und zwei Buttons hat.
So sieht sie aus:

main.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="horizontal" android:padding="50dip" > <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_gravity="center" android:orientation="vertical" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:layout_marginBottom="25dip" android:text="@string/title" android:textSize="30sp" /> <Button android:id="@+id/button1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/button1" /> <Button android:id="@+id/button2" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/button2" /> </LinearLayout> </LinearLayout>
Das sagt und wie der Layout aussehen soll. ‘fill_parent’ oder ‘wrap_content’
android:layout_width="fill_parent"
android:layout_height="wrap_content"
Sind auch visuelle Aspekte.
android:layout_gravity="center"
android:orientation="vertical"
Welcher String sold dort sein?
android:text="@string/title"
Wir geben den Button en ID
android:id="@+id/button1"
Die erste Activity Class:
package de.worldling;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
public class Worldling1Activity extends Activity implements OnClickListener {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//click listeners
View aboutButton = findViewById(R.id.button1);
aboutButton.setOnClickListener(this);
View exitButton = findViewById(R.id.button2);
exitButton.setOnClickListener(this);
}
public void onClick(View v) {
switch (v.getId()) {
case R.id.button1:
Intent i = new Intent(this, Test1.class);
startActivity(i);
break;
case R.id.button2:
finish();
break;
}
}
}
Ein Switch der die Buttons unterstützt
public void onClick(View v) {
switch (v.getId()) {
case R.id.button1:
Intent i = new Intent(this, Test1.class);
startActivity(i);
break;
case R.id.button2:
finish();
break;
}
}
Test1.java – die Java Classe für den test1.xml
package de.worldling;
import android.app.Activity;
import android.os.Bundle;
public class Test1 extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.test1);
}
}
test1.xml – der XML für unseren Dialog
<?xml version="1.0" encoding="utf-8"?> <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:padding="30dip" > <TextView android:id="@+id/about_content" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/test" /> </ScrollView>
strings.xml – wo alle String sind
<?xml version="1.0" encoding="utf-8"?> <resources> <string name="app_name">Worldling1</string> <string name="title">Worldling1 App</string> <string name="title2">Test1</string> <string name="button1">Button</string> <string name="button2">Exit</string> <string name="test">Worldling test</string> </resources>

Der Manifest
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="de.worldling" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="8" /> <application android:icon="@drawable/ic_launcher" android:label="@string/app_name" > <activity android:name=".Worldling1Activity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".Test1" android:label="@string/title2" android:theme="@android:style/Theme.Dialog" > </activity> </application> </manifest>
