• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java OnLoadCompleteListener类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: loadPhoneContacts

import android.content.Loader.OnLoadCompleteListener; //导入依赖的package包/类
public static void loadPhoneContacts(Context context, final OnPhoneContactsLoadedListener listener) {
	final List<Bundle> phoneContacts = new ArrayList<>();
	if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M
			&& context.checkSelfPermission(Manifest.permission.READ_CONTACTS) != PackageManager.PERMISSION_GRANTED) {
		listener.onPhoneContactsLoaded(phoneContacts);
		return;
	}
	final String[] PROJECTION = new String[]{ContactsContract.Data._ID,
			ContactsContract.Data.DISPLAY_NAME,
			ContactsContract.Data.PHOTO_URI,
			ContactsContract.Data.LOOKUP_KEY,
			ContactsContract.CommonDataKinds.Im.DATA};

	final String SELECTION = "(" + ContactsContract.Data.MIMETYPE + "=\""
			+ ContactsContract.CommonDataKinds.Im.CONTENT_ITEM_TYPE
			+ "\") AND (" + ContactsContract.CommonDataKinds.Im.PROTOCOL
			+ "=\"" + ContactsContract.CommonDataKinds.Im.PROTOCOL_JABBER
			+ "\")";

	CursorLoader mCursorLoader = new NotThrowCursorLoader(context,
			ContactsContract.Data.CONTENT_URI, PROJECTION, SELECTION, null,
			null);
	mCursorLoader.registerListener(0, new OnLoadCompleteListener<Cursor>() {

		@Override
		public void onLoadComplete(Loader<Cursor> arg0, Cursor cursor) {
			if (cursor != null) {
				while (cursor.moveToNext()) {
					Bundle contact = new Bundle();
					contact.putInt("phoneid", cursor.getInt(cursor
							.getColumnIndex(ContactsContract.Data._ID)));
					contact.putString(
							"displayname",
							cursor.getString(cursor
									.getColumnIndex(ContactsContract.Data.DISPLAY_NAME)));
					contact.putString("photouri", cursor.getString(cursor
							.getColumnIndex(ContactsContract.Data.PHOTO_URI)));
					contact.putString("lookup", cursor.getString(cursor
							.getColumnIndex(ContactsContract.Data.LOOKUP_KEY)));

					contact.putString(
							"jid",
							cursor.getString(cursor
									.getColumnIndex(ContactsContract.CommonDataKinds.Im.DATA)));
					phoneContacts.add(contact);
				}
				cursor.close();
			}

			if (listener != null) {
				listener.onPhoneContactsLoaded(phoneContacts);
			}
		}
	});
	try {
		mCursorLoader.startLoading();
	} catch (RejectedExecutionException e) {
		if (listener != null) {
			listener.onPhoneContactsLoaded(phoneContacts);
		}
	}
}
 
开发者ID:syntafin,项目名称:TenguChat,代码行数:63,代码来源:PhoneHelper.java


示例2: loadPhoneContacts

import android.content.Loader.OnLoadCompleteListener; //导入依赖的package包/类
public static void loadPhoneContacts(Context context,final List<Bundle> phoneContacts, final OnPhoneContactsLoadedListener listener) {
	if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M
			&& context.checkSelfPermission(Manifest.permission.READ_CONTACTS) != PackageManager.PERMISSION_GRANTED) {
		listener.onPhoneContactsLoaded(phoneContacts);
		return;
	}
	final String[] PROJECTION = new String[] { ContactsContract.Data._ID,
			ContactsContract.Data.DISPLAY_NAME,
			ContactsContract.Data.PHOTO_URI,
			ContactsContract.Data.LOOKUP_KEY,
			ContactsContract.CommonDataKinds.Im.DATA };

	final String SELECTION = "(" + ContactsContract.Data.MIMETYPE + "=\""
			+ ContactsContract.CommonDataKinds.Im.CONTENT_ITEM_TYPE
			+ "\") AND (" + ContactsContract.CommonDataKinds.Im.PROTOCOL
			+ "=\"" + ContactsContract.CommonDataKinds.Im.PROTOCOL_JABBER
			+ "\")";

	CursorLoader mCursorLoader = new CursorLoader(context,
			ContactsContract.Data.CONTENT_URI, PROJECTION, SELECTION, null,
			null);
	mCursorLoader.registerListener(0, new OnLoadCompleteListener<Cursor>() {

		@Override
		public void onLoadComplete(Loader<Cursor> arg0, Cursor cursor) {
			if (cursor == null) {
				return;
			}
			while (cursor.moveToNext()) {
				Bundle contact = new Bundle();
				contact.putInt("phoneid", cursor.getInt(cursor
						.getColumnIndex(ContactsContract.Data._ID)));
				contact.putString(
						"displayname",
						cursor.getString(cursor
								.getColumnIndex(ContactsContract.Data.DISPLAY_NAME)));
				contact.putString("photouri", cursor.getString(cursor
						.getColumnIndex(ContactsContract.Data.PHOTO_URI)));
				contact.putString("lookup", cursor.getString(cursor
						.getColumnIndex(ContactsContract.Data.LOOKUP_KEY)));

				contact.putString(
						"jid",
						cursor.getString(cursor
								.getColumnIndex(ContactsContract.CommonDataKinds.Im.DATA)));
				phoneContacts.add(contact);
			}
			if (listener != null) {
				listener.onPhoneContactsLoaded(phoneContacts);
			}
			cursor.close();
		}
	});
	try {
		mCursorLoader.startLoading();
	} catch (RejectedExecutionException e) {
		if (listener != null) {
			listener.onPhoneContactsLoaded(phoneContacts);
		}
	}
}
 
