Skip to content

Commit fd72ec3

Browse files
committed
🎨 Apply Spotless formatting to Java source files
Apply Google Java Format (AOSP style) formatting to all Java files: - Sort and organize imports alphabetically - Remove comments between import statements - Fix line breaks and indentation - Standardize code formatting across all bootstraps Files formatted: PythonService, PythonUtil, PythonActivity (all bootstraps), GenericBroadcastReceiver, Hardware, AssetExtract, ResourceManager, Service.tmpl.java, and launcher classes.
1 parent 843086b commit fd72ec3

File tree

17 files changed

+931
-1002
lines changed

17 files changed

+931
-1002
lines changed

pythonforandroid/bootstraps/_sdl_common/build/src/main/java/org/kivy/android/launcher/Project.java

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
11
package org.kivy.android.launcher;
22

3-
import java.io.UnsupportedEncodingException;
3+
import android.graphics.Bitmap;
4+
import android.graphics.BitmapFactory;
5+
import android.util.Log;
46
import java.io.File;
57
import java.io.FileInputStream;
8+
import java.io.UnsupportedEncodingException;
69
import java.util.Properties;
710

8-
import android.util.Log;
9-
import android.graphics.Bitmap;
10-
import android.graphics.BitmapFactory;
11-
12-
13-
/**
14-
* This represents a project we've scanned for.
15-
*/
11+
/** This represents a project we've scanned for. */
1612
public class Project {
1713

1814
public String dir = null;
@@ -30,9 +26,8 @@ static String decode(String s) {
3026
}
3127

3228
/**
33-
* Scans directory for a android.txt file. If it finds one,
34-
* and it looks valid enough, then it creates a new Project,
35-
* and returns that. Otherwise, returns null.
29+
* Scans directory for a android.txt file. If it finds one, and it looks valid enough, then it
30+
* creates a new Project, and returns that. Otherwise, returns null.
3631
*/
3732
public static Project scanDirectory(File dir) {
3833

@@ -61,7 +56,7 @@ public static Project scanDirectory(File dir) {
6156
}
6257

6358
// Make sure we're dealing with a directory.
64-
if (! dir.isDirectory()) {
59+
if (!dir.isDirectory()) {
6560
return null;
6661
}
6762

@@ -94,6 +89,5 @@ public static Project scanDirectory(File dir) {
9489
}
9590

9691
return null;
97-
9892
}
9993
}

pythonforandroid/bootstraps/_sdl_common/build/src/main/java/org/kivy/android/launcher/ProjectAdapter.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,14 @@
44
import android.view.View;
55
import android.view.ViewGroup;
66
import android.widget.ArrayAdapter;
7-
import android.widget.TextView;
87
import android.widget.ImageView;
9-
8+
import android.widget.TextView;
109
import org.renpy.android.ResourceManager;
1110

1211
public class ProjectAdapter extends ArrayAdapter<Project> {
1312

1413
private ResourceManager resourceManager;
15-
14+
1615
public ProjectAdapter(Activity context) {
1716
super(context, 0);
1817
resourceManager = new ResourceManager(context);
@@ -29,7 +28,7 @@ public View getView(int position, View convertView, ViewGroup parent) {
2928
title.setText(p.title);
3029
author.setText(p.author);
3130
icon.setImageBitmap(p.icon);
32-
33-
return v;
31+
32+
return v;
3433
}
3534
}

pythonforandroid/bootstraps/_sdl_common/build/src/main/java/org/kivy/android/launcher/ProjectChooser.java

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
11
package org.kivy.android.launcher;
22

33
import android.app.Activity;
4-
54
import android.content.Intent;
5+
import android.net.Uri;
6+
import android.os.Environment;
67
import android.view.View;
8+
import android.widget.AdapterView;
79
import android.widget.ListView;
810
import android.widget.TextView;
9-
import android.widget.AdapterView;
10-
import android.os.Environment;
11-
1211
import java.io.File;
1312
import java.util.Arrays;
14-
import android.net.Uri;
15-
1613
import org.renpy.android.ResourceManager;
1714

1815
public class ProjectChooser extends Activity implements AdapterView.OnItemClickListener {
@@ -22,8 +19,7 @@ public class ProjectChooser extends Activity implements AdapterView.OnItemClickL
2219
String urlScheme;
2320

2421
@Override
25-
public void onStart()
26-
{
22+
public void onStart() {
2723
super.onStart();
2824

2925
resourceManager = new ResourceManager(this);
@@ -55,12 +51,12 @@ public void onStart()
5551
}
5652
}
5753

58-
if (projectAdapter.getCount() != 0) {
54+
if (projectAdapter.getCount() != 0) {
5955

6056
View v = resourceManager.inflateView("project_chooser");
6157
ListView l = (ListView) resourceManager.getViewById(v, "projectList");
6258

63-
l.setAdapter(projectAdapter);
59+
l.setAdapter(projectAdapter);
6460
l.setOnItemClickListener(this);
6561

6662
setContentView(v);
@@ -70,7 +66,10 @@ public void onStart()
7066
View v = resourceManager.inflateView("project_empty");
7167
TextView emptyText = (TextView) resourceManager.getViewById(v, "emptyText");
7268

73-
emptyText.setText("No projects are available to launch. Please place a project into " + dir + " and restart this application. Press the back button to exit.");
69+
emptyText.setText(
70+
"No projects are available to launch. Please place a project into "
71+
+ dir
72+
+ " and restart this application. Press the back button to exit.");
7473

7574
setContentView(v);
7675
}
@@ -79,9 +78,7 @@ public void onStart()
7978
public void onItemClick(AdapterView parent, View view, int position, long id) {
8079
Project p = (Project) parent.getItemAtPosition(position);
8180

82-
Intent intent = new Intent(
83-
"org.kivy.LAUNCH",
84-
Uri.fromParts(urlScheme, p.dir, ""));
81+
Intent intent = new Intent("org.kivy.LAUNCH", Uri.fromParts(urlScheme, p.dir, ""));
8582

8683
intent.setClassName(getPackageName(), "org.kivy.android.PythonActivity");
8784
this.startActivity(intent);

pythonforandroid/bootstraps/common/build/src/main/java/org/kivy/android/GenericBroadcastReceiver.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package org.kivy.android;
22

33
import android.content.BroadcastReceiver;
4-
import android.content.Intent;
54
import android.content.Context;
5+
import android.content.Intent;
66

77
public class GenericBroadcastReceiver extends BroadcastReceiver {
88

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
package org.kivy.android;
22

3-
import android.content.Intent;
43
import android.content.Context;
4+
import android.content.Intent;
55

66
public interface GenericBroadcastReceiverCallback {
77
void onReceive(Context context, Intent intent);
8-
};
8+
}
9+
;

pythonforandroid/bootstraps/common/build/src/main/java/org/kivy/android/PythonService.java

Lines changed: 79 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,21 @@
11
package org.kivy.android;
22

3-
import android.os.Build;
4-
import java.lang.reflect.Method;
5-
import java.lang.reflect.InvocationTargetException;
6-
import android.app.Service;
7-
import android.os.IBinder;
8-
import android.os.Bundle;
9-
import android.content.Intent;
10-
import android.content.Context;
11-
import android.util.Log;
123
import android.app.Notification;
4+
import android.app.NotificationChannel;
5+
import android.app.NotificationManager;
136
import android.app.PendingIntent;
7+
import android.app.Service;
8+
import android.content.Context;
9+
import android.content.Intent;
10+
import android.graphics.Color;
11+
import android.os.Build;
12+
import android.os.Bundle;
13+
import android.os.IBinder;
1414
import android.os.Process;
15+
import android.util.Log;
1516
import java.io.File;
16-
17-
//imports for channel definition
18-
import android.app.NotificationManager;
19-
import android.app.NotificationChannel;
20-
import android.graphics.Color;
17+
import java.lang.reflect.InvocationTargetException;
18+
import java.lang.reflect.Method;
2119

2220
public class PythonService extends Service implements Runnable {
2321

@@ -34,7 +32,6 @@ public class PythonService extends Service implements Runnable {
3432
// Argument to pass to Python code,
3533
private String pythonServiceArgument;
3634

37-
3835
public static PythonService mService = null;
3936
private Intent startIntent = null;
4037

@@ -64,7 +61,7 @@ public int onStartCommand(Intent intent, int flags, int startId) {
6461
Log.v("python service", "service exists, do not start again");
6562
return startType();
6663
}
67-
//intent is null if OS restarts a STICKY service
64+
// intent is null if OS restarts a STICKY service
6865
if (intent == null) {
6966
Context context = getApplicationContext();
7067
intent = getThisDefaultIntent(context, "");
@@ -78,9 +75,8 @@ public int onStartCommand(Intent intent, int flags, int startId) {
7875
pythonName = extras.getString("pythonName");
7976
pythonHome = extras.getString("pythonHome");
8077
pythonPath = extras.getString("pythonPath");
81-
boolean serviceStartAsForeground = (
82-
extras.getString("serviceStartAsForeground").equals("true")
83-
);
78+
boolean serviceStartAsForeground =
79+
(extras.getString("serviceStartAsForeground").equals("true"));
8480
pythonServiceArgument = extras.getString("pythonServiceArgument");
8581
pythonThread = new Thread(this);
8682
pythonThread.start();
@@ -108,51 +104,68 @@ protected void doStartForeground(Bundle extras) {
108104
Notification notification;
109105
Context context = getApplicationContext();
110106
Intent contextIntent = new Intent(context, PythonActivity.class);
111-
PendingIntent pIntent = PendingIntent.getActivity(context, 0, contextIntent,
112-
PendingIntent.FLAG_IMMUTABLE | PendingIntent.FLAG_UPDATE_CURRENT);
113-
114-
// Unspecified icon uses default.
115-
int smallIconId = context.getApplicationInfo().icon;
116-
if (smallIconName != null) {
117-
if (!smallIconName.equals("")){
118-
int resId = getResources().getIdentifier(smallIconName, "mipmap",
119-
getPackageName());
120-
if (resId ==0) {
121-
resId = getResources().getIdentifier(smallIconName, "drawable",
122-
getPackageName());
123-
}
124-
if (resId !=0) {
125-
smallIconId = resId;
107+
PendingIntent pIntent =
108+
PendingIntent.getActivity(
109+
context,
110+
0,
111+
contextIntent,
112+
PendingIntent.FLAG_IMMUTABLE | PendingIntent.FLAG_UPDATE_CURRENT);
113+
114+
// Unspecified icon uses default.
115+
int smallIconId = context.getApplicationInfo().icon;
116+
if (smallIconName != null) {
117+
if (!smallIconName.equals("")) {
118+
int resId = getResources().getIdentifier(smallIconName, "mipmap", getPackageName());
119+
if (resId == 0) {
120+
resId =
121+
getResources()
122+
.getIdentifier(smallIconName, "drawable", getPackageName());
123+
}
124+
if (resId != 0) {
125+
smallIconId = resId;
126+
}
126127
}
127128
}
128-
}
129129

130-
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
131-
// This constructor is deprecated
132-
notification = new Notification(
133-
smallIconId, serviceTitle, System.currentTimeMillis());
130+
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
131+
// This constructor is deprecated
132+
notification = new Notification(smallIconId, serviceTitle, System.currentTimeMillis());
134133
try {
135134
// prevent using NotificationCompat, this saves 100kb on apk
136-
Method func = notification.getClass().getMethod(
137-
"setLatestEventInfo", Context.class, CharSequence.class,
138-
CharSequence.class, PendingIntent.class);
135+
Method func =
136+
notification
137+
.getClass()
138+
.getMethod(
139+
"setLatestEventInfo",
140+
Context.class,
141+
CharSequence.class,
142+
CharSequence.class,
143+
PendingIntent.class);
139144
func.invoke(notification, context, contentTitle, contentText, pIntent);
140-
} catch (NoSuchMethodException | IllegalAccessException |
141-
IllegalArgumentException | InvocationTargetException e) {
145+
} catch (NoSuchMethodException
146+
| IllegalAccessException
147+
| IllegalArgumentException
148+
| InvocationTargetException e) {
142149
}
143150
} else {
144151
// for android 8+ we need to create our own channel
145152
// https://stackoverflow.com/questions/47531742/startforeground-fail-after-upgrade-to-android-8-1
146153
String NOTIFICATION_CHANNEL_ID = "org.kivy.p4a" + getServiceId();
147154
String channelName = "Background Service" + getServiceId();
148-
NotificationChannel chan = new NotificationChannel(NOTIFICATION_CHANNEL_ID, channelName, NotificationManager.IMPORTANCE_NONE);
155+
NotificationChannel chan =
156+
new NotificationChannel(
157+
NOTIFICATION_CHANNEL_ID,
158+
channelName,
159+
NotificationManager.IMPORTANCE_NONE);
149160

150161
chan.setLightColor(Color.BLUE);
151162
chan.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE);
152-
NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
163+
NotificationManager manager =
164+
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
153165
manager.createNotificationChannel(chan);
154166

155-
Notification.Builder builder = new Notification.Builder(context, NOTIFICATION_CHANNEL_ID);
167+
Notification.Builder builder =
168+
new Notification.Builder(context, NOTIFICATION_CHANNEL_ID);
156169
builder.setContentTitle(contentTitle);
157170
builder.setContentText(contentText);
158171
builder.setContentIntent(pIntent);
@@ -174,37 +187,42 @@ public void onDestroy() {
174187
}
175188

176189
/**
177-
* Stops the task gracefully when killed.
178-
* Calling stopSelf() will trigger a onDestroy() call from the system.
190+
* Stops the task gracefully when killed. Calling stopSelf() will trigger a onDestroy() call
191+
* from the system.
179192
*/
180193
@Override
181194
public void onTaskRemoved(Intent rootIntent) {
182195
super.onTaskRemoved(rootIntent);
183-
//sticky service runtime/restart is managed by the OS. leave it running when app is closed
196+
// sticky service runtime/restart is managed by the OS. leave it running when app is closed
184197
if (startType() != START_STICKY) {
185198
stopSelf();
186199
}
187200
}
188201

189202
@Override
190-
public void run(){
191-
String app_root = getFilesDir().getAbsolutePath() + "/app";
203+
public void run() {
204+
String app_root = getFilesDir().getAbsolutePath() + "/app";
192205
File app_root_file = new File(app_root);
193-
PythonUtil.loadLibraries(app_root_file,
194-
new File(getApplicationInfo().nativeLibraryDir));
206+
PythonUtil.loadLibraries(app_root_file, new File(getApplicationInfo().nativeLibraryDir));
195207
this.mService = this;
196208
nativeStart(
197-
androidPrivate, androidArgument,
198-
serviceEntrypoint, pythonName,
199-
pythonHome, pythonPath,
200-
pythonServiceArgument);
209+
androidPrivate,
210+
androidArgument,
211+
serviceEntrypoint,
212+
pythonName,
213+
pythonHome,
214+
pythonPath,
215+
pythonServiceArgument);
201216
stopSelf();
202217
}
203218

204219
// Native part
205220
public static native void nativeStart(
206-
String androidPrivate, String androidArgument,
207-
String serviceEntrypoint, String pythonName,
208-
String pythonHome, String pythonPath,
221+
String androidPrivate,
222+
String androidArgument,
223+
String serviceEntrypoint,
224+
String pythonName,
225+
String pythonHome,
226+
String pythonPath,
209227
String pythonServiceArgument);
210228
}

0 commit comments

Comments
 (0)