Use LayoutInflater.Factory to optimize rendering custom views

RESOLVED FIXED in Firefox 13



Firefox for Android
Keyboards and IME
6 years ago
6 years ago


(Reporter: sriram, Assigned: sriram)


Firefox 14

Firefox Tracking Flags

(firefox13 fixed, firefox14 fixed)



(1 attachment)



6 years ago
There is a LayoutInflater associated with every activity. This layout inflater is responsible for inflating views from XML. This is aware of "android.widget" namescape for creating Views. However, our custom views, like AboutHomeSection, take a round about way:
1. I tries to search if any factory can supply this.
2. It tried to find in default namespace.
3. It tries to resolve the view based on "package name" and "class name".

This can be avoided by asking it to search in the factory we supply to it. This will optimize the search done by android while inflating our custom views.

Comment 1

6 years ago
Created attachment 608116 [details] [diff] [review]

This patch uses a LayoutInflater.Factory. I felt it's better to use a singleton class that handles all the custom views, than every activity "implementing" LayoutInflater.Factory. 

This is the first attempt at it. Ideally, its better to hash all the view names in a HashMap for easier access.
Attachment #608116 - Flags: review?(mark.finkle)
Comment on attachment 608116 [details] [diff] [review]

>diff --git a/mobile/android/base/ b/mobile/android/base/

>+    private static final String GECKO_VIEW_IDENTIFIER = "org.mozilla.gecko.";
>+    private static final int GECKO_VIEW_IDENTIFIER_LENGTH = GECKO_VIEW_IDENTIFIER.length();

remove the extra blank line

>+    public View onCreateView(String name, Context context, AttributeSet attrs) {
>+        if (!TextUtils.isEmpty(name) && name.startsWith(GECKO_VIEW_IDENTIFIER)) {

remove the extra blank line

>+            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);

indented too far in the "else if" blocks

r+ with nits fixed
Attachment #608116 - Flags: review?(mark.finkle) → review+

Comment 3

6 years ago

Comment 4

6 years ago
Please can you set the target milestone & assignee when landing on inbound, along the lines of :-)
Assignee: nobody → sriram
Last Resolved: 6 years ago
Resolution: --- → FIXED
Target Milestone: --- → Firefox 14
status-firefox13: --- → fixed
status-firefox14: --- → fixed
You need to log in before you can comment on or make changes to this bug.