Skip to content
This repository was archived by the owner on Jan 23, 2024. It is now read-only.

Commit dbffaff

Browse files
authored
Merge pull request #1095 from lramati/master
Version 5.5.2!
2 parents 84cd2ca + 7ebd64c commit dbffaff

File tree

192 files changed

+17192
-6660
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

192 files changed

+17192
-6660
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Built application files
22
*.apk
3+
*.aab
34
*.ap_
45

56
# Files for the ART/Dalvik VM
@@ -44,3 +45,6 @@ fabric.properties
4445

4546
# OS files
4647
.DS_Store
48+
49+
# VS Code
50+
.vscode

app/build.gradle

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ repositories {
2424
* Apply plugins and other Gradle scripts
2525
*/
2626
apply plugin: 'com.android.application'
27-
apply plugin: 'io.fabric'
27+
//apply plugin: 'io.fabric'
2828
apply from: '../checkstyle/checkstyle.gradle'
2929

3030
/**
@@ -71,7 +71,7 @@ android {
7171
* Android SDK and build-tools version
7272
* Update (both Gradle and local SDK) whenever possible
7373
*/
74-
compileSdkVersion 28
74+
compileSdkVersion 30
7575

7676
/**
7777
* Build configurations for APK
@@ -81,9 +81,9 @@ android {
8181
*/
8282
defaultConfig {
8383
minSdkVersion 19 /*Dont change this unless you know why*/
84-
targetSdkVersion 28 /*Dont change this unless you know why*/
85-
versionCode 66
86-
versionName "5.4.5"
84+
targetSdkVersion 29 /*Dont change this unless you know why*/
85+
versionCode 69
86+
versionName "5.5.2"
8787
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
8888
vectorDrawables.useSupportLibrary = true
8989
}
@@ -204,6 +204,10 @@ dependencies {
204204
implementation 'com.android.support:palette-v7:27.1.1'
205205
implementation project(':openCVLibrary330')
206206

207+
/* for devMethods.thirdparty.pokebattler, temporally set for All Builds */
208+
// implementation 'org.json:json:20160810' //used to generate moveset list
209+
implementation 'com.squareup.okhttp3:okhttp:3.7.0'//used to generate moveset list
210+
207211
/**
208212
* Online Build Dependencies
209213
*/
@@ -227,8 +231,6 @@ dependencies {
227231
testImplementation 'org.mockito:mockito-core:1.10.19'
228232
testImplementation 'com.android.support.test:runner:1.0.2'
229233
androidTestImplementation 'com.android.support.test:runner:1.0.2'
230-
testImplementation 'org.json:json:20160810' //used to generate moveset list
231-
testImplementation 'com.squareup.okhttp3:okhttp:3.7.0'//used to generate moveset list
232234
}
233235

234236
/**

app/src/main/AndroidManifest.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@
4545

4646
<service
4747
android:name=".Pokefly"
48-
android:exported="true"/>
48+
android:exported="true"
49+
android:foregroundServiceType="mediaProjection"/>
4950
<service
5051
android:name=".updater.DownloadUpdateService"
5152
android:exported="false"/>
@@ -79,4 +80,4 @@
7980
android:theme="@style/AppTheme.NoActionBar.fullscreen"/>
8081
</application>
8182

82-
</manifest>
83+
</manifest>

app/src/main/java/com/kamron/pogoiv/GoIVSettings.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,8 @@ public boolean isAutoUpdateEnabled() {
285285
}
286286

287287
public boolean isPokeSpamEnabled() {
288-
return prefs.getBoolean(POKESPAM_ENABLED, false);
288+
//return prefs.getBoolean(POKESPAM_ENABLED, false);
289+
return false; // Disabling PokeSpam because of Beyond Update
289290
}
290291

291292
public boolean shouldAutoOpenExpandedAppraise() {

app/src/main/java/com/kamron/pogoiv/Pokefly.java

Lines changed: 51 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import android.view.LayoutInflater;
2727
import android.view.View;
2828
import android.view.WindowManager;
29-
import android.view.animation.AnimationUtils;
3029
import android.view.inputmethod.InputMethodManager;
3130
import android.widget.FrameLayout;
3231
import android.widget.ImageView;
@@ -63,6 +62,8 @@
6362

6463
import java.io.File;
6564
import java.lang.ref.WeakReference;
65+
import java.util.Arrays;
66+
import java.util.List;
6667

6768
import butterknife.BindView;
6869
import butterknife.ButterKnife;
@@ -77,7 +78,9 @@ public class Pokefly extends Service {
7778

7879
public static final String ACTION_UPDATE_UI = "com.kamron.pogoiv.ACTION_UPDATE_UI";
7980
private static final String ACTION_SEND_INFO = "com.kamron.pogoiv.ACTION_SEND_INFO";
81+
public static final String ACTION_REQUEST_SCREEN_GRABBER = "com.kamron.pogoiv.ACTION_REQUEST_SCREEN_GRABBER";
8082
private static final String ACTION_START = "com.kamron.pogoiv.ACTION_START";
83+
private static final String ACTION_BEGIN = "com.kamron.pogoiv.ACTION_BEGIN";
8184
public static final String ACTION_STOP = "com.kamron.pogoiv.ACTION_STOP";
8285

8386
private static final String KEY_TRAINER_LEVEL = "key_trainer_level";
@@ -198,14 +201,20 @@ public static Intent createStartIntent(@NonNull Context context, int trainerLeve
198201
return intent;
199202
}
200203

204+
public static Intent createBeginIntent(@NonNull Context context) {
205+
Intent intent = new Intent(context, Pokefly.class);
206+
intent.setAction(ACTION_BEGIN);
207+
return intent;
208+
}
209+
201210
public static Intent createNoInfoIntent() {
202211
return new Intent(ACTION_SEND_INFO);
203212
}
204213

205214
public static void populateInfoIntent(Intent intent, ScanData scanData, @NonNull Optional<String> filePath) {
206215
intent.putExtra(KEY_SEND_INFO_NAME, scanData.getPokemonName());
207216
intent.putExtra(KEY_SEND_INFO_TYPE, scanData.getPokemonType());
208-
intent.putExtra(KEY_SEND_INFO_CANDY, scanData.getCandyName());
217+
intent.putExtra(KEY_SEND_INFO_CANDY, scanData.getCandyNames().toArray());
209218
intent.putExtra(KEY_SEND_INFO_GENDER, scanData.getPokemonGender());
210219
intent.putExtra(KEY_SEND_INFO_HP, scanData.getPokemonHP());
211220
intent.putExtra(KEY_SEND_INFO_CP, scanData.getPokemonCP());
@@ -304,34 +313,49 @@ public int onStartCommand(Intent intent, int flags, int startId) {
304313
ivPreviewPrinter = new IVPreviewPrinter(this);
305314
clipboardTokenHandler = new ClipboardTokenHandler(this);
306315

307-
if (ACTION_STOP.equals(intent.getAction())) {
308-
if (android.os.Build.VERSION.SDK_INT >= 24) {
309-
stopForeground(STOP_FOREGROUND_DETACH);
310-
}
311-
stopSelf();
312-
goIVNotificationManager.showPausedNotification();
316+
switch (intent.getAction()) {
317+
case ACTION_STOP:
318+
if (android.os.Build.VERSION.SDK_INT >= 24) {
319+
stopForeground(STOP_FOREGROUND_DETACH);
320+
}
321+
stopSelf();
322+
goIVNotificationManager.showPausedNotification();
323+
break;
324+
case ACTION_START:
325+
GoIVSettings.reloadPreferences(this);
326+
trainerLevel = intent.getIntExtra(KEY_TRAINER_LEVEL, Data.MINIMUM_TRAINER_LEVEL);
313327

314-
} else if (ACTION_START.equals(intent.getAction())) {
315-
GoIVSettings.reloadPreferences(this);
316-
trainerLevel = intent.getIntExtra(KEY_TRAINER_LEVEL, Data.MINIMUM_TRAINER_LEVEL);
328+
setupDisplaySizeInfo();
317329

318-
setupDisplaySizeInfo();
330+
createFlyingComponents();
319331

320-
createFlyingComponents();
332+
goIVNotificationManager.showRunningNotification();
321333

322-
startedInManualScreenshotMode = GoIVSettings.getInstance(this).isManualScreenshotModeEnabled();
323-
/* Assumes MainActivity initialized ScreenGrabber before starting this service. */
324-
if (!startedInManualScreenshotMode) {
325-
screen = ScreenGrabber.getInstance();
334+
startedInManualScreenshotMode = GoIVSettings.getInstance(this).isManualScreenshotModeEnabled();
335+
if (!startedInManualScreenshotMode) {
336+
// Ask MainActivity to create a ScreenGrabber for us, and wait for it to finish
337+
LocalBroadcastManager.getInstance(this)
338+
.sendBroadcast(new Intent(ACTION_REQUEST_SCREEN_GRABBER));
339+
} else {
340+
appraisalManager = new AppraisalManager(null, this);
341+
screenShotHelper = ScreenShotHelper.start(Pokefly.this);
342+
}
343+
break;
344+
case ACTION_BEGIN:
345+
try {
346+
screen = ScreenGrabber.getInstance();
347+
} catch (Exception e) {
348+
// If for some reason MainActivity failed to make the ScreenGrabber, stop the service.
349+
// In this case we delete the notification to pretend it was never there in the first place.
350+
if (android.os.Build.VERSION.SDK_INT >= 24) {
351+
stopForeground(STOP_FOREGROUND_REMOVE);
352+
}
353+
stopSelf();
354+
}
326355
appraisalManager = new AppraisalManager(screen, this);
327356
screenWatcher = new ScreenWatcher(this, fractionManager, appraisalManager);
328357
screenWatcher.watchScreen();
329-
330-
} else {
331-
appraisalManager = new AppraisalManager(null, this);
332-
screenShotHelper = ScreenShotHelper.start(Pokefly.this);
333-
}
334-
goIVNotificationManager.showRunningNotification();
358+
break;
335359
}
336360
//We have intent data, it's possible this service will be killed and we would want to recreate it
337361
//https://github.com/farkam135/GoIV/issues/477
@@ -475,7 +499,7 @@ private void createArcPointer() {
475499
*/
476500
public void setArcPointer(double pokeLevel) {
477501

478-
int index = Data.maxPokeLevelToIndex(pokeLevel);
502+
int index = Data.levelToLevelIdx(pokeLevel);
479503

480504
//If the pokemon is overleveled (Raid catch or weather modifier the arc indicator will be stuck at max)
481505
if (index >= Data.arcX.length) {
@@ -828,7 +852,8 @@ public void onReceive(Context context, Intent intent) {
828852

829853
String pokemonName = intent.getStringExtra(KEY_SEND_INFO_NAME);
830854
String pokemonType = intent.getStringExtra(KEY_SEND_INFO_TYPE);
831-
String candyName = intent.getStringExtra(KEY_SEND_INFO_CANDY);
855+
List<String> candyNames = Arrays.asList(intent.getStringArrayExtra(KEY_SEND_INFO_CANDY));
856+
832857

833858
@SuppressWarnings("unchecked") Optional<String> lScreenShotFile =
834859
(Optional<String>) intent.getSerializableExtra(KEY_SEND_SCREENSHOT_FILE);
@@ -871,7 +896,7 @@ public void onReceive(Context context, Intent intent) {
871896
new LevelRange(estimatedPokemonLevelMin, estimatedPokemonLevelMax),
872897
pokemonName,
873898
pokemonType,
874-
candyName,
899+
candyNames,
875900
pokemonGender,
876901
pokemonHP,
877902
pokemonCP,

app/src/main/java/com/kamron/pogoiv/activities/MainActivity.java

Lines changed: 45 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,13 @@ public class MainActivity extends AppCompatActivity {
9999
}
100100
};
101101

102+
private final BroadcastReceiver screenGrabberInitializer = new BroadcastReceiver() {
103+
@SuppressWarnings("checkstyle:EmptyCatchBlock")
104+
@Override public void onReceive(Context context, Intent intent) {
105+
initScreenGrabber();
106+
}
107+
};
108+
102109
private final BroadcastReceiver pokeflyStateChanged = new BroadcastReceiver() {
103110
@Override
104111
public void onReceive(Context context, Intent intent) {
@@ -266,11 +273,22 @@ private void updateAppBar(Class<? extends Fragment> newSectionClass) {
266273
private void initiateUserScreenSettings() {
267274
WindowManager windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
268275
rawDisplayMetrics = new DisplayMetrics();
269-
//noinspection ConstantConditions
270276
Display display = windowManager.getDefaultDisplay();
271277
display.getRealMetrics(rawDisplayMetrics);
272278
}
273279

280+
/**
281+
* Initializes ScreenGrabber once Pokefly has been started
282+
*/
283+
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
284+
private void initScreenGrabber() {
285+
// Request screen capture permissions, then, when ready, Pokefly will be started
286+
MainFragment.updateLaunchButtonText(this, R.string.accept_screen_capture, null);
287+
MediaProjectionManager projectionManager =
288+
(MediaProjectionManager) getSystemService(Context.MEDIA_PROJECTION_SERVICE);
289+
startActivityForResult(projectionManager.createScreenCaptureIntent(), SCREEN_CAPTURE_REQ_CODE);
290+
}
291+
274292
/**
275293
* Checks for any published updates if auto-updater settings is on and deletes previous updates.
276294
*/
@@ -318,16 +336,11 @@ private void stopGoIV() {
318336

319337
@SuppressLint("NewApi")
320338
private void startGoIV() {
339+
startPokeFly();
340+
321341
boolean screenshotMode = GoIVSettings.getInstance(this).isManualScreenshotModeEnabled();
322342
if (screenshotMode) {
323-
startPokeFly();
324-
325-
} else { // Start screen capture then, when ready, Pokefly will be started
326-
MainFragment.updateLaunchButtonText(this, R.string.accept_screen_capture, null);
327-
MediaProjectionManager projectionManager =
328-
(MediaProjectionManager) getSystemService(Context.MEDIA_PROJECTION_SERVICE);
329-
//noinspection ConstantConditions
330-
startActivityForResult(projectionManager.createScreenCaptureIntent(), SCREEN_CAPTURE_REQ_CODE);
343+
startPoGoIfSettingOn();
331344
}
332345
}
333346

@@ -382,11 +395,14 @@ protected void onResume() {
382395
initRecalibrationAlertBadge();
383396
LocalBroadcastManager.getInstance(this).registerReceiver(showUpdateDialog,
384397
new IntentFilter(ACTION_SHOW_UPDATE_DIALOG));
398+
LocalBroadcastManager.getInstance(this).registerReceiver(screenGrabberInitializer,
399+
new IntentFilter(Pokefly.ACTION_REQUEST_SCREEN_GRABBER));
385400
}
386401

387402
@Override
388403
protected void onPause() {
389404
LocalBroadcastManager.getInstance(this).unregisterReceiver(showUpdateDialog);
405+
LocalBroadcastManager.getInstance(this).unregisterReceiver(screenGrabberInitializer);
390406
super.onPause();
391407
}
392408

@@ -396,8 +412,6 @@ protected void onPause() {
396412
private void startPokeFly() {
397413
MainFragment.updateLaunchButtonText(this, R.string.main_starting, false);
398414

399-
startPoGoIfSettingOn();
400-
401415
Intent intent = Pokefly
402416
.createStartIntent(this, GoIVSettings.getInstance(this).getLevel());
403417
startService(intent);
@@ -430,24 +444,27 @@ public void onDestroy() {
430444
@TargetApi(Build.VERSION_CODES.M)
431445
@Override
432446
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
433-
if (requestCode == OVERLAY_PERMISSION_REQ_CODE) {
434-
updateLaunchButtonText(false, null);
435-
if (Settings.canDrawOverlays(this)) {
436-
runStartButtonLogic(); // We have obtained the overlay permission: start GoIV!
437-
}
438-
439-
} else if (requestCode == SCREEN_CAPTURE_REQ_CODE) {
440-
if (resultCode == RESULT_OK) {
441-
MediaProjectionManager projectionManager = (MediaProjectionManager) getSystemService(
442-
Context.MEDIA_PROJECTION_SERVICE);
443-
//noinspection ConstantConditions
444-
MediaProjection mProjection = projectionManager.getMediaProjection(resultCode, data);
445-
screen = ScreenGrabber.init(mProjection, rawDisplayMetrics);
446-
447-
startPokeFly();
448-
} else {
447+
switch (requestCode) {
448+
case OVERLAY_PERMISSION_REQ_CODE:
449449
updateLaunchButtonText(false, null);
450-
}
450+
if (Settings.canDrawOverlays(this)) {
451+
runStartButtonLogic(); // We have obtained the overlay permission: start GoIV!
452+
}
453+
break;
454+
case SCREEN_CAPTURE_REQ_CODE:
455+
if (resultCode == RESULT_OK) {
456+
MediaProjectionManager projectionManager = (MediaProjectionManager) getSystemService(
457+
Context.MEDIA_PROJECTION_SERVICE);
458+
MediaProjection mProjection = projectionManager.getMediaProjection(resultCode, data);
459+
screen = ScreenGrabber.init(mProjection, rawDisplayMetrics);
460+
startService(Pokefly.createBeginIntent(this));
461+
} else {
462+
updateLaunchButtonText(false, null);
463+
}
464+
// Launching Pokemon Go here might be a little slower, that right after starting Pokefly, but we need
465+
// the MainActivity instance alive to answer the intent from Pokefly
466+
startPoGoIfSettingOn();
467+
break;
451468
}
452469
}
453470

0 commit comments

Comments
 (0)