use of android.support.v7.widget.helper.ItemTouchHelper.END in project xDrip by NightscoutFoundation.
the class ProfileEditor method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
mContext = this;
doMgdl = (Pref.getString("units", "mgdl").equals("mgdl"));
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_profile_editor);
undoBtn = (Button) findViewById(R.id.profileUndoBtn);
saveBtn = (Button) findViewById(R.id.profileSaveBtn);
adjustallSeekBar = (SeekBar) findViewById(R.id.profileAdjustAllseekBar);
adjustPercentage = (TextView) findViewById(R.id.profileAdjustAllPercentage);
profileItemList.addAll(loadData(true));
// Toolbar toolbar = (Toolbar) findViewById(R.id.profile_toolbar);
// setSupportActionBar(toolbar);
JoH.fixActionBar(this);
// TODO add menu in xml
adjustallSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
adjustmentFactor = 1 + ((progress - 25) * 0.02);
adjustPercentage.setText(JoH.qs(adjustmentFactor * 100, 0) + "%");
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
profileItemList.clear();
// we must preserve the existing object reference used by the adapter
profileItemList.addAll(loadData(false));
// allow autosliding scales downwards
mAdapter.resetTopMax();
// does temporary save
forceRefresh(true);
}
});
recyclerView = (RecyclerView) findViewById(R.id.profile_recycler_view);
mAdapter = new ProfileAdapter(this, profileItemList, doMgdl);
RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getApplicationContext());
recyclerView.setLayoutManager(mLayoutManager);
recyclerView.setItemAnimator(new DefaultItemAnimator());
if (profileItemList.size() == 0) {
profileItemList.add(new ProfileItem(0, END_OF_DAY, JoH.tolerantParseDouble(Pref.getString("profile_carb_ratio_default", "10"), 10d), JoH.tolerantParseDouble(Pref.getString("profile_insulin_sensitivity_default", "0.1"), 0.1d)));
}
updateAdjustmentFactor(1.0);
shuffleFit();
mAdapter.registerAdapterDataObserver(// handle incoming messages from the adapater
new RecyclerView.AdapterDataObserver() {
@Override
public void onChanged() {
super.onChanged();
// Log.d(TAG, "onChanged");
}
@Override
public void onItemRangeChanged(final int positionStart, int itemCount, Object payload) {
super.onItemRangeChanged(positionStart, itemCount, payload);
Log.d(TAG, "onItemRangeChanged: pos:" + positionStart + " cnt:" + itemCount + " p: " + payload.toString());
if (payload.toString().equals("time start updated")) {
if (positionStart > 0) {
// did we encroach on previous item end or open up a gap??
if ((profileItemList.get(positionStart - 1).end_min != profileItemList.get(positionStart).start_min - 1)) {
profileItemList.get(positionStart - 1).end_min = profileItemList.get(positionStart).start_min - 1;
}
} else {
// if setting the first start time also mirror this to the last end time
//
profileItemList.get(profileItemList.size() - 1).end_min = profileItemList.get(positionStart).start_min - 1;
}
forceRefresh();
} else if (payload.toString().equals("time end updated")) {
// don't apply gap calcualtion to last item when end changes
if (positionStart < profileItemList.size() - 1) {
// for all blocks other than the final one
if ((profileItemList.get(positionStart + 1).start_min != profileItemList.get(positionStart).end_min + 1)) {
profileItemList.get(positionStart + 1).start_min = profileItemList.get(positionStart).end_min + 1;
}
} else {
// if setting the last end time also mirror this to the first start time
//
profileItemList.get(0).start_min = profileItemList.get(positionStart).end_min + 1;
}
forceRefresh();
// split or delete
} else if (payload.toString().equals("long-split")) {
final DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
final int screen_width = dm.widthPixels;
final int screen_height = dm.heightPixels;
boolean small_screen = false;
// smaller screens or lower version don't seem to play well with long dialog button names
if ((screen_width < 720) || (screen_height < 720) || ((Build.VERSION.SDK_INT < Build.VERSION_CODES.M)))
small_screen = true;
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(mContext);
alertDialogBuilder.setMessage(R.string.split_delete_or_do_nothing);
alertDialogBuilder.setPositiveButton(small_screen ? getString(R.string.split) : getString(R.string.split_this_block_in_two), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
ProfileItem old_item = profileItemList.get(positionStart);
ProfileItem new_item;
if (old_item.start_min < old_item.end_min) {
// no wrapping time
new_item = new ProfileItem(old_item.end_min - (old_item.end_min - old_item.start_min) / 2, old_item.end_min, old_item.carb_ratio, old_item.sensitivity);
} else {
// wraps around
new_item = new ProfileItem(old_item.end_min - ((old_item.end_min - MINS_PER_DAY) - old_item.start_min) / 2, old_item.end_min, old_item.carb_ratio, old_item.sensitivity);
}
old_item.end_min = new_item.start_min - 1;
profileItemList.add(positionStart + 1, new_item);
forceRefresh();
}
});
if (profileItemList.size() > 1) {
alertDialogBuilder.setNeutralButton(small_screen ? getString(R.string.delete) : getString(R.string.delete_this_time_block), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
profileItemList.remove(positionStart);
forceRefresh();
}
});
}
alertDialogBuilder.setNegativeButton(small_screen ? getString(R.string.cancel) : getString(R.string.cancel_do_nothing), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
AlertDialog alertDialog = alertDialogBuilder.create();
alertDialog.show();
} else {
// for other non special changes
forceRefresh();
}
}
});
DefaultItemAnimator animator = new DefaultItemAnimator() {
@Override
public boolean canReuseUpdatedViewHolder(RecyclerView.ViewHolder viewHolder) {
return true;
}
};
recyclerView.setItemAnimator(animator);
recyclerView.setAdapter(mAdapter);
mAdapter.notifyDataSetChanged();
showcasemenu(SHOWCASE_PROFILE_SPLIT);
}
use of android.support.v7.widget.helper.ItemTouchHelper.END in project seven_develop by seven123456.
the class OverFlyingLayoutManager method layoutItems.
private void layoutItems(RecyclerView.Recycler recycler) {
detachAndScrapAttachedViews(recycler);
// make sure that current position start from 0 to 1
final int currentPos = mReverseLayout ? -getCurrentPositionOffset() : getCurrentPositionOffset();
int start = currentPos - mLeftItems;
int end = currentPos + mRightItems;
// handle max visible count
if (useMaxVisibleCount()) {
boolean isEven = mMaxVisibleItemCount % 2 == 0;
if (isEven) {
int offset = mMaxVisibleItemCount / 2;
start = currentPos - offset + 1;
end = currentPos + offset + 1;
} else {
int offset = (mMaxVisibleItemCount - 1) / 2;
start = currentPos - offset;
end = currentPos + offset + 1;
}
}
final int itemCount = getItemCount();
if (!mInfinite) {
if (start < 0) {
start = 0;
if (useMaxVisibleCount())
end = mMaxVisibleItemCount;
}
if (end > itemCount)
end = itemCount;
}
float lastOrderWeight = Float.MIN_VALUE;
for (int i = start; i < end; i++) {
if (useMaxVisibleCount() || !removeCondition(getProperty(i) - mOffset)) {
// start and end base on current position,
// so we need to calculate the adapter position
int adapterPosition = i;
if (i >= itemCount) {
adapterPosition %= itemCount;
} else if (i < 0) {
int delta = (-adapterPosition) % itemCount;
if (delta == 0)
delta = itemCount;
adapterPosition = itemCount - delta;
}
final View scrap = recycler.getViewForPosition(adapterPosition);
measureChildWithMargins(scrap, 0, 0);
resetViewProperty(scrap);
// we need i to calculate the real offset of current view
final float targetOffset = getProperty(i) - mOffset;
layoutScrap(scrap, targetOffset);
final float orderWeight = mEnableBringCenterToFront ? setViewElevation(scrap, targetOffset) : adapterPosition;
if (orderWeight > lastOrderWeight) {
addView(scrap);
} else {
addView(scrap, 0);
}
lastOrderWeight = orderWeight;
}
}
}
use of android.support.v7.widget.helper.ItemTouchHelper.END in project Taskzilla by CMPUT301W18T05.
the class ViewTaskActivity method theBlueButton.
/**
* @param view pretty much the page it's on
* @author myapplestory
* theBlueButton
* upon pressing place button on task page
* prompts user to enter in a bid amount
* if valid input, will add bid to task
*/
public void theBlueButton(android.view.View view) {
final AlertDialog mBuilder = new AlertDialog.Builder(ViewTaskActivity.this).create();
final View mView = getLayoutInflater().inflate(R.layout.dialog_place_bid, null);
final EditText incomingBidText = mView.findViewById(R.id.place_bid_edittext);
// Taken from https://gist.github.com/gaara87/3607765
// 2018-03-19
// Limits the number of decimals allowed in input
incomingBidText.setFilters(new InputFilter[] { new DigitsKeyListener(Boolean.FALSE, Boolean.TRUE) {
@Override
public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {
StringBuilder builder = new StringBuilder(dest);
builder.insert(dstart, source);
String temp = builder.toString();
if (temp.contains(".")) {
temp = temp.substring(temp.indexOf(".") + 1);
if (temp.length() > 2) {
return "";
}
}
return super.filter(source, start, end, dest, dstart, dend);
}
} });
// bring up keyboard when user taps place bid
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
final Button submitBidButton = mView.findViewById(R.id.submit_bid_button);
submitBidButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Float incomingBidFloat;
try {
incomingBidFloat = Float.parseFloat(incomingBidText.getText().toString());
incomingBidFloat = (float) (Math.round(incomingBidFloat * 100.0) / 100.0);
} catch (Exception exception) {
Toast.makeText(ViewTaskActivity.this, "Please enter in a valid bid amount", Toast.LENGTH_SHORT).show();
return;
}
// do stuff here to actually add bid
if (updateBestBid(incomingBidFloat) == -1) {
return;
} else {
task.addBid(new Bid(currentUserId, taskID, incomingBidFloat));
task.setStatus("bidded");
TaskStatus.setText("Bidded");
}
setProviderField();
Toast.makeText(ViewTaskActivity.this, "Bid placed", Toast.LENGTH_SHORT).show();
// hide keyboard upon pressing button
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(submitBidButton.getWindowToken(), 0);
mBuilder.dismiss();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
updateBidsList();
}
}, 1500);
}
});
mBuilder.setView(mView);
mBuilder.show();
}
use of android.support.v7.widget.helper.ItemTouchHelper.END in project quickstart-android by firebase.
the class PostListFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
View rootView = inflater.inflate(R.layout.fragment_all_posts, container, false);
// [START create_database_reference]
mDatabase = FirebaseDatabase.getInstance().getReference();
// [END create_database_reference]
mRecycler = (RecyclerView) rootView.findViewById(R.id.messages_list);
mRecycler.setHasFixedSize(true);
return rootView;
}
use of android.support.v7.widget.helper.ItemTouchHelper.END in project android-advancedrecyclerview by h6ah4i.
the class CustomRecyclerViewUtils method findOneVisibleChildIncludesPadding.
// This method is a modified version of the LinearLayoutManager.findOneVisibleChild().
private static View findOneVisibleChildIncludesPadding(LinearLayoutManager lm, int fromIndex, int toIndex, boolean completelyVisible, boolean acceptPartiallyVisible) {
boolean isVertical = (lm.getOrientation() == LinearLayoutManager.VERTICAL);
final int start = 0;
final int end = (isVertical) ? lm.getHeight() : lm.getWidth();
final int next = toIndex > fromIndex ? 1 : -1;
View partiallyVisible = null;
for (int i = fromIndex; i != toIndex; i += next) {
final View child = lm.getChildAt(i);
final int childStart = (isVertical) ? child.getTop() : child.getLeft();
final int childEnd = (isVertical) ? child.getBottom() : child.getRight();
if (childStart < end && childEnd > start) {
if (completelyVisible) {
if (childStart >= start && childEnd <= end) {
return child;
} else if (acceptPartiallyVisible && partiallyVisible == null) {
partiallyVisible = child;
}
} else {
return child;
}
}
}
return partiallyVisible;
}
Aggregations