0% found this document useful (0 votes)
164 views

Activity - Main - HTML: Linearlayout

The document contains code for an Android login screen and coffee ordering app. It includes XML layout files for the login screen and order screen, with views like text fields, buttons, checkboxes. It also includes Java code for the login and order activities, including handling button clicks, validating login credentials, and incrementing/decrementing the order quantity. The code defines the user interface and basic interactivity for a login screen that leads to a coffee ordering screen where the user can select items and quantities to place an order.

Uploaded by

David Gustrianda
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
164 views

Activity - Main - HTML: Linearlayout

The document contains code for an Android login screen and coffee ordering app. It includes XML layout files for the login screen and order screen, with views like text fields, buttons, checkboxes. It also includes Java code for the login and order activities, including handling button clicks, validating login credentials, and incrementing/decrementing the order quantity. The code defines the user interface and basic interactivity for a login screen that leads to a coffee ordering screen where the user can select items and quantities to place an order.

Uploaded by

David Gustrianda
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Activity_Main.

html

<?xml version="1.0" encoding="utf-8"?>


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@drawable/cofee4"
tools:context=".MainActivity">

<ImageView
android:id="@+id/gmbr"
android:layout_width="match_parent"
android:layout_height="150sp"
android:textAlignment="center"
android:textSize="50sp"
android:layout_margin="40dp"/>

<TextView
android:id="@+id/username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Masukan Username"
android:textColor="#000000"
android:textSize="20sp"
android:layout_marginHorizontal="50dp"/>

<EditText
android:id="@+id/username2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Username"
android:textColorHint="#000"
android:layout_marginHorizontal="50dp"/>

<TextView
android:id="@+id/password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Masukan Password :"
android:textColor="#000"
android:textSize="20sp"
android:layout_marginHorizontal="50dp"/>

<EditText
android:id="@+id/password2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Password"
android:textColorHint="#000"
android:inputType="textPassword"
android:layout_marginHorizontal="50dp"/>

<CheckBox
android:id="@+id/boxx"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="show password"
android:textColor="#000" />

<Button
android:id="@+id/button"
android:layout_width="150sp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Login"
android:textSize="15sp" />

<Button
android:id="@+id/button2"
android:layout_width="150sp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Register"
android:textSize="15sp" />

<TextView
android:id="@+id/tampil"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
Activity_Main2.html

<?xml version="1.0" encoding="utf-8"?>


<ScrollView android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
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/cofe2"
tools:context="com.wilis.pemesanancoffe.MainActivity">

<EditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:hint="Masukan nama anda"
android:id="@+id/edt_name"
android:inputType="text"/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Choffe"
android:layout_gravity="center"
android:textSize="25dp"/>

<CheckBox

android:id="@+id/Arabica"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Exspresso"
android:paddingLeft="16dp"
android:textSize="15sp"/>

<CheckBox

android:id="@+id/Chocolate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Chocolate"
android:paddingLeft="16dp"
android:textSize="15sp"/>

<CheckBox
android:id="@+id/Arabica_Chocolate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Capuccino"
android:textSize="15sp"
android:paddingLeft="16dp"/>

<TextView

android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="jumlah"
android:textSize="25dp"
android:textAllCaps="true"
android:layout_marginBottom="16dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<LinearLayout

android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">

<Button

android:layout_width="48dp"
android:onClick="increment"
android:text="+"
android:layout_height="48dp" />

<TextView

android:textColor="#212121"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0"
android:paddingRight="8dp"
android:paddingLeft="8dp"
android:id="@+id/quantity_textview"
android:textSize="25dp"/>

<Button

android:layout_width="48dp"
android:onClick="decrement"
android:text="-"
android:layout_height="48dp" />

</LinearLayout>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Harga"
android:textSize="30dp"
android:textAllCaps="true"
android:layout_marginBottom="16dp"/>

<TextView

android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0"
android:textColor="#212121"
android:id="@+id/price_textview"
android:textSize="25dp"/>

<Button

android:layout_width="wrap_content"
android:layout_marginBottom="16dp"
android:onClick="Submitorder"
android:layout_height="wrap_content"
android:text="Order"/>

