Example usage for android.view ViewGroup removeView

List of usage examples for android.view ViewGroup removeView

Introduction

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

Prototype

@Override
public void removeView(View view) 

Source Link

Document

Note: do not invoke this method from #draw(android.graphics.Canvas) , #onDraw(android.graphics.Canvas) , #dispatchDraw(android.graphics.Canvas) or any related method.

Usage

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

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

    Window window = getWindow();/*  www  . 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.apache.cordova.AndroidWebView.java

public void hideCustomView() {
    // This code is adapted from the original Android Browser code, licensed under the Apache License, Version 2.0
    Log.d(TAG, "Hiding Custom View");
    if (mCustomView == null)
        return;/* w w  w .j a v a2 s  .co m*/

    // Hide the custom view.
    mCustomView.setVisibility(View.GONE);

    // Remove the custom view from its container.
    ViewGroup parent = (ViewGroup) this.getParent();
    parent.removeView(mCustomView);
    mCustomView = null;
    mCustomViewCallback.onCustomViewHidden();

    // Show the content view.
    this.setVisibility(View.VISIBLE);
}

From source file:com.appfeel.cordova.admob.AdMobAds.java

private PluginResult executeDestroyBannerView(CallbackContext callbackContext) {
    Log.w(ADMOBADS_LOGTAG, "executeDestroyBannerView");
    final CallbackContext delayCallback = callbackContext;
    cordova.getActivity().runOnUiThread(new Runnable() {
        @Override//from   w w  w.  ja  v a 2 s  .c o m
        public void run() {
            if (adView != null) {
                ViewGroup parentView = (ViewGroup) adView.getParent();
                if (parentView != null) {
                    parentView.removeView(adView);
                }
                adView.destroy();
                adView = null;
            }
            isBannerVisible = false;
            isBannerRequested = false;
            delayCallback.success();
        }
    });
    return null;
}

