Example usage for android.content Context getClassLoader

List of usage examples for android.content Context getClassLoader

Introduction

In this page you can find the example usage for android.content Context getClassLoader.

Prototype

public abstract ClassLoader getClassLoader();

Source Link

Document

Return a class loader you can use to retrieve classes in this package.

Usage

From source file:android.support.design.widget.CoordinatorLayout.java

static Behavior parseBehavior(Context context, AttributeSet attrs, String name) {
    if (TextUtils.isEmpty(name)) {
        return null;
    }// ww w  .ja v a 2 s  .  c o  m

    final String fullName;
    if (name.startsWith(".")) {
        // Relative to the app package. Prepend the app package name.
        fullName = context.getPackageName() + name;
    } else if (name.indexOf('.') >= 0) {
        // Fully qualified package name.
        fullName = name;
    } else {
        // Assume stock behavior in this package (if we have one)
        fullName = !TextUtils.isEmpty(WIDGET_PACKAGE_NAME) ? (WIDGET_PACKAGE_NAME + '.' + name) : name;
    }

    try {
        Map<String, Constructor<Behavior>> constructors = sConstructors.get();
        if (constructors == null) {
            constructors = new HashMap<>();
            sConstructors.set(constructors);
        }
        Constructor<Behavior> c = constructors.get(fullName);
        if (c == null) {
            final Class<Behavior> clazz = (Class<Behavior>) Class.forName(fullName, true,
                    context.getClassLoader());
            c = clazz.getConstructor(CONSTRUCTOR_PARAMS);
            c.setAccessible(true);
            constructors.put(fullName, c);
        }
        return c.newInstance(context, attrs);
    } catch (Exception e) {
        throw new RuntimeException("Could not inflate Behavior subclass " + fullName, e);
    }
}

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 ava 2 s  .c om
    }
    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);// ww  w. j av  a2  s  . c o m
    }
    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:org.getlantern.firetweet.util.Utils.java

public static void addIntentToMenuForExtension(final Context context, final Menu menu, final int groupId,
        final String action, final String parelableKey, final String parelableJSONKey,
        final FiretweetParcelable parcelable) {
    if (context == null || menu == null || action == null || parelableKey == null || parcelable == null)
        return;//from   w w w .j  ava  2 s.c  o m
    final PackageManager pm = context.getPackageManager();
    final Resources res = context.getResources();
    final float density = res.getDisplayMetrics().density;
    final int padding = Math.round(density * 4);
    final Intent queryIntent = new Intent(action);
    queryIntent.setExtrasClassLoader(context.getClassLoader());
    final List<ResolveInfo> activities = pm.queryIntentActivities(queryIntent, PackageManager.GET_META_DATA);
    for (final ResolveInfo info : activities) {
        final Intent intent = new Intent(queryIntent);
        if (isExtensionUseJSON(info)) {
            intent.putExtra(parelableJSONKey, JSONSerializer.toJSONObjectString(parcelable));
        } else {
            intent.putExtra(parelableKey, parcelable);
        }
        intent.setClassName(info.activityInfo.packageName, info.activityInfo.name);
        final MenuItem item = menu.add(groupId, Menu.NONE, Menu.NONE, info.loadLabel(pm));
        item.setIntent(intent);
        final Drawable metaDataDrawable = getMetadataDrawable(pm, info.activityInfo,
                METADATA_KEY_EXTENSION_ICON);
        final int actionIconColor = ThemeUtils.getThemeForegroundColor(context);
        if (metaDataDrawable != null) {
            metaDataDrawable.mutate();
            metaDataDrawable.setColorFilter(actionIconColor, Mode.SRC_ATOP);
            item.setIcon(metaDataDrawable);
        } else {
            final Drawable icon = info.loadIcon(pm);
            final int iw = icon.getIntrinsicWidth(), ih = icon.getIntrinsicHeight();
            if (iw > 0 && ih > 0) {
                final Drawable iconWithPadding = new PaddingDrawable(icon, padding);
                iconWithPadding.setBounds(0, 0, iw, ih);
                item.setIcon(iconWithPadding);
            } else {
                item.setIcon(icon);
            }
        }

    }
}

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

