Skip to content

Commit

Permalink
Tart up layout and build configs so it builds.
Browse files Browse the repository at this point in the history
  • Loading branch information
IanDarwin committed Sep 22, 2023
1 parent 47f7763 commit b8130a0
Show file tree
Hide file tree
Showing 10 changed files with 105 additions and 108 deletions.
2 changes: 2 additions & 0 deletions TelephonyManager/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@
/.idea/workspace.xml
*.iml
/local.properties
app/build
.idea
4 changes: 2 additions & 2 deletions TelephonyManager/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ android {
compileSdk 32

defaultConfig {
applicationId "com.templateapplication"
applicationId "com.example.telephonymanager.TelephonyManager"
minSdk 26
targetSdk 32
versionCode 1
Expand All @@ -25,7 +25,7 @@ android {
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}
namespace 'com.templateapplication'
namespace 'com.example.telephonymanager'
}

dependencies {
Expand Down
8 changes: 4 additions & 4 deletions TelephonyManager/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.telephonymanager"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk android:minSdkVersion="10" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name">
<activity
android:name=".PhoneStateSampleActivity"
android:label="@string/app_name" >
android:name=".TelephonyManagerDemo"
android:label="@string/app_name"
android:exported='true'>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import java.util.List;

import android.Manifest;
import android.app.Activity;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.telephony.CellLocation;
import android.telephony.NeighboringCellInfo;
Expand All @@ -15,7 +17,9 @@
import android.widget.ProgressBar;
import android.widget.TextView;

public class PhoneStateSampleActivity extends Activity {
import androidx.core.app.ActivityCompat;

public class TelephonyManagerDemo extends Activity {

private static final String APP_NAME = "SignalLevelSample";
private static final int EXCELLENT_LEVEL = 75;
Expand All @@ -32,10 +36,10 @@ public class PhoneStateSampleActivity extends Activity {
private static final int INFO_DATA_DIRECTION_INDEX = 6;
private static final int INFO_DEVICE_INFO_INDEX = 7;

private static final int[] info_ids = { R.id.serviceState_info,
private static final int[] info_ids = {R.id.serviceState_info,
R.id.cellLocation_info, R.id.callState_info,
R.id.connectionState_info, R.id.signalLevel, R.id.signalLevelInfo,
R.id.dataDirection, R.id.device_info };
R.id.dataDirection, R.id.device_info};

@Override
public void onCreate(Bundle savedInstanceState) {
Expand Down Expand Up @@ -102,21 +106,21 @@ private int getDataDirectionRes(int direction) {
int resid = R.drawable.data_none;

switch (direction) {
case TelephonyManager.DATA_ACTIVITY_IN:
resid = R.drawable.data_in;
break;
case TelephonyManager.DATA_ACTIVITY_OUT:
resid = R.drawable.data_out;
break;
case TelephonyManager.DATA_ACTIVITY_INOUT:
resid = R.drawable.data_both;
break;
case TelephonyManager.DATA_ACTIVITY_NONE:
resid = R.drawable.data_none;
break;
default:
resid = R.drawable.data_none;
break;
case TelephonyManager.DATA_ACTIVITY_IN:
resid = R.drawable.data_in;
break;
case TelephonyManager.DATA_ACTIVITY_OUT:
resid = R.drawable.data_out;
break;
case TelephonyManager.DATA_ACTIVITY_INOUT:
resid = R.drawable.data_both;
break;
case TelephonyManager.DATA_ACTIVITY_NONE:
resid = R.drawable.data_none;
break;
default:
resid = R.drawable.data_none;
break;
}
return resid;
}
Expand All @@ -136,22 +140,32 @@ private void startSignalLevelListener() {

private void displayTelephonyInfo() {
TelephonyManager tm = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling
// ActivityCompat#requestPermissions
// here to request the missing permissions, and then overriding
// public void onRequestPermissionsResult(int requestCode, String[] permissions,
// int[] grantResults)
// to handle the case where the user grants the permission. See the documentation
// for ActivityCompat#requestPermissions for more details.
return;
}
GsmCellLocation loc = (GsmCellLocation) tm.getCellLocation();
// Reorganize it to do one getSomeData, logString it in pairs, with code guards
if (loc == null) {
return;
}
int cellid = loc.getCid();
int lac = loc.getLac();
String deviceid = tm.getDeviceId();
String phonenumber = tm.getLine1Number();
String softwareversion = tm.getDeviceSoftwareVersion();
String deviceid = null; // tm.getDeviceId();
String phonenumber = null; //tm.getLine1Number();
String softwareversion = null; //tm.getDeviceSoftwareVersion();
String operatorname = tm.getNetworkOperatorName();
String simcountrycode = tm.getSimCountryIso();
String simoperator = tm.getSimOperatorName();
String simserialno = tm.getSimSerialNumber();
String subscriberid = tm.getSubscriberId();
String networktype = getNetworkTypeString(tm.getNetworkType());
String simserialno = null; //tm.getSimSerialNumber();
String subscriberid = null; //tm.getSubscriberId();
String networktype = null; //getNetworkTypeString(tm.getNetworkType());
String phonetype = getPhoneTypeString(tm.getPhoneType());
logString("CellID: " + cellid);
logString("LAC: " + lac);
Expand All @@ -176,7 +190,7 @@ private void displayTelephonyInfo() {
deviceinfo += ("Subscriber ID: " + subscriberid + "\n");
deviceinfo += ("Network Type: " + networktype + "\n");
deviceinfo += ("Phone Type: " + phonetype + "\n");
List<NeighboringCellInfo> cellinfo = tm.getNeighboringCellInfo();
List<NeighboringCellInfo> cellinfo = null; //tm.getNeighboringCellInfo();
if (null != cellinfo) {
for (NeighboringCellInfo info : cellinfo) {
deviceinfo += ("\tCellID: " + info.getCid() + ", RSSI: "
Expand All @@ -189,34 +203,34 @@ private void displayTelephonyInfo() {
private String getNetworkTypeString(int type) {
String typeString = "Unknown";
switch (type) {
case TelephonyManager.NETWORK_TYPE_EDGE:
typeString = "EDGE";
break;
case TelephonyManager.NETWORK_TYPE_GPRS:
typeString = "GPRS";
break;
case TelephonyManager.NETWORK_TYPE_UMTS:
typeString = "UMTS";
break;
default:
typeString = "UNKNOWN";
break;
case TelephonyManager.NETWORK_TYPE_EDGE:
typeString = "EDGE";
break;
case TelephonyManager.NETWORK_TYPE_GPRS:
typeString = "GPRS";
break;
case TelephonyManager.NETWORK_TYPE_UMTS:
typeString = "UMTS";
break;
default:
typeString = "UNKNOWN";
break;
}
return typeString;
}

private String getPhoneTypeString(int type) {
String typeString = "Unknown";
switch (type) {
case TelephonyManager.PHONE_TYPE_GSM:
typeString = "GSM";
break;
case TelephonyManager.PHONE_TYPE_NONE:
typeString = "UNKNOWN";
break;
default:
typeString = "UNKNOWN";
break;
case TelephonyManager.PHONE_TYPE_GSM:
typeString = "GSM";
break;
case TelephonyManager.PHONE_TYPE_NONE:
typeString = "UNKNOWN";
break;
default:
typeString = "UNKNOWN";
break;
}
return typeString;
}
Expand All @@ -230,6 +244,17 @@ private int logString(String message) {
@Override
public void onCallForwardingIndicatorChanged(boolean cfi) {
Log.i(APP_NAME, "onCallForwardingIndicatorChanged " + cfi);
if (ActivityCompat.checkSelfPermission(TelephonyManagerDemo.this,
Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling
// ActivityCompat#requestPermissions
// here to request the missing permissions, and then overriding
// public void onRequestPermissionsResult(int requestCode, String[] permissions,
// int[] grantResults)
// to handle the case where the user grants the permission. See the documentation
// for ActivityCompat#requestPermissions for more details.
return;
}
super.onCallForwardingIndicatorChanged(cfi);
}

Expand Down
29 changes: 19 additions & 10 deletions TelephonyManager/app/src/main/res/layout/main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView android:text="Service State"
<TextView android:text="Service State"
android:textSize="20px"
style="@style/labelStyleRight"/>
<TextView android:id="@+id/serviceState_info"
style="@style/textStyle"/>
Expand All @@ -22,35 +23,42 @@ style="@style/textStyle"/>
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView android:text="Cell Location"
<TextView android:text="Cell Location"
android:textSize="20px"
style="@style/labelStyleRight"/>
<TextView android:id="@+id/cellLocation_info"
<TextView android:id="@+id/cellLocation_info"
android:textSize="20px"
style="@style/textStyle"/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView android:text="Call State"
<TextView android:text="Call State"
android:textSize="20px"
style="@style/labelStyleRight"/>
<TextView android:id="@+id/callState_info"
<TextView android:id="@+id/callState_info"
android:textSize="20px"
style="@style/textStyle"/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView android:text="Connection State"
<TextView android:text="Connection State"
android:textSize="20px"
style="@style/labelStyleRight"/>
<TextView android:id="@+id/connectionState_info"
<TextView android:id="@+id/connectionState_info"
android:textSize="20px"
style="@style/textStyle"/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView android:text="Signal Level"
style="@style/labelStyleRight"/>
<TextView android:text="Signal Level"
android:textSize="20px"
style="@style/labelStyleRight"/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
Expand All @@ -66,7 +74,8 @@ android:id="@+id/signalLevelInfo" style="@style/textSmallStyle"/>
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView android:text="Data"
<TextView android:text="Data"
android:textSize="20px"
style="@style/labelStyleRight"/>
<ImageView android:id="@+id/dataDirection"
style="@style/imageStyle"/>
Expand Down
4 changes: 2 additions & 2 deletions TelephonyManager/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id 'com.android.application' version '7.4.1' apply false
id 'com.android.library' version '7.4.1' apply false
id 'com.android.application' version '8.1.1' apply false
id 'com.android.library' version '8.1.1' apply false
}

task clean(type: Delete) {
Expand Down
5 changes: 3 additions & 2 deletions TelephonyManager/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

android.useAndroidX=true

android.defaults.buildfeatures.buildconfig=true
android.nonFinalResIds=true
android.nonTransitiveRClass=false
android.useAndroidX=true
2 changes: 1 addition & 1 deletion TelephonyManager/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Tue Jun 07 13:24:21 EDT 2022
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
40 changes: 0 additions & 40 deletions TelephonyManager/proguard.cfg

This file was deleted.

2 changes: 1 addition & 1 deletion TelephonyManager/settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ dependencyResolutionManagement {
mavenCentral()
}
}
rootProject.name = "TelephonyManagerDemo""
rootProject.name = "TelephonyManagerDemo"
include ':app'

0 comments on commit b8130a0

Please sign in to comment.