2012-03-19

Re: Practice Mid term Solutions.

Originally Posted By: animeshd
Problem 1 and Problem 2

Q1. A) Explain the difference between an Emulator and a Simulator
• A Simulator creates an environment via the libraries that “simulates” the mobile device’s environment. Runs Machine Code of desktop.
• An emulator reads machine code for the target device and creates environment on desktop that looks the phone. Runs Machine Code of the Phone.
Q1 B) Setting the Icon (Android)
• Take a 48*48 PNG- drop it in res/drawable
• Open AndroidManifest.xml
• Add attribute to application => android:icon=”@drawable/icon

Q2)
a) A class method
Open the header of your program, underneath the @interface tag, add the following line
+(return type) method Name: (type) param

b) Instance in Objective – C
-InstanceMethod{
//implementation
}

c) Argument Passing in Objective – C
[obj method:parameter];
Where obj is Class object
Method is a method of that class
Parameter is the parameter that we are passing.
For passing more than one parameter:
[obj method:parameter1 paramName2: parameter2]
Where paramName2 is the name of the second parameter

Group Members:
Dhruv Jalota
Animesh Dutta
Kevin Grant
Jiajie Wu
ChingYing Kuo
'''Originally Posted By: animeshd''' Problem 1 and Problem 2<br><br>Q1. A) Explain the difference between an Emulator and a Simulator<br>&bull; A Simulator creates an environment via the libraries that &ldquo;simulates&rdquo; the mobile device&rsquo;s environment. Runs Machine Code of desktop.<br>&bull; An emulator reads machine code for the target device and creates environment on desktop that looks the phone. Runs Machine Code of the Phone.<br>Q1 B) Setting the Icon (Android)<br>&bull; Take a 48*48 PNG- drop it in res/drawable<br>&bull; Open AndroidManifest.xml<br>&bull; Add attribute to application =&gt; android:icon=&rdquo;@drawable/icon<br><br>Q2)<br>a) A class method<br>Open the header of your program, underneath the @interface tag, add the following line<br>+(return type) method Name: (type) param<br><br>b) Instance in Objective &ndash; C<br>-InstanceMethod{<br>//implementation<br>}<br><br>c) Argument Passing in Objective &ndash; C<br>[obj method:parameter];<br>Where obj is Class object<br>Method is a method of that class<br>Parameter is the parameter that we are passing.<br>For passing more than one parameter:<br>[obj method:parameter1 paramName2: parameter2]<br>Where paramName2 is the name of the second parameter<br><br>Group Members:<br>Dhruv Jalota<br>Animesh Dutta<br>Kevin Grant<br>Jiajie Wu<br>ChingYing Kuo

-- Practice Mid term Solutions
Originally Posted By: smokkapati
Question 7:

iPhone:
The following method will be called when the device orientation is changed. Write your code inside this method as required to change the layout.
In your ViewController.m file write this method:

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration {

if (interfaceOrientation == UIInterfaceOrientationPortrait) {
// This means new orientation is portrait.
} else if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft) {
// This means new orientation is landscape left.
} else if (interfaceOrientation == UIInterfaceOrientationLandscapeRight) {
// This means new orientation is landscape right.
} else if (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) {
// This means new orientation is portrait upside down.
}
}

