Permalink
Browse files

Rotate the recording time according to orientation. do not merge

bug:3163671
Change-Id: I87d8d8615df136d8347fb345e68eb1f8f8b6fb8b
  • Loading branch information...
1 parent d56274a commit 64fbf551646615592f8bd8320fef57e9aae01492 Wu-cheng Li committed Nov 9, 2010
View
43 res/layout/video_camera.xml
@@ -37,27 +37,32 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone" />
- <!-- Note: In this TextView the paddingRight="2"
- attribute is required because otherwise the
- text's drop shadow will be clipped. -->
- <TextView android:id="@+id/recording_time"
- android:layout_width="180dp"
+ <com.android.camera.ui.RotateRecordingTime android:id="@+id/recording_time_rect"
+ android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left|bottom"
- android:layout_marginBottom="13dp"
- android:layout_marginLeft="17dp"
- android:paddingRight="2dp"
- android:drawablePadding="8dp"
- android:drawableLeft="@drawable/ic_recording_indicator"
- android:shadowColor="#c0000000"
- android:shadowDx="1"
- android:shadowDy="1"
- android:shadowRadius="1"
- android:gravity="left|center_vertical"
- android:textColor="@color/recording_time_elapsed_text"
- android:textSize="23dp"
- android:textStyle="bold"
- android:visibility="gone"/>
+ android:layout_marginBottom="14dp"
+ android:layout_marginLeft="14dp">
+ <!-- Note: In this TextView the paddingRight="2"
+ attribute is required because otherwise the
+ text's drop shadow will be clipped. -->
+ <TextView android:id="@+id/recording_time"
+ android:layout_width="130dp"
+ android:layout_height="130dp"
+ android:layout_gravity="center"
+ android:paddingRight="2dp"
+ android:drawablePadding="8dp"
+ android:drawableLeft="@drawable/ic_recording_indicator"
+ android:shadowColor="#c0000000"
+ android:shadowDx="1"
+ android:shadowDy="1"
+ android:shadowRadius="1"
+ android:gravity="left|center_vertical"
+ android:textColor="@color/recording_time_elapsed_text"
+ android:textSize="23dp"
+ android:textStyle="bold"
+ android:visibility="gone"/>
+ </com.android.camera.ui.RotateRecordingTime>
</FrameLayout>
</com.android.camera.PreviewFrameLayout>
</LinearLayout>
View
8 src/com/android/camera/VideoCamera.java
@@ -22,6 +22,7 @@
import com.android.camera.ui.GLRootView;
import com.android.camera.ui.GLView;
import com.android.camera.ui.HeadUpDisplay;
+import com.android.camera.ui.RotateRecordingTime;
import android.content.ActivityNotFoundException;
import android.content.BroadcastReceiver;
@@ -167,6 +168,7 @@
private ContentResolver mContentResolver;
private ShutterButton mShutterButton;
+ private RotateRecordingTime mRecordingTimeRect;
private TextView mRecordingTimeView;
private Switcher mSwitcher;
private boolean mRecordingTimeCountsDown = false;
@@ -183,7 +185,8 @@
private MyOrientationEventListener mOrientationListener;
// The device orientation in degrees. Default is unknown.
private int mOrientation = OrientationEventListener.ORIENTATION_UNKNOWN;
- // The orientation compensation for icons and thumbnails.
+ // The orientation compensation for icons and thumbnails. Degrees are in
+ // counter-clockwise
private int mOrientationCompensation = 0;
private int mOrientationHint; // the orientation hint for video playback
@@ -336,6 +339,7 @@ public void run() {
mIsVideoCaptureIntent = isVideoCaptureIntent();
mQuickCapture = getIntent().getBooleanExtra(EXTRA_QUICK_CAPTURE, false);
mRecordingTimeView = (TextView) findViewById(R.id.recording_time);
+ mRecordingTimeRect = (RotateRecordingTime) findViewById(R.id.recording_time_rect);
ViewGroup rootView = (ViewGroup) findViewById(R.id.video_camera);
LayoutInflater inflater = this.getLayoutInflater();
@@ -1232,6 +1236,8 @@ private void startVideoRecording() {
mMediaRecorderRecording = true;
mRecordingStartTime = SystemClock.uptimeMillis();
updateRecordingIndicator(false);
+ // Rotate the recording time.
+ mRecordingTimeRect.setOrientation(mOrientationCompensation);
mRecordingTimeView.setText("");
mRecordingTimeView.setVisibility(View.VISIBLE);
updateRecordingTime();
View
72 src/com/android/camera/ui/RotateRecordingTime.java
@@ -0,0 +1,72 @@
+/*
+ * Copyright (C) 2009 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.camera.ui;
+
+import android.content.Context;
+import android.util.AttributeSet;
+import android.util.Log;
+import android.graphics.Canvas;
+import android.view.ViewGroup;
+import android.widget.FrameLayout;
+import android.widget.TextView;
+
+import com.android.camera.R;
+
+// This is a rectangle that contains recording text view. Canvas is rotated
+// before passing to recording text.
+public class RotateRecordingTime extends FrameLayout {
+ private static final String TAG = "RotateRecordingTime";
+ private float mTextSize;
+ private int mOrientation;
+
+ public RotateRecordingTime(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ }
+
+ @Override
+ protected void onFinishInflate() {
+ TextView v = (TextView) findViewById(R.id.recording_time);
+ mTextSize = (float) v.getTextSize();
+ }
+
+ // degrees in counter-clockwise
+ public void setOrientation(int degrees) {
+ if (degrees % 90 == 0) {
+ mOrientation = degrees % 360;
+ if (mOrientation < 0) mOrientation += 360;
+ } else {
+ Log.e(TAG, "Invalid orientation=" + degrees);
+ }
+ }
+
+ @Override
+ protected void dispatchDraw(Canvas canvas) {
+ canvas.save();
+ float width = (float) getWidth();
+ float height = (float) getHeight();
+ if (mOrientation == 0 || mOrientation == 180) {
+ canvas.translate(0, height / 2 - mTextSize / 2);
+ } else {
+ canvas.translate(-width / 2 + mTextSize / 2, 0);
+ }
+ // Rotate the canvas in the opposite direction to compensate.
+ canvas.rotate(-mOrientation, width / 2, height / 2);
+ super.dispatchDraw(canvas);
+ canvas.restore();
+ }
+}
+

0 comments on commit 64fbf55

Please sign in to comment.