Example usage for android.widget ScrollView post

List of usage examples for android.widget ScrollView post

Introduction

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

Prototype

public boolean post(Runnable action) 

Source Link

Document

Causes the Runnable to be added to the message queue.

Usage

From source file:au.org.ala.fielddata.mobile.CollectSurveyData.java

public void scrollTo(final Attribute attribute) {
    pager.post(new Runnable() {
        public void run() {

            Binder binder = (Binder) surveyViewModel.getAttributeListener(attribute);
            View boundView = binder.getView();
            ViewParent parent = boundView.getParent();
            while (parent != null && !(parent instanceof ScrollView)) {
                parent = parent.getParent();
            }//from ww  w.j a va2  s.c  om

            if (parent != null) {
                final ScrollView view = (ScrollView) parent;
                final Rect r = new Rect();

                view.offsetDescendantRectToMyCoords((View) boundView.getParent(), r);
                view.post(new Runnable() {
                    public void run() {
                        view.scrollTo(0, r.bottom);
                    }
                });

            }
        }
    });
}

From source file:com.pranavpandey.smallapp.dialog.ActionDialog.java

/**
 * Creates a {@link ActionDialog} with the arguments supplied to the
 * constructor by using the supplied adapter.
 *
 * @param rootView Root view to which the dialog should attach.
 *//*from  w  w w  .j  ava 2  s  . co m*/
public void createDialog(@NonNull View rootView) {
    if (mType == Type.GRID) {
        mView = mInflater.inflate(R.layout.sas_dialog_action_grid, new LinearLayout(mContext), false);
        mActionGridView = (HeaderGridView) mView.findViewById(R.id.action_grid);

        if (mExtraInfo) {
            ((ColoredTextView) mView.findViewById(R.id.extra_info_desc)).setText(mExtraInfoText);
            ((ColoredImageView) mView.findViewById(R.id.extra_info_icon)).setImageDrawable(mExtraInfoIcon);
            mActionGridView.setExpanded(true);

            if (mExtraInfoListener != null) {
                mView.findViewById(R.id.extra_info_layout).setOnClickListener(new OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        mExtraInfoListener.onExtraInfoClick(v);

                        autoDismiss();
                    }
                });
            }

            mView.findViewById(R.id.extra_info_layout).setVisibility(View.VISIBLE);

            final ScrollView scrollView = (ScrollView) mView.findViewById(R.id.action_grid_scroll);
            scrollView.post(new Runnable() {
                @Override
                public void run() {
                    scrollView.smoothScrollTo(0, 0);
                }
            });
        }

        mActionGridView.setAdapter(mAdapter);
        mActionGridView.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                if (mActionItemListener != null) {
                    mActionItemListener.onActionItemClick(mDialog, mAdapter, parent, view, position, id);
                }

                autoDismiss();
            }
        });
    } else {
        mView = mInflater.inflate(R.layout.sas_dialog_action_list, new LinearLayout(mContext), false);
        mActionListView = (ListView) mView.findViewById(R.id.action_list);

        if (mExtraInfo) {
            View mHeader = mInflater.inflate(R.layout.sas_dialog_extra_info_list, mActionListView, false);
            ((ColoredTextView) mHeader.findViewById(R.id.extra_info_desc)).setText(mExtraInfoText);
            ((ColoredImageView) mHeader.findViewById(R.id.extra_info_icon)).setImageDrawable(mExtraInfoIcon);

            mActionListView.addHeaderView(mHeader, null, mExtraInfoListener != null ? true : false);
        }

        mActionListView.setAdapter(mAdapter);
        mActionListView.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                if (mExtraInfo) {
                    position--;
                    if (position < 0) {
                        if (mExtraInfoListener != null) {
                            mExtraInfoListener.onExtraInfoClick(view);

                            autoDismiss();
                        }
                        return;
                    }
                }

                if (mActionItemListener != null) {
                    mActionItemListener.onActionItemClick(mDialog, mAdapter, parent, view, position, id);
                }

                autoDismiss();
            }
        });
    }

    if (mCheckButtonLayout) {
        final TextView chkText = (TextView) mView.findViewById(R.id.check_text);
        final View chkLayout = (View) mView.findViewById(R.id.check_layout);
        final CompoundButton chkButton = (CompoundButton) mView.findViewById(R.id.check_button);

        chkText.setText(mCheckButtonText);
        chkLayout.setVisibility(View.VISIBLE);

        chkLayout.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                mCheckButtonState = !chkButton.isChecked();
                chkButton.setChecked(mCheckButtonState);

                if (mCheckButtonListener != null) {
                    mCheckButtonListener.onCheckButtonChanged(chkLayout, chkButton, chkButton.isChecked(),
                            chkText);
                }
            }
        });

        chkButton.setChecked(mCheckButtonState);
    }

    mDialog = SmallUtils.createDialog(mDialogBuilder.create(), rootView.getWindowToken(), mView);
}

From source file:com.wubydax.dbeditor.TableValuesFragment.java

