Search in sources :

Example 96 with UP

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);
                }
            }
        });
    }
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) EditText(android.widget.EditText) BucketItemListAdapter(com.thevarunshah.simplebucketlist.internal.BucketItemListAdapter) DialogInterface(android.content.DialogInterface) SimpleItemTouchHelperCallback(com.thevarunshah.simplebucketlist.internal.SimpleItemTouchHelperCallback) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) ItemTouchHelper(android.support.v7.widget.helper.ItemTouchHelper) MenuItem(android.view.MenuItem) Item(com.thevarunshah.classes.Item) LayoutInflater(android.view.LayoutInflater) FloatingActionButton(android.support.design.widget.FloatingActionButton) OnClickListener(android.view.View.OnClickListener) RecyclerView(android.support.v7.widget.RecyclerView) Toolbar(android.support.v7.widget.Toolbar)

Example 97 with UP

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;
        }
    });
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) DialogInterface(android.content.DialogInterface) RestoreObserver(android.app.backup.RestoreObserver) Intent(android.content.Intent) TextView(android.widget.TextView) View(android.view.View) Preference(android.preference.Preference) ActivityNotFoundException(android.content.ActivityNotFoundException) LayoutInflater(android.view.LayoutInflater) TextView(android.widget.TextView) Snackbar(android.support.design.widget.Snackbar)

Example 98 with UP

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);
}
Also used : GridLayoutManager(android.support.v7.widget.GridLayoutManager) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager)

Example 99 with UP

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()));
}
Also used : GraphView(com.jjoe64.graphview.GraphView) ActionBar(android.support.v7.app.ActionBar)

Example 100 with UP

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) {
            }
        }
    });
}
Also used : ArrayList(java.util.ArrayList) Intent(android.content.Intent) View(android.view.View) AdapterView(android.widget.AdapterView) ListView(android.widget.ListView) ListView(android.widget.ListView) AppDatabase(com.sleepycookie.stillstanding.data.AppDatabase) AdapterView(android.widget.AdapterView) Incident(com.sleepycookie.stillstanding.data.Incident) ActionBar(android.support.v7.app.ActionBar)

Aggregations

View (android.view.View)135 RecyclerView (android.support.v7.widget.RecyclerView)97 TextView (android.widget.TextView)69 Toolbar (android.support.v7.widget.Toolbar)51 ActionBar (android.support.v7.app.ActionBar)49 Intent (android.content.Intent)44 ImageView (android.widget.ImageView)41 AdapterView (android.widget.AdapterView)33 ArrayList (java.util.ArrayList)30 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)29 DialogInterface (android.content.DialogInterface)25 AlertDialog (android.support.v7.app.AlertDialog)25 ListView (android.widget.ListView)25 Bundle (android.os.Bundle)22 ActionBarDrawerToggle (android.support.v7.app.ActionBarDrawerToggle)22 SharedPreferences (android.content.SharedPreferences)21 Preference (android.support.v7.preference.Preference)20 GridLayoutManager (android.support.v7.widget.GridLayoutManager)19 SuppressLint (android.annotation.SuppressLint)16 Point (android.graphics.Point)16