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