Android Open Source - geoar-app Data Source Instance Settings Dialog Activity






From Project

Back to project page geoar-app.

License

The source code is released under:

Apache License

If you think the Android project geoar-app 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 52North Initiative for Geospatial Open Source Software GmbH
 *//from w w  w.j a  va2 s. c o  m
 * 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 org.n52.geoar.newdata;

import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.n52.geoar.R;
import org.n52.geoar.settings.SettingsView;

import android.app.Activity;
import android.os.Bundle;
import android.os.Parcel;
import android.os.Parcelable;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

import com.actionbarsherlock.app.SherlockActivity;

/**
 * Activity to set data source instance settings and its filter settings. Also
 * responsible for updating the data source instance.
 * 
 */
public class DataSourceInstanceSettingsDialogActivity extends SherlockActivity {

  public abstract static class SettingsResultListener implements Parcelable {
    private static List<WeakReference<SettingsResultListener>> instances = new ArrayList<WeakReference<SettingsResultListener>>();
    private int id = nextId++;
    private static int nextId = 0;

    public static final Parcelable.Creator<SettingsResultListener> CREATOR = new Parcelable.Creator<SettingsResultListener>() {
      @Override
      public SettingsResultListener createFromParcel(Parcel in) {
        int id = in.readInt();
        // Find SettingsResultListener with provided id
        Iterator<WeakReference<SettingsResultListener>> it = SettingsResultListener.instances
            .iterator();
        while (it.hasNext()) {
          WeakReference<SettingsResultListener> next = it.next();
          if (next.get() == null) {
            it.remove();
          } else if (next.get().id == id) {
            return next.get();
          }
        }
        return null;
      }

      @Override
      public SettingsResultListener[] newArray(int size) {
        return new SettingsResultListener[size];
      }
    };

    public SettingsResultListener() {
      instances.add(new WeakReference<SettingsResultListener>(this));
    }

    abstract void onSettingsResult(int resultCode);

    @Override
    public int describeContents() {
      return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
      dest.writeInt(id);
    }
  }

  private SettingsResultListener resultListener;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_datasourceinstance_dialog);

    final SettingsView generalSettingsView = (SettingsView) findViewById(R.id.settingsViewGeneral);
    final SettingsView filterSettingsView = (SettingsView) findViewById(R.id.settingsViewFilter);

    final DataSourceInstanceHolder dataSourceInstance = getIntent()
        .getParcelableExtra("dataSourceInstance");
    resultListener = getIntent().getParcelableExtra("resultListener");
    generalSettingsView.setStringsContext(dataSourceInstance.getParent()
        .getPluginHolder().getPluginContext());
    filterSettingsView.setStringsContext(dataSourceInstance.getParent()
        .getPluginHolder().getPluginContext());

    generalSettingsView.setSettingsObject(dataSourceInstance
        .getDataSource());
    filterSettingsView.setSettingsObject(dataSourceInstance
        .getCurrentFilter());

    if (generalSettingsView.isEmpty()) {
      findViewById(R.id.textViewGroupGeneral).setVisibility(View.GONE);
    }
    if (filterSettingsView.isEmpty()) {
      findViewById(R.id.textViewGroupFilter).setVisibility(View.GONE);
    }

    Button cancelButton = (Button) findViewById(R.id.negativeButton);
    cancelButton.setOnClickListener(new OnClickListener() {
      @Override
      public void onClick(View arg0) {
        setDialogResult(RESULT_CANCELED);
        finish();
      }
    });

    Button okButton = (Button) findViewById(R.id.positiveButton);
    okButton.setOnClickListener(new OnClickListener() {

      @Override
      public void onClick(View arg0) {
        if (generalSettingsView.validate()
            && filterSettingsView.validate()) {
          generalSettingsView.updateObject();
          filterSettingsView.updateObject();
          setDialogResult(RESULT_OK);
          finish();
        }
      }
    });
  }

  /**
   * Should be used instead of {@link Activity#setResult(int)} to use a passed
   * {@link SettingsResultListener}
   * 
   * @param resultCode
   */
  private void setDialogResult(int resultCode) {
    setResult(resultCode);
    if (resultListener != null) {
      resultListener.onSettingsResult(resultCode);
    }
  }

}




Java Source Code List