From source file:com.b44t.ui.ActionBar.BottomSheet.java

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

    Window window = getWindow();/*from w w  w  . j a  v a 2  s  .co  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.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.xingjitong.DialerFragment.java

@SuppressWarnings("deprecation")
@Override//from   w  w  w.ja va  2 s  .  c  om
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    instance = this;
    handler = new Handler();
    MSG.getInstance().setFragment(this);
    if (view == null) {
        view = inflater.inflate(R.layout.dialer, container, false);

        list_ads = new ArrayList<View>();
        indicator = (CirclePageIndicator) view.findViewById(R.id.indicator);
        // ad view
        viewpager_dialer_ads = (AutoScrollViewPager) view.findViewById(R.id.viewpager_dialer_ads);
        final BitmapUtils utils = new BitmapUtils(getActivity(), "/sdcard/Download");
        utils.configDefaultLoadFailedImage(R.drawable.default_ad);
        // image ads config
        final ImageView view1 = new ImageView(getActivity());
        final ImageView view2 = new ImageView(getActivity());
        final ImageView view3 = new ImageView(getActivity());
        //         view1.setImageResource(R.drawable.ad1);
        //         view2.setImageResource(R.drawable.ad2);
        //         view3.setImageResource(R.drawable.ad3);
        //         final ImageView view4 = new ImageView(getActivity());
        //         final ImageView view5 = new ImageView(getActivity());

        view1.setScaleType(ScaleType.FIT_XY);
        view2.setScaleType(ScaleType.FIT_XY);
        view3.setScaleType(ScaleType.FIT_XY);
        //         view4.setScaleType(ScaleType.FIT_XY);
        //         view5.setScaleType(ScaleType.FIT_XY);

        android.view.ViewGroup.LayoutParams params = new LayoutParams(
                android.view.ViewGroup.LayoutParams.MATCH_PARENT, 200);

        view1.setLayoutParams(params);
        view2.setLayoutParams(params);
        view3.setLayoutParams(params);
        //         view4.setLayoutParams(params);
        //         view5.setLayoutParams(params);

        SharedPreferences prefs = getActivity().getSharedPreferences("ads", Context.MODE_PRIVATE);
        String adsString = prefs.getString("ads", null);
        if (adsString != null && adsString.length() > 0) {
            Map<String, Object> map = JsonToMapAds.getAdsList(adsString);
            if (map != null) {
                @SuppressWarnings("unchecked")
                List<Map<String, Object>> list_pau = (List<Map<String, Object>>) map.get("list");
                if (list_pau != null && list_pau.size() > 0) {
                    list2 = list_pau;
                    handler2.post(new Runnable() {

                        @Override
                        public void run() {
                            if (list2 != null && list2.size() >= 3) {
                                utils.display(view1, (String) list2.get(0).get("content"));
                                utils.display(view2, (String) list2.get(1).get("content"));
                                utils.display(view3, (String) list2.get(2).get("content"));
                                //                           view1.setOnClickListener(new MyClickListener(
                                //                                 getActivity(), (String) list2
                                //                                       .get(0).get("url")));
                                //                           view2.setOnClickListener(new MyClickListener(
                                //                                 getActivity(), (String) list2
                                //                                       .get(1).get("url")));
                                //                           view3.setOnClickListener(new MyClickListener(
                                //                                 getActivity(), (String) list2
                                //                                       .get(2).get("url")));
                            } else {
                                view1.setImageResource(R.drawable.default_ad);
                                view2.setImageResource(R.drawable.default_ad);
                                view3.setImageResource(R.drawable.default_ad);
                            }

                        }
                    });
                }
            }

        } else {
            view1.setImageResource(R.drawable.default_ad);
            view2.setImageResource(R.drawable.default_ad);
            view3.setImageResource(R.drawable.default_ad);
        }

        list_ads.add(view1);
        list_ads.add(view2);
        list_ads.add(view3);
        //         list_ads.add(view4);
        //         list_ads.add(view5);
        viewpager_dialer_ads.setAdapter(new MyAdPagerAdapter(list_ads));
        viewpager_dialer_ads.setOffscreenPageLimit(5);

        viewpager_dialer_ads.startAutoScroll();
        viewpager_dialer_ads.setInterval(5000);
        viewpager_dialer_ads.setSlideBorderMode(2);
        indicator.setViewPager(viewpager_dialer_ads);
        mAddress = (AddressText) view.findViewById(R.id.Adress);
        mAddress.setDialerFragment(this);
        mAddress.requestFocus();
        mAddress.setVisibility(View.VISIBLE);
        // yyppdial add
        dialhint = (TextView) view.findViewById(R.id.dialhint_tv);
        if (mAddress.length() == 0) {
            android.util.Log.v("yyyppdebug", "yyppdialaddress 000");
            mAddress.setVisibility(View.GONE);
            dialhint.setVisibility(View.VISIBLE);
        } else {
            android.util.Log.v("yyyppdebug", "yyppdialaddress 111");
            mAddress.requestFocus();
            mAddress.setVisibility(View.VISIBLE);
            dialhint.setVisibility(View.GONE);
        }
        // yyppdial end
        // yypp add
        Calendar c = Calendar.getInstance();
        // int month = c.get(Calendar.MONTH);
        // int date = c.get(Calendar.DATE);
        int week = c.get(Calendar.DAY_OF_WEEK);
        if (nongli == null)
            nongli = new Lunar(c);
        // nonglistr=nongli.toString();
        gonglistr = nongli.togongliString() + " ";
        nonglistr = "" + nongli.tonongliString() + " ";

        android.util.Log.v("yyppdebug", "yyppnotice dial 000");

        msg = MSG.getnewInstance(); // yyppnotice test

        android.util.Log.v("yyppdebug", "yyppnotice dialerfragment size:" + msg.msgs.size() + "");
        int drawid[] = {
                /*
                 * R.drawable.dial_notice0_img, R.drawable.dial_notice1_img,
                 * R.drawable.dial_notice2_img, R.drawable.dial_notice3_img,
                 * R.drawable.dial_notice4_img, R.drawable.dial_notice5_img,
                 * R.drawable.dial_notice6_img
                 */
        };
        // android.util.Log.v("yyppdebug", "yypp week="+week+"");
        /*
         * RelativeLayout rLayout = (RelativeLayout)
         * view.findViewById(R.id.dialer_notice_bg); Resources res =
         * getResources(); //resource handle Drawable drawable =
         * res.getDrawable(drawid[(week-1)%7]); //new Image that was added
         * to the res folder rLayout.setBackgroundDrawable(drawable);
         */

        // yypp end

        share = PreferenceManager.getDefaultSharedPreferences(getActivity());
        Bundle bundle = getArguments();
        if (bundle != null && mAddress != null) {
            int lBegin = mAddress.getSelectionStart();

            if (lBegin == -1) {
                lBegin = mAddress.length();
            }
            phone = bundle.getString("phone");
        }
        EraseButton erase = (EraseButton) view.findViewById(R.id.Erase);
        erase.setAddressWidget(mAddress);
        mCall = (CallButton) view.findViewById(R.id.Call);
        mCall.setAddressWidget(mAddress);
        if (LinphoneActivity.isInstanciated() && LinphoneManager.getLc().getCallsNb() > 0) {
            if (isCallTransferOngoing) {
                mCall.setImageResource(R.drawable.transfer_call);
            } else {
                mCall.setImageResource(R.drawable.add_call);
            }
        } else {
            mCall.setImageResource(R.drawable.call);
        }

        AddressAware numpad = (AddressAware) view.findViewById(R.id.Dialer);
        if (numpad != null) {
            numpad.setAddressWidget(mAddress);
        }

        addContactListener = new OnClickListener() {
            @Override
            public void onClick(View v) {
                //add person to contacts 
                mylistener.onClick(mAddress.getText().toString());
                LinphoneActivity.instance().displayContactsForEdition(mAddress.getText().toString());
            }
        };
        cancelListener = new OnClickListener() {
            @Override
            public void onClick(View v) {
                LinphoneActivity.instance().resetClassicMenuLayoutAndGoBackToCallIfStillRunning();
            }
        };
        transferListener = new OnClickListener() {
            @Override
            public void onClick(View v) {
                LinphoneCore lc = LinphoneManager.getLc();
                if (lc.getCurrentCall() == null) {
                    return;
                }
                lc.transferCall(lc.getCurrentCall(), mAddress.getText().toString());
                LinphoneActivity.instance().resetClassicMenuLayoutAndGoBackToCallIfStillRunning();
                isCallTransferOngoing = false;
            }
        };

        mAddContact = (ImageView) view.findViewById(R.id.addContact);
        mAddContact
                .setEnabled(!(LinphoneActivity.isInstanciated() && LinphoneManager.getLc().getCallsNb() > 0));
        resetLayout(isCallTransferOngoing);

        if (getArguments() != null) {
            shouldEmptyAddressField = false;
            String number = getArguments().getString("SipUri");
            String displayName = getArguments().getString("DisplayName");
            String photo = getArguments().getString("PhotoUri");
            mAddress.setText(number);
            if (displayName != null) {
                mAddress.setDisplayedName(displayName);
            }
            if (photo != null) {
                mAddress.setPictureUri(Uri.parse(photo));
            }
        }
        // MATCH_PARENT WRAP_CONTENT //yyppdial.test
        /*
         * pop = new PopupWindow((getActivity().getLayoutInflater().inflate(
         * R.layout.dialer_list, null)),
         * ViewGroup.LayoutParams.WRAP_CONTENT,
         * ViewGroup.LayoutParams.WRAP_CONTENT);
         */

        pop = new PopupWindow((getActivity().getLayoutInflater().inflate(R.layout.dialer_list, null)),
                ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);

        if (pop != null) {
            pop.setFocusable(true);
            pop.setBackgroundDrawable(new BitmapDrawable());
            listView = (ListView) pop.getContentView().findViewById(R.id.dialer_pop_list);
        }
        if (listView != null) {
            listView.setOnItemClickListener(new OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
                    mAddress.setDisplayedName(list.get(arg2).num);
                    mAddress.setText(list.get(arg2).num);
                    pop.dismiss();
                }
            });
        }

        // SpannableString str=new SpannableString("1234567890");
        // str.setSpan(new ForegroundColorSpan(Color.MAGENTA), 12, 15,
        // Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        showInfor = (ImageView) view.findViewById(R.id.dialer_infor_showimg1);
        if (showInfor != null) {
            showInfor.setOnClickListener(new OnClickListener() {
                @SuppressWarnings("unchecked")
                @Override
                public void onClick(View v) {
                    if (pop.isShowing()) {
                        pop.dismiss();
                    } else {
                        list = new CallInfor().getCallInfor((List<Contact>) ContactDB.Instance().getAllOb()[2],
                                CallsLogUtils.instance().getCallsLogs(), text);
                        if (list.size() == 0) {
                            return;
                        }
                        // yyyppset //yyppdal del
                        listView.setAdapter(new DialerListViewAdapter(getActivity(), list, text));
                        // pop.setWidth(view.getWidth());
                        pop.setWidth(view.getWidth() - 70);
                        pop.showAsDropDown(mAddress);

                        // yyppcall //yyppset add
                        /*
                         * ListAdapter madapter=new
                         * DialerListViewAdapter(getActivity(), list, text);
                         * //listView.setAdapter(new
                         * DialerListViewAdapter(getActivity(), list,
                         * text)); listView.setAdapter(madapter);
                         * 
                         * if (madapter.getCount()> 9) {
                         * pop.setHeight(view.getHeight()-60); } else {
                         * 
                         * pop.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT)
                         * ; } pop.showAsDropDown(mAddress);
                         */
                        // yyppcall end

                    }
                }
            });
        }

        String tmpstr1 = "";
        if (UserConfig.getInstance().loginstatus == 0)
            tmpstr1 = "";
        else
            tmpstr1 = "";

        //

        /*
         * if (msc != null) { msc.setOnClickListener(new OnClickListener() {
         * 
         * @Override public void onClick(View v) { SettingHelp mes = new
         * SettingHelp(); Bundle bundle = new Bundle();
         * bundle.putInt("type", SettingHelp.NOTICE);
         * mes.setArguments(bundle);
         * mes.setStyle(DialogFragment.STYLE_NO_TITLE,
         * DialogFragment.STYLE_NORMAL);
         * mes.show(getActivity().getSupportFragmentManager(), "mes"); } });
         * }
         */
        // yyppdial end
    }
    ViewGroup parent = (ViewGroup) view.getParent();
    if (parent != null) {
        parent.removeView(view);
    }

    // android.util.Log.i("xushuang", "<<<<2"+list2.toString());
    // views for ads

    return view;
}

