Example usage for android.widget ScrollView smoothScrollTo

List of usage examples for android.widget ScrollView smoothScrollTo

Introduction

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

Prototype

public final void smoothScrollTo(int x, int y) 

Source Link

Document

Like #scrollTo , but scroll smoothly instead of immediately.

Usage

From source file:com.androzic.PreferencesHelpDialog.java

public static void scrollToView(final ScrollView scrollView, final View view) {
    view.requestFocus();//ww  w . j  a v  a  2  s .co m

    final Rect scrollBounds = new Rect();
    scrollView.getHitRect(new Rect());
    if (!view.getLocalVisibleRect(scrollBounds)) {
        new Handler().post(new Runnable() {
            @Override
            public void run() {
                scrollView.smoothScrollTo(0, view.getBottom());
            }
        });
    }
}

From source file:com.baidu.android.voicedemo.ActivityTouch.java

private void print(String msg) {
    txtLog.append(msg + "\n");
    ScrollView sv = (ScrollView) txtLog.getParent();
    sv.smoothScrollTo(0, 1000000);
    Log.d(TAG, "----" + msg);
}

From source file:com.QuarkLabs.BTCeClient.fragments.HomeFragment.java

@Override
@SuppressWarnings("unchecked")
public void onPriceClicked(String pair, double price) {
    try {//  w ww  . j av  a  2 s.  c om
        ScrollView scrollView = (ScrollView) getView();
        if (scrollView != null) {
            scrollView.smoothScrollTo(0, scrollView.findViewById(R.id.tradingSection).getBottom());
            String[] currencies = pair.split("/");
            EditText tradePrice = (EditText) scrollView.findViewById(R.id.TradePrice);
            tradePrice.setText(String.valueOf(price));
            Spinner tradeCurrency = (Spinner) scrollView.findViewById(R.id.TradeCurrency);
            Spinner tradePriceCurrency = (Spinner) scrollView.findViewById(R.id.TradePriceCurrency);
            tradeCurrency.setSelection(
                    ((ArrayAdapter<String>) tradeCurrency.getAdapter()).getPosition(currencies[0]));
            tradePriceCurrency.setSelection(
                    ((ArrayAdapter<String>) tradePriceCurrency.getAdapter()).getPosition(currencies[1]));
        }
    } catch (ClassCastException | NullPointerException e) {
        e.printStackTrace();
    }
}

From source file:chat.client.gui.ChatActivity.java

private void scrollDown() {
    final ScrollView scroller = (ScrollView) findViewById(R.id.scroller);
    final TextView chatField = (TextView) findViewById(R.id.chatTextView);
    scroller.smoothScrollTo(0, chatField.getBottom());
}

From source file:org.openmrs.mobile.activities.addeditpatient.AddEditPatientFragment.java

@Override
public void scrollToTop() {
    ScrollView scrollView = (ScrollView) this.getActivity().findViewById(R.id.scrollView);
    scrollView.smoothScrollTo(0, scrollView.getPaddingTop());
}

From source file:com.QuarkLabs.BTCeClient.fragments.HomeFragment.java

/**
 * Refreshes funds table with fetched data
 *
 * @param response JSONObject with funds data
 *///from ww  w . jav a  2 s .  c o  m
