Example usage for android.view ViewGroup getContext

List of usage examples for android.view ViewGroup getContext

Introduction

In this page you can find the example usage for android.view ViewGroup getContext.

Prototype

@ViewDebug.CapturedViewProperty
public final Context getContext() 

Source Link

Document

Returns the context the view is running in, through which it can access the current theme, resources, etc.

Usage

From source file:com.keylesspalace.tusky.adapter.NotificationsAdapter.java

@NonNull
@Override/*ww  w. ja  v a 2 s  .  c o m*/
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
    switch (viewType) {
    default:
    case VIEW_TYPE_MENTION: {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_status, parent, false);
        return new StatusViewHolder(view);
    }
    case VIEW_TYPE_FOOTER: {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_footer, parent, false);
        return new FooterViewHolder(view);
    }
    case VIEW_TYPE_STATUS_NOTIFICATION: {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_status_notification, parent,
                false);
        return new StatusNotificationViewHolder(view);
    }
    case VIEW_TYPE_FOLLOW: {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_follow, parent, false);
        return new FollowViewHolder(view);
    }
    case VIEW_TYPE_PLACEHOLDER: {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_status_placeholder, parent,
                false);
        return new PlaceholderViewHolder(view);
    }
    }
}

From source file:com.frostwire.android.gui.adapters.TransferListAdapter.java

@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int i) {
    LinearLayout convertView = (LinearLayout) LayoutInflater.from(parent.getContext())
            .inflate(R.layout.view_transfer_list_item, parent, false);
    return new ViewHolder(this, contextRef.get(), convertView, viewOnClickListener, viewOnLongClickListener,
            openOnClickListener, transferDetailsClickListener);
}

From source file:com.marlonjones.voidlauncher.allapps.AllAppsGridAdapter.java

@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    switch (viewType) {
    case VIEW_TYPE_SECTION_BREAK:
        return new ViewHolder(new View(parent.getContext()));
    case VIEW_TYPE_ICON:
        /* falls through */
    case VIEW_TYPE_PREDICTION_ICON: {
        BubbleTextView icon = (BubbleTextView) mLayoutInflater.inflate(R.layout.all_apps_icon, parent, false);
        icon.setOnClickListener(mIconClickListener);
        icon.setOnLongClickListener(mIconLongClickListener);
        icon.setLongPressTimeout(ViewConfiguration.get(parent.getContext()).getLongPressTimeout());
        icon.setOnFocusChangeListener(mIconFocusListener);

        // Ensure the all apps icon height matches the workspace icons
        DeviceProfile profile = mLauncher.getDeviceProfile();
        Point cellSize = profile.getCellSize();
        GridLayoutManager.LayoutParams lp = (GridLayoutManager.LayoutParams) icon.getLayoutParams();
        lp.height = cellSize.y;/*  w  w  w.  j  a v a 2  s  .  co  m*/
        icon.setLayoutParams(lp);
        return new ViewHolder(icon);
    }
    case VIEW_TYPE_EMPTY_SEARCH:
        return new ViewHolder(mLayoutInflater.inflate(R.layout.all_apps_empty_search, parent, false));
    case VIEW_TYPE_SEARCH_MARKET:
        View searchMarketView = mLayoutInflater.inflate(R.layout.all_apps_search_market, parent, false);
        searchMarketView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mLauncher.startActivitySafely(v, mMarketSearchIntent, null);
            }
        });
        return new ViewHolder(searchMarketView);
    case VIEW_TYPE_SEARCH_DIVIDER:
        return new ViewHolder(mLayoutInflater.inflate(R.layout.all_apps_search_divider, parent, false));
    case VIEW_TYPE_PREDICTION_DIVIDER:
        /* falls through */
    case VIEW_TYPE_SEARCH_MARKET_DIVIDER:
        return new ViewHolder(mLayoutInflater.inflate(R.layout.all_apps_divider, parent, false));
    default:
        throw new RuntimeException("Unexpected view type");
    }
}

From source file:com.android.mylauncher3.allapps.AllAppsGridAdapter.java

