Example usage for android.widget FrameLayout FrameLayout

List of usage examples for android.widget FrameLayout FrameLayout

Introduction

In this page you can find the example usage for android.widget FrameLayout FrameLayout.

Prototype

public FrameLayout(@NonNull Context context) 

Source Link

Usage

From source file:com.android.contacts.list.DefaultContactBrowseListFragment.java

@Override
protected void onCreateView(LayoutInflater inflater, ViewGroup container) {
    super.onCreateView(inflater, container);

    initSwipeRefreshLayout();/*  w w  w . j av a  2s .c o  m*/

    // Putting the header view inside a container will allow us to make
    // it invisible later. See checkHeaderViewVisibility()
    final FrameLayout headerContainer = new FrameLayout(inflater.getContext());
    mSearchHeaderView = inflater.inflate(R.layout.search_header, null, false);
    headerContainer.addView(mSearchHeaderView);
    getListView().addHeaderView(headerContainer, null, false);
    checkHeaderViewVisibility();

    mSearchProgress = getView().findViewById(R.id.search_progress);
    mSearchProgressText = (TextView) mSearchHeaderView.findViewById(R.id.totalContactsText);

    mAlertContainer = getView().findViewById(R.id.alert_container);
    mAlertText = (TextView) mAlertContainer.findViewById(R.id.alert_text);
    mAlertDismissIcon = (ImageView) mAlertContainer.findViewById(R.id.alert_dismiss_icon);
    mAlertText.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            turnSyncOn();
        }
    });
    mAlertDismissIcon.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            dismiss();
        }
    });

    mAlertContainer.setVisibility(View.GONE);
}

From source file:com.pdftron.pdf.controls.ReflowPagerAdapter.java

