Android Open Source - SmartCocktailShaker Drink List






From Project

Back to project page SmartCocktailShaker.

License

The source code is released under:

MIT License

If you think the Android project SmartCocktailShaker listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.tonydicola.smartshaker.activities;
//from   w  ww  . ja v  a  2 s. co  m
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;

import com.tonydicola.smartshaker.BluetoothSppProvider;
import com.tonydicola.smartshaker.JsonDrinkProvider;
import com.tonydicola.smartshaker.MockConnectionProvider;
import com.tonydicola.smartshaker.R;
import com.tonydicola.smartshaker.UsbSerialProvider;
import com.tonydicola.smartshaker.factories.ConnectionFactory;
import com.tonydicola.smartshaker.factories.DrinkFactory;
import com.tonydicola.smartshaker.interfaces.DrinkProvider;

import java.util.ArrayList;

import butterknife.ButterKnife;
import butterknife.InjectView;

public class DrinkList extends Activity {

    @InjectView(R.id.drink_listview)
    public ListView drinkListView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // Load layout.
        setContentView(R.layout.activity_drink_list);

        // Inject members.
        ButterKnife.inject(this);

        // Load drink JSON data.
        DrinkFactory.INSTANCE.setProvider(JsonDrinkProvider.loadFromResource(getApplicationContext(), R.raw.drinks));
        DrinkProvider drinks = DrinkFactory.INSTANCE.getProvider();

        // Set connection providers.
        ConnectionFactory.INSTANCE.addSource(new UsbSerialProvider(getApplicationContext()));
        ConnectionFactory.INSTANCE.addSource(new BluetoothSppProvider());

        // Mock connection provider is good for testing.
        //ConnectionFactory.INSTANCE.addSource(new MockConnectionProvider());

        // Populate list with drink names.
        if (drinks != null) {
            drinkListView.setAdapter(
                new ArrayAdapter<String>(
                    this,
                    //android.R.layout.simple_list_item_1,
                    R.layout.drink_list_item,
                    new ArrayList<String>(drinks.getDrinkNames())
                )
            );
        }

        // Set list item click handler.
        drinkListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            public void onItemClick(AdapterView<?> parent,
                                    View view,
                                    int position,
                                    long id) {
                switchDrinkDetails(((TextView) view).getText());
            }
        });
    }

    private void switchDrinkDetails(CharSequence drinkName) {
        Intent intent = new Intent(this, DrinkDetails.class);
        intent.putExtra(DrinkDetails.DRINK_NAME, drinkName);
        startActivity(intent);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.drink_list, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        return super.onOptionsItemSelected(item);
    }

}




Java Source Code List

com.hoho.android.usbserial.driver.CdcAcmSerialDriver.java
com.hoho.android.usbserial.driver.CommonUsbSerialDriver.java
com.hoho.android.usbserial.driver.Cp2102SerialDriver.java
com.hoho.android.usbserial.driver.FtdiSerialDriver.java
com.hoho.android.usbserial.driver.ProlificSerialDriver.java
com.hoho.android.usbserial.driver.UsbId.java
com.hoho.android.usbserial.driver.UsbSerialDriver.java
com.hoho.android.usbserial.driver.UsbSerialProber.java
com.hoho.android.usbserial.driver.UsbSerialRuntimeException.java
com.hoho.android.usbserial.util.HexDump.java
com.hoho.android.usbserial.util.SerialInputOutputManager.java
com.hoho.android.usbserial.util.UsbSerialInputStream.java
com.hoho.android.usbserial.util.UsbSerialOutputStream.java
com.tonydicola.smartshaker.BluetoothSppProvider.java
com.tonydicola.smartshaker.JsonDrinkProvider.java
com.tonydicola.smartshaker.MockConnectionProvider.java
com.tonydicola.smartshaker.PrepareDrinkModel.java
com.tonydicola.smartshaker.StepListAdapter.java
com.tonydicola.smartshaker.UsbSerialProvider.java
com.tonydicola.smartshaker.activities.ChooseConnection.java
com.tonydicola.smartshaker.activities.DrinkDetails.java
com.tonydicola.smartshaker.activities.DrinkList.java
com.tonydicola.smartshaker.activities.PrepareDrink.java
com.tonydicola.smartshaker.factories.ConnectionFactory.java
com.tonydicola.smartshaker.factories.DrinkFactory.java
com.tonydicola.smartshaker.interfaces.ConnectionProvider.java
com.tonydicola.smartshaker.interfaces.DeviceConnection.java
com.tonydicola.smartshaker.interfaces.DrinkProvider.java
com.tonydicola.smartshaker.interfaces.Drink.java
com.tonydicola.smartshaker.interfaces.PreparationStep.java