package com.minamp; import android.app.Notification; import android.appwidget.AppWidgetManager; import android.content.Context; import android.graphics.Bitmap; import android.net.ConnectivityManager; import android.net.NetworkInfo; import com.minamp.plex.Item; /** * What differs between Plexamp Lite's builds, for Android 2.2 and later (the Galaxy Mini). platform/api16 has the * same methods for Android 4.1 and later; the rest of the app is shared and calls these. Keep the two in step. */ final class Platform { private Platform() {} /** The Android level this build is for: its minSdkVersion. */ static final int API = 8; /** Size the current track's art is loaded at for the notification, lock screen and widget, in pixels. */ static final int ART_PX = 96; /** At start-up, before anything else. */ static void init(App app) {} /** The player for a track. {@code fallback}: the track failed to decode in the usual one. */ static Engine newEngine(Context c, boolean fallback) { return new MediaPlayerEngine(c); } /** On a network that may cost by the megabyte (the "away" quality applies): here, anything but Wi-Fi. */ static boolean metered(Context c) { try { ConnectivityManager cm = (ConnectivityManager) c.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo ni = cm.getActiveNetworkInfo(); return ni != null && ni.getType() != ConnectivityManager.TYPE_WIFI; } catch (Exception e) { return false; } } /** The phone has no Menu key, so screens need a ⋮ button for the options menu. Android 2.x phones all have one. */ static boolean needsMenuButton(Context c) { return false; } /** The playback notification. Android 2.x: title and artist; its notifications can't have buttons. */ @SuppressWarnings("deprecation") static Notification playerNotification(Context c, Item it, Bitmap art, int state) { Notification n = new Notification(R.drawable.ic_stat, null, 0); n.flags |= Notification.FLAG_ONGOING_EVENT | Notification.FLAG_NO_CLEAR; String line = (state == PlayerService.PAUSED ? c.getString(R.string.paused_dot) : "") + it.artist; n.setLatestEventInfo(c, it.title, line, PlayerViews.open(c)); return n; } /** The lock screen's player (null item or IDLE: take it away). Android 2.x has none. */ static void lockScreen(Context c, Item it, Bitmap art, int state) {} /** The widget's layout for its current size. Android 2.x widgets have one size. */ static int widgetLayout(AppWidgetManager m, int id) { return R.layout.widget_player; } }