Example usage for android.os Bundle containsKey

List of usage examples for android.os Bundle containsKey

Introduction

In this page you can find the example usage for android.os Bundle containsKey.

Prototype

public boolean containsKey(String key) 

Source Link

Document

Returns true if the given key is contained in the mapping of this Bundle.

Usage

From source file:jp.sonymusicstudio.cast.castcompanionlibrary.utils.Utils.java

/**
 * Builds and returns a {@link MediaInfo} that was wrapped in a {@link Bundle} by
 * <code>mediaInfoToBundle</code>. It is assumed that the type of the {@link MediaInfo} is
 * {@code MediaMetaData.MEDIA_TYPE_MOVIE}
 *
 * @see <code>mediaInfoToBundle()</code>
 *///from   w w  w . j  a v a2 s  .  com
public static MediaInfo bundleToMediaInfo(Bundle wrapper) {
    if (wrapper == null) {
        return null;
    }

    MediaMetadata metaData = new MediaMetadata(wrapper.getInt(KEY_MEDIA_TYPE));

    metaData.putString(MediaMetadata.KEY_SUBTITLE, wrapper.getString(MediaMetadata.KEY_SUBTITLE));
    metaData.putString(MediaMetadata.KEY_TITLE, wrapper.getString(MediaMetadata.KEY_TITLE));
    metaData.putString(MediaMetadata.KEY_STUDIO, wrapper.getString(MediaMetadata.KEY_STUDIO));
    metaData.putString(MediaMetadata.KEY_ALBUM_ARTIST, wrapper.getString(MediaMetadata.KEY_ALBUM_ARTIST));
    metaData.putString(MediaMetadata.KEY_ALBUM_TITLE, wrapper.getString(MediaMetadata.KEY_ALBUM_TITLE));
    metaData.putString(MediaMetadata.KEY_COMPOSER, wrapper.getString(MediaMetadata.KEY_COMPOSER));
    metaData.putString(MediaMetadata.KEY_SERIES_TITLE, wrapper.getString(MediaMetadata.KEY_SERIES_TITLE));

    metaData.putInt(MediaMetadata.KEY_SEASON_NUMBER, wrapper.getInt(MediaMetadata.KEY_SEASON_NUMBER));
    metaData.putInt(MediaMetadata.KEY_EPISODE_NUMBER, wrapper.getInt(MediaMetadata.KEY_EPISODE_NUMBER));

    long releaseDateMillis = wrapper.getLong(MediaMetadata.KEY_RELEASE_DATE, 0);
    if (releaseDateMillis > 0) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(releaseDateMillis);
        metaData.putDate(MediaMetadata.KEY_RELEASE_DATE, calendar);
    }

    ArrayList<String> images = wrapper.getStringArrayList(KEY_IMAGES);
    if (images != null && !images.isEmpty()) {
        for (String url : images) {
            Uri uri = Uri.parse(url);
            metaData.addImage(new WebImage(uri));
        }
    }

    String customDataStr = wrapper.getString(KEY_CUSTOM_DATA);
    JSONObject customData = null;
    if (!TextUtils.isEmpty(customDataStr)) {
        try {
            customData = new JSONObject(customDataStr);
        } catch (JSONException e) {
            LOGE(TAG, "Failed to deserialize the custom data string: custom data= " + customDataStr);
        }
    }

    List<MediaTrack> mediaTracks = null;
    if (wrapper.getString(KEY_TRACKS_DATA) != null) {
        try {
            JSONArray jsonArray = new JSONArray(wrapper.getString(KEY_TRACKS_DATA));
            mediaTracks = new ArrayList<MediaTrack>();

            if (jsonArray.length() > 0) {
                for (int i = 0; i < jsonArray.length(); i++) {
                    JSONObject jsonObj = (JSONObject) jsonArray.get(i);
                    MediaTrack.Builder builder = new MediaTrack.Builder(jsonObj.getLong(KEY_TRACK_ID),
                            jsonObj.getInt(KEY_TRACK_TYPE));
                    if (jsonObj.has(KEY_TRACK_NAME)) {
                        builder.setName(jsonObj.getString(KEY_TRACK_NAME));
                    }
                    if (jsonObj.has(KEY_TRACK_SUBTYPE)) {
                        builder.setSubtype(jsonObj.getInt(KEY_TRACK_SUBTYPE));
                    }
                    if (jsonObj.has(KEY_TRACK_CONTENT_ID)) {
                        builder.setContentType(jsonObj.getString(KEY_TRACK_CONTENT_ID));
                    }
                    if (jsonObj.has(KEY_TRACK_LANGUAGE)) {
                        builder.setLanguage(jsonObj.getString(KEY_TRACK_LANGUAGE));
                    }
                    if (jsonObj.has(KEY_TRACKS_DATA)) {
                        builder.setCustomData(new JSONObject(jsonObj.getString(KEY_TRACKS_DATA)));
                    }
                    mediaTracks.add(builder.build());
                }
            }

        } catch (JSONException e) {
            LOGE(TAG, "Failed to build media tracks from the wrapper bundle", e);
        }
    }
    MediaInfo.Builder mediaBuilder = new MediaInfo.Builder(wrapper.getString(KEY_URL))
            .setStreamType(wrapper.getInt(KEY_STREAM_TYPE)).setContentType(wrapper.getString(KEY_CONTENT_TYPE))
            .setMetadata(metaData).setCustomData(customData).setMediaTracks(mediaTracks);

    if (wrapper.containsKey(KEY_STREAM_DURATION) && wrapper.getLong(KEY_STREAM_DURATION) >= 0) {
        mediaBuilder.setStreamDuration(wrapper.getLong(KEY_STREAM_DURATION));
    }

    return mediaBuilder.build();
}

From source file:de.vanita5.twittnuker.util.Utils.java

