有人已经发过了,我掐头去尾精简了一下
这种效果跟图和布局有很大关系,并不难。
先看布局:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <LinearLayout android:id="@+id/layout" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" android:background="@drawable/whatsnew_bg" android:gravity="center_horizontal|bottom" android:visibility="visible" > <Button android:id="@+id/btn_start" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="开始我的性生活" android:textSize="18sp" android:textColor="#FFFFFFFF" android:background="@drawable/button_bg" android:layout_marginBottom="20dip" /> </LinearLayout> <LinearLayout android:id="@+id/animLayout" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="horizontal" > <LinearLayout android:id="@+id/leftLayout" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1" > <ImageView android:layout_width="fill_parent" android:layout_height="wrap_content" android:src="/blog_article/@drawable/whatsnew_left/index.html" android:layout_weight="1" /> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="/blog_article/@drawable/whatsnew_left_m/index.html" /> </LinearLayout> <LinearLayout android:id="@+id/rightLayout" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1" > <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="/blog_article/@drawable/whatsnew_right_m/index.html" /> <ImageView android:layout_width="fill_parent" android:layout_height="wrap_content" android:src="/blog_article/@drawable/whatsnew_right/index.html" android:layout_weight="1" /> </LinearLayout> </LinearLayout> </LinearLayout>
在看代码:
package com.dl.app; import android.app.Activity; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.view.animation.Animation; import android.view.animation.AnimationUtils; import android.view.animation.Animation.AnimationListener; import android.widget.Button; import android.widget.LinearLayout; public class TestOpenDoorActivity extends Activity { private Context context; private Button btn_start; private LinearLayout layout; private LinearLayout animLayout; private LinearLayout leftLayout; private LinearLayout rightLayout; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); this.context=this; initViews(); } private void initViews(){ btn_start=(Button)findViewById(R.id.btn_start); btn_start.setOnClickListener(onClickListener); layout = (LinearLayout) findViewById(R.id.layout); animLayout = (LinearLayout) findViewById(R.id.animLayout); leftLayout = (LinearLayout) findViewById(R.id.leftLayout); rightLayout = (LinearLayout) findViewById(R.id.rightLayout); } View.OnClickListener onClickListener=new View.OnClickListener(){ @Override public void onClick(View v) { // TODO Auto-generated method stub switch (v.getId()) { case R.id.btn_start: doOpenDoor(); break; default: break; } } }; private void doOpenDoor(){ layout.setVisibility(View.GONE); animLayout.setVisibility(View.VISIBLE); Animation leftOutAnimation = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.translate_left); Animation rightOutAnimation = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.translate_right); leftLayout.setAnimation(leftOutAnimation); rightLayout.setAnimation(rightOutAnimation); leftOutAnimation.setAnimationListener(new AnimationListener() { @Override public void onAnimationStart(Animation animation) { } @Override public void onAnimationRepeat(Animation animation) { } @Override public void onAnimationEnd(Animation animation) { leftLayout.setVisibility(View.GONE); rightLayout.setVisibility(View.GONE); Intent intent = new Intent(context,OtherActivity.class); startActivity(intent); finish(); overridePendingTransition(R.anim.zoom_out_enter, R.anim.zoom_out_exit); } }); } }
其他见附件:
Google Android手机的软件为了安全性和稳定性都是默认安装到手机内存里,但是手机内存有限,所以我们会做app2sd操作,来让我们安装的软件放到sd卡上,这个操作是需要rom的支持的。
Android 2.2 可以将手机程序安装在外置的sd卡上,也就是我们平常所说的app2sd。但是,官方的app2sd非常鸡肋,需要软件自身支持安装在内存卡上才可以,也就是说用官方的app2sd,要把程序安装在内存卡上,并不是我们使用者说了算,而是软件开发者说了算。经测试安装60多个软件,其中仅有可怜的5个程序能使用官方的app2sd安装在内存卡上。所以,官方的这个app2sd就是忽悠人的。当然,现在很多第三方ROM都自带了第三方的app2sd,可以将任何程序都安装在sd卡上。
在正式介绍app2sd之前,我先要介绍下android系统的几个比较重要的目录,这是理解后面内容的基础。
/system 存放的是rom的信息;/system/app 存放rom本身附带的软件即系统软件;/system/data 存放/system/app 中核心系统软件的数据文件信息。
/data 存放的是用户的软件信息(非自带rom安装的软件);/data/app 存放用户安装的软件;/data/data 存放所有软件(包括/system/app 和 /data/app 和 /mnt/asec中装的软件)的一些lib和xml文件等数据信息;/data/dalvik-cache 存放程序的缓存文件,这里的文件都是可以删除的。
/mnt 目录,熟悉linux的人都清楚,linux默认挂载外部设备都会挂到这个目录下面去,如将sd卡挂载上去后,会生成一个/mnt/sdcard 目录。
/sdcard 目录,这是一个软链接(相当于windows的文件夹的快捷方式),链接到/mnt/sdcard 目录,即这个目录的内容就是sdcard的内容。
在Android 2.2之后的版本允许将应用程序安装于SD卡,每一个安装在SD卡的应用程序,都可以在SD卡中的/sdcard/.android_secure 目录里找到名称中有出现它的程序名,和副文件名为asec的经过特殊加密处理后的档案。当SD卡挂载于手机时,/mnt/sdcard/.android_secure 目录会被映射到/mnt/asec 目录和 /mnt/secure 目录。其中/mnt/asec 目录中主要是程序的安装目录,包括其执行文件和lib文件等;而/mnt/secure 目录中就存放程序加密后的档案。也就是说,在/mnt路径下看到的/mnt/asec目录和/mnt/secure目录并不是真正存在在手机内存或者sd卡的分区挂载目录,它们只是/mnt/sdcard/.android_secure目录的一个影像而已。
因此,用户程序安装到到sd卡上后,其内容可能分散到:/mnt/asec , /mnt/secure , /data/data 。
要实现app2sd,目前比较流行有两种方案,分别是app2ext 和 data2ext,下面分别介绍下这2种方案。
在Linux文件系统中,有一种特别的文件叫“软链接”,类似于Windows下的快捷方式,软链接可以把一个文件或者文件夹映射到别的地方,一个例子如上面介绍的/sdcard 就是/mnt/sdcard 的软链接。
app2ext的原理是,删除data区中的app文件夹,然后在sd卡的ext分区上创建一个app文件,并通过软链接映射到data区。这样系统会以为,app这个软链接是一个真实的文件夹,会把程序都安装在里面,但实际上,这些程序都安装到卡上了。但由于操作系统并不知道,所以这种情况下,我们依然看到系统显示这个程序是安装在“内置空间”的。
data2ext则更彻底,它不是用软链接,而是直接用“挂载”功能,Linux下所有的存储设备都必须挂载成一个文件夹才能进行文件操作(如sd卡就挂载在/mnt/sdcard目录下面)。data文件夹本来是对应手机内部Flash中的一个分区(为了保持术语的准确,这里要把内部Flash和内存相区别,内部Flash是ROM,内存是RAM)。而data2ext则是修改了挂载对应关系,使data文件夹挂载的不是内置Flash,而是sd卡的整个ext分区。这样,不仅是app,连存储程序设置的data和缓存dalvik-cache都会存储到sd卡中。
可以看到,dalvik-cache和data这两个文件夹的位置,是这两种方式的一个重大区别。其中dalvik-cache是虚拟机预编译缓存,data(不同于/data,这个是/data/data)是存储程序数据的地方,例如游戏的存档记录,软件的配置信息等。这样有什么区别,区别在于假如你重刷了ROM,app2ext的话,所有的程序都可以保留,但是这些程序的配置信息和游戏的存档都会丢失。而data2ext则可以连同配置和存档都保留,但是dalvik-cache也是一个容易积累垃圾的地方,这些垃圾也会一同保留。
data2ext由于是把整个data分区都放在sd卡上,因此,我们刷ROM需要WIPE的时候,这个data分区的内容就可能不会被wipe,这可以保存用户的个人资料,但是也可能造成系统莫名其妙的故障。
package com.michael.utility.contact; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import com.michael.utility.JudgeLinkmanInfo; import android.content.Context; import android.database.Cursor; import android.provider.ContactsContract; import android.provider.ContactsContract.CommonDataKinds.Email; import android.provider.ContactsContract.CommonDataKinds.Event; import android.provider.ContactsContract.CommonDataKinds.GroupMembership; import android.provider.ContactsContract.CommonDataKinds.Im; import android.provider.ContactsContract.CommonDataKinds.Nickname; import android.provider.ContactsContract.CommonDataKinds.Note; import android.provider.ContactsContract.CommonDataKinds.Organization; import android.provider.ContactsContract.CommonDataKinds.Phone; import android.provider.ContactsContract.CommonDataKinds.Relation; import android.provider.ContactsContract.CommonDataKinds.StructuredPostal; import android.provider.ContactsContract.CommonDataKinds.Website; import android.provider.ContactsContract.Data; /** * * 根据联系人的rawContactId查询出该联系人的所有信息 * 下面是调用方法 * */ public class QueryLinkmanInfoByRawContactId { private final static String NAME = "com.michael.name";//电话类型 private final static String PHONE_TYPE = "com.michael.phone_type";//电话类型 private final static String PHONE = "com.michael.phone";//电话类型所对应的电话号码 private final static String PHONE_CUSTOM = "com.michael.phone.custom";//存放自定义的号码,如果不是自定义的话,这个为null private final static String EMAIL_TYPE = "com.michael.mail.type";//邮件 private final static String EMAIL = "com.michael.mail"; private final static String EMAIL_CUSTOM = "com.michael.mail.custom"; private final static String IM_TYPE = "com.michael.im.type";//即时消息 private final static String IM = "com.michael.im"; private final static String IM_CUSTOM = "com.michael.im.custom"; private final static String EVENT_TYPE = "com.michael.event.type";//事件 private final static String EVENT_TIME = "com.michael.event"; private final static String EVENT_CUSTOM = "com.michael.event.custom"; private final static String ADDRESS_TYPE = "com.michael.address.type";//地址 private final static String ADDRESS = "com.michael.address"; private final static String ADDRESS_CUSTOM = "com.michael.address.custom"; private final static String NOTE = "com.michael.note";//备注 private final static String NICKNAME = "com.michael.nickname";//昵称 private final static String WEBSITE = "com.michael.website";//网站 // private final static String GROUP_TYPE = "com.michael.group.type"; private final static String GROUP_NAME = "com.michael.group.name"; private final static String ORGANIZATION_TYPE = "com.michael.organization.type"; private final static String ORGANIZATION_COMPANY = "com.michael.organization.company"; private final static String ORGANIZATION_POSITION = "com.michael.organization.position"; private final static String ORGANIZATION_CUSTOM = "com.michael.organization.custom"; // private final static String RELATION_NAME = "com.michael.relation.name"; // private final static String RELATION_TYPE = "com.michael.relation,type"; private static List<HashMap<String, String>> listOfResolvedName;//姓名 private static List<HashMap<String, String>> listOfResolvedPhone;//电话 private static List<HashMap<String, String>> listOfResolvedEmail;//邮件 private static List<HashMap<String, String>> listOfResolvedNickname;//昵称 private static List<HashMap<String, String>> listOfResolvedIm;//即时通讯 private static List<HashMap<String, String>> listOfResolvedAddress;//地址 private static List<HashMap<String, String>> listOfResolvedWebsite;//网站 private static List<HashMap<String, String>> listOfResolvedEvent;//事件 private static List<HashMap<String, String>> listOfResolvedOrganization;//组织(公司) private static List<HashMap<String, String>> listOfResolvedRelation;//关系 private static List<HashMap<String, String>> listOfResolvedNote;//备注 private static List<HashMap<String, StringBuffer>> listOfResolvedGroup;//分组 private static List<HashMap<String, String>> listOfResolvedLocation;//位置 /** * 查询姓名 * */ public static List<HashMap<String, String>> queryNameInfo(Context context, String rawContactId) { Cursor cursorOfName = context.getContentResolver().query( Data.CONTENT_URI, //查询data表 new String[]{ Data.DISPLAY_NAME,//姓名 }, Data.RAW_CONTACT_ID + " = ? ", new String[]{ rawContactId }, null); while(cursorOfName.moveToNext()) { String name = cursorOfName.getString(cursorOfName.getColumnIndex(Data.DISPLAY_NAME)); HashMap<String, String> nameMap = new HashMap<String, String>(); nameMap.put(NAME, name); listOfResolvedName = new ArrayList<HashMap<String, String>>(); listOfResolvedName.add(nameMap); System.out.println("解析出名字:" + nameMap); } return listOfResolvedName; } /** * 查询出电话的信息 * */ public static List<HashMap<String, String>> queryPhoneInfo(Context context, String rawContactId) { Cursor cursorOfPhone = context.getContentResolver().query( Data.CONTENT_URI, //查询data表 new String[]{ Phone.NUMBER,//号码 Phone.TYPE,//号码类型,自定义类型是0,自定义的名称保存在data3中,所以data3也需要读取出来 Phone.DATA3,//自定义类型的名称保存在这个字段里面,如果有多个自定义,类型值都是0 }, Data.RAW_CONTACT_ID + " = ? and " +Data.MIMETYPE+" = ? ", new String[]{ rawContactId, Phone.CONTENT_ITEM_TYPE, }, null); System.out.println("Cursor.getCount()" + cursorOfPhone.getCount()); //用来存放联系人信息(<电话类型,号码>) List<HashMap<String, String>> listOfPhone = new ArrayList<HashMap<String, String>>(); while(cursorOfPhone.moveToNext()) { String phoneType = cursorOfPhone.getString(cursorOfPhone.getColumnIndex(Phone.TYPE)); String phone = cursorOfPhone.getString(cursorOfPhone.getColumnIndex(Phone.NUMBER)); String phoneCustom = cursorOfPhone.getString(cursorOfPhone.getColumnIndex(Phone.DATA3)); HashMap<String, String> phoneMap = new HashMap<String, String>(); phoneMap.put(PHONE_TYPE, phoneType); phoneMap.put(PHONE, phone); phoneMap.put(PHONE_CUSTOM, phoneCustom); System.out.println("电话:" + phoneMap); if(phone.equals("")) { //什么都不做 } else { listOfPhone.add(phoneMap);//添加一个号码到数组中 } } cursorOfPhone.close(); // List<HashMap<String, String>> listOfResolvedPhone = new ArrayList<HashMap<String,String>>(); listOfResolvedPhone = new ArrayList<HashMap<String,String>>(); System.out.println("哈罗:listOfPhone:" + listOfPhone); listOfResolvedPhone = JudgeLinkmanInfo.getPhoneType(listOfPhone); return listOfResolvedPhone; } /** * 查询邮件信息 * * */ public static List<HashMap<String, String>> queryEmailInfo(Context context, String rawContactId) { Cursor cursorOfEmail = context.getContentResolver().query( Data.CONTENT_URI, //查询data表 new String[]{ Email.DATA1,//Emial地址 Email.TYPE,//号码类型,自定义类型是0,自定义的名称保存在data3中,所以data3也需要读取出来//Data2 Data.DATA3//自定义的类型名 }, Data.RAW_CONTACT_ID + " = ? and " +Data.MIMETYPE+" = ? ", new String[]{ rawContactId, Email.CONTENT_ITEM_TYPE, }, null); //用来存放Email信息(邮件类型,邮件地址) List<HashMap<String, String>> listOfEmail = new ArrayList<HashMap<String, String>>(); while(cursorOfEmail.moveToNext()) { String emailType = cursorOfEmail.getString(cursorOfEmail.getColumnIndex(ContactsContract.CommonDataKinds.Email.TYPE)); String email = cursorOfEmail.getString(cursorOfEmail.getColumnIndex(Email.DATA1));//Email地址 String customEmail = cursorOfEmail.getString(cursorOfEmail.getColumnIndex(Email.DATA3)); HashMap<String, String> emailMap = new HashMap<String, String>(); emailMap.put(EMAIL_TYPE, emailType); emailMap.put(EMAIL, email); emailMap.put(EMAIL_CUSTOM, customEmail); System.out.println("邮件:" + emailMap); listOfEmail.add(emailMap);//添加一个号码到数组中 } cursorOfEmail.close(); // List<HashMap<String, String>> listOfResolvedEmail = new ArrayList<HashMap<String,String>>(); listOfResolvedEmail = new ArrayList<HashMap<String,String>>(); listOfResolvedEmail = JudgeLinkmanInfo.getEmailType(listOfEmail);//将Email解析出来 return listOfResolvedEmail; } /** * 查询昵称信息 * */ public static List<HashMap<String, String>> queryNicknameInfo(Context context, String rawContactId) { Cursor cursorOfNickname = context.getContentResolver().query( Data.CONTENT_URI, //查询data表 new String[]{ ContactsContract.CommonDataKinds.Nickname.NAME, }, Data.RAW_CONTACT_ID + " = ? and " +Data.MIMETYPE+" = ? ", new String[]{ rawContactId, Nickname.CONTENT_ITEM_TYPE, }, null); //用来存放昵称信息 // List<HashMap<String, String>> listOfNickname = new ArrayList<HashMap<String, String>>(); listOfResolvedNickname = new ArrayList<HashMap<String,String>>(); while(cursorOfNickname.moveToNext()) { String nickname = cursorOfNickname.getString(cursorOfNickname.getColumnIndex(ContactsContract.CommonDataKinds.Nickname.NAME)); if(nickname != null)//昵称不为空的时候,才添加,不如null也会被添加 { HashMap<String, String> nicknameMap = new HashMap<String, String>(); nicknameMap.put(NICKNAME, nickname); System.out.println("昵称:" + nicknameMap); listOfResolvedNickname.add(nicknameMap); } // listOfNickname.add(nicknameMap);//添加一个昵称到数组中 } cursorOfNickname.close(); return listOfResolvedNickname; } /** * 即时消息 * */ public static List<HashMap<String, String>> queryImInfo(Context context, String rawContactId) { Cursor cursorOfIm = context.getContentResolver().query( Data.CONTENT_URI, //查询data表 new String[]{ Im.DATA5,//即时消息类型 Im.TYPE,//注意:这个类型指的是Home ,work那种!!不是QQ Im.DATA1,//即时消息保存的值 Im.DATA6//自定义即时消息的名称 }, Data.RAW_CONTACT_ID + " = ? and " +Data.MIMETYPE+" = ? ", new String[]{ rawContactId, Im.CONTENT_ITEM_TYPE, }, null); //用来存放即时消息 List<HashMap<String, String>> listOfIm = new ArrayList<HashMap<String, String>>(); while(cursorOfIm.moveToNext()) { //DATA5保存的是类型,而不是TYPE,TYPE指的是家庭,单位那种。现在查询没有问题了 //IM类型为什么会是null,第一次查询不是null,保存后查询变为null,所以问题是插入失败了! String imType = cursorOfIm.getString(cursorOfIm.getColumnIndex(Im.DATA5));//null String im = cursorOfIm.getString(cursorOfIm.getColumnIndex(Im.DATA1));//IM值 String customIm = cursorOfIm.getString(cursorOfIm.getColumnIndex(Im.DATA6));//自定义Im名称DATA6 System.out.println("我靠:" + cursorOfIm.getString(cursorOfIm.getColumnIndex(Im.DATA5))); HashMap<String, String> imMap = new HashMap<String, String>(); imMap.put(IM_TYPE, imType); imMap.put(IM, im); imMap.put(IM_CUSTOM, customIm); System.out.println("即时消息:" + imMap); listOfIm.add(imMap);//添加一个号码到数组中 } cursorOfIm.close(); listOfResolvedIm = new ArrayList<HashMap<String,String>>(); System.out.println("listOfIm:" + listOfIm);//type都变成null了 listOfResolvedIm = JudgeLinkmanInfo.getImType(listOfIm);//将Im解析出来111111111111 return listOfResolvedIm; } /** * 查询地址 * */ public static List<HashMap<String, String>> queryAddressInfo(Context context, String rawContactId) { Cursor cursorOfAddress = context.getContentResolver().query( Data.CONTENT_URI, //查询data表 new String[]{ ContactsContract.CommonDataKinds.StructuredPostal.TYPE,//地址类型(单位,住宅..) StructuredPostal.DATA1,//地址的值 StructuredPostal.DATA3//自定义即时消息的名称 }, Data.RAW_CONTACT_ID + " = ? and " +Data.MIMETYPE+" = ? ", new String[]{ rawContactId, StructuredPostal.CONTENT_ITEM_TYPE, }, null); //用来存放地址信息 List<HashMap<String, String>> listOfAddress = new ArrayList<HashMap<String, String>>(); while(cursorOfAddress.moveToNext()) { String addressType = cursorOfAddress.getString(cursorOfAddress.getColumnIndex(ContactsContract.CommonDataKinds.StructuredPostal.TYPE));//IM类型 String address = cursorOfAddress.getString(cursorOfAddress.getColumnIndex(StructuredPostal.DATA1));//地址值 String customAddress = cursorOfAddress.getString(cursorOfAddress.getColumnIndex(StructuredPostal.DATA3));//自定义Im名称 HashMap<String, String> addressMap = new HashMap<String, String>(); addressMap.put(ADDRESS_TYPE, addressType); addressMap.put(ADDRESS, address); addressMap.put(ADDRESS_CUSTOM, customAddress); System.out.println("地址:" + addressMap); listOfAddress.add(addressMap);//添加一个号码到数组中 } cursorOfAddress.close(); listOfResolvedAddress = new ArrayList<HashMap<String,String>>(); listOfResolvedAddress = JudgeLinkmanInfo.getAddressType(listOfAddress);//将Im解析出来 return listOfResolvedAddress; } /** * 查询网站 * */ public static List<HashMap<String, String>> queryWebsiteInfo(Context context, String rawContactId) { Cursor cursorOfWebsite = context.getContentResolver().query( Data.CONTENT_URI, //查询data表 new String[]{ ContactsContract.CommonDataKinds.Website.DATA1,//网站的地址 }, Data.RAW_CONTACT_ID + " = ? and " +Data.MIMETYPE+" = ? ", new String[]{ rawContactId, Website.CONTENT_ITEM_TYPE, }, null); //用来存放网站信息 // List<HashMap<String, String>> listOfWebsite = new ArrayList<HashMap<String, String>>(); listOfResolvedWebsite = new ArrayList<HashMap<String,String>>(); while(cursorOfWebsite.moveToNext()) { String website = cursorOfWebsite.getString(cursorOfWebsite.getColumnIndex(ContactsContract.CommonDataKinds.Website.DATA1)); HashMap<String, String> websiteMap = new HashMap<String, String>(); websiteMap.put(WEBSITE, website); System.out.println("网站:" + websiteMap); // listOfWebsite.add(websiteMap);//添加一个昵称到数组中 listOfResolvedWebsite.add(websiteMap); } cursorOfWebsite.close(); return listOfResolvedWebsite; } /** * 查询事件 * */ public static List<HashMap<String, String>> queryEventInfo(Context context, String rawContactId) { Cursor cursorOfEvent = context.getContentResolver().query( Data.CONTENT_URI, //查询data表 new String[]{ ContactsContract.CommonDataKinds.Event.START_DATE,//事件时间 Event.TYPE,//事件类型 Event.DATA3//自定义事件名称 }, Data.RAW_CONTACT_ID + " = ? and " +Data.MIMETYPE+" = ? ", new String[]{ rawContactId, Event.CONTENT_ITEM_TYPE, }, null); //用来存放 List<HashMap<String, String>> listOfEvent = new ArrayList<HashMap<String, String>>(); while(cursorOfEvent.moveToNext()) { String eventTime = cursorOfEvent.getString(cursorOfEvent.getColumnIndex(ContactsContract.CommonDataKinds.Event.START_DATE));//事件时间 String eventType = cursorOfEvent.getString(cursorOfEvent.getColumnIndex(ContactsContract.CommonDataKinds.Event.TYPE));//事件类型,生日等等 String customEvent = cursorOfEvent.getString(cursorOfEvent.getColumnIndex(ContactsContract.CommonDataKinds.Event.DATA3));//自定义事件名称 HashMap<String, String> eventMap = new HashMap<String, String>(); eventMap.put(EVENT_TYPE, eventType); eventMap.put(EVENT_TIME, eventTime); eventMap.put(EVENT_CUSTOM, customEvent); System.out.println("事件:" + eventMap); listOfEvent.add(eventMap);//添加一个昵称到数组中 } cursorOfEvent.close(); listOfResolvedEvent = new ArrayList<HashMap<String,String>>(); listOfResolvedEvent = JudgeLinkmanInfo.getEventType(listOfEvent);//将Im解析出来 return listOfResolvedEvent; } /** * 查询组织 * */ public static List<HashMap<String, String>> queryOrganizationInfo(Context context, String rawContactId) { Cursor cursorOfOrganization = context.getContentResolver().query( Data.CONTENT_URI, //查询data表 new String[]{ ContactsContract.CommonDataKinds.Organization.COMPANY,//公司 Organization.TITLE,//职位 Organization.TYPE,//类型 Organization.DATA3//自定义名称 }, Data.RAW_CONTACT_ID + " = ? and " +Data.MIMETYPE+" = ? ", new String[]{ rawContactId, Organization.CONTENT_ITEM_TYPE, }, null); System.out.println("OrganizationCount:" + cursorOfOrganization.getCount()); //用来存放 List<HashMap<String, String>> listOfOrganization = new ArrayList<HashMap<String, String>>(); while(cursorOfOrganization.moveToNext()) { String type = cursorOfOrganization.getString(cursorOfOrganization.getColumnIndex(Organization.TYPE));//类型,没用了 String company = cursorOfOrganization.getString(cursorOfOrganization.getColumnIndex(Organization.COMPANY));//公司 String title = cursorOfOrganization.getString(cursorOfOrganization.getColumnIndex(Organization.TITLE));//职位 String customTypeName = cursorOfOrganization.getString(cursorOfOrganization.getColumnIndex(Organization.DATA3));//取出自定义的名称,如果没有就是null HashMap<String, String> organizationMap = new HashMap<String, String>(); organizationMap.put(ORGANIZATION_TYPE, type); organizationMap.put(ORGANIZATION_CUSTOM, customTypeName); organizationMap.put(ORGANIZATION_COMPANY, company); organizationMap.put(ORGANIZATION_POSITION, title); System.out.println("组织:" + organizationMap); listOfOrganization.add(organizationMap);//添加一个昵称到数组中 } cursorOfOrganization.close(); listOfResolvedOrganization = new ArrayList<HashMap<String,String>>(); listOfResolvedOrganization = JudgeLinkmanInfo.getOrganizationType(listOfOrganization);//将Im解析出来 return listOfResolvedOrganization; } /** * 查询关系 * */ private final static String RELATION_NAME = "com.michael.relation.name"; private final static String RELATION_TYPE = "com.michael.relation.type"; private final static String RELATION_CUSTOM = "com.michael.relation.custom"; // private final static String LD_RELATION_ID = ""; // private final static String LD_RELATION_TYPE = ""; // private final static String LD_RELATION_NAME = ""; public static List<HashMap<String, String>> queryRelationInfo(Context context, String rawContactId) { Cursor cursorOfRelation = context.getContentResolver().query( Data.CONTENT_URI, //查询data表 new String[]{ ContactsContract.CommonDataKinds.Relation.NAME,//关系 Relation.TYPE,//关系类型,父子等等 Relation.DATA3 }, Data.RAW_CONTACT_ID + " = ? and " +Data.MIMETYPE+" = ? ", new String[]{ rawContactId, Relation.CONTENT_ITEM_TYPE, }, null); System.out.println("RelationCount:" + cursorOfRelation.getCount()); //用来存放 List<HashMap<String, String>> listOfRelation = new ArrayList<HashMap<String, String>>(); while(cursorOfRelation.moveToNext()) { String relationName = cursorOfRelation.getString(cursorOfRelation.getColumnIndex(Relation.NAME));//关系中保存的字符 String relationType = cursorOfRelation.getString(cursorOfRelation.getColumnIndex(Relation.TYPE));//关系类型 String relationCustom = cursorOfRelation.getString(cursorOfRelation.getColumnIndex(Relation.DATA3));//自定义的关系名 HashMap<String, String> relationMap = new HashMap<String, String>(); relationMap.put(RELATION_CUSTOM, relationCustom); relationMap.put(RELATION_NAME, relationName); relationMap.put(RELATION_TYPE, relationType); System.out.println("关系:" + relationMap); listOfRelation.add(relationMap);//添加一个昵称到数组中 // listOfResolvedRelation.add(relationMap); } listOfResolvedRelation = new ArrayList<HashMap<String,String>>(); listOfResolvedRelation = JudgeLinkmanInfo.getRelationType(listOfRelation); cursorOfRelation.close(); return listOfResolvedRelation; } /** * 查询备注 * */ public static List<HashMap<String, String>> queryNoteInfo(Context context, String rawContactId) { Cursor cursorOfNote = context.getContentResolver().query( Data.CONTENT_URI, //查询data表 new String[]{ ContactsContract.CommonDataKinds.Note.NOTE,//备注的内容 }, Data.RAW_CONTACT_ID + " = ? and " +Data.MIMETYPE+" = ? ", new String[]{ rawContactId, Note.CONTENT_ITEM_TYPE, }, null); //用来存放备注信息 // List<HashMap<String, String>> listOfNote = new ArrayList<HashMap<String, String>>(); listOfResolvedNote = new ArrayList<HashMap<String,String>>(); while(cursorOfNote.moveToNext()) { String note = cursorOfNote.getString(cursorOfNote.getColumnIndex(ContactsContract.CommonDataKinds.Note.NOTE));// if(note != null)//这里要注意&& !note.equals("") { HashMap<String, String> noteMap = new HashMap<String, String>(); noteMap.put(NOTE, note); System.out.println("备注:" + noteMap); listOfResolvedNote.add(noteMap); } } cursorOfNote.close(); return listOfResolvedNote; } /** * 查询分组 * */ public static List<HashMap<String, StringBuffer>> queryGroupInfo(Context context, String rawContactId) { //群组.和Organization没有任何关系,在2.1中的数据库中有分组,但是系统没有提供实现,在4.0里面有实现 //你需要做的是,找到当前用户的GROUP_ROW_ID,根据这个GROUP_ROW_ID再去查找Group表中的TItle,这个Title就是分组的名字了 Cursor cursorOfGroup = context.getContentResolver().query( Data.CONTENT_URI, //查询data表 new String[]{ // Data.DATA1 ContactsContract.CommonDataKinds.GroupMembership.GROUP_ROW_ID,//这个是分组的名称 // GroupMembership.DATA2,//类型。0代表自定义 // GroupMembership.DATA3//自定义名称 }, Data.RAW_CONTACT_ID + " = ? and " +Data.MIMETYPE+" = ? ", new String[]{ rawContactId, GroupMembership.CONTENT_ITEM_TYPE, }, null); // listOfGroupRawId = new ArrayList<Integer>(); // listOfGroupRawTitle = new ArrayList<String>(); //用来存放 // List<HashMap<String, String>> listOfGroup = new ArrayList<HashMap<String, String>>(); StringBuffer sb = new StringBuffer(); listOfResolvedGroup = new ArrayList<HashMap<String, StringBuffer>>(); while(cursorOfGroup.moveToNext()) { //这个GroupRawId是自动增长的吗?应该是的 String groupRawId = cursorOfGroup.getString(cursorOfGroup.getColumnIndex(ContactsContract.CommonDataKinds.GroupMembership.GROUP_ROW_ID));// Cursor cursor = context.getContentResolver().query( ContactsContract.Groups.CONTENT_URI, new String[]{ // ContactsContract.Groups.ACCOUNT_TYPE, ContactsContract.Groups.TITLE }, ContactsContract.Groups._ID + " = ? ", new String[]{ groupRawId }, null ); while(cursor.moveToNext()) { // String groupType = cursor.getString(cursor.getColumnIndex(ContactsContract.Groups.ACCOUNT_TYPE)); String groupName = cursor.getString(cursor.getColumnIndex(ContactsContract.Groups.TITLE)); // HashMap<String, String> groupMap = new HashMap<String, String>(); // groupMap.put(GROUP_TYPE, groupType);// // groupMap.put(GROUP_NAME, groupName); // System.out.println("群组:" + groupName); // listOfGroup.add(groupMap); sb.append(groupName + "\n");//查询出一个就换行,优化显示效果 // sb.append(groupName); System.out.println("groupRawId:" + groupRawId + "groupName:" + groupName); // listOfGroupRawId.add(Integer.parseInt(groupRawId));//保存分组的Id // listOfGroupRawTitle.add(groupName);//保存分组的名称 } cursor.close(); } cursorOfGroup.close(); HashMap<String, StringBuffer> groupMap = new HashMap<String, StringBuffer>(); if(sb.length() != 0)//说明有分组 { sb.setLength(sb.length()-1);//去掉sb最后的两个"\n"哈哈哈,给力啊! } groupMap.put(GROUP_NAME, sb); listOfResolvedGroup.add(groupMap); return listOfResolvedGroup; } private static final String MINETYPE_LOCATION="vnd.android.cursor.item/location"; //存放经度 private static final String FIELD_LATITUDE= "data9"; //存放纬度 private static final String FIELD_LONGITUDE= "data10"; //存放当前地图的ZoomLevel private static final String FIELD_ZOOM_LEVEL = "data11"; private static final String LATITUDE_FROM_QUERY = "com.michael.queryLinkmanInfoByRawContactId.latitude"; private static final String LONGITUDE_FROM_QUERY = "com.michael.queryLinkmanInfoByRawContactId.longitude"; private static final String ZOOM_LEVEL_FROM_QUERY = "com.michael.queryLinkmanInfoByRawContactId.zoomLevel"; /** * 查询位置 * */ public static List<HashMap<String, String>> queryLocationInfo(Context context, String rawContactId) { Cursor cursorOfLocation = context.getContentResolver().query( Data.CONTENT_URI, //查询data表 new String[]{ FIELD_LATITUDE, FIELD_LONGITUDE, FIELD_ZOOM_LEVEL//经纬度和地图的缩放比例 }, Data.RAW_CONTACT_ID + " = ? and " +Data.MIMETYPE+" = ? ", new String[]{ rawContactId, MINETYPE_LOCATION, }, null); listOfResolvedLocation = new ArrayList<HashMap<String,String>>(); while(cursorOfLocation.moveToNext()) { String latitude = cursorOfLocation.getString(cursorOfLocation.getColumnIndex(FIELD_LATITUDE));// String longitude = cursorOfLocation.getString(cursorOfLocation.getColumnIndex(FIELD_LONGITUDE)); String zoomLevel = cursorOfLocation.getString(cursorOfLocation.getColumnIndex(FIELD_ZOOM_LEVEL)); if(latitude != null)//说明存在经纬度 { HashMap<String, String> locationMap = new HashMap<String, String>(); locationMap.put(LATITUDE_FROM_QUERY, latitude); locationMap.put(LONGITUDE_FROM_QUERY, longitude); locationMap.put(ZOOM_LEVEL_FROM_QUERY, zoomLevel); System.out.println("位置:" + locationMap); listOfResolvedLocation.add(locationMap); } } cursorOfLocation.close(); return listOfResolvedLocation; } }