Android Open Source - SensorDataCollector User Interface Utils






From Project

Back to project page SensorDataCollector.

License

The source code is released under:

GNU General Public License

If you think the Android project SensorDataCollector 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

/*
 * Copyright (c) 2014, the SenSee authors.  Please see the AUTHORS file
 * for details. /*from  w  ww. j  av a 2 s  . c  om*/
 * 
 * Licensed under the GNU Public License, Version 3.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *       http://www.gnu.org/copyleft/gpl.html
 * 
 * Unless required by applicable law or agreed to in writing, software 
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and 
 * limitations under the License.
 */

package sysnetlab.android.sdc.ui;

import java.util.ArrayList;
import java.util.List;

import sysnetlab.android.sdc.R;
import sysnetlab.android.sdc.sensor.AbstractSensor;
import sysnetlab.android.sdc.sensor.AndroidSensor;
import sysnetlab.android.sdc.sensor.SensorProperty;
import sysnetlab.android.sdc.sensor.audio.AudioRecordParameter;
import sysnetlab.android.sdc.sensor.audio.AudioSensor;
import sysnetlab.android.sdc.ui.adapters.SensorPropertyListAdapter;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.graphics.drawable.Drawable;
import android.hardware.Sensor;
import android.os.Build;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.GridView;
import android.widget.ListView;
import android.widget.TextView;

public class UserInterfaceUtils {

    private static int mTagsGridNumColumns;

    public static void fillSensorProperties(Activity activity, ListView listView,
            AbstractSensor sensor) {
        UserInterfaceUtils.fillSensorProperties(activity, listView, sensor, false);
    }

    public static void fillSensorProperties(Activity activity, ListView listView,
            AbstractSensor sensor, boolean displayName) {
        ArrayList<SensorProperty> lstSensorProperties = new ArrayList<SensorProperty>();

        SensorProperty property;

        if (displayName) {
            property = new SensorProperty(activity.getResources().getString(R.string.text_name),
                    sensor.getName());
            lstSensorProperties.add(property);
        }

        switch (sensor.getMajorType()) {
            case AbstractSensor.ANDROID_SENSOR:
                property = new SensorProperty(activity.getResources().getString(
                        R.string.text_vendor),
                        sensor.getVendor());
                lstSensorProperties.add(property);

                property = new SensorProperty(activity.getResources().getString(
                        R.string.text_version),
                        Integer.toString(sensor.getVersion()));
                lstSensorProperties.add(property);

                Sensor aSensor = (Sensor) (((AndroidSensor) sensor).getSensor());

                property = new SensorProperty(activity.getResources().getString(
                        R.string.text_android_sensor_type),
                        Integer.toString(aSensor.getType()));
                lstSensorProperties.add(property);

                property = new SensorProperty(activity.getResources().getString(
                        R.string.text_resolution),
                        Float.toString(aSensor.getResolution()));
                lstSensorProperties.add(property);

                property = new SensorProperty(activity.getResources().getString(
                        R.string.text_power_consumption),
                        Float.toString(aSensor.getPower()) + " mA");
                lstSensorProperties.add(property);

                property = new SensorProperty(activity.getResources().getString(
                        R.string.text_maximum_range),
                        Float.toString(aSensor.getMaximumRange()));
                lstSensorProperties.add(property);

                if (((AndroidSensor) sensor).isStreamingSensor()) {
                    property = new SensorProperty(activity.getResources().getString(
                            R.string.text_minimum_sample_delay),
                            Float.toString(((AndroidSensor) sensor).getSamplingInterval()));
                } else {
                    property = new SensorProperty(activity.getResources().getString(
                            R.string.text_minimum_sample_delay),
                            activity.getResources().getString(R.string.text_not_applicable));
                }
                lstSensorProperties.add(property);

                break;
            case AbstractSensor.AUDIO_SENSOR:
                AudioSensor audioSensor = (AudioSensor) sensor;

                AudioRecordParameter param = audioSensor.getAudioRecordParameter();

                property = new SensorProperty(activity.getResources().getString(
                        R.string.text_audio_source), activity.getResources().getString(
                        param.getSource().getSourceNameResId()));
                Log.d("SensorDataCollector", "AUDIO_SENSOR Property: (name, id, resid, string) = " +
                        property.getName() + "," +
                        param.getSource().getSourceId() + "," +
                        param.getSource().getSourceNameResId() + "," +
                        property.getValue());
                lstSensorProperties.add(property);

                property = new SensorProperty(activity.getResources().getString(
                        R.string.text_audio_channel_in), activity.getResources().getString(
                        param.getChannel().getChannelNameResId()));
                lstSensorProperties.add(property);

                property = new SensorProperty(activity.getResources().getString(
                        R.string.text_audio_encoding), activity.getResources().getString(
                        param.getEncoding().getEncodingNameResId()));
                lstSensorProperties.add(property);

                property = new SensorProperty(activity.getResources().getString(
                        R.string.text_audio_sampling_rate), Integer.toString(param
                        .getSamplingRate()));
                lstSensorProperties.add(property);

                property = new SensorProperty(activity.getResources().getString(
                        R.string.text_audio_min_buffer_size), Integer.toString(param
                        .getBufferSize()));
                lstSensorProperties.add(property);

                break;
            case AbstractSensor.CAMERA_SENSOR:
                // TODO: todo ...
                Log.w("SensorDataCollector", "Camera Sensor is a todo.");
                break;
            case AbstractSensor.WIFI_SENSOR:
                // TODO: todo ...
                Log.w("SensorDataCollector", "WiFi Sensor is a todo.");
                break;
            case AbstractSensor.BLUETOOTH_SENSOR:
                // TODO: todo ...
                Log.w("SensorDataCollector", "Bluetooth Sensor is a todo.");
                break;
            default:
                // TODO: todo ...
                Log.w("SensorDataCollector", "unknown sensor. unexpected.");
                break;
        }
        SensorPropertyListAdapter sensorPropertyListAdaptor = new SensorPropertyListAdapter(
                activity, lstSensorProperties);

        listView.setAdapter(sensorPropertyListAdaptor);
    }

