Skip to content

Commit

Permalink
clean up and updates to API 32.
Browse files Browse the repository at this point in the history
  • Loading branch information
JimSeker committed Apr 18, 2022
1 parent 2bbc32e commit c9524cf
Show file tree
Hide file tree
Showing 60 changed files with 611 additions and 815 deletions.
9 changes: 9 additions & 0 deletions BroadCastDemo1/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions BroadCastDemo1/app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 31
compileSdkVersion 32

defaultConfig {
applicationId "edu.cs4730.broadcastdemo1"
minSdkVersion 26
targetSdkVersion 31
targetSdkVersion 32
versionCode="1"
versionName="1.0"
}
Expand All @@ -21,6 +21,6 @@ android {

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'androidx.localbroadcastmanager:localbroadcastmanager:1.0.0'
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'androidx.localbroadcastmanager:localbroadcastmanager:1.1.0'
}
11 changes: 5 additions & 6 deletions BroadCastDemo1/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand All @@ -21,10 +20,10 @@
<receiver
android:name=".MyReceiver"
android:enabled="true"
android:exported="true" >
<intent-filter >
<action android:name="edu.cs4730.bcr.mystaticevent"/>
</intent-filter>
android:exported="true">
<intent-filter>
<action android:name="edu.cs4730.bcr.mystaticevent" />
</intent-filter>
</receiver>
</application>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
package edu.cs4730.broadcastdemo1;

import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;

import android.util.Log;
import android.view.View;

/**
* A simple demo of broadcast receiver and custom intent.
* The fragment has the code to send the broadcast.
*
* this code will register a dynamic intent-filter for Action2
* action one is static registered in the manifest file.
*
* Note, the local broadcast receiver is deprecated. Instead you should be using a viewmodel with observers.
* but it still works, so the example will continue.
*/

public class MainActivity extends AppCompatActivity {
Expand All @@ -29,14 +34,34 @@ public class MainActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.container, new MainFragment()).commit();
}

//need to initialize the variable here.
mReceiver = new MyReceiver();


//setup button to send an intent for static registered receiver.
findViewById(R.id.button1).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent i = new Intent(MainActivity.ACTION1);
i.setPackage("edu.cs4730.broadcastdemo1"); //in API 26, it must be explicit now.
//since it's registered as a global (in the manifest), use sendBroadCast
//LocalBroadcastManager.getInstance(getContext()).sendBroadcast(i);
sendBroadcast(i);
}
});

//setup button to send an intent for dynamic registered receiver, which is registered in MainActivity.
findViewById(R.id.button2).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent i = new Intent(MainActivity.ACTION2);
//since it's registered a local, use the LocalBroadcastManager.
LocalBroadcastManager.getInstance(getApplicationContext()).sendBroadcast(i);
//use this if registered as a global receiver.
//getActivity().sendBroadcast(i);
Log.v(TAG, "Should have sent the broadcast.");
}
});
}

@Override
Expand Down

This file was deleted.

22 changes: 18 additions & 4 deletions BroadCastDemo1/app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,22 @@
<FrameLayout xmlns:android="http:https://schemas.android.com/apk/res/android"
<LinearLayout xmlns:android="http:https://schemas.android.com/apk/res/android"
xmlns:tools="http:https://schemas.android.com/tools"
android:id="@+id/container"
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="edu.cs4730.broadcastdemo1.MainActivity"
tools:ignore="MergeRootFrame" />
android:orientation="vertical"
tools:context=".MainActivity">

<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Send Static intent" />

<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Send Dynamic Intent" />

</LinearLayout>

21 changes: 0 additions & 21 deletions BroadCastDemo1/app/src/main/res/layout/fragment_main.xml

This file was deleted.

10 changes: 0 additions & 10 deletions BroadCastDemo1/app/src/main/res/values-w820dp/dimens.xml

This file was deleted.

6 changes: 6 additions & 0 deletions BroadCastDemo1/app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FF4081</color>
</resources>
7 changes: 0 additions & 7 deletions BroadCastDemo1/app/src/main/res/values/dimens.xml

This file was deleted.

5 changes: 4 additions & 1 deletion BroadCastDemo1/app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.DayNight">
<style name="AppTheme" parent="Theme.AppCompat.DayNight.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>

</resources>
2 changes: 1 addition & 1 deletion BroadCastDemo1/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.0.2'
classpath 'com.android.tools.build:gradle:7.1.3'
}
}

Expand Down
2 changes: 1 addition & 1 deletion BroadCastDemo1/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\:https://services.gradle.org/distributions/gradle-7.0.2-all.zip
distributionUrl=https\:https://services.gradle.org/distributions/gradle-7.2-all.zip
17 changes: 17 additions & 0 deletions BroadCastDemo2/.idea/deploymentTargetDropDown.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 20 additions & 2 deletions BroadCastDemo2/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit c9524cf

Please sign in to comment.