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.ubiLive.GameCloud.activity.MainActivity.java

private GCViewPage initIntroPage(ViewGroup root) {
    SharedPreferences sharedpreferences = PreferenceManager.openPrference(this, Constants.PREFERENCE_DB);
    boolean enableIntro = !PreferenceManager.getBooleanValue(sharedpreferences, Constants.INTROSHOW);
    GCViewPage viewpager = null;//ww  w . j a v a  2s  .c o  m
    if (enableIntro) {
        MarkView mark = null;
        int[] introPictures;
        int[] introStartBtn;
        if (Utils.getLanguage() == Constants.UPUI_MSG_LANGUAGE_TRAN_CHINESE) {
            if ((float) Utils.getScreenWidth(this) / (float) Utils.getScreenHeight(this) > 1.5f) {
                introPictures = GCViewPage.INTRO_16_9_ZH_TW;
                introStartBtn = GCViewPage.INTRO_BTN_16_9_ZH_TW;
                DebugLog.d(TAG, "INTRO_16_9");
            } else {
                introPictures = GCViewPage.INTRO_ZH_TW;
                introStartBtn = GCViewPage.INTRO_BTN_ZH_TW;
                DebugLog.d(TAG, "INTRO");
            }
        } else {
            introPictures = GCViewPage.INTRO;
            introStartBtn = GCViewPage.INTRO_BTN;
            mark = new MarkView(this, introPictures);
        }
        DebugLog.d(TAG, "DetailsFragment introPictures = " + introPictures.length);
        viewpager = new GCViewPage(this, root, introPictures, introStartBtn);
        viewpager.setId(11111);
        viewpager.attachToWindow();
        if (mark != null) {
            viewpager.setOnPageChangeListener(mark);
            root.addView(mark);
        }
    }
    return viewpager;
}

From source file:de.jadehs.jadehsnavigator.adapter.NewsPagerAdapter.java

@Override
public Object instantiateItem(ViewGroup container, int position) {

    LayoutInflater layoutInflater = (LayoutInflater) this.context
            .getSystemService(context.LAYOUT_INFLATER_SERVICE);
    View view;/*ww  w  .ja  v a2s .c o m*/

    /* Sets up content of the current page according to the position */
    ArrayList<RSSItem> newsItems = new ArrayList<RSSItem>();
    if (getPageTitle(position).equals(context.getString(R.string.origin_1))) {
        for (RSSItem item : this.rssItems) {
            if (item.getOrigin().getTitle().equals(context.getString(R.string.origin_1))) {
                newsItems.add(item);
            }
        }
    } else if (getPageTitle(position).equals(context.getString(R.string.origin_2))) {
        for (RSSItem item : this.rssItems) {
            if (item.getOrigin().getTitle().equals(context.getString(R.string.origin_2))) {
                newsItems.add(item);
            }
        }
    } else if (getPageTitle(position).equals(context.getString(R.string.origin_3))) {
        for (RSSItem item : this.rssItems) {
            if (item.getOrigin().getTitle().equals(context.getString(R.string.origin_3))) {
                newsItems.add(item);
            }
        }
    } else if (getPageTitle(position).equals(context.getString(R.string.origin_4))) {
        for (RSSItem item : this.rssItems) {
            if (item.getOrigin().getTitle().equals(context.getString(R.string.origin_4))) {
                newsItems.add(item);
            }
        }
    } else if (getPageTitle(position).equals(context.getString(R.string.origin_5))) {
        for (RSSItem item : this.rssItems) {
            if (item.getOrigin().getTitle().equals(context.getString(R.string.origin_5))) {
                newsItems.add(item);
            }
        }
    }

    view = layoutInflater.inflate(R.layout.news_list, container, false);
    container.addView(view);

    /* Creates a ListView with the correct News Items */
    ListView lv = (ListView) view.findViewById(R.id.list_news);
    NewsAdapter newsAdapter = new NewsAdapter(this.context, newsItems);

    lv.setAdapter(newsAdapter);

    TextView lastUpdateVPlan = (TextView) view.findViewById(R.id.textViewFooter);

    lastUpdateVPlan.setText("Abgerufen am: " + calendarHelper.getDateRightNow(true));

    return view;
}

From source file:com.goliathonline.android.kegbot.ui.DrinkDetailFragment.java

