SlideShare a Scribd company logo
6   Android      in




              Android 2.x




                       2010/10/16
                            sak+
2010/10/16




                                                                    Android         in

  2010/10/16




                                                                 sak         sak+

                                                       Android Market

                 R    digg                        B Lite            W Free/Pro/Quad      W Free/

Pro/Quad                         CF        Free        2010/09/26



Twitter
         @_sak
E-mail 
         sakashita                  sakplus.jp

Blog    
        http://sakplus.jp/blog/




  6    Android       in                                    Android 2.x   
                         1
2010/10/16




Step 1.

          Android

Eclipse                  File > New > Android Project                       New Android Project

                                                 Finish




Project name                                         SampleDialer

Build Target                                         2.1-update1

Application name                                     SampleDialer

Package name                                         com.example.sampledialer

Create Activity                                      SampleDialer

Min SDK Version




Eclipse                  Run > Run As > Android Application




                    Hello World, SampleDialer!




 6   Android        in                                    Android 2.x   
                                 2
2010/10/16




src/com/example/sampledialer/SampleDialer.java

res/drawable-[hlm]dpi/icon.png

res/layout/main.xml

res/values/string.xml

AndroidManifest.xml




res/layout/main.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"
    >
<TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/hello"
    />
</LinearLayout>




src/com/example/sampledialer/SampleDialer.java

public class SampleDialer extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }
}




       Step 1




 6   Android    in                               Android 2.x   
                   3
2010/10/16

Step 2.




                                                                    URI



SimpleCursorAdapter




src/com/example/sampledialer/SampleDialer.java

public class Sapporo01 extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

               String filter = ContactsContract.Data.MIMETYPE + "='"
                  + ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE
                  + "'";

	         Cursor c =
            managedQuery(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
                         null, filter, null, null);
	
          SimpleCursorAdapter adapter =
	           new SimpleCursorAdapter(
	           	 this,
	           	    android.R.layout.simple_list_item_2,
	           	    c,
	                new String[] {
	           	       ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME,
	           	       ContactsContract.CommonDataKinds.Phone.NUMBER,
	           	    },
	                new int[] {
	           	       android.R.id.text1,
	           	       android.R.id.text2,
	           	    }
	           	 );
	
          ListView lv = (ListView)findViewById(R.id.ListView01);
	         lv.setAdapter(adapter);
     }
}



 6   Android        in                           Android 2.x   
                       4
2010/10/16

ListView

res/layout/main.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"
    >
<ListView
    android:id="@+id/ListView01"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"/>
</LinearLayout>




AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.example.sampledialer"
      android:versionCode="1"
      android:versionName="1.0">
    <application android:icon="@drawable/icon"
                 android:label="@string/app_name">
        <activity android:name=".Sapporo01" android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

    <uses-permission android:name="android.permission.READ_CONTACTS" />
</manifest>




 6   Android    in                         Android 2.x   
                         5
2010/10/16




Step 3.




                                  SimpleCursorAdapter

                                          SimpleCursorAdapter



SampleDialer                                      SampleDialer.java

                                                                      ic_contact_picture.png

       res/layout/drawable-mdpi




 6   Android     in                                Android 2.x   
                               6
2010/10/16

src/com/example/sampledialer/SampleDialer.java
private class MyAdapter extends SimpleCursorAdapter{
    public MyAdapter(Context context, int layout,
                                 Cursor c, String[] from, int[] to) {
        super(context, layout, c, from, to);
        setViewBinder(new MyViewBinder());
    }
}