@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    switch (viewType) {
    case SECTION_BREAK_VIEW_TYPE:
        return new ViewHolder(new View(parent.getContext()));
    case ICON_VIEW_TYPE: {
        BubbleTextView icon = (BubbleTextView) mLayoutInflater.inflate(R.layout.all_apps_icon, parent, false);
        icon.setOnTouchListener(mTouchListener);
        icon.setOnClickListener(mIconClickListener);
        icon.setOnLongClickListener(mIconLongClickListener);
        icon.setLongPressTimeout(ViewConfiguration.get(parent.getContext()).getLongPressTimeout());
        icon.setFocusable(true);/*from w  w w  .ja  va  2  s .c o m*/
        return new ViewHolder(icon);
    }
    case PREDICTION_ICON_VIEW_TYPE: {
        BubbleTextView icon = (BubbleTextView) mLayoutInflater.inflate(R.layout.all_apps_prediction_bar_icon,
                parent, false);
        icon.setOnTouchListener(mTouchListener);
        icon.setOnClickListener(mIconClickListener);
        icon.setOnLongClickListener(mIconLongClickListener);
        icon.setLongPressTimeout(ViewConfiguration.get(parent.getContext()).getLongPressTimeout());
        icon.setFocusable(true);
        return new ViewHolder(icon);
    }
    case EMPTY_SEARCH_VIEW_TYPE:
        return new ViewHolder(mLayoutInflater.inflate(R.layout.all_apps_empty_search, parent, false));
    case SEARCH_MARKET_DIVIDER_VIEW_TYPE:
        return new ViewHolder(mLayoutInflater.inflate(R.layout.all_apps_search_market_divider, parent, false));
    case SEARCH_MARKET_VIEW_TYPE:
        View searchMarketView = mLayoutInflater.inflate(R.layout.all_apps_search_market, parent, false);
        searchMarketView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mLauncher.startSearchFromAllApps(v, mMarketSearchIntent, mLastSearchQuery);
            }
        });
        return new ViewHolder(searchMarketView);
    default:
        throw new RuntimeException("Unexpected view type");
    }
}

From source file:de.k3b.android.androFotoFinder.imagedetail.ImagePagerAdapterFromCursor.java

/**
 * Implementation for PagerAdapter://from   w  w w  . j ava 2s  . c  om
 * Create the page for the given position.  The adapter is responsible
 * for adding the view to the container given here, although it only
 * must ensure this is done by the time it returns from
 * {@link #finishUpdate(ViewGroup)}.
 *
 * @param container The containing View in which the page will be shown.
 * @param position The page position to be instantiated.
 * @return Returns an Object representing the new page.  This does not
 * need to be a View, but can be some other container of the page.
 */
@Override
public View instantiateItem(ViewGroup container, int position) {
    Cursor cursor = getCursorAt(position);
    if (cursor != null) {
        long imageID = cursor.getLong(cursor.getColumnIndex(FotoSql.SQL_COL_PK));

        Uri uri = getUri(imageID);

        PhotoView photoView = new PhotoView(container.getContext());

        if (Global.debugEnabledViewItem)
            Log.i(Global.LOG_CONTEXT,
                    debugPrefix + "instantiateItem(#" + position + ") => " + uri + " => " + photoView);

        setImage(position, imageID, uri, photoView);

        // Now just add PhotoView to ViewPager and return it
        container.addView(photoView, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);

        return photoView;

        /*
        LinearLayout llImage = (LinearLayout) getLayoutInflater().inflate(R.layout.view_pager_item, null);
                
        SubsamplingScaleImageView draweeView = (SubsamplingScaleImageView) llImage.getChildAt(0);
        draweeView.setImage(ImageSource.uri(images.get(position)));
                
        container.addView(llImage, 0);
                
        return llImage;
        */
    }
    return null;
}

From source file:app.cloud9.com.cloud9.NoticeBoard.java

