2011-11-28 22:38:35 -08:00
|
|
|
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
|
|
|
|
* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (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.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is Mozilla Android code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Mozilla Foundation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2011
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Brad Lassey <blassey@mozilla.com>
|
2011-12-13 12:15:17 -08:00
|
|
|
* Lucas Rocha <lucasr@mozilla.com>
|
2011-11-28 22:38:35 -08:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
package org.mozilla.gecko;
|
|
|
|
|
2011-12-13 12:15:17 -08:00
|
|
|
import java.io.File;
|
|
|
|
import java.io.FileInputStream;
|
|
|
|
import java.io.FileNotFoundException;
|
|
|
|
import java.io.InputStream;
|
2011-12-15 07:46:36 -08:00
|
|
|
import java.io.IOException;
|
2012-01-24 08:52:26 -08:00
|
|
|
import java.net.URL;
|
|
|
|
import java.net.MalformedURLException;
|
2012-01-17 19:40:43 -08:00
|
|
|
import java.util.ArrayList;
|
2012-01-27 02:08:21 -08:00
|
|
|
import java.util.EnumSet;
|
2012-03-12 12:48:55 -07:00
|
|
|
import java.util.List;
|
2011-12-13 12:15:17 -08:00
|
|
|
import java.util.zip.ZipEntry;
|
|
|
|
import java.util.zip.ZipFile;
|
|
|
|
|
|
|
|
import org.json.JSONArray;
|
2012-01-17 19:40:43 -08:00
|
|
|
import org.json.JSONException;
|
2011-12-13 12:15:17 -08:00
|
|
|
import org.json.JSONObject;
|
|
|
|
import org.mozilla.gecko.db.BrowserDB;
|
|
|
|
import org.mozilla.gecko.db.BrowserDB.URLColumns;
|
2012-01-24 06:03:28 -08:00
|
|
|
import org.mozilla.gecko.sync.setup.activities.SetupSyncActivity;
|
2011-12-13 12:15:17 -08:00
|
|
|
|
2012-01-24 06:03:28 -08:00
|
|
|
import android.accounts.Account;
|
|
|
|
import android.accounts.AccountManager;
|
2012-02-02 08:08:58 -08:00
|
|
|
import android.accounts.OnAccountsUpdateListener;
|
2011-11-28 22:38:35 -08:00
|
|
|
import android.app.Activity;
|
2011-12-13 12:15:17 -08:00
|
|
|
import android.content.ContentResolver;
|
|
|
|
import android.content.Context;
|
2012-01-24 06:03:28 -08:00
|
|
|
import android.content.Intent;
|
2011-12-13 12:15:17 -08:00
|
|
|
import android.content.res.Configuration;
|
2011-11-28 22:38:35 -08:00
|
|
|
import android.database.Cursor;
|
2011-12-13 12:15:17 -08:00
|
|
|
import android.graphics.Bitmap;
|
|
|
|
import android.graphics.BitmapFactory;
|
2012-01-17 19:40:43 -08:00
|
|
|
import android.graphics.drawable.BitmapDrawable;
|
2012-01-24 08:52:26 -08:00
|
|
|
import android.graphics.drawable.Drawable;
|
2012-03-12 12:48:55 -07:00
|
|
|
import android.os.SystemClock;
|
2011-12-13 12:15:17 -08:00
|
|
|
import android.text.SpannableString;
|
2012-01-24 06:03:28 -08:00
|
|
|
import android.text.style.StyleSpan;
|
2011-12-13 12:15:17 -08:00
|
|
|
import android.text.style.UnderlineSpan;
|
2011-12-13 12:15:17 -08:00
|
|
|
import android.util.AttributeSet;
|
2011-11-28 22:38:35 -08:00
|
|
|
import android.util.Log;
|
2011-12-27 09:44:22 -08:00
|
|
|
import android.util.DisplayMetrics;
|
2011-12-19 23:49:44 -08:00
|
|
|
import android.view.LayoutInflater;
|
2011-11-28 22:38:35 -08:00
|
|
|
import android.view.View;
|
2011-12-13 12:15:17 -08:00
|
|
|
import android.widget.AdapterView;
|
|
|
|
import android.widget.ArrayAdapter;
|
2012-01-17 19:40:43 -08:00
|
|
|
import android.widget.FrameLayout;
|
2011-11-28 22:38:35 -08:00
|
|
|
import android.widget.GridView;
|
2011-12-13 12:15:17 -08:00
|
|
|
import android.widget.ImageView;
|
|
|
|
import android.widget.ListView;
|
2012-01-24 06:03:28 -08:00
|
|
|
import android.widget.RelativeLayout;
|
2011-12-13 12:15:17 -08:00
|
|
|
import android.widget.ScrollView;
|
2011-11-28 22:38:35 -08:00
|
|
|
import android.widget.SimpleCursorAdapter;
|
2011-12-13 12:15:17 -08:00
|
|
|
import android.widget.TextView;
|
2012-03-12 12:48:55 -07:00
|
|
|
import android.text.TextUtils;
|
2011-12-02 09:27:56 -08:00
|
|
|
|
2012-03-12 12:48:55 -07:00
|
|
|
public class AboutHomeContent extends ScrollView
|
|
|
|
implements TabsAccessor.OnQueryTabsCompleteListener {
|
2011-12-13 12:15:17 -08:00
|
|
|
private static final String LOGTAG = "GeckoAboutHome";
|
|
|
|
|
|
|
|
private static final int NUMBER_OF_TOP_SITES_PORTRAIT = 4;
|
|
|
|
private static final int NUMBER_OF_TOP_SITES_LANDSCAPE = 3;
|
2011-11-28 22:38:35 -08:00
|
|
|
|
2011-12-13 12:15:17 -08:00
|
|
|
private static final int NUMBER_OF_COLS_PORTRAIT = 2;
|
|
|
|
private static final int NUMBER_OF_COLS_LANDSCAPE = 3;
|
|
|
|
|
2012-03-12 12:48:55 -07:00
|
|
|
private static final int NUMBER_OF_REMOTE_TABS = 10;
|
|
|
|
|
2012-01-27 02:08:21 -08:00
|
|
|
static enum UpdateFlags {
|
|
|
|
TOP_SITES,
|
|
|
|
PREVIOUS_TABS,
|
2012-03-12 12:48:55 -07:00
|
|
|
RECOMMENDED_ADDONS,
|
|
|
|
REMOTE_TABS;
|
2012-01-27 02:08:21 -08:00
|
|
|
|
|
|
|
public static final EnumSet<UpdateFlags> ALL = EnumSet.allOf(UpdateFlags.class);
|
|
|
|
}
|
|
|
|
|
2011-12-13 12:15:17 -08:00
|
|
|
private Cursor mCursor;
|
2011-11-28 22:38:35 -08:00
|
|
|
UriLoadCallback mUriLoadCallback = null;
|
2012-01-17 19:40:43 -08:00
|
|
|
private LayoutInflater mInflater;
|
2011-11-28 22:38:35 -08:00
|
|
|
|
2012-02-02 08:08:58 -08:00
|
|
|
private AccountManager mAccountManager;
|
2012-03-08 15:48:44 -08:00
|
|
|
private OnAccountsUpdateListener mAccountListener = null;
|
2012-02-02 08:08:58 -08:00
|
|
|
|
2011-12-13 12:15:17 -08:00
|
|
|
protected SimpleCursorAdapter mTopSitesAdapter;
|
|
|
|
protected GridView mTopSitesGrid;
|
|
|
|
|
2012-03-19 16:15:05 -07:00
|
|
|
protected AboutHomeSection mAddons;
|
|
|
|
protected AboutHomeSection mLastTabs;
|
|
|
|
protected AboutHomeSection mRemoteTabs;
|
2012-03-12 12:48:55 -07:00
|
|
|
|
|
|
|
private View.OnClickListener mRemoteTabClickListener;
|
2011-12-13 12:15:17 -08:00
|
|
|
|
|
|
|
public interface UriLoadCallback {
|
|
|
|
public void callback(String uriSpec);
|
2011-11-28 22:38:35 -08:00
|
|
|
}
|
|
|
|
|
2012-01-27 02:08:21 -08:00
|
|
|
public AboutHomeContent(Context context) {
|
|
|
|
super(context);
|
2012-02-14 13:30:15 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
public AboutHomeContent(Context context, AttributeSet attrs) {
|
|
|
|
super(context, attrs);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void init() {
|
|
|
|
Context context = getContext();
|
2012-01-17 19:40:43 -08:00
|
|
|
mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
2012-01-27 02:08:21 -08:00
|
|
|
mInflater.inflate(R.layout.abouthome_content, this);
|
|
|
|
|
2012-02-02 08:08:58 -08:00
|
|
|
mAccountManager = AccountManager.get(context);
|
|
|
|
|
|
|
|
// The listener will run on the background thread (see 2nd argument)
|
2012-03-08 15:48:44 -08:00
|
|
|
mAccountManager.addOnAccountsUpdatedListener(mAccountListener = new OnAccountsUpdateListener() {
|
2012-02-02 08:08:58 -08:00
|
|
|
public void onAccountsUpdated(Account[] accounts) {
|
|
|
|
final GeckoApp.StartupMode startupMode = GeckoApp.mAppContext.getStartupMode();
|
|
|
|
final boolean syncIsSetup = isSyncSetup();
|
|
|
|
|
|
|
|
GeckoApp.mAppContext.mMainHandler.post(new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
// The listener might run before the UI is initially updated.
|
|
|
|
// In this case, we should simply wait for the initial setup
|
|
|
|
// to happen.
|
|
|
|
if (mTopSitesAdapter != null)
|
|
|
|
updateLayout(startupMode, syncIsSetup);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2012-02-24 08:22:54 -08:00
|
|
|
}, GeckoAppShell.getHandler(), false);
|
2012-02-02 08:08:58 -08:00
|
|
|
|
2012-01-27 02:08:21 -08:00
|
|
|
mTopSitesGrid = (GridView)findViewById(R.id.top_sites_grid);
|
|
|
|
mTopSitesGrid.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
|
|
|
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
|
|
|
|
Cursor c = (Cursor) parent.getItemAtPosition(position);
|
|
|
|
|
|
|
|
String spec = c.getString(c.getColumnIndex(URLColumns.URL));
|
|
|
|
Log.i(LOGTAG, "clicked: " + spec);
|
|
|
|
|
|
|
|
if (mUriLoadCallback != null)
|
|
|
|
mUriLoadCallback.callback(spec);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2012-03-19 16:15:05 -07:00
|
|
|
mAddons = (AboutHomeSection) findViewById(R.id.recommended_addons);
|
|
|
|
mLastTabs = (AboutHomeSection) findViewById(R.id.last_tabs);
|
|
|
|
mRemoteTabs = (AboutHomeSection) findViewById(R.id.remote_tabs);
|
2011-12-02 15:41:14 -08:00
|
|
|
|
2012-01-27 02:08:21 -08:00
|
|
|
TextView allTopSitesText = (TextView) findViewById(R.id.all_top_sites_text);
|
|
|
|
allTopSitesText.setOnClickListener(new View.OnClickListener() {
|
|
|
|
public void onClick(View v) {
|
|
|
|
GeckoApp.mAppContext.showAwesomebar(AwesomeBar.Type.EDIT);
|
2012-01-24 06:03:28 -08:00
|
|
|
}
|
2012-01-27 02:08:21 -08:00
|
|
|
});
|
2012-01-24 06:03:28 -08:00
|
|
|
|
2012-03-19 16:15:05 -07:00
|
|
|
mAddons.setOnMoreTextClickListener(new View.OnClickListener() {
|
2012-01-27 02:08:21 -08:00
|
|
|
public void onClick(View v) {
|
|
|
|
if (mUriLoadCallback != null)
|
2012-02-02 13:04:27 -08:00
|
|
|
mUriLoadCallback.callback("https://addons.mozilla.org/android");
|
2012-01-27 02:08:21 -08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2012-03-19 16:15:05 -07:00
|
|
|
mRemoteTabs.setOnMoreTextClickListener(new View.OnClickListener() {
|
2012-03-12 12:48:55 -07:00
|
|
|
public void onClick(View v) {
|
|
|
|
Context context = v.getContext();
|
|
|
|
context.startActivity(new Intent(context, RemoteTabs.class));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2012-01-27 02:08:21 -08:00
|
|
|
TextView syncTextView = (TextView) findViewById(R.id.sync_text);
|
|
|
|
String syncText = syncTextView.getText().toString() + " \u00BB";
|
|
|
|
String boldName = getContext().getResources().getString(R.string.abouthome_sync_bold_name);
|
|
|
|
int styleIndex = syncText.indexOf(boldName);
|
|
|
|
|
|
|
|
// Highlight any occurrence of "Firefox Sync" in the string
|
|
|
|
// with a bold style.
|
|
|
|
if (styleIndex >= 0) {
|
|
|
|
SpannableString spannableText = new SpannableString(syncText);
|
|
|
|
spannableText.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), styleIndex, styleIndex + 12, 0);
|
|
|
|
syncTextView.setText(spannableText, TextView.BufferType.SPANNABLE);
|
2011-12-19 23:49:44 -08:00
|
|
|
}
|
2012-01-27 02:08:21 -08:00
|
|
|
|
|
|
|
RelativeLayout syncBox = (RelativeLayout) findViewById(R.id.sync_box);
|
|
|
|
syncBox.setOnClickListener(new View.OnClickListener() {
|
|
|
|
public void onClick(View v) {
|
|
|
|
Context context = v.getContext();
|
|
|
|
Intent intent = new Intent(context, SetupSyncActivity.class);
|
|
|
|
context.startActivity(intent);
|
|
|
|
}
|
|
|
|
});
|
2012-03-12 12:48:55 -07:00
|
|
|
|
|
|
|
mRemoteTabClickListener = new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
String url = ((String) v.getTag());
|
|
|
|
JSONObject args = new JSONObject();
|
|
|
|
try {
|
|
|
|
args.put("url", url);
|
|
|
|
args.put("engine", null);
|
|
|
|
args.put("userEntered", false);
|
|
|
|
} catch (Exception e) {
|
|
|
|
Log.e(LOGTAG, "error building JSON arguments");
|
|
|
|
}
|
|
|
|
|
|
|
|
Log.d(LOGTAG, "Sending message to Gecko: " + SystemClock.uptimeMillis() + " - Tab:Add");
|
|
|
|
GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("Tab:Add", args.toString()));
|
|
|
|
}
|
|
|
|
};
|
2011-11-28 22:38:35 -08:00
|
|
|
}
|
|
|
|
|
2012-03-08 15:48:44 -08:00
|
|
|
public void onDestroy() {
|
|
|
|
if (mAccountListener != null) {
|
|
|
|
mAccountManager.removeOnAccountsUpdatedListener(mAccountListener);
|
|
|
|
mAccountListener = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-14 09:50:55 -08:00
|
|
|
void setLastTabsVisibility(boolean visible) {
|
2012-03-19 16:15:05 -07:00
|
|
|
if (visible)
|
|
|
|
mLastTabs.show();
|
|
|
|
else
|
|
|
|
mLastTabs.hide();
|
2012-02-02 07:49:48 -08:00
|
|
|
}
|
|
|
|
|
2012-01-24 06:03:28 -08:00
|
|
|
private void setTopSitesVisibility(boolean visible, boolean hasTopSites) {
|
|
|
|
int visibility = visible ? View.VISIBLE : View.GONE;
|
|
|
|
int visibilityWithTopSites = visible && hasTopSites ? View.VISIBLE : View.GONE;
|
|
|
|
int visibilityWithoutTopSites = visible && !hasTopSites ? View.VISIBLE : View.GONE;
|
2012-01-24 06:03:28 -08:00
|
|
|
|
|
|
|
findViewById(R.id.top_sites_grid).setVisibility(visibilityWithTopSites);
|
2012-01-24 06:03:28 -08:00
|
|
|
findViewById(R.id.top_sites_title).setVisibility(visibility);
|
2012-01-24 06:03:28 -08:00
|
|
|
findViewById(R.id.all_top_sites_text).setVisibility(visibilityWithTopSites);
|
|
|
|
findViewById(R.id.no_top_sites_text).setVisibility(visibilityWithoutTopSites);
|
|
|
|
}
|
|
|
|
|
2012-01-24 06:03:28 -08:00
|
|
|
private void setSyncVisibility(boolean visible) {
|
|
|
|
int visibility = visible ? View.VISIBLE : View.GONE;
|
|
|
|
findViewById(R.id.sync_box_container).setVisibility(visibility);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updateSyncLayout(boolean isFirstRun, boolean hasTopSites) {
|
|
|
|
RelativeLayout syncContainer = (RelativeLayout) findViewById(R.id.sync_box_container);
|
|
|
|
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) syncContainer.getLayoutParams();
|
|
|
|
|
|
|
|
int below = R.id.all_top_sites_text;
|
|
|
|
if (isFirstRun && !hasTopSites)
|
|
|
|
below = R.id.top_sites_top;
|
|
|
|
else if (!hasTopSites)
|
|
|
|
below = R.id.no_top_sites_text;
|
|
|
|
|
|
|
|
int background = R.drawable.abouthome_bg_repeat;
|
|
|
|
if (isFirstRun && !hasTopSites)
|
|
|
|
background = 0;
|
|
|
|
|
|
|
|
params.addRule(RelativeLayout.BELOW, below);
|
|
|
|
syncContainer.setLayoutParams(params);
|
|
|
|
|
|
|
|
syncContainer.setBackgroundResource(background);
|
|
|
|
}
|
|
|
|
|
|
|
|
private boolean isSyncSetup() {
|
2012-02-02 08:08:58 -08:00
|
|
|
Account[] accounts = mAccountManager.getAccountsByType("org.mozilla.firefox_sync");
|
2012-01-24 06:03:28 -08:00
|
|
|
return accounts.length > 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updateLayout(GeckoApp.StartupMode startupMode, boolean syncIsSetup) {
|
|
|
|
// The idea here is that we only show the sync invitation
|
|
|
|
// on the very first run. Show sync banner below the top
|
|
|
|
// sites section in all other cases.
|
|
|
|
|
|
|
|
boolean hasTopSites = mTopSitesAdapter.getCount() > 0;
|
|
|
|
boolean isFirstRun = (startupMode == GeckoApp.StartupMode.NEW_PROFILE);
|
|
|
|
|
|
|
|
setTopSitesVisibility(!isFirstRun || hasTopSites, hasTopSites);
|
|
|
|
setSyncVisibility(!syncIsSetup);
|
|
|
|
updateSyncLayout(isFirstRun, hasTopSites);
|
|
|
|
}
|
|
|
|
|
2011-12-13 12:15:17 -08:00
|
|
|
private int getNumberOfTopSites() {
|
|
|
|
Configuration config = getContext().getResources().getConfiguration();
|
|
|
|
if (config.orientation == Configuration.ORIENTATION_LANDSCAPE)
|
|
|
|
return NUMBER_OF_TOP_SITES_LANDSCAPE;
|
|
|
|
else
|
|
|
|
return NUMBER_OF_TOP_SITES_PORTRAIT;
|
|
|
|
}
|
2011-11-28 22:38:35 -08:00
|
|
|
|
2011-12-13 12:15:17 -08:00
|
|
|
private int getNumberOfColumns() {
|
|
|
|
Configuration config = getContext().getResources().getConfiguration();
|
|
|
|
if (config.orientation == Configuration.ORIENTATION_LANDSCAPE)
|
|
|
|
return NUMBER_OF_COLS_LANDSCAPE;
|
|
|
|
else
|
|
|
|
return NUMBER_OF_COLS_PORTRAIT;
|
|
|
|
}
|
2011-11-28 22:38:35 -08:00
|
|
|
|
2012-01-27 02:08:21 -08:00
|
|
|
private void loadTopSites(final Activity activity) {
|
2012-01-27 02:08:21 -08:00
|
|
|
if (mCursor != null)
|
|
|
|
activity.stopManagingCursor(mCursor);
|
|
|
|
|
|
|
|
// Ensure we initialize GeckoApp's startup mode in
|
|
|
|
// background thread before we use it when updating
|
|
|
|
// the top sites section layout in main thread.
|
|
|
|
final GeckoApp.StartupMode startupMode = GeckoApp.mAppContext.getStartupMode();
|
|
|
|
|
|
|
|
// The isSyncSetup method should not be called on
|
|
|
|
// UI thread as it touches disk to access a sqlite DB.
|
|
|
|
final boolean syncIsSetup = isSyncSetup();
|
|
|
|
|
|
|
|
ContentResolver resolver = GeckoApp.mAppContext.getContentResolver();
|
|
|
|
mCursor = BrowserDB.getTopSites(resolver, NUMBER_OF_TOP_SITES_PORTRAIT);
|
|
|
|
activity.startManagingCursor(mCursor);
|
|
|
|
|
|
|
|
GeckoApp.mAppContext.mMainHandler.post(new Runnable() {
|
2011-11-28 22:38:35 -08:00
|
|
|
public void run() {
|
2012-01-27 02:08:21 -08:00
|
|
|
if (mTopSitesAdapter == null) {
|
|
|
|
mTopSitesAdapter = new TopSitesCursorAdapter(activity,
|
|
|
|
R.layout.abouthome_topsite_item,
|
|
|
|
mCursor,
|
|
|
|
new String[] { URLColumns.TITLE,
|
|
|
|
URLColumns.THUMBNAIL },
|
|
|
|
new int[] { R.id.title, R.id.thumbnail });
|
|
|
|
|
|
|
|
mTopSitesAdapter.setViewBinder(new TopSitesViewBinder());
|
|
|
|
mTopSitesGrid.setAdapter(mTopSitesAdapter);
|
|
|
|
} else {
|
|
|
|
mTopSitesAdapter.changeCursor(mCursor);
|
|
|
|
}
|
2011-12-13 12:15:17 -08:00
|
|
|
|
2012-01-27 02:08:21 -08:00
|
|
|
mTopSitesGrid.setNumColumns(getNumberOfColumns());
|
2011-12-13 12:15:17 -08:00
|
|
|
|
2012-01-27 02:08:21 -08:00
|
|
|
updateLayout(startupMode, syncIsSetup);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2012-01-24 06:03:28 -08:00
|
|
|
|
2012-01-27 02:08:21 -08:00
|
|
|
void update(final Activity activity, final EnumSet<UpdateFlags> flags) {
|
2012-01-27 02:08:21 -08:00
|
|
|
GeckoAppShell.getHandler().post(new Runnable() {
|
|
|
|
public void run() {
|
2012-01-27 02:08:21 -08:00
|
|
|
if (flags.contains(UpdateFlags.TOP_SITES))
|
|
|
|
loadTopSites(activity);
|
|
|
|
|
|
|
|
if (flags.contains(UpdateFlags.PREVIOUS_TABS))
|
|
|
|
readLastTabs(activity);
|
|
|
|
|
|
|
|
if (flags.contains(UpdateFlags.RECOMMENDED_ADDONS))
|
|
|
|
readRecommendedAddons(activity);
|
2012-03-12 12:48:55 -07:00
|
|
|
|
|
|
|
if (flags.contains(UpdateFlags.REMOTE_TABS))
|
|
|
|
loadRemoteTabs(activity);
|
2011-11-28 22:38:35 -08:00
|
|
|
}
|
2012-01-27 02:08:21 -08:00
|
|
|
});
|
2011-11-28 22:38:35 -08:00
|
|
|
}
|
|
|
|
|
2011-12-13 12:15:17 -08:00
|
|
|
public void setUriLoadCallback(UriLoadCallback uriLoadCallback) {
|
|
|
|
mUriLoadCallback = uriLoadCallback;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void onActivityContentChanged(Activity activity) {
|
2012-01-27 02:08:21 -08:00
|
|
|
update(activity, EnumSet.of(UpdateFlags.TOP_SITES));
|
2011-12-13 12:15:17 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onConfigurationChanged(Configuration newConfig) {
|
2011-12-20 21:17:16 -08:00
|
|
|
if (mTopSitesGrid != null)
|
|
|
|
mTopSitesGrid.setNumColumns(getNumberOfColumns());
|
|
|
|
if (mTopSitesAdapter != null)
|
|
|
|
mTopSitesAdapter.notifyDataSetChanged();
|
2011-12-13 12:15:17 -08:00
|
|
|
|
|
|
|
super.onConfigurationChanged(newConfig);
|
|
|
|
}
|
|
|
|
|
2012-01-17 19:40:43 -08:00
|
|
|
private String readFromZipFile(Activity activity, String filename) {
|
|
|
|
ZipFile zip = null;
|
|
|
|
String str = null;
|
|
|
|
try {
|
|
|
|
InputStream fileStream = null;
|
|
|
|
File applicationPackage = new File(activity.getApplication().getPackageResourcePath());
|
|
|
|
zip = new ZipFile(applicationPackage);
|
|
|
|
if (zip == null)
|
|
|
|
return null;
|
|
|
|
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];
|
|
|
|
StringBuffer jsonString = new StringBuffer();
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2012-01-24 08:52:26 -08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2012-01-17 19:40:43 -08:00
|
|
|
private void readRecommendedAddons(final Activity activity) {
|
|
|
|
final String addonsFilename = "recommended-addons.json";
|
2012-02-25 20:22:40 -08:00
|
|
|
String jsonString;
|
|
|
|
try {
|
|
|
|
jsonString = GeckoApp.mAppContext.getProfile().readFile(addonsFilename);
|
|
|
|
} catch (IOException ioe) {
|
|
|
|
Log.i(LOGTAG, "filestream is null");
|
2012-01-17 19:40:43 -08:00
|
|
|
jsonString = readFromZipFile(activity, addonsFilename);
|
|
|
|
}
|
|
|
|
|
2012-02-02 07:49:48 -08:00
|
|
|
JSONArray addonsArray = null;
|
|
|
|
if (jsonString != null) {
|
|
|
|
try {
|
|
|
|
addonsArray = new JSONObject(jsonString).getJSONArray("addons");
|
|
|
|
} catch (JSONException e) {
|
|
|
|
Log.i(LOGTAG, "error reading json file", e);
|
|
|
|
}
|
2012-01-17 19:40:43 -08:00
|
|
|
}
|
|
|
|
|
2012-02-02 07:49:48 -08:00
|
|
|
final JSONArray array = addonsArray;
|
2012-01-17 19:40:43 -08:00
|
|
|
GeckoApp.mAppContext.mMainHandler.post(new Runnable() {
|
2011-11-28 22:38:35 -08:00
|
|
|
public void run() {
|
|
|
|
try {
|
2012-02-02 07:49:48 -08:00
|
|
|
if (array == null || array.length() == 0) {
|
2012-03-19 16:15:05 -07:00
|
|
|
mAddons.hide();
|
2012-02-02 07:49:48 -08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-01-17 19:40:43 -08:00
|
|
|
for (int i = 0; i < array.length(); i++) {
|
|
|
|
JSONObject jsonobj = array.getJSONObject(i);
|
2012-01-24 08:52:26 -08:00
|
|
|
|
2012-03-19 16:15:05 -07:00
|
|
|
final View row = mInflater.inflate(R.layout.abouthome_addon_row, mAddons.getItemsContainer(), false);
|
2012-01-17 19:40:43 -08:00
|
|
|
((TextView) row.findViewById(R.id.addon_title)).setText(jsonobj.getString("name"));
|
2012-01-24 08:52:26 -08:00
|
|
|
((TextView) row.findViewById(R.id.addon_version)).setText(jsonobj.getString("version"));
|
|
|
|
|
2012-01-24 08:52:26 -08:00
|
|
|
String iconUrl = jsonobj.getString("iconURL");
|
|
|
|
String pageUrl = getPageUrlFromIconUrl(iconUrl);
|
|
|
|
|
2012-02-23 07:20:49 -08:00
|
|
|
final String homepageUrl = jsonobj.getString("homepageURL");
|
|
|
|
row.setOnClickListener(new View.OnClickListener() {
|
|
|
|
public void onClick(View v) {
|
|
|
|
if (mUriLoadCallback != null)
|
|
|
|
mUriLoadCallback.callback(homepageUrl);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2012-01-24 08:52:26 -08:00
|
|
|
Favicons favicons = GeckoApp.mAppContext.mFavicons;
|
|
|
|
favicons.loadFavicon(pageUrl, iconUrl,
|
|
|
|
new Favicons.OnFaviconLoadedListener() {
|
|
|
|
public void onFaviconLoaded(String url, Drawable favicon) {
|
|
|
|
if (favicon != null) {
|
|
|
|
ImageView icon = (ImageView) row.findViewById(R.id.addon_icon);
|
|
|
|
icon.setImageDrawable(favicon);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2012-03-19 16:15:05 -07:00
|
|
|
mAddons.addItem(row);
|
2011-12-20 07:58:21 -08:00
|
|
|
}
|
2012-02-02 07:49:48 -08:00
|
|
|
|
2012-03-19 16:15:05 -07:00
|
|
|
mAddons.show();
|
2012-01-17 19:40:43 -08:00
|
|
|
} catch (JSONException e) {
|
|
|
|
Log.i(LOGTAG, "error reading json file", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2011-12-20 07:58:21 -08:00
|
|
|
|
2012-01-17 19:40:43 -08:00
|
|
|
private void readLastTabs(final Activity activity) {
|
2012-02-25 20:22:40 -08:00
|
|
|
String jsonString = GeckoApp.mAppContext.getProfile().readSessionFile(GeckoApp.sIsGeckoReady);
|
|
|
|
if (jsonString == null) {
|
|
|
|
// no previous session data
|
|
|
|
return;
|
2012-02-14 12:07:53 -08:00
|
|
|
}
|
|
|
|
|
2012-01-17 19:40:43 -08:00
|
|
|
final JSONArray tabs;
|
|
|
|
try {
|
|
|
|
tabs = new JSONObject(jsonString).getJSONArray("windows")
|
|
|
|
.getJSONObject(0)
|
|
|
|
.getJSONArray("tabs");
|
|
|
|
} catch (JSONException e) {
|
|
|
|
Log.i(LOGTAG, "error reading json file", e);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
final ArrayList<String> lastTabUrlsList = new ArrayList<String>();
|
|
|
|
|
|
|
|
for (int i = 0; i < tabs.length(); i++) {
|
|
|
|
final String title;
|
|
|
|
final String url;
|
|
|
|
try {
|
|
|
|
JSONObject tab = tabs.getJSONObject(i);
|
|
|
|
int index = tab.getInt("index");
|
|
|
|
JSONArray entries = tab.getJSONArray("entries");
|
|
|
|
JSONObject entry = entries.getJSONObject(index - 1);
|
|
|
|
url = entry.getString("url");
|
2012-02-02 07:49:43 -08:00
|
|
|
|
|
|
|
String optTitle = entry.optString("title");
|
|
|
|
if (optTitle.length() == 0)
|
|
|
|
title = url;
|
|
|
|
else
|
|
|
|
title = optTitle;
|
2012-01-17 19:40:43 -08:00
|
|
|
} catch (JSONException e) {
|
|
|
|
Log.e(LOGTAG, "error reading json file", e);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// don't show last tabs for about pages
|
|
|
|
if (url.startsWith("about:"))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
ContentResolver resolver = GeckoApp.mAppContext.getContentResolver();
|
|
|
|
final BitmapDrawable favicon = BrowserDB.getFaviconForUrl(resolver, url);
|
|
|
|
lastTabUrlsList.add(url);
|
|
|
|
|
|
|
|
GeckoApp.mAppContext.mMainHandler.post(new Runnable() {
|
|
|
|
public void run() {
|
2012-03-19 16:15:05 -07:00
|
|
|
View container = mInflater.inflate(R.layout.abouthome_last_tabs_row, mLastTabs.getItemsContainer(), false);
|
2012-01-17 19:40:43 -08:00
|
|
|
((TextView) container.findViewById(R.id.last_tab_title)).setText(title);
|
|
|
|
((TextView) container.findViewById(R.id.last_tab_url)).setText(url);
|
|
|
|
if (favicon != null)
|
|
|
|
((ImageView) container.findViewById(R.id.last_tab_favicon)).setImageDrawable(favicon);
|
|
|
|
|
|
|
|
container.findViewById(R.id.last_tab_row).setOnClickListener(new View.OnClickListener() {
|
|
|
|
public void onClick(View v) {
|
|
|
|
GeckoApp.mAppContext.loadUrlInTab(url);
|
2011-11-28 22:38:35 -08:00
|
|
|
}
|
|
|
|
});
|
2012-01-17 19:40:43 -08:00
|
|
|
|
2012-03-19 16:15:05 -07:00
|
|
|
mLastTabs.addItem(container);
|
2012-01-17 19:40:43 -08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2012-03-19 16:15:05 -07:00
|
|
|
final int numLastTabs = lastTabUrlsList.size();
|
|
|
|
GeckoApp.mAppContext.mMainHandler.post(new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
if (numLastTabs > 1) {
|
|
|
|
mLastTabs.showMoreText();
|
|
|
|
mLastTabs.setOnMoreTextClickListener(new View.OnClickListener() {
|
|
|
|
public void onClick(View v) {
|
|
|
|
for (String url : lastTabUrlsList)
|
|
|
|
GeckoApp.mAppContext.loadUrlInTab(url);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
mLastTabs.show();
|
|
|
|
} else if (numLastTabs == 1) {
|
|
|
|
mLastTabs.hideMoreText();
|
|
|
|
mLastTabs.show();
|
2011-11-28 22:38:35 -08:00
|
|
|
}
|
|
|
|
}
|
2012-03-19 16:15:05 -07:00
|
|
|
});
|
2011-11-28 22:38:35 -08:00
|
|
|
}
|
|
|
|
|
2012-03-12 12:48:55 -07:00
|
|
|
private void loadRemoteTabs(final Activity activity) {
|
|
|
|
if (!isSyncSetup()) {
|
2012-03-19 16:15:05 -07:00
|
|
|
GeckoApp.mAppContext.mMainHandler.post(new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
mRemoteTabs.hide();
|
|
|
|
}
|
|
|
|
});
|
2012-03-12 12:48:55 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
TabsAccessor.getTabs(getContext(), NUMBER_OF_REMOTE_TABS, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onQueryTabsComplete(List<TabsAccessor.RemoteTab> tabsList) {
|
|
|
|
ArrayList<TabsAccessor.RemoteTab> tabs = new ArrayList<TabsAccessor.RemoteTab> (tabsList);
|
|
|
|
if (tabs == null || tabs.size() == 0) {
|
2012-03-19 16:15:05 -07:00
|
|
|
mRemoteTabs.hide();
|
2012-03-12 12:48:55 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-03-19 16:15:05 -07:00
|
|
|
mRemoteTabs.clear();
|
2012-03-12 12:48:55 -07:00
|
|
|
|
|
|
|
String client = null;
|
|
|
|
|
|
|
|
for (TabsAccessor.RemoteTab tab : tabs) {
|
|
|
|
if (client == null)
|
|
|
|
client = tab.name;
|
|
|
|
else if (!TextUtils.equals(client, tab.name))
|
|
|
|
break;
|
|
|
|
|
2012-03-19 16:15:05 -07:00
|
|
|
final TextView row = (TextView) mInflater.inflate(R.layout.abouthome_remote_tab_row, mRemoteTabs.getItemsContainer(), false);
|
2012-03-19 10:56:38 -07:00
|
|
|
row.setText(TextUtils.isEmpty(tab.title) ? tab.url : tab.title);
|
2012-03-12 12:48:55 -07:00
|
|
|
row.setTag(tab.url);
|
2012-03-19 16:15:05 -07:00
|
|
|
mRemoteTabs.addItem(row);
|
2012-03-12 12:48:55 -07:00
|
|
|
row.setOnClickListener(mRemoteTabClickListener);
|
|
|
|
}
|
|
|
|
|
2012-03-19 16:15:05 -07:00
|
|
|
mRemoteTabs.setSubtitle(client);
|
|
|
|
mRemoteTabs.show();
|
2012-03-12 12:48:55 -07:00
|
|
|
}
|
|
|
|
|
2011-12-13 12:15:17 -08:00
|
|
|
public static class TopSitesGridView extends GridView {
|
2011-12-27 09:44:22 -08:00
|
|
|
/** From layout xml:
|
|
|
|
* 80dip image height
|
|
|
|
* + 2dip image paddingTop
|
|
|
|
* + 1dip image padding (for bottom)
|
|
|
|
* + 3dip marginTop on the TextView
|
|
|
|
* +15dip TextView height
|
|
|
|
* + 8dip vertical spacing in the GridView
|
|
|
|
* ------
|
|
|
|
* 109dip total height per top site grid item
|
|
|
|
*/
|
|
|
|
private static final int kTopSiteItemHeight = 109;
|
|
|
|
float mDisplayDensity ;
|
|
|
|
|
2011-12-13 12:15:17 -08:00
|
|
|
public TopSitesGridView(Context context, AttributeSet attrs) {
|
|
|
|
super(context, attrs);
|
2011-12-27 09:44:22 -08:00
|
|
|
DisplayMetrics dm = new DisplayMetrics();
|
|
|
|
GeckoApp.mAppContext.getWindowManager().getDefaultDisplay().getMetrics(dm);
|
|
|
|
mDisplayDensity = dm.density;
|
2011-12-13 12:15:17 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
2011-12-27 09:44:22 -08:00
|
|
|
int numRows;
|
2012-02-14 10:15:20 -08:00
|
|
|
|
2012-02-14 10:15:20 -08:00
|
|
|
SimpleCursorAdapter adapter = (SimpleCursorAdapter) getAdapter();
|
|
|
|
int nSites = Integer.MAX_VALUE;
|
|
|
|
|
|
|
|
if (adapter != null) {
|
|
|
|
Cursor c = adapter.getCursor();
|
|
|
|
if (c != null)
|
|
|
|
nSites = c.getCount();
|
|
|
|
}
|
|
|
|
|
2011-12-27 09:44:22 -08:00
|
|
|
Configuration config = getContext().getResources().getConfiguration();
|
|
|
|
if (config.orientation == Configuration.ORIENTATION_LANDSCAPE) {
|
2012-02-14 10:15:20 -08:00
|
|
|
nSites = Math.min(nSites, NUMBER_OF_TOP_SITES_LANDSCAPE);
|
|
|
|
numRows = (int) Math.round((double) nSites / NUMBER_OF_COLS_LANDSCAPE);
|
2011-12-27 09:44:22 -08:00
|
|
|
} else {
|
2012-02-14 10:15:20 -08:00
|
|
|
nSites = Math.min(nSites, NUMBER_OF_TOP_SITES_PORTRAIT);
|
|
|
|
numRows = (int) Math.round((double) nSites / NUMBER_OF_COLS_PORTRAIT);
|
2011-12-27 09:44:22 -08:00
|
|
|
}
|
|
|
|
int expandedHeightSpec =
|
|
|
|
MeasureSpec.makeMeasureSpec((int)(mDisplayDensity * numRows * kTopSiteItemHeight),
|
|
|
|
MeasureSpec.EXACTLY);
|
2011-12-13 12:15:17 -08:00
|
|
|
super.onMeasure(widthMeasureSpec, expandedHeightSpec);
|
|
|
|
}
|
2011-11-28 22:38:35 -08:00
|
|
|
}
|
|
|
|
|
2011-12-13 12:15:17 -08:00
|
|
|
public class TopSitesCursorAdapter extends SimpleCursorAdapter {
|
|
|
|
public TopSitesCursorAdapter(Context context, int layout, Cursor c,
|
2011-12-19 23:49:44 -08:00
|
|
|
String[] from, int[] to) {
|
2011-12-13 12:15:17 -08:00
|
|
|
super(context, layout, c, from, to);
|
2011-11-28 22:38:35 -08:00
|
|
|
}
|
|
|
|
|
2011-12-13 12:15:17 -08:00
|
|
|
@Override
|
|
|
|
public int getCount() {
|
|
|
|
return Math.min(super.getCount(), getNumberOfTopSites());
|
|
|
|
}
|
2011-11-28 22:38:35 -08:00
|
|
|
}
|
|
|
|
|
2011-12-13 12:15:17 -08:00
|
|
|
class TopSitesViewBinder implements SimpleCursorAdapter.ViewBinder {
|
|
|
|
private boolean updateThumbnail(View view, Cursor cursor, int thumbIndex) {
|
|
|
|
byte[] b = cursor.getBlob(thumbIndex);
|
|
|
|
ImageView thumbnail = (ImageView) view;
|
|
|
|
|
|
|
|
if (b == null) {
|
2012-02-15 10:14:29 -08:00
|
|
|
thumbnail.setImageResource(R.drawable.tab_thumbnail_default);
|
2011-12-13 12:15:17 -08:00
|
|
|
} else {
|
|
|
|
try {
|
|
|
|
Bitmap bitmap = BitmapFactory.decodeByteArray(b, 0, b.length);
|
|
|
|
thumbnail.setImageBitmap(bitmap);
|
|
|
|
} catch (OutOfMemoryError oom) {
|
|
|
|
Log.e(LOGTAG, "Unable to load thumbnail bitmap", oom);
|
2012-02-15 10:14:29 -08:00
|
|
|
thumbnail.setImageResource(R.drawable.tab_thumbnail_default);
|
2011-12-13 12:15:17 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2011-11-28 22:38:35 -08:00
|
|
|
}
|
|
|
|
|
2011-12-13 12:15:17 -08:00
|
|
|
private boolean updateTitle(View view, Cursor cursor, int titleIndex) {
|
|
|
|
String title = cursor.getString(titleIndex);
|
|
|
|
TextView titleView = (TextView) view;
|
|
|
|
|
|
|
|
// Use the URL instead of an empty title for consistency with the normal URL
|
|
|
|
// bar view - this is the equivalent of getDisplayTitle() in Tab.java
|
|
|
|
if (title == null || title.length() == 0) {
|
|
|
|
int urlIndex = cursor.getColumnIndexOrThrow(URLColumns.URL);
|
|
|
|
title = cursor.getString(urlIndex);
|
|
|
|
}
|
2011-11-28 22:38:35 -08:00
|
|
|
|
2011-12-13 12:15:17 -08:00
|
|
|
titleView.setText(title);
|
|
|
|
return true;
|
2011-11-28 22:38:35 -08:00
|
|
|
}
|
|
|
|
|
2011-12-13 12:15:17 -08:00
|
|
|
@Override
|
|
|
|
public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
|
|
|
|
int titleIndex = cursor.getColumnIndexOrThrow(URLColumns.TITLE);
|
|
|
|
if (columnIndex == titleIndex) {
|
|
|
|
return updateTitle(view, cursor, titleIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
int thumbIndex = cursor.getColumnIndexOrThrow(URLColumns.THUMBNAIL);
|
|
|
|
if (columnIndex == thumbIndex) {
|
|
|
|
return updateThumbnail(view, cursor, thumbIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Other columns are handled automatically
|
|
|
|
return false;
|
2011-11-28 22:38:35 -08:00
|
|
|
}
|
2011-12-13 12:15:17 -08:00
|
|
|
}
|
2011-11-28 22:38:35 -08:00
|
|
|
}
|