CS185c
Chris Pollett
Sep. 27, 2010
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
namespace WindowsPhoneApplication1
{
public partial class MainPage : PhoneApplicationPage
{
// Constructor
public MainPage()
{
InitializeComponent();
SupportedOrientations = SupportedPageOrientation.Portrait |
SupportedPageOrientation.Landscape;
this.OrientationChanged +=
new EventHandler<OrientationChangedEventArgs>(OnOrientationChanged);
}
private void button1_Click(object sender, RoutedEventArgs e)
{
slider1.Value = 50;
}
private void slider1_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
if (sliderNum != null && slider1 != null)
{
sliderNum.Text = "" + Math.Floor(slider1.Value + 0.5);
}
}
void OnOrientationChanged(object sender, OrientationChangedEventArgs e)
{
if ((e.Orientation & PageOrientation.Landscape) != 0)
{
sliderNum.FontSize = 30;
}
else // Portrait
{
sliderNum.FontSize = 16;
}
}
}
}
Which of the following is true?
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();
~/Library/Application Support/iPhoneSimulator/User/
NSArray *paths = NSSearchPathForDirectoriesInDomains(
NSDocumentDirectory, NSUserDomainMask, YES); //look for Documents directories in user home folder
//YES means expand tilde directories
NSString *documentsDirectory = [paths objectAtIndex:0]; //Will only be one such dir so same
//For temporary dir could have done
//NSString *tempPath = NSTemporaryDirectory
NSString *filename = [documentsDirectory stringByAppendingPathComponent:@"theFile.txt"];
if([[NSFileManager defaultManager] fileExistsAtPath:filename])
{
NSArray *readArray = [[NSArray alloc] initWithContentsOfFile:filename];
NSLog(@"I read from the file: %@", [readArray objectAtIndex:0]);
[readArray release];
}
NSMutableArray *storeArray = [[NSMutableArray alloc] init];
[storeArray addObject:@"Some interesting Data"];
[storeArray writeToFile:filename atomically:YES ];
// writing such an array stores the data as XML much like a plist
NSLog(@"I wrote some data");
[storeArray release];