2012-03-23 12:00:17 -07:00
|
|
|
/* 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;
|
|
|
|
|
2012-07-27 17:53:54 -07:00
|
|
|
import org.mozilla.gecko.gfx.LayerView;
|
|
|
|
|
2012-03-23 12:00:17 -07:00
|
|
|
import android.content.Context;
|
|
|
|
import android.text.TextUtils;
|
|
|
|
import android.util.AttributeSet;
|
|
|
|
import android.util.Log;
|
|
|
|
import android.view.LayoutInflater;
|
|
|
|
import android.view.View;
|
|
|
|
|
2012-07-17 17:54:54 -07:00
|
|
|
public final class GeckoViewsFactory implements LayoutInflater.Factory {
|
2012-03-23 12:00:17 -07:00
|
|
|
private static final String LOGTAG = "GeckoViewsFactory";
|
|
|
|
|
|
|
|
private static final String GECKO_VIEW_IDENTIFIER = "org.mozilla.gecko.";
|
|
|
|
private static final int GECKO_VIEW_IDENTIFIER_LENGTH = GECKO_VIEW_IDENTIFIER.length();
|
|
|
|
|
|
|
|
private GeckoViewsFactory() { }
|
|
|
|
|
|
|
|
// Making this a singleton class.
|
|
|
|
private static final GeckoViewsFactory INSTANCE = new GeckoViewsFactory();
|
|
|
|
|
|
|
|
public static GeckoViewsFactory getInstance() {
|
|
|
|
return INSTANCE;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public View onCreateView(String name, Context context, AttributeSet attrs) {
|
|
|
|
if (!TextUtils.isEmpty(name) && name.startsWith(GECKO_VIEW_IDENTIFIER)) {
|
|
|
|
String viewName = name.substring(GECKO_VIEW_IDENTIFIER_LENGTH);
|
|
|
|
|
|
|
|
if (TextUtils.isEmpty(viewName))
|
|
|
|
return null;
|
|
|
|
|
|
|
|
Log.i(LOGTAG, "Creating custom Gecko view: " + viewName);
|
|
|
|
|
|
|
|
if (TextUtils.equals(viewName, "AboutHomeSection"))
|
|
|
|
return new AboutHomeSection(context, attrs);
|
|
|
|
else if (TextUtils.equals(viewName, "AwesomeBarTabs"))
|
|
|
|
return new AwesomeBarTabs(context, attrs);
|
|
|
|
else if (TextUtils.equals(viewName, "FormAssistPopup"))
|
|
|
|
return new FormAssistPopup(context, attrs);
|
|
|
|
else if (TextUtils.equals(viewName, "LinkTextView"))
|
|
|
|
return new LinkTextView(context, attrs);
|
2012-05-30 13:26:13 -07:00
|
|
|
else if (TextUtils.equals(viewName, "FindInPageBar"))
|
|
|
|
return new FindInPageBar(context, attrs);
|
2012-06-10 16:44:50 -07:00
|
|
|
else if (TextUtils.equals(viewName, "TabsPanel"))
|
|
|
|
return new TabsPanel(context, attrs);
|
2012-07-19 13:16:44 -07:00
|
|
|
else if (TextUtils.equals(viewName, "TextSelectionHandle"))
|
|
|
|
return new TextSelectionHandle(context, attrs);
|
2012-07-28 07:33:51 -07:00
|
|
|
else if (TextUtils.equals(viewName, "gfx.LayerView"))
|
|
|
|
return new LayerView(context, attrs);
|
|
|
|
else
|
|
|
|
Log.e(LOGTAG, "Error: unknown custom view: " + viewName);
|
2012-03-23 12:00:17 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|