diff --git a/res/layout/reader_listitem_post_detail.xml b/res/layout/reader_listitem_post_detail.xml index d2dea98421f8..3481fa8a1fa5 100644 --- a/res/layout/reader_listitem_post_detail.xml +++ b/res/layout/reader_listitem_post_detail.xml @@ -90,6 +90,7 @@ android:id="@+id/webView" android:layout_width="match_parent" android:layout_height="wrap_content" + android:scrollbars="none" android:layout_marginLeft="@dimen/reader_list_margin" android:layout_marginRight="@dimen/reader_list_margin" android:layout_marginTop="@dimen/reader_margin_large" diff --git a/res/values/dimens.xml b/res/values/dimens.xml index aae8a9f3a5e3..2b2d2e5d448c 100644 --- a/res/values/dimens.xml +++ b/res/values/dimens.xml @@ -38,7 +38,7 @@ 12dp - 4dp + 8dp 48dp 48dp 96dp diff --git a/src/org/wordpress/android/ui/reader_native/NativeReaderActivity.java b/src/org/wordpress/android/ui/reader_native/NativeReaderActivity.java index 98219391418e..5892724d06f9 100644 --- a/src/org/wordpress/android/ui/reader_native/NativeReaderActivity.java +++ b/src/org/wordpress/android/ui/reader_native/NativeReaderActivity.java @@ -1,20 +1,14 @@ package org.wordpress.android.ui.reader_native; -import android.annotation.SuppressLint; import android.app.Activity; import android.content.Intent; -import android.graphics.Color; -import android.graphics.drawable.ColorDrawable; import android.os.Bundle; import android.support.v4.app.Fragment; import android.text.TextUtils; -import android.view.Window; import com.actionbarsherlock.view.MenuInflater; import com.actionbarsherlock.view.MenuItem; -import net.simonvt.menudrawer.MenuDrawer; - import org.wordpress.android.Constants; import org.wordpress.android.R; import org.wordpress.android.datasets.ReaderDatabase; @@ -26,7 +20,6 @@ import org.wordpress.android.ui.reader_native.actions.ReaderUserActions; import org.wordpress.android.util.NetworkUtils; import org.wordpress.android.util.ReaderLog; -import org.wordpress.android.util.SysUtils; import org.wordpress.android.util.ToastUtils; /* @@ -34,46 +27,19 @@ * this activity serves as the host for ReaderPostListFragment */ -public class NativeReaderActivity extends WPActionBarActivity implements ReaderPostListFragment.OnFirstVisibleItemChangeListener { +public class NativeReaderActivity extends WPActionBarActivity { private static final String TAG_FRAGMENT_POST_LIST = "reader_post_list"; private static final String KEY_INITIAL_UPDATE = "initial_update"; private static final String KEY_HAS_PURGED = "has_purged"; - // ActionBar alpha - protected static final int ALPHA_NONE = 0; - protected static final int ALPHA_LEVEL_1 = 245; - protected static final int ALPHA_LEVEL_2 = 230; - protected static final int ALPHA_LEVEL_3 = 215; - protected static final int ALPHA_LEVEL_4 = 200; - protected static final int ALPHA_LEVEL_5 = 185; - - private int mCurrentActionBarAlpha = 0; - private int mPrevActionBarAlpha = 0; - private MenuItem mRefreshMenuItem; private boolean mHasPerformedInitialUpdate = false; private boolean mHasPerformedPurge = false; - /* - * enable translucent ActionBar on ICS+ (buggy/unsupported on older versions) - */ - protected static boolean isTranslucentActionBarEnabled() { - return (SysUtils.isGteAndroid4()); - } - - @SuppressLint("NewApi") - protected static void enableTranslucentActionBar(Activity activity) { - activity.getWindow().requestFeature(Window.FEATURE_ACTION_BAR_OVERLAY); - } - @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - boolean isTranslucentActionBarEnabled = isTranslucentActionBarEnabled(); - if (isTranslucentActionBarEnabled) - enableTranslucentActionBar(this); - setContentView(R.layout.reader_activity_main); getSupportActionBar().setDisplayShowTitleEnabled(false); @@ -81,28 +47,6 @@ public void onCreate(Bundle savedInstanceState) { createMenuDrawer(R.layout.reader_activity_main); - if (isTranslucentActionBarEnabled && super.mMenuDrawer!=null) { - // disable ActionBar translucency when drawer is opening, restore it when closing - super.mMenuDrawer.setOnDrawerStateChangeListener(new MenuDrawer.OnDrawerStateChangeListener() { - @Override - public void onDrawerStateChange(int oldState, int newState) { - switch (newState) { - case MenuDrawer.STATE_OPENING : - mPrevActionBarAlpha = mCurrentActionBarAlpha; - setActionBarAlpha(ALPHA_NONE); - break; - case MenuDrawer.STATE_CLOSING: - setActionBarAlpha(mPrevActionBarAlpha); - break; - } - } - @Override - public void onDrawerSlide(float openRatio, int offsetPixels) { - // nop - } - }); - } - if (savedInstanceState != null) { mHasPerformedInitialUpdate = savedInstanceState.getBoolean(KEY_INITIAL_UPDATE); mHasPerformedPurge = savedInstanceState.getBoolean(KEY_HAS_PURGED); @@ -169,21 +113,6 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) { } break; - // user just returned from the login screen - /*case ReaderConst.INTENT_LOGIN : - if (isResultOK) { - if (readerFragment!=null) { - readerFragment.updateTagList(); - readerFragment.updatePostsWithCurrentTag(ReaderActions.RequestDataAction.LOAD_NEWER); - } else { - showPostListFragment(); - } - } else { - // login failed, so app is done - finish(); - } - break;*/ - // user just returned from post detail, reload the displayed post if it changed (will // only be RESULT_OK if changed) case Constants.INTENT_READER_POST_DETAIL: @@ -287,43 +216,4 @@ private ReaderPostListFragment getPostListFragment() { return null; return ((ReaderPostListFragment) fragment); } - - /* - * called from post list - makes the ActionBar increasingly translucent as user scrolls - * through the first few posts in the list - */ - @Override - public void onFirstVisibleItemChanged(int firstVisibleItem) { - switch (firstVisibleItem) { - case 0: - setActionBarAlpha(ALPHA_LEVEL_1); - break; - case 1: - setActionBarAlpha(ALPHA_LEVEL_2); - break; - case 2 : - setActionBarAlpha(ALPHA_LEVEL_3); - break; - case 3 : - setActionBarAlpha(ALPHA_LEVEL_4); - break; - default: - setActionBarAlpha(ALPHA_LEVEL_5); - break; - } - } - - protected void setActionBarAlpha(int alpha) { - if (alpha==mCurrentActionBarAlpha || !isTranslucentActionBarEnabled()) - return; - - // solid background if no alpha, otherwise create color drawable with alpha applied - // (source color is based on R.color.blue_new_kid) - if (alpha==ALPHA_NONE) { - getSupportActionBar().setBackgroundDrawable(getResources().getDrawable(R.color.blue_new_kid)); - } else { - getSupportActionBar().setBackgroundDrawable(new ColorDrawable(Color.argb(alpha, 46, 162, 204))); - } - mCurrentActionBarAlpha = alpha; - } } diff --git a/src/org/wordpress/android/ui/reader_native/ReaderPostDetailActivity.java b/src/org/wordpress/android/ui/reader_native/ReaderPostDetailActivity.java index 78dddbe95345..e3127690979d 100644 --- a/src/org/wordpress/android/ui/reader_native/ReaderPostDetailActivity.java +++ b/src/org/wordpress/android/ui/reader_native/ReaderPostDetailActivity.java @@ -1,13 +1,13 @@ package org.wordpress.android.ui.reader_native; import android.annotation.SuppressLint; +import android.annotation.TargetApi; import android.app.Activity; import android.content.Context; import android.content.Intent; -import android.graphics.Color; -import android.graphics.drawable.ColorDrawable; import android.net.Uri; import android.os.AsyncTask; +import android.os.Build; import android.os.Bundle; import android.os.Handler; import android.text.TextUtils; @@ -16,6 +16,7 @@ import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; +import android.view.Window; import android.view.animation.Animation; import android.view.animation.TranslateAnimation; import android.view.inputmethod.EditorInfo; @@ -199,9 +200,9 @@ private boolean isCommentAdapterEmpty() { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - boolean isTranslucentActionBarEnabled = NativeReaderActivity.isTranslucentActionBarEnabled(); - if (isTranslucentActionBarEnabled) - NativeReaderActivity.enableTranslucentActionBar(this); + boolean isFullScreenSupported = isFullScreenSupported(); + if (isFullScreenSupported) + enableActionBarOverlay(); mInflater = getLayoutInflater(); setContentView(R.layout.reader_activity_post_detail); @@ -212,12 +213,8 @@ public void onCreate(Bundle savedInstanceState) { getSupportActionBar().setDisplayShowTitleEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true); - if (isTranslucentActionBarEnabled) { - getSupportActionBar().setBackgroundDrawable(new ColorDrawable(Color.argb(NativeReaderActivity.ALPHA_LEVEL_3, 46, 162, 204))); - - // add a header to the listView that's the same height as the ActionBar - this moves - // the actual content of the listView below the ActionBar, but enables it to scroll under - // the translucent ActionBar layout + if (isFullScreenSupported) { + // add a header to the listView that's the same height as the ActionBar final int actionbarHeight = DisplayUtils.getActionBarHeight(this); RelativeLayout headerFake = new RelativeLayout(this); headerFake.setLayoutParams(new AbsListView.LayoutParams(AbsListView.LayoutParams.MATCH_PARENT, actionbarHeight)); @@ -243,7 +240,6 @@ public void onCreate(Bundle savedInstanceState) { mLayoutIcons = (ViewGroup) findViewById(R.id.layout_actions); mLayoutLikes = (ViewGroup) findViewById(R.id.layout_likes); - // setup the webView - note that JavaScript is disabled since it's a security risk: // http://developer.android.com/training/articles/security-tips.html#WebView mWebView = (WebView) findViewById(R.id.webView); @@ -318,12 +314,16 @@ public boolean onOptionsItemSelected(com.actionbarsherlock.view.MenuItem item) { } /* - * auto-hiding the ActionBar and icon bar is jittery/buggy when the translucent ActionBar - * isn't enabled (which it won't be on pre-ICS devices), so disable full-screen mode - * when the translucent ActionBar isn't enabled + * auto-hiding the ActionBar and icon bar is jittery/buggy on Gingerbread (and probably other + * pre-ICS devices), and requires the ActionBar overlay (ICS or later) */ private boolean isFullScreenSupported() { - return NativeReaderActivity.isTranslucentActionBarEnabled(); + return (SysUtils.isGteAndroid4()); + } + + @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) + protected void enableActionBarOverlay() { + getWindow().requestFeature(Window.FEATURE_ACTION_BAR_OVERLAY); } /* diff --git a/src/org/wordpress/android/ui/reader_native/ReaderPostListFragment.java b/src/org/wordpress/android/ui/reader_native/ReaderPostListFragment.java index 4c4c63c80e27..7d7eab52a8a8 100644 --- a/src/org/wordpress/android/ui/reader_native/ReaderPostListFragment.java +++ b/src/org/wordpress/android/ui/reader_native/ReaderPostListFragment.java @@ -1,6 +1,5 @@ package org.wordpress.android.ui.reader_native; -import android.app.Activity; import android.content.Context; import android.os.Bundle; import android.os.Handler; @@ -17,7 +16,6 @@ import android.widget.ImageView; import android.widget.ListView; import android.widget.ProgressBar; -import android.widget.RelativeLayout; import android.widget.TextView; import com.actionbarsherlock.app.ActionBar; @@ -35,7 +33,6 @@ import org.wordpress.android.ui.reader_native.actions.ReaderTagActions; import org.wordpress.android.ui.reader_native.adapters.ReaderActionBarTagAdapter; import org.wordpress.android.ui.reader_native.adapters.ReaderPostAdapter; -import org.wordpress.android.util.DisplayUtils; import org.wordpress.android.util.NetworkUtils; import org.wordpress.android.util.ReaderAniUtils; import org.wordpress.android.util.ReaderLog; @@ -56,6 +53,7 @@ public class ReaderPostListFragment extends Fragment implements AbsListView.OnSc private String mCurrentTag; private boolean mIsUpdating = false; private boolean mAlreadyUpdatedTagList = false; + private boolean mIsFlinging = false; private static final String KEY_TAG_LIST_UPDATED = "tags_updated"; private static final String KEY_TAG_NAME = "tag_name"; @@ -63,12 +61,6 @@ public class ReaderPostListFragment extends Fragment implements AbsListView.OnSc private static final String LIST_STATE = "list_state"; private Parcelable mListState = null; - protected interface OnFirstVisibleItemChangeListener { - void onFirstVisibleItemChanged(int firstVisibleItem); - } - - private OnFirstVisibleItemChangeListener mFirstVisibleItemChangeListener; - protected static ReaderPostListFragment newInstance(Context context) { ReaderLog.d("post list newInstance"); @@ -113,18 +105,6 @@ public void onActivityCreated(Bundle savedInstanceState) { setupActionBar(); } - @Override - public void onAttach(Activity activity) { - super.onAttach(activity); - - // activity is assumed to implement OnFirstVisibleItemChangeListener - try { - mFirstVisibleItemChangeListener = (OnFirstVisibleItemChangeListener) activity; - } catch (ClassCastException e) { - throw new ClassCastException(activity.toString() + " must implement OnFirstVisibleItemChangeListener"); - } - } - @Override public void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); @@ -158,11 +138,8 @@ public void onPause() { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - final Context context = container.getContext(); - final int actionbarHeight = DisplayUtils.getActionBarHeight(context); - final boolean isTranslucentActionBarEnabled = NativeReaderActivity.isTranslucentActionBarEnabled(); - final View view = inflater.inflate(R.layout.reader_fragment_post_list, container, false); + final ListView listView = (ListView) view.findViewById(android.R.id.list); // bar that appears at top when new posts are downloaded mNewPostsBar = (TextView) view.findViewById(R.id.text_new_posts); @@ -178,32 +155,14 @@ public void onClick(View view) { // textView that appears when current tag has no posts mEmptyView = view.findViewById(R.id.empty_view); - // move the "new posts" bar and "empty" textView down when the translucent ActionBar is enabled - if (isTranslucentActionBarEnabled) { - RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) mNewPostsBar.getLayoutParams(); - if (params != null) { - params.setMargins(0, actionbarHeight, 0, 0); - } - mEmptyView.setPadding(0, actionbarHeight, 0, 0); - } - // progress bar that appears when loading more posts mProgress = (ProgressBar) view.findViewById(R.id.progress_footer); mProgress.setVisibility(View.GONE); - final ListView listView = (ListView) view.findViewById(android.R.id.list); - // set the listView's scroll listeners so we can detect up/down scrolling listView.setOnScrollListener(this); - if (isTranslucentActionBarEnabled) { - // add a transparent header to the listView that matches the size of the ActionBar - RelativeLayout header = new RelativeLayout(context); - header.setLayoutParams(new AbsListView.LayoutParams(AbsListView.LayoutParams.MATCH_PARENT, actionbarHeight)); - listView.addHeaderView(header, null, false); - listView.setOverScrollMode(View.OVER_SCROLL_ALWAYS); - } - + // tapping a post opens the detail view listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView adapterView, View view, int position, long id) { @@ -211,7 +170,6 @@ public void onItemClick(AdapterView adapterView, View view, int position, lon position -= listView.getHeaderViewsCount(); ReaderPost post = (ReaderPost) getPostAdapter().getItem(position); ReaderActivityLauncher.showReaderPostDetailForResult(getActivity(), post); - //ReaderActivityLauncher.openUrl(getActivity(), "wordpress://viewpost?blogId=" + post.blogId + "&postId=" + post.postId, ReaderActivityLauncher.OpenUrlType.EXTERNAL); } }); @@ -639,7 +597,6 @@ protected void hideLoadingProgress() { mProgress.setVisibility(View.GONE); } - private boolean mIsFlinging = false; @Override public void onScrollStateChanged(AbsListView absListView, int scrollState) { boolean isFlingingNow = (scrollState == SCROLL_STATE_FLING); @@ -650,16 +607,8 @@ public void onScrollStateChanged(AbsListView absListView, int scrollState) { } } - private int mPrevFirstVisibleItem = -1; @Override public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { - if (visibleItemCount==0 || !hasActivity()) - return; - if (firstVisibleItem != mPrevFirstVisibleItem && mFirstVisibleItemChangeListener != null) { - // this tells NativeReaderActivity to make the ActionBar more translucent as the user - // scrolls through the list - mFirstVisibleItemChangeListener.onFirstVisibleItemChanged(firstVisibleItem); - mPrevFirstVisibleItem = firstVisibleItem; - } + // nop } }