Android Open Source - android-augment-reality-framework Demo






From Project

Back to project page android-augment-reality-framework.

License

The source code is released under:

GNU General Public License

If you think the Android project android-augment-reality-framework 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

package com.jwetherell.augmented_reality.activity;
//from   w w  w  . j a v a  2  s . c om
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.RejectedExecutionException;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

import android.graphics.Color;
import android.location.Location;
import android.os.Bundle;
import android.util.Log;
import android.view.Gravity;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.ViewGroup.LayoutParams;
import android.widget.LinearLayout;
import android.widget.Toast;

import com.jwetherell.augmented_reality.R;
import com.jwetherell.augmented_reality.data.ARData;
import com.jwetherell.augmented_reality.data.GooglePlacesDataSource;
import com.jwetherell.augmented_reality.data.LocalDataSource;
import com.jwetherell.augmented_reality.data.NetworkDataSource;
import com.jwetherell.augmented_reality.data.WikipediaDataSource;
import com.jwetherell.augmented_reality.ui.Marker;
import com.jwetherell.augmented_reality.widget.VerticalTextView;

/**
 * This class extends the AugmentedReality and is designed to be an example on
 * how to extends the AugmentedReality class to show multiple data sources.
 * 
 * @author Justin Wetherell <phishman3579@gmail.com>
 */
public class Demo extends AugmentedReality {
  
    private static final String TAG = "Demo";
    private static final String locale = Locale.getDefault().getLanguage();
    private static final BlockingQueue<Runnable> queue = new ArrayBlockingQueue<Runnable>(1);
    private static final ThreadPoolExecutor exeService = new ThreadPoolExecutor(1, 1, 20, TimeUnit.SECONDS, queue);
    private static final Map<String, NetworkDataSource> sources = new ConcurrentHashMap<String, NetworkDataSource>();

    private static Toast myToast = null;
    private static VerticalTextView text = null;

    /**
     * {@inheritDoc}
     */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // Create toast
        myToast = new Toast(getApplicationContext());
        myToast.setGravity(Gravity.CENTER, 0, 0);
        // Creating our custom text view, and setting text/rotation
        text = new VerticalTextView(getApplicationContext());
        LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
        text.setLayoutParams(params);
        text.setBackgroundResource(android.R.drawable.toast_frame);
        text.setTextAppearance(getApplicationContext(), android.R.style.TextAppearance_Small);
        text.setShadowLayer(2.75f, 0f, 0f, Color.parseColor("#BB000000"));
        myToast.setView(text);
        // Setting duration and displaying the toast
        myToast.setDuration(Toast.LENGTH_SHORT);

        // Local
        LocalDataSource localData = new LocalDataSource(this.getResources());
        ARData.addMarkers(localData.getMarkers());

        NetworkDataSource wikipedia = new WikipediaDataSource(this.getResources());
        sources.put("wiki", wikipedia);
        NetworkDataSource googlePlaces = new GooglePlacesDataSource(this.getResources());
        sources.put("googlePlaces", googlePlaces);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public void onStart() {
        super.onStart();

        Location last = ARData.getCurrentLocation();
        updateData(last.getLatitude(), last.getLongitude(), last.getAltitude());
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.menu, menu);
        return true;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        Log.v(TAG, "onOptionsItemSelected() item=" + item);
        switch (item.getItemId()) {
            case R.id.showRadar:
                showRadar = !showRadar;
                item.setTitle(((showRadar) ? "Hide" : "Show") + " Radar");
                break;
            case R.id.showZoomBar:
                showZoomBar = !showZoomBar;
                item.setTitle(((showZoomBar) ? "Hide" : "Show") + " Zoom Bar");
                zoomLayout.setVisibility((showZoomBar) ? LinearLayout.VISIBLE : LinearLayout.GONE);
                break;
            case R.id.exit:
                finish();
                break;
        }
        return true;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public void onLocationChanged(Location location) {
        super.onLocationChanged(location);

        updateData(location.getLatitude(), location.getLongitude(), location.getAltitude());
    }

