CS175
Chris Pollett
Nov. 10, 2014
Consider the following code which might be placed in a helper class:
public static String readTextFileFromRawResource(final Context context, final int resourceId) { final InputStream inputStream = context.getResources().openRawResource( resourceId); final InputStreamReader inputStreamReader = new InputStreamReader( inputStream); final BufferedReader bufferedReader = new BufferedReader( inputStreamReader); String nextLine; final StringBuilder body = new StringBuilder(); try { while ((nextLine = bufferedReader.readLine()) != null) { body.append(nextLine); body.append('\n'); } } catch (IOException e) { return null; } return body.toString(); }
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
telnet localhost 5554
geo fix -10.5 23.4
locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
protected void onResume() { /* * Add LocationListener and request updates every 1000ms or 10m * Notice in this case we are saying this Activity implements LocationListener */ locationManager.requestLocationUpdates( LocationManager.GPS_PROVIDER, 1000, 10f, this); super.onResume(); } protected void onPause() { locationManager.removeUpdates(this); super.onPause(); }
public void onProviderDisabled(String provider) { Log.v("GPS", "Disabled"); Intent intent = new Intent( android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS); startActivity(intent); } public void onProviderEnabled(String provider) { Log.v("GPS", "Enabled"); } public void onStatusChanged(String provider, int status, Bundle extras) { switch (status) { case LocationProvider.OUT_OF_SERVICE: Log.v("GPS", "Status Changed: Out of Service"); break; case LocationProvider.TEMPORARILY_UNAVAILABLE: Log.v("GPS", "Status Changed: Temporarily Unavailable"); break; case LocationProvider.AVAILABLE: Log.v("GPS", "Status Changed: Available"); break; } }
Which of the following is true?
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetLineWidth(context, 2.0); CGContextSetStrokeColorWithColor(context, [UIColor redColor].CGColor); CGContextMoveToPoint(context, 100.0f, 100.0f); CGContextAddLineToPoint(context, 200.0f, 200.0f); CGContextStrokePath(context);
CGContextSetStrokeColorWithColor(context, [UIColor redColor].CGColor);
[UIColor colorWithRed:1.0f green: 0.0f blue: 0.0f alpha:1.0f];
CGPoint drawPoint = CGPointMake(100.0f, 100.0f); [image drawAtPoint: drawPoint];
CGRect theRect = CGRectMake(0, 0, 100, 100); CGContextAddEllipseInRect(context, theRect); CGContextDrawPath(context, kCGPathFillStroke);
#import <UIKit/UIKit.h> @interface UIColor(Random) +(UIColor *)randomColor; @end
#import "UIRandomColor.h" #define ARC4RANDOM_MAX 0x100000000LL @implementation UIColor(Random) +(UIColor *)randomColor { CGFloat red = (CGFloat)arc4random()/(CGFloat)ARC4RANDOM_MAX; CGFloat blue = (CGFloat)arc4random()/(CGFloat)ARC4RANDOM_MAX; CGFloat green = (CGFloat)arc4random()/(CGFloat)ARC4RANDOM_MAX; return [UIColor colorWithRed: red green:green blue:blue alpha:1.0f]; } @end
typedef enum { kLineShape = 0, kRectShape, kEllipseShape, kImageShape } ShapeType; typedef enum { kRedColorTab = 0, kBlueColorTab, kYellowColorTab, kGreenColorTab, kRandomColorTab } ColorTabIndex; #define degreesToRadians(x) (3.1415926535897932846 * x /180)