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.firma.dev.letschat.MyFavoriteFragment.java

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

    final View listFragmentView = super.onCreateView(inflater, container, savedInstanceState);

    apiManager = new ApiManager();
    ProfileDataSource profileDao = new ProfileDataSource(inflater.getContext());

    try {//  w ww  . j  a v  a  2 s  .c  o  m
        profileDao.open();

        currentProfile = profileDao.getAllProfiles().get(0);
        profileDao.close();
    } catch (SQLException e) {
        e.printStackTrace();
    }

    userContactsTimer = new Timer();
    getUserContactsTask = new GetUserContactsTask();

    userContactsTimer.schedule(getUserContactsTask, 1000, 60000);

    fAdapter = new FavoriteAdapter(inflater.getContext(), getActivity());
    setListAdapter(fAdapter);

    mSwipeRefreshLayout = new ListFragmentSwipeRefreshLayout(container.getContext());

    mSwipeRefreshLayout.addView(listFragmentView, ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT);

    mSwipeRefreshLayout.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    this.setRefreshing(false);

    mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            forceUpdate();
        }
    });
    return mSwipeRefreshLayout;
}

From source file:com.racoon.ampdroid.views.SettingsView.java

@SuppressLint("InflateParams")
@Override/* ww w .  j a va2s  . c o m*/
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    controller = Controller.getInstance();
    ViewGroup root = (ViewGroup) inflater.inflate(R.layout.settings, null);
    final EditText editServer = (EditText) root.findViewById(R.id.settingsServer);
    final EditText editUser = (EditText) root.findViewById(R.id.settingsUser);
    final EditText editPassword = (EditText) root.findViewById(R.id.settingsPassword);
    final TextView connectionInfo = (TextView) root.findViewById(R.id.settingsConnectionInfo);
    final TextView connectionInfoText = (TextView) root.findViewById(R.id.settingsConnectionInfoText);
    if (controller.getServer() != null) {
        if (!controller.getServer().getHost().equals("")) {
            editServer.setText(controller.getServer().getHost());
        }
        if (!controller.getServer().getUser().equals("")) {
            editUser.setText(controller.getServer().getUser());
        }
        if (!controller.getServer().getPassword().equals("")) {
            editPassword.setText(controller.getServer().getPassword());
        }
        if (controller.getServer().isConnected(controller.isOnline(root.getContext()))) {
            connectionInfoText.setText(R.string.settingsExpireText);
            connectionInfo.setText(controller.getServer().getAmpacheConnection().getSessionExpireString());
        }
    }
    setHasOptionsMenu(true);
    return root;
}

From source file:com.box.myview.MyTopSnackBar.TSnackbar.java

private TSnackbar(ViewGroup parent) {
    appearDirection = APPEAR_FROM_TOP_TO_DOWN;

    mParent = parent;//from  ww w .ja  v a 2  s .  c o  m
    mContext = parent.getContext();
    LayoutInflater inflater = LayoutInflater.from(mContext);
    if (appearDirection == APPEAR_FROM_BOTTOM_TO_TOP) {
        mView = (SnackbarLayout) inflater.inflate(R.layout.view_bsnackbar_layout, mParent, false);
    } else {
        mView = (SnackbarLayout) inflater.inflate(R.layout.view_tsnackbar_layout, mParent, false);
    }
    mAccessibilityManager = (AccessibilityManager) mContext.getSystemService(Context.ACCESSIBILITY_SERVICE);

}

From source file:com.google.android.apps.muzei.render.MuzeiRendererFragment.java