private void onUsersQueryComplete(Cursor cursor) {
    try {//w ww.java  2  s . c om
        mSpeakersCursor = true;
        // TODO: remove any existing speakers from layout, since this cursor
        // might be from a data change notification.
        final ViewGroup speakersGroup = (ViewGroup) mRootView.findViewById(R.id.drink_user_block);
        final LayoutInflater inflater = getActivity().getLayoutInflater();

        boolean hasSpeakers = false;

        while (cursor.moveToNext()) {
            final String userName = cursor.getString(UserQuery.USER_ID);
            if (TextUtils.isEmpty(userName)) {
                continue;
            }

            final String speakerImageUrl = cursor.getString(UserQuery.USER_IMAGE_URL);

            String speakerHeader = userName;

            final View speakerView = inflater.inflate(R.layout.user_detail, speakersGroup, false);
            final TextView speakerHeaderView = (TextView) speakerView.findViewById(R.id.user_header);
            final ImageView speakerImgView = (ImageView) speakerView.findViewById(R.id.user_image);

            if (!TextUtils.isEmpty(speakerImageUrl)) {
                BitmapUtils.fetchImage(getActivity(), speakerImageUrl, null, null,
                        new BitmapUtils.OnFetchCompleteListener() {
                            public void onFetchComplete(Object cookie, Bitmap result) {
                                if (result != null) {
                                    speakerImgView.setImageBitmap(result);
                                }
                            }
                        });
            }

            speakerHeaderView.setText(speakerHeader);

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

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

        // Show empty message when all data is loaded, and nothing to show
        if (mSessionCursor && !mHasSummaryContent) {
            mRootView.findViewById(android.R.id.empty).setVisibility(View.VISIBLE);
        }
    } finally {
        if (null != cursor) {
            cursor.close();
        }
    }
}

From source file:com.digi.android.wva.fragments.ChartFragment.java

/**
 * Repaints the chart view onto the screen. This is done by
 * removing the chart view from the layout, calling repaint(),
 * and putting the view back into the layout.
  */*  w w w . jav a2  s.  co  m*/
  * <p>This method is protected, rather than private, due to a bug between JaCoCo and
  * the Android build tools which causes the instrumented bytecode to be invalid when this
  * method is private:
  * http://stackoverflow.com/questions/17603192/dalvik-transformation-using-wrong-invoke-opcode
  * </p>
 */
protected void redrawChart() {
    // super.getView() should return NoSaveStateFrameLayout, which
    // extends FrameLayout, which extends ViewGroup
    ViewGroup l = (ViewGroup) super.getView();
    if (mChart == null) {
        mChart = ChartFactory.getCombinedXYChartView(getActivity(), mDataset, mRenderer,
                new String[] { LineChart.TYPE, LineChart.TYPE });
        mChart.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                SeriesSelection sel = mChart.getCurrentSeriesAndPoint();

                if (sel == null)
                    return;

                String series = "SERIES";
                switch (sel.getSeriesIndex()) {
                case 0:
                    series = "Vehicle Speed";
                    break;
                case 1:
                    series = "Engine RPM";
                    break;
                }

                String time = ISODateTimeFormat.dateTimeNoMillis().print((long) sel.getXValue());

                Toast.makeText(getActivity(), series + " (" + time + "): " + sel.getValue(), Toast.LENGTH_SHORT)
                        .show();
            }
        });
    }
    if (l != null) {
        // Ensure that the chart is removed from all views.
        try {
            if (mChart.getParent() != null) {
                //noinspection ConstantConditions
                ((ViewGroup) mChart.getParent()).removeAllViews();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        l.removeAllViews();
        mChart.repaint();
        l.addView(mChart);
    } else {
        // If the getView() result is null, something's up, like
        // the activity has been backgrounded.
        Log.d(TAG, "redrawChart -- l is null");
    }
}

From source file:android.support.v7.app.AppCompatDelegateImplV7.java

private void ensureSubDecor() {
    if (!mSubDecorInstalled) {
        final LayoutInflater inflater = LayoutInflater.from(mContext);

        if (!mWindowNoTitle) {
            if (mIsFloating) {
                // If we're floating, inflate the dialog title decor
                mSubDecor = (ViewGroup) inflater.inflate(R.layout.abc_dialog_title_material, null);
            } else if (mHasActionBar) {
                /**/*from   w ww.j  av  a 2  s.c om*/
                 * This needs some explanation. As we can not use the android:theme attribute
                 * pre-L, we emulate it by manually creating a LayoutInflater using a
                 * ContextThemeWrapper pointing to actionBarTheme.
                 */
                TypedValue outValue = new TypedValue();
                mContext.getTheme().resolveAttribute(R.attr.actionBarTheme, outValue, true);

                Context themedContext;
                if (outValue.resourceId != 0) {
                    themedContext = new ContextThemeWrapper(mContext, outValue.resourceId);
                } else {
                    themedContext = mContext;
                }

                // Now inflate the view using the themed context and set it as the content view
                mSubDecor = (ViewGroup) LayoutInflater.from(themedContext).inflate(R.layout.abc_screen_toolbar,
                        null);

                mDecorContentParent = (DecorContentParent) mSubDecor.findViewById(R.id.decor_content_parent);
                mDecorContentParent.setWindowCallback(getWindowCallback());

                /**
                 * Propagate features to DecorContentParent
                 */
                if (mOverlayActionBar) {
                    mDecorContentParent.initFeature(FEATURE_ACTION_BAR_OVERLAY);
                }
                if (mFeatureProgress) {
                    mDecorContentParent.initFeature(Window.FEATURE_PROGRESS);
                }
                if (mFeatureIndeterminateProgress) {
                    mDecorContentParent.initFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
                }
            }
        } else {
            if (mOverlayActionMode) {
                mSubDecor = (ViewGroup) inflater.inflate(R.layout.abc_screen_simple_overlay_action_mode, null);
            } else {
                mSubDecor = (ViewGroup) inflater.inflate(R.layout.abc_screen_simple, null);
            }

            if (Build.VERSION.SDK_INT >= 21) {
                // If we're running on L or above, we can rely on ViewCompat's
                // setOnApplyWindowInsetsListener
                ViewCompat.setOnApplyWindowInsetsListener(mSubDecor, new OnApplyWindowInsetsListener() {
                    @Override
                    public WindowInsetsCompat onApplyWindowInsets(View v, WindowInsetsCompat insets) {
                        final int top = insets.getSystemWindowInsetTop();
                        final int newTop = updateStatusGuard(top);

                        if (top != newTop) {
                            insets = insets.replaceSystemWindowInsets(insets.getSystemWindowInsetLeft(), newTop,
                                    insets.getSystemWindowInsetRight(), insets.getSystemWindowInsetBottom());
                        }

                        // Now apply the insets on our view
                        return ViewCompat.onApplyWindowInsets(v, insets);
                    }
                });
            } else {
                // Else, we need to use our own FitWindowsViewGroup handling
                ((FitWindowsViewGroup) mSubDecor)
                        .setOnFitSystemWindowsListener(new FitWindowsViewGroup.OnFitSystemWindowsListener() {
                            @Override
                            public void onFitSystemWindows(Rect insets) {
                                insets.top = updateStatusGuard(insets.top);
                            }
                        });
            }
        }

        if (mSubDecor == null) {
            throw new IllegalArgumentException("AppCompat does not support the current theme features");
        }

        if (mDecorContentParent == null) {
            mTitleView = (TextView) mSubDecor.findViewById(R.id.title);
        }

        // Make the decor optionally fit system windows, like the window's decor
        ViewUtils.makeOptionalFitsSystemWindows(mSubDecor);

        final ViewGroup decorContent = (ViewGroup) mWindow.findViewById(android.R.id.content);
        final ViewGroup abcContent = (ViewGroup) mSubDecor.findViewById(R.id.action_bar_activity_content);

        // There might be Views already added to the Window's content view so we need to
        // migrate them to our content view
        while (decorContent.getChildCount() > 0) {
            final View child = decorContent.getChildAt(0);
            decorContent.removeViewAt(0);
            abcContent.addView(child);
        }

        // Now set the Window's content view with the decor
        mWindow.setContentView(mSubDecor);

        // Change our content FrameLayout to use the android.R.id.content id.
        // Useful for fragments.
        decorContent.setId(View.NO_ID);
        abcContent.setId(android.R.id.content);

        // The decorContent may have a foreground drawable set (windowContentOverlay).
        // Remove this as we handle it ourselves
        if (decorContent instanceof FrameLayout) {
            ((FrameLayout) decorContent).setForeground(null);
        }

        // If a title was set before we installed the decor, propogate it now
        CharSequence title = getTitle();
        if (!TextUtils.isEmpty(title)) {
            onTitleChanged(title);
        }

        applyFixedSizeWindow();

        onSubDecorInstalled(mSubDecor);

        mSubDecorInstalled = true;

        // Invalidate if the panel menu hasn't been created before this.
        // Panel menu invalidation is deferred avoiding application onCreateOptionsMenu
        // being called in the middle of onCreate or similar.
        // A pending invalidation will typically be resolved before the posted message
        // would run normally in order to satisfy instance state restoration.
        PanelFeatureState st = getPanelState(FEATURE_OPTIONS_PANEL, false);
        if (!isDestroyed() && (st == null || st.menu == null)) {
            invalidatePanelMenu(FEATURE_ACTION_BAR);
        }
    }
}

From source file:com.mooshim.mooshimeter.main.ScanActivity.java

private void refreshMeterTile(final MooshimeterDevice d, final ViewGroup wrapper) {
    if (wrapper.getChildCount() == 0) {
        Log.e(TAG, "Received empty wrapper");
    }/*from  w w w  .  j a  va  2  s.  c  o  m*/
    if (wrapper.getChildCount() > 0) {
        // Update the title bar
        int rssi = d.mRssi;
        String name;
        String build;
        if (d.mOADMode) {
            name = "Bootloader";
        } else {
            name = d.getBLEDevice().getName();
            if (name == null) {
                name = "Unknown device";
            }
        }

        if (d.mBuildTime == 0) {
            build = "Invalid firmware";
        } else {
            build = "Build: " + d.mBuildTime;
        }

        String descr = name + "\n" + build + "\nRssi: " + rssi + " dBm";
        ((TextView) wrapper.findViewById(R.id.descr)).setText(descr);

        final Button bv = (Button) wrapper.findViewById(R.id.btnConnect);

        int bgid = d.mConnectionState == BluetoothProfile.STATE_CONNECTED ? R.drawable.connected
                : R.drawable.disconnected;
        bv.setBackground(getResources().getDrawable(bgid));

        // Set the click listeners
        bv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                toggleConnectionState(bv, d);
            }
        });
    }
    if (d.mInitialized && !d.isInOADMode()) {
        // We are representing a connected meter
        if (wrapper.getChildCount() != 2) {
            // We need to create a new value pane
            wrapper.addView(mInflater.inflate(R.layout.element_mm_readingsbar, mDeviceScrollView, false));
        }
        Util.dispatch(new Runnable() {
            @Override
            public void run() {
                if (!d.isNotificationEnabled(d.getChar(MooshimeterDevice.mUUID.METER_SAMPLE))) {
                    // We need to enable notifications
                    d.playSampleStream(new Runnable() {
                        @Override
                        public void run() {
                            TextView ch1 = (TextView) wrapper.findViewById(R.id.ch1_value_label);
                            TextView ch2 = (TextView) wrapper.findViewById(R.id.ch2_value_label);
                            TextView ch1_unit = (TextView) wrapper.findViewById(R.id.ch1_unit_label);
                            TextView ch2_unit = (TextView) wrapper.findViewById(R.id.ch2_unit_label);
                            valueLabelRefresh(0, d, ch1, ch1_unit);
                            valueLabelRefresh(1, d, ch2, ch2_unit);
                        }
                    });
                }
            }
        });
    } else {
        //We are representing a disconnected meter or a meter in OAD mode
        if (wrapper.getChildCount() == 2) {
            // We need to eliminate a pane
            wrapper.removeViewAt(1);
        }
    }
}

