BLP 4216 MOBİL UYGULAMA GELİŞTİRME-2 Dr. Aslı Ergün 1
BMI Ornek 27.05.2019
<. xml version="1. 0" encoding="utf-8" <?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:background="#E1C58E" tools:context=".MainActivity"> <LinearLayout android:layout_height="wrap_content" android:orientation="vertical" android:layout_marginTop="80dp"> <TextView android:id="@+id/tv_baslik" android:layout_width="wrap_content" android:text="BMI HESAPLAMA" android:textSize="24sp" android:textStyle="bold" android:layout_gravity="center" /> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:layout_marginTop="30dp"> <TextView android:id="@+id/textview4" android:layout_width="50dp" android:layout_marginStart="30dp" android:text="@string/kilo" /> <EditText android:id="@+id/kilo" android:hint="Kilo" android:inputType="number" app:layout_constraintStart_toEndOf="@+id/textview4" /> </LinearLayout> 27.05.2019
<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <TextView android:id="@+id/textView" android:layout_width="50dp" android:text="@string/boy" android:layout_marginStart="30dp" /> <EditText android:id="@+id/boy" android:hint="Boy" android:inputType="number" app:layout_constraintStart_toEndOf="@id/textView" </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <TextView android:id="@+id/textView2" android:layout_width="50dp" android:text="@string/yas" android:layout_marginStart="30dp" /> <EditText android:id="@+id/yas" android:hint="Yaş" android:inputType="number" app:layout_constraintStart_toEndOf="@id/textView2" </LinearLayout> 27.05.2019
<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <RadioGroup android:id="@+id/rdgroup" android:layout_width="wrap_content" android:orientation="horizontal" android:layout_marginTop="30dp" android:layout_gravity="center"> <RadioButton android:id="@+id/kadin" android:text="Kadın" /> <RadioButton android:id="@+id/erkek" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginStart="30dp" android:text="Erkek" /> </RadioGroup> <Button android:id="@+id/button" android:layout_marginTop="30dp" android:layout_gravity="center" android:text="HESAPLA" <TextView android:id="@+id/ideal" android:text="@string/BMI" </LinearLayout> 27.05.2019
Mainactivity.java public class MainActivity extends AppCompatActivity { Button butonhesap; TextView tv_ideal; EditText kilo; EditText boy; EditText yas; RadioGroup rdgrup; RadioButton k; RadioButton e; float katsayi; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); kilo = findViewById(R.id.kilo); boy = findViewById(R.id.boy); yas = findViewById(R.id.yas); tv_ideal = findViewById(R.id.ideal); rdgrup = findViewById(R.id.rdgroup); k = findViewById(R.id.kadin); e = findViewById(R.id.erkek); butonhesap = findViewById(R.id.button); butonhesap.setOnClickListener(new View.OnClickListener() { 27.05.2019
Mainactivity.java 27.05.2019 @Override public void onClick(View view) { int secilenRadio= rdgrup.getCheckedRadioButtonId(); switch(secilenRadio) { case(R.id.kadin): katsayi =0.8f; break; case(R.id.erkek): katsayi =0.9f; default: Toast.makeText(MainActivity.this, "Secim yapılmalı", Toast.LENGTH_SHORT).show(); } float b = Float.parseFloat(boy.getText().toString()); float y =Float.parseFloat(yas.getText().toString()); float k =Float.parseFloat(kilo.getText().toString()); float ideal = (b - 100 + y / 10) * katsayi; tv_ideal.setText(Float.toString(ideal)); if (ideal<k) Toast.makeText(MainActivity.this, "Kilolu", Toast.LENGTH_LONG).show(); else if(ideal>k) Toast.makeText(MainActivity.this, "Zayıf", Toast.LENGTH_LONG).show(); else Toast.makeText(MainActivity.this, "Normal", Toast.LENGTH_LONG).show(); }); 27.05.2019
Camera App 27.05.2019
Activity_main.xml <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:layout_margin="20dp" tools:context=".MainActivity"> <LinearLayout android:layout_height="wrap_content" android:orientation="vertical"> <VideoView android:id="@+id/videoView" android:layout_height="150dp" /> <ImageView android:id="@+id/imageView" android:layout_marginTop="20dp" app:srcCompat="@android:drawable/ic_menu_camera" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <Button android:id="@+id/videocek" android:layout_width="150dp" android:layout_height="60dp" android:text="Video Çek" android:layout_gravity="center" app:layout_constraintEnd_toEndOf="parent" android:layout_margin="20dp" /> android:id="@+id/fotocek" android:text="Fotograf Cek" </LinearLayout> 27.05.2019
AndroidManifest.xml <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.myapplication19"> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.RECORD_AUDIO" /> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> 27.05.2019
MainActivity.java public class MainActivity extends AppCompatActivity { Button fotografcek; Button videocek; private static final int VIDEO_ACTION_CODE = 101; private static final int IMAGE_ACTION_CODE = 102; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); fotografcek = findViewById(R.id.fotocek); videocek = findViewById(R.id.videocek); fotografcek.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { takePhoto(); } }); videocek.setOnClickListener(new View.OnClickListener() { recordVideo(); public void takePhoto() { Intent fotointent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); startActivityForResult(fotointent, IMAGE_ACTION_CODE); } public void recordVideo() { Intent videointent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE); startActivityForResult(videointent, VIDEO_ACTION_CODE); @Override protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { super.onActivityResult(requestCode, resultCode, data); if (resultCode != RESULT_OK) return; switch (requestCode) { case VIDEO_ACTION_CODE: VideoView videoV = findViewById(R.id.videoView); videoV.setVideoURI(data.getData()); videoV.setMediaController(new MediaController(this)); videoV.requestFocus(); videoV.start(); break; case IMAGE_ACTION_CODE: Bundle extras = data.getExtras(); ImageView img = findViewById(R.id.imageView); img.setImageBitmap((Bitmap) extras.get("data")); default: } }