private void initRecyclerView() {
    mRecentRecyclerView = (RecyclerView) findViewById(R.id.recentrecyclerView);
    mRecentRecyclerView.setVisibility(View.GONE);
    mRecentRecyclerView.setHasFixedSize(true);

    mRecentLayoutManager = new LinearLayoutManager(this);

    mRecentRecyclerView.setLayoutManager(mRecentLayoutManager);

    mAdapter = new RecyclerView.Adapter<CustomViewHolder>() {
        @Override//from  ww w.  j av a 2 s . c  om
        public CustomViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
            View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.notice_snippet, viewGroup,
                    false);
            return new CustomViewHolder(view);
        }

        @Override
        public void onBindViewHolder(CustomViewHolder viewHolder, int i) {
            viewHolder.noticeSubject.setText(mItems.get(i).getSubject());
            viewHolder.noticeBody.setText(mItems.get(i).getText());
            viewHolder.noticeTime.setText(mItems.get(i).getPosted_at());
            viewHolder.noticePoster.setText(mItems.get(i).getPosted_by());

            // viewHolder.noticeBody.setText(arraylist.get(i).text);
        }

        @Override
        public int getItemCount() {
            return mItems.size();
        }

    };
    mRecentRecyclerView.setAdapter(mAdapter);

    if (mAdapter.getItemCount() == 0) {
        emptyNotice.setVisibility(View.VISIBLE);
        mRecentRecyclerView.setVisibility(View.GONE);

    } else {
        emptyNotice.setVisibility(View.GONE);
        mRecentRecyclerView.setVisibility(View.VISIBLE);

    }

    SwipeDismissRecyclerViewTouchListener touchListener = new SwipeDismissRecyclerViewTouchListener(
            mRecentRecyclerView, new SwipeDismissRecyclerViewTouchListener.DismissCallbacks() {
                @Override
                public boolean canDismiss(int position) {
                    return true;
                }

                @Override
                public void onDismiss(RecyclerView recyclerView, int[] reverseSortedPositions) {
                    for (int position : reverseSortedPositions) {
                        //                                    mLayoutManager.removeView(mLayoutManager.getChildAt(position));
                        mItems.remove(position);
                        mAdapter.notifyItemRemoved(position);
                    }
                    mAdapter.notifyDataSetChanged();
                    Toast.makeText(NoticeBoard.this, "Notice Removed", Toast.LENGTH_SHORT).show();

                    //If no notice available,

                    if (mItems.size() == 0) {
                        //mRecentRecyclerView.setVisibility(View.GONE);
                        emptyNotice.setVisibility(View.VISIBLE);
                    }

                }
            });
    mRecentRecyclerView.setOnTouchListener(touchListener);
    // Setting this scroll listener is required to ensure that during ListView scrolling,
    // we don't look for swipes.
    mRecentRecyclerView.setOnScrollListener(touchListener.makeScrollListener());
    mRecentRecyclerView.addOnItemTouchListener(new RecyclerItemClickListener(this, new OnItemClickListener() {
        @Override
        public void onItemClick(View view, int position) {
            //Toast.makeText(NoticeBoard.this, "Clicked " + mItems.get(position), Toast.LENGTH_SHORT).show();
            Intent i = new Intent(getBaseContext(), NoticeViewer.class);

            View noticeSubj = view.findViewById(R.id.notice_subject);
            View noticeIcon = view.findViewById(R.id.group_icon);

            View noticeBody = view.findViewById(R.id.notice_body);
            View card = view.findViewById(R.id.card_view);

            Bundle b = new Bundle();
            b.putString("Subject", arraylist.get(position).getSubject());
            b.putString("Text", arraylist.get(position).getText());
            b.putString("Path", arraylist.get(position).getPath());
            b.putString("Posted_by", arraylist.get(position).getPosted_by());
            b.putString("Posted_at", arraylist.get(position).getPosted_at());
            i.putExtras(b);

            String subjectTransitionName = getString(R.string.transition_notice);
            String groupIconTransitionName = getString(R.string.transition_group_icon);
            String bodyTransitionName = getString(R.string.transition_notice_body);
            String cardTransitionName = getString(R.string.transition_card);

            ActivityOptionsCompat options = ActivityOptionsCompat.makeSceneTransitionAnimation(NoticeBoard.this,
                    Pair.create(noticeSubj, subjectTransitionName),
                    Pair.create(noticeIcon, groupIconTransitionName),
                    Pair.create(noticeBody, bodyTransitionName), Pair.create(card, cardTransitionName));

            ActivityCompat.startActivity(NoticeBoard.this, i, options.toBundle());
        }
    }));

}

From source file:com.orpheusdroid.screenrecorder.adapter.VideoRecyclerAdapter.java

@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
    View view;/* www  .j  a v  a2s  . c  o m*/
    switch (viewType) {
    case VIEW_SECTION:
        view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.content_video_section, viewGroup,
                false);
        return new SectionViewHolder(view);
    case VIEW_ITEM:
        view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.content_video, viewGroup, false);
        return new ItemViewHolder(view);
    default:
        view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.content_video, viewGroup, false);
        return new ItemViewHolder(view);
    }
}

