Search in sources :

Example 26 with SwipeRefreshLayout

use of android.support.v4.widget.SwipeRefreshLayout in project EC2018App by Manan-YMCA.

the class LeaderboardFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final View view = inflater.inflate(R.layout.fragment_leaderboard, container, false);
    if (mContext == null) {
        mContext = getActivity();
    }
    c = mContext;
    // refreshB=view.findViewById(R.id.refresh_butto);
    refresh = view.findViewById(R.id.refresh_text);
    swipeRefreshLayout = view.findViewById(R.id.swipe);
    swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {

        @Override
        public void onRefresh() {
            reload();
        }
    });
    bar = (ProgressBar) view.findViewById(R.id.pb_leaderboard);
    bar.setVisibility(View.VISIBLE);
    bar.getIndeterminateDrawable().setColorFilter(mContext.getResources().getColor(R.color.pb_xunbao), android.graphics.PorterDuff.Mode.MULTIPLY);
    if (isNetworkAvailable()) {
        setData();
    } else {
        MDToast.makeText(mContext.getApplicationContext(), "Connect to Internet", Toast.LENGTH_SHORT, MDToast.TYPE_ERROR).show();
    }
    // progressBar = new ProgressDialog(mContext);
    // progressBar.setMessage("Loading");
    // progressBar.setCanceledOnTouchOutside(false);
    // progressBar.show();
    recyclerView = (RecyclerView) view.findViewById(R.id.recycler_view);
    RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(c);
    recyclerView.setLayoutManager(mLayoutManager);
    // });
    return view;
}
Also used : RecyclerView(android.support.v7.widget.RecyclerView) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout)

Example 27 with SwipeRefreshLayout

use of android.support.v4.widget.SwipeRefreshLayout in project LollipopShowcase by mikepenz.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    // Handle Toolbar
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    final SharedPreferences pref = getSharedPreferences("com.mikepenz.applicationreader", 0);
    drawer = new DrawerBuilder(this).withToolbar(toolbar).addDrawerItems(new SwitchDrawerItem().withOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(IDrawerItem drawerItem, CompoundButton compoundButton, boolean b) {
            SharedPreferences.Editor editor = pref.edit();
            editor.putBoolean("autouploadenabled", b);
            editor.apply();
        }
    }).withName(R.string.drawer_switch).withChecked(pref.getBoolean("autouploadenabled", false))).addStickyDrawerItems(new SecondaryDrawerItem().withName(R.string.drawer_opensource).withIdentifier(DRAWER_ITEM_OPEN_SOURCE).withIcon(FontAwesome.Icon.faw_github).withSelectable(false)).withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {

        @Override
        public boolean onItemClick(View view, int i, IDrawerItem drawerItem) {
            if (drawerItem.getIdentifier() == DRAWER_ITEM_OPEN_SOURCE) {
                new LibsBuilder().withFields(R.string.class.getFields()).withVersionShown(true).withLicenseShown(true).withActivityTitle(getString(R.string.drawer_opensource)).withActivityStyle(Libs.ActivityStyle.LIGHT_DARK_TOOLBAR).start(MainActivity.this);
            }
            return false;
        }
    }).withSelectedItem(-1).withSavedInstance(savedInstanceState).build();
    // Handle ProgressBar
    mProgressBar = (ProgressBar) findViewById(R.id.progressBar);
    // Fab Button
    mFabButton = (FloatingActionButton) findViewById(R.id.fab_normal);
    mFabButton.setImageDrawable(new IconicsDrawable(this, GoogleMaterial.Icon.gmd_file_upload).color(Color.WHITE).actionBar());
    mFabButton.setOnClickListener(fabClickListener);
    mRecyclerView = (RecyclerView) findViewById(R.id.list);
    mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
    mRecyclerView.setItemAnimator(new CustomItemAnimator());
    // mRecyclerView.setItemAnimator(new ReboundItemAnimator());
    mAdapter = new ApplicationAdapter(new ArrayList<AppInfo>(), R.layout.row_application, MainActivity.this);
    mRecyclerView.setAdapter(mAdapter);
    mSwipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_container);
    mSwipeRefreshLayout.setColorSchemeColors(getResources().getColor(R.color.theme_accent));
    mSwipeRefreshLayout.setRefreshing(true);
    mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {

        @Override
        public void onRefresh() {
            new InitializeApplicationsTask().execute();
        }
    });
    new InitializeApplicationsTask().execute();
    if (savedInstanceState != null) {
        if (uploadComponentInfoTask != null) {
            if (uploadComponentInfoTask.isRunning) {
                uploadComponentInfoTask.showProgress(this);
            }
        }
    }
    // show progress
    mRecyclerView.setVisibility(View.GONE);
    mProgressBar.setVisibility(View.VISIBLE);
}
Also used : IDrawerItem(com.mikepenz.materialdrawer.model.interfaces.IDrawerItem) OnCheckedChangeListener(com.mikepenz.materialdrawer.interfaces.OnCheckedChangeListener) SharedPreferences(android.content.SharedPreferences) ArrayList(java.util.ArrayList) SwitchDrawerItem(com.mikepenz.materialdrawer.model.SwitchDrawerItem) Drawer(com.mikepenz.materialdrawer.Drawer) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) SecondaryDrawerItem(com.mikepenz.materialdrawer.model.SecondaryDrawerItem) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) LibsBuilder(com.mikepenz.aboutlibraries.LibsBuilder) CustomItemAnimator(com.mikepenz.lollipopshowcase.itemanimator.CustomItemAnimator) DrawerBuilder(com.mikepenz.materialdrawer.DrawerBuilder) ApplicationAdapter(com.mikepenz.lollipopshowcase.adapter.ApplicationAdapter) IconicsDrawable(com.mikepenz.iconics.IconicsDrawable) CompoundButton(android.widget.CompoundButton) Toolbar(android.support.v7.widget.Toolbar)