private class MyViewBinder implements SimpleCursorAdapter.ViewBinder {
	 @Override
	 public boolean setViewValue(View view, Cursor cursor, int columnIndex) { 	
	 	 if (columnIndex == cursor.getColumnIndex(
                            ContactsContract.CommonDataKinds.Phone.PHOTO_ID)) {
	      	 String person_id = cursor.getString(columnIndex);
	      	 if (person_id == null) {
	      	 	 ((ImageView)view).setImageResource(R.drawable.ic_contact_picture);
	      	 	 return true;
	      	}

	                	   Uri uri = ContentUris.withAppendedId(
	                	   	 	 ContactsContract.Data.CONTENT_URI, Integer.parseInt(person_id));
	                	   String[] projection = { ContactsContract.CommonDataKinds.Photo.PHOTO };
	                	
	                	   Cursor c = getContentResolver().query(uri, projection, null, null, null);
	                	   byte[] photoData = null;
	                	   if (c.moveToFirst()) {
	                	   	 photoData = c.getBlob(0);
	                	   }
	       	    	       c.close();
	       	    	
	       	    	       if (photoData != null) {
	       	    	       	 ((ImageView)view).setImageBitmap(
	       	    	       	 	 	 BitmapFactory.decodeByteArray(photoData, 0, photoData.length));
	       	    	       }
	       	    	       return true;

	       	    } else if (columnIndex == cursor.getColumnIndex(
                                         ContactsContract.CommonDataKinds.Phone.TYPE)) {
	       	    	 String type;
	       	    	 int ntype = Integer.parseInt(cursor.getString(columnIndex));
	             	 if (ntype == 1) {
	             	 	 type = "    ";
	                	 } else if (ntype == 2) {
	                	 	 type = "    ";
	                	 } else if (ntype == 3) {
	                	 	 type = "    ";
	                	 } else {
	                	 	 type = "       ";
	              	}
	       	    	 ((TextView)view).setText(type);
	       	    	 return true;
	       	    }
	       	    return false;
	       }
}



    6       Android         in                              Android 2.x   
                            7
2010/10/16




                             simple_list_item_2

                                        ImageView

TextView                               item.xml




res/layout/item.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"
    >
<ImageView
    android:id="@+id/photo"
    android:layout_width="48dp"
    android:layout_height="48dp"
    android:src="@drawable/ic_contact_picture"/>
<TextView
    android:text="Name"
    android:id="@+id/name"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"/>
<TextView
    android:text="Number"
    android:id="@+id/number"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"/>
<TextView
    android:text="Type"
    android:id="@+id/type"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"/>
</LinearLayout>




 6   Android    in                         Android 2.x   
                         8
2010/10/16




src/com/example/sampledialer/SampleDialer.java
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

     String filter = ContactsContract.Data.MIMETYPE + "='"
                + ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE
                + "'";

     Cursor c =
        managedQuery(Contacts.Phones.CONTENT_URI, null, filter, null, null);

     MyAdapter adapter =
     	 new MyAdapter(
     	 	     this,
     	 	     R.layout.item,
     	 	     c,
             new String[] {
     	     	 	     ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME,
     	     	 	     ContactsContract.CommonDataKinds.Phone.NUMBER,
     	     	 	     ContactsContract.CommonDataKinds.Phone.PHOTO_ID,
     	     	 	     ContactsContract.CommonDataKinds.Phone.TYPE,
     	 	     },
             new int[] {
     	 	     	     R.id.name,
     	 	     	     R.id.number,
     	 	     	     R.id.photo,
     	 	     	     R.id.type,
     	 	     }
     	 );

     ListView lv = (ListView)findViewById(R.id.ListView01);
     lv.setAdapter(adapter);
}




 6   Android   in                                Android 2.x   
                  9
2010/10/16




Step 4.

                              RelativeLayout

           RelativeLayout




 6   Android     in         Android 2.x   
           10
2010/10/16

res/layout/item.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:padding="2dp"
    >
<ImageView
    android:id="@+id/photo"
    android:layout_width="56dp"
    android:layout_height="56dp"
    android:src="@drawable/ic_contact_picture"/>
<TextView
    android:text="Name"
    android:id="@+id/name"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_toRightOf="@id/photo"
    android:layout_marginTop="5dp"
    android:layout_marginLeft="10dp"
    android:maxWidth="190dp"
    android:singleLine="true"
    android:textSize="18dp"
    />
<TextView
    android:text="Number"
    android:id="@+id/number"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_toRightOf="@id/photo"
    android:layout_below="@id/name"
    android:layout_marginTop="5dp"
    android:layout_marginLeft="15dp"
    android:textSize="14dp"
    />
<TextView
    android:text="Type"
    android:id="@+id/type"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_toRightOf="@id/name"
    android:layout_marginTop="5dp"
    android:layout_marginRight="15dp"
    android:textSize="14dp"
    android:gravity="right"
    />
</RelativeLayout>




 6   Android    in                         Android 2.x   
                     11
2010/10/16




Step 5.




                              ACTION_DIAL

                    tel URI   tel:09012345678




 6   Android   in              Android 2.x   
          12
2010/10/16

