SlideShare a Scribd company logo
1 of 24
Introducing
Activity and
Intent

1
Memory
TextView

ListView

2

LinearLayout,
weight=2

LinearLayout,
weight=1
How to create xml file

Right click
(on the
folder)

3
The menu.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent“
android:layout_height="fill_parent">
<LinearLayout android:orientation="vertical"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:layout_weight="2">

<TextView android:id="@+id/TextView01" android:layout_width="wrap_content”
android:layout_height="wrap_content“ android:textSize="@dimen/screen_title_size"
android:text="@string/menu" android:layout_gravity="center"

android:shadowColor="@android:color/white"
android:textColor="@color/title_color" />
</LinearLayout>

4
The menu.xml cont.
<LinearLayout android:orientation="vertical"
android:layout_width="fill_parent" android:layout_height="fill_parent“ android:layout_weight="1">

<ListView android:layout_height="wrap_content" android:id="@+id/list_menu"
android:layout_width="fill_parent" android:layout_gravity="center_horizontal"

android:divider="@drawable/divider"
android:listSelector="@drawable/textured">
</ListView>
</LinearLayout>
</LinearLayout>

5
The dimens.xml (in values
folder)
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen
name="logo_size">24pt</dimen>
<dimen
name="version_size">5pt</dimen>
<dimen
name="version_spacing">3pt</dimen>
<dimen
name="screen_title_size">16pt</dimen>
<dimen
name="menu_item_size">16pt</dimen>
<dimen
name="game_question_size">10pt</dimen>
<dimen
name="help_text_size">7pt</dimen>
<dimen
name="help_text_padding">20px</dimen>
</resources>
6
The colors.xml (in values
folder)
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color
name="logo_color">#FFFF0F</color>
<color
name="version_color">#f0f0f0</color>
<color
name="version_bkgrd">#1a1a48</color>
<color
name="title_color">#f0f0f0</color>
<color
name="title_glow">#F00</color>
<color
name="menu_color">#FFFF0F</color>
<color
name="menu_glow">#F00</color>
<color
name="error_color">#F00</color>
</resources>
7
How to create java file
Right click
(on the
folder)

8
How to override a method

Right click
on the code
pane

9
How to override a method cont.

Select the
method to
overridem
eg, onCreate

10
The strings.xml (in values
folder)
<Resources>
….
<string name="menu">Memory</string>
<string name="menu_item_settings">Settings</string>
<string name="menu_item_play">Play Game</string>
<string name="menu_item_scores">View Scores</string>
<string name="menu_item_help">Help</string>
…
</Resources>

11
Create ListView from resource
ListView menuList = (ListView) findViewById(R.id.list_menu);
String[] items = { getResources().getString(R.string.menu_item_play),
getResources().getString(R.string.menu_item_scores),
getResources().getString(R.string.menu_item_settings),
getResources().getString(R.string.menu_item_help) };
ArrayAdapter<String> adapt = new ArrayAdapter<String>
(this,R.layout.menu_item, items);
menuList.setAdapter(adapt);

12
Starting an Activity class
public class Memory extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.menu);
ListView menuList = (ListView) findViewById(R.id.list_menu);
String[] items = { getResources().getString(R.string.menu_item_play),
getResources().getString(R.string.menu_item_scores),
getResources().getString(R.string.menu_item_settings),
getResources().getString(R.string.menu_item_help) };
ArrayAdapter<String> adapt = new ArrayAdapter<String>(this,R.layout.menu_item, items);
menuList.setAdapter(adapt);
menuList.setSelection(-1);
13
Starting an Activity class
menuList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View itemClicked, int position, long id)
{
// Note: if the list was built "by hand" the id could be used.
// As-is, though, each item has the same id
TextView textView = (TextView) itemClicked;
String strText = textView.getText().toString();

if (strText.equalsIgnoreCase(
getResources().getString(R.string.menu_item_play))) {
startActivity(new Intent(Memory.this, MemoryPlayGame.class));
} else if (strText.equalsIgnoreCase(getResources().getString(R.string.menu_item_help))) {
//

startActivity(new Intent(Memory.this, MemoryHelp.class));
}
}
});

}
}
14
Include the Activity in the
manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.plearn" android:versionCode="1" android:versionName="1.0">
<uses-sdk android:minSdkVersion="8" />
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".Memory" android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".PlayGame" android:label="@string/app_name">
</activity>
</application>
</manifest>
15
Introducing
Graphics