@Override
@TargetApi(Build.VERSION_CODES.KITKAT)//  w ww.  jav a2s .  c  o m
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    boolean simpleDemoMode = false;
    if (mDemoMode && Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        ActivityManager activityManager = (ActivityManager) getActivity()
                .getSystemService(Context.ACTIVITY_SERVICE);
        if (activityManager.isLowRamDevice()) {
            simpleDemoMode = true;
        }
    }

    if (simpleDemoMode) {
        DisplayMetrics dm = getResources().getDisplayMetrics();
        int targetWidth = dm.widthPixels;
        int targetHeight = dm.heightPixels;
        if (!mDemoFocus) {
            targetHeight = MathUtil.roundMult4(
                    ImageBlurrer.MAX_SUPPORTED_BLUR_PIXELS * 10000 / MuzeiBlurRenderer.DEFAULT_BLUR);
            targetWidth = MathUtil.roundMult4((int) (dm.widthPixels * 1f / dm.heightPixels * targetHeight));
        }

        mSimpleDemoModeImageView = new ImageView(container.getContext());
        mSimpleDemoModeImageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
        Picasso.with(getActivity()).load("file:///android_asset/starrynight.jpg")
                .resize(targetWidth, targetHeight).centerCrop().into(mSimpleDemoModeLoadedTarget);
        return mSimpleDemoModeImageView;
    } else {
        mView = new MuzeiView(getActivity());
        mView.setPreserveEGLContextOnPause(true);
        return mView;
    }
}

From source file:com.ndn.menurandom.ImageDownloader.java

private void makeFrameLayout(ImageView imageView) {
    boolean isExist = false;
    ViewGroup vg = (ViewGroup) imageView.getParent();
    if (vg instanceof FrameLayout) {
        FrameLayout frameLayout = (FrameLayout) vg;
        String tag = (String) frameLayout.getTag();
        if (tag != null && tag.equals("fl_imagedownloader")) {
            isExist = true;//  w w  w.  j a  va 2 s .com
        }
    }

    if (!isExist) {
        int childCount = vg.getChildCount();
        int index = 0;
        while (index < childCount) {
            if (imageView == vg.getChildAt(index)) {
                break;
            }
            index++;
        }
        vg.removeViewAt(index);

        FrameLayout frameLayout = new FrameLayout(vg.getContext().getApplicationContext());
        frameLayout.setTag("fl_imagedownloader");
        ViewGroup.LayoutParams lpImageView = (ViewGroup.LayoutParams) imageView.getLayoutParams();
        frameLayout.setLayoutParams(lpImageView);
        imageView.setLayoutParams(new LayoutParams(lpImageView.width, lpImageView.height));
        frameLayout.setPadding(imageView.getPaddingLeft(), imageView.getPaddingTop(),
                imageView.getPaddingRight(), imageView.getPaddingBottom());
        imageView.setPadding(0, 0, 0, 0);
        frameLayout.addView(imageView);
        vg.addView(frameLayout, index);

        ProgressBar progressBar = new ProgressBar(frameLayout.getContext());
        progressBar.setTag("pb_imagedownloader");
        int leftRightPadding = (imageView.getLayoutParams().width - 50) / 2;
        int topBottomPadding = (imageView.getLayoutParams().height - 50) / 2;
        progressBar.setPadding(leftRightPadding, topBottomPadding, leftRightPadding, topBottomPadding);
        frameLayout.addView(progressBar);

    }
}

From source file:com.stockita.stockitapointofsales.salespack.pendingpack.SalesPendingListFragmentUI.java

