Skip to content

Commit

Permalink
updated to api 34, viewbinding, plus permissions fixes too.
Browse files Browse the repository at this point in the history
  • Loading branch information
JimSeker committed Oct 17, 2023
1 parent 36bf7b9 commit b75ce17
Show file tree
Hide file tree
Showing 46 changed files with 244 additions and 109 deletions.
2 changes: 1 addition & 1 deletion BroadCastDemo1/.idea/compiler.xml

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

2 changes: 1 addition & 1 deletion BroadCastDemo1/.idea/gradle.xml

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

8 changes: 5 additions & 3 deletions BroadCastDemo1/.idea/misc.xml

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

12 changes: 8 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 32
compileSdk 34

defaultConfig {
applicationId "edu.cs4730.broadcastdemo1"
minSdkVersion 26
targetSdkVersion 32
minSdkVersion 28
targetSdk 34
versionCode="1"
versionName="1.0"
}
Expand All @@ -17,10 +17,14 @@ android {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
buildFeatures {
viewBinding = true
}
namespace 'edu.cs4730.broadcastdemo1'
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.5.1'
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'androidx.localbroadcastmanager:localbroadcastmanager:1.1.0'
}
3 changes: 1 addition & 2 deletions BroadCastDemo1/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http:https://schemas.android.com/apk/res/android"
package="edu.cs4730.broadcastdemo1">
<manifest xmlns:android="http:https://schemas.android.com/apk/res/android">

<application
android:allowBackup="true"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,21 @@
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.util.Log;
import android.view.View;

import androidx.appcompat.app.AppCompatActivity;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;

import android.util.Log;
import android.view.View;
import edu.cs4730.broadcastdemo1.databinding.ActivityMainBinding;

/**
* A simple demo of broadcast receiver and custom intent.
* The fragment has the code to send the broadcast.
*
* <p>
* this code will register a dynamic intent-filter for Action2
* action one is static registered in the manifest file.
*
* <p>
* 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.
*/
Expand All @@ -29,17 +31,20 @@ public class MainActivity extends AppCompatActivity {
String TAG = "MainActivity";

MyReceiver mReceiver;
ActivityMainBinding binding;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
binding = ActivityMainBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());

//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() {
binding.button1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent i = new Intent(MainActivity.ACTION1);
Expand All @@ -51,7 +56,7 @@ public void onClick(View view) {
});

//setup button to send an intent for dynamic registered receiver, which is registered in MainActivity.
findViewById(R.id.button2).setOnClickListener(new View.OnClickListener() {
binding.button2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent i = new Intent(MainActivity.ACTION2);
Expand Down Expand Up @@ -82,7 +87,6 @@ protected void onPause() { //or onDestory()
//unregisterReceiver(mReceiver);
Log.v(TAG, "receiver should be unregistered");
super.onPause();

}

}
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.1.3'
classpath 'com.android.tools.build:gradle:8.1.2'
}
}

Expand Down
3 changes: 3 additions & 0 deletions BroadCastDemo1/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
android.defaults.buildfeatures.buildconfig=true
android.enableJetifier=true
android.nonFinalResIds=false
android.nonTransitiveRClass=false
android.useAndroidX=true
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.2-all.zip
distributionUrl=https\:https://services.gradle.org/distributions/gradle-8.0-all.zip
2 changes: 1 addition & 1 deletion BroadCastDemo2/.idea/compiler.xml

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

3 changes: 1 addition & 2 deletions BroadCastDemo2/.idea/gradle.xml

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

8 changes: 5 additions & 3 deletions BroadCastDemo2/.idea/misc.xml

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

14 changes: 9 additions & 5 deletions BroadCastDemo2/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
compileSdk 34

defaultConfig {
applicationId "edu.cs4730.broadcastdemo2"
minSdkVersion 26
targetSdkVersion 31
minSdkVersion 28
targetSdk 34
versionCode = "1"
versionName = "1.0"
}
Expand All @@ -17,10 +17,14 @@ android {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
buildFeatures {
viewBinding = true
}
namespace 'edu.cs4730.broadcastdemo2'
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.0'
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
}
7 changes: 2 additions & 5 deletions BroadCastDemo2/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http:https://schemas.android.com/apk/res/android"
package="edu.cs4730.broadcastdemo2">

<manifest xmlns:android="http:https://schemas.android.com/apk/res/android">

<application
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 Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

import androidx.appcompat.app.AppCompatActivity;

import edu.cs4730.broadcastdemo2.databinding.ActivityMainBinding;

/**
* this app will need to be run on emulator to test the varying pieces
* unless you can charge and discharge your battery very quickly.
Expand All @@ -23,15 +25,16 @@
* a normal app can know if it is charging or on battery, but not the level of the battery.
*/
public class MainActivity extends AppCompatActivity {
TextView logger;
ActivityMainBinding binding;
MyReceiver mReceiver = new MyReceiver();
String TAG = "MainActivity";

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
logger = findViewById(R.id.textView1);

binding = ActivityMainBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());

//manual check.
IntentFilter ifilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
Expand All @@ -45,15 +48,15 @@ protected void onCreate(Bundle savedInstanceState) {
float batteryPct = level * 100 / (float)scale;

if (isCharging) {
logger.setText("status is Charging");
binding.logger.setText("status is Charging");
// How are we charging?
int chargePlug = batteryStatus.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1);
boolean usbCharge = chargePlug == BatteryManager.BATTERY_PLUGGED_USB;
if (usbCharge) logger.append("\n via the usb chargerbattery at "+ batteryPct);
if (usbCharge) binding.logger.append("\n via the usb chargerbattery at "+ batteryPct);
boolean acCharge = chargePlug == BatteryManager.BATTERY_PLUGGED_AC;
if (acCharge) logger.append("\n via the AC chargerbattery at "+ batteryPct);
if (acCharge) binding.logger.append("\n via the AC chargerbattery at "+ batteryPct);
} else {
logger.setText("status is not Charging. battery at "+ batteryPct);
binding.logger.setText("status is not Charging. battery at "+ batteryPct);
}

}
Expand Down Expand Up @@ -123,7 +126,7 @@ public void onReceive(Context context, Intent intent) {
mStatus = 4;
Log.v("myReceiver", "ac off");
}
logger.setText("status is " + mStatus + info);
binding.logger.setText("status is " + mStatus + info);
}
}

Expand Down
2 changes: 1 addition & 1 deletion BroadCastDemo2/app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
android:orientation="vertical">

<TextView
android:id="@+id/textView1"
android:id="@+id/logger"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginBottom="8dp"
Expand Down
2 changes: 1 addition & 1 deletion BroadCastDemo2/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.1.3'
classpath 'com.android.tools.build:gradle:8.1.2'
}
}

Expand Down
3 changes: 3 additions & 0 deletions BroadCastDemo2/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
android.defaults.buildfeatures.buildconfig=true
android.enableJetifier=true
android.nonFinalResIds=false
android.nonTransitiveRClass=false
android.useAndroidX=true
2 changes: 1 addition & 1 deletion BroadCastDemo2/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.2-all.zip
distributionUrl=https\:https://services.gradle.org/distributions/gradle-8.0-all.zip
Loading

0 comments on commit b75ce17

Please sign in to comment.