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 |
|
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.compose.foundation.layout.* |
|
29 import androidx.compose.material3.* |
|
30 import androidx.compose.runtime.Composable |
|
31 import androidx.compose.ui.Modifier |
|
32 import androidx.compose.ui.tooling.preview.Preview |
|
33 import androidx.compose.ui.unit.dp |
|
34 import com.geekorum.aboutoss.sampleapp.ui.theme.AboutOssTheme |
|
35 import com.geekorum.aboutoss.sampleapp.ui.theme.OpenSourceLicenseTheme |
|
36 import com.geekorum.aboutoss.ui.material3.OpenSourceLicensesActivity |
|
37 import com.geekorum.aboutoss.ui.material.OpenSourceLicensesActivity as Material2OpenSourceLicensesActivity |
|
38 |
|
39 class MainActivity : ComponentActivity() { |
|
40 override fun onCreate(savedInstanceState: Bundle?) { |
|
41 super.onCreate(savedInstanceState) |
|
42 setContent { |
|
43 AboutOssTheme { |
|
44 Sample( |
|
45 onMaterial2Click = { |
|
46 startMaterial2LicenseActivity() |
|
47 }, |
|
48 onMaterial3Click = { |
|
49 startMaterial3LicenseActivity() |
|
50 } |
|
51 ) |
|
52 } |
|
53 } |
|
54 } |
|
55 |
|
56 private fun startMaterial2LicenseActivity() { |
|
57 val intent = if (BuildConfig.DEBUG) { |
|
58 // we launch a custom activity in debug to display some fake licenses |
|
59 // see Material2AcPrebuiltLicencesMaterial2Activitytivity for more info |
|
60 Intent(this, PrebuiltLicencesMaterial2Activity::class.java) |
|
61 } else { |
|
62 Intent(this, Material2OpenSourceLicensesActivity::class.java) |
|
63 } |
|
64 startActivity(intent) |
|
65 } |
|
66 |
|
67 private fun startMaterial3LicenseActivity() { |
|
68 // Don't use default MaterialTheme but supply our own |
|
69 OpenSourceLicensesActivity.themeProvider = { content -> |
|
70 OpenSourceLicenseTheme(content) |
|
71 } |
|
72 val intent = if (BuildConfig.DEBUG) { |
|
73 // we launch a custom activity in debug to display some fake licenses |
|
74 // see PrebuiltLicencesMaterial3Activity for more info |
|
75 Intent(this, PrebuiltLicencesMaterial3Activity::class.java) |
|
76 } else { |
|
77 Intent(this, OpenSourceLicensesActivity::class.java) |
|
78 } |
|
79 startActivity(intent) |
|
80 } |
|
81 } |
|
82 |
|
83 @Composable |
|
84 private fun Sample( |
|
85 onMaterial2Click: () -> Unit, |
|
86 onMaterial3Click: () -> Unit, |
|
87 ) { |
|
88 Surface( |
|
89 modifier = Modifier.fillMaxSize(), |
|
90 color = MaterialTheme.colorScheme.background |
|
91 ) { |
|
92 Column(Modifier.fillMaxSize()) { |
|
93 LaunchActivitySection(onMaterial2Click, onMaterial3Click) |
|
94 CustomViewer(modifier = Modifier.padding(horizontal = 16.dp)) |
|
95 } |
|
96 } |
|
97 } |
|
98 |
|
99 @Composable |
|
100 private fun LaunchActivitySection( |
|
101 onMaterial2Click: () -> Unit, |
|
102 onMaterial3Click: () -> Unit, |
|
103 modifier: Modifier = Modifier |
|
104 ) { |
|
105 Column(modifier.padding(16.dp)) { |
|
106 Text("This section launch a new activity to display licences information") |
|
107 Row( |
|
108 horizontalArrangement = Arrangement.SpaceAround, modifier = Modifier |
|
109 .fillMaxWidth() |
|
110 .padding(32.dp) |
|
111 ) { |
|
112 Material2Card(onClick = onMaterial2Click) |
|
113 Material3Card(onClick = onMaterial3Click) |
|
114 } |
|
115 } |
|
116 } |
|
117 |
|
118 |
|
119 @Composable |
|
120 @OptIn(ExperimentalMaterial3Api::class) |
|
121 private fun Material2Card( |
|
122 onClick: () -> Unit, |
|
123 modifier: Modifier = Modifier |
|
124 ) { |
|
125 Card(modifier = modifier, onClick = onClick) { |
|
126 Column(Modifier.padding(16.dp)) { |
|
127 Text("Material2 UI", style = MaterialTheme.typography.labelLarge) |
|
128 } |
|
129 } |
|
130 } |
|
131 |
|
132 @Composable |
|
133 @OptIn(ExperimentalMaterial3Api::class) |
|
134 private fun Material3Card( |
|
135 onClick: () -> Unit, |
|
136 modifier: Modifier = Modifier |
|
137 ) { |
|
138 Card(modifier = modifier, onClick = onClick) { |
|
139 Column(Modifier.padding(16.dp)) { |
|
140 Text("Material3 UI", style = MaterialTheme.typography.labelLarge) |
|
141 } |
|
142 } |
|
143 } |
|
144 |
|
145 |
|
146 @Preview(showBackground = true) |
|
147 @Composable |
|
148 fun LauncherActivitySectionPreview() { |
|
149 AboutOssTheme { |
|
150 LaunchActivitySection(onMaterial2Click = {}, onMaterial3Click = {}) |
|
151 } |
|
152 } |
|