@Nullable
@Override/*w  w w  .jav a 2s .  c o  m*/
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    // Initialize the view
    final View view = inflater.inflate(R.layout.fragment_list_of_pending_sales, container, false);

    // Initialize the ButterKnife
    ButterKnife.bind(this, view);

    /**
     * The code below is for the sales detail recycler view
     */

    // Set more efficient
    mListOfSalesDetail.setHasFixedSize(true);

    // Initialize the cash toolbar
    initCashToolbar();

    // Server reference location sales detail pending ref
    DatabaseReference salesDetailPendingRef = FirebaseDatabase.getInstance().getReference().child(mUserUid)
            .child(Constants.FIREBASE_SALES_DETAIL_PENDING_LOCATION);

    // Initialize the adapter
    mMyAdapter = new MyAdapter(SalesDetailModel.class, R.layout.adapter_each_card_in_sales_detail,
            ViewHolder.class, salesDetailPendingRef, mUserUid) {

        @Override
        protected void populateViewHolder(final ViewHolder viewHolder, final SalesDetailModel model,
                int position) {

            // Get the pushKey()
            DatabaseReference keyRef = getRef(viewHolder.getLayoutPosition());

            // Convert the keyRef to type String, then pass it to the UI
            final String pushKeyDetail = keyRef.getKey();

            // Get the field from the model
            //String itemNumber = model.getItemNumber();
            String itemDesc = model.getItemDesc();
            //String itemUnit = model.getItemUnit();
            String itemPrice = model.getItemPrice();
            String itemQuantity = model.getItemQuantity();
            //String itemDiscount = model.getItemDiscount();
            String itemAmount = model.getItemAmount();

            // update the UI
            viewHolder.mAdapterView.getmItemDesc().setText(itemDesc);
            viewHolder.mAdapterView.getmItemPrice().setText(itemPrice);
            viewHolder.mAdapterView.getmItemQuantity().setText(itemQuantity);
            viewHolder.mAdapterView.getmItemAmount().setText(itemAmount);

            /**
             * The below for the popup menu in each element in the list
             */
            viewHolder.mAdapterView.getmPopupMenu()
                    .setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
                        @Override
                        public boolean onMenuItemClick(MenuItem menuItem) {

                            /**
                             * If action mode then cancel before we can proceed with the click
                             * Here we use {@link com.stockita.stockitapointofsales.itemmaster.ItemMasterListFragmentUI.DeleteMultiItemMaster}
                             * to avoid redundancy.
                             * */
                            if (((ItemMasterListFragmentUI.DeleteMultiItemMaster) getActivity())
                                    .getActionModeItemMaster() != null) {
                                ((ItemMasterListFragmentUI.DeleteMultiItemMaster) getActivity())
                                        .getActionModeItemMaster().finish();
                            }

                            // Get the menu item id
                            int id = menuItem.getItemId();

                            switch (id) {

                            // Delete
                            case R.id.menu_delete:

                                // Alert the user before delete.
                                new AlertDialog.Builder(getActivity()).setTitle("Warning")
                                        .setMessage("You are about to delete this detail item sales?")
                                        .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                                            @Override
                                            public void onClick(DialogInterface dialogInterface, int i) {

                                                /**
                                                 * Do the delete here...
                                                 */

                                                // Get the reference
                                                DatabaseReference itemRef = FirebaseDatabase.getInstance()
                                                        .getReference().child(mAdapterUserUid)
                                                        .child(Constants.FIREBASE_SALES_DETAIL_PENDING_LOCATION)
                                                        .child(pushKeyDetail);

                                                // Pass null to delete
                                                itemRef.setValue(null);

                                            }
                                        }).setNegativeButton("No", new DialogInterface.OnClickListener() {
                                            @Override
                                            public void onClick(DialogInterface dialogInterface, int i) {
                                                // do nothing
                                            }
                                        }).show();
                                return true;

                            // Edit
                            case R.id.menu_edit:

                                // Call the SalesPendingEditFormDialogFragment via MainActivity
                                ((SalesDetailPendingCallbacks) getActivity()).onSalesEditDialogCallbacks(
                                        Constants.REQUEST_CODE_SALES_DIALOG_ONE, mAdapterUserUid, pushKeyDetail,
                                        null, model);

                                return true;
                            }
                            return false;
                        }
                    });

            /**
            * Check if in contextual mode, so the following line of codes is to prevent other view holders
            * from changing colors if they are not the one chosen for multi delete. It is kind of workaround.
            * Because RV will recycle the view holder.
            */
            if (isContextualMode) {
                if (mViewHolderMap.get(pushKeyDetail) == null) {
                    viewHolder.mAdapterView.getmRoot()
                            .setBackgroundColor(getResources().getColor(R.color.white));
                    viewHolder.mAdapterView.getmItemPopupMenu()
                            .setBackgroundColor(getResources().getColor(R.color.white));
                } else {
                    viewHolder.mAdapterView.getmRoot()
                            .setBackgroundColor(getResources().getColor(R.color.purple_100));
                    viewHolder.mAdapterView.getmItemPopupMenu()
                            .setBackgroundColor(getResources().getColor(R.color.purple_100));

                }
            }

            /**
             * when the user long click it will fire the ActionMenu to perform
             * multi item delete.
             */
            viewHolder.mAdapterView.getmRoot().setOnLongClickListener(new View.OnLongClickListener() {
                @Override
                public boolean onLongClick(View view) {

                    // Check if the ActionMode is not yet on.
                    if (!isContextualMode) {

                        // Now set this to true to mark that the ActionMode is on
                        isContextualMode = true;

                        // Initialize the array list as a container for item master push() key
                        mListOfDeletePushKeys = new ArrayList<>();

                        // Initialize the HashMap as a container for view holder objects
                        mViewHolderMap = new HashMap<>();

                        // Pass the pushKey for this current position
                        mListOfDeletePushKeys.add(pushKeyDetail);

                        // Pass the view holder instance as a value, and pass the pushKeyDetail as the key
                        mViewHolderMap.put(pushKeyDetail, viewHolder);

                        // Change the color for the item clicked by the user
                        viewHolder.mAdapterView.getmRoot()
                                .setBackgroundColor(getResources().getColor(R.color.purple_100));
                        viewHolder.mAdapterView.getmItemPopupMenu()
                                .setBackgroundColor(getResources().getColor(R.color.purple_100));

                        // Pass the data to the MainActivity using callbacks
                        ((DeleteMultiSalesPending) getActivity())
                                .sendDeleteMultiSalesPending(mListOfDeletePushKeys, mViewHolderMap);

                        // Now turn the ActionMode on using callbacks
                        ((DeleteMultiSalesPending) getActivity()).onTurnActionModeOnSalesPending();

                        return true;
                    }

                    return false;
                }
            });

            /**
             * When it is already in Action Mode menu the single click will add or remove
             * item from the list to be delete.
             */
            viewHolder.mAdapterView.getmRoot().setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {

                    // Check if the ActionMode is on
                    if (isContextualMode) {

                        // initialize local variables
                        boolean found = false;
                        int record = 0;

                        // check if the pushList is not 0
                        if (mListOfDeletePushKeys.size() > 0) {

                            // Itarate for each element
                            for (int i = 0; i < mListOfDeletePushKeys.size(); i++) {

                                // check if item master push() key is already exist
                                if (pushKeyDetail.equals(mListOfDeletePushKeys.get(i))) {

                                    // flag to true
                                    found = true;

                                    // capture the position in the list
                                    record = i;

                                    // break the iteration
                                    break;
                                } // end if

                                else {

                                    // flag to false of not found
                                    found = false;
                                } // end else

                            } // end for loop

                            // If the item master push key is already exist in the list then
                            if (found) {

                                // Remove the push key and the view holder object
                                String pushKeyTobeRemoved = mListOfDeletePushKeys.get(record);
                                mListOfDeletePushKeys.remove(record);

                                // Change the color back to normal
                                if (mViewHolderMap.get(pushKeyTobeRemoved) != null) {
                                    mViewHolderMap.get(pushKeyTobeRemoved).mAdapterView.getmRoot()
                                            .setBackgroundColor(getResources().getColor(R.color.white));
                                    mViewHolderMap.get(pushKeyTobeRemoved).mAdapterView.getmItemPopupMenu()
                                            .setBackgroundColor(getResources().getColor(R.color.white));
                                    // Remove the push key and the view holder object from the HashMap
                                    mViewHolderMap.remove(pushKeyTobeRemoved);

                                }

                                // Pass the data to MainActivity
                                ((DeleteMultiSalesPending) getActivity())
                                        .sendDeleteMultiSalesPending(mListOfDeletePushKeys, mViewHolderMap);

                                /**
                                 * If the list is empty then invoke finish()
                                 * reuse {@link com.stockita.stockitapointofsales.itemmaster.ItemMasterListFragmentUI.DeleteMultiItemMaster}
                                 * to avoid redundancy.
                                 * */
                                if (mListOfDeletePushKeys.size() == 0
                                        && ((ItemMasterListFragmentUI.DeleteMultiItemMaster) getActivity())
                                                .getActionModeItemMaster() != null) {
                                    ((ItemMasterListFragmentUI.DeleteMultiItemMaster) getActivity())
                                            .getActionModeItemMaster().finish();
                                }

                            } else {

                                // If not found then add what the user just clicked into the list
                                mListOfDeletePushKeys.add(pushKeyDetail);

                                // If not found then add what the user just clicked into the hashMap
                                mViewHolderMap.put(pushKeyDetail, viewHolder);

                                // Change the color to
                                if (mViewHolderMap.get(pushKeyDetail) != null) {
                                    mViewHolderMap.get(pushKeyDetail).mAdapterView.getmRoot()
                                            .setBackgroundColor(getResources().getColor(R.color.purple_100));
                                    mViewHolderMap.get(pushKeyDetail).mAdapterView.getmItemPopupMenu()
                                            .setBackgroundColor(getResources().getColor(R.color.purple_100));
                                }

                                // Pass the data to MainActivity
                                ((DeleteMultiSalesPending) getActivity())
                                        .sendDeleteMultiSalesPending(mListOfDeletePushKeys, mViewHolderMap);

                            }

                        }

                        /**
                         * Display the number of item selected on the toolbar
                         * reuse {@link com.stockita.stockitapointofsales.itemmaster.ItemMasterListFragmentUI.DeleteMultiItemMaster
                         * to avoid redundency.
                         */
                        if (((ItemMasterListFragmentUI.DeleteMultiItemMaster) getActivity())
                                .getActionModeItemMaster() != null) {
                            int size = mListOfDeletePushKeys.size();
                            ((ItemMasterListFragmentUI.DeleteMultiItemMaster) getActivity())
                                    .getActionModeItemMaster().setTitle(size + " Item(s) will be deleted");

                        }

                    }
                }
            });

        }

        @Override
        public void onBindViewHolder(ViewHolder holder, int position, List<Object> payloads) {
            super.onBindViewHolder(holder, position, payloads);
            // For animation
        }

        @Override
        public int getItemViewType(int position) {
            return R.layout.adapter_each_card_in_sales_detail;
        }

        @Override
        public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

            // Initialize the view object
            View view = LayoutInflater.from(parent.getContext()).inflate(viewType, parent, false);

            // Return the view holder and pass the view object as argument
            return new ViewHolder(view);

        }
    };

    /**
     * Code below is for the number of span depend device (Phone / tablet)
     * and orientation (portrait / landscape)
     */
    int columnCount;
    boolean isTablet = getResources().getBoolean(R.bool.isTablet);
    boolean isLandscape = getResources().getBoolean(R.bool.isLandscape);

    if (isTablet && isLandscape) {
        columnCount = 3;
    } else if (!isTablet && isLandscape) {
        columnCount = 2;
    } else if (isTablet && !isLandscape) {
        columnCount = 2;
    } else {
        columnCount = 1;
    }

    // Initialize the LayoutManager for item master
    GridLayoutManager gridLayoutManager = new GridLayoutManager(getActivity(), columnCount,
            GridLayoutManager.VERTICAL, false);

    // Set the layout manager for the item master
    mListOfSalesDetail.setLayoutManager(gridLayoutManager);

    // Set the adapter for the item master
    mListOfSalesDetail.setAdapter(mMyAdapter);

    // Return view object
    return view;
}

