Bug 880047 - [fig] Kill unused AboutHome code (AddonsSection), r=margaret

This commit is contained in:
Mark Capella 2013-07-17 18:39:38 -04:00
parent 13b5e4f8cf
commit 18d02d5092
12 changed files with 1 additions and 285 deletions

View File

@ -254,7 +254,6 @@ FENNEC_JAVA_FILES = \
widget/AboutHomeView.java \
widget/AboutHomeSection.java \
widget/ActivityChooserModel.java \
widget/AddonsSection.java \
widget/ButtonToast.java \
widget/ArrowPopup.java \
widget/DateTimePicker.java \
@ -509,7 +508,6 @@ RES_LAYOUT = \
res/layout/select_dialog_singlechoice.xml \
res/layout/simple_dropdown_item_1line.xml \
res/layout/suggestion_item.xml \
res/layout/abouthome_addon_row.xml \
res/layout/abouthome_last_tabs_row.xml \
res/layout/abouthome_section.xml \
res/layout/abouthome_topsite_item.xml \
@ -637,7 +635,6 @@ RES_DRAWABLE_MDPI = \
res/drawable-mdpi/bookmark_folder_closed.png \
res/drawable-mdpi/bookmark_folder_opened.png \
res/drawable-mdpi/desktop_notification.png \
res/drawable-mdpi/ic_addons_empty.png \
res/drawable-mdpi/ic_menu_addons_filler.png \
res/drawable-mdpi/ic_menu_bookmark_add.png \
res/drawable-mdpi/ic_menu_bookmark_remove.png \
@ -757,7 +754,6 @@ RES_DRAWABLE_HDPI = \
res/drawable-hdpi/alert_mic.png \
res/drawable-hdpi/alert_mic_camera.png \
res/drawable-hdpi/arrow_popup_bg.9.png \
res/drawable-hdpi/ic_addons_empty.png \
res/drawable-hdpi/ic_menu_addons_filler.png \
res/drawable-hdpi/ic_menu_bookmark_add.png \
res/drawable-hdpi/ic_menu_bookmark_remove.png \
@ -854,7 +850,6 @@ RES_DRAWABLE_XHDPI = \
res/drawable-xhdpi/alert_mic.png \
res/drawable-xhdpi/alert_mic_camera.png \
res/drawable-xhdpi/arrow_popup_bg.9.png \
res/drawable-xhdpi/ic_addons_empty.png \
res/drawable-xhdpi/ic_menu_addons_filler.png \
res/drawable-xhdpi/ic_menu_bookmark_add.png \
res/drawable-xhdpi/ic_menu_bookmark_remove.png \

View File

@ -266,8 +266,6 @@ size. -->
<!ENTITY button_set "Set">
<!ENTITY button_clear "Clear">
<!ENTITY abouthome_addons_title "Add-ons for your &brandShortName;">
<!ENTITY abouthome_addons_browse "Browse all &brandShortName; add-ons">
<!ENTITY abouthome_last_tabs_title "Your tabs from last time">
<!ENTITY abouthome_last_tabs_open "Open all tabs from last time">
<!ENTITY abouthome_top_sites_title "Top sites">

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.3 KiB

View File

@ -68,13 +68,6 @@
gecko:title="@string/abouthome_last_tabs_title"
gecko:more_text="@string/abouthome_last_tabs_open"/>
<org.mozilla.gecko.widget.AddonsSection android:id="@+id/recommended_addons"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:visibility="gone"
gecko:title="@string/abouthome_addons_title"
gecko:more_text="@string/abouthome_addons_browse"/>
</LinearLayout>
</LinearLayout>

View File

@ -1,12 +0,0 @@
<?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/. -->
<org.mozilla.gecko.GeckoTextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="@dimen/abouthome_rowitem_height"
android:paddingLeft="@dimen/abouthome_rowitem_left_padding"
android:gravity="center_vertical"
android:drawablePadding="12dip"
style="@style/AboutHome.RowItem.TextRow"/>

View File

@ -53,13 +53,6 @@
gecko:title="@string/abouthome_last_tabs_title"
gecko:more_text="@string/abouthome_last_tabs_open"/>
<org.mozilla.gecko.widget.AddonsSection android:id="@+id/recommended_addons"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:visibility="gone"
gecko:title="@string/abouthome_addons_title"
gecko:more_text="@string/abouthome_addons_browse"/>
</LinearLayout>
</org.mozilla.gecko.widget.AboutHomeView>

View File

@ -5,7 +5,6 @@
<resources>
<dimen name="abouthome_addon_icon_size">32dp</dimen>
<dimen name="abouthome_content_top_sites_item_height">110dp</dimen>
<dimen name="abouthome_gutter_small">0dp</dimen>
<dimen name="abouthome_gutter_large">0dp</dimen>

View File