From source file:nya.miku.wishmaster.http.cloudflare.CloudflareChecker.java

private Cookie checkAntiDDOS(final CloudflareException exception, final HttpHost proxy, CancellableTask task,
        final Activity activity) {
    synchronized (lock) {
        if (processing)
            return null;
        processing = true;/* w ww  . j  a v  a2  s . c om*/
    }
    processing2 = true;
    currentCookie = null;

    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        CookieSyncManager.createInstance(activity);
        CookieManager.getInstance().removeAllCookie();
    } else {
        CompatibilityImpl.clearCookies(CookieManager.getInstance());
    }

    final ViewGroup layout = (ViewGroup) activity.getWindow().getDecorView().getRootView();
    final WebViewClient client = new WebViewClient() {
        @Override
        public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
            handler.proceed();
        }

        @Override
        public void onPageFinished(WebView webView, String url) {
            super.onPageFinished(webView, url);
            Logger.d(TAG, "Got Page: " + url);
            String value = null;
            try {
                String[] cookies = CookieManager.getInstance().getCookie(url).split("[;]");
                for (String cookie : cookies) {
                    if ((cookie != null) && (!cookie.trim().equals(""))
                            && (cookie.startsWith(" " + exception.getRequiredCookieName() + "="))) {
                        value = cookie.substring(exception.getRequiredCookieName().length() + 2);
                    }
                }
            } catch (NullPointerException e) {
                Logger.e(TAG, e);
            }
            if (value != null) {
                BasicClientCookieHC4 cf_cookie = new BasicClientCookieHC4(exception.getRequiredCookieName(),
                        value);
                cf_cookie.setDomain("." + Uri.parse(url).getHost());
                cf_cookie.setPath("/");
                currentCookie = cf_cookie;
                Logger.d(TAG, "Cookie found: " + value);
                processing2 = false;
            } else {
                Logger.d(TAG, "Cookie is not found");
            }
        }
    };

    activity.runOnUiThread(new Runnable() {
        @SuppressLint("SetJavaScriptEnabled")
        @Override
        public void run() {
            webView = new WebView(activity);
            webView.setVisibility(View.GONE);
            layout.addView(webView);
            webView.setWebViewClient(client);
            webView.getSettings().setUserAgentString(HttpConstants.USER_AGENT_STRING);
            webView.getSettings().setJavaScriptEnabled(true);
            webViewContext = webView.getContext();
            if (proxy != null)
                WebViewProxy.setProxy(webViewContext, proxy.getHostName(), proxy.getPort());
            webView.loadUrl(exception.getCheckUrl());
        }
    });

    long startTime = System.currentTimeMillis();
    while (processing2) {
        long time = System.currentTimeMillis() - startTime;
        if ((task != null && task.isCancelled()) || time > TIMEOUT) {
            processing2 = false;
        }
    }

    activity.runOnUiThread(new Runnable() {
        @Override
        public void run() {
            try {
                layout.removeView(webView);
                webView.stopLoading();
                webView.clearCache(true);
                webView.destroy();
                webView = null;
            } finally {
                if (proxy != null)
                    WebViewProxy.setProxy(webViewContext, null, 0);
                processing = false;
            }
        }
    });

    return currentCookie;
}