@Override
public Object instantiateItem(final ViewGroup container, final int position) {
    int availIndex = mWebViewRepository.pop();
    ReflowWebView webView = mWebViewRepository.getWebView(availIndex);
    if (webView == null) {
        AnalyticsHandlerAdapter.getInstance()
                .sendException(new Exception("Reflow: there is no available WebView in repository"));
        Log.e(TAG, "there is no available WebView in repository");
        return null;
    }//from ww  w  . j a va2  s.  co  m
    webView.loadUrl("about:blank");

    int pagePosition = mIsRtlMode ? mPageCount - 1 - position : position;

    boolean need_load_flag = true;
    String filename = mReflowFiles.get(pagePosition);
    if (filename != null) {
        File file = new File(filename);
        if (file.exists()) {
            need_load_flag = false;
            if (DEBUG)
                Log.d(TAG, "the file at page #" + (position + 1) + " already received");
            webView.loadUrl("file:///" + filename);
            setTextZoom(webView);
        }
    }

    if (need_load_flag) {
        webView.loadUrl(mLoadingFile);
        try {
            // request for reflow output
            if (DEBUG)
                Log.d(TAG, "request for page #" + (pagePosition + 1));
            Page page = mDoc.getPage(pagePosition + 1);
            ReflowProcessor.getReflow(page, mRequestHandler, position);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    FrameLayout layout = new FrameLayout(mContext);
    FrameLayout parent = (FrameLayout) webView.getParent();
    if (parent != null) {
        // note that we share WebViews,
        // so before adding a WebView make sure it's not a child of any layout
        parent.removeAllViews();
    }
    layout.addView(webView);
    mViewHolders.put(position, layout);
    mViewIndexes.put(position, new Integer(availIndex));
    container.addView(layout);
    return layout;
}

From source file:com.heneryh.aquanotes.ui.controllers.ControllersActivity.java

/**
 * Build and add "sessions" tab.//from  w w  w.  j  av  a  2s .  c  o  m
 */
private void setupOutletsTab(Ctlr ctlr) {

    /**
     * nearly all of the comments here are the same as for the probes.
     */
    String tagSpec = TAG_OUTLETS + "_" + ctlr.mControllerId.toString().replace('-', 'n');

    int Rid;
    switch (ctlr.index) {
    case 0:
        Rid = R.id.fragment_outlets_0;
        break;
    case 1:
        Rid = R.id.fragment_outlets_1;
        break;
    case 2:
        Rid = R.id.fragment_outlets_2;
        break;
    case 3:
        Rid = R.id.fragment_outlets_3;
        break;
    case 4:
        Rid = R.id.fragment_outlets_4;
        break;
    case 5:
        Rid = R.id.fragment_outlets_5;
        break;
    case 6:
        Rid = R.id.fragment_outlets_6;
        break;
    case 7:
        Rid = R.id.fragment_outlets_7;
        break;
    case 8:
        Rid = R.id.fragment_outlets_8;
        break;
    case 9:
        Rid = R.id.fragment_outlets_9;
        break;
    default:
        Rid = 0;
    }

    ctlr.outletsFragmentContainer = new FrameLayout(this);
    ctlr.outletsFragmentContainer.setId(Rid);
    ctlr.outletsFragmentContainer.setLayoutParams(
            new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT));

    ViewGroup tabContentView = (ViewGroup) ctlr.mRootView.findViewById(android.R.id.tabcontent);
    tabContentView.addView(ctlr.outletsFragmentContainer);

    final Intent intent = new Intent(Intent.ACTION_VIEW,
            Data.buildQueryODataAtUri(ctlr.mControllerId, ctlr.mTimestamp));

    final FragmentManager fm = getSupportFragmentManager();
    ctlr.mOutletsFragment = (OutletsDataFragment) fm.findFragmentByTag(tagSpec); // was OutletXFragment
    if (ctlr.mOutletsFragment == null) {
        ctlr.mOutletsFragment = new OutletsDataFragment(); // was OutletXFragment
        ctlr.mOutletsFragment.setArguments(intentToFragmentArguments(intent));
        fm.beginTransaction().add(Rid, ctlr.mOutletsFragment, tagSpec).commit();
    }

    ctlr.mTabHost.addTab(ctlr.mTabHost.newTabSpec(tagSpec)
            .setIndicator(buildIndicator(ctlr, R.string.outlets_tab_title)).setContent(Rid));

    //        ctlr.mTabManager.addTab(ctlr.mTabHost.newTabSpec(tagSpec)
    //                                 .setIndicator("Outlets")//buildIndicator(ctlr, R.string.outlets_tab_title))
    //                                 .setContent(Rid),
    //                        OutletsDataFragment.class, 
    //                        Rid,
    //                        intentToFragmentArguments(intent));     

}

From source file:foam.starwisp.StarwispBuilder.java

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

    if (StarwispLinearLayout.m_DisplayMetrics == null) {
        StarwispLinearLayout.m_DisplayMetrics = ctx.getResources().getDisplayMetrics();
    }/*from   w w  w  .j  a  v a 2  s .co m*/

    try {
        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("map")) {
            int ID = arr.getInt(1);
            LinearLayout inner = new LinearLayout(ctx);
            inner.setLayoutParams(BuildLayoutParams(arr.getJSONArray(2)));
            inner.setId(ID);
            Fragment mapfrag = SupportMapFragment.newInstance();
            FragmentTransaction fragmentTransaction = ctx.getSupportFragmentManager().beginTransaction();
            fragmentTransaction.add(ID, mapfrag);
            fragmentTransaction.commit();
            parent.addView(inner);
            return;
        }

        if (type.equals("drawmap")) {
            final LinearLayout inner = new LinearLayout(ctx);
            inner.setLayoutParams(BuildLayoutParams(arr.getJSONArray(2)));
            DrawableMap dm = new DrawableMap();
            dm.init(arr.getInt(1), inner, (StarwispActivity) ctx, this, arr.getString(3));
            parent.addView(inner);
            m_DMaps.put(arr.getInt(1), dm);
            return;
        }

        if (type.equals("linear-layout")) {
            StarwispLinearLayout.Build(this, ctx, ctxname, arr, parent);
            return;
        }

        if (type.equals("relative-layout")) {
            StarwispRelativeLayout.Build(this, ctx, ctxname, arr, parent);
            return;
        }

        if (type.equals("draggable")) {
            final LinearLayout v = new LinearLayout(ctx);
            final int id = arr.getInt(1);
            final String behaviour_type = arr.getString(5);
            v.setPadding(20, 20, 20, 10);
            v.setId(id);
            v.setOrientation(StarwispLinearLayout.BuildOrientation(arr.getString(2)));
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(3)));
            v.setClickable(true);
            v.setFocusable(true);

            JSONArray col = arr.getJSONArray(4);
            v.setBackgroundResource(R.drawable.draggable);

            GradientDrawable drawable = (GradientDrawable) v.getBackground();
            final int colour = Color.argb(col.getInt(3), col.getInt(0), col.getInt(1), col.getInt(2));
            drawable.setColor(colour);

            /*LayerDrawable bgDrawable = (LayerDrawable)v.getBackground();
            GradientDrawable bgShape = (GradientDrawable)bgDrawable.findDrawableByLayerId(R.id.draggableshape);
            bgShape.setColor(colour);*/
            /*v.getBackground().setColorFilter(colour, PorterDuff.Mode.MULTIPLY);*/

            parent.addView(v);
            JSONArray children = arr.getJSONArray(6);
            for (int i = 0; i < children.length(); i++) {
                Build(ctx, ctxname, new JSONArray(children.getString(i)), v);
            }

            // Sets a long click listener for the ImageView using an anonymous listener object that
            // implements the OnLongClickListener interface
            if (!behaviour_type.equals("drop-only") && !behaviour_type.equals("drop-only-consume")) {
                v.setOnLongClickListener(new View.OnLongClickListener() {
                    public boolean onLongClick(View vv) {
                        if (id != 99) {
                            ClipData dragData = new ClipData(
                                    new ClipDescription("" + id,
                                            new String[] { ClipDescription.MIMETYPE_TEXT_PLAIN }),
                                    new ClipData.Item("" + id));

                            View.DragShadowBuilder myShadow = new MyDragShadowBuilder(v);
                            Log.i("starwisp", "start drag id " + vv.getId() + " " + v);
                            v.startDrag(dragData, myShadow, v, 0);
                            v.setVisibility(View.GONE);
                            return true;
                        }
                        return false;
                    }
                });
            }

            if (!behaviour_type.equals("drag-only")) {
                // ye gads - needed as drag/drop doesn't deal with nested targets
                final StarwispBuilder that = this;

                v.setOnDragListener(new View.OnDragListener() {
                    public boolean onDrag(View vv, DragEvent event) {

                        //Log.i("starwisp","on drag event happened");

                        final int action = event.getAction();
                        switch (action) {
                        case DragEvent.ACTION_DRAG_STARTED:
                            //Log.i("starwisp","Drag started"+v );
                            if (event.getClipDescription().hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN)) {
                                // returns true to indicate that the View can accept the dragged data.
                                return true;
                            } else {
                                // Returns false. During the current drag and drop operation, this View will
                                // not receive events again until ACTION_DRAG_ENDED is sent.
                                return false;
                            }
                        case DragEvent.ACTION_DRAG_ENTERED: {
                            if (that.m_LastDragHighlighted != null) {
                                that.m_LastDragHighlighted.getBackground().setColorFilter(null);
                            }
                            v.getBackground().setColorFilter(0x77777777, PorterDuff.Mode.MULTIPLY);
                            that.m_LastDragHighlighted = v;
                            //Log.i("starwisp","Drag entered"+v );
                            return true;
                        }
                        case DragEvent.ACTION_DRAG_LOCATION: {
                            //View dragee = (View)event.getLocalState();
                            //dragee.setVisibility(View.VISIBLE);
                            //Log.i("starwisp","Drag location"+v );
                            return true;
                        }
                        case DragEvent.ACTION_DRAG_EXITED: {
                            //Log.i("starwisp","Drag exited "+v );
                            v.getBackground().setColorFilter(null);
                            return true;
                        }
                        case DragEvent.ACTION_DROP: {
                            v.getBackground().setColorFilter(null);
                            //Log.i("starwisp","Drag dropped "+v );
                            View otherw = (View) event.getLocalState();
                            //Log.i("starwisp","removing from parent "+((View)otherw.getParent()).getId());

                            // check we are not adding to ourself
                            if (id != otherw.getId()) {
                                ((ViewManager) otherw.getParent()).removeView(otherw);
                                //Log.i("starwisp","adding to " + id);

                                if (!behaviour_type.equals("drop-only-consume")) {
                                    v.addView(otherw);
                                }
                            }
                            otherw.setVisibility(View.VISIBLE);
                            return true;
                        }
                        case DragEvent.ACTION_DRAG_ENDED: {
                            //Log.i("starwisp","Drag ended "+v );
                            v.getBackground().setColorFilter(null);

                            View dragee = (View) event.getLocalState();
                            dragee.setVisibility(View.VISIBLE);

                            if (event.getResult()) {
                                //Log.i("starwisp","sucess " );
                            } else {
                                //Log.i("starwisp","fail " );
                            }
                            ;
                            return true;
                        }
                        // An unknown action type was received.
                        default:
                            //Log.e("starwisp","Unknown action type received by OnDragListener.");
                            break;
                        }
                        ;
                        return true;
                    }
                });
                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 fragment 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)));
            v.setAdjustViewBounds(true);

            String image = arr.getString(2);

            if (image.startsWith("/")) {
                Bitmap b = BitmapCache.Load(image);
                if (b != null) {
                    v.setImageBitmap(b);
                }
            } else {
                int id = ctx.getResources().getIdentifier(image, "drawable", ctx.getPackageName());
                v.setImageResource(id);
            }

            parent.addView(v);
        }

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

            String image = arr.getString(2);

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

            final String fn = arr.getString(4);
            v.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    Callback(ctx, ctxname, v.getId());
                }
            });

            v.setAdjustViewBounds(true);
            v.setScaleType(ImageView.ScaleType.CENTER_INSIDE);

            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)), BufferType.SPANNABLE);
            v.setTextSize(arr.getInt(3));
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(4)));
            v.setLinkTextColor(0xff00aa00);

            // uncomment all this to get hyperlinks to work in text...
            // should make this an option of course

            //v.setClickable(true); // make links
            //v.setMovementMethod(LinkMovementMethod.getInstance());
            //v.setEnabled(true);   // go to browser
            /*v.setOnTouchListener(new View.OnTouchListener() {
            public boolean onTouch(View vv, MotionEvent event) {
                return false;
            }
            };*/

            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.CENTER);
            }
            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));
            v.setGravity(Gravity.LEFT | Gravity.TOP);

            String inputtype = arr.getString(4);
            if (inputtype.equals("text")) {
                //v.setInputType(InputType.TYPE_CLASS_TEXT);
            } else if (inputtype.equals("numeric")) {
                v.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL
                        | InputType.TYPE_NUMBER_FLAG_SIGNED);
            } 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("colour-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);
            JSONArray col = arr.getJSONArray(6);
            v.getBackground().setColorFilter(
                    Color.argb(col.getInt(3), col.getInt(0), col.getInt(1), col.getInt(2)),
                    PorterDuff.Mode.MULTIPLY);
            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);
            if (arr.getString(5).equals("fancy")) {
                v = (ToggleButton) ctx.getLayoutInflater().inflate(R.layout.toggle_button_fancy, null);
            }

            if (arr.getString(5).equals("yes")) {
                v = (ToggleButton) ctx.getLayoutInflater().inflate(R.layout.toggle_button_yes, null);
            }

            if (arr.getString(5).equals("maybe")) {
                v = (ToggleButton) ctx.getLayoutInflater().inflate(R.layout.toggle_button_maybe, null);
            }

            if (arr.getString(5).equals("no")) {
                v = (ToggleButton) ctx.getLayoutInflater().inflate(R.layout.toggle_button_no, null);
            }

            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(6);
            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)));
            v.setMinimumWidth(100); // stops tiny buttons
            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, R.layout.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;
                }
            };

            spinnerArrayAdapter.setDropDownViewResource(R.layout.spinner_layout);

            v.setAdapter(spinnerArrayAdapter);
            v.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
                public void onItemSelected(AdapterView<?> a, View v, int pos, long id) {
                    CallbackArgs(ctx, ctxname, wid, "" + pos);
                }

                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)));
            Log.e("starwisp", "built the thing");
            parent.addView(v);
            Log.e("starwisp", "addit to the view");
        }

        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);
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(2)));
            parent.addView(v);

            Log.i("starwisp", "in camera-preview...");

            List<List<String>> info = v.mPictureTaker.GetInfo();
            // can't find a way to do this via a callback yet
            String arg = "'(";
            for (List<String> e : info) {
                arg += "(" + e.get(0) + " " + e.get(1) + ")";
                //Log.i("starwisp","converting prop "+arg);
            }
            arg += ")";
            m_Scheme.eval("(set! camera-properties " + arg + ")");
        }

        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);
            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:org.navitproject.navit.NavitGraphics.java