Example 28 with SwipeRefreshLayout

use of android.support.v4.widget.SwipeRefreshLayout in project OpenBikeSharing by bparmentier.

the class StationsListActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_stations_list);
    refreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_container);
    refreshLayout.setColorSchemeResources(R.color.bike_red, R.color.parking_blue_dark);
    refreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {

        @Override
        public void onRefresh() {
            executeDownloadTask();
        }
    });
    viewPager = (ViewPager) findViewById(R.id.viewPager);
    viewPager.setOffscreenPageLimit(2);
    viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {

        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
        }

        @Override
        public void onPageSelected(int position) {
            actionBar.setSelectedNavigationItem(position);
        }

        @Override
        public void onPageScrollStateChanged(int state) {
            /* as explained on
                http://stackoverflow.com/questions/25978462/swiperefreshlayout-viewpager-limit-horizontal-scroll-only
                 */
            refreshLayout.setEnabled(state == ViewPager.SCROLL_STATE_IDLE);
        }
    });
    stationsDataSource = new StationsDataSource(this);
    stations = stationsDataSource.getStations();
    favStations = stationsDataSource.getFavoriteStations();
    nearbyStations = new ArrayList<>();
    tabsPagerAdapter = new TabsPagerAdapter(getSupportFragmentManager());
    viewPager.setAdapter(tabsPagerAdapter);
    settings = PreferenceManager.getDefaultSharedPreferences(this);
    actionBar = getActionBar();
    int defaultTabIndex = Integer.valueOf(settings.getString(PREF_KEY_DEFAULT_TAB, "0"));
    for (int i = 0; i < 3; i++) {
        ActionBar.Tab tab = actionBar.newTab();
        tab.setTabListener(this);
        tab.setText(tabsPagerAdapter.getPageTitle(i));
        actionBar.addTab(tab, (defaultTabIndex == i));
    }
    actionBar.setHomeButtonEnabled(false);
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    boolean firstRun = settings.getString(PREF_KEY_NETWORK_ID, "").isEmpty();
    setDBLastUpdateText();
    if (firstRun) {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setMessage(R.string.welcome_dialog_message);
        builder.setTitle(R.string.welcome_dialog_title);
        builder.setPositiveButton(R.string.welcome_dialog_ok, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                Intent intent = new Intent(StationsListActivity.this, BikeNetworksListActivity.class);
                startActivityForResult(intent, PICK_NETWORK_REQUEST);
            }
        });
        builder.setNegativeButton(R.string.welcome_dialog_cancel, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                finish();
            }
        });
        AlertDialog dialog = builder.create();
        dialog.show();
    } else {
        if (savedInstanceState != null) {
            bikeNetwork = (BikeNetwork) savedInstanceState.getSerializable(KEY_BIKE_NETWORK);
            stations = (ArrayList<Station>) savedInstanceState.getSerializable(KEY_STATIONS);
            favStations = (ArrayList<Station>) savedInstanceState.getSerializable(KEY_FAV_STATIONS);
            nearbyStations = (ArrayList<Station>) savedInstanceState.getSerializable(KEY_NEARBY_STATIONS);
        } else {
            String networkId = settings.getString(PREF_KEY_NETWORK_ID, "");
            String stationUrl = settings.getString(PREF_KEY_API_URL, DEFAULT_API_URL) + "networks/" + networkId;
            jsonDownloadTask = new JSONDownloadTask();
            jsonDownloadTask.execute(stationUrl);
        }
    }
}
Also used : AlertDialog(android.app.AlertDialog) DialogInterface(android.content.DialogInterface) Intent(android.content.Intent) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) ViewPager(android.support.v4.view.ViewPager) Station(be.brunoparmentier.openbikesharing.app.models.Station) StationsDataSource(be.brunoparmentier.openbikesharing.app.db.StationsDataSource) ActionBar(android.app.ActionBar)