From source file:foam.jellyfish.StarwispBuilder.java

public void Build(final StarwispActivity ctx, final String ctxname, JSONArray arr, ViewGroup parent) {

    try {//from w  w  w . j a  va2  s . c  om
        String type = arr.getString(0);

        //Log.i("starwisp","building started "+type);

        if (type.equals("build-fragment")) {
            String name = arr.getString(1);
            int ID = arr.getInt(2);
            Fragment fragment = ActivityManager.GetFragment(name);
            LinearLayout inner = new LinearLayout(ctx);
            inner.setLayoutParams(BuildLayoutParams(arr.getJSONArray(3)));
            inner.setId(ID);
            FragmentTransaction fragmentTransaction = ctx.getSupportFragmentManager().beginTransaction();
            fragmentTransaction.add(ID, fragment);
            fragmentTransaction.commit();
            parent.addView(inner);
            return;
        }

        if (type.equals("linear-layout")) {
            LinearLayout v = new LinearLayout(ctx);
            v.setId(arr.getInt(1));
            v.setOrientation(BuildOrientation(arr.getString(2)));
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(3)));
            //v.setPadding(2,2,2,2);
            JSONArray col = arr.getJSONArray(4);
            v.setBackgroundColor(Color.argb(col.getInt(3), col.getInt(0), col.getInt(1), col.getInt(2)));
            parent.addView(v);
            JSONArray children = arr.getJSONArray(5);
            for (int i = 0; i < children.length(); i++) {
                Build(ctx, ctxname, new JSONArray(children.getString(i)), v);
            }
            return;
        }

        if (type.equals("frame-layout")) {
            FrameLayout v = new FrameLayout(ctx);
            v.setId(arr.getInt(1));
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(2)));
            parent.addView(v);
            JSONArray children = arr.getJSONArray(3);
            for (int i = 0; i < children.length(); i++) {
                Build(ctx, ctxname, new JSONArray(children.getString(i)), v);
            }
            return;
        }

        /*
        if (type.equals("grid-layout")) {
        GridLayout v = new GridLayout(ctx);
        v.setId(arr.getInt(1));
        v.setRowCount(arr.getInt(2));
        //v.setColumnCount(arr.getInt(2));
        v.setOrientation(BuildOrientation(arr.getString(3)));
        v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(4)));
                
        parent.addView(v);
        JSONArray children = arr.getJSONArray(5);
        for (int i=0; i<children.length(); i++) {
            Build(ctx,ctxname,new JSONArray(children.getString(i)), v);
        }
                
        return;
        }
        */

        if (type.equals("scroll-view")) {
            HorizontalScrollView v = new HorizontalScrollView(ctx);
            v.setId(arr.getInt(1));
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(2)));
            parent.addView(v);
            JSONArray children = arr.getJSONArray(3);
            for (int i = 0; i < children.length(); i++) {
                Build(ctx, ctxname, new JSONArray(children.getString(i)), v);
            }
            return;
        }

        if (type.equals("scroll-view-vert")) {
            ScrollView v = new ScrollView(ctx);
            v.setId(arr.getInt(1));
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(2)));
            parent.addView(v);
            JSONArray children = arr.getJSONArray(3);
            for (int i = 0; i < children.length(); i++) {
                Build(ctx, ctxname, new JSONArray(children.getString(i)), v);
            }
            return;
        }

        if (type.equals("view-pager")) {
            ViewPager v = new ViewPager(ctx);
            v.setId(arr.getInt(1));
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(2)));
            v.setOffscreenPageLimit(3);
            final JSONArray items = arr.getJSONArray(3);

            v.setAdapter(new FragmentPagerAdapter(ctx.getSupportFragmentManager()) {

                @Override
                public int getCount() {
                    return items.length();
                }

                @Override
                public Fragment getItem(int position) {
                    try {
                        String fragname = items.getString(position);
                        return ActivityManager.GetFragment(fragname);
                    } catch (JSONException e) {
                        Log.e("starwisp", "Error parsing data " + e.toString());
                    }
                    return null;
                }
            });
            parent.addView(v);
            return;
        }

        if (type.equals("space")) {
            // Space v = new Space(ctx); (class not found runtime error??)
            TextView v = new TextView(ctx);
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(2)));
            parent.addView(v);
        }

        if (type.equals("image-view")) {
            ImageView v = new ImageView(ctx);
            v.setId(arr.getInt(1));
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(3)));

            String image = arr.getString(2);

            if (image.startsWith("/")) {
                Bitmap bitmap = BitmapFactory.decodeFile(image);
                v.setImageBitmap(bitmap);
            } else {
                int id = ctx.getResources().getIdentifier(image, "drawable", ctx.getPackageName());
                v.setImageResource(id);
            }

            parent.addView(v);
        }

        if (type.equals("text-view")) {
            TextView v = new TextView(ctx);
            v.setId(arr.getInt(1));
            v.setText(Html.fromHtml(arr.getString(2)));
            v.setTextSize(arr.getInt(3));
            v.setMovementMethod(LinkMovementMethod.getInstance());
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(4)));
            if (arr.length() > 5) {
                if (arr.getString(5).equals("left")) {
                    v.setGravity(Gravity.LEFT);
                } else {
                    if (arr.getString(5).equals("fill")) {
                        v.setGravity(Gravity.FILL);
                    } else {
                        v.setGravity(Gravity.CENTER);
                    }
                }
            } else {
                v.setGravity(Gravity.LEFT);
            }
            v.setTypeface(((StarwispActivity) ctx).m_Typeface);
            parent.addView(v);
        }

        if (type.equals("debug-text-view")) {
            TextView v = (TextView) ctx.getLayoutInflater().inflate(R.layout.debug_text, null);
            //                v.setBackgroundResource(R.color.black);
            v.setId(arr.getInt(1));
            //                v.setText(Html.fromHtml(arr.getString(2)));
            //                v.setTextColor(R.color.white);
            //                v.setTextSize(arr.getInt(3));
            //                v.setMovementMethod(LinkMovementMethod.getInstance());
            //                v.setMaxLines(10);
            //                v.setVerticalScrollBarEnabled(true);
            //                v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(4)));
            //v.setMovementMethod(new ScrollingMovementMethod());

            /*
            if (arr.length()>5) {
            if (arr.getString(5).equals("left")) {
                v.setGravity(Gravity.LEFT);
            } else {
                if (arr.getString(5).equals("fill")) {
                    v.setGravity(Gravity.FILL);
                } else {
                    v.setGravity(Gravity.CENTER);
                }
            }
            } else {
            v.setGravity(Gravity.LEFT);
            }
            v.setTypeface(((StarwispActivity)ctx).m_Typeface);*/
            parent.addView(v);
        }

        if (type.equals("web-view")) {
            WebView v = new WebView(ctx);
            v.setId(arr.getInt(1));
            v.setVerticalScrollBarEnabled(false);
            v.loadData(arr.getString(2), "text/html", "utf-8");
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(3)));
            parent.addView(v);
        }

        if (type.equals("edit-text")) {
            final EditText v = new EditText(ctx);
            v.setId(arr.getInt(1));
            v.setText(arr.getString(2));
            v.setTextSize(arr.getInt(3));

            String inputtype = arr.getString(4);
            if (inputtype.equals("text")) {
                //v.setInputType(InputType.TYPE_CLASS_TEXT);
            } else if (inputtype.equals("numeric")) {
                v.setInputType(InputType.TYPE_NUMBER_FLAG_DECIMAL | InputType.TYPE_NUMBER_FLAG_DECIMAL);
            } else if (inputtype.equals("email")) {
                v.setInputType(InputType.TYPE_TEXT_VARIATION_WEB_EMAIL_ADDRESS);
            }

            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(5)));
            v.setTypeface(((StarwispActivity) ctx).m_Typeface);
            final String fn = arr.getString(5);
            v.setSingleLine(true);

            v.addTextChangedListener(new TextWatcher() {
                public void afterTextChanged(Editable s) {
                    CallbackArgs(ctx, ctxname, v.getId(), "\"" + s.toString() + "\"");
                }

                public void beforeTextChanged(CharSequence s, int start, int count, int after) {
                }

                public void onTextChanged(CharSequence s, int start, int before, int count) {
                }
            });

            parent.addView(v);
        }

        if (type.equals("button")) {
            Button v = new Button(ctx);
            v.setId(arr.getInt(1));
            v.setText(arr.getString(2));
            v.setTextSize(arr.getInt(3));
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(4)));
            v.setTypeface(((StarwispActivity) ctx).m_Typeface);
            final String fn = arr.getString(5);
            v.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    Callback(ctx, ctxname, v.getId());
                }
            });
            parent.addView(v);
        }

        if (type.equals("toggle-button")) {
            ToggleButton v = new ToggleButton(ctx);
            v.setId(arr.getInt(1));
            v.setText(arr.getString(2));
            v.setTextSize(arr.getInt(3));
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(4)));
            v.setTypeface(((StarwispActivity) ctx).m_Typeface);
            final String fn = arr.getString(5);
            v.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    String arg = "#f";
                    if (((ToggleButton) v).isChecked())
                        arg = "#t";
                    CallbackArgs(ctx, ctxname, v.getId(), arg);
                }
            });
            parent.addView(v);
        }

        if (type.equals("seek-bar")) {
            SeekBar v = new SeekBar(ctx);
            v.setId(arr.getInt(1));
            v.setMax(arr.getInt(2));
            v.setProgress(arr.getInt(2) / 2);
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(3)));
            final String fn = arr.getString(4);

            v.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
                public void onProgressChanged(SeekBar v, int a, boolean s) {
                    CallbackArgs(ctx, ctxname, v.getId(), Integer.toString(a));
                }

                public void onStartTrackingTouch(SeekBar v) {
                }

                public void onStopTrackingTouch(SeekBar v) {
                }
            });
            parent.addView(v);
        }

        if (type.equals("spinner")) {
            Spinner v = new Spinner(ctx);
            final int wid = arr.getInt(1);
            v.setId(wid);
            final JSONArray items = arr.getJSONArray(2);
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(3)));
            ArrayList<String> spinnerArray = new ArrayList<String>();

            for (int i = 0; i < items.length(); i++) {
                spinnerArray.add(items.getString(i));
            }

            ArrayAdapter spinnerArrayAdapter = new ArrayAdapter<String>(ctx,
                    android.R.layout.simple_spinner_item, spinnerArray) {
                public View getView(int position, View convertView, ViewGroup parent) {
                    View v = super.getView(position, convertView, parent);
                    ((TextView) v).setTypeface(((StarwispActivity) ctx).m_Typeface);
                    return v;
                }
            };

            v.setAdapter(spinnerArrayAdapter);
            v.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
                public void onItemSelected(AdapterView<?> a, View v, int pos, long id) {
                    try {
                        CallbackArgs(ctx, ctxname, wid, "\"" + items.getString(pos) + "\"");
                    } catch (JSONException e) {
                        Log.e("starwisp", "Error parsing data " + e.toString());
                    }
                }

                public void onNothingSelected(AdapterView<?> v) {
                }
            });

            parent.addView(v);
        }

        if (type.equals("nomadic")) {
            final int wid = arr.getInt(1);
            NomadicSurfaceView v = new NomadicSurfaceView(ctx, wid);
            v.setId(wid);
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(2)));

            parent.addView(v);
        }

        /*
                    if (type.equals("canvas")) {
        StarwispCanvas v = new StarwispCanvas(ctx);
        final int wid = arr.getInt(1);
        v.setId(wid);
        v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(2)));
        v.SetDrawList(arr.getJSONArray(3));
        parent.addView(v);
                    }
                
                    if (type.equals("camera-preview")) {
        PictureTaker pt = new PictureTaker();
        CameraPreview v = new CameraPreview(ctx,pt);
        final int wid = arr.getInt(1);
        v.setId(wid);
                
                
        //              LinearLayout.LayoutParams lp =
        //  new LinearLayout.LayoutParams(minWidth, minHeight, 1);
                
        v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(2)));
                
        //                v.setLayoutParams(lp);
        parent.addView(v);
                    }
        */
        if (type.equals("button-grid")) {
            LinearLayout horiz = new LinearLayout(ctx);
            final int id = arr.getInt(1);
            final String buttontype = arr.getString(2);
            horiz.setId(id);
            horiz.setOrientation(LinearLayout.HORIZONTAL);
            parent.addView(horiz);
            int height = arr.getInt(3);
            int textsize = arr.getInt(4);
            LinearLayout.LayoutParams lp = BuildLayoutParams(arr.getJSONArray(5));
            JSONArray buttons = arr.getJSONArray(6);
            int count = buttons.length();
            int vertcount = 0;
            LinearLayout vert = null;

            for (int i = 0; i < count; i++) {
                JSONArray button = buttons.getJSONArray(i);

                if (vertcount == 0) {
                    vert = new LinearLayout(ctx);
                    vert.setId(0);
                    vert.setOrientation(LinearLayout.VERTICAL);
                    horiz.addView(vert);
                }
                vertcount = (vertcount + 1) % height;

                if (buttontype.equals("button")) {
                    Button b = new Button(ctx);
                    b.setId(button.getInt(0));
                    b.setText(button.getString(1));
                    b.setTextSize(textsize);
                    b.setLayoutParams(lp);
                    b.setTypeface(((StarwispActivity) ctx).m_Typeface);
                    final String fn = arr.getString(6);
                    b.setOnClickListener(new View.OnClickListener() {
                        public void onClick(View v) {
                            CallbackArgs(ctx, ctxname, id, "" + v.getId() + " #t");
                        }
                    });
                    vert.addView(b);
                } else if (buttontype.equals("toggle")) {
                    ToggleButton b = new ToggleButton(ctx);
                    b.setId(button.getInt(0));
                    b.setText(button.getString(1));
                    b.setTextSize(textsize);
                    b.setLayoutParams(lp);
                    b.setTypeface(((StarwispActivity) ctx).m_Typeface);
                    final String fn = arr.getString(6);
                    b.setOnClickListener(new View.OnClickListener() {
                        public void onClick(View v) {
                            String arg = "#f";
                            if (((ToggleButton) v).isChecked())
                                arg = "#t";
                            CallbackArgs(ctx, ctxname, id, "" + v.getId() + " " + arg);
                        }
                    });
                    vert.addView(b);
                }
            }
        }

    } catch (JSONException e) {
        Log.e("starwisp", "Error parsing [" + arr.toString() + "] " + e.toString());
    }

    //Log.i("starwisp","building ended");

}

