1414 * limitations under the License.
1515 */
1616
17- package com.example.snippets
17+ package com.example.snippets
1818
1919import android.net.Uri
2020import android.os.Build
@@ -41,10 +41,9 @@ class PdfViewerKotlinSnippets {
4141
4242 // [START android_pdf_viewer_extension_version_kotlin]
4343 if (SdkExtensions .getExtensionVersion(Build .VERSION_CODES .S ) >= 13 ) {
44- // Load the fragment and document.
44+ // Load the fragment and document.
4545 }
4646 // [END android_pdf_viewer_extension_version_kotlin]
47-
4847 }
4948
5049 // [START android_pdf_viewer_create_compat_activity_kotlin]
@@ -55,15 +54,14 @@ class PdfViewerKotlinSnippets {
5554
5655 val getContentButton: MaterialButton = findViewById(R .id.launch_button)
5756 val searchButton: MaterialButton = findViewById(R .id.search_button)
58- }
57+ }
5958 }
6059 // [END android_pdf_viewer_create_compat_activity_kotlin]
6160
62-
6361 // [START android_pdf_viewer_extend_fragment_kotlin]
6462 @RequiresExtension(extension = Build .VERSION_CODES .S , version = 13 )
6563 class PdfViewerFragmentExtended : PdfViewerFragment () {
66- private val myLogger : Logger = Logger .getLogger(Logger .GLOBAL_LOGGER_NAME )
64+ private val myLogger: Logger = Logger .getLogger(Logger .GLOBAL_LOGGER_NAME )
6765
6866 override fun onLoadDocumentSuccess () {
6967 myLogger.log(INFO , " // Log document success." )
@@ -90,9 +88,8 @@ class PdfViewerKotlinSnippets {
9088 if (pdfViewerFragment == null ) {
9189 pdfViewerFragment =
9290 supportFragmentManager
93- .findFragmentByTag(PDF_VIEWER_FRAGMENT_TAG ) as PdfViewerFragment ?
91+ .findFragmentByTag(PDF_VIEWER_FRAGMENT_TAG ) as PdfViewerFragment ?
9492 }
95-
9693 }
9794
9895 // Used to instantiate and commit the fragment.
@@ -102,18 +99,18 @@ class PdfViewerKotlinSnippets {
10299 if (pdfViewerFragment == null ) {
103100 val fragmentManager: FragmentManager = supportFragmentManager
104101
105- // Fragment initialization.
106- pdfViewerFragment = PdfViewerFragmentExtended ()
107- val transaction: FragmentTransaction = fragmentManager.beginTransaction()
108-
109- // Replace an existing fragment in a container with an instance of a new fragment.
110- transaction.replace(
111- R .id.fragment_container_view,
112- pdfViewerFragment!! ,
113- PDF_VIEWER_FRAGMENT_TAG
114- )
115- transaction.commitAllowingStateLoss()
116- fragmentManager.executePendingTransactions()
102+ // Fragment initialization.
103+ pdfViewerFragment = PdfViewerFragmentExtended ()
104+ val transaction: FragmentTransaction = fragmentManager.beginTransaction()
105+
106+ // Replace an existing fragment in a container with an instance of a new fragment.
107+ transaction.replace(
108+ R .id.fragment_container_view,
109+ pdfViewerFragment!! ,
110+ PDF_VIEWER_FRAGMENT_TAG
111+ )
112+ transaction.commitAllowingStateLoss()
113+ fragmentManager.executePendingTransactions()
117114 }
118115 }
119116
@@ -123,7 +120,6 @@ class PdfViewerKotlinSnippets {
123120 }
124121 }
125122 // [END android_pdf_viewer_create_fragment_kotlin]
126-
127123 }
128124
129125 /* * Enable nested classes. **/
@@ -146,11 +142,10 @@ class PdfViewerKotlinSnippets {
146142 }
147143 }
148144 // [END android_pdf_viewer_enable_document_search_kotlin]
149-
150145 }
151146
152147 /* * Enable nested classes. **/
153- class ClassHolder3 : AppCompatActivity () {
148+ class ClassHolder3 : AppCompatActivity () {
154149
155150 private var pdfViewerFragment: PdfViewerFragment ? = null
156151 private const val PDF_VIEWER_FRAGMENT_TAG = " pdf_viewer_fragment_tag"
@@ -163,13 +158,12 @@ class PdfViewerKotlinSnippets {
163158 if (pdfViewerFragment == null ) {
164159 pdfViewerFragment =
165160 supportFragmentManager
166- .findFragmentByTag(PDF_VIEWER_FRAGMENT_TAG ) as PdfViewerFragment ?
161+ .findFragmentByTag(PDF_VIEWER_FRAGMENT_TAG ) as PdfViewerFragment ?
167162 }
168-
169163 }
170164
171165 // [START android_pdf_viewer_launch_file_picker_kotlin]
172- @RequiresExtension(extension= Build .VERSION_CODES .S , version= 13 )
166+ @RequiresExtension(extension = Build .VERSION_CODES .S , version = 13 )
173167 class MainActivity : AppCompatActivity () {
174168 private var pdfViewerFragment: PdfViewerFragment ? = null
175169 private var filePicker =
@@ -199,28 +193,27 @@ class PdfViewerKotlinSnippets {
199193 // [END android_pdf_viewer_launch_file_picker_kotlin]
200194
201195 // [START android_pdf_viewer_style_fragment_kotlin]
202- @RequiresExtension(extension= Build .VERSION_CODES .S , version= 13 )
196+ @RequiresExtension(extension = Build .VERSION_CODES .S , version = 13 )
203197 private fun initialisePdfViewerFragment () {
204198 // This condition can be skipped if you want to create a new fragment everytime
205199 if (pdfViewerFragment == null ) {
206- val fragmentManager: FragmentManager = supportFragmentManager
200+ val fragmentManager: FragmentManager = supportFragmentManager
207201
208- // Create styling options
209- val stylingOptions = PdfStylingOptions (R .style.pdfContainerStyle)
202+ // Create styling options
203+ val stylingOptions = PdfStylingOptions (R .style.pdfContainerStyle)
210204
211- // Fragment initialization
212- pdfViewerFragment = PdfViewerFragment .newInstance(stylingOptions)
205+ // Fragment initialization
206+ pdfViewerFragment = PdfViewerFragment .newInstance(stylingOptions)
213207
214- // .. execute fragment transaction
208+ // .. execute fragment transaction
215209 }
216210 }
217211 // [END android_pdf_viewer_style_fragment_kotlin]
218-
219212 }
220213
221214 // [START android_pdf_viewer_style_fragment_constructor_kotlin]
222- @RequiresExtension(extension= Build .VERSION_CODES .S , version= 13 )
223- class StyledPdfViewerFragment : PdfViewerFragment {
215+ @RequiresExtension(extension = Build .VERSION_CODES .S , version = 13 )
216+ class StyledPdfViewerFragment : PdfViewerFragment {
224217
225218 constructor () : super ()
226219
@@ -239,7 +232,7 @@ class PdfViewerKotlinSnippets {
239232 class ClassHolder4 {
240233
241234 // [START android_pdf_viewer_full_code_kotlin]
242- @RequiresExtension(extension= Build .VERSION_CODES .S , version= 13 )
235+ @RequiresExtension(extension = Build .VERSION_CODES .S , version = 13 )
243236 class MainActivity : AppCompatActivity () {
244237
245238 private var pdfViewerFragment: PdfViewerFragment ? = null
@@ -258,7 +251,7 @@ class PdfViewerKotlinSnippets {
258251 if (pdfViewerFragment == null ) {
259252 pdfViewerFragment =
260253 supportFragmentManager
261- .findFragmentByTag(PDF_VIEWER_FRAGMENT_TAG ) as PdfViewerFragment ?
254+ .findFragmentByTag(PDF_VIEWER_FRAGMENT_TAG ) as PdfViewerFragment ?
262255 }
263256
264257 val getContentButton: MaterialButton = findViewById(R .id.launch_button)
@@ -275,23 +268,23 @@ class PdfViewerKotlinSnippets {
275268 if (pdfViewerFragment == null ) {
276269 val fragmentManager: FragmentManager = supportFragmentManager
277270
278- // Create styling options
279- // val stylingOptions = PdfStylingOptions(R.style.pdfContainerStyle)
280-
281- // Fragment initialization
282- // For customization
283- // pdfViewerFragment = PdfViewerFragment.newInstance(stylingOptions)
284- pdfViewerFragment = PdfViewerFragmentExtended ()
285- val transaction: FragmentTransaction = fragmentManager.beginTransaction()
286-
287- // Replace an existing fragment in a container with an instance of a new fragment
288- transaction.replace(
289- R .id.fragment_container_view,
290- pdfViewerFragment!! ,
291- PDF_VIEWER_FRAGMENT_TAG
292- )
293- transaction.commitAllowingStateLoss()
294- fragmentManager.executePendingTransactions()
271+ // Create styling options
272+ // val stylingOptions = PdfStylingOptions(R.style.pdfContainerStyle)
273+
274+ // Fragment initialization
275+ // For customization
276+ // pdfViewerFragment = PdfViewerFragment.newInstance(stylingOptions)
277+ pdfViewerFragment = PdfViewerFragmentExtended ()
278+ val transaction: FragmentTransaction = fragmentManager.beginTransaction()
279+
280+ // Replace an existing fragment in a container with an instance of a new fragment
281+ transaction.replace(
282+ R .id.fragment_container_view,
283+ pdfViewerFragment!! ,
284+ PDF_VIEWER_FRAGMENT_TAG
285+ )
286+ transaction.commitAllowingStateLoss()
287+ fragmentManager.executePendingTransactions()
295288 }
296289 }
297290
@@ -301,7 +294,5 @@ class PdfViewerKotlinSnippets {
301294 }
302295 }
303296 // [END android_pdf_viewer_full_code_kotlin]
304-
305297 }
306-
307- }
298+ }
0 commit comments