Skip to content

Commit 34eaae5

Browse files
committed
feat: remove deprecations and update error activity layout
1 parent 1cf7105 commit 34eaae5

File tree

7 files changed

+45
-40
lines changed

7 files changed

+45
-40
lines changed

test-app/runtime/build.gradle

+1
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ dependencies {
205205
implementation "androidx.appcompat:appcompat:$androidXAppCompatVersion"
206206
implementation 'androidx.navigation:navigation-fragment-ktx:2.5.3'
207207
implementation 'androidx.navigation:navigation-ui-ktx:2.5.3'
208+
implementation 'androidx.preference:preference:1.2.1'
208209
}
209210

210211

test-app/runtime/src/debug/java/com/tns/ErrorReport.java

+19-18
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,10 @@
3232
import androidx.annotation.NonNull;
3333
import androidx.core.app.ActivityCompat;
3434
import androidx.fragment.app.Fragment;
35+
import androidx.fragment.app.FragmentActivity;
3536
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;
3839
import androidx.appcompat.app.AppCompatActivity;
3940
import 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
}

test-app/runtime/src/debug/res/layout/error_activity.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,14 @@
3535
android:layout_height="wrap_content"
3636
android:minHeight="?attr/actionBarSize" />
3737

38-
<androidx.viewpager.widget.ViewPager
38+
<androidx.viewpager2.widget.ViewPager2
3939
android:id="@+id/pager"
4040
android:layout_width="match_parent"
4141
android:layout_height="fill_parent"
4242
android:layout_below="@+id/toolbar"
4343
android:scrollbarAlwaysDrawVerticalTrack="false">
4444

45-
</androidx.viewpager.widget.ViewPager>
45+
</androidx.viewpager2.widget.ViewPager2>
4646

4747
<com.google.android.material.tabs.TabLayout
4848
android:id="@+id/tabLayout"

test-app/runtime/src/debug/res/layout/exception_tab.xml

+12-10
Original file line numberDiff line numberDiff line change
@@ -45,24 +45,26 @@
4545

4646
<Button
4747
android:id="@+id/btnRestartApp"
48-
android:text="Restart APP"
49-
android:textAlignment="center"
50-
android:textColor="@android:color/white"
51-
android:background="@drawable/button_accented"
5248
android:layout_width="0dp"
5349
android:layout_height="wrap_content"
50+
android:layout_marginRight="10dp"
5451
android:layout_weight="1"
55-
android:layout_marginRight="10dp" />
52+
android:background="@drawable/button_accented"
53+
android:foreground="?android:attr/selectableItemBackground"
54+
android:text="Restart APP"
55+
android:textAlignment="center"
56+
android:textColor="@android:color/white" />
5657

5758
<Button
5859
android:id="@+id/btnCopyException"
59-
android:textColor="@android:color/white"
60-
android:text="Copy"
61-
android:background="@drawable/button"
62-
android:textAlignment="center"
6360
android:layout_width="0dp"
6461
android:layout_height="wrap_content"
65-
android:layout_weight="1" />
62+
android:layout_weight="1"
63+
android:background="@drawable/button"
64+
android:foreground="?android:attr/selectableItemBackground"
65+
android:text="Copy"
66+
android:textAlignment="center"
67+
android:textColor="@android:color/white" />
6668

6769

6870
</LinearLayout>

test-app/runtime/src/debug/res/layout/logcat_tab.xml

+9-8
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,19 @@
2121

2222
<Button
2323
android:id="@+id/btnCopyLogcat"
24-
android:layout_height="wrap_content"
25-
android:text="Copy to sdcard"
2624
android:layout_width="match_parent"
25+
android:layout_height="wrap_content"
26+
android:layout_alignParentBottom="true"
27+
android:layout_centerHorizontal="true"
28+
android:layout_marginLeft="10dp"
29+
android:layout_marginRight="10dp"
2730
android:background="@drawable/button"
28-
android:textColor="@android:color/white"
29-
android:textAlignment="center"
31+
android:foreground="?android:attr/selectableItemBackground"
3032
android:paddingLeft="20dp"
3133
android:paddingRight="20dp"
32-
android:layout_marginRight="10dp"
33-
android:layout_marginLeft="10dp"
34-
android:layout_alignParentBottom="true"
35-
android:layout_centerHorizontal="true"
34+
android:text="Copy to sdcard"
35+
android:textAlignment="center"
36+
android:textColor="@android:color/white"
3637
tools:layout_width="match_parent" />
3738

3839
</LinearLayout>

test-app/runtime/src/main/java/com/tns/RuntimeHelper.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import android.content.SharedPreferences;
99
import android.content.pm.PackageManager.NameNotFoundException;
1010
import android.os.Build;
11-
import android.preference.PreferenceManager;
11+
import androidx.preference.PreferenceManager;
1212
import android.util.Log;
1313

1414
import java.io.File;

test-app/runtime/src/main/java/com/tns/Util.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ static boolean runPlugin(Logger logger, Context context) {
5656

5757
try {
5858
Class<?> liveSyncPluginClass = Class.forName(pluginClassName);
59-
Plugin p = (Plugin) liveSyncPluginClass.newInstance();
59+
Plugin p = (Plugin) liveSyncPluginClass.getDeclaredConstructor().newInstance();
6060
success = p.execute(context);
6161
} catch (Exception e) {
6262
if (Util.isDebuggableApp(context) && logger.isEnabled()) {

0 commit comments

Comments
 (0)