You are on page 1of 17

LAPORAN TUGAS PRAKTIKUM

APLIKASI MOBILE
“Aktivitas Dan Maksud “

Disusun oleh:

Rakhmilawati Faznur A1316096

TEKNIK INFORMATIKA
POLITEKNIK NEGERI TANAH LAUT
2018
1. Hello Toast

a. Deskripsi
Merupakan aplikasi yang digunakan untuk menghitung score dengan mengklik
tombol count untuk menambah data yang kemudian data itu akan di kirim ke
aktivitas dua dengan isi “Aloha ! 6”.

b. Flowchart

c. Koding

Source Code ActivityMain.xml


<?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"
tools:context="com.example.emiliyana.hellotoastfaznur.MainActivity"
android:paddingRight="16dp"
android:paddingLeft="16dp"
android:paddingTop="16dp"
android:paddingBottom="16dp"
android:orientation="vertical">

<Button
android:id="@+id/button_toast"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimary"
android:textColor="@android:color/white"
android:text="Aloha !"
android:onClick="LaunchHelloToast"
tools:ignore="HardcodedText" />

<TextView
android:id="@+id/show_count"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textStyle="bold"
android:textColor="@color/colorPrimary"
android:text="0"
android:background="@color/MyBackgroundColor"
android:gravity="center"
android:layout_weight="2"
android:textSize="@dimen/count_text_size"
tools:ignore="HardcodedText,InefficientWeight,SpUsage" />

<Button
android:id="@+id/button_count"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimary"
android:textColor="@android:color/white"
android:text="Count"
android:onClick="showCount"
tools:ignore="HardcodedText" />

</LinearLayout>

Source Code MainActivity.Java


package com.example.emiliyana.hellotoastfaznur;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import static android.provider.AlarmClock.EXTRA_MESSAGE;


public class MainActivity extends AppCompatActivity {
public static final String EXTRA_MESSAGE =
"com.example.emiliyana.hellotoastemiliyana.extra.MESSAGE";
private int mCount = 0;
private TextView mShowCount;
private static final String LOG_TAG =
MainActivity.class.getSimpleName();
public static final int TEXT_REQUEST = 1;

@SuppressLint("WrongViewCast")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

mShowCount = (TextView) findViewById(R.id.show_count);


}

public void showCount(View view) {


mCount++;
if (mShowCount != null)
mShowCount.setText(Integer.toString(mCount));
}

public void LaunchHelloToast(View view) {


Log.d(LOG_TAG, "Button clicked!");
Intent intent = new Intent(this, SecondActivity.class);
String message = mShowCount.getText().toString();
intent.putExtra(EXTRA_MESSAGE, message);
startActivityForResult(intent, TEXT_REQUEST);
startActivity(intent);
}
}

Source Code SecondActivity.xml


package com.example.emiliyana.hellotoastfaznur;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;

public class SecondActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
Intent intent = getIntent();
String message =
intent.getStringExtra(MainActivity.EXTRA_MESSAGE);
TextView textView = (TextView) findViewById(R.id.text_count);
textView.setText(message);
}
}
Source Code ActivitySecond.Java
<?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"
tools:context="com.example.emiliyana.hellotoastfaznur.SecondActivity"
android:orientation="vertical">

<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="45dp"
android:text="Hello !"
android:textAlignment="center"
android:textSize="30sp"
tools:ignore="HardcodedText" />

<TextView
android:id="@+id/text_count"
android:layout_width="match_parent"
android:layout_height="42dp"
android:text="0"
android:textAlignment="center"
android:textSize="30sp"
tools:ignore="HardcodedText" />

</LinearLayout>

Source Code colors.xml


<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FF4081</color>
<color name="MyBackgroundColor">#FFF043</color>
</resources>

Source Code dimens.xml


<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="count_text_size">160sp</dimen>
</resources>

Source Code String.xml


<resources>
<string name="app_name">HelloToastFaznur</string>
</resources>
Source Code Styles.xml
<resources>

<!-- Base application theme. -->


<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>

</resources>

d. Screenshot
2. Counter Home Work

a. Deskripsi

Merupakan aplikasi yang digunakan untuk memasukkan angka, dimana


apabila rotasinya di putar maka jumlah count yang telah dimasukkan akan berubah
menjadi nol.

b. Flowchart

c. Koding

Source Code ActivityMain.xml


<?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"

tools:context="com.example.emiliyana.counterhomeworkfaznur.MainActivity"
android:visibility="visible"
android:orientation="vertical">

<TextView
android:id="@+id/show_count"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="0"
android:textAlignment="center"
android:textStyle="bold"
tools:ignore="HardcodedText" />
<Button
android:id="@+id/button_count"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="showCount"
android:text="count"
tools:ignore="HardcodedText" />
<EditText
android:id="@+id/editText2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:text="Edit text"
tools:ignore="HardcodedText" />

</LinearLayout>

Source Code MainActivity.Java


