diff options
60 files changed, 326 insertions, 241 deletions
diff --git a/res/drawable-hdpi/ic_viewfinder_gps_no_signal.png b/res/drawable-hdpi/ic_viewfinder_gps_no_signal.png Binary files differindex 4a0d016..ab91ae9 100644 --- a/res/drawable-hdpi/ic_viewfinder_gps_no_signal.png +++ b/res/drawable-hdpi/ic_viewfinder_gps_no_signal.png diff --git a/res/drawable-hdpi/ic_viewfinder_video_high.png b/res/drawable-hdpi/ic_viewfinder_video_high.png Binary files differnew file mode 100644 index 0000000..1a8575b --- /dev/null +++ b/res/drawable-hdpi/ic_viewfinder_video_high.png diff --git a/res/drawable-hdpi/ic_viewfinder_video_low.png b/res/drawable-hdpi/ic_viewfinder_video_low.png Binary files differnew file mode 100644 index 0000000..76f17c7 --- /dev/null +++ b/res/drawable-hdpi/ic_viewfinder_video_low.png diff --git a/res/drawable-hdpi/ic_viewfinder_video_mms.png b/res/drawable-hdpi/ic_viewfinder_video_mms.png Binary files differnew file mode 100644 index 0000000..6126f9e --- /dev/null +++ b/res/drawable-hdpi/ic_viewfinder_video_mms.png diff --git a/res/drawable-hdpi/ic_viewfinder_video_youtube.png b/res/drawable-hdpi/ic_viewfinder_video_youtube.png Binary files differnew file mode 100644 index 0000000..e354c94 --- /dev/null +++ b/res/drawable-hdpi/ic_viewfinder_video_youtube.png diff --git a/res/drawable-hdpi/menu_popup.9.png b/res/drawable-hdpi/menu_popup.9.png Binary files differindex 534d3cf..872702c 100644 --- a/res/drawable-hdpi/menu_popup.9.png +++ b/res/drawable-hdpi/menu_popup.9.png diff --git a/res/drawable-mdpi/ic_menuselect_flash_auto.png b/res/drawable-mdpi/ic_menuselect_flash_auto.png Binary files differindex 39e1eed..1967233 100644 --- a/res/drawable-mdpi/ic_menuselect_flash_auto.png +++ b/res/drawable-mdpi/ic_menuselect_flash_auto.png diff --git a/res/drawable-mdpi/ic_menuselect_flash_off.png b/res/drawable-mdpi/ic_menuselect_flash_off.png Binary files differindex 44b6e95..973ef41 100644 --- a/res/drawable-mdpi/ic_menuselect_flash_off.png +++ b/res/drawable-mdpi/ic_menuselect_flash_off.png diff --git a/res/drawable-mdpi/ic_menuselect_flash_on.png b/res/drawable-mdpi/ic_menuselect_flash_on.png Binary files differindex bb1343a..fe9eaac 100644 --- a/res/drawable-mdpi/ic_menuselect_flash_on.png +++ b/res/drawable-mdpi/ic_menuselect_flash_on.png diff --git a/res/drawable-mdpi/ic_menuselect_focus_auto.png b/res/drawable-mdpi/ic_menuselect_focus_auto.png Binary files differindex 2eb28da..324c4b9 100644 --- a/res/drawable-mdpi/ic_menuselect_focus_auto.png +++ b/res/drawable-mdpi/ic_menuselect_focus_auto.png diff --git a/res/drawable-mdpi/ic_menuselect_focus_infinity.png b/res/drawable-mdpi/ic_menuselect_focus_infinity.png Binary files differindex c5f902e..f538e3c 100644 --- a/res/drawable-mdpi/ic_menuselect_focus_infinity.png +++ b/res/drawable-mdpi/ic_menuselect_focus_infinity.png diff --git a/res/drawable-mdpi/ic_menuselect_focus_macro.png b/res/drawable-mdpi/ic_menuselect_focus_macro.png Binary files differindex dd3ecb3..0de79ce 100644 --- a/res/drawable-mdpi/ic_menuselect_focus_macro.png +++ b/res/drawable-mdpi/ic_menuselect_focus_macro.png diff --git a/res/drawable-mdpi/ic_menuselect_gps_off.png b/res/drawable-mdpi/ic_menuselect_gps_off.png Binary files differindex 6f36907..29532f7 100644 --- a/res/drawable-mdpi/ic_menuselect_gps_off.png +++ b/res/drawable-mdpi/ic_menuselect_gps_off.png diff --git a/res/drawable-mdpi/ic_menuselect_gps_on.png b/res/drawable-mdpi/ic_menuselect_gps_on.png Binary files differindex 19d4c85..ed19e00 100644 --- a/res/drawable-mdpi/ic_menuselect_gps_on.png +++ b/res/drawable-mdpi/ic_menuselect_gps_on.png diff --git a/res/drawable-mdpi/ic_menuselect_settings.png b/res/drawable-mdpi/ic_menuselect_settings.png Binary files differindex 495d854..6dbc1d7 100644 --- a/res/drawable-mdpi/ic_menuselect_settings.png +++ b/res/drawable-mdpi/ic_menuselect_settings.png diff --git a/res/drawable-mdpi/ic_menuselect_wb_auto.png b/res/drawable-mdpi/ic_menuselect_wb_auto.png Binary files differindex 65f5d18..2a05a53 100644 --- a/res/drawable-mdpi/ic_menuselect_wb_auto.png +++ b/res/drawable-mdpi/ic_menuselect_wb_auto.png diff --git a/res/drawable-mdpi/ic_menuselect_wb_cloudy.png b/res/drawable-mdpi/ic_menuselect_wb_cloudy.png Binary files differindex 1867c9b..2baf25e 100644 --- a/res/drawable-mdpi/ic_menuselect_wb_cloudy.png +++ b/res/drawable-mdpi/ic_menuselect_wb_cloudy.png diff --git a/res/drawable-mdpi/ic_menuselect_wb_daylight.png b/res/drawable-mdpi/ic_menuselect_wb_daylight.png Binary files differindex d16a930..4f27f2b 100644 --- a/res/drawable-mdpi/ic_menuselect_wb_daylight.png +++ b/res/drawable-mdpi/ic_menuselect_wb_daylight.png diff --git a/res/drawable-mdpi/ic_menuselect_wb_fluorescent.png b/res/drawable-mdpi/ic_menuselect_wb_fluorescent.png Binary files differindex b788229..8ed26a1 100644 --- a/res/drawable-mdpi/ic_menuselect_wb_fluorescent.png +++ b/res/drawable-mdpi/ic_menuselect_wb_fluorescent.png diff --git a/res/drawable-mdpi/ic_menuselect_wb_incandescent.png b/res/drawable-mdpi/ic_menuselect_wb_incandescent.png Binary files differindex af78583..d20734d 100644 --- a/res/drawable-mdpi/ic_menuselect_wb_incandescent.png +++ b/res/drawable-mdpi/ic_menuselect_wb_incandescent.png diff --git a/res/drawable-mdpi/ic_viewfinder_flash_auto.png b/res/drawable-mdpi/ic_viewfinder_flash_auto.png Binary files differindex 4a86340..fd73fe1 100755..100644 --- a/res/drawable-mdpi/ic_viewfinder_flash_auto.png +++ b/res/drawable-mdpi/ic_viewfinder_flash_auto.png diff --git a/res/drawable-mdpi/ic_viewfinder_flash_off.png b/res/drawable-mdpi/ic_viewfinder_flash_off.png Binary files differindex 830fb23..b2c0516 100644 --- a/res/drawable-mdpi/ic_viewfinder_flash_off.png +++ b/res/drawable-mdpi/ic_viewfinder_flash_off.png diff --git a/res/drawable-mdpi/ic_viewfinder_flash_on.png b/res/drawable-mdpi/ic_viewfinder_flash_on.png Binary files differindex 8f600e5..1641aa1 100755..100644 --- a/res/drawable-mdpi/ic_viewfinder_flash_on.png +++ b/res/drawable-mdpi/ic_viewfinder_flash_on.png diff --git a/res/drawable-mdpi/ic_viewfinder_focus_auto.png b/res/drawable-mdpi/ic_viewfinder_focus_auto.png Binary files differindex 076b434..efea6be 100644 --- a/res/drawable-mdpi/ic_viewfinder_focus_auto.png +++ b/res/drawable-mdpi/ic_viewfinder_focus_auto.png diff --git a/res/drawable-mdpi/ic_viewfinder_focus_infinity.png b/res/drawable-mdpi/ic_viewfinder_focus_infinity.png Binary files differindex 7eb90cb..7bb4485 100644 --- a/res/drawable-mdpi/ic_viewfinder_focus_infinity.png +++ b/res/drawable-mdpi/ic_viewfinder_focus_infinity.png diff --git a/res/drawable-mdpi/ic_viewfinder_gps_no_signal.png b/res/drawable-mdpi/ic_viewfinder_gps_no_signal.png Binary files differindex fbdea07..d851241 100644 --- a/res/drawable-mdpi/ic_viewfinder_gps_no_signal.png +++ b/res/drawable-mdpi/ic_viewfinder_gps_no_signal.png diff --git a/res/drawable-mdpi/ic_viewfinder_gps_off.png b/res/drawable-mdpi/ic_viewfinder_gps_off.png Binary files differindex 918c914..7ea537b 100644 --- a/res/drawable-mdpi/ic_viewfinder_gps_off.png +++ b/res/drawable-mdpi/ic_viewfinder_gps_off.png diff --git a/res/drawable-mdpi/ic_viewfinder_gps_on.png b/res/drawable-mdpi/ic_viewfinder_gps_on.png Binary files differindex 4bbb47b..660faea 100644 --- a/res/drawable-mdpi/ic_viewfinder_gps_on.png +++ b/res/drawable-mdpi/ic_viewfinder_gps_on.png diff --git a/res/drawable-mdpi/ic_viewfinder_iconbar.9.png b/res/drawable-mdpi/ic_viewfinder_iconbar.9.png Binary files differindex 0cd4dfe..9858303 100644 --- a/res/drawable-mdpi/ic_viewfinder_iconbar.9.png +++ b/res/drawable-mdpi/ic_viewfinder_iconbar.9.png diff --git a/res/drawable-mdpi/ic_viewfinder_settings.png b/res/drawable-mdpi/ic_viewfinder_settings.png Binary files differindex 8687eec..49b6ec9 100644 --- a/res/drawable-mdpi/ic_viewfinder_settings.png +++ b/res/drawable-mdpi/ic_viewfinder_settings.png diff --git a/res/drawable-mdpi/ic_viewfinder_video_high.png b/res/drawable-mdpi/ic_viewfinder_video_high.png Binary files differnew file mode 100644 index 0000000..e14c7c9 --- /dev/null +++ b/res/drawable-mdpi/ic_viewfinder_video_high.png diff --git a/res/drawable-mdpi/ic_viewfinder_video_low.png b/res/drawable-mdpi/ic_viewfinder_video_low.png Binary files differnew file mode 100644 index 0000000..1a706bc --- /dev/null +++ b/res/drawable-mdpi/ic_viewfinder_video_low.png diff --git a/res/drawable-mdpi/ic_viewfinder_video_mms.png b/res/drawable-mdpi/ic_viewfinder_video_mms.png Binary files differnew file mode 100644 index 0000000..d952551 --- /dev/null +++ b/res/drawable-mdpi/ic_viewfinder_video_mms.png diff --git a/res/drawable-mdpi/ic_viewfinder_video_youtube.png b/res/drawable-mdpi/ic_viewfinder_video_youtube.png Binary files differnew file mode 100644 index 0000000..c58037e --- /dev/null +++ b/res/drawable-mdpi/ic_viewfinder_video_youtube.png diff --git a/res/drawable-mdpi/ic_viewfinder_wb_auto.png b/res/drawable-mdpi/ic_viewfinder_wb_auto.png Binary files differindex 0f18ca5..2cfceef 100644 --- a/res/drawable-mdpi/ic_viewfinder_wb_auto.png +++ b/res/drawable-mdpi/ic_viewfinder_wb_auto.png diff --git a/res/drawable-mdpi/ic_viewfinder_wb_cloudy.png b/res/drawable-mdpi/ic_viewfinder_wb_cloudy.png Binary files differindex 8a45c53..5f5e3d5 100644 --- a/res/drawable-mdpi/ic_viewfinder_wb_cloudy.png +++ b/res/drawable-mdpi/ic_viewfinder_wb_cloudy.png diff --git a/res/drawable-mdpi/ic_viewfinder_wb_daylight.png b/res/drawable-mdpi/ic_viewfinder_wb_daylight.png Binary files differindex 35268a0..f5ea586 100644 --- a/res/drawable-mdpi/ic_viewfinder_wb_daylight.png +++ b/res/drawable-mdpi/ic_viewfinder_wb_daylight.png diff --git a/res/drawable-mdpi/ic_viewfinder_wb_fluorescent.png b/res/drawable-mdpi/ic_viewfinder_wb_fluorescent.png Binary files differindex acfd9a7..b71b74a 100644 --- a/res/drawable-mdpi/ic_viewfinder_wb_fluorescent.png +++ b/res/drawable-mdpi/ic_viewfinder_wb_fluorescent.png diff --git a/res/drawable-mdpi/ic_viewfinder_wb_incandescent.png b/res/drawable-mdpi/ic_viewfinder_wb_incandescent.png Binary files differindex fe5a60f..64364ba 100644 --- a/res/drawable-mdpi/ic_viewfinder_wb_incandescent.png +++ b/res/drawable-mdpi/ic_viewfinder_wb_incandescent.png diff --git a/res/drawable-mdpi/menu_popup.9.png b/res/drawable-mdpi/menu_popup.9.png Binary files differindex 534d3cf..3e197a1 100644 --- a/res/drawable-mdpi/menu_popup.9.png +++ b/res/drawable-mdpi/menu_popup.9.png diff --git a/res/drawable-mdpi/menu_popup_triangle.png b/res/drawable-mdpi/menu_popup_triangle.png Binary files differindex 59e2f99..4262398 100644 --- a/res/drawable-mdpi/menu_popup_triangle.png +++ b/res/drawable-mdpi/menu_popup_triangle.png diff --git a/src/com/android/camera/Camera.java b/src/com/android/camera/Camera.java index a0acb1a..d3d44c4 100644 --- a/src/com/android/camera/Camera.java +++ b/src/com/android/camera/Camera.java @@ -36,8 +36,8 @@ import android.location.Location; import android.location.LocationManager; import android.location.LocationProvider; import android.media.AudioManager; -import android.media.ToneGenerator; import android.media.CameraProfile; +import android.media.ToneGenerator; import android.net.Uri; import android.os.Build; import android.os.Bundle; @@ -138,7 +138,7 @@ public class Camera extends NoSearchActivity implements View.OnClickListener, private Switcher mSwitcher; private boolean mStartPreviewFail = false; - private GLRootView mRootView; + private GLRootView mGLRootView; // mPostCaptureAlert, mLastPictureButton, mThumbController // are non-null only if isImageCaptureIntent() is true. @@ -273,7 +273,7 @@ public class Camera extends NoSearchActivity implements View.OnClickListener, if (!mIsImageCaptureIntent) { setOrientationIndicator(mLastOrientation); } - mRootView.queueEvent(new Runnable() { + mGLRootView.queueEvent(new Runnable() { public void run() { mHeadUpDisplay.setOrientation(mLastOrientation); } @@ -327,12 +327,11 @@ public class Camera extends NoSearchActivity implements View.OnClickListener, mFirstTimeInitialized = true; - mRootView = (GLRootView) findViewById(R.id.settings_ui); - mHeadUpDisplay = new HeadUpDisplay(); + mHeadUpDisplay = new HeadUpDisplay(this); CameraSettings settings = new CameraSettings(this, mInitialParams); mHeadUpDisplay.initialize(this, settings.getPreferenceGroup(R.xml.camera_preferences)); - mRootView.setContentPane(mHeadUpDisplay); + mGLRootView.setContentPane(mHeadUpDisplay); } private void updateThumbnailButton() { @@ -964,6 +963,8 @@ public class Camera extends NoSearchActivity implements View.OnClickListener, LayoutInflater inflater = getLayoutInflater(); ViewGroup rootView = (ViewGroup) findViewById(R.id.camera); + mGLRootView = (GLRootView) findViewById(R.id.settings_ui); + if (mIsImageCaptureIntent) { View controlBar = inflater.inflate( R.layout.attach_camera_control, rootView); @@ -1242,6 +1243,8 @@ public class Camera extends NoSearchActivity implements View.OnClickListener, @Override protected void onResume() { super.onResume(); + mGLRootView.onResume(); + mPreferences.registerOnSharedPreferenceChangeListener(this); mPausing = false; @@ -1278,6 +1281,7 @@ public class Camera extends NoSearchActivity implements View.OnClickListener, @Override protected void onPause() { mPausing = true; + mGLRootView.onPause(); stopPreview(); // Close the camera now because other activities may need to use it. closeCamera(); @@ -1788,9 +1792,9 @@ public class Camera extends NoSearchActivity implements View.OnClickListener, final String whiteBalance = mParameters.getWhiteBalance(); mFocusMode = mParameters.getFocusMode(); - if (mRootView != null) { + if (mHeadUpDisplay != null) { final String finalFlashMode = flashMode; - mRootView.queueEvent(new Runnable() { + mGLRootView.queueEvent(new Runnable() { public void run() { mHeadUpDisplay.overrideSettings( CameraSettings.KEY_FLASH_MODE, flashMode); @@ -1801,8 +1805,8 @@ public class Camera extends NoSearchActivity implements View.OnClickListener, }}); } } else { - if (mRootView != null) { - mRootView.queueEvent(new Runnable() { + if (mHeadUpDisplay != null) { + mGLRootView.queueEvent(new Runnable() { public void run() { mHeadUpDisplay.overrideSettings( CameraSettings.KEY_FLASH_MODE, null); diff --git a/src/com/android/camera/Menu3DTest.java b/src/com/android/camera/Menu3DTest.java index 5e599ad..c0adc6a 100644 --- a/src/com/android/camera/Menu3DTest.java +++ b/src/com/android/camera/Menu3DTest.java @@ -3,6 +3,7 @@ package com.android.camera; import android.app.Activity; import android.os.Bundle; import android.view.OrientationEventListener; +import android.widget.FrameLayout; import com.android.camera.ui.GLRootView; import com.android.camera.ui.HeadUpDisplay; @@ -21,7 +22,7 @@ public class Menu3DTest extends Activity { // set background as 18% gray :D mRootView.setBackgroundColor(0xffb7b7b7); - final HeadUpDisplay hud = new HeadUpDisplay(); + final HeadUpDisplay hud = new HeadUpDisplay(this); mRootView.setContentPane(hud); PreferenceInflater inflater = new PreferenceInflater(this); @@ -68,4 +69,11 @@ public class Menu3DTest extends Activity { mRootView.onPause(); mOrientationListener.disable(); } + + @Override + protected void onDestroy() { + mRootView = null; + setContentView(new FrameLayout(this)); + super.onDestroy(); + } } diff --git a/src/com/android/camera/ui/AbstractIndicator.java b/src/com/android/camera/ui/AbstractIndicator.java index 531640d..77fbc87 100644 --- a/src/com/android/camera/ui/AbstractIndicator.java +++ b/src/com/android/camera/ui/AbstractIndicator.java @@ -1,17 +1,19 @@ package com.android.camera.ui; +import android.content.Context; import android.graphics.Rect; import javax.microedition.khronos.opengles.GL11; public abstract class AbstractIndicator extends GLView { - private static final int DEFAULT_PADDING = 5; + private static final int DEFAULT_PADDING = 3; abstract protected ResourceTexture getIcon(); - public AbstractIndicator() { - setPaddings(DEFAULT_PADDING, 0, DEFAULT_PADDING, 0); + public AbstractIndicator(Context context) { + int padding = GLRootView.dpToPixel(context, DEFAULT_PADDING); + setPaddings(padding, 0, padding, 0); } @Override diff --git a/src/com/android/camera/ui/BasicIndicator.java b/src/com/android/camera/ui/BasicIndicator.java index 0d97ee7..3a5b330 100644 --- a/src/com/android/camera/ui/BasicIndicator.java +++ b/src/com/android/camera/ui/BasicIndicator.java @@ -4,6 +4,7 @@ import android.content.Context; import com.android.camera.IconListPreference; import com.android.camera.R; +import com.android.camera.Util; import com.android.camera.ui.GLListView.OnItemSelectedListener; public class BasicIndicator extends AbstractIndicator { @@ -15,7 +16,8 @@ public class BasicIndicator extends AbstractIndicator { private PreferenceAdapter mModel; private String mOverride; - public BasicIndicator(IconListPreference preference) { + public BasicIndicator(Context context, IconListPreference preference) { + super(context); mPreference = preference; mIcon = new ResourceTexture[preference.getIconIds().length]; mIndex = preference.findIndexOfValue(preference.getValue()); @@ -24,12 +26,16 @@ public class BasicIndicator extends AbstractIndicator { @Override public void overrideSettings(String key, String settings) { IconListPreference pref = mPreference; - if (!pref.getKey().equals(key)) return; + if (Util.equals(mOverride, settings)) return; + mOverride = settings; - mIndex = pref.findIndexOfValue( + int index = pref.findIndexOfValue( settings == null ? pref.getValue() : settings); - invalidate(); + if (mIndex != index) { + mIndex = index; + invalidate(); + } } @Override diff --git a/src/com/android/camera/ui/GLListView.java b/src/com/android/camera/ui/GLListView.java index c5161ea..bbee042 100644 --- a/src/com/android/camera/ui/GLListView.java +++ b/src/com/android/camera/ui/GLListView.java @@ -66,8 +66,8 @@ public class GLListView extends GLView { int height = bounds.height(); mHighLight.setSize(width, height); if (mHighLight.bind(root, gl)) { - root.draw2D(bounds.left - mScrollX, - bounds.top - mScrollY, width, height); + mHighLight.draw(root, + bounds.left - mScrollX, bounds.top - mScrollY); } } } @@ -80,7 +80,7 @@ public class GLListView extends GLView { mScrollbar.setSize(width, height); if (mScrollbar.bind(root, gl)) { int yoffset = mScrollY * getHeight() / mScrollHeight; - root.draw2D(getWidth() - width, yoffset, width, height); + mScrollbar.draw(root, getWidth() - width, yoffset); } } } diff --git a/src/com/android/camera/ui/GLOptionHeader.java b/src/com/android/camera/ui/GLOptionHeader.java index d49fbc4..bec9b76 100644 --- a/src/com/android/camera/ui/GLOptionHeader.java +++ b/src/com/android/camera/ui/GLOptionHeader.java @@ -1,5 +1,6 @@ package com.android.camera.ui; +import android.content.Context; import android.graphics.Rect; import com.android.camera.ListPreference; @@ -8,15 +9,17 @@ import javax.microedition.khronos.opengles.GL11; public class GLOptionHeader extends GLView { private static final int FONT_COLOR = 0xFF979797; + private static final float FONT_SIZE = 12; private final ListPreference mPreference; private final StringTexture mTitle; private NinePatchTexture mBackground; - public GLOptionHeader(ListPreference preference) { + public GLOptionHeader(Context context, ListPreference preference) { + float fontSize = GLRootView.dpToPixel(context, FONT_SIZE); mPreference = preference; mTitle = StringTexture.newInstance( - preference.getTitle(), 16, FONT_COLOR); + preference.getTitle(), fontSize, FONT_COLOR); } public ListPreference getPreference() { diff --git a/src/com/android/camera/ui/GLOptionItem.java b/src/com/android/camera/ui/GLOptionItem.java index 00d7a55..9229813 100644 --- a/src/com/android/camera/ui/GLOptionItem.java +++ b/src/com/android/camera/ui/GLOptionItem.java @@ -1,5 +1,6 @@ package com.android.camera.ui; +import static com.android.camera.ui.GLRootView.dpToPixel; import android.content.Context; import android.graphics.Color; import android.graphics.Rect; @@ -11,46 +12,68 @@ import javax.microedition.khronos.opengles.GL11; public class GLOptionItem extends GLView { private static final int FONT_COLOR = Color.WHITE; - private static final int MINIMAL_WIDTH = 180; - private static final int MINIMAL_HEIGHT = 48; - private static final int NO_ICON_LEADING_SPACE = 15; - private static final int TEXT_LEFT_PADDING = 9; - private static final int TEXT_RIGHT_PADDING = 15; + private static final float FONT_SIZE = 18; + + private static final int MINIMAL_WIDTH = 120; + private static final int MINIMAL_HEIGHT = 32; + + private static final int NO_ICON_LEADING_SPACE = 10; + private static final int TEXT_LEFT_PADDING = 6; + private static final int TEXT_RIGHT_PADDING = 10; + private static final float ENABLED_ALPHA = 1f; private static final float DISABLED_ALPHA = 0.3f; private static ResourceTexture sCheckOn; private static ResourceTexture sCheckOff; + private static int sNoIconLeadingSpace; + private static int sTextLeftPadding; + private static int sTextRightPadding; + private static int sMinimalWidth; + private static int sMinimalHeight; + private static float sFontSize; + private final ResourceTexture mIcon; private final StringTexture mText; private boolean mEnabled = true; private ResourceTexture mCheckBox; - private static void initCheckIcons(Context context) { + + private static void initializeStaticVariables(Context context) { if (sCheckOn != null) return; + sCheckOn = new ResourceTexture(context, R.drawable.ic_menuselect_on); sCheckOff = new ResourceTexture(context, R.drawable.ic_menuselect_off); + + sNoIconLeadingSpace = dpToPixel(context, NO_ICON_LEADING_SPACE); + sTextLeftPadding = dpToPixel(context, TEXT_LEFT_PADDING); + sTextRightPadding = dpToPixel(context, TEXT_RIGHT_PADDING); + sMinimalWidth = dpToPixel(context, MINIMAL_WIDTH); + sMinimalHeight = dpToPixel(context, MINIMAL_HEIGHT); + + sFontSize = dpToPixel(context, FONT_SIZE); } public GLOptionItem(Context context, int iconId, String title) { - initCheckIcons(context); + initializeStaticVariables(context); mIcon = iconId == 0 ? null : new ResourceTexture(context, iconId); - mText = StringTexture.newInstance(title, 26, FONT_COLOR); + mText = StringTexture.newInstance(title, sFontSize, FONT_COLOR); mCheckBox = sCheckOff; } @Override protected void onMeasure(int widthSpec, int heightSpec) { - int width = (mIcon == null ? NO_ICON_LEADING_SPACE : mIcon.getWidth()) - + mText.getWidth() + mCheckBox.getWidth() - + TEXT_RIGHT_PADDING + TEXT_LEFT_PADDING; + int width = mIcon == null ? sNoIconLeadingSpace : mIcon.getWidth(); + width += mText.getWidth() + mCheckBox.getWidth(); + width += sTextRightPadding + sTextLeftPadding; + int height = Math.max(Math.max(mIcon == null ? 0 : mIcon.getHeight(), mText.getHeight()), mCheckBox.getHeight()); - width = Math.max(MINIMAL_WIDTH, width); - height = Math.max(MINIMAL_HEIGHT, height); + width = Math.max(sMinimalWidth, width); + height = Math.max(sMinimalHeight, height); new MeasureHelper(this) .setPreferedContentSize(width, height) @@ -78,11 +101,11 @@ public class GLOptionItem extends GLView { } xoffset += icon.getWidth(); } else { - xoffset += NO_ICON_LEADING_SPACE; + xoffset += sNoIconLeadingSpace; } StringTexture title = mText; - xoffset += TEXT_LEFT_PADDING; + xoffset += sTextLeftPadding; if (title.bind(root, gl)) { int yoffset = p.top + (height - title.getHeight()) / 2; //TODO: cut the text if it is too long diff --git a/src/com/android/camera/ui/GLRootView.java b/src/com/android/camera/ui/GLRootView.java index 23db5f8..b16d443 100644 --- a/src/com/android/camera/ui/GLRootView.java +++ b/src/com/android/camera/ui/GLRootView.java @@ -7,21 +7,22 @@ import android.graphics.PixelFormat; import android.opengl.GLSurfaceView; import android.opengl.GLU; import android.os.Process; +import android.os.SystemClock; import android.util.AttributeSet; import android.util.DisplayMetrics; import android.util.Log; import android.view.MotionEvent; +import android.view.animation.Animation; import android.view.animation.Transformation; import com.android.camera.Util; import java.nio.ByteBuffer; import java.nio.ByteOrder; +import java.util.ArrayList; import java.util.Stack; import java.util.concurrent.Callable; import java.util.concurrent.FutureTask; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; import javax.microedition.khronos.egl.EGLConfig; import javax.microedition.khronos.opengles.GL10; @@ -36,18 +37,19 @@ public class GLRootView extends GLSurfaceView private int mFrameCount = 0; private long mFrameCountingStart = 0; - // The event processing timeout for GL events, 1.5 seconds - private static final long EVENT_TIMEOUT = 1500; private static final int VERTEX_BUFFER_SIZE = 8; private static final int FLAG_INITIALIZED = 1; private static final int FLAG_NEED_LAYOUT = 2; - private static final int FLAG_TEXTURE_MODE = 4; + + private static float sPixelDensity = -1f; private GL11 mGL; private GLView mContentView; private DisplayMetrics mDisplayMetrics; + private final ArrayList<Animation> mAnimations = new ArrayList<Animation>(); + private final Stack<Transformation> mFreeTransform = new Stack<Transformation>(); @@ -59,16 +61,46 @@ public class GLRootView extends GLSurfaceView private final float mMatrixValues[] = new float[16]; + private final float mCoordBuffer[] = new float[8]; + private final float mPointBuffer[] = new float[4]; + private ByteBuffer mVertexBuffer; private ByteBuffer mTexCoordBuffer; private int mFlags = FLAG_NEED_LAYOUT; + private long mAnimationTime; public GLRootView(Context context) { super(context); initialize(); } + void registerLaunchedAnimation(Animation animation) { + // Register the newly launched animation so that we can set the start + // time more precisely. (Usually, it takes much longer for the first + // rendering, so we set the animation start time as the time we + // complete rendering) + mAnimations.add(animation); + } + + public long currentAnimationTimeMillis() { + return mAnimationTime; + } + + public synchronized static float dpToPixel(Context context, float dp) { + if (sPixelDensity < 0) { + DisplayMetrics metrics = new DisplayMetrics(); + ((Activity) context).getWindowManager() + .getDefaultDisplay().getMetrics(metrics); + sPixelDensity = metrics.density; + } + return sPixelDensity * dp; + } + + public static int dpToPixel(Context context, int dp) { + return (int)(dpToPixel(context, (float) dp) + .5f); + } + public Transformation obtainTransformation() { return mFreeTransform.isEmpty() ? new Transformation() : mFreeTransform.pop(); } @@ -103,7 +135,7 @@ public class GLRootView extends GLSurfaceView setEGLConfigChooser(8, 8, 8, 8, 0, 0); getHolder().setFormat(PixelFormat.TRANSLUCENT); setZOrderOnTop(true); - super.setDebugFlags(DEBUG_CHECK_GL_ERROR); + setDebugFlags(DEBUG_CHECK_GL_ERROR); setRenderer(this); @@ -196,7 +228,6 @@ public class GLRootView extends GLSurfaceView gl.glEnableClientState(GL10.GL_VERTEX_ARRAY); gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY); gl.glEnable(GL11.GL_TEXTURE_2D); - gl.glEnable(GL11.GL_STENCIL_TEST); gl.glTexEnvf(GL11.GL_TEXTURE_ENV, GL11.GL_TEXTURE_ENV_MODE, GL11.GL_REPLACE); @@ -210,10 +241,6 @@ public class GLRootView extends GLSurfaceView gl.glTexCoordPointer(2, GL11.GL_FLOAT, 0, mTexCoordBuffer); } - protected void setTexCoords(float ... point) { - mTexCoordBuffer.asFloatBuffer().put(point).position(0); - } - /** * Called when the OpenGL surface is recreated without destroying the * context. @@ -223,6 +250,7 @@ public class GLRootView extends GLSurfaceView Log.v(TAG, "onSurfaceChanged: " + width + "x" + height + ", gl10: " + gl1.toString()); GL11 gl = (GL11) gl1; + mGL = gl; gl.glMatrixMode(GL11.GL_PROJECTION); gl.glLoadIdentity(); @@ -250,26 +278,39 @@ public class GLRootView extends GLSurfaceView } public void drawRect(int x, int y, int width, int height) { - drawRect(x, y, width, height, mTransformation.getAlpha()); + float matrix[] = mMatrixValues; + mTransformation.getMatrix().getValues(matrix); + drawRect(x, y, width, height, matrix, mTransformation.getAlpha()); } - public void drawRect(int x, int y, int width, int height, float alpha) { + private void drawRect( + int x, int y, int width, int height, float matrix[], float alpha) { GL11 gl = mGL; gl.glPushMatrix(); - mTransformation.getMatrix().getValues(mMatrixValues); - setAlphaValue(alpha); - gl.glMultMatrixf(toGLMatrix(mMatrixValues), 0); + gl.glMultMatrixf(toGLMatrix(matrix), 0); gl.glTranslatef(x, y, 0); gl.glScalef(width, height, 1); gl.glDrawArrays(GL11.GL_TRIANGLE_STRIP, 0, 4); gl.glPopMatrix(); } - public void clipRect(int x, int y, int width, int height) { - float point[] = new float[]{x, y + height, x + width, y}; + public void drawRect(int x, int y, int width, int height, float alpha) { + float matrix[] = mMatrixValues; + mTransformation.getMatrix().getValues(matrix); + drawRect(x, y, width, height, matrix, alpha); + } - mTransformation.getMatrix().mapPoints(point); + private float[] mapPoints(Matrix matrix, int x1, int y1, int x2, int y2) { + float[] point = mPointBuffer; + point[0] = x1; point[1] = y1; point[2] = x2; point[3] = y2; + matrix.mapPoints(point); + return point; + } + + public void clipRect(int x, int y, int width, int height) { + float point[] = mapPoints( + mTransformation.getMatrix(), x, y + height, x + width, y); // mMatrix could be a rotation matrix. In this case, we need to find // the boundaries after rotation. (only handle 90 * n degrees) @@ -302,20 +343,23 @@ public class GLRootView extends GLSurfaceView return v; } - public void draw2D(int x, int y, int width, int height, float alpha) { + public void drawTexture( + Texture texture, int x, int y, int width, int height, float alpha) { + if (width <= 0 || height <= 0) return ; Matrix matrix = mTransformation.getMatrix(); matrix.getValues(mMatrixValues); - // Test if it has been rotated, if it is, glDrawTexiOES won't work - if (mMatrixValues[1] != 0 - || mMatrixValues[3] != 0 || mMatrixValues[0] < 0) { - drawRect(x, y, width, height, alpha); + // Test whether it has been rotated or flipped, if so, glDrawTexiOES + // won't work + if (isMatrixRotatedOrFlipped(mMatrixValues)) { + texture.getTextureCoords(mCoordBuffer, 0); + mTexCoordBuffer.asFloatBuffer().put(mCoordBuffer).position(0); + drawRect(x, y, width, height, mMatrixValues, alpha); } else { // draw the rect from bottom-left to top-right - float points[] = new float[]{x, y + height, x + width, y}; - matrix.mapPoints(points); + float points[] = mapPoints(matrix, x, y + height, x + width, y); x = (int) points[0]; y = (int) points[1]; width = (int) points[2] - x; @@ -327,8 +371,14 @@ public class GLRootView extends GLSurfaceView } } - public void draw2D(int x, int y, int width, int height) { - draw2D(x, y, width, height, mTransformation.getAlpha()); + private static boolean isMatrixRotatedOrFlipped(float matrix[]) { + return matrix[Matrix.MSKEW_X] != 0 || matrix[Matrix.MSKEW_Y] != 0 + || matrix[Matrix.MSCALE_X] < 0 || matrix[Matrix.MSCALE_Y] > 0; + } + + public void drawTexture( + Texture texture, int x, int y, int width, int height) { + drawTexture(texture, x, y, width, height, mTransformation.getAlpha()); } // This is a GLSurfaceView.Renderer callback @@ -345,34 +395,36 @@ public class GLRootView extends GLSurfaceView } ++mFrameCount; } + if ((mFlags & FLAG_NEED_LAYOUT) != 0) layoutContentPane(); - // gl.glScissor(0, 0, getWidth(), getHeight()); - gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_STENCIL_BUFFER_BIT); + gl.glClear(GL10.GL_COLOR_BUFFER_BIT); gl.glEnable(GL11.GL_BLEND); gl.glBlendFunc(GL11.GL_ONE, GL11.GL_ONE_MINUS_SRC_ALPHA); - /*gl.glBindTexture(GL11.GL_TEXTURE_2D, 0); + /*gl.glDisable(GL11.GL_TEXTURE_2D); gl.glColor4f(0, 0, 0.5f, 0.4f); - drawRect(30, 30, 30, 30);*/ + drawRect(30, 30, 30, 30); + gl.glEnable(GL11.GL_TEXTURE_2D);*/ + mAnimationTime = SystemClock.uptimeMillis(); if (mContentView != null) { mContentView.render(GLRootView.this, (GL11) gl); } + long now = SystemClock.uptimeMillis(); + for (Animation animation : mAnimations) { + animation.setStartTime(now); + } + mAnimations.clear(); } @Override public boolean dispatchTouchEvent(MotionEvent event) { - - // Allocate a new event to prevent concurrency access FutureTask<Boolean> task = new FutureTask<Boolean>( - new TouchEventHandler(MotionEvent.obtain(event))); + new TouchEventHandler(event)); queueEvent(task); try { - return task.get(EVENT_TIMEOUT, TimeUnit.MILLISECONDS); - } catch (TimeoutException e) { - Log.w(TAG, "event timeout, assume the event is handled"); - return true; + return task.get(); } catch (Exception e) { throw new RuntimeException(e); } @@ -387,6 +439,7 @@ public class GLRootView extends GLSurfaceView } public Boolean call() throws Exception { + if (mContentView == null) return false; return mContentView.dispatchTouchEvent(mEvent); } } @@ -400,19 +453,16 @@ public class GLRootView extends GLSurfaceView return mDisplayMetrics; } - public Texture copyTexture2D(int x, int y, int width, int height) + public void copyTexture2D( + RawTexture texture, int x, int y, int width, int height) throws GLOutOfMemoryException { - Matrix matrix = mTransformation.getMatrix(); matrix.getValues(mMatrixValues); - // Test if it has been rotated, if it is, glDrawTexiOES won't work - if (mMatrixValues[1] != 0 || mMatrixValues[3] != 0) { + if (isMatrixRotatedOrFlipped(mMatrixValues)) { throw new IllegalArgumentException("cannot support rotated matrix"); } - - float points[] = new float[]{x, y + height, x + width, y}; - matrix.mapPoints(points); + float points[] = mapPoints(matrix, x, y + height, x + width, y); x = (int) points[0]; y = (int) points[1]; width = (int) points[2] - x; @@ -423,9 +473,8 @@ public class GLRootView extends GLSurfaceView int newHeight = Util.nextPowerOf2(height); int glError = GL11.GL_NO_ERROR; - int[] textureId = new int[1]; - gl.glGenTextures(1, textureId, 0); - gl.glBindTexture(GL11.GL_TEXTURE_2D, textureId[0]); + gl.glBindTexture(GL11.GL_TEXTURE_2D, texture.getId()); + int[] cropRect = {0, 0, width, height}; gl.glTexParameteriv(GL11.GL_TEXTURE_2D, GL11Ext.GL_TEXTURE_CROP_RECT_OES, cropRect, 0); @@ -445,12 +494,13 @@ public class GLRootView extends GLSurfaceView throw new GLOutOfMemoryException(); } - if (glError == GL11.GL_NO_ERROR) { - return new RawTexture(gl, textureId[0], width, height, - (float) width / newWidth, (float) height / newHeight); + if (glError != GL11.GL_NO_ERROR) { + throw new RuntimeException( + "Texture copy fail, glError " + glError); } - throw new RuntimeException( - "Texture copy fail, glError " + glError); - } + texture.setSize(width, height); + texture.setTexCoordSize( + (float) width / newWidth, (float) height / newHeight); + } } diff --git a/src/com/android/camera/ui/GLView.java b/src/com/android/camera/ui/GLView.java index 1df1f9e..3154ff7 100644 --- a/src/com/android/camera/ui/GLView.java +++ b/src/com/android/camera/ui/GLView.java @@ -4,7 +4,6 @@ import android.graphics.Matrix; import android.graphics.Rect; import android.view.MotionEvent; import android.view.animation.Animation; -import android.view.animation.AnimationUtils; import android.view.animation.Transformation; import java.util.ArrayList; @@ -69,10 +68,14 @@ public class GLView { } public void startAnimation(Animation animation) { + GLRootView root = getGLRootView(); + if (root == null) throw new IllegalStateException(); + mAnimation = animation; animation.initialize(getWidth(), getHeight(), mParent.getWidth(), mParent.getHeight()); mAnimation.start(); + root.registerLaunchedAnimation(animation); invalidate(); } @@ -183,15 +186,16 @@ public class GLView { } protected void renderChild(GLRootView root, GL11 gl, GLView component) { - Animation anim = component.mAnimation; int xoffset = component.mBounds.left - mScrollX; int yoffset = component.mBounds.top - mScrollY; Transformation transform = root.getTransformation(); Matrix matrix = transform.getMatrix(); matrix.preTranslate(xoffset, yoffset); + + Animation anim = component.mAnimation; if (anim != null) { - long now = AnimationUtils.currentAnimationTimeMillis(); + long now = root.currentAnimationTimeMillis(); Transformation temp = root.obtainTransformation(); temp.clear(); if (!anim.getTransformation(now, temp)) { diff --git a/src/com/android/camera/ui/GpsIndicator.java b/src/com/android/camera/ui/GpsIndicator.java index 27fe0a1..955b3ae 100644 --- a/src/com/android/camera/ui/GpsIndicator.java +++ b/src/com/android/camera/ui/GpsIndicator.java @@ -12,8 +12,8 @@ public class GpsIndicator extends BasicIndicator { private ResourceTexture mNoSignalIcon; private boolean mHasSignal = false; - public GpsIndicator(IconListPreference preference) { - super(preference); + public GpsIndicator(Context context, IconListPreference preference) { + super(context, preference); } @Override diff --git a/src/com/android/camera/ui/HeadUpDisplay.java b/src/com/android/camera/ui/HeadUpDisplay.java index c2e444c..585884a 100644 --- a/src/com/android/camera/ui/HeadUpDisplay.java +++ b/src/com/android/camera/ui/HeadUpDisplay.java @@ -1,5 +1,6 @@ package com.android.camera.ui; +import static com.android.camera.ui.GLRootView.dpToPixel; import android.content.Context; import android.graphics.Rect; import android.os.Handler; @@ -23,13 +24,20 @@ import java.util.concurrent.Callable; import java.util.concurrent.FutureTask; public class HeadUpDisplay extends GLView { - private static final int INDICATOR_BAR_RIGHT_MARGIN = 15; - private static final int POPUP_WINDOW_OVERLAP = 30; + private static final int INDICATOR_BAR_RIGHT_MARGIN = 10; + private static final int POPUP_WINDOW_OVERLAP = 20; + private static final int POPUP_TRIANGLE_OFFSET = 16; + private static final float MAX_HEIGHT_RATIO = 0.8f; private static final float MAX_WIDTH_RATIO = 0.8f; private static final int HIDE_POPUP_WINDOW = 0; private static final int DEACTIVATE_INDICATOR_BAR = 1; + + private static int sIndicatorBarRightMargin = -1; + private static int sPopupWindowOverlap; + private static int sPopupTriangleOffset; + protected static final String TAG = "HeadUpDisplay"; private IndicatorBar mIndicatorBar; @@ -48,7 +56,9 @@ public class HeadUpDisplay extends GLView { private final Handler mHandler; - public HeadUpDisplay() { + public HeadUpDisplay(Context context) { + initializeStaticVariables(context); + mTimerThread.setDaemon(true); mTimerThread.start(); mHandler = new Handler(mTimerThread.getLooper()) { @@ -76,6 +86,14 @@ public class HeadUpDisplay extends GLView { }; } + private static void initializeStaticVariables(Context context) { + if (sIndicatorBarRightMargin >= 0) return; + + sIndicatorBarRightMargin = dpToPixel(context, INDICATOR_BAR_RIGHT_MARGIN); + sPopupWindowOverlap = dpToPixel(context, POPUP_WINDOW_OVERLAP); + sPopupTriangleOffset = dpToPixel(context, POPUP_TRIANGLE_OFFSET); + } + private final Callable<Void> mHidePopupWindow = new Callable<Void> () { public Void call() throws Exception { hidePopupWindow(); @@ -206,7 +224,7 @@ public class HeadUpDisplay extends GLView { mPopupWindow.setBackground( new NinePatchTexture(context, R.drawable.menu_popup)); mPopupWindow.setAnchor(new ResourceTexture( - context, R.drawable.menu_popup_triangle), 23); + context, R.drawable.menu_popup_triangle), sPopupTriangleOffset); mPopupWindow.setVisibility(GLView.INVISIBLE); mPopupWindow.setOrientation(mOrientation); addComponent(mPopupWindow); @@ -253,12 +271,12 @@ public class HeadUpDisplay extends GLView { return list.toArray(new ListPreference[list.size()]); } - private static BasicIndicator addIndicator( + private static BasicIndicator addIndicator(Context context, IndicatorBar indicatorBar, PreferenceGroup group, String key) { IconListPreference iconPref = (IconListPreference) group.findPreference(key); if (iconPref == null) return null; - BasicIndicator indicator = new BasicIndicator(iconPref); + BasicIndicator indicator = new BasicIndicator(context, iconPref); indicatorBar.addComponent(indicator); return indicator; } @@ -274,6 +292,7 @@ public class HeadUpDisplay extends GLView { context, R.drawable.ic_viewfinder_iconbar_highlight)); OtherSettingsIndicator otherSettings = new OtherSettingsIndicator( + context, getListPreferences(group, CameraSettings.KEY_FOCUS_MODE, CameraSettings.KEY_SCENE_MODE, @@ -282,13 +301,17 @@ public class HeadUpDisplay extends GLView { CameraSettings.KEY_COLOR_EFFECT)); mIndicatorBar.addComponent(otherSettings); - GpsIndicator gpsIndicator = new GpsIndicator((IconListPreference) + GpsIndicator gpsIndicator = new GpsIndicator( + context, (IconListPreference) group.findPreference(CameraSettings.KEY_RECORD_LOCATION)); + mGpsIndicator = gpsIndicator; mIndicatorBar.addComponent(gpsIndicator); - addIndicator(mIndicatorBar, group, CameraSettings.KEY_WHITE_BALANCE); - addIndicator(mIndicatorBar, group, CameraSettings.KEY_FLASH_MODE); + addIndicator(context, mIndicatorBar, group, + CameraSettings.KEY_WHITE_BALANCE); + addIndicator(context, mIndicatorBar, group, + CameraSettings.KEY_FLASH_MODE); addComponent(mIndicatorBar); mIndicatorBar.setOnItemSelectedListener(new IndicatorBarListener()); @@ -313,7 +336,7 @@ public class HeadUpDisplay extends GLView { public void onItemSelected(GLView view, int position) { Rect rect = new Rect(); getBoundsOf(view, rect); - int anchorX = rect.left + POPUP_WINDOW_OVERLAP; + int anchorX = rect.left + sPopupWindowOverlap; int anchorY = (rect.top + rect.bottom) / 2; AbstractIndicator indicator = (AbstractIndicator) view; diff --git a/src/com/android/camera/ui/OtherSettingsIndicator.java b/src/com/android/camera/ui/OtherSettingsIndicator.java index 27d0d80..2833cfe 100644 --- a/src/com/android/camera/ui/OtherSettingsIndicator.java +++ b/src/com/android/camera/ui/OtherSettingsIndicator.java @@ -15,8 +15,10 @@ public class OtherSettingsIndicator extends AbstractIndicator { private GLListView mPopupContent; private final HashMap<String, String> mOverrides = new HashMap<String, String>(); - public OtherSettingsIndicator(ListPreference preference[]) { - mPreference = preference.clone(); + public OtherSettingsIndicator( + Context context, ListPreference preference[]) { + super(context); + mPreference = preference; mAdapters = new PreferenceAdapter[preference.length]; } @@ -56,7 +58,7 @@ public class OtherSettingsIndicator extends AbstractIndicator { String override = mOverrides.get(prefs[i].getKey()); if (override != null) adapters[i].overrideSettings(override); } - return new UberAdapter(adapters); + return new UberAdapter(); } @Override @@ -78,12 +80,6 @@ public class OtherSettingsIndicator extends AbstractIndicator { private class UberAdapter implements GLListView.Model, GLListView.OnItemSelectedListener { - private final PreferenceAdapter mAdapters[]; - - public UberAdapter(PreferenceAdapter[] adapters) { - mAdapters = adapters; - } - public GLView getView(int index) { for (PreferenceAdapter adapter : mAdapters) { if (index < adapter.size()) { diff --git a/src/com/android/camera/ui/PopupWindow.java b/src/com/android/camera/ui/PopupWindow.java index 616b3de..6ebf08c 100644 --- a/src/com/android/camera/ui/PopupWindow.java +++ b/src/com/android/camera/ui/PopupWindow.java @@ -17,14 +17,15 @@ public class PopupWindow extends GLView { protected int mAnchorPosition; private final RotatePane mRotatePane = new RotatePane(); + private RawTexture mBackupTexture; - protected NinePatchTexture mBackground; + protected FrameTexture mBackground; public PopupWindow() { super.addComponent(mRotatePane); } - public void setBackground(NinePatchTexture background) { + public void setBackground(FrameTexture background) { if (background == mBackground) return; mBackground = background; if (background != null) { @@ -89,7 +90,7 @@ public class PopupWindow extends GLView { } @Override - protected void renderBackground(GLRootView rootView, GL11 gl) { + protected void renderBackground(GLRootView root, GL11 gl) { int width = getWidth(); int height = getHeight(); int aWidth = mAnchor.getWidth(); @@ -101,30 +102,32 @@ public class PopupWindow extends GLView { aYoffset = Math.min(aYoffset, height - p.bottom - aHeight); if (mAnchor != null) { - if (mAnchor.bind(rootView, gl)) { - rootView.draw2D(aXoffset, aYoffset, aWidth, aHeight); + if (mAnchor.bind(root, gl)) { + mAnchor.draw(root, aXoffset, aYoffset); } } - Texture backup = null; + if (mBackupTexture == null || mBackupTexture.getBoundGL() != gl) { + mBackupTexture = RawTexture.newInstance(gl); + } + + RawTexture backup = mBackupTexture; try { - backup = rootView.copyTexture2D( - aXoffset, aYoffset, aWidth, aHeight); + root.copyTexture2D(backup, aXoffset, aYoffset, aWidth, aHeight); } catch (GLOutOfMemoryException e) { e.printStackTrace(); } if (mBackground != null) { mBackground.setSize(width - aWidth + mAnchorOffset, height); - if (mBackground.bind(rootView, gl)) { - rootView.draw2D( - 0, 0, mBackground.getWidth(), mBackground.getHeight()); + if (mBackground.bind(root, gl)) { + mBackground.draw(root, 0, 0); } } - if (backup.bind(rootView, gl)) { + if (backup.bind(root, gl)) { gl.glBlendFunc(GL11.GL_ONE, GL11.GL_ZERO); - rootView.draw2D(aXoffset, aYoffset, aWidth, aHeight, 1); + backup.draw(root, aXoffset, aYoffset, aWidth, aHeight, 1); gl.glBlendFunc(GL11.GL_ONE, GL11.GL_ONE_MINUS_SRC_ALPHA); } } @@ -148,8 +151,8 @@ public class PopupWindow extends GLView { set.addAnimation(scale); set.addAnimation(alpha); - scale.setDuration(200); - alpha.setDuration(200); + scale.setDuration(150); + alpha.setDuration(100); scale.setInterpolator(new OvershootInterpolator()); startAnimation(set); } diff --git a/src/com/android/camera/ui/PopupWindowStencilImpl.java b/src/com/android/camera/ui/PopupWindowStencilImpl.java index eaf9134..b05b4e5 100644 --- a/src/com/android/camera/ui/PopupWindowStencilImpl.java +++ b/src/com/android/camera/ui/PopupWindowStencilImpl.java @@ -23,7 +23,7 @@ public class PopupWindowStencilImpl extends PopupWindow { gl.glStencilOp(GL11.GL_KEEP, GL11.GL_KEEP, GL11.GL_REPLACE); gl.glStencilFunc(GL11.GL_ALWAYS, 1, 1); if (mAnchor.bind(rootView, gl)) { - rootView.draw2D(aXoffset, aYoffset, aWidth, aHeight); + mAnchor.draw(rootView, aXoffset, aYoffset); } gl.glStencilFunc(GL11.GL_NOTEQUAL, 1, 1); gl.glStencilOp(GL11.GL_KEEP, GL11.GL_KEEP, GL11.GL_KEEP); @@ -32,8 +32,7 @@ public class PopupWindowStencilImpl extends PopupWindow { if (mBackground != null) { mBackground.setSize(width - aWidth + mAnchorOffset, height); if (mBackground.bind(rootView, gl)) { - rootView.draw2D( - 0, 0, mBackground.getWidth(), mBackground.getHeight()); + mBackground.draw(rootView, 0, 0); } } } diff --git a/src/com/android/camera/ui/PreferenceAdapter.java b/src/com/android/camera/ui/PreferenceAdapter.java index 233f154..de3cda9 100644 --- a/src/com/android/camera/ui/PreferenceAdapter.java +++ b/src/com/android/camera/ui/PreferenceAdapter.java @@ -1,5 +1,6 @@ package com.android.camera.ui; +import static com.android.camera.ui.GLRootView.dpToPixel; import android.content.Context; import com.android.camera.IconListPreference; @@ -13,16 +14,26 @@ public class PreferenceAdapter implements GLListView.Model, GLListView.OnItemSelectedListener { private static final int ICON_NONE = 0; + private static final int HORIZONTAL_PADDINGS = 4; + private static final int VERTICAL_PADDINGS = 2; + + private static int sHorizontalPaddings = -1; + private static int sVerticalPaddings; - private final Context mContext; private final ArrayList<GLView> mContent = new ArrayList<GLView>(); private final ListPreference mPreference; private String mOverride; + private static void initializeStaticVariable(Context context) { + if (sHorizontalPaddings >= 0) return; + sHorizontalPaddings = dpToPixel(context, HORIZONTAL_PADDINGS); + sVerticalPaddings = dpToPixel(context, VERTICAL_PADDINGS); + } + public PreferenceAdapter(Context context, ListPreference preference) { - mContext = context; + initializeStaticVariable(context); mPreference = preference; - generateContent(preference); + generateContent(context, preference); } public void overrideSettings(String settings) { @@ -47,13 +58,12 @@ public class PreferenceAdapter } } - private void generateContent(ListPreference preference) { - Context context = mContext; - - GLOptionHeader header = new GLOptionHeader(preference); + private void generateContent(Context context, ListPreference preference) { + GLOptionHeader header = new GLOptionHeader(context, preference); header.setBackground(new NinePatchTexture( context, R.drawable.optionheader_background)); - header.setPaddings(5, 2, 5, 2); + header.setPaddings(sHorizontalPaddings, + sVerticalPaddings, sHorizontalPaddings, sVerticalPaddings); mContent.add(header); CharSequence[] entries = preference.getEntries(); CharSequence[] values = preference.getEntryValues(); @@ -67,7 +77,8 @@ public class PreferenceAdapter GLOptionItem item = new GLOptionItem( context, icons == null ? ICON_NONE : icons[i], entries[i].toString()); - item.setPaddings(5, 2, 5, 2); + item.setPaddings(sHorizontalPaddings, + sVerticalPaddings, sHorizontalPaddings, sVerticalPaddings); item.setChecked(values[i].equals(value)); mContent.add(item); } diff --git a/src/com/android/camera/ui/RawTexture.java b/src/com/android/camera/ui/RawTexture.java index d8c9cda..aecea9d 100644 --- a/src/com/android/camera/ui/RawTexture.java +++ b/src/com/android/camera/ui/RawTexture.java @@ -6,11 +6,22 @@ import javax.microedition.khronos.opengles.GL11; public class RawTexture extends Texture { - protected RawTexture(GL11 gl, int id, - int width, int height, float widthf, float heightf) { + private RawTexture(GL11 gl, int id) { super(gl, id, STATE_LOADED); - super.setSize(width, height); - super.setTexCoordSize(widthf, heightf); + } + + public GL11 getBoundGL() { + return mGL; + } + + public static RawTexture newInstance(GL11 gl) { + int[] textureId = new int[1]; + gl.glGenTextures(1, textureId, 0); + int glError = gl.glGetError(); + if (glError != GL11.GL_NO_ERROR) { + throw new RuntimeException("GL_ERROR: " + glError); + } + return new RawTexture(gl, textureId[0]); } @Override @@ -23,4 +34,12 @@ public class RawTexture extends Texture { throw new UnsupportedOperationException(); } + @Override + protected boolean bind(GLRootView glRootView, GL11 gl) { + if (mGL == gl) { + gl.glBindTexture(GL11.GL_TEXTURE_2D, getId()); + return true; + } + return false; + } } diff --git a/src/com/android/camera/ui/StateListTexture.java b/src/com/android/camera/ui/StateListTexture.java deleted file mode 100644 index 432450c..0000000 --- a/src/com/android/camera/ui/StateListTexture.java +++ /dev/null @@ -1,79 +0,0 @@ -package com.android.camera.ui; - -import android.graphics.Bitmap; -import android.graphics.Rect; - -import java.util.ArrayList; - -import javax.microedition.khronos.opengles.GL11; - -public class StateListTexture extends FrameTexture { - - private int mIndex; - private final ArrayList<Entry> mEntries = new ArrayList<Entry>(); - - private static class Entry { - public int mMustHave; - public int mMustNotHave; - public FrameTexture mTexture; - - public Entry(int mustHave, int mustNotHave, FrameTexture texture) { - mMustHave = mustHave; - mMustNotHave = mustNotHave; - mTexture = texture; - } - } - - @Override - protected void freeBitmap(Bitmap bitmap) { - mEntries.get(mIndex).mTexture.freeBitmap(bitmap); - } - - @Override - protected Bitmap getBitmap() { - return mEntries.get(mIndex).mTexture.getBitmap(); - } - - private int getStateIndex(int state) { - for (int i = 0, n = mEntries.size(); i < n; ++i) { - Entry entry = mEntries.get(i); - if ((entry.mMustHave & state) == entry.mMustHave - && (state & entry.mMustNotHave) == 0) return i; - } - return -1; - } - - @Override - public void setSize(int width, int height) { - super.setSize(width, height); - for (Entry entry : mEntries) { - entry.mTexture.setSize(width, height); - } - } - - public boolean isDifferent(int stateA, int stateB) { - return getStateIndex(stateA) != getStateIndex(stateB); - } - - public boolean setState(int state) { - int oldIndex = mIndex; - mIndex = getStateIndex(state); - return mIndex != oldIndex; - } - - @Override - public boolean bind(GLRootView root, GL11 gl) { - if (mIndex < 0) return false; - return mEntries.get(mIndex).mTexture.bind(root, gl); - } - - public void addState( - int mustHave, int mustNotHave, FrameTexture texture) { - mEntries.add(new Entry(mustHave, mustNotHave, texture)); - } - - @Override - public Rect getPaddings() { - return mEntries.get(mIndex).mTexture.getPaddings(); - } -} diff --git a/src/com/android/camera/ui/Texture.java b/src/com/android/camera/ui/Texture.java index 6d5f8d8..aa116e7 100644 --- a/src/com/android/camera/ui/Texture.java +++ b/src/com/android/camera/ui/Texture.java @@ -19,10 +19,10 @@ public abstract class Texture { public static final int STATE_LOADED = 1; public static final int STATE_ERROR = -1; - private GL11 mGL; + protected GL11 mGL; - private int mId; - private int mState; + protected int mId; + protected int mState; protected int mWidth = UNSPECIFIED; protected int mHeight = UNSPECIFIED; @@ -119,31 +119,40 @@ public abstract class Texture { } public void draw(GLRootView root, int x, int y) { - draw(root, x, y, getWidth(), getHeight()); + root.drawTexture(this, x, y, mWidth, mHeight); } - public void draw(GLRootView root, - int x, int y, int width, int height) { - root.draw2D(x, y, width, height); + public void draw(GLRootView root, int x, int y, int w, int h, float alpha) { + root.drawTexture(this, x, y, w, h, alpha); } - protected boolean bind(GLRootView glRootView, GL11 gl) { + protected boolean bind(GLRootView root, GL11 gl) { if (mState == Texture.STATE_UNLOADED || mGL != gl) { mState = Texture.STATE_UNLOADED; try { uploadToGL(gl); } catch (GLOutOfMemoryException e) { - glRootView.handleLowMemory(); + root.handleLowMemory(); return false; } } else { gl.glBindTexture(GL11.GL_TEXTURE_2D, getId()); } + return true; + } + public void getTextureCoords(float coord[], int offset) { float w = mTexCoordWidth; float h = mTexCoordHeight; - glRootView.setTexCoords(0, 0, w, 0, 0, h, w, h); - return true; + + coord[offset++] = 0; + coord[offset++] = 0; + coord[offset++] = w; + coord[offset++] = 0; + coord[offset++] = 0; + coord[offset++] = h; + coord[offset++] = w; + coord[offset] = h; } protected Bitmap generateGLCompatibleBitmap(int width, int height) { diff --git a/src/com/android/camera/ui/GLZoomIndicator.java b/src/com/android/camera/ui/ZoomIndicator.java index c6612bf..36c06a3 100644 --- a/src/com/android/camera/ui/GLZoomIndicator.java +++ b/src/com/android/camera/ui/ZoomIndicator.java @@ -1,16 +1,20 @@ package com.android.camera.ui; +import android.content.Context; import android.graphics.Color; import android.graphics.Rect; import javax.microedition.khronos.opengles.GL11; -public class GLZoomIndicator extends GLView { +public class ZoomIndicator extends GLView { + + private static final int FONT_SIZE = 16; private final StringTexture mTitle; - public GLZoomIndicator(String title) { - mTitle = StringTexture.newInstance(title, 24, Color.WHITE); + public ZoomIndicator(Context context, String title) { + float fontSize = GLRootView.dpToPixel(context, FONT_SIZE); + mTitle = StringTexture.newInstance(title, fontSize, Color.WHITE); } @Override |