From source file:com.fjoglar.etsitnoticias.view.adapter.AboutViewPagerAdapter.java

private View getPage(int position, final ViewGroup parent) {
    switch (position) {
    case 0://from   w ww.  j  a  va2  s. c o  m
        if (aboutEtsitNews == null) {
            aboutEtsitNews = layoutInflater.inflate(R.layout.about_etsit_news, parent, false);
            ButterKnife.bind(this, aboutEtsitNews);

            infoVersionName.setText(mContext.getString(R.string.info_version_name, BuildConfig.VERSION_NAME));
            githubLink.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Navigator.getInstance().openUrl(parent.getContext(), GITHUB_LINK);
                }
            });
        }
        return aboutEtsitNews;
    case 1:
        if (aboutImages == null) {
            aboutImages = layoutInflater.inflate(R.layout.about_images, parent, false);
        }
        return aboutImages;
    case 2:
        if (aboutLibs == null) {
            aboutLibs = layoutInflater.inflate(R.layout.about_libs, parent, false);
            ButterKnife.bind(this, aboutLibs);

            recyclerLibs.setAdapter(new LibraryAdapter());
        }
        return aboutLibs;
    }
    throw new InvalidParameterException();
}

From source file:com.ryan.ryanreader.fragments.PostListingFragment.java

@Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container,
        final Bundle savedInstanceState) {

    super.onCreateView(inflater, container, savedInstanceState);
    final Context context = container.getContext();
    sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context);

    final LinearLayout outer = new LinearLayout(context) {
        @Override//from w ww  .  j  a  v  a  2s. co  m
        protected void onAttachedToWindow() {
            super.onAttachedToWindow();
            getLayoutParams().height = ViewGroup.LayoutParams.FILL_PARENT;
        }
    };

    outer.setOrientation(android.widget.LinearLayout.VERTICAL);

    fragmentHeader = createVerticalLinearLayout(context);
    final LinearLayout listHeader = createVerticalLinearLayout(context);
    listHeaderNotifications = createVerticalLinearLayout(context);
    listFooterNotifications = createVerticalLinearLayout(context);

    if (subreddit.isReal()) {
        final SubredditHeader subredditHeader = new SubredditHeader(context, subreddit);
        listHeader.addView(subredditHeader);
    }

    listHeader.addView(listHeaderNotifications);

    lv = (ListView) inflater.inflate(R.layout.reddit_post_list);
    lv.setOnScrollListener(this);
    lv.addHeaderView(listHeader);
    lv.addFooterView(listFooterNotifications, null, false);

    lv.setPersistentDrawingCache(ViewGroup.PERSISTENT_ALL_CACHES);
    lv.setAlwaysDrawnWithCacheEnabled(true);

    adapter = new PostListingAdapter(lv, this);
    lv.setAdapter(adapter);

    final ListOverlayView lov = new ListOverlayView(context, lv);

    outer.addView(fragmentHeader);
    outer.addView(lov);

    lv.getLayoutParams().height = ViewGroup.LayoutParams.FILL_PARENT;

    request = new PostListingRequest(url, RedditAccountManager.getInstance(context).getDefaultAccount(),
            session, downloadType, true);

    CacheManager.getInstance(context).makeRequest(request);

    return outer;
}

From source file:com.alexcoliveira1.lighttalesreader.view.NovelListFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.novellist_fragment, container, false);

    Bundle args = getArguments();//from  w w  w .  ja  v  a 2s .c  om

    if (args != null) {
        Log.d(TAG, "Args found");
        List<Novel> lNovel = args.getParcelableArrayList("novels");
        if (lNovel != null) {
            Log.d(TAG, "List NOT null = " + lNovel.size());
            novels.clear();
            novels.addAll(lNovel);
        }
    }

    mRecyclerView = (RecyclerView) view.findViewById(R.id.recyclerview_novels);
    mAdapter = new NovelListAdapter(container.getContext(), novels);
    mRecyclerView.setAdapter(mAdapter);
    mRecyclerView.setLayoutManager(new LinearLayoutManager(container.getContext()));
    DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(mRecyclerView.getContext(),
            DividerItemDecoration.VERTICAL);
    mRecyclerView.addItemDecoration(dividerItemDecoration);

    return view;
}