Java Code Examples for android.widget.ScrollView#post()
The following examples show how to use
android.widget.ScrollView#post() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FragmentBase.java From FairEmail with GNU General Public License v3.0 | 6 votes |
private void scrollTo() { if (scrollTo == 0) return; View view = getView(); if (view == null) return; final ScrollView scroll = view.findViewById(R.id.scroll); if (scroll == null) return; final View child = scroll.findViewById(scrollTo); if (child == null) return; scrollTo = 0; scroll.post(new Runnable() { @Override public void run() { scroll.scrollTo(0, child.getTop()); } }); }
Example 2
Source File: SketchFile.java From APDE with GNU General Public License v2.0 | 6 votes |
protected void updateEditor(EditorActivity context) { final CodeEditText code = fragment.getCodeEditText(); final HorizontalScrollView scrollerX = fragment.getCodeScrollerX(); final ScrollView scrollerY = fragment.getCodeScroller(); //Update the code area text code.setNoUndoText(getText()); //Update the code area selection code.setSelection(getSelectionStart(), getSelectionEnd()); code.post(code::updateBracketMatch); scrollerX.post(() -> scrollerX.scrollTo(getScrollX(), 0)); scrollerY.post(() -> scrollerY.scrollTo(0, getScrollY())); context.supportInvalidateOptionsMenu(); }
Example 3
Source File: LicenseActivity.java From google-authenticator-android with Apache License 2.0 | 6 votes |
@Override public void onRestoreInstanceState(Bundle savedInstanceState) { super.onRestoreInstanceState(savedInstanceState); final ScrollView scrollView = (ScrollView) findViewById(R.id.license_activity_scrollview); final int firstVisibleChar = savedInstanceState.getInt(STATE_SCROLL_POS); scrollView.post( new Runnable() { @Override public void run() { TextView textView = (TextView) findViewById(R.id.license_activity_textview); int firstVisibleLine = textView.getLayout().getLineForOffset(firstVisibleChar); int offset = textView.getLayout().getLineTop(firstVisibleLine); scrollView.scrollTo(0, offset); } }); }
Example 4
Source File: CBIActivityTerminal.java From CarBusInterface with MIT License | 5 votes |
private void terminalScroll() { if (DD) Log.d(TAG, "terminalScroll()"); final ScrollView scrollView = (ScrollView) findViewById(R.id.scrollView); scrollView.post(new Runnable() { public void run() { scrollView.smoothScrollTo(0, mTxtTerminal.getBottom()); } }); }
Example 5
Source File: ObservationFilterActivity.java From mage-android with Apache License 2.0 | 5 votes |
public void showOrHideCustomWindow() { if (timeFilter == getResources().getInteger(R.integer.time_filter_custom)) { findViewById(R.id.custom_window_view).setVisibility(View.VISIBLE); final ScrollView sv = (ScrollView)findViewById(R.id.scrollView); sv.post(new Runnable() { public void run() { sv.scrollTo(0, sv.getBottom()); } }); } else { findViewById(R.id.custom_window_view).setVisibility(View.GONE); } }
Example 6
Source File: BaseNoteFragment.java From nextcloud-notes with GNU General Public License v3.0 | 5 votes |
@Override public void onActivityCreated(@Nullable Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); final ScrollView scrollView = getScrollView(); if (scrollView != null) { this.originalScrollY = note.getScrollY(); scrollView.post(() -> scrollView.scrollTo(0, originalScrollY)); } }
Example 7
Source File: SearchableBaseNoteFragment.java From nextcloud-notes with GNU General Public License v3.0 | 5 votes |
private void jumpToOccurrence() { Layout layout = getLayout(); if (layout == null) { Log.w(TAG, "getLayout() is null"); } else if (getContent() == null || getContent().isEmpty()) { Log.w(TAG, "getContent is null or empty"); } else if (currentOccurrence < 1) { // if currentOccurrence is lower than 1, jump to last occurrence currentOccurrence = occurrenceCount; jumpToOccurrence(); } else if (searchQuery != null && !searchQuery.isEmpty()) { String currentContent = getContent().toLowerCase(); int indexOfNewText = indexOfNth(currentContent, searchQuery.toLowerCase(), 0, currentOccurrence); if (indexOfNewText <= 0) { // Search term is not n times in text // Go back to first search result if (currentOccurrence != 1) { currentOccurrence = 1; jumpToOccurrence(); } return; } String textUntilFirstOccurrence = currentContent.substring(0, indexOfNewText); int numberLine = layout.getLineForOffset(textUntilFirstOccurrence.length()); if (numberLine >= 0) { ScrollView scrollView = getScrollView(); if (scrollView != null) { scrollView.post(() -> scrollView.smoothScrollTo(0, layout.getLineTop(numberLine))); } } } }
Example 8
Source File: MainActivity.java From android-SkeletonWearableApp with Apache License 2.0 | 5 votes |
private void scroll(final int scrollDirection) { final ScrollView scrollView = (ScrollView) findViewById(R.id.scroll); scrollView.post(new Runnable() { @Override public void run() { scrollView.fullScroll(scrollDirection); } }); }
Example 9
Source File: ScrollingUtil.java From Pas with Apache License 2.0 | 5 votes |
public static void scrollToBottom(final ScrollView scrollView) { if (scrollView != null) { scrollView.post(new Runnable() { @Override public void run() { scrollView.fullScroll(ScrollView.FOCUS_DOWN); } }); } }
Example 10
Source File: MainActivity.java From Locate-driver with GNU General Public License v3.0 | 5 votes |
private void scrollTop() { final ScrollView scrollView = (ScrollView) this.findViewById(R.id.scrollview); scrollView.post(new Runnable() { public void run() { scrollView.scrollTo(0, 0); } }); }
Example 11
Source File: EditorActivity.java From APDE with GNU General Public License v2.0 | 5 votes |
/** * Add a message to the console and automatically scroll to the bottom (if the user has this feature turned on) * * @param msg */ public void postConsole(String msg) { // Check to see if we've suspended messages if (FLAG_SUSPEND_OUT_STREAM.get() && !PreferenceManager.getDefaultSharedPreferences(this).getBoolean("pref_debug_global_verbose_output", false)) { return; } final TextView tv = findViewById(R.id.console); // Add the text tv.append(msg); final ScrollView scroll = findViewById(R.id.console_scroller); final HorizontalScrollView scrollX = findViewById(R.id.console_scroller_x); // Scroll to the bottom (if the user has this feature enabled) if(PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getBoolean("pref_scroll_lock", true)) scroll.post(() -> { // Scroll to the bottom //scroll.fullScroll(ScrollView.FOCUS_DOWN); scroll.scrollTo(0, scroll.getHeight()); scrollX.post(() -> { // Don't scroll horizontally at all... // TODO This doesn't really work scrollX.scrollTo(0, 0); }); }); }
Example 12
Source File: MainActivity.java From DialogflowChat with Apache License 2.0 | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); final ScrollView scrollview = findViewById(R.id.chatScrollView); scrollview.post(() -> scrollview.fullScroll(ScrollView.FOCUS_DOWN)); chatLayout = findViewById(R.id.chatLayout); ImageView sendBtn = findViewById(R.id.sendBtn); sendBtn.setOnClickListener(this::sendMessage); queryEditText = findViewById(R.id.queryEditText); queryEditText.setOnKeyListener((view, keyCode, event) -> { if (event.getAction() == KeyEvent.ACTION_DOWN) { switch (keyCode) { case KeyEvent.KEYCODE_DPAD_CENTER: case KeyEvent.KEYCODE_ENTER: sendMessage(sendBtn); return true; default: break; } } return false; }); // Android client for older V1 --- recommend not to use this // initChatbot(); // Java V2 initV2Chatbot(); }
Example 13
Source File: MainActivity.java From astrobee_android with Apache License 2.0 | 5 votes |
private static void scrollToBottom(final ScrollView sv) { sv.post(new Runnable() { @Override public void run() { sv.fullScroll(View.FOCUS_DOWN); } }); }
Example 14
Source File: MDA_DraggedViewPager.java From DraggedViewPager with Apache License 2.0 | 5 votes |
/** * 滚动到页底部 * * @param pageIndex 页索引 */ public void scrollToPageBottom(int pageIndex) { final ScrollView scrollView = (ScrollView) container.getChildAt(pageIndex).findViewById(R.id.dvp_scroll_view); scrollView.post(new Runnable() { @Override public void run() { scrollView.fullScroll(FOCUS_DOWN); } }); }
Example 15
Source File: DrMIPSActivity.java From drmips with GNU General Public License v3.0 | 5 votes |
/** * Updates the state of the simulation controls and the values displayed. * Updates the enabled/disabled states of the simulation controls. * It also refreshes the values displayed in the tables and the datapath, * and scrolls the assembled code table to make the current instruction visible. */ private void refreshValues() { updateStepBackEnabled(); updateStepEnabled(); refreshRegistersTableValues(); refreshDataMemoryTableValues(); refreshAssembledCodeTableValues(); refreshExecTableValues(); if(datapath != null) datapath.refresh(); // Scroll the assembled code table to the current instruction int index = getCPU().getPC().getCurrentInstructionIndex(); if(index >= 0) { final ScrollView scroll = (ScrollView)findViewById(R.id.tblAssembledCodeScroll); final View row = tblAssembledCode.getChildAt(index + 1); // Scroll only if the row is out of view if(row != null && (row.getTop() < scroll.getScrollY() || row.getBottom() > (scroll.getScrollY() + scroll.getHeight()))) { scroll.post(new Runnable() { @Override public void run() { if(row.getTop() < scroll.getScrollY()) { // Row is above the visible area // > scroll up until the row is visible at the top of the ScrollView scroll.smoothScrollTo(0, row.getTop()); } else { // Row is below the visible area // > scroll down until the row is visible at the bottom of the ScrollView scroll.smoothScrollTo(0, row.getBottom() - scroll.getHeight()); } } }); } } }
Example 16
Source File: AddOrEditContactFragment.java From BlackList with Apache License 2.0 | 5 votes |
private void moveScroll() { View view = getView(); if (view != null) { final ScrollView scroll = (ScrollView) view.findViewById(R.id.scroll); scroll.post(new Runnable() { @Override public void run() { scroll.fullScroll(ScrollView.FOCUS_DOWN); } }); } }
Example 17
Source File: SMSSendFragment.java From BlackList with Apache License 2.0 | 5 votes |
private void moveScroll() { View view = getView(); if (view != null) { final ScrollView scroll = (ScrollView) view.findViewById(R.id.scroll); scroll.post(new Runnable() { @Override public void run() { scroll.fullScroll(ScrollView.FOCUS_DOWN); } }); } }
Example 18
Source File: ListenerHelper.java From Vidsta with GNU General Public License v3.0 | 5 votes |
static void createListenerLog(LinearLayout messagesContainer, String text) { String currentDateTime = new SimpleDateFormat("HH:mm:ss.SSS", Locale.getDefault()).format(new Date()); TextView textView = new TextView(messagesContainer.getContext()); textView.setTextColor(Color.WHITE); textView.setTextSize(14); textView.setText(currentDateTime + ": " + text); messagesContainer.addView(textView); final ScrollView scrollView = (ScrollView)messagesContainer.getParent(); scrollView.post(new Runnable() { public void run() { scrollView.fullScroll(ScrollView.FOCUS_DOWN); } }); }
Example 19
Source File: SecondActivity.java From MultiWindow with Apache License 2.0 | 4 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.layout_activity2); setTitle("Second Activity"); mTextView = (TextView) findViewById(R.id.textview); mScrollView = (ScrollView) findViewById(R.id.scrollview); mScrollView.post(new Runnable() { @Override public void run() { mScrollView.fullScroll(View.FOCUS_DOWN); } }); mDrawTextView = (TextView) findViewById(R.id.drag_textview); mDrawImageView = (ImageView) findViewById(R.id.drag_imageview); mDrawTextView.setOnDragListener(new View.OnDragListener() { @Override public boolean onDrag(View view, DragEvent dragEvent) { switch (dragEvent.getAction()) { case DragEvent.ACTION_DRAG_STARTED: log("ACTION_DRAG_STARTED"); break; case DragEvent.ACTION_DRAG_ENTERED: log("ACTION_DRAG_ENTERED"); break; case DragEvent.ACTION_DRAG_EXITED: log("ACTION_DRAG_EXITED"); break; case DragEvent.ACTION_DRAG_LOCATION: log("ACTION_DRAG_LOCATION"); break; case DragEvent.ACTION_DRAG_ENDED: log("ACTION_DRAG_ENDED"); break; case DragEvent.ACTION_DROP: log("ACTION_DROP"); mDrawTextView.setVisibility(View.GONE); mDrawImageView.setVisibility(View.VISIBLE); ClipData clipData = dragEvent.getClipData(); mDrawImageView.setImageURI(clipData.getItemAt(1).getUri()); Toast.makeText(mActivity, clipData.getItemAt(0).getText(), Toast.LENGTH_LONG).show(); break; default: break; } return true; } }); print("onCreate", "#ff0000", false); }
Example 20
Source File: MainFragment.java From InviZible with GNU General Public License v3.0 | 4 votes |
private synchronized void scrollToBottom(ScrollView scrollView) { scrollView.post(() -> scrollView.fullScroll(ScrollView.FOCUS_DOWN)); }