package com.example.emiliyana.counterhomeworkfaznur;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {


private int mCount = 0;
private TextView mShowCount;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mShowCount = (TextView) findViewById(R.id.show_count);

public void showCount(View view) {


mCount++;
if (mShowCount != null)
mShowCount.setText(Integer.toString(mCount));
}
}
Source Code Colors.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FF4081</color>
</resources>

Source Code Strings.xml


<resources>
<string name="app_name">CounterHomeWorkFaznur</string>
</resources>

Source Code Styles.xml


<resources>

<!-- Base application theme. -->


<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>

</resources>

e. Screenshot
3. Implicit Intens

a. Deskripsi

Merupakan aplikasi yang akan menampilkan foto saat mengklik tombol Take
A pic yang mana didalamnya terdapat open website, open location, dan share text.

b. Flowchart
c. Koding

Source Code ActivityMain.xml


<?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"

tools:context="com.example.emiliyana.implisitintensfaznur.MainActivit
y"
android:paddingBottom="16dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingTop="16dp"
android:orientation="vertical">

<EditText
android:id="@+id/website_edittext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Rakhmilawatif@gmail.com"
tools:ignore="HardcodedText,TextFields" />
<Button
android:id="@+id/open_website_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="24dp"
android:onClick="openWebsite"
android:text="Open Website"
tools:ignore="HardcodedText" />
<EditText
android:id="@+id/location_edittext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Golden Gate Bridge"
tools:ignore="HardcodedText,TextFields" />
<Button
android:id="@+id/open_location_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="24dp"
android:onClick="openLocation"
android:text="Open Location"
tools:ignore="HardcodedText" />
<EditText
android:id="@+id/share_edittext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Twass brilling and the slithy tovers"
tools:ignore="HardcodedText,TextFields" />
<Button
android:id="@+id/share_text_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="24dp"
android:onClick="shareText"
android:text="Share Text"
tools:ignore="HardcodedText" />

<Button
android:id="@+id/ambil_foto_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="take_pict"
android:text="Take A pic"
tools:ignore="HardcodedText" />

</LinearLayout>

Source Code MainActivity. Java


package com.example.emiliyana.implisitintensfaznur;

import android.content.Intent;
import android.net.Uri;
import android.provider.MediaStore;
import android.support.v4.app.ShareCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.EditText;

public class MainActivity extends AppCompatActivity {


private EditText mWebsiteEditText;
private EditText mLocationEditText;
private EditText mShareTextEditText;
private final int requestCode = 1;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mWebsiteEditText = (EditText)
findViewById(R.id.website_edittext);
mLocationEditText = (EditText)
findViewById(R.id.location_edittext);
mShareTextEditText = (EditText)
findViewById(R.id.share_edittext);
}

public void shareText(View view) {


String txt = mShareTextEditText.getText().toString();
String mimeType = "text/plain";
ShareCompat.IntentBuilder
.from(this)
.setType(mimeType)
.setChooserTitle("Share this text with: ")
.setText(txt)
.startChooser();
}

public void openLocation(View view) {


String loc = mLocationEditText.getText().toString();
Uri addressUri = Uri.parse("geo:0,0?q=" + loc);
Intent intent = new Intent(Intent.ACTION_VIEW, addressUri);
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
} else {
Log.d("ImplicitIntents", "Can't handle this intent!");
}
}

public void openWebsite(View view) {


String url = mWebsiteEditText.getText().toString();
Uri webpage = Uri.parse(url);
Intent intent = new Intent(Intent.ACTION_VIEW, webpage);
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
} else {
Log.d("ImplicitIntents", "Can't handle this!");
}
}

public void take_pict(View view) {


Intent photoCaptureIntent = new
Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(photoCaptureIntent, requestCode);

}
}

Source Code Colors.xml


<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FF4081</color>
</resources>

Source Code Strings.xml


<resources>
<string name="app_name">ImplisitIntensFaznur</string>
</resources>

Source Code Styles.xml


<resources>
<!-- Base application theme. -->
<style name="AppTheme"
parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
</resources>
d. Screenshot
JAWABAN PERTANYAAN

1. a. Cari app (klik kanan) New  Activity Empy Activity.

b. Menambahkan Button dan TextView.


c. untuk ekstra makud.
e. Semua hal diatas.

2. a. Karena nilai tidak tersimpan dan akan berubah ketika berubah rotasi, text edit akan
tetap sama karena sudah didefinisikan/terdeklarasi dari awal.
b. onSaveinstanceState().
c. Saat layar mengalami peruahan rotasi (perangkat di putar).
d. Void on SaveinstanceState().
e. Dalam onCreate() dapat membuat status aktivitas sedangkan dalam
onRestoreInstance() hanya bisa merestore yang sudah dibuat.
f. Aplikasi akan mereset dan nilai sebelumnya tidak tersimpan.

3. a. New Intent ().


b. Untuk mengambil kamera atau menangkap foto bisa menggunakan fungsi private
final requestCode = 1;