Java Code Examples for android.support.v4.widget.SwipeRefreshLayout#setProgressViewOffset()

The following examples show how to use android.support.v4.widget.SwipeRefreshLayout#setProgressViewOffset() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DevicePermissionsListActivity.java    From freeiot-android with MIT License 6 votes vote down vote up
@Override
protected void onCreate(Bundle arg0) {
	super.onCreate(arg0);
	
	setContentView(R.layout.activity_deivces_permission_list);
	
	identifier = getIntent().getStringExtra("identifier");
	
	swipeLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_container);
	swipeLayout.setColorScheme(R.color.main_red_color);
	swipeLayout.setOnRefreshListener(this);
	swipeLayout.setProgressViewOffset(true, 0, UIUtils.dip2px(this, 48));
       mListView = (ListView) findViewById(R.id.listview);
       
       findViewById(R.id.back).setOnClickListener(this);
       findViewById(R.id.btn_add).setOnClickListener(this);
       loadDeviceAuthList(true);
}
 
Example 2
Source File: SubredditListView.java    From Slide with GNU General Public License v3.0 6 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    final Context contextThemeWrapper = new ContextThemeWrapper(getActivity(), new ColorPreferences(inflater.getContext()).getThemeSubreddit(where));
    View v = ((LayoutInflater) contextThemeWrapper.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.fragment_verticalcontent, container, false);

    rv = ((RecyclerView) v.findViewById(R.id.vertical_content));
    final RecyclerView.LayoutManager mLayoutManager = new PreCachingLayoutManager(getActivity());

    rv.setLayoutManager(mLayoutManager);
    rv.setItemAnimator(new SlideUpAlphaAnimator().withInterpolator(new LinearOutSlowInInterpolator()));

    mSwipeRefreshLayout = (SwipeRefreshLayout) v.findViewById(R.id.activity_main_swipe_refresh_layout);
    mSwipeRefreshLayout.setColorSchemeColors(Palette.getColors("no sub", getContext()));

    //If we use 'findViewById(R.id.header).getMeasuredHeight()', 0 is always returned.
    //So, we estimate the height of the header in dp
    mSwipeRefreshLayout.setProgressViewOffset(false,
            Constants.TAB_HEADER_VIEW_OFFSET - Constants.PTR_OFFSET_TOP,
            Constants.TAB_HEADER_VIEW_OFFSET + Constants.PTR_OFFSET_BOTTOM);

    v.findViewById(R.id.post_floating_action_button).setVisibility(View.GONE);
    doAdapter();

    return v;
}
 
Example 3
Source File: GalleryActivity.java    From meizhi with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_gallery);

    application = MeizhiApplication.from(this);

    DisplayMetrics metrics = getResources().getDisplayMetrics();
    int actionBarHeight = getSupportActionBar().getHeight();
    int swipeEndTarget = actionBarHeight + (int) (DEFAULT_CIRCLE_TARGET * metrics.density);

    refresh = (SwipeRefreshLayout) findViewById(R.id.refresh);
    refresh.setColorSchemeResources(R.color.accent);
    refresh.setProgressViewOffset(false, actionBarHeight, swipeEndTarget);
    refresh.setOnRefreshListener(this);

    adapter = new GalleryAdapter(this, this);

    layoutManager = new GridLayoutManager(this, getSpanCount());
    layoutManager.setSpanSizeLookup(new HeaderSpanSizeLookup(layoutManager));

    albums = (ObservableRecyclerView) findViewById(R.id.albums);
    albums.setHasFixedSize(true);
    albums.setLayoutManager(layoutManager);
    albums.setAdapter(adapter);
    albums.setScrollViewCallbacks(this);
}
 
