Notes
Notes - notes.io |
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.pm.PackageManager;
import android.hardware.Camera;
import android.hardware.Camera.Parameters;
import android.media.MediaPlayer;
import androidx.appcompat.app.AppCompatActivity;
import android.media.MediaPlayer.OnCompletionListener;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ImageButton;
import com.example.android2.R;
public class MainActivity extends AppCompatActivity {
ImageButton btnSwitch;
private Camera camera;
private boolean flashAcik;
private boolean flashVarmı;
Parameters params;
MediaPlayer mp;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnSwitch = (ImageButton) findViewById(R.id.btnSwitch); //ImageButton'u tanımladık
//İlk işlem kameranın flash'ının olup olmadığı
flashVarmı = getApplicationContext().getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH);
if (!flashVarmı) {
//FlashYoksa alertDialog ile ekrana flash'ın olmadığını çıkardık
AlertDialog alert = new AlertDialog.Builder(MainActivity.this).create();
alert.setTitle("HATA");
alert.setMessage("Bu aygıt Flash desteklemiyor");
alert.setButton("Tamam", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// Tamam'a basınca uygulamayı kapatıyoruz.
finish();
}
});
alert.show();
return;
}
// camera'ya erişiyoruz
cameraAc();
//Flash'ın durumuna göre button'un resmini ayarlıyoruz
toggleButtonImage();
/*
* Button'a her tıklandığında olacaklar. Flash açıksa kapat, Kapalıysa aç
*/
btnSwitch.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (flashAcik) { // Flash Acik true dönücek. Eğer Flash Açıksa Kapatıcak
flashKapat();
} else {
// Açık değilse button'a basınca açıcak
flashAc();
}
}
});
}
/*
* Get the camera
*/
private void cameraAc() {
if (camera == null) {
camera = Camera.open();
params = camera.getParameters();
}
}
/*
* Flash'ı açma kısmı burada
*/
private void flashAc() {
if (!flashAcik) {
if (camera == null || params == null) {
return;
}
params = camera.getParameters();
params.setFlashMode(Parameters.FLASH_MODE_TORCH);
camera.setParameters(params);
camera.startPreview();
flashAcik = true;
// Flash Button'u Değişiyor
toggleButtonImage();
}
}
/*
* Flash'ı kapatma kısmı
*/
private void flashKapat() {
if (flashAcik) {
if (camera == null || params == null) {
return;
}
params = camera.getParameters();
params.setFlashMode(Parameters.FLASH_MODE_OFF);
camera.setParameters(params);
camera.stopPreview();
flashAcik = false;
// changing button/switch image
toggleButtonImage();
}
}
/*
* Button'un değiştirmesi
* */
private void toggleButtonImage(){
if(flashAcik){
btnSwitch.setImageResource(R.drawable.btn_switch_off);
}else{
btnSwitch.setImageResource(R.drawable.btn_switch_on);
}
}}
|
Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...
With notes.io;
- * You can take a note from anywhere and any device with internet connection.
- * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
- * You can quickly share your contents without website, blog and e-mail.
- * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
- * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.
Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.
Easy: Notes.io doesn’t require installation. Just write and share note!
Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )
Free: Notes.io works for 12 years and has been free since the day it was started.
You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;
Email: [email protected]
Twitter: http://twitter.com/notesio
Instagram: http://instagram.com/notes.io
Facebook: http://facebook.com/notesio
Regards;
Notes.io Team