Example usage for android.view ViewTreeObserver addOnGlobalLayoutListener

List of usage examples for android.view ViewTreeObserver addOnGlobalLayoutListener

Introduction

In this page you can find the example usage for android.view ViewTreeObserver addOnGlobalLayoutListener.

Prototype

public void addOnGlobalLayoutListener(OnGlobalLayoutListener listener) 

Source Link

Document

Register a callback to be invoked when the global layout state or the visibility of views within the view tree changes

Usage

From source file:com.tengio.FloatingSearchView.java

private void setupQueryBar() {

    mSearchInput.setTextColor(mSearchInputTextColor);
    mSearchInput.setHintTextColor(mSearchInputHintColor);

    if (!isInEditMode() && mHostActivity != null) {
        mHostActivity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
    }/* www  .  j a  v  a2  s. co m*/

    ViewTreeObserver vto = mQuerySection.getViewTreeObserver();
    vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            Util.removeGlobalLayoutObserver(mQuerySection, this);

            inflateOverflowMenu(mMenuId);
        }
    });

    mMenuView.setMenuCallback(new MenuBuilder.Callback() {
        @Override
        public boolean onMenuItemSelected(MenuBuilder menu, MenuItem item) {

            if (mActionMenuItemListener != null) {
                mActionMenuItemListener.onActionMenuItemSelected(item);
            }

            //todo check if we should care about this return or not
            return false;
        }

        @Override
        public void onMenuModeChange(MenuBuilder menu) {
        }
    });

    mMenuView.setOnVisibleWidthChanged(new MenuView.OnVisibleWidthChangedListener() {
        @Override
        public void onItemsMenuVisibleWidthChanged(int newVisibleWidth) {

            refreshSearchInputPaddingEnd(newVisibleWidth);
        }
    });

    mMenuView.setActionIconColor(mActionMenuItemColor);
    mMenuView.setOverflowColor(mOverflowIconColor);

    mClearButton.setVisibility(View.INVISIBLE);
    mClearButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            mSearchInput.setText("");
        }
    });

    mSearchInput.addTextChangedListener(new TextWatcherAdapter() {

        public void onTextChanged(final CharSequence s, int start, int before, int count) {
            //todo investigate why this is called twice when pressing back on the keyboard

            if (mSkipTextChangeEvent || !mIsFocused) {
                mSkipTextChangeEvent = false;
            } else {
                if (mSearchInput.getText().toString().length() != 0
                        && mClearButton.getVisibility() == View.INVISIBLE) {
                    mClearButton.setAlpha(0.0f);
                    mClearButton.setVisibility(View.VISIBLE);
                    ViewCompat.animate(mClearButton).alpha(1.0f).setDuration(CLEAR_BTN_FADE_ANIM_DURATION)
                            .start();
                } else if (mSearchInput.getText().toString().length() == 0) {
                    mClearButton.setVisibility(View.INVISIBLE);
                }

                if (mQueryListener != null && mIsFocused
                        && !mOldQuery.equals(mSearchInput.getText().toString())) {
                    mQueryListener.onSearchTextChanged(mOldQuery, mSearchInput.getText().toString());
                }
            }

            mOldQuery = mSearchInput.getText().toString();
        }
    });

    mSearchInput.setOnFocusChangeListener(new TextView.OnFocusChangeListener() {
        @Override
        public void onFocusChange(View v, boolean hasFocus) {

            if (mSkipQueryFocusChangeEvent) {
                mSkipQueryFocusChangeEvent = false;
            } else if (hasFocus != mIsFocused) {
                setSearchFocusedInternal(hasFocus);
            }
        }
    });

    mSearchInput.setOnKeyboardDismissedListener(new SearchInputView.OnKeyboardDismissedListener() {
        @Override
        public void onKeyboardDismissed() {
            if (mCloseSearchOnSofteKeyboardDismiss) {
                setSearchFocusedInternal(false);
            }
        }
    });

    mSearchInput.setOnSearchKeyListener(new SearchInputView.OnKeyboardSearchKeyClickListener() {
        @Override
        public void onSearchKeyClicked() {
            if (mSearchListener != null) {
                mSearchListener.onSearchAction(getQuery());
            }
            mSkipTextChangeEvent = true;
            mSkipTextChangeEvent = true;
            if (mIsTitleSet) {
                setSearchBarTitle(getQuery());
            } else {
                setSearchText(getQuery());
            }
            setSearchFocusedInternal(false);
        }
    });

    mLeftAction.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {

            if (isSearchBarFocused()) {
                setSearchFocusedInternal(false);
            } else {
                switch (mLeftActionMode) {
                case LEFT_ACTION_MODE_SHOW_HAMBURGER:
                    toggleLeftMenu();
                    break;
                case LEFT_ACTION_MODE_SHOW_SEARCH:
                    setSearchFocusedInternal(true);
                    break;
                case LEFT_ACTION_MODE_SHOW_HOME:
                    if (mOnHomeActionClickListener != null) {
                        mOnHomeActionClickListener.onHomeClicked();
                    }
                    break;
                case LEFT_ACTION_MODE_NO_LEFT_ACTION:
                    //do nothing
                    break;
                }
            }
        }
    });

    refreshLeftIcon(false);
}

