Difference between revisions of "Basic Android"
(→In Class Demo=) |
|||
(24 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
+ | [[Category:Tech]] | ||
+ | [[Category:Tutorial]] | ||
+ | [[Category:Video Tutorial]] | ||
+ | |||
=Android Basics= | =Android Basics= | ||
− | *App Inventor Pretty basic web interface an blocks editor to build simple android apps http://appinventor. | + | |
− | **Setup App Inventor http://appinventor. | + | |
+ | *Install 32 or 64 bit Java JDK http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html | ||
+ | |||
+ | *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 | ||
+ | **Download Android Studio | ||
+ | **For SDK path we will use c:\user\Android | ||
+ | |||
*Android NDK | *Android NDK | ||
+ | **we're not covering this http://developer.android.com/sdk/ndk/index.html | ||
+ | |||
+ | ==Basics== | ||
+ | |||
+ | *src folder containing all the source | ||
+ | *res folder containing all the resources | ||
+ | |||
+ | folder hierchy explained @http://developer.android.com/training/basics/firstapp/running-app.html | ||
+ | |||
+ | ==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 | ||
+ | |||
+ | <java>/** 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); | ||
+ | } | ||
+ | </java> | ||
+ | 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 | ||
+ | |||
+ | handle a click event | ||
+ | <java> | ||
+ | btn.setOnClickListener(new View.OnClickListener() { | ||
+ | |||
+ | @Override | ||
+ | public void onClick(View v) { | ||
+ | // TODO Auto-generated method stub | ||
+ | tv.setText(d.About()); | ||
+ | } | ||
+ | });</java> | ||
+ | |||
+ | ==Events== | ||
+ | |||
+ | Lots more good reading http://developer.android.com/guide/topics/fundamentals.html | ||
+ | |||
+ | |||
+ | ==AVD== | ||
+ | |||
+ | ==Dog Class in java== | ||
+ | <pre> | ||
+ | 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); | ||
+ | } | ||
+ | |||
+ | |||
+ | } | ||
+ | </pre> | ||
+ | |||
+ | |||
+ | =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{{AndroidStudioConfigure.png|Alt}} | ||
+ | *Select Android SDK Manager{{AndroidStudioSDKManager.png|Alt}} | ||
+ | *Make sure you have a current SDK for this Demo we will use 23.05 {{AndroidSDKManagerCurrentVersion.PNG|Alt}} | ||
+ | *Go back to the main menu and select New Project{{AndroidStudioNewProject.PNG|Alt}} | ||
+ | *Name the Project OOPDog and select Next{{AnroidStudioConfigureNewProject.PNG|Alt}} | ||
+ | *Select a Minimum SDK for this demo we will use ASI15 : IceCreamSandwich{{AnroidStudioConfigureNewProjectSDK.PNG|Alt}} | ||
+ | *Select Blank Activity for the Project template{{AndroidStudioBlankActivity.PNG|Alt}} | ||
+ | *The defaults are fine for the activity name select next{{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 {{AndroidStudioShowOpenMyActivity.png|Alt}} | ||
+ | *Add Dog class {{AndroidStudioNewClass.png|Alt}} | ||
+ | *Name the class Dog {{AndroidStudioNewClassName.PNG|Alt}} | ||
+ | |||
+ | *Here is the c# dog class we have been using we need to change it a bit [[Android Studio CSharpDog Code]] | ||
+ | {{AndroidStudioCSharpDog.PNG|Alt}} | ||
+ | *In Java [[Android Studio JavaDog]] | ||
+ | {{AndroidStudioJavaDog.PNG|Alt}} |
Revision as of 18:03, 10 November 2015
Contents
Android Basics
- Install 32 or 64 bit Java JDK http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html
- 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
- http://developer.android.com/sdk/index.html
- Download Android Studio
- For SDK path we will use c:\user\Android
- Android NDK
- we're not covering this http://developer.android.com/sdk/ndk/index.html
Basics
- src folder containing all the source
- res folder containing all the resources
folder hierchy explained @http://developer.android.com/training/basics/firstapp/running-app.html
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
<java>/** 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); }
</java>
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 <java> btn.setOnClickListener(new View.OnClickListener() {
@Override public void onClick(View v) { // TODO Auto-generated method stub tv.setText(d.About()); } });</java>
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
- Get and install Android Studio this demo uses .086 https://developer.android.com/sdk/installing/studio.html
- Start Android Studio
- Select ConfigureTemplate:AndroidStudioConfigure.png
- Select Android SDK ManagerTemplate:AndroidStudioSDKManager.png
- Make sure you have a current SDK for this Demo we will use 23.05 Template:AndroidSDKManagerCurrentVersion.PNG
- Go back to the main menu and select New ProjectTemplate:AndroidStudioNewProject.PNG
- Name the Project OOPDog and select NextTemplate:AnroidStudioConfigureNewProject.PNG
- Select a Minimum SDK for this demo we will use ASI15 : IceCreamSandwichTemplate:AnroidStudioConfigureNewProjectSDK.PNG
- Select Blank Activity for the Project templateTemplate:AndroidStudioBlankActivity.PNG
- The defaults are fine for the activity name select nextTemplate:AnroidStudioNewProjectAcvtivity.PNG
- After a minute or so you can open the Project window if it isn't already open Att-1 or View/Tool Windows/Project Template:AndroidStudioShowOpenMyActivity.png
- Add Dog class Template:AndroidStudioNewClass.png
- Name the class Dog Template:AndroidStudioNewClassName.PNG
- Here is the c# dog class we have been using we need to change it a bit Android Studio CSharpDog Code
Template:AndroidStudioCSharpDog.PNG
- In Java Android Studio JavaDog