Example usage for android.view ViewGroup addView

List of usage examples for android.view ViewGroup addView

Introduction

In this page you can find the example usage for android.view ViewGroup addView.

Prototype

public void addView(View child) 

Source Link

Document

Adds a child view.

Usage

From source file:com.saarang.samples.apps.iosched.ui.SessionDetailActivity.java

private void buildLinksSection(Cursor cursor) {
    // Compile list of links (I/O live link, submit feedback, and normal links)
    ViewGroup linkContainer = (ViewGroup) findViewById(com.saarang.samples.apps.iosched.R.id.links_container);
    linkContainer.removeAllViews();//w  w w .  j a v a2s . c  om

    // Build links section
    // the Object can be either a string URL or an Intent
    List<Pair<Integer, Object>> links = new ArrayList<Pair<Integer, Object>>();

    long currentTimeMillis = UIUtils.getCurrentTime(this);
    if (mHasLivestream && currentTimeMillis > mSessionStart && currentTimeMillis <= mSessionEnd) {
        links.add(new Pair<Integer, Object>(com.saarang.samples.apps.iosched.R.string.session_link_livestream,
                getWatchLiveIntent(this)));
    }

    // Add session feedback link, if appropriate
    if (!mAlreadyGaveFeedback && currentTimeMillis > mSessionEnd - Config.FEEDBACK_MILLIS_BEFORE_SESSION_END) {
        links.add(new Pair<Integer, Object>(
                com.saarang.samples.apps.iosched.R.string.session_feedback_submitlink, getFeedbackIntent()));
    }

    for (int i = 0; i < SessionsQuery.LINKS_INDICES.length; i++) {
        final String linkUrl = cursor.getString(SessionsQuery.LINKS_INDICES[i]);
        if (TextUtils.isEmpty(linkUrl)) {
            continue;
        }

        links.add(new Pair<Integer, Object>(SessionsQuery.LINKS_TITLES[i],
                new Intent(Intent.ACTION_VIEW, Uri.parse(linkUrl))
                        .addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET)));
    }

    // Render links
    if (links.size() > 0) {
        LayoutInflater inflater = LayoutInflater.from(this);
        int columns = getResources().getInteger(com.saarang.samples.apps.iosched.R.integer.links_columns);

        LinearLayout currentLinkRowView = null;
        for (int i = 0; i < links.size(); i++) {
            final Pair<Integer, Object> link = links.get(i);

            // Create link view
            TextView linkView = (TextView) inflater.inflate(
                    com.saarang.samples.apps.iosched.R.layout.list_item_session_link, linkContainer, false);
            if (link.first == com.saarang.samples.apps.iosched.R.string.session_feedback_submitlink) {
                mSubmitFeedbackView = linkView;
            }
            linkView.setText(getString(link.first));
            linkView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    fireLinkEvent(link.first);
                    Intent intent = null;
                    if (link.second instanceof Intent) {
                        intent = (Intent) link.second;
                    } else if (link.second instanceof String) {
                        intent = new Intent(Intent.ACTION_VIEW, Uri.parse((String) link.second))
                                .addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
                    }
                    try {
                        startActivity(intent);
                    } catch (ActivityNotFoundException ignored) {
                    }
                }
            });

            // Place it inside a container
            if (columns == 1) {
                linkContainer.addView(linkView);
            } else {
                // create a new link row
                if (i % columns == 0) {
                    currentLinkRowView = (LinearLayout) inflater.inflate(
                            com.saarang.samples.apps.iosched.R.layout.include_link_row, linkContainer, false);
                    currentLinkRowView.setWeightSum(columns);
                    linkContainer.addView(currentLinkRowView);
                }

                ((LinearLayout.LayoutParams) linkView.getLayoutParams()).width = 0;
                ((LinearLayout.LayoutParams) linkView.getLayoutParams()).weight = 1;
                currentLinkRowView.addView(linkView);
            }
        }

        findViewById(com.saarang.samples.apps.iosched.R.id.session_links_header).setVisibility(View.VISIBLE);
        findViewById(com.saarang.samples.apps.iosched.R.id.links_container).setVisibility(View.VISIBLE);

    } else {
        findViewById(com.saarang.samples.apps.iosched.R.id.session_links_header).setVisibility(View.GONE);
        findViewById(com.saarang.samples.apps.iosched.R.id.links_container).setVisibility(View.GONE);
    }

}

From source file:com.plusot.senselib.SenseMain.java