private void showDialog(final String key, final String value, final int position) {
    @SuppressLint("InflateParams")
    View view = LayoutInflater.from(getActivity()).inflate(R.layout.dialog_layout, null, false);
    TextView keyText = (TextView) view.findViewById(R.id.textKey);
    final EditText editText = (EditText) view.findViewById(R.id.valueEditText);
    final ScrollView scroll = (ScrollView) view.findViewById(R.id.ScrollView1);
    if (value.matches("\\d+(?:\\.\\d+)?")) {
        editText.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);
        editText.setSingleLine(true);/*from   ww  w.  j  a  v  a  2s .co m*/
    } else {
        editText.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.WRAP_CONTENT));
        editText.setHint(getResources().getString(R.string.enter_string));
    }
    keyText.setText(key);
    editText.setText(value);
    editText.setSelection(editText.getText().length());
    scroll.post(new Runnable() {
        @Override
        public void run() {
            scroll.fullScroll(View.FOCUS_DOWN);
        }
    });
    new AlertDialog.Builder(getActivity()).setTitle(getResources().getString(R.string.change_value))
            .setView(view).setNegativeButton(android.R.string.cancel, null)
            .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    String newValue = editText.getText().toString();
                    boolean isGranted = Settings.System.canWrite(getActivity());
                    if (!isGranted) {
                        Intent grantPermission = new Intent(Settings.ACTION_MANAGE_WRITE_SETTINGS);
                        startActivity(grantPermission);
                    } else {
                        switch (mTableName) {
                        case "system":
                            Settings.System.putString(getActivity().getContentResolver(), key, newValue);
                            break;
                        case "global":
                            Settings.Global.putString(getActivity().getContentResolver(), key, newValue);
                            break;
                        case "secure":
                            Settings.Secure.putString(getActivity().getContentResolver(), key, newValue);
                            break;
                        }
                        mList.get(position).value = newValue;
                    }
                    mRecyclerView.getAdapter().notifyDataSetChanged();
                }
            }).show();
}

From source file:com.google.reviewit.ReviewChangesFragment.java

private void init() {
    SwipeRefreshLayout swipeRefreshLayout = (SwipeRefreshLayout) v(R.id.swipeRefreshLayout);
    swipeRefreshLayout.setColorSchemeColors(widgetUtil.color(R.color.progressBar));
    swipeRefreshLayout.setRefreshing(true);
    swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override//  ww  w  . j av  a2s . c  o  m
        public void onRefresh() {
            getApp().getQueryHandler().reset();
            loadAndDisplay(true);
        }
    });

    v(R.id.reloadButton).setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            reloadQuery();
        }
    });

    final View nextPageProgress = v(R.id.nextPageProgress);
    final ScrollView scrollView = (ScrollView) v(R.id.scrollView);
    scrollView.getViewTreeObserver().addOnScrollChangedListener(new ViewTreeObserver.OnScrollChangedListener() {
        @Override
        public void onScrollChanged() {
            if (isAdded() && getApp().getQueryHandler().hasNext()
                    && nextPageProgress.getVisibility() == View.GONE) {
                View lastChild = scrollView.getChildAt(scrollView.getChildCount() - 1);
                if ((lastChild.getBottom() - (scrollView.getHeight() + scrollView.getScrollY())) == 0) {
                    setVisible(nextPageProgress);
                    scrollView.post(new Runnable() {
                        @Override
                        public void run() {
                            scrollView.fullScroll(View.FOCUS_DOWN);
                            loadAndDisplay();
                        }
                    });
                }
            }
        }
    });
}

From source file:org.catrobat.paintroid.ui.BottomBar.java

private void startBottomBarAnimation() {
    final HorizontalScrollView horizontalScrollView = (HorizontalScrollView) mMainActivity
            .findViewById(R.id.bottom_bar_scroll_view);
    final ScrollView verticalScrollView = (ScrollView) mMainActivity
            .findViewById(R.id.bottom_bar_landscape_scroll_view);
    final int animationDuration = 1000;
    int orientation = mMainActivity.getResources().getConfiguration().orientation;
    if (orientation == Configuration.ORIENTATION_PORTRAIT) {
        horizontalScrollView.post(new Runnable() {
            public void run() {
                int scrollToX = (int) (getToolButtonByToolType(mCurrentToolType).getX()
                        - horizontalScrollView.getWidth() / 2.0f
                        + mMainActivity.getResources().getDimension(R.dimen.bottom_bar_button_width) / 2.0f);
                int scrollFromX = PaintroidApplication.isRTL ? horizontalScrollView.getChildAt(0).getLeft()
                        : horizontalScrollView.getChildAt(0).getRight();
                horizontalScrollView.setScrollX(scrollFromX);
                ObjectAnimator.ofInt(horizontalScrollView, "scrollX", scrollToX).setDuration(animationDuration)
                        .start();// ww w .  j  av  a  2 s.  c  o m
            }
        });
    } else if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
        verticalScrollView.post(new Runnable() {
            public void run() {
                int scrollToY = (int) (getToolButtonByToolType(mCurrentToolType).getY()
                        - verticalScrollView.getHeight() / 2.0f
                        + mMainActivity.getResources().getDimension(R.dimen.bottom_bar_landscape_button_height)
                                / 2.0f);
                int scrollFromY = verticalScrollView.getChildAt(0).getBottom();
                verticalScrollView.setScrollY(scrollFromY);
                ObjectAnimator.ofInt(verticalScrollView, "scrollY", scrollToY).setDuration(animationDuration)
                        .start();
            }
        });
    }

    delayedAnimateSelectedTool(animationDuration);
}

From source file:com.mobicage.rogerthat.plugins.messaging.ServiceMessageDetailActivity.java

protected void expandDetails() {
    // Memberdetails
    for (int id : new int[] { R.id.member_details_title, R.id.members }) {
        findViewById(id).setVisibility(View.VISIBLE);
    }/*from  w w w. j a  v a 2 s . c  om*/

    findViewById(R.id.member_summary).setVisibility(View.GONE);

    final ScrollView msgScrollView = (ScrollView) findViewById(R.id.message_scroll_view);
    msgScrollView.post(new SafeRunnable() {
        @Override
        protected void safeRun() throws Exception {
            msgScrollView.fullScroll(ScrollView.FOCUS_DOWN);
        }
    });
}