Android Open Source - SmartCocktailShaker Choose Connection






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.  j  a  v  a 2s.c  om
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Spinner;

import com.tonydicola.smartshaker.factories.ConnectionFactory;
import com.tonydicola.smartshaker.interfaces.DeviceConnection;
import com.tonydicola.smartshaker.R;

import butterknife.ButterKnife;
import butterknife.InjectView;

public class ChooseConnection extends Activity {

    @InjectView(R.id.chooseconnection_device_names)
    public Spinner deviceNames;

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

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

    @Override
    protected void onResume() {
        super.onResume();
        refreshDeviceNames();
    }

    public void refreshDeviceNames() {
        deviceNames.setAdapter(new ArrayAdapter<DeviceConnection>(
                this,
                android.R.layout.simple_list_item_1,
                ConnectionFactory.INSTANCE.getConnections()
        ));
    }

    public void refresh(View view) {
        refreshDeviceNames();
    }

    public void select(View view) {
        // Get selected device.
        final DeviceConnection device = (DeviceConnection) deviceNames.getSelectedItem();
        if (device != null) {
            // Request permission to the device.
            device.requestPermission(new Runnable() {
                @Override
                public void run() {
                    // When permission is granted, save the connection and finish the activity.
                    ConnectionFactory.INSTANCE.setConnection(device);
                    finish();
                }
            });
        }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.connection, 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