private void addView() {
    // ViewGroup vg = (ViewGroup) findViewById(R.id.values_layout);
    if (viewsAdded >= MAX_VIEWS_ADDED)
        return;//from   w  w w.  j a v a 2 s  .com

    ViewGroup vg;
    if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE || map != null) {
        switch (viewsAdded) {
        case 0:
        case 2:
            vg = (ViewGroup) findViewById(R.id.double1);
            break;
        case 1:
        case 3:
            vg = (ViewGroup) findViewById(R.id.double2);
            break;
        case 4:
        case 5:
            vg = (ViewGroup) findViewById(R.id.double3);
            break;
        case 6:
        case 7:
            vg = (ViewGroup) findViewById(R.id.double4);
            break;
        default:
            vg = (ViewGroup) findViewById(R.id.main_layout);
            break;
        }
    } else {
        switch (viewsAdded) {
        case 0:
        case 7:
            vg = (ViewGroup) findViewById(R.id.double1);
            break;
        case 1:
        case 6:
            vg = (ViewGroup) findViewById(R.id.double2);
            break;
        case 2:
        case 5:
            vg = (ViewGroup) findViewById(R.id.double3);
            break;
        case 3:
        case 4:
            vg = (ViewGroup) findViewById(R.id.double4);
            break;
        default:
            vg = (ViewGroup) findViewById(R.id.main_layout);
            break;
        }
    }

    final View view = LayoutInflater.from(this).inflate(R.layout.graph_view, vg, false);
    valueViews[viewsAdded] = view;

    if (Globals.testing.isTest()) {
        FitLabelView fit = (FitLabelView) view.findViewById(R.id.caption);
        fit.setPadding(0, 0, 0, 6);
        fit.setHeightPercentage(0.24f);
    }
    view.setId(viewsAdded + VIEW_ID_BASE);
    vg.addView(view);
    View value = view.findViewById(R.id.value);

    addOnValueClick(value, VIEW_ID_BASE + viewsAdded);
    value.setOnTouchListener(new GestureTouchListener(this, view));
    viewsAdded++;
    adjustViews();

}

From source file:com.achep.acdisplay.ui.fragments.AcDisplayFragment.java

private void rebuildNotifications() {
    final long now = SystemClock.elapsedRealtime();

    ViewGroup container = mIconsContainer;

    final int childCount = container.getChildCount();

    // Count the number of non-notification fragments
    // such as unlock or music controls fragments.
    int start = 0;
    for (int i = 0; i < childCount; i++) {
        View child = container.getChildAt(i);
        Widget fragment = findWidgetByIcon(child);
        if (fragment instanceof NotifyWidget) {
            // Those fragments are placed at the begin of layout
            // so no reason to continue searching.
            break;
        } else {/* w w w .  j  av  a 2  s  .c o  m*/
            start++;
        }
    }

    final ArrayList<OpenNotification> list = NotificationPresenter.getInstance().getList();
    final int notifyCount = list.size();

    final boolean[] notifyUsed = new boolean[notifyCount];
    final boolean[] childUsed = new boolean[childCount];

    for (int i = start; i < childCount; i++) {
        View child = container.getChildAt(i);
        NotifyWidget widget = (NotifyWidget) findWidgetByIcon(child);
        OpenNotification target = widget.getNotification();

        for (int j = 0; j < notifyCount; j++) {
            OpenNotification n = list.get(j);
            if (NotificationUtils.hasIdenticalIds(target, n)) {

                notifyUsed[j] = true;
                childUsed[i] = true;

                if (target != n) {
                    widget.setNotification(n);
                }
                break;
            }
        }
    }

    // Re-use free views and remove redundant views.
    boolean removeAllAfter = false;
    for (int a = start, j = 0, offset = 0; a < childCount; a++) {
        if (childUsed[a])
            continue;
        final int i = a + offset;

        View child = container.getChildAt(i);
        removing_all_next_views: {
            if (!removeAllAfter) {
                for (; j < notifyCount; j++) {
                    if (notifyUsed[j])
                        continue;

                    assert child != null;
                    notifyUsed[j] = true;

                    NotifyWidget nw = (NotifyWidget) findWidgetByIcon(child);
                    nw.setNotification(list.get(j));
                    break removing_all_next_views;
                }
            }
            removeAllAfter = true;
            internalReleaseWidget(child);

            // Remove widget's icon.
            container.removeViewAt(i);
            offset--;
        }
    }

    assert getActivity() != null;
    LayoutInflater inflater = getActivity().getLayoutInflater();

    final int iconSize = getConfig().getIconSizePx();
    for (int i = 0; i < notifyCount; i++) {
        if (notifyUsed[i])
            continue;

        NotifyWidget nw = new NotifyWidget(this, this);
        if (isResumed())
            nw.start();

        View iconView = nw.createIconView(inflater, container);
        ViewUtils.setSize(iconView, iconSize);
        container.addView(iconView);

        nw.setNotification(list.get(i));
        mWidgetsMap.put(iconView, nw);
    }

    // /////////////////////
    // ~~ UPDATE HASH MAP ~~
    // /////////////////////

    HashMap<String, SceneCompat> map = (HashMap<String, SceneCompat>) mScenesMap.clone();

    mScenesMap.clear();
    for (Widget fragment : mWidgetsMap.values()) {
        String type = fragment.getClass().getName();
        SceneCompat scene = map.get(type);
        if (scene != null) {
            fragment.createView(null, null, scene.getView());
        } else {
            ViewGroup sceneView = fragment.createView(inflater, mSceneContainer, null);
            if (sceneView != null) {
                scene = new SceneCompat(mSceneContainer, sceneView);
                map.put(type, scene);
            }
        }
        if (scene != null) {
            mScenesMap.put(type, scene);
        }
    }

    if (DEBUG) {
        long delta = SystemClock.elapsedRealtime() - now;
        Log.d(TAG, "Fragment list updated in " + delta + "ms.");
    }

    // Do not animate divider's visibility change on
    // pause/resume, cause it _somehow_ confuses people.
    boolean animate = !mResuming;
    updateDividerVisibility(animate);
}

