下面列出了android.content.ComponentName#equals ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public void onServiceConnected(ComponentName component, IBinder service) {
if (component.equals(new ComponentName(PreviewImageActivity.this,
FileDownloader.class))) {
mDownloaderBinder = (FileDownloaderBinder) service;
if (mRequestWaitingForBinder) {
mRequestWaitingForBinder = false;
Log_OC.d(TAG, "Simulating reselection of current page after connection " +
"of download binder");
onPageSelected(mViewPager.getCurrentItem());
}
} else if (component.equals(new ComponentName(PreviewImageActivity.this,
FileUploader.class))) {
Log_OC.d(TAG, "Upload service connected");
mUploaderBinder = (FileUploaderBinder) service;
} else {
return;
}
}
/**
* @return true iff a RecognitionService with the given component name is installed
*/
public static boolean isRecognitionServiceInstalled(PackageManager pm, ComponentName componentName) {
List<ResolveInfo> services = pm.queryIntentServices(
new Intent(RecognitionService.SERVICE_INTERFACE), 0);
for (ResolveInfo ri : services) {
ServiceInfo si = ri.serviceInfo;
if (si == null) {
Log.i("serviceInfo == null");
continue;
}
if (componentName.equals(new ComponentName(si.packageName, si.name))) {
return true;
}
}
return false;
}
@Override
public void onServiceConnected(ComponentName component, IBinder service) {
if (getActivity() != null) {
if (component.equals(
new ComponentName(getActivity(), MediaService.class))) {
Log_OC.d(TAG, "Media service connected");
mMediaServiceBinder = (MediaServiceBinder) service;
if (mMediaServiceBinder != null) {
prepareMediaController();
playAudio(); // do not wait for the touch of nobody to play audio
Log_OC.d(TAG, "Successfully bound to MediaService, MediaController ready");
}
else {
Log_OC.e(TAG, "Unexpected response from MediaService while binding");
}
}
}
}
/**
* 选择匹配的ServiceInfo
*
* @param pluginIntent 插件的Intent
* @return ServiceInfo
*/
private ServiceInfo selectPluginService(Intent pluginIntent) {
for (ComponentName componentName : mServiceInfoMap.keySet()) {
if (componentName.equals(pluginIntent.getComponent())) {
return mServiceInfoMap.get(componentName);
}
}
return null;
}
/**
* 选择匹配的ServiceInfo
*
* @param pluginIntent 插件的Intent
* @return ServiceInfo
*/
private ServiceInfo selectPluginService(Intent pluginIntent) {
for (ComponentName componentName : mServiceInfoMap.keySet()) {
if (componentName.equals(pluginIntent.getComponent())) {
return mServiceInfoMap.get(componentName);
}
}
return null;
}
@Override
public void onServiceConnected(ComponentName component, IBinder binder) {
synchronized (mLock) {
if (component.equals(mBoundComponent)) {
if (D) Log.d(mTag, component + " connected");
mBoundService = binder;
if (mHandler !=null && mNewServiceWork != null) {
mHandler.post(mNewServiceWork);
}
} else {
Log.w(mTag, "unexpected onServiceConnected: " + component);
}
}
}
@Override
public void onServiceDisconnected(ComponentName component) {
synchronized (mLock) {
if (D) Log.d(mTag, component + " disconnected");
if (component.equals(mBoundComponent)) {
mBoundService = null;
}
}
}
/** Determines, from system settings, if {@code imeClass} is the default input method. */
public static boolean isInputMethodDefault(Context contextArg, Class<?> imeClass) {
final ComponentName imeComponentName = new ComponentName(contextArg, imeClass);
final String defaultIMEId =
Settings.Secure.getString(
contextArg.getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD);
return defaultIMEId != null && imeComponentName.equals(
ComponentName.unflattenFromString(defaultIMEId));
}
@Override
public void onServiceDisconnected(ComponentName component) {
if (component.equals(new ComponentName(FileActivity.this, OperationsService.class))) {
Log_OC.d(TAG, "Operations service disconnected");
mOperationsServiceBinder = null;
// TODO whatever could be waiting for the service is unbound
}
}
@Override
public void onServiceDisconnected(ComponentName component) {
if (component.equals(new ComponentName(FileDisplayActivity.this,
FileDownloader.class))) {
Log_OC.d(TAG, "Download service disconnected");
mDownloaderBinder = null;
} else if (component.equals(new ComponentName(FileDisplayActivity.this,
FileUploader.class))) {
Log_OC.d(TAG, "Upload service disconnected");
mUploaderBinder = null;
}
}
private boolean isAutomaticActive(ComponentName component) {
if (component == null) return false;
final ZenModeConfig config = mHelper.getConfig();
if (config == null) return false;
for (ZenRule rule : config.automaticRules.values()) {
if (component.equals(rule.component) && rule.isAutomaticActive()) {
return true;
}
}
return false;
}
public IConditionProvider findConditionProvider(ComponentName component) {
if (component == null) return null;
for (ManagedServiceInfo service : getServices()) {
if (component.equals(service.component)) {
return provider(service);
}
}
return null;
}
private ArrayList<ItemInfo> getItemInfoForComponentName(final ComponentName cname,
final UserHandleCompat user) {
ItemInfoFilter filter = new ItemInfoFilter() {
@Override
public boolean filterItem(ItemInfo parent, ItemInfo info, ComponentName cn) {
if (info.user == null) {
return cn.equals(cname);
} else {
return cn.equals(cname) && info.user.equals(user);
}
}
};
return filterItemInfos(sBgItemsIdMap.values(), filter);
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
LOGI(TAG, "--onStartComment(" + intent + ", " + flags + ", " + startId + ')');
// If this app is sending us a request, show the volume panel!
ComponentName thisComponent = new ComponentName(getApplicationContext(), getClass());
if (intent != null && thisComponent.equals(intent.getComponent())) {
mLastNotificationEventTime = System.currentTimeMillis();
if (null != mVolumePanel) {
mVolumePanel.reveal();
}
}
return super.onStartCommand(intent, flags, startId);
}
@Override
public void onServiceDisconnected(ComponentName component) {
if (component.equals(new ComponentName(PreviewImageActivity.this,
FileDownloader.class))) {
Log_OC.d(TAG, "Download service suddenly disconnected");
mDownloaderBinder = null;
} else if (component.equals(new ComponentName(PreviewImageActivity.this,
FileUploader.class))) {
Log_OC.d(TAG, "Upload service suddenly disconnected");
mUploaderBinder = null;
}
}
public void processQuickApps(List<AppLauncher> launchers) {
List<AppLauncher> quickRowApps = new ArrayList<>();
final List<ComponentName> quickRowOrder = db().getAppCategoryOrder(QUICK_ROW_CAT);
boolean newstuff = DefaultApps.checkDefaultApps(mQuickRow.getContext(), launchers, quickRowOrder);
for (ComponentName compname: quickRowOrder) {
//Log.d("Quick", compname.flattenToString());
AppLauncher app = null;
for (AppLauncher a: launchers) {
if (compname.equals(a.getComponentName())) {
app = a;
break;
}
}
if (app==null) {
//Log.d("Quick", "Not found: " + compname.flattenToString());
newstuff = true; //app could have been uninstalled
} else if (compname.equals(app.getComponentName())) {
//Log.d("Quick", "Found: " + compname.flattenToString());
// AppLauncher qapp = AppLauncher.createAppLauncher(app, true);
quickRowApps.add(app);
}
}
if (newstuff) db().setAppCategoryOrder(QUICK_ROW_CAT, quickRowApps);
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
LOGI(TAG, "--onStartComment(" + intent + ", " + flags + ", " + startId + ')');
// If this app is sending us a request, show the volume panel!
ComponentName thisComponent = new ComponentName(getApplicationContext(), getClass());
if (intent != null && thisComponent.equals(intent.getComponent())) {
mLastNotificationEventTime = System.currentTimeMillis();
if (null != mVolumePanel) {
mVolumePanel.reveal();
}
}
return super.onStartCommand(intent, flags, startId);
}
private void evaluateRule(ZenRule rule, ArraySet<Uri> current, ComponentName trigger,
boolean processSubscriptions) {
if (rule == null || rule.conditionId == null) return;
final Uri id = rule.conditionId;
boolean isSystemCondition = false;
for (SystemConditionProviderService sp : mConditionProviders.getSystemProviders()) {
if (sp.isValidConditionId(id)) {
mConditionProviders.ensureRecordExists(sp.getComponent(), id, sp.asInterface());
rule.component = sp.getComponent();
isSystemCondition = true;
}
}
if (!isSystemCondition) {
final IConditionProvider cp = mConditionProviders.findConditionProvider(rule.component);
if (DEBUG) Log.d(TAG, "Ensure external rule exists: " + (cp != null) + " for " + id);
if (cp != null) {
mConditionProviders.ensureRecordExists(rule.component, id, cp);
}
}
if (rule.component == null) {
Log.w(TAG, "No component found for automatic rule: " + rule.conditionId);
rule.enabled = false;
return;
}
if (current != null) {
current.add(id);
}
if (processSubscriptions && ((trigger != null && trigger.equals(rule.component))
|| isSystemCondition)) {
if (DEBUG) Log.d(TAG, "Subscribing to " + rule.component);
if (mConditionProviders.subscribeIfNecessary(rule.component, rule.conditionId)) {
synchronized (mSubscriptions) {
mSubscriptions.put(rule.conditionId, rule.component);
}
} else {
rule.condition = null;
if (DEBUG) Log.d(TAG, "zmc failed to subscribe");
}
}
if (rule.condition == null) {
rule.condition = mConditionProviders.findCondition(rule.component, rule.conditionId);
if (rule.condition != null && DEBUG) Log.d(TAG, "Found existing condition for: "
+ rule.conditionId);
}
}
/**
* Make an ShortcutInfo object for a shortcut that is an application.
*
* If c is not null, then it will be used to fill in missing data like the
* title and icon.
*/
public ShortcutInfo getShortcutInfo(PackageManager manager, Intent intent,
Context context, Cursor c, int iconIndex, int titleIndex,
HashMap<Object, CharSequence> labelCache) {
ComponentName componentName = intent.getComponent();
final ShortcutInfo info = new ShortcutInfo();
if (componentName != null
&& !isValidPackageComponent(manager, componentName)) {
return null;
} else {
try {
PackageInfo pi = manager.getPackageInfo(
componentName.getPackageName(), 0);
info.initFlagsAndFirstInstallTime(pi);
} catch (NameNotFoundException e) {
}
}
Bitmap icon = null;
ResolveInfo resolveInfo = null;
ComponentName oldComponent = intent.getComponent();
Intent newIntent = new Intent(intent.getAction(), null);
newIntent.addCategory(Intent.CATEGORY_LAUNCHER);
newIntent.setPackage(oldComponent.getPackageName());
List<ResolveInfo> infos = manager.queryIntentActivities(newIntent, 0);
for (ResolveInfo i : infos) {
ComponentName cn = new ComponentName(i.activityInfo.packageName,
i.activityInfo.name);
if (cn.equals(oldComponent)) {
resolveInfo = i;
}
}
if (resolveInfo == null) {
resolveInfo = manager.resolveActivity(intent, 0);
}
if (resolveInfo != null) {
icon = mIconCache.getIcon(componentName, resolveInfo, labelCache);
}
// the db
if (icon == null) {
if (c != null) {
icon = getIconFromCursor(c, iconIndex, context);
}
}
// the fallback icon
if (icon == null) {
icon = getFallbackIcon();
info.usingFallbackIcon = true;
}
info.setIcon(icon);
// from the resource
if (resolveInfo != null) {
ComponentName key = LauncherModel
.getComponentNameFromResolveInfo(resolveInfo);
if (labelCache != null && labelCache.containsKey(key)) {
info.title = labelCache.get(key);
} else {
info.title = resolveInfo.activityInfo.loadLabel(manager);
if (labelCache != null) {
labelCache.put(key, info.title);
}
}
}
// from the db
if (info.title == null) {
if (c != null) {
info.title = c.getString(titleIndex);
}
}
// fall back to the class name of the activity
if (info.title == null) {
info.title = componentName.getClassName();
}
info.itemType = LauncherSettings.Favorites.ITEM_TYPE_APPLICATION;
return info;
}
/**
* Returns true if the specified dock app intent should be started.
* False if we should dream instead, if appropriate.
*/
public static boolean shouldStartDockApp(Context context, Intent intent) {
ComponentName name = intent.resolveActivity(context.getPackageManager());
return name != null && !name.equals(SOMNAMBULATOR_COMPONENT);
}