Example usage for android.content ComponentName unflattenFromString

List of usage examples for android.content ComponentName unflattenFromString

Introduction

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

Prototype

public static @Nullable ComponentName unflattenFromString(@NonNull String str) 

Source Link

Document

Recover a ComponentName from a String that was previously created with #flattenToString() .

Usage

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

public List<ComponentName> readDisabledPlugins() {
    List<ComponentName> list = new ArrayList<>();
    String json = settings.getString(PREF_DISABLED_PLUGINS, null);
    Timber.v("Read disabled plugins=" + json);
    if (json != null) {
        JsonReader jr = new JsonReader(new StringReader(json));
        try {/*w  w  w.ja  v  a2  s .co  m*/
            jr.beginArray();
            while (jr.hasNext()) {
                list.add(ComponentName.unflattenFromString(jr.nextString()));
            }
            jr.endArray();
        } catch (IOException e) {
            settings.remove(PREF_DISABLED_PLUGINS);
            list.clear();
        } finally {
            IOUtils.closeQuietly(jr);
        }
    }
    return list;
}

From source file:com.appsimobile.appsii.module.apps.AppPageLoader.java

private void loadTaggedApps(List<? extends AppEntry> allApps, AppPageData result) {
    if (allApps == null || allApps.isEmpty())
        return;//  ww w. j  ava2 s .  c om

    Cursor cursor = mContext.getContentResolver().query(AppsContract.TaggedAppColumns.CONTENT_URI,
            AppQuery.PROJECTION, AppQuery.WHERE_NOT_DELETED, null, AppQuery.ORDER);

    int appsSize = allApps.size();
    SimpleArrayMap<ComponentName, AppEntry> entriesByComponent = new SimpleArrayMap<>(appsSize);
    for (int i = 0; i < appsSize; i++) {
        AppEntry app = allApps.get(i);
        entriesByComponent.put(app.getComponentName(), app);
    }

    while (cursor.moveToNext()) {
        String shortComponentName = cursor.getString(AppQuery.COMPONENT_NAME);
        ComponentName componentName = ComponentName.unflattenFromString(shortComponentName);

        // find the app entry from all apps. If it does not exists, the component
        // was changed or uninstalled. In that case, ignore it.
        AppEntry appEntry = entriesByComponent.get(componentName);
        if (appEntry == null)
            continue;

        // now create the tagged-app object. This holds the details of the
        // tagged instance
        TaggedApp taggedApp = new TaggedApp();
        long tagId = cursor.getLong(AppQuery.TAG_ID);
        String tagName = cursor.getString(AppQuery.TAG_NAME);

        taggedApp.mComponentName = componentName;
        taggedApp.mId = cursor.getLong(AppQuery._ID);
        taggedApp.mTagName = tagName;
        taggedApp.mTagId = tagId;
        taggedApp.mAppEntry = appEntry;

        addItemToLongSparseArray(result.mAppsPerTag, tagId, appEntry);
        addItemToMapList(result.mTagsPerComponent, componentName, taggedApp);

    }

    cursor.close();
}

From source file:arun.com.chromer.settings.Preferences.java

@Nullable
public String secondaryBrowserPackage() {
    final String flatString = secondaryBrowserComponent();
    if (flatString == null) {
        return null;
    }/*ww w.  j  a  v a2s  .c  om*/
    final ComponentName cN = ComponentName.unflattenFromString(flatString);
    if (cN == null)
        return null;
    return cN.getPackageName();
}

From source file:com.notepadlite.MainActivity.java