From source file:im.vector.activity.CallViewActivity.java

private void saveCallView() {
    if ((null != mCall) && !mCall.getCallState().equals(IMXCall.CALL_STATE_ENDED) && (null != mCallView)
            && (null != mCallView.getParent())) {
        ViewGroup parent = (ViewGroup) mCallView.getParent();
        parent.removeView(mCallView);
        mSavedCallview = mCallView;/*from ww w  .  j  a v  a2s.c  om*/

        EventStreamService.getInstance().displayPendingCallNotification(mSession, mCall.getRoom(),
                mCall.getCallId());
        mCallView = null;
    }
}

From source file:org.telegram.ui.MessagesActivity.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    if (fragmentView == null) {
        fragmentView = inflater.inflate(R.layout.messages_list, container, false);

        messagesListViewAdapter = new MessagesAdapter(parentActivity);

        messagesListView = (ListView) fragmentView.findViewById(R.id.messages_list_view);
        messagesListView.setAdapter(messagesListViewAdapter);

        progressView = fragmentView.findViewById(R.id.progressLayout);
        messagesListViewAdapter.notifyDataSetChanged();
        searchEmptyView = (TextView) fragmentView.findViewById(R.id.searchEmptyView);
        empryView = fragmentView.findViewById(R.id.list_empty_view);

        if (MessagesController.Instance.loadingDialogs && MessagesController.Instance.dialogs.isEmpty()) {
            messagesListView.setEmptyView(null);
            searchEmptyView.setVisibility(View.GONE);
            empryView.setVisibility(View.GONE);
            progressView.setVisibility(View.VISIBLE);
        } else {//from   w w  w. j  a v  a 2s  .  co  m
            if (searching && searchWas) {
                messagesListView.setEmptyView(searchEmptyView);
                empryView.setVisibility(View.GONE);
            } else {
                messagesListView.setEmptyView(empryView);
                searchEmptyView.setVisibility(View.GONE);
            }
            progressView.setVisibility(View.GONE);
        }

        messagesListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                long dialog_id = 0;
                if (searching && searchWas) {
                    if (i >= searchResult.size()) {
                        return;
                    }
                    TLObject obj = searchResult.get(i);
                    if (obj instanceof TLRPC.User) {
                        dialog_id = ((TLRPC.User) obj).id;
                    } else if (obj instanceof TLRPC.Chat) {
                        dialog_id = -((TLRPC.Chat) obj).id;
                    } else if (obj instanceof TLRPC.EncryptedChat) {
                        dialog_id = ((long) ((TLRPC.EncryptedChat) obj).id) << 32;
                    }
                } else {
                    if (serverOnly) {
                        if (i >= MessagesController.Instance.dialogsServerOnly.size()) {
                            return;
                        }
                        TLRPC.TL_dialog dialog = MessagesController.Instance.dialogsServerOnly.get(i);
                        dialog_id = dialog.id;
                    } else {
                        if (i >= MessagesController.Instance.dialogs.size()) {
                            return;
                        }
                        TLRPC.TL_dialog dialog = MessagesController.Instance.dialogs.get(i);
                        dialog_id = dialog.id;
                    }
                }
                if (onlySelect) {
                    didSelectResult(dialog_id, true);
                } else {
                    ChatActivity fragment = new ChatActivity();
                    Bundle bundle = new Bundle();
                    int lower_part = (int) dialog_id;
                    if (lower_part != 0) {
                        if (lower_part > 0) {
                            bundle.putInt("user_id", lower_part);
                            fragment.setArguments(bundle);
                            ((ApplicationActivity) parentActivity).presentFragment(fragment,
                                    "chat" + Math.random(), false);
                        } else if (lower_part < 0) {
                            bundle.putInt("chat_id", -lower_part);
                            fragment.setArguments(bundle);
                            ((ApplicationActivity) parentActivity).presentFragment(fragment,
                                    "chat" + Math.random(), false);
                        }
                    } else {
                        int id = (int) (dialog_id >> 32);
                        bundle.putInt("enc_id", id);
                        fragment.setArguments(bundle);
                        ((ApplicationActivity) parentActivity).presentFragment(fragment, "chat" + Math.random(),
                                false);
                    }
                }
            }
        });

        messagesListView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
            @Override
            public boolean onItemLongClick(AdapterView<?> adapterView, View view, int i, long l) {
                if (onlySelect) {
                    return false;
                }
                TLRPC.TL_dialog dialog;
                if (serverOnly) {
                    if (i >= MessagesController.Instance.dialogsServerOnly.size()) {
                        return false;
                    }
                    dialog = MessagesController.Instance.dialogsServerOnly.get(i);
                } else {
                    if (i >= MessagesController.Instance.dialogs.size()) {
                        return false;
                    }
                    dialog = MessagesController.Instance.dialogs.get(i);
                }
                selectedDialog = dialog.id;

                AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity);
                builder.setTitle(getStringEntry(R.string.AppName));

                if ((int) selectedDialog < 0) {
                    builder.setItems(
                            new CharSequence[] { getStringEntry(R.string.ClearHistory),
                                    getStringEntry(R.string.DeleteChat) },
                            new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    if (which == 0) {
                                        MessagesController.Instance.deleteDialog(selectedDialog, 0, true);
                                    } else if (which == 1) {
                                        MessagesController.Instance.deleteUserFromChat((int) -selectedDialog,
                                                MessagesController.Instance.users.get(UserConfig.clientUserId),
                                                null);
                                        MessagesController.Instance.deleteDialog(selectedDialog, 0, false);
                                    }
                                }
                            });
                } else {
                    builder.setMessage(getStringEntry(R.string.DeleteChatQuestion));
                    builder.setPositiveButton(getStringEntry(R.string.Delete),
                            new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialogInterface, int i) {
                                    MessagesController.Instance.deleteDialog(selectedDialog, 0, false);
                                }
                            });
                }
                builder.setNegativeButton(getStringEntry(R.string.Cancel), null);
                builder.show().setCanceledOnTouchOutside(true);
                return true;
            }
        });

        messagesListView.setOnScrollListener(new AbsListView.OnScrollListener() {
            @Override
            public void onScrollStateChanged(AbsListView absListView, int i) {

            }

            @Override
            public void onScroll(AbsListView absListView, int firstVisibleItem, int visibleItemCount,
                    int totalItemCount) {
                if (searching && searchWas) {
                    return;
                }
                if (visibleItemCount > 0) {
                    if (absListView.getLastVisiblePosition() == MessagesController.Instance.dialogs.size()
                            && !serverOnly
                            || absListView
                                    .getLastVisiblePosition() == MessagesController.Instance.dialogsServerOnly
                                            .size()
                                    && serverOnly) {
                        MessagesController.Instance.loadDialogs(MessagesController.Instance.dialogs.size(),
                                MessagesController.Instance.dialogsServerOnly.size(), 100, true);
                    }
                }
            }
        });

        if (MessagesController.Instance.loadingDialogs) {
            progressView.setVisibility(View.VISIBLE);
        }

    } else {
        ViewGroup parent = (ViewGroup) fragmentView.getParent();
        if (parent != null) {
            parent.removeView(fragmentView);
        }
    }
    return fragmentView;
}

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

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

    Window window = getWindow();/*from www.  ja va2  s . c  om*/
    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);
}