src/com/example/sampledialer/SampleDialer.java
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);




     MyListView lv = (MyListView)findViewById(R.id.ListView01);
     lv.setDynamics(new SimpleDynamics(0.9f, 0.6f));
     lv.setAdapter(adapter);

     lv.setOnItemClickListener(new OnItemClickListener() {
         public void onItemClick(
             AdapterView<?> parent, View v, int position, long id) {
         	   call(id);
         }
     });
}

private void call(long id) {
    Uri uri = ContentUris.withAppendedId(
                 ContactsContract.CommonDataKinds.Phone.CONTENT_URI, id);
	
    Cursor c = getContentResolver().query(uri, null, null, null, null);
    c.moveToFirst();
    String number =
        (String)c.getString(c.getColumnIndex(
                     ContactsContract. CommonDataKinds.Phone.NUMBER));
    c.close();

     Intent i = new Intent(Intent.ACTION_DIAL);
     i.setData(Uri.parse("tel:" + number));
     startActivity(i);
}




 6   Android   in                                Android 2.x   
               13
2010/10/16




ACTION_DIAL           ACTION_CALL



AndroidManifest.xml

     <uses-permission android:name="android.permission.CALL_PHONE" />
     <uses-permission android:name="android.permission.CALL_PRIVILEGED" />




 6   Android   in                           Android 2.x   
                     14
2010/10/16




Step 1.

                                URL

http://blogs.sonyericsson.com/developerworld/2010/06/23/android-tutorial-making-your-own-3d-list-
part-3/




[Download] 3D List sample project – Part 3 (37kb)


                     ListTutrialPart3.zip




src/com/sonyericsson/tutrial/list3/MyListView.java

src/com/sonyericsson/tutrial/list3/TestActivity.java    SimpleDynamics
src/com/sonyericsson/util/Dynamics.java

res/drawable-ldpi/background.9.png




src                                     src                                   TestActivity.java

                                      SimpleDynamics                       SimpleDialer

                                                       TestActivity.java




          res/drawable-ldpi/backgrund.9.png                    res/drawable-mdpi




 6    Android       in                                 Android 2.x   
                                   15
2010/10/16

Step 2.




res/layout/main.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"
    >
    <com.sonyericsson.tutorial.list3.MyListView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/ListView01"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        />
</LinearLayout>




res/layout/item.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:padding="2dp"
    android:background="@drawable/background"
    >




 6   Android    in                         Android 2.x   
                        16
2010/10/16

Step 3.

                          ListView




src/com/example/sampledialer/SampleDialer.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);




     MyListView lv = (MyListView)findViewById(R.id.ListView01);
     lv.setDynamics(new SimpleDynamics(0.9f, 0.6f));
     lv.setAdapter(adapter);

     lv.setOnItemClickListener(new OnItemClickListener() {
         public void onItemClick(
             AdapterView<?> parent, View v, int position, long id) {
         	   call(id);
         }
     });
}




 6   Android   in                                Android 2.x   
              17
2010/10/16




          Android

                     CF




6   Android     in        Android 2.x   
          18

More Related Content

PDF
ハンズオン資料 電話を作ろう(v1.6用)
PPTX
Google Plus SignIn : l'Authentification Google
PPT
Android gui framework
PDF
"Android Data Binding в массы" Михаил Анохин
PDF
Михаил Анохин "Data binding 2.0"
PDF
안드로이드 데이터 바인딩
PPT
Ruby conf2012
PPTX
Mvp - типичные задачи и способ их решения в Moxy
ハンズオン資料 電話を作ろう(v1.6用)
Google Plus SignIn : l'Authentification Google
Android gui framework
"Android Data Binding в массы" Михаил Анохин
Михаил Анохин "Data binding 2.0"
안드로이드 데이터 바인딩
Ruby conf2012
Mvp - типичные задачи и способ их решения в Moxy

What's hot (16)

PDF
Android Testing
DOC
Android App Dev Manual-1.doc
PPTX
Data binding в массы! (1.2)
PPTX
Reactive Model-View-ViewModel Architecture
PDF
I os 11
PDF
Anton Minashkin Dagger 2 light
PDF
droidparts
PPTX
Android 3
PDF
I os 03
PDF
droidQuery: The Android port of jQuery
PDF
Architectures in the compose world
DOCX
package org dev
PPT
Larena3 0架构与关键技术
PDF
Android Sliding Menu dengan Navigation Drawer
PDF
Managing parallelism using coroutines
PPTX
Android dev toolbox
Android Testing
Android App Dev Manual-1.doc
Data binding в массы! (1.2)
Reactive Model-View-ViewModel Architecture
I os 11
Anton Minashkin Dagger 2 light
droidparts
Android 3
I os 03
droidQuery: The Android port of jQuery
Architectures in the compose world
package org dev
Larena3 0架构与关键技术
Android Sliding Menu dengan Navigation Drawer
Managing parallelism using coroutines
Android dev toolbox
Ad