From source file:com.rareventure.gps2.reviewer.map.OsmMapGpsTrailerReviewerMapActivity.java

@Override
public void doOnCreate(Bundle savedInstanceState) {
    super.doOnCreate(savedInstanceState);

    locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

    ContextCompat.startForegroundService(this, new Intent(this, GpsTrailerService.class));

    timeAndDateSdf = new SimpleDateFormat(getString(R.string.time_and_date_format));

    GTG.cacheCreatorLock.registerReadingThread();
    try {/*from  w  w w  .j  a va  2 s  .  com*/
        /* ttt_installer:remove_line */Log.d(GTG.TAG, "OsmMapGpsTrailerReviewerMapActivity.onCreate()");

        //sometimes onDestroy forgets to be called, so we need to check for this and cleanup after the last instance
        if (reviewerStillRunning) {
            Log.w(GTG.TAG, "OsmMapGpsTrailerReviewerMapActivity: onDestroy() forgot to be called!");
            cleanup();
        }

        reviewerStillRunning = true;

        setContentView(R.layout.osm_gps_trailer_reviewer);

        osmMapView = (OsmMapView) findViewById(R.id.osmmapview);
        osmMapView.onCreate(savedInstanceState);

        initUI();

        ViewTreeObserver vto = this.findViewById(android.R.id.content).getViewTreeObserver();
        vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
            @Override
            public void onGlobalLayout() {
                initWithWorkingGetWidth();
                findViewById(android.R.id.content).getViewTreeObserver().removeGlobalOnLayoutListener(this);
                osmMapView.initAfterLayout();
            }
        });
    } finally {
        GTG.cacheCreatorLock.unregisterReadingThread();
    }
}

From source file:org.thoughtcrime.securesms.ProfileFragment.java