Example 4
Source File: MyBehaviorActivity.java    From CoordinatorLayoutExample with Apache License 2.0 5 votes vote down vote up
private void initView(){
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    coordinatorLayout=(CoordinatorLayout)findViewById(R.id.behavior_demo_coordinatorLayout);

    recyclerview=(RecyclerView)findViewById(R.id.behavior_demo_recycler);
    mLayoutManager=new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL);
    recyclerview.setLayoutManager(mLayoutManager);

    swipeRefreshLayout=(SwipeRefreshLayout) findViewById(R.id.behavior_demo_swipe_refresh) ;
    swipeRefreshLayout.setProgressViewOffset(false, 0,  (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 24, getResources().getDisplayMetrics()));//调整下拉控件位置

    fab=(FloatingActionButton) findViewById(R.id.fab);
}
 
Example 5
Source File: MainActivity.java    From good-weather with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    ((GoodWeatherApp) getApplication()).applyTheme(this);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mWeather = new Weather();
    mCitySearch = new CitySearch();

    weatherConditionsIcons();
    initializeTextView();
    initializeWeatherReceiver();

    connectionDetector = new ConnectionDetector(MainActivity.this);
    locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

    mPrefWeather = getSharedPreferences(Constants.PREF_WEATHER_NAME, Context.MODE_PRIVATE);
    mSharedPreferences = getSharedPreferences(Constants.APP_SETTINGS_NAME,
            Context.MODE_PRIVATE);
    setTitle(Utils.getCityAndCountry(this));

    /**
     * Configure SwipeRefreshLayout
     */
    mSwipeRefresh = (SwipeRefreshLayout) findViewById(R.id.main_swipe_refresh);
    int top_to_padding = 150;
    mSwipeRefresh.setProgressViewOffset(false, 0, top_to_padding);
    mSwipeRefresh.setColorSchemeResources(R.color.swipe_red, R.color.swipe_green,
            R.color.swipe_blue);
    mSwipeRefresh.setOnRefreshListener(swipeRefreshListener);

    /**
     * Share weather fab
     */
    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    this.storedContext = this;
    fab.setOnClickListener(fabListener);
}
 
Example 6
Source File: MyDevicesListFragment.java    From freeiot-android with MIT License 5 votes vote down vote up
public void initView(View rootView) {
        mSwipeRefreshLayout = (SwipeRefreshLayout) rootView.findViewById(R.id.swipe_container);
        mSwipeRefreshLayout.setColorScheme(R.color.main_red_color);
        mSwipeRefreshLayout.setOnRefreshListener(this);
        mSwipeRefreshLayout.setProgressViewOffset(true, 0, UIUtils.dip2px(getActivity(), 48));
        mListView = (ListView) rootView.findViewById(R.id.listview);

        LocalBroadcastManager.getInstance(getActivity())
                .registerReceiver(refreshDevicesReceiver,
                        new IntentFilter(ActionConstants.ACTON_REFRESH_DEVICES));
        refreshDevices(true);
//		UpdateConfig.setDebug(true);
        UmengUpdateAgent.forceUpdate(getActivity());
    }
 
Example 7
Source File: ReaderMode.java    From Slide with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    overrideSwipeFromAnywhere();
    super.onCreate(savedInstanceState);
    applyColorTheme("");
    setContentView(R.layout.activity_reader);

    mSubredditColor =
            getIntent().getExtras().getInt(LinkUtil.EXTRA_COLOR, Palette.getDefaultColor());

    setSupportActionBar((Toolbar) findViewById(R.id.toolbar));
    setupAppBar(R.id.toolbar, "", true, mSubredditColor, R.id.appbar);

    if (getIntent().hasExtra("url")) {
        url = getIntent().getExtras().getString(LinkUtil.EXTRA_URL, "");
        ((Toolbar) findViewById(R.id.toolbar)).setTitle(url);

    }

    v = (SpoilerRobotoTextView) findViewById(R.id.body);
    final SwipeRefreshLayout mSwipeRefreshLayout =
            ((SwipeRefreshLayout) ReaderMode.this.findViewById(R.id.refresh));
    mSwipeRefreshLayout.setColorSchemeColors(Palette.getColors("", this));

    //If we use 'findViewById(R.id.header).getMeasuredHeight()', 0 is always returned.
    //So, we estimate the height of the header in dp.
    mSwipeRefreshLayout.setProgressViewOffset(false,
            Constants.SINGLE_HEADER_VIEW_OFFSET - Constants.PTR_OFFSET_TOP,
            Constants.SINGLE_HEADER_VIEW_OFFSET + Constants.PTR_OFFSET_BOTTOM);

    mSwipeRefreshLayout.post(new Runnable() {
        @Override
        public void run() {
            mSwipeRefreshLayout.setRefreshing(true);
        }
    });

    new AsyncGetArticle().execute();

}
 
