Search in sources :

Example 81 with Adapter

use of android.support.v7.widget.RecyclerView.Adapter in project AndroidDevelop by 7449.

the class MainActivity method initCreate.

@Override
protected void initCreate(Bundle savedInstanceState) {
    toolbar.setTitle("推荐");
    setSupportActionBar(toolbar);
    presenter = new RecommendPresenterImpl(this);
    adapter = new RecommendAdapter();
    recyclerView.setAdapter(adapter);
    recyclerView.setHasFixedSize(true);
    recyclerView.setLayoutManager(new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL));
    swipeRefreshLayout.setOnRefreshListener(this);
    swipeRefreshLayout.setColorSchemeColors(ContextCompat.getColor(getBaseContext(), R.color.colorPrimary));
    swipeRefreshLayout.post(new Runnable() {

        @Override
        public void run() {
            onRefresh();
        }
    });
}
Also used : RecommendPresenterImpl(com.bilirecommendui.main.presenter.RecommendPresenterImpl) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager) RecommendAdapter(com.bilirecommendui.main.widget.adapter.RecommendAdapter)

Example 82 with Adapter

use of android.support.v7.widget.RecyclerView.Adapter in project AndroidDevelop by 7449.

the class SettingFragment method initData.

@Override
protected void initData() {
    mPresenter = new SettingPresenterImpl(this);
    List<SettingBean> list = new ArrayList<>();
    list.add(new SettingBean(getString(R.string.setting_clear_setting)));
    list.add(new SettingBean(getString(R.string.setting_delete_app_name)));
    list.add(new SettingBean(getString(R.string.setting_alter_pass_word)));
    list.add(new SettingBean(getString(R.string.setting_exit)));
    mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
    SettingAdapter adapter = new SettingAdapter(list);
    adapter.setOnItemClickListener(this);
    mRecyclerView.setAdapter(adapter);
}
Also used : SettingPresenterImpl(com.lock.setting.presenter.SettingPresenterImpl) ArrayList(java.util.ArrayList) SettingBean(com.lock.setting.model.SettingBean) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager)

Example 83 with Adapter

use of android.support.v7.widget.RecyclerView.Adapter in project AndroidDevelop by 7449.

the class LinearLayoutManagerActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recyclerView);
    mDatas = new ArrayList<>();
    initData(mDatas);
    adapter = new MyAdapter(mDatas, recyclerView);
    adapter.setOnItemClickListener(this);
    adapter.addHeader(getView(R.layout.header));
    adapter.addFooter(getView(R.layout.footer));
    recyclerView.setLayoutManager(new LinearLayoutManager(this));
    recyclerView.setAdapter(adapter);
    View headerView = adapter.getHeaderView();
    View footerView = adapter.getFooterView();
    footerView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Toast("this is footer");
        }
    });
    headerView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Toast("this is header");
        }
    });
    adapter.setLoadingListener(new SuperAdapter.LoadingListener() {

        @Override
        public void onRefresh() {
            count = 0;
            new Handler().postDelayed(new Runnable() {

                @Override
                public void run() {
                    adapter.removeAll();
                    initData(mDatas);
                    adapter.refreshComplete(RefreshHeaderLayout.STATE_SUCCESS);
                }
            }, 1000);
        }

        @Override
        public void onLoadMore() {
            count++;
            adapter.loadMoreComplete(LoadMoreFooterLayout.STATE_LOADING);
            new Handler().postDelayed(new Runnable() {

                @Override
                public void run() {
                    if (count > 1) {
                        adapter.loadMoreComplete(LoadMoreFooterLayout.STATE_LOAD_EMPTY);
                        return;
                    }
                    adapter.loadMoreComplete(LoadMoreFooterLayout.STATE_SUCCESS);
                    initData(mDatas);
                }
            }, 1000);
        }
    });
    adapter.setRefreshing(true);
}
Also used : Handler(android.os.Handler) RecyclerView(android.support.v7.widget.RecyclerView) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View) SuperAdapter(com.superadapter.widget.SuperAdapter)

Example 84 with Adapter

use of android.support.v7.widget.RecyclerView.Adapter in project AntennaPod by AntennaPod.

