Example usage for android.graphics Point offset

List of usage examples for android.graphics Point offset

Introduction

In this page you can find the example usage for android.graphics Point offset.

Prototype

public final void offset(int dx, int dy) 

Source Link

Document

Offset the point's coordinates by dx, dy

Usage

From source file:com.cyrilmottier.android.polaris2demo.MarkerDemoActivity.java

@Override
public boolean onMarkerClick(final Marker marker) {
    // This causes the marker at Perth to bounce into position when it is clicked.
    if (marker.equals(mPerth)) {
        final Handler handler = new Handler();
        final long start = SystemClock.uptimeMillis();
        Projection proj = mMap.getProjection();
        Point startPoint = proj.toScreenLocation(PERTH);
        startPoint.offset(0, -100);
        final LatLng startLatLng = proj.fromScreenLocation(startPoint);
        final long duration = 1500;

        final Interpolator interpolator = new BounceInterpolator();

        handler.post(new Runnable() {
            @Override/*from w w  w . j av  a 2s .co  m*/
            public void run() {
                long elapsed = SystemClock.uptimeMillis() - start;
                float t = interpolator.getInterpolation((float) elapsed / duration);
                double lng = t * PERTH.longitude + (1 - t) * startLatLng.longitude;
                double lat = t * PERTH.latitude + (1 - t) * startLatLng.latitude;
                marker.setPosition(new LatLng(lat, lng));

                if (t < 1.0) {
                    // Post again 16ms later.
                    handler.postDelayed(this, 16);
                }
            }
        });
    }
    // We return false to indicate that we have not consumed the event and that we wish
    // for the default behavior to occur (which is for the camera to move such that the
    // marker is centered and for the marker's info window to open, if it has one).
    return false;
}

From source file:crackerjack.education.Indijisites.StartUp.java

@Override
public boolean onMarkerClick(final Marker marker) {
    // This method makes the marker bounce when you click on it. It's not really needed, but it's a neat feature.
    // Will expand this if offered more time.
    if (marker.equals(mBrisbane)) {
        final Handler handler = new Handler();
        final long start = SystemClock.uptimeMillis();
        Projection proj = mMap.getProjection();
        Point startPoint = proj.toScreenLocation(BRISBANE);
        startPoint.offset(0, -100);
        final LatLng startLatLng = proj.fromScreenLocation(startPoint);
        final long duration = 1500;

        final Interpolator interpolator = new BounceInterpolator();

        handler.post(new Runnable() {
            @Override/*  w w  w .  j a v a  2 s  .  c om*/
            public void run() {
                long elapsed = SystemClock.uptimeMillis() - start;
                float t = interpolator.getInterpolation((float) elapsed / duration);
                double lng = t * BRISBANE.longitude + (1 - t) * startLatLng.longitude; // This allows the marker to pinpoint if offscreen (I think =/)
                double lat = t * BRISBANE.latitude + (1 - t) * startLatLng.latitude;
                marker.setPosition(new LatLng(lat, lng));

                if (t < 1.0) {
                    // Post again 16ms later
                    handler.postDelayed(this, 16);
                }
            }
        });
    }
    //False is returned to indicate we have not consumed the event and that we wish
    //for the default behaviour to occur (move to marker location).
    return false;
}

From source file:com.waz.zclient.pages.main.RootFragment.java

@Override
public void onShowUserProfile(User user, View anchorView) {
    if (LayoutSpec.isPhone(getActivity())) {
        return;//  w  w  w .  ja v  a2 s  .c o m
    }

    final Rect outRect = new Rect();
    anchorView.getDrawingRect(outRect);

    final Point locationOnScreen = ViewUtils.getLocationOnScreen(anchorView);
    final Point rootViewLocation = ViewUtils
            .getLocationOnScreen(ViewUtils.getView(getActivity(), R.id.fl_main_content));

    locationOnScreen.offset(-rootViewLocation.x, -rootViewLocation.y);

    final int posX = locationOnScreen.x;
    final int posY = locationOnScreen.y;

    getChildFragmentManager().beginTransaction()
            .replace(R.id.fl__root__participant_container,
                    ParticipantsDialogFragment.newAvatarPopoverInstance(posX, posY, outRect, user.getId()),
                    ParticipantsDialogFragment.TAG)
            .commit();
}

From source file:com.waz.zclient.pages.main.RootFragment.java