Example 8
Source File: ModLog.java    From Slide with GNU General Public License v3.0 4 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    View v = inflater.inflate(R.layout.fragment_verticalcontent, container, false);

    RecyclerView rv = ((RecyclerView) v.findViewById(R.id.vertical_content));
    final PreCachingLayoutManager mLayoutManager;
    mLayoutManager = new PreCachingLayoutManager(getActivity());
    rv.setLayoutManager(mLayoutManager);

    v.findViewById(R.id.post_floating_action_button).setVisibility(View.GONE);

    final SwipeRefreshLayout mSwipeRefreshLayout = (SwipeRefreshLayout) v.findViewById(R.id.activity_main_swipe_refresh_layout);

    mSwipeRefreshLayout.setColorSchemeColors(Palette.getColors("mod", getActivity()));

    //If we use 'findViewById(R.id.header).getMeasuredHeight()', 0 is always returned.
    //So, we estimate the height of the header in dp
    mSwipeRefreshLayout.setProgressViewOffset(false,
            Constants.TAB_HEADER_VIEW_OFFSET - Constants.PTR_OFFSET_TOP,
            Constants.TAB_HEADER_VIEW_OFFSET + Constants.PTR_OFFSET_BOTTOM);

    mSwipeRefreshLayout.post(new Runnable() {
        @Override
        public void run() {
            mSwipeRefreshLayout.setRefreshing(true);
        }
    });
    posts = new ModLogPosts();
    adapter = new ModLogAdapter(getActivity(), posts, rv);
    rv.setAdapter(adapter);

    rv.setOnScrollListener(new ToolbarScrollHideHandler(((ModQueue) getActivity()).mToolbar, (getActivity()).findViewById(R.id.header)));

    posts.bindAdapter(adapter, mSwipeRefreshLayout);
    mSwipeRefreshLayout.setOnRefreshListener(
            new SwipeRefreshLayout.OnRefreshListener() {
                @Override
                public void onRefresh() {
                    posts.loadMore(adapter);
                }
            }
    );
    return v;
}
 
Example 9
Source File: AboutFragment.java    From qBittorrent-Controller with MIT License 4 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    // Tell the host activity that your fragment has menu options that it
    // wants to add/replace/delete using the onCreateOptionsMenu method.
    setHasOptionsMenu(true);

    View rootView = inflater.inflate(R.layout.about, container, false);

    // Get Refresh Listener
    refreshListener = (com.lgallardo.qbittorrentclient.RefreshListener) getActivity();

    mSwipeRefreshLayout = (SwipeRefreshLayout) rootView.findViewById(R.id.about_refresh_layout);

    // This fix the SwipeRefreshLayout setRefreshing not showing indicator initially issue
    // by calling setProgressViewOffset() on the SwipeRefreshLayout that invalidtes the circle view of the layout causing
    // SwipeRefreshLayout.onMeasure() to be called immediately.

    if(isFragmentFirstLoaded) {

        TypedValue typed_value = new TypedValue();
        getActivity().getTheme().resolveAttribute(android.support.v7.appcompat.R.attr.actionBarSize, typed_value, true);
        mSwipeRefreshLayout.setProgressViewOffset(false, 0, getResources().getDimensionPixelSize(typed_value.resourceId) * 2);

        mSwipeRefreshLayout.setColorSchemeColors(R.color.primary, R.color.primary_dark, R.color.primary_text);

        if(!MainActivity.hostname.equals("")) {
            mSwipeRefreshLayout.setRefreshing(true);
        }

        isFragmentFirstLoaded = false;
    }

    if(mSwipeRefreshLayout != null) {
        mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                Log.d("Debug", "Swipe!");
                refreshListener.swipeRefresh();

            }
        });
    }



    return rootView;
}
 
