BeyondAR / beyondar

Augmented Reality framework for Android based on geolocalization ( GPS )
beyondar.com
Apache License 2.0
193 stars 132 forks source link

issue with integrating beyond AR with fragment #60

Open nitin0331 opened 10 years ago

nitin0331 commented 10 years ago

Hi i wanted to add navigation drawer in my app so i wanted to integrate with fragment but getting error

FATAL EXCEPTION: main java.lang.RuntimeException: Unable to start activity ComponentInfo{com.nitin.suche/com.nitin.suche.BaseActivity}: android.view.InflateException: Binary XML file line #18: Error inflating class fragment at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2060) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2085) at android.app.ActivityThread.access$600(ActivityThread.java:130) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:137) at android.app.ActivityThread.main(ActivityThread.java:4747) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:511) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) at dalvik.system.NativeStart.main(Native Method) Caused by: android.view.InflateException: Binary XML file line #18: Error inflating class fragment at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704) at android.view.LayoutInflater.rInflate(LayoutInflater.java:746) at android.view.LayoutInflater.rInflate(LayoutInflater.java:749) at android.view.LayoutInflater.rInflate(LayoutInflater.java:749) at android.view.LayoutInflater.inflate(LayoutInflater.java:489) at android.view.LayoutInflater.inflate(LayoutInflater.java:396) at com.nitin.suche.HomeFragment.onCreateView(HomeFragment.java:52) at android.support.v4.app.Fragment.performCreateView(Fragment.java:1500) at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:938) at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1115) at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682) at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1478) at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:570) at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1163) at android.app.Activity.performStart(Activity.java:5018) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2033) ... 11 more Caused by: java.lang.IllegalArgumentException: Binary XML file line #18: Duplicate id 0x7f05001f, tag null, or parent id 0x0 with another fragment for com.beyondar.android.fragment.BeyondarFragmentSupport at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:296) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:676) ... 26 more

is it due to static fragment already exist in my layout ?

my code is below -

public class HomeFragment extends Fragment implements OnSeekBarChangeListener, OnClickBeyondarObjectListener{ private SeekBar mSeekBarPullCloserDistance, mSeekBarPushAwayDistance, mSeekBarMaxDistanceToRender, mSeekBarDistanceFactor; private TextView mMaxFarText, mMinFarText, mArViewDistanceText, mZfarText; private List showViewOn; private BeyondarFragmentSupport mBeyondarFragment; private World mWorld; private Location location;

public HomeFragment(){

}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    View rootView = null;

    if (rootView == null) {
        rootView = inflater.inflate(R.layout.main, container, false);
        showViewOn = Collections.synchronizedList(new ArrayList<BeyondarObject>());

        mBeyondarFragment = (BeyondarFragmentSupport)getActivity().getSupportFragmentManager().findFragmentById(R.id.beyondarFragment);

// mTextValues = (TextView) rootView.findViewById(R.id.textValues);

        mMaxFarText = (TextView) rootView.findViewById(R.id.textBarMax);
        mMinFarText = (TextView) rootView.findViewById(R.id.textBarMin);
        mArViewDistanceText = (TextView) rootView.findViewById(R.id.textBarArViewDistance);
        mZfarText= (TextView) rootView.findViewById(R.id.textBarZFar);
        mMaxFarText.setText("Pull closer:");
        mMinFarText.setText("Push away:");
        mArViewDistanceText.setText("Max dst render:");
        mZfarText.setText("Dst factor:");

// mRadarView = (RadarView) rootView.findViewById(R.id.radarView); // // // Create the Radar plugin // mRadarPlugin = new RadarWorldPlugin(this); // // set the radar view in to our radar plugin // mRadarPlugin.setRadarView(mRadarView); // // Set how far (in meters) we want to display in the view // mRadarPlugin.setMaxDistance(100); //
// // We can customize the color of the items // mRadarPlugin.setListColor(CustomWorldHelper.LIST_TYPE_EXAMPLE_1, Color.RED); // // and also the size // mRadarPlugin.setListDotRadius(CustomWorldHelper.LIST_TYPE_EXAMPLE_1, 3);

        mSeekBarPullCloserDistance = (SeekBar) rootView.findViewById(R.id.seekBarMax);
        mSeekBarPushAwayDistance = (SeekBar) rootView.findViewById(R.id.seekBarMin);
        mSeekBarMaxDistanceToRender = (SeekBar) rootView.findViewById(R.id.seekBarArViewDistance);
        mSeekBarDistanceFactor = (SeekBar) rootView.findViewById(R.id.seekBarZFar);
        mSeekBarPullCloserDistance.setMax(1000);
        mSeekBarPushAwayDistance.setMax(1000);
        mSeekBarMaxDistanceToRender.setMax(20000); // 20 km
        mSeekBarDistanceFactor.setMax(50000);

        mSeekBarPullCloserDistance.setOnSeekBarChangeListener(this);
        mSeekBarPushAwayDistance.setOnSeekBarChangeListener(this);
        mSeekBarMaxDistanceToRender.setOnSeekBarChangeListener(this);
        mSeekBarDistanceFactor.setOnSeekBarChangeListener(this);

        updateTextValues();

        mSeekBarPushAwayDistance.setProgress(115);
        mSeekBarMaxDistanceToRender.setProgress(20000);
        mSeekBarDistanceFactor.setProgress(50000);

        // We create the world and fill it ...

// mWorld = CustomWorldHelper.generateObjects(this); // // .. and send it to the fragment // mBeyondarFragment.setWorld(mWorld); fetchinglocation(getActivity(), new GetDataCallBack() {

            @Override
            public void processResponse(Object result) {
                location=(Location)result;
                if(location!=null){
                mWorld = new CustomWorldHelper().generateObjects(getActivity(),location,new GetDataCallBack() {
                    @Override
                    public void processResponse(Object result) {
                        // TODO Auto-generated method stub
                        mBeyondarFragment.setWorld(mWorld);
                        CustomBeyondarViewAdapter customBeyondarViewAdapter = new CustomBeyondarViewAdapter(getActivity());
                        mBeyondarFragment.setBeyondarViewAdapter(customBeyondarViewAdapter);
                    mBeyondarFragment.setOnClickBeyondarObjectListener(HomeFragment.this);

// mWorld.addPlugin(mRadarPlugin); // mRadarPlugin.setMaxDistance(100);

                    }
                });
            }
            else{
            Toast.makeText(getActivity(), "Location not available ", Toast.LENGTH_LONG).show();
            }
            }
        });

    }
    return rootView;
}
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
    if (seekBar == mSeekBarPullCloserDistance) {
        mBeyondarFragment.setPullCloserDistance(progress);
    } else if (seekBar == mSeekBarPushAwayDistance) {
        mBeyondarFragment.setPushAwayDistance(progress);
    } else if (seekBar == mSeekBarMaxDistanceToRender) {
        mBeyondarFragment.setMaxDistanceToRender(progress);
    } else if (seekBar == mSeekBarDistanceFactor) {
        mBeyondarFragment.setDistanceFactor(progress);
    }