public static Fragment createFragmentForIntent(final Context context, final Intent intent) {
    final long start = System.currentTimeMillis();
    intent.setExtrasClassLoader(context.getClassLoader());
    final Bundle extras = intent.getExtras();
    final Uri uri = intent.getData();
    final Fragment fragment;
    if (uri == null)
        return null;
    final Bundle args = new Bundle();
    if (extras != null) {
        args.putAll(extras);/*from  ww  w.j av a  2s .  c o  m*/
    }
    switch (matchLinkId(uri)) {
    case LINK_ID_STATUS: {
        fragment = new StatusFragment();
        if (!args.containsKey(EXTRA_STATUS_ID)) {
            final String param_status_id = uri.getQueryParameter(QUERY_PARAM_STATUS_ID);
            args.putLong(EXTRA_STATUS_ID, ParseUtils.parseLong(param_status_id));
        }
        break;
    }
    case LINK_ID_USER: {
        fragment = new UserProfileFragment();
        final String paramScreenName = uri.getQueryParameter(QUERY_PARAM_SCREEN_NAME);
        final String param_user_id = uri.getQueryParameter(QUERY_PARAM_USER_ID);
        if (!args.containsKey(EXTRA_SCREEN_NAME)) {
            args.putString(EXTRA_SCREEN_NAME, paramScreenName);
        }
        if (!args.containsKey(EXTRA_USER_ID)) {
            args.putLong(EXTRA_USER_ID, ParseUtils.parseLong(param_user_id));
        }
        break;
    }
    case LINK_ID_USER_LIST_MEMBERSHIPS: {
        fragment = new UserListMembershipsListFragment();
        final String paramScreenName = uri.getQueryParameter(QUERY_PARAM_SCREEN_NAME);
        final String param_user_id = uri.getQueryParameter(QUERY_PARAM_USER_ID);
        if (!args.containsKey(EXTRA_SCREEN_NAME)) {
            args.putString(EXTRA_SCREEN_NAME, paramScreenName);
        }
        if (!args.containsKey(EXTRA_USER_ID)) {
            args.putLong(EXTRA_USER_ID, ParseUtils.parseLong(param_user_id));
        }
        break;
    }
    case LINK_ID_USER_TIMELINE: {
        fragment = new UserTimelineFragment();
        final String paramScreenName = uri.getQueryParameter(QUERY_PARAM_SCREEN_NAME);
        final String param_user_id = uri.getQueryParameter(QUERY_PARAM_USER_ID);
        if (!args.containsKey(EXTRA_SCREEN_NAME)) {
            args.putString(EXTRA_SCREEN_NAME, paramScreenName);
        }
        if (!args.containsKey(EXTRA_USER_ID)) {
            args.putLong(EXTRA_USER_ID, ParseUtils.parseLong(param_user_id));
        }
        if (isEmpty(paramScreenName) && isEmpty(param_user_id))
            return null;
        break;
    }
    case LINK_ID_USER_FAVORITES: {
        fragment = new UserFavoritesFragment();
        final String paramScreenName = uri.getQueryParameter(QUERY_PARAM_SCREEN_NAME);
        final String paramUserId = uri.getQueryParameter(QUERY_PARAM_USER_ID);
        if (!args.containsKey(EXTRA_SCREEN_NAME)) {
            args.putString(EXTRA_SCREEN_NAME, paramScreenName);
        }
        if (!args.containsKey(EXTRA_USER_ID)) {
            args.putLong(EXTRA_USER_ID, ParseUtils.parseLong(paramUserId));
        }
        if (!args.containsKey(EXTRA_SCREEN_NAME) && !args.containsKey(EXTRA_USER_ID))
            return null;
        break;
    }
    case LINK_ID_USER_FOLLOWERS: {
        fragment = new UserFollowersFragment();
        final String paramScreenName = uri.getQueryParameter(QUERY_PARAM_SCREEN_NAME);
        final String param_user_id = uri.getQueryParameter(QUERY_PARAM_USER_ID);
        if (!args.containsKey(EXTRA_SCREEN_NAME)) {
            args.putString(EXTRA_SCREEN_NAME, paramScreenName);
        }
        if (!args.containsKey(EXTRA_USER_ID)) {
            args.putLong(EXTRA_USER_ID, ParseUtils.parseLong(param_user_id));
        }
        if (isEmpty(paramScreenName) && isEmpty(param_user_id))
            return null;
        break;
    }
    case LINK_ID_USER_FRIENDS: {
        fragment = new UserFriendsFragment();
        final String paramScreenName = uri.getQueryParameter(QUERY_PARAM_SCREEN_NAME);
        final String param_user_id = uri.getQueryParameter(QUERY_PARAM_USER_ID);
        if (!args.containsKey(EXTRA_SCREEN_NAME)) {
            args.putString(EXTRA_SCREEN_NAME, paramScreenName);
        }
        if (!args.containsKey(EXTRA_USER_ID)) {
            args.putLong(EXTRA_USER_ID, ParseUtils.parseLong(param_user_id));
        }
        if (isEmpty(paramScreenName) && isEmpty(param_user_id))
            return null;
        break;
    }
    case LINK_ID_USER_BLOCKS: {
        fragment = new UserBlocksListFragment();
        break;
    }
    case LINK_ID_MUTES_USERS: {
        fragment = new MutesUsersListFragment();
        break;
    }
    case LINK_ID_DIRECT_MESSAGES_CONVERSATION: {
        fragment = new DirectMessagesConversationFragment();
        final String paramRecipientId = uri.getQueryParameter(QUERY_PARAM_RECIPIENT_ID);
        final String paramScreenName = uri.getQueryParameter(QUERY_PARAM_SCREEN_NAME);
        final long conversationId = ParseUtils.parseLong(paramRecipientId);
        if (conversationId > 0) {
            args.putLong(EXTRA_RECIPIENT_ID, conversationId);
        } else if (paramScreenName != null) {
            args.putString(EXTRA_SCREEN_NAME, paramScreenName);
        }
        break;
    }
    case LINK_ID_USER_LIST: {
        fragment = new UserListDetailsFragment();
        final String paramScreenName = uri.getQueryParameter(QUERY_PARAM_SCREEN_NAME);
        final String param_user_id = uri.getQueryParameter(QUERY_PARAM_USER_ID);
        final String param_list_id = uri.getQueryParameter(QUERY_PARAM_LIST_ID);
        final String paramListName = uri.getQueryParameter(QUERY_PARAM_LIST_NAME);
        if (isEmpty(param_list_id)
                && (isEmpty(paramListName) || isEmpty(paramScreenName) && isEmpty(param_user_id)))
            return null;
        args.putInt(EXTRA_LIST_ID, ParseUtils.parseInt(param_list_id));
        args.putLong(EXTRA_USER_ID, ParseUtils.parseLong(param_user_id));
        args.putString(EXTRA_SCREEN_NAME, paramScreenName);
        args.putString(EXTRA_LIST_NAME, paramListName);
        break;
    }
    case LINK_ID_USER_LISTS: {
        fragment = new UserListsListFragment();
        final String paramScreenName = uri.getQueryParameter(QUERY_PARAM_SCREEN_NAME);
        final String param_user_id = uri.getQueryParameter(QUERY_PARAM_USER_ID);
        if (!args.containsKey(EXTRA_SCREEN_NAME)) {
            args.putString(EXTRA_SCREEN_NAME, paramScreenName);
        }
        if (!args.containsKey(EXTRA_USER_ID)) {
            args.putLong(EXTRA_USER_ID, ParseUtils.parseLong(param_user_id));
        }
        if (isEmpty(paramScreenName) && isEmpty(param_user_id))
            return null;
        break;
    }
    case LINK_ID_USER_LIST_TIMELINE: {
        fragment = new UserListTimelineFragment();
        final String paramScreenName = uri.getQueryParameter(QUERY_PARAM_SCREEN_NAME);
        final String param_user_id = uri.getQueryParameter(QUERY_PARAM_USER_ID);
        final String param_list_id = uri.getQueryParameter(QUERY_PARAM_LIST_ID);
        final String paramListName = uri.getQueryParameter(QUERY_PARAM_LIST_NAME);
        if (isEmpty(param_list_id)
                && (isEmpty(paramListName) || isEmpty(paramScreenName) && isEmpty(param_user_id)))
            return null;
        args.putInt(EXTRA_LIST_ID, ParseUtils.parseInt(param_list_id));
        args.putLong(EXTRA_USER_ID, ParseUtils.parseLong(param_user_id));
        args.putString(EXTRA_SCREEN_NAME, paramScreenName);
        args.putString(EXTRA_LIST_NAME, paramListName);
        break;
    }
    case LINK_ID_USER_LIST_MEMBERS: {
        fragment = new UserListMembersFragment();
        final String paramScreenName = uri.getQueryParameter(QUERY_PARAM_SCREEN_NAME);
        final String param_user_id = uri.getQueryParameter(QUERY_PARAM_USER_ID);
        final String param_list_id = uri.getQueryParameter(QUERY_PARAM_LIST_ID);
        final String paramListName = uri.getQueryParameter(QUERY_PARAM_LIST_NAME);
        if (isEmpty(param_list_id)
                && (isEmpty(paramListName) || isEmpty(paramScreenName) && isEmpty(param_user_id)))
            return null;
        args.putInt(EXTRA_LIST_ID, ParseUtils.parseInt(param_list_id));
        args.putLong(EXTRA_USER_ID, ParseUtils.parseLong(param_user_id));
        args.putString(EXTRA_SCREEN_NAME, paramScreenName);
        args.putString(EXTRA_LIST_NAME, paramListName);
        break;
    }
    case LINK_ID_USER_LIST_SUBSCRIBERS: {
        fragment = new UserListSubscribersFragment();
        final String paramScreenName = uri.getQueryParameter(QUERY_PARAM_SCREEN_NAME);
        final String param_user_id = uri.getQueryParameter(QUERY_PARAM_USER_ID);
        final String param_list_id = uri.getQueryParameter(QUERY_PARAM_LIST_ID);
        final String paramListName = uri.getQueryParameter(QUERY_PARAM_LIST_NAME);
        if (isEmpty(param_list_id)
                && (isEmpty(paramListName) || isEmpty(paramScreenName) && isEmpty(param_user_id)))
            return null;
        args.putInt(EXTRA_LIST_ID, ParseUtils.parseInt(param_list_id));
        args.putLong(EXTRA_USER_ID, ParseUtils.parseLong(param_user_id));
        args.putString(EXTRA_SCREEN_NAME, paramScreenName);
        args.putString(EXTRA_LIST_NAME, paramListName);
        break;
    }
    case LINK_ID_SAVED_SEARCHES: {
        fragment = new SavedSearchesListFragment();
        break;
    }
    case LINK_ID_USER_MENTIONS: {
        fragment = new UserMentionsFragment();
        final String paramScreenName = uri.getQueryParameter(QUERY_PARAM_SCREEN_NAME);
        if (!args.containsKey(EXTRA_SCREEN_NAME) && !isEmpty(paramScreenName)) {
            args.putString(EXTRA_SCREEN_NAME, paramScreenName);
        }
        if (isEmpty(args.getString(EXTRA_SCREEN_NAME)))
            return null;
        break;
    }
    case LINK_ID_INCOMING_FRIENDSHIPS: {
        fragment = new IncomingFriendshipsFragment();
        break;
    }
    case LINK_ID_USERS: {
        fragment = new UsersListFragment();
        break;
    }
    case LINK_ID_STATUSES: {
        fragment = new StatusesListFragment();
        break;
    }
    case LINK_ID_STATUS_RETWEETERS: {
        fragment = new StatusRetweetersListFragment();
        if (!args.containsKey(EXTRA_STATUS_ID)) {
            final String param_status_id = uri.getQueryParameter(QUERY_PARAM_STATUS_ID);
            args.putLong(EXTRA_STATUS_ID, ParseUtils.parseLong(param_status_id));
        }
        break;
    }
    case LINK_ID_STATUS_FAVORITERS: {
        fragment = new StatusFavoritersListFragment();
        if (!args.containsKey(EXTRA_STATUS_ID)) {
            final String param_status_id = uri.getQueryParameter(QUERY_PARAM_STATUS_ID);
            args.putLong(EXTRA_STATUS_ID, ParseUtils.parseLong(param_status_id));
        }
        break;
    }
    case LINK_ID_STATUS_REPLIES: {
        fragment = new StatusRepliesListFragment();
        if (!args.containsKey(EXTRA_STATUS_ID)) {
            final String paramStatusId = uri.getQueryParameter(QUERY_PARAM_STATUS_ID);
            args.putLong(EXTRA_STATUS_ID, ParseUtils.parseLong(paramStatusId));
        }
        if (!args.containsKey(EXTRA_SCREEN_NAME)) {
            final String paramScreenName = uri.getQueryParameter(QUERY_PARAM_SCREEN_NAME);
            args.putString(EXTRA_SCREEN_NAME, paramScreenName);
        }
        break;
    }
    case LINK_ID_SEARCH: {
        final String param_query = uri.getQueryParameter(QUERY_PARAM_QUERY);
        if (isEmpty(param_query))
            return null;
        args.putString(EXTRA_QUERY, param_query);
        fragment = new SearchFragment();
        break;
    }
    default: {
        return null;
    }
    }
    final String param_account_id = uri.getQueryParameter(QUERY_PARAM_ACCOUNT_ID);
    if (param_account_id != null) {
        args.putLong(EXTRA_ACCOUNT_ID, ParseUtils.parseLong(param_account_id));
    } else {
        final String param_account_name = uri.getQueryParameter(QUERY_PARAM_ACCOUNT_NAME);
        if (param_account_name != null) {
            args.putLong(EXTRA_ACCOUNT_ID, getAccountId(context, param_account_name));
        } else {
            final long account_id = getDefaultAccountId(context);
            if (isMyAccount(context, account_id)) {
                args.putLong(EXTRA_ACCOUNT_ID, account_id);
            }
        }
    }
    fragment.setArguments(args);
    if (isDebugBuild()) {
        Log.d(LOGTAG, String.format("createFragmentForIntent used %d ms", System.currentTimeMillis() - start));
    }
    return fragment;
}

