Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Android: Added widget compatible with lock screen on Android 4.2+. Th…
…e widget only shows "Loading" for now. Related to issue #406.
- Loading branch information
1 parent
5dc027d
commit e69bac3
Showing
8 changed files
with
390 additions
and
195 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// Copyright © 2011-2013 Yanick Castonguay | ||
// | ||
// This file is part of MPfm. | ||
// | ||
// MPfm is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// MPfm is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with MPfm. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
using System; | ||
using Android.App; | ||
using Android.Content; | ||
using Android.OS; | ||
using Android.Views; | ||
using Android.Views.Animations; | ||
using MPfm.MVP.Bootstrap; | ||
using MPfm.MVP.Messages; | ||
using MPfm.MVP.Services.Interfaces; | ||
using TinyMessenger; | ||
|
||
namespace MPfm.Android.Classes.Services | ||
{ | ||
[Service] | ||
public class WidgetService : Service | ||
{ | ||
private ITinyMessengerHub _messengerHub; | ||
private IPlayerService _playerService; | ||
private Context _context; | ||
|
||
public override void OnStart(Intent intent, int startId) | ||
{ | ||
Console.WriteLine("TestService - OnStart - startId: {0}", startId); | ||
Initialize(); | ||
base.OnStart(intent, startId); | ||
} | ||
|
||
public override StartCommandResult OnStartCommand(Intent intent, StartCommandFlags flags, int startId) | ||
{ | ||
Console.WriteLine("TestService - OnStartCommand - startId: {0}", startId); | ||
Initialize(); | ||
return base.OnStartCommand(intent, flags, startId); | ||
} | ||
|
||
private void Initialize() | ||
{ | ||
_messengerHub = Bootstrapper.GetContainer().Resolve<ITinyMessengerHub>(); | ||
_playerService = Bootstrapper.GetContainer().Resolve<IPlayerService>(); | ||
_messengerHub.Subscribe<PlayerPlaylistIndexChangedMessage>((message) => | ||
{ | ||
Console.WriteLine("WidgetService - PlayerPlaylistIndexChangedMessage"); | ||
}); | ||
_messengerHub.Subscribe<PlayerStatusMessage>((message) => | ||
{ | ||
Console.WriteLine("WidgetService - PlayerStatusMessage - Status=" + message.Status.ToString()); | ||
}); | ||
|
||
// Force updating the view for the first time | ||
UpdateView(); | ||
} | ||
|
||
private void UpdateView() | ||
{ | ||
} | ||
|
||
public override IBinder OnBind(Intent intent) | ||
{ | ||
// We don't need to bind to this service | ||
return null; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Copyright © 2011-2013 Yanick Castonguay | ||
// | ||
// This file is part of MPfm. | ||
// | ||
// MPfm is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// MPfm is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with MPfm. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
using System; | ||
using Android.App; | ||
using Android.Appwidget; | ||
using Android.Content; | ||
using MPfm.Android.Classes.Services; | ||
|
||
namespace MPfm.Android.Classes.Widgets | ||
{ | ||
[BroadcastReceiver(Label = "Sessions")] | ||
[IntentFilter(new string[] { "android.appwidget.action.APPWIDGET_UPDATE" })] | ||
[MetaData("android.appwidget.provider", Resource = "@xml/widget_player")] | ||
public class PlayerWidget : AppWidgetProvider | ||
{ | ||
public override void OnUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) | ||
{ | ||
Console.WriteLine("PlayerWidget - OnUpdate"); | ||
context.StartService(new Intent(context, typeof (WidgetService))); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:installLocation="internalOnly"> | ||
<uses-sdk android:targetSdkVersion="15" /> | ||
<uses-sdk android:targetSdkVersion="17" /> | ||
<application android:label="Sessions" android:theme="@style/MyAppTheme" android:icon="@drawable/icon"></application> | ||
<uses-permission android:name="android.permission.INTERNET" /> | ||
</manifest> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:id="@+id/widgetPlayer" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:orientation="vertical" | ||
android:background="#FF0000"> | ||
<TextView | ||
android:id="@+id/widgetPlayer_message" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:layout_marginTop="12dip" | ||
android:padding="10dip" | ||
android:gravity="center" | ||
android:text="Loading" /> | ||
</LinearLayout> |
16 changes: 16 additions & 0 deletions
16
MPfm/MPfm.Android/Resources/Layout/WidgetPlayerLoading.axml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:id="@+id/widgetPlayerLoading" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:orientation="vertical" | ||
android:background="#36454F"> | ||
<TextView | ||
android:id="@+id/widgetPlayerLoading_Message" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:layout_marginTop="12dip" | ||
android:padding="10dip" | ||
android:gravity="center" | ||
android:text="Loading..." /> | ||
</LinearLayout> |
Oops, something went wrong.