mirror of
https://github.com/strongswan/strongswan.git
synced 2025-10-03 00:00:24 -04:00
android: Handle deprecated getParcelable* and getSerializable methods
This commit is contained in:
parent
288bd41aca
commit
4e2c88f7ed
@ -16,6 +16,7 @@
|
||||
|
||||
package org.strongswan.android.ui;
|
||||
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
@ -58,7 +59,14 @@ public class RemediationInstructionFragment extends ListFragment
|
||||
|
||||
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 */
|
||||
getListView().setHeaderDividersEnabled(false);
|
||||
@ -85,7 +93,14 @@ public class RemediationInstructionFragment extends ListFragment
|
||||
Bundle args = getArguments();
|
||||
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);
|
||||
}
|
||||
@ -117,4 +132,10 @@ public class RemediationInstructionFragment extends ListFragment
|
||||
setListAdapter(null);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
private static RemediationInstruction getInstructionCompat(Bundle bundle)
|
||||
{
|
||||
return bundle.getParcelable(ARG_REMEDIATION_INSTRUCTION);
|
||||
}
|
||||
}
|
||||
|
@ -43,7 +43,16 @@ public class RemediationInstructionsActivity extends AppCompatActivity implement
|
||||
if (frag != null)
|
||||
{ /* two-pane layout, update fragment */
|
||||
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);
|
||||
}
|
||||
else
|
||||
|
@ -17,6 +17,7 @@
|
||||
package org.strongswan.android.ui;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.ListView;
|
||||
@ -55,7 +56,14 @@ public class RemediationInstructionsFragment extends ListFragment
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
@ -93,7 +101,14 @@ public class RemediationInstructionsFragment extends ListFragment
|
||||
Bundle args = getArguments();
|
||||
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);
|
||||
|
||||
@ -123,4 +138,10 @@ public class RemediationInstructionsFragment extends ListFragment
|
||||
mInstructions = instructions;
|
||||
mAdapter.setData(mInstructions);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public static ArrayList<RemediationInstruction> getInstructionsCompat(Bundle bundle)
|
||||
{
|
||||
return bundle.getParcelableArrayList(RemediationInstructionsFragment.EXTRA_REMEDIATION_INSTRUCTIONS);
|
||||
}
|
||||
}
|
||||
|
@ -21,6 +21,7 @@ import android.content.ActivityNotFoundException;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.widget.Toast;
|
||||
|
||||
@ -191,7 +192,14 @@ public class TrustedCertificateImportActivity extends AppCompatActivity
|
||||
{
|
||||
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())
|
||||
.setIcon(R.mipmap.ic_app)
|
||||
@ -230,5 +238,11 @@ public class TrustedCertificateImportActivity extends AppCompatActivity
|
||||
{
|
||||
getActivity().finish();
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
private static X509Certificate getCertificateCompat(Bundle bundle)
|
||||
{
|
||||
return (X509Certificate)bundle.getSerializable(VpnProfileDataSource.KEY_CERTIFICATE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -17,6 +17,7 @@
|
||||
package org.strongswan.android.ui;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.text.TextUtils;
|
||||
import android.view.Menu;
|
||||
@ -83,7 +84,14 @@ public class TrustedCertificateListFragment extends ListFragment implements Menu
|
||||
Bundle arguments = getArguments();
|
||||
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);
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -21,6 +21,7 @@ import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.security.KeyChain;
|
||||
import android.security.KeyChainAliasCallback;
|
||||
@ -139,6 +140,19 @@ public class VpnProfileImportActivity extends AppCompatActivity
|
||||
{
|
||||
@Override
|
||||
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));
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user