Android Open Source - sensorreadout Overview Activity






From Project

Back to project page sensorreadout.

License

The source code is released under:

Apache License

If you think the Android project sensorreadout 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 2012 Patrick Ahlbrecht/*from  w  w w  . j a v a2 s. com*/

   Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0

   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 de.onyxbits.sensorreadout;

import android.app.*;
import android.os.Bundle;
import android.widget.*;
import android.view.*;
import android.hardware.*;
import android.content.*;
import android.net.*;

/**
 * Main <code>Activity</code>. Shows a list of all available <code>Sensor</code>
 * S and starts the <code>ReadoutActivity</code> of the selected
 * <code>Sensor</code>
 */
public class OverviewActivity extends ListActivity implements
    AdapterView.OnItemLongClickListener {

  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    SensorManager sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
    setListAdapter(new SensorAdapter(this, 0,
        sensorManager.getSensorList(Sensor.TYPE_ALL)));
    getListView().setOnItemLongClickListener(this);
    AppRater.appLaunched(this);
  }

  @Override
  public void onListItemClick(ListView l, View v, int position, long id) {
    // Short click on an item starts the readout activity
    Intent intent = new Intent(this, ReadoutActivity.class);
    intent.putExtra(ReadoutActivity.SENSORINDEX, position);
    startActivity(intent);
  }

  @Override
  public boolean onItemLongClick(AdapterView<?> parent, View view,
      int position, long id) {
    // Long click on an item brings up verbose info about the sensor
    Sensor sensor = (Sensor) parent.getItemAtPosition(position);
    LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
    View layout = inflater.inflate(R.layout.verbose, null);
    ((TextView) layout.findViewById(R.id.vendor_value)).setText(sensor
        .getVendor());
    ((TextView) layout.findViewById(R.id.power_value)).setText(sensor
        .getPower() + getString(R.string.unit_consumption));
    ((TextView) layout.findViewById(R.id.resolution_value)).setText(sensor
        .getResolution() + "");
    ((TextView) layout.findViewById(R.id.version_value)).setText(sensor
        .getVersion() + "");
    ((TextView) layout.findViewById(R.id.delay_value)).setText(sensor
        .getMinDelay() + getString(R.string.unit_mindelay));
    ((TextView) layout.findViewById(R.id.range_value)).setText(sensor
        .getMaximumRange() + "");
    ScrollView scrollView = new ScrollView(this);
    scrollView.addView(layout);

    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle(sensor.getName());
    int imageResource = R.drawable.ic_sensor_unknown;
    try {
      // Don't use a giant switch statement here to map types to image files.
      // Besides saving
      // a lot of code, this solution also has the advantage that we can declare
      // the
      // app to require a low API level while still being able to show icons for
      // sensors that
      // came in later.
      imageResource = getResources().getIdentifier(
          "drawable/ic_sensor_" + sensor.getType(), null,
          "de.onyxbits.sensorreadout");
      if (imageResource == 0) {
        imageResource = R.drawable.ic_sensor_unknown;
      }
    }
    catch (Exception e) {
    }
    builder.setIcon(imageResource);
    builder.setView(scrollView);
    builder.create().show();

    return true;
  }

  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.overview, menu);
    return true;
  }

  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
      case R.id.faq: {
        try {
          Intent browserIntent = new Intent(Intent.ACTION_VIEW,
              Uri.parse(getString(R.string.homepage_faq)));
          startActivity(browserIntent);
        }
        catch (ActivityNotFoundException e) {
          Toast.makeText(this, R.string.no_webbrowser_installed, Toast.LENGTH_SHORT).show();
        }
        break;
      }
      case R.id.plug: {
        try {
          Intent browserIntent = new Intent(Intent.ACTION_VIEW,
              Uri.parse(getString(R.string.homepage_market)));
          startActivity(browserIntent);
        }
        catch (ActivityNotFoundException e) {
          Toast.makeText(this, R.string.no_webbrowser_installed, Toast.LENGTH_SHORT).show();
        }
        break;
      }
    }
    return super.onOptionsItemSelected(item);
  }
}




Java Source Code List

de.onyxbits.sensorreadout.AppRater.java
de.onyxbits.sensorreadout.ExportTask.java
de.onyxbits.sensorreadout.OverviewActivity.java
de.onyxbits.sensorreadout.ReadoutActivity.java
de.onyxbits.sensorreadout.SensorAdapter.java
de.onyxbits.sensorreadout.Ticker.java
org.achartengine.ChartFactory.java
org.achartengine.GraphicalActivity.java
org.achartengine.GraphicalView.java
org.achartengine.ITouchHandler.java
org.achartengine.TouchHandlerOld.java
org.achartengine.TouchHandler.java
org.achartengine.chart.AbstractChart.java
org.achartengine.chart.BarChart.java
org.achartengine.chart.BubbleChart.java
org.achartengine.chart.ClickableArea.java
org.achartengine.chart.CombinedXYChart.java
org.achartengine.chart.CubicLineChart.java
org.achartengine.chart.DialChart.java
org.achartengine.chart.DoughnutChart.java
org.achartengine.chart.LineChart.java
org.achartengine.chart.PieChart.java
org.achartengine.chart.PieMapper.java
org.achartengine.chart.PieSegment.java
org.achartengine.chart.PointStyle.java
org.achartengine.chart.RangeBarChart.java
org.achartengine.chart.RangeStackedBarChart.java
org.achartengine.chart.RoundChart.java
org.achartengine.chart.ScatterChart.java
org.achartengine.chart.TimeChart.java
org.achartengine.chart.XYChart.java
org.achartengine.model.CategorySeries.java
org.achartengine.model.MultipleCategorySeries.java
org.achartengine.model.Point.java
org.achartengine.model.RangeCategorySeries.java
org.achartengine.model.SeriesSelection.java
org.achartengine.model.TimeSeries.java
org.achartengine.model.XYMultipleSeriesDataset.java
org.achartengine.model.XYSeries.java
org.achartengine.model.XYValueSeries.java
org.achartengine.renderer.BasicStroke.java
org.achartengine.renderer.DefaultRenderer.java
org.achartengine.renderer.DialRenderer.java
org.achartengine.renderer.SimpleSeriesRenderer.java
org.achartengine.renderer.XYMultipleSeriesRenderer.java
org.achartengine.renderer.XYSeriesRenderer.java
org.achartengine.tools.AbstractTool.java
org.achartengine.tools.FitZoom.java
org.achartengine.tools.PanListener.java
org.achartengine.tools.Pan.java
org.achartengine.tools.ZoomEvent.java
org.achartengine.tools.ZoomListener.java
org.achartengine.tools.Zoom.java
org.achartengine.util.IndexXYMap.java
org.achartengine.util.MathHelper.java
org.achartengine.util.XYEntry.java