当前位置: 首页>>代码示例>>Java>>正文


Java Photo类代码示例

本文整理汇总了Java中android.provider.ContactsContract.CommonDataKinds.Photo的典型用法代码示例。如果您正苦于以下问题:Java Photo类的具体用法?Java Photo怎么用?Java Photo使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Photo类属于android.provider.ContactsContract.CommonDataKinds包,在下文中一共展示了Photo类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: loadContact2

import android.provider.ContactsContract.CommonDataKinds.Photo; //导入依赖的package包/类
public static List<ContactEntity> loadContact2(Context context){
	List<ContactEntity> contacts=new ArrayList<ContactEntity>();
	ContentResolver cr=context.getContentResolver();
	String [] projection={Phone.DISPLAY_NAME,Phone.NUMBER,Photo.PHOTO_ID,Phone.CONTACT_ID};
	Cursor c=cr.query(Phone.CONTENT_URI, projection, null, null, null);
	if(c!=null){
		while(c.moveToNext()){
			String name=c.getString(0);
			String number=c.getString(1);
			long contactId=c.getLong(3);
			long photoId=c.getLong(2);
			Bitmap bitmap=null;
			if(photoId>0){
				Uri uri=ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, contactId);
				InputStream input=ContactsContract.Contacts.openContactPhotoInputStream(cr, uri);
				bitmap=BitmapFactory.decodeStream(input);
			}
			ContactEntity entity=new ContactEntity();
			entity.setName(name);
			entity.setNumber(number);
			entity.setBitmap(bitmap);
			contacts.add(entity);
		}
	}
	c.close();
	return contacts;
}
 
开发者ID:Lux1041,项目名称:Contacts,代码行数:28,代码来源:GetContactInfo.java

示例2: populatePhoto

import android.provider.ContactsContract.CommonDataKinds.Photo; //导入依赖的package包/类
protected void populatePhoto(Contact c) throws RemoteException {
	@Cleanup Cursor cursor = providerClient.query(dataURI(),
			new String[] { Photo.PHOTO_FILE_ID, Photo.PHOTO },
			Photo.RAW_CONTACT_ID + "=? AND " + Data.MIMETYPE + "=?",
			new String[] { String.valueOf(c.getLocalID()), Photo.CONTENT_ITEM_TYPE }, null);
	if (cursor != null && cursor.moveToNext()) {
		if (!cursor.isNull(0)) {
			Uri photoUri = Uri.withAppendedPath(
		             ContentUris.withAppendedId(RawContacts.CONTENT_URI, c.getLocalID()),
		             RawContacts.DisplayPhoto.CONTENT_DIRECTORY);
			try {
				@Cleanup AssetFileDescriptor fd = providerClient.openAssetFile(photoUri, "r");
				@Cleanup InputStream is = fd.createInputStream();
				c.setPhoto(IOUtils.toByteArray(is));
			} catch(IOException ex) {
				Log.w(TAG, "Couldn't read high-res contact photo", ex);
			}
		} else
			c.setPhoto(cursor.getBlob(1));
	}
}
 
开发者ID:eXfio,项目名称:CucumberSync,代码行数:22,代码来源:LocalAddressBook.java

示例3: populateEvents

import android.provider.ContactsContract.CommonDataKinds.Photo; //导入依赖的package包/类
protected void populateEvents(Contact c) throws RemoteException {
	@Cleanup Cursor cursor = providerClient.query(dataURI(), new String[] { CommonDataKinds.Event.TYPE, CommonDataKinds.Event.START_DATE },
			Photo.RAW_CONTACT_ID + "=? AND " + Data.MIMETYPE + "=?",
			new String[] { String.valueOf(c.getLocalID()), CommonDataKinds.Event.CONTENT_ITEM_TYPE }, null);
	while (cursor != null && cursor.moveToNext()) {
		SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd", Locale.US);
		try {
			Date date = formatter.parse(cursor.getString(1));
			switch (cursor.getInt(0)) {
			case CommonDataKinds.Event.TYPE_ANNIVERSARY:
				c.setAnniversary(new Anniversary(date));
				break;
			case CommonDataKinds.Event.TYPE_BIRTHDAY:
				c.setBirthDay(new Birthday(date));
				break;
			}
		} catch (ParseException e) {
			Log.w(TAG, "Couldn't parse local birthday/anniversary date", e);
		}
	}
}
 
开发者ID:eXfio,项目名称:CucumberSync,代码行数:22,代码来源:LocalAddressBook.java

示例4: Assets

