Skip to content

Commit

Permalink
tv-casting-app: simplified android discovery API
Browse files Browse the repository at this point in the history
  • Loading branch information
pgregorr-amazon committed Dec 19, 2023
1 parent 48891d5 commit 9bd4822
Show file tree
Hide file tree
Showing 33 changed files with 1,197 additions and 21 deletions.
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"
package="com.chip.casting.app">
package="com">

<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
Expand All @@ -19,9 +19,9 @@
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:name=".ChipTvCastingApplication"
android:name=".chip.casting.app.ChipTvCastingApplication"
android:theme="@style/Theme.CHIPTVCastingApp">
<activity android:name=".MainActivity"
<activity android:name=".chip.casting.app.MainActivity"
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.content.Context;
import android.widget.LinearLayout;
import androidx.fragment.app.FragmentActivity;
import com.R;

public class CastingContext {
private FragmentActivity fragmentActivity;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import android.widget.ListView;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import com.R;
import com.chip.casting.ContentApp;
import com.chip.casting.ContentLauncherTypes;
import com.chip.casting.FailureCallback;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import android.widget.Toast;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import com.R;
import com.chip.casting.DiscoveredNodeData;
import com.chip.casting.FailureCallback;
import com.chip.casting.MatterError;
Expand Down Expand Up @@ -67,6 +68,7 @@ public View onCreateView(

@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
Log.d(TAG, "onViewCreated() called");
super.onViewCreated(view, savedInstanceState);

Button manualCommissioningButton = getView().findViewById(R.id.manualCommissioningButton);
Expand Down Expand Up @@ -103,7 +105,10 @@ public void onClick(View v) {
new SuccessCallback<DiscoveredNodeData>() {
@Override
public void handle(DiscoveredNodeData discoveredNodeData) {
Log.d(TAG, "Discovered a Video Player Commissioner: " + discoveredNodeData);
Log.d(
TAG,
"SuccessCallback handle() Discovered a Video Player Commissioner: "
+ discoveredNodeData);
new Handler(Looper.getMainLooper())
.post(
() -> {
Expand All @@ -129,7 +134,10 @@ public void handle(DiscoveredNodeData discoveredNodeData) {
new FailureCallback() {
@Override
public void handle(MatterError matterError) {
Log.e(TAG, "Error occurred during video player commissioner discovery: " + matterError);
Log.e(
TAG,
"FailureCallback handle() Error occurred during video player commissioner discovery: "
+ matterError);
if (MatterError.DISCOVERY_SERVICE_LOST == matterError) {
Log.d(TAG, "Attempting to restart service");
tvCastingApp.discoverVideoPlayerCommissioners(successCallback, this);
Expand All @@ -148,7 +156,7 @@ public void handle(MatterError matterError) {
@Override
public void onResume() {
super.onResume();
Log.d(TAG, "Auto discovering");
Log.d(TAG, "onResume() called. Auto discovering");

poller =
executor.scheduleAtFixedRate(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import android.widget.TextView;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import com.R;
import com.chip.casting.CommissioningCallbacks;
import com.chip.casting.ContentApp;
import com.chip.casting.DiscoveredNodeData;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import android.widget.TextView;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import com.R;
import com.chip.casting.ContentApp;
import com.chip.casting.MatterCallbackHandler;
import com.chip.casting.MatterError;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,22 @@
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentTransaction;
import com.R;
import com.chip.casting.AppParameters;
import com.chip.casting.DiscoveredNodeData;
import com.chip.casting.TvCastingApp;
import com.chip.casting.util.GlobalCastingConstants;
import com.chip.casting.util.PreferencesConfigurationManager;
import com.matter.casting.DiscoveryExampleFragment;
import com.matter.casting.InitializationExample;
import com.matter.casting.core.CastingPlayer;
import java.util.Random;

public class MainActivity extends AppCompatActivity
implements CommissionerDiscoveryFragment.Callback,
ConnectionFragment.Callback,
SelectClusterFragment.Callback {
SelectClusterFragment.Callback,
DiscoveryExampleFragment.Callback {

private static final String TAG = MainActivity.class.getSimpleName();

Expand All @@ -36,7 +40,12 @@ protected void onCreate(Bundle savedInstanceState) {
return;
}

Fragment fragment = CommissionerDiscoveryFragment.newInstance(tvCastingApp);
Fragment fragment = null;
if (GlobalCastingConstants.ChipCastingSimplified) {
fragment = DiscoveryExampleFragment.newInstance();
} else {
fragment = CommissionerDiscoveryFragment.newInstance(tvCastingApp);
}
getSupportFragmentManager()
.beginTransaction()
.add(R.id.main_fragment_container, fragment, fragment.getClass().getSimpleName())
Expand All @@ -48,6 +57,13 @@ public void handleCommissioningButtonClicked(DiscoveredNodeData commissioner) {
showFragment(ConnectionFragment.newInstance(tvCastingApp, commissioner));
}

@Override
public void handleConnectionButtonClicked(CastingPlayer player) {
Log.i(TAG, "MainActivity.handleConnectionButtonClicked() called");
// TODO: In future PR, show fragment that connects to the player.
// showFragment(ConnectionFragment.newInstance(CastingPlayer player));
}

@Override
public void handleCommissioningComplete() {
showFragment(SelectClusterFragment.newInstance(tvCastingApp));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import com.R;
import com.chip.casting.ContentApp;
import com.chip.casting.FailureCallback;
import com.chip.casting.MatterError;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import android.view.ViewGroup;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import com.R;
import com.chip.casting.TvCastingApp;

/** An interstitial {@link Fragment} to select one of the supported media actions to perform */
Expand Down
Loading

0 comments on commit 9bd4822

Please sign in to comment.