Skip to content

Commit

Permalink
Fix obsolete API usage (#315)
Browse files Browse the repository at this point in the history
Context: dotnet/java-interop@fefe0cad
Context: https://dev.azure.com/devdiv/DevDiv/_releaseProgress?releaseId=654124&_a=release-environment-extension&environmentId=3567428&extensionId=ms.vss-test-web.test-result-in-release-environment-editor-tab

These projects have been failing to build against Xamarin.Android d16-6,
and they can be fixed by updating their usage of obsolete APIs.
  • Loading branch information
pjcollins authored Apr 24, 2020
1 parent eb0e85d commit a4d2b33
Show file tree
Hide file tree
Showing 15 changed files with 44 additions and 53 deletions.
5 changes: 2 additions & 3 deletions HoneycombGallery/CameraFragment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,13 @@

using System;
using System.Collections.Generic;
using Android.Graphics;
using Java.IO;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Util;
using Android.Views;
using Camera = Android.Hardware.Camera;
using Android.Hardware;

namespace com.example.monodroid.hcgallery
{
Expand Down Expand Up @@ -54,7 +53,7 @@ public override void OnCreate (Bundle savedInstanceState)
Camera.CameraInfo cameraInfo = new Camera.CameraInfo ();
for (int i = 0; i < mNumberOfCameras; i++) {
Camera.GetCameraInfo (i, cameraInfo);
if (cameraInfo.Facing == Camera.CameraInfo.CameraFacingBack) {
if (cameraInfo.Facing == CameraFacing.Back) {
mDefaultCameraId = i;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ protected override void OnCreate (Bundle bundle)
var visibleButton = FindViewById<Button> (Resource.Id.visibleButton);

lowProfileButton.Click += delegate {
tv.SystemUiVisibility = (StatusBarVisibility)View.SystemUiFlagLowProfile;
tv.SystemUiVisibility = (StatusBarVisibility)SystemUiFlags.LowProfile;
};

hideNavButton.Click += delegate {
tv.SystemUiVisibility = (StatusBarVisibility)View.SystemUiFlagHideNavigation;
tv.SystemUiVisibility = (StatusBarVisibility)SystemUiFlags.HideNavigation;
};

visibleButton.Click += delegate {
tv.SystemUiVisibility = (StatusBarVisibility)View.SystemUiFlagVisible;
tv.SystemUiVisibility = (StatusBarVisibility)SystemUiFlags.Visible;
};

tv.SystemUiVisibilityChange += delegate(object sender, View.SystemUiVisibilityChangeEventArgs e) {
Expand Down
8 changes: 4 additions & 4 deletions UrbanAirship/samples/PushSample/CustomPreferencesActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -182,14 +182,14 @@ public override void OnStop() {

// Grab the start date.
Calendar cal = Calendar.Instance;
cal.Set(Calendar.HourOfDay, (int) startTime.CurrentHour);
cal.Set(Calendar.Minute, (int) startTime.CurrentMinute);
cal.Set(CalendarField.HourOfDay, (int) startTime.CurrentHour);
cal.Set(CalendarField.Minute, (int) startTime.CurrentMinute);
Date startDate = cal.Time;

// Prepare the end date.
cal = Calendar.Instance;
cal.Set(Calendar.HourOfDay, (int) endTime.CurrentHour);
cal.Set(Calendar.Minute, (int) endTime.CurrentMinute);
cal.Set(CalendarField.HourOfDay, (int) endTime.CurrentHour);
cal.Set(CalendarField.Minute, (int) endTime.CurrentMinute);
Date endDate = cal.Time;

pushPrefs.SetQuietTimeInterval (startDate, endDate);
Expand Down
17 changes: 7 additions & 10 deletions android-o/AndroidCipher/AndroidCipher/AndroidCipher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
using System.Text;
using Android.Util;
using Java.Security.Spec;
using static System.Text.Encoding;
using static Android.Util.Base64;
using static Javax.Crypto.Cipher;

namespace AndroidCipher
{
Expand All @@ -27,11 +24,11 @@ public AndroidCipher(MainActivity activity)

public void Decryption(object sender, EventArgs eventArgs)
{
var decipher = GetInstance(Constants.Transformation);
var decipher = Cipher.GetInstance(Constants.Transformation);
var algorithmParameterSpec = (IAlgorithmParameterSpec)_encipher.Parameters.GetParameterSpec(Java.Lang.Class.FromType(typeof(GCMParameterSpec)));
decipher.Init(DecryptMode, _secretKey, algorithmParameterSpec);
decipher.Init(CipherMode.DecryptMode, _secretKey, algorithmParameterSpec);

byte[] decodedValue = Decode(UTF8.GetBytes(_activity.textOutput.Text), Base64.Default);
byte[] decodedValue = Base64.Decode(Encoding.UTF8.GetBytes(_activity.textOutput.Text), Base64Flags.Default);
byte[] decryptedVal = decipher.DoFinal(decodedValue);
_activity.textOriginal.Text = Encoding.Default.GetString(decryptedVal);
}
Expand All @@ -47,12 +44,12 @@ public void Encryption(object sender, EventArgs eventArgs)
_secretKey = GenerateKey();
if (ValidateInput(_activity.textInput.Text)) return;

_encipher = GetInstance(Constants.Transformation);
_encipher.Init(EncryptMode, _secretKey, GenerateGcmParameterSpec());
_encipher = Cipher.GetInstance(Constants.Transformation);
_encipher.Init(CipherMode.EncryptMode, _secretKey, GenerateGcmParameterSpec());

byte[]
results = _encipher.DoFinal(UTF8.GetBytes(_activity.textInput.Text));
_activity.textOutput.Text = EncodeToString(results, Base64.Default);
results = _encipher.DoFinal(Encoding.UTF8.GetBytes(_activity.textInput.Text));
_activity.textOutput.Text = Base64.EncodeToString(results, Base64Flags.Default);
}

private bool ValidateInput(string input)
Expand Down
1 change: 0 additions & 1 deletion android-o/AndroidCipher/AndroidCipher/AndroidCipher.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
<AndroidResgenFile>Resources\Resource.Designer.cs</AndroidResgenFile>
<AndroidResgenClass>Resource</AndroidResgenClass>
<GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
<AndroidUseLatestPlatformSdk>False</AndroidUseLatestPlatformSdk>
<TargetFrameworkVersion>v8.1</TargetFrameworkVersion>
<AndroidManifest>Properties\AndroidManifest.xml</AndroidManifest>
<MonoAndroidResourcePrefix>Resources</MonoAndroidResourcePrefix>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
<AndroidManifest>Properties\AndroidManifest.xml</AndroidManifest>
<MonoAndroidResourcePrefix>Resources</MonoAndroidResourcePrefix>
<MonoAndroidAssetsPrefix>Assets</MonoAndroidAssetsPrefix>
<AndroidUseLatestPlatformSdk>false</AndroidUseLatestPlatformSdk>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,10 @@ public override void OnCreate()
ServiceHandler = new Handler(handlerThread.Looper);
NotificationManager = (NotificationManager) GetSystemService(NotificationService);

if (Build.VERSION.SdkInt >= Build.VERSION_CODES.O)
if (Build.VERSION.SdkInt >= BuildVersionCodes.O)
{
string name = GetString(Resource.String.app_name);
NotificationChannel mChannel = new NotificationChannel(ChannelId, name, NotificationManager.ImportanceDefault);
NotificationChannel mChannel = new NotificationChannel(ChannelId, name, NotificationImportance.Default);
NotificationManager.CreateNotificationChannel(mChannel);
}
}
Expand Down Expand Up @@ -269,7 +269,7 @@ Notification GetNotification()
.SetTicker(text)
.SetWhen(JavaSystem.CurrentTimeMillis());

if (Build.VERSION.SdkInt>= Build.VERSION_CODES.O)
if (Build.VERSION.SdkInt>= BuildVersionCodes.O)
{
builder.SetChannelId(ChannelId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
<AndroidManifest>Properties\AndroidManifest.xml</AndroidManifest>
<MonoAndroidResourcePrefix>Resources</MonoAndroidResourcePrefix>
<MonoAndroidAssetsPrefix>Assets</MonoAndroidAssetsPrefix>
<AndroidUseLatestPlatformSdk>false</AndroidUseLatestPlatformSdk>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,12 @@ public static void SendNotification(Context context, string notificationDetails)
var mNotificationManager = context.GetSystemService(Context.NotificationService) as NotificationManager;

// Android O requires a Notification Channel.
if (Build.VERSION.SdkInt>= Build.VERSION_CODES.O)
if (Build.VERSION.SdkInt>= BuildVersionCodes.O)
{
string name = context.GetString(Resource.String.app_name);
// Create the channel for the notification
// Create the channel for the notification
NotificationChannel mChannel = new NotificationChannel(ChannelId, name, NotificationManager.ImportanceDefault);
NotificationChannel mChannel = new NotificationChannel(ChannelId, name, NotificationImportance.Default);

// Set the Notification Channel for the Notification Manager.
mNotificationManager.CreateNotificationChannel(mChannel);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
<AndroidManifest>Properties\AndroidManifest.xml</AndroidManifest>
<MonoAndroidResourcePrefix>Resources</MonoAndroidResourcePrefix>
<MonoAndroidAssetsPrefix>Assets</MonoAndroidAssetsPrefix>
<AndroidUseLatestPlatformSdk>false</AndroidUseLatestPlatformSdk>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ public CreditCardExpirationDateCompoundView(Context context, IAttributeSet attrs
var rootView = LayoutInflater.From(context).Inflate(Resource.Layout.cc_exp_date, this);
mCcExpMonthSpinner = rootView.FindViewById<Spinner>(Resource.Id.ccExpMonth);
mCcExpYearSpinner = rootView.FindViewById<Spinner>(Resource.Id.ccExpYear);
ImportantForAutofill = ImportantForAutofillYesExcludeDescendants;
ImportantForAutofill = ImportantForAutofill.YesExcludeDescendants;
var monthAdapter = ArrayAdapter.CreateFromResource(context, Resource.Array.month_array,
Android.Resource.Layout.SimpleSpinnerItem);
monthAdapter.SetDropDownViewResource(Android.Resource.Layout.SimpleSpinnerDropDownItem);
mCcExpMonthSpinner.Adapter = monthAdapter;
int year = Calendar.Instance.Get(Calendar.Year);
int year = Calendar.Instance.Get(CalendarField.Year);
for (int i = 0; i < mYears.Length; i++)
{
mYears[i] = (year + i).ToString();
Expand Down Expand Up @@ -92,8 +92,8 @@ public override AutofillValue AutofillValue
calendar.Clear();
var year = Integer.ParseInt(mCcExpYearSpinner.SelectedItem.ToString());
var month = mCcExpMonthSpinner.SelectedItemPosition;
calendar.Set(Calendar.Year, year);
calendar.Set(Calendar.Month, month);
calendar.Set(CalendarField.Year, year);
calendar.Set(CalendarField.Month, month);
var unixTime = calendar.TimeInMillis;
return AutofillValue.ForDate(unixTime);
}
Expand All @@ -109,8 +109,8 @@ public override void Autofill(AutofillValue value)

var calendar = Calendar.Instance;
calendar.TimeInMillis = value.DateValue;
var month = calendar.Get(Calendar.Month);
var year = calendar.Get(Calendar.Year);
var month = calendar.Get(CalendarField.Month);
var year = calendar.Get(CalendarField.Year);
mCcExpMonthSpinner.SetSelection(month);
mCcExpYearSpinner.SetSelection(year - Integer.ParseInt(mYears[0]));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ public CreditCardExpirationDatePickerView(Context context, IAttributeSet attrs,
{
// Use the current date as the initial date in the picker.
mTempCalendar = Calendar.Instance;
mYear = mTempCalendar.Get(Calendar.Year);
mMonth = mTempCalendar.Get(Calendar.Month);
mYear = mTempCalendar.Get(CalendarField.Year);
mMonth = mTempCalendar.Get(CalendarField.Month);
}

/**
Expand All @@ -55,9 +55,9 @@ public CreditCardExpirationDatePickerView(Context context, IAttributeSet attrs,
private Calendar GetCalendar()
{
mTempCalendar.Clear();
mTempCalendar.Set(Calendar.Year, mYear);
mTempCalendar.Set(Calendar.Month, mMonth);
mTempCalendar.Set(Calendar.Date, 1);
mTempCalendar.Set(CalendarField.Year, mYear);
mTempCalendar.Set(CalendarField.Month, mMonth);
mTempCalendar.Set(CalendarField.Date, 1);
return mTempCalendar;
}

Expand All @@ -81,8 +81,8 @@ public override void Autofill(AutofillValue value)
}
var time = value.DateValue;
mTempCalendar.TimeInMillis = time;
var year = mTempCalendar.Get(Calendar.Year);
var month = mTempCalendar.Get(Calendar.Month);
var year = mTempCalendar.Get(CalendarField.Year);
var month = mTempCalendar.Get(CalendarField.Month);
if (CommonUtil.DEBUG) Log.Debug(CommonUtil.TAG, "autofill(" + value + "): " + month + "/" + year);
SetDate(year, month);
}
Expand All @@ -101,7 +101,7 @@ private void SetDate(int year, int month)
public void Reset()
{
mTempCalendar.TimeInMillis = DateTime.Now.Millisecond;
SetDate(mTempCalendar.Get(Calendar.Year), mTempCalendar.Get(Calendar.Month));
SetDate(mTempCalendar.Get(CalendarField.Year), mTempCalendar.Get(CalendarField.Month));
}

public void ShowDatePickerDialog(FragmentManager fragmentManager)
Expand All @@ -126,7 +126,7 @@ public override Dialog OnCreateDialog(Bundle savedInstanceState)
// Limit range.
Calendar c = mParent.GetCalendar();
datePicker.MinDate = c.TimeInMillis;
c.Set(Calendar.Year, mParent.mYear + CC_EXP_YEARS_COUNT - 1);
c.Set(CalendarField.Year, mParent.mYear + CC_EXP_YEARS_COUNT - 1);
datePicker.MaxDate = c.TimeInMillis;

// Remove day.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ autofill this spinner.
monthAdapter.SetDropDownViewResource(Android.Resource.Layout.SimpleSpinnerDropDownItem);
mCcExpirationMonthSpinner.Adapter = monthAdapter;

int year = Java.Util.Calendar.Instance.Get(Java.Util.Calendar.Year);
int year = Java.Util.Calendar.Instance.Get(Java.Util.CalendarField.Year);
for (int i = 0; i < years.Length; i++)
{
years[i] = (year + i).ToString();
Expand Down
14 changes: 7 additions & 7 deletions android-o/AutofillFramework/AutofillService/AutofillHints.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using Android.Util;
using Android.Views;
using AutofillService.Model;
using static Android.Icu.Util.Calendar;
using static Android.Icu.Util.CalendarField;

namespace AutofillService
{
Expand Down Expand Up @@ -805,7 +805,7 @@ public FakeFieldGeneratorForDate(string type)
public FilledAutofillField Generate(int seed)
{
var filledAutofillField = new FilledAutofillField(Type);
var calendar = Instance;
var calendar = Android.Icu.Util.Calendar.Instance;
calendar.Set(Year, calendar.Get(Year) + seed);
filledAutofillField.SetDateValue(calendar.TimeInMillis);
return filledAutofillField;
Expand All @@ -825,7 +825,7 @@ public FilledAutofillField Generate(int seed)
{
var months = MonthRange();
int month = seed % months.Length;
var calendar = Instance;
var calendar = Android.Icu.Util.Calendar.Instance;
calendar.Set(Month, month);
var filledAutofillField = new FilledAutofillField(Type);
filledAutofillField.SetListValue(months, month);
Expand All @@ -847,7 +847,7 @@ public FakeFieldGeneratorExpirationYear(string type)
public FilledAutofillField Generate(int seed)
{
FilledAutofillField filledAutofillField = new FilledAutofillField(Type);
var calendar = Instance;
var calendar = Android.Icu.Util.Calendar.Instance;
int expYear = calendar.Get(Year) + seed;
calendar.Set(Year, expYear);
filledAutofillField.SetDateValue(calendar.TimeInMillis);
Expand All @@ -870,7 +870,7 @@ public FilledAutofillField Generate(int seed)
var days = DayRange();
int day = seed % days.Length;
var filledAutofillField = new FilledAutofillField(Type);
var calendar = Instance;
var calendar = Android.Icu.Util.Calendar.Instance;
calendar.Set(Date, day);
filledAutofillField.SetListValue(days, day);
filledAutofillField.SetTextValue(day.ToString());
Expand All @@ -891,7 +891,7 @@ public FakeFieldGeneratorBdayYear(string type)
public FilledAutofillField Generate(int seed)
{
var filledAutofillField = new FilledAutofillField(Type);
int year = Instance.Get(Year) - seed * 10;
int year = Android.Icu.Util.Calendar.Instance.Get(Year) - seed * 10;
filledAutofillField.SetTextValue("" + year);
return filledAutofillField;
}
Expand All @@ -909,7 +909,7 @@ public FakeFieldGeneratorForBirthDay(string type)
public FilledAutofillField Generate(int seed)
{
var filledAutofillField = new FilledAutofillField(Type);
var calendar = Instance;
var calendar = Android.Icu.Util.Calendar.Instance;
calendar.Set(Year, calendar.Get(Year) - seed * 10);
calendar.Set(Month, seed % 12);
calendar.Set(Date, seed % 27);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
<AndroidManifest>Properties\AndroidManifest.xml</AndroidManifest>
<MonoAndroidResourcePrefix>Resources</MonoAndroidResourcePrefix>
<MonoAndroidAssetsPrefix>Assets</MonoAndroidAssetsPrefix>
<AndroidUseLatestPlatformSdk>false</AndroidUseLatestPlatformSdk>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
Expand Down

0 comments on commit a4d2b33

Please sign in to comment.