-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
quick play widget, don't wrap news cards, minor improvements
* restart player when error occurred, don't wrap news * update .travis.yml * improve playback error listener * add quick play widget * widget improvements
- Loading branch information
1 parent
d47eb14
commit 03052c4
Showing
27 changed files
with
258 additions
and
14 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
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
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
81 changes: 81 additions & 0 deletions
81
app/src/main/java/org/indywidualni/centrumfm/WidgetIntentReceiver.java
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,81 @@ | ||
package org.indywidualni.centrumfm; | ||
|
||
import android.content.BroadcastReceiver; | ||
import android.content.ComponentName; | ||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.content.ServiceConnection; | ||
import android.content.SharedPreferences; | ||
import android.os.IBinder; | ||
import android.preference.PreferenceManager; | ||
import android.util.Log; | ||
import android.widget.Toast; | ||
|
||
import com.google.android.gms.analytics.HitBuilders; | ||
import com.google.android.gms.analytics.Tracker; | ||
|
||
import org.indywidualni.centrumfm.activity.MainActivity; | ||
import org.indywidualni.centrumfm.util.Connectivity; | ||
|
||
public class WidgetIntentReceiver extends BroadcastReceiver { | ||
|
||
@Override | ||
public void onReceive(Context context, Intent intent) { | ||
if (WidgetProvider.QUICK_PLAY.equals(intent.getAction())) | ||
bindStreamService(context); | ||
} | ||
|
||
private void bindStreamService(Context context) { | ||
context = context.getApplicationContext(); | ||
Intent intent = new Intent(context, StreamService.class); | ||
context.bindService(intent, mConnection, Context.BIND_AUTO_CREATE); | ||
} | ||
|
||
private ServiceConnection mConnection = new ServiceConnection() { | ||
@Override | ||
public void onServiceConnected(ComponentName className, IBinder service) { | ||
Log.d("ServiceConnectionWidget", "connected"); | ||
StreamService.LocalBinder binder = (StreamService.LocalBinder) service; | ||
StreamService streamService = binder.getService(); | ||
|
||
Context context = MyApplication.getContextOfApplication(); | ||
Tracker tracker = ((MyApplication) context).getDefaultTracker(); | ||
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context); | ||
|
||
if (streamService.isPlaying()) { | ||
streamService.stopPlayer(); | ||
} else { | ||
if (Connectivity.isConnected(context)) { | ||
if (Connectivity.isConnectedMobile(context) | ||
&& !preferences.getBoolean("mobile_streaming", false)) { | ||
Toast.makeText(context, context.getString(R.string.mobile_restriction), | ||
Toast.LENGTH_SHORT).show(); | ||
} else { | ||
streamService.playUrl(MainActivity.STREAM_URL); | ||
streamService.foregroundStart(); | ||
|
||
if (Connectivity.isConnectedMobile(context)) { | ||
tracker.send(new HitBuilders.EventBuilder() | ||
.setCategory("Quick Play Radio") | ||
.setAction("Play stream mobile") | ||
.build()); | ||
} else { | ||
tracker.send(new HitBuilders.EventBuilder() | ||
.setCategory("Quick Play Radio") | ||
.setAction("Play stream Wi-Fi") | ||
.build()); | ||
} | ||
} | ||
} else { | ||
Toast.makeText(context, context.getString(R.string.no_network), | ||
Toast.LENGTH_SHORT).show(); | ||
} | ||
} | ||
} | ||
@Override | ||
public void onServiceDisconnected(ComponentName className) { | ||
Log.d("ServiceConnectionWidget", "disconnected"); | ||
} | ||
}; | ||
|
||
} |
36 changes: 36 additions & 0 deletions
36
app/src/main/java/org/indywidualni/centrumfm/WidgetProvider.java
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,36 @@ | ||
package org.indywidualni.centrumfm; | ||
|
||
import android.app.PendingIntent; | ||
import android.appwidget.AppWidgetManager; | ||
import android.appwidget.AppWidgetProvider; | ||
import android.content.ComponentName; | ||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.widget.RemoteViews; | ||
|
||
public class WidgetProvider extends AppWidgetProvider { | ||
|
||
public static final String QUICK_PLAY = "org.indywidualni.centrumfm.intent.action.QUICK_PLAY"; | ||
|
||
@Override | ||
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { | ||
|
||
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_quick_play); | ||
views.setOnClickPendingIntent(R.id.button, buildButtonPendingIntent(context)); | ||
|
||
pushWidgetUpdate(context, views); | ||
} | ||
|
||
public static PendingIntent buildButtonPendingIntent(Context context) { | ||
Intent intent = new Intent(); | ||
intent.setAction(QUICK_PLAY); | ||
return PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); | ||
} | ||
|
||
public static void pushWidgetUpdate(Context context, RemoteViews remoteViews) { | ||
ComponentName myWidget = new ComponentName(context, WidgetProvider.class); | ||
AppWidgetManager manager = AppWidgetManager.getInstance(context); | ||
manager.updateAppWidget(myWidget, remoteViews); | ||
} | ||
|
||
} |
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,5 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<shape xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:shape="oval"> | ||
<solid android:color="@color/colorAccent" /> | ||
</shape> |
Oops, something went wrong.