Android Augmented Reality Pro AR 9: activity gets back when displays too many markers

Alessandro

I'm using this very useful tutorial (https://github.com/RaghavSood/ProAndroidAugmentedReality) for developing a custom AR app. It works pretty fine, but when I display markers extracted from a file folder (sometimes) the app gets blocked and restarts from the previous activity. I suppose it's because of the big number of markers situated in the same point of the screen. Infact, when I lower the radius, and then showing a littler number of markers, the activity continues to work. Besides, I've tried to modify the function "getTextWidth()" as many people suggest on the net. I don't know how to reduce the number of Markers drawn on the same point of the screen (so indipendently from reducing the radius). Can you suggest me something? THANKS A LOT!!!!!

I show you the LocalDataSource.java modified:

package com.example.pointofinterests;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.os.AsyncTask;
import android.util.Log;
import android.widget.Toast;

import com.example.pointofinterests.R;
import com.example.pointofinterests.IconMarker;
import com.example.pointofinterests.Marker;

/**
* This class should be used as a example local data source. It is an example of
* how to add data programatically. You can add data either programatically,
* SQLite or through any other source.
* 
* @author Justin Wetherell <[email protected]>
*/
public class LocalDataSource extends DataSource {

    private List<Marker> cachedMarkers = new ArrayList<Marker>();
    private static Bitmap icon = null;

    public LocalDataSource(Resources res) {
        if (res == null) throw new NullPointerException();
            createIcon(res);
    }

    protected void createIcon(Resources res) {
       if (res == null) throw new NullPointerException();
           icon = BitmapFactory.decodeResource(res, R.drawable.icon);
    }

    public List<Marker> getMarkers() {
        try{
        String TestoIDPercorsi = readFileAsString("/sdcard/Epulia/IDPercorsi.txt");
        if(TestoIDPercorsi==""){
           // DOING NOTHING
        }else {
            String[] IDPercorso = TestoIDPercorsi.split("#");
            for(int l=0; l<IDPercorso.length-1; l++){
                String TestoPercorso = readFileAsString("/sdcard/Epulia/Percorso" +          IDPercorso[l] + ".txt");
                if (TestoPercorso.equals("")){
                }else {
                    ArrayList<String> IDSTEPS2 = new ArrayList<String>();
                    String[] temp = TestoPercorso.split("#");
                    for (int j=1; j < temp.length; j++){
                        Log.d("RIGA_" + j + "_" + IDPercorso[l], temp[j]);
                        if(temp[j].substring(0,2).contains("P")){//POI
                            String[] POI = temp[j].split("\\|");
                            String id = POI[1];
                            String description = POI[2];
                            Double lat = Double.parseDouble(POI[3]);
                            Double lng = Double.parseDouble(POI[4]);
                            String type = POI[5];

                            Marker poi = new IconMarker(description, lat,lng, 0, Color.DKGRAY, icon);
                            cachedMarkers.add(poi);

                        }
                    }



                }
            }


        }
    }catch (Exception e){
        Log.e("EXCEPTION", "> " + e);
    }



    return cachedMarkers;
}

public static String readFileAsString(String filePath) {

    String result = "";
    File file = new File(filePath);
    if ( file.exists() ) {
       FileInputStream fis = null;
        try {
           fis = new FileInputStream(file);
            char current;
            while (fis.available() > 0) {
                current = (char) fis.read();
                result = result + String.valueOf(current);

            }

        } catch (Exception e) {
            Log.d("TourGuide", e.toString());
        } finally {
            if (fis != null)
                try {
                    fis.close();
                } catch (IOException ignored) {
            }
        }

   }
    return result;
    }



}
Alessandro

I would like to thank the Author of the Tutorial who helped me in fixing the problem. I report his answer that soled my problem:

Not sure why you have that limitation but this should limit the number of Markers drawn on the screen.

In class AugmentedView.java

You can introduce a new member variable:

private static int MAX_NUM_TO_DRAW = 10;

Then in the method onDraw(Canvas canvas):

You can quit the drawing loop early.

        int i=0;
        ListIterator<Marker> iter = collection.listIterator(collection.size());
        while (iter.hasPrevious() && i<MAX_NUM_TO_DRAW ) {
            Marker marker = iter.previous();
            marker.draw(canvas);
            i++;
        }

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

Android Augmented Reality Pro AR 9:显示太多标记时活动恢复

来自分类Dev

Android Augmented Reality Pro AR 9:显示太多标记时活动恢复

来自分类Dev

我想在Android的vuforia Augmented Reality中更改3D模型

来自分类Dev

迁移到Qualcomm Augmented Reality时的ARCamera问题vuforia-unity-android-ios-3-0-6

来自分类Dev

Too many fetch faliuers

来自分类Dev

Navigating back to Parent activity with toolbar

来自分类Dev

ArangoDB Too many open files

来自分类Dev

Screen goes black when changing activity in Android app

来自分类Dev

Convert bitmask back to 9 booleans

来自分类Dev

Cropped iOS Image comes back too large

来自分类Dev

Entity Framework applying too many migrations

来自分类Dev

MYSQL Too many connections error will not go away

来自分类Dev

Traefik / Portainer-ERR_TOO_MANY_REDIRECTS

来自分类Dev

wordpress:ERR_TOO_MANY_REDIRECTS

来自分类Dev

ERR_TOO_MANY_REDIRECTS - Laravel

来自分类Dev

Open Activity with Linkify Android

来自分类Dev

Android launching wrong activity

来自分类Dev

Android Activity的启动模式

来自分类Dev

Android how to restart an activity

来自分类Dev

无法启动Activity Android

来自分类Dev

Android Activity的启动模式

来自分类Dev

Android Main Activity太慢

来自分类Dev

Android 从 Activity 返回

来自分类Dev

Android Activity 导航错误

来自分类Dev

Android:Activity和Fragment Activity之间的通信

来自分类Dev

Android Fragment Back Stack

来自分类Dev

How do i detect when the back button on an Android action layout is tapped?

来自分类Dev

Visual fox Pro 9.地址的组合框用法

来自分类Dev

How to go to root activity from any fragment by pressing back button?