</LinearLayout>

</ScrollView>

MainActivity.java

package com.kmftapp.tes;

import android.content.Intent;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

EditText username, password;


Button btnLogin;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

username = (EditText) findViewById(R.id.username2);


password = (EditText) findViewById(R.id.password2);
btnLogin = (Button)findViewById(R.id.button);

btnLogin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

String usernameKey = username.getText().toString();


String passwordKey = password.getText().toString();

if (usernameKey.equals("admin") && passwordKey.equals("123")){


//jika login berhasil
Toast.makeText(getApplicationContext(), "LOGIN SUKSES",
Toast.LENGTH_SHORT).show();
Intent intent = new Intent(MainActivity.this, Main2Activity.class);
MainActivity.this.startActivity(intent);
finish();
}else {
//jika login gagal
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
builder.setMessage("Username atau Password Anda salah!")
.setNegativeButton("Retry", null).create().show();
}
}

});

}
}

main2activity.java

package com.kmftapp.tes;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import java.text.NumberFormat;

import static android.R.string.no;


import static android.os.Build.VERSION_CODES.N;

public class Main2Activity extends AppCompatActivity {


int quantity=0;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
}
public void increment(View view){//perintah tombol tambah

if(quantity==100){
Toast.makeText(this,"pesanan maximal 100",Toast.LENGTH_SHORT).show();
return;

}
quantity = quantity+1 ;
display(quantity);
}
public void decrement(View view){//perintah tombol tambah

if (quantity==1){

Toast.makeText(this,"pesanan minimal 1",Toast.LENGTH_SHORT).show();


return;
}
quantity = quantity -1;
display(quantity);

}
public void Submitorder(View view) {
EditText nameEditText=(EditText)findViewById(R.id.edt_name);
String name=nameEditText.getText().toString();
Log.v("Main2Activity","Nama:"+name);

CheckBox ArabicaCheckBox=(CheckBox)findViewById(R.id.Arabica);
boolean hasArabica=ArabicaCheckBox.isChecked();
Log.v("Main2Activity","has Arabica: "+hasArabica);

CheckBox chocolateChekBox =(CheckBox)findViewById(R.id.Chocolate);


boolean haschocolate=chocolateChekBox.isChecked();
Log.v("Main2Activity","has whippedcream:"+haschocolate);

CheckBox arabicachocolate =(CheckBox)findViewById(R.id.Arabica_Chocolate);


boolean hasarabicachocolate=arabicachocolate.isChecked();
Log.v("Main2Activity","has arabicachocolate: "+hasarabicachocolate);
int price=calculateprice(hasArabica,haschocolate,hasarabicachocolate);
String pricemessage=createOrderSummary(price,name,hasArabica,haschocolate,hasarabicachocolate);

displayMessage(pricemessage);
}

private int calculateprice(boolean addArabica, boolean addchocolate, boolean addarabicachocolate){


int harga=0;
if(addArabica){
harga=harga+3000;

}
if (addchocolate){
harga=harga+4000;

}
if (addarabicachocolate){
harga=harga+5000;
}
return quantity * harga;

}
private String createOrderSummary(int price, String name, boolean Benar, boolean Yakin, boolean
Sungguh) {
String pricemessage=" Nama :"+name;
pricemessage+="\n Apakah Anda ingin Menambahkan arabica?";
pricemessage+="\n Apakah Anda ingin Menambahkan Chocolate?";
pricemessage+="\n Apakah Anda Ingin Menambahkan ArabicaChocolate ?";
pricemessage+="\n Jumlah"+quantity;
pricemessage+="\n Total Rp"+price;
pricemessage+="\n Thankyou ";

return pricemessage;
}
private void displayMessage(String massage){
TextView priceTextView =(TextView)findViewById(R.id.price_textview);
priceTextView.setText(massage);

}
private void display(int number){
TextView quantityTextView = (TextView) findViewById(R.id.quantity_textview);
quantityTextView.setText("" + number);
}
private void displayPrice(int number) {
TextView priceTextView = (TextView) findViewById(R.id.price_textview);
priceTextView.setText(NumberFormat.getCurrencyInstance().format(number));
}
}

You might also like