bug 862801: New About:home snippets. [r=lucasr]

--HG--
extra : rebase_source : a81ed8090f1e2fdd9ffd02c633db2470ae428413
This commit is contained in:
Sriram Ramasubramanian 2013-08-08 15:15:13 -07:00
parent 12e1ab669d
commit 78089f5693
10 changed files with 256 additions and 8 deletions

View File

@ -227,6 +227,7 @@ FENNEC_JAVA_FILES = \
home/HomeListView.java \
home/HomePager.java \
home/HomePagerTabStrip.java \
home/HomeBanner.java \
home/FadedTextView.java \
home/FaviconsLoader.java \
home/LastTabsPage.java \
@ -481,6 +482,7 @@ RES_LAYOUT = \
res/layout/home_pager.xml \
res/layout/home_reading_list_page.xml \
res/layout/home_search_item_row.xml \
res/layout/home_banner.xml \
res/layout/home_suggestion_prompt.xml \
res/layout/web_app.xml \
res/layout/launch_app_list.xml \
@ -1113,6 +1115,7 @@ RES_DRAWABLE += \
res/drawable/handle_start_level.xml \
res/drawable/home_history_tabs_indicator.xml \
res/drawable/home_page_title_background.xml \
res/drawable/home_banner.xml \
res/drawable/ic_menu_back.xml \
res/drawable/ic_menu_desktop_mode_off.xml \
res/drawable/ic_menu_desktop_mode_on.xml \

View File

@ -8,6 +8,9 @@ package org.mozilla.gecko.home;
import org.mozilla.gecko.Favicons;
import org.mozilla.gecko.R;
import org.mozilla.gecko.Tabs;
import org.mozilla.gecko.animation.PropertyAnimator;
import org.mozilla.gecko.animation.PropertyAnimator.Property;
import org.mozilla.gecko.animation.ViewHelper;
import org.mozilla.gecko.db.BrowserContract.Bookmarks;
import org.mozilla.gecko.db.BrowserContract.Thumbnails;
import org.mozilla.gecko.db.BrowserDB;
@ -41,7 +44,9 @@ import android.view.ContextMenu.ContextMenuInfo;
import android.view.LayoutInflater;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.view.ViewGroup;
import android.widget.Toast;
@ -76,6 +81,9 @@ public class BookmarksPage extends HomeFragment {
// Grid of top bookmarks.
private TopBookmarksView mTopBookmarks;
// Banner to show snippets.
private HomeBanner mBanner;
// Adapter for list of bookmarks.
private BookmarksListAdapter mListAdapter;
@ -91,14 +99,22 @@ public class BookmarksPage extends HomeFragment {
// Listener for pinning bookmarks.
private PinBookmarkListener mPinBookmarkListener;
// Raw Y value of the last event that happened on the list view.
private float mListTouchY = -1;
// Scrolling direction of the banner.
private boolean mSnapBannerToTop;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
BookmarksListView list = (BookmarksListView) inflater.inflate(R.layout.home_bookmarks_page, container, false);
final View view = inflater.inflate(R.layout.home_bookmarks_page, container, false);
mList = (BookmarksListView) view.findViewById(R.id.bookmarks_list);
mTopBookmarks = new TopBookmarksView(getActivity());
list.addHeaderView(mTopBookmarks);
mList.addHeaderView(mTopBookmarks);
return list;
return view;
}
@Override
@ -115,7 +131,6 @@ public class BookmarksPage extends HomeFragment {
mPinBookmarkListener = new PinBookmarkListener();
mList = (BookmarksListView) view.findViewById(R.id.bookmarks_list);
mList.setTag(HomePager.LIST_TAG_BOOKMARKS);
mList.setOnUrlOpenListener(listener);
mList.setHeaderDividersEnabled(false);
@ -125,6 +140,15 @@ public class BookmarksPage extends HomeFragment {
registerForContextMenu(mList);
registerForContextMenu(mTopBookmarks);
mBanner = (HomeBanner) view.findViewById(R.id.home_banner);
mList.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
BookmarksPage.this.handleListTouchEvent(event);
return false;
}
});
}
@Override
@ -190,6 +214,60 @@ public class BookmarksPage extends HomeFragment {
}
}
private void handleListTouchEvent(MotionEvent event) {
// Ignore the event if the banner is hidden for this session.
if (mBanner.isDismissed()) {
return;
}
switch (event.getActionMasked()) {
case MotionEvent.ACTION_DOWN: {
mListTouchY = event.getRawY();
break;
}
case MotionEvent.ACTION_MOVE: {
// There is a chance that we won't receive ACTION_DOWN, if the touch event
// actually started on the Grid instead of the List. Treat this as first event.
if (mListTouchY == -1) {
mListTouchY = event.getRawY();
return;
}
final float curY = event.getRawY();
final float delta = mListTouchY - curY;
mSnapBannerToTop = (delta > 0.0f) ? false : true;
final float height = mBanner.getHeight();
float newTranslationY = ViewHelper.getTranslationY(mBanner) + delta;
// Clamp the values to be between 0 and height.
if (newTranslationY < 0.0f) {
newTranslationY = 0.0f;
} else if (newTranslationY > height) {
newTranslationY = height;
}
ViewHelper.setTranslationY(mBanner, newTranslationY);
mListTouchY = curY;
break;
}
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL: {
mListTouchY = -1;
final float y = ViewHelper.getTranslationY(mBanner);
final float height = mBanner.getHeight();
if (y > 0.0f && y < height) {
final PropertyAnimator animator = new PropertyAnimator(100);
animator.attach(mBanner, Property.TRANSLATION_Y, mSnapBannerToTop ? 0 : height);
animator.start();
}
break;
}
}
}
@Override
public void onCreateContextMenu(ContextMenu menu, View view, ContextMenuInfo menuInfo) {
if (menuInfo == null) {

View File

@ -0,0 +1,51 @@
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.gecko.home;
import org.mozilla.gecko.R;
import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageButton;
import android.widget.LinearLayout;
public class HomeBanner extends LinearLayout {
public HomeBanner(Context context) {
this(context, null);
}
public HomeBanner(Context context, AttributeSet attrs) {
super(context, attrs);
LayoutInflater.from(context).inflate(R.layout.home_banner, this);
}
@Override
public void onAttachedToWindow() {
super.onAttachedToWindow();
// Tapping on the close button will ensure that the banner is never
// showed again on this session.
final ImageButton closeButton = (ImageButton) findViewById(R.id.close);
// The drawable should have 50% opacity.
closeButton.getDrawable().setAlpha(127);
closeButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
HomeBanner.this.setVisibility(View.GONE);
}
});
}
public boolean isDismissed() {
return (getVisibility() == View.GONE);
}
}

