From 336aec5251fc9aac2e8b519fc6ef11e1dc088eed Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Thu, 22 Sep 2016 16:55:13 +0900 Subject: [PATCH] Replaced deprecated methods --- .../syncthingandroid/activities/FolderPickerActivity.java | 3 ++- .../nutomic/syncthingandroid/activities/MainActivity.java | 2 +- .../nutomic/syncthingandroid/fragments/DrawerFragment.java | 5 +++-- .../syncthingandroid/syncthing/DeviceStateHolder.java | 4 +++- .../syncthingandroid/syncthing/NetworkReceiver.java | 4 ++-- .../syncthing/PollWebGuiAvailableTask.java | 3 +-- .../com/nutomic/syncthingandroid/util/DevicesAdapter.java | 7 ++++--- .../com/nutomic/syncthingandroid/util/FoldersAdapter.java | 3 ++- 8 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/nutomic/syncthingandroid/activities/FolderPickerActivity.java b/src/main/java/com/nutomic/syncthingandroid/activities/FolderPickerActivity.java index c6abbe7c..caa97258 100644 --- a/src/main/java/com/nutomic/syncthingandroid/activities/FolderPickerActivity.java +++ b/src/main/java/com/nutomic/syncthingandroid/activities/FolderPickerActivity.java @@ -12,6 +12,7 @@ import android.os.Bundle; import android.os.Environment; import android.os.IBinder; import android.preference.PreferenceManager; +import android.support.v4.content.ContextCompat; import android.view.Menu; import android.view.MenuItem; import android.view.View; @@ -236,7 +237,7 @@ public class FolderPickerActivity extends SyncthingActivity int textColor = (f.isDirectory()) ? android.R.color.primary_text_light : android.R.color.tertiary_text_light; - title.setTextColor(getContext().getResources().getColor(textColor)); + title.setTextColor(ContextCompat.getColor(getContext(), textColor)); return convertView; } diff --git a/src/main/java/com/nutomic/syncthingandroid/activities/MainActivity.java b/src/main/java/com/nutomic/syncthingandroid/activities/MainActivity.java index 72ebd922..64c93a2a 100644 --- a/src/main/java/com/nutomic/syncthingandroid/activities/MainActivity.java +++ b/src/main/java/com/nutomic/syncthingandroid/activities/MainActivity.java @@ -221,7 +221,7 @@ public class MainActivity extends SyncthingActivity .commit(); mDrawerToggle = new Toggle(this, mDrawerLayout); mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED); - mDrawerLayout.setDrawerListener(mDrawerToggle); + mDrawerLayout.addDrawerListener(mDrawerToggle); setOptimalDrawerWidth(findViewById(R.id.drawer)); onNewIntent(getIntent()); diff --git a/src/main/java/com/nutomic/syncthingandroid/fragments/DrawerFragment.java b/src/main/java/com/nutomic/syncthingandroid/fragments/DrawerFragment.java index 2e4b2ade..2aa20193 100644 --- a/src/main/java/com/nutomic/syncthingandroid/fragments/DrawerFragment.java +++ b/src/main/java/com/nutomic/syncthingandroid/fragments/DrawerFragment.java @@ -4,6 +4,7 @@ import android.app.AlertDialog; import android.content.Intent; import android.os.Bundle; import android.support.v4.app.Fragment; +import android.support.v4.content.ContextCompat; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -161,9 +162,9 @@ public class DrawerFragment extends Fragment implements RestApi.OnReceiveSystemI mAnnounceServer.setText(Integer.toString(info.extAnnounceConnected) + "/" + Integer.toString(info.extAnnounceTotal)); if (info.extAnnounceConnected > 0) { - mAnnounceServer.setTextColor(getResources().getColor(R.color.text_green)); + mAnnounceServer.setTextColor(ContextCompat.getColor(getContext(), R.color.text_green)); } else { - mAnnounceServer.setTextColor(getResources().getColor(R.color.text_red)); + mAnnounceServer.setTextColor(ContextCompat.getColor(getContext(), R.color.text_red)); } } diff --git a/src/main/java/com/nutomic/syncthingandroid/syncthing/DeviceStateHolder.java b/src/main/java/com/nutomic/syncthingandroid/syncthing/DeviceStateHolder.java index 4157515e..01a4f4b2 100644 --- a/src/main/java/com/nutomic/syncthingandroid/syncthing/DeviceStateHolder.java +++ b/src/main/java/com/nutomic/syncthingandroid/syncthing/DeviceStateHolder.java @@ -6,6 +6,7 @@ import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; import android.net.ConnectivityManager; +import android.net.NetworkInfo; import android.net.wifi.WifiInfo; import android.net.wifi.WifiManager; import android.os.BatteryManager; @@ -53,7 +54,8 @@ public class DeviceStateHolder extends BroadcastReceiver { mContext = context; ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); - mIsWifiConnected = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI).isConnected(); + NetworkInfo ni = cm.getActiveNetworkInfo(); + mIsWifiConnected = ni != null && ni.getType() == ConnectivityManager.TYPE_WIFI && ni.isConnected(); if (android.os.Build.VERSION.SDK_INT >= 16 && cm.isActiveNetworkMetered()) mIsWifiConnected = false; if (mIsWifiConnected) { diff --git a/src/main/java/com/nutomic/syncthingandroid/syncthing/NetworkReceiver.java b/src/main/java/com/nutomic/syncthingandroid/syncthing/NetworkReceiver.java index 121c6bd0..dbcfe98c 100644 --- a/src/main/java/com/nutomic/syncthingandroid/syncthing/NetworkReceiver.java +++ b/src/main/java/com/nutomic/syncthingandroid/syncthing/NetworkReceiver.java @@ -24,8 +24,8 @@ public class NetworkReceiver extends BroadcastReceiver { ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); - NetworkInfo wifiInfo = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI); - boolean isWifiConnected = wifiInfo != null && wifiInfo.isConnected(); + NetworkInfo ni = cm.getActiveNetworkInfo(); + boolean isWifiConnected = ni != null && ni.getType() == ConnectivityManager.TYPE_WIFI && ni.isConnected(); Log.v(TAG, "Received wifi " + (isWifiConnected ? "connected" : "disconnected") + " event"); Intent i = new Intent(context, SyncthingService.class); i.putExtra(DeviceStateHolder.EXTRA_HAS_WIFI, isWifiConnected); diff --git a/src/main/java/com/nutomic/syncthingandroid/syncthing/PollWebGuiAvailableTask.java b/src/main/java/com/nutomic/syncthingandroid/syncthing/PollWebGuiAvailableTask.java index 3d64b46b..e178ed03 100644 --- a/src/main/java/com/nutomic/syncthingandroid/syncthing/PollWebGuiAvailableTask.java +++ b/src/main/java/com/nutomic/syncthingandroid/syncthing/PollWebGuiAvailableTask.java @@ -2,7 +2,6 @@ package com.nutomic.syncthingandroid.syncthing; import android.os.AsyncTask; -import android.util.Log; import com.nutomic.syncthingandroid.util.Https; @@ -53,7 +52,7 @@ public abstract class PollWebGuiAvailableTask extends AsyncTask if (conn != null && conn.connected) { if (conn.completion == 100) { status.setText(r.getString(R.string.device_up_to_date)); - status.setTextColor(r.getColor(R.color.text_green)); + status.setTextColor(ContextCompat.getColor(getContext(), R.color.text_green)); } else { status.setText(r.getString(R.string.device_syncing, conn.completion)); - status.setTextColor(r.getColor(R.color.text_blue)); + status.setTextColor(ContextCompat.getColor(getContext(), R.color.text_blue)); } download.setText(RestApi.readableTransferRate(getContext(), conn.inBits)); upload.setText(RestApi.readableTransferRate(getContext(), conn.outBits)); @@ -61,7 +62,7 @@ public class DevicesAdapter extends ArrayAdapter download.setText(RestApi.readableTransferRate(getContext(), 0)); upload.setText(RestApi.readableTransferRate(getContext(), 0)); status.setText(r.getString(R.string.device_disconnected)); - status.setTextColor(r.getColor(R.color.text_red)); + status.setTextColor(ContextCompat.getColor(getContext(), R.color.text_red)); } return convertView; diff --git a/src/main/java/com/nutomic/syncthingandroid/util/FoldersAdapter.java b/src/main/java/com/nutomic/syncthingandroid/util/FoldersAdapter.java index b73699f3..6d740891 100644 --- a/src/main/java/com/nutomic/syncthingandroid/util/FoldersAdapter.java +++ b/src/main/java/com/nutomic/syncthingandroid/util/FoldersAdapter.java @@ -1,6 +1,7 @@ package com.nutomic.syncthingandroid.util; import android.content.Context; +import android.support.v4.content.ContextCompat; import android.text.TextUtils; import android.view.LayoutInflater; import android.view.View; @@ -47,7 +48,7 @@ public class FoldersAdapter extends ArrayAdapter RestApi.Folder folder = getItem(position); RestApi.Model model = mModels.get(folder.id); label.setText(TextUtils.isEmpty(folder.label) ? folder.id : folder.label); - state.setTextColor(getContext().getResources().getColor(R.color.text_green)); + state.setTextColor(ContextCompat.getColor(getContext(), R.color.text_green)); directory.setText(folder.path); if (model != null) { int percentage = (model.globalBytes != 0)