.DataSourcesOverlay.java
.VisualizationOverlayItem.java
org.n52.geoar.AboutDialog.java
org.n52.geoar.DataSourceListAdapter.java
org.n52.geoar.GeoARActivity.java
org.n52.geoar.GeoARApplication.java
org.n52.geoar.ar.view.ARFragment.java
org.n52.geoar.ar.view.ARObject.java
org.n52.geoar.ar.view.ARView.java
org.n52.geoar.ar.view.DataSourceVisualizationHandler.java
org.n52.geoar.ar.view.IntroController.java
org.n52.geoar.ar.view.IntroViewer.java
org.n52.geoar.ar.view.gl.ARSurfaceViewRenderer.java
org.n52.geoar.ar.view.gl.ARSurfaceView.java
org.n52.geoar.ar.view.gl.GLESCamera.java
org.n52.geoar.ar.view.gl.MultisampleConfigs.java
org.n52.geoar.ar.view.gl.SurfaceTopology.java
org.n52.geoar.ar.view.overlay.ARCanvasSurfaceView.java
org.n52.geoar.ar.view.overlay.GUIDrawable.java
org.n52.geoar.ar.view.overlay.Radar.java
org.n52.geoar.exception.UnsupportedGeometryType.java
org.n52.geoar.map.view.DataSourceOverlayHandler.java
org.n52.geoar.map.view.GeoARMapView.java
org.n52.geoar.map.view.MapActivityContext.java
org.n52.geoar.map.view.MapFragment.java
org.n52.geoar.map.view.overlay.DataSourceOverlay.java
org.n52.geoar.map.view.overlay.DataSourcePointOverlay.java
org.n52.geoar.map.view.overlay.DataSourcePolygonOverlay.java
org.n52.geoar.map.view.overlay.DataSourcePolylineOverlay.java
org.n52.geoar.map.view.overlay.DataSourcesOverlay.java
org.n52.geoar.map.view.overlay.OverlayType.java
org.n52.geoar.map.view.overlay.PointOverlayType.java
org.n52.geoar.map.view.overlay.PolygonOverlayType.java
org.n52.geoar.map.view.overlay.PolylineOverlayType.java
org.n52.geoar.newdata.CheckList.java
org.n52.geoar.newdata.DataCache.java
org.n52.geoar.newdata.DataSourceHolder.java
org.n52.geoar.newdata.DataSourceInstanceHolder.java
org.n52.geoar.newdata.DataSourceInstanceSettingsDialogActivity.java
org.n52.geoar.newdata.InstalledPluginHolder.java
org.n52.geoar.newdata.PluginActivityContext.java
org.n52.geoar.newdata.PluginContext.java
org.n52.geoar.newdata.PluginDialogFragment.java
org.n52.geoar.newdata.PluginDownloadHolder.java
org.n52.geoar.newdata.PluginDownloader.java
org.n52.geoar.newdata.PluginFragment.java
org.n52.geoar.newdata.PluginGridAdapter.java
org.n52.geoar.newdata.PluginHolder.java
org.n52.geoar.newdata.PluginLoader.java
org.n52.geoar.newdata.PluginLogger.java
org.n52.geoar.newdata.PluginStateInputStream.java
org.n52.geoar.newdata.Tile.java
org.n52.geoar.settings.DateTimeSettingsViewField.java
org.n52.geoar.settings.DateUtils.java
org.n52.geoar.settings.NumberSettingsViewField.java
org.n52.geoar.settings.SettingsException.java
org.n52.geoar.settings.SettingsHelper.java
org.n52.geoar.settings.SettingsViewField.java
org.n52.geoar.settings.SettingsView.java
org.n52.geoar.settings.SpinnerSettingsViewField.java
org.n52.geoar.settings.StringSettingsViewField.java
org.n52.geoar.tracking.camera.CameraView.java
org.n52.geoar.tracking.camera.RealityCamera.java
org.n52.geoar.tracking.location.AdaptiveLowPassSensorBuffer.java
org.n52.geoar.tracking.location.LocationHandler.java
org.n52.geoar.tracking.location.LowPassSensorBuffer.java
org.n52.geoar.tracking.location.MeanSensorBuffer.java
org.n52.geoar.tracking.location.SensorBuffer.java
org.n52.geoar.view.InfoView.java
org.n52.geoar.view.geoar.CalibrationControlView.java
org.n52.geoar.view.geoar.Settings.java
org.n52.geoar.view.geoar.gl.mode.BilligerColorShader.java
org.n52.geoar.view.geoar.gl.mode.BilligerLightShader.java
org.n52.geoar.view.geoar.gl.mode.BilligerTextureShader.java
org.n52.geoar.view.geoar.gl.mode.BoundingBox.java
org.n52.geoar.view.geoar.gl.mode.FeatureShader.java
org.n52.geoar.view.geoar.gl.mode.PhongFeatureShader.java
org.n52.geoar.view.geoar.gl.mode.RenderFeature2.java
org.n52.geoar.view.geoar.gl.mode.Spatial.java
org.n52.geoar.view.geoar.gl.mode.TextureFeatureShader.java
org.n52.geoar.view.geoar.gl.mode.Texture.java
org.n52.geoar.view.geoar.gl.mode.features.CubeFeature2.java
org.n52.geoar.view.geoar.gl.mode.features.FlatCircleFeature.java
org.n52.geoar.view.geoar.gl.mode.features.HeightMapFeature.java
org.n52.geoar.view.geoar.gl.mode.features.NewGridFeature.java
org.n52.geoar.view.geoar.gl.mode.features.ReferencedGridFeature.java
org.n52.geoar.view.geoar.gl.mode.features.SphereFeature.java
org.n52.geoar.view.geoar.gl.mode.features.TriangleFeature.java