CS185c
Chris Pollett
Sep. 22, 2010
We'll cover these first for iPhone then in the second half of the lecture talk about Android.
/* // Override to allow orientations other than the default portrait orientation. - (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation { // Return YES for supported orientations return (interfaceOrientation == UIInterfaceOrientationPortrait); } */
#import <UIKit/UIKit.h> @interface RotateExampleViewController : UIViewController { IBOutlet UIButton *button1; IBOutlet UIButton *button2; IBOutlet UIButton *button3; IBOutlet UIButton *button4; IBOutlet UIButton *button5; IBOutlet UIButton *button6; } @property (nonatomic, retain) UIButton *button1; @property (nonatomic, retain) UIButton *button2; @property (nonatomic, retain) UIButton *button3; @property (nonatomic, retain) UIButton *button4; @property (nonatomic, retain) UIButton *button5; @property (nonatomic, retain) UIButton *button6; @end
@synthesize button1; @synthesize button2; @synthesize button3; @synthesize button4; @synthesize button5; @synthesize button6; -(void)willAnimateSecondHalfOfRotationToInterfaceOrientation: (UIInterfaceOrientation)fromInterfaceOrientation duration:(NSTimeInterval)duration { UIInterfaceOrientation toOrientation = self.interfaceOrientation; [UIView beginAnimations:@"move my buttons" context:nil]; //says we'd like the switch animated; give animation block a name if(toOrientation == UIInterfaceOrientationPortrait || toOrientation == UIInterfaceOrientationPortraitUpsideDown) { button1.frame = CGRectMake(20, 20, 125, 125); button2.frame = CGRectMake(175, 20, 125, 125); button3.frame = CGRectMake(20, 168, 125, 125); button4.frame = CGRectMake(175, 168, 125, 125); button5.frame = CGRectMake(20, 315, 125, 125); button6.frame = CGRectMake(175, 315, 125, 125); } else { button1.frame = CGRectMake(20, 20, 125, 125); button2.frame = CGRectMake(20, 155, 125, 125); button3.frame = CGRectMake(177, 20, 125, 125); button4.frame = CGRectMake(177, 155, 125, 125); button5.frame = CGRectMake(328, 20, 125, 125); button6.frame = CGRectMake(328, 155, 125, 125); } [UIView commitAnimations]; // our animation clock is finished } - (void)dealloc { [button1 release]; [button2 release]; [button3 release]; [button4 release]; [button5 release]; [button6 release]; [super dealloc]; }
IBOutlet UIView *landscape; IBOutlet UIView *portrait;
#define degreesToRandians(x) (M_PI * (x)/180.0)
if(toOrientation == UIInterfaceOrientationPortrait) { self.view = self.portrait; //selects which view //next two lines set up rotation need self.view.transform = CGAffineTransformIdentity; self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(0)); // this is rect view should live in self.view.bounds = CGRectMake(0.0, 0.0, 320.0, 460.0); } else if (toOrientation == UIInterfaceOrientationLandscapeLeft) { self.view = self.landscape; self.view.transform = CGAffineTransformIdentity; self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(-90)); self.view.bounds = CGRectMake(0.0, 0.0, 460, 320); } // similar code for the other two orientations;
NSLog(@"Hello world of logging");
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if(getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) { setContentView(R.layout.main_portrait); } else { setContentView(R.layout.main_landscape); } //other code of onCreate }
Log.i("Hw1", "Main ViewCreated");
SharedPreferences myPref = getSharedPreferences("MY_APP_PREFS", Context.MODE_WORLD_WRITEABLE + Context.MODE_WORLD_READABLE); Log.i("My_Activity", "Old Some_Key" + myPref.getString("Some_Key","Key did not exist") ); //second arg is returned if key did not exist Editor myPrefEditor = myPref.edit(); myPrefEditor.putString("Some_Key", "Some Value"); myPrefEditor.commit();