From source file:com.box.myview.MyTopSnackBar.TSnackbar.java

private TSnackbar(ViewGroup parent, @OverSnackAppearDirection int appearDirection) {
    this.appearDirection = appearDirection;
    mParent = parent;/*from   w  w w  .  j  a  v a  2  s . c  o  m*/
    mContext = parent.getContext();
    LayoutInflater inflater = LayoutInflater.from(mContext);
    if (appearDirection == APPEAR_FROM_BOTTOM_TO_TOP) {
        mView = (SnackbarLayout) inflater.inflate(R.layout.view_bsnackbar_layout, mParent, false);
    } else {
        mView = (SnackbarLayout) inflater.inflate(R.layout.view_tsnackbar_layout, mParent, false);
    }
    mAccessibilityManager = (AccessibilityManager) mContext.getSystemService(Context.ACCESSIBILITY_SERVICE);
    if (appearDirection == APPEAR_FROM_TOP_TO_DOWN) {
        setMinHeight(0, 0);
    }
}

From source file:android.support.v17.leanback.widget.GuidedActionsStylist.java

/**
 * Constructs a {@link ViewHolder} capable of representing {@link GuidedAction}s. Subclasses
 * may choose to return a subclass of ViewHolder.  To support different view types, override
 * {@link #onCreateViewHolder(ViewGroup, int)}
 * <p>/*w ww.j  a  v a 2  s . co  m*/
 * <i>Note: Should not actually add the created view to the parent; the caller will do
 * this.</i>
 * @param parent The view group to be used as the parent of the new view.
 * @return The view to be added to the caller's view hierarchy.
 */
