Skip to content

Commit b8130a0

Browse files
committed
Tart up layout and build configs so it builds.
1 parent 47f7763 commit b8130a0

File tree

10 files changed

+105
-108
lines changed

10 files changed

+105
-108
lines changed

TelephonyManager/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@
66
/.idea/workspace.xml
77
*.iml
88
/local.properties
9+
app/build
10+
.idea

TelephonyManager/app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ android {
66
compileSdk 32
77

88
defaultConfig {
9-
applicationId "com.templateapplication"
9+
applicationId "com.example.telephonymanager.TelephonyManager"
1010
minSdk 26
1111
targetSdk 32
1212
versionCode 1
@@ -25,7 +25,7 @@ android {
2525
sourceCompatibility JavaVersion.VERSION_11
2626
targetCompatibility JavaVersion.VERSION_11
2727
}
28-
namespace 'com.templateapplication'
28+
namespace 'com.example.telephonymanager'
2929
}
3030

3131
dependencies {

TelephonyManager/app/src/main/AndroidManifest.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3-
package="com.example.telephonymanager"
43
android:versionCode="1"
54
android:versionName="1.0" >
65

7-
<uses-sdk android:minSdkVersion="10" />
86
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
97
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
8+
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
109

1110
<application
1211
android:icon="@drawable/ic_launcher"
1312
android:label="@string/app_name">
1413
<activity
15-
android:name=".PhoneStateSampleActivity"
16-
android:label="@string/app_name" >
14+
android:name=".TelephonyManagerDemo"
15+
android:label="@string/app_name"
16+
android:exported='true'>
1717
<intent-filter>
1818
<action android:name="android.intent.action.MAIN" />
1919
<category android:name="android.intent.category.LAUNCHER" />

TelephonyManager/app/src/main/java/com/example/telephonymanager/PhoneStateSampleActivity.java renamed to TelephonyManager/app/src/main/java/com/example/telephonymanager/TelephonyManagerDemo.java

Lines changed: 71 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
import java.util.List;
44

5+
import android.Manifest;
56
import android.app.Activity;
7+
import android.content.pm.PackageManager;
68
import android.os.Bundle;
79
import android.telephony.CellLocation;
810
import android.telephony.NeighboringCellInfo;
@@ -15,7 +17,9 @@
1517
import android.widget.ProgressBar;
1618
import android.widget.TextView;
1719

18-
public class PhoneStateSampleActivity extends Activity {
20+
import androidx.core.app.ActivityCompat;
21+
22+
public class TelephonyManagerDemo extends Activity {
1923

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

35-
private static final int[] info_ids = { R.id.serviceState_info,
39+
private static final int[] info_ids = {R.id.serviceState_info,
3640
R.id.cellLocation_info, R.id.callState_info,
3741
R.id.connectionState_info, R.id.signalLevel, R.id.signalLevelInfo,
38-
R.id.dataDirection, R.id.device_info };
42+
R.id.dataDirection, R.id.device_info};
3943

4044
@Override
4145
public void onCreate(Bundle savedInstanceState) {
@@ -102,21 +106,21 @@ private int getDataDirectionRes(int direction) {
102106
int resid = R.drawable.data_none;
103107

104108
switch (direction) {
105-
case TelephonyManager.DATA_ACTIVITY_IN:
106-
resid = R.drawable.data_in;
107-
break;
108-
case TelephonyManager.DATA_ACTIVITY_OUT:
109-
resid = R.drawable.data_out;
110-
break;
111-
case TelephonyManager.DATA_ACTIVITY_INOUT:
112-
resid = R.drawable.data_both;
113-
break;
114-
case TelephonyManager.DATA_ACTIVITY_NONE:
115-
resid = R.drawable.data_none;
116-
break;
117-
default:
118-
resid = R.drawable.data_none;
119-
break;
109+
case TelephonyManager.DATA_ACTIVITY_IN:
110+
resid = R.drawable.data_in;
111+
break;
112+
case TelephonyManager.DATA_ACTIVITY_OUT:
113+
resid = R.drawable.data_out;
114+
break;
115+
case TelephonyManager.DATA_ACTIVITY_INOUT:
116+
resid = R.drawable.data_both;
117+
break;
118+
case TelephonyManager.DATA_ACTIVITY_NONE:
119+
resid = R.drawable.data_none;
120+
break;
121+
default:
122+
resid = R.drawable.data_none;
123+
break;
120124
}
121125
return resid;
122126
}
@@ -136,22 +140,32 @@ private void startSignalLevelListener() {
136140

137141
private void displayTelephonyInfo() {
138142
TelephonyManager tm = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
143+
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
144+
// TODO: Consider calling
145+
// ActivityCompat#requestPermissions
146+
// here to request the missing permissions, and then overriding
147+
// public void onRequestPermissionsResult(int requestCode, String[] permissions,
148+
// int[] grantResults)
149+
// to handle the case where the user grants the permission. See the documentation
150+
// for ActivityCompat#requestPermissions for more details.
151+
return;
152+
}
139153
GsmCellLocation loc = (GsmCellLocation) tm.getCellLocation();
140154
// Reorganize it to do one getSomeData, logString it in pairs, with code guards
141155
if (loc == null) {
142156
return;
143157
}
144158
int cellid = loc.getCid();
145159
int lac = loc.getLac();
146-
String deviceid = tm.getDeviceId();
147-
String phonenumber = tm.getLine1Number();
148-
String softwareversion = tm.getDeviceSoftwareVersion();
160+
String deviceid = null; // tm.getDeviceId();
161+
String phonenumber = null; //tm.getLine1Number();
162+
String softwareversion = null; //tm.getDeviceSoftwareVersion();
149163
String operatorname = tm.getNetworkOperatorName();
150164
String simcountrycode = tm.getSimCountryIso();
151165
String simoperator = tm.getSimOperatorName();
152-
String simserialno = tm.getSimSerialNumber();
153-
String subscriberid = tm.getSubscriberId();
154-
String networktype = getNetworkTypeString(tm.getNetworkType());
166+
String simserialno = null; //tm.getSimSerialNumber();
167+
String subscriberid = null; //tm.getSubscriberId();
168+
String networktype = null; //getNetworkTypeString(tm.getNetworkType());
155169
String phonetype = getPhoneTypeString(tm.getPhoneType());
156170
logString("CellID: " + cellid);
157171
logString("LAC: " + lac);
@@ -176,7 +190,7 @@ private void displayTelephonyInfo() {
176190
deviceinfo += ("Subscriber ID: " + subscriberid + "\n");
177191
deviceinfo += ("Network Type: " + networktype + "\n");
178192
deviceinfo += ("Phone Type: " + phonetype + "\n");
179-
List<NeighboringCellInfo> cellinfo = tm.getNeighboringCellInfo();
193+
List<NeighboringCellInfo> cellinfo = null; //tm.getNeighboringCellInfo();
180194
if (null != cellinfo) {
181195
for (NeighboringCellInfo info : cellinfo) {
182196
deviceinfo += ("\tCellID: " + info.getCid() + ", RSSI: "
@@ -189,34 +203,34 @@ private void displayTelephonyInfo() {
189203
private String getNetworkTypeString(int type) {
190204
String typeString = "Unknown";
191205
switch (type) {
192-
case TelephonyManager.NETWORK_TYPE_EDGE:
193-
typeString = "EDGE";
194-
break;
195-
case TelephonyManager.NETWORK_TYPE_GPRS:
196-
typeString = "GPRS";
197-
break;
198-
case TelephonyManager.NETWORK_TYPE_UMTS:
199-
typeString = "UMTS";
200-
break;
201-
default:
202-
typeString = "UNKNOWN";
203-
break;
206+
case TelephonyManager.NETWORK_TYPE_EDGE:
207+
typeString = "EDGE";
208+
break;
209+
case TelephonyManager.NETWORK_TYPE_GPRS:
210+
typeString = "GPRS";
211+
break;
212+
case TelephonyManager.NETWORK_TYPE_UMTS:
213+
typeString = "UMTS";
214+
break;
215+
default:
216+
typeString = "UNKNOWN";
217+
break;
204218
}
205219
return typeString;
206220
}
207221

208222
private String getPhoneTypeString(int type) {
209223
String typeString = "Unknown";
210224
switch (type) {
211-
case TelephonyManager.PHONE_TYPE_GSM:
212-
typeString = "GSM";
213-
break;
214-
case TelephonyManager.PHONE_TYPE_NONE:
215-
typeString = "UNKNOWN";
216-
break;
217-
default:
218-
typeString = "UNKNOWN";
219-
break;
225+
case TelephonyManager.PHONE_TYPE_GSM:
226+
typeString = "GSM";
227+
break;
228+
case TelephonyManager.PHONE_TYPE_NONE:
229+
typeString = "UNKNOWN";
230+
break;
231+
default:
232+
typeString = "UNKNOWN";
233+
break;
220234
}
221235
return typeString;
222236
}
@@ -230,6 +244,17 @@ private int logString(String message) {
230244
@Override
231245
public void onCallForwardingIndicatorChanged(boolean cfi) {
232246
Log.i(APP_NAME, "onCallForwardingIndicatorChanged " + cfi);
247+
if (ActivityCompat.checkSelfPermission(TelephonyManagerDemo.this,
248+
Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) {
249+
// TODO: Consider calling
250+
// ActivityCompat#requestPermissions
251+
// here to request the missing permissions, and then overriding
252+
// public void onRequestPermissionsResult(int requestCode, String[] permissions,
253+
// int[] grantResults)
254+
// to handle the case where the user grants the permission. See the documentation
255+
// for ActivityCompat#requestPermissions for more details.
256+
return;
257+
}
233258
super.onCallForwardingIndicatorChanged(cfi);
234259
}
235260

TelephonyManager/app/src/main/res/layout/main.xml

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
android:layout_width="fill_parent"
1414
android:layout_height="wrap_content"
1515
android:orientation="horizontal">
16-
<TextView android:text="Service State"
16+
<TextView android:text="Service State"
17+
android:textSize="20px"
1718
style="@style/labelStyleRight"/>
1819
<TextView android:id="@+id/serviceState_info"
1920
style="@style/textStyle"/>
@@ -22,35 +23,42 @@ style="@style/textStyle"/>
2223
android:layout_width="fill_parent"
2324
android:layout_height="wrap_content"
2425
android:orientation="horizontal">
25-
<TextView android:text="Cell Location"
26+
<TextView android:text="Cell Location"
27+
android:textSize="20px"
2628
style="@style/labelStyleRight"/>
27-
<TextView android:id="@+id/cellLocation_info"
29+
<TextView android:id="@+id/cellLocation_info"
30+
android:textSize="20px"
2831
style="@style/textStyle"/>
2932
</LinearLayout>
3033
<LinearLayout
3134
android:layout_width="fill_parent"
3235
android:layout_height="wrap_content"
3336
android:orientation="horizontal">
34-
<TextView android:text="Call State"
37+
<TextView android:text="Call State"
38+
android:textSize="20px"
3539
style="@style/labelStyleRight"/>
36-
<TextView android:id="@+id/callState_info"
40+
<TextView android:id="@+id/callState_info"
41+
android:textSize="20px"
3742
style="@style/textStyle"/>
3843
</LinearLayout>
3944
<LinearLayout
4045
android:layout_width="fill_parent"
4146
android:layout_height="wrap_content"
4247
android:orientation="horizontal">
43-
<TextView android:text="Connection State"
48+
<TextView android:text="Connection State"
49+
android:textSize="20px"
4450
style="@style/labelStyleRight"/>
45-
<TextView android:id="@+id/connectionState_info"
51+
<TextView android:id="@+id/connectionState_info"
52+
android:textSize="20px"
4653
style="@style/textStyle"/>
4754
</LinearLayout>
4855
<LinearLayout
4956
android:layout_width="fill_parent"
5057
android:layout_height="wrap_content"
5158
android:orientation="horizontal">
52-
<TextView android:text="Signal Level"
53-
style="@style/labelStyleRight"/>
59+
<TextView android:text="Signal Level"
60+
android:textSize="20px"
61+
style="@style/labelStyleRight"/>
5462
<LinearLayout
5563
android:layout_width="fill_parent"
5664
android:layout_height="wrap_content"
@@ -66,7 +74,8 @@ android:id="@+id/signalLevelInfo" style="@style/textSmallStyle"/>
6674
android:layout_width="fill_parent"
6775
android:layout_height="wrap_content"
6876
android:orientation="horizontal">
69-
<TextView android:text="Data"
77+
<TextView android:text="Data"
78+
android:textSize="20px"
7079
style="@style/labelStyleRight"/>
7180
<ImageView android:id="@+id/dataDirection"
7281
style="@style/imageStyle"/>

TelephonyManager/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Top-level build file where you can add configuration options common to all sub-projects/modules.
22
plugins {
3-
id 'com.android.application' version '7.4.1' apply false
4-
id 'com.android.library' version '7.4.1' apply false
3+
id 'com.android.application' version '8.1.1' apply false
4+
id 'com.android.library' version '8.1.1' apply false
55
}
66

77
task clean(type: Delete) {

TelephonyManager/gradle.properties

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11

2-
android.useAndroidX=true
3-
2+
android.defaults.buildfeatures.buildconfig=true
3+
android.nonFinalResIds=true
4+
android.nonTransitiveRClass=false
45
android.useAndroidX=true
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#Tue Jun 07 13:24:21 EDT 2022
22
distributionBase=GRADLE_USER_HOME
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip
44
distributionPath=wrapper/dists
55
zipStorePath=wrapper/dists
66
zipStoreBase=GRADLE_USER_HOME

TelephonyManager/proguard.cfg

Lines changed: 0 additions & 40 deletions
This file was deleted.

TelephonyManager/settings.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ dependencyResolutionManagement {
1212
mavenCentral()
1313
}
1414
}
15-
rootProject.name = "TelephonyManagerDemo""
15+
rootProject.name = "TelephonyManagerDemo"
1616
include ':app'

0 commit comments

Comments
 (0)