Android Open Source - geoar-app Intro Viewer






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
 *//w  w w  .j  a va 2  s . co  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.ar.view;

import org.n52.geoar.R;
import org.n52.geoar.ar.view.IntroController.Task;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.PorterDuff.Mode;
import android.graphics.PorterDuffXfermode;
import android.graphics.RadialGradient;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.Shader;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

/**
 * 
 * @author Arne de Wall <a.dewall@52North.org>
 *
 */
public class IntroViewer extends RelativeLayout implements View.OnTouchListener {

  private Activity activity;
  private Task currentStep;

  private RelativeLayout descriptionView;
  private View skipButton;
  private View startButton;

  // painting stuff
  private final int backgroundColor = Color.argb(150, 15, 15, 60);
  private final Paint transparentPainter;
  private Drawable pointerSpot;
  private Bitmap viewIndicator;

  private Rect pointerSpotRect;
  private Rect viewRect;
  private RectF transparentRect;

  /** drawing stuff */
  private float viewCenterX = -1f;
  private float viewCenterY = -1f;
  
  public IntroViewer(final Activity activity, final String title,
      final String description) {
    super(activity);
    this.activity = activity;
    descriptionView = (RelativeLayout) LayoutInflater.from(activity)
        .inflate(R.layout.intro_description, this);
    setDescriptionView(title, description, null);

    skipButton = descriptionView.findViewById(R.id.intro_skipButton);
    skipButton.setOnTouchListener(this);
    startButton = descriptionView.findViewById(R.id.intro_startButton);
    startButton.setOnTouchListener(this);

    // Init painting Stuff
    transparentPainter = new Paint();
    transparentPainter.setAlpha(255);
    transparentPainter.setXfermode(new PorterDuffXfermode(Mode.MULTIPLY));

    pointerSpot = activity.getResources().getDrawable(
        R.drawable.pointer_spot_hover);
    viewIndicator = BitmapFactory.decodeResource(getResources(),
        R.drawable.hand);

    setOnTouchListener(this);
  }

  void updateView(final Task step) {
    // update description
    currentStep = step;
    final String t = getResources().getString(step.id);
    final String d = getResources().getString(step.description);
    final Bitmap b = step.bitmapResource == 0 ? null : BitmapFactory
        .decodeResource(getResources(), step.bitmapResource);

    this.postDelayed(new Runnable() {

      @Override
      public void run() {
        setDescriptionView(t, d, b);
        // update highlightedView
        if (step.view != null) {
          // activity.getWindow().getDecorView().postInvalidate();
          setEmphasizedView(step.view);
        }
        activity.getWindow().getDecorView().postInvalidate();
        setVisibility(View.VISIBLE);
        IntroViewer.this.invalidate();
      }
    }, 100);
  }

  private void setDescriptionView(String title, String description,
      Bitmap bitmap) {
    TextView titleTextView = (TextView) descriptionView
        .findViewById(R.id.intro_titleTextView);
    TextView descTextView = (TextView) descriptionView
        .findViewById(R.id.intro_descriptionTextView);
    ImageView descImage = (ImageView) descriptionView
        .findViewById(R.id.intro_imageView);

    titleTextView.setText(title);
    descTextView.setText(description);

    if (bitmap != null) {
      descImage.setImageBitmap(bitmap);
      descImage.setVisibility(View.VISIBLE);
    } else {
      descImage.setVisibility(View.GONE);
    }
  }

  private void setEmphasizedView(View view) {
    int[] screenPos = new int[2];
    view.getLocationOnScreen(screenPos);

    int viewWidth = view.getWidth();
    int viewHeight = view.getHeight();

    // calculate the BoundingBox of the View
    viewRect = new Rect(screenPos[0], screenPos[1], screenPos[0]
        + viewWidth, screenPos[1] + viewHeight);

    viewCenterX = (float) (screenPos[0] + viewWidth / 2);
    viewCenterY = (float) (screenPos[1] + viewHeight / 2);

    int pointerWidth = pointerSpot.getIntrinsicWidth();
    int pointerHeight = pointerSpot.getIntrinsicHeight();

    pointerSpotRect = new Rect((int) (viewCenterX - pointerWidth / 2),
        (int) (viewCenterY - pointerHeight / 2),
        (int) (viewCenterX + pointerWidth / 2),
        (int) (viewCenterY + pointerHeight / 2));

    transparentRect = new RectF(screenPos[0], screenPos[1], screenPos[0]
        + viewWidth, screenPos[1] + viewHeight);
  }




  @Override
  protected void dispatchDraw(Canvas canvas) {
    if (currentStep != null && currentStep.view != null) {
      if (viewCenterX < 0 && viewCenterY < 0) {
        super.dispatchDraw(canvas);
        return;
      } else if (viewCenterX <= 0 || viewCenterY <= 0) {
        setEmphasizedView(currentStep.view);
        int[] screenPos = new int[2];
        currentStep.view.getLocationOnScreen(screenPos);

        currentStep.view.getLeft();
        currentStep.view.getLocationInWindow(screenPos);
        int x = 0;
      }

      int width = getMeasuredWidth();
      int height = getMeasuredHeight();
      transparentPainter.setShader(new RadialGradient(viewCenterX,
          viewCenterY, 200f, 0xFFFFFF,
          Color.argb(255, 255, 255, 255), Shader.TileMode.CLAMP));

      Bitmap b = Bitmap.createBitmap(width, height,
          Bitmap.Config.ARGB_8888);
      Canvas c = new Canvas(b);
      c.drawColor(backgroundColor);
      c.drawCircle(viewCenterX, viewCenterY, 200f, transparentPainter);

      c.save();
      c.scale(2, 2, viewCenterX, viewCenterY);
      pointerSpot.setBounds(pointerSpotRect);
      pointerSpot.draw(c);
      c.restore();
      
      c.drawBitmap(viewIndicator, viewCenterX, viewCenterY, null);
      canvas.drawBitmap(b, 0, 0, null);
      c.setBitmap(null);
      b.recycle();
      b = null;
    }
    super.dispatchDraw(canvas);
  }

  @Override
  public boolean onTouch(View v, MotionEvent event) {

    final float eventCoordX = event.getRawX();
    final float eventCoordY = event.getRawY();

    int[] pos = new int[2];

    // check skipButton;
    skipButton.getLocationOnScreen(pos);

    int top = pos[1], bottom = pos[1] + skipButton.getHeight();
    int left = pos[0], right = pos[0] + skipButton.getWidth();

    if (top < eventCoordY && bottom > eventCoordY && left < eventCoordX
        && right > eventCoordX) {
      descriptionView.setVisibility(View.GONE);
      IntroViewer.this.setVisibility(View.GONE);
      IntroController.skipIntro();
      return true;
    }

    // check startButton;
    startButton.getLocationOnScreen(pos);

    top = pos[1];
    bottom = pos[1] + startButton.getHeight();
    left = pos[0];
    right = pos[0] + startButton.getWidth();

    if (!IntroController.isActivated && top < eventCoordY && bottom > eventCoordY
        && left < eventCoordX && right > eventCoordX) {
      IntroController.isActivated = true;
      IntroController.handler.start();
      startButton.setVisibility(View.GONE);
      return true;
    }

    // check view
    if (viewRect != null)
      if ((eventCoordX >= viewRect.left)
          && (eventCoordX <= viewRect.right)
          && (eventCoordY >= viewRect.top)
          && (eventCoordY <= viewRect.bottom)) {
        viewCenterX = 0;
        viewCenterY = 0;
      }
    return false;
  }
}




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