From source file:com.simas.vc.editor.player.PlayerFragment.java

void toggleFullscreen() {
    // Disable touch listener (to prevent multiple toggles until done)
    getContainer().setOnTouchListener(null);
    final ViewGroup root = (ViewGroup) getActivity().findViewById(android.R.id.content);
    final View progressOverlay = (getActivity() instanceof MainActivity)
            ? ((MainActivity) getActivity()).getProgressOverlay()
            : null;/*from   www  . java  2s .co m*/
    if (progressOverlay != null) {
        progressOverlay.setVisibility(View.VISIBLE);
        ViewGroup progressParent = (ViewGroup) progressOverlay.getParent();
        if (progressParent != null) {
            progressParent.removeView(progressOverlay);
        }
    }

    // Toggle state
    mFullscreen = !isFullscreen();

    if (isFullscreen()) {
        // Add preview to the root view
        if (progressOverlay != null) {
            root.addView(progressOverlay);
        }

        // All APIs can go fullscreen
        getActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);

        // Low profile is only for APIs 14+
        if (Build.VERSION.SDK_INT >= 14) {
            // Enable the low profile mode
            getActivity().getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE);
        }

    } else {
        // Add preview to the default parent
        if (mDefaultContainerParent != null && progressOverlay != null) {
            mDefaultContainerParent.addView(progressOverlay);
        }

        // All APIs can go fullscreen
        getActivity().getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);

        // Low profile is only for APIs 14+
        if (Build.VERSION.SDK_INT >= 14) {
            // Remove low profile
            getActivity().getWindow().getDecorView().setSystemUiVisibility(ViewGroup.SYSTEM_UI_FLAG_VISIBLE);
        }
    }

    final Runnable changeContainerParent = new Runnable() {
        @Override
        public void run() {
            // Hide surface view while doing all the work, this is to make sure it's not being re-drawn
            mSurfaceView.setVisibility(View.GONE);

            // Controls should be hidden while working
            final boolean controlsWereShown = getControls().isShown();
            getControls().hide();

            // Video should be paused while working
            boolean playing = false;
            if (getPlayer().getState() == Player.State.STARTED) {
                // Pause if started
                playing = true;
                getPlayer().pause();
            }
            final boolean wasPlaying = playing;

            // Expand or collapse the PlayerView
            if (isFullscreen()) {
                // Save current params
                mDefaultContainerParams = new ViewGroup.LayoutParams(getContainer().getLayoutParams());

                // Remove from current parent
                mDefaultContainerParent = (ViewGroup) getContainer().getParent();
                mDefaultContainerParent.removeView(getContainer());

                // Set new params
                ViewGroup.LayoutParams params = getContainer().getLayoutParams();
                params.width = LinearLayout.LayoutParams.MATCH_PARENT;
                params.height = LinearLayout.LayoutParams.MATCH_PARENT;

                // Re-measure the SurfaceView
                invalidateSurface();

                // Add to the root view before the progressOverlay (if it's added)
                int progressIndex = root.indexOfChild(progressOverlay);
                root.addView(getContainer(), progressIndex);
                getContainer().requestFocus();
            } else {
                if (mDefaultContainerParams != null && mDefaultContainerParent != null) {
                    // Remove from current parent
                    ((ViewGroup) getContainer().getParent()).removeView(getContainer());

                    // Restore params
                    getContainer().setLayoutParams(mDefaultContainerParams);

                    // Re-measure the SurfaceView
                    invalidateSurface();

                    // Add as the first child to the default parent
                    mDefaultContainerParent.addView(getContainer(), 0);
                }
            }

            getContainer().post(new Runnable() {
                @Override
                public void run() {
                    mSurfaceView.setVisibility(View.VISIBLE);
                    // Check if fragment and player data sources match
                    if (getItem() != null
                            && getItem().getFile().getPath().equals(getPlayer().getDataSource())) {
                        switch (getPlayer().getState()) {
                        case PAUSED:
                        case PREPARED:
                        case STARTED:
                            if (wasPlaying) {
                                getPlayer().start();
                            } else {
                                updatePreview();
                            }
                            break;
                        }
                    } else {
                        setPreviewVisible(true);
                    }
                    if (controlsWereShown) {
                        getControls().show();
                    }
                    if (progressOverlay != null) {
                        progressOverlay.setVisibility(View.INVISIBLE);
                    }
                    // Re-enable touch listener
                    getContainer().post(new Runnable() {
                        @Override
                        public void run() {
                            getContainer().setOnTouchListener(PlayerFragment.this);
                        }
                    });
                }
            });
        }
    };

    if (getPlayer().getState() == Player.State.PREPARING) {
        getPlayer().addOnPreparedListener(new MediaPlayer.OnPreparedListener() {
            @Override
            public void onPrepared(MediaPlayer mp) {
                changeContainerParent.run();
            }
        });
    } else {
        changeContainerParent.run();
    }
}