    public static void updateAudioSensorPropertyListView(Activity activity, ListView listView,
            AudioRecordParameter param) {
        ArrayList<SensorProperty> listProperties = new ArrayList<SensorProperty>();

        SensorProperty property;

        property = new SensorProperty(activity.getResources().getString(
                R.string.text_audio_source), activity.getResources().getString(
                param.getSource().getSourceNameResId()));
        listProperties.add(property);

        property = new SensorProperty(activity.getResources().getString(
                R.string.text_audio_channel_in), activity.getResources().getString(
                param.getChannel().getChannelNameResId()));
        listProperties.add(property);

        property = new SensorProperty(activity.getResources().getString(
                R.string.text_audio_encoding), activity.getResources().getString(
                param.getEncoding().getEncodingNameResId()));
        listProperties.add(property);

        property = new SensorProperty(activity.getResources().getString(
                R.string.text_audio_sampling_rate), Integer.toString(param
                .getSamplingRate()));
        listProperties.add(property);

        property = new SensorProperty(activity.getResources().getString(
                R.string.text_audio_min_buffer_size), Integer.toString(param.getBufferSize()));
        listProperties.add(property);

        SensorPropertyListAdapter sensorPropertyListAdaptor = new SensorPropertyListAdapter(
                activity, listProperties);

        listView.setAdapter(sensorPropertyListAdaptor);

    }

    @SuppressWarnings("deprecation")
    @SuppressLint("NewApi")
    public static void setViewBackgroundCompatible(View view, Drawable background) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            view.setBackground(background);
        } else {
            view.setBackgroundDrawable(background);
        }
    }

    public static void setEllipsizeforTextView(TextView textView, TextUtils.TruncateAt truncateAt) {
        // truncateAt can be any of the 4 values
        /*
         * TextUtils.TruncateAt.END TextUtils.TruncateAt.MARQUEE
         * TextUtils.TruncateAt.MIDDLE TextUtils.TruncateAt.START
         */
        textView.setEllipsize(truncateAt);
        textView.setSingleLine();
        textView.setHorizontallyScrolling(false);
    }

    public static String filterOutNewLines(String text) {
        String[] lines = text.split(System.getProperty("line.separator"));
        String strLongLine = "";
        for (String s : lines) {
            strLongLine += s + " ";
        }
        return strLongLine;
    }

    @SuppressLint("InlinedApi")
    public static boolean bindRunExperimentServiceCompatible(Context context, Intent service,
            ServiceConnection conn) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
            return context.bindService(service, conn, Context.BIND_ABOVE_CLIENT);
        } else {
            return context.bindService(service, conn, Context.BIND_AUTO_CREATE);
        }
    }

    @SuppressLint("NewApi")
    public static int getNumColumnsCompatible(GridView gridView) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            return gridView.getNumColumns();
        } else {
            if (mTagsGridNumColumns > 0) {
                return mTagsGridNumColumns;
            } else {
                if (gridView.getChildCount() > 0) {
                    int width = gridView.getChildAt(0).getMeasuredWidth();
                    if (width > 0) {
                        mTagsGridNumColumns = gridView.getWidth() / width;
                    }
                }
            }
            return mTagsGridNumColumns > 0 ? mTagsGridNumColumns : GridView.AUTO_FIT;

        }
    }

    @SuppressLint("NewApi")
    public static boolean isInLayoutCompatible(View view) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
            return view.isInLayout();
        } else {
            return false;
        }
    }

    @SuppressLint("NewApi")
    public static <T> void addAllCompatible(ArrayAdapter<T> adapter, List<T> list) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            adapter.addAll(list);
        } else {
            adapter.setNotifyOnChange(false);
            for (T e : list) {
                adapter.add(e);
            }
            adapter.setNotifyOnChange(true);
            adapter.notifyDataSetChanged();
        }
    }
}




Java Source Code List