Example 10
Source File: ContributionsView.java    From Slide with GNU General Public License v3.0 4 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    View v = inflater.inflate(R.layout.fragment_verticalcontent, container, false);

    final RecyclerView rv = ((RecyclerView) v.findViewById(R.id.vertical_content));
    final PreCachingLayoutManager mLayoutManager;

    mLayoutManager = new PreCachingLayoutManager(getContext());


    rv.setLayoutManager(mLayoutManager);
    rv.setItemViewCacheSize(2);
    v.findViewById(R.id.post_floating_action_button).setVisibility(View.GONE);
    final SwipeRefreshLayout mSwipeRefreshLayout = (SwipeRefreshLayout) v.findViewById(R.id.activity_main_swipe_refresh_layout);

    mSwipeRefreshLayout.setColorSchemeColors(Palette.getColors(id, getActivity()));

    //If we use 'findViewById(R.id.header).getMeasuredHeight()', 0 is always returned.
    //So, we estimate the height of the header in dp
    mSwipeRefreshLayout.setProgressViewOffset(false,
            Constants.TAB_HEADER_VIEW_OFFSET - Constants.PTR_OFFSET_TOP,
            Constants.TAB_HEADER_VIEW_OFFSET + Constants.PTR_OFFSET_BOTTOM);

    mSwipeRefreshLayout.post(new Runnable() {
        @Override
        public void run() {
            mSwipeRefreshLayout.setRefreshing(true);
        }
    });

    if (where.equals("saved") && getActivity() instanceof Profile)
        posts = new ContributionPostsSaved(id, where, ((Profile) getActivity()).category);
    else
        posts = new ContributionPosts(id, where);

    //noinspection StringEquality
    if (where == "hidden") adapter = new ContributionAdapter(getActivity(), posts, rv, true);
    else adapter = new ContributionAdapter(getActivity(), posts, rv);
    rv.setAdapter(adapter);

    posts.bindAdapter(adapter, mSwipeRefreshLayout);
    //TODO catch errors
    mSwipeRefreshLayout.setOnRefreshListener(
            new SwipeRefreshLayout.OnRefreshListener() {
                @Override
                public void onRefresh() {
                    posts.loadMore(adapter, id, true);
                    //TODO catch errors
                }
            }
    );
    rv.addOnScrollListener(new ToolbarScrollHideHandler((Toolbar) getActivity().findViewById(R.id.toolbar), getActivity().findViewById(R.id.header)) {
        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            super.onScrolled(recyclerView, dx, dy);
            visibleItemCount = rv.getLayoutManager().getChildCount();
            totalItemCount = rv.getLayoutManager().getItemCount();
            if (rv.getLayoutManager() instanceof PreCachingLayoutManager) {
                pastVisiblesItems = ((PreCachingLayoutManager) rv.getLayoutManager()).findFirstVisibleItemPosition();
            } else {
                int[] firstVisibleItems = null;
                firstVisibleItems = ((CatchStaggeredGridLayoutManager) rv.getLayoutManager()).findFirstVisibleItemPositions(firstVisibleItems);
                if (firstVisibleItems != null && firstVisibleItems.length > 0) {
                    pastVisiblesItems = firstVisibleItems[0];
                }
            }

            if (!posts.loading) {
                if ((visibleItemCount + pastVisiblesItems) + 5 >= totalItemCount && !posts.nomore) {
                    posts.loading = true;
                    posts.loadMore(adapter, id, false);
                }
            }
        }
    });
    return v;
}
 
Example 11
Source File: ReadLaterView.java    From Slide with GNU General Public License v3.0 4 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.fragment_verticalcontent, container, false);

    final RecyclerView rv = ((RecyclerView) v.findViewById(R.id.vertical_content));
    final PreCachingLayoutManager mLayoutManager;

    mLayoutManager = new PreCachingLayoutManager(getContext());

    rv.setLayoutManager(mLayoutManager);
    v.findViewById(R.id.post_floating_action_button).setVisibility(View.GONE);
    final SwipeRefreshLayout mSwipeRefreshLayout = (SwipeRefreshLayout) v.findViewById(R.id.activity_main_swipe_refresh_layout);

    mSwipeRefreshLayout.setColorSchemeColors(Palette.getColors("default", getActivity()));

    //If we use 'findViewById(R.id.header).getMeasuredHeight()', 0 is always returned.
    //So, we estimate the height of the header in dp
    mSwipeRefreshLayout.setProgressViewOffset(false,
            Constants.SINGLE_HEADER_VIEW_OFFSET - Constants.PTR_OFFSET_TOP,
            Constants.SINGLE_HEADER_VIEW_OFFSET + Constants.PTR_OFFSET_BOTTOM);

    mSwipeRefreshLayout.post(new Runnable() {
        @Override
        public void run() {
            mSwipeRefreshLayout.setRefreshing(true);
        }
    });

    posts = new HistoryPosts("readLater");
    adapter = new ContributionAdapter(getActivity(), posts, rv);
    rv.setAdapter(adapter);

    posts.bindAdapter(adapter, mSwipeRefreshLayout);

    //TODO catch errors
    mSwipeRefreshLayout.setOnRefreshListener(
            new SwipeRefreshLayout.OnRefreshListener() {
                @Override
                public void onRefresh() {
                    posts.loadMore(adapter, true);

                    //TODO catch errors
                }
            }
    );
    rv.addOnScrollListener(new ToolbarScrollHideHandler((Toolbar) getActivity().findViewById(R.id.toolbar), getActivity().findViewById(R.id.header)) {
        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            super.onScrolled(recyclerView, dx, dy);
            visibleItemCount = rv.getLayoutManager().getChildCount();
            totalItemCount = rv.getLayoutManager().getItemCount();
            if (rv.getLayoutManager() instanceof PreCachingLayoutManager) {
                pastVisiblesItems = ((PreCachingLayoutManager) rv.getLayoutManager()).findFirstVisibleItemPosition();
            } else {
                int[] firstVisibleItems = null;
                firstVisibleItems = ((CatchStaggeredGridLayoutManager) rv.getLayoutManager()).findFirstVisibleItemPositions(firstVisibleItems);
                if (firstVisibleItems != null && firstVisibleItems.length > 0) {
                    pastVisiblesItems = firstVisibleItems[0];
                }
            }

            if (!posts.loading) {
                if ((visibleItemCount + pastVisiblesItems) + 5 >= totalItemCount && !posts.nomore) {
                    posts.loading = true;
                    posts.loadMore(adapter, false);
                }
            }
        }
    });
    return v;
}
 
