Professional Documents
Culture Documents
Tugas Pemrograman Aplikasi Mobile: Oleh
Tugas Pemrograman Aplikasi Mobile: Oleh
OLEH :
NAMA : ANGEL
STAMBUK : 171103
STMIK DIPANEGARA
MAKASSAR
2020
Project
Form Camera
Camera 2 Galeri
Xml android:textColorHint="#000000" />
xmlns:app="http://schemas.android.com/a android:layout_height="wrap_content"
pk/res-auto" android:ems="10"
android:hint="Alamat"
xmlns:tools="http://schemas.android.com
/tools" android:inputType="textPersonName"
android:layout_width="match_parent"
android:textColorHint="#000000" />
android:layout_height="match_parent"
<EditText
tools:context="com.example.Angel171103. android:id="@+id/ettelepon"
MainActivity"
> android:layout_width="match_parent"
android:layout_height="wrap_content"
<LinearLayout android:ems="10"
android:hint="Telepon"
android:layout_width="match_parent"
android:inputType="textPersonName"
android:layout_height="match_parent"
android:orientation="vertical" android:textColorHint="#000000" />
android:gravity="center">
<LinearLayout
<EditText
android:id="@+id/etnim"
android:layout_width="match_parent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
android:ems="10"
android:hint="NIM"
<TextView
android:inputType="textPersonName"
android:id="@+id/textView2"
android:textColorHint="#000000" />
android:layout_width="259dp"
<EditText
android:id="@+id/etnama" android:layout_height="wrap_content"
android:layout_width="match_parent" android:layout_weight="1"
android:hint=""
android:ems="10"
android:layout_height="wrap_content"
android:text=" Jenis
android:ems="10"
Kelamin"
android:hint="Nama"
android:textColor="#000000"
android:inputType="textPersonName"
android:textColorHint="#FFFFFF" android:inputType="textPersonName"
android:textSize="18sp"
/> android:textColorHint="#000000" />
<RadioGroup <EditText
android:id="@+id/rgjk"
android:id="@+id/ettanggallahir"
android:layout_width="match_parent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" android:ems="10"
android:hint="Tanggal
android:orientation="horizontal"> Lahir"
<RadioButton android:inputType="textPersonName"
android:layout_width="wrap_content" <TextView
android:id="@+id/tvhobby"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_weight="1"
android:text="Laki android:layout_height="wrap_content"
- Laki" /> android:hint="NIM"
android:text=" Hobby :"
<RadioButton android:textColor="#000000"
android:id="@+id/rbperempuan" android:textColorHint="#FFFFFF"
android:textSize="18sp" />
android:layout_width="wrap_content"
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="Perempuan" />
</RadioGroup> android:orientation="horizontal">
</LinearLayout> <CheckBox
android:id="@+id/cb1"
<EditText
android:layout_width="171dp"
android:id="@+id/ettempatlahir"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_height="wrap_content" android:text="Membaca"
android:ems="10" />
android:hint="Tempat Lahir"
<CheckBox
android:id="@+id/cb2"
android:layout_width="71dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_weight="1"
android:text="Berkumpul android:text="Bersepeda" />
Dengan Teman" />
</LinearLayout> <CheckBox
android:id="@+id/cb6"
<LinearLayout
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal">
android:text="Sepakbola" />
<CheckBox </LinearLayout>
android:id="@+id/cb3"
<LinearLayout
android:layout_width="wrap_content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Main android:orientation="horizontal">
Games" />
<ImageView
<CheckBox
android:id="@+id/cb4" android:id="@+id/imagecamera"
android:layout_width="wrap_content" android:layout_width="200dp"
android:layout_height="wrap_content" android:layout_height="150dp"
android:layout_weight="1" android:layout_weight="1"
android:text="Mendaki
Gunung" />
app:srcCompat="@android:drawable/ic_men
</LinearLayout>
u_camera" />
<LinearLayout
<LinearLayout
android:layout_width="match_parent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
android:layout_weight="1"
<CheckBox
android:id="@+id/cb5" android:orientation="vertical">
<Button
Java
android:id="@+id/btncamera"
android:layout_height="75dp" import
androidx.appcompat.app.AppCompatActivit
android:layout_marginLeft="10dp" y;
import
androidx.core.app.ActivityCompat;
android:layout_marginRight="10dp"
import
androidx.core.content.ContextCompat;
android:text="Capture" />
import android.Manifest;
<Button import android.app.Activity;
import android.app.AlertDialog;
android:id="@+id/btngaleri" import android.content.Context;
import android.content.DialogInterface;
android:layout_width="200dp" import android.content.Intent;
import
android:layout_height="75dp" android.content.SharedPreferences;
import
android:layout_marginLeft="10dp" android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
android:layout_marginRight="10dp"
import android.net.Uri;
import android.os.Build;
android:text="galeri" /> import android.os.Bundle;
</LinearLayout> import android.os.Environment;
import android.provider.MediaStore;
</LinearLayout> import android.provider.Settings;
import android.util.Log;
<Button import android.view.View;
android:id="@+id/btndaftar" import android.widget.Button;
import android.widget.CheckBox;
android:layout_width="match_parent" import android.widget.EditText;
import android.widget.ImageView;
android:layout_height="wrap_content" import android.widget.RadioButton;
import android.widget.RadioGroup;
android:layout_marginTop="10dp" import android.widget.Toast;
android:onClick="save" import java.io.File;
android:text="Daftar" /> import java.io.FileNotFoundException;
import java.io.InputStream;
import java.io.PrintWriter;
</LinearLayout> import java.util.Scanner;
photoPickerIntent.setType("image/*"); Toast.LENGTH_SHORT).show();
}
startActivityForResult(photoPickerInten else{
t, PrintWriter pw;
try {
MY_PERMISSIONS_REQUEST_GALERI);
}
}); if(cb1.isChecked()){
//Izin Mengakses Camera hobby =
if "Membaca";
(ContextCompat.checkSelfPermission(this }else if(!
, Manifest.permission.CAMERA) != cb1.isChecked()){
hobby = "
PackageManager.PERMISSION_GRANTED) { ";
if (getFromPref(this, }
ALLOW_KEY)) {
showSettingsAlert(); if(cb2.isChecked()){
} else if hobby =
"Berkumpul Dengan Teman";
(ContextCompat.checkSelfPermission(this }else if(!
,Manifest.permission.CAMERA) cb2.isChecked()){
!= hobby = "
PackageManager.PERMISSION_GRANTED) { ";
if }
(ActivityCompat.shouldShowRequestPermis if(cb3.isChecked()){
sionRationale(this,Manifest.permission. hobby =
CAMERA)) { "Main Games";
showAlert(); }else if(!
} else { cb3.isChecked()){
// No explanation hobby = "
needed, we can request the permission. ";
}
ActivityCompat.requestPermissions(this,
new if(cb4.isChecked()){
String[] hobby =
{Manifest.permission.CAMERA},MY_PERMISS "Mendaki Gunung";
IONS_REQUEST_CAMERA); }else if(!
} cb4.isChecked()){
} hobby = "
} ";
}
daftar.setOnClickListener(new
View.OnClickListener() { if(cb5.isChecked()){
@Override hobby =
public void onClick(View v) "Bersepeda";
{ }else if(!
cb5.isChecked()){
if(nim.getText().toString().equals("")) hobby = "
{ ";
}
dialog.setMessage("Sukses Menulis Data
if(cb6.isChecked()){ Ke file ");
hobby = dialog.show();
"Sepak Bola "; } catch
}else if(! (FileNotFoundException e) {
cb6.isChecked()){ // TODO Auto-
hobby = " generated catch block
";
} e.printStackTrace();
int radioId =
jk.getCheckedRadioButtonId(); Toast.makeText(getApplicationContext(),
jeniskelamin = e.toString(),
(RadioButton)findViewById(radioId);
pw = new Toast.LENGTH_SHORT).show();
PrintWriter(filename); }
}
pw.println(nim.getText().toString());
}
pw.println("\n \r"); });
pw.println(nama.getText().toString());
pw.println("\n \r");
}
pw.println(alamat.getText().toString())
@Override
;
public void onActivityResult(int
requestCode, int resultCode, Intent
pw.println("\n \r"); data) {
pw.println(tanggallahir.getText().toStr super.onActivityResult(requestCode,
ing()); resultCode, data);
switch (requestCode) {
pw.println("\n \r");
case(MY_PERMISSIONS_REQUEST_CAMERA) :
pw.println(tempatlahir.getText().toStri if(resultCode ==
ng()); Activity.RESULT_OK)
{
pw.println("\n \r"); // result code
sama, save gambar ke bitmap
pw.println(telepon.getText().toString() Bitmap bitmap;
); bitmap = (Bitmap)
data.getExtras().get("data");
pw.println("\n \r");
imagecamera.setImageBitmap(bitmap);
pw.println(jeniskelamin.getText().toStr }
ing()); break;
Toast.makeText(getApplicationContext(), alertDialog.setButton(AlertDialog.BUTTO
"Something went wrong", N_POSITIVE, "ALLOW",
Toast.LENGTH_LONG).show(); new
} DialogInterface.OnClickListener() {
} public void
break; onClick(DialogInterface dialog, int
} which) {
}
public static void dialog.dismiss();
saveToPreferences(Context context,
String key, Boolean ActivityCompat.requestPermissions(MainA
allowed) { ctivity.this,
SharedPreferences myPrefs = new
context.getSharedPreferences(CAMERA_PRE String[]{Manifest.permission.CAMERA},
F,
Context.MODE_PRIVATE); MY_PERMISSIONS_REQUEST_CAMERA);
SharedPreferences.Editor }
prefsEditor = myPrefs.edit(); });
prefsEditor.putBoolean(key, alertDialog.show();
allowed); }
prefsEditor.commit(); private void showSettingsAlert() {
} AlertDialog alertDialog = new
public static Boolean
getFromPref(Context context, String AlertDialog.Builder(MainActivity.this).
key) { create();
SharedPreferences myPrefs = alertDialog.setTitle("Alert");
context.getSharedPreferences(CAMERA_PRE alertDialog.setMessage("App
F, needs to access the Camera.");
Context.MODE_PRIVATE);
return (myPrefs.getBoolean(key,
alertDialog.setButton(AlertDialog.BUTTO
false));
N_NEGATIVE, "DONT ALLOW",
}
new
private void showAlert() {
DialogInterface.OnClickListener() {
AlertDialog alertDialog = new
public void
onClick(DialogInterface dialog, int
which) { context.startActivity(i);
}
dialog.dismiss(); private boolean checkPermission() {
//finish(); int result =
} ContextCompat.checkSelfPermission(MainA
}); ctivity.this,
alertDialog.setButton(AlertDialog.BUTTO android.Manifest.permission.WRITE_EXTER
N_POSITIVE, "SETTINGS", NAL_STORAGE);
new if (result ==
DialogInterface.OnClickListener() { PackageManager.PERMISSION_GRANTED) {
public void return true;
onClick(DialogInterface dialog, int } else {
which) { return false;
}
dialog.dismiss(); }
private void requestPermission() {
if
startInstalledAppDetailsActivity(MainAc
(ActivityCompat.shouldShowRequestPermis
tivity.this);
sionRationale(MainActivity.this,
}
});
alertDialog.show(); android.Manifest.permission.WRITE_EXTER
} NAL_STORAGE)) {
@Override Toast.makeText(MainActivity.this,
protected void onResume() { "Write External Storage permission
super.onResume(); allows us to do store images. Please
} allow this permission in App
public static void Settings.",
startInstalledAppDetailsActivity(final
MainActivity Toast.LENGTH_LONG).show();
} else {
context) {
if (context == null) { ActivityCompat.requestPermissions(MainA
return; ctivity.this, new
} String[]
final Intent i = new Intent(); {android.Manifest.permission.WRITE_EXTE
RNAL_STORAGE},
i.setAction(Settings.ACTION_APPLICATION
_DETAILS_SETTINGS); PERMISSION_REQUEST_CODE);
}
i.addCategory(Intent.CATEGORY_DEFAULT); }
i.setData(Uri.parse("package:" @Override
+ context.getPackageName())); public void
onRequestPermissionsResult(int
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TAS requestCode, String permissions[],
K);
int[] grantResults) {
i.addFlags(Intent.FLAG_ACTIVITY_NO_HIST switch (requestCode) {
ORY); case
MY_PERMISSIONS_REQUEST_CAMERA: {
for (int i = 0, len =
i.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE
permissions.length; i < len; i++) {
_FROM_RECENTS);
String permission =
permissions[i];
if (grantResults[i]
== PackageManager.PERMISSION_DENIED) {
boolean
showRationale =
ActivityCompat.shouldShowRequestPermiss
ionRationale(this, permission);
if
(showRationale) {
showAlert();
} else if (!
showRationale) {
saveToPreferences(MainActivity.this,ALL
OW_KEY, true);
}
}
}
}
}
switch (requestCode) {
case
PERMISSION_REQUEST_CODE:
if (grantResults.length
> 0 && grantResults[0] ==
PackageManager.PERMISSION_GRANTED) {
Log.e("value",
"Permission Granted, Now you can use
local drive .");
} else {
Log.e("value",
"Permission Denied, You cannot use
local drive .");
}
break;
}
}