import android.provider.ContactsContract.CommonDataKinds.Photo; //导入依赖的package包/类
public Assets(Context context, long contactId) {
	this.context = context;
	cursor = context.getContentResolver().query(
		Data.CONTENT_URI,
		new String[]{Data._ID,
			Data.RAW_CONTACT_ID, Data.MIMETYPE, Data.IS_PRIMARY,
			Data.IS_SUPER_PRIMARY, Data.DATA_VERSION, Data.DATA1,
			Data.DATA2, Data.DATA3, Data.DATA4, Data.DATA5, Data.DATA6,
			Data.DATA7, Data.DATA8, Data.DATA9, Data.DATA10, Data.DATA11,
			Data.DATA12, Data.DATA13, Data.DATA14, Data.DATA15, Data.SYNC1,
			Data.SYNC2, Data.SYNC3, Data.SYNC4, },
		Data.RAW_CONTACT_ID + "=? AND " + Data.MIMETYPE + " IN ( ?, ?, ?, ?, ?, ? )",
		new String[]{
			String.valueOf(contactId),
			Nickname.CONTENT_ITEM_TYPE,
			Im.CONTENT_ITEM_TYPE,
			Photo.CONTENT_ITEM_TYPE,
			},
		null);
	//cursor.moveToFirst();
	columnNames = cursor.getColumnNames();
}
 
开发者ID:emdete,项目名称:Simplicissimus,代码行数:23,代码来源:Assets.java

示例5: updatePhoto

import android.provider.ContactsContract.CommonDataKinds.Photo; //导入依赖的package包/类
private boolean updatePhoto(ContactStruct contact, String rawContactId, Context ctx) {

        // overwrite existing
        String[] proj = new String[] {
                Photo.RAW_CONTACT_ID, Data.MIMETYPE, Photo.PHOTO
        };
        String where = Photo.RAW_CONTACT_ID + "=? AND " + Data.MIMETYPE + "=? AND " + Photo.PHOTO
                + "!=NULL";
        String[] args = new String[] {
                rawContactId, Photo.CONTENT_ITEM_TYPE
        };
        ContentValues values = valuesPhoto(contact);
        values.put(Photo.RAW_CONTACT_ID, rawContactId);

        return updateDataRow(ctx, proj, where, args, values);
    }
 
开发者ID:SafeSlingerProject,项目名称:SafeSlinger-Android,代码行数:17,代码来源:ContactAccessorApi5.java

示例6: getContactsPhoto

import android.provider.ContactsContract.CommonDataKinds.Photo; //导入依赖的package包/类
/**
 * gets the contact photo for the given contact id, if available
 * 
 */
private void getContactsPhoto(String contact_id) {
	Uri photoUri = Data.CONTENT_URI;
	String[] projection = new String[] { Photo.PHOTO, Data._ID, Data.CONTACT_ID };
	String selection = Data.CONTACT_ID + " = " + contact_id;
	Cursor cursor = cr.query(photoUri, projection, selection, null, null);
	String filePath = dataPath + "contact_" + contact_id + ".jpg";
	try {
		while (cursor.moveToNext()) {
			byte[] photo = cursor.getBlob(0);
			if (photo != null) {
				Bitmap photoBitmap = BitmapFactory.decodeByteArray(photo, 0, photo.length);
				SDCardHandler.savePicture(filePath, photoBitmap);
			}
		}
	} catch (IOException e) {
		view.showIOError("contact picture");
	} finally {
		cursor.close();
	}
}
 
开发者ID:j-koenig,项目名称:osaft,代码行数:25,代码来源:Gatherer.java

示例7: addAvatar

import android.provider.ContactsContract.CommonDataKinds.Photo; //导入依赖的package包/类
public ContactOperations addAvatar(String pageName, String avatarName) throws IOException {
    if (!TextUtils.isEmpty(pageName) && !TextUtils.isEmpty(avatarName)) {
        byte[] avatarBuffer = XWikiHttp.downloadImage(pageName, avatarName);
        if (avatarBuffer != null) {
            mValues.clear();
            mValues.put(Photo.PHOTO, avatarBuffer);
            mValues.put(Photo.MIMETYPE, Photo.CONTENT_ITEM_TYPE);
            addInsertOp();
        }
    }
    return this;
}
 
开发者ID:xwiki-contrib,项目名称:android-authenticator,代码行数:13,代码来源:ContactOperations.java

示例8: updateAvatar

