use of android.support.v7.widget.RecyclerView.LayoutManager in project greedo-layout-for-android by 500px.
the class SampleActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sample);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
getWindow().setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS, WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
}
PhotosAdapter photosAdapter = new PhotosAdapter(this);
final GreedoLayoutManager layoutManager = new GreedoLayoutManager(photosAdapter);
layoutManager.setMaxRowHeight(MeasUtils.dpToPx(150, this));
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
recyclerView.setLayoutManager(layoutManager);
recyclerView.setAdapter(photosAdapter);
int spacing = MeasUtils.dpToPx(4, this);
recyclerView.addItemDecoration(new GreedoSpacingItemDecoration(spacing));
findViewById(R.id.toggle_fixed_height).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
layoutManager.setFixedHeight(((ToggleButton) view).isChecked());
layoutManager.requestLayout();
}
});
}
use of android.support.v7.widget.RecyclerView.LayoutManager in project weex-example by KalicyZhou.
the class BasicListComponent method onBeforeScroll.
@Override
public void onBeforeScroll(int dx, int dy) {
T bounceRecyclerView = getHostView();
if (mStickyMap == null || bounceRecyclerView == null) {
return;
}
HashMap<String, WXComponent> stickyMap = mStickyMap.get(getRef());
if (stickyMap == null) {
return;
}
Iterator<Map.Entry<String, WXComponent>> iterator = stickyMap.entrySet().iterator();
Map.Entry<String, WXComponent> entry;
WXComponent stickyComponent;
while (iterator.hasNext()) {
entry = iterator.next();
stickyComponent = entry.getValue();
if (stickyComponent != null && stickyComponent.getDomObject() != null && stickyComponent instanceof WXCell) {
WXCell cell = (WXCell) stickyComponent;
if (cell.getHostView() == null) {
return;
}
if (stickyComponent != null && stickyComponent.getDomObject() != null && stickyComponent instanceof WXCell) {
if (stickyComponent.getHostView() == null) {
return;
}
RecyclerView.LayoutManager layoutManager;
boolean beforeFirstVisibleItem = false;
if ((layoutManager = getHostView().getInnerView().getLayoutManager()) instanceof LinearLayoutManager) {
int fVisible = ((LinearLayoutManager) layoutManager).findFirstVisibleItemPosition();
int pos = mChildren.indexOf(cell);
if (pos <= fVisible) {
beforeFirstVisibleItem = true;
}
}
int[] location = new int[2];
stickyComponent.getHostView().getLocationOnScreen(location);
int[] parentLocation = new int[2];
stickyComponent.getParentScroller().getView().getLocationOnScreen(parentLocation);
int top = location[1] - parentLocation[1];
boolean showSticky = beforeFirstVisibleItem && cell.getLocationFromStart() >= 0 && top <= 0 && dy >= 0;
boolean removeSticky = cell.getLocationFromStart() <= 0 && top > 0 && dy <= 0;
if (showSticky) {
bounceRecyclerView.notifyStickyShow(cell);
} else if (removeSticky) {
bounceRecyclerView.notifyStickyRemove(cell);
}
cell.setLocationFromStart(top);
}
}
}
}
use of android.support.v7.widget.RecyclerView.LayoutManager in project 2017-01-HUDI-MAC-CHAR by NHNNEXT.
the class RoomListActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_room_list);
mafiaRemoteService = ServiceGenerator.createService(MafiaRemoteService.class, context);
user = (User) getIntent().getSerializableExtra("user");
roomCreate = (Button) findViewById(R.id.create_room);
logout = (Button) findViewById(R.id.logout);
nickNameText = (TextView) findViewById(R.id.userName);
roomCreate.setOnClickListener(this);
logout.setOnClickListener(this);
nickNameText.setText(user.getNickName());
roomListView = (RecyclerView) findViewById(R.id.room_list);
LinearLayoutManager layoutManager = new LinearLayoutManager(context);
layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
RoomAdapter roomAdapter = new RoomAdapter(context, rooms, user, R.layout.item_room);
roomListView.setLayoutManager(layoutManager);
roomListView.setItemAnimator(new DefaultItemAnimator());
roomListView.setAdapter(roomAdapter);
roomUpdateTask = new RoomUpdateTask(handler);
timer = new Timer();
timer.schedule(roomUpdateTask, 0, 500);
}
use of android.support.v7.widget.RecyclerView.LayoutManager in project Space-Station-Tracker by Kiarasht.
the class Locations method onCreate.
/**
* Assign simple widgets while also use the Google API to get user's location.
*
* @param savedInstanceState on create method
*/
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.locations_layout);
mActivity = this;
LinearLayoutManager layoutManager = new LinearLayoutManager(mActivity, LinearLayoutManager.VERTICAL, false);
mRecyclerView = (ObservableRecyclerView) findViewById(R.id.recycler);
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
// Show an ad, or hide it if its disabled
if (!sharedPreferences.getBoolean("advertisement", false)) {
adView = (AdView) findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().addTestDevice(getString(R.string.test_device)).build();
if (adView != null) {
adView.loadAd(adRequest);
adView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
if (!mPaddingOnce) {
mPaddingOnce = true;
mRecyclerView.setPadding(mRecyclerView.getPaddingLeft(), mRecyclerView.getPaddingTop(), mRecyclerView.getPaddingRight(), mRecyclerView.getPaddingBottom() + adView.getHeight());
}
}
});
}
} else {
findViewById(R.id.adView).setVisibility(View.GONE);
}
mFlexibleSpaceImageHeight = getResources().getDimensionPixelSize(R.dimen.flexible_space_image_height);
mActionBarSize = getActionBarSize();
mImageView = (ImageView) findViewById(R.id.image);
mOverlayView = findViewById(R.id.overlay);
mTitleView = (TextView) findViewById(R.id.title);
mTitleView.setText(getTitle());
setTitle(null);
mRecyclerView.setScrollViewCallbacks(this);
mRecyclerView.setLayoutManager(layoutManager);
mRecyclerView.setHasFixedSize(true);
mRecyclerView.setNestedScrollingEnabled(true);
// mRecyclerViewBackground makes RecyclerView's background except header view.
mRecyclerViewBackground = findViewById(R.id.list_background);
//since you cannot programmatically add a header view to a RecyclerView we added an empty view as the header
// in the adapter and then are shifting the views OnCreateView to compensate
final float scale = 1 + MAX_TEXT_SCALE_DELTA;
mRecyclerViewBackground.post(new Runnable() {
@Override
public void run() {
ViewHelper.setTranslationY(mRecyclerViewBackground, mFlexibleSpaceImageHeight);
}
});
ViewHelper.setTranslationY(mOverlayView, mFlexibleSpaceImageHeight);
mTitleView.post(new Runnable() {
@Override
public void run() {
ViewHelper.setTranslationY(mTitleView, (int) (mFlexibleSpaceImageHeight - mTitleView.getHeight() * scale));
ViewHelper.setPivotX(mTitleView, 0);
ViewHelper.setPivotY(mTitleView, 0);
ViewHelper.setScaleX(mTitleView, scale);
ViewHelper.setScaleY(mTitleView, scale);
}
});
requestQueue = Volley.newRequestQueue(this);
Connected();
}
use of android.support.v7.widget.RecyclerView.LayoutManager in project Space-Station-Tracker by Kiarasht.
the class PeopleinSpace method display_people.
/**
* Displays a list of astronauts in a RecyclerView
*/
private void display_people() {
final String url = "http://www.howmanypeopleareinspacerightnow.com/peopleinspace.json";
final List<Astronaut> peopleInSpace = new ArrayList<>();
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.GET, url, null, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try {
LinearLayoutManager layoutManager = new LinearLayoutManager(mActivity, LinearLayoutManager.VERTICAL, false);
mRecyclerView.setLayoutManager(layoutManager);
mAdapter = new PeopleInSpaceAdapter(mActivity, peopleInSpace);
mRecyclerView.setHasFixedSize(true);
mRecyclerView.setNestedScrollingEnabled(true);
mAdapter.setDataSet(peopleInSpace);
mRecyclerView.setAdapter(mAdapter);
} catch (Exception e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError e) {
}
}) {
@Override
protected Response<JSONObject> parseNetworkResponse(NetworkResponse response) {
try {
String jsonString = new String(response.data, HttpHeaderParser.parseCharset(response.headers, PROTOCOL_CHARSET));
JSONObject jsonResponse = new JSONObject(jsonString);
try {
JSONArray astronauts = jsonResponse.getJSONArray("people");
for (int i = 0; i < astronauts.length(); ++i) {
JSONObject anAstronaut = astronauts.getJSONObject(i);
final String name = anAstronaut.getString("name");
final String image = anAstronaut.getString("biophoto");
final String countryLink = anAstronaut.getString("countryflag");
final String launchDate = anAstronaut.getString("launchdate");
String role = anAstronaut.getString("title");
final String location = anAstronaut.getString("location");
final String bio = anAstronaut.getString("bio");
final String wiki = anAstronaut.getString("biolink");
final String twitter = anAstronaut.getString("twitter");
if (role != null && !role.isEmpty())
role = role.substring(0, 1).toUpperCase() + role.substring(1);
Astronaut storeAnAstronaut = new Astronaut(name, image, countryLink, launchDate, role, location, bio, wiki, twitter);
peopleInSpace.add(storeAnAstronaut);
}
Collections.sort(peopleInSpace);
} catch (Exception e) {
e.printStackTrace();
}
return Response.success(new JSONObject(jsonString), HttpHeaderParser.parseCacheHeaders(response));
} catch (UnsupportedEncodingException e) {
return Response.error(new ParseError(e));
} catch (JSONException je) {
return Response.error(new ParseError(je));
}
}
};
mRequestQueue.add(jsonObjectRequest);
}
Aggregations