public NavitGraphics(final Activity activity, NavitGraphics parent, int x, int y, int w, int h, int wraparound,
        int use_camera) {
    if (parent == null) {
        this.activity = (Navit) activity;
        view = new NavitView(activity);
        //activity.registerForContextMenu(view);
        view.setClickable(false);//from   www  .j  a  v  a 2 s  . c om
        view.setFocusable(true);
        view.setFocusableInTouchMode(true);
        view.setKeepScreenOn(true);
        relativelayout = new RelativeLayout(activity);
        if (use_camera != 0) {
            SetCamera(use_camera);
        }
        relativelayout.addView(view);

        /* The navigational and status bar tinting code is meaningful only on API19+ */
        if (Build.VERSION.SDK_INT >= 19) {
            frameLayout = new FrameLayout(activity);
            frameLayout.addView(relativelayout);
            navigationTintView = new SystemBarTintView(activity);
            statusTintView = new SystemBarTintView(activity);
            frameLayout.addView(navigationTintView);
            frameLayout.addView(statusTintView);
            activity.setContentView(frameLayout);
        } else {
            activity.setContentView(relativelayout);
        }

        view.requestFocus();
    } else {
        draw_bitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
        bitmap_w = w;
        bitmap_h = h;
        pos_x = x;
        pos_y = y;
        pos_wraparound = wraparound;
        draw_canvas = new Canvas(draw_bitmap);
        parent.overlays.add(this);
    }
    parent_graphics = parent;
}

From source file:tk.eatheat.omnisnitch.ui.SwitchLayout.java

private synchronized void createView() {
    mView = mInflater.inflate(R.layout.recents_list_horizontal, null, false);
    mRecentListHorizontal = (HorizontalListView) mView.findViewById(R.id.recent_list_horizontal);

    mNoRecentApps = (TextView) mView.findViewById(R.id.no_recent_apps);

    mRecentListHorizontal.setSelectionListener(mSelectionGlowListener);

    mRecentListHorizontal.setOnItemClickListener(new OnItemClickListener() {
        @Override/*from ww w.  ja  v a 2  s. c  o  m*/
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            if (DEBUG) {
                Log.d(TAG, "onItemClick");
            }
            TaskDescription task = mLoadedTasks.get(position);
            mRecentsManager.switchTask(task);
        }
    });

    mRecentListHorizontal.setOnItemLongClickListener(new OnItemLongClickListener() {
        @Override
        public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
            if (DEBUG) {
                Log.d(TAG, "onItemLongClick");
            }
            TaskDescription task = mLoadedTasks.get(position);
            handleLongPress(task, view);
            return true;
        }
    });

    SwipeDismissHorizontalListViewTouchListener touchListener = new SwipeDismissHorizontalListViewTouchListener(
            mRecentListHorizontal, new SwipeDismissHorizontalListViewTouchListener.DismissCallbacks() {
                public void onDismiss(HorizontalListView listView, int[] reverseSortedPositions) {
                    for (int position : reverseSortedPositions) {
                        TaskDescription ad = mRecentListAdapter.getItem(position);
                        mRecentsManager.killTask(ad);
                        break;
                    }
                }

                @Override
                public boolean canDismiss(int position) {
                    return true;
                }
            });

    mRecentListHorizontal.setSwipeListener(touchListener);
    mRecentListHorizontal.setAdapter(mRecentListAdapter);

    mOpenFavorite = (ImageButton) mView.findViewById(R.id.openFavorites);

    mOpenFavorite.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            setButtonGlow(mOpenFavorite, mShowFavorites ? "arrow_up" : "arrow_down",
                    mShowFavorites ? R.drawable.arrow_up : R.drawable.arrow_down, true);

            mShowFavorites = !mShowFavorites;

            if (mConfiguration.mAnimate) {
                mFavoriteListHorizontal.startAnimation(
                        mShowFavorites ? getShowFavoriteAnimation() : getHideFavoriteAnimation());
            } else {
                mFavoriteListHorizontal.setVisibility(mShowFavorites ? View.VISIBLE : View.GONE);
                setButtonGlow(mOpenFavorite, mShowFavorites ? "arrow_up" : "arrow_down",
                        mShowFavorites ? R.drawable.arrow_up : R.drawable.arrow_down, false);
            }
        }
    });

    mFavoriteListHorizontal = (HorizontalListView) mView.findViewById(R.id.favorite_list_horizontal);

    mFavoriteListHorizontal.setSelectionListener(mSelectionGlowListener);

    mFavoriteListHorizontal.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            if (DEBUG) {
                Log.d(TAG, "onItemClick");
            }
            String intent = mFavoriteList.get(position);
            mRecentsManager.startIntentFromtString(intent);
        }
    });
    mFavoriteListHorizontal.setAdapter(mFavoriteListAdapter);

    mHomeButton = (GlowImageButton) mView.findViewById(R.id.home);
    mHomeButton.setOriginalImage(mContext.getResources().getDrawable(R.drawable.home));
    mHomeButton.setGlowImage(Utils.getGlowDrawable(mContext.getResources(), "home", mConfiguration.mGlowColor,
            mContext.getResources().getDrawable(R.drawable.home)));
    mHomeButton.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_DOWN) {
                mHomeButton.setImageDrawable(mHomeButton.getGlowImage());
            }
            v.onTouchEvent(event);
            return true;
        }
    });
    mHomeButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            mRecentsManager.dismissAndGoHome();
            mHomeButton.setImageDrawable(mHomeButton.getOriginalImage());
        }
    });
    mHomeButton.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {
            Toast.makeText(mContext, mContext.getResources().getString(R.string.home_help), Toast.LENGTH_SHORT)
                    .show();
            mHomeButton.setImageDrawable(mHomeButton.getOriginalImage());
            return true;
        }
    });

    mLastAppButton = (GlowImageButton) mView.findViewById(R.id.lastApp);
    mLastAppButton.setOriginalImage(mContext.getResources().getDrawable(R.drawable.lastapp));
    mLastAppButton.setGlowImage(Utils.getGlowDrawable(mContext.getResources(), "lastapp",
            mConfiguration.mGlowColor, mContext.getResources().getDrawable(R.drawable.lastapp)));
    mLastAppButton.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_DOWN) {
                mLastAppButton.setImageDrawable(mLastAppButton.getGlowImage());
            }
            v.onTouchEvent(event);
            return true;
        }
    });

    mLastAppButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            mRecentsManager.toggleLastApp();
            mLastAppButton.setImageDrawable(mLastAppButton.getOriginalImage());
        }
    });
    mLastAppButton.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {
            Toast.makeText(mContext, mContext.getResources().getString(R.string.toogle_last_app_help),
                    Toast.LENGTH_SHORT).show();
            mLastAppButton.setImageDrawable(mLastAppButton.getOriginalImage());
            return true;
        }
    });
    mKillAllButton = (GlowImageButton) mView.findViewById(R.id.killAll);
    mKillAllButton.setOriginalImage(mContext.getResources().getDrawable(R.drawable.kill_all));
    mKillAllButton.setGlowImage(Utils.getGlowDrawable(mContext.getResources(), "kill_other",
            mConfiguration.mGlowColor, mContext.getResources().getDrawable(R.drawable.kill_all)));
    mKillAllButton.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_DOWN) {
                mKillAllButton.setImageDrawable(mKillAllButton.getGlowImage());
            }
            v.onTouchEvent(event);
            return true;
        }
    });
    mKillAllButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            mRecentsManager.killAll();
            mKillAllButton.setImageDrawable(mKillAllButton.getOriginalImage());
        }
    });

    mKillAllButton.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {
            Toast.makeText(mContext, mContext.getResources().getString(R.string.kill_all_apps_help),
                    Toast.LENGTH_SHORT).show();
            mKillAllButton.setImageDrawable(mKillAllButton.getOriginalImage());
            return true;
        }
    });

    mKillOtherButton = (GlowImageButton) mView.findViewById(R.id.killOther);
    mKillOtherButton.setOriginalImage(mContext.getResources().getDrawable(R.drawable.kill_other));
    mKillOtherButton.setGlowImage(Utils.getGlowDrawable(mContext.getResources(), "kill_other",
            mConfiguration.mGlowColor, mContext.getResources().getDrawable(R.drawable.kill_other)));
    mKillOtherButton.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_DOWN) {
                mKillOtherButton.setImageDrawable(mKillOtherButton.getGlowImage());
            }
            v.onTouchEvent(event);
            return true;
        }
    });

    mKillOtherButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            mRecentsManager.killOther();
            mKillOtherButton.setImageDrawable(mKillOtherButton.getOriginalImage());
            mKillOtherButton.setImageDrawable(mKillOtherButton.getOriginalImage());
        }
    });
    mKillOtherButton.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {
            Toast.makeText(mContext, mContext.getResources().getString(R.string.kill_other_apps_help),
                    Toast.LENGTH_SHORT).show();
            mKillOtherButton.setImageDrawable(mKillOtherButton.getOriginalImage());
            return true;
        }
    });

    mSettingsButton = (GlowImageButton) mView.findViewById(R.id.settings);
    mSettingsButton.setOriginalImage(mContext.getResources().getDrawable(R.drawable.settings));
    mSettingsButton.setGlowImage(Utils.getGlowDrawable(mContext.getResources(), "settings",
            mConfiguration.mGlowColor, mContext.getResources().getDrawable(R.drawable.settings)));

    mSettingsButton.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_DOWN) {
                mSettingsButton.setImageDrawable(mSettingsButton.getGlowImage());
            }
            v.onTouchEvent(event);
            return true;
        }
    });

    mSettingsButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            Intent hideRecent = new Intent(SwitchService.RecentsReceiver.ACTION_HIDE_OVERLAY);
            mContext.sendBroadcast(hideRecent);

            Intent mainActivity = new Intent(mContext, SettingsActivity.class);
            mainActivity.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
            mContext.startActivity(mainActivity);
            mSettingsButton.setImageDrawable(mSettingsButton.getOriginalImage());
        }
    });
    //mSettingsButton.setImageDrawable(Utils.getGlow(mContext.getResources(), "settings", mContext.getResources().getDrawable(R.drawable.settings)));
    mSettingsButton.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {
            Toast.makeText(mContext, mContext.getResources().getString(R.string.settings_help),
                    Toast.LENGTH_SHORT).show();
            mSettingsButton.setImageDrawable(mSettingsButton.getOriginalImage());
            return true;
        }
    });

    // touches inside the overlay should not hide it
    mView.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (DEBUG) {
                Log.d(TAG, "mView:onTouch");
            }
            return true;
        }
    });

    mRamUsageBar = (LinearColorBar) mView.findViewById(R.id.ram_usage_bar);
    mForegroundProcessText = (TextView) mView.findViewById(R.id.foregroundText);
    mBackgroundProcessText = (TextView) mView.findViewById(R.id.backgroundText);

    mPopupView = new FrameLayout(mContext);
    try {
        mPopupView.setBackground(mContext.getResources().getDrawable(R.drawable.overlay_bg));
    } catch (NoSuchMethodError x) {
        mPopupView.setBackgroundDrawable(mContext.getResources().getDrawable(R.drawable.overlay_bg));

    }
    mPopupView.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_DOWN) {
                if (mShowing) {
                    if (DEBUG) {
                        Log.d(TAG, "mPopupView:onTouch");
                    }
                    Intent hideRecent = new Intent(SwitchService.RecentsReceiver.ACTION_HIDE_OVERLAY);
                    mContext.sendBroadcast(hideRecent);
                    return true;
                }
            }
            return false;
        }
    });
    mPopupView.setOnKeyListener(new View.OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (event.getAction() == KeyEvent.ACTION_DOWN) {
                if (mShowing) {
                    if (DEBUG) {
                        Log.d(TAG, "onKey");
                    }
                    Intent hideRecent = new Intent(SwitchService.RecentsReceiver.ACTION_HIDE_OVERLAY);
                    mContext.sendBroadcast(hideRecent);
                    return true;
                }
            }
            return false;
        }
    });
}

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  va 2  s.  c  o m
 * @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 "";
}

