Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 460bd399 authored by Mohammed Althaf T's avatar Mohammed Althaf T 😊
Browse files

Update QR implementation from lineage

parent f98f0c33
Loading
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -17,7 +17,7 @@ android {

    defaultConfig {
        applicationId "foundation.e.camera"
        minSdkVersion 21
        minSdkVersion 26
        targetSdkVersion 35
        //compileSdkVersion 31 // needed to support appcompat:1.4.0 (which we need for emoji policy support, and not yet ready to target SDK 30)

+4 −4
Original line number Diff line number Diff line
@@ -5,7 +5,7 @@ import net.sourceforge.opencamera.cameracontroller.CameraControllerManager;
import net.sourceforge.opencamera.cameracontroller.CameraControllerManager2;
import net.sourceforge.opencamera.preview.Preview;
import net.sourceforge.opencamera.preview.VideoProfile;
import net.sourceforge.opencamera.qr.QrImageAnalyzer;
import net.sourceforge.opencamera.qr.QrBottomSheetDialog;
import net.sourceforge.opencamera.remotecontrol.BluetoothRemoteControl;
import net.sourceforge.opencamera.ui.CircleImageView;
import net.sourceforge.opencamera.ui.DrawPreview;
@@ -262,9 +262,9 @@ public class MainActivity extends AppCompatActivity implements PreferenceFragmen
    public static final boolean lock_to_landscape = false;

    // QRCode
    public QrImageAnalyzer qrImageAnalyzer;
    public QrBottomSheetDialog qrBottomSheetDialog;
    private Job job;
    private CoroutineScope coroutineScope;
    public CoroutineScope coroutineScope;

    // handling for lock_to_landscape==false:

@@ -305,7 +305,7 @@ public class MainActivity extends AppCompatActivity implements PreferenceFragmen
        //QRCode
        job = JobKt.Job(null);
        coroutineScope = () -> Dispatchers.getMain().plus(job);
        qrImageAnalyzer = new QrImageAnalyzer(this, coroutineScope);
        qrBottomSheetDialog = new QrBottomSheetDialog(this);

        setContentView(R.layout.activity_main);
        PreferenceManager.setDefaultValues(this, R.xml.preferences, false); // initialise any unset preferences to their default values
+0 −130
Original line number Diff line number Diff line
/*
 * SPDX-FileCopyrightText: 2024 The LineageOS Project
 * SPDX-License-Identifier: Apache-2.0
 */

package net.sourceforge.opencamera.ext

import android.app.RemoteAction
import android.content.Context
import android.content.Intent
import android.os.Build
import android.provider.ContactsContract
import android.view.textclassifier.TextClassification
import android.view.textclassifier.TextClassifier
import com.google.zxing.client.result.AddressBookParsedResult
import net.sourceforge.opencamera.R

fun AddressBookParsedResult.createIntent() = Intent(
    Intent.ACTION_INSERT, ContactsContract.Contacts.CONTENT_URI
).apply {
    names.firstOrNull()?.let {
        putExtra(ContactsContract.Intents.Insert.NAME, it)
    }

    pronunciation?.let {
        putExtra(ContactsContract.Intents.Insert.PHONETIC_NAME, it)
    }

    phoneNumbers?.let { phoneNumbers ->
        val phoneTypes = phoneTypes ?: arrayOf()

        for ((key, keys) in listOf(
            listOf(
                ContactsContract.Intents.Insert.PHONE,
                ContactsContract.Intents.Insert.PHONE_TYPE,
            ),
            listOf(
                ContactsContract.Intents.Insert.SECONDARY_PHONE,
                ContactsContract.Intents.Insert.SECONDARY_PHONE_TYPE,
            ),
            listOf(
                ContactsContract.Intents.Insert.TERTIARY_PHONE,
                ContactsContract.Intents.Insert.TERTIARY_PHONE_TYPE,
            ),
        ).withIndex()) {
            phoneNumbers.getOrNull(key)?.let { phone ->
                putExtra(keys.first(), phone)
                phoneTypes.getOrNull(key)?.let {
                    putExtra(keys.last(), it)
                }
            }
        }
    }

    emails?.let { emails ->
        val emailTypes = emailTypes ?: arrayOf()

        for ((key, keys) in listOf(
            listOf(
                ContactsContract.Intents.Insert.EMAIL,
                ContactsContract.Intents.Insert.EMAIL_TYPE,
            ),
            listOf(
                ContactsContract.Intents.Insert.SECONDARY_EMAIL,
                ContactsContract.Intents.Insert.SECONDARY_EMAIL_TYPE,
            ),
            listOf(
                ContactsContract.Intents.Insert.TERTIARY_EMAIL,
                ContactsContract.Intents.Insert.TERTIARY_EMAIL_TYPE,
            ),
        ).withIndex()) {
            emails.getOrNull(key)?.let { phone ->
                putExtra(keys.first(), phone)
                emailTypes.getOrNull(key)?.let {
                    putExtra(keys.last(), it)
                }
            }
        }
    }

    instantMessenger?.let {
        putExtra(ContactsContract.Intents.Insert.IM_HANDLE, it)
    }

    note?.let {
        putExtra(ContactsContract.Intents.Insert.NOTES, it)
    }

    addresses?.let { emails ->
        val addressTypes = addressTypes ?: arrayOf()

        for ((key, keys) in listOf(
            listOf(
                ContactsContract.Intents.Insert.POSTAL,
                ContactsContract.Intents.Insert.POSTAL_TYPE,
            ),
        ).withIndex()) {
            emails.getOrNull(key)?.let { phone ->
                putExtra(keys.first(), phone)
                addressTypes.getOrNull(key)?.let {
                    putExtra(keys.last(), it)
                }
            }
        }
    }

    org?.let {
        putExtra(ContactsContract.Intents.Insert.COMPANY, it)
    }
}

fun AddressBookParsedResult.createTextClassification(
    context: Context
) = TextClassification.Builder()
    .setText(title ?: names.firstOrNull() ?: "")
    .setEntityType(TextClassifier.TYPE_OTHER, 1.0f)
    .apply {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
            addAction(
                RemoteAction::class.build(
                    context,
                    R.drawable.ic_contact_phone,
                    R.string.qr_address_title,
                    R.string.qr_address_content_description,
                    createIntent()
                )
            )
        }
    }
    .build()
+0 −63
Original line number Diff line number Diff line
/*
 * SPDX-FileCopyrightText: 2024 The LineageOS Project
 * SPDX-License-Identifier: Apache-2.0
 */

package net.sourceforge.opencamera.ext

import android.app.RemoteAction
import android.content.Context
import android.content.Intent
import android.os.Build
import android.provider.CalendarContract
import android.view.textclassifier.TextClassification
import android.view.textclassifier.TextClassifier
import androidx.core.os.bundleOf
import com.google.zxing.client.result.CalendarParsedResult
import net.sourceforge.opencamera.R

fun CalendarParsedResult.createIntent() = Intent(
    Intent.ACTION_INSERT, CalendarContract.Events.CONTENT_URI
).apply {
    summary?.let {
        putExtra(CalendarContract.Events.TITLE, it)
    }
    description?.let {
        putExtra(CalendarContract.Events.DESCRIPTION, it)
    }
    location?.let {
        putExtra(CalendarContract.Events.EVENT_LOCATION, it)
    }
    organizer?.let {
        putExtra(CalendarContract.Events.ORGANIZER, it)
    }
    attendees?.let {
        putExtra(Intent.EXTRA_EMAIL, it.joinToString(","))
    }

    putExtras(
        bundleOf(
            CalendarContract.EXTRA_EVENT_BEGIN_TIME to startTimestamp,
            CalendarContract.EXTRA_EVENT_END_TIME to endTimestamp,
            CalendarContract.EXTRA_EVENT_ALL_DAY to (isStartAllDay && isEndAllDay),
        )
    )
}

fun CalendarParsedResult.createTextClassification(context: Context) = TextClassification.Builder()
    .setText(summary)
    .setEntityType(TextClassifier.TYPE_OTHER, 1.0f)
    .apply {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
            addAction(
                RemoteAction::class.build(
                    context,
                    R.drawable.ic_calendar_add_on,
                    R.string.qr_calendar_title,
                    R.string.qr_calendar_content_description,
                    createIntent()
                )
            )
        }
    }
    .build()
+0 −17
Original line number Diff line number Diff line
/*
 * SPDX-FileCopyrightText: 2024 The LineageOS Project
 * SPDX-License-Identifier: Apache-2.0
 */

package net.sourceforge.opencamera.ext

import android.content.Context
import android.util.TypedValue
import androidx.annotation.AttrRes
import androidx.annotation.ColorInt

@ColorInt
fun Context.getThemeColor(@AttrRes attribute: Int) = TypedValue().let {
    theme.resolveAttribute(attribute, it, true)
    it.data
}
Loading