-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extending Media attribute subscriptions to Android tv-casting-app and…
… lib (#22859)
- Loading branch information
1 parent
3bd7c37
commit 5701b17
Showing
28 changed files
with
2,672 additions
and
72 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
133 changes: 133 additions & 0 deletions
133
...casting-app/android/App/app/src/main/java/com/chip/casting/app/MediaPlaybackFragment.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,133 @@ | ||
package com.chip.casting.app; | ||
|
||
import android.os.Bundle; | ||
import android.util.Log; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.widget.TextView; | ||
import androidx.annotation.Nullable; | ||
import androidx.fragment.app.Fragment; | ||
import com.chip.casting.FailureCallback; | ||
import com.chip.casting.MatterError; | ||
import com.chip.casting.MediaPlaybackTypes; | ||
import com.chip.casting.SubscriptionEstablishedCallback; | ||
import com.chip.casting.SuccessCallback; | ||
import com.chip.casting.TvCastingApp; | ||
|
||
/** A {@link Fragment} for the Media Playback cluster */ | ||
public class MediaPlaybackFragment extends Fragment { | ||
private static final String TAG = MediaPlaybackFragment.class.getSimpleName(); | ||
|
||
private final TvCastingApp tvCastingApp; | ||
|
||
private View.OnClickListener subscribeToCurrentStateButtonClickListener; | ||
|
||
public MediaPlaybackFragment(TvCastingApp tvCastingApp) { | ||
this.tvCastingApp = tvCastingApp; | ||
} | ||
|
||
/** | ||
* Use this factory method to create a new instance of this fragment using the provided | ||
* parameters. | ||
* | ||
* @param tvCastingApp TV Casting App (JNI) | ||
* @return A new instance of fragment MediaPlaybackFragment. | ||
*/ | ||
public static MediaPlaybackFragment newInstance(TvCastingApp tvCastingApp) { | ||
return new MediaPlaybackFragment(tvCastingApp); | ||
} | ||
|
||
@Override | ||
public void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
} | ||
|
||
@Override | ||
public View onCreateView( | ||
LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { | ||
this.subscribeToCurrentStateButtonClickListener = | ||
new View.OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
Log.d(TAG, "SubscribeToCurrentStateButtonClickListener called"); | ||
TextView minInterval = getView().findViewById(R.id.minIntervalEditText); | ||
TextView maxInterval = getView().findViewById(R.id.maxIntervalEditText); | ||
TextView subscriptionStatus = | ||
getView().findViewById(R.id.currentStateSubscriptionEstablishedStatus); | ||
TextView currentStateValue = getView().findViewById(R.id.currentStateValue); | ||
|
||
SuccessCallback<MediaPlaybackTypes.PlaybackStateEnum> successCallback = | ||
playbackStateEnum -> { | ||
Log.d( | ||
TAG, | ||
"handle() called on SuccessCallback<MediaPlaybackResponseTypes.PlaybackStateEnum> with " | ||
+ playbackStateEnum); | ||
getActivity() | ||
.runOnUiThread( | ||
new Runnable() { | ||
@Override | ||
public void run() { | ||
if (playbackStateEnum != null) { | ||
currentStateValue.setText(playbackStateEnum.toString()); | ||
} | ||
} | ||
}); | ||
}; | ||
|
||
FailureCallback failureCallback = | ||
new FailureCallback() { | ||
@Override | ||
public void handle(MatterError matterError) { | ||
Log.d(TAG, "handle() called on FailureCallback with " + matterError); | ||
getActivity() | ||
.runOnUiThread( | ||
new Runnable() { | ||
@Override | ||
public void run() { | ||
currentStateValue.setText("Error!"); | ||
} | ||
}); | ||
} | ||
}; | ||
|
||
SubscriptionEstablishedCallback subscriptionEstablishedCallback = | ||
(SubscriptionEstablishedCallback) | ||
() -> { | ||
Log.d(TAG, "handle() called on SubscriptionEstablishedCallback"); | ||
getActivity() | ||
.runOnUiThread( | ||
new Runnable() { | ||
@Override | ||
public void run() { | ||
subscriptionStatus.setText("Subscription established!"); | ||
} | ||
}); | ||
}; | ||
|
||
boolean retVal = | ||
tvCastingApp.mediaPlayback_subscribeToCurrentState( | ||
successCallback, | ||
failureCallback, | ||
Integer.parseInt(minInterval.getText().toString()), | ||
Integer.parseInt(maxInterval.getText().toString()), | ||
subscriptionEstablishedCallback); | ||
Log.d(TAG, "tvCastingApp.mediaPlayback_subscribeToCurrentState returned " + retVal); | ||
if (retVal == false) { | ||
subscriptionStatus.setText("Subscribe call failed!"); | ||
} | ||
} | ||
}; | ||
|
||
return inflater.inflate(R.layout.fragment_media_playback, container, false); | ||
} | ||
|
||
@Override | ||
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { | ||
super.onViewCreated(view, savedInstanceState); | ||
Log.d(TAG, "MediaPlaybackFragment.onViewCreated called"); | ||
getView() | ||
.findViewById(R.id.subscribeToCurrentStateButton) | ||
.setOnClickListener(subscribeToCurrentStateButtonClickListener); | ||
} | ||
} |
78 changes: 78 additions & 0 deletions
78
...casting-app/android/App/app/src/main/java/com/chip/casting/app/SelectClusterFragment.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,78 @@ | ||
package com.chip.casting.app; | ||
|
||
import android.os.Bundle; | ||
import android.util.Log; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import androidx.annotation.Nullable; | ||
import androidx.fragment.app.Fragment; | ||
|
||
/** An interstitial {@link Fragment} to select one of the supported media actions to perform */ | ||
public class SelectClusterFragment extends Fragment { | ||
private static final String TAG = SelectClusterFragment.class.getSimpleName(); | ||
|
||
private View.OnClickListener selectContentLauncherButtonClickListener; | ||
private View.OnClickListener selectMediaPlaybackButtonClickListener; | ||
|
||
/** | ||
* Use this factory method to create a new instance of this fragment using the provided | ||
* parameters. | ||
* | ||
* @return A new instance of fragment SelectActionFragment. | ||
*/ | ||
public static SelectClusterFragment newInstance() { | ||
return new SelectClusterFragment(); | ||
} | ||
|
||
@Override | ||
public void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
} | ||
|
||
@Override | ||
public View onCreateView( | ||
LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { | ||
SelectClusterFragment.Callback callback = (SelectClusterFragment.Callback) this.getActivity(); | ||
this.selectContentLauncherButtonClickListener = | ||
new View.OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
Log.d(TAG, "handle() called on selectContentLauncherButtonClickListener"); | ||
callback.handleContentLauncherSelected(); | ||
} | ||
}; | ||
|
||
this.selectMediaPlaybackButtonClickListener = | ||
new View.OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
Log.d(TAG, "handle() called on selectMediaPlaybackButtonClickListener"); | ||
callback.handleMediaPlaybackSelected(); | ||
} | ||
}; | ||
|
||
return inflater.inflate(R.layout.fragment_select_cluster, container, false); | ||
} | ||
|
||
@Override | ||
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { | ||
super.onViewCreated(view, savedInstanceState); | ||
Log.d(TAG, "SelectActionFragment.onViewCreated called"); | ||
getView() | ||
.findViewById(R.id.selectContentLauncherButton) | ||
.setOnClickListener(selectContentLauncherButtonClickListener); | ||
getView() | ||
.findViewById(R.id.selectMediaPlaybackButton) | ||
.setOnClickListener(selectMediaPlaybackButtonClickListener); | ||
} | ||
|
||
/** Interface for notifying the host. */ | ||
public interface Callback { | ||
/** Notifies listener to trigger transition on selection of Content Launcher cluster */ | ||
void handleContentLauncherSelected(); | ||
|
||
/** Notifies listener to trigger transition on selection of Media Playback cluster */ | ||
void handleMediaPlaybackSelected(); | ||
} | ||
} |
96 changes: 96 additions & 0 deletions
96
...es/tv-casting-app/android/App/app/src/main/jni/com/chip/casting/ContentLauncherTypes.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,96 @@ | ||
/* | ||
* Copyright (c) 2022 Project CHIP Authors | ||
* 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. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
package com.chip.casting; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Optional; | ||
|
||
public class ContentLauncherTypes { | ||
public static class AdditionalInfo { | ||
public String name; | ||
public String value; | ||
|
||
public AdditionalInfo(String name, String value) { | ||
this.name = name; | ||
this.value = value; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
StringBuilder output = new StringBuilder(); | ||
output.append("AdditionalInfo {\n"); | ||
output.append("\tname: "); | ||
output.append(name); | ||
output.append("\n"); | ||
output.append("\tvalue: "); | ||
output.append(value); | ||
output.append("\n"); | ||
output.append("}\n"); | ||
return output.toString(); | ||
} | ||
} | ||
|
||
public static class Parameter { | ||
public Integer type; | ||
public String value; | ||
public Optional<ArrayList<AdditionalInfo>> externalIDList; | ||
|
||
public Parameter( | ||
Integer type, String value, Optional<ArrayList<AdditionalInfo>> externalIDList) { | ||
this.type = type; | ||
this.value = value; | ||
this.externalIDList = externalIDList; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
StringBuilder output = new StringBuilder(); | ||
output.append("Parameter {\n"); | ||
output.append("\ttype: "); | ||
output.append(type); | ||
output.append("\n"); | ||
output.append("\tvalue: "); | ||
output.append(value); | ||
output.append("\n"); | ||
output.append("\texternalIDList: "); | ||
output.append(externalIDList); | ||
output.append("\n"); | ||
output.append("}\n"); | ||
return output.toString(); | ||
} | ||
} | ||
|
||
public static class ContentSearch { | ||
public ArrayList<Parameter> parameterList; | ||
|
||
public ContentSearch(ArrayList<Parameter> parameterList) { | ||
this.parameterList = parameterList; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
StringBuilder output = new StringBuilder(); | ||
output.append("ContentSearch {\n"); | ||
output.append("\tparameterList: "); | ||
output.append(parameterList); | ||
output.append("\n"); | ||
output.append("}\n"); | ||
return output.toString(); | ||
} | ||
} | ||
} |
Oops, something went wrong.