use of android.support.v7.widget.helper.ItemTouchHelper.UP in project Taskzilla by CMPUT301W18T05.
the class ViewTaskActivity method thePinkButton.
/**
*@param view pretty much the page it's on
* @author myapplestory
* thePinkButton
* upon pressing place button on task page
* prompts user to enter in a bid amount
* if valid input, will add bid to task
*
* notes
* can probably add more stuff to dialog
*/
public void thePinkButton(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
task.addBid(new Bid(currentUserId, taskID, incomingBidFloat));
task.setStatus("bidded");
TaskStatus.setText("bidded");
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();
}
});
mBuilder.setView(mView);
mBuilder.show();
}
use of android.support.v7.widget.helper.ItemTouchHelper.UP in project OnlineCanteen by josephgunawan97.
the class UserProductListFragment method onViewCreated.
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
if (currentStore != null)
getActivity().setTitle(currentStore.getStoreName());
// Order Floating Action Button
orderButton = view.findViewById(R.id.order_floating_action_button);
orderButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(getActivity(), UserOrderProductActivity.class);
intent.putExtra(UserOrderProductActivity.CURRENT_STORE_KEY, currentStore);
intent.putExtra(UserOrderProductActivity.PRODUCT_LIST_KEY, userProductItemAdapter.getProducts());
startActivity(intent);
}
});
// Set up recycler view
productRecyclerView = view.findViewById(R.id.product_recycler_view);
layoutManager = new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false);
productRecyclerView.setLayoutManager(layoutManager);
DividerItemDecoration divider = new DividerItemDecoration(getContext(), DividerItemDecoration.VERTICAL);
productRecyclerView.addItemDecoration(divider);
userProductItemAdapter = new UserProductItemAdapter();
productRecyclerView.setAdapter(userProductItemAdapter);
}
use of android.support.v7.widget.helper.ItemTouchHelper.UP in project scroball by peterjosling.
the class MainActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
application = (ScroballApplication) getApplication();
application.startListenerService();
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
// Create the adapter that will return a fragment for each of the three
// primary sections of the activity.
mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
// Set up the ViewPager with the sections adapter.
mViewPager = findViewById(R.id.container);
mViewPager.setAdapter(mSectionsPagerAdapter);
TabLayout tabLayout = findViewById(R.id.tabs);
tabLayout.setupWithViewPager(mViewPager);
// Initial tab may have been specified in the intent.
int initialTab = getIntent().getIntExtra(EXTRA_INITIAL_TAB, TAB_NOW_PLAYING);
mViewPager.setCurrentItem(initialTab);
this.adsRemoved = application.getSharedPreferences().getBoolean(REMOVE_ADS_SKU, false);
adView = findViewById(R.id.adView);
if (this.adsRemoved) {
RelativeLayout parent = (RelativeLayout) adView.getParent();
if (parent != null) {
parent.removeView(adView);
}
} else {
AdRequest adRequest = new AdRequest.Builder().addTestDevice("86193DC9EBC8E1C3873178900C9FCCFC").build();
adView.loadAd(adRequest);
}
}
use of android.support.v7.widget.helper.ItemTouchHelper.UP 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")), JoH.tolerantParseDouble(Pref.getString("profile_insulin_sensitivity_default", "0.1"))));
}
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.UP in project pink-panthers by MrTrai.
the class ListOfSheltersActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout);
// data to populate the RecyclerView with
ArrayList<String> shelterNames = new ArrayList<>();
DBI db = new Db("pinkpanther", "PinkPantherReturns!", "pinkpanther");
shelters = db.getAllShelters();
for (int i = 0; i < shelters.size(); i++) {
shelterNames.add(shelters.get(i).getShelterName());
}
// set up the RecyclerView
RecyclerView recyclerView = findViewById(R.id.rvShelters);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
adapter = new RecyclerAdapter(this, shelterNames);
adapter.setClickListener(this);
recyclerView.setAdapter(adapter);
// set up search button
Button search_button = findViewById(R.id.search_button);
search_button.setOnClickListener(this);
username = getIntent().getExtras().getString("username");
}
Aggregations