2012-03-23 19:00:17 +00: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-28 00:53:54 +00:00
|
|
|
import org.mozilla.gecko.gfx.LayerView;
|
|
|
|
|
2012-03-23 19:00:17 +00: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-18 00:54:54 +00:00
|
|
|
public final class GeckoViewsFactory implements LayoutInflater.Factory {
|
2012-03-23 19:00:17 +00: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();
|
|
|
|
|
2012-11-28 19:23:54 +00:00
|
|
|
private static final String GECKO_IDENTIFIER = "Gecko.";
|
|
|
|
private static final int GECKO_IDENTIFIER_LENGTH = GECKO_IDENTIFIER.length();
|
|
|
|
|
2012-03-23 19:00:17 +00:00
|
|
|
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) {
|
2012-11-28 19:23:54 +00:00
|
|
|
if (!TextUtils.isEmpty(name)) {
|
|
|
|
String viewName = null;
|
|
|
|
|
|
|
|
if (name.startsWith(GECKO_VIEW_IDENTIFIER))
|
|
|
|
viewName = name.substring(GECKO_VIEW_IDENTIFIER_LENGTH);
|
|
|
|
else if (name.startsWith(GECKO_IDENTIFIER))
|
|
|
|
viewName = name.substring(GECKO_IDENTIFIER_LENGTH);
|
|
|
|
else
|
|
|
|
return null;
|
2012-03-23 19:00:17 +00:00
|
|
|
|
|
|
|
if (TextUtils.isEmpty(viewName))
|
|
|
|
return null;
|
|
|
|
|
|
|
|
Log.i(LOGTAG, "Creating custom Gecko view: " + viewName);
|
|
|
|
|
2012-08-20 04:10:00 +00:00
|
|
|
if (TextUtils.equals(viewName, "AboutHomePromoBox"))
|
|
|
|
return new AboutHomePromoBox(context, attrs);
|
2012-09-26 12:24:34 +00:00
|
|
|
else if (TextUtils.equals(viewName, "AboutHomeContent"))
|
|
|
|
return new AboutHomeContent(context, attrs);
|
|
|
|
else if (TextUtils.equals(viewName, "AboutHomeContent$TopSitesGridView"))
|
|
|
|
return new AboutHomeContent.TopSitesGridView(context, attrs);
|
2012-08-20 04:10:00 +00:00
|
|
|
else if (TextUtils.equals(viewName, "AboutHomeSection"))
|
2012-03-23 19:00:17 +00:00
|
|
|
return new AboutHomeSection(context, attrs);
|
|
|
|
else if (TextUtils.equals(viewName, "AwesomeBarTabs"))
|
|
|
|
return new AwesomeBarTabs(context, attrs);
|
2012-11-01 05:12:45 +00:00
|
|
|
else if (TextUtils.equals(viewName, "AwesomeBarTabs.Background"))
|
|
|
|
return new AwesomeBarTabs.Background(context, attrs);
|
2012-11-30 21:16:45 +00:00
|
|
|
else if (TextUtils.equals(viewName, "BackButton"))
|
|
|
|
return new BackButton(context, attrs);
|
2012-08-31 18:59:50 +00:00
|
|
|
else if (TextUtils.equals(viewName, "BrowserToolbarBackground"))
|
|
|
|
return new BrowserToolbarBackground(context, attrs);
|
2012-11-01 05:12:02 +00:00
|
|
|
else if (TextUtils.equals(viewName, "BrowserToolbar$RightEdge"))
|
|
|
|
return new BrowserToolbar.RightEdge(context, attrs);
|
2012-03-23 19:00:17 +00:00
|
|
|
else if (TextUtils.equals(viewName, "FormAssistPopup"))
|
|
|
|
return new FormAssistPopup(context, attrs);
|
2012-12-18 22:20:01 +00:00
|
|
|
else if (TextUtils.equals(viewName, "ForwardButton"))
|
|
|
|
return new ForwardButton(context, attrs);
|
2012-10-12 23:23:20 +00:00
|
|
|
else if (TextUtils.equals(viewName, "GeckoApp$MainLayout"))
|
|
|
|
return new GeckoApp.MainLayout(context, attrs);
|
2012-03-23 19:00:17 +00:00
|
|
|
else if (TextUtils.equals(viewName, "LinkTextView"))
|
|
|
|
return new LinkTextView(context, attrs);
|
2012-05-30 20:26:13 +00:00
|
|
|
else if (TextUtils.equals(viewName, "FindInPageBar"))
|
|
|
|
return new FindInPageBar(context, attrs);
|
2012-08-31 19:03:25 +00:00
|
|
|
else if (TextUtils.equals(viewName, "MenuButton"))
|
|
|
|
return new MenuButton(context, attrs);
|
2012-12-19 01:04:39 +00:00
|
|
|
else if (TextUtils.equals(viewName, "RemoteTabs"))
|
|
|
|
return new RemoteTabs(context, attrs);
|
2012-08-31 19:00:24 +00:00
|
|
|
else if (TextUtils.equals(viewName, "TabsButton"))
|
|
|
|
return new TabsButton(context, attrs);
|
2012-06-10 23:44:50 +00:00
|
|
|
else if (TextUtils.equals(viewName, "TabsPanel"))
|
|
|
|
return new TabsPanel(context, attrs);
|
2012-12-19 01:04:39 +00:00
|
|
|
else if (TextUtils.equals(viewName, "TabsTray"))
|
|
|
|
return new TabsTray(context, attrs);
|
2012-07-19 20:16:44 +00:00
|
|
|
else if (TextUtils.equals(viewName, "TextSelectionHandle"))
|
|
|
|
return new TextSelectionHandle(context, attrs);
|
2012-07-28 14:33:51 +00:00
|
|
|
else if (TextUtils.equals(viewName, "gfx.LayerView"))
|
|
|
|
return new LayerView(context, attrs);
|
2012-11-28 19:23:54 +00:00
|
|
|
else if (TextUtils.equals(viewName, "Button"))
|
|
|
|
return new GeckoButton(context, attrs);
|
2012-11-16 08:41:53 +00:00
|
|
|
else if (TextUtils.equals(viewName, "EditText"))
|
|
|
|
return new GeckoEditText(context, attrs);
|
2012-11-28 19:23:54 +00:00
|
|
|
else if (TextUtils.equals(viewName, "FrameLayout"))
|
|
|
|
return new GeckoFrameLayout(context, attrs);
|
|
|
|
else if (TextUtils.equals(viewName, "ImageButton"))
|
|
|
|
return new GeckoImageButton(context, attrs);
|
|
|
|
else if (TextUtils.equals(viewName, "ImageView"))
|
|
|
|
return new GeckoImageView(context, attrs);
|
|
|
|
else if (TextUtils.equals(viewName, "LinearLayout"))
|
|
|
|
return new GeckoLinearLayout(context, attrs);
|
2012-11-16 05:40:57 +00:00
|
|
|
else if (TextUtils.equals(viewName, "RelativeLayout"))
|
|
|
|
return new GeckoRelativeLayout(context, attrs);
|
2012-11-16 07:59:25 +00:00
|
|
|
else if (TextUtils.equals(viewName, "TextSwitcher"))
|
|
|
|
return new GeckoTextSwitcher(context, attrs);
|
2012-11-28 19:23:54 +00:00
|
|
|
else if (TextUtils.equals(viewName, "TextView"))
|
|
|
|
return new GeckoTextView(context, attrs);
|
2012-07-28 14:33:51 +00:00
|
|
|
else
|
2012-09-26 12:24:34 +00:00
|
|
|
Log.d(LOGTAG, "Warning: unknown custom view: " + viewName);
|
2012-03-23 19:00:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|