@Override
public void onShowPickUser(IPickUserController.Destination destination, View anchorView) {
    if (LayoutSpec.isPhone(getActivity()) || anchorView == null
            || !destination.equals(IPickUserController.Destination.CURSOR)) {
        return;//  w  w  w .  ja v a2s .com
    }

    final Rect outRect = new Rect();
    anchorView.getDrawingRect(outRect);
    final Point locationOnScreen = ViewUtils.getLocationOnScreen(anchorView);
    final Point rootViewLocation = ViewUtils
            .getLocationOnScreen(ViewUtils.getView(getActivity(), R.id.fl_main_content));

    locationOnScreen.offset(-rootViewLocation.x, -rootViewLocation.y);

    final int posX = locationOnScreen.x;
    final int posY = locationOnScreen.y;
    if (!groupConversation && otherUser != null) {
        getControllerFactory().getPickUserController().addUser(otherUser);
    }
    getControllerFactory().getConversationScreenController()
            .setPopoverLaunchedMode(DialogLaunchMode.PARTICIPANT_BUTTON);
    getChildFragmentManager().beginTransaction()
            .replace(R.id.fl__root__participant_container,
                    ParticipantsDialogFragment.newStartUiInstance(posX, posY, outRect, groupConversation),
                    ParticipantsDialogFragment.TAG)
            .commit();
}

From source file:com.waz.zclient.pages.main.RootFragment.java

@Override
public void onShowParticipants(View anchorView, boolean isSingleConversation, boolean isMemberOfConversation,
        boolean showDeviceTabSingle) {
    if (LayoutSpec.isPhone(getActivity()) || anchorView == null) {
        return;/* w w w .  j av  a  2 s.c  o  m*/
    }

    final Rect outRect = new Rect();
    anchorView.getDrawingRect(outRect);
    final Point locationOnScreen = ViewUtils.getLocationOnScreen(anchorView);
    final Point rootViewLocation = ViewUtils
            .getLocationOnScreen(ViewUtils.getView(getActivity(), R.id.fl_main_content));

    locationOnScreen.offset(-rootViewLocation.x, -rootViewLocation.y);

    final int posX = locationOnScreen.x;
    final int posY = locationOnScreen.y;
    if (anchorView instanceof Toolbar) {
        getControllerFactory().getConversationScreenController()
                .setPopoverLaunchedMode(DialogLaunchMode.CONVERSATION_TOOLBAR);
    } else {
        getControllerFactory().getConversationScreenController()
                .setPopoverLaunchedMode(DialogLaunchMode.PARTICIPANT_BUTTON);
    }
    int firstPage = (isSingleConversation && showDeviceTabSingle) ? TabbedParticipantBodyFragment.DEVICE_PAGE
            : TabbedParticipantBodyFragment.USER_PAGE;
    getChildFragmentManager().beginTransaction()
            .replace(R.id.fl__root__participant_container,
                    ParticipantsDialogFragment.newParticipantButtonInstance(posX, posY, outRect, firstPage),
                    ParticipantsDialogFragment.TAG)
            .commit();
}

From source file:org.chromium.chrome.browser.ntp.NewTabPageView.java

/**
 * Get the bounds of the search box in relation to the top level NewTabPage view.
 *
 * @param bounds The current drawing location of the search box.
 * @param translation The translation applied to the search box by the parent view hierarchy up
 *                    to the NewTabPage view.
 *//*  ww w .  j  a va  2 s. com*/
void getSearchBoxBounds(Rect bounds, Point translation) {
    int searchBoxX = (int) mSearchBoxView.getX();
    int searchBoxY = (int) mSearchBoxView.getY();

    bounds.set(searchBoxX + mSearchBoxView.getPaddingLeft(), searchBoxY + mSearchBoxView.getPaddingTop(),
            searchBoxX + mSearchBoxView.getWidth() - mSearchBoxView.getPaddingRight(),
            searchBoxY + mSearchBoxView.getHeight() - mSearchBoxView.getPaddingBottom());

    translation.set(0, 0);

    View view = mSearchBoxView;
    while (true) {
        view = (View) view.getParent();
        if (view == null) {
            // The |mSearchBoxView| is not a child of this view. This can happen if the
            // RecyclerView detaches the NewTabPageLayout after it has been scrolled out of
            // view. Set the translation to the minimum Y value as an approximation.
            translation.y = Integer.MIN_VALUE;
            break;
        }
        translation.offset(-view.getScrollX(), -view.getScrollY());
        if (view == this)
            break;
        translation.offset((int) view.getX(), (int) view.getY());
    }
    bounds.offset(translation.x, translation.y);
}