Skip to content

Commit b520413

Browse files
committed
Revise snippets.
2 parents b82f869 + 1ba6a2b commit b520413

File tree

1 file changed

+44
-44
lines changed

1 file changed

+44
-44
lines changed

misc/src/main/java/com/example/snippets/PdfViewerKotlinSnippets.kt

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ class PdfViewerKotlinSnippets {
5959
}
6060
// [END android_pdf_viewer_create_compat_activity_kotlin]
6161

62-
6362
// [START android_pdf_viewer_extend_fragment_kotlin]
6463
@RequiresExtension(extension = Build.VERSION_CODES.S, version = 13)
6564
class PdfViewerFragmentExtended : PdfViewerFragment() {
@@ -102,18 +101,18 @@ class PdfViewerKotlinSnippets {
102101
if (pdfViewerFragment == null) {
103102
val fragmentManager: FragmentManager = supportFragmentManager
104103

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()
104+
// Fragment initialization.
105+
pdfViewerFragment = PdfViewerFragmentExtended()
106+
val transaction: FragmentTransaction = fragmentManager.beginTransaction()
107+
108+
// Replace an existing fragment in a container with an instance of a new fragment.
109+
transaction.replace(
110+
R.id.fragment_container_view,
111+
pdfViewerFragment!!,
112+
PDF_VIEWER_FRAGMENT_TAG
113+
)
114+
transaction.commitAllowingStateLoss()
115+
fragmentManager.executePendingTransactions()
117116
}
118117
}
119118

@@ -150,7 +149,7 @@ class PdfViewerKotlinSnippets {
150149
}
151150

152151
/** Enable nested classes. **/
153-
class ClassHolder3: AppCompatActivity() {
152+
class ClassHolder3 : AppCompatActivity() {
154153

155154
private var pdfViewerFragment: PdfViewerFragment? = null
156155

@@ -162,13 +161,13 @@ class PdfViewerKotlinSnippets {
162161
if (pdfViewerFragment == null) {
163162
pdfViewerFragment =
164163
supportFragmentManager
165-
.findFragmentByTag(PDF_VIEWER_FRAGMENT_TAG) as PdfViewerFragment?
164+
.findFragmentByTag(PDF_VIEWER_FRAGMENT_TAG) as PdfViewerFragment?
166165
}
167166

168167
}
169168

170169
// [START android_pdf_viewer_launch_file_picker_kotlin]
171-
@RequiresExtension(extension=Build.VERSION_CODES.S, version=13)
170+
@RequiresExtension(extension = Build.VERSION_CODES.S, version = 13)
172171
class MainActivity : AppCompatActivity() {
173172
private var pdfViewerFragment: PdfViewerFragment? = null
174173
private var filePicker =
@@ -198,19 +197,19 @@ class PdfViewerKotlinSnippets {
198197
// [END android_pdf_viewer_launch_file_picker_kotlin]
199198

200199
// [START android_pdf_viewer_style_fragment_kotlin]
201-
@RequiresExtension(extension=Build.VERSION_CODES.S, version=13)
200+
@RequiresExtension(extension = Build.VERSION_CODES.S, version = 13)
202201
private fun initialisePdfViewerFragment() {
203202
// This condition can be skipped if you want to create a new fragment everytime
204203
if (pdfViewerFragment == null) {
205-
val fragmentManager: FragmentManager = supportFragmentManager
204+
val fragmentManager: FragmentManager = supportFragmentManager
206205

207-
// Create styling options
208-
val stylingOptions = PdfStylingOptions(R.style.pdfContainerStyle)
206+
// Create styling options
207+
val stylingOptions = PdfStylingOptions(R.style.pdfContainerStyle)
209208

210-
// Fragment initialization
211-
pdfViewerFragment = PdfViewerFragment.newInstance(stylingOptions)
209+
// Fragment initialization
210+
pdfViewerFragment = PdfViewerFragment.newInstance(stylingOptions)
212211

213-
// .. execute fragment transaction
212+
// .. execute fragment transaction
214213
}
215214
}
216215
// [END android_pdf_viewer_style_fragment_kotlin]
@@ -221,9 +220,10 @@ class PdfViewerKotlinSnippets {
221220

222221
}
223222

223+
224224
// [START android_pdf_viewer_style_fragment_constructor_kotlin]
225-
@RequiresExtension(extension=Build.VERSION_CODES.S, version=13)
226-
class StyledPdfViewerFragment: PdfViewerFragment {
225+
@RequiresExtension(extension = Build.VERSION_CODES.S, version = 13)
226+
class StyledPdfViewerFragment : PdfViewerFragment {
227227

228228
constructor() : super()
229229

@@ -242,7 +242,7 @@ class PdfViewerKotlinSnippets {
242242
class ClassHolder4 {
243243

244244
// [START android_pdf_viewer_full_code_kotlin]
245-
@RequiresExtension(extension=Build.VERSION_CODES.S, version=13)
245+
@RequiresExtension(extension = Build.VERSION_CODES.S, version = 13)
246246
class MainActivity : AppCompatActivity() {
247247

248248
private var pdfViewerFragment: PdfViewerFragment? = null
@@ -261,7 +261,7 @@ class PdfViewerKotlinSnippets {
261261
if (pdfViewerFragment == null) {
262262
pdfViewerFragment =
263263
supportFragmentManager
264-
.findFragmentByTag(PDF_VIEWER_FRAGMENT_TAG) as PdfViewerFragment?
264+
.findFragmentByTag(PDF_VIEWER_FRAGMENT_TAG) as PdfViewerFragment?
265265
}
266266

267267
val getContentButton: MaterialButton = findViewById(R.id.launch_button)
@@ -278,23 +278,23 @@ class PdfViewerKotlinSnippets {
278278
if (pdfViewerFragment == null) {
279279
val fragmentManager: FragmentManager = supportFragmentManager
280280

281-
// Create styling options
282-
// val stylingOptions = PdfStylingOptions(R.style.pdfContainerStyle)
283-
284-
// Fragment initialization
285-
// For customization
286-
// pdfViewerFragment = PdfViewerFragment.newInstance(stylingOptions)
287-
pdfViewerFragment = PdfViewerFragmentExtended()
288-
val transaction: FragmentTransaction = fragmentManager.beginTransaction()
289-
290-
// Replace an existing fragment in a container with an instance of a new fragment
291-
transaction.replace(
292-
R.id.fragment_container_view,
293-
pdfViewerFragment!!,
294-
PDF_VIEWER_FRAGMENT_TAG
295-
)
296-
transaction.commitAllowingStateLoss()
297-
fragmentManager.executePendingTransactions()
281+
// Create styling options
282+
// val stylingOptions = PdfStylingOptions(R.style.pdfContainerStyle)
283+
284+
// Fragment initialization
285+
// For customization
286+
// pdfViewerFragment = PdfViewerFragment.newInstance(stylingOptions)
287+
pdfViewerFragment = PdfViewerFragmentExtended()
288+
val transaction: FragmentTransaction = fragmentManager.beginTransaction()
289+
290+
// Replace an existing fragment in a container with an instance of a new fragment
291+
transaction.replace(
292+
R.id.fragment_container_view,
293+
pdfViewerFragment!!,
294+
PDF_VIEWER_FRAGMENT_TAG
295+
)
296+
transaction.commitAllowingStateLoss()
297+
fragmentManager.executePendingTransactions()
298298
}
299299
}
300300

0 commit comments

Comments
 (0)