Skip to content
This repository has been archived by the owner on Nov 2, 2018. It is now read-only.

Vertical Scroll is returning null #39

Closed
tagrudev opened this issue Mar 7, 2014 · 2 comments
Closed

Vertical Scroll is returning null #39

tagrudev opened this issue Mar 7, 2014 · 2 comments
Labels

Comments

@tagrudev
Copy link

tagrudev commented Mar 7, 2014

I am trying to implement the library but I got my head stuck on this issue can you please point me out what I am doing wrong ?

That's the debug info

03-07 11:29:00.979    1755-1755/com.project.app E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: com.project.app, PID: 1755
    java.lang.NullPointerException
            at com.comcast.freeflow.core.FreeFlowContainer.getViewChanges(FreeFlowContainer.java:615)
            at com.comcast.freeflow.core.FreeFlowContainer.moveViewport(FreeFlowContainer.java:1064)
            at com.comcast.freeflow.core.FreeFlowContainer.moveViewportBy(FreeFlowContainer.java:1004)
            at com.comcast.freeflow.core.FreeFlowContainer.onTouchEvent(FreeFlowContainer.java:848)
            at android.view.View.dispatchTouchEvent(View.java:7706)
            at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2210)
            at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1945)
            at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
            at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
            at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
            at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
            at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
            at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
            at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
            at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
            at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
            at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
            at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
            at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
            at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:2068)
            at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1515)
            at android.app.Activity.dispatchTouchEvent(Activity.java:2458)
            at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:2016)
            at android.view.View.dispatchPointerEvent(View.java:7886)
            at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:3954)
            at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:3833)
            at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3399)
            at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3449)
            at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3418)
            at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3525)
            at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3426)
            at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:3582)
            at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3399)
            at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3449)
            at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3418)
            at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3426)
            at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3399)
            at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:5602)
            at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:5582)
            at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:5553)
            at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:5682)
            at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:185)
            at android.view.InputEventReceiver.nativeConsumeBatchedInputEvents(Native Method)
            at android.view.InputEventReceiver.consumeBatchedInputEvents(InputEventReceiver.java:176)
            at android.view.ViewRootImpl.doConsumeBatchedInput(ViewRootImpl.java:5655)
            at android.view.ViewRootImpl$ConsumeBatchedInputRunnable.run(ViewRootImpl.java:5701)
            at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761)
            at android.view.Choreographer.doCallbacks(Choreographer.java:574)
            at android.view.Choreographer.doFrame(Choreographer.java:542)
            at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747)
            at android.os.Handler.handleCallback(Handler.java:733)
            at android.os.Handler.dispat

Here is my Fragment

package com.project.app.fragments;

import android.app.Activity;
import android.content.Context;
import android.graphics.Point;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.Display;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.comcast.freeflow.core.AbsLayoutContainer;
import com.comcast.freeflow.core.FreeFlowContainer;
import com.comcast.freeflow.core.FreeFlowItem;
import com.comcast.freeflow.core.Section;
import com.comcast.freeflow.core.SectionedAdapter;
import com.comcast.freeflow.layouts.FreeFlowLayout;
import com.comcast.freeflow.layouts.VGridLayout;
import com.comcast.freeflow.layouts.VLayout;
import com.koushikdutta.urlimageviewhelper.UrlImageViewHelper;
import com.loopj.android.http.AsyncHttpClient;
import com.loopj.android.http.JsonHttpResponseHandler;
import com.loopj.android.http.RequestParams;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

import de.keyboardsurfer.android.widget.crouton.Configuration;
import de.keyboardsurfer.android.widget.crouton.Crouton;
import de.keyboardsurfer.android.widget.crouton.Style;
import com.project.app.R;
import com.project.app.models.Event;
import com.project.app.models.Photo;
import com.project.app.models.User;
import com.project.app.models.Venue;
import com.project.app.ui.ArtbookLayout;
import com.project.app.utils.Fields;