// if (mRadarPlugin == null) // return; // if (seekBar == mSeekBarPushAwayDistance) { // // float value = ((float) progress/(float) 10000); //// mTextviewMaxDistance.setText("Max distance Value: " + progress); // mRadarPlugin.setMaxDistance(progress); // }

    updateTextValues();
}

private void updateTextValues() {

// mTextValues.setText("dst factor=" + mBeyondarFragment.getDistanceFactor() + " max dst render=" // + mBeyondarFragment.getMaxDistanceToRender() + "\npull closer=" // + mBeyondarFragment.getPullCloserDistance() + " push away=" // + mBeyondarFragment.getPushAwayDistance()); }

@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}

@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}

@Override
public void onClickBeyondarObject(ArrayList<BeyondarObject> beyondarObjects) {
    if (beyondarObjects.size() == 0) {
        return;
    }
    BeyondarObject beyondarObject = beyondarObjects.get(0);
    if (showViewOn.contains(beyondarObject)) {
        showViewOn.remove(beyondarObject);
        showViewOn.removeAll(beyondarObjects);
    } else {
        showViewOn.add(beyondarObject);
    }

}
private class CustomBeyondarViewAdapter extends BeyondarViewAdapter {

    LayoutInflater inflater;

    public CustomBeyondarViewAdapter(Context context) {
        super(context);
        inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    @Override
    public View getView(final BeyondarObject beyondarObject, View recycledView, ViewGroup parent) {
        if (!showViewOn.contains(beyondarObject)) {
            return null;
        }
        if (recycledView == null) {
            recycledView = inflater.inflate(R.layout.beyondar_object_view, null);
        }

        TextView textView = (TextView) recycledView.findViewById(R.id.titleTextView);
        final String nameid[]=beyondarObject.getName().split("###");
        textView.setText(nameid[0]);
        textView.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {

// Intent i=new Intent(SimpleCameraWithMaxFarMinAwayActivity.this, DetailsActivity.class); // i.putExtra("id", nameid[1]); //// i.putExtra("location", location.getLatitude()+","+location.getLongitude()); // startActivity(i); } }); // Button button = (Button) recycledView.rootView.findViewById(R.id.button); // button.setOnClickListener(SimpleCameraWithRadarActivity.this);

        // Once the view is ready we specify the position
        setPosition(beyondarObject.getScreenPositionTopRight());

        return recycledView;
    }

}
private void fetchinglocation(final Activity act,final GetDataCallBack callback){
    final ProgressDialog    progressDialog = new ProgressDialog(act);
        progressDialog.setProgress(0);
        progressDialog.setMax(100);
        progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
        progressDialog.setMessage("Fetching location ...");
        progressDialog.setCancelable(false);
        progressDialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
        if(!progressDialog.isShowing()){
            progressDialog.show();
        }

    MyLocation  myloc = new MyLocation();
        LocationResult lr=new LocationResult() {
            @Override
            public void gotLocation(Location location) {
                if(location!=null){
                    progressDialog.dismiss();
                    callback.processResponse(location);

// locationlatlong=location.getLatitude()+","+location.getLongitude(); } else{ Toast.makeText(act, "lOCATION NOT AVAILABLE", Toast.LENGTH_SHORT).show(); progressDialog.dismiss(); } } }; myloc.getLocation(act, lr); } }

joanpuigsanz commented 10 years ago

Can you upload a test example that I can import to try it? But it looks to me that it is not related to the Beyondar Framework

nitin0331 commented 10 years ago

@joanpuigsanz yes its may be not related to Beyondar Framework but would u plz help me how to integrate this framework with Fragment instead of Activity android

joanpuigsanz commented 10 years ago

Try to upload a zipped project to reproduce the issue and I'll take a look

nitin0331 commented 10 years ago

@joanpuigsanz in which id i can send u the code ?

joanpuigsanz commented 10 years ago

A project that i can import on eclipse or android studio

nitin0331 commented 10 years ago

@joanpuigsanz send me ur id as in comment only image file support yes i will send once i get ur ID

taufikwidhiarto commented 10 years ago

i have same problem.. please tell me how to fix it

nitin0331 commented 10 years ago

@joanpuigsanz @newhuts i also wont able to fix this issue and if u find anything let me know ..

nitin0331 commented 9 years ago

@newhuts have u sort out the issue .

joanpuigsanz commented 9 years ago

Can you upload the project on dropbox and share the link here?