the class ItunesSearchFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View root = inflater.inflate(R.layout.fragment_itunes_search, container, false);
    gridView = (GridView) root.findViewById(R.id.gridView);
    adapter = new ItunesAdapter(getActivity(), new ArrayList<>());
    gridView.setAdapter(adapter);
    //Show information about the podcast when the list item is clicked
    gridView.setOnItemClickListener((parent, view1, position, id) -> {
        Podcast podcast = searchResults.get(position);
        if (!podcast.feedUrl.contains("itunes.apple.com")) {
            Intent intent = new Intent(getActivity(), OnlineFeedViewActivity.class);
            intent.putExtra(OnlineFeedViewActivity.ARG_FEEDURL, podcast.feedUrl);
            intent.putExtra(OnlineFeedViewActivity.ARG_TITLE, "iTunes");
            startActivity(intent);
        } else {
            gridView.setVisibility(View.GONE);
            progressBar.setVisibility(View.VISIBLE);
            subscription = Observable.create((Observable.OnSubscribe<String>) subscriber -> {
                OkHttpClient client = AntennapodHttpClient.getHttpClient();
                Request.Builder httpReq = new Request.Builder().url(podcast.feedUrl).header("User-Agent", ClientConfig.USER_AGENT);
                try {
                    Response response = client.newCall(httpReq.build()).execute();
                    if (response.isSuccessful()) {
                        String resultString = response.body().string();
                        JSONObject result = new JSONObject(resultString);
                        JSONObject results = result.getJSONArray("results").getJSONObject(0);
                        String feedUrl = results.getString("feedUrl");
                        subscriber.onNext(feedUrl);
                    } else {
                        String prefix = getString(R.string.error_msg_prefix);
                        subscriber.onError(new IOException(prefix + response));
                    }
                } catch (IOException | JSONException e) {
                    subscriber.onError(e);
                }
                subscriber.onCompleted();
            }).subscribeOn(Schedulers.newThread()).observeOn(AndroidSchedulers.mainThread()).subscribe(feedUrl -> {
                progressBar.setVisibility(View.GONE);
                gridView.setVisibility(View.VISIBLE);
                Intent intent = new Intent(getActivity(), OnlineFeedViewActivity.class);
                intent.putExtra(OnlineFeedViewActivity.ARG_FEEDURL, feedUrl);
                intent.putExtra(OnlineFeedViewActivity.ARG_TITLE, "iTunes");
                startActivity(intent);
            }, error -> {
                Log.e(TAG, Log.getStackTraceString(error));
                progressBar.setVisibility(View.GONE);
                gridView.setVisibility(View.VISIBLE);
                String prefix = getString(R.string.error_msg_prefix);
                new MaterialDialog.Builder(getActivity()).content(prefix + " " + error.getMessage()).neutralText(android.R.string.ok).show();
            });
        }
    });
    progressBar = (ProgressBar) root.findViewById(R.id.progressBar);
    txtvError = (TextView) root.findViewById(R.id.txtvError);
    butRetry = (Button) root.findViewById(R.id.butRetry);
    txtvEmpty = (TextView) root.findViewById(android.R.id.empty);
    loadToplist();
    return root;
}
Also used : Bundle(android.os.Bundle) GridView(android.widget.GridView) ProgressBar(android.widget.ProgressBar) SearchView(android.support.v7.widget.SearchView) ItunesAdapter(de.danoeh.antennapod.adapter.itunes.ItunesAdapter) AndroidSchedulers(rx.android.schedulers.AndroidSchedulers) Intent(android.content.Intent) MenuItem(android.view.MenuItem) ArrayList(java.util.ArrayList) Observable(rx.Observable) JSONException(org.json.JSONException) JSONObject(org.json.JSONObject) MenuItemUtils(de.danoeh.antennapod.menuhandler.MenuItemUtils) MenuInflater(android.view.MenuInflater) Locale(java.util.Locale) Menu(android.view.Menu) Schedulers(rx.schedulers.Schedulers) View(android.view.View) Button(android.widget.Button) Response(okhttp3.Response) AntennapodHttpClient(de.danoeh.antennapod.core.service.download.AntennapodHttpClient) Log(android.util.Log) Request(okhttp3.Request) LayoutInflater(android.view.LayoutInflater) R(de.danoeh.antennapod.R) MenuItemCompat(android.support.v4.view.MenuItemCompat) Fragment(android.support.v4.app.Fragment) ClientConfig(de.danoeh.antennapod.core.ClientConfig) IOException(java.io.IOException) ViewGroup(android.view.ViewGroup) URLEncoder(java.net.URLEncoder) List(java.util.List) TextView(android.widget.TextView) OkHttpClient(okhttp3.OkHttpClient) Podcast(de.danoeh.antennapod.adapter.itunes.ItunesAdapter.Podcast) OnlineFeedViewActivity(de.danoeh.antennapod.activity.OnlineFeedViewActivity) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Subscription(rx.Subscription) JSONArray(org.json.JSONArray) ItunesAdapter(de.danoeh.antennapod.adapter.itunes.ItunesAdapter) OnlineFeedViewActivity(de.danoeh.antennapod.activity.OnlineFeedViewActivity) OkHttpClient(okhttp3.OkHttpClient) ArrayList(java.util.ArrayList) Podcast(de.danoeh.antennapod.adapter.itunes.ItunesAdapter.Podcast) Request(okhttp3.Request) Intent(android.content.Intent) IOException(java.io.IOException) GridView(android.widget.GridView) SearchView(android.support.v7.widget.SearchView) View(android.view.View) TextView(android.widget.TextView) Observable(rx.Observable) Response(okhttp3.Response) JSONObject(org.json.JSONObject)