16
Using View to draw graphics
public class GraphicsExample extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(new ViewGraphics(this));
}
class ViewGraphics extends View{
public ViewGraphics(Context context){
super(context);
}
public void onDraw(Canvas canvas){ // canvas to draw on
}
}
}
17
Paint contains drawing
properties
Paint mPaint=new Paint(); // Paint contains properties to use when drawing
Typeface mTypeFace;
public ViewGraphics(Context context){
super(context);
mPaint.setStrokeWidth(3);
mPaint.setStrokeCap(Paint.Cap.ROUND);
mPaint.setTextSize(30);
mPaint.setTypeface(Typeface.create(Typeface.SERIF,
Typeface.BOLD_ITALIC));
mFace = Typeface.createFromAsset(getContext().getAssets(),
"fonts/gigi.ttf");
//copy a font file in to Assets/fonts folder
}
18
Drawing primitives in onDraw()
public void onDraw(Canvas canvas){
canvas.drawColor(Color.WHITE);
mPaint.setColor(Color.BLUE);
canvas.drawText(“Android Graphics", 10, 70, mPaint);
mPaint.setStyle(Style.STROKE);
float x1=100, y1=200, x2=x1+170, y2=y1+150; //top-left, bottomright
canvas.drawRect(x1,y1,x2,y2, mPaint); //RectF : Rectangle
//with flaoting number
canvas.drawLine(x1,x2,y1,y2, mPaint);
mPaint.setColor(Color.MAGENTA);
canvas.drawOval(new RectF(x1,y1,x2,y2), mPaint);
19
}
Drawing primitives cont.
mPaint.setStyle(Style.FILL);
canvas.drawArc(new RectF(x1,y1,x2,y2), 90, 100, true, mPaint);
(start angle, num angle, use radius)
mPaint.setTypeface(mFace);
mPaint.setColor(Color.BLACK); mPaint.setTextSize(40);
canvas.drawText("Custom Fontface from assets", 10, 150, mPaint);
// Draw a Drawable (image file)
Drawable mDrawable =
mContext.getResources().getDrawable(R.drawable.cherry);
mDrawable.setBounds(new Rect(100, 400, 250, 550));
mDrawable.draw(canvas);
20
The onTouchEvent
The onTouchEvent method occurred when the user touch the screen.
The (getX(), getY()) is the coordinate (x,y) axis where the screen is touched.
public boolean onTouchEvent(MotionEvent event) {
super.onTouchEvent(event);
float x = event.getX();
float y = event.getY();
return true;
}

21
The PlayGame Activity
public class PlayGame extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
GameView gameView = new GameView(this);
setContentView(gameView);
}
}

22
The PlayGame Activity cont.
public class PlayGame extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
GameView gameView = new GameView(this);
setContentView(gameView);
}
}

class GameView extends View {
public GameView(Context context){
}
public void onDraw(Canvas canvas) {
}
public boolean onTouchEvent(MotionEvent event) {
}
}
23
Assignment 6
1. Implement the graphic primitives in the onDraw() method

of the PlayGame Activity.
2. Implement the TouchEvent method to show the
coordinate (x,y) using the Toast.makeText().

24

More Related Content

What's hot

Londroid Android Home Screen Widgets
Londroid Android Home Screen WidgetsLondroid Android Home Screen Widgets
Londroid Android Home Screen WidgetsRichard Hyndman
 
A comprehensive guide on developing responsive and common react filter component
A comprehensive guide on developing responsive and common react filter componentA comprehensive guide on developing responsive and common react filter component
A comprehensive guide on developing responsive and common react filter componentKaty Slemon
 
STYLISH FLOOR
STYLISH FLOORSTYLISH FLOOR
STYLISH FLOORABU HASAN
 
Chapt 04 user interaction
Chapt 04 user interactionChapt 04 user interaction
Chapt 04 user interactionEdi Faizal
 
android layouts
android layoutsandroid layouts
android layoutsDeepa Rani
 
Android Development project
Android Development projectAndroid Development project
Android Development projectMinhaj Kazi
 
Introduction to Silverlight for Windows Phone
Introduction to Silverlight for Windows PhoneIntroduction to Silverlight for Windows Phone
Introduction to Silverlight for Windows PhoneDave Bost
 
