Commit f975da36 authored by Christophe Geuzaine's avatar Christophe Geuzaine

replace last instances of deprecated UIAlertView with UIAlertController

parent b28c99de
Pipeline #1654 passed with stage
in 63 minutes 23 seconds
#import <UIKit/UIKit.h>
#import "EAGLView.h"
@interface UIErrorAlertView : UIAlertView
@end
@interface ModelViewController : UIViewController <UISplitViewControllerDelegate, UIAlertViewDelegate>
@interface ModelViewController : UIViewController <UISplitViewControllerDelegate>
{
@private
double scaleFactor;
UIBarButtonItem *_runStopButton, *_playButton, *_stopButton;
UIErrorAlertView *_errorAlert;
NSTimer *_animation;
}
......
......@@ -8,14 +8,6 @@
#import "AppDelegate.h"
@implementation UIErrorAlertView
-(void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex animated:(BOOL)animated
{
if(buttonIndex == 0) [super dismissWithClickedButtonIndex:buttonIndex animated:animated];
}
@end
@interface ModelViewController ()
- (void)configureView;
@end
......@@ -133,6 +125,8 @@
- (void)compute
{
AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
appDelegate->compute = YES;
[_runStopButton setAction:@selector(stop)];
[_runStopButton setTitle:@"Stop"];
[_progressLabel setText:@""];
......@@ -140,10 +134,7 @@
[_progressIndicator setHidden:NO];
[_progressIndicator startAnimating];
[[UIApplication sharedApplication] cancelAllLocalNotifications];
AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
appDelegate->compute = YES;
dispatch_queue_t queue = dispatch_queue_create("org.geuz.onelab", NULL);
dispatch_async(queue, ^{
dispatch_async(dispatch_get_global_queue(QOS_CLASS_USER_INITIATED, 0), ^{
onelab_cb("compute");
dispatch_async(dispatch_get_main_queue(), ^{
AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
......@@ -243,23 +234,28 @@
- (void) showModelsList
{
if(((AppDelegate *)[UIApplication sharedApplication].delegate)->compute) {
UIAlertView *alert;
alert = [[UIAlertView alloc] initWithTitle:@"Can't show the model list"
message:@"The computation has to complete before you can select another model."
delegate:nil
cancelButtonTitle:@"Ok"
otherButtonTitles:nil, nil];
[alert show];
AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
if(appDelegate->compute) {
UIAlertController *alert =
[UIAlertController
alertControllerWithTitle:@"Cannot show model list"
message:@"Computation has to complete before a new model can be selected"
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *dismissButton =
[UIAlertAction actionWithTitle:@"Dismiss"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) { }];
[alert addAction:dismissButton];
[self presentViewController:alert animated:YES completion:nil];
return;
}
if([[UIDevice currentDevice].model isEqualToString:@"iPad"] ||
[[UIDevice currentDevice].model isEqualToString:@"iPad Simulator"]){
AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
[UIView transitionWithView:appDelegate.window
duration:0.5
options:UIViewAnimationOptionTransitionFlipFromRight
animations:^{ appDelegate.window.rootViewController = appDelegate.modelListController; }
animations:^{
appDelegate.window.rootViewController = appDelegate.modelListController; }
completion:nil];
}
[self.navigationController popToRootViewControllerAnimated:YES];
......@@ -328,15 +324,21 @@ void messageFromCpp (void *self, std::string level, std::string msg)
-(void)showError:(NSString *)msg
{
// only show first error
if(_errorAlert != nil && _errorAlert.visible) return;
// remove document path from error message
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *docPath = [[paths objectAtIndex:0] stringByAppendingString:@"/"];
NSString *str = [msg stringByReplacingOccurrencesOfString:docPath withString:@""];
_errorAlert = [[UIErrorAlertView alloc] initWithTitle:@"Error" message:str delegate:self
cancelButtonTitle:@"Dismiss" otherButtonTitles:nil, nil];
[_errorAlert show];
UIAlertController *alert =
[UIAlertController
alertControllerWithTitle:@"Error"
message:str
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *dismissButton =
[UIAlertAction actionWithTitle:@"Dismiss"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) { }];
[alert addAction:dismissButton];
[self presentViewController:alert animated:YES completion:nil];
}
-(void)handleProgressIndicatorTap:(id)sender
......@@ -379,9 +381,10 @@ void getBitmap(void *self, const char *text, int textsize, unsigned char **map,
NSUInteger bytesPerPixel = 4;
NSUInteger bytesPerRow = bytesPerPixel * *width;
NSUInteger bitsPerComponent = 8;
CGContextRef context = CGBitmapContextCreate(rawData, *width, *height,
bitsPerComponent, bytesPerRow, colorSpace,
kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big);
CGContextRef context = CGBitmapContextCreate
(rawData, *width, *height,
bitsPerComponent, bytesPerRow, colorSpace,
kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big);
CGColorSpaceRelease(colorSpace);
CGContextDrawImage(context, CGRectMake(0, 0, *width, *height), bitmap);
......
......@@ -85,31 +85,37 @@
std::vector<onelab::number> number;
onelab::server::instance()->get(number, [name UTF8String]);
if(number.size() && !number[0].getReadOnly()){
NSLog(@"Manual edit of parameter '%s' with value '%g'", number[0].getName().c_str(),
number[0].getValue());
UIAlertView *alertView =
[[UIAlertView alloc] initWithTitle:[Utils getStringFromCString:number[0].getShortName().c_str()]
message:name delegate:self cancelButtonTitle:@"Cancel"
otherButtonTitles:@"Ok", nil];
alertView.alertViewStyle = UIAlertViewStylePlainTextInput;
[alertView textFieldAtIndex:0].text = [NSString stringWithFormat:@"%g", number[0].getValue()];
[alertView show];
}
}
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSLog(@"%@ -> %@", [alertView message], [alertView textFieldAtIndex:0].text);
std::vector<onelab::number> number;
onelab::server::instance()->get(number, [[alertView message] UTF8String]);
if(number.size()){
double value = [[alertView textFieldAtIndex:0].text doubleValue];
number[0].setValue(value);
onelab::server::instance()->set(number[0]);
if(onelab_cb("check") > 0){
[[NSNotificationCenter defaultCenter] postNotificationName:@"requestRender" object:nil];
[[NSNotificationCenter defaultCenter] postNotificationName:@"refreshParameters" object:nil];
}
UIAlertController * alertController =
[UIAlertController alertControllerWithTitle:@"Edit parameter"
message:[Utils getStringFromCString:number[0].getShortName().c_str()]
preferredStyle:UIAlertControllerStyleAlert];
[alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {
textField.text = name;
[textField setEnabled:FALSE];
}];
[alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {
textField.text = [NSString stringWithFormat:@"%g", number[0].getValue()];
}];
[alertController addAction:[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault
handler:^(UIAlertAction *action) {
NSArray * textfields = alertController.textFields;
UITextField * namefield = textfields[0];
UITextField * valuefield = textfields[1];
std::vector<onelab::number> number;
onelab::server::instance()->get(number, [namefield.text UTF8String]);
if(number.size()){
double value = [valuefield.text doubleValue];
number[0].setValue(value);
onelab::server::instance()->set(number[0]);
if(onelab_cb("check") > 0){
[[NSNotificationCenter defaultCenter] postNotificationName:@"requestRender" object:nil];
[[NSNotificationCenter defaultCenter] postNotificationName:@"refreshParameters" object:nil];
}
}
}]];
[alertController addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleDefault
handler:^(UIAlertAction *action) { }]];
[self presentViewController:alertController animated:YES completion:nil];
}
}
......@@ -317,12 +323,17 @@ NSInteger compareParameter(id p1, id p2, void *context)
- (void)resetParameters:(id)sender
{
if(((AppDelegate *)[UIApplication sharedApplication].delegate)->compute) {
UIAlertView *alert;
alert = [[UIAlertView alloc]
initWithTitle:@"Can't reset model parameters"
message:@"The computation has to complete before you can reset the parameters."
delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
[alert show];
UIAlertController *alert =
[UIAlertController
alertControllerWithTitle:@"Cannot reset model parameters"
message:@"Computation has to complete before parameters can be reset"
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *dismissButton =
[UIAlertAction actionWithTitle:@"Dismiss"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) { }];
[alert addAction:dismissButton];
[self presentViewController:alert animated:YES completion:nil];
return;
}
onelab_cb("reset");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment