design
This commit is contained in:
@@ -10,6 +10,10 @@ import android.widget.Switch;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.core.content.FileProvider;
|
||||
import java.io.File;
|
||||
|
||||
import androidx.activity.EdgeToEdge;
|
||||
import androidx.activity.result.ActivityResultLauncher;
|
||||
import androidx.activity.result.contract.ActivityResultContracts;
|
||||
@@ -39,6 +43,8 @@ public class DefinicoesActivity extends AppCompatActivity {
|
||||
private Uri selectedImageUri;
|
||||
|
||||
private ActivityResultLauncher<String> pickImageLauncher;
|
||||
private ActivityResultLauncher<Uri> takePictureLauncher;
|
||||
private Uri photoUri;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
@@ -69,8 +75,16 @@ public class DefinicoesActivity extends AppCompatActivity {
|
||||
}
|
||||
});
|
||||
|
||||
tvChangePhoto.setOnClickListener(v -> pickImageLauncher.launch("image/*"));
|
||||
ivProfilePicture.setOnClickListener(v -> pickImageLauncher.launch("image/*"));
|
||||
takePictureLauncher = registerForActivityResult(new ActivityResultContracts.TakePicture(),
|
||||
success -> {
|
||||
if (success) {
|
||||
selectedImageUri = photoUri;
|
||||
ivProfilePicture.setImageURI(selectedImageUri);
|
||||
}
|
||||
});
|
||||
|
||||
tvChangePhoto.setOnClickListener(v -> showPhotoOptionsDialog());
|
||||
ivProfilePicture.setOnClickListener(v -> showPhotoOptionsDialog());
|
||||
|
||||
SharedPreferences prefs = getSharedPreferences("LifeGridPrefs", Context.MODE_PRIVATE);
|
||||
String savedName = prefs.getString("username", "");
|
||||
@@ -123,4 +137,19 @@ public class DefinicoesActivity extends AppCompatActivity {
|
||||
finish();
|
||||
});
|
||||
}
|
||||
private void showPhotoOptionsDialog() {
|
||||
String[] options = {"Tirar fotografia", "Escolher da galeria de fotos"};
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
builder.setTitle("Alterar fotografia de perfil");
|
||||
builder.setItems(options, (dialog, which) -> {
|
||||
if (which == 0) {
|
||||
File photoFile = new File(getCacheDir(), "profile_photo.jpg");
|
||||
photoUri = FileProvider.getUriForFile(this, getPackageName() + ".fileprovider", photoFile);
|
||||
takePictureLauncher.launch(photoUri);
|
||||
} else if (which == 1) {
|
||||
pickImageLauncher.launch("image/*");
|
||||
}
|
||||
});
|
||||
builder.show();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user