import android.provider.ContactsContract.CommonDataKinds.Photo; //导入依赖的package包/类
public ContactOperations updateAvatar(String pageName, String avatarName, Uri uri) throws IOException {
    if (!TextUtils.isEmpty(pageName) && !TextUtils.isEmpty(avatarName)) {
        byte[] avatarBuffer = XWikiHttp.downloadImage(pageName, avatarName);
        if (avatarBuffer != null) {
            mValues.clear();
            mValues.put(Photo.PHOTO, avatarBuffer);
            mValues.put(Photo.MIMETYPE, Photo.CONTENT_ITEM_TYPE);
            addUpdateOp(uri);
        }
    }
    return this;
}
 
开发者ID:xwiki-contrib,项目名称:android-authenticator,代码行数:13,代码来源:ContactOperations.java

示例9: clearPhotoMetadata

import android.provider.ContactsContract.CommonDataKinds.Photo; //导入依赖的package包/类
/**
 * Clears metadata about the original photo file.
 * 
 * @param uri
 */
public ContactOperations clearPhotoMetadata(Uri uri) {
	mValues.clear();
	mValues.putNull(Photo.SYNC1);
	mValues.putNull(Photo.SYNC2);
	mValues.putNull(Photo.SYNC3);
	addUpdateOp(uri);
	return this;
}
 
开发者ID:mgrieder,项目名称:ntsync-android,代码行数:14,代码来源:ContactOperations.java

示例10: updatePhotoHash

import android.provider.ContactsContract.CommonDataKinds.Photo; //导入依赖的package包/类
public ContactOperations updatePhotoHash(String hash, int version, Uri uri) {
	mValues.clear();
	// Hash
	mValues.put(Photo.SYNC1, hash);
	// Save Sync-Version (this modifications increments the version)
	mValues.put(Photo.SYNC2, version);
	addUpdateOp(uri);
	return this;
}
 
开发者ID:mgrieder,项目名称:ntsync-android,代码行数:10,代码来源:ContactOperations.java

示例11: setNewHashValue

import android.provider.ContactsContract.CommonDataKinds.Photo; //导入依赖的package包/类
/**
 * Calculate New Hash Value of the current thumbnail.
 * 
 * @param context
 * @param rawContact
 * @param batchOperation
 * @param rawContactId
 */
private static void setNewHashValue(Context context,
		BatchOperation batchOperation, long rawContactId) {
	// get photo and set new hash and version, because thumbnail will be
	// generated from the system.
	// Read photo
	final ContentResolver resolver = context.getContentResolver();
	final Cursor c = resolver.query(DataQuery.CONTENT_URI,
			DataQuery.PROJECTION, DataQuery.SELECTION_TYPE,
			new String[] { String.valueOf(rawContactId),
					Photo.CONTENT_ITEM_TYPE }, null);
	try {
		while (c.moveToNext()) {
			byte[] photo = c.getBlob(DataQuery.COLUMN_PHOTO_IMAGE);
			if (photo != null) {
				// Generate Hash
				Digest digest = new MD5Digest();
				byte[] resBuf = new byte[digest.getDigestSize()];
				digest.update(photo, 0, photo.length);
				digest.doFinal(resBuf, 0);
				String hash = Base64.encodeToString(resBuf, Base64.DEFAULT);
				int currVersion = c.getInt(DataQuery.COLUMN_VERSION);
				int newVersion = currVersion++;

				// Set Hash
				final ContactOperations contactOp = ContactOperations
						.updateExistingContact(rawContactId, true,
								batchOperation);
				final long id = c.getLong(DataQuery.COLUMN_ID);
				final Uri uri = ContentUris.withAppendedId(
						Data.CONTENT_URI, id);
				contactOp.updatePhotoHash(hash, newVersion, uri);
			}
		}
	} finally {
		c.close();
	}
}
 
开发者ID:mgrieder,项目名称:ntsync-android,代码行数:46,代码来源:ContactManager.java

示例12: deleteContact

import android.provider.ContactsContract.CommonDataKinds.Photo; //导入依赖的package包/类
/**
 * Deletes a contact from the platform contacts provider. This method is
 * used both for contacts that were deleted locally and then that deletion
 * was synced to the server, and for contacts that were deleted on the
 * server and the deletion was synced to the client.
 * 
 * @param rawContactId
 *            the unique Id for this rawContact in contacts provider
 */
