diff --git a/examples/tv-app/android/App/app/src/main/java/com/tcl/chip/chiptvserver/MainActivity.java b/examples/tv-app/android/App/app/src/main/java/com/tcl/chip/chiptvserver/MainActivity.java index e71a4663ea412d..08816f922a5746 100644 --- a/examples/tv-app/android/App/app/src/main/java/com/tcl/chip/chiptvserver/MainActivity.java +++ b/examples/tv-app/android/App/app/src/main/java/com/tcl/chip/chiptvserver/MainActivity.java @@ -4,6 +4,7 @@ import android.os.Bundle; import android.view.View; import android.widget.ImageView; +import android.widget.SeekBar; import android.widget.TextView; import androidx.appcompat.app.AppCompatActivity; import chip.setuppayload.DiscoveryCapability; @@ -33,6 +34,29 @@ public void onClick(View view) { MatterServant.get().restart(); } }); + findViewById(R.id.OnOffBtn) + .setOnClickListener( + new View.OnClickListener() { + @Override + public void onClick(View view) { + MatterServant.get().toggleOnOff(); + } + }); + + SeekBar sb = findViewById(R.id.seekBar); + sb.setOnSeekBarChangeListener( + new SeekBar.OnSeekBarChangeListener() { + @Override + public void onProgressChanged(SeekBar seekBar, int i, boolean b) { + MatterServant.get().updateLevel(i); + } + + @Override + public void onStartTrackingTouch(SeekBar seekBar) {} + + @Override + public void onStopTrackingTouch(SeekBar seekBar) {} + }); // TODO: Get these parameters from PreferencesConfigurationManager HashSet discoveryCapabilities = new HashSet<>(); diff --git a/examples/tv-app/android/App/app/src/main/java/com/tcl/chip/chiptvserver/service/MatterServant.java b/examples/tv-app/android/App/app/src/main/java/com/tcl/chip/chiptvserver/service/MatterServant.java index 18842aabde64b9..8e24c3e17967f8 100644 --- a/examples/tv-app/android/App/app/src/main/java/com/tcl/chip/chiptvserver/service/MatterServant.java +++ b/examples/tv-app/android/App/app/src/main/java/com/tcl/chip/chiptvserver/service/MatterServant.java @@ -32,9 +32,11 @@ import com.tcl.chip.tvapp.ContentLaunchManagerStub; import com.tcl.chip.tvapp.DACProviderStub; import com.tcl.chip.tvapp.KeypadInputManagerStub; +import com.tcl.chip.tvapp.LevelManagerStub; import com.tcl.chip.tvapp.LowPowerManagerStub; import com.tcl.chip.tvapp.MediaInputManagerStub; import com.tcl.chip.tvapp.MediaPlaybackManagerStub; +import com.tcl.chip.tvapp.OnOffManagerStub; import com.tcl.chip.tvapp.TvApp; import com.tcl.chip.tvapp.WakeOnLanManagerStub; @@ -44,6 +46,10 @@ public class MatterServant { public int testDiscriminator = 0xF00; private ChipAppServer chipAppServer; + private TvApp mTvApp; + private boolean mIsOn = true; + private int mOnOffEndpoint; + private int mLevelEndpoint; private MatterServant() {} @@ -61,7 +67,7 @@ public void init(@NonNull Context context) { // then chipPlatform to prepare platform // then TvApp.postInit to init app which needs platform // then start ChipAppServer - TvApp tvApp = + mTvApp = new TvApp( (app, clusterId, endpoint) -> { switch (clusterId) { @@ -86,9 +92,17 @@ public void init(@NonNull Context context) { case Clusters.ClusterId_Channel: app.setChannelManager(endpoint, new ChannelManagerStub(endpoint)); break; + case Clusters.ClusterId_OnOff: + mOnOffEndpoint = endpoint; + app.setOnOffManager(endpoint, new OnOffManagerStub(endpoint)); + break; + case Clusters.ClusterId_LevelControl: + mLevelEndpoint = endpoint; + app.setLevelManager(endpoint, new LevelManagerStub(endpoint)); + break; } }); - tvApp.setDACProvider(new DACProviderStub()); + mTvApp.setDACProvider(new DACProviderStub()); Context applicationContext = context.getApplicationContext(); AndroidChipPlatform chipPlatform = @@ -103,7 +117,7 @@ public void init(@NonNull Context context) { chipPlatform.updateCommissionableDataProviderData( null, null, 0, testSetupPasscode, testDiscriminator); - tvApp.postInit(); + mTvApp.postInit(); chipAppServer = new ChipAppServer(); chipAppServer.startApp(); @@ -113,4 +127,13 @@ public void restart() { chipAppServer.stopApp(); chipAppServer.startApp(); } + + public void toggleOnOff() { + mTvApp.setOnOff(mOnOffEndpoint, mIsOn); + mIsOn = !mIsOn; + } + + public void updateLevel(int value) { + mTvApp.setCurrentLevel(mLevelEndpoint, value); + } } diff --git a/examples/tv-app/android/App/app/src/main/res/layout/activity_main.xml b/examples/tv-app/android/App/app/src/main/res/layout/activity_main.xml index f26237c235c4eb..32a1ab4bf46648 100644 --- a/examples/tv-app/android/App/app/src/main/res/layout/activity_main.xml +++ b/examples/tv-app/android/App/app/src/main/res/layout/activity_main.xml @@ -42,4 +42,25 @@ app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" /> +