Example 29 with SwipeRefreshLayout

use of android.support.v4.widget.SwipeRefreshLayout in project OpenBikeSharing by bparmentier.

the class StationsListFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_stations_list, container, false);
    ListView listView = (ListView) view.findViewById(R.id.stationsListView);
    listView.setAdapter(stationsListAdapter);
    TextView emptyView = (TextView) view.findViewById(R.id.emptyList);
    emptyView.setText(emptyListResourceId);
    listView.setEmptyView(view.findViewById(R.id.emptyList));
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Intent intent = new Intent(getActivity(), StationActivity.class);
            intent.putExtra(KEY_STATION, stations.get(position));
            startActivity(intent);
        }
    });
    listView.setOnScrollListener(new AbsListView.OnScrollListener() {

        @Override
        public void onScrollStateChanged(AbsListView view, int scrollState) {
        }

        @Override
        public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
            SwipeRefreshLayout refreshLayout = (SwipeRefreshLayout) getActivity().findViewById(R.id.swipe_container);
            if (firstVisibleItem == 0)
                refreshLayout.setEnabled(true);
            else
                refreshLayout.setEnabled(false);
        }
    });
    return view;
}
Also used : AbsListView(android.widget.AbsListView) Intent(android.content.Intent) AbsListView(android.widget.AbsListView) TextView(android.widget.TextView) View(android.view.View) AdapterView(android.widget.AdapterView) ListView(android.widget.ListView) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) AbsListView(android.widget.AbsListView) ListView(android.widget.ListView) StationActivity(be.brunoparmentier.openbikesharing.app.activities.StationActivity) TextView(android.widget.TextView) AdapterView(android.widget.AdapterView)

Example 30 with SwipeRefreshLayout

use of android.support.v4.widget.SwipeRefreshLayout in project MiMangaNu by raulhaag.

the class DetailsFragment method onStart.