private void refreshLayout() {
    gDataPreferences = new GDataPreferences(getActivity());
    boolean isMyProfile = (GUtil.numberToLong(gDataPreferences.getE164Number() + "") + "")
            .contains(GUtil.numberToLong(profileId) + "");

    layout_status = (RelativeLayout) getView().findViewById(R.id.layout_status);
    layout_phone = (RelativeLayout) getView().findViewById(R.id.layout_phone);
    layout_group = (RelativeLayout) getView().findViewById(R.id.layout_member);

    statusDate = (TextView) getView().findViewById(R.id.profile__date);
    leaveGroup = (Button) getView().findViewById(R.id.buttonLeaveGroup);
    profileHeader = (TextView) getView().findViewById(R.id.profile_header);
    profileStatus = (AutoCompleteTextView) getView().findViewById(R.id.profile_status);
    xCloseButton = (ImageView) getView().findViewById(R.id.profile_close);
    imageText = (TextView) getView().findViewById(R.id.image_text);
    profilePhone = (TextView) getView().findViewById(R.id.profile_phone);
    groupMember = (ListView) getView().findViewById(R.id.selected_contacts_list);
    historyLayout = (LinearLayout) getView().findViewById(R.id.historylayout);
    historyContentTextView = (TextView) getView().findViewById(R.id.history_content);
    historyScrollView = (HorizontalScrollView) getView().findViewById(R.id.horizontal_scroll);
    recipientsPanel = (PushRecipientsPanel) getView().findViewById(R.id.recipients);
    profilePhone.setText(phonenumber);//from   w ww .jav  a  2s. c o m
    profilePicture = (ThumbnailView) getView().findViewById(R.id.profile_picture);
    phoneCall = (ImageView) getView().findViewById(R.id.phone_call);
    (getView().findViewById(R.id.contacts_button)).setOnClickListener(new AddRecipientButtonListener());
    historyLine = (RelativeLayout) getView().findViewById(R.id.layout_history);
    recipient = recipients.getPrimaryRecipient();
    attachmentAdapter = new ProfileImageTypeSelectorAdapter(getActivity());
    scrollView = (ScrollView) getView().findViewById(R.id.scrollView);
    seekBarFont = (SeekBar) getView().findViewById(R.id.seekbar_font);
    chatPartnersColor = (CheckBox) getView().findViewById(R.id.enabled_chat_partners_color);
    colorDefault = (CheckBox) getView().findViewById(R.id.color_default);
    layoutColor = (RelativeLayout) getView().findViewById(R.id.layout_color);
    floatingActionColorButton = (FloatingActionButton) getView().findViewById(R.id.fab_new_color);
    final ImageView profileStatusEdit = (ImageView) getView().findViewById(R.id.profile_status_edit);

    if (!isGroup) {
        ImageSlide slide = ProfileAccessor.getProfileAsImageSlide(getActivity(), masterSecret, profileId);
        if (slide != null && !isMyProfile) {
            if (masterSecret != null) {
                try {
                    profilePicture.setImageResource(slide, masterSecret);
                } catch (IllegalStateException e) {
                    Log.w("GDATA", "Unable to load profile image");
                }
                profileStatus.setText(ProfileAccessor.getProfileStatusForRecepient(getActivity(), profileId),
                        TextView.BufferType.EDITABLE);
                profileStatus.setEnabled(false);
                layout_status.setOnTouchListener(new View.OnTouchListener() {
                    @Override
                    public boolean onTouch(View view, MotionEvent motionEvent) {
                        profileStatusEdit.performClick();
                        return false;
                    }
                });
                statusDate.setText(GUtil.getLocalDate(
                        ProfileAccessor.getProfileUpdateTimeForRecepient(getActivity(), profileId),
                        getActivity().getApplicationContext()));
                imageText.setText(recipient.getName());
            }
            profilePicture.setThumbnailClickListener(new ThumbnailClickListener());
        } else if (ProfileAccessor.getMyProfilePicture(getActivity()).hasImage() && isMyProfile) {
            profileStatus.setText(ProfileAccessor.getProfileStatus(getActivity()),
                    TextView.BufferType.EDITABLE);
            imageText.setText(getString(R.string.MediaPreviewActivity_you));
            initColorSeekbar();
            profilePicture.setThumbnailClickListener(new ThumbnailClickListener());
            if ((ProfileAccessor.getMyProfilePicture(getActivity()).getUri() + "").equals("")) {
                profilePicture.setImageBitmap(ContactPhotoFactory.getDefaultContactPhoto(getActivity()));
            } else {
                profilePicture.setImageResource(ProfileAccessor.getMyProfilePicture(getActivity()));
            }
            historyLine.setVisibility(View.GONE);
        } else {
            imageText.setText(recipient.getName());
            profilePicture.setImageBitmap(recipient.getContactPhoto());
        }
        layout_group.setVisibility(View.GONE);
    } else {
        String groupName = recipient.getName();
        Bitmap avatar = recipient.getContactPhoto();
        String encodedGroupId = recipient.getNumber();
        if (encodedGroupId != null) {
            try {
                groupId = GroupUtil.getDecodedId(encodedGroupId);
            } catch (IOException ioe) {
                groupId = null;
            }
        }
        GroupDatabase db = DatabaseFactory.getGroupDatabase(getActivity());
        Recipients recipients = db.getGroupMembers(groupId, false);

        recipientsPanel.setPanelChangeListener(new PushRecipientsPanel.RecipientsPanelChangedListener() {
            @Override
            public void onRecipientsPanelUpdate(Recipients recipients) {
                Log.w("GDATA", "onRecipientsPanelUpdate received.");
                if (recipients != null) {
                    addAllSelectedContacts(recipients.getRecipientsList());
                    syncAdapterWithSelectedContacts();
                }
            }
        });

        if (recipients != null) {
            final List<Recipient> recipientList = recipients.getRecipientsList();
            if (recipientList != null) {
                if (existingContacts == null)
                    existingContacts = new HashSet<>(recipientList.size());
                existingContacts.addAll(recipientList);
            }
            if (recipientList != null) {
                if (existingContacts == null)
                    existingContacts = new HashSet<>(recipientList.size());
                existingContacts.addAll(recipientList);
            }

            SelectedRecipientsAdapter adapter = new SelectedRecipientsAdapter(getActivity(), android.R.id.text1,
                    new ArrayList<SelectedRecipientsAdapter.RecipientWrapper>());
            adapter.clear();

            if (existingContacts != null) {
                for (Recipient contact : existingContacts) {
                    adapter.add(new SelectedRecipientsAdapter.RecipientWrapper(contact, false));
                }
            }
            adapter.setMasterSecret(masterSecret);
            adapter.setThreadId(threadId);
            adapter.setOnRecipientDeletedListener(new SelectedRecipientsAdapter.OnRecipientDeletedListener() {
                @Override
                public void onRecipientDeleted(Recipient recipient) {
                    removeSelectedContact(recipient);
                }
            });
            groupMember.setAdapter(adapter);
            adapter.notifyDataSetChanged();
        }
        if (avatar != null) {
            profilePicture.setVisibility(View.GONE);
            getView().findViewById(R.id.profile_picture_group).setVisibility(View.VISIBLE);
            scaleImage((ImageView) getView().findViewById(R.id.profile_picture_group), avatar);
        }
        imageText.setText(groupName);
        if (profileStatusString.equals("")) {
            profileStatus.setText(groupName);
        }
        layout_phone.setVisibility(View.GONE);

        leaveGroup.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (isActiveGroup()) {
                    handleLeavePushGroup();
                } else {
                    handleDeleteThread();
                }
            }
        });
        if (!isActiveGroup()) {
            leaveGroup.setText(getString(R.string.conversation__menu_delete_thread));
        }

        heightMemberList = GUtil.setListViewHeightBasedOnChildren(groupMember);
    }
    ImageView profileImageEdit = (ImageView) getView().findViewById(R.id.profile_picture_edit);
    ImageView profileImageDelete = (ImageView) getView().findViewById(R.id.profile_picture_delete);
    if (!isMyProfile && !isGroup) {
        profileStatusEdit.setVisibility(View.GONE);
        profileImageDelete.setVisibility(View.GONE);
        profileImageEdit.setVisibility(View.GONE);
    } else {
        if (isGroup) {
            profileImageDelete.setVisibility(View.GONE);
            profileHeader.setText(getString(R.string.group_title));
        } else {
            profileImageDelete.setVisibility(View.VISIBLE);
        }
        profileStatusEdit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                profileStatus.setEnabled(!profileStatus.isEnabled());
                if (!profileStatus.isEnabled()) {
                    hasChanged = true;
                    hasLeft = false;
                    profileStatusEdit.setImageDrawable(getResources().getDrawable(R.drawable.ic_content_edit));

                    InputMethodManager imm = (InputMethodManager) getActivity()
                            .getSystemService(Context.INPUT_METHOD_SERVICE);
                    imm.hideSoftInputFromWindow(profileStatus.getWindowToken(), 0);
                    if (isGroup) {
                        new UpdateWhisperGroupAsyncTask().execute();
                    } else {
                        ProfileAccessor.setProfileStatus(getActivity(), profileStatus.getText() + "");
                    }
                } else {
                    profileStatusEdit
                            .setImageDrawable(getResources().getDrawable(R.drawable.ic_send_sms_gdata));
                    profileStatus.showDropDown();
                    profileStatus.requestFocus();
                }
            }
        });
        profileImageDelete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                hasChanged = true;
                hasLeft = false;
                ProfileAccessor.deleteMyProfilePicture(getActivity());
                refreshLayout();
                profileStatus.dismissDropDown();
                gDataPreferences.hasProfileImageChanged(true);
            }
        });
        profileImageEdit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                gDataPreferences.hasProfileImageChanged(true);
                hasChanged = true;
                hasLeft = false;
                handleAddAttachment();
            }
        });
    }
    if (isMyProfile) {
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(),
                android.R.layout.simple_dropdown_item_1line,
                getResources().getStringArray(R.array.status_suggestions));
        profileStatus.setAdapter(adapter);
        profileStatus.setCompletionHint(getString(R.string.status_hint));
        profileStatus.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                profileStatus.dismissDropDown();
            }
        });
        profileStatus.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                profileStatus.setEnabled(!profileStatus.isEnabled());
                if (!profileStatus.isEnabled()) {
                    hasChanged = true;
                    hasLeft = false;
                    profileStatusEdit.setImageDrawable(getResources().getDrawable(R.drawable.ic_content_edit));

                    InputMethodManager imm = (InputMethodManager) getActivity()
                            .getSystemService(Context.INPUT_METHOD_SERVICE);
                    imm.hideSoftInputFromWindow(profileStatus.getWindowToken(), 0);
                    if (isGroup) {
                        new UpdateWhisperGroupAsyncTask().execute();
                    } else {
                        ProfileAccessor.setProfileStatus(getActivity(), profileStatus.getText() + "");
                    }
                }
            }
        });
    } else {
        //        if(!isMyProfile) {
        setMediaHistoryImages();
    }
    xCloseButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            finishAndSave();
        }
    });
    phoneCall.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            handleDial(recipient);
        }
    });
    final RelativeLayout scrollContainer = (RelativeLayout) getView().findViewById(R.id.scrollContainer);
    final LinearLayout mainLayout = (LinearLayout) getView().findViewById(R.id.mainlayout);
    scrollView.setSmoothScrollingEnabled(true);
    ViewTreeObserver vto = scrollView.getViewTreeObserver();
    vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        public void onGlobalLayout() {
            scrollView.scrollTo(0, mainLayout.getTop() - PADDING_TOP);
        }
    });
    scrollContainer.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            // getActivity().finish();
        }
    });
    onScrollChangeListener = new ViewTreeObserver.OnScrollChangedListener() {

        @Override
        public void onScrollChanged() {
            if (BuildConfig.VERSION_CODE >= 11) {
                scrollContainer.setBackgroundColor(Color.WHITE);
                scrollContainer
                        .setAlpha((float) ((1000.0 / scrollContainer.getHeight()) * scrollView.getHeight()));
            }
            int keyboardHeight = 150;
            int paddingBottom = 250;
            int scrollViewHeight = scrollView.getHeight();
            if (getActivity().getResources()
                    .getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
                scrollViewHeight = 2 * scrollViewHeight;
            }
            int heightDiff = scrollView.getRootView().getHeight() - scrollView.getHeight();
            if (pxToDp(heightDiff) > keyboardHeight) {
                keyboardIsVisible = true;
            } else {
                keyboardIsVisible = false;
            }
            if (!keyboardIsVisible) {
                if ((mainLayout.getTop() - scrollViewHeight) > scrollView.getScrollY()
                        - pxToDp(paddingBottom)) {
                    finishAndSave();
                }
                if ((scrollViewHeight + (heightMemberList)) < (scrollView.getScrollY() - mainLayout.getTop())) {
                    finishAndSave();
                }
            }
        }
    };
    scrollView.getViewTreeObserver().addOnScrollChangedListener(onScrollChangeListener);
    scrollView.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {

            ViewTreeObserver observer = scrollView.getViewTreeObserver();
            observer.addOnScrollChangedListener(onScrollChangeListener);
            return false;
        }

    });
}