For HTML5:
$(function(){
// Orientation Change
// When orientation changes event is triggered
// exposing an orientation property of either
// landscape or portrait
$('body').bind('orientationchange', function(event){
changeOrientation(event.orientation)
})

// Change the style depending on orientation
function changeOrientation(ori) {
// Remove all classes
$("#orientation").removeClass('portrait landscape');
$("#orientation").addClass(ori);
$("#orientation").html("
"+ori.toUpperCase()+" ");
}

$("body").trigger("orientationchange");
})

Group Members:
Snigdha Mokkapati
Vy Luong
Xiu Guo
'''Originally Posted By: smokkapati''' Question 7:<br><br>iPhone:<br>The following method will be called when the device orientation is changed. Write your code inside this method as required to change the layout.<br>In your ViewController.m file write this method:<br><br>- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration {<br> <br> if (interfaceOrientation == UIInterfaceOrientationPortrait) {<br> // This means new orientation is portrait.<br> } else if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft) {<br> // This means new orientation is landscape left.<br> } else if (interfaceOrientation == UIInterfaceOrientationLandscapeRight) {<br> // This means new orientation is landscape right.<br> } else if (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) {<br> // This means new orientation is portrait upside down.<br> }<br>}<br><br>For HTML5:<br>$(function(){<br> // Orientation Change<br> // When orientation changes event is triggered<br> // exposing an orientation property of either<br> // landscape or portrait<br> $('body').bind('orientationchange', function(event){<br> changeOrientation(event.orientation)<br> })<br><br> // Change the style depending on orientation<br> function changeOrientation(ori) {<br> // Remove all classes<br> $(&quot;#orientation&quot;).removeClass('portrait landscape');<br> $(&quot;#orientation&quot;).addClass(ori);<br> $(&quot;#orientation&quot;).html(&quot; &quot;+ori.toUpperCase()+&quot; &quot;);<br> }<br><br> $(&quot;body&quot;).trigger(&quot;orientationchange&quot;);<br> })<br><br>Group Members:<br>Snigdha Mokkapati<br>Vy Luong<br>Xiu Guo

Practice Mid term Solutions
Originally Posted By: shailbenq
Solution 4 : by Chinmay bhawe, Eugene, Ajinkya amrute and Shailesh Benake

Show the necessary code and describe any interface building activities needed to create a small app (platform of your choice from amongst those covered this semester) with a button on it, which when clicked opens an alert dialog with the words "Cancel Me!" on it. When the user clicks cancel me, the alert goes away.

Android way -
step 1: Go to the layout (say main.xml)
step 2: Add a button to the layout,set its id to say "button1"
step 3:
Set method Attribute as,
[ android:onClick = "clickerMethod"]
now add a method by the name "void clickerMethod"
code:
Code: public void clickerMethod(View v)
        {
                    AlertDialog.Builder bd = new AlertDialog.Builder(this);
                    bd.setNegativeButton("Cancel Me", new DialogInterface.OnClickListener(){
                    public void onClick(DialogInterface dialog,int d){
                                     dialog.cancel();
                     }
          });
           AlertDialog confirmation = bd.create();
           confirmation.show();
        }


I executed the above code on emulator its working fine as mentioned in the question
'''Originally Posted By: shailbenq''' Solution 4 : by Chinmay bhawe, Eugene, Ajinkya amrute and Shailesh Benake<br><br>Show the necessary code and describe any interface building activities needed to create a small app (platform of your choice from amongst those covered this semester) with a button on it, which when clicked opens an alert dialog with the words &quot;Cancel Me!&quot; on it. When the user clicks cancel me, the alert goes away.<br><br>Android way -<br>step 1: Go to the layout (say main.xml)<br>step 2: Add a button to the layout,set its id to say &quot;button1&quot;<br>step 3:<br> Set method Attribute as,<br> [ android:onClick = &quot;clickerMethod&quot;]<br> now add a method by the name &quot;void clickerMethod&quot;<br>code:<br> Code: public void clickerMethod(View v)<br>&nbsp; &nbsp; &nbsp; &nbsp; { <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; AlertDialog.Builder bd = new AlertDialog.Builder(this);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bd.setNegativeButton(&quot;Cancel Me&quot;, new DialogInterface.OnClickListener(){<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; public void onClick(DialogInterface dialog,int d){<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;dialog.cancel();<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; });<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;AlertDialog confirmation = bd.create();<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;confirmation.show();<br>&nbsp; &nbsp; &nbsp; &nbsp; }<br><br><br>I executed the above code on emulator its working fine as mentioned in the question<br>

-- Practice Mid term Solutions
Originally Posted By: arshiagrawal
Problem 6: For either iOS or Android, give the code to make the keyboard go away if the user clicks outside of the text input area.

Android:
In the onclick method of relative layout's onClickListener, write the following code to make the keyboard go away when user clicks outside the text area -

EditText dicEditTextID= (EditText) findViewById(R.id.EditText01);
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(dicEditTextID.getApplicationWindowToken(), 0);

Group members:
Arshi
Carlos
Chinmayee
'''Originally Posted By: arshiagrawal''' Problem 6: For either iOS or Android, give the code to make the keyboard go away if the user clicks outside of the text input area.<br><br>Android:<br>In the onclick method of relative layout's onClickListener, write the following code to make the keyboard go away when user clicks outside the text area - <br><br>EditText dicEditTextID= (EditText) findViewById(R.id.EditText01);<br>InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);<br>imm.hideSoftInputFromWindow(dicEditTextID.getApplicationWindowToken(), 0);<br><br>Group members:<br>Arshi<br>Carlos<br>Chinmayee
X