开发者ID:xavierle,项目名称:messengerxmpp,代码行数:62,代码来源:PhoneHelper.java


示例3: loadPhoneContacts

import android.content.Loader.OnLoadCompleteListener; //导入依赖的package包/类
public static void loadPhoneContacts(Context context, final OnPhoneContactsLoadedListener listener) {
    final List<Bundle> phoneContacts = new ArrayList<>();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M
            && context.checkSelfPermission(Manifest.permission.READ_CONTACTS) != PackageManager.PERMISSION_GRANTED) {
        listener.onPhoneContactsLoaded(phoneContacts);
        return;
    }
    final String[] PROJECTION = new String[]{ContactsContract.Data._ID,
            ContactsContract.Data.DISPLAY_NAME,
            ContactsContract.Data.PHOTO_URI,
            ContactsContract.Data.LOOKUP_KEY,
            ContactsContract.CommonDataKinds.Im.DATA};

    final String SELECTION = "(" + ContactsContract.Data.MIMETYPE + "=\""
            + ContactsContract.CommonDataKinds.Im.CONTENT_ITEM_TYPE
            + "\") AND (" + ContactsContract.CommonDataKinds.Im.PROTOCOL
            + "=\"" + ContactsContract.CommonDataKinds.Im.PROTOCOL_JABBER
            + "\")";

    CursorLoader mCursorLoader = new NotThrowCursorLoader(context,
            ContactsContract.Data.CONTENT_URI, PROJECTION, SELECTION, null,
            null);
    mCursorLoader.registerListener(0, new OnLoadCompleteListener<Cursor>() {

        @Override
        public void onLoadComplete(Loader<Cursor> arg0, Cursor cursor) {
            if (cursor != null) {
                while (cursor.moveToNext()) {
                    Bundle contact = new Bundle();
                    contact.putInt("phoneid", cursor.getInt(cursor
                            .getColumnIndex(ContactsContract.Data._ID)));
                    contact.putString(
                            "displayname",
                            cursor.getString(cursor
                                    .getColumnIndex(ContactsContract.Data.DISPLAY_NAME)));
                    contact.putString("photouri", cursor.getString(cursor
                            .getColumnIndex(ContactsContract.Data.PHOTO_URI)));
                    contact.putString("lookup", cursor.getString(cursor
                            .getColumnIndex(ContactsContract.Data.LOOKUP_KEY)));

                    contact.putString(
                            "jid",
                            cursor.getString(cursor
                                    .getColumnIndex(ContactsContract.CommonDataKinds.Im.DATA)));
                    phoneContacts.add(contact);
                }
                cursor.close();
            }

            if (listener != null) {
                listener.onPhoneContactsLoaded(phoneContacts);
            }
        }
    });
    try {
        mCursorLoader.startLoading();
    } catch (RejectedExecutionException e) {
        if (listener != null) {
            listener.onPhoneContactsLoaded(phoneContacts);
        }
    }
}
 
开发者ID:kriztan,项目名称:Pix-Art-Messenger,代码行数:63,代码来源:PhoneHelper.java


示例4: getLoaderResultSynchronously

import android.content.Loader.OnLoadCompleteListener; //导入依赖的package包/类
/**
 * Runs a Loader synchronously and returns the result of the load. The loader will
 * be started, stopped, and destroyed by this method so it cannot be reused.
 *
 * @param loader The loader to run synchronously
 * @return The result from the loader
 */