public class VenueGalleryFragment extends Fragment {
    Activity venueActivity;
    FreeFlowContainer ffContainer;
    ArtbookLayout custom;
    FreeFlowLayout[] layouts;
    VenuePhotosListAdapter adapter;
    Venue venue;
    AsyncHttpClient client;
    RequestParams photosParams;
    User currentUser;
    List<Photo> photos = new ArrayList<Photo>();

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment_venue_gallery, container, false);
        venue = (Venue) venueActivity.getIntent().getExtras().getSerializable("venue");

        ffContainer = (FreeFlowContainer) rootView.findViewById(R.id.ffcGallery);
        Display display = venueActivity.getWindowManager().getDefaultDisplay();
        Point size = new Point();
        display.getSize(size);

        custom = new ArtbookLayout();
        layouts = new FreeFlowLayout[]{custom};

        // Get the images
        client = new AsyncHttpClient();
        client.setTimeout(Fields.DEFAULT_TIMEOUT);
        currentUser = User.currentUser();
        photosParams = new RequestParams();

        adapter = new VenuePhotosListAdapter(venueActivity);
        ffContainer.setLayout(layouts[0]);
        ffContainer.setAdapter(adapter);

        client.get(Fields.GRAPH_VENUES_URL + "/" + venue.venueId + "/photos", photosParams, new JsonHttpResponseHandler() {
            @Override
            public void onSuccess(int statusCode, JSONObject response) {
                venueActivity.setProgressBarIndeterminateVisibility(Boolean.FALSE);
                try {
                    JSONArray photosArray = response.getJSONArray("photos");
                    for (int i = 0; i < photosArray.length(); i++) {
                        JSONObject photo = photosArray.getJSONObject(i);
                        photos.add(Photo.fromJson(photo));
                    }

                } catch (JSONException e) {
                    e.printStackTrace();
                }
                adapter.update(photos);
                ffContainer.dataInvalidated();
                ffContainer.setOnItemClickListener(new AbsLayoutContainer.OnItemClickListener() {
                    @Override
                    public void onItemClick(AbsLayoutContainer parent, FreeFlowItem proxy) {

                    }
                });

                ffContainer.addScrollListener( new FreeFlowContainer.OnScrollListener() {

                    @Override
                    public void onScroll(FreeFlowContainer container) {
                    }
                });
            }
        });

        return rootView;
    }

    protected class VenuePhotosListAdapter implements SectionedAdapter {

        private Context context;
        private Section section;

        public VenuePhotosListAdapter(Context context) {
            this.context = context;
            section = new Section();
            section.setSectionTitle("Pics");
        }

        public void update(List<Photo> photos){

            for(Photo o : photos){
                section.getData().add(o);
            }
        }
        @Override
        public long getItemId(int section, int position) {
            return section * 1000 + position;
        }

        @Override
        public View getItemView(int sectionIndex, int position, View convertView, ViewGroup parent) {
            if (convertView == null) {
                convertView = LayoutInflater.from(context).inflate(R.layout.list_item_pic_view, parent, false);
            }
            ImageView img = (ImageView) convertView.findViewById(R.id.pic);
            Photo p = (Photo) (section.getData().get(position));
            UrlImageViewHelper.setUrlDrawable(img, p.imageUrl, getResources().getDrawable(R.drawable.logo));
            return convertView;
        }

        @Override
        public View getHeaderViewForSection(int section, View convertView,
                                            ViewGroup parent) {
            return null;
        }

        @Override
        public int getNumberOfSections() {
            if(section.getData().size() == 0) return 0;
            return 1;
        }

        @Override
        public Section getSection(int index) {
            return section;
        }

        @Override
        public Class[] getViewTypes() {
            return new Class[] { LinearLayout.class };
        }

        @Override
        public Class getViewType(FreeFlowItem proxy) {
            return LinearLayout.class;
        }

        @Override
        public boolean shouldDisplaySectionHeaders() {
            return false;
        }

    }

    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
        venueActivity = activity;
    }

}
@tagrudev
Copy link
Author

tagrudev commented Mar 7, 2014

This seems to happen even when I am trying to switch from one layout to another hmm any ideas ?

@arpit
Copy link
Member

arpit commented Mar 13, 2014

I'll need some more info here, like the layouts etc. Please upload a compiling android project with this bug and I can take a look.

@arpit arpit added the question label Mar 14, 2014
@arpit arpit closed this as completed Mar 24, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants