32
32
import androidx .annotation .NonNull ;
33
33
import androidx .core .app .ActivityCompat ;
34
34
import androidx .fragment .app .Fragment ;
35
+ import androidx .fragment .app .FragmentActivity ;
35
36
import androidx .fragment .app .FragmentManager ;
36
- import androidx .fragment . app . FragmentStatePagerAdapter ;
37
- import androidx .viewpager . widget . ViewPager ;
37
+ import androidx .viewpager2 . widget . ViewPager2 ;
38
+ import androidx .viewpager2 . adapter . FragmentStateAdapter ;
38
39
import androidx .appcompat .app .AppCompatActivity ;
39
40
import androidx .appcompat .widget .Toolbar ;
40
41
@@ -59,7 +60,7 @@ class ErrorReport implements TabLayout.OnTabSelectedListener {
59
60
private static AppCompatActivity activity ;
60
61
61
62
private TabLayout tabLayout ;
62
- private ViewPager viewPager ;
63
+ private ViewPager2 viewPager ;
63
64
private Context context ;
64
65
65
66
private static String exceptionMsg ;
@@ -279,12 +280,12 @@ void buildUI() {
279
280
tabLayout .setTabGravity (TabLayout .GRAVITY_FILL );
280
281
int pagerId = this .context .getResources ().getIdentifier ("pager" , "id" , this .context .getPackageName ());
281
282
282
- viewPager = (ViewPager ) activity .findViewById (pagerId );
283
+ viewPager = (ViewPager2 ) activity .findViewById (pagerId );
283
284
284
- Pager adapter = new Pager (activity . getSupportFragmentManager () , tabLayout .getTabCount ());
285
+ Pager adapter = new Pager (activity , tabLayout .getTabCount ());
285
286
286
287
viewPager .setAdapter (adapter );
287
- viewPager .addOnPageChangeListener (new ViewPager . OnPageChangeListener () {
288
+ viewPager .registerOnPageChangeCallback (new ViewPager2 . OnPageChangeCallback () {
288
289
@ Override
289
290
public void onPageScrolled (int position , float positionOffset , int positionOffsetPixels ) {
290
291
@@ -332,18 +333,18 @@ public void onTabReselected(TabLayout.Tab tab) {
332
333
viewPager .setCurrentItem (tab .getPosition ());
333
334
}
334
335
335
- private class Pager extends FragmentStatePagerAdapter {
336
+ private class Pager extends FragmentStateAdapter {
336
337
337
338
int tabCount ;
338
339
339
340
@ SuppressWarnings ("deprecation" )
340
- public Pager (FragmentManager fm , int tabCount ) {
341
+ public Pager (FragmentActivity fm , int tabCount ) {
341
342
super (fm );
342
343
this .tabCount = tabCount ;
343
344
}
344
345
345
346
@ Override
346
- public Fragment getItem (int position ) {
347
+ public Fragment createFragment (int position ) {
347
348
switch (position ) {
348
349
case 0 :
349
350
return new ExceptionTab ();
@@ -355,7 +356,7 @@ public Fragment getItem(int position) {
355
356
}
356
357
357
358
@ Override
358
- public int getCount () {
359
+ public int getItemCount () {
359
360
return tabCount ;
360
361
}
361
362
}
@@ -410,14 +411,14 @@ public static void restartApp(Context context) {
410
411
411
412
@ Override
412
413
public View onCreateView (LayoutInflater inflater , ViewGroup container , Bundle savedInstanceState ) {
413
- int exceptionTabId = container . getContext ().getResources ().getIdentifier ("exception_tab" , "layout" , container . getContext ().getPackageName ());
414
+ int exceptionTabId = getContext ().getResources ().getIdentifier ("exception_tab" , "layout" , getContext ().getPackageName ());
414
415
View view = inflater .inflate (exceptionTabId , container , false );
415
416
416
417
int errorExceptionViewId = activity .getResources ().getIdentifier ("errorException" , "id" , activity .getPackageName ());
417
418
TextView errorExceptionView = (TextView ) activity .findViewById (errorExceptionViewId );
418
419
errorExceptionView .setMovementMethod (new ScrollingMovementMethod ());
419
420
420
- int errorStackTraceViewId = container . getContext ().getResources ().getIdentifier ("errorStacktrace" , "id" , container . getContext ().getPackageName ());
421
+ int errorStackTraceViewId = getContext ().getResources ().getIdentifier ("errorStacktrace" , "id" , getContext ().getPackageName ());
421
422
TextView errorStackTraceView = (TextView ) view .findViewById (errorStackTraceViewId );
422
423
423
424
String [] exceptionParts = exceptionMsg .split ("StackTrace:" );
@@ -438,10 +439,10 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
438
439
errorStackTraceView .setMovementMethod (LinkMovementMethod .getInstance ());
439
440
errorStackTraceView .setEnabled (true );
440
441
441
- int btnCopyExceptionId = container . getContext ().getResources ().getIdentifier ("btnCopyException" , "id" , container . getContext ().getPackageName ());
442
+ int btnCopyExceptionId = getContext ().getResources ().getIdentifier ("btnCopyException" , "id" , getContext ().getPackageName ());
442
443
Button copyToClipboard = (Button ) view .findViewById (btnCopyExceptionId );
443
444
444
- int btnRestartAppId = container . getContext ().getResources ().getIdentifier ("btnRestartApp" , "id" , container . getContext ().getPackageName ());
445
+ int btnRestartAppId = getContext ().getResources ().getIdentifier ("btnRestartApp" , "id" , getContext ().getPackageName ());
445
446
Button restartApp = (Button ) view .findViewById (btnRestartAppId );
446
447
restartApp .setOnClickListener (v -> {
447
448
restartApp (getContext ().getApplicationContext ());
@@ -459,18 +460,18 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
459
460
public static class LogcatTab extends Fragment {
460
461
@ Override
461
462
public View onCreateView (LayoutInflater inflater , ViewGroup container , Bundle savedInstanceState ) {
462
- int logcatTabId = container . getContext ().getResources ().getIdentifier ("logcat_tab" , "layout" , container . getContext ().getPackageName ());
463
+ int logcatTabId = getContext ().getResources ().getIdentifier ("logcat_tab" , "layout" , getContext ().getPackageName ());
463
464
View view = inflater .inflate (logcatTabId , container , false );
464
465
465
- int textViewId = container . getContext ().getResources ().getIdentifier ("logcatMsg" , "id" , container . getContext ().getPackageName ());
466
+ int textViewId = getContext ().getResources ().getIdentifier ("logcatMsg" , "id" , getContext ().getPackageName ());
466
467
TextView txtlogcatMsg = (TextView ) view .findViewById (textViewId );
467
468
txtlogcatMsg .setText (logcatMsg );
468
469
469
470
txtlogcatMsg .setMovementMethod (new ScrollingMovementMethod ());
470
471
471
472
final String logName = "Log-" + new SimpleDateFormat ("yyyy-MM-dd-HH-mm-ss" ).format (new Date ());
472
473
473
- int btnCopyLogcatId = container . getContext ().getResources ().getIdentifier ("btnCopyLogcat" , "id" , container . getContext ().getPackageName ());
474
+ int btnCopyLogcatId = getContext ().getResources ().getIdentifier ("btnCopyLogcat" , "id" , getContext ().getPackageName ());
474
475
Button copyToClipboard = (Button ) view .findViewById (btnCopyLogcatId );
475
476
copyToClipboard .setOnClickListener (new View .OnClickListener () {
476
477
@ Override
@@ -498,7 +499,7 @@ public void onClick(View v) {
498
499
} catch (Exception e ) {
499
500
String err = "Could not write logcat report to sdcard. Make sure you have allowed access to external storage!" ;
500
501
Toast .makeText (activity , err , Toast .LENGTH_LONG ).show ();
501
- if (Util .isDebuggableApp (container . getContext ())) {
502
+ if (Util .isDebuggableApp (getContext ())) {
502
503
e .printStackTrace ();
503
504
}
504
505
}
0 commit comments