Example #1
0
  private void setShareIntent(int position) {

    if (mShareActionProvider != null) {
      // Get the currently selected item, and retrieve it's share intent
      ContentItem item = mItems.get(position);
      Intent shareIntent = item.getShareIntent(MainActivity.this);

      // Now update the ShareActionProvider with the new share intent
      mShareActionProvider.setShareIntent(shareIntent);
    }
  }
Example #2
0
        @Override
        public Object instantiateItem(ViewGroup container, int position) {
          // Ensure that the LayoutInflater is instantiated
          if (mInflater == null) {
            mInflater = LayoutInflater.from(MainActivity.this);
          }

          // Get the item for the requested position
          final ContentItem item = mItems.get(position);

          // The view we need to inflate changes based on the type of content
          switch (item.contentType) {
            case ContentItem.CONTENT_TYPE_TEXT:
              {
                // Inflate item layout for text
                TextView tv = (TextView) mInflater.inflate(R.layout.item_text, container, false);

                // Set text content using it's resource id
                tv.setText(item.contentResourceId);

                // Add the view to the ViewPager
                container.addView(tv);
                return tv;
              }
            case ContentItem.CONTENT_TYPE_IMAGE:
              {
                // Inflate item layout for images
                ImageView iv = (ImageView) mInflater.inflate(R.layout.item_image, container, false);

                // Load the image from it's content URI
                iv.setImageURI(item.getContentUri());

                // Add the view to the ViewPager
                container.addView(iv);
                return iv;
              }
          }

          return null;
        }