From source file:$.GooglePlayServicesExtension.java

public void GoogleMobileAds_AddBannerAt(String _bannerId, double _sizeType, double _x, double _y) {
        final String bannerId = _bannerId;
        BannerXPos = (int) _x;
        BannerYPos = (int) _y;
        int type = (int) (_sizeType + 0.5);

        switch (type) {
        case 1:// w  ww.jav  a 2 s .com
            BannerSize = AdSize.BANNER;
            break;
        case 2:
            BannerSize = AdSize.MEDIUM_RECTANGLE;
            break;
        case 3:
            BannerSize = AdSize.FULL_BANNER;
            break;
        case 4:
            BannerSize = AdSize.LEADERBOARD;
            break;
        case 5:
            BannerSize = AdSize.WIDE_SKYSCRAPER;
            break;
        default:
            Log.i("yoyo", "AddBanner illegal banner size type:" + _sizeType);
            return;
        }

        RunnerActivity.ViewHandler.post(new Runnable() {
            public void run() {
                AbsoluteLayout layout = (AbsoluteLayout) RunnerActivity.CurrentActivity.findViewById(R.id.ad);
                ViewGroup vg = (ViewGroup) layout;

                //remove existing banner
                if (adView != null) {
                    if (vg != null) {
                        vg.removeView(adView);
                    }
                    adView.destroy();
                    adView = null;
                }

                //create new banner
                adView = new AdView(RunnerActivity.CurrentActivity);
                //adView.setAdListener(GoogleMobileAdsExt.this);
                adView.setAdListener(new AdListener() {
                    /** Called when an ad is loaded. */
                    @Override
                    public void onAdLoaded() {
                        Log.i("yoyo", "Banner Ad onAdLoaded");
                        sendBannerLoadedEvent(true);
                    }

                    @Override
                    public void onAdFailedToLoad(int errorCode) {
                        Log.i("yoyo", "Banner Ad onAdFailedToLoad");
                        sendBannerLoadedEvent(false);
                    }

                });

                SetLayerType();

                //adView.setAdSize(AdSize.BANNER);   
                adView.setAdSize(BannerSize);
                adView.setAdUnitId(bannerId);

                if (vg != null) {
                    vg.addView((View) adView);

                    AdRequest.Builder builder = new AdRequest.Builder();
                    builder.addTestDevice(AdRequest.DEVICE_ID_EMULATOR);
                    if (bUseTestAds)
                        builder.addTestDevice(TestDeviceId);
                    AdRequest adRequest = builder.build();

                    // Start loading the ad in the background.
                    adView.setVisibility(View.INVISIBLE);
                    adView.loadAd(adRequest);
                }
            }
        });
    }

