Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🤖 Sync main to latest #372

Merged
merged 29 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
31b4de2
Added two snippets for showcasing how to do Masking and Clipping in C…
riggaroo Oct 2, 2024
d1e297b
🤖 Update Dependencies (#366)
compose-devrel-github-bot Oct 3, 2024
0c9024b
Add Material Carousel (#363)
riggaroo Oct 3, 2024
68fef6e
Basic menu examples (#371)
jakeroseman Oct 11, 2024
fbfd07d
Filter chip dropdown menu (#375)
JolandaVerhoef Oct 11, 2024
f67b849
Add example of date picker textfield opening picker dialog on click (…
JolandaVerhoef Oct 11, 2024
a0b94c0
Add auto advance pager snippets (#377)
jakeroseman Oct 11, 2024
591dfa5
Tooltip component examples (#373)
jakeroseman Oct 11, 2024
4baf477
Add pull to refresh snippets (#378)
JolandaVerhoef Oct 11, 2024
5545f37
Remove LaunchedEffect workaround (#379)
jakeroseman Oct 14, 2024
90b8500
Navigation drawer examples (#380)
jakeroseman Oct 14, 2024
e9116f5
Snippets for keyboard input (#368)
chikoski Oct 16, 2024
2af26d9
Snippet for animated sorted list with add/remove buttons. (#381)
jakeroseman Oct 16, 2024
514653c
Add basic segmented button examples (#383)
jakeroseman Oct 24, 2024
5ccd4a8
Adding views snippets module with Generated Preview samples (#384)
secondsun Oct 28, 2024
195bd61
Adding top bar multi selection examples (#387)
jakeroseman Oct 29, 2024
d081491
Include AppScaffold in navigation Snippet (#385)
kul3r4 Oct 31, 2024
81c1a2a
Animate image size on scroll (#390)
jakeroseman Nov 5, 2024
1da22a0
Add basic HTML text styling example (#389)
jakeroseman Nov 5, 2024
f595a0d
🤖 Update Dependencies (#391)
compose-devrel-github-bot Nov 6, 2024
f4e4987
add in predictive back snippets for NavHost and predictive back handl…
trambui09 Nov 21, 2024
515b08e
Add region tags to auto advance pager examples (#398)
jakeroseman Nov 27, 2024
fb654a9
Init Wear Tiles snippets (#400)
ithinkihaveacat Nov 27, 2024
c699e70
Create misc module, add broadcast receiver snippets (#397)
JolandaVerhoef Nov 28, 2024
6f61cb5
Add live search with FilterTextView example (#402)
jakeroseman Dec 4, 2024
0d07b08
Add single option radio button example (#401)
jakeroseman Dec 4, 2024
c79a414
update to use type safe routes (#399)
trambui09 Dec 6, 2024
273d399
Migrated relevant MotionCompose snippets into snippets (#411)
riggaroo Dec 9, 2024
e60f073
Merge remote-tracking branch 'origin/main' into latest
compose-devrel-github-bot Dec 9, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Create misc module, add broadcast receiver snippets (#397)
* Create misc module, add broadcast receiver snippets

* Apply Spotless
  • Loading branch information
JolandaVerhoef authored Nov 28, 2024
commit c699e70b7ad6df9e7982424c6e91bc4fc27f86ca
11 changes: 7 additions & 4 deletions .github/workflows/apply_spotless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,13 @@ jobs:
- name: Run spotlessApply
run: ./gradlew :compose:spotlessApply --init-script gradle/init.gradle.kts --no-configuration-cache --stacktrace

- name: Run spotlessApply for Wear
run: ./gradlew :wear:spotlessApply --init-script gradle/init.gradle.kts --no-configuration-cache --stacktrace

- name: Run spotlessApply for Misc
run: ./gradlew :misc:spotlessApply --init-script gradle/init.gradle.kts --no-configuration-cache --stacktrace

- name: Auto-commit if spotlessApply has changes
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: Apply Spotless

- name: Run spotlessApply for Wear
run: ./gradlew :wear:spotlessApply --init-script gradle/init.gradle.kts --no-configuration-cache --stacktrace
commit_message: Apply Spotless
2 changes: 2 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,5 @@ jobs:
run: ./gradlew :kotlin:build
- name: Build Wear snippets
run: ./gradlew :wear:build
- name: Build misc snippets
run: ./gradlew :misc:build
1 change: 1 addition & 0 deletions misc/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
72 changes: 72 additions & 0 deletions misc/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
plugins {
alias(libs.plugins.android.application)
alias(libs.plugins.kotlin.android)
alias(libs.plugins.ksp)
alias(libs.plugins.hilt)
alias(libs.plugins.compose.compiler)
}

android {
compileSdk = libs.versions.compileSdk.get().toInt()
namespace = "com.example.snippets"

defaultConfig {
applicationId = "com.example.snippets"
minSdk = libs.versions.minSdk.get().toInt()
targetSdk = libs.versions.targetSdk.get().toInt()
versionCode = 1
versionName = "1.0"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}

kotlin {
jvmToolchain(17)
}

buildTypes {
getByName("debug") {
signingConfig = signingConfigs.getByName("debug")
}

getByName("release") {
isMinifyEnabled = false
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro")
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
buildFeatures {
compose = true
// Disable unused AGP features
viewBinding = true
}

}
dependencies {
val composeBom = platform(libs.androidx.compose.bom)
implementation(composeBom)
androidTestImplementation(composeBom)
implementation(libs.androidx.core.ktx)
implementation(libs.androidx.activity.compose)
implementation(libs.androidx.compose.runtime)
implementation(libs.androidx.compose.foundation)
implementation(libs.androidx.compose.foundation.layout)
implementation(libs.androidx.compose.ui.util)
implementation(libs.androidx.compose.ui.tooling.preview)
implementation(libs.androidx.compose.material3)

implementation(libs.hilt.android)
implementation(libs.androidx.hilt.navigation.compose)
implementation(libs.kotlinx.serialization.json)
ksp(libs.hilt.compiler)

implementation(libs.androidx.lifecycle.runtime)
testImplementation(libs.junit)
androidTestImplementation(libs.junit)
androidTestImplementation(libs.androidx.test.core)
androidTestImplementation(libs.androidx.test.runner)
androidTestImplementation(libs.androidx.test.espresso.core)
}
File renamed without changes.
50 changes: 50 additions & 0 deletions misc/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<permission android:name="com.example.snippets.CUSTOM_PERMISSION"/>

<!--[START android_broadcast_receiver_10_manifest_permission]-->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<!--[END android_broadcast_receiver_10_manifest_permission]-->

<application
android:name=".MyApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Snippets">

<!-- [START android_broadcast_receiver_1_receiver_manifest]-->
<!-- If this receiver listens for broadcasts sent from the system or from
other apps, even other apps that you own, set android:exported to "true". -->
<receiver android:name=".MyBroadcastReceiver" android:exported="false">
<intent-filter>
<action android:name="com.example.snippets.ACTION_UPDATE_DATA" />
</intent-filter>
</receiver>
<!-- [END android_broadcast_receiver_1_receiver_manifest]-->
<!-- [START android_broadcast_receiver_11_receiver_manifest_with_permission]-->
<!-- If this receiver listens for broadcasts sent from the system or from
other apps, even other apps that you own, set android:exported to "true". -->
<receiver
android:name=".MyBroadcastReceiverWithPermission"
android:permission="android.permission.ACCESS_COARSE_LOCATION"
android:exported="true">
<intent-filter>
<action android:name="com.example.snippets.ACTION_UPDATE_DATA" />
</intent-filter>
</receiver>
<!-- [END android_broadcast_receiver_11_receiver_manifest_with_permission]-->
<activity
android:name="com.example.snippets.MainActivity"
android:exported="true"
android:theme="@style/Theme.Snippets">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
package com.example.snippets;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;

import androidx.activity.ComponentActivity;
import androidx.core.content.ContextCompat;

import java.util.Objects;

import javax.inject.Inject;

import dagger.hilt.android.qualifiers.ApplicationContext;

// Warning for reader: This file has the Java code snippets for completeness of the corresponding
// documentation page, but these snippets are not part of the actual sample. Refer to the Kotlin
// code for the actual sample.
public class BroadcastReceiverJavaSnippets {

// [START android_broadcast_receiver_2_class_java]
public static class MyBroadcastReceiver extends BroadcastReceiver {

@Inject
DataRepository dataRepository;

@Override
public void onReceive(Context context, Intent intent) {
if (Objects.equals(intent.getAction(), "com.example.snippets.ACTION_UPDATE_DATA")) {
String data = intent.getStringExtra("com.example.snippets.DATA");
// Do something with the data, for example send it to a data repository:
if (data != null) { dataRepository.updateData(data); }
}
}
}
// [END android_broadcast_receiver_2_class_java]

/** @noinspection ConstantValue, unused */
public static class BroadcastReceiverViewModel {
Context context;

public BroadcastReceiverViewModel(@ApplicationContext Context context) {
this.context = context;
}

// [START android_broadcast_receiver_3_definition_java]
MyBroadcastReceiver myBroadcastReceiver = new MyBroadcastReceiver();
// [END android_broadcast_receiver_3_definition_java]

public void registerBroadcastReceiver() {
// [START android_broadcast_receiver_4_intent_filter_java]
IntentFilter filter = new IntentFilter("com.example.snippets.ACTION_UPDATE_DATA");
// [END android_broadcast_receiver_4_intent_filter_java]
// [START android_broadcast_receiver_5_exported_java]
boolean listenToBroadcastsFromOtherApps = false;
int receiverFlags = listenToBroadcastsFromOtherApps
? ContextCompat.RECEIVER_EXPORTED
: ContextCompat.RECEIVER_NOT_EXPORTED;
// [END android_broadcast_receiver_5_exported_java]

// [START android_broadcast_receiver_6_register_java]
ContextCompat.registerReceiver(context, myBroadcastReceiver, filter, receiverFlags);
// [END android_broadcast_receiver_6_register_java]

// [START android_broadcast_receiver_12_register_with_permission_java]
ContextCompat.registerReceiver(
context, myBroadcastReceiver, filter,
android.Manifest.permission.ACCESS_COARSE_LOCATION,
null, // scheduler that defines thread, null means run on main thread
receiverFlags
);
// [END android_broadcast_receiver_12_register_with_permission_java]
}

public void unregisterBroadcastReceiver() {
context.unregisterReceiver(myBroadcastReceiver);
}

public void sendBroadcast(String newData, boolean usePermission) {
if(usePermission) {
// [START android_broadcast_receiver_8_send_java]
Intent intent = new Intent("com.example.snippets.ACTION_UPDATE_DATA");
intent.putExtra("com.example.snippets.DATA", newData);
intent.setPackage("com.example.snippets");
context.sendBroadcast(intent);
// [END android_broadcast_receiver_8_send_java]
} else {
Intent intent = new Intent("com.example.snippets.ACTION_UPDATE_DATA");
intent.putExtra("com.example.snippets.DATA", newData);
intent.setPackage("com.example.snippets");
// [START android_broadcast_receiver_9_send_with_permission_java]
context.sendBroadcast(intent, android.Manifest.permission.ACCESS_COARSE_LOCATION);
// [END android_broadcast_receiver_9_send_with_permission_java]
}
}
}

/** @noinspection InnerClassMayBeStatic*/
// [START android_broadcast_receiver_13_activity_java]
class MyActivity extends ComponentActivity {
MyBroadcastReceiver myBroadcastReceiver;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// [START_EXCLUDE]
IntentFilter filter = new IntentFilter("com.example.snippets.ACTION_UPDATE_DATA");
boolean listenToBroadcastsFromOtherApps = false;
int receiverFlags = listenToBroadcastsFromOtherApps
? ContextCompat.RECEIVER_EXPORTED
: ContextCompat.RECEIVER_NOT_EXPORTED;
// [END_EXCLUDE]
ContextCompat.registerReceiver(this, myBroadcastReceiver, filter, receiverFlags);
// Set content
}
}
// [END android_broadcast_receiver_13_activity_java]
}
Loading
Loading