follow-app BOOTCAMP 2: Introduction to silverlight
follow-app BOOTCAMP 2: Introduction to silverlightfollow-app BOOTCAMP 2: Introduction to silverlight
follow-app BOOTCAMP 2: Introduction to silverlightQIRIS
 
Learning Appcelerator® Alloy™
Learning Appcelerator® Alloy™Learning Appcelerator® Alloy™
Learning Appcelerator® Alloy™Ricardo Alcocer
 
Different types of sticker apps
Different types of sticker appsDifferent types of sticker apps
Different types of sticker appsJelena Krmar
 

What's hot (11)

Londroid Android Home Screen Widgets
Londroid Android Home Screen WidgetsLondroid Android Home Screen Widgets
Londroid Android Home Screen Widgets
 
Android UI
Android UIAndroid UI
Android UI
 
A comprehensive guide on developing responsive and common react filter component
A comprehensive guide on developing responsive and common react filter componentA comprehensive guide on developing responsive and common react filter component
A comprehensive guide on developing responsive and common react filter component
 
STYLISH FLOOR
STYLISH FLOORSTYLISH FLOOR
STYLISH FLOOR
 
Chapt 04 user interaction
Chapt 04 user interactionChapt 04 user interaction
Chapt 04 user interaction
 
android layouts
android layoutsandroid layouts
android layouts
 
Android Development project
Android Development projectAndroid Development project
Android Development project
 
Introduction to Silverlight for Windows Phone
Introduction to Silverlight for Windows PhoneIntroduction to Silverlight for Windows Phone
Introduction to Silverlight for Windows Phone
 
follow-app BOOTCAMP 2: Introduction to silverlight
follow-app BOOTCAMP 2: Introduction to silverlightfollow-app BOOTCAMP 2: Introduction to silverlight
follow-app BOOTCAMP 2: Introduction to silverlight
 
Learning Appcelerator® Alloy™
Learning Appcelerator® Alloy™Learning Appcelerator® Alloy™
Learning Appcelerator® Alloy™
 
Different types of sticker apps
Different types of sticker appsDifferent types of sticker apps
Different types of sticker apps
 

Viewers also liked

Mfc系统教学
Mfc系统教学Mfc系统教学
Mfc系统教学M4 Members
 
MFACE INDIA Presentation- Earn Big Money With MBI International MFACE
MFACE INDIA Presentation- Earn Big Money With MBI International MFACEMFACE INDIA Presentation- Earn Big Money With MBI International MFACE
MFACE INDIA Presentation- Earn Big Money With MBI International MFACEMFACE INDIA
 
Mobility Beyond Imagination (MBI)
Mobility Beyond Imagination (MBI)Mobility Beyond Imagination (MBI)
Mobility Beyond Imagination (MBI)Alex Ureta Jr.
 
沃客国际说明
沃客国际说明沃客国际说明
沃客国际说明leehoychin
 
Mface presentation english
Mface presentation englishMface presentation english
Mface presentation englishSaly Man
 

Viewers also liked (7)

Livery Presentation - AirAsia
Livery Presentation - AirAsiaLivery Presentation - AirAsia
Livery Presentation - AirAsia
 
Mfc系统教学
Mfc系统教学Mfc系统教学
Mfc系统教学
 
MFACE INDIA Presentation- Earn Big Money With MBI International MFACE
MFACE INDIA Presentation- Earn Big Money With MBI International MFACEMFACE INDIA Presentation- Earn Big Money With MBI International MFACE
MFACE INDIA Presentation- Earn Big Money With MBI International MFACE
 
Mobility Beyond Imagination (MBI)
Mobility Beyond Imagination (MBI)Mobility Beyond Imagination (MBI)
Mobility Beyond Imagination (MBI)
 
沃客国际说明
沃客国际说明沃客国际说明
沃客国际说明
 
Mface
MfaceMface
Mface
 
Mface presentation english
Mface presentation englishMface presentation english
Mface presentation english
 

Similar to Android 2

Making it fit - DroidCon Paris 18 june 2013
Making it fit - DroidCon Paris 18 june 2013Making it fit - DroidCon Paris 18 june 2013
Making it fit - DroidCon Paris 18 june 2013Paris Android User Group
 
