-
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.
Added Content Launcher to android tv-casting-app (#18356)
- Loading branch information
1 parent
cd440e5
commit 1484668
Showing
18 changed files
with
395 additions
and
42 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
65 changes: 65 additions & 0 deletions
65
...sting-app/android/App/app/src/main/java/com/chip/casting/app/ContentLauncherFragment.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,65 @@ | ||
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.EditText; | ||
import androidx.annotation.Nullable; | ||
import androidx.fragment.app.Fragment; | ||
import com.chip.casting.TvCastingApp; | ||
|
||
/** A {@link Fragment} to send Content Launcher commands from the TV Casting App. */ | ||
public class ContentLauncherFragment extends Fragment { | ||
private static final String TAG = ContentLauncherFragment.class.getSimpleName(); | ||
|
||
private final TvCastingApp tvCastingApp; | ||
|
||
private View.OnClickListener launchUrlButtonClickListener; | ||
|
||
public ContentLauncherFragment(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 ContentLauncherFragment. | ||
*/ | ||
public static ContentLauncherFragment newInstance(TvCastingApp tvCastingApp) { | ||
return new ContentLauncherFragment(tvCastingApp); | ||
} | ||
|
||
@Override | ||
public void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
} | ||
|
||
@Override | ||
public View onCreateView( | ||
LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { | ||
this.launchUrlButtonClickListener = | ||
new View.OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
EditText contentUrl = getView().findViewById(R.id.contentUrlEditText); | ||
EditText contentDisplayString = | ||
getView().findViewById(R.id.contentDisplayStringEditText); | ||
tvCastingApp.contentLauncherLaunchURL( | ||
contentUrl.getText().toString(), contentDisplayString.getText().toString()); | ||
} | ||
}; | ||
|
||
return inflater.inflate(R.layout.fragment_content_launcher, container, false); | ||
} | ||
|
||
@Override | ||
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { | ||
super.onViewCreated(view, savedInstanceState); | ||
Log.d(TAG, "ContentLauncherFragment.onViewCreated called"); | ||
getView().findViewById(R.id.launchUrlButton).setOnClickListener(launchUrlButtonClickListener); | ||
} | ||
} |
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
5 changes: 5 additions & 0 deletions
5
...ng-app/android/App/app/src/main/java/com/chip/casting/platform/MatterCallbackHandler.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,5 @@ | ||
package com.chip.casting.platform; | ||
|
||
public interface MatterCallbackHandler { | ||
boolean handle(boolean success); | ||
} |
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
73 changes: 73 additions & 0 deletions
73
examples/tv-casting-app/android/App/app/src/main/jni/cpp/CallbackHelper.cpp
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,73 @@ | ||
/* | ||
* | ||
* 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. | ||
*/ | ||
|
||
#include "CallbackHelper.h" | ||
|
||
#include <lib/support/JniReferences.h> | ||
|
||
using namespace chip; | ||
|
||
struct MatterCallbackHandler gCommissioningCompleteHandler; | ||
|
||
CHIP_ERROR SetUpMatterCallbackHandler(JNIEnv * env, jobject inHandler, MatterCallbackHandler & callback) | ||
{ | ||
ChipLogProgress(AppServer, "SetUpMatterCallbackHandler called"); | ||
CHIP_ERROR err = CHIP_NO_ERROR; | ||
|
||
callback.object = env->NewGlobalRef(inHandler); | ||
VerifyOrExit(callback.object != nullptr, ChipLogError(AppServer, "Failed to NewGlobalRef for handler object")); | ||
|
||
callback.clazz = env->GetObjectClass(callback.object); | ||
VerifyOrExit(callback.clazz != nullptr, ChipLogError(AppServer, "Failed to get handler Java class")); | ||
|
||
callback.method = env->GetMethodID(callback.clazz, "handle", "(Z)Z"); | ||
if (callback.method == nullptr) | ||
{ | ||
ChipLogError(AppServer, "Failed to access 'handle' method"); | ||
env->ExceptionClear(); | ||
} | ||
|
||
exit: | ||
if (err != CHIP_NO_ERROR) | ||
{ | ||
ChipLogError(AppServer, "SetUpMatterCallbackHandler error: %s", err.AsString()); | ||
return err; | ||
} | ||
|
||
return err; | ||
} | ||
|
||
CHIP_ERROR CommissioningCompleteHandler() | ||
{ | ||
ChipLogProgress(AppServer, "CommissioningCompleteHandler called"); | ||
|
||
JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); | ||
CHIP_ERROR err = CHIP_NO_ERROR; | ||
VerifyOrExit(gCommissioningCompleteHandler.object != nullptr, err = CHIP_ERROR_INCORRECT_STATE); | ||
VerifyOrExit(gCommissioningCompleteHandler.method != nullptr, err = CHIP_ERROR_INCORRECT_STATE); | ||
VerifyOrExit(env->CallBooleanMethod(gCommissioningCompleteHandler.object, gCommissioningCompleteHandler.method, | ||
static_cast<jboolean>(true)) != JNI_FALSE, | ||
err = CHIP_ERROR_INCORRECT_STATE); | ||
exit: | ||
if (err != CHIP_NO_ERROR) | ||
{ | ||
ChipLogError(AppServer, "CommissioningCompleteHandler status error: %s", err.AsString()); | ||
} | ||
|
||
return err; | ||
} |
35 changes: 35 additions & 0 deletions
35
examples/tv-casting-app/android/App/app/src/main/jni/cpp/CallbackHelper.h
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,35 @@ | ||
/* | ||
* | ||
* 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. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <jni.h> | ||
#include <lib/core/CHIPError.h> | ||
|
||
struct MatterCallbackHandler | ||
{ | ||
jobject object = nullptr; | ||
jclass clazz = nullptr; | ||
jmethodID method = nullptr; | ||
}; | ||
|
||
extern struct MatterCallbackHandler gCommissioningCompleteHandler; | ||
|
||
CHIP_ERROR SetUpMatterCallbackHandler(JNIEnv * env, jobject inHandler, MatterCallbackHandler & callback); | ||
|
||
CHIP_ERROR CommissioningCompleteHandler(); |
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
Oops, something went wrong.