From source file:ch.blinkenlights.android.vanilla.LibraryPagerAdapter.java

@Override
public Object instantiateItem(ViewGroup container, int position) {
    int type = mTabOrder[position];
    ListView view = mLists[type];

    if (view == null) {
        LibraryActivity activity = mActivity;
        LayoutInflater inflater = activity.getLayoutInflater();
        LibraryAdapter adapter;/* w  w  w.j  av  a  2s  . c om*/
        DraggableRow header = null;

        switch (type) {
        case MediaUtils.TYPE_ARTIST:
            adapter = mArtistAdapter = new MediaAdapter(activity, MediaUtils.TYPE_ARTIST, mPendingArtistLimiter,
                    activity);
            mArtistAdapter.setExpandable(getMediaTypePosition(MediaUtils.TYPE_SONG) != -1
                    || getMediaTypePosition(MediaUtils.TYPE_ALBUM) != -1);
            header = (DraggableRow) inflater.inflate(R.layout.draggable_row, null);
            break;
        case MediaUtils.TYPE_ALBARTIST:
            adapter = mAlbArtAdapter = new MediaAdapter(activity, MediaUtils.TYPE_ALBARTIST,
                    mPendingAlbArtLimiter, activity);
            mAlbArtAdapter.setExpandable(getMediaTypePosition(MediaUtils.TYPE_SONG) != -1
                    || getMediaTypePosition(MediaUtils.TYPE_ALBUM) != -1);
            header = (DraggableRow) inflater.inflate(R.layout.draggable_row, null);
            break;
        case MediaUtils.TYPE_COMPOSER:
            adapter = mComposerAdapter = new MediaAdapter(activity, MediaUtils.TYPE_COMPOSER,
                    mPendingComposerLimiter, activity);
            mComposerAdapter.setExpandable(getMediaTypePosition(MediaUtils.TYPE_SONG) != -1
                    || getMediaTypePosition(MediaUtils.TYPE_ALBUM) != -1);
            header = (DraggableRow) inflater.inflate(R.layout.draggable_row, null);
            break;
        case MediaUtils.TYPE_ALBUM:
            adapter = mAlbumAdapter = new MediaAdapter(activity, MediaUtils.TYPE_ALBUM, mPendingAlbumLimiter,
                    activity);
            mAlbumAdapter.setExpandable(getMediaTypePosition(MediaUtils.TYPE_SONG) != -1);
            mPendingAlbumLimiter = null;
            header = (DraggableRow) inflater.inflate(R.layout.draggable_row, null);
            break;
        case MediaUtils.TYPE_SONG:
            adapter = mSongAdapter = new MediaAdapter(activity, MediaUtils.TYPE_SONG, mPendingSongLimiter,
                    activity);
            mPendingSongLimiter = null;
            header = (DraggableRow) inflater.inflate(R.layout.draggable_row, null);
            break;
        case MediaUtils.TYPE_PLAYLIST:
            adapter = mPlaylistAdapter = new MediaAdapter(activity, MediaUtils.TYPE_PLAYLIST, null, activity);
            break;
        case MediaUtils.TYPE_GENRE:
            adapter = mGenreAdapter = new MediaAdapter(activity, MediaUtils.TYPE_GENRE, null, activity);
            mGenreAdapter.setExpandable(getMediaTypePosition(MediaUtils.TYPE_SONG) != -1);
            break;
        case MediaUtils.TYPE_FILE:
            adapter = mFilesAdapter = new FileSystemAdapter(activity, mPendingFileLimiter);
            mPendingFileLimiter = null;
            header = (DraggableRow) inflater.inflate(R.layout.draggable_row, null);
            break;
        default:
            throw new IllegalArgumentException("Invalid media type: " + type);
        }

        view = (ListView) inflater.inflate(R.layout.listview, null);
        view.setOnCreateContextMenuListener(this);
        view.setOnItemClickListener(this);

        view.setTag(type);
        if (header != null) {
            header.setText(mHeaderText);
            header.setTag(new ViewHolder()); // behave like a normal library row
            view.addHeaderView(header);
            mHeaderViews.add(header);
        }
        view.setAdapter(adapter);

        loadSortOrder((SortableAdapter) adapter);

        adapter.setFilter(mFilter);

        mAdapters[type] = adapter;
        mLists[type] = view;
        mRequeryNeeded[type] = true;
    }

    requeryIfNeeded(type);
    container.addView(view);
    return view;
}

From source file:com.saarang.samples.apps.iosched.ui.SessionDetailActivity.java