From source file:org.telegram.ui.LaunchActivity.java

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

    this.setTheme(R.style.Theme_TMessages);
    getWindow().setBackgroundDrawableResource(R.drawable.transparent);
    getWindow().setFormat(PixelFormat.RGB_565);

    if (!UserConfig.clientActivated) {
        Intent intent = getIntent();//from   w w w . j ava  2  s. co  m
        if (intent != null && intent.getAction() != null && Intent.ACTION_SEND.equals(intent.getAction())
                || intent.getAction().equals(Intent.ACTION_SEND_MULTIPLE)) {
            finish();
            return;
        }
        Intent intent2 = new Intent(this, IntroActivity.class);
        startActivity(intent2);
        finish();
        return;
    }

    int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
    if (resourceId > 0) {
        Utilities.statusBarHeight = getResources().getDimensionPixelSize(resourceId);
    }

    NotificationCenter.getInstance().postNotificationName(702, this);
    currentConnectionState = ConnectionsManager.getInstance().connectionState;
    for (BaseFragment fragment : ApplicationLoader.fragmentsStack) {
        if (fragment.fragmentView != null) {
            ViewGroup parent = (ViewGroup) fragment.fragmentView.getParent();
            if (parent != null) {
                parent.removeView(fragment.fragmentView);
            }
            fragment.fragmentView = null;
        }
        fragment.parentActivity = this;
    }
    setContentView(R.layout.application_layout);
    NotificationCenter.getInstance().addObserver(this, 1234);
    NotificationCenter.getInstance().addObserver(this, 658);
    NotificationCenter.getInstance().addObserver(this, 701);
    NotificationCenter.getInstance().addObserver(this, 702);
    NotificationCenter.getInstance().addObserver(this, 703);
    NotificationCenter.getInstance().addObserver(this, GalleryImageViewer.needShowAllMedia);
    getSupportActionBar().setLogo(R.drawable.ab_icon_fixed2);

    statusView = getLayoutInflater().inflate(R.layout.updating_state_layout, null);
    statusBackground = statusView.findViewById(R.id.back_button_background);
    backStatusButton = statusView.findViewById(R.id.back_button);
    containerView = findViewById(R.id.container);
    statusText = (TextView) statusView.findViewById(R.id.status_text);
    statusBackground.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (ApplicationLoader.fragmentsStack.size() > 1) {
                onBackPressed();
            }
        }
    });

    if (ApplicationLoader.fragmentsStack.isEmpty()) {
        MessagesActivity fragment = new MessagesActivity();
        fragment.onFragmentCreate();
        ApplicationLoader.fragmentsStack.add(fragment);
    }

    handleIntent(getIntent(), false, savedInstanceState != null);
}