Example usage for android.content ComponentName flattenToShortString

List of usage examples for android.content ComponentName flattenToShortString

Introduction

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

Prototype

public @NonNull String flattenToShortString() 

Source Link

Document

The same as #flattenToString() , but abbreviates the class name if it is a suffix of the package.

Usage

From source file:Main.java

public static String getVoiceSearchIMId(Context context) {
    ComponentName voiceInputComponent = new ComponentName("com.google.android.voicesearch",
            "com.google.android.voicesearch.ime.VoceInputMethdServce");
    if (DEBUG)//from w  ww  .  j a v  a 2s .  c  o m
        Log.i(TAG, "getVoiceSearchIMId(), Comonent name = " + voiceInputComponent.flattenToString() + ", id = "
                + voiceInputComponent.flattenToShortString());
    return voiceInputComponent.flattenToShortString();
}

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

@Override
protected void onHandleIntent(Intent intent) {
    if (intent == null || intent.getAction() == null) {
        return;/*from  ww w  .java2s .  c  o  m*/
    }

    String action = intent.getAction();
    if (!ACTION_PUBLISH_STATE.equals(action)) {
        return;
    }
    // Handle API call from source
    String token = intent.getStringExtra(EXTRA_TOKEN);
    ComponentName selectedSource = SourceManager.getSelectedSource(this);
    if (selectedSource == null || !TextUtils.equals(token, selectedSource.flattenToShortString())) {
        Log.w(TAG, "Dropping update from non-selected source, token=" + token + " does not match token for "
                + selectedSource);
        return;
    }

    SourceState state = null;
    if (intent.hasExtra(EXTRA_STATE)) {
        Bundle bundle = intent.getBundleExtra(EXTRA_STATE);
        if (bundle != null) {
            state = SourceState.fromBundle(bundle);
        }
    }

    if (state == null) {
        // If there is no state, there is nothing to change
        return;
    }

    ContentValues values = new ContentValues();
    values.put(MuzeiContract.Sources.COLUMN_NAME_COMPONENT_NAME, selectedSource.flattenToShortString());
    values.put(MuzeiContract.Sources.COLUMN_NAME_IS_SELECTED, true);
    values.put(MuzeiContract.Sources.COLUMN_NAME_DESCRIPTION, state.getDescription());
    values.put(MuzeiContract.Sources.COLUMN_NAME_WANTS_NETWORK_AVAILABLE, state.getWantsNetworkAvailable());
    JSONArray commandsSerialized = new JSONArray();
    int numSourceActions = state.getNumUserCommands();
    boolean supportsNextArtwork = false;
    for (int i = 0; i < numSourceActions; i++) {
        UserCommand command = state.getUserCommandAt(i);
        if (command.getId() == MuzeiArtSource.BUILTIN_COMMAND_ID_NEXT_ARTWORK) {
            supportsNextArtwork = true;
        } else {
            commandsSerialized.put(command.serialize());
        }
    }
    values.put(MuzeiContract.Sources.COLUMN_NAME_SUPPORTS_NEXT_ARTWORK_COMMAND, supportsNextArtwork);
    values.put(MuzeiContract.Sources.COLUMN_NAME_COMMANDS, commandsSerialized.toString());
    ContentResolver contentResolver = getContentResolver();
    Cursor existingSource = contentResolver.query(MuzeiContract.Sources.CONTENT_URI,
            new String[] { BaseColumns._ID }, MuzeiContract.Sources.COLUMN_NAME_COMPONENT_NAME + "=?",
            new String[] { selectedSource.flattenToShortString() }, null, null);
    if (existingSource != null && existingSource.moveToFirst()) {
        Uri sourceUri = ContentUris.withAppendedId(MuzeiContract.Sources.CONTENT_URI,
                existingSource.getLong(0));
        contentResolver.update(sourceUri, values, null, null);
    } else {
        contentResolver.insert(MuzeiContract.Sources.CONTENT_URI, values);
    }
    if (existingSource != null) {
        existingSource.close();
    }

    Artwork artwork = state.getCurrentArtwork();
    if (artwork != null) {
        artwork.setComponentName(selectedSource);
        contentResolver.insert(MuzeiContract.Artwork.CONTENT_URI, artwork.toContentValues());

        // Download the artwork contained from the newly published SourceState
        startService(TaskQueueService.getDownloadCurrentArtworkIntent(this));
    }
}

From source file:com.battlelancer.seriesguide.extensions.ExtensionManager.java

private synchronized void saveSubscriptions() {
    List<String> serializedSubscriptions = new ArrayList<>();
    for (ComponentName extension : mEnabledExtensions) {
        serializedSubscriptions.add(extension.flattenToShortString() + "|" + mSubscriptions.get(extension));
    }//w  w  w  .j av a  2  s  .c o m
    Timber.d("Saving " + serializedSubscriptions.size() + " subscriptions");
    JSONArray json = new JSONArray(serializedSubscriptions);
    mSharedPrefs.edit().putString(PREF_SUBSCRIPTIONS, json.toString()).apply();
}

From source file:com.stephenmcgruer.simpleupnp.fragments.FileBrowserFragment.java

@Override
public void onServiceDisconnected(ComponentName name) {
    Log.d(TAG, "onServiceDisconnected: " + name.flattenToShortString());
    mUpnpService = null;//from ww  w  .j  av  a 2s  . c  o m
}

From source file:com.stephenmcgruer.simpleupnp.fragments.FileBrowserFragment.java