From source file:ir.besteveryeverapp.ui.ActionBar.BottomSheet.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Window window = getWindow();/*from   w w  w.  j a va  2  s  .c  o m*/
    window.setWindowAnimations(R.style.DialogNoAnimation);
    setContentView(container, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    if (containerView == null) {
        containerView = new FrameLayout(getContext()) {
            @Override
            public boolean hasOverlappingRendering() {
                return false;
            }
        };
        containerView.setBackgroundDrawable(shadowDrawable);
        containerView.setPadding(backgroundPaddingLeft,
                (applyTopPadding ? AndroidUtilities.dp(8) : 0) + backgroundPaddingTop, backgroundPaddingLeft,
                (applyBottomPadding ? AndroidUtilities.dp(8) : 0));
    }
    if (Build.VERSION.SDK_INT >= 21) {
        containerView.setFitsSystemWindows(true);
    }
    containerView.setVisibility(View.INVISIBLE);
    container.addView(containerView, 0,
            LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.BOTTOM));

    if (customView != null) {
        if (customView.getParent() != null) {
            ViewGroup viewGroup = (ViewGroup) customView.getParent();
            viewGroup.removeView(customView);
        }
        containerView.addView(customView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT,
                LayoutHelper.WRAP_CONTENT, Gravity.LEFT | Gravity.TOP));
    } else {
        int topOffset = 0;
        if (title != null) {
            TextView titleView = new TextView(getContext());
            titleView.setTypeface(FontManager.instance().getTypeface());
            titleView.setLines(1);
            titleView.setSingleLine(true);
            titleView.setText(title);
            titleView.setTextColor(0xff757575);
            titleView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
            titleView.setEllipsize(TextUtils.TruncateAt.MIDDLE);
            titleView.setPadding(AndroidUtilities.dp(16), 0, AndroidUtilities.dp(16), AndroidUtilities.dp(8));
            titleView.setGravity(Gravity.CENTER_VERTICAL);
            containerView.addView(titleView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48));
            titleView.setOnTouchListener(new View.OnTouchListener() {
                @Override
                public boolean onTouch(View v, MotionEvent event) {
                    return true;
                }
            });
            topOffset += 48;
        }
        if (items != null) {
            FrameLayout rowLayout = null;
            int lastRowLayoutNum = 0;
            for (int a = 0; a < items.length; a++) {
                BottomSheetCell cell = new BottomSheetCell(getContext(), 0);
                cell.setTextAndIcon(items[a], itemIcons != null ? itemIcons[a] : 0);
                containerView.addView(cell, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48,
                        Gravity.LEFT | Gravity.TOP, 0, topOffset, 0, 0));
                topOffset += 48;
                cell.setTag(a);
                cell.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        dismissWithButtonClick((Integer) v.getTag());
                    }
                });
                itemViews.add(cell);
            }
        }
    }

    WindowManager.LayoutParams params = window.getAttributes();
    params.width = ViewGroup.LayoutParams.MATCH_PARENT;
    params.gravity = Gravity.TOP | Gravity.LEFT;
    params.dimAmount = 0;
    params.flags &= ~WindowManager.LayoutParams.FLAG_DIM_BEHIND;
    if (!focusable) {
        params.flags |= WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
    }
    params.height = ViewGroup.LayoutParams.MATCH_PARENT;
    window.setAttributes(params);
}