From source file:org.getlantern.firetweet.util.Utils.java

public static Fragment createFragmentForIntent(final Context context, final int linkId, final Intent intent) {
    intent.setExtrasClassLoader(context.getClassLoader());
    final Bundle extras = intent.getExtras();
    final Uri uri = intent.getData();
    final Fragment fragment;
    if (uri == null)
        return null;
    final Bundle args = new Bundle();
    if (extras != null) {
        args.putAll(extras);//  w  ww . j  a  v a  2 s . c om
    }
    switch (linkId) {
    case LINK_ID_STATUS: {
        fragment = new StatusFragment();
        if (!args.containsKey(EXTRA_STATUS_ID)) {
            final String param_status_id = uri.getQueryParameter(QUERY_PARAM_STATUS_ID);
            args.putLong(EXTRA_STATUS_ID, ParseUtils.parseLong(param_status_id));
        }
        break;
    }
    case LINK_ID_USER: {
        fragment = new UserFragment();
        final String paramScreenName = uri.getQueryParameter(QUERY_PARAM_SCREEN_NAME);
        final String param_user_id = uri.getQueryParameter(QUERY_PARAM_USER_ID);
        if (!args.containsKey(EXTRA_SCREEN_NAME)) {
            args.putString(EXTRA_SCREEN_NAME, paramScreenName);
        }
        if (!args.containsKey(EXTRA_USER_ID)) {
            args.putLong(EXTRA_USER_ID, ParseUtils.parseLong(param_user_id));
        }
        break;
    }
    case LINK_ID_USER_LIST_MEMBERSHIPS: {
        fragment = new UserListMembershipsListFragment();
        final String paramScreenName = uri.getQueryParameter(QUERY_PARAM_SCREEN_NAME);
        final String paramUserId = uri.getQueryParameter(QUERY_PARAM_USER_ID);
        if (!args.containsKey(EXTRA_SCREEN_NAME)) {
            args.putString(EXTRA_SCREEN_NAME, paramScreenName);
        }
        if (!args.containsKey(EXTRA_USER_ID)) {
            args.putLong(EXTRA_USER_ID, ParseUtils.parseLong(paramUserId));
        }
        break;
    }
    case LINK_ID_USER_TIMELINE: {
        fragment = new UserTimelineFragment();
        final String paramScreenName = uri.getQueryParameter(QUERY_PARAM_SCREEN_NAME);
        final String paramUserId = uri.getQueryParameter(QUERY_PARAM_USER_ID);
        if (!args.containsKey(EXTRA_SCREEN_NAME)) {
            args.putString(EXTRA_SCREEN_NAME, paramScreenName);
        }
        if (!args.containsKey(EXTRA_USER_ID)) {
            args.putLong(EXTRA_USER_ID, ParseUtils.parseLong(paramUserId));
        }
        if (isEmpty(paramScreenName) && isEmpty(paramUserId))
            return null;
        break;
    }
    case LINK_ID_USER_MEDIA_TIMELINE: {
        fragment = new UserMediaTimelineFragment();
        final String paramScreenName = uri.getQueryParameter(QUERY_PARAM_SCREEN_NAME);
        final String paramUserId = uri.getQueryParameter(QUERY_PARAM_USER_ID);
        if (!args.containsKey(EXTRA_SCREEN_NAME)) {
            args.putString(EXTRA_SCREEN_NAME, paramScreenName);
        }
        if (!args.containsKey(EXTRA_USER_ID)) {
            args.putLong(EXTRA_USER_ID, ParseUtils.parseLong(paramUserId));
        }
        if (isEmpty(paramScreenName) && isEmpty(paramUserId))
            return null;
        break;
    }
    case LINK_ID_USER_FAVORITES: {
        fragment = new UserFavoritesFragment();
        final String paramScreenName = uri.getQueryParameter(QUERY_PARAM_SCREEN_NAME);
        final String paramUserId = uri.getQueryParameter(QUERY_PARAM_USER_ID);
        if (!args.containsKey(EXTRA_SCREEN_NAME)) {
            args.putString(EXTRA_SCREEN_NAME, paramScreenName);
        }
        if (!args.containsKey(EXTRA_USER_ID)) {
            args.putLong(EXTRA_USER_ID, ParseUtils.parseLong(paramUserId));
        }
        if (!args.containsKey(EXTRA_SCREEN_NAME) && !args.containsKey(EXTRA_USER_ID))
            return null;
        break;
    }
    case LINK_ID_USER_FOLLOWERS: {
        fragment = new UserFollowersFragment();
        final String paramScreenName = uri.getQueryParameter(QUERY_PARAM_SCREEN_NAME);
        final String param_user_id = uri.getQueryParameter(QUERY_PARAM_USER_ID);
        if (!args.containsKey(EXTRA_SCREEN_NAME)) {
            args.putString(EXTRA_SCREEN_NAME, paramScreenName);
        }
        if (!args.containsKey(EXTRA_USER_ID)) {
            args.putLong(EXTRA_USER_ID, ParseUtils.parseLong(param_user_id));
        }
        if (isEmpty(paramScreenName) && isEmpty(param_user_id))
            return null;
        break;
    }
    case LINK_ID_USER_FRIENDS: {
        fragment = new UserFriendsFragment();
        final String paramScreenName = uri.getQueryParameter(QUERY_PARAM_SCREEN_NAME);
        final String param_user_id = uri.getQueryParameter(QUERY_PARAM_USER_ID);
        if (!args.containsKey(EXTRA_SCREEN_NAME)) {
            args.putString(EXTRA_SCREEN_NAME, paramScreenName);
        }
        if (!args.containsKey(EXTRA_USER_ID)) {
            args.putLong(EXTRA_USER_ID, ParseUtils.parseLong(param_user_id));
        }
        if (isEmpty(paramScreenName) && isEmpty(param_user_id))
            return null;
        break;
    }
    case LINK_ID_USER_BLOCKS: {
        fragment = new UserBlocksListFragment();
        break;
    }
    case LINK_ID_MUTES_USERS: {
        fragment = new MutesUsersListFragment();
        break;
    }
    case LINK_ID_DIRECT_MESSAGES_CONVERSATION: {
        fragment = new MessagesConversationFragment();
        final String paramRecipientId = uri.getQueryParameter(QUERY_PARAM_RECIPIENT_ID);
        final String paramScreenName = uri.getQueryParameter(QUERY_PARAM_SCREEN_NAME);
        final long conversationId = ParseUtils.parseLong(paramRecipientId);
        if (conversationId > 0) {
            args.putLong(EXTRA_RECIPIENT_ID, conversationId);
        } else if (paramScreenName != null) {
            args.putString(EXTRA_SCREEN_NAME, paramScreenName);
        }
        break;
    }
    case LINK_ID_USER_LIST: {
        fragment = new UserListFragment();
        final String paramScreenName = uri.getQueryParameter(QUERY_PARAM_SCREEN_NAME);
        final String paramUserId = uri.getQueryParameter(QUERY_PARAM_USER_ID);
        final String paramListId = uri.getQueryParameter(QUERY_PARAM_LIST_ID);
        final String paramListName = uri.getQueryParameter(QUERY_PARAM_LIST_NAME);
        if (isEmpty(paramListId)
                && (isEmpty(paramListName) || isEmpty(paramScreenName) && isEmpty(paramUserId)))
            return null;
        args.putLong(EXTRA_LIST_ID, ParseUtils.parseLong(paramListId));
        args.putLong(EXTRA_USER_ID, ParseUtils.parseLong(paramUserId));
        args.putString(EXTRA_SCREEN_NAME, paramScreenName);
        args.putString(EXTRA_LIST_NAME, paramListName);
        break;
    }
    case LINK_ID_USER_LISTS: {
        fragment = new UserListsFragment();
        final String paramScreenName = uri.getQueryParameter(QUERY_PARAM_SCREEN_NAME);
        final String paramUserId = uri.getQueryParameter(QUERY_PARAM_USER_ID);
        if (!args.containsKey(EXTRA_SCREEN_NAME)) {
            args.putString(EXTRA_SCREEN_NAME, paramScreenName);
        }
        if (!args.containsKey(EXTRA_USER_ID)) {
            args.putLong(EXTRA_USER_ID, ParseUtils.parseLong(paramUserId));
        }
        if (isEmpty(paramScreenName) && isEmpty(paramUserId))
            return null;
        break;
    }
    case LINK_ID_USER_LIST_TIMELINE: {
        fragment = new UserListTimelineFragment();
        final String paramScreenName = uri.getQueryParameter(QUERY_PARAM_SCREEN_NAME);
        final String paramUserId = uri.getQueryParameter(QUERY_PARAM_USER_ID);
        final String paramListId = uri.getQueryParameter(QUERY_PARAM_LIST_ID);
        final String paramListName = uri.getQueryParameter(QUERY_PARAM_LIST_NAME);
        if (isEmpty(paramListId)
                && (isEmpty(paramListName) || isEmpty(paramScreenName) && isEmpty(paramUserId)))
            return null;
        args.putLong(EXTRA_LIST_ID, ParseUtils.parseLong(paramListId));
        args.putLong(EXTRA_USER_ID, ParseUtils.parseLong(paramUserId));
        args.putString(EXTRA_SCREEN_NAME, paramScreenName);
        args.putString(EXTRA_LIST_NAME, paramListName);
        break;
    }
    case LINK_ID_USER_LIST_MEMBERS: {
        fragment = new UserListMembersFragment();
        final String paramScreenName = uri.getQueryParameter(QUERY_PARAM_SCREEN_NAME);
        final String paramUserId = uri.getQueryParameter(QUERY_PARAM_USER_ID);
        final String paramListId = uri.getQueryParameter(QUERY_PARAM_LIST_ID);
        final String paramListName = uri.getQueryParameter(QUERY_PARAM_LIST_NAME);
        if (isEmpty(paramListId)
                && (isEmpty(paramListName) || isEmpty(paramScreenName) && isEmpty(paramUserId)))
            return null;
        args.putLong(EXTRA_LIST_ID, ParseUtils.parseLong(paramListId));
        args.putLong(EXTRA_USER_ID, ParseUtils.parseLong(paramUserId));
        args.putString(EXTRA_SCREEN_NAME, paramScreenName);
        args.putString(EXTRA_LIST_NAME, paramListName);
        break;
    }
    case LINK_ID_USER_LIST_SUBSCRIBERS: {
        fragment = new UserListSubscribersFragment();
        final String paramScreenName = uri.getQueryParameter(QUERY_PARAM_SCREEN_NAME);
        final String paramUserId = uri.getQueryParameter(QUERY_PARAM_USER_ID);
        final String paramListId = uri.getQueryParameter(QUERY_PARAM_LIST_ID);
        final String paramListName = uri.getQueryParameter(QUERY_PARAM_LIST_NAME);
        if (isEmpty(paramListId)
                && (isEmpty(paramListName) || isEmpty(paramScreenName) && isEmpty(paramUserId)))
            return null;
        args.putLong(EXTRA_LIST_ID, ParseUtils.parseLong(paramListId));
        args.putLong(EXTRA_USER_ID, ParseUtils.parseLong(paramUserId));
        args.putString(EXTRA_SCREEN_NAME, paramScreenName);
        args.putString(EXTRA_LIST_NAME, paramListName);
        break;
    }
    case LINK_ID_SAVED_SEARCHES: {
        fragment = new SavedSearchesListFragment();
        break;
    }
    case LINK_ID_USER_MENTIONS: {
        fragment = new UserMentionsFragment();
        final String paramScreenName = uri.getQueryParameter(QUERY_PARAM_SCREEN_NAME);
        if (!args.containsKey(EXTRA_SCREEN_NAME) && !isEmpty(paramScreenName)) {
            args.putString(EXTRA_SCREEN_NAME, paramScreenName);
        }
        if (isEmpty(args.getString(EXTRA_SCREEN_NAME)))
            return null;
        break;
    }
    case LINK_ID_INCOMING_FRIENDSHIPS: {
        fragment = new IncomingFriendshipsFragment();
        break;
    }
    case LINK_ID_USERS: {
        fragment = new UsersListFragment();
        break;
    }
    case LINK_ID_STATUSES: {
        fragment = new StatusesListFragment();
        break;
    }
    case LINK_ID_STATUS_RETWEETERS: {
        fragment = new StatusRetweetersListFragment();
        if (!args.containsKey(EXTRA_STATUS_ID)) {
            final String paramStatusId = uri.getQueryParameter(QUERY_PARAM_STATUS_ID);
            args.putLong(EXTRA_STATUS_ID, ParseUtils.parseLong(paramStatusId));
        }
        break;
    }
    case LINK_ID_STATUS_FAVORITERS: {
        fragment = new StatusFavoritersListFragment();
        if (!args.containsKey(EXTRA_STATUS_ID)) {
            final String paramStatusId = uri.getQueryParameter(QUERY_PARAM_STATUS_ID);
            args.putLong(EXTRA_STATUS_ID, ParseUtils.parseLong(paramStatusId));
        }
        break;
    }
    case LINK_ID_STATUS_REPLIES: {
        fragment = new StatusRepliesListFragment();
        if (!args.containsKey(EXTRA_STATUS_ID)) {
            final String paramStatusId = uri.getQueryParameter(QUERY_PARAM_STATUS_ID);
            args.putLong(EXTRA_STATUS_ID, ParseUtils.parseLong(paramStatusId));
        }
        if (!args.containsKey(EXTRA_SCREEN_NAME)) {
            final String paramScreenName = uri.getQueryParameter(QUERY_PARAM_SCREEN_NAME);
            args.putString(EXTRA_SCREEN_NAME, paramScreenName);
        }
        break;
    }
    case LINK_ID_SEARCH: {
        final String param_query = uri.getQueryParameter(QUERY_PARAM_QUERY);
        if (isEmpty(param_query))
            return null;
        args.putString(EXTRA_QUERY, param_query);
        fragment = new SearchFragment();
        break;
    }
    default: {
        return null;
    }
    }
    final String paramAccountId = uri.getQueryParameter(QUERY_PARAM_ACCOUNT_ID);
    if (paramAccountId != null) {
        args.putLong(EXTRA_ACCOUNT_ID, ParseUtils.parseLong(paramAccountId));
    } else {
        final String paramAccountName = uri.getQueryParameter(QUERY_PARAM_ACCOUNT_NAME);
        if (paramAccountName != null) {
            args.putLong(EXTRA_ACCOUNT_ID, getAccountId(context, paramAccountName));
        } else {
            final long accountId = getDefaultAccountId(context);
            if (isMyAccount(context, accountId)) {
                args.putLong(EXTRA_ACCOUNT_ID, accountId);
            }
        }
    }
    fragment.setArguments(args);
    return fragment;
}

