Код: Выделить всё
<android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/pager"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="600dp"
android:accessibilityLiveRegion="polite">
<!--
This title strip will display the currently visible page title, as well as the page
titles for adjacent pages.
-->
<android.support.v4.view.PagerTabStrip
android:id="@+id/pager_title_strip"
android:layout_width="match_parent"
android:layout_height="40sp"
android:layout_gravity="top"
android:background="@color/header_bg"
android:paddingBottom="6dp"
android:paddingTop="6dp"
android:paddingLeft="22dp"
android:paddingRight="22dp"
android:textColor="#ffffff"
android:clickable="true"/>
Код: Выделить всё
public class TaskTabListFragment extends Fragment implements OnMapReadyCallback, GoogleMap.OnInfoWindowClickListener,GoogleApiClient.ConnectionCallbacks,
GoogleApiClient.OnConnectionFailedListener, GoogleMap.OnMyLocationChangeListener
{
private RecyclerView mRecyclerView;
private int mPosition;
private MapView mMapV;
private GoogleMap mGMap;
LinearLayout mLayout;
private LatLng mUserLoc;
private Marker mUserMarker;
private SwipeRefreshLayout mSwipeRefLayout;
private ImageView mBackgroundEmpty;
private MapMarkerInfoAdapter mMapInfoAdapter;
public static TaskTabListFragment newInstance(int position)
{
Log.d("TaskTabListFrag ins",""+position);
TaskTabListFragment fragment = new TaskTabListFragment();
Bundle b = new Bundle();
b.putInt("position", position);
fragment.setArguments(b);
return fragment;
}
public TaskTabListFragment()
{
}
@Override
public void onSaveInstanceState(Bundle outState)
{
super.onSaveInstanceState(outState);
mMapV.onSaveInstanceState(outState);
}
@Override
public void onResume()
{
Log.d("onResume",this.toString());
super.onResume();
mMapV.onResume();
if (mGMap != null)
{
refreshTasksList(getActivity(), mPosition);
}
}
@Override
public void onViewStateRestored(Bundle savedInstanceState)
{
super.onViewStateRestored(savedInstanceState);
Log.d("onViewStateRestored",this.toString());
}
@Override
public void onPause()
{
super.onPause();
mMapV.onPause();
}
@Override
public void onMapReady(GoogleMap googleMap)
{
Log.d("onMapready","mPos= "+mPosition);
mGMap = googleMap;
AppLogic.runOnMainThread(new Runnable()
{
@Override
public void run()
{
mGMap.setOnMyLocationChangeListener(TaskTabListFragment.this);
mGMap.setMyLocationEnabled(true);
refreshTasksList(getActivity(), mPosition); // important to call this to setup the adapter.
}
});
}
@Override
public void onInfoWindowClick(Marker marker)
{
Log.d("onInfoWindowClick", marker.getTitle());
try
{
AppLogic.getInstance().showTaskDetails(null, AppData.markersToTaskIndex.get(marker));
}
catch (Exception e)
{
Log.e("onInfoWindowClick",e.toString());
}
}
private void setUpMap()
{
try
{
// Log.d("setUpMap-"+mPosition,Log.getStackTraceString(new Throwable()));
createMarkersForTasks();
}
catch (Exception e)
{
Log.e("setUpMap",e.getLocalizedMessage());
}
}
public void setupMapInfoWindowAdapter()
{
if (mGMap == null)
{
Log.w("setup infoW","bad state gMap == null");
return;
}
Log.d("setup infoWinAdpt",mGMap.toString());
if (mMapInfoAdapter == null)
{
mMapInfoAdapter = new MapMarkerInfoAdapter(AppLogic.getActivityContext().getLayoutInflater());
}
mGMap.setInfoWindowAdapter(mMapInfoAdapter);
mGMap.setOnInfoWindowClickListener(this);
}
private void createMarkersForTasks() throws JSONException
{
if (mGMap == null)
{
Log.d("createMarkersForTasks", "canceling "+mPosition+" -- map="+mGMap);
return;
}
Log.d("createMarkersForTasks", "Map "+mGMap.toString()+" for tab " + mPosition);
mGMap.clear();
JSONObject task;
JSONObject obj;
JSONArray currentTasks = AppData.sTasks[mPosition];
Log.d("createMarkersForTasks","number of markers: "+currentTasks.length());
for (int i = 0; i < currentTasks.length(); i++)
{
task = currentTasks.getJSONObject(i);
obj = task.getJSONObject("property");
String latStr = obj.getString("latitude");
String longStr = obj.getString("longitude");
if (latStr.equalsIgnoreCase("null"))
{
latStr = "0";
}
if (longStr.equalsIgnoreCase("null"))
{
longStr = "0";
}
LatLng location = new LatLng(Double.parseDouble(latStr), Double.parseDouble(longStr));
String ktovetNeces = obj.getString("ktovetNeces");
Marker m = mGMap.addMarker(
new MarkerOptions().position(location).
icon(BitmapDescriptorFactory.fromResource(AppLogic.calcMapIconForTask(task,mPosition)))
);
m.setTitle("כתובת: " + ktovetNeces);
m.setSnippet(AppData.translateActionTypeToDisplayString(task.getInt("actionTypeId")));
AppData.markersToTaskIndex.put(m, i); // store the mapping from marker to taskIndex
}
Log.d("createMarkersForTasks","finished");
}
@Override
public void onConnectionSuspended(int i)
{
Log.d("onConnectionSuspended", "" + i);
}
@Override
public void onConnected(Bundle bundle)
{
Log.d("onConnected", bundle.toString());
}
@Override
public void onConnectionFailed(ConnectionResult connectionResult)
{
Log.d("onConnectionFailed", connectionResult.toString());
}
@Override
public void onMyLocationChange(Location location)
{
mGMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(location.getLatitude(), location.getLongitude()), 14), 500, null);
mGMap.setMyLocationEnabled(false);
mGMap.setOnMyLocationChangeListener(null);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState)
{
View rootView = inflater.inflate(R.layout.tasks_tab_fragment,
container, false);
Bundle b = getArguments();
if (b != null)
{
mPosition = b.getInt("position"); // which tab
}
mLayout = (LinearLayout)rootView.findViewById(R.id.layout);
mMapV = (MapView)rootView.findViewById(R.id.map);
mMapV.onCreate(savedInstanceState);
AppLogic.runOnMainThread(new Runnable()
{
@Override
public void run()
{
//must be from main thread
mMapV.getMapAsync(TaskTabListFragment.this);
}
});
mBackgroundEmpty = (ImageView) rootView.findViewById(R.id.background_empty);
mBackgroundEmpty.setBackgroundColor(getResources().getColor(R.color.bar_bg));
mBackgroundEmpty.setImageResource(AppLogic.calcBackgroundIcon(mPosition));
mRecyclerView = (RecyclerView) rootView.findViewById(R.id.recyclerView);
mSwipeRefLayout = (SwipeRefreshLayout)rootView.findViewById(R.id.swipeRefreshLayout);
mSwipeRefLayout.setTag(mPosition);
mSwipeRefLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener()
{
@Override
public void onRefresh()
{
AppLogic.getInstance().doGetTasks(new GenericCallBack()
{
@Override
public void callBack(Object data)
{
Log.d("onRefresh",""+mSwipeRefLayout.getTag()+" ?? "+AppData.sActiveTaskGroup);
refreshTasksList(null, AppData.sActiveTaskGroup);
mSwipeRefLayout.setRefreshing(false);
AppLogic.hideProgressBar();
}
});
}
});
return rootView;
}
public void onVisible()
{
setupMapInfoWindowAdapter();
}
public void refreshTasksList(final Activity activity, final int tabPosition)
{
Log.d("refreshTasksList", "" + tabPosition+"("+mPosition+")");
if (mRecyclerView == null)
{
return;
}
AppLogic.runOnMainThread(new Runnable()
{
@Override
public void run()
{
Activity localActivity = (activity != null) ? activity : AppLogic.getActivityContext();
if (mRecyclerView.getLayoutManager() == null)
{
mRecyclerView.setLayoutManager(new LinearLayoutManager(localActivity));
}
int direction = AppData.shouldTasksDisplayOnMap ? LinearLayoutManager.HORIZONTAL : LinearLayoutManager.VERTICAL;
LinearLayoutManager layoutManager = (LinearLayoutManager) mRecyclerView.getLayoutManager();
layoutManager.setOrientation(direction);
mRecyclerView.setAdapter(new TasksRecyclerAdapter(tabPosition));
mRecyclerView.getAdapter().notifyDataSetChanged();
setupMapVisibilityIfNeeded();
setupEmptyListImageIfNeeded();
}
});
}
private void setupMapVisibilityIfNeeded()
{
final float scale = getResources().getDisplayMetrics().density;
if (mGMap != null)
{
ViewGroup.LayoutParams params = mMapV.getLayoutParams();
if (AppData.shouldTasksDisplayOnMap)
{
params.height = (int)(340 * scale);
mMapV.setLayoutParams(params);
mMapV.setVisibility(View.VISIBLE);
Log.d("setupMapVisibilityIfNe","setting map "+mPosition);
setUpMap();
onVisible();
}
else
{
params.height = 0;
mMapV.setLayoutParams(params);
mMapV.setVisibility(View.INVISIBLE);
}
}
}
private void setupEmptyListImageIfNeeded()
{
if (mBackgroundEmpty != null)
{
// Log.d("refresh",""+tabPosition+" has "+mRecyclerView.getAdapter().getItemCount()+" items");
if (mRecyclerView.getAdapter().getItemCount() == 0)
{
mBackgroundEmpty.setVisibility(View.VISIBLE);
mRecyclerView.setVisibility(View.GONE);
}
else
{
mBackgroundEmpty.setVisibility(View.GONE);
mRecyclerView.setVisibility(View.VISIBLE);
}
}
}
class MapMarkerInfoAdapter implements InfoWindowAdapter
{
private View info = null;
private LayoutInflater inflater = null;
MapMarkerInfoAdapter(LayoutInflater inflater)
{
this.inflater=inflater;
}
@Override
public View getInfoWindow(Marker marker) {
return(null);
}
@SuppressLint("InflateParams")
@Override
public View getInfoContents(Marker marker)
{
try
{
Log.d("getInfoContents",marker.toString());
if (info == null)
{
info = inflater.inflate(R.layout.map_marker_info, null);
}
TextView tv = (TextView) info.findViewById(R.id.title);
tv.setText(marker.getTitle());
tv = (TextView) info.findViewById(R.id.task_description);
tv.setText(marker.getSnippet());
tv = (TextView) info.findViewById(R.id.date_status);
Integer taskIndexInteger = AppData.markersToTaskIndex.get(marker);
if (taskIndexInteger != null)
{
int taskIndex = taskIndexInteger;
tv.setText(AppLogic.calcTaskStatus(taskIndex));
}
else
{
Log.w("getInfoContents", "inconsistent state taskIndexInteger == null");
Log.d("marker", marker.toString());
Log.d("markersToIndex", AppData.markersToTaskIndex.toString());
Log.d("Task Group", "" + AppData.sActiveTaskGroup);
AppLogic.getInstance().showPopup("Ooops");
}
}
catch (Exception e)
{
Log.e("getInfoContents",e.toString());
}
return(info);
}
}
}
и второй вопрос как переместить карту в левой край ?