@Override
public void onServiceConnected(ComponentName name, IBinder service) {
    Log.d(TAG, "onServiceConnected: " + name.flattenToShortString() + ", " + service.toString());

    mUpnpService = (AndroidUpnpService) service;

    Device device = mUpnpService.getRegistry().getDevice(new UDN(mDeviceUdn), false);
    mContentDirectoryService = device.findService(new UDAServiceType("ContentDirectory"));
    if (mContentDirectoryService == null) {
        throw new IllegalStateException("Unable to find ContentDirectory service for device " + mDeviceUdn);
    }//from  w w  w. j  av  a  2  s  . co m
    mDeviceName = (device.getDetails() != null && device.getDetails().getFriendlyName() != null)
            ? device.getDetails().getFriendlyName()
            : device.getDisplayString();

    selectContainer(mCurrentContainer);
}

From source file:com.battlelancer.seriesguide.api.SeriesGuideExtension.java

private synchronized void saveSubscriptions() {
    Set<String> serializedSubscriptions = new HashSet<String>();
    for (ComponentName subscriber : mSubscribers.keySet()) {
        serializedSubscriptions.add(subscriber.flattenToShortString() + "|" + mSubscribers.get(subscriber));
    }// w  w  w  .j  a v  a 2 s  .c o  m
    mSharedPrefs.edit().putStringSet(PREF_SUBSCRIPTIONS, serializedSubscriptions).commit();
}

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

public void handlePublishState(String token, SourceState state) {
    synchronized (this) {
        if (!TextUtils.equals(token, mSelectedSourceToken)) {
            LOGW(TAG, "Dropping update from non-selected source (token mismatch).");
            return;
        }//from w  w  w  .  ja va2  s  .c om

        if (state == null) {
            mSourceStates.remove(mSelectedSource);
        } else {
            mSourceStates.put(mSelectedSource, state);
        }

        try {
            StringBuilder sb = new StringBuilder();
            Set<String> sourceStates = new HashSet<String>();
            for (ComponentName source : mSourceStates.keySet()) {
                SourceState sourceState = mSourceStates.get(source);
                if (sourceState == null) {
                    continue;
                }

                sb.setLength(0);
                sb.append(source.flattenToShortString()).append("|").append(sourceState.toJson().toString());
                sourceStates.add(sb.toString());
            }

            mSharedPrefs.edit().putStringSet(PREF_SOURCE_STATES, sourceStates).apply();
        } catch (JSONException e) {
            LOGE(TAG, "Error storing source status data.", e);
        }
    }

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

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

public void handlePublishState(String token, SourceState state) {
    synchronized (this) {
        if (!TextUtils.equals(token, mSelectedSourceToken)) {
            Log.w(TAG, "Dropping update from non-selected source (token mismatch).");
            return;
        }//from  w  w w  . ja  v  a 2  s . co  m

        if (state == null) {
            mSourceStates.remove(mSelectedSource);
        } else {
            mSourceStates.put(mSelectedSource, state);
        }

        try {
            StringBuilder sb = new StringBuilder();
            Set<String> sourceStates = new HashSet<String>();
            for (ComponentName source : mSourceStates.keySet()) {
                SourceState sourceState = mSourceStates.get(source);
                if (sourceState == null) {
                    continue;
                }

                sb.setLength(0);
                sb.append(source.flattenToShortString()).append("|").append(sourceState.toJson().toString());
                sourceStates.add(sb.toString());
            }

            mSharedPrefs.edit().putStringSet(PREF_SOURCE_STATES, sourceStates).apply();
        } catch (JSONException e) {
            Log.e(TAG, "Error storing source status data.", e);
        }
    }

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

From source file:com.actionlauncher.api.LiveWallpaperSource.java

private synchronized void saveSubscriptions() {
    Set<String> serializedSubscriptions = new HashSet<String>();
    for (ComponentName subscriber : mSubscriptions.keySet()) {
        serializedSubscriptions.add(subscriber.flattenToShortString() + "|" + mSubscriptions.get(subscriber));
    }/*  w w  w . j  av a2 s  . co  m*/
    mSharedPrefs.edit().putStringSet(PREF_SUBSCRIPTIONS, serializedSubscriptions).commit();
}

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

@Override
public void onReceive(Context context, Intent intent) {
    ExtensionManager extensionManager = ExtensionManager.getInstance(context);
    if (extensionManager.cleanupExtensions()) {
        LOGD(TAG, "Extension cleanup performed and action taken.");

        Intent widgetUpdateIntent = new Intent(context, DashClockService.class);
        widgetUpdateIntent.setAction(DashClockService.ACTION_UPDATE_WIDGETS);
        startWakefulService(context, widgetUpdateIntent);
    }/*w  w w .j ava 2 s  . com*/

    // If this is a replacement or change in the package, update all active extensions from
    // this package.
    String action = intent.getAction();
    if (Intent.ACTION_PACKAGE_CHANGED.equals(action) || Intent.ACTION_PACKAGE_REPLACED.equals(action)) {
        String packageName = intent.getData().getSchemeSpecificPart();
        if (TextUtils.isEmpty(packageName)) {
            return;
        }

        Set<ComponentName> activeExtensions = extensionManager.getActiveExtensionNames();
        for (ComponentName cn : activeExtensions) {
            if (packageName.equals(cn.getPackageName())) {
                LOGD(TAG, "Package for extension " + cn + " changed; asking it for an update.");
                Intent extensionUpdateIntent = new Intent(context, DashClockService.class);
                extensionUpdateIntent.setAction(DashClockService.ACTION_UPDATE_EXTENSIONS);
                // TODO: UPDATE_REASON_PACKAGE_CHANGED
                extensionUpdateIntent.putExtra(DashClockService.EXTRA_COMPONENT_NAME,
                        cn.flattenToShortString());
                startWakefulService(context, extensionUpdateIntent);
            }
        }
    }
}