//
#import "TwitImageAppDelegate.h"
@interface TwitterMain : UIViewController<UIActionSheetDelegate> {
TwitImageAppDelegate *appDel;
IBOutlet UIButton *doneBtn;
IBOutlet UITextField *userNameTxt;
IBOutlet UITextField *passTxt;
IBOutlet UIImageView *imageView;
}
-(IBAction)doneBtnPress;
//////////
#import "TwitterMain.h"
#import "SHKItem.h"
#import "SHKActionSheet.h"
#import "SHKSharer.h"
#import "SHKCustomShareMenu.h"
#import "Global.h"
BOOL checkImg;
@implementation TwitterMain
@synthesize controller,popover;
- (void)viewDidLoad
{
[super viewDidLoad];
}
- (void)viewWillAppear:(BOOL)animated
{
checkImg=NO;
appDel=(TwitImageAppDelegate *)[[UIApplication sharedApplication]delegate];
[super viewWillAppear:animated];
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
}
- (void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
}
-(IBAction)doneBtnPress{
if (checkImg==NO) {
[Global showAlert:@"! Opps" message:@"First Select the Image To Upload"];
}
else{
appDel.username=userNameTxt.text;
appDel.password=passTxt.text;
SHKItem *item = [SHKItem image:imageView.image title:@"Selected Image"];
// SHKSharer *sharers;
SHKActionSheet *as = [[SHKActionSheet alloc] initWithTitle:SHKLocalizedString(@"Share")
delegate:self
cancelButtonTitle:nil
destructiveButtonTitle:nil
otherButtonTitles:nil];
as.item = [[[SHKItem alloc] init] autorelease];
as.item.shareType = SHKShareTypeImage;
as.sharers = [NSMutableArray arrayWithCapacity:0];
id class;
class = NSClassFromString(@"SHKTwitter");
[as addButtonWithTitle: [class sharerTitle]];
[as.sharers addObject:@"SHKTwitter"];
[NSClassFromString([as.sharers objectAtIndex:0]) performSelector:@selector(shareItem:) withObject:item];
}
//SHKActionSheet *actionSheet = [SHKActionSheet actionSheetForItem:item];
//[actionSheet showFromToolbar:self.navigationController.toolbar];
}
-(BOOL)textFieldShouldReturn:(UITextField *)textField{
[textField resignFirstResponder];
return YES;
}
-(IBAction)camera{
//UIImagePickerController *controller;
if (appDel.iphoneIpad==1) {
#if TARGET_IPHONE_SIMULATOR
[Global showAlert:@"Camera is not available." message:@"Not Successfull"];
#elif TARGET_OS_IPHONE
if ([UIImagePickerController isSourceTypeAvailable:
UIImagePickerControllerSourceTypeCamera])
{
controller = [[UIImagePickerController alloc] init];
controller.sourceType = UIImagePickerControllerSourceTypeCamera;
controller.delegate = self;
//picker.allowsEditing = YES;
[self presentModalViewController:controller animated:YES];
[controller release];
}
else {
[Global showAlert:@"Camera is not available." message:@"Not Successfull"];
}
#endif
}
else if(appDel.iphoneIpad==2){
controller = [[UIImagePickerController alloc] init];
self.popover = [[UIPopoverController alloc] initWithContentViewController:controller];
NSLog(@"The value of the bool is %@\n", (self.popover.popoverVisible ? @"YES" : @"NO"));
//[self dismissPopoverAnimated:YES];
if (self.popover.popoverVisible == YES) {
[self.popover dismissPopoverAnimated:YES];
[Global showAlert:@"FIRST CLOSE THE." message:@"PHOTO GALLARY"];
}
else {
if ([UIImagePickerController isSourceTypeAvailable:
UIImagePickerControllerSourceTypeCamera])
{
controller.sourceType=UIImagePickerControllerSourceTypeCamera;
[controller setDelegate:self];
[self.popover setDelegate:self];
[self.popover presentPopoverFromRect:CGRectMake(0.0, 0.0, 1200.0,1200.0)
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionAny
animated:YES];
//[self.popover presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionRight animated:YES];
}
else {
[Global showAlert:@"Camera is not available." message:@"Not Successfull"];
}
}
}
}
-(IBAction)addPhoto {
if (appDel.iphoneIpad==1) {
controller = [[UIImagePickerController alloc] init];
//[controller setMediaTypes:[NSArray arrayWithObject:kUTTypeImage]];
[controller setDelegate:self];
[self presentModalViewController:controller animated:YES];
}
else if(appDel.iphoneIpad==2){
controller = [[UIImagePickerController alloc] init];
self.popover = [[UIPopoverController alloc] initWithContentViewController:controller];
if ( self.popover.popoverVisible == YES) {
[self.popover dismissPopoverAnimated:YES];
[Global showAlert:@"FIRST CLOSE THE." message:@"PHOTO GALLARY"];
}
else {
controller.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[controller setDelegate:self];
[popover setPopoverContentSize:CGSizeMake(700.0f,300.0f)];
//self.popover= [[UIPopoverController alloc] initWithContentViewController:controller];
[self.popover setDelegate:self];
[self.popover presentPopoverFromRect:CGRectMake(0.0, 0.0, 800.0, 400.0)
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionAny
animated:YES];
}
}
}
-(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{
[[picker parentViewController] dismissModalViewControllerAnimated:YES];
[picker release];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
// savePhotoBtn.enabled=YES;
UIImage *image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
///heroImgView.image=image;
checkImg=YES;
imageView.image=image;
if (appDel.iphoneIpad==2) {
[self.popover dismissPopoverAnimated:YES];
}
[self dismissModalViewControllerAnimated:YES];
}
- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
{
UIAlertView *alert;
// Unable to save the image
if (error){
alert = [[UIAlertView alloc] initWithTitle:@"Error"
message:@"Unable to save image to Photo Album."
delegate:self cancelButtonTitle:@"Ok"
otherButtonTitles:nil];
}
else{ // All is well
alert = [[UIAlertView alloc] initWithTitle:@"Success"
message:@"Image saved to Photo Album."
delegate:self cancelButtonTitle:@"Ok"
otherButtonTitles:nil];
[alert show];
[alert release];
}
}
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Relinquish ownership any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Relinquish ownership of anything that can be recreated in viewDidLoad or on demand.
// For example: self.myOutlet = nil;
}
- (void)dealloc
{
[super dealloc];
}
@end
No comments:
Post a Comment