Merge pull request #1013 from Bars107/master
Floating button will now dissapaer when scroll down and appear when scro...
This commit is contained in:
commit
a1f5d2c6cd
2 changed files with 35 additions and 1 deletions
|
@ -2,6 +2,7 @@
|
||||||
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:layout_height="fill_parent"
|
android:layout_height="fill_parent"
|
||||||
|
android:id="@+id/main_scroll"
|
||||||
android:background="@color/dashboard_background" >
|
android:background="@color/dashboard_background" >
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
|
|
|
@ -9,6 +9,8 @@ import java.util.Random;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.view.Gravity;
|
import android.view.Gravity;
|
||||||
|
import android.view.ViewTreeObserver;
|
||||||
|
import android.widget.LinearLayout;
|
||||||
import net.osmand.Location;
|
import net.osmand.Location;
|
||||||
import net.osmand.access.AccessibleAlertBuilder;
|
import net.osmand.access.AccessibleAlertBuilder;
|
||||||
import net.osmand.plus.OsmAndAppCustomization;
|
import net.osmand.plus.OsmAndAppCustomization;
|
||||||
|
@ -113,7 +115,7 @@ public class MainMenuActivity extends BaseDownloadActivity implements OsmAndLoca
|
||||||
setupContributionVersion();
|
setupContributionVersion();
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
|
||||||
FloatingActionButton fabButton = new FloatingActionButton.Builder(this)
|
final FloatingActionButton fabButton = new FloatingActionButton.Builder(this)
|
||||||
.withDrawable(getResources().getDrawable(R.drawable.ic_action_map))
|
.withDrawable(getResources().getDrawable(R.drawable.ic_action_map))
|
||||||
.withButtonColor(Color.parseColor("#ff8f00"))
|
.withButtonColor(Color.parseColor("#ff8f00"))
|
||||||
.withGravity(Gravity.BOTTOM | Gravity.RIGHT)
|
.withGravity(Gravity.BOTTOM | Gravity.RIGHT)
|
||||||
|
@ -125,6 +127,37 @@ public class MainMenuActivity extends BaseDownloadActivity implements OsmAndLoca
|
||||||
startMapActivity();
|
startMapActivity();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
final ScrollView mainScroll = (ScrollView) findViewById(R.id.main_scroll);
|
||||||
|
if (mainScroll == null){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
mainScroll.getViewTreeObserver().addOnScrollChangedListener(new ViewTreeObserver.OnScrollChangedListener() {
|
||||||
|
private int previousScroll = 0;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onScrollChanged() {
|
||||||
|
int scrollY = mainScroll.getScrollY();
|
||||||
|
if (previousScroll == scrollY){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (scrollY > previousScroll && previousScroll >= 0){
|
||||||
|
if (!fabButton.isHidden() ){
|
||||||
|
fabButton.hideFloatingActionButton();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
int layoutHeight = mainScroll.getChildAt(0).getMeasuredHeight();
|
||||||
|
int scrollHeight = scrollY + mainScroll.getHeight();
|
||||||
|
//scroll can actually be more than entire layout height
|
||||||
|
if (fabButton.isHidden() && scrollHeight < layoutHeight){
|
||||||
|
fabButton.showFloatingActionButton();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
previousScroll = scrollY;
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue