[Android] Use app context for toasts
Geoffrey Métais
git at videolan.org
Tue Jun 28 11:38:20 CEST 2016
vlc-android | branch: 2.0.x | Geoffrey Métais <geoffrey.metais at gmail.com> | Tue Jun 28 11:32:07 2016 +0200| [15b29ed6a52531e21d87dd6893cec419289e835e] | committer: Geoffrey Métais
Use app context for toasts
Could prevend context leaks
(cherry picked from commit 9e195cc758cd19033a41c9eacbc43d2416f41314)
> https://code.videolan.org/videolan/vlc-android/commit/15b29ed6a52531e21d87dd6893cec419289e835e
---
vlc-android/src/org/videolan/vlc/gui/audio/PlaylistAdapter.java | 2 +-
.../src/org/videolan/vlc/gui/tv/MediaItemDetailsFragment.java | 4 ++--
vlc-android/src/org/videolan/vlc/gui/tv/preferences/Advanced.java | 5 +++--
vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java | 4 ++--
vlc-android/src/org/videolan/vlc/util/SubtitlesDownloader.java | 2 +-
5 files changed, 9 insertions(+), 8 deletions(-)
diff --git a/vlc-android/src/org/videolan/vlc/gui/audio/PlaylistAdapter.java b/vlc-android/src/org/videolan/vlc/gui/audio/PlaylistAdapter.java
index 58306f9..09a0c97 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/PlaylistAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/PlaylistAdapter.java
@@ -180,7 +180,7 @@ public class PlaylistAdapter extends RecyclerView.Adapter<PlaylistAdapter.ViewHo
};
UiTools.snackerWithCancel(v, message, null, cancelAction);
} else if (mAudioPlayer instanceof Context){
- Toast.makeText((Context) mAudioPlayer, message, Toast.LENGTH_SHORT).show();
+ Toast.makeText(VLCApplication.getAppContext(), message, Toast.LENGTH_SHORT).show();
}
remove(position);
}
diff --git a/vlc-android/src/org/videolan/vlc/gui/tv/MediaItemDetailsFragment.java b/vlc-android/src/org/videolan/vlc/gui/tv/MediaItemDetailsFragment.java
index 1d8190d..ba5289f 100644
--- a/vlc-android/src/org/videolan/vlc/gui/tv/MediaItemDetailsFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/tv/MediaItemDetailsFragment.java
@@ -120,14 +120,14 @@ public class MediaItemDetailsFragment extends DetailsFragment implements Playbac
detailsOverview.removeAction(actionAdd);
detailsOverview.addAction(actionDelete);
mRowsAdapter.notifyArrayItemRangeChanged(0, mRowsAdapter.size());
- Toast.makeText(getActivity(), R.string.favorite_added, Toast.LENGTH_SHORT).show();
+ Toast.makeText(VLCApplication.getAppContext(), R.string.favorite_added, Toast.LENGTH_SHORT).show();
break;
case ID_FAVORITE_DELETE:
mDb.deleteNetworkFav(Uri.parse(mMedia.getLocation()));
detailsOverview.removeAction(actionDelete);
detailsOverview.addAction(actionAdd);
mRowsAdapter.notifyArrayItemRangeChanged(0, mRowsAdapter.size());
- Toast.makeText(getActivity(), R.string.favorite_removed, Toast.LENGTH_SHORT).show();
+ Toast.makeText(VLCApplication.getAppContext(), R.string.favorite_removed, Toast.LENGTH_SHORT).show();
break;
case ID_BROWSE:
TvUtil.openMedia(getActivity(), media, null);
diff --git a/vlc-android/src/org/videolan/vlc/gui/tv/preferences/Advanced.java b/vlc-android/src/org/videolan/vlc/gui/tv/preferences/Advanced.java
index 3c62363..90562e9 100644
--- a/vlc-android/src/org/videolan/vlc/gui/tv/preferences/Advanced.java
+++ b/vlc-android/src/org/videolan/vlc/gui/tv/preferences/Advanced.java
@@ -39,6 +39,7 @@ import android.widget.Toast;
import org.videolan.libvlc.util.HWDecoderUtil;
import org.videolan.vlc.BuildConfig;
import org.videolan.vlc.R;
+import org.videolan.vlc.VLCApplication;
import org.videolan.vlc.gui.helpers.AudioUtil;
import org.videolan.vlc.gui.helpers.BitmapCache;
import org.videolan.vlc.media.MediaDatabase;
@@ -121,7 +122,7 @@ public class Advanced extends BasePreferenceFragment implements SharedPreference
setLocalePref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
- Toast.makeText(getActivity(), R.string.set_locale_popup, Toast.LENGTH_SHORT).show();
+ Toast.makeText(VLCApplication.getAppContext(), R.string.set_locale_popup, Toast.LENGTH_SHORT).show();
return true;
}
});
@@ -164,7 +165,7 @@ public class Advanced extends BasePreferenceFragment implements SharedPreference
BitmapCache.getInstance().clear();
AudioUtil.clearCacheFolders();
getActivity().setResult(PreferencesActivity.RESULT_RESCAN);
- Toast.makeText(getActivity(), R.string.media_db_cleared, Toast.LENGTH_SHORT).show();
+ Toast.makeText(VLCApplication.getAppContext(), R.string.media_db_cleared, Toast.LENGTH_SHORT).show();
return true;
case "quit_app":
android.os.Process.killProcess(android.os.Process.myPid());
diff --git a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
index d48d1a8..2988268 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
@@ -1100,7 +1100,7 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C
if (mLockBackButton) {
mLockBackButton = false;
mHandler.sendEmptyMessageDelayed(RESET_BACK_LOCK, 2000);
- Toast.makeText(this, getString(R.string.back_quit_lock), Toast.LENGTH_SHORT).show();
+ Toast.makeText(VLCApplication.getAppContext(), getString(R.string.back_quit_lock), Toast.LENGTH_SHORT).show();
} else if(mPlaylist.getVisibility() == View.VISIBLE) {
togglePlaylist();
} else if (mPlaybackSetting != DelayState.OFF){
@@ -1720,7 +1720,7 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C
mHardwareAccelerationError = true;
if (mSwitchingView)
return;
- Toast.makeText(this, R.string.hardware_acceleration_error, Toast.LENGTH_LONG).show();
+ Toast.makeText(VLCApplication.getAppContext(), R.string.hardware_acceleration_error, Toast.LENGTH_LONG).show();
final boolean wasPaused = !mService.isPlaying();
final long oldTime = mService.getTime();
int position = mService.getCurrentMediaPosition();
diff --git a/vlc-android/src/org/videolan/vlc/util/SubtitlesDownloader.java b/vlc-android/src/org/videolan/vlc/util/SubtitlesDownloader.java
index 4971901..6dde45f 100644
--- a/vlc-android/src/org/videolan/vlc/util/SubtitlesDownloader.java
+++ b/vlc-android/src/org/videolan/vlc/util/SubtitlesDownloader.java
@@ -516,7 +516,7 @@ public class SubtitlesDownloader {
mHandler.post(new Runnable() {
@Override
public void run() {
- Toast.makeText(mContext, text, Toast.LENGTH_SHORT).show();
+ Toast.makeText(VLCApplication.getAppContext(), text, Toast.LENGTH_SHORT).show();
}
});
}
More information about the Android
mailing list