@ -234,8 +234,6 @@
<string name="button_yes">&button_yes;</string>
<string name="button_no">&button_no;</string>
<string name="abouthome_addons_title">&abouthome_addons_title;</string>
<string name="abouthome_addons_browse">&abouthome_addons_browse;</string>
<string name="abouthome_last_tabs_title">&abouthome_last_tabs_title;</string>
<string name="abouthome_last_tabs_open">&abouthome_last_tabs_open;</string>
<string name="abouthome_top_sites_title">&abouthome_top_sites_title;</string>

View File

@ -28,8 +28,7 @@ import android.view.ViewGroup;
public class AboutHome extends Fragment {
public static enum UpdateFlags {
TOP_SITES,
PREVIOUS_TABS,
RECOMMENDED_ADDONS;
PREVIOUS_TABS;
public static final EnumSet<UpdateFlags> ALL = EnumSet.allOf(UpdateFlags.class);
}
@ -39,7 +38,6 @@ public class AboutHome extends Fragment {
private LightweightTheme mLightweightTheme;
private int mTopPadding;
private AboutHomeView mAboutHomeView;
private AddonsSection mAddonsSection;
private LastTabsSection mLastTabsSection;
private TopSitesView mTopSitesView;
private ScrollAnimator mScrollAnimator;
@ -91,7 +89,6 @@ public class AboutHome extends Fragment {
super.onCreateView(inflater, container, savedInstanceState);
mAboutHomeView = (AboutHomeView) inflater.inflate(R.layout.abouthome_content, container, false);
mAddonsSection = (AddonsSection) mAboutHomeView.findViewById(R.id.recommended_addons);
mLastTabsSection = (LastTabsSection) mAboutHomeView.findViewById(R.id.last_tabs);
mTopSitesView = (TopSitesView) mAboutHomeView.findViewById(R.id.top_sites_grid);
@ -118,7 +115,6 @@ public class AboutHome extends Fragment {
mTopSitesView.setLoadCompleteListener(mLoadCompleteListener);
mTopSitesView.setUriLoadListener(mUriLoadListener);
mAddonsSection.setUriLoadListener(mUriLoadListener);
}
@Override
@ -132,7 +128,6 @@ public class AboutHome extends Fragment {
mScrollAnimator = null;
mAboutHomeView = null;
mAddonsSection = null;
mLastTabsSection = null;
mTopSitesView = null;
@ -204,10 +199,6 @@ public class AboutHome extends Fragment {
if (flags.contains(UpdateFlags.PREVIOUS_TABS)) {
mLastTabsSection.readLastTabs();
}
if (flags.contains(UpdateFlags.RECOMMENDED_ADDONS)) {
mAddonsSection.readRecommendedAddons();
}
}
public void setLastTabsVisibility(boolean visible) {

View File

@ -1,239 +0,0 @@
/* -*- 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.widget;
import org.mozilla.gecko.BrowserApp;
import org.mozilla.gecko.Favicons;
import org.mozilla.gecko.R;
import org.mozilla.gecko.util.GamepadUtils;
import org.mozilla.gecko.util.ThreadUtils;
import org.mozilla.gecko.util.UiAsyncTask;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Rect;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.text.SpannableString;
import android.text.TextUtils;
import android.text.style.TextAppearanceSpan;
import android.util.AttributeSet;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
public class AddonsSection extends AboutHomeSection {
private static final String LOGTAG = "GeckoAboutHomeAddons";
private Context mContext;
private BrowserApp mActivity;
private AboutHome.UriLoadListener mUriLoadListener;
private static Rect sIconBounds;
private static TextAppearanceSpan sSubTitleSpan;
public AddonsSection(Context context, AttributeSet attrs) {
super(context, attrs);
mContext = context;
mActivity = (BrowserApp) context;
int iconSize = mContext.getResources().getDimensionPixelSize(R.dimen.abouthome_addon_icon_size);
sIconBounds = new Rect(0, 0, iconSize, iconSize);
sSubTitleSpan = new TextAppearanceSpan(mContext, R.style.AboutHome_TextAppearance_SubTitle);
setOnMoreTextClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (mUriLoadListener != null)
mUriLoadListener.onAboutHomeUriLoad(mContext.getString(R.string.bookmarkdefaults_url_addons));
}
});
}
public void setUriLoadListener(AboutHome.UriLoadListener uriLoadListener) {
mUriLoadListener = uriLoadListener;
}
private String readFromZipFile(String filename) {
ZipFile zip = null;
String str = null;
try {
InputStream fileStream = null;
File applicationPackage = new File(mActivity.getApplication().getPackageResourcePath());
zip = new ZipFile(applicationPackage);
ZipEntry fileEntry = zip.getEntry(filename);
if (fileEntry == null)
return null;
fileStream = zip.getInputStream(fileEntry);
str = readStringFromStream(fileStream);
} catch (IOException ioe) {
Log.e(LOGTAG, "error reading zip file: " + filename, ioe);
} finally {
try {
if (zip != null)
zip.close();
} catch (IOException ioe) {
// catch this here because we can continue even if the
// close failed
Log.e(LOGTAG, "error closing zip filestream", ioe);
}
}
return str;
}
private String readStringFromStream(InputStream fileStream) {
String str = null;
try {
byte[] buf = new byte[32768];
StringBuilder jsonString = new StringBuilder();
int read = 0;
while ((read = fileStream.read(buf, 0, 32768)) != -1)
jsonString.append(new String(buf, 0, read));
str = jsonString.toString();
} catch (IOException ioe) {
Log.i(LOGTAG, "error reading filestream", ioe);
} finally {
try {
if (fileStream != null)
fileStream.close();
} catch (IOException ioe) {
// catch this here because we can continue even if the
// close failed
Log.e(LOGTAG, "error closing filestream", ioe);
}
}
return str;
}
private String getPageUrlFromIconUrl(String iconUrl) {
// Addon icon URLs come with a query argument that is usually
// used for expiration purposes. We want the "page URL" here to be
// stable enough to avoid unnecessary duplicate records of the
// same addon.
String pageUrl = iconUrl;
try {
URL urlForIcon = new URL(iconUrl);
URL urlForPage = new URL(urlForIcon.getProtocol(), urlForIcon.getAuthority(), urlForIcon.getPath());
pageUrl = urlForPage.toString();
} catch (MalformedURLException e) {
// Defaults to pageUrl = iconUrl in case of error
}
return pageUrl;
}
public void readRecommendedAddons() {
new UiAsyncTask<Void, Void, JSONArray>(ThreadUtils.getBackgroundHandler()) {
@Override
public JSONArray doInBackground(Void... params) {
final String addonsFilename = "recommended-addons.json";
String jsonString;
try {
jsonString = mActivity.getProfile().readFile(addonsFilename);
} catch (IOException ioe) {
Log.i(LOGTAG, "filestream is null");
jsonString = readFromZipFile(addonsFilename);
}
JSONArray addonsArray = null;
if (jsonString != null) {
try {
addonsArray = new JSONObject(jsonString).getJSONArray("addons");
} catch (JSONException e) {
Log.i(LOGTAG, "error reading json file", e);
}
}
return addonsArray;
}
@Override
public void onPostExecute(JSONArray addons) {
if (addons == null || addons.length() == 0) {
hide();
return;
}
try {
for (int i = 0; i < addons.length(); i++) {
View addonView = createAddonView(addons.getJSONObject(i), getItemsContainer());
addItem(addonView);
}
} catch (JSONException e) {
Log.e(LOGTAG, "Error reading JSON", e);
return;
}
show();
}
}.execute();
}
View createAddonView(JSONObject addonJSON, ViewGroup parent) throws JSONException {
String name = addonJSON.getString("name");
String version = addonJSON.getString("version");
String text = name + " " + version;
SpannableString spannable = new SpannableString(text);
spannable.setSpan(sSubTitleSpan, name.length() + 1, text.length(), 0);
final TextView row = (TextView) LayoutInflater.from(mContext).inflate(R.layout.abouthome_addon_row, getItemsContainer(), false);
row.setText(spannable, TextView.BufferType.SPANNABLE);
Drawable drawable = mContext.getResources().getDrawable(R.drawable.ic_addons_empty);
drawable.setBounds(sIconBounds);
row.setCompoundDrawables(drawable, null, null, null);
String iconUrl = addonJSON.getString("iconURL");
String pageUrl = getPageUrlFromIconUrl(iconUrl);
// homepageURL may point to non-AMO installs. For now we use learnmoreURL instead
// which is more likely to point to a mobile AMO page
String homepageUrl = addonJSON.optString("learnmoreURL");
if (TextUtils.isEmpty(homepageUrl)) {
homepageUrl = addonJSON.getString("homepageURL");
}
final String addonUrl = homepageUrl;
row.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (mUriLoadListener != null)
mUriLoadListener.onAboutHomeUriLoad(addonUrl);
}
});
row.setOnKeyListener(GamepadUtils.getClickDispatcher());
Favicons favicons = Favicons.getInstance();
favicons.loadFavicon(pageUrl, iconUrl, Favicons.FLAG_PERSIST | Favicons.FLAG_SCALE,
new Favicons.OnFaviconLoadedListener() {
@Override
public void onFaviconLoaded(String url, Bitmap favicon) {
if (favicon != null) {
Drawable drawable = new BitmapDrawable(favicon);
drawable.setBounds(sIconBounds);
row.setCompoundDrawables(drawable, null, null, null);
}
}
});
return row;
}
}