public void setObject(Face face) {
    Log.d(
        TAG,
        "[setObject]mZoomInAnimaState:"
            + mZoomInAnimaState
            + ""
            + ", mZoomOutAnimaState:"
            + mZoomOutAnimaState);

    if (mZoomInAnimaState == ANIMATION_DOING || mIsClear) {
      return;
    }
    mFace = face;

    if (mZoomOutAnimaState == ANIMATION_IDLE) {
      if (face.score == OBJECT_TRACKING_SUCCEED) {
        showSuccess(true);
      } else if (face.score == OBJECT_TRACKING_FAILED) {
        showFail(true);
      }
    } else if (mZoomOutAnimaState == ANIMATION_DONE) {
      Log.i(TAG, "[setObject]invalidate ");
      resetView();
      invalidate();
    }
  }
 private void clearPreviewCallback() {
   Log.i(TAG, "[clearPreviewCallback]...");
   int cameraId = mICameraDeviceManager.getCurrentCameraId();
   ICameraDevice cameraDevice = mICameraDeviceManager.getCameraDevice(cameraId);
   if (cameraDevice == null) {
     Log.i(TAG, "[clearPreviewCallback], cameraDevice is null");
     return;
   }
   cameraDevice.setPreviewCallbackWithBuffer(null);
 }
 @Override
 protected void onDraw(Canvas canvas) {
   Log.d(
       TAG,
       "[onDraw]mZoomInAnimaState:"
           + mZoomInAnimaState
           + ", mZoomOutAnimaState:"
           + mZoomOutAnimaState
           + ", mOrientation:"
           + mOrientation);
   if (mZoomOutAnimaState != ANIMATION_DONE || mZoomInAnimaState != ANIMATION_DONE) {
     return;
   }
   if (mFace != null) {
     if (mFace.score == OBJECT_TRACKING_SUCCEED) {
       mTrackIndicator = mTrackStatusIndicator[OBJECT_FOCUSED];
     } else {
       Log.i(TAG, "[onDraw]mFace is null.");
       return;
     }
     // Prepare the matrix.
     Util.prepareMatrix(mMatrix, false, mDisplayOrientation, mUnCropWidth, mUnCropHeight);
     // OT indicator is directional. Rotate the matrix and the canvas
     // so it looks correctly in all orientations.
     float dx = (getWidth() - mUnCropWidth) / 2;
     float dy = (getHeight() - mUnCropHeight) / 2;
     Matrix pointMatrix = new Matrix();
     float[] pointes = new float[] {dx, dy};
     canvas.save();
     mMatrix.postRotate(mOrientation);
     canvas.rotate(-mOrientation);
     pointMatrix.postRotate(mCompesation);
     pointMatrix.mapPoints(pointes);
     // Transform the coordinates.
     mRect.set(mFace.rect);
     mMatrix.mapRect(mRect);
     mRect.offset(pointes[0], pointes[1]);
     mTrackIndicator.setBounds(
         Math.round(mRect.left),
         Math.round(mRect.top),
         Math.round(mRect.right),
         Math.round(mRect.bottom));
     if (needDraw()) {
       mTrackIndicator.draw(canvas);
     }
     canvas.restore();
   }
   super.onDraw(canvas);
 }
 public void clear() {
   Log.i(TAG, "[clear]...");
   mFace = null;
   mIsClear = true;
   resetView();
   invalidate();
 }
 @Override
 public void destory() {
   Log.i(TAG, "[destory]...");
   if (mCameraService != null) {
     unBindCameraService();
   }
 }
 private void onOrientationChanged(int orientation) {
   Log.i(TAG, "[onOrientationChanged], orientation:" + orientation);
   Message msg = new Message();
   msg.what = MtkCameraService.MSG_ORIENTATION_CHANGED;
   msg.arg1 = orientation;
   sendMessageToService(msg);
 }
