android: Handle deprecated getParcelable* and getSerializable methods
This commit is contained in:
+23
-2
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package org.strongswan.android.ui;
|
package org.strongswan.android.ui;
|
||||||
|
|
||||||
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
@@ -58,7 +59,14 @@ public class RemediationInstructionFragment extends ListFragment
|
|||||||
|
|
||||||
if (savedInstanceState != null)
|
if (savedInstanceState != null)
|
||||||
{
|
{
|
||||||
mInstruction = savedInstanceState.getParcelable(ARG_REMEDIATION_INSTRUCTION);
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU)
|
||||||
|
{
|
||||||
|
mInstruction = getInstructionCompat(savedInstanceState);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mInstruction = savedInstanceState.getParcelable(ARG_REMEDIATION_INSTRUCTION, RemediationInstruction.class);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
/* show dividers only between list items */
|
/* show dividers only between list items */
|
||||||
getListView().setHeaderDividersEnabled(false);
|
getListView().setHeaderDividersEnabled(false);
|
||||||
@@ -85,7 +93,14 @@ public class RemediationInstructionFragment extends ListFragment
|
|||||||
Bundle args = getArguments();
|
Bundle args = getArguments();
|
||||||
if (args != null)
|
if (args != null)
|
||||||
{
|
{
|
||||||
mInstruction = args.getParcelable(ARG_REMEDIATION_INSTRUCTION);
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU)
|
||||||
|
{
|
||||||
|
mInstruction = getInstructionCompat(args);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mInstruction = args.getParcelable(ARG_REMEDIATION_INSTRUCTION, RemediationInstruction.class);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
updateView(mInstruction);
|
updateView(mInstruction);
|
||||||
}
|
}
|
||||||
@@ -117,4 +132,10 @@ public class RemediationInstructionFragment extends ListFragment
|
|||||||
setListAdapter(null);
|
setListAdapter(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
private static RemediationInstruction getInstructionCompat(Bundle bundle)
|
||||||
|
{
|
||||||
|
return bundle.getParcelable(ARG_REMEDIATION_INSTRUCTION);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+10
-1
@@ -43,7 +43,16 @@ public class RemediationInstructionsActivity extends AppCompatActivity implement
|
|||||||
if (frag != null)
|
if (frag != null)
|
||||||
{ /* two-pane layout, update fragment */
|
{ /* two-pane layout, update fragment */
|
||||||
Bundle extras = getIntent().getExtras();
|
Bundle extras = getIntent().getExtras();
|
||||||
ArrayList<RemediationInstruction> list = extras.getParcelableArrayList(RemediationInstructionsFragment.EXTRA_REMEDIATION_INSTRUCTIONS);
|
ArrayList<RemediationInstruction> list = null;
|
||||||
|
if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.TIRAMISU)
|
||||||
|
{
|
||||||
|
list = RemediationInstructionsFragment.getInstructionsCompat(extras);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
list = extras.getParcelableArrayList(RemediationInstructionsFragment.EXTRA_REMEDIATION_INSTRUCTIONS,
|
||||||
|
RemediationInstruction.class);
|
||||||
|
}
|
||||||
frag.updateView(list);
|
frag.updateView(list);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
+23
-2
@@ -17,6 +17,7 @@
|
|||||||
package org.strongswan.android.ui;
|
package org.strongswan.android.ui;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
@@ -55,7 +56,14 @@ public class RemediationInstructionsFragment extends ListFragment
|
|||||||
|
|
||||||
if (savedInstanceState != null)
|
if (savedInstanceState != null)
|
||||||
{
|
{
|
||||||
mInstructions = savedInstanceState.getParcelableArrayList(EXTRA_REMEDIATION_INSTRUCTIONS);
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU)
|
||||||
|
{
|
||||||
|
mInstructions = getInstructionsCompat(savedInstanceState);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mInstructions = savedInstanceState.getParcelableArrayList(EXTRA_REMEDIATION_INSTRUCTIONS, RemediationInstruction.class);
|
||||||
|
}
|
||||||
mCurrentPosition = savedInstanceState.getInt(KEY_POSITION);
|
mCurrentPosition = savedInstanceState.getInt(KEY_POSITION);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -93,7 +101,14 @@ public class RemediationInstructionsFragment extends ListFragment
|
|||||||
Bundle args = getArguments();
|
Bundle args = getArguments();
|
||||||
if (mInstructions == null && args != null)
|
if (mInstructions == null && args != null)
|
||||||
{
|
{
|
||||||
mInstructions = args.getParcelableArrayList(EXTRA_REMEDIATION_INSTRUCTIONS);
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU)
|
||||||
|
{
|
||||||
|
mInstructions = getInstructionsCompat(args);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mInstructions = args.getParcelableArrayList(EXTRA_REMEDIATION_INSTRUCTIONS, RemediationInstruction.class);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
updateView(mInstructions);
|
updateView(mInstructions);
|
||||||
|
|
||||||
@@ -123,4 +138,10 @@ public class RemediationInstructionsFragment extends ListFragment
|
|||||||
mInstructions = instructions;
|
mInstructions = instructions;
|
||||||
mAdapter.setData(mInstructions);
|
mAdapter.setData(mInstructions);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
public static ArrayList<RemediationInstruction> getInstructionsCompat(Bundle bundle)
|
||||||
|
{
|
||||||
|
return bundle.getParcelableArrayList(RemediationInstructionsFragment.EXTRA_REMEDIATION_INSTRUCTIONS);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+15
-1
@@ -21,6 +21,7 @@ import android.content.ActivityNotFoundException;
|
|||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
@@ -191,7 +192,14 @@ public class TrustedCertificateImportActivity extends AppCompatActivity
|
|||||||
{
|
{
|
||||||
final X509Certificate certificate;
|
final X509Certificate certificate;
|
||||||
|
|
||||||
certificate = (X509Certificate)getArguments().getSerializable(VpnProfileDataSource.KEY_CERTIFICATE);
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU)
|
||||||
|
{
|
||||||
|
certificate = getCertificateCompat(getArguments());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
certificate = getArguments().getSerializable(VpnProfileDataSource.KEY_CERTIFICATE, X509Certificate.class);
|
||||||
|
}
|
||||||
|
|
||||||
return new AlertDialog.Builder(getActivity())
|
return new AlertDialog.Builder(getActivity())
|
||||||
.setIcon(R.mipmap.ic_app)
|
.setIcon(R.mipmap.ic_app)
|
||||||
@@ -230,5 +238,11 @@ public class TrustedCertificateImportActivity extends AppCompatActivity
|
|||||||
{
|
{
|
||||||
getActivity().finish();
|
getActivity().finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
private static X509Certificate getCertificateCompat(Bundle bundle)
|
||||||
|
{
|
||||||
|
return (X509Certificate)bundle.getSerializable(VpnProfileDataSource.KEY_CERTIFICATE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+15
-1
@@ -17,6 +17,7 @@
|
|||||||
package org.strongswan.android.ui;
|
package org.strongswan.android.ui;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
@@ -83,7 +84,14 @@ public class TrustedCertificateListFragment extends ListFragment implements Menu
|
|||||||
Bundle arguments = getArguments();
|
Bundle arguments = getArguments();
|
||||||
if (arguments != null)
|
if (arguments != null)
|
||||||
{
|
{
|
||||||
mSource = (TrustedCertificateSource)arguments.getSerializable(EXTRA_CERTIFICATE_SOURCE);
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU)
|
||||||
|
{
|
||||||
|
mSource = getCertificateSourceCompat(arguments);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mSource = arguments.getSerializable(EXTRA_CERTIFICATE_SOURCE, TrustedCertificateSource.class);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
LoaderManager.getInstance(this).initLoader(0, null, this);
|
LoaderManager.getInstance(this).initLoader(0, null, this);
|
||||||
@@ -268,4 +276,10 @@ public class TrustedCertificateListFragment extends ListFragment implements Menu
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
private static TrustedCertificateSource getCertificateSourceCompat(Bundle bundle)
|
||||||
|
{
|
||||||
|
return (TrustedCertificateSource)bundle.getSerializable(EXTRA_CERTIFICATE_SOURCE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+14
@@ -21,6 +21,7 @@ import android.content.ContentResolver;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.security.KeyChain;
|
import android.security.KeyChain;
|
||||||
import android.security.KeyChainAliasCallback;
|
import android.security.KeyChainAliasCallback;
|
||||||
@@ -139,6 +140,19 @@ public class VpnProfileImportActivity extends AppCompatActivity
|
|||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
public Loader<ProfileLoadResult> onCreateLoader(int id, Bundle args)
|
public Loader<ProfileLoadResult> onCreateLoader(int id, Bundle args)
|
||||||
|
{
|
||||||
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU)
|
||||||
|
{
|
||||||
|
return createCompat(args);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return new ProfileLoader(VpnProfileImportActivity.this, args.getParcelable(PROFILE_URI, Uri.class));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
public Loader<ProfileLoadResult> createCompat(Bundle args)
|
||||||
{
|
{
|
||||||
return new ProfileLoader(VpnProfileImportActivity.this, args.getParcelable(PROFILE_URI));
|
return new ProfileLoader(VpnProfileImportActivity.this, args.getParcelable(PROFILE_URI));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user