use of android.support.v7.widget.LinearLayoutManager.HORIZONTAL in project android-advancedrecyclerview by h6ah4i.
the class RecyclerViewSwipeManager method adaptAmount.
/*package*/
static float adaptAmount(SwipeableItemViewHolder holder, boolean horizontal, float srcAmount, boolean isSrcProportional, boolean isDestProportional) {
float destAmount = srcAmount;
if ((isSrcProportional ^ isDestProportional) && (srcAmount != 0.0f) && !isSpecialSwipeAmountValue(srcAmount)) {
View v = SwipeableViewHolderUtils.getSwipeableContainerView(holder);
float d = (horizontal) ? v.getWidth() : v.getHeight();
if (isDestProportional) {
d = (d != 0) ? (1 / d) : 0;
}
destAmount *= d;
}
return destAmount;
}
use of android.support.v7.widget.LinearLayoutManager.HORIZONTAL in project WordPress-Android by wordpress-mobile.
the class ReaderPostListFragment method setupRecyclerToolbar.
/*
* adds a menu to the recycler's toolbar containing settings & search items - only called
* for followed tags
*/
private void setupRecyclerToolbar() {
Menu menu = mRecyclerView.addToolbarMenu(R.menu.reader_list);
mSettingsMenuItem = menu.findItem(R.id.menu_reader_settings);
mSearchMenuItem = menu.findItem(R.id.menu_reader_search);
mSettingsMenuItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
ReaderActivityLauncher.showReaderSubs(getActivity());
return true;
}
});
mSearchView = (SearchView) mSearchMenuItem.getActionView();
mSearchView.setQueryHint(getString(R.string.reader_hint_post_search));
mSearchView.setSubmitButtonEnabled(false);
mSearchView.setIconifiedByDefault(true);
mSearchView.setIconified(true);
// force the search view to take up as much horizontal space as possible (without this
// it looks truncated on landscape)
int maxWidth = DisplayUtils.getDisplayPixelWidth(getActivity());
mSearchView.setMaxWidth(maxWidth);
// this is hacky, but we want to change the SearchView's autocomplete to show suggestions
// after a single character is typed, and there's no less hacky way to do this...
View view = mSearchView.findViewById(android.support.v7.appcompat.R.id.search_src_text);
if (view instanceof AutoCompleteTextView) {
((AutoCompleteTextView) view).setThreshold(1);
}
MenuItemCompat.setOnActionExpandListener(mSearchMenuItem, new MenuItemCompat.OnActionExpandListener() {
@Override
public boolean onMenuItemActionExpand(MenuItem item) {
if (getPostListType() != ReaderPostListType.SEARCH_RESULTS) {
AnalyticsTracker.track(AnalyticsTracker.Stat.READER_SEARCH_LOADED);
}
resetPostAdapter(ReaderPostListType.SEARCH_RESULTS);
showSearchMessage();
mSettingsMenuItem.setVisible(false);
return true;
}
@Override
public boolean onMenuItemActionCollapse(MenuItem item) {
hideSearchMessage();
resetSearchSuggestionAdapter();
mSettingsMenuItem.setVisible(true);
mCurrentSearchQuery = null;
// return to the followed tag that was showing prior to searching
resetPostAdapter(ReaderPostListType.TAG_FOLLOWED);
return true;
}
});
mSearchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
submitSearchQuery(query);
return true;
}
@Override
public boolean onQueryTextChange(String newText) {
if (TextUtils.isEmpty(newText)) {
showSearchMessage();
} else {
populateSearchSuggestionAdapter(newText);
}
return true;
}
});
}
use of android.support.v7.widget.LinearLayoutManager.HORIZONTAL in project HumaneApp by Ganesh1010.
the class DonorNeedViewAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
System.out.println("position : " + position);
Log.d(TAG, "onBindViewHolder: Start @Need " + (position + 1));
if (holder instanceof ViewHolder) {
NeedDetails need = needDetails.get(position);
((ViewHolder) holder).donorNeedView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(context, "Org Details Page will be opened", Toast.LENGTH_SHORT).show();
context.startActivity(new Intent(context, OrgDetailsActivity.class));
}
});
((ViewHolder) holder).orgName.setText(need.org.org_name);
((ViewHolder) holder).orgAddress.setText(need.org.getAddress());
((ViewHolder) holder).orgContactNo.setText(need.org.getPhone());
((ViewHolder) holder).orgLogo.setImageResource(R.drawable.ngo);
// 2500ms = 2,5s
int animationDuration = 1000;
int totalQuantity = 0;
int totalDonatedReceived = 0;
for (int i = 0; i < need.getItems().size(); i++) {
totalQuantity += need.getItems().get(i).getQuantity();
totalDonatedReceived += need.getItems().get(i).getDonated_and_received_amount();
}
System.out.println("quantity:" + totalQuantity);
System.out.println("total donated " + totalDonatedReceived);
if (totalQuantity != 0 || totalDonatedReceived != 0) {
((ViewHolder) holder).overallSatisfiedBar.setProgressWithAnimation(totalDonatedReceived * 100 / totalQuantity, animationDuration);
((ViewHolder) holder).percentage.setText(totalDonatedReceived * 100 / totalQuantity + "%");
} else {
((ViewHolder) holder).overallSatisfiedBar.setProgressWithAnimation(50, animationDuration);
((ViewHolder) holder).percentage.setText(50 + "%");
}
//Glide.with(context).load(needDetails.orgLogo).into(((ViewHolder)holder).orgLogo);
((ViewHolder) holder).needItems.removeAllViews();
View itemView = null;
for (int i = 0; i < need.items.size(); i++) {
NeedItemDetails itemDetails = need.items.get(i);
itemView = LayoutInflater.from(context).inflate(R.layout.layout_item_view, null);
itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(context, "Org Details Page will be opened", Toast.LENGTH_SHORT).show();
context.startActivity(new Intent(context, OrgDetailsActivity.class));
}
});
ImageView itemIcon = (ImageView) itemView.findViewById(R.id.item_image_item_view);
TextView itemName = (TextView) itemView.findViewById(R.id.item_name_item_view);
ProgressBar satisfactionBar = (ProgressBar) itemView.findViewById(R.id.item_status_item_view);
switch(itemDetails.getItem_type_id()) {
case 1:
itemIcon.setImageResource(R.drawable.ic_food_black);
//Glide.with(context).load(itemDetails.itemIcon).into(itemIcon);
itemName.setText("Food");
satisfactionBar.setProgress(need.getItems().get(i).getDonated_and_received_amount());
break;
case 2:
itemIcon.setImageResource(R.drawable.ic_cloth_black);
//Glide.with(context).load(itemDetails.itemIcon).into(itemIcon);
itemName.setText("Cloth");
satisfactionBar.setProgress(need.getItems().get(i).getDonated_and_received_amount());
break;
case 3:
itemIcon.setImageResource(R.drawable.ic_blood_black);
//Glide.with(context).load(itemDetails.itemIcon).into(itemIcon);
itemName.setText("Blood");
satisfactionBar.setProgress(need.getItems().get(i).getDonated_and_received_amount());
break;
case 4:
itemIcon.setImageResource(R.drawable.ic_grocery_cart_black);
//Glide.with(context).load(itemDetails.itemIcon).into(itemIcon);
itemName.setText("Groceries");
satisfactionBar.setProgress(need.getItems().get(i).getDonated_and_received_amount());
break;
case 5:
itemIcon.setImageResource(R.drawable.ic_stationery_black);
//Glide.with(context).load(itemDetails.itemIcon).into(itemIcon);
itemName.setText("Stationeries");
satisfactionBar.setProgress(40);
break;
default:
itemIcon.setImageResource(R.drawable.ic_stationery_black);
//Glide.with(context).load(itemDetails.itemIcon).into(itemIcon);
itemName.setText("Others");
satisfactionBar.setProgress(need.getItems().get(i).getDonated_and_received_amount());
break;
}
// Adding the item to the items layout(Horizontal Scolling Linear Layout)
((ViewHolder) holder).needItems.addView(itemView);
Log.d("Child count+ position", ((ViewHolder) holder).needItems.getChildCount() + "");
Log.d(TAG, "onBindViewHolder: " + (i + 1) + " item(s) added");
}
Log.d(TAG, "onBindViewHolder: End");
} else {
((ProgressViewHolder) holder).progressBar.setIndeterminate(true);
}
}
use of android.support.v7.widget.LinearLayoutManager.HORIZONTAL in project AntennaPod by AntennaPod.
the class CustomMRControllerDialog method onCreateMediaControlView.
@Override
public View onCreateMediaControlView(Bundle savedInstanceState) {
boolean landscape = getContext().getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE;
if (landscape) {
/*
* When a horizontal LinearLayout measures itself, it first measures its children and
* settles their widths on the first pass, and only then figures out its height, never
* revisiting the widths measurements.
* When one has a child view that imposes a certain aspect ratio (such as an ImageView),
* then its width and height are related to each other, and so if one allows for a large
* height, then it will request for itself a large width as well. However, on the first
* child measurement, the LinearLayout imposes a very relaxed height bound, that the
* child uses to tell the width it wants, a value which the LinearLayout will interpret
* as final, even though the child will want to change it once a more restrictive height
* bound is imposed later.
*
* Our solution is, given that the heights of the children do not depend on their widths
* in this case, we first figure out the layout's height and only then perform the
* usual sequence of measurements.
*
* Note: this solution does not take into account any vertical paddings nor children's
* vertical margins in determining the height, as this View as well as its children are
* defined in code and no paddings/margins that would influence these computations are
* introduced.
*
* There were no resources online for this type of issue as far as I could gather.
*/
rootView = new LinearLayout(getContext()) {
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
// We'd like to find the overall height before adjusting the widths within the LinearLayout
int maxHeight = Integer.MIN_VALUE;
if (MeasureSpec.getMode(heightMeasureSpec) != MeasureSpec.EXACTLY) {
for (int i = 0; i < getChildCount(); i++) {
int height = Integer.MIN_VALUE;
View child = getChildAt(i);
ViewGroup.LayoutParams lp = child.getLayoutParams();
// we only measure children whose layout_height is not MATCH_PARENT
if (lp.height >= 0) {
height = lp.height;
} else if (lp.height == ViewGroup.LayoutParams.WRAP_CONTENT) {
child.measure(widthMeasureSpec, heightMeasureSpec);
height = child.getMeasuredHeight();
}
maxHeight = Math.max(maxHeight, height);
}
}
if (maxHeight > 0) {
super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(maxHeight, MeasureSpec.EXACTLY));
} else {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
}
};
rootView.setOrientation(LinearLayout.HORIZONTAL);
} else {
rootView = new LinearLayout(getContext());
rootView.setOrientation(LinearLayout.VERTICAL);
}
FrameLayout.LayoutParams rootParams = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
rootParams.setMargins(0, 0, 0, getContext().getResources().getDimensionPixelSize(R.dimen.media_router_controller_bottom_margin));
rootView.setLayoutParams(rootParams);
// Start the session activity when a content item (album art, title or subtitle) is clicked.
View.OnClickListener onClickListener = v -> {
if (mediaController != null) {
PendingIntent pi = mediaController.getSessionActivity();
if (pi != null) {
try {
pi.send();
dismiss();
} catch (PendingIntent.CanceledException e) {
Log.e(TAG, pi + " was not sent, it had been canceled.");
}
}
}
};
LinearLayout.LayoutParams artParams;
/*
* On portrait orientation, we want to limit the artView's height to 9/16 of the available
* width. Reason is that we need to choose the height wisely otherwise we risk the dialog
* being much larger than the screen, and there doesn't seem to be a good way to know the
* available height beforehand.
*
* On landscape orientation, we want to limit the artView's width to its available height.
* Otherwise, horizontal images would take too much space and severely restrict the space
* for episode title and play/pause button.
*
* Internal implementation of ImageView only uses the source image's aspect ratio, but we
* want to impose our own and fallback to the source image's when it is more favorable.
* Solutions were inspired, among other similar sources, on
* http://stackoverflow.com/questions/18077325/scale-image-to-fill-imageview-width-and-keep-aspect-ratio
*/
if (landscape) {
artView = new ImageView(getContext()) {
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int desiredWidth = widthMeasureSpec;
int desiredMeasureMode = MeasureSpec.getMode(heightMeasureSpec) == MeasureSpec.EXACTLY ? MeasureSpec.EXACTLY : MeasureSpec.AT_MOST;
if (MeasureSpec.getMode(widthMeasureSpec) != MeasureSpec.EXACTLY) {
Drawable drawable = getDrawable();
if (drawable != null) {
int intrHeight = drawable.getIntrinsicHeight();
int intrWidth = drawable.getIntrinsicWidth();
int originalHeight = MeasureSpec.getSize(heightMeasureSpec);
if (intrHeight < intrWidth) {
desiredWidth = MeasureSpec.makeMeasureSpec(originalHeight, desiredMeasureMode);
} else {
desiredWidth = MeasureSpec.makeMeasureSpec(Math.round((float) originalHeight * intrWidth / intrHeight), desiredMeasureMode);
}
}
}
super.onMeasure(desiredWidth, heightMeasureSpec);
}
};
artParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT);
MarginLayoutParamsCompat.setMarginStart(artParams, getContext().getResources().getDimensionPixelSize(R.dimen.media_router_controller_playback_control_horizontal_spacing));
} else {
artView = new ImageView(getContext()) {
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int desiredHeight = heightMeasureSpec;
if (MeasureSpec.getMode(heightMeasureSpec) != MeasureSpec.EXACTLY) {
Drawable drawable = getDrawable();
if (drawable != null) {
int originalWidth = MeasureSpec.getSize(widthMeasureSpec);
int intrHeight = drawable.getIntrinsicHeight();
int intrWidth = drawable.getIntrinsicWidth();
float scale;
if (intrHeight * 16 > intrWidth * 9) {
// image is taller than 16:9
scale = (float) originalWidth * 9 / 16 / intrHeight;
} else {
// image is more horizontal than 16:9
scale = (float) originalWidth / intrWidth;
}
desiredHeight = MeasureSpec.makeMeasureSpec(Math.round(intrHeight * scale), MeasureSpec.EXACTLY);
}
}
super.onMeasure(widthMeasureSpec, desiredHeight);
}
};
artParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
}
// When we fetch the bitmap, we want to know if we should set a background color or not.
artView.setTag(landscape);
artView.setScaleType(ImageView.ScaleType.FIT_CENTER);
artView.setOnClickListener(onClickListener);
artView.setLayoutParams(artParams);
rootView.addView(artView);
ViewGroup wrapper = rootView;
if (landscape) {
// Here we wrap with a frame layout because we want to set different layout parameters
// for landscape orientation.
wrapper = new FrameLayout(getContext());
wrapper.setLayoutParams(new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.WRAP_CONTENT, 1f));
rootView.addView(wrapper);
rootView.setWeightSum(1f);
}
View playbackControlLayout = View.inflate(getContext(), R.layout.media_router_controller, wrapper);
titleView = (TextView) playbackControlLayout.findViewById(R.id.mrc_control_title);
subtitleView = (TextView) playbackControlLayout.findViewById(R.id.mrc_control_subtitle);
playbackControlLayout.findViewById(R.id.mrc_control_title_container).setOnClickListener(onClickListener);
playPauseButton = (ImageButton) playbackControlLayout.findViewById(R.id.mrc_control_play_pause);
playPauseButton.setOnClickListener(v -> {
PlaybackStateCompat state;
if (mediaController != null && (state = mediaController.getPlaybackState()) != null) {
boolean isPlaying = state.getState() == PlaybackStateCompat.STATE_PLAYING;
if (isPlaying) {
mediaController.getTransportControls().pause();
} else {
mediaController.getTransportControls().play();
}
AccessibilityManager accessibilityManager = (AccessibilityManager) getContext().getSystemService(Context.ACCESSIBILITY_SERVICE);
if (accessibilityManager != null && accessibilityManager.isEnabled()) {
AccessibilityEvent event = AccessibilityEvent.obtain(AccessibilityEventCompat.TYPE_ANNOUNCEMENT);
event.setPackageName(getContext().getPackageName());
event.setClassName(getClass().getName());
int resId = isPlaying ? android.support.v7.mediarouter.R.string.mr_controller_pause : android.support.v7.mediarouter.R.string.mr_controller_play;
event.getText().add(getContext().getString(resId));
accessibilityManager.sendAccessibilityEvent(event);
}
}
});
viewsCreated = true;
updateViews();
return rootView;
}
use of android.support.v7.widget.LinearLayoutManager.HORIZONTAL in project devbricks by dailystudio.
the class DividerItemDecoration method onDrawOver.
@Override
public void onDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state) {
if (mDivider == null) {
super.onDrawOver(c, parent, state);
return;
}
if (getOrientation(parent) == LinearLayoutManager.VERTICAL) {
final int left = parent.getPaddingLeft();
final int right = parent.getWidth() - parent.getPaddingRight();
final int childCount = parent.getChildCount();
for (int i = 1; i < childCount; i++) {
final View child = parent.getChildAt(i);
final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
final int size = mDivider.getIntrinsicHeight();
final int top = child.getTop() - params.topMargin;
final int bottom = top + size;
mDivider.setBounds(left, top, right, bottom);
mDivider.draw(c);
}
} else {
// horizontal
final int top = parent.getPaddingTop();
final int bottom = parent.getHeight() - parent.getPaddingBottom();
final int childCount = parent.getChildCount();
for (int i = 1; i < childCount; i++) {
final View child = parent.getChildAt(i);
final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
final int size = mDivider.getIntrinsicWidth();
final int left = child.getLeft() - params.leftMargin;
final int right = left + size;
mDivider.setBounds(left, top, right, bottom);
mDivider.draw(c);
}
}
}
Aggregations