    /**
     * {@inheritDoc}
     */
    @Override
    protected void markerTouched(Marker marker) {
        text.setText(marker.getName());
        myToast.show();
    }

    /**
     * {@inheritDoc}
     */
    @Override
    protected void updateDataOnZoom() {
        super.updateDataOnZoom();
        Location last = ARData.getCurrentLocation();
        updateData(last.getLatitude(), last.getLongitude(), last.getAltitude());
    }

    private void updateData(final double lat, final double lon, final double alt) {
        try {
            exeService.execute(new Runnable() {
                @Override
                public void run() {
                    for (NetworkDataSource source : sources.values())
                        download(source, lat, lon, alt);
                }
            });
        } catch (RejectedExecutionException rej) {
            Log.w(TAG, "Not running new download Runnable, queue is full.");
        } catch (Exception e) {
            Log.e(TAG, "Exception running download Runnable.", e);
        }
    }

    private static boolean download(NetworkDataSource source, double lat, double lon, double alt) {
        if (source == null) return false;

        String url = null;
        try {
            url = source.createRequestURL(lat, lon, alt, ARData.getRadius(), locale);
        } catch (NullPointerException e) {
            return false;
        }

        List<Marker> markers = null;
        try {
            markers = source.parse(url);
        } catch (NullPointerException e) {
            return false;
        }

        ARData.addMarkers(markers);
        return true;
    }
}




Java Source Code List

com.jwetherell.augmented_reality.activity.AugmentedReality.java
com.jwetherell.augmented_reality.activity.AugmentedView.java
com.jwetherell.augmented_reality.activity.Demo.java
com.jwetherell.augmented_reality.activity.SensorsActivity.java
com.jwetherell.augmented_reality.camera.CameraCompatibility.java
com.jwetherell.augmented_reality.camera.CameraModel.java
com.jwetherell.augmented_reality.camera.CameraSurface.java
com.jwetherell.augmented_reality.common.LowPassFilter.java
com.jwetherell.augmented_reality.common.Matrix.java
com.jwetherell.augmented_reality.common.Navigation.java
com.jwetherell.augmented_reality.common.Orientation.java
com.jwetherell.augmented_reality.common.ReusableString.java
com.jwetherell.augmented_reality.common.Vector.java
com.jwetherell.augmented_reality.data.ARData.java
com.jwetherell.augmented_reality.data.BuzzDataSource.java
com.jwetherell.augmented_reality.data.DataSource.java
com.jwetherell.augmented_reality.data.GooglePlacesDataSource.java
com.jwetherell.augmented_reality.data.LocalDataSource.java
com.jwetherell.augmented_reality.data.NetworkDataSource.java
com.jwetherell.augmented_reality.data.PhysicalLocation.java
com.jwetherell.augmented_reality.data.ScreenPosition.java
com.jwetherell.augmented_reality.data.TwitterDataSource.java
com.jwetherell.augmented_reality.data.WikipediaDataSource.java
com.jwetherell.augmented_reality.ui.IconMarker.java
com.jwetherell.augmented_reality.ui.Marker.java
com.jwetherell.augmented_reality.ui.Radar.java
com.jwetherell.augmented_reality.ui.objects.PaintableBox.java
com.jwetherell.augmented_reality.ui.objects.PaintableBoxedText.java
com.jwetherell.augmented_reality.ui.objects.PaintableCircle.java
com.jwetherell.augmented_reality.ui.objects.PaintableGps.java
com.jwetherell.augmented_reality.ui.objects.PaintableIcon.java
com.jwetherell.augmented_reality.ui.objects.PaintableLine.java
com.jwetherell.augmented_reality.ui.objects.PaintableObject.java
com.jwetherell.augmented_reality.ui.objects.PaintablePoint.java
com.jwetherell.augmented_reality.ui.objects.PaintablePosition.java
com.jwetherell.augmented_reality.ui.objects.PaintableRadarPoints.java
com.jwetherell.augmented_reality.ui.objects.PaintableText.java
com.jwetherell.augmented_reality.widget.VerticalSeekBar.java
com.jwetherell.augmented_reality.widget.VerticalTextView.java