Similar to ハンズオン資料 電話を作ろう(v2.x用) (20)

DOC
Unit5 Mobile Application Development.doc
PDF
android level 3
PPT
Android应用开发简介
PPT
MAD-Lec8 Spinner Adapater and Intents (1).ppt
PDF
Workshop 26: React Native - The Native Side
PDF
Building Modern Apps using Android Architecture Components
PPT
Android overview
PPTX
Android
PDF
Slightly Advanced Android Wear ;)
PDF
Hacking the Codename One Source Code - Part IV - Transcript.pdf
PDF
React Native for multi-platform mobile applications
PPTX
Dependency Injection for Android @ Ciklum speakers corner Kiev 29. May 2014
PPTX
Dependency Injection for Android
PPTX
Compose In Practice
PPT
Android activity, service, and broadcast recievers
PDF
Data binding в массы!
PPTX
ProTips DroidCon Paris 2013
PPT
Beginning Native Android Apps
PPTX
Introduction To Google Android (Ft Rohan Bomle)
PPTX
GDG GeorgeTown Devfest 2014 Presentation: Android Wear: A Developer's Perspec...
Unit5 Mobile Application Development.doc
android level 3
Android应用开发简介
MAD-Lec8 Spinner Adapater and Intents (1).ppt
Workshop 26: React Native - The Native Side
Building Modern Apps using Android Architecture Components
Android overview
Android
Slightly Advanced Android Wear ;)
Hacking the Codename One Source Code - Part IV - Transcript.pdf
React Native for multi-platform mobile applications
Dependency Injection for Android @ Ciklum speakers corner Kiev 29. May 2014
Dependency Injection for Android
Compose In Practice
Android activity, service, and broadcast recievers
Data binding в массы!
ProTips DroidCon Paris 2013
Beginning Native Android Apps
Introduction To Google Android (Ft Rohan Bomle)
GDG GeorgeTown Devfest 2014 Presentation: Android Wear: A Developer's Perspec...
Ad

Recently uploaded (20)

PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PPT
Teaching material agriculture food technology
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPTX
sap open course for s4hana steps from ECC to s4
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Machine learning based COVID-19 study performance prediction
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PPTX
Big Data Technologies - Introduction.pptx
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Chapter 3 Spatial Domain Image Processing.pdf
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Digital-Transformation-Roadmap-for-Companies.pptx
Advanced methodologies resolving dimensionality complications for autism neur...
The AUB Centre for AI in Media Proposal.docx
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Teaching material agriculture food technology
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
sap open course for s4hana steps from ECC to s4
Network Security Unit 5.pdf for BCA BBA.
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Machine learning based COVID-19 study performance prediction
Per capita expenditure prediction using model stacking based on satellite ima...
Diabetes mellitus diagnosis method based random forest with bat algorithm
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Mobile App Security Testing_ A Comprehensive Guide.pdf
The Rise and Fall of 3GPP – Time for a Sabbatical?
Big Data Technologies - Introduction.pptx

