This commit is contained in:
2026-05-04 14:23:43 +01:00
parent dd80c8d9bb
commit bcd9bcc4f2
3 changed files with 46 additions and 2 deletions

View File

@@ -34,6 +34,16 @@
<category android:name="android.intent.category.LAUNCHER" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter> </intent-filter>
</activity> </activity>
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths" />
</provider>
</application> </application>
</manifest> </manifest>

View File

@@ -10,6 +10,10 @@ import android.widget.Switch;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; 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.EdgeToEdge;
import androidx.activity.result.ActivityResultLauncher; import androidx.activity.result.ActivityResultLauncher;
import androidx.activity.result.contract.ActivityResultContracts; import androidx.activity.result.contract.ActivityResultContracts;
@@ -39,6 +43,8 @@ public class DefinicoesActivity extends AppCompatActivity {
private Uri selectedImageUri; private Uri selectedImageUri;
private ActivityResultLauncher<String> pickImageLauncher; private ActivityResultLauncher<String> pickImageLauncher;
private ActivityResultLauncher<Uri> takePictureLauncher;
private Uri photoUri;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@@ -69,8 +75,16 @@ public class DefinicoesActivity extends AppCompatActivity {
} }
}); });
tvChangePhoto.setOnClickListener(v -> pickImageLauncher.launch("image/*")); takePictureLauncher = registerForActivityResult(new ActivityResultContracts.TakePicture(),
ivProfilePicture.setOnClickListener(v -> pickImageLauncher.launch("image/*")); success -> {
if (success) {
selectedImageUri = photoUri;
ivProfilePicture.setImageURI(selectedImageUri);
}
});
tvChangePhoto.setOnClickListener(v -> showPhotoOptionsDialog());
ivProfilePicture.setOnClickListener(v -> showPhotoOptionsDialog());
SharedPreferences prefs = getSharedPreferences("LifeGridPrefs", Context.MODE_PRIVATE); SharedPreferences prefs = getSharedPreferences("LifeGridPrefs", Context.MODE_PRIVATE);
String savedName = prefs.getString("username", ""); String savedName = prefs.getString("username", "");
@@ -123,4 +137,19 @@ public class DefinicoesActivity extends AppCompatActivity {
finish(); 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();
}
} }

View File

@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<paths>
<cache-path name="camera_images" path="." />
<files-path name="internal_files" path="." />
</paths>