private void onSpeakersQueryComplete(Cursor cursor) {
    mSpeakersCursor = true;//from  w  w w .  j  ava  2  s . c  o  m
    final ViewGroup speakersGroup = (ViewGroup) findViewById(
            com.saarang.samples.apps.iosched.R.id.session_speakers_block);

    // Remove all existing speakers (everything but first child, which is the header)
    for (int i = speakersGroup.getChildCount() - 1; i >= 1; i--) {
        speakersGroup.removeViewAt(i);
    }

    final LayoutInflater inflater = getLayoutInflater();

    boolean hasSpeakers = false;

    cursor.moveToPosition(-1); // move to just before first record
    while (cursor.moveToNext()) {
        final String speakerName = cursor.getString(SpeakersQuery.SPEAKER_NAME);
        if (TextUtils.isEmpty(speakerName)) {
            continue;
        }

        final String speakerImageUrl = cursor.getString(SpeakersQuery.SPEAKER_IMAGE_URL);
        final String speakerCompany = cursor.getString(SpeakersQuery.SPEAKER_COMPANY);
        final String speakerUrl = cursor.getString(SpeakersQuery.SPEAKER_URL);
        final String speakerAbstract = cursor.getString(SpeakersQuery.SPEAKER_ABSTRACT);

        String speakerHeader = speakerName;
        if (!TextUtils.isEmpty(speakerCompany)) {
            speakerHeader += ", " + speakerCompany;
        }

        final View speakerView = inflater.inflate(com.saarang.samples.apps.iosched.R.layout.speaker_detail,
                speakersGroup, false);
        final TextView speakerHeaderView = (TextView) speakerView
                .findViewById(com.saarang.samples.apps.iosched.R.id.speaker_header);
        final ImageView speakerImageView = (ImageView) speakerView
                .findViewById(com.saarang.samples.apps.iosched.R.id.speaker_image);
        final TextView speakerAbstractView = (TextView) speakerView
                .findViewById(com.saarang.samples.apps.iosched.R.id.speaker_abstract);

        if (!TextUtils.isEmpty(speakerImageUrl) && mSpeakersImageLoader != null) {
            mSpeakersImageLoader.loadImage(speakerImageUrl, speakerImageView);
        }

        speakerHeaderView.setText(speakerHeader);
        speakerImageView.setContentDescription(
                getString(com.saarang.samples.apps.iosched.R.string.speaker_googleplus_profile, speakerHeader));
        UIUtils.setTextMaybeHtml(speakerAbstractView, speakerAbstract);

        if (!TextUtils.isEmpty(speakerUrl)) {
            speakerImageView.setEnabled(true);
            speakerImageView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    String number = "tel:" + speakerUrl.trim();
                    Intent callIntent = new Intent(Intent.ACTION_CALL, Uri.parse(number));
                    startActivity(callIntent);
                    /*Intent speakerProfileIntent = new Intent(Intent.ACTION_VIEW,
                        Uri.parse(speakerUrl));
                    speakerProfileIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
                    UIUtils.preferPackageForIntent(SessionDetailActivity.this,
                        speakerProfileIntent,
                        UIUtils.GOOGLE_PLUS_PACKAGE_NAME);
                    startActivity(speakerProfileIntent);*/
                }
            });
        } else {
            speakerImageView.setEnabled(true);
            speakerImageView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    Toast.makeText(SessionDetailActivity.this,
                            "Sorry, No number found for this person. Call the other coordinator",
                            Toast.LENGTH_SHORT).show();

                    /*Intent speakerProfileIntent = new Intent(Intent.ACTION_VIEW,
                        Uri.parse(speakerUrl));
                    speakerProfileIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
                    UIUtils.preferPackageForIntent(SessionDetailActivity.this,
                        speakerProfileIntent,
                        UIUtils.GOOGLE_PLUS_PACKAGE_NAME);
                    startActivity(speakerProfileIntent);*/
                }
            });

        }

        speakersGroup.addView(speakerView);
        hasSpeakers = true;
        mHasSummaryContent = true;
    }

    speakersGroup.setVisibility(hasSpeakers ? View.VISIBLE : View.GONE);
    updateEmptyView();
}

From source file:ca.vijaysharma.resume.adapters.ProfileAdapter.java