private void refreshFunds(JSONObject response) {
    try {
        if (response == null) {
            Toast.makeText(getActivity(), getResources().getString(R.string.GeneralErrorText),
                    Toast.LENGTH_LONG).show();
            return;
        }
        String notificationText;
        if (response.getInt("success") == 1) {

            View.OnClickListener fillAmount = new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    ScrollView scrollView = (ScrollView) getView();
                    if (scrollView != null) {
                        EditText tradeAmount = (EditText) scrollView.findViewById(R.id.TradeAmount);
                        tradeAmount.setText(((TextView) v).getText());
                        scrollView.smoothScrollTo(0, scrollView.findViewById(R.id.tradingSection).getBottom());
                    }
                }
            };

            notificationText = getResources().getString(R.string.FundsInfoUpdatedtext);
            TableLayout fundsContainer = (TableLayout) getView().findViewById(R.id.FundsContainer);
            fundsContainer.removeAllViews();
            JSONObject funds = response.getJSONObject("return").getJSONObject("funds");
            JSONArray fundsNames = response.getJSONObject("return").getJSONObject("funds").names();
            List<String> arrayList = new ArrayList<>();

            for (int i = 0; i < fundsNames.length(); i++) {
                arrayList.add(fundsNames.getString(i));
            }
            Collections.sort(arrayList);
            TableRow.LayoutParams layoutParams = new TableRow.LayoutParams(0,
                    ViewGroup.LayoutParams.MATCH_PARENT, 1);

            for (String anArrayList : arrayList) {

                TableRow row = new TableRow(getActivity());
                TextView currency = new TextView(getActivity());
                TextView amount = new TextView(getActivity());
                currency.setText(anArrayList.toUpperCase(Locale.US));
                amount.setText(funds.getString(anArrayList));
                currency.setLayoutParams(layoutParams);
                currency.setTypeface(Typeface.DEFAULT, Typeface.BOLD);
                currency.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16);
                currency.setGravity(Gravity.CENTER);
                amount.setLayoutParams(layoutParams);
                amount.setGravity(Gravity.CENTER);
                amount.setOnClickListener(fillAmount);
                row.addView(currency);
                row.addView(amount);
                fundsContainer.addView(row);
            }

        } else {
            notificationText = response.getString("error");
        }

        mCallback.makeNotification(ConstantHolder.ACCOUNT_INFO_NOTIF_ID, notificationText);

    } catch (JSONException e) {
        e.printStackTrace();
    }
}

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   ww w.ja  v a 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.air.mobilebrowser.BrowserActivity.java

/** Logs an onscreen message for debugging. */
public void logMessage(final TextView consoleView, String message, String value, int color) {
    if (mIsDebugEnabled && consoleView != null) {
        consoleView.setOnFocusChangeListener(new OnFocusChangeListener() {

            @Override/*from   w  w w. ja  v  a  2s .c o  m*/
            public void onFocusChange(View v, boolean hasFocus) {

                ViewParent parent = consoleView.getParent();
                final ScrollView scroll = (ScrollView) parent;

                new Handler().postDelayed(new Runnable() {

                    @Override
                    public void run() {

                        scroll.smoothScrollTo(0, consoleView.getMeasuredHeight() + 10);

                    }
                }, 0);

            }
        });
        Editable editable = consoleView.getEditableText();

        SpannableString str = null;

        if (editable == null) {
            editable = new SpannableStringBuilder();
            str = new SpannableString(message + ": " + value);
            str.setSpan(new ForegroundColorSpan(color), message.length() + 2,
                    message.length() + 2 + value.length(), 0);
        } else {
            str = new SpannableString("\n" + message + ": " + value);
            str.setSpan(new ForegroundColorSpan(color), message.length() + 2,
                    message.length() + 3 + value.length(), 0);
        }

        editable.append(str);

        consoleView.setText(editable, TextView.BufferType.EDITABLE);

        ViewParent parent = consoleView.getParent();
        if (parent instanceof ScrollView) {
            final ScrollView scroll = (ScrollView) parent;

            new Handler().postDelayed(new Runnable() {

                @Override
                public void run() {

                    scroll.smoothScrollTo(0, consoleView.getMeasuredHeight() + 10);

                }
            }, 1000);
        }
    }
}

From source file:com.mobicage.rogerthat.plugins.messaging.widgets.AdvancedOrderWidget.java

private void scrollToCategory(View view) {
    ScrollView v = (ScrollView) mActivity.findViewById(R.id.message_scroll_view);
    int relativeTop = getRelativeTop(v, view);
    v.smoothScrollTo(0, relativeTop);
}

From source file:com.todoroo.astrid.activity.TaskEditFragment.java

public void scrollToView(View v) {
    View child = v;/*  w  ww  .j av a  2s  .c  o m*/
    ScrollView scrollView = (ScrollView) getView().findViewById(R.id.edit_scroll);
    int top = v.getTop();
    while (!child.equals(scrollView)) {
        top += child.getTop();
        ViewParent parentView = child.getParent();
        if (parentView != null && View.class.isInstance(parentView)) {
            child = (View) parentView;
        } else {
            break;
        }
    }
    scrollView.smoothScrollTo(0, top);
}