Просмотр исходного кода

Initial commit for ContentProviderContactsList project.

Cristian Tanas 11 лет назад
Родитель
Сommit
5d1eaa7e93

+ 33 - 0
ContentProviderContactsList/AndroidManifest.xml

@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="utf-8"?>
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+    package="org.uab.android.contentprovider.contactslist"
+    android:versionCode="1"
+    android:versionName="1.0" >
+
+    <uses-sdk
+        android:minSdkVersion="14"
+        android:targetSdkVersion="19" />
+    
+    <uses-permission android:name="android.permission.READ_CONTACTS"/>
+
+    <application
+        android:allowBackup="true"
+        android:icon="@drawable/ic_launcher"
+        android:label="@string/app_name"
+        android:theme="@style/AppTheme" >
+        <activity
+            android:name=".MainActivity"
+            android:label="@string/app_name" >
+            <intent-filter>
+                <action android:name="android.intent.action.MAIN" />
+
+                <category android:name="android.intent.category.LAUNCHER" />
+            </intent-filter>
+        </activity>
+        
+        <provider 
+            android:name=".CoursesProvider"
+            android:authorities="org.uab.android.contentprovider.sqlite.provider"></provider>
+    </application>
+
+</manifest>

BIN
ContentProviderContactsList/ic_launcher-web.png


BIN
ContentProviderContactsList/libs/android-support-v4.jar


BIN
ContentProviderContactsList/res/drawable-hdpi/ic_launcher.png


BIN
ContentProviderContactsList/res/drawable-mdpi/ic_launcher.png


BIN
ContentProviderContactsList/res/drawable-xhdpi/ic_launcher.png


BIN
ContentProviderContactsList/res/drawable-xxhdpi/ic_launcher.png


+ 11 - 0
ContentProviderContactsList/res/values-v11/styles.xml

@@ -0,0 +1,11 @@
+<resources>
+
+    <!--
+        Base application theme for API 11+. This theme completely replaces
+        AppBaseTheme from res/values/styles.xml on API 11+ devices.
+    -->
+    <style name="AppBaseTheme" parent="android:Theme.Holo.Light">
+        <!-- API 11 theme customizations can go here. -->
+    </style>
+
+</resources>

+ 12 - 0
ContentProviderContactsList/res/values-v14/styles.xml

@@ -0,0 +1,12 @@
+<resources>
+
+    <!--
+        Base application theme for API 14+. This theme completely replaces
+        AppBaseTheme from BOTH res/values/styles.xml and
+        res/values-v11/styles.xml on API 14+ devices.
+    -->
+    <style name="AppBaseTheme" parent="android:Theme.Holo.Light.DarkActionBar">
+        <!-- API 14 theme customizations can go here. -->
+    </style>
+
+</resources>

+ 7 - 0
ContentProviderContactsList/res/values/strings.xml

@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+
+    <string name="app_name">ContentProviderContactsList</string>
+    <string name="hello_world">Hello world!</string>
+
+</resources>

+ 20 - 0
ContentProviderContactsList/res/values/styles.xml

@@ -0,0 +1,20 @@
+<resources>
+
+    <!--
+        Base application theme, dependent on API level. This theme is replaced
+        by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
+    -->
+    <style name="AppBaseTheme" parent="android:Theme.Light">
+        <!--
+            Theme customizations available in newer API levels can go in
+            res/values-vXX/styles.xml, while customizations related to
+            backward-compatibility can go here.
+        -->
+    </style>
+
+    <!-- Application theme. -->
+    <style name="AppTheme" parent="AppBaseTheme">
+        <!-- All customizations that are NOT specific to a particular API-level can go here. -->
+    </style>
+
+</resources>

+ 50 - 0
ContentProviderContactsList/src/org/uab/android/contentprovider/contactslist/MainActivity.java

@@ -0,0 +1,50 @@
+package org.uab.android.contentprovider.contactslist;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import android.app.ListActivity;
+import android.content.ContentResolver;
+import android.database.Cursor;
+import android.os.Bundle;
+import android.provider.ContactsContract;
+import android.widget.ArrayAdapter;
+
+public class MainActivity extends ListActivity {
+
+	@Override
+	protected void onCreate(Bundle savedInstanceState) {
+		super.onCreate(savedInstanceState);
+		
+		// Get a reference to the ContentResolver
+		ContentResolver contentResolver = getContentResolver();
+		
+		// Query the ContentResolver for the name of all contacts stored in the device
+		Cursor contactsListCursor = contentResolver.query(
+				ContactsContract.Contacts.CONTENT_URI, 
+				new String[] {ContactsContract.Contacts.DISPLAY_NAME}, 
+				null, 
+				null, 
+				null);
+		
+		// Create an ArrayList of String from the Cursor previously obtained
+		List<String> contacts = new ArrayList<String>();
+		if (contactsListCursor.moveToFirst()) {
+			do {
+				
+				contacts.add(
+						contactsListCursor.getString(
+								contactsListCursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME)
+								)
+						);
+				
+			} while (contactsListCursor.moveToNext());
+		}
+		
+		// Create an ArrayAdapter for the ArrayList previously created
+		ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, contacts);
+		
+		// Set the list's adapter
+		setListAdapter(adapter);
+	}
+}