public ViewHolder onCreateViewHolder(ViewGroup parent) {
    LayoutInflater inflater = LayoutInflater.from(parent.getContext());
    View v = inflater.inflate(onProvideItemLayoutId(), parent, false);
    return new ViewHolder(v, parent == mSubActionsGridView);
}

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

/**
 * Constructor for the transient bottom bar.
 *
 * @param parent The parent for this transient bottom bar.
 * @param content The content view for this transient bottom bar.
 * @param contentViewCallback The content view callback for this transient bottom bar.
 *//*from www.j  a  v a  2 s  .  com*/
protected BaseTransientBottomBar(@NonNull ViewGroup parent, @NonNull View content,
        @NonNull ContentViewCallback contentViewCallback) {
    if (parent == null) {
        throw new IllegalArgumentException("Transient bottom bar must have non-null parent");
    }
    if (content == null) {
        throw new IllegalArgumentException("Transient bottom bar must have non-null content");
    }
    if (contentViewCallback == null) {
        throw new IllegalArgumentException("Transient bottom bar must have non-null callback");
    }

    mTargetParent = parent;
    mContentViewCallback = contentViewCallback;
    mContext = parent.getContext();

    ThemeUtils.checkAppCompatTheme(mContext);

    LayoutInflater inflater = LayoutInflater.from(mContext);
    // Note that for backwards compatibility reasons we inflate a layout that is defined
    // in the extending Snackbar class. This is to prevent breakage of apps that have custom
    // coordinator layout behaviors that depend on that layout.
    mView = (SnackbarBaseLayout) inflater.inflate(R.layout.design_layout_snackbar, mTargetParent, false);
    mView.addView(content);

    ViewCompat.setAccessibilityLiveRegion(mView, ViewCompat.ACCESSIBILITY_LIVE_REGION_POLITE);
    ViewCompat.setImportantForAccessibility(mView, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES);

    // Make sure that we fit system windows and have a listener to apply any insets
    ViewCompat.setFitsSystemWindows(mView, true);
    ViewCompat.setOnApplyWindowInsetsListener(mView, new android.support.v4.view.OnApplyWindowInsetsListener() {
        @Override
        public WindowInsetsCompat onApplyWindowInsets(View v, WindowInsetsCompat insets) {
            // Copy over the bottom inset as padding so that we're displayed
            // above the navigation bar
            v.setPadding(v.getPaddingLeft(), v.getPaddingTop(), v.getPaddingRight(),
                    insets.getSystemWindowInsetBottom());
            return insets;
        }
    });

    mAccessibilityManager = (AccessibilityManager) mContext.getSystemService(Context.ACCESSIBILITY_SERVICE);
}

