ANDROID
You can use the Instant-position analysis feature of Analyze This from your own Chess App! All you need to do is invoke Analyze This and pass additional Intent extras.
public static final String PKG_ANALYZE_THIS_FREE
= "com.pereira.analysis";
public static final String PKG_ANALYZE_THIS_PAID
= "com.pereira.analysis.paid";
public static final String ANALYZE_THIS_ACTIVITY
= "com.pereira.analysis.ui.BoardActivity";
public static final String KEY_FEN = "KEY_FEN";
//default to free version,
//but check below if paid version is installed
String analyzeThisPackageName = PKG_ANALYZE_THIS_FREE;
if (isInstalled(this, if (isInstalled(this, PKG_ANALYZE_THIS_PAID)) {
//paid version is installed, so use it!
analyzeThisPackageName = PKG_ANALYZE_THIS_PAID;
}
Intent intent = new Intent();//send the "fen" string from your program
intent.putExtra(KEY_FEN, fen);
Intent intent = new Intent();
try {
startActivity(intent);
} catch (ActivityNotFoundException e) {
//TODO neither Free nor Paid version of Analyze This is installed,so show message to the user to install the App from the Play store
}
//Method to check if the given package is installed on the device
public static boolean isInstalled(Context context, String packageName) {
boolean installed = true;
try {
PackageInfo pinfo =context.getPackageManager().getPackageInfo(packageName, 0);
} catch (NameNotFoundException e) {
installed = false;
}
return installed;
}
//complete pgn text
intent.putExtra(android.content.Intent.EXTRA_TEXT, pgn);
ComponentName name = new ComponentName(analyzeThisPackageName,
ANALYZE_THIS_ACTIVITY);
//plyNum (half-move) at which to start analyzing
intent.putExtra(KEY_PLY_NUM, plyNum);
intent.setComponent(name);
//Integer value, where 0="Aqua", 1="Blue", 2="Brown", 3="Gray",
4="Green" , 5="Fritz", 6="Sky Blue"
intent.putExtra("KEY_COLOR", 0);
intent.putExtra("KEY_FLIPPED", true);
//set the component
ComponentName name = new ComponentName(analyzeThisPackageName,
ANALYZE_THIS_ACTIVITY);
intent.setComponent(name);
public static final String KEY_PLY_NUM = "KEY_PLY_NUM";
Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
intent.setType("application/x-chess-pgn");
try {
startActivity(intent);
} catch (ActivityNotFoundException e) {
//TODO neither Free nor Paid version of Analyze This is installed,
so show message to the user to install the App from the Play store
}
static NSString *kPasteboardName = @"pgnPasteBoard";
//MUST – The pgn string that should be sent to Analyze This.
Currently the App only accepts a single game in pgn string format
static NSString *kPgnKey = @"pgn";
//OPTIONAL - the position at given ply which Analyze This will jump to
static NSString *kPlyKey = @"ply";
//OPTIONAL – if Analyze This should immediately start analyzing the position.
Default -
static NSString *kAutoEngineKey = @"autoengine";
//OPTIONAL - Integer value where 1=”Aqua”, 2=”Blue”, 3=”Brown”,
4=”Gray”, 5=”Green”, 6=”Fritz” (starts from 1 not 0)
static NSString *kColorIndex = @"colorIndex";
//OPTIONAL - whether Analyze This should flip the board [true|false]
static NSString *kFlipped = @"boardFlip";
- (void)analyzeTapped {
NSInteger colorIndex = 1; // ex. Aqua board
BOOL isFlip = false;
NSNumber *currentPly;
// get pgn string from your app
NSString* pgnStr;
NSString *customURL = [NSString
stringWithFormat:@"apxchesspgn://?%@=%@",kPgnKey,
kPasteboardName]; // configure the url
customURL = [customURL stringByAppendingString:
[NSString stringWithFormat:@"&%@=%@",
kPlyKey, currentPly]];
//plyNum (half-move) at which to start analysing
customURL = [customURL stringByAppendingString:
[NSString stringWithFormat:@"&%@=%@",
kAutoEngineKey, @(true)]];
// start engine when Analyze This loads
customURL = [customURL stringByAppendingString:
[NSString stringWithFormat:@"&%@=%ld",
kColorIndex, (long)colorIndex]];
// colour of your choice
customURL = [customURL stringByAppendingString:
[NSString stringWithFormat:@"&%@=%d",
kFlipped, isFlip]];
// flipped bool
// create a UIPasteboard with name “pgnPasteBoard”
UIPasteboard *pasteBoard =
[UIPasteboard pasteboardWithName:kPasteboardName
create:true];
// set pin string to paste Board
[pasteBoard setString:pgnStr];
//if the url opens, it means Analyze This is installed else show the
//user alert to install Analyze This
if ([[UIApplication sharedApplication]
canOpenURL:[NSURL URLWithString:customURL]]) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:customURL]];
} else {
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@"Install Analyze This"
message:@"Analyze this game with a powerful Chess engine!
Its free.
Would you like to install it now?"
delegate:self
cancelButtonTitle:nil
otherButtonTitles:@"Install", @"Cancel", nil];
[alert show];
}
}
#pragma mark - UIAlertView Delegate
//Handle button clicks
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:
(NSInteger)buttonIndex
{
switch (buttonIndex) {
case 0:
//install
NSLog(@"Install");
[self installAnalyze];
break;
case 1:
//Do nothing // cancel button
NSLog(@"Do nothing");
break;
}
}
- (void)installAnalyze{
// Initialize Product View Controller
SKStoreProductViewController *storeProductViewController =
[[SKStoreProductViewController alloc] init];
// Configure View Controller
[storeProductViewController setDelegate:self];
[storeProductViewController loadProductWithParameters:
@{SKStoreProductParameterITunesItemIdentifier : @1090863537}
completionBlock:^(BOOL result, NSError *error) {
if (error) {
NSLog(@"Error %@ with User Info %@.", error, [error userInfo]);
} else {
// Present Store Product View Controller
// [self presentViewController:storeProductViewController
animated:YES completion:nil];
}
}];
[self presentViewController:storeProductViewController
animated:YES completion:nil];
}