Difference between revisions of "Basic Android"

esse quam videri
Jump to: navigation, search
(Android Basics)
(Basics)
(30 intermediate revisions by the same user not shown)
Line 5: Line 5:
 
=Android Basics=
 
=Android Basics=
  
*Install 32 bit Java JDK http://www.oracle.com/technetwork/java/javase/downloads/index.html
 
  
*App Inventor Pretty basic web interface an blocks editor to build simple android apps http://appinventor.googlelabs.com/about/ <html><img src="http://appinventor.googlelabs.com/static/images/appinventor_logo.gif"></html>
+
*Install 32 or 64  bit Java JDK http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html
**Setup App Inventor http://appinventor.googlelabs.com/learn/setup/
+
 
 +
*App Inventor Pretty basic web interface an blocks editor to build simple android apps http://appinventor.mit.edu/about/  
 +
**Setup App Inventor http://appinventor.mit.edu/
  
 
*Android SDK
 
*Android SDK
 
**http://developer.android.com/sdk/index.html
 
**http://developer.android.com/sdk/index.html
**Install SDK Installer http://developer.android.com/sdk/tools-notes.html
+
**Download Android Studio
**Install Eclipse http://www.eclipse.org/downloads/
+
**For SDK path we will use c:\user\Android
**Install Eclipse ADT Plugin http://developer.android.com/sdk/eclipse-adt.html#installing
 
after installing the plugin you may need to change the path to the SDK there is currently a bug if you us a folder with a space in the name use C:\PROGRA~2\Android\android-sdk if you installed to "C:\Program Files (x86)\Android"
 
  
 
*Android NDK
 
*Android NDK
Line 22: Line 21:
 
==Basics==
 
==Basics==
  
*src folder containg all the source
+
For the demo please login to https://storefront.iam.local/Citrix/IAMVDIWeb
 +
 
 +
 
 +
*src folder containing all the source
 
*res folder containing all the resources
 
*res folder containing all the resources
 +
 +
folder hierarchy explained http://developer.android.com/tools/projects/index.html
 +
 +
First app demo http://developer.android.com/training/basics/firstapp/running-app.html
 +
 +
App lifecycle http://developer.android.com/guide/components/activities.html
 +
 +
http://developer.android.com/images/activity_lifecycle.png
  
 
==Resources==
 
==Resources==
Line 37: Line 47:
 
Get an instance of an object from the R class
 
Get an instance of an object from the R class
 
   
 
   
<java>/** Called when the activity is first created. */
+
<syntaxhighlight lang="java">/** Called when the activity is first created. */
 
     @Override
 
     @Override
 
     public void onCreate(Bundle savedInstanceState) {
 
     public void onCreate(Bundle savedInstanceState) {
Line 49: Line 59:
 
         tv.setText(s);
 
         tv.setText(s);
 
     }
 
     }
</java>
+
</syntaxhighlight>
 
  notice the cast to the type also notice that the TextView is marked as [http://en.wikipedia.org/wiki/Final_%28Java%29 final]  
 
  notice the cast to the type also notice that the TextView is marked as [http://en.wikipedia.org/wiki/Final_%28Java%29 final]  
 
  this is so that we can use it in an inner method
 
  this is so that we can use it in an inner method
  
 
handle a click event  
 
handle a click event  
<java>
+
<syntaxhighlight lang="java">
 
btn.setOnClickListener(new View.OnClickListener() {
 
btn.setOnClickListener(new View.OnClickListener() {
 
 
Line 62: Line 72:
 
tv.setText(d.About());
 
tv.setText(d.About());
 
}
 
}
});</java>
+
});</syntaxhighlight>
  
 
==Events==
 
==Events==
Line 69: Line 79:
  
  
 +
==AVD==
 +
 +
==Dog Class in java==
 +
<syntaxhighlight lang="java">
 +
public class Dog {
 +
 +
public String Name;
 +
public int Weight;
 +
public String BarkSound;
 +
 +
//Constructor
 +
public Dog()
 +
{
 +
this.Name = "fido";
 +
this.Weight = 1;
 +
this.BarkSound = "woof";
 +
}
 +
 +
public void Eat()
 +
{
 +
this.Weight++;
 +
}
 +
public void Poop()
 +
{
 +
this.Weight--;
 +
}
 +
 +
public String About()
 +
{
 +
return String.format("Hello my name is %s. I weigh %s lbs",
 +
this.Name, this.Weight);
 +
}
 +
 +
 +
}
 +
</syntaxhighlight>
 +
 +
=In Class Demo=
 +
*Get and install Android Studio this demo uses .086 https://developer.android.com/sdk/installing/studio.html
 +
*Start Android Studio
 +
*Select Configure
 +
[[File:AndroidStudioConfigure.png]]
 +
*Select Android SDK Manager
 +
[[File:AndroidStudioSDKManager.png]]
 +
*Make sure you have a current SDK for this Demo we will use 23.05
 +
