Android Open Source - MrParkingNavigator Sw Navigator Screen






From Project

Back to project page MrParkingNavigator.

License

The source code is released under:

MIT License

If you think the Android project MrParkingNavigator listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package ru.mail.parking.sw2.screens;
/*from   w  w  w  . java2 s .c  om*/
import com.sonyericsson.extras.liveware.aef.control.Control;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;

import ru.mail.parking.App;
import ru.mail.parking.R;
import ru.mail.parking.floors.Floor;
import ru.mail.parking.floors.Place;
import ru.mail.parking.sw2.SwControlFlow;

import static ru.mail.parking.App.app;
import static ru.mail.parking.App.prefs;

public class SwNavigatorScreen extends SwBaseScreen {
  private static final float SCALE = 0.6616f;
  private static final int TOP_OFFSET = 5;

  private static final int MARKER_COLOR = 0x707070FF;
  private static final int WINDOW_COLOR = 0x60D0D0F0;
  private static final int MARKER_WIDTH = 33;
  private static final int MARKER_HEIGHT = 13;

  private final SwBaseScreen mReturnScreen;

  private final Bitmap mFloor;
  private final Bitmap mFloorThumb;

  private final Bitmap mDrawBitmap;
  private final Canvas mDrawCanvas;
  private final Paint mDrawPaint = new Paint();
  private final Rect mDrawRect;

  private final Paint mMarkerPaint = new Paint();
  private final Paint mThumbWindowPaint = new Paint();

  private final int mScreenWidth;
  private final int mScreenHeight;
  private final int mFloorSize;
  private final int mThumbSize;
  private final int mThumbWindowWidth;
  private final int mThumbWindowHeight;
  private final int mMarkerLeft;
  private final int mMarkerTop;
  private final int mMarkerWidth;
  private final int mMarkerHeight;

  private final int mScrollDeltaX;
  private final int mScrollDeltaY;


  private int mScrollX;
  private int mScrollY;


  public SwNavigatorScreen(SwControlFlow flow, SwBaseScreen returnScreen) {
    super(flow);
    mReturnScreen = returnScreen;

    mFloorThumb = BitmapFactory.decodeResource(app().getResources(), R.drawable.thumb_sw);
    mThumbSize = mFloorThumb.getWidth();

    mScreenWidth = app().getResources().getDimensionPixelSize(R.dimen.smart_watch_2_control_width);
    mScreenHeight = app().getResources().getDimensionPixelSize(R.dimen.smart_watch_2_control_height);
    mDrawRect = new Rect(0, 0, mScreenWidth, mScreenHeight);
    mScrollDeltaX = mScreenWidth / 2;
    mScrollDeltaY = mScreenHeight / 2;

    mDrawBitmap = Bitmap.createBitmap(mScreenWidth, mScreenHeight, Bitmap.Config.RGB_565);
    mDrawCanvas = new Canvas(mDrawBitmap);

    Place place = prefs().getStoredPlace();
    Floor f = App.floors().getFloor(place.getFloor());
    mFloor = BitmapFactory.decodeResource(app().getResources(), f.getSwImageRes());
    mThumbWindowPaint.setColor(WINDOW_COLOR);
    mMarkerPaint.setColor(MARKER_COLOR);

    mFloorSize = mFloor.getWidth();
    mThumbWindowWidth = (mThumbSize * mScreenWidth) / mFloorSize;
    mThumbWindowHeight = (mThumbSize * mScreenHeight) / mFloorSize;

    mMarkerLeft = (int)(place.getCoordX() * SCALE);
    mMarkerTop = (int)(place.getCoordY() * SCALE);
    mMarkerWidth = (place.isVertical() ? MARKER_HEIGHT : MARKER_WIDTH);
    mMarkerHeight = (place.isVertical() ? MARKER_WIDTH : MARKER_HEIGHT);

    mScrollX = mMarkerLeft + mMarkerWidth - mScreenWidth / 2;
    mScrollY = mMarkerTop + mMarkerHeight - mScreenHeight / 2;
    adjustScroll();
  }

  private void adjustScroll() {
    if (mScrollX < 0)
      mScrollX = 0;

    if (mScrollY < 0)
      mScrollY = 0;

    if (mScrollX + mScreenWidth > mFloorSize)
      mScrollX = mFloorSize - mScreenWidth;

    if (mScrollY + mScreenHeight > mFloorSize)
      mScrollY = mFloorSize - mScreenHeight;
  }

  private void draw() {
    mDrawCanvas.drawColor(Color.BLACK);

    // Image
    Rect r = new Rect(mScrollX, mScrollY, mScrollX + mScreenWidth, mScrollY + mScreenHeight);
    mDrawCanvas.drawBitmap(mFloor, r, mDrawRect, mDrawPaint);

    mDrawCanvas.save();
    mDrawCanvas.translate(mMarkerLeft - mScrollX, mMarkerTop - mScrollY - TOP_OFFSET);
    mDrawCanvas.drawRect(0, 0, mMarkerWidth, mMarkerHeight, mMarkerPaint);
    mDrawCanvas.restore();

    // Thumb
    int xoff = mScreenWidth - mThumbSize;
    int yoff = mScreenHeight - mThumbSize;
    mDrawCanvas.drawBitmap(mFloorThumb, xoff, yoff, mDrawPaint);

    xoff += (mThumbSize * mScrollX) / mFloorSize;
    yoff += (mThumbSize * mScrollY) / mFloorSize;

    mDrawCanvas.save();
    mDrawCanvas.translate(xoff, yoff);
    mDrawCanvas.drawRect(0, 0, mThumbWindowWidth, mThumbWindowHeight, mThumbWindowPaint);
    mDrawCanvas.restore();

    mFlow.showBitmap(mDrawBitmap);
  }