@Override
public Object instantiateItem(ViewGroup collection, int position) {
    View view = null;//from   ww  w. j a v a 2 s . c  o  m
    if (position == 0) {
        final Section objective = TextSection.create("Objective", Lists.newArrayList(profile.getObjective()));
        final Section biography = TextSection.create("Bio", Lists.newArrayList(profile.getBiography()));
        final Section awards = TextSection.create("Awards", profile.getAwards());

        view = new ImageButtonBuilder(this.context)
                .setConnectorColor(ContextCompat.getColor(context, R.color.white))
                .setBackgroundDrawable(Drawables.doubleBorderDrawable(this.context,
                        ContextCompat.getColor(context, R.color.white)))
                .setAddConnection(false).setImage(profile.getAvatarUrl())
                .setListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        DetailParcel parcel = DetailParcel.builder().detail1(profile.getName())
                                .detail2(profile.getTitle()).detail3(profile.getLocation())
                                .hero(profile.getAvatarUrl()).back(R.drawable.ic_arrow_back_black_24dp)
                                .primaryColor(ContextCompat.getColor(context, R.color.white))
                                .secondaryColor(ContextCompat.getColor(context, R.color.black))
                                .tertiaryColor(ContextCompat.getColor(context, R.color.dark_grey))
                                .background(ContextCompat.getColor(context, R.color.white))
                                .action1(DetailAction.builder().action(R.drawable.ic_public_white_24dp)
                                        .intent(Intents.createUrlIntent(profile.getWebsite())).build())
                                .action2(DetailAction.builder().action(R.drawable.email_48)
                                        .intent(Intents.createEmailIntent(profile.getEmail())).build())
                                .sections(Lists.newArrayList(objective, biography, awards)).build();

                        bus.post(new ShowDetailsEvent(parcel, view));
                    }
                }).build();
    } else if (position == 1) {
        view = new ImageButtonBuilder(this.context)
                .setConnectorColor(ContextCompat.getColor(context, R.color.white))
                .setBackgroundDrawable(
                        Drawables.rippleDrawable(this.context, ContextCompat.getColor(context, R.color.white)))
                .setAddConnection(true)
                .setImage("https://cdn.rawgit.com/vijaysharm/resume-android/master/images/globe_256.png")
                .setListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        bus.post(IntentEvent.urlEvent(profile.getWebsite()));
                    }
                }).build();
    } else if (position == 2) {
        view = new ImageButtonBuilder(this.context)
                .setConnectorColor(ContextCompat.getColor(context, R.color.white))
                .setBackgroundDrawable(
                        Drawables.rippleDrawable(this.context, ContextCompat.getColor(context, R.color.white)))
                .setAddConnection(true)
                .setImage("https://cdn.rawgit.com/vijaysharm/resume-android/master/images/email_256.png")
                .setListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        bus.post(IntentEvent.emailEvent(profile.getEmail()));
                    }
                }).build();
    } else if (position == 3) {
        String version = String.format("%s (%d)", BuildConfig.VERSION_NAME, BuildConfig.VERSION_CODE);
        String build = String.format("%s (%s)", BuildConfig.GIT_SHA, BuildConfig.BUILD_TIME);
        final Section versionSection = TextSection.create("Version", Lists.newArrayList(version));
        final Section buildSection = TextSection.create("Build", Lists.newArrayList(build));
        final Section projects = ProjectSection.create("Libraries", ProjectSectionItem.items(projects()));

        view = new ImageButtonBuilder(this.context)
                .setConnectorColor(ContextCompat.getColor(context, R.color.white))
                .setBackgroundDrawable(
                        Drawables.rippleDrawable(this.context, ContextCompat.getColor(context, R.color.white)))
                .setAddConnection(true)
                .setImage("https://cdn.rawgit.com/vijaysharm/resume-android/master/images/settings_256.png")
                .setListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        DetailParcel parcel = DetailParcel.builder().detail1("Settings").detail2("").detail3("")
                                .hero("https://cdn.rawgit.com/vijaysharm/resume-android/master/images/settings_256.png")
                                .back(R.drawable.ic_arrow_back_black_24dp)
                                .primaryColor(ContextCompat.getColor(context, R.color.white))
                                .secondaryColor(ContextCompat.getColor(context, R.color.black))
                                .tertiaryColor(ContextCompat.getColor(context, R.color.dark_grey))
                                .background(ContextCompat.getColor(context, R.color.background_color))
                                .action1(DetailAction.builder().action(R.drawable.ic_public_white_24dp)
                                        .intent(Intents.createEmptyIntent()).build())
                                .action2(DetailAction.builder().action(R.drawable.ic_place_white_24dp)
                                        .intent(Intents.createEmptyIntent()).build())
                                .sections(Lists.newArrayList(versionSection, buildSection, projects)).build();

                        bus.post(new ShowDetailsEvent(parcel, view));
                    }
                }).build();
    }

    collection.addView(view);

    return view;
}

From source file:com.initialxy.cordova.themeablebrowser.ThemeableBrowser.java

/**
 * Display a new browser with the specified URL.
 *
 * @param url/*from w w w  .  j a v a  2s. c  om*/
 * @param features
 * @return
 */