Custom UI Components at Android Only 2011
Custom UI Components at Android Only 2011Custom UI Components at Android Only 2011
Custom UI Components at Android Only 2011Johan Nilsson
 
Android Development Made Easy - With Sample Project
Android Development Made Easy - With Sample ProjectAndroid Development Made Easy - With Sample Project
Android Development Made Easy - With Sample ProjectJoemarie Amparo
 
View groups containers
View groups containersView groups containers
View groups containersMani Selvaraj
 
Android Development for Beginners with Sample Project - Day 1
Android Development for Beginners with Sample Project - Day 1Android Development for Beginners with Sample Project - Day 1
Android Development for Beginners with Sample Project - Day 1Joemarie Amparo
 
Big Data for each one of us
Big Data for each one of usBig Data for each one of us
Big Data for each one of usOSCON Byrum
 
Anko試食会
Anko試食会Anko試食会
Anko試食会susan335
 
Android por onde começar? Mini Curso Erbase 2015
Android por onde começar? Mini Curso Erbase 2015 Android por onde começar? Mini Curso Erbase 2015
Android por onde começar? Mini Curso Erbase 2015 Mario Jorge Pereira
 
SE2016 Android Mikle Anokhin "Speed up application development with data bind...
SE2016 Android Mikle Anokhin "Speed up application development with data bind...SE2016 Android Mikle Anokhin "Speed up application development with data bind...
SE2016 Android Mikle Anokhin "Speed up application development with data bind...Inhacking
 
03 layouts & ui design - Android
03   layouts & ui design - Android03   layouts & ui design - Android
03 layouts & ui design - AndroidWingston
 
Android Custom views
Android Custom views   Android Custom views
Android Custom views Matej Vukosav
 
Advance Android application development workshop day 2
Advance Android application development workshop day 2Advance Android application development workshop day 2
Advance Android application development workshop day 2cresco
 
A mobile web app for Android in 75 minutes
A mobile web app for Android in 75 minutesA mobile web app for Android in 75 minutes
A mobile web app for Android in 75 minutesJames Pearce
 
TinyMCE: WYSIWYG editor 2010-12-08
TinyMCE: WYSIWYG editor 2010-12-08TinyMCE: WYSIWYG editor 2010-12-08
TinyMCE: WYSIWYG editor 2010-12-08Andy Gelme
 

Similar to Android 2 (20)

Making it fit - DroidCon Paris 18 june 2013
Making it fit - DroidCon Paris 18 june 2013Making it fit - DroidCon Paris 18 june 2013
Making it fit - DroidCon Paris 18 june 2013
 
Custom UI Components at Android Only 2011
Custom UI Components at Android Only 2011Custom UI Components at Android Only 2011
Custom UI Components at Android Only 2011
 
Android Development Made Easy - With Sample Project
Android Development Made Easy - With Sample ProjectAndroid Development Made Easy - With Sample Project
Android Development Made Easy - With Sample Project
 
View groups containers
View groups containersView groups containers
View groups containers
 
Android Development for Beginners with Sample Project - Day 1
Android Development for Beginners with Sample Project - Day 1Android Development for Beginners with Sample Project - Day 1
Android Development for Beginners with Sample Project - Day 1
 
Chapter 5 - Layouts
Chapter 5 - LayoutsChapter 5 - Layouts
Chapter 5 - Layouts
 
Layouts in android
Layouts in androidLayouts in android
Layouts in android
 
Big Data for each one of us
Big Data for each one of usBig Data for each one of us
Big Data for each one of us
 
Android App Dev Manual-1.doc
Android App Dev Manual-1.docAndroid App Dev Manual-1.doc
Android App Dev Manual-1.doc
 
Android 3
Android 3Android 3
Android 3
 
Anko試食会
Anko試食会Anko試食会
Anko試食会
 
Android por onde começar? Mini Curso Erbase 2015
Android por onde começar? Mini Curso Erbase 2015 Android por onde começar? Mini Curso Erbase 2015
Android por onde começar? Mini Curso Erbase 2015
 
SE2016 Android Mikle Anokhin "Speed up application development with data bind...
SE2016 Android Mikle Anokhin "Speed up application development with data bind...SE2016 Android Mikle Anokhin "Speed up application development with data bind...
SE2016 Android Mikle Anokhin "Speed up application development with data bind...
 