public <T> T getLoaderResultSynchronously(final Loader<T> loader) {
    // The test thread blocks on this queue until the loader puts it's result in
    final ArrayBlockingQueue<T> queue = new ArrayBlockingQueue<T>(1);

    // This callback runs on the "main" thread and unblocks the test thread
    // when it puts the result into the blocking queue
    final OnLoadCompleteListener<T> listener = new OnLoadCompleteListener<T>() {
        @Override
        public void onLoadComplete(Loader<T> completedLoader, T data) {
            // Shut the loader down
            completedLoader.unregisterListener(this);
            completedLoader.stopLoading();
            completedLoader.reset();

            // Store the result, unblocking the test thread
            queue.add(data);
        }
    };

    // This handler runs on the "main" thread of the process since AsyncTask
    // is documented as needing to run on the main thread and many Loaders use
    // AsyncTask
    final Handler mainThreadHandler = new Handler(Looper.getMainLooper()) {
        @Override
        public void handleMessage(Message msg) {
            loader.registerListener(0, listener);
            loader.startLoading();
        }
    };

    // Ask the main thread to start the loading process
    mainThreadHandler.sendEmptyMessage(0);

    // Block on the queue waiting for the result of the load to be inserted
    T result;
    while (true) {
        try {
            result = queue.take();
            break;
        } catch (InterruptedException e) {
            throw new RuntimeException("waiting thread interrupted", e);
        }
    }

    return result;
}
 
开发者ID:twofortyfouram,项目名称:android-plugin-host-sdk-for-locale,代码行数:54,代码来源:Junit4LoaderTestCase.java


示例5: loadPhoneContacts

import android.content.Loader.OnLoadCompleteListener; //导入依赖的package包/类
public static void loadPhoneContacts(Context context, final List<Bundle> phoneContacts, final OnPhoneContactsLoadedListener listener) {
	if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M
			&& context.checkSelfPermission(Manifest.permission.READ_CONTACTS) != PackageManager.PERMISSION_GRANTED) {
		listener.onPhoneContactsLoaded(phoneContacts);
		return;
	}
	final String[] PROJECTION = new String[]{ContactsContract.Data._ID,
			ContactsContract.Data.DISPLAY_NAME,
			ContactsContract.Data.PHOTO_URI,
			ContactsContract.Data.LOOKUP_KEY,
			ContactsContract.CommonDataKinds.Im.DATA};

	final String SELECTION = "(" + ContactsContract.Data.MIMETYPE + "=\""
			+ ContactsContract.CommonDataKinds.Im.CONTENT_ITEM_TYPE
			+ "\") AND (" + ContactsContract.CommonDataKinds.Im.PROTOCOL
			+ "=\"" + ContactsContract.CommonDataKinds.Im.PROTOCOL_JABBER
			+ "\")";

	CursorLoader mCursorLoader = new NotThrowCursorLoader(context,
			ContactsContract.Data.CONTENT_URI, PROJECTION, SELECTION, null,
			null);
	mCursorLoader.registerListener(0, new OnLoadCompleteListener<Cursor>() {

		@Override
		public void onLoadComplete(Loader<Cursor> arg0, Cursor cursor) {
			if (cursor != null) {
				while (cursor.moveToNext()) {
					Bundle contact = new Bundle();
					contact.putInt("phoneid", cursor.getInt(cursor
							.getColumnIndex(ContactsContract.Data._ID)));
					contact.putString(
							"displayname",
							cursor.getString(cursor
									.getColumnIndex(ContactsContract.Data.DISPLAY_NAME)));
					contact.putString("photouri", cursor.getString(cursor
							.getColumnIndex(ContactsContract.Data.PHOTO_URI)));
					contact.putString("lookup", cursor.getString(cursor
							.getColumnIndex(ContactsContract.Data.LOOKUP_KEY)));

					contact.putString(
							"jid",
							cursor.getString(cursor
									.getColumnIndex(ContactsContract.CommonDataKinds.Im.DATA)));
					phoneContacts.add(contact);
				}
				cursor.close();
			}

			if (listener != null) {
				listener.onPhoneContactsLoaded(phoneContacts);
			}
		}
	});
	try {
		mCursorLoader.startLoading();
	} catch (RejectedExecutionException e) {
		if (listener != null) {
			listener.onPhoneContactsLoaded(phoneContacts);
		}
	}
}
 
开发者ID:Frozenbox,项目名称:frozenchat,代码行数:62,代码来源:PhoneHelper.java


示例6: loadPhoneContacts

