sample/androidApp/src/main/kotlin/MainActivity.kt
author Da Risk <da_risk@geekorum.com>
Mon, 04 May 2026 18:00:16 -0400
changeset 114 ab226603d0f5
permissions -rw-r--r--
build: convert to AGP 9.2.0 and latest kotlin multiplatform
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
114
ab226603d0f5 build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
     1
/*
ab226603d0f5 build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
     2
 * AboutOss is an utility library to retrieve and display
ab226603d0f5 build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
     3
 * opensource licenses in Android applications.
ab226603d0f5 build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
     4
 *
ab226603d0f5 build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
     5
 * Copyright (C) 2023-2025 by Frederic-Charles Barthelery.
ab226603d0f5 build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
     6
 *
ab226603d0f5 build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
     7
 * This file is part of AboutOss.
ab226603d0f5 build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
     8
 *
ab226603d0f5 build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
     9
 * AboutOss is free software: you can redistribute it and/or modify
ab226603d0f5 build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    10
 * it under the terms of the GNU General Public License as published by
ab226603d0f5 build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    11
 * the Free Software Foundation, either version 3 of the License, or
ab226603d0f5 build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    12
 * (at your option) any later version.
ab226603d0f5 build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    13
 *
ab226603d0f5 build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    14
 * AboutOss is distributed in the hope that it will be useful,
ab226603d0f5 build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
ab226603d0f5 build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
ab226603d0f5 build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    17
 * GNU General Public License for more details.
ab226603d0f5 build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    18
 *
ab226603d0f5 build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    19
 * You should have received a copy of the GNU General Public License
ab226603d0f5 build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    20
 * along with AboutOss.  If not, see <http://www.gnu.org/licenses/>.
ab226603d0f5 build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    21
 */
ab226603d0f5 build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    22
package com.geekorum.aboutoss.sampleapp.android
ab226603d0f5 build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    23
ab226603d0f5 build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    24
import android.content.Intent
ab226603d0f5 build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    25
import android.os.Bundle
ab226603d0f5 build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    26
import androidx.activity.ComponentActivity
ab226603d0f5 build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    27
import androidx.activity.compose.setContent
ab226603d0f5 build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    28
import androidx.activity.enableEdgeToEdge
ab226603d0f5 build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    29
import com.geekorum.aboutoss.sampleapp.PrebuiltLicencesMaterial2Activity
ab226603d0f5 build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    30
import com.geekorum.aboutoss.sampleapp.PrebuiltLicencesMaterial3Activity
ab226603d0f5 build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    31
import com.geekorum.aboutoss.sampleapp.SampleApp
ab226603d0f5 build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    32
import com.geekorum.aboutoss.sampleapp.ui.theme.AboutOssTheme
ab226603d0f5 build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    33
import com.geekorum.aboutoss.sampleapp.ui.theme.OpenSourceLicenseTheme
ab226603d0f5 build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    34
import com.geekorum.aboutoss.ui.material3.OpenSourceLicensesActivity
ab226603d0f5 build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    35
import com.geekorum.aboutoss.ui.material.OpenSourceLicensesActivity as Material2OpenSourceLicensesActivity
ab226603d0f5 build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    36
ab226603d0f5 build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    37
class MainActivity : ComponentActivity() {
ab226603d0f5 build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    38
    override fun onCreate(savedInstanceState: Bundle?) {
ab226603d0f5 build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    39
        super.onCreate(savedInstanceState)
ab226603d0f5 build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    40
        enableEdgeToEdge()
ab226603d0f5 build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    41
        setContent {
ab226603d0f5 build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    42
            AboutOssTheme {
ab226603d0f5 build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    43
                SampleApp(
ab226603d0f5 build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    44
                    onMaterial2Click = {
ab226603d0f5 build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    45
                        startMaterial2LicenseActivity()
ab226603d0f5 build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    46
                    },
ab226603d0f5 build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    47
                    onMaterial3Click = {
ab226603d0f5 build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    48
                        startMaterial3LicenseActivity()
ab226603d0f5 build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    49
                    }
ab226603d0f5 build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    50
                )
ab226603d0f5 build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    51
            }
ab226603d0f5 build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    52
        }
ab226603d0f5 build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    53
    }
ab226603d0f5 build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    54
ab226603d0f5 build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    55
    private fun startMaterial2LicenseActivity() {
ab226603d0f5 build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    56
        val intent = if (BuildConfig.DEBUG) {
ab226603d0f5 build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    57
            // we launch a custom activity in debug to display some fake licenses
ab226603d0f5 build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    58
            // see Material2AcPrebuiltLicencesMaterial2Activitytivity for more info
ab226603d0f5 build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    59
            Intent(this, PrebuiltLicencesMaterial2Activity::class.java)
ab226603d0f5 build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    60
        } else {
ab226603d0f5 build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    61
            Intent(this, Material2OpenSourceLicensesActivity::class.java)
ab226603d0f5 build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    62
        }
ab226603d0f5 build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    63
        startActivity(intent)
ab226603d0f5 build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    64
    }
ab226603d0f5 build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    65
ab226603d0f5 build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    66
    private fun startMaterial3LicenseActivity() {
ab226603d0f5 build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    67
        // Don't use default MaterialTheme but supply our own
ab226603d0f5 build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    68
        OpenSourceLicensesActivity.themeProvider = { content ->
ab226603d0f5 build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    69
            OpenSourceLicenseTheme(content)
ab226603d0f5 build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    70
        }
ab226603d0f5 build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    71
        val intent = if (BuildConfig.DEBUG) {
ab226603d0f5 build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    72
            // we launch a custom activity in debug to display some fake licenses
ab226603d0f5 build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    73
            // see PrebuiltLicencesMaterial3Activity for more info
ab226603d0f5 build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    74
            Intent(this, PrebuiltLicencesMaterial3Activity::class.java)
ab226603d0f5 build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    75
        } else {
ab226603d0f5 build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    76
            Intent(this, OpenSourceLicensesActivity::class.java)
ab226603d0f5 build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    77
        }
ab226603d0f5 build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    78
        startActivity(intent)
ab226603d0f5 build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    79
    }
ab226603d0f5 build: convert to AGP 9.2.0 and latest kotlin multiplatform
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    80
}