Skip to content

Commit

Permalink
Android Sender Kotlin app alongside Java app
Browse files Browse the repository at this point in the history
Change-Id: Idc1aaa9ee2011fd83daa17522fdf2ecaf0579423
  • Loading branch information
kaniu Ndungu committed Sep 8, 2022
1 parent 95e9fa8 commit 8bb8ce2
Show file tree
Hide file tree
Showing 604 changed files with 3,382 additions and 93 deletions.
53 changes: 53 additions & 0 deletions app-java/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 32

defaultConfig {
minSdkVersion 18
targetSdkVersion 32
versionCode 20
versionName "3.0"
applicationId="com.google.sample.cast.refplayer"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}

lintOptions.abortOnError false

sourceSets {
main {
res.srcDirs = [projectDir.path+'/../resources']
}
androidTest {
java.srcDirs = ['androidTest']
}
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

namespace 'com.google.sample.cast.refplayer'
}

dependencies {
implementation 'androidx.appcompat:appcompat:1.5.0'
implementation 'androidx.mediarouter:mediarouter:1.3.1'
implementation 'androidx.recyclerview:recyclerview:1.2.1'
implementation 'com.google.android.gms:play-services-cast-framework:21.1.0'
implementation 'com.android.volley:volley:1.2.1'

androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
androidTestImplementation 'androidx.test.espresso:espresso-contrib:3.4.0'
androidTestImplementation 'androidx.test:runner:1.4.0'
androidTestImplementation 'androidx.test:rules:1.4.0'
androidTestImplementation 'androidx.test.uiautomator:uiautomator:2.2.0'
testImplementation 'junit:junit:4.12'
}
5 changes: 2 additions & 3 deletions AndroidManifest.xml → app-java/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright 2019 Google LLC. All rights reserved.
Copyright 2022 Google LLC. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -14,8 +14,7 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.google.sample.cast.refplayer">
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019 Google LLC. All Rights Reserved.
* Copyright 2022 Google LLC. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019 Google LLC. All Rights Reserved.
* Copyright 2022 Google LLC. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -39,6 +39,9 @@
import android.view.Menu;
import android.view.MenuItem;

import java.util.concurrent.Executor;
import java.util.concurrent.Executors;

/**
* The main activity that displays the list of videos.
*/
Expand All @@ -54,6 +57,7 @@ public class VideoBrowserActivity extends AppCompatActivity {
private Toolbar mToolbar;
private IntroductoryOverlay mIntroductoryOverlay;
private CastStateListener mCastStateListener;
private Executor localExecutor = Executors.newSingleThreadExecutor();

private class MySessionManagerListener implements SessionManagerListener<CastSession> {

Expand Down Expand Up @@ -121,7 +125,7 @@ public void onCastStateChanged(int newState) {
}
}
};
mCastContext = CastContext.getSharedInstance(this);
mCastContext = CastContext.getSharedInstance(this,localExecutor).getResult();
}