From source file:cl.gisred.android.InspActivity.java

@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
    super.onRestoreInstanceState(savedInstanceState);
    if (savedInstanceState.containsKey("Uri")) {
        mImageUri = Uri.parse(savedInstanceState.getString("Uri"));
    }//from  www .j a  va2 s  .  co  m
    if (savedInstanceState.containsKey("req")) {
        int req = (int) savedInstanceState.get("req");
        if (req == ActivityInfo.SCREEN_ORIENTATION_LOCKED)
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LOCKED);
    }
}

From source file:com.irccloud.android.fragment.BuffersListFragment.java

@SuppressWarnings("unchecked")
@Override//from  w w w  . j  a va  2 s.c o m
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    conn = NetworkConnection.getInstance();
    view = inflater.inflate(R.layout.bufferslist, null);
    topUnreadIndicator = (LinearLayout) view.findViewById(R.id.topUnreadIndicator);
    topUnreadIndicator.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            int scrollTo = adapter.unreadPositionAbove(getListView().getFirstVisiblePosition());
            if (scrollTo > 0)
                getListView().setSelection(scrollTo - 1);
            else
                getListView().setSelection(0);

            updateUnreadIndicators(getListView().getFirstVisiblePosition(),
                    getListView().getLastVisiblePosition());
        }

    });
    topUnreadIndicatorColor = (LinearLayout) view.findViewById(R.id.topUnreadIndicatorColor);
    topUnreadIndicatorBorder = (LinearLayout) view.findViewById(R.id.topUnreadIndicatorBorder);
    bottomUnreadIndicator = (LinearLayout) view.findViewById(R.id.bottomUnreadIndicator);
    bottomUnreadIndicator.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            int offset = getListView().getLastVisiblePosition() - getListView().getFirstVisiblePosition();
            int scrollTo = adapter.unreadPositionBelow(getListView().getLastVisiblePosition()) - offset + 2;
            if (scrollTo < adapter.getCount())
                getListView().setSelection(scrollTo);
            else
                getListView().setSelection(adapter.getCount() - 1);

            updateUnreadIndicators(getListView().getFirstVisiblePosition(),
                    getListView().getLastVisiblePosition());
        }

    });
    bottomUnreadIndicatorColor = (LinearLayout) view.findViewById(R.id.bottomUnreadIndicatorColor);
    bottomUnreadIndicatorBorder = (LinearLayout) view.findViewById(R.id.bottomUnreadIndicatorBorder);
    listView = (ListView) view.findViewById(android.R.id.list);
    listView.setOnScrollListener(new OnScrollListener() {
        @Override
        public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
            updateUnreadIndicators(firstVisibleItem, firstVisibleItem + visibleItemCount - 1);
        }

        @Override
        public void onScrollStateChanged(AbsListView view, int scrollState) {
        }
    });
    listView.setOnItemLongClickListener(new OnItemLongClickListener() {

        @Override
        public boolean onItemLongClick(AdapterView<?> arg0, View arg1, int pos, long id) {
            return mListener
                    .onBufferLongClicked(BuffersDataSource.getInstance().getBuffer(adapter.data.get(pos).bid));
        }

    });

    ready = NetworkConnection.getInstance().ready;

    if (ready) {
        if (savedInstanceState != null && savedInstanceState.containsKey("expandedArchives")) {
            ArrayList<Integer> expandedArchives = savedInstanceState.getIntegerArrayList("expandedArchives");
            Iterator<Integer> i = expandedArchives.iterator();
            while (i.hasNext()) {
                Integer cid = i.next();
                mExpandArchives.put(cid, true);
            }
        }
        refreshTask = new RefreshTask();
        refreshTask.doInBackground((Void) null);
        refreshTask.onPostExecute(null);
        if (savedInstanceState != null && savedInstanceState.containsKey("scrollPosition"))
            listView.setSelection(savedInstanceState.getInt("scrollPosition"));
    }
    return view;
}