Example 12
Source File: HistoryView.java    From Slide with GNU General Public License v3.0 4 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    View v = inflater.inflate(R.layout.fragment_verticalcontent, container, false);

    final RecyclerView rv = ((RecyclerView) v.findViewById(R.id.vertical_content));
    final PreCachingLayoutManager mLayoutManager;

    mLayoutManager = new PreCachingLayoutManager(getContext());


    rv.setLayoutManager(mLayoutManager);
    rv.setItemViewCacheSize(2);
    v.findViewById(R.id.post_floating_action_button).setVisibility(View.GONE);
    final SwipeRefreshLayout mSwipeRefreshLayout = (SwipeRefreshLayout) v.findViewById(R.id.activity_main_swipe_refresh_layout);

    mSwipeRefreshLayout.setColorSchemeColors(Palette.getColors("default", getActivity()));

    //If we use 'findViewById(R.id.header).getMeasuredHeight()', 0 is always returned.
    //So, we estimate the height of the header in dp
    mSwipeRefreshLayout.setProgressViewOffset(false,
            Constants.TAB_HEADER_VIEW_OFFSET - Constants.PTR_OFFSET_TOP,
            Constants.TAB_HEADER_VIEW_OFFSET + Constants.PTR_OFFSET_BOTTOM);

    mSwipeRefreshLayout.post(new Runnable() {
        @Override
        public void run() {
            mSwipeRefreshLayout.setRefreshing(true);
        }
    });

    posts = new HistoryPosts();
    adapter = new ContributionAdapter(getActivity(), posts, rv);
    rv.setAdapter(adapter);

    posts.bindAdapter(adapter, mSwipeRefreshLayout);

    //TODO catch errors
    mSwipeRefreshLayout.setOnRefreshListener(
            new SwipeRefreshLayout.OnRefreshListener() {
                @Override
                public void onRefresh() {
                    posts.loadMore(adapter, true);

                    //TODO catch errors
                }
            }
    );
    rv.addOnScrollListener(new ToolbarScrollHideHandler((Toolbar) getActivity().findViewById(R.id.toolbar), getActivity().findViewById(R.id.header)) {
        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            super.onScrolled(recyclerView, dx, dy);
            visibleItemCount = rv.getLayoutManager().getChildCount();
            totalItemCount = rv.getLayoutManager().getItemCount();
            if (rv.getLayoutManager() instanceof PreCachingLayoutManager) {
                pastVisiblesItems = ((PreCachingLayoutManager) rv.getLayoutManager()).findFirstVisibleItemPosition();
            } else {
                int[] firstVisibleItems = null;
                firstVisibleItems = ((CatchStaggeredGridLayoutManager) rv.getLayoutManager()).findFirstVisibleItemPositions(firstVisibleItems);
                if (firstVisibleItems != null && firstVisibleItems.length > 0) {
                    pastVisiblesItems = firstVisibleItems[0];
                }
            }

            if (!posts.loading) {
                if ((visibleItemCount + pastVisiblesItems) + 5 >= totalItemCount && !posts.nomore) {
                    posts.loading = true;
                    posts.loadMore(adapter, false);
                }
            }
        }
    });
    return v;
}
 
Example 13
Source File: InboxPage.java    From Slide with GNU General Public License v3.0 4 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.fragment_verticalcontent, container, false);

    final RecyclerView rv = ((RecyclerView) v.findViewById(R.id.vertical_content));
    final PreCachingLayoutManager mLayoutManager;
    mLayoutManager = new PreCachingLayoutManager(getActivity());
    rv.setLayoutManager(mLayoutManager);

    final SwipeRefreshLayout mSwipeRefreshLayout = (SwipeRefreshLayout) v.findViewById(R.id.activity_main_swipe_refresh_layout);
    v.findViewById(R.id.post_floating_action_button).setVisibility(View.GONE);

    mSwipeRefreshLayout.setColorSchemeColors(Palette.getColors(id, getActivity()));

    //If we use 'findViewById(R.id.header).getMeasuredHeight()', 0 is always returned.
    //So, we estimate the height of the header in dp
    mSwipeRefreshLayout.setProgressViewOffset(false,
            Constants.TAB_HEADER_VIEW_OFFSET - Constants.PTR_OFFSET_TOP,
            Constants.TAB_HEADER_VIEW_OFFSET + Constants.PTR_OFFSET_BOTTOM);

    mSwipeRefreshLayout.post(new Runnable() {
        @Override
        public void run() {
            mSwipeRefreshLayout.setRefreshing(true);
        }
    });
    posts = new InboxMessages(id);
    adapter = new InboxAdapter(getContext(), posts, rv);
    rv.setAdapter(adapter);

    posts.bindAdapter(adapter, mSwipeRefreshLayout);

    //TODO catch errors
    mSwipeRefreshLayout.setOnRefreshListener(
            new SwipeRefreshLayout.OnRefreshListener() {
                @Override
                public void onRefresh() {
                    posts.loadMore(adapter, id, true);

                    //TODO catch errors
                }
            }
    );
    rv.addOnScrollListener(new ToolbarScrollHideHandler((Toolbar) (getActivity()).findViewById(R.id.toolbar), getActivity().findViewById(R.id.header)) {
        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            super.onScrolled(recyclerView, dx, dy);
            visibleItemCount = rv.getLayoutManager().getChildCount();
            totalItemCount = rv.getLayoutManager().getItemCount();

            if (rv.getLayoutManager() instanceof PreCachingLayoutManager) {
                pastVisiblesItems = ((PreCachingLayoutManager) rv.getLayoutManager()).findFirstVisibleItemPosition();
            } else {
                int[] firstVisibleItems = null;
                firstVisibleItems = ((CatchStaggeredGridLayoutManager) rv.getLayoutManager()).findFirstVisibleItemPositions(firstVisibleItems);

                if (firstVisibleItems != null && firstVisibleItems.length > 0) {
                    pastVisiblesItems = firstVisibleItems[0];
                }
            }

            if (!posts.loading && !posts.nomore) {
                if ((visibleItemCount + pastVisiblesItems) + 5 >= totalItemCount) {
                    posts.loading = true;
                    posts.loadMore(adapter, id, false);
                }
            }
        }
    });
    return v;
}
 
