1. Registrasi.java
package com.example.pmb_poligon;
import java.util.ArrayList;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import android.os.Build;
import android.os.Bundle;
import android.os.StrictMode;
import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class Registrasi extends Activity {
/** Called when the activity is first created. */
EditText email,username,password;
TextView status;
Button login,kelogin;
@TargetApi(Build.VERSION_CODES.GINGERBREAD)
@SuppressLint("NewApi")
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_registrasi);
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
email=(EditText) findViewById(R.id.txtemail);
username=(EditText) findViewById(R.id.txtusername);
password=(EditText) findViewById(R.id.txtpassword);
status=(TextView) findViewById (R.id.txtstatus);
login=(Button) findViewById (R.id.btn_login);
kelogin=(Button) findViewById (R.id.btn_ke_login);
kelogin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent a=new Intent(getApplicationContext(),Login.class);
startActivity(a);
}
});
login.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ArrayList<NameValuePair> postParameters = new ArrayList<NameValuePair>();
postParameters.add(new BasicNameValuePair("email", email.getText().toString()));
postParameters.add(new BasicNameValuePair("username", username.getText().toString()));
postParameters.add(new BasicNameValuePair("password", password.getText().toString()));
/* String valid = "1";*/
String response = null;
try {
response = CustomHttpClient.executeHttpPost("http://192.168.100.27/pmb/regis.php", postParameters);
String res = response.toString();
res = res.trim();
res = res.replaceAll("\\s+","");
status.setText(res);
if (res.equals("1")) status.setText("Maaf!! Anda Belum Terdaftar");
else status.setText("Anda Sudah Terdaftar, Silahkan Login!");
}
catch (Exception e) {
username.setText(e.toString());
}
}
});
// penutup buka dari public void onCreate
}
}
2. Registrasi.xml
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bgs"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".Login" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ImageView android:src="@drawable/logopmb"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_marginRight="2dp"
android:layout_marginBottom="20dp"
android:layout_marginTop="10dp"/>
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Email" />
<EditText
android:id="@+id/txtemail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textStyle="italic"
android:hint="contoh@gmail.com"
android:layout_marginBottom="30dp"
android:ems="10" >
<requestFocus />
</EditText>
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Username" />
<EditText
android:id="@+id/txtusername"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="username"
android:layout_marginBottom="30dp"
android:ems="10" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Password" />
<EditText
android:id="@+id/txtpassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="password"
android:inputType="textPassword"
android:layout_marginBottom="30dp"
android:ems="10" />
<Button
android:id="@+id/btn_login"
android:layout_width="200dp"
android:layout_height="50dp"
android:layout_gravity="center"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:background="@drawable/tombol"
android:layout_marginBottom="10dp"
android:text="Daftar"
android:textColor="#00cccc"
android:textSize="20dp"
android:textStyle="bold"
android:ems="10"
/>
<Button
android:id="@+id/btn_ke_login"
android:layout_width="200dp"
android:layout_height="50dp"
android:layout_gravity="center"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:background="@drawable/tombol"
android:layout_marginBottom="10dp"
android:text="Login"
android:textColor="#00cccc"
android:textSize="20dp"
android:textStyle="bold"
android:ems="10"
/>
<TextView
android:id="@+id/txtstatus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="" />
</LinearLayout>
</ScrollView>
3. Splashscreen.java
package com.example.pmb_poligon;
import android.os.Bundle;
import android.os.Handler;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.Window;
import android.view.WindowManager;
public class Splash_Screen extends Activity {
//Set waktu lama splashscreen
private static int splashInterval = 3000;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_splash__screen);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
Intent i = new Intent(Splash_Screen.this, Login.class);
startActivity(i);
//jeda selesai Splashscreen
this.finish();
}
private void finish() {
// TODO Auto-generated method stub
}
}, splashInterval);
};
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.splash__screen, menu);
return true;
}
}
4. Splashscreen.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
tools:context=".Splash_Screen" >
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/splash"/>
<ProgressBar
android:id="@+id/progressBar1"
style="?android:attr/progressBarStyleLarge"
android:layout_width="500dp"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="91dp" />
</RelativeLayout>
0 komentar: