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

Commit

Permalink
Merge pull request #1095 from lramati/master
Browse files Browse the repository at this point in the history
Version 5.5.2!
  • Loading branch information
nahojjjen authored Jan 30, 2021
2 parents 84cd2ca + 7ebd64c commit dbffaff
Show file tree
Hide file tree
Showing 192 changed files with 17,192 additions and 6,660 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Built application files
*.apk
*.aab
*.ap_

# Files for the ART/Dalvik VM
Expand Down Expand Up @@ -44,3 +45,6 @@ fabric.properties

# OS files
.DS_Store

# VS Code
.vscode
16 changes: 9 additions & 7 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ repositories {
* Apply plugins and other Gradle scripts
*/
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
//apply plugin: 'io.fabric'
apply from: '../checkstyle/checkstyle.gradle'

/**
Expand Down Expand Up @@ -71,7 +71,7 @@ android {
* Android SDK and build-tools version
* Update (both Gradle and local SDK) whenever possible
*/
compileSdkVersion 28
compileSdkVersion 30

/**
* Build configurations for APK
Expand All @@ -81,9 +81,9 @@ android {
*/
defaultConfig {
minSdkVersion 19 /*Dont change this unless you know why*/
targetSdkVersion 28 /*Dont change this unless you know why*/
versionCode 66
versionName "5.4.5"
targetSdkVersion 29 /*Dont change this unless you know why*/
versionCode 69
versionName "5.5.2"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
}
Expand Down Expand Up @@ -204,6 +204,10 @@ dependencies {
implementation 'com.android.support:palette-v7:27.1.1'
implementation project(':openCVLibrary330')

/* for devMethods.thirdparty.pokebattler, temporally set for All Builds */
// implementation 'org.json:json:20160810' //used to generate moveset list
implementation 'com.squareup.okhttp3:okhttp:3.7.0'//used to generate moveset list

/**
* Online Build Dependencies
*/
Expand All @@ -227,8 +231,6 @@ dependencies {
testImplementation 'org.mockito:mockito-core:1.10.19'
testImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
testImplementation 'org.json:json:20160810' //used to generate moveset list
testImplementation 'com.squareup.okhttp3:okhttp:3.7.0'//used to generate moveset list
}

/**
Expand Down
5 changes: 3 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@

<service
android:name=".Pokefly"
android:exported="true"/>
android:exported="true"
android:foregroundServiceType="mediaProjection"/>
<service
android:name=".updater.DownloadUpdateService"
android:exported="false"/>
Expand Down Expand Up @@ -79,4 +80,4 @@
android:theme="@style/AppTheme.NoActionBar.fullscreen"/>
</application>

</manifest>
</manifest>
3 changes: 2 additions & 1 deletion app/src/main/java/com/kamron/pogoiv/GoIVSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,8 @@ public boolean isAutoUpdateEnabled() {
}

public boolean isPokeSpamEnabled() {
return prefs.getBoolean(POKESPAM_ENABLED, false);
//return prefs.getBoolean(POKESPAM_ENABLED, false);
return false; // Disabling PokeSpam because of Beyond Update
}

public boolean shouldAutoOpenExpandedAppraise() {
Expand Down
77 changes: 51 additions & 26 deletions app/src/main/java/com/kamron/pogoiv/Pokefly.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.view.animation.AnimationUtils;
import android.view.inputmethod.InputMethodManager;
import android.widget.FrameLayout;
import android.widget.ImageView;
Expand Down Expand Up @@ -63,6 +62,8 @@

import java.io.File;
import java.lang.ref.WeakReference;
import java.util.Arrays;
import java.util.List;

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

public static final String ACTION_UPDATE_UI = "com.kamron.pogoiv.ACTION_UPDATE_UI";
private static final String ACTION_SEND_INFO = "com.kamron.pogoiv.ACTION_SEND_INFO";
public static final String ACTION_REQUEST_SCREEN_GRABBER = "com.kamron.pogoiv.ACTION_REQUEST_SCREEN_GRABBER";
private static final String ACTION_START = "com.kamron.pogoiv.ACTION_START";
private static final String ACTION_BEGIN = "com.kamron.pogoiv.ACTION_BEGIN";
public static final String ACTION_STOP = "com.kamron.pogoiv.ACTION_STOP";

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

public static Intent createBeginIntent(@NonNull Context context) {
Intent intent = new Intent(context, Pokefly.class);
intent.setAction(ACTION_BEGIN);
return intent;
}

public static Intent createNoInfoIntent() {
return new Intent(ACTION_SEND_INFO);
}

public static void populateInfoIntent(Intent intent, ScanData scanData, @NonNull Optional<String> filePath) {
intent.putExtra(KEY_SEND_INFO_NAME, scanData.getPokemonName());
intent.putExtra(KEY_SEND_INFO_TYPE, scanData.getPokemonType());
intent.putExtra(KEY_SEND_INFO_CANDY, scanData.getCandyName());
intent.putExtra(KEY_SEND_INFO_CANDY, scanData.getCandyNames().toArray());
intent.putExtra(KEY_SEND_INFO_GENDER, scanData.getPokemonGender());
intent.putExtra(KEY_SEND_INFO_HP, scanData.getPokemonHP());
intent.putExtra(KEY_SEND_INFO_CP, scanData.getPokemonCP());
Expand Down Expand Up @@ -304,34 +313,49 @@ public int onStartCommand(Intent intent, int flags, int startId) {
ivPreviewPrinter = new IVPreviewPrinter(this);
clipboardTokenHandler = new ClipboardTokenHandler(this);

if (ACTION_STOP.equals(intent.getAction())) {
if (android.os.Build.VERSION.SDK_INT >= 24) {
stopForeground(STOP_FOREGROUND_DETACH);
}
stopSelf();
goIVNotificationManager.showPausedNotification();
switch (intent.getAction()) {
case ACTION_STOP:
if (android.os.Build.VERSION.SDK_INT >= 24) {
stopForeground(STOP_FOREGROUND_DETACH);
}
stopSelf();
goIVNotificationManager.showPausedNotification();
break;
case ACTION_START:
GoIVSettings.reloadPreferences(this);
trainerLevel = intent.getIntExtra(KEY_TRAINER_LEVEL, Data.MINIMUM_TRAINER_LEVEL);

} else if (ACTION_START.equals(intent.getAction())) {
GoIVSettings.reloadPreferences(this);
trainerLevel = intent.getIntExtra(KEY_TRAINER_LEVEL, Data.MINIMUM_TRAINER_LEVEL);
setupDisplaySizeInfo();

setupDisplaySizeInfo();
createFlyingComponents();

createFlyingComponents();
goIVNotificationManager.showRunningNotification();

startedInManualScreenshotMode = GoIVSettings.getInstance(this).isManualScreenshotModeEnabled();
/* Assumes MainActivity initialized ScreenGrabber before starting this service. */
if (!startedInManualScreenshotMode) {
screen = ScreenGrabber.getInstance();
startedInManualScreenshotMode = GoIVSettings.getInstance(this).isManualScreenshotModeEnabled();
if (!startedInManualScreenshotMode) {
// Ask MainActivity to create a ScreenGrabber for us, and wait for it to finish
LocalBroadcastManager.getInstance(this)
.sendBroadcast(new Intent(ACTION_REQUEST_SCREEN_GRABBER));
} else {
appraisalManager = new AppraisalManager(null, this);
screenShotHelper = ScreenShotHelper.start(Pokefly.this);
}
break;
case ACTION_BEGIN:
try {
screen = ScreenGrabber.getInstance();
} catch (Exception e) {
// If for some reason MainActivity failed to make the ScreenGrabber, stop the service.
// In this case we delete the notification to pretend it was never there in the first place.
if (android.os.Build.VERSION.SDK_INT >= 24) {
stopForeground(STOP_FOREGROUND_REMOVE);
}
stopSelf();
}
appraisalManager = new AppraisalManager(screen, this);
screenWatcher = new ScreenWatcher(this, fractionManager, appraisalManager);
screenWatcher.watchScreen();

} else {
appraisalManager = new AppraisalManager(null, this);
screenShotHelper = ScreenShotHelper.start(Pokefly.this);
}
goIVNotificationManager.showRunningNotification();
break;
}
//We have intent data, it's possible this service will be killed and we would want to recreate it
//https://github.com/farkam135/GoIV/issues/477
Expand Down Expand Up @@ -475,7 +499,7 @@ private void createArcPointer() {
*/
public void setArcPointer(double pokeLevel) {

int index = Data.maxPokeLevelToIndex(pokeLevel);
int index = Data.levelToLevelIdx(pokeLevel);

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

String pokemonName = intent.getStringExtra(KEY_SEND_INFO_NAME);
String pokemonType = intent.getStringExtra(KEY_SEND_INFO_TYPE);
String candyName = intent.getStringExtra(KEY_SEND_INFO_CANDY);
List<String> candyNames = Arrays.asList(intent.getStringArrayExtra(KEY_SEND_INFO_CANDY));


@SuppressWarnings("unchecked") Optional<String> lScreenShotFile =
(Optional<String>) intent.getSerializableExtra(KEY_SEND_SCREENSHOT_FILE);
Expand Down Expand Up @@ -871,7 +896,7 @@ public void onReceive(Context context, Intent intent) {
new LevelRange(estimatedPokemonLevelMin, estimatedPokemonLevelMax),
pokemonName,
pokemonType,
candyName,
candyNames,
pokemonGender,
pokemonHP,
pokemonCP,
Expand Down
73 changes: 45 additions & 28 deletions app/src/main/java/com/kamron/pogoiv/activities/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,13 @@ public class MainActivity extends AppCompatActivity {
}
};

private final BroadcastReceiver screenGrabberInitializer = new BroadcastReceiver() {
@SuppressWarnings("checkstyle:EmptyCatchBlock")
@Override public void onReceive(Context context, Intent intent) {
initScreenGrabber();
}
};

private final BroadcastReceiver pokeflyStateChanged = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
Expand Down Expand Up @@ -266,11 +273,22 @@ private void updateAppBar(Class<? extends Fragment> newSectionClass) {
private void initiateUserScreenSettings() {
WindowManager windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
rawDisplayMetrics = new DisplayMetrics();
//noinspection ConstantConditions
Display display = windowManager.getDefaultDisplay();
display.getRealMetrics(rawDisplayMetrics);
}

/**
* Initializes ScreenGrabber once Pokefly has been started
*/
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void initScreenGrabber() {
// Request screen capture permissions, then, when ready, Pokefly will be started
MainFragment.updateLaunchButtonText(this, R.string.accept_screen_capture, null);
MediaProjectionManager projectionManager =
(MediaProjectionManager) getSystemService(Context.MEDIA_PROJECTION_SERVICE);
startActivityForResult(projectionManager.createScreenCaptureIntent(), SCREEN_CAPTURE_REQ_CODE);
}

/**
* Checks for any published updates if auto-updater settings is on and deletes previous updates.
*/
Expand Down Expand Up @@ -318,16 +336,11 @@ private void stopGoIV() {

@SuppressLint("NewApi")
private void startGoIV() {
startPokeFly();

boolean screenshotMode = GoIVSettings.getInstance(this).isManualScreenshotModeEnabled();
if (screenshotMode) {
startPokeFly();

} else { // Start screen capture then, when ready, Pokefly will be started
MainFragment.updateLaunchButtonText(this, R.string.accept_screen_capture, null);
MediaProjectionManager projectionManager =
(MediaProjectionManager) getSystemService(Context.MEDIA_PROJECTION_SERVICE);
//noinspection ConstantConditions
startActivityForResult(projectionManager.createScreenCaptureIntent(), SCREEN_CAPTURE_REQ_CODE);
startPoGoIfSettingOn();
}
}

Expand Down Expand Up @@ -382,11 +395,14 @@ protected void onResume() {
initRecalibrationAlertBadge();
LocalBroadcastManager.getInstance(this).registerReceiver(showUpdateDialog,
new IntentFilter(ACTION_SHOW_UPDATE_DIALOG));
LocalBroadcastManager.getInstance(this).registerReceiver(screenGrabberInitializer,
new IntentFilter(Pokefly.ACTION_REQUEST_SCREEN_GRABBER));
}

@Override
protected void onPause() {
LocalBroadcastManager.getInstance(this).unregisterReceiver(showUpdateDialog);
LocalBroadcastManager.getInstance(this).unregisterReceiver(screenGrabberInitializer);
super.onPause();
}

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

startPoGoIfSettingOn();

Intent intent = Pokefly
.createStartIntent(this, GoIVSettings.getInstance(this).getLevel());
startService(intent);
Expand Down Expand Up @@ -430,24 +444,27 @@ public void onDestroy() {
@TargetApi(Build.VERSION_CODES.M)
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == OVERLAY_PERMISSION_REQ_CODE) {
updateLaunchButtonText(false, null);
if (Settings.canDrawOverlays(this)) {
runStartButtonLogic(); // We have obtained the overlay permission: start GoIV!
}

} else if (requestCode == SCREEN_CAPTURE_REQ_CODE) {
if (resultCode == RESULT_OK) {
MediaProjectionManager projectionManager = (MediaProjectionManager) getSystemService(
Context.MEDIA_PROJECTION_SERVICE);
//noinspection ConstantConditions
MediaProjection mProjection = projectionManager.getMediaProjection(resultCode, data);
screen = ScreenGrabber.init(mProjection, rawDisplayMetrics);

startPokeFly();
} else {
switch (requestCode) {
case OVERLAY_PERMISSION_REQ_CODE:
updateLaunchButtonText(false, null);
}
if (Settings.canDrawOverlays(this)) {
runStartButtonLogic(); // We have obtained the overlay permission: start GoIV!
}
break;
case SCREEN_CAPTURE_REQ_CODE:
if (resultCode == RESULT_OK) {
MediaProjectionManager projectionManager = (MediaProjectionManager) getSystemService(
Context.MEDIA_PROJECTION_SERVICE);
MediaProjection mProjection = projectionManager.getMediaProjection(resultCode, data);
screen = ScreenGrabber.init(mProjection, rawDisplayMetrics);
startService(Pokefly.createBeginIntent(this));
} else {
updateLaunchButtonText(false, null);
}
// Launching Pokemon Go here might be a little slower, that right after starting Pokefly, but we need
// the MainActivity instance alive to answer the intent from Pokefly
startPoGoIfSettingOn();
break;
}
}

Expand Down
Loading

0 comments on commit dbffaff

Please sign in to comment.