示例#7
0
  public void setCurrentMode(CameraModeType type) {
    Log.i(TAG, "[setCurrentMode]type = " + type);
    switch (type) {
      case EXT_MODE_PHOTO:
        mModeAddition = mPhotoAddtion;
        break;

      case EXT_MODE_VIDEO:
        mModeAddition = mVideoAddtion;
        break;

      case EXT_MODE_PHOTO_PIP:
        mModeAddition = mPipPhotoAddition;
        break;

      case EXT_MODE_VIDEO_PIP:
        mModeAddition = mPipVideoAddition;
        break;

      case EXT_MODE_FACE_BEAUTY:
        mModeAddition = mFaceBeautyAddition;
        break;
      default:
        mModeAddition = mDummyAddtion;
        break;
    }
  }
 @Override
 public void onClick(View v) {
   Log.i(TAG, "onClick()");
   if (v == mIndicator && getContext().getCameraAppUI().isNormalViewState()) {
     mListener.onClick();
     hide();
   }
 }
 @Override
 public View getView() {
   View view = inflate(R.layout.lomo_effect_indicator);
   mIndicator = (RotateImageView) view.findViewById(R.id.lomo_effect_indicator);
   mIndicator.setOnClickListener(this);
   Log.i(TAG, "[getView], view:" + view);
   return view;
 }
示例#10
0
 public boolean execute(AdditionActionType type, Object... arg) {
   Log.i(TAG, "[execute],addition action type = " + type);
   boolean result = false;
   for (ICameraAddition addition : mModeAddition) {
     result = addition.execute(type, arg) || result;
   }
   return result;
 }
  private void setPreviewCallback() {
    Log.i(TAG, "[setPreviewCallback]...");

    int cameraId = mICameraDeviceManager.getCurrentCameraId();
    ICameraDevice cameraDevice = mICameraDeviceManager.getCameraDevice(cameraId);
    if (cameraDevice == null) {
      Log.i(TAG, "[setPreviewCallback], cameraDevice is null");
      return;
    }
    int bufferSize = getBufferSize();
    Log.i(TAG, "[setPreviewCallback], bufferSize:" + bufferSize);
    for (int i = 0; i < 3; i++) {
      byte[] buffer = new byte[bufferSize];
      cameraDevice.addCallbackBuffer(buffer);
    }
    cameraDevice.setPreviewCallbackWithBuffer(mPreviewCallback);
  }
 private boolean needDraw() {
   boolean need = false;
   float hight = Math.abs(mRect.top - mRect.bottom);
   float width = Math.abs(mRect.right - mRect.left);
   need = Math.abs(hight - width) / hight <= MIN_RATE ? true : false;
   Log.i(TAG, "needDraw need = " + need);
   return need;
 }
示例#13
0
 public void destory() {
   Log.i(TAG, "[destory]");
   for (ICameraAddition addition : mNormalAddition) {
     addition.destory();
   }
   for (ICameraAddition addition : mModeAddition) {
     addition.destory();
   }
 }
示例#14
0
 public void pause() {
   Log.i(TAG, "[pause]");
   for (ICameraAddition addition : mNormalAddition) {
     addition.pause();
   }
   for (ICameraAddition addition : mModeAddition) {
     addition.pause();
   }
 }