Example 14
Source File: ModPage.java    From Slide with GNU General Public License v3.0 4 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    View v = inflater.inflate(R.layout.fragment_verticalcontent, container, false);

    RecyclerView rv = ((RecyclerView) v.findViewById(R.id.vertical_content));
    final PreCachingLayoutManager mLayoutManager;
    mLayoutManager = new PreCachingLayoutManager(getActivity());
    rv.setLayoutManager(mLayoutManager);

    v.findViewById(R.id.post_floating_action_button).setVisibility(View.GONE);

    final SwipeRefreshLayout mSwipeRefreshLayout = (SwipeRefreshLayout) v.findViewById(R.id.activity_main_swipe_refresh_layout);

    mSwipeRefreshLayout.setColorSchemeColors(Palette.getColors(id, getActivity()));

    //If we use 'findViewById(R.id.header).getMeasuredHeight()', 0 is always returned.
    //So, we estimate the height of the header in dp
    mSwipeRefreshLayout.setProgressViewOffset(false,
            Constants.TAB_HEADER_VIEW_OFFSET - Constants.PTR_OFFSET_TOP,
            Constants.TAB_HEADER_VIEW_OFFSET + Constants.PTR_OFFSET_BOTTOM);

    mSwipeRefreshLayout.post(new Runnable() {
        @Override
        public void run() {
            mSwipeRefreshLayout.setRefreshing(true);
        }
    });
    posts = new ModeratorPosts(id, sub);
    adapter = new ModeratorAdapter(getActivity(), posts, rv);
    rv.setAdapter(adapter);

    rv.setOnScrollListener(new ToolbarScrollHideHandler(((ModQueue) getActivity()).mToolbar, (getActivity()).findViewById(R.id.header)));

    posts.bindAdapter(adapter, mSwipeRefreshLayout);
    mSwipeRefreshLayout.setOnRefreshListener(
            new SwipeRefreshLayout.OnRefreshListener() {
                @Override
                public void onRefresh() {
                    posts.loadMore(adapter, id, sub);
                }
            }
    );
    return v;
}
 
