Search in sources :

Example 1 with MediaWikiImageView

use of fr.free.nrw.commons.MediaWikiImageView in project apps-android-commons by commons-app.

the class MediaDetailFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    detailProvider = (MediaDetailPagerFragment.MediaDetailProvider) getActivity();
    if (savedInstanceState != null) {
        editable = savedInstanceState.getBoolean("editable");
        index = savedInstanceState.getInt("index");
        initialListTop = savedInstanceState.getInt("listTop");
    } else {
        editable = getArguments().getBoolean("editable");
        index = getArguments().getInt("index");
        initialListTop = 0;
    }
    categoryNames = new ArrayList<>();
    categoryNames.add(getString(R.string.detail_panel_cats_loading));
    final View view = inflater.inflate(R.layout.fragment_media_detail, container, false);
    image = (MediaWikiImageView) view.findViewById(R.id.mediaDetailImage);
    scrollView = (ScrollView) view.findViewById(R.id.mediaDetailScrollView);
    // Detail consists of a list view with main pane in header view, plus category list.
    spacer = (MediaDetailSpacer) view.findViewById(R.id.mediaDetailSpacer);
    title = (TextView) view.findViewById(R.id.mediaDetailTitle);
    desc = (TextView) view.findViewById(R.id.mediaDetailDesc);
    license = (TextView) view.findViewById(R.id.mediaDetailLicense);
    coordinates = (TextView) view.findViewById(R.id.mediaDetailCoordinates);
    uploadedDate = (TextView) view.findViewById(R.id.mediaDetailuploadeddate);
    categoryContainer = (LinearLayout) view.findViewById(R.id.mediaDetailCategoryContainer);
    licenseList = new LicenseList(getActivity());
    // Progressively darken the image in the background when we scroll detail pane up
    scrollListener = new ViewTreeObserver.OnScrollChangedListener() {

        @Override
        public void onScrollChanged() {
            updateTheDarkness();
        }
    };
    view.getViewTreeObserver().addOnScrollChangedListener(scrollListener);
    // Layout layoutListener to size the spacer item relative to the available space.
    // There may be a .... better way to do this.
    layoutListener = new ViewTreeObserver.OnGlobalLayoutListener() {

        private int currentHeight = -1;

        @Override
        public void onGlobalLayout() {
            int viewHeight = view.getHeight();
            //int textHeight = title.getLineHeight();
            int paddingDp = 112;
            float paddingPx = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, paddingDp, getResources().getDisplayMetrics());
            int newHeight = viewHeight - Math.round(paddingPx);
            if (newHeight != currentHeight) {
                currentHeight = newHeight;
                ViewGroup.LayoutParams params = spacer.getLayoutParams();
                params.height = newHeight;
                spacer.setLayoutParams(params);
                scrollView.scrollTo(0, initialListTop);
            }
        }
    };
    view.getViewTreeObserver().addOnGlobalLayoutListener(layoutListener);
    return view;
}
Also used : MediaWikiImageView(fr.free.nrw.commons.MediaWikiImageView) View(android.view.View) TextView(android.widget.TextView) ScrollView(android.widget.ScrollView) ViewTreeObserver(android.view.ViewTreeObserver) LicenseList(fr.free.nrw.commons.LicenseList)

Aggregations

View (android.view.View)1 ViewTreeObserver (android.view.ViewTreeObserver)1 ScrollView (android.widget.ScrollView)1 TextView (android.widget.TextView)1 LicenseList (fr.free.nrw.commons.LicenseList)1 MediaWikiImageView (fr.free.nrw.commons.MediaWikiImageView)1