Example usage for android.view View scrollBy

List of usage examples for android.view View scrollBy

Introduction

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

Prototype

public void scrollBy(int x, int y) 

Source Link

Document

Move the scrolled position of your view.

Usage

From source file:cn.zy.ef.refresh.utils.ScrollingUtil.java

public static void scrollAViewBy(View view, int height) {
    if (view instanceof RecyclerView)
        ((RecyclerView) view).smoothScrollBy(0, height);
    else if (view instanceof ScrollView)
        ((ScrollView) view).smoothScrollBy(0, height);
    else if (view instanceof AbsListView)
        ((AbsListView) view).smoothScrollBy(height, 150);
    else {//from  w  w w  .  j a v a2 s  .  co  m
        try {
            Method method = view.getClass().getDeclaredMethod("smoothScrollBy", Integer.class, Integer.class);
            method.invoke(view, 0, height);
        } catch (Exception e) {
            view.scrollBy(0, height);
        }
    }
}

From source file:com.ranger.xyg.library.tkrefreshlayout.utils.ScrollingUtil.java

public static void scrollAViewBy(View view, int height) {
    if (view instanceof RecyclerView)
        ((RecyclerView) view).scrollBy(0, height);
    else if (view instanceof ScrollView)
        ((ScrollView) view).smoothScrollBy(0, height);
    else if (view instanceof AbsListView)
        ((AbsListView) view).smoothScrollBy(height, 0);
    else {/*  w w  w . j a  v  a2  s  .  co m*/
        try {
            Method method = view.getClass().getDeclaredMethod("smoothScrollBy", Integer.class, Integer.class);
            method.invoke(view, 0, height);
        } catch (Exception e) {
            view.scrollBy(0, height);
        }
    }
}

From source file:com.lanma.customviewproject.utils.ScrollingUtil.java

/**viewY??
 *//*from   w ww.  j a  v  a2  s  . c  om*/
public static void scrollAViewBy(View view, int height) {
    if (view instanceof RecyclerView)
        ((RecyclerView) view).smoothScrollBy(0, height);
    else if (view instanceof ScrollView)
        ((ScrollView) view).smoothScrollBy(0, height);
    else if (view instanceof AbsListView)
        ((AbsListView) view).smoothScrollBy(height, 150);
    else {
        try {
            Method method = view.getClass().getDeclaredMethod("smoothScrollBy", Integer.class, Integer.class);
            method.invoke(view, 0, height);
        } catch (Exception e) {
            view.scrollBy(0, height);
        }
    }
}

From source file:com.geekapp.materialweather.adapter.ViewPagerRunnableAdapter.java

@Override
public void onSyncOffset(int position, final int offset, final Runnable callback) {
    final View scrollView = getScrollView(position);
    if (scrollView instanceof RecyclerView) {
        if (offset == 0) {
            ((RecyclerView) scrollView).scrollToPosition(0);
        } else {//from   www . j  a  v a2s  .  c o m
            scrollView.scrollBy(0, offset - ((RecyclerView) scrollView).computeVerticalScrollOffset());
        }
        if (callback != null) {
            callback.run();
        }
    } else if (scrollView instanceof NestedScrollView) {
        scrollView.scrollTo(0, offset);
        if (callback != null) {
            callback.run();
        }
    }
}

From source file:org.linphone.CallIncomingActivity.java

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

    if (getResources().getBoolean(R.bool.orientation_portrait_only)) {
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    }//from w w  w. j  a  v a2s  .  co m

    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    setContentView(R.layout.call_incoming);

    name = (TextView) findViewById(R.id.contact_name);
    number = (TextView) findViewById(R.id.contact_number);
    contactPicture = (ImageView) findViewById(R.id.contact_picture);

    // set this flag so this activity will stay in front of the keyguard
    int flags = WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
            | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON;
    getWindow().addFlags(flags);

    final int screenWidth = getResources().getDisplayMetrics().widthPixels;

    acceptUnlock = (LinearLayout) findViewById(R.id.acceptUnlock);
    declineUnlock = (LinearLayout) findViewById(R.id.declineUnlock);

    accept = (ImageView) findViewById(R.id.accept);
    decline = (ImageView) findViewById(R.id.decline);
    accept.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            decline.setVisibility(View.GONE);
            acceptUnlock.setVisibility(View.VISIBLE);

        }
    });

    accept.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View view, MotionEvent motionEvent) {
            float curX;
            switch (motionEvent.getAction()) {
            case MotionEvent.ACTION_DOWN:
                acceptUnlock.setVisibility(View.VISIBLE);
                decline.setVisibility(View.GONE);
                answerX = motionEvent.getX();
                break;
            case MotionEvent.ACTION_MOVE:
                curX = motionEvent.getX();
                if ((answerX - curX) >= 0)
                    view.scrollBy((int) (answerX - curX), view.getScrollY());
                answerX = curX;
                if (curX < screenWidth / 4) {
                    answer();
                    return true;
                }
                break;
            case MotionEvent.ACTION_UP:
                view.scrollTo(0, view.getScrollY());
                decline.setVisibility(View.VISIBLE);
                acceptUnlock.setVisibility(View.GONE);
                break;
            }
            return true;
        }
    });

    decline.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View view, MotionEvent motionEvent) {
            float curX;
            switch (motionEvent.getAction()) {
            case MotionEvent.ACTION_DOWN:
                declineUnlock.setVisibility(View.VISIBLE);
                accept.setVisibility(View.GONE);
                declineX = motionEvent.getX();
                break;
            case MotionEvent.ACTION_MOVE:
                curX = motionEvent.getX();
                view.scrollBy((int) (declineX - curX), view.getScrollY());
                declineX = curX;
                Log.w(curX);
                if (curX > (screenWidth / 2)) {
                    decline();
                    return true;
                }
                break;
            case MotionEvent.ACTION_UP:
                view.scrollTo(0, view.getScrollY());
                accept.setVisibility(View.VISIBLE);
                declineUnlock.setVisibility(View.GONE);
                break;

            }
            return true;
        }
    });

    decline.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            accept.setVisibility(View.GONE);
            acceptUnlock.setVisibility(View.VISIBLE);
        }
    });

    mListener = new LinphoneCoreListenerBase() {
        @Override
        public void callState(LinphoneCore lc, LinphoneCall call, State state, String message) {
            if (call == mCall && State.CallEnd == state) {
                finish();
            }
            if (state == State.StreamsRunning) {
                Log.e("CallIncommingActivity - onCreate -  State.StreamsRunning - speaker = "
                        + LinphoneManager.getLc().isSpeakerEnabled());
                // The following should not be needed except some devices need it (e.g. Galaxy S).
                LinphoneManager.getLc().enableSpeaker(LinphoneManager.getLc().isSpeakerEnabled());
            }
        }
    };

    // super.onCreate(savedInstanceState);
    instance = this;
}