Example 15
Source File: MainActivity.java    From your-local-weather with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    ((YourLocalWeather) getApplication()).applyTheme(this);
    super.onCreate(savedInstanceState);
    locationsDbHelper = LocationsDbHelper.getInstance(this);
    weatherForecastDbHelper = WeatherForecastDbHelper.getInstance(this);
    currentWeatherDbHelper = CurrentWeatherDbHelper.getInstance(this);
    setContentView(R.layout.activity_main);

    weatherConditionsIcons();
    initializeTextView();
    initializeWeatherReceiver();

    connectionDetector = new ConnectionDetector(MainActivity.this);
    setTitle( R.string.label_activity_main);

    /**
     * Configure SwipeRefreshLayout
     */
    mSwipeRefresh = (SwipeRefreshLayout) findViewById(R.id.main_swipe_refresh);
    int top_to_padding = 150;
    mSwipeRefresh.setProgressViewOffset(false, 0, top_to_padding);
    mSwipeRefresh.setColorSchemeResources(R.color.swipe_red, R.color.swipe_green,
            R.color.swipe_blue);
    mSwipeRefresh.setOnRefreshListener(swipeRefreshListener);

    NestedScrollView main_scroll_view = (NestedScrollView) findViewById(R.id.main_scroll_view);
    main_scroll_view.setOnTouchListener(new ActivityTransitionTouchListener(
            null,
            WeatherForecastActivity.class, this));

    updateUI();
    /**
     * Share weather fab
     */
    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    this.storedContext = this;
    fab.setOnClickListener(fabListener);
    checkSettingsAndPermisions();
    //startAlarms();
    StartAlarmsTask startAlarmsTask = new StartAlarmsTask();
    startAlarmsTask.execute(new Integer[0]);
}
 
Example 16
Source File: BottomSheetActivity.java    From CoordinatorLayoutExample with Apache License 2.0 4 votes vote down vote up
private void initView(){
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    coordinatorLayout=(CoordinatorLayout)findViewById(R.id.bottom_sheet_demo_coordinatorLayout);

    recyclerview=(RecyclerView)findViewById(R.id.bottom_sheet_demo_recycler);
    mLayoutManager=new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL);
    recyclerview.setLayoutManager(mLayoutManager);

    swipeRefreshLayout=(SwipeRefreshLayout) findViewById(R.id.bottom_sheet_demo_swipe_refresh) ;
    swipeRefreshLayout.setProgressViewOffset(false, 0,  (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 24, getResources().getDisplayMetrics()));//调整下拉控件位置

    design_bottom_sheet_bar=(RelativeLayout) findViewById(R.id.design_bottom_sheet_bar);

    design_bottom_sheet=(RelativeLayout) findViewById(R.id.design_bottom_sheet);
    bottom_sheet_iv=(ImageView) findViewById(R.id.bottom_sheet_iv);
    bottom_sheet_tv=(TextView) findViewById(R.id.bottom_sheet_tv);

    behavior = BottomSheetBehavior.from(design_bottom_sheet);

}
 
Example 17
Source File: BaiduMapSample.java    From CoordinatorLayoutExample with Apache License 2.0 4 votes vote down vote up
private void initView(){
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    coordinatorLayout=(CoordinatorLayout)findViewById(R.id.bottom_sheet_demo_coordinatorLayout);

    recyclerview=(RecyclerView)findViewById(R.id.bottom_sheet_demo_recycler);
    mLayoutManager=new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL);
    recyclerview.setLayoutManager(mLayoutManager);

    swipeRefreshLayout=(SwipeRefreshLayout) findViewById(R.id.bottom_sheet_demo_swipe_refresh) ;
    swipeRefreshLayout.setProgressViewOffset(false, 0,  (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 24, getResources().getDisplayMetrics()));//调整下拉控件位置

    design_bottom_sheet_bar=(RelativeLayout) findViewById(R.id.design_bottom_sheet_bar);

    design_bottom_sheet=(RelativeLayout) findViewById(R.id.design_bottom_sheet);
    bottom_sheet_iv=(ImageView) findViewById(R.id.bottom_sheet_iv);
    bottom_sheet_tv=(TextView) findViewById(R.id.bottom_sheet_tv);

    behavior = BottomSheetBehavior.from(design_bottom_sheet);

}