Android Panorama Client - How to modify view?

749 views Asked by At


Is there an option to modify the content view on the android panorama client?

For example I want to display the action bar on top. But currently the action bar is just shown at the beginning and subsequently hidden by the loaded panorama client, since the panorama client is always shown in full screen mode, although it is started in an extra fragment.


I tried now to put the panorama client in a seperated frame through a fragment - this is my code so far:


1. This is the activity whit the panorama fragment and and a text field:

public class PanoramaActivity extends Activity {

public static final String TAG = PanoramaActivity.class.getSimpleName();

private ActionBar actionBar;
private Fragment panoramaClient = new PanoramaClientFragment();

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_snow);
    actionBar = getActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);


    FragmentManager fragMan = getFragmentManager();
    FragmentTransaction fragTrans = fragMan.beginTransaction();

    fragTrans.replace(R.id.panoramaCLientFrame, panoramaClient, "PANO");
    fragTrans.commit();

  //Non fullscreen
    requestWindowFeature(Window.FEATURE_ACTION_BAR);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
    getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.panorama, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home: 
        onBackPressed();
        break;

    default:
        return super.onOptionsItemSelected(item);
    }
    return true;
}
}


2.And this is the fragment class with the panorama client:

public class PanoramaClientFragment extends Fragment implements ConnectionCallbacks,
OnConnectionFailedListener, OnPanoramaInfoLoadedListener {

private View view;
private PanoramaClient panoramaClient;

public static final String TAG = PanoramaClientFragment.class.getSimpleName();

public PanoramaClientFragment() {
    // TODO Auto-generated constructor stub
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle     savedInstanteState){
    view = inflater.inflate(R.layout.panorama_client, container, false);
    return view;
}

@Override
public void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    panoramaClient = new PanoramaClient(getActivity().getApplicationContext(), this, this);

//Non fullscreen
//getActivity().requestWindowFeature(Window.FEATURE_ACTION_BAR);
//getActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
//getActivity().getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
}

@Override
public void onStart() {
    super.onStart();
    panoramaClient.connect();
}

@Override
public void onPanoramaInfoLoaded(ConnectionResult result, Intent viewerIntent) {
    if (result.isSuccess()) {
        Log.i(TAG, "found viewerIntent: " + viewerIntent);
        if (viewerIntent != null) {
            startActivity(viewerIntent);
        }
    } else {
        Log.e(TAG, "error: " + result);
    }
}

@Override
public void onConnectionFailed(ConnectionResult status) {
    Log.e(TAG, "connection failed: " + status);
}

@Override
public void onConnected(Bundle arg0) {
    Uri uri = Uri.parse("android.resource://" + this.getActivity().getPackageName() + "/" + R.raw.pano1);
    panoramaClient.loadPanoramaInfo(this, uri); 
}

@Override
public void onDisconnected() {
    // Do nothing.
}

@Override
public void onStop() {
    super.onStop();
    panoramaClient.disconnect();
}
}

If i uncomment the three "non fullscreen"-lines in the fragment class, the app crashes and says:

android.util.AndroidRuntimeException: requestFeature() must be called before adding content


Thanks for your replies. Greetings.

2

There are 2 answers

0
FiLaXx36 On

Try to create a fragment and add the panorama client activity to it.

0
JerothKP On

I think you cannot show the action bar for one simple reason, when your panorama info is loaded you are starting a new activity which is completely out of your control.

if (viewerIntent != null) {
    startActivity(viewerIntent);
}

So your code tries to modify the activity that handles the PanoramaClient instance, but not the one that loads the panorama image.