View File

@ -0,0 +1,38 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- This Source Code Form is subject to the terms of the Mozilla Public
- License, v. 2.0. If a copy of the MPL was not distributed with this
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<layer-list>
<item android:left="-2dp"
android:right="-2dp"
android:bottom="-2dp">
<shape android:shape="rectangle" >
<stroke android:width="2dp"
android:color="#FFE0E4E7" />
<solid android:color="#FFC5D0DA" />
</shape>
</item>
</layer-list>
</item>
<item>
<layer-list>
<item android:left="-2dp"
android:right="-2dp"
android:bottom="-2dp">
<shape android:shape="rectangle" >
<stroke android:width="2dp"
android:color="#FFE0E4E7" />
<solid android:color="@color/background_light" />
</shape>
</item>
</layer-list>
</item>
</selector>

View File

@ -0,0 +1,36 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- This Source Code Form is subject to the terms of the Mozilla Public
- License, v. 2.0. If a copy of the MPL was not distributed with this
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
<merge xmlns:android="http://schemas.android.com/apk/res/android">
<ImageView android:id="@+id/icon"
android:layout_width="48dip"
android:layout_height="48dip"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:scaleType="centerInside"/>
<TextView android:id="@+id/text"
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="1"
android:paddingTop="7dp"
android:paddingBottom="7dp"
android:textAppearance="@style/TextAppearance.Widget.HomeBanner"
android:layout_gravity="bottom"
android:singleLine="false"
android:maxLines="3"
android:ellipsize="end"
android:gravity="center_vertical"/>
<ImageButton android:id="@+id/close"
android:layout_width="34dip"
android:layout_height="fill_parent"
android:background="@drawable/home_banner"
android:scaleType="center"
android:contentDescription="@string/close_tab"
android:src="@drawable/tab_close"/>
</merge>

View File

@ -3,7 +3,24 @@
- License, v. 2.0. If a copy of the MPL was not distributed with this
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
<org.mozilla.gecko.home.BookmarksListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/bookmarks_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<org.mozilla.gecko.home.BookmarksListView
android:id="@+id/bookmarks_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
<org.mozilla.gecko.home.HomeBanner android:id="@+id/home_banner"
style="@style/Widget.HomeBanner"
android:layout_width="fill_parent"
android:layout_height="@dimen/home_banner_height"
android:background="@drawable/home_banner"
android:layout_gravity="bottom"
android:gravity="center_vertical"
android:visibility="gone"
android:clickable="true"
android:focusable="true"/>
</FrameLayout>

View File

@ -50,4 +50,15 @@
<item name="android:paddingTop">30dp</item>
</style>
<!--
The content of the banner should align with the Grid/List views
in BookmarksPage. BookmarksListView has a 120dp padding and
the TwoLinePageRows have a 50dp padding. Hence HomeBanner should
have 170dp padding.
-->
<style name="Widget.HomeBanner">
<item name="android:paddingLeft">170dp</item>
<item name="android:paddingRight">170dp</item>
</style>
</resources>

View File

@ -60,4 +60,9 @@
<item name="topDivider">true</item>
</style>
<style name="Widget.HomeBanner">
<item name="android:paddingLeft">32dp</item>
<item name="android:paddingRight">32dp</item>
</style>
</resources>

View File

@ -87,4 +87,7 @@
<!-- PageActionButtons dimensions -->
<dimen name="page_action_button_width">32dp</dimen>
<!-- Banner -->
<dimen name="home_banner_height">72dp</dimen>
</resources>

View File

@ -160,6 +160,8 @@
<style name="Widget.ReadingListView" parent="Widget.BookmarksListView"/>
<style name="Widget.HomeBanner"/>
<style name="Widget.Home" />
<style name="Widget.Home.HeaderItem">
@ -318,6 +320,10 @@
<item name="android:textColor">#00ACFF</item>
</style>
<style name="TextAppearance.Widget.HomeBanner" parent="TextAppearance.Small">
<item name="android:textColor">?android:attr/textColorHint</item>
</style>
<!-- BrowserToolbar -->
<style name="BrowserToolbar">
<item name="android:layout_width">fill_parent</item>