Ap quiz app
Ap quiz appAp quiz app
Ap quiz app
 
03 layouts & ui design - Android
03   layouts & ui design - Android03   layouts & ui design - Android
03 layouts & ui design - Android
 
Android Custom views
Android Custom views   Android Custom views
Android Custom views
 
Advance Android application development workshop day 2
Advance Android application development workshop day 2Advance Android application development workshop day 2
Advance Android application development workshop day 2
 
Layout
LayoutLayout
Layout
 
A mobile web app for Android in 75 minutes
A mobile web app for Android in 75 minutesA mobile web app for Android in 75 minutes
A mobile web app for Android in 75 minutes
 
TinyMCE: WYSIWYG editor 2010-12-08
TinyMCE: WYSIWYG editor 2010-12-08TinyMCE: WYSIWYG editor 2010-12-08
TinyMCE: WYSIWYG editor 2010-12-08
 

Recently uploaded

CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxnull - The Open Security Community
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Hyundai Motor Group
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsHyundai Motor Group
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 

Recently uploaded (20)

CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
The transition to renewables in India.pdf
The transition to renewables in India.pdfThe transition to renewables in India.pdf
The transition to renewables in India.pdf
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 

Android 2

  • 3. How to create xml file Right click (on the folder) 3
  • 4. The menu.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent“ android:layout_height="fill_parent"> <LinearLayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="2"> <TextView android:id="@+id/TextView01" android:layout_width="wrap_content” android:layout_height="wrap_content“ android:textSize="@dimen/screen_title_size" android:text="@string/menu" android:layout_gravity="center" android:shadowColor="@android:color/white" android:textColor="@color/title_color" /> </LinearLayout> 4
  • 5. The menu.xml cont. <LinearLayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent“ android:layout_weight="1"> <ListView android:layout_height="wrap_content" android:id="@+id/list_menu" android:layout_width="fill_parent" android:layout_gravity="center_horizontal" android:divider="@drawable/divider" android:listSelector="@drawable/textured"> </ListView> </LinearLayout> </LinearLayout> 5
  • 6. The dimens.xml (in values folder) <?xml version="1.0" encoding="utf-8"?> <resources> <dimen name="logo_size">24pt</dimen> <dimen name="version_size">5pt</dimen> <dimen name="version_spacing">3pt</dimen> <dimen name="screen_title_size">16pt</dimen> <dimen name="menu_item_size">16pt</dimen> <dimen name="game_question_size">10pt</dimen> <dimen name="help_text_size">7pt</dimen> <dimen name="help_text_padding">20px</dimen> </resources> 6
  • 7. The colors.xml (in values folder) <?xml version="1.0" encoding="utf-8"?> <resources> <color name="logo_color">#FFFF0F</color> <color name="version_color">#f0f0f0</color> <color name="version_bkgrd">#1a1a48</color> <color name="title_color">#f0f0f0</color> <color name="title_glow">#F00</color> <color name="menu_color">#FFFF0F</color> <color name="menu_glow">#F00</color> <color name="error_color">#F00</color> </resources> 7
  • 8. How to create java file Right click (on the folder) 8
  • 9. How to override a method Right click on the code pane 9
  • 10. How to override a method cont. Select the method to overridem eg, onCreate 10
  • 11. The strings.xml (in values folder) <Resources> …. <string name="menu">Memory</string> <string name="menu_item_settings">Settings</string> <string name="menu_item_play">Play Game</string> <string name="menu_item_scores">View Scores</string> <string name="menu_item_help">Help</string> … </Resources> 11
  • 12. Create ListView from resource ListView menuList = (ListView) findViewById(R.id.list_menu); String[] items = { getResources().getString(R.string.menu_item_play), getResources().getString(R.string.menu_item_scores), getResources().getString(R.string.menu_item_settings), getResources().getString(R.string.menu_item_help) }; ArrayAdapter<String> adapt = new ArrayAdapter<String> (this,R.layout.menu_item, items); menuList.setAdapter(adapt); 12
  • 13. Starting an Activity class public class Memory extends Activity { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.menu); ListView menuList = (ListView) findViewById(R.id.list_menu); String[] items = { getResources().getString(R.string.menu_item_play), getResources().getString(R.string.menu_item_scores), getResources().getString(R.string.menu_item_settings), getResources().getString(R.string.menu_item_help) }; ArrayAdapter<String> adapt = new ArrayAdapter<String>(this,R.layout.menu_item, items); menuList.setAdapter(adapt); menuList.setSelection(-1); 13
  • 14. Starting an Activity class menuList.setOnItemClickListener(new AdapterView.OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View itemClicked, int position, long id) { // Note: if the list was built "by hand" the id could be used. // As-is, though, each item has the same id TextView textView = (TextView) itemClicked; String strText = textView.getText().toString(); if (strText.equalsIgnoreCase( getResources().getString(R.string.menu_item_play))) { startActivity(new Intent(Memory.this, MemoryPlayGame.class)); } else if (strText.equalsIgnoreCase(getResources().getString(R.string.menu_item_help))) { // startActivity(new Intent(Memory.this, MemoryHelp.class)); } } }); } } 14
  • 15. Include the Activity in the manifest <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.plearn" android:versionCode="1" android:versionName="1.0"> <uses-sdk android:minSdkVersion="8" /> <application android:icon="@drawable/icon" android:label="@string/app_name"> <activity android:name=".Memory" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".PlayGame" android:label="@string/app_name"> </activity> </application> </manifest> 15
  • 17. Using View to draw graphics public class GraphicsExample extends Activity { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(new ViewGraphics(this)); } class ViewGraphics extends View{ public ViewGraphics(Context context){ super(context); } public void onDraw(Canvas canvas){ // canvas to draw on } } } 17
  • 18. Paint contains drawing properties Paint mPaint=new Paint(); // Paint contains properties to use when drawing Typeface mTypeFace; public ViewGraphics(Context context){ super(context); mPaint.setStrokeWidth(3); mPaint.setStrokeCap(Paint.Cap.ROUND); mPaint.setTextSize(30); mPaint.setTypeface(Typeface.create(Typeface.SERIF, Typeface.BOLD_ITALIC)); mFace = Typeface.createFromAsset(getContext().getAssets(), "fonts/gigi.ttf"); //copy a font file in to Assets/fonts folder } 18
  • 19. Drawing primitives in onDraw() public void onDraw(Canvas canvas){ canvas.drawColor(Color.WHITE); mPaint.setColor(Color.BLUE); canvas.drawText(“Android Graphics", 10, 70, mPaint); mPaint.setStyle(Style.STROKE); float x1=100, y1=200, x2=x1+170, y2=y1+150; //top-left, bottomright canvas.drawRect(x1,y1,x2,y2, mPaint); //RectF : Rectangle //with flaoting number canvas.drawLine(x1,x2,y1,y2, mPaint); mPaint.setColor(Color.MAGENTA); canvas.drawOval(new RectF(x1,y1,x2,y2), mPaint); 19 }
  • 20. Drawing primitives cont. mPaint.setStyle(Style.FILL); canvas.drawArc(new RectF(x1,y1,x2,y2), 90, 100, true, mPaint); (start angle, num angle, use radius) mPaint.setTypeface(mFace); mPaint.setColor(Color.BLACK); mPaint.setTextSize(40); canvas.drawText("Custom Fontface from assets", 10, 150, mPaint); // Draw a Drawable (image file) Drawable mDrawable = mContext.getResources().getDrawable(R.drawable.cherry); mDrawable.setBounds(new Rect(100, 400, 250, 550)); mDrawable.draw(canvas); 20
  • 21. The onTouchEvent The onTouchEvent method occurred when the user touch the screen. The (getX(), getY()) is the coordinate (x,y) axis where the screen is touched. public boolean onTouchEvent(MotionEvent event) { super.onTouchEvent(event); float x = event.getX(); float y = event.getY(); return true; } 21
  • 22. The PlayGame Activity public class PlayGame extends Activity { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); GameView gameView = new GameView(this); setContentView(gameView); } } 22
  • 23. The PlayGame Activity cont. public class PlayGame extends Activity { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); GameView gameView = new GameView(this); setContentView(gameView); } } class GameView extends View { public GameView(Context context){ } public void onDraw(Canvas canvas) { } public boolean onTouchEvent(MotionEvent event) { } } 23
  • 24. Assignment 6 1. Implement the graphic primitives in the onDraw() method of the PlayGame Activity. 2. Implement the TouchEvent method to show the coordinate (x,y) using the Toast.makeText(). 24