From source file:org.cafemember.ui.DialogsActivity.java

@Override
public View createView(final Context context) {
    Commands.checkChannels(MessagesController.getInstance().getDialogs());
    int today = Calendar.getInstance().get(Calendar.DAY_OF_WEEK);
    if (today != Defaults.getInstance().getLastDay()) {
        Defaults.getInstance().setLastDay(today);
        AlertDialog.Builder builder = null;
        /*if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) {
        builder = new AlertDialog.Builder(context, R.style.MyDialog);
        }//from   w  ww  .  java 2s  .  co m
        else {*/
        builder = new AlertDialog.Builder(context);
        //            }

        builder.setTitle(" ");
        builder.setMessage(
                AndroidUtilities.replaceTags(LocaleController.getString("giftText", R.string.giftText)));

        builder.setPositiveButton("", null);
        showDialog(builder.create());

    }
    searching = false;
    searchWas = false;

    Theme.loadRecources(context);

    ActionBarMenu menu = actionBar.createMenu();
    if (!onlySelect && searchString == null) {
        passcodeItem = menu.addItem(1, R.drawable.lock_close);
        updatePasscodeButton();
    }
    joinCoins = menu.addItemResource(7, R.layout.join_coins_view);
    FontManager.instance().setTypefaceImmediate(joinCoins);
    //        viewCoins = menu.addItemResource(8, R.layout.view_coins_view);

    //        final ActionBarMenuItem item = menu.addItem(0, R.drawable.ic_ab_search).setIsSearchField(true).setActionBarMenuItemSearchListener(new ActionBarMenuItem.ActionBarMenuItemSearchListener() {
    //            @Override
    //            public void onSearchExpand() {
    //                searching = true;
    //                if (listView != null) {
    //                    if (searchString != null) {
    //                        listView.setEmptyView(searchEmptyView);
    //                        progressView.setVisibility(View.GONE);
    //                        emptyView.setVisibility(View.GONE);
    //                    }
    //                    if (!onlySelect) {
    //                        floatingButton.setVisibility(View.GONE);
    //                    }
    //                }
    //                updatePasscodeButton();
    //            }
    //
    //            @Override
    //            public boolean canCollapseSearch() {
    //                if (searchString != null) {
    //                    finishFragment();
    //                    return false;
    //                }
    //                return true;
    //            }
    //
    //            @Override
    //            public void onSearchCollapse() {
    //                searching = false;
    //                searchWas = false;
    //                if (listView != null) {
    //                    searchEmptyView.setVisibility(View.GONE);
    //                    if (MessagesController.getInstance().loadingDialogs && MessagesController.getInstance().dialogs.isEmpty()) {
    //                        emptyView.setVisibility(View.GONE);
    //                        listView.setEmptyView(progressView);
    //                    } else {
    //                        progressView.setVisibility(View.GONE);
    //                        listView.setEmptyView(emptyView);
    //                    }
    //                    if (!onlySelect) {
    //                        floatingButton.setVisibility(View.VISIBLE);
    //                        floatingHidden = true;
    //                        ViewProxy.setTranslationY(floatingButton, AndroidUtilities.dp(100));
    //                        hideFloatingButton(false);
    //                    }
    //                    if (listView.getAdapter() != dialogsAdapter) {
    //                        listView.setAdapter(dialogsAdapter);
    //                        dialogsAdapter.notifyDataSetChanged();
    //                    }
    //                }
    //                if (dialogsSearchAdapter != null) {
    //                    dialogsSearchAdapter.searchDialogs(null);
    //                }
    //                updatePasscodeButton();
    //            }
    //
    //            @Override
    //            public void onTextChanged(EditText editText) {
    //                String text = editText.getText().toString();
    //                if (text.length() != 0 || dialogsSearchAdapter != null && dialogsSearchAdapter.hasRecentRearch()) {
    //                    searchWas = true;
    //                    if (dialogsSearchAdapter != null && listView.getAdapter() != dialogsSearchAdapter) {
    //                        listView.setAdapter(dialogsSearchAdapter);
    //                        dialogsSearchAdapter.notifyDataSetChanged();
    //                    }
    //                    if (searchEmptyView != null && listView.getEmptyView() != searchEmptyView) {
    //                        emptyView.setVisibility(View.GONE);
    //                        progressView.setVisibility(View.GONE);
    //                        searchEmptyView.showTextView();
    //                        listView.setEmptyView(searchEmptyView);
    //                    }
    //                }
    //                if (dialogsSearchAdapter != null) {
    //                    dialogsSearchAdapter.searchDialogs(text);
    //                }
    //            }
    //        });
    //        item.getSearchField().setHint(LocaleController.getString("Search", R.string.Search));
    if (onlySelect) {
        actionBar.setBackButtonImage(R.drawable.ic_ab_back);
        actionBar.setTitle(LocaleController.getString("SelectChat", R.string.SelectChat));
    } else {
        if (searchString != null) {
            actionBar.setBackButtonImage(R.drawable.ic_ab_back);
        } else {
            actionBar.setBackButtonDrawable(new MenuDrawable());
        }
        if (BuildVars.DEBUG_VERSION) {
            actionBar.setTitle(LocaleController.getString("AppNameBeta", R.string.AppNameBeta));
        } else {
            actionBar.setTitle(LocaleController.getString("AppName", R.string.AppName));
        }
    }
    actionBar.setAllowOverlayTitle(true);

    actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
        @Override
        public void onItemClick(int id) {
            if (id == -1) {
                if (onlySelect) {
                    finishFragment();
                } else if (parentLayout != null) {
                    parentLayout.getDrawerLayoutContainer().openDrawer(false);
                }
            } else if (id == 1) {
                UserConfig.appLocked = !UserConfig.appLocked;
                UserConfig.saveConfig(false);
                updatePasscodeButton();
            }
        }
    });

    FrameLayout frameLayout = new FrameLayout(context);
    //        fragmentView = frameLayout;
    fragmentView = Views.getTabLayout((FragmentActivity) context, this, frameLayout);

    listView = new RecyclerListView(context);
    listView.setVerticalScrollBarEnabled(true);
    listView.setItemAnimator(null);
    listView.setInstantClick(true);
    listView.setLayoutAnimation(null);
    layoutManager = new LinearLayoutManager(context) {
        @Override
        public boolean supportsPredictiveItemAnimations() {
            return false;
        }
    };
    layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
    listView.setLayoutManager(layoutManager);
    if (Build.VERSION.SDK_INT >= 11) {
        listView.setVerticalScrollbarPosition(
                LocaleController.isRTL ? ListView.SCROLLBAR_POSITION_LEFT : ListView.SCROLLBAR_POSITION_RIGHT);
    }
    frameLayout.addView(listView,
            LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));

    listView.setOnAddChannelClickListener(new RecyclerListView.OnItemClickListener() {
        @Override
        public void onItemClick(View view, int position) {
            if (listView == null || listView.getAdapter() == null) {
                return;
            }
            long dialog_id = 0;
            int message_id = 0;
            RecyclerView.Adapter adapter = listView.getAdapter();
            if (adapter == dialogsAdapter) {
                TLRPC.Dialog dialog = dialogsAdapter.getItem(position);
                if (dialog == null) {
                    return;
                }
                int lower_id = (int) dialog.id;
                final TLRPC.Chat chat = MessagesController.getInstance().getChat(-lower_id);
                AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                builder.setTitle(LocaleController.getString("MemberBegirTitle", R.string.MemberBegirTitle));

                /*builder.setItems(Defaults.MEMBERS_COUNT , new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        Commands.addChannel(chat,Integer.parseInt(Defaults.MEMBERS_COUNT[which]));
                    }
                });*/
                /*builder.setAdapter(new ReserveAdapter(getParentActivity(),R.layout.adapter_buy_coin,1), new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        Commands.addChannel(chat,Integer.parseInt(Defaults.MEMBERS_COUNT[which]));
                    }
                });*/
                builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
                showDialog(builder.create());
            }
        }
    });

    listView.setOnItemClickListener(new RecyclerListView.OnItemClickListener() {
        @Override
        public void onItemClick(View view, int position) {

            if (listView == null || listView.getAdapter() == null) {
                return;
            }
            long dialog_id = 0;
            int message_id = 0;
            RecyclerView.Adapter adapter = listView.getAdapter();
            if (adapter == dialogsAdapter) {
                TLRPC.Dialog dialog = dialogsAdapter.getItem(position);
                if (dialog == null) {
                    return;
                }
                dialog_id = dialog.id;
            } else if (adapter == dialogsSearchAdapter) {
                Object obj = dialogsSearchAdapter.getItem(position);
                if (obj instanceof TLRPC.User) {
                    dialog_id = ((TLRPC.User) obj).id;
                    if (dialogsSearchAdapter.isGlobalSearch(position)) {
                        ArrayList<TLRPC.User> users = new ArrayList<>();
                        users.add((TLRPC.User) obj);
                        MessagesController.getInstance().putUsers(users, false);
                        MessagesStorage.getInstance().putUsersAndChats(users, null, false, true);
                    }
                    if (!onlySelect) {
                        dialogsSearchAdapter.putRecentSearch(dialog_id, (TLRPC.User) obj);
                    }
                } else if (obj instanceof TLRPC.Chat) {
                    if (dialogsSearchAdapter.isGlobalSearch(position)) {
                        ArrayList<TLRPC.Chat> chats = new ArrayList<>();
                        chats.add((TLRPC.Chat) obj);
                        MessagesController.getInstance().putChats(chats, false);
                        MessagesStorage.getInstance().putUsersAndChats(null, chats, false, true);
                    }
                    if (((TLRPC.Chat) obj).id > 0) {
                        dialog_id = -((TLRPC.Chat) obj).id;
                    } else {
                        dialog_id = AndroidUtilities.makeBroadcastId(((TLRPC.Chat) obj).id);
                    }
                    if (!onlySelect) {
                        dialogsSearchAdapter.putRecentSearch(dialog_id, (TLRPC.Chat) obj);
                    }
                } else if (obj instanceof TLRPC.EncryptedChat) {
                    dialog_id = ((long) ((TLRPC.EncryptedChat) obj).id) << 32;
                    if (!onlySelect) {
                        dialogsSearchAdapter.putRecentSearch(dialog_id, (TLRPC.EncryptedChat) obj);
                    }
                } else if (obj instanceof MessageObject) {
                    MessageObject messageObject = (MessageObject) obj;
                    dialog_id = messageObject.getDialogId();
                    message_id = messageObject.getId();
                    dialogsSearchAdapter.addHashtagsFromMessage(dialogsSearchAdapter.getLastSearchString());
                } else if (obj instanceof String) {
                    actionBar.openSearchField((String) obj);
                }
            }

            if (dialog_id == 0) {
                return;
            }

            if (onlySelect) {
                didSelectResult(dialog_id, true, false);
            } else {
                Bundle args = new Bundle();
                int lower_part = (int) dialog_id;
                int high_id = (int) (dialog_id >> 32);
                if (lower_part != 0) {
                    if (high_id == 1) {
                        args.putInt("chat_id", lower_part);
                    } else {
                        if (lower_part > 0) {
                            args.putInt("user_id", lower_part);
                        } else if (lower_part < 0) {
                            if (message_id != 0) {
                                TLRPC.Chat chat = MessagesController.getInstance().getChat(-lower_part);
                                if (chat != null && chat.migrated_to != null) {
                                    args.putInt("migrated_to", lower_part);
                                    lower_part = -chat.migrated_to.channel_id;
                                }
                            }
                            args.putInt("chat_id", -lower_part);
                        }
                    }
                } else {
                    args.putInt("enc_id", high_id);
                }
                if (message_id != 0) {
                    args.putInt("message_id", message_id);
                } else {
                    if (actionBar != null) {
                        actionBar.closeSearchField();
                    }
                }
                if (AndroidUtilities.isTablet()) {
                    if (openedDialogId == dialog_id && adapter != dialogsSearchAdapter) {
                        return;
                    }
                    if (dialogsAdapter != null) {
                        dialogsAdapter.setOpenedDialogId(openedDialogId = dialog_id);
                        updateVisibleRows(MessagesController.UPDATE_MASK_SELECT_DIALOG);
                    }
                }
                if (searchString != null) {
                    if (MessagesController.checkCanOpenChat(args, DialogsActivity.this)) {
                        NotificationCenter.getInstance().postNotificationName(NotificationCenter.closeChats);
                        presentFragment(new ChatActivity(args));
                    }
                } else {
                    if (MessagesController.checkCanOpenChat(args, DialogsActivity.this)) {
                        presentFragment(new ChatActivity(args));
                    }
                }
            }
        }
    });
    listView.setOnItemLongClickListener(new RecyclerListView.OnItemLongClickListener() {
        @Override
        public boolean onItemClick(View view, int position) {
            if (onlySelect || searching && searchWas || getParentActivity() == null) {
                if (searchWas && searching || dialogsSearchAdapter.isRecentSearchDisplayed()) {
                    RecyclerView.Adapter adapter = listView.getAdapter();
                    if (adapter == dialogsSearchAdapter) {
                        Object item = dialogsSearchAdapter.getItem(position);
                        if (item instanceof String || dialogsSearchAdapter.isRecentSearchDisplayed()) {
                            AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                            builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
                            builder.setMessage(LocaleController.getString("ClearSearch", R.string.ClearSearch));
                            builder.setPositiveButton(LocaleController
                                    .getString("ClearButton", R.string.ClearButton).toUpperCase(),
                                    new DialogInterface.OnClickListener() {
                                        @Override
                                        public void onClick(DialogInterface dialogInterface, int i) {
                                            if (dialogsSearchAdapter.isRecentSearchDisplayed()) {
                                                dialogsSearchAdapter.clearRecentSearch();
                                            } else {
                                                dialogsSearchAdapter.clearRecentHashtags();
                                            }
                                        }
                                    });
                            builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel),
                                    null);
                            showDialog(builder.create());
                            return true;
                        }
                    }
                }
                return false;
            }
            TLRPC.Dialog dialog;
            ArrayList<TLRPC.Dialog> dialogs = getDialogsArray();
            if (position < 0 || position >= dialogs.size()) {
                return false;
            }
            dialog = dialogs.get(position);
            selectedDialog = dialog.id;

            BottomSheet.Builder builder = new BottomSheet.Builder(getParentActivity());
            int lower_id = (int) selectedDialog;
            int high_id = (int) (selectedDialog >> 32);

            if (dialog instanceof TLRPC.TL_dialogChannel) {
                final TLRPC.Chat chat = MessagesController.getInstance().getChat(-lower_id);
                CharSequence items[];
                if (chat != null && chat.megagroup) {
                    items = new CharSequence[] {
                            LocaleController.getString("ClearHistoryCache", R.string.ClearHistoryCache),
                            chat == null || !chat.creator
                                    ? LocaleController.getString("LeaveMegaMenu", R.string.LeaveMegaMenu)
                                    : LocaleController.getString("DeleteMegaMenu", R.string.DeleteMegaMenu) };
                } else {
                    items = new CharSequence[] {
                            LocaleController.getString("ClearHistoryCache", R.string.ClearHistoryCache),
                            chat == null || !chat.creator
                                    ? LocaleController.getString("LeaveChannelMenu", R.string.LeaveChannelMenu)
                                    : LocaleController.getString("ChannelDeleteMenu",
                                            R.string.ChannelDeleteMenu),
                            LocaleController.getString("MemberBegir", R.string.MemberBegir) };
                }
                builder.setItems(items, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, final int which) {
                        AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                        builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
                        if (which == 0) {
                            if (chat != null && chat.megagroup) {
                                builder.setMessage(LocaleController.getString("AreYouSureClearHistorySuper",
                                        R.string.AreYouSureClearHistorySuper));
                            } else {
                                builder.setMessage(LocaleController.getString("AreYouSureClearHistoryChannel",
                                        R.string.AreYouSureClearHistoryChannel));
                            }
                            builder.setPositiveButton(LocaleController.getString("OK", R.string.OK),
                                    new DialogInterface.OnClickListener() {
                                        @Override
                                        public void onClick(DialogInterface dialogInterface, int i) {
                                            MessagesController.getInstance().deleteDialog(selectedDialog, 2);
                                        }
                                    });
                        } else if (which == 2) {
                            builder.setTitle(
                                    LocaleController.getString("MemberBegirTitle", R.string.MemberBegirTitle));

                            /*builder.setAdapter(new ReserveAdapter(getParentActivity(),R.layout.adapter_buy_coin,1), new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                Commands.addChannel(chat,Integer.parseInt(Defaults.MEMBERS_COUNT[which]));
                            }
                            });*/

                            /*builder.setItems(Defaults.MEMBERS_COUNT , new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                Commands.addChannel(chat,Integer.parseInt(Defaults.MEMBERS_COUNT[which]));
                            }
                            });*/
                        } else {
                            if (chat != null && chat.megagroup) {
                                if (!chat.creator) {
                                    builder.setMessage(LocaleController.getString("MegaLeaveAlert",
                                            R.string.MegaLeaveAlert));
                                } else {
                                    builder.setMessage(LocaleController.getString("MegaDeleteAlert",
                                            R.string.MegaDeleteAlert));
                                }
                            } else {
                                if (chat == null || !chat.creator) {
                                    builder.setMessage(LocaleController.getString("ChannelLeaveAlert",
                                            R.string.ChannelLeaveAlert));
                                } else {
                                    builder.setMessage(LocaleController.getString("ChannelDeleteAlert",
                                            R.string.ChannelDeleteAlert));
                                }
                            }
                            builder.setPositiveButton(LocaleController.getString("OK", R.string.OK),
                                    new DialogInterface.OnClickListener() {
                                        @Override
                                        public void onClick(DialogInterface dialogInterface, int i) {
                                            MessagesController.getInstance().deleteUserFromChat(
                                                    (int) -selectedDialog, UserConfig.getCurrentUser(), null);
                                            if (AndroidUtilities.isTablet()) {
                                                NotificationCenter.getInstance().postNotificationName(
                                                        NotificationCenter.closeChats, selectedDialog);
                                            }
                                        }
                                    });
                        }
                        builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
                        showDialog(builder.create());
                    }
                });
                showDialog(builder.create());
            } else {
                final boolean isChat = lower_id < 0 && high_id != 1;
                TLRPC.User user = null;
                if (!isChat && lower_id > 0 && high_id != 1) {
                    user = MessagesController.getInstance().getUser(lower_id);
                }
                final boolean isBot = user != null && user.bot;
                builder.setItems(
                        new CharSequence[] { LocaleController.getString("ClearHistory", R.string.ClearHistory),
                                isChat ? LocaleController.getString("DeleteChat", R.string.DeleteChat)
                                        : isBot ? LocaleController.getString("DeleteAndStop",
                                                R.string.DeleteAndStop)
                                                : LocaleController.getString("Delete", R.string.Delete) },
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, final int which) {
                                AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                                builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
                                if (which == 0) {
                                    builder.setMessage(LocaleController.getString("AreYouSureClearHistory",
                                            R.string.AreYouSureClearHistory));
                                } else {
                                    if (isChat) {
                                        builder.setMessage(LocaleController.getString("AreYouSureDeleteAndExit",
                                                R.string.AreYouSureDeleteAndExit));
                                    } else {
                                        builder.setMessage(LocaleController.getString(
                                                "AreYouSureDeleteThisChat", R.string.AreYouSureDeleteThisChat));
                                    }
                                }
                                builder.setPositiveButton(LocaleController.getString("OK", R.string.OK),
                                        new DialogInterface.OnClickListener() {
                                            @Override
                                            public void onClick(DialogInterface dialogInterface, int i) {
                                                if (which != 0) {
                                                    if (isChat) {
                                                        TLRPC.Chat currentChat = MessagesController
                                                                .getInstance().getChat((int) -selectedDialog);
                                                        if (currentChat != null
                                                                && ChatObject.isNotInChat(currentChat)) {
                                                            MessagesController.getInstance()
                                                                    .deleteDialog(selectedDialog, 0);
                                                        } else {
                                                            MessagesController.getInstance().deleteUserFromChat(
                                                                    (int) -selectedDialog,
                                                                    MessagesController.getInstance().getUser(
                                                                            UserConfig.getClientUserId()),
                                                                    null);
                                                        }
                                                    } else {
                                                        MessagesController.getInstance()
                                                                .deleteDialog(selectedDialog, 0);
                                                    }
                                                    if (isBot) {
                                                        MessagesController.getInstance()
                                                                .blockUser((int) selectedDialog);
                                                    }
                                                    if (AndroidUtilities.isTablet()) {
                                                        NotificationCenter.getInstance().postNotificationName(
                                                                NotificationCenter.closeChats, selectedDialog);
                                                    }
                                                } else {
                                                    MessagesController.getInstance()
                                                            .deleteDialog(selectedDialog, 1);
                                                }
                                            }
                                        });
                                builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel),
                                        null);
                                showDialog(builder.create());
                            }
                        });
                showDialog(builder.create());
            }
            return true;
        }
    });

    searchEmptyView = new EmptyTextProgressView(context);
    searchEmptyView.setVisibility(View.GONE);
    searchEmptyView.setShowAtCenter(true);
    searchEmptyView.setText(LocaleController.getString("NoResult", R.string.NoResult));
    frameLayout.addView(searchEmptyView,
            LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));

    emptyView = new LinearLayout(context);
    emptyView.setOrientation(LinearLayout.VERTICAL);
    emptyView.setVisibility(View.GONE);
    emptyView.setGravity(Gravity.CENTER);
    frameLayout.addView(emptyView,
            LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
    emptyView.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            return true;
        }
    });

    TextView textView = new TextView(context);
    textView.setText(LocaleController.getString("NoChats", R.string.NoChats));
    textView.setTextColor(0xff959595);
    textView.setGravity(Gravity.CENTER);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20);
    emptyView.addView(textView,
            LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT));

    textView = new TextView(context);
    String help = LocaleController.getString("NoChatsHelp", R.string.NoChatsHelp);
    if (AndroidUtilities.isTablet() && !AndroidUtilities.isSmallTablet()) {
        help = help.replace('\n', ' ');
    }
    textView.setText(help);
    textView.setTextColor(0xff959595);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15);
    textView.setGravity(Gravity.CENTER);
    textView.setPadding(AndroidUtilities.dp(8), AndroidUtilities.dp(6), AndroidUtilities.dp(8), 0);
    textView.setLineSpacing(AndroidUtilities.dp(2), 1);
    emptyView.addView(textView,
            LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT));

    progressView = new ProgressBar(context);
    progressView.setVisibility(View.GONE);
    frameLayout.addView(progressView,
            LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER));

    floatingButton = new ImageView(context);
    floatingButton.setVisibility(onlySelect ? View.GONE : View.VISIBLE);
    floatingButton.setScaleType(ImageView.ScaleType.CENTER);
    floatingButton.setBackgroundResource(R.drawable.floating_states);
    floatingButton.setImageResource(R.drawable.floating_pencil);
    if (Build.VERSION.SDK_INT >= 21) {
        StateListAnimator animator = new StateListAnimator();
        animator.addState(new int[] { android.R.attr.state_pressed },
                ObjectAnimator
                        .ofFloat(floatingButton, "translationZ", AndroidUtilities.dp(2), AndroidUtilities.dp(4))
                        .setDuration(200));
        animator.addState(new int[] {},
                ObjectAnimator
                        .ofFloat(floatingButton, "translationZ", AndroidUtilities.dp(4), AndroidUtilities.dp(2))
                        .setDuration(200));
        floatingButton.setStateListAnimator(animator);
        floatingButton.setOutlineProvider(new ViewOutlineProvider() {
            @SuppressLint("NewApi")
            @Override
            public void getOutline(View view, Outline outline) {
                outline.setOval(0, 0, AndroidUtilities.dp(56), AndroidUtilities.dp(56));
            }
        });
    }
    frameLayout.addView(floatingButton,
            LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT,
                    (LocaleController.isRTL ? Gravity.LEFT : Gravity.RIGHT) | Gravity.BOTTOM,
                    LocaleController.isRTL ? 14 : 0, 0, LocaleController.isRTL ? 0 : 14, 14));
    floatingButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Bundle args = new Bundle();
            args.putBoolean("destroyAfterSelect", true);
            presentFragment(new ContactsActivity(args));
        }
    });

    listView.setOnScrollListener(new RecyclerView.OnScrollListener() {
        @Override
        public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
            if (newState == RecyclerView.SCROLL_STATE_DRAGGING && searching && searchWas) {
                AndroidUtilities.hideKeyboard(getParentActivity().getCurrentFocus());
            }
        }

        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            int firstVisibleItem = layoutManager.findFirstVisibleItemPosition();
            int visibleItemCount = Math.abs(layoutManager.findLastVisibleItemPosition() - firstVisibleItem) + 1;
            int totalItemCount = recyclerView.getAdapter().getItemCount();

            if (searching && searchWas) {
                if (visibleItemCount > 0 && layoutManager.findLastVisibleItemPosition() == totalItemCount - 1
                        && !dialogsSearchAdapter.isMessagesSearchEndReached()) {
                    dialogsSearchAdapter.loadMoreSearchMessages();
                }
                return;
            }
            if (visibleItemCount > 0) {
                if (layoutManager.findLastVisibleItemPosition() >= getDialogsArray().size() - 10) {
                    MessagesController.getInstance().loadDialogs(-1, 100,
                            !MessagesController.getInstance().dialogsEndReached);
                }
            }

            if (floatingButton.getVisibility() != View.GONE) {
                final View topChild = recyclerView.getChildAt(0);
                int firstViewTop = 0;
                if (topChild != null) {
                    firstViewTop = topChild.getTop();
                }
                boolean goingDown;
                boolean changed = true;
                if (prevPosition == firstVisibleItem) {
                    final int topDelta = prevTop - firstViewTop;
                    goingDown = firstViewTop < prevTop;
                    changed = Math.abs(topDelta) > 1;
                } else {
                    goingDown = firstVisibleItem > prevPosition;
                }
                if (changed && scrollUpdated) {
                    hideFloatingButton(goingDown);
                }
                prevPosition = firstVisibleItem;
                prevTop = firstViewTop;
                scrollUpdated = true;
            }
        }
    });

    if (searchString == null) {
        dialogsAdapter = new DialogsAdapter(context, dialogsType);
        if (AndroidUtilities.isTablet() && openedDialogId != 0) {
            dialogsAdapter.setOpenedDialogId(openedDialogId);
        }
        listView.setAdapter(dialogsAdapter);
    }
    int type = 0;
    if (searchString != null) {
        type = 2;
    } else if (!onlySelect) {
        type = 1;
    }
    dialogsSearchAdapter = new DialogsSearchAdapter(context, type, dialogsType);
    dialogsSearchAdapter.setDelegate(new DialogsSearchAdapter.MessagesActivitySearchAdapterDelegate() {
        @Override
        public void searchStateChanged(boolean search) {
            if (searching && searchWas && searchEmptyView != null) {
                if (search) {
                    searchEmptyView.showProgress();
                } else {
                    searchEmptyView.showTextView();
                }
            }
        }
    });

    if (MessagesController.getInstance().loadingDialogs && MessagesController.getInstance().dialogs.isEmpty()) {
        searchEmptyView.setVisibility(View.GONE);
        emptyView.setVisibility(View.GONE);
        listView.setEmptyView(progressView);
    } else {
        searchEmptyView.setVisibility(View.GONE);
        progressView.setVisibility(View.GONE);
        listView.setEmptyView(emptyView);
    }
    if (searchString != null) {
        actionBar.openSearchField(searchString);
    }

    if (!onlySelect && dialogsType == 0) {
        frameLayout.addView(new PlayerView(context, this), LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT,
                39, Gravity.TOP | Gravity.LEFT, 0, -36, 0, 0));
    }

    //        fragmentView = Views.getTabLayout((FragmentActivity) context, this, frameLayout);
    return fragmentView;
}

