3232import androidx .annotation .NonNull ;
3333import androidx .core .app .ActivityCompat ;
3434import androidx .fragment .app .Fragment ;
35+ import androidx .fragment .app .FragmentActivity ;
3536import 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 ;
3839import androidx .appcompat .app .AppCompatActivity ;
3940import androidx .appcompat .widget .Toolbar ;
4041
@@ -59,7 +60,7 @@ class ErrorReport implements TabLayout.OnTabSelectedListener {
5960 private static AppCompatActivity activity ;
6061
6162 private TabLayout tabLayout ;
62- private ViewPager viewPager ;
63+ private ViewPager2 viewPager ;
6364 private Context context ;
6465
6566 private static String exceptionMsg ;
@@ -279,12 +280,12 @@ void buildUI() {
279280 tabLayout .setTabGravity (TabLayout .GRAVITY_FILL );
280281 int pagerId = this .context .getResources ().getIdentifier ("pager" , "id" , this .context .getPackageName ());
281282
282- viewPager = (ViewPager ) activity .findViewById (pagerId );
283+ viewPager = (ViewPager2 ) activity .findViewById (pagerId );
283284
284- Pager adapter = new Pager (activity . getSupportFragmentManager () , tabLayout .getTabCount ());
285+ Pager adapter = new Pager (activity , tabLayout .getTabCount ());
285286
286287 viewPager .setAdapter (adapter );
287- viewPager .addOnPageChangeListener (new ViewPager . OnPageChangeListener () {
288+ viewPager .registerOnPageChangeCallback (new ViewPager2 . OnPageChangeCallback () {
288289 @ Override
289290 public void onPageScrolled (int position , float positionOffset , int positionOffsetPixels ) {
290291
@@ -332,18 +333,18 @@ public void onTabReselected(TabLayout.Tab tab) {
332333 viewPager .setCurrentItem (tab .getPosition ());
333334 }
334335
335- private class Pager extends FragmentStatePagerAdapter {
336+ private class Pager extends FragmentStateAdapter {
336337
337338 int tabCount ;
338339
339340 @ SuppressWarnings ("deprecation" )
340- public Pager (FragmentManager fm , int tabCount ) {
341+ public Pager (FragmentActivity fm , int tabCount ) {
341342 super (fm );
342343 this .tabCount = tabCount ;
343344 }
344345
345346 @ Override
346- public Fragment getItem (int position ) {
347+ public Fragment createFragment (int position ) {
347348 switch (position ) {
348349 case 0 :
349350 return new ExceptionTab ();
@@ -355,7 +356,7 @@ public Fragment getItem(int position) {
355356 }
356357
357358 @ Override
358- public int getCount () {
359+ public int getItemCount () {
359360 return tabCount ;
360361 }
361362 }
@@ -410,14 +411,14 @@ public static void restartApp(Context context) {
410411
411412 @ Override
412413 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 ());
414415 View view = inflater .inflate (exceptionTabId , container , false );
415416
416417 int errorExceptionViewId = activity .getResources ().getIdentifier ("errorException" , "id" , activity .getPackageName ());
417418 TextView errorExceptionView = (TextView ) activity .findViewById (errorExceptionViewId );
418419 errorExceptionView .setMovementMethod (new ScrollingMovementMethod ());
419420
420- int errorStackTraceViewId = container . getContext ().getResources ().getIdentifier ("errorStacktrace" , "id" , container . getContext ().getPackageName ());
421+ int errorStackTraceViewId = getContext ().getResources ().getIdentifier ("errorStacktrace" , "id" , getContext ().getPackageName ());
421422 TextView errorStackTraceView = (TextView ) view .findViewById (errorStackTraceViewId );
422423
423424 String [] exceptionParts = exceptionMsg .split ("StackTrace:" );
@@ -438,10 +439,10 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
438439 errorStackTraceView .setMovementMethod (LinkMovementMethod .getInstance ());
439440 errorStackTraceView .setEnabled (true );
440441
441- int btnCopyExceptionId = container . getContext ().getResources ().getIdentifier ("btnCopyException" , "id" , container . getContext ().getPackageName ());
442+ int btnCopyExceptionId = getContext ().getResources ().getIdentifier ("btnCopyException" , "id" , getContext ().getPackageName ());
442443 Button copyToClipboard = (Button ) view .findViewById (btnCopyExceptionId );
443444
444- int btnRestartAppId = container . getContext ().getResources ().getIdentifier ("btnRestartApp" , "id" , container . getContext ().getPackageName ());
445+ int btnRestartAppId = getContext ().getResources ().getIdentifier ("btnRestartApp" , "id" , getContext ().getPackageName ());
445446 Button restartApp = (Button ) view .findViewById (btnRestartAppId );
446447 restartApp .setOnClickListener (v -> {
447448 restartApp (getContext ().getApplicationContext ());
@@ -459,18 +460,18 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
459460 public static class LogcatTab extends Fragment {
460461 @ Override
461462 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 ());
463464 View view = inflater .inflate (logcatTabId , container , false );
464465
465- int textViewId = container . getContext ().getResources ().getIdentifier ("logcatMsg" , "id" , container . getContext ().getPackageName ());
466+ int textViewId = getContext ().getResources ().getIdentifier ("logcatMsg" , "id" , getContext ().getPackageName ());
466467 TextView txtlogcatMsg = (TextView ) view .findViewById (textViewId );
467468 txtlogcatMsg .setText (logcatMsg );
468469
469470 txtlogcatMsg .setMovementMethod (new ScrollingMovementMethod ());
470471
471472 final String logName = "Log-" + new SimpleDateFormat ("yyyy-MM-dd-HH-mm-ss" ).format (new Date ());
472473
473- int btnCopyLogcatId = container . getContext ().getResources ().getIdentifier ("btnCopyLogcat" , "id" , container . getContext ().getPackageName ());
474+ int btnCopyLogcatId = getContext ().getResources ().getIdentifier ("btnCopyLogcat" , "id" , getContext ().getPackageName ());
474475 Button copyToClipboard = (Button ) view .findViewById (btnCopyLogcatId );
475476 copyToClipboard .setOnClickListener (new View .OnClickListener () {
476477 @ Override
@@ -498,7 +499,7 @@ public void onClick(View v) {
498499 } catch (Exception e ) {
499500 String err = "Could not write logcat report to sdcard. Make sure you have allowed access to external storage!" ;
500501 Toast .makeText (activity , err , Toast .LENGTH_LONG ).show ();
501- if (Util .isDebuggableApp (container . getContext ())) {
502+ if (Util .isDebuggableApp (getContext ())) {
502503 e .printStackTrace ();
503504 }
504505 }
0 commit comments