forked from android/snippets
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Resources snippets * Apply Spotless --------- Co-authored-by: florina-muntenescu <[email protected]>
- Loading branch information
1 parent
6cc9fa4
commit 742fdcc
Showing
11 changed files
with
352 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
All font files are licensed under the SIL OPEN FONT LICENSE license. All other files are licensed under the Apache 2 license. | ||
|
||
|
||
SIL OPEN FONT LICENSE | ||
Version 1.1 - 26 February 2007 | ||
|
||
PREAMBLE | ||
The goals of the Open Font License (OFL) are to stimulate worldwide | ||
development of collaborative font projects, to support the font creation | ||
efforts of academic and linguistic communities, and to provide a free and | ||
open framework in which fonts may be shared and improved in partnership | ||
with others. | ||
|
||
The OFL allows the licensed fonts to be used, studied, modified and | ||
redistributed freely as long as they are not sold by themselves. The | ||
fonts, including any derivative works, can be bundled, embedded, | ||
redistributed and/or sold with any software provided that any reserved | ||
names are not used by derivative works. The fonts and derivatives, | ||
however, cannot be released under any other type of license. The | ||
requirement for fonts to remain under this license does not apply | ||
to any document created using the fonts or their derivatives. | ||
|
||
DEFINITIONS | ||
"Font Software" refers to the set of files released by the Copyright | ||
Holder(s) under this license and clearly marked as such. This may | ||
include source files, build scripts and documentation. | ||
|
||
"Reserved Font Name" refers to any names specified as such after the | ||
copyright statement(s). | ||
|
||
"Original Version" refers to the collection of Font Software components as | ||
distributed by the Copyright Holder(s). | ||
|
||
"Modified Version" refers to any derivative made by adding to, deleting, | ||
or substituting — in part or in whole — any of the components of the | ||
Original Version, by changing formats or by porting the Font Software to a | ||
new environment. | ||
|
||
"Author" refers to any designer, engineer, programmer, technical | ||
writer or other person who contributed to the Font Software. | ||
|
||
PERMISSION & CONDITIONS | ||
Permission is hereby granted, free of charge, to any person obtaining | ||
a copy of the Font Software, to use, study, copy, merge, embed, modify, | ||
redistribute, and sell modified and unmodified copies of the Font | ||
Software, subject to the following conditions: | ||
|
||
1) Neither the Font Software nor any of its individual components, | ||
in Original or Modified Versions, may be sold by itself. | ||
|
||
2) Original or Modified Versions of the Font Software may be bundled, | ||
redistributed and/or sold with any software, provided that each copy | ||
contains the above copyright notice and this license. These can be | ||
included either as stand-alone text files, human-readable headers or | ||
in the appropriate machine-readable metadata fields within text or | ||
binary files as long as those fields can be easily viewed by the user. | ||
|
||
3) No Modified Version of the Font Software may use the Reserved Font | ||
Name(s) unless explicit written permission is granted by the corresponding | ||
Copyright Holder. This restriction only applies to the primary font name as | ||
presented to the users. | ||
|
||
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font | ||
Software shall not be used to promote, endorse or advertise any | ||
Modified Version, except to acknowledge the contribution(s) of the | ||
Copyright Holder(s) and the Author(s) or with their explicit written | ||
permission. | ||
|
||
5) The Font Software, modified or unmodified, in part or in whole, | ||
must be distributed entirely under this license, and must not be | ||
distributed under any other license. The requirement for fonts to | ||
remain under this license does not apply to any document created | ||
using the Font Software. | ||
|
||
TERMINATION | ||
This license becomes null and void if any of the above conditions are | ||
not met. | ||
|
||
DISCLAIMER | ||
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT | ||
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE | ||
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL | ||
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM | ||
OTHER DEALINGS IN THE FONT SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
183 changes: 183 additions & 0 deletions
183
compose/snippets/src/main/java/com/example/compose/snippets/resources/ResourcesSnippets.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,183 @@ | ||
/* | ||
* Copyright 2023 The Android Open Source Project | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
@file:Suppress("unused") | ||
|
||
package com.example.compose.snippets.resources | ||
|
||
import androidx.compose.animation.graphics.ExperimentalAnimationGraphicsApi | ||
import androidx.compose.animation.graphics.res.animatedVectorResource | ||
import androidx.compose.animation.graphics.res.rememberAnimatedVectorPainter | ||
import androidx.compose.animation.graphics.vector.AnimatedImageVector | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.material.Divider | ||
import androidx.compose.material.Icon | ||
import androidx.compose.material.Text | ||
import androidx.compose.material.icons.Icons | ||
import androidx.compose.material.icons.rounded.Menu | ||
import androidx.compose.material3.MaterialTheme | ||
import androidx.compose.material3.Typography | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.ui.ExperimentalComposeUiApi | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.res.colorResource | ||
import androidx.compose.ui.res.dimensionResource | ||
import androidx.compose.ui.res.painterResource | ||
import androidx.compose.ui.res.pluralStringResource | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.compose.ui.text.TextStyle | ||
import androidx.compose.ui.text.font.Font | ||
import androidx.compose.ui.text.font.FontFamily | ||
import androidx.compose.ui.text.font.FontWeight | ||
import com.example.compose.snippets.R | ||
|
||
@OptIn(ExperimentalComposeUiApi::class) | ||
@Composable | ||
fun Strings() { | ||
// [START android_compose_resources_strings] | ||
// In the res/values/strings.xml file | ||
// <string name="compose">Jetpack Compose</string> | ||
|
||
// In your Compose code | ||
Text( | ||
text = stringResource(R.string.compose) | ||
) | ||
// [END android_compose_resources_strings] | ||
|
||
// [START android_compose_resources_strings_formatting] | ||
// In the res/values/strings.xml file | ||
// <string name="congratulate">Happy %1$s %2$d</string> | ||
|
||
// In your Compose code | ||
Text( | ||
text = stringResource(R.string.congratulate, "New Year", 2021) | ||
) | ||
// [END android_compose_resources_strings_formatting] | ||
|
||
val quantity = 1 | ||
// [START android_compose_resources_strings_plural] | ||
// In the res/strings.xml file | ||
// <plurals name="runtime_format"> | ||
// <item quantity="one">%1$d minute</item> | ||
// <item quantity="other">%1$d minutes</item> | ||
// </plurals> | ||
|
||
// In your Compose code | ||
Text( | ||
text = pluralStringResource( | ||
R.plurals.runtime_format, | ||
quantity, | ||
quantity | ||
) | ||
) | ||
// [END android_compose_resources_strings_plural] | ||
} | ||
|
||
@Composable | ||
fun Dimensions() { | ||
// [START android_compose_resources_dimensions] | ||
// In the res/values/dimens.xml file | ||
// <dimen name="padding_small">8dp</dimen> | ||
|
||
// In your Compose code | ||
val smallPadding = dimensionResource(R.dimen.padding_small) | ||
Text( | ||
text = "...", | ||
modifier = Modifier.padding(smallPadding) | ||
) | ||
// [END android_compose_resources_dimensions] | ||
} | ||
|
||
@Composable | ||
fun Colors() { | ||
// [START android_compose_resources_colors] | ||
// In the res/colors.xml file | ||
// <color name="purple_200">#FFBB86FC</color> | ||
|
||
// In your Compose code | ||
Divider(color = colorResource(R.color.purple_200)) | ||
// [END android_compose_resources_colors] | ||
} | ||
|
||
@Composable | ||
fun VectorAssets() { | ||
// [START android_compose_resources_vector_assets] | ||
// Files in res/drawable folders. For example: | ||
// - res/drawable-nodpi/ic_logo.xml | ||
// - res/drawable-xxhdpi/ic_logo.png | ||
|
||
// In your Compose code | ||
Icon( | ||
painter = painterResource(id = R.drawable.ic_logo), | ||
contentDescription = null // decorative element | ||
) | ||
// [END android_compose_resources_vector_assets] | ||
} | ||
|
||
@OptIn(ExperimentalAnimationGraphicsApi::class) | ||
@Composable | ||
fun AnimatedVectorDrawables() { | ||
// [START android_compose_resources_avd] | ||
// Files in res/drawable folders. For example: | ||
// - res/drawable/ic_hourglass_animated.xml | ||
|
||
// In your Compose code | ||
val image = | ||
AnimatedImageVector.animatedVectorResource(R.drawable.ic_hourglass_animated) | ||
val atEnd by remember { mutableStateOf(false) } | ||
Icon( | ||
painter = rememberAnimatedVectorPainter(image, atEnd), | ||
contentDescription = null // decorative element | ||
) | ||
// [END android_compose_resources_avd] | ||
} | ||
|
||
@Composable | ||
fun Icons() { | ||
// [START android_compose_resources_icons] | ||
Icon(Icons.Rounded.Menu, contentDescription = "Localized description") | ||
// [END android_compose_resources_icons] | ||
} | ||
|
||
// [START android_compose_resources_fonts] | ||
// Define and load the fonts of the app | ||
private val light = Font(R.font.raleway_light, FontWeight.W300) | ||
private val regular = Font(R.font.raleway_regular, FontWeight.W400) | ||
private val medium = Font(R.font.raleway_medium, FontWeight.W500) | ||
private val semibold = Font(R.font.raleway_semibold, FontWeight.W600) | ||
|
||
// Create a font family to use in TextStyles | ||
private val craneFontFamily = FontFamily(light, regular, medium, semibold) | ||
|
||
// Use the font family to define a custom typography | ||
val craneTypography = Typography( | ||
titleLarge = TextStyle( | ||
fontFamily = craneFontFamily | ||
) /* ... */ | ||
) | ||
|
||
// Pass the typography to a MaterialTheme that will create a theme using | ||
// that typography in the part of the UI hierarchy where this theme is used | ||
@Composable | ||
fun CraneTheme(content: @Composable () -> Unit) { | ||
MaterialTheme(typography = craneTypography) { | ||
content() | ||
} | ||
} | ||
// [END android_compose_resources_fonts] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<!-- | ||
~ Copyright 2019 The Android Open Source Project | ||
~ | ||
~ Licensed under the Apache License, Version 2.0 (the "License"); | ||
~ you may not use this file except in compliance with the License. | ||
~ You may obtain a copy of the License at | ||
~ | ||
~ http://www.apache.org/licenses/LICENSE-2.0 | ||
~ | ||
~ Unless required by applicable law or agreed to in writing, software | ||
~ distributed under the License is distributed on an "AS IS" BASIS, | ||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
~ See the License for the specific language governing permissions and | ||
~ limitations under the License. | ||
~ | ||
--> | ||
<vector android:height="24dp" android:tint="#000000" | ||
android:viewportHeight="24" android:viewportWidth="24" | ||
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<path android:fillColor="#FF000000" android:pathData="M17.6,11.48 L19.44,8.3a0.63,0.63 0,0 0,-1.09 -0.63l-1.88,3.24a11.43,11.43 0,0 0,-8.94 0L5.65,7.67a0.63,0.63 0,0 0,-1.09 0.63L6.4,11.48A10.81,10.81 0,0 0,1 20L23,20A10.81,10.81 0,0 0,17.6 11.48ZM7,17.25A1.25,1.25 0,1 1,8.25 16,1.25 1.25,0 0,1 7,17.25ZM17,17.25A1.25,1.25 0,1 1,18.25 16,1.25 1.25,0 0,1 17,17.25Z"/> | ||
</vector> |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- | ||
~ Copyright 2023 The Android Open Source Project | ||
~ | ||
~ Licensed under the Apache License, Version 2.0 (the "License"); | ||
~ you may not use this file except in compliance with the License. | ||
~ You may obtain a copy of the License at | ||
~ | ||
~ http://www.apache.org/licenses/LICENSE-2.0 | ||
~ | ||
~ Unless required by applicable law or agreed to in writing, software | ||
~ distributed under the License is distributed on an "AS IS" BASIS, | ||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
~ See the License for the specific language governing permissions and | ||
~ limitations under the License. | ||
~ | ||
--> | ||
<resources> | ||
<dimen name="padding_small">8dp</dimen> | ||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters