TRACKING APP: hud overlay animation

This commit is contained in:
Lukas Zielinski committed 2014-12-06 15:39:48 +01:00
1 parent 98969e5350
commit 1a7bbcc68a
7 files changed
+74 -108

No files matched your search

@@ -180,7 +180,7 @@
android:id="@+id/stop_tracking_box"
android:layout_width="fill_parent"
android:layout_height="60dp"
android:layout_alignParentBottom="true"
android:layout_above="@id/bottomLayout"
android:background="@color/gray" >
<View
@@ -204,4 +204,22 @@
android:textStyle="bold" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/bottomLayout"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:background="@color/darker_gray" >
<com.sap.sailing.android.tracking.app.customviews.OpenSansTextView
android:id="@+id/bottom_announcement"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:gravity="center"
android:textColor="@color/white" />
</RelativeLayout>
</RelativeLayout>
@@ -24,16 +24,6 @@
android:textColor="@color/black"
android:textStyle="bold" />
<com.sap.sailing.android.tracking.app.customviews.OpenSansTextView
android:id="@+id/hud_course_label"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="BER: ???°"
android:gravity="center"
android:textColor="@color/black"
android:textStyle="bold" />
<com.sap.sailing.android.tracking.app.customviews.OpenSansTextView
android:id="@+id/hud_speed_label"
android:layout_width="match_parent"
@@ -13,7 +13,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="10dp" >
android:padding="0dp" >
<com.sap.sailing.android.tracking.app.customviews.AutoResizeTextView
android:id="@+id/toolbar_title"
@@ -176,7 +176,7 @@
</ScrollView>
<RelativeLayout
android:id="@+id/start_tracking_box"
android:id="@+id/stop_tracking_box"
android:layout_width="fill_parent"
android:layout_height="100dp"
android:layout_above="@id/bottomLayout"
@@ -82,13 +82,13 @@ public class TrackingActivity extends BaseActivity implements GPSQualityListener
startTrackingService(eventId);
}
// @Override
// public void onWindowFocusChanged(boolean hasFocus) {
// super.onWindowFocusChanged(hasFocus);
// HudFragment hudFragment = (HudFragment) getSupportFragmentManager().findFragmentById(R.id.hud_content_frame);
// hudFragment.layoutOverlay();
// }
//
@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
HudFragment hudFragment = (HudFragment) getSupportFragmentManager().findFragmentById(R.id.hud_content_frame);
hudFragment.layoutOverlay();
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
@@ -17,4 +17,16 @@ public abstract class BaseFragment extends Fragment {
prefs = new AppPreferences(getActivity());
return super.onCreateView(inflater, container, savedInstanceState);
}
protected float dpToPx(float dp)
{
float density = getActivity().getResources().getDisplayMetrics().density;
return dp * density;
}
protected float pxToDp(float px)
{
float density = getActivity().getResources().getDisplayMetrics().density;
return px / density;
}
}
@@ -1,16 +1,15 @@
package com.sap.sailing.android.tracking.app.ui.fragments;
import android.content.res.Configuration;
import android.os.Build;
import android.os.Bundle;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.view.ViewGroup;
import android.view.animation.BounceInterpolator;
import android.view.animation.LinearInterpolator;
import android.view.animation.OvershootInterpolator;
import android.widget.FrameLayout;
import android.widget.RelativeLayout;
import com.sap.sailing.android.tracking.app.R;
@@ -18,6 +17,9 @@ public class HudFragment extends BaseFragment {
private static final String TAG = HudFragment.class.getName();
private float maxTranslateY;
private float minTranslateY;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
@@ -34,105 +36,49 @@ public class HudFragment extends BaseFragment {
/**
* called from activity
*/
// public void layoutOverlay() {
// FrameLayout layout = (FrameLayout)getActivity().findViewById(R.id.hud_content_frame);
//
// Configuration configuration = getActivity().getResources().getConfiguration();
// int screenHeight = configuration.screenHeightDp;
//
// float bottomNotificationBarHeightPx = TypedValue.applyDimension(
// TypedValue.COMPLEX_UNIT_DIP, 40, getActivity().getResources().getDisplayMetrics());
//
//
//
// float actionbarHeightPixels = TypedValue.applyDimension(
// TypedValue.COMPLEX_UNIT_DIP, getActionBarHeight(), getActivity().getResources().getDisplayMetrics());
//
// float translateYPixels = screenHeight / 2; //- bottomNotificationBarHeightPx - actionbarHeightPixels;
// // TODO FIX HUGE MESS.
//
// //FrameLayout.LayoutParams params = (FrameLayout.LayoutParams)layout.getLayoutParams();
// //params.topMargin = Math.round(dpToPx(screenHeight - 100));
// System.out.println("40 in PX = " + dpToPx(40));
// System.out.println("100 in DP = " + pxToDp(100));
// System.out.println("SCREEN HEIGHT IN DP = " + screenHeight);
// System.out.println("SCREEN HEIGHT IN PX = " + dpToPx(screenHeight));
// System.out.println("ACTION BAR IN DP = " + getActionBarHeight());
// System.out.println("ACTION BAR IN PX = " + dpToPx(getActionBarHeight()));
//
// RelativeLayout r = (RelativeLayout) ((ViewGroup) layout.getParent()).getParent();
//
// System.out.println("PARENT HEIGHT = " + r.getHeight());
//
// layout.setTranslationY(Math.round(dpToPx(screenHeight - 40 - pxToDp(getActionBarHeight()) - getStatusBarHeight() )));
// //layout.setTranslationY(dpToPx(screenHeight / 2));
//
// }
private float dpToPx(float dp)
{
float density = getActivity().getResources().getDisplayMetrics().density;
return dp * density;
}
private float pxToDp(float px)
{
float density = getActivity().getResources().getDisplayMetrics().density;
return px / density;
}
private int getStatusBarHeight() {
int result = 0;
int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
if (resourceId > 0) {
result = getResources().getDimensionPixelSize(resourceId);
}
return result;
}
private int getActionBarHeight() {
int actionBarHeight = 0;
TypedValue tv = new TypedValue();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
if (getActivity().getTheme().resolveAttribute(android.R.attr.actionBarSize, tv,
true))
actionBarHeight = TypedValue.complexToDimensionPixelSize(
tv.data, getResources().getDisplayMetrics());
} else {
actionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data,
getResources().getDisplayMetrics());
}
return actionBarHeight;
public void layoutOverlay() {
FrameLayout layout = (FrameLayout)getActivity().findViewById(R.id.hud_content_frame);
maxTranslateY = layout.getHeight()- dpToPx(40);
View modeLabel = (View)getActivity().findViewById(R.id.mode_label);
float heightOfOneDataRow = modeLabel.getHeight();
minTranslateY = layout.getTranslationY() + (heightOfOneDataRow * 2);
layout.setTranslationY(maxTranslateY);
}
class OverlayOnTouchListener implements OnTouchListener {
private float actionBarHeight = 0;
private int xDelta;
private int yDelta;
public OverlayOnTouchListener() {
TypedValue tv = new TypedValue();
if (getActivity().getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true))
{
actionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data,getResources().getDisplayMetrics());
}
}
private int lastTranslation;
@Override
public boolean onTouch(View view, MotionEvent event) {
//FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) view.getLayoutParams();
if (view.getId() != R.id.hud_content_frame) return false;
final int y = (int) event.getRawY();
switch (event.getAction()) {
case MotionEvent.ACTION_MOVE:
view.setTranslationY(y - yDelta);
System.out.println("translationY = " + view.getTranslationY());
int newTranslation = y - yDelta;
if (newTranslation >= minTranslateY && newTranslation < maxTranslateY)
{
view.setTranslationY(newTranslation);
lastTranslation = newTranslation;
}
break;
case MotionEvent.ACTION_UP:
int treshold = Math.round((maxTranslateY - minTranslateY) / 2);
if (lastTranslation < treshold) {
view.animate().translationY(minTranslateY).setDuration(500)
.setInterpolator(new LinearInterpolator()).start();
lastTranslation = (int) minTranslateY;
} else {
view.animate().translationY(maxTranslateY).setDuration(100)
.setInterpolator(new BounceInterpolator()).start();
lastTranslation = (int) maxTranslateY;
}
break;
case MotionEvent.ACTION_DOWN: