If you think the Android project arcgis-runtime-samples-android 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 2014 ESRI
*/*www.java2s.com*/
* All rights reserved under the copyright laws of the United States
* and applicable international laws, treaties, and conventions.
*
* You may freely redistribute and use this sample code, with or
* without modification, provided you include the original copyright
* notice and use restrictions.
*
* See the Sample code usage restrictions document for further information.
*
*/package com.arcgis.android.samples.oauth2sample;
import android.app.Activity;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.FrameLayout;
import android.widget.ProgressBar;
import android.widget.Toast;
import com.esri.android.map.MapView;
import com.esri.android.map.event.OnStatusChangedListener;
import com.esri.core.map.CallbackListener;
import com.esri.core.portal.WebMap;
publicclass MapFragment extends Fragment {
protectedstaticfinal String TAG = "MapFragment";
private String mItemId;
@SuppressWarnings("unused")
private OnFragmentInteractionListener_MapFragment mListener;
View mUserMapView;
MapView mMap;
ProgressBar mProgressBar;
protectedstaticfinalint CLOSE_LOADING_WINDOW = 0;
/**
* factory method to create a new instance of this fragment using the provided
* parameters.
*
* @param itemId
* @return A new instance of fragment MapFragment.
*/publicstatic MapFragment newInstance(String itemId) {
MapFragment fragment = new MapFragment();
Bundle args = new Bundle();
args.putString("ItemId", itemId);
fragment.setArguments(args);
return fragment;
}
public MapFragment() {
// Required empty public constructor
}
@Override
publicvoid onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getArguments() != null) {
mItemId = getArguments().getString("ItemId");
}
// create a new instance of the webmap from item
// the webmap will be created in the callback
WebMap.newInstance(mItemId, UserContentActivity.mMyPortal, new CallbackListener<WebMap>() {
@Override
publicvoid onError(Throwable e) {
Log.e(TAG, "Error instantiating WebMap", e);
}
@Override
publicvoid onCallback(final WebMap webmap) {
// Add the mapview in the ui thread.
getActivity().runOnUiThread(new Runnable() {
@Override
publicvoid run() {
if (webmap != null) {
mMap = new MapView(getActivity(), webmap, null, null);
mMap.setOnStatusChangedListener(new OnStatusChangedListener() {
privatestaticfinallong serialVersionUID = 1L;
@Override
publicvoid onStatusChanged(Object source, STATUS status) {
if (status.getValue() == EsriStatusException.INIT_FAILED_WEBMAP_UNSUPPORTED_LAYER) {
Toast.makeText(getActivity(), "Webmap failed to load", Toast.LENGTH_SHORT).show();
}
}
});
// set the visibility of progress bar to
// invisible
mProgressBar.setVisibility(View.INVISIBLE);
// add the mapview to the fragment
((ViewGroup) getView()).addView(mMap, new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT,
LayoutParams.MATCH_PARENT));
}
}
});
}
});
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// Inflate the layout for this fragment
mUserMapView = inflater.inflate(R.layout.fragment_map, container, false);
mProgressBar = (ProgressBar) mUserMapView.findViewById(R.id.progress);
mProgressBar.setVisibility(View.VISIBLE);
return mUserMapView;
}
@Override
publicvoid onAttach(Activity activity) {
super.onAttach(activity);
try {
mListener = (OnFragmentInteractionListener_MapFragment) activity;
} catch (ClassCastException e) {
thrownew ClassCastException(activity.toString() + " must implement OnFragmentInteractionListener");
}
}
@Override
publicvoid onDetach() {
super.onDetach();
mListener = null;
}
@Override
publicvoid onDestroyView() {
super.onDestroyView();
}
publicinterface OnFragmentInteractionListener_MapFragment {
publicvoid onFragmentInteraction(Uri uri);
}
}