Skip to content

Commit

Permalink
Merge branch 'cast'
Browse files Browse the repository at this point in the history
  • Loading branch information
unknown committed Jul 4, 2017
2 parents 5ea0163 + 639e27d commit 9549a24
Show file tree
Hide file tree
Showing 15 changed files with 571 additions and 121 deletions.
17 changes: 10 additions & 7 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ android {
}
defaultConfig {
applicationId "net.programmierecke.radiodroid2"
minSdkVersion 9
minSdkVersion 14
targetSdkVersion 23

versionCode 42
versionName "0.32"
versionCode 46
versionName "0.36"
}
buildTypes {
release {
Expand All @@ -27,10 +27,13 @@ android {
}

dependencies {
compile 'com.android.support:support-v4:25.3.1'
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:design:25.3.1'
compile 'com.android.support:preference-v7:25.3.1'
compile 'com.android.support:support-v4:25.2.0'
compile 'com.android.support:appcompat-v7:25.2.0'
compile 'com.android.support:design:25.2.0'
compile 'com.android.support:preference-v7:25.2.0'
compile 'com.android.support:mediarouter-v7:25.2.0'
compile 'com.google.code.gson:gson:2.7'
compile 'com.google.android.exoplayer:exoplayer:r2.3.1'
compile 'com.google.android.gms:play-services-cast:11.0.1'
compile 'com.google.android.gms:play-services-cast-framework:11.0.1'
}
6 changes: 6 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,11 @@
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>

<meta-data
android:name=
"com.google.android.gms.cast.framework.OPTIONS_PROVIDER_CLASS_NAME"
android:value="net.programmierecke.radiodroid2.CastOptionsProvider" />

</application>
</manifest>
124 changes: 116 additions & 8 deletions app/src/main/java/net/programmierecke/radiodroid2/ActivityMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.os.Handler;
import android.support.design.widget.NavigationView;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
Expand All @@ -21,14 +22,20 @@
import android.view.MenuItem;
import android.widget.Toast;

import com.google.android.gms.cast.framework.CastButtonFactory;
import com.google.android.gms.cast.framework.CastContext;
import com.google.android.gms.cast.framework.Session;
import com.google.android.gms.cast.framework.SessionManager;
import com.google.android.gms.cast.framework.SessionManagerListener;

import net.programmierecke.radiodroid2.interfaces.IFragmentRefreshable;
import net.programmierecke.radiodroid2.interfaces.IFragmentSearchable;

import java.io.File;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

public class ActivityMain extends AppCompatActivity implements SearchView.OnQueryTextListener {
public class ActivityMain extends AppCompatActivity implements SearchView.OnQueryTextListener, IMPDClientStatusChange {
private SearchView mSearchView;

private static final String TAG = "RadioDroid";
Expand All @@ -45,13 +52,82 @@ public class ActivityMain extends AppCompatActivity implements SearchView.OnQuer
MenuItem menuItemRefresh;

private SharedPreferences sharedPref;

@Override
private CastContext mCastContext;
private MenuItem mediaRouteMenuItem;
private SessionManager mSessionManager;

private final SessionManagerListener mSessionManagerListener =
new SessionManagerListenerImpl();
private MenuItem menuItemMPDOK;
private MenuItem menuItemMPDNok;

@Override
public void changed() {
Handler mainHandler = new Handler(getMainLooper());
Runnable myRunnable = new Runnable() {
@Override
public void run() {
invalidateOptionsMenu();
}
};
mainHandler.post(myRunnable);
}

private class SessionManagerListenerImpl implements SessionManagerListener {
@Override
public void onSessionStarting(Session session) {

}

@Override
public void onSessionStarted(Session session, String sessionId) {
invalidateOptionsMenu();
Utils.mCastSession = mSessionManager.getCurrentCastSession();
}

@Override
public void onSessionStartFailed(Session session, int i) {

}

@Override
public void onSessionEnding(Session session) {
}

@Override
public void onSessionResumed(Session session, boolean wasSuspended) {
invalidateOptionsMenu();
Utils.mCastSession = mSessionManager.getCurrentCastSession();
}

@Override
public void onSessionResumeFailed(Session session, int i) {
Utils.mCastSession = null;
}

@Override
public void onSessionSuspended(Session session, int i) {
Utils.mCastSession = null;
}

@Override
public void onSessionEnded(Session session, int error) {
Utils.mCastSession = null;
}

@Override
public void onSessionResuming(Session session, String s) {

}
}


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_main);

try {
try {
File dir = new File(getFilesDir().getAbsolutePath());
if (dir.isDirectory()) {
String[] children = dir.list();
Expand Down Expand Up @@ -159,7 +235,12 @@ public boolean onNavigationItemSelected(MenuItem menuItem) {
ActionBarDrawerToggle mDrawerToggle = new ActionBarDrawerToggle(this,mDrawerLayout, R.string.app_name,R.string.app_name);
mDrawerLayout.addDrawerListener(mDrawerToggle);
mDrawerToggle.syncState();
}

mCastContext = CastContext.getSharedInstance(this);
mSessionManager = mCastContext.getSessionManager();

MPDClient.StartDiscovery(this, this);
}

@Override
public void onRequestPermissionsResult(int requestCode,
Expand All @@ -186,15 +267,21 @@ public void onRequestPermissionsResult(int requestCode,
public void onDestroy() {
super.onDestroy();
PlayerServiceUtil.unBind(this);
MPDClient.StopDiscovery();
}

@Override
protected void onPause() {
Log.i(TAG,"PAUSED");
super.onPause();
}
mSessionManager.removeSessionManagerListener(mSessionManagerListener);
Utils.mCastSession = null;
MPDClient.StopDiscovery();
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);

Expand All @@ -203,6 +290,8 @@ public boolean onCreateOptionsMenu(Menu menu) {
mSearchView.setOnQueryTextListener(this);

menuItemRefresh = menu.findItem(R.id.action_refresh);
menuItemMPDNok = menu.findItem(R.id.action_mpd_nok);
menuItemMPDOK = menu.findItem(R.id.action_mpd_ok);

if (fragSearchable == null) {
menuItemSearch.setVisible(false);
Expand All @@ -212,7 +301,14 @@ public boolean onCreateOptionsMenu(Menu menu) {
menuItemRefresh.setVisible(false);
}

return true;
menuItemMPDOK.setVisible(MPDClient.Discovered() && MPDClient.Connected());
menuItemMPDNok.setVisible(MPDClient.Discovered() && !MPDClient.Connected());

mediaRouteMenuItem = CastButtonFactory.setUpMediaRouteButton(getApplicationContext(),
menu,
R.id.media_route_menu_item);

return true;
}

@Override
Expand All @@ -226,6 +322,12 @@ public boolean onOptionsItemSelected(MenuItem item) {
fragRefreshable.Refresh();
}
return true;
case R.id.action_mpd_nok:
MPDClient.Connect(this);
return true;
case R.id.action_mpd_ok:
MPDClient.Disconnect(this, this);
return true;
}
return super.onOptionsItemSelected(item);
}
Expand Down Expand Up @@ -255,7 +357,13 @@ protected void onResume() {

mFragmentTransaction = mFragmentManager.beginTransaction();
mFragmentTransaction.replace(R.id.containerView,first).commit();
}

Utils.mCastSession = mSessionManager.getCurrentCastSession();
mSessionManager.addSessionManagerListener(mSessionManagerListener);

Log.i(TAG,"RESUMED");
MPDClient.StartDiscovery(this, this);
}

public void Search(String query){
if (fragSearchable != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package net.programmierecke.radiodroid2;

import android.content.Context;

import com.google.android.gms.cast.framework.CastOptions;
import com.google.android.gms.cast.framework.OptionsProvider;
import com.google.android.gms.cast.framework.SessionProvider;

import java.util.List;

public class CastOptionsProvider implements OptionsProvider {

@Override
public CastOptions getCastOptions(Context context) {
return new CastOptions.Builder()
.setReceiverApplicationId(context.getString(R.string.app_id))
.build();
}

@Override
public List<SessionProvider> getAdditionalSessionProviders(Context context) {
return null;
}
}
Loading

0 comments on commit 9549a24

Please sign in to comment.