[[File:AndroidSDKManagerCurrentVersion.PNG|Alt]]
 +
*Go back to the main menu and select New Project
 +
[[File:AndroidStudioNewProject.PNG|Alt]]
 +
*Name the Project OOPDog and select Next
 +
[[File:AnroidStudioConfigureNewProject.PNG|Alt]]
 +
*Select a Minimum SDK for this demo we will use API15 : IceCreamSandwich
 +
[[File:AnroidStudioConfigureNewProjectSDK.PNG|Alt]]
 +
*Select Blank Activity for the Project template
 +
[[File:AndroidStudioBlankActivity.PNG|Alt]]
 +
*The defaults are fine for the activity name select next
 +
[[File:AnroidStudioNewProjectAcvtivity.PNG|Alt]]
 +
 +
*After a minute or so you can open the Project window if it isn't already open Att-1 or View/Tool Windows/Project
 +
[[File:AndroidStudioShowOpenMyActivity.png|Alt]]
 +
*Add Dog class
 +
[[File:AndroidStudioNewClass.png|Alt]]
 +
*Name the class Dog
 +
[[File:AndroidStudioNewClassName.PNG|Alt]]
 +
 +
*Here is the c# dog class we have been using we need to change it a bit
 +
[[Android Studio CSharpDog Code]]
 +
 +
[[File:AndroidStudioCSharpDog.PNG|Alt]]
  
<html>
+
*In Java [[Android Studio JavaDog]]
<script type='text/javascript' src='http://iam.colum.edu/videotutorials/mediaplayer-5.2/swfobject.js'></script>
+
[[File:AndroidStudioJavaDog.PNG|Alt]]
<div id='mediaspace2'>This text will be replaced</div>
 
<script type='text/javascript'>
 
var so = new SWFObject('http://iam.colum.edu/videotutorials/mediaplayer-5.2/player.swf','mpl','800','600','9');so.addParam('allowfullscreen','true')
 
;so.addParam('allowscriptaccess','always');
 
so.addParam('wmode','opaque');
 
so.addVariable('file','http://iam.colum.edu/screenz/Video_Tutorials/Android%20Basics/Android%20Basics.mp4');
 
so.write('mediaspace2');
 
</script>
 
</html>
 

Revision as of 19:32, 5 April 2016


Android Basics

Basics

For the demo please login to https://storefront.iam.local/Citrix/IAMVDIWeb


  • src folder containing all the source
  • res folder containing all the resources

folder hierarchy explained http://developer.android.com/tools/projects/index.html

First app demo http://developer.android.com/training/basics/firstapp/running-app.html

App lifecycle http://developer.android.com/guide/components/activities.html

activity_lifecycle.png

Resources

No DPI or PPI Andoid uses dp density independent pixels or sp scale interdependent pixels http://developer.android.com/guide/topics/resources/more-resources.html#Dimension

also see supporting multiple screens http://developer.android.com/guide/practices/screens_support.html

Activities

Activity life cycle http://developer.android.com/guide/topics/fundamentals/activities.html#Lifecycle

Get an instance of an object from the R class

/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        //Get the Button and the TextView from the Resource class
        Button btn = (Button)this.findViewById(R.id.button1);
        final TextView tv = (TextView)this.findViewById(R.id.textView1);  
        String s = "hello";
        tv.setText(s);
    }
notice the cast to the type also notice that the TextView is marked as final 
this is so that we can use it in an inner method

handle a click event

btn.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				tv.setText(d.About());
			}
		});

Events

Lots more good reading http://developer.android.com/guide/topics/fundamentals.html


AVD

Dog Class in java

public class Dog {

	public String Name;
	public int Weight;
	public String BarkSound;
	
	//Constructor
	public Dog()
	{
		this.Name = "fido";
		this.Weight = 1;
		this.BarkSound = "woof";
	}
	
	public void Eat()
	{
		this.Weight++;
	}
	public void Poop()
	{
		this.Weight--;
	}
	
	public String About()
	{
		return String.format("Hello my name is %s. I weigh %s lbs",	
				this.Name, this.Weight);
	}
	
	
}

In Class Demo

AndroidStudioConfigure.png

  • Select Android SDK Manager

AndroidStudioSDKManager.png

  • Make sure you have a current SDK for this Demo we will use 23.05

Alt

  • Go back to the main menu and select New Project

Alt

  • Name the Project OOPDog and select Next

Alt

  • Select a Minimum SDK for this demo we will use API15 : IceCreamSandwich

Alt

  • Select Blank Activity for the Project template

Alt

  • The defaults are fine for the activity name select next

Alt

  • After a minute or so you can open the Project window if it isn't already open Att-1 or View/Tool Windows/Project

Alt

  • Add Dog class

Alt

  • Name the class Dog

Alt

  • Here is the c# dog class we have been using we need to change it a bit

Android Studio CSharpDog Code

Alt

Alt