public String showWebPage(final String url, final Options features) {
    final CordovaWebView thatWebView = this.webView;

    // Create dialog in new thread
    Runnable runnable = new Runnable() {
        @SuppressLint("NewApi")
        public void run() {
            // Let's create the main dialog
            dialog = new ThemeableBrowserDialog(cordova.getActivity(), android.R.style.Theme_Black_NoTitleBar,
                    features.hardwareback);
            if (!features.disableAnimation) {
                dialog.getWindow().getAttributes().windowAnimations = android.R.style.Animation_Dialog;
            }
            dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
            dialog.setCancelable(true);
            dialog.setThemeableBrowser(getThemeableBrowser());

            // Main container layout
            ViewGroup main = null;

            if (features.fullscreen) {
                main = new FrameLayout(cordova.getActivity());
            } else {
                main = new LinearLayout(cordova.getActivity());
                ((LinearLayout) main).setOrientation(LinearLayout.VERTICAL);
            }

            // Toolbar layout
            Toolbar toolbarDef = features.toolbar;
            FrameLayout toolbar = new FrameLayout(cordova.getActivity());
            toolbar.setBackgroundColor(hexStringToColor(
                    toolbarDef != null && toolbarDef.color != null ? toolbarDef.color : "#ffffffff"));
            toolbar.setLayoutParams(new ViewGroup.LayoutParams(LayoutParams.MATCH_PARENT,
                    dpToPixels(toolbarDef != null ? toolbarDef.height : TOOLBAR_DEF_HEIGHT)));

            if (toolbarDef != null && (toolbarDef.image != null || toolbarDef.wwwImage != null)) {
                try {
                    Drawable background = getImage(toolbarDef.image, toolbarDef.wwwImage,
                            toolbarDef.wwwImageDensity);
                    setBackground(toolbar, background);
                } catch (Resources.NotFoundException e) {
                    emitError(ERR_LOADFAIL,
                            String.format("Image for toolbar, %s, failed to load", toolbarDef.image));
                } catch (IOException ioe) {
                    emitError(ERR_LOADFAIL,
                            String.format("Image for toolbar, %s, failed to load", toolbarDef.wwwImage));
                }
            }

            // Left Button Container layout
            LinearLayout leftButtonContainer = new LinearLayout(cordova.getActivity());
            FrameLayout.LayoutParams leftButtonContainerParams = new FrameLayout.LayoutParams(
                    LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
            leftButtonContainerParams.gravity = Gravity.LEFT | Gravity.CENTER_VERTICAL;
            leftButtonContainer.setLayoutParams(leftButtonContainerParams);
            leftButtonContainer.setVerticalGravity(Gravity.CENTER_VERTICAL);

            // Right Button Container layout
            LinearLayout rightButtonContainer = new LinearLayout(cordova.getActivity());
            FrameLayout.LayoutParams rightButtonContainerParams = new FrameLayout.LayoutParams(
                    LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
            rightButtonContainerParams.gravity = Gravity.RIGHT | Gravity.CENTER_VERTICAL;
            rightButtonContainer.setLayoutParams(rightButtonContainerParams);
            rightButtonContainer.setVerticalGravity(Gravity.CENTER_VERTICAL);

            // Edit Text Box
            edittext = new EditText(cordova.getActivity());
            RelativeLayout.LayoutParams textLayoutParams = new RelativeLayout.LayoutParams(
                    LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
            textLayoutParams.addRule(RelativeLayout.RIGHT_OF, 1);
            textLayoutParams.addRule(RelativeLayout.LEFT_OF, 5);
            edittext.setLayoutParams(textLayoutParams);
            edittext.setSingleLine(true);
            edittext.setText(url);
            edittext.setInputType(InputType.TYPE_TEXT_VARIATION_URI);
            edittext.setImeOptions(EditorInfo.IME_ACTION_GO);
            edittext.setInputType(InputType.TYPE_NULL); // Will not except input... Makes the text NON-EDITABLE
            edittext.setOnKeyListener(new View.OnKeyListener() {
                public boolean onKey(View v, int keyCode, KeyEvent event) {
                    // If the event is a key-down event on the "enter" button
                    if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
                        navigate(edittext.getText().toString());
                        return true;
                    }
                    return false;
                }
            });

            // Back button
            final Button back = createButton(features.backButton, "back button", new View.OnClickListener() {
                public void onClick(View v) {
                    emitButtonEvent(features.backButton, inAppWebView.getUrl());

                    if (features.backButtonCanClose && !canGoBack()) {
                        closeDialog();
                    } else {
                        goBack();
                    }
                }
            });

            if (back != null) {
                back.setEnabled(features.backButtonCanClose);
            }

            // Forward button
            final Button forward = createButton(features.forwardButton, "forward button",
                    new View.OnClickListener() {
                        public void onClick(View v) {
                            emitButtonEvent(features.forwardButton, inAppWebView.getUrl());

                            goForward();
                        }
                    });

            if (forward != null) {
                forward.setEnabled(false);
            }

            // Close/Done button
            Button close = createButton(features.closeButton, "close button", new View.OnClickListener() {
                public void onClick(View v) {
                    emitButtonEvent(features.closeButton, inAppWebView.getUrl());
                    closeDialog();
                }
            });

            // Menu button
            Spinner menu = features.menu != null ? new MenuSpinner(cordova.getActivity()) : null;
            if (menu != null) {
                menu.setLayoutParams(
                        new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
                menu.setContentDescription("menu button");
                setButtonImages(menu, features.menu, DISABLED_ALPHA);

                // We are not allowed to use onClickListener for Spinner, so we will use
                // onTouchListener as a fallback.
                menu.setOnTouchListener(new View.OnTouchListener() {
                    @Override
                    public boolean onTouch(View v, MotionEvent event) {
                        if (event.getAction() == MotionEvent.ACTION_UP) {
                            emitButtonEvent(features.menu, inAppWebView.getUrl());
                        }
                        return false;
                    }
                });

                if (features.menu.items != null) {
                    HideSelectedAdapter<EventLabel> adapter = new HideSelectedAdapter<EventLabel>(
                            cordova.getActivity(), android.R.layout.simple_spinner_item, features.menu.items);
                    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
                    menu.setAdapter(adapter);
                    menu.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
                        @Override
                        public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
                            if (inAppWebView != null && i < features.menu.items.length) {
                                emitButtonEvent(features.menu.items[i], inAppWebView.getUrl(), i);
                            }
                        }

                        @Override
                        public void onNothingSelected(AdapterView<?> adapterView) {
                        }
                    });
                }
            }

            // Title
            final TextView title = features.title != null ? new TextView(cordova.getActivity()) : null;
            final TextView subtitle = features.title != null ? new TextView(cordova.getActivity()) : null;
            if (title != null) {
                FrameLayout.LayoutParams titleParams = new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT,
                        LayoutParams.FILL_PARENT);
                titleParams.gravity = Gravity.CENTER;
                title.setLayoutParams(titleParams);
                title.setSingleLine();
                title.setEllipsize(TextUtils.TruncateAt.END);
                title.setGravity(Gravity.CENTER | Gravity.TOP);
                title.setTextColor(
                        hexStringToColor(features.title.color != null ? features.title.color : "#000000ff"));
                title.setTypeface(title.getTypeface(), Typeface.BOLD);
                title.setTextSize(TypedValue.COMPLEX_UNIT_PT, 8);

                FrameLayout.LayoutParams subtitleParams = new FrameLayout.LayoutParams(
                        LayoutParams.MATCH_PARENT, LayoutParams.FILL_PARENT);
                titleParams.gravity = Gravity.CENTER;
                subtitle.setLayoutParams(subtitleParams);
                subtitle.setSingleLine();
                subtitle.setEllipsize(TextUtils.TruncateAt.END);
                subtitle.setGravity(Gravity.CENTER | Gravity.BOTTOM);
                subtitle.setTextColor(hexStringToColor(
                        features.title.subColor != null ? features.title.subColor : "#000000ff"));
                subtitle.setTextSize(TypedValue.COMPLEX_UNIT_PT, 6);
                subtitle.setVisibility(View.GONE);

                if (features.title.staticText != null) {
                    title.setGravity(Gravity.CENTER);
                    title.setText(features.title.staticText);
                } else {
                    subtitle.setVisibility(View.VISIBLE);
                }
            }

            // WebView
            inAppWebView = new WebView(cordova.getActivity());
            final ViewGroup.LayoutParams inAppWebViewParams = features.fullscreen
                    ? new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)
                    : new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, 0);
            if (!features.fullscreen) {
                ((LinearLayout.LayoutParams) inAppWebViewParams).weight = 1;
            }
            inAppWebView.setLayoutParams(inAppWebViewParams);
            inAppWebView.setWebChromeClient(new InAppChromeClient(thatWebView));
            WebViewClient client = new ThemeableBrowserClient(thatWebView, new PageLoadListener() {

                @Override
                public void onPageStarted(String url) {
                    if (inAppWebView != null && title != null && features.title != null
                            && features.title.staticText == null && features.title.showPageTitle
                            && features.title.loadingText != null) {
                        title.setText(features.title.loadingText);
                        subtitle.setText(url);
                    }
                }

                @Override
                public void onPageFinished(String url, boolean canGoBack, boolean canGoForward) {
                    if (inAppWebView != null && title != null && features.title != null
                            && features.title.staticText == null && features.title.showPageTitle) {
                        title.setText(inAppWebView.getTitle());
                        subtitle.setText(inAppWebView.getUrl());
                    }

                    if (back != null) {
                        back.setEnabled(canGoBack || features.backButtonCanClose);
                    }

                    if (forward != null) {
                        forward.setEnabled(canGoForward);
                    }
                }
            });
            inAppWebView.setWebViewClient(client);
            WebSettings settings = inAppWebView.getSettings();
            settings.setJavaScriptEnabled(true);
            settings.setJavaScriptCanOpenWindowsAutomatically(true);
            settings.setBuiltInZoomControls(features.zoom);
            settings.setDisplayZoomControls(false);
            settings.setPluginState(android.webkit.WebSettings.PluginState.ON);

            //Toggle whether this is enabled or not!
            Bundle appSettings = cordova.getActivity().getIntent().getExtras();
            boolean enableDatabase = appSettings == null
                    || appSettings.getBoolean("ThemeableBrowserStorageEnabled", true);
            if (enableDatabase) {
                String databasePath = cordova.getActivity().getApplicationContext()
                        .getDir("themeableBrowserDB", Context.MODE_PRIVATE).getPath();
                settings.setDatabasePath(databasePath);
                settings.setDatabaseEnabled(true);
            }
            settings.setDomStorageEnabled(true);

            if (features.clearcache) {
                CookieManager.getInstance().removeAllCookie();
            } else if (features.clearsessioncache) {
                CookieManager.getInstance().removeSessionCookie();
            }

            inAppWebView.loadUrl(url);
            inAppWebView.getSettings().setLoadWithOverviewMode(true);
            inAppWebView.getSettings().setUseWideViewPort(true);
            inAppWebView.requestFocus();
            inAppWebView.requestFocusFromTouch();

            // Add buttons to either leftButtonsContainer or
            // rightButtonsContainer according to user's alignment
            // configuration.
            int leftContainerWidth = 0;
            int rightContainerWidth = 0;

            if (features.customButtons != null) {
                for (int i = 0; i < features.customButtons.length; i++) {
                    final BrowserButton buttonProps = features.customButtons[i];
                    final int index = i;
                    Button button = createButton(buttonProps, String.format("custom button at %d", i),
                            new View.OnClickListener() {
                                @Override
                                public void onClick(View view) {
                                    if (inAppWebView != null) {
                                        emitButtonEvent(buttonProps, inAppWebView.getUrl(), index);
                                    }
                                }
                            });

                    if (ALIGN_RIGHT.equals(buttonProps.align)) {
                        rightButtonContainer.addView(button);
                        rightContainerWidth += button.getLayoutParams().width;
                    } else {
                        leftButtonContainer.addView(button, 0);
                        leftContainerWidth += button.getLayoutParams().width;
                    }
                }
            }

            // Back and forward buttons must be added with special ordering logic such
            // that back button is always on the left of forward button if both buttons
            // are on the same side.
            if (forward != null && features.forwardButton != null
                    && !ALIGN_RIGHT.equals(features.forwardButton.align)) {
                leftButtonContainer.addView(forward, 0);
                leftContainerWidth += forward.getLayoutParams().width;
            }

            if (back != null && features.backButton != null && ALIGN_RIGHT.equals(features.backButton.align)) {
                rightButtonContainer.addView(back);
                rightContainerWidth += back.getLayoutParams().width;
            }

            if (back != null && features.backButton != null && !ALIGN_RIGHT.equals(features.backButton.align)) {
                leftButtonContainer.addView(back, 0);
                leftContainerWidth += back.getLayoutParams().width;
            }

            if (forward != null && features.forwardButton != null
                    && ALIGN_RIGHT.equals(features.forwardButton.align)) {
                rightButtonContainer.addView(forward);
                rightContainerWidth += forward.getLayoutParams().width;
            }

            if (menu != null) {
                if (features.menu != null && ALIGN_RIGHT.equals(features.menu.align)) {
                    rightButtonContainer.addView(menu);
                    rightContainerWidth += menu.getLayoutParams().width;
                } else {
                    leftButtonContainer.addView(menu, 0);
                    leftContainerWidth += menu.getLayoutParams().width;
                }
            }

            if (close != null) {
                if (features.closeButton != null && ALIGN_RIGHT.equals(features.closeButton.align)) {
                    rightButtonContainer.addView(close);
                    rightContainerWidth += close.getLayoutParams().width;
                } else {
                    leftButtonContainer.addView(close, 0);
                    leftContainerWidth += close.getLayoutParams().width;
                }
            }

            // Add the views to our toolbar
            toolbar.addView(leftButtonContainer);
            // Don't show address bar.
            // toolbar.addView(edittext);
            toolbar.addView(rightButtonContainer);

            if (title != null) {
                int titleMargin = Math.max(leftContainerWidth, rightContainerWidth);

                FrameLayout.LayoutParams titleParams = (FrameLayout.LayoutParams) title.getLayoutParams();
                titleParams.setMargins(titleMargin, 8, titleMargin, 0);
                toolbar.addView(title);
            }

            if (subtitle != null) {
                int subtitleMargin = Math.max(leftContainerWidth, rightContainerWidth);

                FrameLayout.LayoutParams subtitleParams = (FrameLayout.LayoutParams) subtitle.getLayoutParams();
                subtitleParams.setMargins(subtitleMargin, 0, subtitleMargin, 8);
                toolbar.addView(subtitle);
            }

            if (features.fullscreen) {
                // If full screen mode, we have to add inAppWebView before adding toolbar.
                main.addView(inAppWebView);
            }

            // Don't add the toolbar if its been disabled
            if (features.location) {
                // Add our toolbar to our main view/layout
                main.addView(toolbar);
            }

            if (!features.fullscreen) {
                // If not full screen, we add inAppWebView after adding toolbar.
                main.addView(inAppWebView);
            }

            WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
            lp.copyFrom(dialog.getWindow().getAttributes());
            lp.width = WindowManager.LayoutParams.MATCH_PARENT;
            lp.height = WindowManager.LayoutParams.MATCH_PARENT;

            dialog.setContentView(main);
            dialog.show();
            dialog.getWindow().setAttributes(lp);
            // the goal of openhidden is to load the url and not display it
            // Show() needs to be called to cause the URL to be loaded
            if (features.hidden) {
                dialog.hide();
            }
        }
    };
    this.cordova.getActivity().runOnUiThread(runnable);
    return "";
}