Example usage for android.content ComponentName equals

List of usage examples for android.content ComponentName equals

Introduction

In this page you can find the example usage for android.content ComponentName equals.

Prototype

@Override
    public boolean equals(Object obj) 

Source Link

Usage

From source file:Main.java

public static boolean isAccessibilityServiceEnabled(Context context,
        Class<? extends AccessibilityService> accessibilityService) {
    ComponentName expectedComponentName = new ComponentName(context, accessibilityService);

    String enabledServicesSetting = Settings.Secure.getString(context.getContentResolver(),
            Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES);
    if (enabledServicesSetting == null)
        return false;

    TextUtils.SimpleStringSplitter colonSplitter = new TextUtils.SimpleStringSplitter(':');
    colonSplitter.setString(enabledServicesSetting);

    while (colonSplitter.hasNext()) {
        String componentNameString = colonSplitter.next();
        ComponentName enabledService = ComponentName.unflattenFromString(componentNameString);

        if (enabledService != null && enabledService.equals(expectedComponentName))
            return true;
    }// w w  w . j av  a 2  s.  c  om

    return false;
}

From source file:com.googlecode.eyesfree.brailleback.IMEHelper.java

/**
 * Determines, from system settings, if {@code IMEClass} is the default
 * input method./*www.j  a va  2 s.c o  m*/
 */
public static boolean isInputMethodDefault(Context context, Class<?> IMEClass) {
    final ComponentName imeComponentName = new ComponentName(context, IMEClass);
    final String defaultIMEId = Settings.Secure.getString(context.getContentResolver(),
            Settings.Secure.DEFAULT_INPUT_METHOD);

    return defaultIMEId != null && imeComponentName.equals(ComponentName.unflattenFromString(defaultIMEId));
}

From source file:net.wequick.small.Small.java

public static void preSetUp(Application context) {
    sContext = context;//from  w  ww  .  ja  va  2 s  .  com

    // Register default bundle launchers
    registerLauncher(new ActivityLauncher());
    registerLauncher(new ApkBundleLauncher());
    registerLauncher(new WebBundleLauncher());

    PackageManager pm = context.getPackageManager();
    String packageName = context.getPackageName();

    // Check if host app is first-installed or upgraded
    int backupHostVersion = getHostVersionCode();
    int currHostVersion = 0;
    try {
        PackageInfo pi = pm.getPackageInfo(packageName, 0);
        currHostVersion = pi.versionCode;
    } catch (PackageManager.NameNotFoundException ignored) {
        // Never reach
    }

    if (backupHostVersion != currHostVersion) {
        sIsNewHostApp = true;
        setHostVersionCode(currHostVersion);
    } else {
        sIsNewHostApp = false;
    }

    // Collect host certificates
    try {
        Signature[] ss = pm.getPackageInfo(Small.getContext().getPackageName(),
                PackageManager.GET_SIGNATURES).signatures;
        if (ss != null) {
            int N = ss.length;
            sHostCertificates = new byte[N][];
            for (int i = 0; i < N; i++) {
                sHostCertificates[i] = ss[i].toByteArray();
            }
        }
    } catch (PackageManager.NameNotFoundException ignored) {

    }

    // Check if application is started after unexpected exit (killed in background etc.)
    ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    ComponentName launchingComponent = am.getRunningTasks(1).get(0).topActivity;
    ComponentName launcherComponent = pm.getLaunchIntentForPackage(packageName).getComponent();
    if (!launchingComponent.equals(launcherComponent)) {
        // In this case, system launching the last restored activity instead of our launcher
        // activity. Call `setUp' synchronously to ensure `Small' available.
        setUp(context, null);
    }
}

From source file:com.googlecode.eyesfree.brailleback.IMEHelper.java

/**
 * Determines from system settings if {@code IMEClass} is an enabled input
 * method.//from  w  ww . j a  v  a2s . co  m
 */
public static boolean isInputMethodEnabled(Context context, Class<?> IMEClass) {
    final ComponentName imeComponentName = new ComponentName(context, IMEClass);
    final String enabledIMEIds = Settings.Secure.getString(context.getContentResolver(),
            Settings.Secure.ENABLED_INPUT_METHODS);
    if (enabledIMEIds == null) {
        return false;
    }

    for (String enabledIMEId : enabledIMEIds.split(":")) {
        if (imeComponentName.equals(ComponentName.unflattenFromString(enabledIMEId))) {
            return true;
        }
    }
    return false;
}

From source file:com.jaspersoft.android.jaspermobile.test.acceptance.viewer.WebViewInjector.java

@Override
public void onActivityLifecycleChanged(Activity activity, Stage stage) {
    ComponentName targetComponentName = new ComponentName(activity, mClass.getName());

    ComponentName currentComponentName = activity.getComponentName();
    if (!currentComponentName.equals(targetComponentName))
        return;/*from www  .j a v a 2s. c  o  m*/

    switch (stage) {
    case RESUMED:
        // As soon as, we are trying to register inject of idle resource during on Resume.
        // We need to do this only first time. And yes, I know it is dirty. Any suggestions welcomed :)
        if (!mInjected) {
            FragmentActivity htmlViewerActivity = (FragmentActivity) activity;
            WebViewFragment fragment = (WebViewFragment) htmlViewerActivity.getSupportFragmentManager()
                    .findFragmentByTag(WebViewFragment.TAG);
            ViewGroup holder = (ViewGroup) fragment.getView().findViewById(R.id.webViewPlaceholder);
            // We need to wait for the activity to be created before getting a reference
            // to the webview
            JSWebView webView = (JSWebView) holder.getChildAt(0);

            mWebViewIdlingResource.inject(webView);
            mInjected = true;
        }
        break;
    case STOPPED:
        // Clean up reference
        if (activity.isFinishing())
            mWebViewIdlingResource.clear();
        break;
    default: // NOP
    }
}

