Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Material Refresh #480

Merged
merged 16 commits into from
Nov 26, 2024
2 changes: 1 addition & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ android {
defaultConfig {
applicationId = "app.grapheneos.camera"
minSdk = 29
targetSdk = 34
targetSdk = 35
versionCode = 75
versionName = versionCode.toString()
resourceConfigurations.add("en")
Expand Down
15 changes: 9 additions & 6 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/Theme.App"
android:enableOnBackInvokedCallback="true"
tools:ignore="UnusedAttribute">

<!-- The main activity of the app (supports all modes) -->
Expand All @@ -38,7 +39,8 @@
android:configChanges="orientation|keyboardHidden|screenSize"
android:windowSoftInputMode="stateAlwaysHidden|adjustPan"
android:screenOrientation="nosensor"
android:exported="true">
android:exported="true"
android:theme="@style/Theme.Camera">

<intent-filter>
<action android:name="android.intent.action.MAIN"/>
Expand Down Expand Up @@ -71,7 +73,8 @@
android:screenOrientation="nosensor"
android:showWhenLocked="true"
android:excludeFromRecents="true"
android:exported="true">
android:exported="true"
android:theme="@style/Theme.Camera">

<intent-filter>
<action android:name="android.media.action.STILL_IMAGE_CAMERA_SECURE"/>
Expand Down Expand Up @@ -159,28 +162,28 @@

<activity
android:name=".ui.activities.VideoPlayer"
android:theme="@style/OverlayActionBar"
android:theme="@style/Theme.Viewer"
android:taskAffinity=".ui.activities.VideoPlayer"
android:excludeFromRecents="true"
android:exported="false"/>

<activity
android:name=".ui.activities.InAppGallery"
android:theme="@style/OverlayActionBar"
android:theme="@style/Theme.Viewer"
android:taskAffinity=".ui.activities.InAppGallery"
android:excludeFromRecents="true"
android:exported="false"/>

<activity
android:name=".ui.activities.MoreSettings"
android:theme="@style/OverlayActionBar"
android:theme="@style/Theme.App"
android:taskAffinity=".ui.activities.InAppGallery"
android:excludeFromRecents="true"
android:exported="false"/>

<activity
android:name=".ui.activities.MoreSettingsSecure"
android:theme="@style/OverlayActionBar"
android:theme="@style/Theme.App"
android:taskAffinity=".ui.activities.InAppGallery"
android:excludeFromRecents="true"
android:showWhenLocked="true"
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/java/app/grapheneos/camera/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import android.view.WindowManager
import androidx.annotation.RequiresPermission
import androidx.appcompat.app.AppCompatActivity
import app.grapheneos.camera.ui.activities.MainActivity
import com.google.android.material.color.DynamicColors

class App : Application() {
private var activity: MainActivity? = null
Expand Down Expand Up @@ -91,6 +92,7 @@ class App : Application() {
override fun onCreate() {
super.onCreate()
registerActivityLifecycleCallbacks(activityLifeCycleHelper)
DynamicColors.applyToActivitiesIfAvailable(this)
}

@RequiresPermission(allOf = [Manifest.permission.ACCESS_COARSE_LOCATION])
Expand Down
28 changes: 15 additions & 13 deletions app/src/main/java/app/grapheneos/camera/CamConfig.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package app.grapheneos.camera

import android.annotation.SuppressLint
import android.app.AlertDialog
import android.content.Context
import android.content.SharedPreferences
import android.net.Uri
Expand All @@ -16,6 +15,7 @@ import android.view.animation.Animation
import android.view.animation.LinearInterpolator
import android.widget.Button
import androidx.annotation.StringRes
import androidx.appcompat.app.AlertDialog
import androidx.camera.core.AspectRatio
import androidx.camera.core.Camera
import androidx.camera.core.CameraInfo
Expand Down Expand Up @@ -47,7 +47,9 @@ import app.grapheneos.camera.ui.activities.SecureActivity
import app.grapheneos.camera.ui.activities.SecureMainActivity
import app.grapheneos.camera.ui.activities.VideoCaptureActivity
import app.grapheneos.camera.ui.activities.VideoOnlyActivity
import app.grapheneos.camera.ui.showIgnoringShortEdgeMode
import app.grapheneos.camera.util.edit
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.google.zxing.BarcodeFormat
import java.util.concurrent.ExecutionException
import java.util.concurrent.Executors
Expand Down Expand Up @@ -1449,7 +1451,7 @@ class CamConfig(private val mActivity: MainActivity) {
}

fun showMoreOptionsForQR() {
val builder = AlertDialog.Builder(mActivity)
val builder = MaterialAlertDialogBuilder(mActivity)
builder.setTitle(mActivity.resources.getString(R.string.more_options))

val optionNames = arrayListOf<String>()
Expand Down Expand Up @@ -1517,28 +1519,28 @@ class CamConfig(private val mActivity: MainActivity) {
val dialog = builder.create()

dialog.setOnShowListener {
val button: Button = (dialog as AlertDialog).getButton(AlertDialog.BUTTON_NEUTRAL)
val button: Button = dialog.getButton(AlertDialog.BUTTON_NEUTRAL)
button.setOnClickListener {

}
}

dialog.show()
dialog.showIgnoringShortEdgeMode()
}

fun onStorageLocationNotFound() {
// Reverting back to DEFAULT_MEDIA_STORE_CAPTURE_PATH
storageLocation = SettingValues.Default.STORAGE_LOCATION

val builder = AlertDialog.Builder(mActivity)
builder.setTitle(R.string.folder_not_found)
builder.setMessage(R.string.reverting_to_default_folder)
builder.setPositiveButton(R.string.ok, null)
builder.setNeutralButton(R.string.more_settings) { _, _ ->
MoreSettings.start(mActivity)
}
val alertDialog: AlertDialog = builder.create()
val builder = MaterialAlertDialogBuilder(mActivity)
.setTitle(R.string.folder_not_found)
.setMessage(R.string.reverting_to_default_folder)
.setPositiveButton(R.string.ok, null)
.setNeutralButton(R.string.more_settings) { _, _ ->
MoreSettings.start(mActivity)
}
val alertDialog = builder.create()
alertDialog.setCancelable(false)
alertDialog.show()
alertDialog.showIgnoringShortEdgeMode()
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package app.grapheneos.camera.capturer

import android.annotation.SuppressLint
import android.app.AlertDialog
import android.app.Notification
import android.app.NotificationChannel
import android.app.NotificationManager
Expand All @@ -22,7 +21,9 @@ import app.grapheneos.camera.CapturedItem
import app.grapheneos.camera.R
import app.grapheneos.camera.ui.activities.MainActivity
import app.grapheneos.camera.ui.activities.SecureMainActivity
import app.grapheneos.camera.ui.showIgnoringShortEdgeMode
import app.grapheneos.camera.util.printStackTraceToString
import com.google.android.material.dialog.MaterialAlertDialogBuilder

private const val imageFileFormat = ".jpg"
var isTakingPicture: Boolean = false
Expand Down Expand Up @@ -196,7 +197,7 @@ class ImageCapturer(val mActivity: MainActivity) {
private fun showErrorDialog(message: String, exception: Throwable) {
val ctx = mActivity

AlertDialog.Builder(ctx).apply {
MaterialAlertDialogBuilder(ctx).apply {
setMessage(message)
setPositiveButton(R.string.show_details) { _, _ ->
val pkgName = ctx.packageName
Expand All @@ -205,18 +206,18 @@ class ImageCapturer(val mActivity: MainActivity) {
"\npackage: $pkgName:$pkgVersion" +
"\n\n${exception.printStackTraceToString()}"

AlertDialog.Builder(ctx).apply {
MaterialAlertDialogBuilder(ctx).apply {
setItems(text.lines().toTypedArray(), null)
setNeutralButton(R.string.copy_to_clipboard) { _, _ ->
val clipData = ClipData.newPlainText(exception.javaClass.name, text)
val cm = mActivity.getSystemService(ClipboardManager::class.java)
cm.setPrimaryClip(clipData)
ctx.showMessage(R.string.copied_text_to_clipboard)
}
show()
showIgnoringShortEdgeMode()
}
}
show()
showIgnoringShortEdgeMode()
}
}

Expand Down
27 changes: 27 additions & 0 deletions app/src/main/java/app/grapheneos/camera/ui/DialogUtil.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package app.grapheneos.camera.ui

import android.view.WindowManager
import androidx.appcompat.app.AlertDialog
import com.google.android.material.dialog.MaterialAlertDialogBuilder

/**
* When in an activity where the status bar is hidden, the window layoutInDisplayCutoutMode
* is set to [WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES], and a
* material alert dialog is present that is large enough, the layout of the dialog will appear
* broken and sometimes will shift randomly. These extensions force the dialog window to ignore
* the short edges mode so that it will appear as normal.
*/

fun AlertDialog.ignoreShortEdges() {
window?.attributes?.layoutInDisplayCutoutMode =
WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_DEFAULT
}

fun AlertDialog.showIgnoringShortEdgeMode(): AlertDialog {
ignoreShortEdges()
show()
return this
}

fun MaterialAlertDialogBuilder.showIgnoringShortEdgeMode(): AlertDialog =
this.create().showIgnoringShortEdgeMode()
Loading