From source file:co.taqat.call.CallIncomingActivity.java

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

    if (getResources().getBoolean(R.bool.orientation_portrait_only)) {
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    }/*w  w  w.j a v a  2 s  .  c om*/

    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    setContentView(R.layout.call_incoming);

    name = (TextView) findViewById(R.id.contact_name);
    number = (TextView) findViewById(R.id.contact_number);
    contactPicture = (ImageView) findViewById(R.id.contact_picture);

    // set this flag so this activity will stay in front of the keyguard
    int flags = WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
            | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON;
    getWindow().addFlags(flags);

    PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);

    final int screenWidth = getResources().getDisplayMetrics().widthPixels;

    acceptUnlock = (LinearLayout) findViewById(R.id.acceptUnlock);
    declineUnlock = (LinearLayout) findViewById(R.id.declineUnlock);

    accept = (ImageView) findViewById(R.id.accept);
    decline = (ImageView) findViewById(R.id.decline);
    accept.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            decline.setVisibility(View.GONE);
            acceptUnlock.setVisibility(View.VISIBLE);

        }
    });

    accept.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View view, MotionEvent motionEvent) {
            float curX;
            switch (motionEvent.getAction()) {
            case MotionEvent.ACTION_DOWN:
                acceptUnlock.setVisibility(View.VISIBLE);
                decline.setVisibility(View.GONE);
                answerX = motionEvent.getX();
                break;
            case MotionEvent.ACTION_MOVE:
                curX = motionEvent.getX();
                if ((answerX - curX) >= 0)
                    view.scrollBy((int) (answerX - curX), view.getScrollY());
                answerX = curX;
                if (curX < screenWidth / 4) {
                    answer();
                    return true;
                }
                break;
            case MotionEvent.ACTION_UP:
                view.scrollTo(0, view.getScrollY());
                decline.setVisibility(View.VISIBLE);
                acceptUnlock.setVisibility(View.GONE);
                break;
            }
            return true;
        }
    });

    decline.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View view, MotionEvent motionEvent) {
            float curX;
            switch (motionEvent.getAction()) {
            case MotionEvent.ACTION_DOWN:
                declineUnlock.setVisibility(View.VISIBLE);
                accept.setVisibility(View.GONE);
                declineX = motionEvent.getX();
                break;
            case MotionEvent.ACTION_MOVE:
                curX = motionEvent.getX();
                view.scrollBy((int) (declineX - curX), view.getScrollY());
                declineX = curX;
                Log.w(curX);
                if (curX > (screenWidth / 2)) {
                    decline();
                    return true;
                }
                break;
            case MotionEvent.ACTION_UP:
                view.scrollTo(0, view.getScrollY());
                accept.setVisibility(View.VISIBLE);
                declineUnlock.setVisibility(View.GONE);
                break;

            }
            return true;
        }
    });

    decline.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            accept.setVisibility(View.GONE);
            acceptUnlock.setVisibility(View.VISIBLE);
        }
    });

    mListener = new LinphoneCoreListenerBase() {
        @Override
        public void callState(LinphoneCore lc, LinphoneCall call, State state, String message) {
            if (call == mCall && State.CallEnd == state) {
                finish();
            }
            if (state == State.StreamsRunning) {
                // The following should not be needed except some devices need it (e.g. Galaxy S).
                LinphoneManager.getLc().enableSpeaker(LinphoneManager.getLc().isSpeakerEnabled());
            }
        }
    };

    super.onCreate(savedInstanceState);
    instance = this;
}