From source file:com.tmall.ultraviewpager.UltraViewPagerAdapter.java

@Override
public Object instantiateItem(ViewGroup container, int position) {
    int realPosition = position;
    //TODO/* w  w  w  . ja  v a  2  s .  com*/
    if (enableLoop && adapter.getCount() != 0) {
        realPosition = position % adapter.getCount();
    }

    Object item = adapter.instantiateItem(container, realPosition);
    //TODO
    View childView = null;
    if (item instanceof View)
        childView = (View) item;
    if (item instanceof RecyclerView.ViewHolder)
        childView = ((RecyclerView.ViewHolder) item).itemView;

    ViewPager viewPager = (ViewPager) container;
    int childCount = viewPager.getChildCount();
    for (int i = 0; i < childCount; i++) {
        View child = viewPager.getChildAt(i);
        if (isViewFromObject(child, item)) {
            viewArray.put(realPosition, child);
            break;
        }
    }

    if (isEnableMultiScr()) {
        if (scrWidth == 0) {
            scrWidth = container.getResources().getDisplayMetrics().widthPixels;
        }
        RelativeLayout relativeLayout = new RelativeLayout(container.getContext());

        if (childView.getLayoutParams() != null) {
            RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(
                    (int) (scrWidth * multiScrRatio), ViewGroup.LayoutParams.MATCH_PARENT);

            layoutParams.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);
            childView.setLayoutParams(layoutParams);
        }

        container.removeView(childView);
        relativeLayout.addView(childView);

        container.addView(relativeLayout);
        return relativeLayout;
    }

    return item;
}