ハンズオン資料 電話を作ろう(v2.x用)

  • 1. 6 Android in Android 2.x 2010/10/16 sak+
  • 2. 2010/10/16 Android in 2010/10/16 sak sak+ Android Market R digg B Lite W Free/Pro/Quad W Free/ Pro/Quad CF Free 2010/09/26 Twitter @_sak E-mail sakashita sakplus.jp Blog http://sakplus.jp/blog/ 6 Android in Android 2.x 1
  • 3. 2010/10/16 Step 1. Android Eclipse File > New > Android Project New Android Project Finish Project name SampleDialer Build Target 2.1-update1 Application name SampleDialer Package name com.example.sampledialer Create Activity SampleDialer Min SDK Version Eclipse Run > Run As > Android Application Hello World, SampleDialer! 6 Android in Android 2.x 2
  • 4. 2010/10/16 src/com/example/sampledialer/SampleDialer.java res/drawable-[hlm]dpi/icon.png res/layout/main.xml res/values/string.xml AndroidManifest.xml res/layout/main.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" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /> </LinearLayout> src/com/example/sampledialer/SampleDialer.java public class SampleDialer extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } } Step 1 6 Android in Android 2.x 3
  • 5. 2010/10/16 Step 2. URI SimpleCursorAdapter src/com/example/sampledialer/SampleDialer.java public class Sapporo01 extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); String filter = ContactsContract.Data.MIMETYPE + "='" + ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE + "'"; Cursor c = managedQuery(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, filter, null, null); SimpleCursorAdapter adapter = new SimpleCursorAdapter( this, android.R.layout.simple_list_item_2, c, new String[] { ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME, ContactsContract.CommonDataKinds.Phone.NUMBER, }, new int[] { android.R.id.text1, android.R.id.text2, } ); ListView lv = (ListView)findViewById(R.id.ListView01); lv.setAdapter(adapter); } } 6 Android in Android 2.x 4
  • 6. 2010/10/16 ListView res/layout/main.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" > <ListView android:id="@+id/ListView01" android:layout_width="fill_parent" android:layout_height="fill_parent"/> </LinearLayout> AndroidManifest.xml <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.sampledialer" android:versionCode="1" android:versionName="1.0"> <application android:icon="@drawable/icon" android:label="@string/app_name"> <activity android:name=".Sapporo01" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> <uses-permission android:name="android.permission.READ_CONTACTS" /> </manifest> 6 Android in Android 2.x 5
  • 7. 2010/10/16 Step 3. SimpleCursorAdapter SimpleCursorAdapter SampleDialer SampleDialer.java ic_contact_picture.png res/layout/drawable-mdpi 6 Android in Android 2.x 6
  • 8. 2010/10/16 src/com/example/sampledialer/SampleDialer.java private class MyAdapter extends SimpleCursorAdapter{ public MyAdapter(Context context, int layout, Cursor c, String[] from, int[] to) { super(context, layout, c, from, to); setViewBinder(new MyViewBinder()); } } private class MyViewBinder implements SimpleCursorAdapter.ViewBinder { @Override public boolean setViewValue(View view, Cursor cursor, int columnIndex) { if (columnIndex == cursor.getColumnIndex( ContactsContract.CommonDataKinds.Phone.PHOTO_ID)) { String person_id = cursor.getString(columnIndex); if (person_id == null) { ((ImageView)view).setImageResource(R.drawable.ic_contact_picture); return true; } Uri uri = ContentUris.withAppendedId( ContactsContract.Data.CONTENT_URI, Integer.parseInt(person_id)); String[] projection = { ContactsContract.CommonDataKinds.Photo.PHOTO }; Cursor c = getContentResolver().query(uri, projection, null, null, null); byte[] photoData = null; if (c.moveToFirst()) { photoData = c.getBlob(0); } c.close(); if (photoData != null) { ((ImageView)view).setImageBitmap( BitmapFactory.decodeByteArray(photoData, 0, photoData.length)); } return true; } else if (columnIndex == cursor.getColumnIndex( ContactsContract.CommonDataKinds.Phone.TYPE)) { String type; int ntype = Integer.parseInt(cursor.getString(columnIndex)); if (ntype == 1) { type = " "; } else if (ntype == 2) { type = " "; } else if (ntype == 3) { type = " "; } else { type = " "; } ((TextView)view).setText(type); return true; } return false; } } 6 Android in Android 2.x 7
  • 9. 2010/10/16 simple_list_item_2 ImageView TextView item.xml res/layout/item.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" > <ImageView android:id="@+id/photo" android:layout_width="48dp" android:layout_height="48dp" android:src="@drawable/ic_contact_picture"/> <TextView android:text="Name" android:id="@+id/name" android:layout_width="wrap_content" android:layout_height="wrap_content"/> <TextView android:text="Number" android:id="@+id/number" android:layout_width="wrap_content" android:layout_height="wrap_content"/> <TextView android:text="Type" android:id="@+id/type" android:layout_width="wrap_content" android:layout_height="wrap_content"/> </LinearLayout> 6 Android in Android 2.x 8
  • 10. 2010/10/16 src/com/example/sampledialer/SampleDialer.java @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); String filter = ContactsContract.Data.MIMETYPE + "='" + ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE + "'"; Cursor c = managedQuery(Contacts.Phones.CONTENT_URI, null, filter, null, null); MyAdapter adapter = new MyAdapter( this, R.layout.item, c, new String[] { ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME, ContactsContract.CommonDataKinds.Phone.NUMBER, ContactsContract.CommonDataKinds.Phone.PHOTO_ID, ContactsContract.CommonDataKinds.Phone.TYPE, }, new int[] { R.id.name, R.id.number, R.id.photo, R.id.type, } ); ListView lv = (ListView)findViewById(R.id.ListView01); lv.setAdapter(adapter); } 6 Android in Android 2.x 9
  • 11. 2010/10/16 Step 4. RelativeLayout RelativeLayout 6 Android in Android 2.x 10
  • 12. 2010/10/16 res/layout/item.xml <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:padding="2dp" > <ImageView android:id="@+id/photo" android:layout_width="56dp" android:layout_height="56dp" android:src="@drawable/ic_contact_picture"/> <TextView android:text="Name" android:id="@+id/name" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_toRightOf="@id/photo" android:layout_marginTop="5dp" android:layout_marginLeft="10dp" android:maxWidth="190dp" android:singleLine="true" android:textSize="18dp" /> <TextView android:text="Number" android:id="@+id/number" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_toRightOf="@id/photo" android:layout_below="@id/name" android:layout_marginTop="5dp" android:layout_marginLeft="15dp" android:textSize="14dp" /> <TextView android:text="Type" android:id="@+id/type" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_toRightOf="@id/name" android:layout_marginTop="5dp" android:layout_marginRight="15dp" android:textSize="14dp" android:gravity="right" /> </RelativeLayout> 6 Android in Android 2.x 11
  • 13. 2010/10/16 Step 5. ACTION_DIAL tel URI tel:09012345678 6 Android in Android 2.x 12
  • 14. 2010/10/16 src/com/example/sampledialer/SampleDialer.java @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); MyListView lv = (MyListView)findViewById(R.id.ListView01); lv.setDynamics(new SimpleDynamics(0.9f, 0.6f)); lv.setAdapter(adapter); lv.setOnItemClickListener(new OnItemClickListener() { public void onItemClick( AdapterView<?> parent, View v, int position, long id) { call(id); } }); } private void call(long id) { Uri uri = ContentUris.withAppendedId( ContactsContract.CommonDataKinds.Phone.CONTENT_URI, id); Cursor c = getContentResolver().query(uri, null, null, null, null); c.moveToFirst(); String number = (String)c.getString(c.getColumnIndex( ContactsContract. CommonDataKinds.Phone.NUMBER)); c.close(); Intent i = new Intent(Intent.ACTION_DIAL); i.setData(Uri.parse("tel:" + number)); startActivity(i); } 6 Android in Android 2.x 13
  • 15. 2010/10/16 ACTION_DIAL ACTION_CALL AndroidManifest.xml <uses-permission android:name="android.permission.CALL_PHONE" /> <uses-permission android:name="android.permission.CALL_PRIVILEGED" /> 6 Android in Android 2.x 14
  • 16. 2010/10/16 Step 1. URL http://blogs.sonyericsson.com/developerworld/2010/06/23/android-tutorial-making-your-own-3d-list- part-3/ [Download] 3D List sample project – Part 3 (37kb) ListTutrialPart3.zip src/com/sonyericsson/tutrial/list3/MyListView.java src/com/sonyericsson/tutrial/list3/TestActivity.java SimpleDynamics src/com/sonyericsson/util/Dynamics.java res/drawable-ldpi/background.9.png src src TestActivity.java SimpleDynamics SimpleDialer TestActivity.java res/drawable-ldpi/backgrund.9.png res/drawable-mdpi 6 Android in Android 2.x 15
  • 17. 2010/10/16 Step 2. res/layout/main.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" > <com.sonyericsson.tutorial.list3.MyListView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/ListView01" android:layout_width="fill_parent" android:layout_height="fill_parent" /> </LinearLayout> res/layout/item.xml <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:padding="2dp" android:background="@drawable/background" > 6 Android in Android 2.x 16
  • 18. 2010/10/16 Step 3. ListView src/com/example/sampledialer/SampleDialer.java @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); MyListView lv = (MyListView)findViewById(R.id.ListView01); lv.setDynamics(new SimpleDynamics(0.9f, 0.6f)); lv.setAdapter(adapter); lv.setOnItemClickListener(new OnItemClickListener() { public void onItemClick( AdapterView<?> parent, View v, int position, long id) { call(id); } }); } 6 Android in Android 2.x 17
  • 19. 2010/10/16 Android CF 6 Android in Android 2.x 18