Example 85 with Adapter

use of android.support.v7.widget.RecyclerView.Adapter in project android_frameworks_base by DirtyUnicorns.

the class FocusManager method findTargetPosition.

/**
     * Finds the destination position where the focus should land for a given navigation event.
     *
     * @param view The view that received the event.
     * @param keyCode The key code for the event.
     * @param event
     * @return The adapter position of the destination item. Could be RecyclerView.NO_POSITION.
     */
private int findTargetPosition(View view, int keyCode, KeyEvent event) {
    switch(keyCode) {
        case KeyEvent.KEYCODE_MOVE_HOME:
            return 0;
        case KeyEvent.KEYCODE_MOVE_END:
            return mAdapter.getItemCount() - 1;
        case KeyEvent.KEYCODE_PAGE_UP:
        case KeyEvent.KEYCODE_PAGE_DOWN:
            return findPagedTargetPosition(view, keyCode, event);
    }
    // Find a navigation target based on the arrow key that the user pressed.
    int searchDir = -1;
    switch(keyCode) {
        case KeyEvent.KEYCODE_DPAD_UP:
            searchDir = View.FOCUS_UP;
            break;
        case KeyEvent.KEYCODE_DPAD_DOWN:
            searchDir = View.FOCUS_DOWN;
            break;
    }
    if (inGridMode()) {
        int currentPosition = mView.getChildAdapterPosition(view);
        // Left and right arrow keys only work in grid mode.
        switch(keyCode) {
            case KeyEvent.KEYCODE_DPAD_LEFT:
                if (currentPosition > 0) {
                    // Stop backward focus search at the first item, otherwise focus will wrap
                    // around to the last visible item.
                    searchDir = View.FOCUS_BACKWARD;
                }
                break;
            case KeyEvent.KEYCODE_DPAD_RIGHT:
                if (currentPosition < mAdapter.getItemCount() - 1) {
                    // Stop forward focus search at the last item, otherwise focus will wrap
                    // around to the first visible item.
                    searchDir = View.FOCUS_FORWARD;
                }
                break;
        }
    }
    if (searchDir != -1) {
        // Focus search behaves badly if the parent RecyclerView is focused. However, focusable
        // shouldn't be unset on RecyclerView, otherwise focus isn't properly restored after
        // events that cause a UI rebuild (like rotating the device). Compromise: turn focusable
        // off while performing the focus search.
        // TODO: Revisit this when RV focus issues are resolved.
        mView.setFocusable(false);
        View targetView = view.focusSearch(searchDir);
        mView.setFocusable(true);
        // of the list.
        if (targetView != null) {
            // Ignore navigation targets that aren't items in the RecyclerView.
            if (targetView.getParent() == mView) {
                return mView.getChildAdapterPosition(targetView);
            }
        }
    }
    return RecyclerView.NO_POSITION;
}
Also used : View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView)

Aggregations

RecyclerView (android.support.v7.widget.RecyclerView)688 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)612 View (android.view.View)593 TextView (android.widget.TextView)245 ArrayList (java.util.ArrayList)179 Intent (android.content.Intent)148 ImageView (android.widget.ImageView)132 Toolbar (android.support.v7.widget.Toolbar)118 GridLayoutManager (android.support.v7.widget.GridLayoutManager)111 AdapterView (android.widget.AdapterView)109 ViewGroup (android.view.ViewGroup)97 AlertDialog (android.support.v7.app.AlertDialog)91 Bundle (android.os.Bundle)85 ListView (android.widget.ListView)85 BindView (butterknife.BindView)85 Nullable (android.support.annotation.Nullable)78 DialogInterface (android.content.DialogInterface)71 Context (android.content.Context)65 ArrayAdapter (android.widget.ArrayAdapter)65 LayoutInflater (android.view.LayoutInflater)64