示例#15
0
 public void resume() {
   Log.i(TAG, "[resume]");
   for (ICameraAddition addition : mNormalAddition) {
     addition.resume();
   }
   for (ICameraAddition addition : mModeAddition) {
     addition.resume();
   }
 }
 @Override
 public void open() {
   Log.i(TAG, "[open], mIsMtkCameraApServiceLaunched:" + mIsMtkCameraApServiceLaunched);
   if (mIsMtkCameraApServiceLaunched) {
     int cameraId = mICameraDeviceManager.getCurrentCameraId();
     ICameraDevice cameraDevice = mICameraDeviceManager.getCameraDevice(cameraId);
     if (cameraDevice == null) {
       Log.i(TAG, "cameraDevice is null, return.");
       return;
     }
     Parameters parameters = cameraDevice.getParameters();
     parameters.setPreviewFormat(ImageFormat.NV21);
     if (mCameraService == null) {
       bindCameraService();
     }
     mOpened = true;
   }
 }
 @Override
 public void pause() {
   Log.i(TAG, "[pause]...");
   clearPreviewCallback();
   if (mCameraService != null) {
     Message msg = Message.obtain();
     msg.what = MtkCameraService.MSG_SERVER_EXIT;
     sendMessageToService(msg);
   }
 }
 private void resetView() {
   Log.i(TAG, "resetView mUnCropWidth = " + mUnCropWidth + " mUnCropHeight = " + mUnCropHeight);
   RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) getLayoutParams();
   setBackground(null);
   animate().cancel();
   setScaleX(1f);
   setScaleY(1f);
   params.width = mUnCropWidth;
   params.height = mUnCropHeight;
   params.setMargins(0, 0, 0, 0);
 }
 private void sendMessageToService(Message msg) {
   if (mCameraService != null) {
     try {
       if (!mHasNotifyParameterReady) {
         Message parameterMessage = Message.obtain();
         int cameraId = mICameraDeviceManager.getCurrentCameraId();
         ICameraDevice cameraDevice = mICameraDeviceManager.getCameraDevice(cameraId);
         parameterMessage.what = MtkCameraService.MSG_PARAMETERS_READY;
         parameterMessage.obj = cameraDevice.getParameters();
         mCameraService.sendMessage(parameterMessage);
         mHasNotifyParameterReady = true;
       }
       Log.i(TAG, "msg:" + msg.what);
       mCameraService.sendMessage(msg);
     } catch (Exception e) {
       // TODO: handle exception
       Log.i(TAG, "sendMessageToService exception");
     }
   }
 }
示例#20
0
 public void close(boolean isMode) {
   Log.i(TAG, "[close]isMode = " + isMode);
   Vector<ICameraAddition> curAddition = mModeAddition;
   if (!isMode) {
     curAddition = mNormalAddition;
   }
   for (ICameraAddition addition : curAddition) {
     if (addition.isOpen()) {
       addition.close();
     }
   }
 }
示例#21
0
 public void open(boolean isMode) {
   Log.i(TAG, "[open]isMode = " + isMode);
   Vector<ICameraAddition> curAddition = mModeAddition;
   if (!isMode) {
     curAddition = mNormalAddition;
   }
   for (ICameraAddition addition : curAddition) {
     if (addition.isSupport()) {
       addition.open();
     }
   }
 }
 @Override
 public void handleMessage(Message msg) {
   Log.i(TAG, "[handleMessage]msg.what = " + msg.what);
   switch (msg.what) {
     case MSG_ON_PREVIEW_STARTED:
       if (mIsMtkCameraApServiceLaunched) {
         setPreviewCallback();
       }
       break;
     default:
       break;
   }
 }
 @Override
 public boolean execute(ActionType type, Object... arg) {
   Log.i(TAG, "[execute], ActionType = " + type);
   switch (type) {
     case ACTION_ORITATION_CHANGED:
       mOrientation = (Integer) arg[0];
       onOrientationChanged(mOrientation);
       break;
     default:
       break;
   }
   return false;
 }
 public void showFail(boolean timeout) {
   Log.d(TAG, "[showFail]timeout= " + timeout);
   mIsClear = false;
   mZoomOutAnimaState = ANIMATION_DOING;
   mTrackIndicator = mTrackStatusIndicator[OBJECT_FOCUSED];
   setBackground(mTrackIndicator);
   animate()
       .withLayer()
       .setDuration(SCALING_DOWN_TIME)
       .scaleX(0.8f)
       .scaleY(0.8f)
       .withEndAction(mEndAction);
 }
 public void showStart() {
   Log.d(TAG, "[showStart]...");
   mIsClear = false;
   mZoomInAnimaState = ANIMATION_DOING;
   mZoomOutAnimaState = ANIMATION_IDLE;
   mTrackIndicator = mTrackStatusIndicator[OBJECT_FOCUSING];
   setBackground(mTrackIndicator);
   animate()
       .withLayer()
       .setDuration(SCALING_UP_TIME)
       .scaleX(1.5f)
       .scaleY(1.5f)
       .withEndAction(mStartAction);
 }
 @Override
 public void onPictureTaken(byte[] jpegData, Camera camera) {
   Log.i(TAG, "[mJpegPictureCallback]onPictureTaken, jpegData:" + jpegData);
   if (mModeListener != null) {
     mModeListener.restartPreview(true);
   }
   if (jpegData == null) {
     return;
   }
   long dateTaken = System.currentTimeMillis();
   mIFileSaver.savePhotoFile(jpegData, null, dateTaken, mIModuleCtrl.getLocation(), 0, null);
   Message msg = Message.obtain();
   msg.what = MtkCameraService.MSG_CAPTURE_DATA;
   msg.obj = jpegData;
   sendMessageToService(msg);
 }