From source file:kr.wdream.ui.ActionBar.BottomSheet.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Window window = getWindow();/*from w  ww.  j  a  v  a2  s  . c  o m*/
    window.setWindowAnimations(kr.wdream.storyshop.R.style.DialogNoAnimation);
    setContentView(container, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    if (containerView == null) {
        containerView = new FrameLayout(getContext()) {
            @Override
            public boolean hasOverlappingRendering() {
                return false;
            }
        };
        containerView.setBackgroundDrawable(shadowDrawable);
        containerView.setPadding(backgroundPaddingLeft,
                (applyTopPadding ? AndroidUtilities.dp(8) : 0) + backgroundPaddingTop, backgroundPaddingLeft,
                (applyBottomPadding ? AndroidUtilities.dp(8) : 0));
    }
    if (Build.VERSION.SDK_INT >= 21) {
        containerView.setFitsSystemWindows(true);
    }
    containerView.setVisibility(View.INVISIBLE);
    container.addView(containerView, 0,
            LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.BOTTOM));

    if (customView != null) {
        if (customView.getParent() != null) {
            ViewGroup viewGroup = (ViewGroup) customView.getParent();
            viewGroup.removeView(customView);
        }
        containerView.addView(customView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT,
                LayoutHelper.WRAP_CONTENT, Gravity.LEFT | Gravity.TOP));
    } else {
        int topOffset = 0;
        if (title != null) {
            TextView titleView = new TextView(getContext());
            titleView.setLines(1);
            titleView.setSingleLine(true);
            titleView.setText(title);
            titleView.setTextColor(0xff757575);
            titleView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
            titleView.setEllipsize(TextUtils.TruncateAt.MIDDLE);
            titleView.setPadding(AndroidUtilities.dp(16), 0, AndroidUtilities.dp(16), AndroidUtilities.dp(8));
            titleView.setGravity(Gravity.CENTER_VERTICAL);
            containerView.addView(titleView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48));
            titleView.setOnTouchListener(new View.OnTouchListener() {
                @Override
                public boolean onTouch(View v, MotionEvent event) {
                    return true;
                }
            });
            topOffset += 48;
        }
        if (items != null) {
            FrameLayout rowLayout = null;
            int lastRowLayoutNum = 0;
            for (int a = 0; a < items.length; a++) {
                BottomSheetCell cell = new BottomSheetCell(getContext(), 0);
                cell.setTextAndIcon(items[a], itemIcons != null ? itemIcons[a] : 0);
                containerView.addView(cell, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48,
                        Gravity.LEFT | Gravity.TOP, 0, topOffset, 0, 0));
                topOffset += 48;
                cell.setTag(a);
                cell.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        dismissWithButtonClick((Integer) v.getTag());
                    }
                });
                itemViews.add(cell);
            }
        }
    }

    WindowManager.LayoutParams params = window.getAttributes();
    params.width = ViewGroup.LayoutParams.MATCH_PARENT;
    params.gravity = Gravity.TOP | Gravity.LEFT;
    params.dimAmount = 0;
    params.flags &= ~WindowManager.LayoutParams.FLAG_DIM_BEHIND;
    if (!focusable) {
        params.flags |= WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
    }
    params.height = ViewGroup.LayoutParams.MATCH_PARENT;
    window.setAttributes(params);
}