@Override
public void onStart() {
    super.onStart();
    Thread t0 = new Thread(new Runnable() {

        @Override
        public void run() {
            try {
                List<Manga> mangas = Database.getMangas(getContext(), null, true);
                for (Manga m : mangas) {
                    if (m.getPath().equals(manga.getPath())) {
                        mangaAlreadyAdded = true;
                        if (floatingActionButton_add != null)
                            floatingActionButton_add.hide();
                    }
                }
            } catch (Exception e) {
                Log.e(TAG, "Exception", e);
                Util.getInstance().toast(getContext(), Log.getStackTraceString(e));
            }
        }
    });
    t0.start();
    data = (ControlInfo) getView().findViewById(R.id.datos);
    swipeRefreshLayout = (SwipeRefreshLayout) getView().findViewById(R.id.str);
    ActionBar mActBar = getActivity().getActionBar();
    if (mActBar != null) {
        mActBar.setDisplayHomeAsUpEnabled(true);
    }
    floatingActionButton_add = (FloatingActionButton) getView().findViewById(R.id.floatingActionButton_add);
    floatingActionButton_add.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            if (!mangaAlreadyAdded) {
                AsyncAddManga nAsyncAddManga = new AsyncAddManga(manga, getActivity(), getView(), false, false, true);
                nAsyncAddManga.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
                AnimatorSet set = new AnimatorSet();
                ObjectAnimator anim1 = ObjectAnimator.ofFloat(floatingActionButton_add, "alpha", 1.0f, 0.0f);
                anim1.setDuration(0);
                DisplayMetrics displayMetrics = getResources().getDisplayMetrics();
                ObjectAnimator anim2 = ObjectAnimator.ofFloat(floatingActionButton_add, "y", displayMetrics.heightPixels);
                anim2.setDuration(500);
                set.playSequentially(anim2, anim1);
                set.start();
            } else {
                Util.getInstance().showFastSnackBar(getString(R.string.already_on_db), getView(), getContext());
            }
        }
    });
    int[] colors = ThemeColors.getColors(PreferenceManager.getDefaultSharedPreferences(getActivity()));
    floatingActionButton_add.setBackgroundTintList(ColorStateList.valueOf(colors[1]));
    swipeRefreshLayout.setColorSchemeColors(colors[0], colors[1]);
    data.setColor(MainActivity.darkTheme, colors[0]);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        Window window = getActivity().getWindow();
        window.setNavigationBarColor(colors[0]);
        window.setStatusBarColor(colors[4]);
    }
    if (getActivity() != null) {
        ((MainActivity) getActivity()).setTitle(getResources().getString(R.string.datosde) + " " + title);
    }
    manga = new Manga(id, title, path, false);
    manga.setImages(img);
    data.enableTitleCopy(getActivity(), manga.getTitle());
    serverBase = ServerBase.getServer(id, getContext());
    imageLoader = new ImageLoader(getContext());
    swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {

        @Override
        public void onRefresh() {
            loadDetailsTask = (LoadDetailsTask) new LoadDetailsTask().execute();
        }
    });
    swipeRefreshLayout.post(new Runnable() {

        @Override
        public void run() {
            swipeRefreshLayout.setRefreshing(true);
        }
    });
    loadDetailsTask = (LoadDetailsTask) new LoadDetailsTask().execute();
}
Also used : Window(android.view.Window) ObjectAnimator(android.animation.ObjectAnimator) AnimatorSet(android.animation.AnimatorSet) View(android.view.View) DisplayMetrics(android.util.DisplayMetrics) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) AsyncAddManga(ar.rulosoft.mimanganu.utils.AsyncAddManga) OnClickListener(android.view.View.OnClickListener) ColorStateList(android.content.res.ColorStateList) List(java.util.List) ImageLoader(com.fedorvlasov.lazylist.ImageLoader) Manga(ar.rulosoft.mimanganu.componentes.Manga) AsyncAddManga(ar.rulosoft.mimanganu.utils.AsyncAddManga) ActionBar(android.app.ActionBar)

Aggregations

SwipeRefreshLayout (android.support.v4.widget.SwipeRefreshLayout)102 View (android.view.View)55 RecyclerView (android.support.v7.widget.RecyclerView)43 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)41 TextView (android.widget.TextView)29 Bundle (android.os.Bundle)21 Intent (android.content.Intent)17 Handler (android.os.Handler)17 DefaultItemAnimator (android.support.v7.widget.DefaultItemAnimator)16 AdapterView (android.widget.AdapterView)15 ListView (android.widget.ListView)15 ArrayList (java.util.ArrayList)13 ImageView (android.widget.ImageView)10 ViewGroup (android.view.ViewGroup)9 Context (android.content.Context)8 LayoutInflater (android.view.LayoutInflater)8 GridLayoutManager (android.support.v7.widget.GridLayoutManager)7 PandaRecyclerView (com.instructure.pandarecycler.PandaRecyclerView)7 SearchView (android.support.v7.widget.SearchView)6 Toolbar (android.support.v7.widget.Toolbar)6