public final class

PdfSearchViewModular

extends DocumentListenerFrameLayout
implements PSPDFKitViews.PSPDFView PdfSearchView
java.lang.Object
   ↳ android.view.View
     ↳ android.view.ViewGroup
       ↳ android.widget.FrameLayout
         ↳ com.pspdfkit.framework.views.utils.DocumentListenerFrameLayout
           ↳ com.pspdfkit.ui.search.PdfSearchViewModular

Class Overview

Search view sitting inside a panel that slides in above the rest of the content.

Summary

Constants
String LOG_TAG
int SEARCH_DELAY Delay waited after a call to performSearch(String) before starting the search.
[Expand]
Inherited Constants
From class android.view.ViewGroup
From class android.view.View
Fields
protected int currentPage Tracks current page of the document.
protected PdfDocument document
protected EditText inputField
protected boolean isDisplayed
protected final OnVisibilityChangedListenerManager listeners
protected Disposable searchInProgress
[Expand]
Inherited Fields
From class android.view.View
Public Constructors
PdfSearchViewModular(Context context)
PdfSearchViewModular(Context context, AttributeSet attrs)
Public Methods
void addOnVisibilityChangedListener(OnVisibilityChangedListener listener)
Adds a new listener for visibility changes.
void clearDocument()
Called by the activity when the view should unbind the previously set document.
void clearOnVisibilityChangedListeners()
Removes all previously registered visibility change listeners.
final void clearSearch()
Clears the search input field as well as any previously collected search results.
int getBackgroundColor()
Returns background color of the modular search view.
int getHighlightBackgroundColor()
Returns the background color of the highlighted search result.
int getHighlightBorderColor()
Returns the border color of the highlighted search result.
int getHighlightTextColor()
Returns the text color of the highlighted search result.
int getInputFieldBackgroundColor()
Returns modular search input field background color.
int getInputFieldHintColor()
Returns modular search input field hint text color.
int getInputFieldTextColor()
Returns modular search input field text color.
int getListItemBackgroundColor()
Returns the background color of the list items.
void getListItemBackgroundColor(int listItemBackgroundColor)
Sets the background color of the list items.
int getListItemSubtitleColor()
Returns the text color of the list item subtitle.
int getListItemTitleColor()
Returns the title color of the list items.
int getListSelector()
Returns the list item selector.
Integer getMaxSearchResults()
Returns the maximum count of search results, null if not set, or SearchConfiguration#UNLIMITED_SEARCH_RESULTS if limiting is turned off.
PSPDFKitViews.Type getPSPDFViewType()
Returns the type of this view.
final List<SearchResult> getSearchResults()
Returns the current list of search results (may be empty if there are no search hits or search still in progress), or null if no search was performed.
int getSeparatorColor()
Returns the input field separator color.
int getSnippetLength()
Returns the number of preview characters extracted with every search result.
int getStartSearchChars()
Returns the number of characters that need to be entered for the search to start.
void hide()
Hides the modular search view.
boolean isDisplayed()
Called when the activity needs to know the visibility of this view.
boolean isStartSearchOnCurrentPage()
Returns whether the search should start on the current page or not.
void onMoreSearchResults(List<SearchResult> results)
Called when another chunk of search results is ready.
void onPageChanged(PdfDocument document, int pageIndex)
Called when user scrolled to a new page.
void onSearchCanceled()
Called when search has been cancelled.
void onSearchComplete()
Called when searching has finished.
void onSearchError(Throwable ex)
Called in case of an error that prevented searching the document.
void onSearchStarted(String query)
Called when a fresh search has been started.
boolean onTouchEvent(MotionEvent event)
final void performSearch(String searchQuery)
Performs the search action.
void removeOnVisibilityChangedListener(OnVisibilityChangedListener listener)
Removes added listener for visibility changes.
void setBackgroundColor(int backgroundColor)
Sets background color of the modular search view.
void setDocument(PdfDocument document, PdfConfiguration configuration)
Called when the document has been loaded and is going to be displayed.
void setHighlightBackgroundColor(int highlightBackgroundColor)
Sets the background color of the highlighted search result.
void setHighlightBorderColor(int highlightBorderColor)
Sets the border color of the highlighted search result.
void setHighlightTextColor(int highlightTextColor)
Sets the text color of the highlighted search result.
void setInputFieldBackgroundColor(int inputFieldBackgroundColor)
Sets modular search input field background color.
void setInputFieldHintColor(int inputFieldHintColor)
Sets modular search input field hint text color.
void setInputFieldText(String text, boolean startSearch)
Inserts text in the search input field and optionally starts search.
void setInputFieldTextColor(int inputFieldTextColor)
Sets modular search input field text color.
void setListItemSubtitleColor(int listItemSubtitleColor)
Sets the text color of the list item subtitle.
void setListItemTitleColor(int listItemTitleColor)
Sets the title color of the list items.
void setListSelector(int listSelector)
Sets the list item selector.
void setMaxSearchResults(Integer maxSearchResults)
Sets maximum number of search results.
void setSearchConfiguration(SearchConfiguration searchConfiguration)
Sets the search configuration to this search view.
final void setSearchViewListener(PdfSearchView.Listener searchViewListener)
Sets a listener to be notified of search events on this view.
void setSeparatorColor(int separatorColor)
Sets the input field separator color.
void setSnippetLength(int snippetLength)
Sets the number of preview characters extracted with every search result.
void setStartSearchChars(int startSearchChars)
Sets the number of characters that need to be entered for the search to start.
void setStartSearchOnCurrentPage(boolean startSearchOnCurrentPage)
Sets whether the search should start on the current page or not.
void show()
Shows the modular search view.
Protected Methods
void applyTheme()
void clearSearchResults()
When called subclasses have to update their UI and remove any previously collected search results from memory.
final void dispatchSearchResultSelected(SearchResult selectedSearchResult)
Subclasses may call this method providing a selectedSearchResult (e.g.
boolean fitSystemWindows(Rect insets)
void hideKeyboard()
void init()
void onDetachedFromWindow()
void onDraw(Canvas canvas)
void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
void showKeyboard()
[Expand]
Inherited Methods
From class com.pspdfkit.framework.views.utils.DocumentListenerFrameLayout
From class android.widget.FrameLayout
From class android.view.ViewGroup
From class android.view.View
From class java.lang.Object
From interface android.graphics.drawable.Drawable.Callback
From interface android.view.KeyEvent.Callback
From interface android.view.ViewManager
From interface android.view.ViewParent
From interface android.view.accessibility.AccessibilityEventSource
From interface com.pspdfkit.listeners.DocumentListener
From interface com.pspdfkit.ui.PSPDFKitViews.PSPDFView
From interface com.pspdfkit.ui.search.PdfSearchView

Constants

protected static final String LOG_TAG

Constant Value: "PSPDFKit.SearchView"

public static final int SEARCH_DELAY

Delay waited after a call to performSearch(String) before starting the search.

Constant Value: 300 (0x0000012c)

Fields

protected int currentPage

Tracks current page of the document.

protected PdfDocument document

protected EditText inputField

protected boolean isDisplayed

protected final OnVisibilityChangedListenerManager listeners

protected Disposable searchInProgress

Public Constructors

public PdfSearchViewModular (Context context)

public PdfSearchViewModular (Context context, AttributeSet attrs)

Public Methods

public void addOnVisibilityChangedListener (OnVisibilityChangedListener listener)

Adds a new listener for visibility changes. If the listener has already been added previously, this method will be a no-op. Adding null is not allowed, and will result in an exception.

Parameters
listener OnVisibilityChangedListener that should be notified. Must be non-null.

public void clearDocument ()

Called by the activity when the view should unbind the previously set document. This may be called in low-memory situations or prior to re-binding another document.

public void clearOnVisibilityChangedListeners ()

Removes all previously registered visibility change listeners. To remove just one listener use removeOnVisibilityChangedListener(OnVisibilityChangedListener). Upon calling this method no listeners will be notified of any changes.

public final void clearSearch ()

Clears the search input field as well as any previously collected search results. This will also cancel any currently running search operation. Implementations of PdfSearchView need to call onSearchCleared() on the current listener.

public int getBackgroundColor ()

Returns background color of the modular search view.

Returns
  • Modular search view background color.

public int getHighlightBackgroundColor ()

Returns the background color of the highlighted search result.

Returns
  • Highlighted search result background color.

public int getHighlightBorderColor ()

Returns the border color of the highlighted search result.

Returns
  • Border color of the highlighted search result.

public int getHighlightTextColor ()

Returns the text color of the highlighted search result.

Returns
  • Highlighted search result text color.

public int getInputFieldBackgroundColor ()

Returns modular search input field background color.

Returns
  • Background color of the search input field.

public int getInputFieldHintColor ()

Returns modular search input field hint text color.

Returns
  • Hint text color of the input field.

public int getInputFieldTextColor ()

Returns modular search input field text color.

Returns
  • Text color of the input field.

public int getListItemBackgroundColor ()

Returns the background color of the list items.

Returns
  • Background color of the list items.

public void getListItemBackgroundColor (int listItemBackgroundColor)

Sets the background color of the list items.

Parameters
listItemBackgroundColor Background color of the list items.

public int getListItemSubtitleColor ()

Returns the text color of the list item subtitle.

Returns
  • Text color of the list item subtitle (search snippet).

public int getListItemTitleColor ()

Returns the title color of the list items.

Returns
  • Text color of the list item title (page number).

public int getListSelector ()

Returns the list item selector.

Returns
  • Search result list item selector.

public Integer getMaxSearchResults ()

Returns the maximum count of search results, null if not set, or SearchConfiguration#UNLIMITED_SEARCH_RESULTS if limiting is turned off.

public PSPDFKitViews.Type getPSPDFViewType ()

Returns the type of this view.

Returns

public final List<SearchResult> getSearchResults ()

Returns the current list of search results (may be empty if there are no search hits or search still in progress), or null if no search was performed. Note that the returned list is immutable.

Returns
  • List of search results, or null.

public int getSeparatorColor ()

Returns the input field separator color.

Returns
  • Color of the horizontal line separator below the input field.

public int getSnippetLength ()

Returns the number of preview characters extracted with every search result. This defaults to {@value com.pspdfkit.configuration.search.SearchConfiguration#DEFAULT_SNIPPET_LENGTH}.

public int getStartSearchChars ()

Returns the number of characters that need to be entered for the search to start. This defaults to {@value com.pspdfkit.configuration.search.SearchConfiguration#DEFAULT_START_SEARCH_CHARS}.

public void hide ()

Hides the modular search view.

public boolean isDisplayed ()

Called when the activity needs to know the visibility of this view. Returns true if this view is visible, otherwise returns false.

public boolean isStartSearchOnCurrentPage ()

Returns whether the search should start on the current page or not. This defaults to {@value com.pspdfkit.configuration.search.SearchConfiguration#DEFAULT_START_SEARCH_ON_CURRENT_PAGE}.

public void onMoreSearchResults (List<SearchResult> results)

Called when another chunk of search results is ready.

Parameters
results List of search results.

public void onPageChanged (PdfDocument document, int pageIndex)

Called when user scrolled to a new page.

Parameters
document Currently opened document.
pageIndex Page number of new page.

public void onSearchCanceled ()

Called when search has been cancelled.

public void onSearchComplete ()

Called when searching has finished.

public void onSearchError (Throwable ex)

Called in case of an error that prevented searching the document.

Parameters
ex Throwable containing the search error reason.

public void onSearchStarted (String query)

Called when a fresh search has been started.

Parameters
query Search term.

public boolean onTouchEvent (MotionEvent event)

public final void performSearch (String searchQuery)

Performs the search action.

Parameters
searchQuery String query to be searched.

public void removeOnVisibilityChangedListener (OnVisibilityChangedListener listener)

Removes added listener for visibility changes. Upon calling this method the listener will no longer be notified of any changes. If the listener has not been added, this method will be a no-op. Adding null is not allowed,and will result in an exception.

Parameters
listener OnVisibilityChangedListener that should be removed. Must be non-null.

public void setBackgroundColor (int backgroundColor)

Sets background color of the modular search view.

Parameters
backgroundColor Modular search view background color.

public void setDocument (PdfDocument document, PdfConfiguration configuration)

Called when the document has been loaded and is going to be displayed. This has to be called on the main thread.

Parameters
document Loaded PdfDocument.
configuration Containing document and presentation settings.

public void setHighlightBackgroundColor (int highlightBackgroundColor)

Sets the background color of the highlighted search result.

Parameters
highlightBackgroundColor Highlighted search result background color.

public void setHighlightBorderColor (int highlightBorderColor)

Sets the border color of the highlighted search result.

Parameters
highlightBorderColor Border color of the highlighted search result.

public void setHighlightTextColor (int highlightTextColor)

Sets the text color of the highlighted search result.

Parameters
highlightTextColor Highlighted search result text color.

public void setInputFieldBackgroundColor (int inputFieldBackgroundColor)

Sets modular search input field background color.

Parameters
inputFieldBackgroundColor Background color of the search input field.

public void setInputFieldHintColor (int inputFieldHintColor)

Sets modular search input field hint text color.

Parameters
inputFieldHintColor Hint text color of the input field.

public void setInputFieldText (String text, boolean startSearch)

Inserts text in the search input field and optionally starts search.

Parameters
text Search text.
startSearch Hides keyboard and starts search if true.

public void setInputFieldTextColor (int inputFieldTextColor)

Sets modular search input field text color.

Parameters
inputFieldTextColor Text color of the input field.

public void setListItemSubtitleColor (int listItemSubtitleColor)

Sets the text color of the list item subtitle.

Parameters
listItemSubtitleColor Text color of the list item subtitle (search snippet).

public void setListItemTitleColor (int listItemTitleColor)

Sets the title color of the list items.

Parameters
listItemTitleColor Text color of the list item title (page number).

public void setListSelector (int listSelector)

Sets the list item selector.

Parameters
listSelector Search result list item selector.

public void setMaxSearchResults (Integer maxSearchResults)

Sets maximum number of search results. Defaults to {@value SearchOptions.Builder#MAX_SEARCH_RESULTS} or {@value SearchOptions.Builder#MAX_SEARCH_RESULTS_LOW_MEM} on devices with little of RAM.

Parameters
maxSearchResults Maximum count of search results, null to fallback to default or SearchConfiguration#UNLIMITED_SEARCH_RESULTS to turn off limiting.

public void setSearchConfiguration (SearchConfiguration searchConfiguration)

Sets the search configuration to this search view.

Parameters
searchConfiguration Search configuration to be set for this AbstractPdfSearchView.

public final void setSearchViewListener (PdfSearchView.Listener searchViewListener)

Sets a listener to be notified of search events on this view. May be null to remove any previously set listener.

Parameters
searchViewListener A Listener which should be notified of search events, or null to remove a previously registered listener.

public void setSeparatorColor (int separatorColor)

Sets the input field separator color.

Parameters
separatorColor Color of the horizontal line separator below the input field.

public void setSnippetLength (int snippetLength)

Sets the number of preview characters extracted with every search result.

Parameters
snippetLength Number of characters, defaults to {@value com.pspdfkit.configuration.search.SearchConfiguration#DEFAULT_SNIPPET_LENGTH}.

public void setStartSearchChars (int startSearchChars)

Sets the number of characters that need to be entered for the search to start.

Parameters
startSearchChars Number of characters needed to trigger the search, defaults to {@value com.pspdfkit.configuration.search.SearchConfiguration#DEFAULT_START_SEARCH_CHARS}.

public void setStartSearchOnCurrentPage (boolean startSearchOnCurrentPage)

Sets whether the search should start on the current page or not. This defaults to {@value com.pspdfkit.configuration.search.SearchConfiguration#DEFAULT_START_SEARCH_ON_CURRENT_PAGE}.

Parameters
startSearchOnCurrentPage true to start search on the current page, false to start from the beginning of the document.

public void show ()

Shows the modular search view.

Protected Methods

protected void applyTheme ()

protected void clearSearchResults ()

When called subclasses have to update their UI and remove any previously collected search results from memory.

protected final void dispatchSearchResultSelected (SearchResult selectedSearchResult)

Subclasses may call this method providing a selectedSearchResult (e.g. from user interaction) so that any registered listener may be notified of this event. May also receive null in case the previous selection was cleared.

protected boolean fitSystemWindows (Rect insets)

protected void hideKeyboard ()

protected void init ()

protected void onDetachedFromWindow ()

protected void onDraw (Canvas canvas)

protected void onMeasure (int widthMeasureSpec, int heightMeasureSpec)

protected void showKeyboard ()