public static void openStatus(final Context context, final ParcelableStatus status, Bundle activityOptions) {
    if (context == null || status == null)
        return;/*  ww w . ja  va  2s .c o m*/
    final long account_id = status.account_id, status_id = status.id;
    final Bundle extras = new Bundle();
    extras.putParcelable(EXTRA_STATUS, status);
    final Uri.Builder builder = new Uri.Builder();
    builder.scheme(SCHEME_FIRETWEET);
    builder.authority(AUTHORITY_STATUS);
    builder.appendQueryParameter(QUERY_PARAM_ACCOUNT_ID, String.valueOf(account_id));
    builder.appendQueryParameter(QUERY_PARAM_STATUS_ID, String.valueOf(status_id));
    final Intent intent = new Intent(Intent.ACTION_VIEW, builder.build());
    intent.setExtrasClassLoader(context.getClassLoader());
    intent.putExtras(extras);
    if (context instanceof Activity) {
        ActivityCompat.startActivity((Activity) context, intent, activityOptions);
    } else {
        context.startActivity(intent);
    }
}

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

public static void openUserProfile(final Context context, final ParcelableUser user,
        final Bundle activityOptions) {
    if (context == null || user == null)
        return;//w  w w. j  av  a 2s  .co  m
    final Bundle extras = new Bundle();
    extras.putParcelable(EXTRA_USER, user);
    final Uri.Builder builder = new Uri.Builder();
    builder.scheme(SCHEME_FIRETWEET);
    builder.authority(AUTHORITY_USER);
    builder.appendQueryParameter(QUERY_PARAM_ACCOUNT_ID, String.valueOf(user.account_id));
    if (user.id > 0) {
        builder.appendQueryParameter(QUERY_PARAM_USER_ID, String.valueOf(user.id));
    }
    if (user.screen_name != null) {
        builder.appendQueryParameter(QUERY_PARAM_SCREEN_NAME, user.screen_name);
    }
    final Intent intent = new Intent(Intent.ACTION_VIEW, builder.build());
    intent.setExtrasClassLoader(context.getClassLoader());
    intent.putExtras(extras);
    if (context instanceof Activity) {
        ActivityCompat.startActivity((Activity) context, intent, activityOptions);
    } else {
        context.startActivity(intent);
    }
}

From source file:android.support.v71.widget.RecyclerView.java

/**
 * Instantiate and set a LayoutManager, if specified in the attributes.
 *  LayotManager//from   w ww.j av  a 2  s .  com
 */
private void createLayoutManager(Context context, String className, AttributeSet attrs, int defStyleAttr,
        int defStyleRes) {
    if (className != null) {
        className = className.trim();
        if (className.length() != 0) { // Can't use isEmpty since it was added in API 9.
            className = getFullClassName(context, className);
            try {
                ClassLoader classLoader;
                if (isInEditMode()) {
                    // Stupid layoutlib cannot handle simple class loaders.
                    classLoader = this.getClass().getClassLoader();
                } else {
                    classLoader = context.getClassLoader();
                }
                Class<? extends LayoutManager> layoutManagerClass = classLoader.loadClass(className)
                        .asSubclass(LayoutManager.class);
                Constructor<? extends LayoutManager> constructor;
                Object[] constructorArgs = null;
                try {
                    constructor = layoutManagerClass.getConstructor(LAYOUT_MANAGER_CONSTRUCTOR_SIGNATURE);
                    constructorArgs = new Object[] { context, attrs, defStyleAttr, defStyleRes };
                } catch (NoSuchMethodException e) {
                    try {
                        constructor = layoutManagerClass.getConstructor();
                    } catch (NoSuchMethodException e1) {
                        e1.initCause(e);
                        throw new IllegalStateException(
                                attrs.getPositionDescription() + ": Error creating LayoutManager " + className,
                                e1);
                    }
                }
                constructor.setAccessible(true);
                setLayoutManager(constructor.newInstance(constructorArgs));
            } catch (ClassNotFoundException e) {
                throw new IllegalStateException(
                        attrs.getPositionDescription() + ": Unable to find LayoutManager " + className, e);
            } catch (InvocationTargetException e) {
                throw new IllegalStateException(attrs.getPositionDescription()
                        + ": Could not instantiate the LayoutManager: " + className, e);
            } catch (InstantiationException e) {
                throw new IllegalStateException(attrs.getPositionDescription()
                        + ": Could not instantiate the LayoutManager: " + className, e);
            } catch (IllegalAccessException e) {
                throw new IllegalStateException(
                        attrs.getPositionDescription() + ": Cannot access non-public constructor " + className,
                        e);
            } catch (ClassCastException e) {
                throw new IllegalStateException(
                        attrs.getPositionDescription() + ": Class is not a LayoutManager " + className, e);
            }
        }
    }
}