From source file:com.tweetlanes.android.core.view.TweetFeedFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    super.onCreateView(inflater, container, savedInstanceState);

    mProfileImageLoader = getApp().getProfileImageLoader();
    mPreviewImageLoader = getApp().getPreviewImageLoader();

    mContentHandle = TwitterManager.get().getContentHandle(getContentHandleBase(), getScreenName(),
            getLaneIdentifier(), getApp().getCurrentAccountKey());

    View resultView = inflater.inflate(R.layout.lane, null);
    configureLaneWidth(resultView);/*from   w  w w .  j a  v  a  2  s. co m*/

    mViewSwitcher = (ViewSwitcher) resultView.findViewById(R.id.profileSwitcher);
    mListHeadingTextView = (TextView) resultView.findViewById(R.id.list_heading);
    mListHeadingHideImage = (ImageView) resultView.findViewById(R.id.list_hide);
    mListHeadingHideImage.setOnClickListener(mListHeadingHideImageOnClickListener);
    mMultipleTweetSelectionCallback = new MultipleTweetSelectionCallback();
    mTweetFeedListAdapter = new TweetFeedListAdapter(inflater);

    mTweetFeedListView = (PullToRefreshListView) resultView.findViewById(R.id.pull_to_refresh_listview);
    mTweetFeedListView.getRefreshableView().setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);
    mTweetFeedListView.getRefreshableView().setMultiChoiceModeListener(mMultipleTweetSelectionCallback);
    mTweetFeedListView.getRefreshableView().setOnScrollListener(mTweetFeedOnScrollListener);
    mTweetFeedListView.getRefreshableView().setAdapter(mTweetFeedListAdapter);
    mTweetFeedListView.setOnRefreshListener(mTweetFeedOnRefreshListener);
    mTweetFeedListView.setOnLastItemVisibleListener(mTweetFeedOnLastItemVisibleListener);

    mRefreshTimestampsHandler.removeCallbacks(mRefreshTimestampsTask);
    mRefreshTimestampsHandler.postDelayed(mRefreshTimestampsTask, REFRESH_TIMESTAMPS_INTERVAL);

    LocalBroadcastManager.getInstance(getActivity()).registerReceiver(mVolumeUpKeyDownReceiver,
            new IntentFilter("" + SystemEvent.VOLUME_UP_KEY_DOWN));
    LocalBroadcastManager.getInstance(getActivity()).registerReceiver(mVolumeDownKeyDownReceiver,
            new IntentFilter("" + SystemEvent.VOLUME_DOWN_KEY_DOWN));

    if (savedInstanceState != null) {
        mTwitterStatusIdWhenRefreshed = savedInstanceState.containsKey("TwitterStatusIdWhenRefreshed")
                ? savedInstanceState.getLong("TwitterStatusIdWhenRefreshed")
                : 0L;
        mLastTwitterStatusIdSeen = savedInstanceState.containsKey("LastTwitterStatusIdSeen")
                ? savedInstanceState.getLong("LastTwitterStatusIdSeen")
                : 0L;
        mNewStatuses = savedInstanceState.getInt("NewStatuses", 0);
        mHidingListHeading = savedInstanceState.getBoolean("HidingListHeading", false);
    }

    configureInitialStatuses();

    return resultView;
}

