diff options
author | Andrew Sapperstein <asapperstein@google.com> | 2012-07-30 12:55:13 -0700 |
---|---|---|
committer | Andrew Sapperstein <asapperstein@google.com> | 2012-07-30 17:46:11 -0700 |
commit | b81f8c963a0d97034872f14f4e2294d1e2b44da1 (patch) | |
tree | 67155a1efe25e9f6b5e141e3e385c40db9dcd7ee | |
parent | 9a7b600e8bd26ed0a0095f62fb405e67d2f47834 (diff) | |
download | android_frameworks_ex-b81f8c963a0d97034872f14f4e2294d1e2b44da1.tar.gz android_frameworks_ex-b81f8c963a0d97034872f14f4e2294d1e2b44da1.tar.bz2 android_frameworks_ex-b81f8c963a0d97034872f14f4e2294d1e2b44da1.zip |
ActionBar now auto-hides like Gallery's version.
5 second delay from opened. Will not hide on first
appearance. Has be closed and re-opened. Also,
eliminated the progress spinner when the photo hadn't
yet loaded.
Additionally, modified the action bar to match gallery's
transparency.
Change-Id: I69e72d787bc2cda9c18df6a9cf1800d155d6876a
-rw-r--r-- | photoviewer/res/drawable-hdpi/actionbar_translucent.9.png | bin | 0 -> 155 bytes | |||
-rw-r--r-- | photoviewer/res/drawable-mdpi/actionbar_translucent.9.png | bin | 0 -> 153 bytes | |||
-rw-r--r-- | photoviewer/res/layout/photo_activity_view.xml | 16 | ||||
-rw-r--r-- | photoviewer/res/values/constants.xml | 21 | ||||
-rw-r--r-- | photoviewer/res/values/themes.xml | 7 | ||||
-rw-r--r-- | photoviewer/src/com/android/ex/photo/PhotoViewActivity.java | 69 | ||||
-rw-r--r-- | photoviewer/src/com/android/ex/photo/fragments/PhotoViewFragment.java | 8 |
7 files changed, 84 insertions, 37 deletions
diff --git a/photoviewer/res/drawable-hdpi/actionbar_translucent.9.png b/photoviewer/res/drawable-hdpi/actionbar_translucent.9.png Binary files differnew file mode 100644 index 0000000..f18761f --- /dev/null +++ b/photoviewer/res/drawable-hdpi/actionbar_translucent.9.png diff --git a/photoviewer/res/drawable-mdpi/actionbar_translucent.9.png b/photoviewer/res/drawable-mdpi/actionbar_translucent.9.png Binary files differnew file mode 100644 index 0000000..f78fb8a --- /dev/null +++ b/photoviewer/res/drawable-mdpi/actionbar_translucent.9.png diff --git a/photoviewer/res/layout/photo_activity_view.xml b/photoviewer/res/layout/photo_activity_view.xml index b7ffdfd..e273140 100644 --- a/photoviewer/res/layout/photo_activity_view.xml +++ b/photoviewer/res/layout/photo_activity_view.xml @@ -18,25 +18,11 @@ <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/photo_activity_root_view" android:layout_width="match_parent" - android:layout_height="match_parent" - android:background="@color/solid_black" > + android:layout_height="match_parent" > <com.android.ex.photo.PhotoViewPager android:id="@+id/photo_view_pager" android:layout_width="match_parent" android:layout_height="match_parent" /> - <LinearLayout - android:id="@+id/empty_view" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:layout_gravity="center" > - - <ProgressBar - style="?android:attr/progressBarStyleLarge" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:indeterminate="true" /> - </LinearLayout> - </FrameLayout> diff --git a/photoviewer/res/values/constants.xml b/photoviewer/res/values/constants.xml new file mode 100644 index 0000000..ae480ce --- /dev/null +++ b/photoviewer/res/values/constants.xml @@ -0,0 +1,21 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + Copyright (C) 2012 Google Inc. + Licensed to 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. +--> + +<resources> + <integer name="action_bar_delay_time_in_millis">5000</integer> +</resources> diff --git a/photoviewer/res/values/themes.xml b/photoviewer/res/values/themes.xml index 0945056..04bec53 100644 --- a/photoviewer/res/values/themes.xml +++ b/photoviewer/res/values/themes.xml @@ -17,9 +17,14 @@ --> <resources> - <style name="PhotoViewTheme" parent="android:Theme.Holo.Light.DarkActionBar"> + <style name="PhotoViewTheme" parent="android:Theme.Holo"> <item name="android:windowNoTitle">false</item> <item name="android:windowContentOverlay">@null</item> <item name="android:windowActionBarOverlay">true</item> + <item name="android:windowBackground">@color/solid_black</item> + <item name="android:actionBarStyle">@style/Holo.ActionBar</item> + </style> + <style name="Holo.ActionBar" parent="android:Widget.Holo.ActionBar"> + <item name="android:background">@drawable/actionbar_translucent</item> </style> </resources> diff --git a/photoviewer/src/com/android/ex/photo/PhotoViewActivity.java b/photoviewer/src/com/android/ex/photo/PhotoViewActivity.java index 9c04346..170a9eb 100644 --- a/photoviewer/src/com/android/ex/photo/PhotoViewActivity.java +++ b/photoviewer/src/com/android/ex/photo/PhotoViewActivity.java @@ -26,6 +26,7 @@ import android.content.Intent; import android.content.Loader; import android.database.Cursor; import android.net.Uri; +import android.os.Build; import android.os.Bundle; import android.os.Handler; import android.support.v4.view.ViewPager.OnPageChangeListener; @@ -57,7 +58,7 @@ public class PhotoViewActivity extends Activity implements /** * The full screen state has changed. */ - public void onFullScreenChanged(boolean fullScreen, boolean animate); + public void onFullScreenChanged(boolean fullScreen); /** * A new view has been activated and the previous view de-activated. @@ -120,8 +121,6 @@ public class PhotoViewActivity extends Activity implements private int mAlbumCount = ALBUM_COUNT_UNKNOWN; /** {@code true} if the view is empty. Otherwise, {@code false}. */ private boolean mIsEmpty; - /** The view to be shown if the current photo is not displayed. */ - private View mEmptyView; /** The main pager; provides left/right swipe between photos */ private PhotoViewPager mViewPager; /** Adapter to create pager views */ @@ -136,12 +135,14 @@ public class PhotoViewActivity extends Activity implements private boolean mRestartLoader; /** Whether or not this activity is paused */ private boolean mIsPaused = true; + private Handler mActionBarHideHandler; // TODO Find a better way to do this. We basically want the activity to display the // "loading..." progress until the fragment takes over and shows it's own "loading..." // progress [located in photo_header_view.xml]. We could potentially have all status displayed // by the activity, but, that gets tricky when it comes to screen rotation. For now, we // track the loading by this variable which is fragile and may cause phantom "loading..." // text. + private long mActionBarHideDelayTime; @Override protected void onCreate(Bundle savedInstanceState) { @@ -187,7 +188,6 @@ public class PhotoViewActivity extends Activity implements mPhotoIndex = currentItem; setContentView(R.layout.photo_activity_view); - mEmptyView = findViewById(R.id.empty_view); // Create the adapter and add the view pager mAdapter = new PhotoPagerAdapter(this, getFragmentManager(), null); @@ -203,6 +203,8 @@ public class PhotoViewActivity extends Activity implements final ActionBar actionBar = getActionBar(); actionBar.setDisplayHomeAsUpEnabled(true); + mActionBarHideDelayTime = getResources().getInteger( + R.integer.action_bar_delay_time_in_millis); } @Override @@ -373,12 +375,6 @@ public class PhotoViewActivity extends Activity implements } public void onFragmentVisible(PhotoViewFragment fragment) { - setEmptyViewVisibility( - fragment.isPhotoBound() ? View.GONE : View.VISIBLE); - } - - public void setEmptyViewVisibility(int visibility) { - mEmptyView.setVisibility(visibility); } @Override @@ -410,24 +406,67 @@ public class PhotoViewActivity extends Activity implements /** * Updates the title bar according to the value of {@link #mFullScreen}. */ - private void setFullScreen(boolean fullScreen, boolean animate) { + private void setFullScreen(boolean fullScreen, boolean setDelayedRunnable) { final boolean fullScreenChanged = (fullScreen != mFullScreen); mFullScreen = fullScreen; - ActionBar actionBar = getActionBar(); if (mFullScreen) { - actionBar.hide(); + setLightsOutMode(true); + if (mActionBarHideHandler == null) { + mActionBarHideHandler = new Handler(); + } + mActionBarHideHandler.removeCallbacks(mActionBarHideRunnable); } else { - actionBar.show(); + setLightsOutMode(false); + if (setDelayedRunnable) { + if (mActionBarHideHandler == null) { + mActionBarHideHandler = new Handler(); + } + mActionBarHideHandler.postDelayed(mActionBarHideRunnable, + mActionBarHideDelayTime); + } } if (fullScreenChanged) { for (OnScreenListener listener : mScreenListeners) { - listener.onFullScreenChanged(mFullScreen, animate); + listener.onFullScreenChanged(mFullScreen); + } + } + } + + private void setLightsOutMode(boolean enabled) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { + int flags = enabled + ? View.SYSTEM_UI_FLAG_LOW_PROFILE + | View.SYSTEM_UI_FLAG_FULLSCREEN + | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN + | View.SYSTEM_UI_FLAG_LAYOUT_STABLE + : View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN + | View.SYSTEM_UI_FLAG_LAYOUT_STABLE; + + // using mViewPager since we have it and we need a view + mViewPager.setSystemUiVisibility(flags); + } else { + final ActionBar actionBar = getActionBar(); + if (enabled) { + actionBar.hide(); + } else { + actionBar.show(); } + int flags = enabled + ? View.SYSTEM_UI_FLAG_LOW_PROFILE + : View.SYSTEM_UI_FLAG_VISIBLE; + mViewPager.setSystemUiVisibility(flags); } } + private Runnable mActionBarHideRunnable = new Runnable() { + @Override + public void run() { + PhotoViewActivity.this.setLightsOutMode(true); + } + }; + public void setViewActivated() { for (OnScreenListener listener : mScreenListeners) { listener.onViewActivated(); diff --git a/photoviewer/src/com/android/ex/photo/fragments/PhotoViewFragment.java b/photoviewer/src/com/android/ex/photo/fragments/PhotoViewFragment.java index b4e6cd5..8479f2c 100644 --- a/photoviewer/src/com/android/ex/photo/fragments/PhotoViewFragment.java +++ b/photoviewer/src/com/android/ex/photo/fragments/PhotoViewFragment.java @@ -299,15 +299,11 @@ public class PhotoViewFragment extends Fragment implements @Override public void onClick(View v) { - // If there is no photo, don't allow any actions except to exit - // full-screen mode. - if (mCallback.isFragmentFullScreen(this) || isPhotoBound()) { - mCallback.toggleFullScreen(); - } + mCallback.toggleFullScreen(); } @Override - public void onFullScreenChanged(boolean fullScreen, boolean animate) { + public void onFullScreenChanged(boolean fullScreen) { setViewVisibility(); } |