use of android.support.v7.widget.helper.ItemTouchHelper.UP in project SimpleBucketList-material by thevarunshah.
the class BucketItemListView method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.bucket_item_listview);
// fetch toolbar and set it as the action bar
Toolbar toolbar = findViewById(R.id.toolbar);
toolbar.setContentInsetsRelative(72, 72);
setSupportActionBar(toolbar);
// check if tablet view is being used
boolean tablet = (findViewById(R.id.coordLayout_tablet) != null);
// obtain list view and create new bucket list custom adapter
recyclerView = findViewById(R.id.recycler_view);
recyclerAdapter = new BucketItemListAdapter(this, Utility.getBucketList(), tablet, this);
// attach adapter to list view
recyclerView.setAdapter(recyclerAdapter);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
ItemTouchHelper.Callback callback = new SimpleItemTouchHelperCallback(recyclerAdapter);
itemTouchHelper = new ItemTouchHelper(callback);
itemTouchHelper.attachToRecyclerView(recyclerView);
// obtain add button and attach a on-tap listener to it
final FloatingActionButton addButton = findViewById(R.id.add_item);
addButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// inflate layout with customized alert dialog view
LayoutInflater layoutInflater = LayoutInflater.from(BucketItemListView.this);
final View dialog = layoutInflater.inflate(R.layout.input_dialog, null);
final AlertDialog.Builder newItemDialogBuilder = new AlertDialog.Builder(BucketItemListView.this, R.style.AppCompatAlertDialogStyle);
// customize alert dialog and set its view
newItemDialogBuilder.setTitle("New Item");
newItemDialogBuilder.setIcon(R.drawable.ic_launcher);
newItemDialogBuilder.setView(dialog);
// fetch and set up edittext
final EditText input = dialog.findViewById(R.id.input_dialog_text);
input.setHint("Enter Details");
input.setFocusableInTouchMode(true);
input.requestFocus();
// set up actions for dialog buttons
newItemDialogBuilder.setPositiveButton("ADD", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialogInterface, int whichButton) {
// create new item
String itemText = input.getText().toString();
Item item = new Item(itemText);
// add item to main list and update view
Utility.getBucketList().add(item);
recyclerAdapter.notifyDataSetChanged();
// backup data
Utility.writeData(getApplicationContext());
}
});
newItemDialogBuilder.setNegativeButton("CANCEL", null);
// create and show the dialog
AlertDialog newItemDialog = newItemDialogBuilder.create();
newItemDialog.show();
// show keyboard
newItemDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
}
});
// add specific listeners only if tablet is not being used
if (!tablet) {
// moving fab out of the way when scrolling listview
recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
if (dy > 0) {
// scrolling down
addButton.animate().translationY(addButton.getHeight() * 2);
} else {
// scrolling up
addButton.animate().translationY(0);
}
}
});
}
}
use of android.support.v7.widget.helper.ItemTouchHelper.UP in project SimpleBucketList-material by thevarunshah.
the class SettingsFragment method onCreate.
@Override
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.settings);
overlay = getActivity().findViewById(R.id.overlay);
progressBar = getActivity().findViewById(R.id.progress_bar);
Preference restore = findPreference("restore");
restore.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
// inflate layout with customized alert dialog view
LayoutInflater layoutInflater = LayoutInflater.from(getActivity());
final View dialog = layoutInflater.inflate(R.layout.info_dialog, null);
final AlertDialog.Builder infoDialogBuilder = new AlertDialog.Builder(getActivity(), R.style.AppCompatAlertDialogStyle);
// customize alert dialog and set its view
infoDialogBuilder.setTitle("Restore Data");
infoDialogBuilder.setIcon(R.drawable.ic_warning_black_24dp);
infoDialogBuilder.setView(dialog);
// fetch textview and set its text
final TextView message = dialog.findViewById(R.id.info_dialog);
message.setText(R.string.restore_message);
// set up actions for dialog buttons
infoDialogBuilder.setPositiveButton("RESTORE", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int whichButton) {
overlay.setVisibility(View.VISIBLE);
progressBar.setVisibility(View.VISIBLE);
Utility.restoreData(getActivity().getApplicationContext(), new RestoreObserver() {
@Override
public void restoreFinished(int error) {
super.restoreFinished(error);
Snackbar snackbar;
if (error == 0) {
Utility.readData(getActivity().getApplicationContext());
snackbar = Snackbar.make(getActivity().findViewById(R.id.relativeLayout), "Data successfully restored.", Snackbar.LENGTH_SHORT);
} else {
snackbar = Snackbar.make(getActivity().findViewById(R.id.relativeLayout), "Could not restore data - please try again later.", Snackbar.LENGTH_LONG);
}
overlay.setVisibility(View.GONE);
progressBar.setVisibility(View.GONE);
snackbar.show();
}
});
}
});
infoDialogBuilder.setNegativeButton("CANCEL", null);
// create and show the dialog
AlertDialog infoDialog = infoDialogBuilder.create();
infoDialog.show();
return true;
}
});
Preference about = findPreference("about");
about.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
// display app information and prompt them to rate it.
@Override
public boolean onPreferenceClick(Preference preference) {
// inflate layout with customized alert dialog view
LayoutInflater layoutInflater = LayoutInflater.from(getActivity());
final View dialog = layoutInflater.inflate(R.layout.info_dialog, null);
final AlertDialog.Builder infoDialogBuilder = new AlertDialog.Builder(getActivity(), R.style.AppCompatAlertDialogStyle);
// customize alert dialog and set its view
infoDialogBuilder.setTitle("About");
infoDialogBuilder.setIcon(R.drawable.ic_info_black_24dp);
infoDialogBuilder.setView(dialog);
// fetch textview and set its text
final TextView message = dialog.findViewById(R.id.info_dialog);
message.setText(R.string.about_message);
// set up actions for dialog buttons
infoDialogBuilder.setPositiveButton("RATE APP", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int whichButton) {
String appPackageName = getActivity().getApplicationContext().getPackageName();
Intent i = new Intent(Intent.ACTION_VIEW);
try {
i.setData(Uri.parse("market://details?id=" + appPackageName));
startActivity(i);
} catch (ActivityNotFoundException e) {
try {
i.setData(Uri.parse("https://play.google.com/store/apps/details?id=" + appPackageName));
startActivity(i);
} catch (ActivityNotFoundException e2) {
Snackbar errorBar = Snackbar.make(getActivity().findViewById(R.id.relativeLayout), "Could not launch the Google Play app.", Snackbar.LENGTH_SHORT);
errorBar.show();
}
}
}
});
infoDialogBuilder.setNegativeButton("DISMISS", null);
// create and show the dialog
AlertDialog infoDialog = infoDialogBuilder.create();
infoDialog.show();
return true;
}
});
}
use of android.support.v7.widget.helper.ItemTouchHelper.UP in project android-samples by googlemaps.
the class LiteListDemoActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.lite_list_demo);
mGridLayoutManager = new GridLayoutManager(this, 2);
mLinearLayoutManager = new LinearLayoutManager(this);
// Set up the RecyclerView
mRecyclerView = findViewById(R.id.recycler_view);
mRecyclerView.setHasFixedSize(true);
mRecyclerView.setLayoutManager(mLinearLayoutManager);
mRecyclerView.setAdapter(new MapAdapter(LIST_LOCATIONS));
mRecyclerView.setRecyclerListener(mRecycleListener);
}
use of android.support.v7.widget.helper.ItemTouchHelper.UP in project stillStanding by katsik.
the class GraphActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setTheme(R.style.AppTheme);
setContentView(R.layout.activity_graph);
// Get a support ActionBar corresponding to this toolbar
ActionBar ab = getSupportActionBar();
// Enable the Up button
ab.setDisplayHomeAsUpEnabled(true);
sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
GraphView graph = (GraphView) findViewById(R.id.graph);
series = new LineGraphSeries<>();
series.setColor(Color.BLUE);
series.setThickness(10);
graph.addSeries(series);
series.setDrawBackground(true);
// activate horizontal zooming and scrolling
graph.getViewport().setScalable(true);
// activate horizontal scrolling
graph.getViewport().setScrollable(true);
// activate horizontal and vertical zooming and scrolling
graph.getViewport().setScalableY(true);
// activate vertical scrolling
graph.getViewport().setScrollableY(true);
// To set a fixed manual viewport use this:
// set manual X bounds
graph.getViewport().setXAxisBoundsManual(true);
graph.getViewport().setMinX(0.5);
graph.getViewport().setMaxX(6.5);
// set manual Y bounds
graph.getViewport().setYAxisBoundsManual(true);
graph.getViewport().setMinY(0);
graph.getViewport().setMaxY(20);
graph.setTitle(getString(R.string.graph_title));
currentX = 0;
// Start chart thread
liveChartExecutor = (ThreadPoolExecutor) Executors.newFixedThreadPool(1);
if (liveChartExecutor != null)
liveChartExecutor.execute(new AccelerationChart(new AccelerationChartHandler()));
}
use of android.support.v7.widget.helper.ItemTouchHelper.UP in project stillStanding by katsik.
the class IncidentHistory method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
setTheme(R.style.AppTheme);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_history);
// Get a support ActionBar corresponding to this toolbar
ActionBar ab = getSupportActionBar();
// Enable the Up button
ab.setDisplayHomeAsUpEnabled(true);
AppDatabase db = AppDatabase.getInstance(this);
final ArrayList<Incident> incidents = new ArrayList<Incident>();
Collections.addAll(incidents, db.incidentDao().loadAllIncidents());
IncidentAdapter adapter = new IncidentAdapter(this, incidents);
ListView listView = (ListView) findViewById(R.id.history);
listView.setAdapter(adapter);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
long viewId = view.getId();
if (viewId == R.id.incident_location) {
Incident tempIncident = incidents.get(position);
StringBuffer url = new StringBuffer();
url.append("http://maps.google.com?q=");
url.append(String.format("%.7f", tempIncident.getLatitude()));
url.append(",");
url.append(String.format("%.7f", tempIncident.getLongitude()));
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url.toString()));
startActivity(i);
} else if (viewId == R.id.list_item) {
}
}
});
}
Aggregations