示例#27
0
 public void onCameraParameterReady(boolean isMode) {
   Log.i(TAG, "[onCameraParameterReady]isMode = " + isMode);
   Vector<ICameraAddition> curAddition = mModeAddition;
   if (!isMode) {
     curAddition = mNormalAddition;
   }
   for (ICameraAddition addition : curAddition) {
     boolean isSupport = addition.isSupport();
     boolean isOpen = addition.isOpen();
     if (isSupport && !isOpen) {
       addition.open();
     } else if (!isSupport && isOpen) {
       addition.close();
     }
   }
 }
 @Override
 public boolean execute(AdditionActionType type, Object... arg) {
   Log.i(TAG, "[execute], AdditionActionType = " + type);
   switch (type) {
     case ACTION_TAKEN_PICTURE:
       if (mIsMtkCameraApServiceLaunched) {
         takePicture();
         return true;
       }
       break;
     case ACTION_ON_START_PREVIEW:
       mMainHandler.sendEmptyMessage(MSG_ON_PREVIEW_STARTED);
       break;
     default:
       break;
   }
   return false;
 }
 private boolean isMtkCameraApServiceLaunched(Context context) {
   ActivityManager activityManager =
       (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
   List<ActivityManager.RunningServiceInfo> serviceList =
       activityManager.getRunningServices(Integer.MAX_VALUE);
   if (!(serviceList.size() > 0)) {
     return false;
   }
   for (int i = 0; i < serviceList.size(); i++) {
     RunningServiceInfo serviceInfo = serviceList.get(i);
     ComponentName servcieName = serviceInfo.service;
     if ("com.mediatek.camera.addition.remotecamera.service.MtkCameraService"
         .equals(servcieName.getClassName())) {
       Log.i(TAG, "isMtkCameraApServiceLaunched true");
       return true;
     }
   }
   return false;
 }
示例#30
0
 public boolean execute(ActionType type, boolean isMode, Object... arg) {
   Log.i(TAG, "[execute]isMode = " + isMode + ",action type = " + type);
   Vector<ICameraAddition> curAddition = mModeAddition;
   if (!isMode) {
     curAddition = mNormalAddition;
   }
   boolean result = false;
   for (ICameraAddition addition : curAddition) {
     result = result || addition.execute(type, arg);
   }
   // must tell effect if preview size changed.
   if (!isMode
       && type == ActionType.ACTION_ON_PREVIEW_DISPLAY_SIZE_CHANGED
       && !mModeAddition.contains(mIEffect)) {
     if (mIEffect != null) {
       mIEffect.execute(type, arg);
     }
   }
   return result;
 }