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();
}
});
}
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);
}
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);
}
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;
}
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;
}
Aggregations