From source file:ca.zadrox.dota2esportticker.ui.MatchDetailActivity.java

private void updateContentFromGG(Match data) {

    if (data == null) {
        Toast.makeText(this, "Network Connection issues", Toast.LENGTH_SHORT).show();
        return;/*from   w w  w . j ava2 s .c  o  m*/
    }

    if (Long.parseLong(dateTime) < TimeUtils.getUTCTime()) {
        mMatchScoreView.setText(data.teamOne.score + " : " + data.teamTwo.score);
    } else {
        mMatchScoreView.setText(" vs ");
    }

    if (data.livestreams != null && data.livestreams.length != 0) {
        final ViewGroup livestreamsCard = (ViewGroup) getLayoutInflater().inflate(R.layout.card_livestream,
                mDetailsContainer, false);
        final ViewGroup livestreamsBlock = (ViewGroup) livestreamsCard
                .findViewById(R.id.card_livestreams_block);
        for (int i = 0; i < data.livestreams.length; i++) {
            if (data.livestreams[i].url == null) {
                continue;
            }
            final View livestreamItem = getLayoutInflater().inflate(R.layout.livestream_detail,
                    livestreamsBlock, false);
            final TextView livestreamNameView = (TextView) livestreamItem
                    .findViewById(R.id.livestream_name_view);
            final TextView livestreamServiceView = (TextView) livestreamItem
                    .findViewById(R.id.livestream_service_view);

            final Uri livestreamUri = Uri.parse(data.livestreams[i].url);

            livestreamNameView
                    .setText(data.livestreams[i].language.toUpperCase() + " - " + data.livestreams[i].title);
            livestreamServiceView
                    .setText(data.livestreams[i].url.contains("twitch.tv") ? "Twitch.tv" : "DailyMotion");

            livestreamItem.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent viewLivestreamIntent = new Intent(Intent.ACTION_VIEW, livestreamUri);
                    startActivity(viewLivestreamIntent);
                }
            });

            livestreamsBlock.addView(livestreamItem);

            final View divider = getLayoutInflater().inflate(R.layout.divider, livestreamsBlock, false);
            livestreamsBlock.addView(divider);
        }

        mDetailsContainer.addView(livestreamsCard, 1);

    }

    if (data.vods != null && data.vods.length != 0) {
        final ViewGroup vodsCard = (ViewGroup) getLayoutInflater().inflate(R.layout.card_vods,
                mDetailsContainer, false);
        final ViewGroup vodsBlock = (ViewGroup) vodsCard.findViewById(R.id.card_vods_block);
        for (int i = 0; i < data.vods.length; i++) {
            final TextView vodsItem = (TextView) getLayoutInflater().inflate(R.layout.vod_detail, vodsBlock,
                    false);

            vodsItem.setText(data.vods[i].vodDesc);

            final Uri vodUri = Uri.parse(data.vods[i].vodUrl);

            vodsItem.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent viewVodIntent = new Intent(Intent.ACTION_VIEW, vodUri);
                    startActivity(viewVodIntent);
                }
            });

            vodsBlock.addView(vodsItem);

            final View divider = getLayoutInflater().inflate(R.layout.divider, vodsBlock, false);
            vodsBlock.addView(divider);
        }

        mDetailsContainer.addView(vodsCard, 2);

    }

    data.teamOne.flagUrl = teamLeftFlagUrl;
    data.teamTwo.flagUrl = teamRightFlagUrl;
    data.teamOne.name = teamLeftName;
    data.teamTwo.name = teamRightName;

    mTeamCardOne = makeTeamView(data.teamOne, mDetailsContainer);
    mTeamCardTwo = makeTeamView(data.teamTwo, mDetailsContainer);

    mDetailsContainer.addView(mTeamCardOne);
    mDetailsContainer.addView(mTeamCardTwo);

    mMatchTeamOneImageView.setClickable(true);
    mMatchTeamTwoImageView.setClickable(true);

    mMatchTeamOneImageView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mScrollView.smoothScrollTo(0,
                    Math.round(mTeamCardOne.getY() + mTeamCardOne.getHeight() - mHeaderHeightPixels));
        }
    });

    mMatchTeamTwoImageView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mScrollView.smoothScrollTo(0,
                    Math.round(mTeamCardTwo.getY() + mTeamCardTwo.getHeight() - mHeaderHeightPixels));
        }
    });

    final ViewGroup extrasCard = (ViewGroup) getLayoutInflater().inflate(R.layout.card_links, mDetailsContainer,
            false);

    final ViewGroup extrasBlock = (ViewGroup) extrasCard.findViewById(R.id.card_links_block);

    final TextView extrasItem = (TextView) getLayoutInflater().inflate(R.layout.link_item, extrasBlock, false);

    extrasItem.setText("GosuGamers Match Page");

    extrasItem.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent viewGGNetMatchPage = new Intent(Intent.ACTION_VIEW, Uri.parse(mUrl));
            startActivity(viewGGNetMatchPage);
        }
    });

    extrasBlock.addView(extrasItem);

    mDetailsContainer.addView(extrasCard);

    mMatchViewContainer.setBackground(null);
    //getWindow().setBackgroundDrawable(null);

    mDetailsContainer.animate().translationY(0).setDuration(350).setInterpolator(new DecelerateInterpolator())
            .start();

}