From source file:org.opensilk.music.ui2.loader.PluginLoader.java

private PluginInfo readResolveInfo(PackageManager pm, List<ComponentName> disabledPlugins,
        ResolveInfo resolveInfo) {/*from   w w  w .j ava 2  s  .  c  o  m*/
    boolean hasPermission = false;
    final String permission = resolveInfo.serviceInfo.permission;
    if (TextUtils.equals(permission, OrpheusApi.PERMISSION_BIND_LIBRARY_SERVICE)
            || TextUtils.equals(permission, "org.opensilk.music.debug.api.permission.BIND_LIBRARY_SERVICE")) {
        hasPermission = true;
    }
    final CharSequence title = resolveInfo.loadLabel(pm);
    final ComponentName cn = getComponentName(resolveInfo);
    final Drawable icon = resolveInfo.loadIcon(pm);
    CharSequence description;
    try {
        Context packageContext = context.createPackageContext(cn.getPackageName(), 0);
        Resources packageRes = packageContext.getResources();
        description = packageRes.getString(resolveInfo.serviceInfo.descriptionRes);
    } catch (PackageManager.NameNotFoundException e) {
        description = null;
    }
    PluginInfo pluginInfo = new PluginInfo(title, description, cn);
    pluginInfo.hasPermission = hasPermission;
    pluginInfo.icon = icon;
    for (ComponentName c : disabledPlugins) {
        if (c.equals(pluginInfo.componentName)) {
            pluginInfo.isActive = false;
            break;
        }
    }
    return pluginInfo;
}

From source file:org.opensilk.music.ui2.loader.PluginLoader.java

public void setPluginDisabled(ComponentName plugin) {
    List<ComponentName> disabledPlugins = readDisabledPlugins();
    for (ComponentName cn : disabledPlugins) {
        if (plugin.equals(cn)) {
            return;
        }//from  www. jav  a  2 s .co  m
    }
    disabledPlugins.add(plugin);
    writeDisabledPlugins(disabledPlugins);
}

From source file:com.google.android.apps.muzei.SourceManager.java

public void selectSource(ComponentName source) {
    if (source == null) {
        LOGE(TAG, "selectSource: Empty source");
        return;//from  w ww . ja  v a2s.  c o  m
    }

    synchronized (this) {
        if (source.equals(mSelectedSource)) {
            return;
        }

        LOGD(TAG, "Source " + source + " selected.");

        if (mSelectedSource != null) {
            // unsubscribe from existing source
            mApplicationContext.startService(new Intent(ACTION_SUBSCRIBE).setComponent(mSelectedSource)
                    .putExtra(EXTRA_SUBSCRIBER_COMPONENT, mSubscriberComponentName)
                    .putExtra(EXTRA_TOKEN, (String) null));
        }

        // generate a new token and subscribe to new source
        mSelectedSource = source;
        mSelectedSourceToken = UUID.randomUUID().toString();
        mSharedPrefs.edit().putString(PREF_SELECTED_SOURCE, source.flattenToShortString())
                .putString(PREF_SELECTED_SOURCE_TOKEN, mSelectedSourceToken).apply();

        subscribeToSelectedSource();
    }

    EventBus.getDefault().post(new SelectedSourceChangedEvent());
    EventBus.getDefault().post(new SelectedSourceStateChangedEvent());
}

From source file:org.opensilk.music.ui2.loader.PluginLoader.java

public void setPluginEnabled(ComponentName plugin) {
    List<ComponentName> disabledPlugins = readDisabledPlugins();
    Iterator<ComponentName> ii = disabledPlugins.iterator();
    while (ii.hasNext()) {
        if (plugin.equals(ii.next())) {
            ii.remove();/* www .ja  v a 2s  . c  o  m*/
        }
    }
    writeDisabledPlugins(disabledPlugins);
}

From source file:com.androidzeitgeist.dashwatch.muzei.SourceManager.java

public void selectSource(ComponentName source) {
    if (source == null) {
        Log.e(TAG, "selectSource: Empty source");
        return;/*from www.j  a  v a 2 s . co m*/
    }

    synchronized (this) {
        if (source.equals(mSelectedSource)) {
            return;
        }

        Log.d(TAG, "Source " + source + " selected.");

        if (mSelectedSource != null) {
            // unsubscribe from existing source
            mApplicationContext.startService(new Intent(ACTION_SUBSCRIBE).setComponent(mSelectedSource)
                    .putExtra(EXTRA_SUBSCRIBER_COMPONENT, mSubscriberComponentName)
                    .putExtra(EXTRA_TOKEN, (String) null));
        }

        // generate a new token and subscribe to new source
        mSelectedSource = source;
        mSelectedSourceToken = UUID.randomUUID().toString();
        mSharedPrefs.edit().putString(PREF_SELECTED_SOURCE, source.flattenToShortString())
                .putString(PREF_SELECTED_SOURCE_TOKEN, mSelectedSourceToken).apply();

        subscribeToSelectedSource();
    }

    // EventBus.getDefault().post(new SelectedSourceChangedEvent());
    // EventBus.getDefault().post(new SelectedSourceStateChangedEvent());
}