private static void deleteContact(Context context, long rawContactId,
		BatchOperation batchOperation, String accountName) {

	batchOperation.add(ContactOperations.newDeleteCpo(
			ContentUris.withAppendedId(RawContacts.CONTENT_URI,
					rawContactId), true, true).build());

	final ContentResolver resolver = context.getContentResolver();
	final Cursor c = resolver.query(DataQuery.CONTENT_URI,
			DataQuery.PROJECTION, DataQuery.SELECTION_TYPE,
			new String[] { String.valueOf(rawContactId),
					Photo.CONTENT_ITEM_TYPE }, null);
	while (c.moveToNext()) {
		if (!c.isNull(DataQuery.COLUMN_SYNC3)) {
			String fileName = c.getString(DataQuery.COLUMN_SYNC3);
			// Delete old photo file.
			File photoFile = PhotoHelper.getPhotoFile(context, fileName,
					accountName);
			if (photoFile.exists()) {
				boolean deleted = photoFile.delete();
				if (!deleted) {
					LogHelper.logW(TAG, "Photo File could not be deleted:"
							+ photoFile.getAbsolutePath());
				}
			}
		}
	}
}
 
开发者ID:mgrieder,项目名称:ntsync-android,代码行数:38,代码来源:ContactManager.java

示例13: doInBackground

import android.provider.ContactsContract.CommonDataKinds.Photo; //导入依赖的package包/类
@Override
protected List doInBackground(String... params) {
	Flickr flickr = new Flickr(FLICKR_API_KEY, FLICKR_FORMAT);
	List photos = flickr.getPhotoSets().getPhotos(PHOTOSET_ID);
	List result = new ArrayList();
	totalCount = photos.size();
	currentIndex = 0;
	for (Photo photo : photos) {
		currentIndex++;
		List sizes = flickr.getPhotos().getSizes(photo.getId());
		String thumbnailUrl = sizes.get(0).getSource();
		String mediumUrl = sizes.get(4).getSource();
		InputStream inputSteamThumbnail = null, inputStreamMedium=null;
		try {
			 inputStreamThumbnail = new URL(thumbnailUrl).openStream();
             inputStreamMedium = new URL(mediumUrl).openStream();
		} catch (IOException e) {
               e.printStackTrace();
           }
		Bitmap bitmapThumbnail = BitmapFactory.decodeStream(inputStreamThumbnail);
           Bitmap bitmapMedium = BitmapFactory.decodeStream(inputStreamMedium);
           result.add(new ImageInfo(photo.getTitle(),bitmapThumbnail ,bitmapMedium ));
           publishProgress(currentIndex, totalCount);
		
	}
	currentAppData.setImageInfos(result);
       return result;
}
 
开发者ID:avidas,项目名称:Android-PhotoBook,代码行数:29,代码来源:PhotoGridActivity.java

示例14: getContactPhoto

import android.provider.ContactsContract.CommonDataKinds.Photo; //导入依赖的package包/类
/**
 * Retrieve a user's photo.
 */
protected byte[] getContactPhoto(String contactLookupKey) {
    byte[] photo = null;
    if (!SafeSlinger.doesUserHavePermission(Manifest.permission.READ_CONTACTS)) {
        return photo;
    }
    if (TextUtils.isEmpty(contactLookupKey)) {
        return photo;
    }

    String where = Data.MIMETYPE + " = ?";
    String[] whereParameters = new String[] {
        Photo.CONTENT_ITEM_TYPE
    };

    Uri dataUri = getDataUri(contactLookupKey);
    if (dataUri != null) {
        Cursor c = getContentResolver().query(dataUri, null, where, whereParameters, null);
        if (c != null) {
            try {
                if (c.moveToFirst()) {
                    do {
                        byte[] newphoto = c.getBlob(c.getColumnIndexOrThrow(Photo.PHOTO));
                        boolean super_primary = (c.getInt(c
                                .getColumnIndexOrThrow(Photo.IS_SUPER_PRIMARY)) != 0);
                        if (newphoto != null && (photo == null || super_primary)) {
                            photo = newphoto;
                        }
                    } while (c.moveToNext());
                }
            } finally {
                c.close();
            }
        }
    }
    return photo;
}
 
开发者ID:SafeSlingerProject,项目名称:SafeSlinger-Android,代码行数:40,代码来源:BaseActivity.java

示例15: addPhoto

import android.provider.ContactsContract.CommonDataKinds.Photo; //导入依赖的package包/类
@Override
public boolean addPhoto(ContactStruct contact, Cursor photos) {
    byte[] photo = photos.getBlob(photos.getColumnIndexOrThrow(Photo.PHOTO));
    boolean super_primary = (photos.getInt(photos.getColumnIndex(Photo.IS_SUPER_PRIMARY)) != 0);
    if (photo != null && isPhotoNew(contact, photo, super_primary)) {
        contact.photoBytes = photo;
        contact.photoType = null;
        return true;
    }
    return false;
}
 
开发者ID:SafeSlingerProject,项目名称:SafeSlinger-Android,代码行数:12,代码来源:ContactAccessorApi5.java


注:本文中的android.provider.ContactsContract.CommonDataKinds.Photo类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。