From source file:net.exclaimindustries.geohashdroid.wiki.WikiPictureEditor.java

@Override
protected void onCreate(Bundle icicle) {
    super.onCreate(icicle);

    // Get some display metrics.  We need to scale the gallery thumbnails
    // accordingly, else they look too small on big screens and too big on
    // small screens.  We do this here to save calculations later, else
    // we'd be doing floating-point multiplication on EVERY SINGLE
    // THUMBNAIL, and we can't guarantee that won't be painful on every
    // Android phone.
    DisplayMetrics metrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(metrics);
    THUMB_DIMEN = (int) (getResources().getDimensionPixelSize(R.dimen.nominal_icon_size) * metrics.density);

    Log.d(DEBUG_TAG, "Thumbnail dimensions: " + THUMB_DIMEN);

    mInfo = (Info) getIntent().getParcelableExtra(GeohashDroid.INFO);

    setContentView(R.layout.pictureselect);

    Button submitButton = (Button) findViewById(R.id.wikieditbutton);
    ImageButton galleryButton = (ImageButton) findViewById(R.id.GalleryButton);

    galleryButton.setOnClickListener(new View.OnClickListener() {
        @Override/*from   w w  w.  j av a  2 s . co m*/
        public void onClick(View v) {
            // Fire off the Gallery!
            startActivityForResult(new Intent(Intent.ACTION_PICK,
                    android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI), REQUEST_PICTURE);
        }
    });

    submitButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            // We don't want to let the Activity handle the dialog.  That WILL
            // cause it to show up properly and all, but after a configuration
            // change (i.e. orientation shift), it won't show or update any text
            // (as far as I know), as we can't reassign the handler properly.
            // So, we'll handle it ourselves.
            mProgress = ProgressDialog.show(WikiPictureEditor.this, "", "", true, true, WikiPictureEditor.this);
            mConnectionHandler = new PictureConnectionRunner(mProgressHandler, WikiPictureEditor.this);
            mWikiConnectionThread = new Thread(mConnectionHandler, "WikiConnectionThread");
            mWikiConnectionThread.start();
        }
    });

    // We can set the background on the thumbnail view right away, even if
    // it's not actually visible.
    ImageView thumbView = (ImageView) findViewById(R.id.ThumbnailImage);
    thumbView.setBackgroundResource(R.drawable.gallery_selected_default);
    thumbView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);

    // Now, let's see if we have anything retained...
    try {
        RetainedThings retain = (RetainedThings) getLastNonConfigurationInstance();
        if (retain != null) {
            // We have something retained!  Thus, we need to construct the
            // popup and update it with the right status, assuming the
            // thread's still going.
            if (retain.thread != null && retain.thread.isAlive()) {
                mProgress = ProgressDialog.show(WikiPictureEditor.this, "", "", true, true,
                        WikiPictureEditor.this);
                mConnectionHandler = retain.handler;
                mConnectionHandler.resetHandler(mProgressHandler);
                mWikiConnectionThread = retain.thread;
            }

            // And in any event, put the image info back up.
            mCurrentFile = retain.currentFile;
            mCurrentThumbnail = retain.thumbnail;
            mPictureLocation = retain.picLocation;

            setThumbnail();
        } else {
            // If there was nothing to retain, maybe we've got a bundle.
            if (icicle != null) {
                if (icicle.containsKey(STORED_FILE))
                    mCurrentFile = icicle.getString(STORED_FILE);
                if (icicle.containsKey(STORED_LOCATION))
                    mPictureLocation = icicle.getParcelable(STORED_LOCATION);
            }

            // Rebuild it all in any event.
            buildThumbnail();
            setThumbnail();
        }
    } catch (Exception ex) {
        // If we got an exception, reset the thumbnail info with whatever
        // we have handy.
        buildThumbnail();
        setThumbnail();
    }

    // Rebuild the thumbnail and display it as need be.

}