private void checkForAndroidWear() {
    // Notepad Plugin for Android Wear sends intent with "plugin_install_complete" extra,
    // in order to verify that the main Notepad app is installed correctly
    if (getIntent().hasExtra("plugin_install_complete")) {
        if (getSupportFragmentManager().findFragmentByTag("WearPluginDialogFragmentAlt") == null) {
            DialogFragment wearDialog = new WearPluginDialogFragmentAlt();
            wearDialog.show(getSupportFragmentManager(), "WearPluginDialogFragmentAlt");
        }/*from w w  w . j a v  a 2 s  . co m*/

        SharedPreferences pref = getSharedPreferences(getPackageName() + "_preferences", Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = pref.edit();
        editor.putBoolean("show_wear_dialog", false);
        editor.apply();
    } else {
        boolean hasAndroidWear = false;

        @SuppressWarnings("unused")
        PackageInfo pInfo;
        try {
            pInfo = getPackageManager().getPackageInfo("com.google.android.wearable.app", 0);
            hasAndroidWear = true;
        } catch (PackageManager.NameNotFoundException e) {
        }

        if (hasAndroidWear) {
            try {
                pInfo = getPackageManager().getPackageInfo("com.notepadlite.wear", 0);
                Intent intent = new Intent(Intent.ACTION_MAIN);
                intent.setComponent(ComponentName
                        .unflattenFromString("com.notepadlite.wear/com.notepadlite.wear.MobileMainActivity"));
                intent.addCategory(Intent.CATEGORY_LAUNCHER);
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                startActivity(intent);
            } catch (PackageManager.NameNotFoundException e) {
                SharedPreferences pref = getSharedPreferences(getPackageName() + "_preferences",
                        Context.MODE_PRIVATE);
                if (pref.getBoolean("show_wear_dialog", true)
                        && getSupportFragmentManager().findFragmentByTag("WearPluginDialogFragment") == null) {
                    DialogFragment wearDialog = new WearPluginDialogFragment();
                    wearDialog.show(getSupportFragmentManager(), "WearPluginDialogFragment");
                }
            } catch (ActivityNotFoundException e) {
            }
        }
    }
}

From source file:arun.com.chromer.settings.Preferences.java

@Nullable
public String favSharePackage() {
    final String flatString = favShareComponent();
    if (flatString == null) {
        return null;
    }//from w ww  .  j  a  v a2s.c o  m
    final ComponentName cN = ComponentName.unflattenFromString(flatString);
    if (cN == null)
        return null;
    return cN.getPackageName();
}

From source file:com.google.android.apps.dashclock.DashClockService.java

/**
 * Asks extensions to provide data updates.
 *///from   w  w  w  . j  a  va  2s .c o m
private void handleUpdateExtensions(Intent intent) {
    int reason = intent.getIntExtra(EXTRA_UPDATE_REASON, DashClockExtension.UPDATE_REASON_UNKNOWN);
    String updateExtension = intent.getStringExtra(EXTRA_COMPONENT_NAME);

    LOGD(TAG, String.format("handleUpdateExtensions [action=%s, reason=%d, extension=%s]", intent.getAction(),
            reason, updateExtension == null ? "" : updateExtension));

    // Either update all extensions, or only the requested one.
    if (!TextUtils.isEmpty(updateExtension)) {
        ComponentName cn = ComponentName.unflattenFromString(updateExtension);
        mExtensionHost.execute(cn, ExtensionHost.UPDATE_OPERATIONS.get(reason),
                ExtensionHost.UPDATE_COLLAPSE_TIME_MILLIS, reason);
    } else {
        for (ComponentName cn : mExtensionManager.getActiveExtensionNames()) {
            mExtensionHost.execute(cn, ExtensionHost.UPDATE_OPERATIONS.get(reason),
                    ExtensionHost.UPDATE_COLLAPSE_TIME_MILLIS, reason);
        }
    }
}

From source file:com.android.dialer.calllog.DefaultVoicemailNotifier.java

/**
 * Determines which ringtone Uri and Notification defaults to use when updating the notification
 * for the given call.//from   ww w. j  ava  2 s  .co m
 */
private Pair<Uri, Integer> getNotificationInfo(@Nullable NewCall callToNotify) {
    Log.v(TAG, "getNotificationInfo");
    if (callToNotify == null) {
        Log.i(TAG, "callToNotify == null");
        return new Pair<>(null, 0);
    }
    PhoneAccountHandle accountHandle = null;
    if (callToNotify.accountComponentName == null || callToNotify.accountId == null) {
        Log.v(TAG, "accountComponentName == null || callToNotify.accountId == null");
        accountHandle = TelecomUtil.getDefaultOutgoingPhoneAccount(mContext, PhoneAccount.SCHEME_TEL);
        if (accountHandle == null) {
            Log.i(TAG, "No default phone account found, using default notification ringtone");
            return new Pair<>(null, Notification.DEFAULT_ALL);
        }

    } else {
        accountHandle = new PhoneAccountHandle(
                ComponentName.unflattenFromString(callToNotify.accountComponentName), callToNotify.accountId);
    }
    if (accountHandle.getComponentName() != null) {
        Log.v(TAG, "PhoneAccountHandle.ComponentInfo:" + accountHandle.getComponentName());
    } else {
        Log.i(TAG, "PhoneAccountHandle.ComponentInfo: null");
    }
    return new Pair<>(TelephonyManagerCompat.getVoicemailRingtoneUri(getTelephonyManager(), accountHandle),
            getNotificationDefaults(accountHandle));
}

From source file:com.anjalimacwan.MainActivity.java

private void checkForAndroidWear() {
    // Notepad Plugin for Android Wear sends intent with "plugin_install_complete" extra,
    // in order to verify that the main Notepad app is installed correctly
    if (getIntent().hasExtra("plugin_install_complete")) {
        if (getSupportFragmentManager().findFragmentByTag("WearPluginDialogFragmentAlt") == null) {
            DialogFragment wearDialog = new WearPluginDialogFragmentAlt();
            wearDialog.show(getSupportFragmentManager(), "WearPluginDialogFragmentAlt");
        }/*from  w  w w . jav a2s .  co m*/

        SharedPreferences pref = getSharedPreferences(getPackageName() + "_preferences", Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = pref.edit();
        editor.putBoolean("show_wear_dialog", false);
        editor.apply();
    } else {
        boolean hasAndroidWear = false;

        @SuppressWarnings("unused")
        PackageInfo pInfo;
        try {
            pInfo = getPackageManager().getPackageInfo("com.google.android.wearable.app", 0);
            hasAndroidWear = true;
        } catch (PackageManager.NameNotFoundException e) {
            /* Gracefully fail */ }

        if (hasAndroidWear) {
            try {
                pInfo = getPackageManager().getPackageInfo("com.anjalimacwan.wear", 0);
                Intent intent = new Intent(Intent.ACTION_MAIN);
                intent.setComponent(ComponentName
                        .unflattenFromString("com.anjalimacwan.wear/com.anjalimacwan.wear.MobileMainActivity"));
                intent.addCategory(Intent.CATEGORY_LAUNCHER);
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                startActivity(intent);
            } catch (PackageManager.NameNotFoundException e) {
                SharedPreferences pref = getSharedPreferences(getPackageName() + "_preferences",
                        Context.MODE_PRIVATE);
                if (pref.getBoolean("show_wear_dialog", true)
                        && getSupportFragmentManager().findFragmentByTag("WearPluginDialogFragment") == null) {
                    DialogFragment wearDialog = new WearPluginDialogFragment();
                    wearDialog.show(getSupportFragmentManager(), "WearPluginDialogFragment");
                }
            } catch (ActivityNotFoundException e) {
                /* Gracefully fail */ }
        }
    }
}

From source file:androidx.core.app.NotificationManagerCompat.java

/**
 * Get the set of packages that have an enabled notification listener component within them.
 */// www  .  jav a  2s. c o  m
@NonNull
public static Set<String> getEnabledListenerPackages(@NonNull Context context) {
    final String enabledNotificationListeners = Settings.Secure.getString(context.getContentResolver(),
            SETTING_ENABLED_NOTIFICATION_LISTENERS);
    synchronized (sEnabledNotificationListenersLock) {
        // Parse the string again if it is different from the last time this method was called.
        if (enabledNotificationListeners != null
                && !enabledNotificationListeners.equals(sEnabledNotificationListeners)) {
            final String[] components = enabledNotificationListeners.split(":");
            Set<String> packageNames = new HashSet<String>(components.length);
            for (String component : components) {
                ComponentName componentName = ComponentName.unflattenFromString(component);
                if (componentName != null) {
                    packageNames.add(componentName.getPackageName());
                }
            }
            sEnabledNotificationListenerPackages = packageNames;
            sEnabledNotificationListeners = enabledNotificationListeners;
        }
        return sEnabledNotificationListenerPackages;
    }
}

From source file:com.android.leanlauncher.IconCache.java

public void loadIconPackDrawables(boolean forceReload) {
    final long t = SystemClock.uptimeMillis();
    synchronized (mIconPackDrawables) {
        if (!forceReload && mIconPackDrawables.size() > 0) {
            return;
        }//from  www  . ja  v  a  2 s  . c o  m

        // load appfilter.xml from the icon pack package
        try {
            XmlPullParser xpp = null;

            final Resources iconPackRes = getIconPackResources();
            if (iconPackRes == null) {
                return;
            }

            int appfilterid = iconPackRes.getIdentifier("appfilter", "xml", mCurrentIconTheme);
            if (appfilterid > 0) {
                xpp = iconPackRes.getXml(appfilterid);
            } else {
                // no resource found, try to open it from assets folder
                try {
                    InputStream is = iconPackRes.getAssets().open("appfilter.xml");

                    XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
                    factory.setNamespaceAware(true);
                    xpp = factory.newPullParser();
                    xpp.setInput(is, "utf-8");
                } catch (IOException e) {
                    Log.d(TAG, "Can't find appfilter.xml file in : " + mCurrentIconTheme);
                }
            }

            if (xpp != null) {
                int eventType = xpp.getEventType();
                while (eventType != XmlPullParser.END_DOCUMENT) {
                    if (eventType == XmlPullParser.START_TAG) {
                        if ("item".equals(xpp.getName())) {
                            String componentName = null;
                            String drawableName = null;

                            for (int i = 0; i < xpp.getAttributeCount(); i++) {
                                if ("component".equals(xpp.getAttributeName(i))) {
                                    componentName = xpp.getAttributeValue(i);
                                } else if ("drawable".equals(xpp.getAttributeName(i))) {
                                    drawableName = xpp.getAttributeValue(i);
                                }
                            }

                            if (TextUtils.isEmpty(componentName) || TextUtils.isEmpty(drawableName)) {
                                eventType = xpp.next();
                                continue;
                            }

                            try {
                                componentName = componentName.substring(componentName.indexOf('{') + 1,
                                        componentName.indexOf('}'));
                            } catch (StringIndexOutOfBoundsException e) {
                                Log.d(TAG, "Can't parse icon for package = " + componentName);
                                eventType = xpp.next();
                                continue;
                            }

                            ComponentName componentNameKey = ComponentName.unflattenFromString(componentName);
                            if (componentNameKey != null) {
                                mIconPackDrawables.put(componentNameKey, drawableName);
                            } else {
                                Log.d(TAG, "ComponentName can't be obtained from: " + componentName);
                            }
                        } else if ("iconback".equals(xpp.getName())) {
                            for (int i = 0; i < xpp.getAttributeCount(); i++) {
                                if (xpp.getAttributeName(i).startsWith("img")) {
                                    mIconBackgrounds.add(loadBitmapFromIconPack(xpp.getAttributeValue(i)));
                                }
                            }
                        } else if ("iconmask".equals(xpp.getName())) {
                            if (xpp.getAttributeCount() > 0 && "img1".equals(xpp.getAttributeName(0))) {
                                mIconMask = loadBitmapFromIconPack(xpp.getAttributeValue(0));
                            }
                        } else if ("iconupon".equals(xpp.getName())) {
                            if (xpp.getAttributeCount() > 0 && "img1".equals(xpp.getAttributeName(0))) {
                                mIconFront = loadBitmapFromIconPack(xpp.getAttributeValue(0));
                            }
                        } else if ("scale".equals(xpp.getName())) {
                            if (xpp.getAttributeCount() > 0 && "factor".equals(xpp.getAttributeName(0))) {
                                mIconScaleFactor = Float.valueOf(xpp.getAttributeValue(0));
                            }
                        }
                    }
                    eventType = xpp.next();
                }
            }
            Log.d(TAG, "Finished parsing icon pack: " + (SystemClock.uptimeMillis() - t) + "ms");
        } catch (XmlPullParserException e) {
            Log.d(TAG, "Cannot parse icon pack appfilter.xml" + e);
        } catch (IOException e) {
            Log.d(TAG, "Exception loading icon pack " + e);
        }
    }
}