private void setupActionBar() {
Expand Down Expand Up @@ -184,7 +188,9 @@ protected void onResume() {
mSessionManagerListener, CastSession.class);
intentToJoin();
if (mCastSession == null) {
mCastSession = CastContext.getSharedInstance(this).getSessionManager()
mCastSession = CastContext.getSharedInstance(this,localExecutor)
.getResult()
.getSessionManager()
.getCurrentCastSession();
}
if (mQueueMenuItem != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019 Google LLC. All Rights Reserved.
* Copyright 2022 Google LLC. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -41,6 +41,8 @@
import android.widget.ImageButton;

import java.util.List;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;

/**
* A fragment to host a list view of the video catalog.
Expand All @@ -57,7 +59,8 @@ public class VideoBrowserFragment extends Fragment implements VideoListAdapter.I
private View mLoadingView;
private final SessionManagerListener<CastSession> mSessionManagerListener =
new MySessionManagerListener();

private Executor localExecutor = Executors.newSingleThreadExecutor();

public VideoBrowserFragment() {
}

Expand All @@ -78,7 +81,7 @@ public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
mRecyclerView.setLayoutManager(layoutManager);
mAdapter = new VideoListAdapter(this, getContext());
mRecyclerView.setAdapter(mAdapter);
getLoaderManager().initLoader(0, null, this);
LoaderManager.getInstance(this).initLoader(0, null, this);
}

@Override
Expand All @@ -88,7 +91,7 @@ public void itemClicked(View view, MediaInfo item, int position) {
} else {
String transitionName = getString(R.string.transition_image);
VideoListAdapter.ViewHolder viewHolder =
(VideoListAdapter.ViewHolder) mRecyclerView.findViewHolderForPosition(position);
(VideoListAdapter.ViewHolder) mRecyclerView.findViewHolderForLayoutPosition(position);
Pair<View, String> imagePair = Pair
.create((View) viewHolder.getImageView(), transitionName);
ActivityOptionsCompat options = ActivityOptionsCompat
Expand Down Expand Up @@ -120,14 +123,18 @@ public void onLoaderReset(Loader<List<MediaInfo>> loader) {

@Override
public void onStart() {
CastContext.getSharedInstance(getContext()).getSessionManager()
CastContext.getSharedInstance(getContext(),localExecutor)
.getResult()
.getSessionManager()
.addSessionManagerListener(mSessionManagerListener, CastSession.class);
super.onStart();
}

@Override
public void onStop() {
CastContext.getSharedInstance(getContext()).getSessionManager()
CastContext.getSharedInstance(getContext(),localExecutor)
.getResult()
.getSessionManager()
.removeSessionManagerListener(mSessionManagerListener, CastSession.class);
super.onStop();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019 Google LLC. All Rights Reserved.
* Copyright 2022 Google LLC. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019 Google LLC. All Rights Reserved.
* Copyright 2022 Google LLC. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -35,6 +35,8 @@
import com.google.sample.cast.refplayer.R;

import java.util.List;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;

/**
* An {@link ArrayAdapter} to populate the list of videos.
Expand All @@ -45,6 +47,7 @@ public class VideoListAdapter extends RecyclerView.Adapter<VideoListAdapter.View
private final ItemClickListener mClickListener;
private final Context mAppContext;
private List<MediaInfo> videos;
private Executor localExecutor = Executors.newSingleThreadExecutor();

public VideoListAdapter(ItemClickListener clickListener, Context context) {
mClickListener = clickListener;
Expand Down Expand Up @@ -85,7 +88,9 @@ public void onClick(View view) {
mClickListener.itemClicked(view, item, position);
}
});
CastSession castSession = CastContext.getSharedInstance(mAppContext).getSessionManager()
CastSession castSession = CastContext.getSharedInstance(mAppContext,localExecutor)
.getResult()
.getSessionManager()
.getCurrentCastSession();
viewHolder.mMenu.setVisibility(
(castSession != null && castSession.isConnected()) ? View.VISIBLE : View.GONE);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019 Google LLC. All Rights Reserved.
* Copyright 2022 Google LLC. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -99,6 +99,7 @@ protected JSONObject parseUrl(String urlString) {
is.close();
} catch (IOException e) {
// ignore
Log.w(TAG,"Ignore",e);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019 Google LLC. All Rights Reserved.
* Copyright 2022 Google LLC. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019 Google LLC. All Rights Reserved.
* Copyright 2022 Google LLC. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -73,6 +73,8 @@

import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;

/**
* Activity for the local media player.
Expand Down Expand Up @@ -107,6 +109,7 @@ public class LocalPlayerActivity extends AppCompatActivity {
private SessionManagerListener<CastSession> mSessionManagerListener;
private MenuItem mQueueMenuItem;
private ImageLoader mImageLoader;
private Executor localExecutor = Executors.newSingleThreadExecutor();

/**
* indicates whether we are doing a local or a remote playback
Expand All @@ -130,7 +133,8 @@ protected void onCreate(Bundle savedInstanceState) {
loadViews();
setupControlsCallbacks();
setupCastListener();
mCastContext = CastContext.getSharedInstance(this);
mCastContext = CastContext.getSharedInstance(this,localExecutor)
.getResult();
mCastSession = mCastContext.getSessionManager().getCurrentCastSession();
// see what we need to play and where
Bundle bundle = getIntent().getExtras();
Expand Down Expand Up @@ -586,7 +590,7 @@ public void onStartTrackingTouch(SeekBar seekBar) {

@Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
boolean fromUser) {
mStartText.setText(Utils.formatMillis(progress));
}
});
Expand Down Expand Up @@ -674,12 +678,11 @@ public void onConfigurationChanged(Configuration newConfig) {
}

private void updateMetadata(boolean visible) {
Point displaySize;
Point displaySize = Utils.getDisplaySize(this);
if (!visible) {
mDescriptionView.setVisibility(View.GONE);
mTitleView.setVisibility(View.GONE);
mAuthorView.setVisibility(View.GONE);
displaySize = Utils.getDisplaySize(this);
RelativeLayout.LayoutParams lp = new
RelativeLayout.LayoutParams(displaySize.x,
displaySize.y + getSupportActionBar().getHeight());
Expand All @@ -695,7 +698,6 @@ private void updateMetadata(boolean visible) {
mDescriptionView.setVisibility(View.VISIBLE);
mTitleView.setVisibility(View.VISIBLE);
mAuthorView.setVisibility(View.VISIBLE);
displaySize = Utils.getDisplaySize(this);
RelativeLayout.LayoutParams lp = new
RelativeLayout.LayoutParams(displaySize.x,
(int) (displaySize.x * mAspectRatio));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019 Google LLC. All Rights Reserved.
* Copyright 2022 Google LLC. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -27,6 +27,9 @@
import com.google.android.gms.cast.framework.media.MediaQueue;
import com.google.android.gms.cast.framework.media.RemoteMediaClient;

import java.util.concurrent.Executor;
import java.util.concurrent.Executors;

/**
* A singleton to manage the queue. Upon instantiation, it syncs up its own copy of the queue with
* the one that the VideoCastManager holds. After that point, it maintains an up-to-date version of
Expand All @@ -52,12 +55,15 @@ public class QueueDataProvider {
private MediaQueueItem mUpcomingItem;
private OnQueueDataChangedListener mListener;
private boolean mDetachedQueue = true;
private Executor localExecutor = Executors.newSingleThreadExecutor();

private QueueDataProvider(Context context) {
mAppContext = context.getApplicationContext();
mCurrentItem = null;
CastContext.getSharedInstance(mAppContext).getSessionManager().addSessionManagerListener(
mSessionManagerListener, CastSession.class);
CastContext.getSharedInstance(mAppContext,localExecutor)
.getResult()
.getSessionManager()
.addSessionManagerListener(mSessionManagerListener, CastSession.class);
MediaQueue queue = getMediaQueue();
if (queue != null) {
queue.setCacheCapacity(30);
Expand Down Expand Up @@ -254,7 +260,9 @@ private void updateMediaQueue() {
}

private RemoteMediaClient getRemoteMediaClient() {
CastSession castSession = CastContext.getSharedInstance(mAppContext).getSessionManager()
CastSession castSession = CastContext.getSharedInstance(mAppContext,localExecutor)
.getResult()
.getSessionManager()
.getCurrentCastSession();
if (castSession == null || !castSession.isConnected()) {
Log.w(TAG, "Trying to get a RemoteMediaClient when no CastSession is started.");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019 Google LLC. All Rights Reserved.
* Copyright 2022 Google LLC. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -71,7 +71,7 @@ public void onChildDraw(Canvas c, RecyclerView recyclerView, RecyclerView.ViewHo
if (viewHolder instanceof QueueListAdapter.QueueItemViewHolder) {
QueueListAdapter.QueueItemViewHolder queueHolder
= (QueueListAdapter.QueueItemViewHolder) viewHolder;
ViewCompat.setTranslationX(queueHolder.mContainer, dX);
queueHolder.mContainer.setTranslationX(dX);
}
} else {
super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);
Expand Down
Loading

0 comments on commit 8bb8ce2

Please sign in to comment.