  @Override
  protected int getLayoutResource() {
    return R.layout.sw_navigator;
  }

  @Override
  public boolean onBack() {
    if (mReturnScreen != null) {
      mFlow.run(mReturnScreen);
      return true;
    }

    return false;
  }

  @Override
  public void onResume() {
    draw();
  }

  @Override
  public void onSwipe(int direction) {
    int oldx = mScrollX;
    int oldy = mScrollY;

    switch (direction) {
      case Control.Intents.SWIPE_DIRECTION_LEFT:
        mScrollX += mScrollDeltaX;
        break;

      case Control.Intents.SWIPE_DIRECTION_RIGHT:
        mScrollX -= mScrollDeltaX;
        break;

      case Control.Intents.SWIPE_DIRECTION_UP:
        mScrollY += mScrollDeltaY;
        break;

      case Control.Intents.SWIPE_DIRECTION_DOWN:
        mScrollY -= mScrollDeltaY;
        break;
    }

    adjustScroll();

    if (oldx != mScrollX || oldy != mScrollY)
      draw();
  }
}




Java Source Code List

com.sonyericsson.extras.liveware.aef.control.Control.java
com.sonyericsson.extras.liveware.aef.control.package-info.java
com.sonyericsson.extras.liveware.aef.notification.Notification.java
com.sonyericsson.extras.liveware.aef.notification.package-info.java
com.sonyericsson.extras.liveware.aef.registration.Registration.java
com.sonyericsson.extras.liveware.aef.registration.package-info.java
com.sonyericsson.extras.liveware.aef.sensor.Sensor.java
com.sonyericsson.extras.liveware.aef.sensor.package-info.java
com.sonyericsson.extras.liveware.extension.util.Dbg.java
com.sonyericsson.extras.liveware.extension.util.ExtensionService.java
com.sonyericsson.extras.liveware.extension.util.ExtensionUtils.java
com.sonyericsson.extras.liveware.extension.util.control.ControlExtension.java
com.sonyericsson.extras.liveware.extension.util.control.ControlListItem.java
com.sonyericsson.extras.liveware.extension.util.control.ControlObjectClickEvent.java
com.sonyericsson.extras.liveware.extension.util.control.ControlTouchEvent.java
com.sonyericsson.extras.liveware.extension.util.control.ControlViewGroup.java
com.sonyericsson.extras.liveware.extension.util.control.ControlView.java
com.sonyericsson.extras.liveware.extension.util.notification.DelayedContentObserver.java
com.sonyericsson.extras.liveware.extension.util.notification.NotificationUtil.java
com.sonyericsson.extras.liveware.extension.util.registration.DeviceInfoHelper.java
com.sonyericsson.extras.liveware.extension.util.registration.DeviceInfo.java
com.sonyericsson.extras.liveware.extension.util.registration.DisplayInfo.java
com.sonyericsson.extras.liveware.extension.util.registration.HostApplicationInfo.java
com.sonyericsson.extras.liveware.extension.util.registration.IRegisterCallback.java
com.sonyericsson.extras.liveware.extension.util.registration.InputInfo.java
com.sonyericsson.extras.liveware.extension.util.registration.KeyPadInfo.java
com.sonyericsson.extras.liveware.extension.util.registration.RegisterExtensionTask.java
com.sonyericsson.extras.liveware.extension.util.registration.RegistrationAdapter.java
com.sonyericsson.extras.liveware.extension.util.registration.RegistrationInformation.java
com.sonyericsson.extras.liveware.extension.util.sensor.AccessorySensorEventListener.java
com.sonyericsson.extras.liveware.extension.util.sensor.AccessorySensorEvent.java
com.sonyericsson.extras.liveware.extension.util.sensor.AccessorySensorException.java
com.sonyericsson.extras.liveware.extension.util.sensor.AccessorySensorManager.java
com.sonyericsson.extras.liveware.extension.util.sensor.AccessorySensorType.java
com.sonyericsson.extras.liveware.extension.util.sensor.AccessorySensor.java
ru.mail.parking.App.java
ru.mail.parking.Preferences.java
ru.mail.parking.floors.FloorNavigator.java
ru.mail.parking.floors.Floor.java
ru.mail.parking.floors.Place.java
ru.mail.parking.sw2.SwControlFlow.java
ru.mail.parking.sw2.screens.SwBaseScreen.java
ru.mail.parking.sw2.screens.SwEnterPlaceScreen.java
ru.mail.parking.sw2.screens.SwFreePlacesScreen.java
ru.mail.parking.sw2.screens.SwNavigatorScreen.java
ru.mail.parking.sw2.screens.SwPlaceScreen.java
ru.mail.parking.sw2.system.SwReceiver.java
ru.mail.parking.sw2.system.SwRegInfo.java
ru.mail.parking.sw2.system.SwService.java
ru.mail.parking.ui.AboutActivity.java
ru.mail.parking.ui.DataDetailsActivity.java
ru.mail.parking.ui.EnterPlaceActivity.java
ru.mail.parking.ui.MultiscrollView.java
ru.mail.parking.ui.NavigatorActivity.java
ru.mail.parking.ui.NavigatorFloorView.java
ru.mail.parking.ui.SettingsActivity.java
ru.mail.parking.utils.NetworkAwaiter.java
ru.mail.parking.utils.NetworkStateReceiver.java
ru.mail.parking.utils.Utils.java
ru.mail.parking.widget.MainReceiver.java
ru.mail.parking.widget.MainWidgetProvider.java
ru.mail.parking.widget.SmartUpdate.java
ru.mail.parking.widget.UpdateService.java