sysnetlab.android.sdc.datacollector.AndroidSensorEventListener.java
sysnetlab.android.sdc.datacollector.DataCollectionState.java
sysnetlab.android.sdc.datacollector.DateUtils.java
sysnetlab.android.sdc.datacollector.DeviceInformation.java
sysnetlab.android.sdc.datacollector.DropboxHelper.java
sysnetlab.android.sdc.datacollector.ExperimentManagerSingleton.java
sysnetlab.android.sdc.datacollector.ExperimentManager.java
sysnetlab.android.sdc.datacollector.ExperimentTime.java
sysnetlab.android.sdc.datacollector.Experiment.java
sysnetlab.android.sdc.datacollector.Note.java
sysnetlab.android.sdc.datacollector.StateTag.java
sysnetlab.android.sdc.datacollector.Tag.java
sysnetlab.android.sdc.datacollector.TaggingAction.java
sysnetlab.android.sdc.datacollector.TaggingState.java
sysnetlab.android.sdc.datastore.AbstractStore.java
sysnetlab.android.sdc.datastore.SimpleFileStore.java
sysnetlab.android.sdc.datastore.SimpleXmlFileStore.java
sysnetlab.android.sdc.datastore.StoreSingleton.java
sysnetlab.android.sdc.loaders.ExperimentListLoader.java
sysnetlab.android.sdc.sensor.AbstractSensor.java
sysnetlab.android.sdc.sensor.AndroidSensor.java
sysnetlab.android.sdc.sensor.SensorDiscoverer.java
sysnetlab.android.sdc.sensor.SensorProperty.java
sysnetlab.android.sdc.sensor.audio.AudioChannelIn.java
sysnetlab.android.sdc.sensor.audio.AudioEncoding.java
sysnetlab.android.sdc.sensor.audio.AudioRecordParameter.java
sysnetlab.android.sdc.sensor.audio.AudioRecordSettingDBHelper.java
sysnetlab.android.sdc.sensor.audio.AudioRecordSettingDataSource.java
sysnetlab.android.sdc.sensor.audio.AudioSensorHelper.java
sysnetlab.android.sdc.sensor.audio.AudioSensor.java
sysnetlab.android.sdc.sensor.audio.AudioSource.java
sysnetlab.android.sdc.sensor.audio.WaveHeader.java
sysnetlab.android.sdc.sensor.camera.CameraHelper.java
sysnetlab.android.sdc.sensor.camera.CameraSensor.java
sysnetlab.android.sdc.services.RunExperimentService.java
sysnetlab.android.sdc.ui.AudioSensorProbingActivity.java
sysnetlab.android.sdc.ui.CreateExperimentActivity.java
sysnetlab.android.sdc.ui.FragmentActivityBase.java
sysnetlab.android.sdc.ui.GestureEventListener.java
sysnetlab.android.sdc.ui.SensorDataCollectorActivity.java
sysnetlab.android.sdc.ui.TaggingGridView.java
sysnetlab.android.sdc.ui.UserInterfaceUtils.java
sysnetlab.android.sdc.ui.ViewExperimentActivity.java
sysnetlab.android.sdc.ui.adapters.DataStoreListAdapter.java
sysnetlab.android.sdc.ui.adapters.ExperimentListAdapter.java
sysnetlab.android.sdc.ui.adapters.OperationAdapter.java
sysnetlab.android.sdc.ui.adapters.SensorListAdapter.java
sysnetlab.android.sdc.ui.adapters.SensorPropertyListAdapter.java
sysnetlab.android.sdc.ui.adapters.TagListAdapter.java
sysnetlab.android.sdc.ui.adapters.TaggingTagListAdapter.java
sysnetlab.android.sdc.ui.fragments.AudioSensorSetupDialogFragment.java
sysnetlab.android.sdc.ui.fragments.ExperimentDataStoreFragment.java
sysnetlab.android.sdc.ui.fragments.ExperimentEditNotesFragment.java
sysnetlab.android.sdc.ui.fragments.ExperimentEditTagsFragment.java
sysnetlab.android.sdc.ui.fragments.ExperimentListFragment.java
sysnetlab.android.sdc.ui.fragments.ExperimentRunFragment.java
sysnetlab.android.sdc.ui.fragments.ExperimentRunTaggingFragment.java
sysnetlab.android.sdc.ui.fragments.ExperimentSensorListFragment.java
sysnetlab.android.sdc.ui.fragments.ExperimentSensorSelectionFragment.java
sysnetlab.android.sdc.ui.fragments.ExperimentSensorSetupFragment.java
sysnetlab.android.sdc.ui.fragments.ExperimentSetupFragment.java
sysnetlab.android.sdc.ui.fragments.ExperimentViewFragment.java
sysnetlab.android.sdc.ui.fragments.ExperimentViewNotesFragment.java
sysnetlab.android.sdc.ui.fragments.ExperimentViewSensorDataFragment.java
sysnetlab.android.sdc.ui.fragments.ExperimentViewSensorListFragment.java
sysnetlab.android.sdc.ui.fragments.ExperimentViewTagsFragment.java
sysnetlab.android.sdc.ui.fragments.FragmentUtils.java