Skip to content

Commit

Permalink
fixed issue #7, moved to fragments and Material theme
Browse files Browse the repository at this point in the history
  • Loading branch information
dlukashev committed Jun 21, 2015
1 parent 812d889 commit 7b86939
Show file tree
Hide file tree
Showing 13 changed files with 518 additions and 209 deletions.
3 changes: 2 additions & 1 deletion app/app.iml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/appcompat-v7/22.2.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-v4/22.2.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.google.android.gms/play-services-base/7.5.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.google.android.gms/play-services-location/7.5.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.google.android.gms/play-services-maps/7.5.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/jacoco" />
Expand Down Expand Up @@ -109,9 +110,9 @@
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" exported="" name="play-services-maps-7.5.0" level="project" />
<orderEntry type="library" exported="" name="play-services-base-7.5.0" level="project" />
<orderEntry type="library" exported="" name="nineoldandroids-2.4.0" level="project" />
<orderEntry type="library" exported="" name="support-v4-22.2.0" level="project" />
<orderEntry type="library" exported="" name="support-annotations-22.2.0" level="project" />
<orderEntry type="library" exported="" name="appcompat-v7-22.2.0" level="project" />
<orderEntry type="library" exported="" name="play-services-location-7.5.0" level="project" />
</component>
</module>
5 changes: 3 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ android {
defaultConfig {
minSdkVersion 14
targetSdkVersion 22
versionCode 1
versionName "1.0"
versionCode 2
versionName "1.1"
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.google.android.gms:play-services-location:7.5.0'
compile 'com.google.android.gms:play-services-maps:7.5.0'
compile 'com.android.support:appcompat-v7:22.2.0'
}
Binary file removed app/libs/nineoldandroids-2.4.0.jar
Binary file not shown.
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>

<application
android:name=".TheApp"
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/**
* Copyright 2015-present Amberfog
* <p/>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p/>
* http://www.apache.org/licenses/LICENSE-2.0
* <p/>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.amberfog.mapslidingtest.app;

import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.widget.ListView;

public class LockableListView extends ListView {

private boolean mScrollable = true;

public LockableListView(Context context) {
super(context);
}

public LockableListView(Context context, AttributeSet attrs) {
super(context, attrs);
}

public LockableListView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}

public void setScrollingEnabled(boolean enabled) {
mScrollable = enabled;
}

@Override
public boolean onTouchEvent(MotionEvent ev) {
switch (ev.getAction()) {
case MotionEvent.ACTION_DOWN:
// if we can scroll pass the event to the superclass
if (mScrollable) {
return super.onTouchEvent(ev);
}
// only continue to handle the touch event if scrolling enabled
return mScrollable; // mScrollable is always false at this point
default:
return super.onTouchEvent(ev);
}
}

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
// Don't do anything with intercepted touch events if
// we are not scrollable
if (!mScrollable) {
return false;
} else {
return super.onInterceptTouchEvent(ev);
}
}

}
157 changes: 11 additions & 146 deletions app/src/main/java/com/amberfog/mapslidingtest/app/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/**
* Copyright 2014-present Amberfog
*
* <p/>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* <p/>
* http://www.apache.org/licenses/LICENSE-2.0
* <p/>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand All @@ -16,159 +16,24 @@

package com.amberfog.mapslidingtest.app;

import android.app.Activity;
import android.app.FragmentTransaction;
import android.content.Context;
import android.location.Criteria;
import android.location.Location;
import android.location.LocationManager;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;

import com.google.android.gms.maps.CameraUpdate;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.model.CameraPosition;
import com.google.android.gms.maps.model.LatLng;
import com.sothree.slidinguppanel.SlidingUpPanelLayout;

import java.util.ArrayList;


public class MainActivity extends Activity implements SlidingUpPanelLayout.PanelSlideListener {

private ListView mListView;
private SlidingUpPanelLayout mSlidingUpPanelLayout;

private View mTransparentHeaderView;
private View mTransparentView;
private View mSpaceView;

private MapFragment mMapFragment;

private GoogleMap mMap;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

mListView = (ListView) findViewById(R.id.list);
mListView.setOverScrollMode(ListView.OVER_SCROLL_NEVER);

mSlidingUpPanelLayout = (SlidingUpPanelLayout) findViewById(R.id.slidingLayout);
mSlidingUpPanelLayout.setEnableDragViewTouchEvents(true);

int mapHeight = getResources().getDimensionPixelSize(R.dimen.map_height);
mSlidingUpPanelLayout.setPanelHeight(mapHeight); // you can use different height here
mSlidingUpPanelLayout.setScrollableView(mListView, mapHeight);

mSlidingUpPanelLayout.setPanelSlideListener(this);

// transparent view at the top of ListView
mTransparentView = findViewById(R.id.transparentView);

// init header view for ListView
mTransparentHeaderView = LayoutInflater.from(this).inflate(R.layout.transparent_header_view, null, false);
mSpaceView = mTransparentHeaderView.findViewById(R.id.space);

ArrayList<String> testData = new ArrayList<String>(100);
for (int i = 0; i < 100; i++) {
testData.add("Item " + i);
}
mListView.addHeaderView(mTransparentHeaderView);
mListView.setAdapter(new ArrayAdapter<String>(this, R.layout.simple_list_item, testData));
mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
mSlidingUpPanelLayout.collapsePane();
}
});
collapseMap();

mMapFragment = MapFragment.newInstance();
FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
fragmentTransaction.add(R.id.mapContainer, mMapFragment, "map");
fragmentTransaction.commit();

setUpMapIfNeeded();
}

private void setUpMapIfNeeded() {
// Do a null check to confirm that we have not already instantiated the map.
if (mMap == null) {
// Try to obtain the map from the SupportMapFragment.
mMap = mMapFragment.getMap();
// Check if we were successful in obtaining the map.
if (mMap != null) {
mMap.setMyLocationEnabled(true);
mMap.getUiSettings().setCompassEnabled(false);
mMap.getUiSettings().setZoomControlsEnabled(false);
mMap.getUiSettings().setMyLocationButtonEnabled(false);
CameraUpdate update = getLastKnownLocation();
if (update != null) {
mMap.moveCamera(update);
}
}
}
}

@Override
protected void onResume() {
super.onResume();
// In case Google Play services has since become available.
setUpMapIfNeeded();
}

private CameraUpdate getLastKnownLocation() {
LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_LOW);
String provider = lm.getBestProvider(criteria, true);
if (provider == null) {
return null;
if (savedInstanceState == null) {
FragmentTransaction trans = getSupportFragmentManager().beginTransaction();
trans.add(R.id.fragment, MainFragment.newInstance(null));
trans.commit();
}
Location loc = lm.getLastKnownLocation(provider);
if (loc != null) {
return CameraUpdateFactory.newCameraPosition(CameraPosition.fromLatLngZoom(new LatLng(loc.getLatitude(), loc.getLongitude()), 14.0f));
}
return null;
}

private void collapseMap() {
mSpaceView.setVisibility(View.VISIBLE);
mTransparentView.setVisibility(View.GONE);
}

private void expandMap() {
mSpaceView.setVisibility(View.GONE);
mTransparentView.setVisibility(View.INVISIBLE);
}

@Override
public void onPanelSlide(View view, float v) {
}

@Override
public void onPanelCollapsed(View view) {
expandMap();
mMap.animateCamera(CameraUpdateFactory.zoomTo(14f), 1000, null);
}

@Override
public void onPanelExpanded(View view) {
collapseMap();
mMap.animateCamera(CameraUpdateFactory.zoomTo(11f), 1000, null);
}

@Override
public void onPanelAnchored(View view) {

}
}
Loading

0 comments on commit 7b86939

Please sign in to comment.