import android.content.Loader.OnLoadCompleteListener; //导入依赖的package包/类
public static void loadPhoneContacts(Context context,final List<Bundle> phoneContacts, final OnPhoneContactsLoadedListener listener) {
	final String[] PROJECTION = new String[] { ContactsContract.Data._ID,
			ContactsContract.Data.DISPLAY_NAME,
			ContactsContract.Data.PHOTO_URI,
			ContactsContract.Data.LOOKUP_KEY,
			ContactsContract.CommonDataKinds.Im.DATA };

	final String SELECTION = "(" + ContactsContract.Data.MIMETYPE + "=\""
			+ ContactsContract.CommonDataKinds.Im.CONTENT_ITEM_TYPE
			+ "\") AND (" + ContactsContract.CommonDataKinds.Im.PROTOCOL
			+ "=\"" + ContactsContract.CommonDataKinds.Im.PROTOCOL_JABBER
			+ "\")";

	CursorLoader mCursorLoader = new CursorLoader(context,
			ContactsContract.Data.CONTENT_URI, PROJECTION, SELECTION, null,
			null);
	mCursorLoader.registerListener(0, new OnLoadCompleteListener<Cursor>() {

		@Override
		public void onLoadComplete(Loader<Cursor> arg0, Cursor cursor) {
			if (cursor == null) {
				return;
			}
			while (cursor.moveToNext()) {
				Bundle contact = new Bundle();
				contact.putInt("phoneid", cursor.getInt(cursor
						.getColumnIndex(ContactsContract.Data._ID)));
				contact.putString(
						"displayname",
						cursor.getString(cursor
								.getColumnIndex(ContactsContract.Data.DISPLAY_NAME)));
				contact.putString("photouri", cursor.getString(cursor
						.getColumnIndex(ContactsContract.Data.PHOTO_URI)));
				contact.putString("lookup", cursor.getString(cursor
						.getColumnIndex(ContactsContract.Data.LOOKUP_KEY)));

				contact.putString(
						"jid",
						cursor.getString(cursor
								.getColumnIndex(ContactsContract.CommonDataKinds.Im.DATA)));
				phoneContacts.add(contact);
			}
			if (listener != null) {
				listener.onPhoneContactsLoaded(phoneContacts);
			}
			cursor.close();
		}
	});
	try {
		mCursorLoader.startLoading();
	} catch (RejectedExecutionException e) {
		if (listener != null) {
			listener.onPhoneContactsLoaded(phoneContacts);
		}
	}
}
 
开发者ID:juanignaciomolina,项目名称:txtr,代码行数:57,代码来源:PhoneHelper.java


示例7: loadPhoneContacts

import android.content.Loader.OnLoadCompleteListener; //导入依赖的package包/类
public static void loadPhoneContacts(Context context,
		final OnPhoneContactsLoadedListener listener) {
	final List<Bundle> phoneContacts = new ArrayList<Bundle>();
	
	final String[] PROJECTION = new String[] { ContactsContract.Data._ID,
			ContactsContract.Data.DISPLAY_NAME,
			ContactsContract.Data.PHOTO_THUMBNAIL_URI,
			ContactsContract.Data.LOOKUP_KEY,
			ContactsContract.CommonDataKinds.Im.DATA };

	final String SELECTION = "(" + ContactsContract.Data.MIMETYPE + "=\""
			+ ContactsContract.CommonDataKinds.Im.CONTENT_ITEM_TYPE
			+ "\") AND (" + ContactsContract.CommonDataKinds.Im.PROTOCOL
			+ "=\"" + ContactsContract.CommonDataKinds.Im.PROTOCOL_JABBER
			+ "\")";

	CursorLoader mCursorLoader = new CursorLoader(context,
			ContactsContract.Data.CONTENT_URI, PROJECTION, SELECTION, null,
			null);
	mCursorLoader.registerListener(0, new OnLoadCompleteListener<Cursor>() {

		@Override
		public void onLoadComplete(Loader<Cursor> arg0, Cursor cursor) {
			while (cursor.moveToNext()) {
				Bundle contact = new Bundle();
				contact.putInt("phoneid", cursor.getInt(cursor
						.getColumnIndex(ContactsContract.Data._ID)));
				contact.putString(
						"displayname",
						cursor.getString(cursor
								.getColumnIndex(ContactsContract.Data.DISPLAY_NAME)));
				contact.putString(
						"photouri",
						cursor.getString(cursor
								.getColumnIndex(ContactsContract.Data.PHOTO_THUMBNAIL_URI)));
				contact.putString("lookup", cursor.getString(cursor
						.getColumnIndex(ContactsContract.Data.LOOKUP_KEY)));
				
				contact.putString("jid",cursor.getString(cursor
								.getColumnIndex(ContactsContract.CommonDataKinds.Im.DATA)));
				phoneContacts.add(contact);
			}
			if (listener != null) {
				listener.onPhoneContactsLoaded(phoneContacts);
			}
		}
	});
	mCursorLoader.startLoading();
}
 
开发者ID:GitESS,项目名称:SyncChatAndroid,代码行数:50,代码来源:PhoneHelper.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Request类代码示例发布时间:2022-05-22
下一篇:
Java Status类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap