Example usage for android.view View post

List of usage examples for android.view View post

Introduction

In this page you can find the example usage for android.view View post.

Prototype

public boolean post(Runnable action) 

Source Link

Document

Causes the Runnable to be added to the message queue.

Usage

From source file:org.catnut.adapter.TweetAdapter.java

@Override
public void onClick(final View v) {
    v.post(new Runnable() {
        @Override/*from  w w  w.j  a  va  2s  .c  o  m*/
        public void run() {
            showPopupMenu(v);
        }
    });
}

From source file:org.jorge.cmp.ui.activity.MainActivity.java

private void initChat() {
    final View thisView = findViewById(android.R.id.content);
    registerLocalBroadcastReceiver();/*from w w w. j  a v a2s.c o m*/
    if (mAlreadyInited) {
        if (!Utils.isInternetReachable()) {
            thisView.post(new Runnable() {
                @Override
                public void run() {
                    showChatViewNoConnection();
                }
            });
        } else {
            if (!ChatIntentService.isLoggedIn()) {
                thisView.post(new Runnable() {
                    @Override
                    public void run() {
                        showChatViewLoading();
                    }
                });
                runChat();
            } else {
                thisView.post(new Runnable() {
                    @Override
                    public void run() {
                        showChatViewConnected();
                    }
                });
            }
        }
        return;
    }
    final Runnable viewRunnable;
    if (!Utils.isInternetReachable()) {
        viewRunnable = new Runnable() {
            @Override
            public void run() {
                showChatViewNoConnection();
            }
        };
    } else {
        viewRunnable = new Runnable() {
            @Override
            public void run() {
                showChatViewLoading();
            }
        };
        if (!ChatIntentService.isLoggedIn()) {
            runChat();
        }
    }
    thisView.post(viewRunnable);

    if (getIntent().getBooleanExtra(KEY_OPEN_CHAT, Boolean.FALSE) && !mSlidingLayout.isPanelExpanded()) {
        mSlidingLayout.expandPanel();
    }
}

From source file:com.xxxifan.devbox.core.base.BaseFragment.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    lifecycleSubject.onNext(FragmentEvent.CREATE_VIEW);
    Cannon.load(view);/*from w  w w . j av  a  2  s  .  c o  m*/

    onSetupFragment(view, savedInstanceState);

    if (getDataLoader() != null) {
        if (savedInstanceState != null) {
            getDataLoader().onRestoreState(savedInstanceState);
        }

        view.post(new Runnable() {
            @Override
            public void run() {
                if (getUserVisibleHint() && getDataLoader().isLazyLoadEnabled()) {
                    setUserVisibleHint(true);
                }
            }
        });
    }
}

From source file:com.simas.vc.editor.EditorFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedState) {
    View root = inflater.inflate(R.layout.fragment_editor, container, false);
    // Overlay a ProgressBar when preparing the PlayerFragment for the first time
    mProgressOverlay = root.findViewById(R.id.editor_progress_overlay);

    mPlayerFragment = (PlayerFragment) getChildFragmentManager().findFragmentById(R.id.player_fragment);

    // Queue container modifications until it's measured
    final View playerContainer = mPlayerFragment.getContainer();
    final Runnable playerResize = new Runnable() {
        @Override/*from   w  w  w.  j  a v a 2 s  .co  m*/
        public void run() {
            ViewGroup.LayoutParams params = playerContainer.getLayoutParams();
            params.width = MainActivity.sPlayerContainerSize;
            params.height = MainActivity.sPlayerContainerSize;
            playerContainer.setLayoutParams(params);

            playerContainer.post(new Runnable() {
                @Override
                public void run() {
                    modifyProgressOverlayStates(true, ProgressStates.PLAYER_CONTAINER_DRAWN);
                }
            });
        }
    };
    if (MainActivity.sPlayerContainerSize != 0) {
        playerResize.run();
    } else {
        playerContainer.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
            @Override
            public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft,
                    int oldTop, int oldRight, int oldBottom) {
                int size = Math.max(playerContainer.getWidth(), playerContainer.getHeight());
                if (size <= 0)
                    return;
                MainActivity.sPlayerContainerSize = size;
                playerContainer.removeOnLayoutChangeListener(this);
                playerResize.run();
            }
        });
    }

    mDelayedHandler.resume();

    View actions = root.findViewById(R.id.editor_actions);
    mDataMap.put(Data.ACTIONS, actions);
    mDataMap.put(Data.FILENAME, actions.findViewById(R.id.filename_value));
    mDataMap.put(Data.SIZE, actions.findViewById(R.id.size_value));
    mDataMap.put(Data.DURATION, actions.findViewById(R.id.duration_value));
    mDataMap.put(Data.STREAM_TREE, actions.findViewById(R.id.tree_view));

    if (savedState != null) {
        NavItem previousItem = savedState.getParcelable(STATE_PREVIOUS_ITEM);
        if (previousItem != null) {
            setItem(previousItem);
        }
    }

    return root;
}

From source file:com.taobao.weex.ui.component.WXSliderNeighbor.java

private void updateAdapterScaleAndAlpha(final float alpha, final float scale) {
    final List<View> pageViews = mAdapter.getViews();
    final int curPos = mViewPager.getCurrentItem();

    if (pageViews.size() > 0) {
        final View currentPage = pageViews.get(curPos);
        updateScaleAndAlpha(((ViewGroup) currentPage).getChildAt(0), 1.0F, WX_DEFAULT_MAIN_NEIGHBOR_SCALE);

        if (pageViews.size() < 2) {
            return;
        }//ww  w  .j  av a 2s  .c  o m
        //make sure View's width & height are measured.
        currentPage.post(WXThread.secure(new Runnable() {
            @Override
            public void run() {
                //change left and right page's translation
                updateNeighbor(currentPage, alpha, scale);

            }
        }));

        // make sure only display view current, left, right.
        int left = (curPos == 0) ? pageViews.size() - 1 : curPos - 1;
        int right = (curPos == pageViews.size() - 1) ? 0 : curPos + 1;
        for (int i = 0; i < mAdapter.getRealCount(); i++) {
            if (i != left && i != curPos && i != right) {
                ((ViewGroup) pageViews.get(i)).getChildAt(0).setAlpha(0F);
            }
        }
    }
}

From source file:com.taobao.weex.dom.transition.WXTransition.java

private synchronized void onTransitionAnimationEnd() {
    if (duration > 0) {
        if (transitionEndEvent != null) {
            View view = getTargetView();
            if (view != null && transitionEndEvent != null) {
                view.post(transitionEndEvent);
            }/*from  w w w.  j  a v  a  2  s. c om*/
            transitionEndEvent = null;
        }
    }
    synchronized (targetStyles) {
        if (targetStyles.size() > 0) {
            WXComponent component = getComponent();
            for (String property : properties) {
                if (targetStyles.containsKey(property)) {
                    Object targetValue = targetStyles.remove(property);
                    domObject.getStyles().put(property, targetValue);
                    if (component != null && component.getDomObject() != null) {
                        component.getDomObject().getStyles().put(property, targetValue);
                    }
                }
            }
            targetStyles.clear();
        }
    }
}

From source file:im.neon.adapters.VectorMediasViewerAdapter.java

@Override
public void setPrimaryItem(ViewGroup container, final int position, Object object) {
    if (mLatestPrimaryItemPosition != position) {
        mLatestPrimaryItemPosition = position;

        final View view = (View) object;
        mLatestPrimaryView = view;//from  w w  w .  j  ava 2 s .  co  m

        view.post(new Runnable() {
            @Override
            public void run() {
                stopPlayingVideo();
            }
        });

        view.post(new Runnable() {
            @Override
            public void run() {
                if (mHighResMediaIndex.indexOf(position) < 0) {
                    downloadHighResMedia(view, position);
                } else if (position == mAutoPlayItemAt) {
                    SlidableMediaInfo mediaInfo = mMediasMessagesList.get(position);

                    if (mediaInfo.mMessageType.equals(Message.MSGTYPE_VIDEO)) {
                        final VideoView videoView = (VideoView) view.findViewById(R.id.media_slider_videoview);
                        playVideo(view, videoView, mediaInfo.mMediaUrl, mediaInfo.mMimeType);
                    }

                    mAutoPlayItemAt = -1;
                }
            }
        });
    }
}

From source file:org.jorge.lolin1.ui.activities.ChatOverviewActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    if (savedInstanceState == null) {
        savedInstanceState = new Bundle();
    }//from   ww  w  .  j av  a  2 s.c o m
    //        getIntent().putExtra(DrawerLayoutFragmentActivity.ACTION_BAR_MENU_LAYOUT,
    //                R.menu.menu_chat_overview);
    savedInstanceState.putInt(DrawerLayoutFragmentActivity.ACTIVITY_LAYOUT, R.layout.activity_chat_overview);
    super.onCreate(savedInstanceState);
    final View thisView = findViewById(android.R.id.content);
    mViewPager = (ViewPager) findViewById(R.id.chat_overview_view_pager);
    if (mViewPager.getAdapter() == null) {
        mViewPager.setAdapter(mPagerAdapter = new ChatStatesPagerAdapter(getSupportFragmentManager()));
    }
    Runnable viewRunnable;
    registerLocalBroadcastReceiver();
    if (alreadyInited) {
        logString("debug", "Chat: rotation detected");
        if (!LoLin1Utils.isInternetReachable(getApplicationContext())) {
            thisView.post(new Runnable() {
                @Override
                public void run() {
                    showViewNoConnection();
                }
            });
        } else {
            if (!ChatIntentService.isLoggedIn()) {
                logString("debug", "Showing view loading");
                thisView.post(new Runnable() {
                    @Override
                    public void run() {
                        showViewLoading();
                    }
                });
                runChat();
            } else {
                logString("debug", "Showing view connected");
                thisView.post(new Runnable() {
                    @Override
                    public void run() {
                        showViewConnected();
                    }
                });
            }
        }
        return;
    }
    if (!LoLin1Utils.isInternetReachable(getApplicationContext())) {
        viewRunnable = new Runnable() {
            @Override
            public void run() {
                showViewNoConnection();
            }
        };
    } else {
        viewRunnable = new Runnable() {
            @Override
            public void run() {
                showViewLoading();
            }
        };
        if (!ChatIntentService.isLoggedIn()) {
            runChat();
        }
    }
    thisView.post(viewRunnable);
}

From source file:com.philliphsu.clock2.MainActivity.java

@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    final View rootView = ((ViewGroup) findViewById(android.R.id.content)).getChildAt(0);
    // http://stackoverflow.com/a/24035591/5055032
    // http://stackoverflow.com/a/3948036/5055032
    // The views in our layout have begun drawing.
    // There is no lifecycle callback that tells us when our layout finishes drawing;
    // in my own test, drawing still isn't finished by onResume().
    // Post a message in the UI events queue to be executed after drawing is complete,
    // so that we may get their dimensions.
    rootView.post(new Runnable() {
        @Override//from   w  w  w.  ja v  a 2 s .  c om
        public void run() {
            if (mViewPager.getCurrentItem() == mSectionsPagerAdapter.getCount() - 1) {
                // Restore the FAB's translationX from a previous configuration.
                mFab.setTranslationX(mViewPager.getWidth() / -2f + getFabPixelOffsetForXTranslation());
            }
        }
    });

    mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
    mViewPager.setAdapter(mSectionsPagerAdapter);
    mViewPager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        /**
         * @param position Either the current page position if the offset is increasing,
         *                 or the previous page position if it is decreasing.
         * @param positionOffset If increasing from [0, 1), scrolling right and position = currentPagePosition
         *                       If decreasing from (1, 0], scrolling left and position = (currentPagePosition - 1)
         */
        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
            Log.d(TAG, String.format("pos = %d, posOffset = %f, posOffsetPixels = %d", position, positionOffset,
                    positionOffsetPixels));
            int pageBeforeLast = mSectionsPagerAdapter.getCount() - 2;
            if (position <= pageBeforeLast) {
                if (position < pageBeforeLast) {
                    // When the scrolling is due to tab selection between multiple tabs apart,
                    // this callback is called for each intermediate page, but each of those pages
                    // will briefly register a sparsely decreasing range of positionOffsets, always
                    // from (1, 0). As such, you would notice the FAB to jump back and forth between
                    // x-positions as each intermediate page is scrolled through.
                    // This is a visual optimization that ends the translation motion, immediately
                    // returning the FAB to its target position.
                    // TODO: The animation visibly skips to the end. We could interpolate
                    // intermediate x-positions if we cared to smooth it out.
                    mFab.setTranslationX(0);
                } else {
                    // Initially, the FAB's translationX property is zero because, at its original
                    // position, it is not translated. setTranslationX() is relative to the view's
                    // left position, at its original position; this left position is taken to be
                    // the zero point of the coordinate system relative to this view. As your
                    // translationX value is increasingly negative, the view is translated left.
                    // But as translationX is decreasingly negative and down to zero, the view
                    // is translated right, back to its original position.
                    float translationX = positionOffsetPixels / -2f;
                    // NOTE: You MUST scale your own additional pixel offsets by positionOffset,
                    // or else the FAB will immediately translate by that many pixels, appearing
                    // to skip/jump.
                    translationX += positionOffset * getFabPixelOffsetForXTranslation();
                    mFab.setTranslationX(translationX);
                }
            }
        }

        @Override
        public void onPageSelected(int position) {
            Log.d(TAG, "onPageSelected");
            if (position < mSectionsPagerAdapter.getCount() - 1) {
                mFab.setImageDrawable(mAddItemDrawable);
            }
            Fragment f = mSectionsPagerAdapter.getFragment(mViewPager.getCurrentItem());
            // NOTE: This callback is fired after a rotation, right after onStart().
            // Unfortunately, the FragmentManager handling the rotation has yet to
            // tell our adapter to re-instantiate the Fragments, so our collection
            // of fragments is empty. You MUST keep this check so we don't cause a NPE.
            if (f instanceof BaseFragment) {
                ((BaseFragment) f).onPageSelected();
            }
        }
    });

    TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
    tabLayout.setupWithViewPager(mViewPager);

    ColorStateList tabIconColor = ContextCompat.getColorStateList(this, R.color.tab_icon_color);
    setTabIcon(PAGE_ALARMS, R.drawable.ic_alarm_24dp, tabIconColor);
    setTabIcon(PAGE_TIMERS, R.drawable.ic_timer_24dp, tabIconColor);
    setTabIcon(PAGE_STOPWATCH, R.drawable.ic_stopwatch_24dp, tabIconColor);

    // TODO: @OnCLick instead.
    mFab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Fragment f = mSectionsPagerAdapter.getFragment(mViewPager.getCurrentItem());
            if (f instanceof RecyclerViewFragment) {
                ((RecyclerViewFragment) f).onFabClick();
            }
        }
    });

    mAddItemDrawable = ContextCompat.getDrawable(this, R.drawable.ic_add_24dp);
    handleActionScrollToStableId(getIntent(), false);
}