@Override
  public String summarizeValue(Context context, Bundle bundle) {
    double xReading = bundle.getDoubleArray("X")[0];
    double yReading = bundle.getDoubleArray("Y")[0];
    double zReading = bundle.getDoubleArray("Z")[0];

    return String.format(
        context.getResources().getString(R.string.summary_gyroscope_probe),
        xReading,
        yReading,
        zReading);
  }
Exemple #2
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.theater);

    gridview = (GridView) findViewById(R.id.gridview);

    Bundle b = this.getIntent().getExtras();

    th_name = b.getStringArray("th_name");
    lat = b.getDoubleArray("lat");
    lng = b.getDoubleArray("lng");
    address = b.getStringArray("address");
    mv_time = b.getStringArray("mv_time");
    wh = b.getString("wh");
    setTitle(wh);
    th_distance = new String[address.length];
    Wm = th_name.length;
    for (int a = 0; a < Wm; a++) {
      Pois.add(new Poi(th_name[a], lat[a], lng[a], address[a], mv_time[a]));
    }
    // 取得定位權限
    mLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    mLocationManager.requestLocationUpdates(
        LocationManager.NETWORK_PROVIDER, 0, 10000.0f, LocationChange);

    // Mv_find fl = new Mv_find();
    // fl.start();

    // 按下按鈕後讀取我的位置,定位抓取方式為網路讀取(若欲以GPS為定位抓取方式則更改成LocationManager.GPS_PROVIDER),最後則帶入定位更新Listener。

    // 建立物件,並放入List裡 (建立物件需帶入名稱、緯度、經度)
    /*
    Pois.add(new Poi("台北車站" , 25.04661 , 121.5168 ));
     	Pois.add(new Poi("台中車站" , 24.13682 , 120.6850 ));
     	Pois.add(new Poi("台北101" , 25.03362 , 121.56500 ));
     	Pois.add(new Poi("高雄85大樓" , 22.61177 , 120.30031 ));
     	Pois.add(new Poi("九份老街" , 25.10988 , 121.84519 ));*/

    gridview.setOnItemClickListener(
        new OnItemClickListener() {

          @Override
          public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {

            Intent intent = new Intent();

            Bundle b = new Bundle();
            b.putString("address1", String.valueOf(Pois.get(arg2).getLatitude()));
            b.putString("address2", String.valueOf(Pois.get(arg2).getLongitude()));
            b.putString("theater_name", Pois.get(arg2).getName());
            b.putString("theater", Pois.get(arg2).getaddress());
            intent.putExtras(b);
            intent.setClass(Movie_th2.this, find_theater.class);
            startActivity(intent);
          }
        });
    // 將字串 list 回傳的 JSON 透過解析後存到 values 陣列並傳給 listView 作清單的顯示
    gridview.setAdapter(adapter);
  }
        @Override
        public void handleMessage(Message msg) {
          switch (msg.what) {
            case MSG_PUSH_DATA:
              Bundle bundle = (Bundle) msg.obj;
              int sensor = bundle.getInt(BUNDLE_SENSOR);
              SeedNode seed = mSeedNodeMap.get(sensor);

              if (seed == null) {
                // throw new UnsupportedOperationException("No SeedNode for SensorType: " + sensor);
                DebugHelper.log(TAG, "No SeedNode for SensorType: " + sensor);
                return;
              }

              int deviceID = bundle.getInt(BUNDLE_DEVICE_ID);

              if (seed.getAttachedDevice() != mDeviceMap.get(deviceID)) {
                DebugHelper.log(
                    TAG,
                    "Unmatched seed node and attached device(sensor: "
                        + sensor
                        + ", attempted device ID: "
                        + deviceID);
                return;
              }

              String type = bundle.getString(BUNDLE_TYPE);
              int length = bundle.getInt(BUNDLE_LENGTH);
              String name = SensorType.getSensorName(sensor);
              long timestamp = bundle.getLong(BUNDLE_TIMESTAMP);

              // show notification
              showNotification(sensor, name);

              if (type.equals("double[]")) {
                seed.input(name, type, bundle.getDoubleArray(BUNDLE_DATA), length, timestamp);
              } else if (type.equals("double")) {
                seed.input(name, type, bundle.getDouble(BUNDLE_DATA), length, timestamp);
              } else if (type.equals("int[]")) {
                seed.input(name, type, bundle.getIntArray(BUNDLE_DATA), length, timestamp);
              } else if (type.equals("int")) {
                seed.input(name, type, bundle.getInt(BUNDLE_DATA), length, timestamp);
              } else if (type.equals("String")) {
                seed.input(name, type, bundle.getString(BUNDLE_DATA), length, timestamp);
              } else {
                throw new IllegalArgumentException("Unknown data_type: " + type);
              }
              break;

            default:
              super.handleMessage(msg);
              break;
          }
        }
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Inflate the layout for this fragment

    setHasOptionsMenu(true);
    View rootView = inflater.inflate(R.layout.fragment_temperature, container, false);

    chart = (LineChartView) rootView.findViewById(R.id.chart);
    previewChart = (PreviewLineChartView) rootView.findViewById(R.id.chart_preview);

    // Generate data for previewed chart and copy of that data for preview chart.

    if (getArguments() != null) {
      temperatureData = getArguments();
      latitude = temperatureData.getFloat("latitude");
      longitude = temperatureData.getFloat("longitude");
      temperatures = temperatureData.getDoubleArray("temperatureArr");
      times = temperatureData.getIntArray("timeArr");
      numData = temperatureData.getInt("numData");
      Log.d("ARRAY", Arrays.toString(temperatures));
      Log.d("ARRAY", Arrays.toString(times));
      getForecastData();

      Log.d("receiver", "OK");
    } else {
      generateDefaultData();
    }
    chart.setLineChartData(data);
    // Disable zoom/scroll for previewed chart, visible chart ranges depends on preview chart
    // viewport so
    // zoom/scroll is unnecessary.
    chart.setZoomEnabled(false);
    chart.setScrollEnabled(false);

    previewChart.setLineChartData(previewData);
    previewChart.setViewportChangeListener(new ViewportListener());

    previewX(false);

    return rootView;
  }
 private void getBundle() {
   Bundle bundle = getIntent().getExtras();
   coordenadas = bundle.getDoubleArray(TelaEndereco.COORDENADA);
   endereco = bundle.getString(TelaEndereco.ENDERECO);
 }
  @SmallTest
  @MediumTest
  @LargeTest
  public void testAllTypes() {
    Bundle originalBundle = new Bundle();

    putBoolean(BOOLEAN_KEY, originalBundle);
    putBooleanArray(BOOLEAN_ARRAY_KEY, originalBundle);
    putByte(BYTE_KEY, originalBundle);
    putByteArray(BYTE_ARRAY_KEY, originalBundle);
    putShort(SHORT_KEY, originalBundle);
    putShortArray(SHORT_ARRAY_KEY, originalBundle);
    putInt(INT_KEY, originalBundle);
    putIntArray(INT_ARRAY_KEY, originalBundle);
    putLong(LONG_KEY, originalBundle);
    putLongArray(LONG_ARRAY_KEY, originalBundle);
    putFloat(FLOAT_KEY, originalBundle);
    putFloatArray(FLOAT_ARRAY_KEY, originalBundle);
    putDouble(DOUBLE_KEY, originalBundle);
    putDoubleArray(DOUBLE_ARRAY_KEY, originalBundle);
    putChar(CHAR_KEY, originalBundle);
    putCharArray(CHAR_ARRAY_KEY, originalBundle);
    putString(STRING_KEY, originalBundle);
    putStringList(STRING_LIST_KEY, originalBundle);
    originalBundle.putSerializable(SERIALIZABLE_KEY, AccessTokenSource.FACEBOOK_APPLICATION_WEB);

    ensureApplicationContext();

    SharedPreferencesTokenCachingStrategy cache =
        new SharedPreferencesTokenCachingStrategy(getContext());
    cache.save(originalBundle);

    SharedPreferencesTokenCachingStrategy cache2 =
        new SharedPreferencesTokenCachingStrategy(getContext());
    Bundle cachedBundle = cache2.load();

    Assert.assertEquals(
        originalBundle.getBoolean(BOOLEAN_KEY), cachedBundle.getBoolean(BOOLEAN_KEY));
    assertArrayEquals(
        originalBundle.getBooleanArray(BOOLEAN_ARRAY_KEY),
        cachedBundle.getBooleanArray(BOOLEAN_ARRAY_KEY));
    Assert.assertEquals(originalBundle.getByte(BYTE_KEY), cachedBundle.getByte(BYTE_KEY));
    assertArrayEquals(
        originalBundle.getByteArray(BYTE_ARRAY_KEY), cachedBundle.getByteArray(BYTE_ARRAY_KEY));
    Assert.assertEquals(originalBundle.getShort(SHORT_KEY), cachedBundle.getShort(SHORT_KEY));
    assertArrayEquals(
        originalBundle.getShortArray(SHORT_ARRAY_KEY), cachedBundle.getShortArray(SHORT_ARRAY_KEY));
    Assert.assertEquals(originalBundle.getInt(INT_KEY), cachedBundle.getInt(INT_KEY));
    assertArrayEquals(
        originalBundle.getIntArray(INT_ARRAY_KEY), cachedBundle.getIntArray(INT_ARRAY_KEY));
    Assert.assertEquals(originalBundle.getLong(LONG_KEY), cachedBundle.getLong(LONG_KEY));
    assertArrayEquals(
        originalBundle.getLongArray(LONG_ARRAY_KEY), cachedBundle.getLongArray(LONG_ARRAY_KEY));
    Assert.assertEquals(originalBundle.getFloat(FLOAT_KEY), cachedBundle.getFloat(FLOAT_KEY));
    assertArrayEquals(
        originalBundle.getFloatArray(FLOAT_ARRAY_KEY), cachedBundle.getFloatArray(FLOAT_ARRAY_KEY));
    Assert.assertEquals(originalBundle.getDouble(DOUBLE_KEY), cachedBundle.getDouble(DOUBLE_KEY));
    assertArrayEquals(
        originalBundle.getDoubleArray(DOUBLE_ARRAY_KEY),
        cachedBundle.getDoubleArray(DOUBLE_ARRAY_KEY));
    Assert.assertEquals(originalBundle.getChar(CHAR_KEY), cachedBundle.getChar(CHAR_KEY));
    assertArrayEquals(
        originalBundle.getCharArray(CHAR_ARRAY_KEY), cachedBundle.getCharArray(CHAR_ARRAY_KEY));
    Assert.assertEquals(originalBundle.getString(STRING_KEY), cachedBundle.getString(STRING_KEY));
    assertListEquals(
        originalBundle.getStringArrayList(STRING_LIST_KEY),
        cachedBundle.getStringArrayList(STRING_LIST_KEY));
    Assert.assertEquals(
        originalBundle.getSerializable(SERIALIZABLE_KEY),
        cachedBundle.getSerializable(SERIALIZABLE_KEY));
  }
 /**
  * Retrieve extended data from the request.
  *
  * @param name The name of the desired item.
  * @return the value of an item that previously added with putExtra() or null if no double array
  *     value was found.
  * @see #putExtra(String, double[])
  */
 public double[] getDoubleArrayExtra(String name) {
   return mExtras == null ? null : mExtras.getDoubleArray(name);
 }
  protected void processData(final Context context, Bundle dataBundle) {
    if (dataBundle.containsKey(ContinuousProbe.EVENT_TIMESTAMP)
        && dataBundle.containsKey("X")
        && dataBundle.containsKey("Y")
        && dataBundle.containsKey("Z")) {
      double[] incomingTimes = dataBundle.getDoubleArray(ContinuousProbe.EVENT_TIMESTAMP);

      float[] incomingX = dataBundle.getFloatArray("X");
      float[] incomingY = dataBundle.getFloatArray("Y");
      float[] incomingZ = dataBundle.getFloatArray("Z");

      this.appendValues(incomingX, incomingY, incomingZ, incomingTimes);

      final long now = System.currentTimeMillis();

      final String key = this.featureKey();

      final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
      long updateInterval =
          Long.parseLong(
                  prefs.getString(
                      "config_probe_" + key + "_frequency",
                      XYZBasicFrequencyFeature.DEFAULT_FREQUENCY))
              * 1000;

      if (now - this._lastUpdate > updateInterval) // add last updated
      // check for config
      {
        this._lastUpdate = now;

        LinearInterpolator interpolator = new LinearInterpolator();

        double[] xs = _xValues;
        double[] ys = _yValues;
        double[] zs = _zValues;
        double[] ts = _timestamps;

        if (this._currentIndex < BUFFER_SIZE - 1) {
          xs = Arrays.copyOfRange(_xValues, 0, this._currentIndex);
          ys = Arrays.copyOfRange(_yValues, 0, this._currentIndex);
          zs = Arrays.copyOfRange(_zValues, 0, this._currentIndex);
          ts = Arrays.copyOfRange(_timestamps, 0, this._currentIndex);
        }

        // Log.e("PR", "FIRST RAW TIME: " + ts[0] + " LAST RAW TIME: " +
        // ts[ts.length - 1]);

        // Log.e("PR", "RAW TIME[0]: " + ts[0]);
        // Log.e("PR", "RAW TIME[1]: " + ts[1]);

        PolynomialSplineFunction fX = interpolator.interpolate(ts, xs);
        PolynomialSplineFunction fY = interpolator.interpolate(ts, ys);
        PolynomialSplineFunction fZ = interpolator.interpolate(ts, zs);

        // double lowFreq = 0.6;
        // double highFreq = 7.0;

        double durationOffset = ts[0];
        double bufferDuration = ts[ts.length - 1] - durationOffset;

        double interval = 1.0 / 120.0;

        // Log.e("PR", "TS/0: " + ts[0] + " -- TS/-1: " + ts[ts.length -
        // 1] + " -- LEN TS: " + ts.length);
        // Log.e("PR", "BD: " + bufferDuration + " INT: " + interval);

        int twoPow = ts.length == 0 ? 0 : (32 - Integer.numberOfLeadingZeros(ts.length - 1));
        int bufferSize = (int) Math.pow(2, twoPow);

        // Log.e("PR", "BUFF SIZE: " + bufferSize);

        final double[] _interX = new double[bufferSize];
        final double[] _interY = new double[bufferSize];
        final double[] _interZ = new double[bufferSize];

        Arrays.fill(_interX, 0.0);
        Arrays.fill(_interY, 0.0);
        Arrays.fill(_interZ, 0.0);

        interTimes = new double[bufferSize];

        for (int i = 0; i < bufferSize; i++) {
          interTimes[i] = durationOffset + (i * interval);

          // Log.e("PR", "TIME REQUEST: " + time);
          // Log.e("PR", "TIME DIFFERENCE: " + (oldTime - time));

          if (interTimes[i] > ts[ts.length - 1]) // If the current
            // timestamp is
            // greater than the
            // last recorded
            // timestamp, set it
            // to the last
            // timestamp
            interTimes[i] = ts[ts.length - 1];

          _interX[i] = fX.value(interTimes[i]);
          _interY[i] = fY.value(interTimes[i]);
          _interZ[i] = fZ.value(interTimes[i]);
        }

        // double timeDifference = interTimes[bufferSize - 1] -
        // interTimes[0];

        // Log.e("PR", "INTERP TIME: " + timeDifference +
        // " BUFFER SIZE: " + bufferSize);
        // Log.e("PR", "FIRST INTERP TIME: " + interTimes[0] +
        // " LAST INTERP TIME: " + interTimes[interTimes.length - 1]);

        // Log.e("PR", "INTERP SAMPLE: " + interX[bufferSize - 1] +
        // " - " + interY[bufferSize - 1] + " - " + interZ[bufferSize -
        // 1]);

        final double[] _dynamicX = new double[_interX.length];
        final double[] _dynamicY = new double[_interY.length];
        final double[] _dynamicZ = new double[_interZ.length];

        final double[] _staticX = new double[_interX.length];
        final double[] _staticY = new double[_interY.length];
        final double[] _staticZ = new double[_interZ.length];

        for (int i = 0; i < _interX.length; i++) {
          if (i < 2) {
            _dynamicX[i] = 0;
            _dynamicY[i] = 0;
            _dynamicZ[i] = 0;

            _staticX[i] = 0;
            _staticY[i] = 0;
            _staticZ[i] = 0;
          } else {
            if (i == _dynamicX.length - 1) {
              _dynamicX[i] = XYZBasicFrequencyFeature.bpFilter(_interX, this._xBPHistory, i, "X");
              _dynamicY[i] = XYZBasicFrequencyFeature.bpFilter(_interY, this._yBPHistory, i, "Y");
              _dynamicZ[i] = XYZBasicFrequencyFeature.bpFilter(_interZ, this._zBPHistory, i, "Z");

              _staticX[i] = XYZBasicFrequencyFeature.lpFilter(_interX, this._xLPHistory, i, "X");
              _staticY[i] = XYZBasicFrequencyFeature.lpFilter(_interY, this._yLPHistory, i, "Y");
              _staticZ[i] = XYZBasicFrequencyFeature.lpFilter(_interZ, this._zLPHistory, i, "Z");
            } else {
              _dynamicX[i] = XYZBasicFrequencyFeature.bpFilter(_interX, this._xBPHistory, i, null);
              _dynamicY[i] = XYZBasicFrequencyFeature.bpFilter(_interY, this._yBPHistory, i, null);
              _dynamicZ[i] = XYZBasicFrequencyFeature.bpFilter(_interZ, this._zBPHistory, i, null);

              _staticX[i] = XYZBasicFrequencyFeature.lpFilter(_interX, this._xLPHistory, i, null);
              _staticY[i] = XYZBasicFrequencyFeature.lpFilter(_interY, this._yLPHistory, i, null);
              _staticZ[i] = XYZBasicFrequencyFeature.lpFilter(_interZ, this._zLPHistory, i, null);
            }

            this._xBPHistory[1] = this._xBPHistory[0];
            this._xBPHistory[0] = _dynamicX[i];

            this._yBPHistory[1] = this._yBPHistory[0];
            this._yBPHistory[0] = _dynamicY[i];

            this._zBPHistory[1] = this._zBPHistory[0];
            this._zBPHistory[0] = _dynamicZ[i];

            this._xLPHistory[1] = this._xLPHistory[0];
            this._xLPHistory[0] = _staticX[i];

            this._yLPHistory[1] = this._yLPHistory[0];
            this._yLPHistory[0] = _staticY[i];

            this._zLPHistory[1] = this._zLPHistory[0];
            this._zLPHistory[0] = _staticZ[i];
          }
        }

        // Log.e("PR", "Inter Sample: " + _interX[_interX.length - 1] +
        // " - " + _interY[_interX.length - 1] + " - " +
        // _interZ[_interX.length - 1]);
        // Log.e("PR", "DY Sample: " + _dynamicX[_dynamicX.length - 1] +
        // " - " + _dynamicY[_dynamicX.length - 1] + " - " +
        // _dynamicZ[_interX.length - 1]);
        // Log.e("PR", "GR Sample: " + _staticX[_staticX.length - 1] +
        // " - " + _staticY[_staticY.length - 1] + " - " +
        // _staticZ[_staticZ.length - 1]);

        double observedFreq = _interX.length / bufferDuration; // (((double)
        // this._currentIndex)
        // /
        // bufferDuration);

        // Log.e("PR", "IL: + " + _interX.length + " / BD: " +
        // bufferDuration);
        // Log.e("PR", "OBS HZ: " + observedFreq);

        FastFourierTransformer fft = new FastFourierTransformer(DftNormalization.STANDARD);

        Complex[] xFFT = fft.transform(_dynamicX, TransformType.FORWARD);
        Complex[] yFFT = fft.transform(_dynamicY, TransformType.FORWARD);
        Complex[] zFFT = fft.transform(_dynamicZ, TransformType.FORWARD);

        double[] frequencies =
            XYZBasicFrequencyFeature.calculateFreqArray(_interX.length, observedFreq);

        final double[] _xMaxFreqPowPair =
            XYZBasicFrequencyFeature.findPeakFrequency(xFFT, frequencies);
        final double[] _yMaxFreqPowPair =
            XYZBasicFrequencyFeature.findPeakFrequency(yFFT, frequencies);
        final double[] _zMaxFreqPowPair =
            XYZBasicFrequencyFeature.findPeakFrequency(zFFT, frequencies);

        // Log.e("PR", "FREQS & GEEKS: x:" + _xMaxFreqPowPair[0] + " - "
        // + _xMaxFreqPowPair[1] + " y:" + _yMaxFreqPowPair[0] + " - " +
        // _yMaxFreqPowPair[1] + " z:" + _zMaxFreqPowPair[0] + " - " +
        // _zMaxFreqPowPair[1] );

        final XYZBasicFrequencyFeature me = this;

        Runnable r =
            new Runnable() {
              public void run() {
                Bundle data = new Bundle();

                data.putDouble("TIMESTAMP", now / 1000);
                data.putString("PROBE", me.name(context));

                boolean incInterpolated =
                    prefs.getBoolean(
                        "config_probe_" + key + "_interpolated_enabled",
                        XYZBasicFrequencyFeature.INTERPOLATED_ENABLED);
                boolean incBandpass =
                    prefs.getBoolean(
                        "config_probe_" + key + "_bandpass_enabled",
                        XYZBasicFrequencyFeature.BANDPASS_ENABLED);
                boolean incLowpass =
                    prefs.getBoolean(
                        "config_probe_" + key + "_lowpass_enabled",
                        XYZBasicFrequencyFeature.LOWPASS_ENABLED);

                if (incInterpolated || incBandpass || incLowpass) {
                  Bundle sensorData = new Bundle();

                  synchronized (me) {
                    sensorData.putDoubleArray("INTERP_TIMESTAMPS", interTimes);

                    if (incInterpolated) {
                      sensorData.putDoubleArray("INTER_X", _interX);
                      sensorData.putDoubleArray("INTER_Y", _interY);
                      sensorData.putDoubleArray("INTER_Z", _interZ);
                    }

                    if (incBandpass) {
                      sensorData.putDoubleArray("DYNAMIC_X", _dynamicX);
                      sensorData.putDoubleArray("DYNAMIC_Y", _dynamicY);
                      sensorData.putDoubleArray("DYNAMIC_Z", _dynamicZ);
                    }

                    if (incLowpass) {
                      sensorData.putDoubleArray("STATIC_X", _staticX);
                      sensorData.putDoubleArray("STATIC_Y", _staticY);
                      sensorData.putDoubleArray("STATIC_Z", _staticZ);
                    }

                    data.putBundle("CALCULATIONS", sensorData);
                  }
                }

                data.putDouble("WINDOW_TIMESTAMP", interTimes[0]);

                data.putDouble("POWER_X", _xMaxFreqPowPair[1]);
                data.putDouble("POWER_Y", _yMaxFreqPowPair[1]);
                data.putDouble("POWER_Z", _zMaxFreqPowPair[1]);

                data.putDouble("FREQ_X", _xMaxFreqPowPair[0]);
                data.putDouble("FREQ_Y", _yMaxFreqPowPair[0]);
                data.putDouble("FREQ_Z", _zMaxFreqPowPair[0]);

                me.transmitData(context, data);
              }
            };

        Thread t = new Thread(r);

        t.start();
      }
    }
  }
  @Override
  public String summarizeValue(Context context, Bundle bundle) {
    double lux = bundle.getDoubleArray(LIGHT_KEY)[0];

    return String.format(context.getResources().getString(R.string.summary_light_probe), lux);
  }