From source file:com.segma.trim.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    MobileAds.initialize(getApplicationContext(), ADMOB_KEY);
    setContentView(R.layout.activity_main);
    loadAds();/*from   w w  w. j  a  va 2 s.c  o m*/
    MEMORY_SIZE = ((ActivityManager) getSystemService(ACTIVITY_SERVICE)).getMemoryClass();
    MAX_BITMAP_PIXELS = calculateMaxBitmapPixels();
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    ipv = (ImageProcessingView) findViewById(R.id.ipv);
    loadLicense();
    loadUserSetting();
    final Runnable runnableOnTextView = new Runnable() {
        @Override
        public void run() {
            ipv.setVisibility(View.VISIBLE);
            // TODO: update pending: the image enlarges due to larger space
            rawBitmap = getSampleImage();
            rawBitmapWidth = rawBitmap.getWidth();
            rawBitmapHeight = rawBitmap.getHeight();
            STATE = STATE_PROCESSING_IMAGE;
            textView.setVisibility(View.GONE);
            ipv.process(rawBitmap);
        }
    };
    Display display = getWindowManager().getDefaultDisplay();
    Point size = new Point();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
        display.getSize(size);
        screenWidth = size.x;
        screenHeight = size.y;
    } else {
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        screenWidth = display.getWidth();
        screenHeight = display.getHeight();
    }

    initControls();
    textView = (TextView) findViewById(R.id.tv_message);
    textView.setEnabled(false);
    ViewTreeObserver viewTreeObserver = ipv.getViewTreeObserver();
    if (viewTreeObserver.isAlive()) {
        viewTreeObserver.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
            @Override
            public void onGlobalLayout() {
                ImageProcessingViewWidth = ipv.getWidth();
                ImageProcessingViewHeight = ipv.getHeight();
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                    ipv.getViewTreeObserver().removeOnGlobalLayoutListener(this);
                } else {
                    ipv.getViewTreeObserver().removeGlobalOnLayoutListener(this);
                }
                if (ImageProcessingViewHeight != 0)
                    textView.setEnabled(true);
            }
        });
    }
    textView.setText(MESSAGE_STARTUP);
    textView.setOnTouchListener(new View.OnTouchListener() {
        float original_text_size;

        @Override
        public boolean onTouch(View v, final MotionEvent event) {
            switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                original_text_size = textView.getTextSize();
                //textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, Math.round(original_text_size * 1.15));
                handlerOnTextView.postDelayed(runnableOnTextView, LONG_PRESS_TIME_ON_TEXTVIEW);
                textView.setEnabled(false);
                break;
            case MotionEvent.ACTION_MOVE:
                handlerOnTextView.removeCallbacks(runnableOnTextView);
                break;
            case MotionEvent.ACTION_UP:
                //textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, original_text_size);
                handlerOnTextView.removeCallbacks(runnableOnTextView);
                v.setEnabled(true);
                break;
            }
            return false;
        }
    });
    setSupportActionBar((Toolbar) findViewById(R.id.toolbar));
    actionBar = getSupportActionBar();
    //actionBar.setDisplayHomeAsUpEnabled(true);
    ipv.setVisibility(View.INVISIBLE);

    if (MODE_DEBUG) {
        LICENSE = LICENSE_PREMIUM;
        getPackageManager().clearPackagePreferredActivities(getApplicationContext().getPackageName());
    }
}

From source file:com.quran.labs.androidquran.widgets.spinner.SpinnerCompat.java

@Override
public void onRestoreInstanceState(Parcelable state) {
    super.onRestoreInstanceState(state);

    if (((AbsSpinnerCompat.SavedState) state).showDropdown) {
        ViewTreeObserver vto = getViewTreeObserver();
        if (vto != null) {
            final ViewTreeObserver.OnGlobalLayoutListener listener = new ViewTreeObserver.OnGlobalLayoutListener() {
                @Override/*from  w w w.ja  va 2 s.  com*/
                public void onGlobalLayout() {
                    if (!mPopup.isShowing()) {
                        mPopup.show();
                    }
                    final ViewTreeObserver vto = getViewTreeObserver();
                    if (vto != null) {
                        vto.removeGlobalOnLayoutListener(this);
                    }
                }
            };
            vto.addOnGlobalLayoutListener(listener);
        }
    }
}

From source file:uk.co.samuelwall.materialtaptargetprompt.MaterialTapTargetPrompt.java

/**
 * Adds layout listener to view parent to capture layout changes.
 *//*from ww  w  .j  ava 2s .co m*/
void addGlobalLayoutListener() {
    final ViewTreeObserver viewTreeObserver = getParentView().getViewTreeObserver();
    if (viewTreeObserver.isAlive()) {
        viewTreeObserver.addOnGlobalLayoutListener(mGlobalLayoutListener);
    }
}

From source file:android.support.v7.internal.widget.SpinnerCompat.java

@Override
public void onRestoreInstanceState(Parcelable state) {
    SavedState ss = (SavedState) state;//from ww  w  .ja  v  a 2 s.  co  m

    super.onRestoreInstanceState(ss.getSuperState());

    if (ss.showDropdown) {
        ViewTreeObserver vto = getViewTreeObserver();
        if (vto != null) {
            final ViewTreeObserver.OnGlobalLayoutListener listener = new ViewTreeObserver.OnGlobalLayoutListener() {
                @Override
                public void onGlobalLayout() {
                    if (!mPopup.isShowing()) {
                        mPopup.show();
                    }
                    final ViewTreeObserver vto = getViewTreeObserver();
                    if (vto != null) {
                        vto.removeGlobalOnLayoutListener(this);
                    }
                }
            };
            vto.addOnGlobalLayoutListener(listener);
        }
    }
}

From source file:com.arlib.floatingsearchview.FloatingSearchView.java

@Override
public void onRestoreInstanceState(Parcelable state) {
    final SavedState savedState = (SavedState) state;
    super.onRestoreInstanceState(savedState.getSuperState());

    if (savedState.isFocused) {

        mBackgroundDrawable.setAlpha(BACKGROUND_DRAWABLE_ALPHA_SEARCH_ACTIVE);
        mSkipTextChangeEvent = savedState.isFocused;
        mSkipQueryFocusChangeEvent = savedState.isFocused;
        mIsFocused = savedState.isFocused;

        mSuggestionsSection.setVisibility(VISIBLE);

        ViewTreeObserver vto = mSuggestionListContainer.getViewTreeObserver();
        vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
            @Override//from   w ww . j a  v  a2  s .co m
            public void onGlobalLayout() {
                if (Build.VERSION.SDK_INT < 16) {
                    mSuggestionListContainer.getViewTreeObserver().removeGlobalOnLayoutListener(this);
                } else {
                    mSuggestionListContainer.getViewTreeObserver().removeOnGlobalLayoutListener(this);
                }

                swapSuggestions(savedState.suggestions, false);
            }
        });

        if (savedState.mQuery.length() == 0) {

            if (mShowVoiceInput)
                changeIcon(mVoiceInputOrClearButton, mIconMic, false);
            else
                mVoiceInputOrClearButton.setVisibility(View.INVISIBLE);

        } else if (mOldQuery.length() == 0) {
            changeIcon(mVoiceInputOrClearButton, mIconClear, false);
            mVoiceInputOrClearButton.setVisibility(View.VISIBLE);
        }

        if (mShowOverFlowMenu && mHideOverflowMenuFocused)
            hideOverflowMenu(false);

        if (mShowMenuAction && !mMenuOpen)
            openMenuDrawable(mMenuBtnDrawable, false);
        else if (!mShowMenuAction)
            changeIcon(mMenuSearchOrExitButton, mIconBackArrow, false);

        adjustSearchInputPadding();

        Util.showSoftKeyboard(getContext(), mSearchInput);
    }
}

From source file:com.androzic.vnspeech.MapFragment.java

private void updateMapViewArea() {
    final ViewTreeObserver vto = map.getViewTreeObserver();
    vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
        @SuppressLint("NewApi")
        @SuppressWarnings("deprecation")
        public void onGlobalLayout() {
            View root = getView();
            Rect area = new Rect();
            map.getLocalVisibleRect(area);
            View v = root.findViewById(R.id.topbar);
            if (v != null)
                area.top = v.getBottom();
            v = root.findViewById(R.id.bottombar);
            if (v != null)
                area.bottom = v.getTop();
            if (mapLicense.isShown()) {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB && mapLicense.getRotation() != 0f)
                    area.left = mapLicense.getHeight(); // rotated view does not correctly report it's position
                else
                    area.bottom = mapLicense.getTop();
            }/*from   www. jav a  2  s .c o m*/
            v = root.findViewById(R.id.rightbar);
            if (v != null)
                area.right = v.getLeft();
            if (mapButtons.isShown()) {
                // Landscape mode
                if (v != null)
                    area.bottom = mapButtons.getTop();
                else
                    area.right = mapButtons.getLeft();
            }
            if (!area.isEmpty())
                map.updateViewArea(area);
            ViewTreeObserver ob;
            if (vto.isAlive())
                ob = vto;
            else
                ob = map.getViewTreeObserver();

            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
                ob.removeGlobalOnLayoutListener(this);
            } else {
                ob.removeOnGlobalLayoutListener(this);
            }
        }
    });
}

From source file:com.arlib.floatingsearchview.FloatingSearchView.java

@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
    super.onLayout(changed, l, t, r, b);

    if (mIsInitialLayout) {

        //we need to add 5dp to the mSuggestionsSection because we are
        //going to move it up by 5dp in order to cover the search bar's
        //shadow padding and rounded corners. We also need to add an additional 10dp to
        //mSuggestionsSection in order to hide mSuggestionListContainer's
        //rounded corners and shadow for both, top and bottom.
        int addedHeight = 3 * Util.dpToPx(CARD_VIEW_CORNERS_AND_TOP_BOTTOM_SHADOW_HEIGHT);
        final int finalHeight = mSuggestionsSection.getHeight() + addedHeight;
        mSuggestionsSection.getLayoutParams().height = finalHeight;
        mSuggestionsSection.requestLayout();
        ViewTreeObserver vto = mSuggestionListContainer.getViewTreeObserver();
        vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
            @Override//from  w  ww.j  a  v a 2s.c  om
            public void onGlobalLayout() {

                if (mSuggestionsSection.getHeight() == finalHeight) {
                    Util.removeGlobalLayoutObserver(mSuggestionListContainer, this);

                    mIsSuggestionsSectionHeightSet = true;
                    moveSuggestListToInitialPos();
                    if (mSuggestionSecHeightListener != null) {
                        mSuggestionSecHeightListener.onSuggestionSecHeightSet();
                        mSuggestionSecHeightListener = null;
                    }
                }
            }
        });

        mIsInitialLayout = false;

        refreshDimBackground();

        if (isInEditMode()) {
            inflateOverflowMenu(mMenuId);
        }
    }
}