├── gradle.properties
├── .DS_Store
├── ic_launcher-web.png
├── res
├── drawable-hdpi
│ ├── ic_drawer.png
│ ├── ic_launcher.png
│ └── drawer_shadow.9.png
├── drawable-mdpi
│ ├── ic_drawer.png
│ ├── icon_12676.png
│ ├── icon_15111.png
│ ├── icon_15307.png
│ ├── icon_17114.png
│ ├── icon_17183.png
│ ├── icon_3330.png
│ ├── ic_launcher.png
│ └── drawer_shadow.9.png
├── drawable-xhdpi
│ ├── ic_drawer.png
│ ├── icon_3330.png
│ ├── ic_launcher.png
│ ├── icon_12676.png
│ ├── icon_15111.png
│ ├── icon_15307.png
│ ├── icon_17114.png
│ ├── icon_17183.png
│ └── drawer_shadow.9.png
├── drawable-xxhdpi
│ ├── ic_drawer.png
│ ├── ic_launcher.png
│ └── drawer_shadow.9.png
├── values
│ ├── styles.xml
│ └── dimens.xml
├── layout
│ ├── activity_main.xml
│ ├── fragment_navigation_drawer.xml
│ ├── app_item.xml
│ ├── channel_item.xml
│ ├── fragment_apps.xml
│ ├── fragment_webapp.xml
│ ├── fragment_fiveway.xml
│ ├── fragment_system.xml
│ ├── fragment_tv.xml
│ └── fragment_media_player.xml
├── menu
│ └── main.xml
└── values-w820dp
│ └── dimens.xml
├── lint.xml
├── project.properties
├── .gitignore
├── proguard-project.txt
├── src
└── com
│ └── connectsdk
│ └── sampler
│ ├── MainApplication.java
│ ├── widget
│ ├── AppAdapter.java
│ └── ChannelAdapter.java
│ ├── SectionsPagerAdapter.java
│ ├── util
│ └── TestResponseObject.java
│ ├── fragments
│ ├── BaseFragment.java
│ ├── TVFragment.java
│ ├── SystemFragment.java
│ ├── AppsFragment.java
│ ├── WebAppFragment.java
│ ├── KeyControlFragment.java
│ └── MediaPlayerFragment.java
│ └── MainActivity.java
├── AndroidManifest.xml
├── README.md
└── LICENSE
/gradle.properties:
--------------------------------------------------------------------------------
1 | android.enableJetifier=true
2 | android.useAndroidX=true
--------------------------------------------------------------------------------
/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ConnectSDK/Connect-SDK-Android-API-Sampler/HEAD/.DS_Store
--------------------------------------------------------------------------------
/ic_launcher-web.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ConnectSDK/Connect-SDK-Android-API-Sampler/HEAD/ic_launcher-web.png
--------------------------------------------------------------------------------
/res/drawable-hdpi/ic_drawer.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ConnectSDK/Connect-SDK-Android-API-Sampler/HEAD/res/drawable-hdpi/ic_drawer.png
--------------------------------------------------------------------------------
/res/drawable-mdpi/ic_drawer.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ConnectSDK/Connect-SDK-Android-API-Sampler/HEAD/res/drawable-mdpi/ic_drawer.png
--------------------------------------------------------------------------------
/res/drawable-mdpi/icon_12676.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ConnectSDK/Connect-SDK-Android-API-Sampler/HEAD/res/drawable-mdpi/icon_12676.png
--------------------------------------------------------------------------------
/res/drawable-mdpi/icon_15111.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ConnectSDK/Connect-SDK-Android-API-Sampler/HEAD/res/drawable-mdpi/icon_15111.png
--------------------------------------------------------------------------------
/res/drawable-mdpi/icon_15307.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ConnectSDK/Connect-SDK-Android-API-Sampler/HEAD/res/drawable-mdpi/icon_15307.png
--------------------------------------------------------------------------------
/res/drawable-mdpi/icon_17114.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ConnectSDK/Connect-SDK-Android-API-Sampler/HEAD/res/drawable-mdpi/icon_17114.png
--------------------------------------------------------------------------------
/res/drawable-mdpi/icon_17183.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ConnectSDK/Connect-SDK-Android-API-Sampler/HEAD/res/drawable-mdpi/icon_17183.png
--------------------------------------------------------------------------------
/res/drawable-mdpi/icon_3330.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ConnectSDK/Connect-SDK-Android-API-Sampler/HEAD/res/drawable-mdpi/icon_3330.png
--------------------------------------------------------------------------------
/res/drawable-xhdpi/ic_drawer.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ConnectSDK/Connect-SDK-Android-API-Sampler/HEAD/res/drawable-xhdpi/ic_drawer.png
--------------------------------------------------------------------------------
/res/drawable-xhdpi/icon_3330.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ConnectSDK/Connect-SDK-Android-API-Sampler/HEAD/res/drawable-xhdpi/icon_3330.png
--------------------------------------------------------------------------------
/res/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ConnectSDK/Connect-SDK-Android-API-Sampler/HEAD/res/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/res/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ConnectSDK/Connect-SDK-Android-API-Sampler/HEAD/res/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/res/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ConnectSDK/Connect-SDK-Android-API-Sampler/HEAD/res/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/res/drawable-xhdpi/icon_12676.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ConnectSDK/Connect-SDK-Android-API-Sampler/HEAD/res/drawable-xhdpi/icon_12676.png
--------------------------------------------------------------------------------
/res/drawable-xhdpi/icon_15111.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ConnectSDK/Connect-SDK-Android-API-Sampler/HEAD/res/drawable-xhdpi/icon_15111.png
--------------------------------------------------------------------------------
/res/drawable-xhdpi/icon_15307.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ConnectSDK/Connect-SDK-Android-API-Sampler/HEAD/res/drawable-xhdpi/icon_15307.png
--------------------------------------------------------------------------------
/res/drawable-xhdpi/icon_17114.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ConnectSDK/Connect-SDK-Android-API-Sampler/HEAD/res/drawable-xhdpi/icon_17114.png
--------------------------------------------------------------------------------
/res/drawable-xhdpi/icon_17183.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ConnectSDK/Connect-SDK-Android-API-Sampler/HEAD/res/drawable-xhdpi/icon_17183.png
--------------------------------------------------------------------------------
/res/drawable-xxhdpi/ic_drawer.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ConnectSDK/Connect-SDK-Android-API-Sampler/HEAD/res/drawable-xxhdpi/ic_drawer.png
--------------------------------------------------------------------------------
/res/drawable-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ConnectSDK/Connect-SDK-Android-API-Sampler/HEAD/res/drawable-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/res/drawable-hdpi/drawer_shadow.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ConnectSDK/Connect-SDK-Android-API-Sampler/HEAD/res/drawable-hdpi/drawer_shadow.9.png
--------------------------------------------------------------------------------
/res/drawable-mdpi/drawer_shadow.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ConnectSDK/Connect-SDK-Android-API-Sampler/HEAD/res/drawable-mdpi/drawer_shadow.9.png
--------------------------------------------------------------------------------
/res/drawable-xhdpi/drawer_shadow.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ConnectSDK/Connect-SDK-Android-API-Sampler/HEAD/res/drawable-xhdpi/drawer_shadow.9.png
--------------------------------------------------------------------------------
/res/drawable-xxhdpi/drawer_shadow.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ConnectSDK/Connect-SDK-Android-API-Sampler/HEAD/res/drawable-xxhdpi/drawer_shadow.9.png
--------------------------------------------------------------------------------
/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/lint.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
--------------------------------------------------------------------------------
/res/menu/main.xml:
--------------------------------------------------------------------------------
1 |
9 |
--------------------------------------------------------------------------------
/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/res/layout/fragment_navigation_drawer.xml:
--------------------------------------------------------------------------------
1 |
10 |
--------------------------------------------------------------------------------
/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
8 | 240dp
9 |
10 |
--------------------------------------------------------------------------------
/project.properties:
--------------------------------------------------------------------------------
1 | # This file is automatically generated by Android Tools.
2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3 | #
4 | # This file must be checked in Version Control Systems.
5 | #
6 | # To customize properties used by the Ant build system edit
7 | # "ant.properties", and override values to adapt the script to your
8 | # project structure.
9 | #
10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
12 |
13 | # Project target.
14 | target=android-22
15 | android.library.reference.1=../Connect-SDK-Android/core
16 | android.library.reference.2=../Connect-SDK-Android/modules/google_cast
17 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # built application files
2 | *.apk
3 | *.ap_
4 |
5 | # files for the dex VM
6 | *.dex
7 |
8 | # Java class files
9 | *.class
10 |
11 | # generated files
12 | bin/
13 | gen/
14 |
15 | # Ignore gradle files
16 | .gradle/
17 | build/
18 |
19 | # Local configuration file (sdk path, etc)
20 | local.properties
21 |
22 | # Proguard folder generated by Eclipse
23 | proguard/
24 |
25 | *.pydevproject
26 | .project
27 | .metadata
28 | bin/**
29 | tmp/**
30 | tmp/**/*
31 | *.tmp
32 | *.bak
33 | *.swp
34 | *~.nib
35 | local.properties
36 | .classpath
37 | .settings/
38 | .loadpath
39 |
40 | # External tool builders
41 | .externalToolBuilders/
42 |
43 | # Locally stored "Eclipse launch configurations"
44 | *.launch
45 |
46 | # CDT-specific
47 | .cproject
48 |
49 | # PDT-specific
50 | .buildpath
--------------------------------------------------------------------------------
/proguard-project.txt:
--------------------------------------------------------------------------------
1 | # To enable ProGuard in your project, edit project.properties
2 | # to define the proguard.config property as described in that file.
3 | #
4 | # Add project specific ProGuard rules here.
5 | # By default, the flags in this file are appended to flags specified
6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt
7 | # You can edit the include path and order by changing the ProGuard
8 | # include property in project.properties.
9 | #
10 | # For more details, see
11 | # http://developer.android.com/guide/developing/tools/proguard.html
12 |
13 | # Add any project specific keep options here:
14 |
15 | # If your project uses WebView with JS, uncomment the following
16 | # and specify the fully qualified class name to the JavaScript interface
17 | # class:
18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
19 | # public *;
20 | #}
21 |
--------------------------------------------------------------------------------
/src/com/connectsdk/sampler/MainApplication.java:
--------------------------------------------------------------------------------
1 | //
2 | // Connect SDK Sample App by LG Electronics
3 | //
4 | // To the extent possible under law, the person who associated CC0 with
5 | // this sample app has waived all copyright and related or neighboring rights
6 | // to the sample app.
7 | //
8 | // You should have received a copy of the CC0 legalcode along with this
9 | // work. If not, see http://creativecommons.org/publicdomain/zero/1.0/.
10 | //
11 |
12 | package com.connectsdk.sampler;
13 |
14 | import android.app.Application;
15 |
16 | import com.connectsdk.discovery.DiscoveryManager;
17 | import com.connectsdk.service.DIALService;
18 |
19 | public class MainApplication extends Application {
20 | @Override
21 | public void onCreate() {
22 | DIALService.registerApp("Levak");
23 | DiscoveryManager.init(getApplicationContext());
24 |
25 | super.onCreate();
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/res/layout/app_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
12 |
18 |
24 |
25 |
26 |
35 |
36 |
--------------------------------------------------------------------------------
/res/layout/channel_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
12 |
18 |
24 |
25 |
26 |
35 |
36 |
--------------------------------------------------------------------------------
/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
21 |
22 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | #Connect SDK Sampler App for Android
2 |
3 | Connect SDK is an open source framework that connects your mobile apps with multiple TV platforms. Because most TV platforms support a variety of protocols, Connect SDK integrates and abstracts the discovery and connectivity between all supported protocols.
4 |
5 | For more information, visit our [website](http://www.connectsdk.com/).
6 |
7 | * [General information about Connect SDK](http://www.connectsdk.com/discover/)
8 | * [Platform documentation & FAQs](http://www.connectsdk.com/docs/android/)
9 | * [API documentation](http://www.connectsdk.com/apis/android/)
10 |
11 | ##Dependencies
12 | - [Android v7 appcompat library](http://developer.android.com/tools/support-library/features.html#v7-appcompat)
13 | - Android SDK v22 (the Sampler app targets v22, but works on v10 and greater)
14 | - [Connect-SDK-Android-Core](https://github.com/ConnectSDK/Connect-SDK-Android-Core)
15 | - [Connect-SDK-Android-Google-Cast](https://github.com/ConnectSDK/Connect-SDK-Android-Google-Cast) for full version of Connect-SDK
16 |
17 | ##Setup with Android Studio
18 | 1. Download the Sampler project
19 | ```
20 | git clone https://github.com/ConnectSDK/Connect-SDK-Android-API-Sampler.git
21 | ```
22 | 2. Import the Sampler project into Android Studio
23 |
24 | ##Using dev branch
25 | If you use dev branch you should [setup](https://github.com/ConnectSDK/Connect-SDK-Android#including-connect-sdk-in-your-app-with-android-studio-from-sources) Connect-SDK-Android from sources and you should use Connect-SDK-Android dev branch as well
26 |
27 | ##Contact
28 | * Twitter [@ConnectSDK](https://www.twitter.com/ConnectSDK)
29 | * Ask a question on Stack Overflow with the [Connect-SDK tag](https://stackoverflow.com/tags/connect-sdk) (or [TV tag](https://stackoverflow.com/tags/tv))
30 | * General Inquiries info@connectsdk.com
31 | * Developer Support support@connectsdk.com
32 | * Partnerships partners@connectsdk.com
33 |
34 | ##License
35 |
36 | Connect SDK Sample App by LG Electronics
37 |
38 | To the extent possible under law, the person who associated CC0 with
39 | this sample app has waived all copyright and related or neighboring rights
40 | to the sample app.
41 |
42 | You should have received a copy of the CC0 legalcode along with this
43 | work. If not, see http://creativecommons.org/publicdomain/zero/1.0/.
--------------------------------------------------------------------------------
/src/com/connectsdk/sampler/widget/AppAdapter.java:
--------------------------------------------------------------------------------
1 | //
2 | // Connect SDK Sample App by LG Electronics
3 | //
4 | // To the extent possible under law, the person who associated CC0 with
5 | // this sample app has waived all copyright and related or neighboring rights
6 | // to the sample app.
7 | //
8 | // You should have received a copy of the CC0 legalcode along with this
9 | // work. If not, see http://creativecommons.org/publicdomain/zero/1.0/.
10 | //
11 |
12 | package com.connectsdk.sampler.widget;
13 |
14 | import java.util.Comparator;
15 |
16 | import android.content.Context;
17 | import android.graphics.Color;
18 | import android.view.View;
19 | import android.view.ViewGroup;
20 | import android.widget.ArrayAdapter;
21 | import android.widget.ImageView;
22 | import android.widget.TextView;
23 |
24 | import com.connectsdk.core.AppInfo;
25 | import com.connectsdk.sampler.R;
26 |
27 | public class AppAdapter extends ArrayAdapter {
28 | Context context;
29 | int resourceId;
30 | String runningAppId;
31 |
32 | public AppAdapter(Context context, int resource) {
33 | super(context, resource);
34 | this.context = context;
35 | this.resourceId = resource;
36 | }
37 |
38 | @Override
39 | public View getView(int position, View convertView, ViewGroup parent) {
40 | View view = convertView;
41 |
42 | if (convertView == null) {
43 | view = View.inflate(getContext(), resourceId, null);
44 | }
45 |
46 | AppInfo app = this.getItem(position);
47 |
48 | TextView textView = (TextView) view.findViewById(R.id.itemTitle);
49 | TextView subTextView = (TextView) view.findViewById(R.id.itemSubTitle);
50 | ImageView imageView = (ImageView) view.findViewById(R.id.itemCheck);
51 | textView.setText(app.getName());
52 | subTextView.setText(app.getId());
53 | if (runningAppId != null && runningAppId.equals(app.getId())) {
54 | System.out.println("runningAppId: " + runningAppId + ", id: " + app.getId());
55 | textView.setTextColor(Color.RED);
56 | imageView.setVisibility(View.VISIBLE);
57 | } else {
58 | textView.setTextColor(Color.BLACK);
59 | imageView.setVisibility(View.INVISIBLE);
60 | }
61 |
62 | return view;
63 | }
64 |
65 | public void setRunningAppId(String appId) {
66 | runningAppId = appId;
67 | }
68 |
69 | public void sort() {
70 | this.sort(new Comparator() {
71 | @Override
72 | public int compare(AppInfo lhs, AppInfo rhs) {
73 | return lhs.getName().compareTo(rhs.getName());
74 | }
75 | });
76 | }
77 | }
78 |
--------------------------------------------------------------------------------
/res/layout/fragment_apps.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
20 |
21 |
28 |
29 |
35 |
36 |
42 |
43 |
49 |
50 |
51 |
52 |
59 |
60 |
66 |
67 |
73 |
74 |
80 |
81 |
82 |
83 |
88 |
89 |
90 |
91 |
--------------------------------------------------------------------------------
/src/com/connectsdk/sampler/SectionsPagerAdapter.java:
--------------------------------------------------------------------------------
1 | //
2 | // Connect SDK Sample App by LG Electronics
3 | //
4 | // To the extent possible under law, the person who associated CC0 with
5 | // this sample app has waived all copyright and related or neighboring rights
6 | // to the sample app.
7 | //
8 | // You should have received a copy of the CC0 legalcode along with this
9 | // work. If not, see http://creativecommons.org/publicdomain/zero/1.0/.
10 | //
11 |
12 | package com.connectsdk.sampler;
13 |
14 | import android.content.Context;
15 | import android.content.res.TypedArray;
16 |
17 | import androidx.fragment.app.Fragment;
18 | import androidx.fragment.app.FragmentManager;
19 | import androidx.fragment.app.FragmentPagerAdapter;
20 |
21 | import com.connectsdk.sampler.fragments.AppsFragment;
22 | import com.connectsdk.sampler.fragments.BaseFragment;
23 | import com.connectsdk.sampler.fragments.KeyControlFragment;
24 | import com.connectsdk.sampler.fragments.MediaPlayerFragment;
25 | import com.connectsdk.sampler.fragments.SystemFragment;
26 | import com.connectsdk.sampler.fragments.TVFragment;
27 | import com.connectsdk.sampler.fragments.WebAppFragment;
28 |
29 | /**
30 | * A {@link FragmentPagerAdapter} that returns a fragment corresponding to
31 | * one of the sections/tabs/pages.
32 | */
33 | public class SectionsPagerAdapter extends FragmentPagerAdapter {
34 | private int[] mItems;
35 | private String[] mTitles;
36 | private FragmentManager mFragmentManager;
37 | private Context mContext;
38 |
39 | public SectionsPagerAdapter(Context context, FragmentManager fm) {
40 | super(fm);
41 | mContext = context;
42 | mFragmentManager = fm;
43 |
44 | TypedArray items = context.getResources().obtainTypedArray(R.array.tab_icons);
45 | mTitles = context.getResources().getStringArray(R.array.tab_titles);
46 |
47 | mItems = new int[items.length()];
48 |
49 | for (int i = 0; i < items.length(); i++) {
50 | mItems[i] = items.getResourceId(i, -1);
51 | }
52 |
53 | items.recycle();
54 | }
55 |
56 | @Override
57 | public Fragment getItem(int position) {
58 | BaseFragment newFragment;
59 |
60 | switch (position)
61 | {
62 | case 1:
63 | newFragment = new WebAppFragment(mContext);
64 | break;
65 |
66 | case 2:
67 | newFragment = new KeyControlFragment(mContext);
68 | break;
69 |
70 | case 3:
71 | newFragment = new AppsFragment(mContext);
72 | break;
73 |
74 | case 4:
75 | newFragment = new TVFragment(mContext);
76 | break;
77 |
78 | case 5:
79 | newFragment = new SystemFragment(mContext);
80 | break;
81 |
82 | case 0:
83 | default:
84 | newFragment = new MediaPlayerFragment(mContext);
85 | }
86 |
87 | return newFragment;
88 | }
89 |
90 | public BaseFragment getFragment(int position) {
91 | return (BaseFragment) mFragmentManager.findFragmentByTag("android:switcher:" + R.id.pager + ":" + position);
92 | }
93 |
94 | @Override
95 | public int getCount() {
96 | return mItems.length;
97 | }
98 |
99 | public int getIcon(int position) {
100 | return mItems[position];
101 | }
102 |
103 | public String getTitle(int position) {
104 | return mTitles[position];
105 | }
106 | }
--------------------------------------------------------------------------------
/src/com/connectsdk/sampler/util/TestResponseObject.java:
--------------------------------------------------------------------------------
1 | //
2 | // Connect SDK Sample App by LG Electronics
3 | //
4 | // To the extent possible under law, the person who associated CC0 with
5 | // this sample app has waived all copyright and related or neighboring rights
6 | // to the sample app.
7 | //
8 | // You should have received a copy of the CC0 legalcode along with this
9 | // work. If not, see http://creativecommons.org/publicdomain/zero/1.0/.
10 | //
11 |
12 | package com.connectsdk.sampler.util;
13 |
14 | public class TestResponseObject {
15 |
16 | public boolean isSuccess;
17 | public int httpResponseCode;
18 | public String responseMessage;
19 |
20 |
21 | public static final String Default = "default";
22 | public static final int SuccessCode = 200;
23 |
24 | public static final String Display_image = "ImageLaunched";
25 | public static final String Play_Video = "VideoLaunched";
26 | public static final String Play_Audio = "AudioLaunched";
27 |
28 | public static final String Closed_Media = "MediaClosed";
29 | public static final String Stopped_Media = "MediaStop";
30 | public static final String Stopped_image = "ImageStopped";
31 | public static final String Paused_Media = "MediaPaused";
32 | public static final String Played_Media = "MediaPlayed";
33 | public static final String Rewind_Media = "MediaRewind";
34 | public static final String FastForward_Media = "MediaFastForward";
35 |
36 | public static final String Launched_Netflix = "NetflixLaunched";
37 | public static final String Launched_Browser = "BrowserLaunched";
38 | public static final String Launched_Youtube = "YoutubeLaunched";
39 | public static final String Launched_WebAPP = "WebAPPLaunched";
40 | public static final String Joined_WebAPP = "WebAPPJoined";
41 | public static final String Pinned_WebAPP = "WebAPPPinned";
42 | public static final String UnPinned_WebAPP = "WebAPPUnPinned";
43 | public static final String Sent_Message = "SentMessage";
44 | public static final String Sent_JSON = "SentJSON";
45 | public static final String Leave_WebAPP = "LeaveWebAPP";
46 | public static final String Close_WebAPP = "ClosedWebAPP";
47 |
48 | public static final String Power_OFF = "PowerOFF";
49 |
50 | public static final String Show_Toast = "ShowedToast";
51 |
52 | public static final String Mute_Toggle = "MuteToggle";
53 | public static final String Muted_Media = "MuteMedia";
54 | public static final String UnMuted_Media = "UnMuteMedia";
55 |
56 | public static final String VolumeUp = "VolumeIncreased";
57 | public static final String VolumeDown = "VolumeDecreased";
58 | public static final String InputPickerVisible = "InputPickerShowing";
59 |
60 | public static final String HomeClicked = "HomeClicked";
61 | public static final String LeftClicked = "LeftClicked";
62 | public static final String RightClicked = "RightClicked";
63 | public static final String UpClicked = "UpClicked";
64 | public static final String DownClicked = "DownClicked";
65 | public static final String Clicked = "Clicked";
66 |
67 | public static final String Played_Playlist = "PlayedPlaylist";
68 | public static final String Jump = "jumpedTrack";
69 | public static final String Previous = "PreviousClicked";
70 | public static final String Next = "NextClicked";
71 |
72 |
73 | public TestResponseObject() {
74 | super();
75 | this.isSuccess = false;
76 | this.httpResponseCode = 0;
77 | this.responseMessage = "default";
78 |
79 | }
80 |
81 | public TestResponseObject(boolean isSuccess, int httpResponseCode, String responseMessage) {
82 | super();
83 | this.isSuccess = isSuccess;
84 | this.httpResponseCode = httpResponseCode;
85 | this.responseMessage = responseMessage;
86 | }
87 |
88 |
89 | }
90 |
--------------------------------------------------------------------------------
/res/layout/fragment_webapp.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
13 |
14 |
18 |
24 |
25 |
31 |
32 |
33 |
37 |
38 |
44 |
45 |
51 |
52 |
53 |
57 |
58 |
64 |
65 |
71 |
72 |
73 |
77 |
83 |
84 |
90 |
91 |
92 |
93 |
94 |
95 |
102 |
103 |
--------------------------------------------------------------------------------
/src/com/connectsdk/sampler/widget/ChannelAdapter.java:
--------------------------------------------------------------------------------
1 | //
2 | // Connect SDK Sample App by LG Electronics
3 | //
4 | // To the extent possible under law, the person who associated CC0 with
5 | // this sample app has waived all copyright and related or neighboring rights
6 | // to the sample app.
7 | //
8 | // You should have received a copy of the CC0 legalcode along with this
9 | // work. If not, see http://creativecommons.org/publicdomain/zero/1.0/.
10 | //
11 |
12 | package com.connectsdk.sampler.widget;
13 |
14 | import java.util.Comparator;
15 | import java.util.List;
16 |
17 | import android.content.Context;
18 | import android.view.View;
19 | import android.view.ViewGroup;
20 | import android.widget.ArrayAdapter;
21 | import android.widget.TextView;
22 |
23 | import com.connectsdk.core.ChannelInfo;
24 | import com.connectsdk.sampler.R;
25 |
26 | public class ChannelAdapter extends ArrayAdapter {
27 | private int resourceId;
28 | private ChannelInfo currentChannel;
29 |
30 | public ChannelAdapter(Context context, int resource) {
31 | super(context, resource);
32 | resourceId = resource;
33 | }
34 |
35 | public ChannelAdapter(Context context, int resource, int textViewResourceId) {
36 | super(context, resource, textViewResourceId);
37 | resourceId = resource;
38 | }
39 |
40 | public ChannelAdapter(Context context, int resource, ChannelInfo[] objects) {
41 | super(context, resource, objects);
42 | resourceId = resource;
43 | }
44 |
45 | public ChannelAdapter(Context context, int resource, List objects) {
46 | super(context, resource, objects);
47 | resourceId = resource;
48 | }
49 |
50 | public ChannelAdapter(Context context, int resource,
51 | int textViewResourceId, ChannelInfo[] objects) {
52 | super(context, resource, textViewResourceId, objects);
53 | resourceId = resource;
54 | }
55 |
56 | public ChannelAdapter(Context context, int resource,
57 | int textViewResourceId, List objects) {
58 | super(context, resource, textViewResourceId, objects);
59 | resourceId = resource;
60 | }
61 |
62 | @Override
63 | public View getView(int position, View convertView, ViewGroup parent) {
64 | View view = convertView;
65 |
66 | if (convertView == null) {
67 | view = View.inflate(getContext(), resourceId, null);
68 | }
69 |
70 | ChannelInfo app = this.getItem(position);
71 |
72 | TextView textView = (TextView) view.findViewById(R.id.itemTitle);
73 | TextView subTextView = (TextView) view.findViewById(R.id.itemSubTitle);
74 | TextView channelNumber = (TextView) view.findViewById(R.id.itemNumber);
75 | textView.setText(app.getName());
76 | subTextView.setText(app.getId());
77 | channelNumber.setText(app.getNumber());
78 |
79 | boolean isChannel = app.equals(currentChannel);
80 | int textColor = isChannel ? 0xFFFFFFFF : 0xFF000000;
81 | view.setBackgroundColor(isChannel ? 0xFF550000 : 0);
82 | textView.setTextColor(textColor);
83 | subTextView.setTextColor(textColor);
84 | channelNumber.setTextColor(textColor);
85 |
86 | return view;
87 | }
88 |
89 | public void setCurrentChannel(ChannelInfo currentChannel) {
90 | this.currentChannel = currentChannel;
91 | }
92 |
93 | public int getCurrentPosition() {
94 | if (currentChannel == null)
95 | return -1;
96 |
97 |
98 | for (int i = 0; i < getCount(); i++) {
99 | if (getItem(i).equals(currentChannel))
100 | return i;
101 | }
102 |
103 | return -1;
104 | }
105 |
106 | public void sort() {
107 | this.sort(new Comparator() {
108 | @Override
109 | public int compare(ChannelInfo lhs, ChannelInfo rhs) {
110 | int sortMajor = lhs.getMajorNumber() - rhs.getMajorNumber();
111 | if (sortMajor == 0)
112 | return lhs.getMinorNumber() - rhs.getMinorNumber();
113 | else
114 | return sortMajor;
115 | }
116 | });
117 | }
118 | }
119 |
--------------------------------------------------------------------------------
/res/layout/fragment_fiveway.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
14 |
15 |
23 |
24 |
31 |
32 |
39 |
40 |
41 |
42 |
48 |
49 |
56 |
57 |
64 |
65 |
72 |
73 |
74 |
80 |
81 |
88 |
89 |
96 |
97 |
104 |
105 |
106 |
107 |
113 |
114 |
115 |
121 |
122 |
123 |
124 |
--------------------------------------------------------------------------------
/res/layout/fragment_system.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
13 |
14 |
20 |
21 |
28 |
29 |
30 |
31 |
37 |
38 |
47 |
48 |
55 |
56 |
63 |
64 |
65 |
66 |
73 |
74 |
80 |
81 |
87 |
88 |
94 |
95 |
96 |
97 |
103 |
104 |
110 |
111 |
117 |
118 |
119 |
120 |
125 |
126 |
131 |
132 |
133 |
134 |
139 |
140 |
141 |
142 |
--------------------------------------------------------------------------------
/src/com/connectsdk/sampler/fragments/BaseFragment.java:
--------------------------------------------------------------------------------
1 | //
2 | // Connect SDK Sample App by LG Electronics
3 | //
4 | // To the extent possible under law, the person who associated CC0 with
5 | // this sample app has waived all copyright and related or neighboring rights
6 | // to the sample app.
7 | //
8 | // You should have received a copy of the CC0 legalcode along with this
9 | // work. If not, see http://creativecommons.org/publicdomain/zero/1.0/.
10 | //
11 |
12 | package com.connectsdk.sampler.fragments;
13 |
14 | import android.content.Context;
15 | import android.os.Bundle;
16 | import androidx.fragment.app.Fragment;
17 | import android.view.KeyEvent;
18 | import android.widget.Button;
19 |
20 | import com.connectsdk.device.ConnectableDevice;
21 | import com.connectsdk.service.capability.ExternalInputControl;
22 | import com.connectsdk.service.capability.KeyControl;
23 | import com.connectsdk.service.capability.Launcher;
24 | import com.connectsdk.service.capability.MediaControl;
25 | import com.connectsdk.service.capability.MediaPlayer;
26 | import com.connectsdk.service.capability.MouseControl;
27 | import com.connectsdk.service.capability.PowerControl;
28 | import com.connectsdk.service.capability.TVControl;
29 | import com.connectsdk.service.capability.TextInputControl;
30 | import com.connectsdk.service.capability.ToastControl;
31 | import com.connectsdk.service.capability.VolumeControl;
32 | import com.connectsdk.service.capability.WebAppLauncher;
33 |
34 | public class BaseFragment extends Fragment {
35 |
36 | private ConnectableDevice mTv;
37 | private Launcher launcher;
38 | private MediaPlayer mediaPlayer;
39 | private MediaControl mediaControl;
40 | private TVControl tvControl;
41 | private VolumeControl volumeControl;
42 | private ToastControl toastControl;
43 | private MouseControl mouseControl;
44 | private TextInputControl textInputControl;
45 | private PowerControl powerControl;
46 | private ExternalInputControl externalInputControl;
47 | private KeyControl keyControl;
48 | private WebAppLauncher webAppLauncher;
49 | public Button[] buttons;
50 | Context mContext;
51 |
52 | public BaseFragment() {}
53 |
54 | public BaseFragment(Context context)
55 | {
56 | mContext = context;
57 | }
58 |
59 | @Override
60 | public void onActivityCreated(Bundle savedInstanceState) {
61 | super.onActivityCreated(savedInstanceState);
62 |
63 | setTv(mTv);
64 | }
65 |
66 | public void setTv(ConnectableDevice tv)
67 | {
68 | mTv = tv;
69 |
70 | if (tv == null) {
71 | launcher = null;
72 | mediaPlayer = null;
73 | mediaControl = null;
74 | tvControl = null;
75 | volumeControl = null;
76 | toastControl = null;
77 | textInputControl = null;
78 | mouseControl = null;
79 | externalInputControl = null;
80 | powerControl = null;
81 | keyControl = null;
82 | webAppLauncher = null;
83 |
84 | disableButtons();
85 | }
86 | else {
87 | launcher = mTv.getCapability(Launcher.class);
88 | mediaPlayer = mTv.getCapability(MediaPlayer.class);
89 | mediaControl = mTv.getCapability(MediaControl.class);
90 | tvControl = mTv.getCapability(TVControl.class);
91 | volumeControl = mTv.getCapability(VolumeControl.class);
92 | toastControl = mTv.getCapability(ToastControl.class);
93 | textInputControl = mTv.getCapability(TextInputControl.class);
94 | mouseControl = mTv.getCapability(MouseControl.class);
95 | externalInputControl = mTv.getCapability(ExternalInputControl.class);
96 | powerControl = mTv.getCapability(PowerControl.class);
97 | keyControl = mTv.getCapability(KeyControl.class);
98 | webAppLauncher = mTv.getCapability(WebAppLauncher.class);
99 |
100 | enableButtons();
101 | }
102 | }
103 |
104 | public void disableButtons() {
105 | if (buttons != null)
106 | {
107 | for (Button button : buttons)
108 | {
109 | button.setOnClickListener(null);
110 | button.setEnabled(false);
111 | }
112 | }
113 | }
114 |
115 | public void enableButtons() {
116 | if (buttons != null)
117 | {
118 | for (Button button : buttons)
119 | button.setEnabled(true);
120 | }
121 | }
122 |
123 | public boolean onKeyDown(int keyCode, KeyEvent event) {
124 | return false;
125 | }
126 |
127 | public boolean onKeyUp(int keyCode, KeyEvent event) {
128 | return false;
129 | }
130 |
131 | public ConnectableDevice getTv()
132 | {
133 | return mTv;
134 | }
135 |
136 | public Launcher getLauncher()
137 | {
138 | return launcher;
139 | }
140 |
141 | public MediaPlayer getMediaPlayer()
142 | {
143 | return mediaPlayer;
144 | }
145 |
146 | public MediaControl getMediaControl()
147 | {
148 | return mediaControl;
149 | }
150 |
151 | public VolumeControl getVolumeControl()
152 | {
153 | return volumeControl;
154 | }
155 |
156 | public TVControl getTVControl()
157 | {
158 | return tvControl;
159 | }
160 |
161 | public ToastControl getToastControl()
162 | {
163 | return toastControl;
164 | }
165 |
166 | public TextInputControl getTextInputControl()
167 | {
168 | return textInputControl;
169 | }
170 |
171 | public MouseControl getMouseControl()
172 | {
173 | return mouseControl;
174 | }
175 |
176 | public ExternalInputControl getExternalInputControl()
177 | {
178 | return externalInputControl;
179 | }
180 |
181 | public PowerControl getPowerControl()
182 | {
183 | return powerControl;
184 | }
185 |
186 | public KeyControl getKeyControl()
187 | {
188 | return keyControl;
189 | }
190 |
191 | public WebAppLauncher getWebAppLauncher()
192 | {
193 | return webAppLauncher;
194 | }
195 |
196 | public Context getContext()
197 | {
198 | return mContext;
199 | }
200 |
201 | protected void disableButton(final Button button) {
202 | button.setEnabled(false);
203 | }
204 | }
--------------------------------------------------------------------------------
/res/layout/fragment_tv.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
14 |
15 |
22 |
23 |
30 |
31 |
38 |
39 |
40 |
46 |
47 |
54 |
55 |
62 |
63 |
70 |
71 |
72 |
78 |
79 |
86 |
87 |
94 |
95 |
102 |
103 |
104 |
110 |
111 |
118 |
119 |
126 |
127 |
134 |
135 |
136 |
137 |
144 |
145 |
151 |
152 |
158 |
159 |
160 |
161 |
166 |
167 |
172 |
173 |
178 |
179 |
184 |
185 |
186 |
187 |
192 |
193 |
194 |
195 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Creative Commons Legal Code
2 |
3 | CC0 1.0 Universal
4 |
5 | CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE
6 | LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN
7 | ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS
8 | INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES
9 | REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS
10 | PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM
11 | THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED
12 | HEREUNDER.
13 |
14 | Statement of Purpose
15 |
16 | The laws of most jurisdictions throughout the world automatically confer
17 | exclusive Copyright and Related Rights (defined below) upon the creator
18 | and subsequent owner(s) (each and all, an "owner") of an original work of
19 | authorship and/or a database (each, a "Work").
20 |
21 | Certain owners wish to permanently relinquish those rights to a Work for
22 | the purpose of contributing to a commons of creative, cultural and
23 | scientific works ("Commons") that the public can reliably and without fear
24 | of later claims of infringement build upon, modify, incorporate in other
25 | works, reuse and redistribute as freely as possible in any form whatsoever
26 | and for any purposes, including without limitation commercial purposes.
27 | These owners may contribute to the Commons to promote the ideal of a free
28 | culture and the further production of creative, cultural and scientific
29 | works, or to gain reputation or greater distribution for their Work in
30 | part through the use and efforts of others.
31 |
32 | For these and/or other purposes and motivations, and without any
33 | expectation of additional consideration or compensation, the person
34 | associating CC0 with a Work (the "Affirmer"), to the extent that he or she
35 | is an owner of Copyright and Related Rights in the Work, voluntarily
36 | elects to apply CC0 to the Work and publicly distribute the Work under its
37 | terms, with knowledge of his or her Copyright and Related Rights in the
38 | Work and the meaning and intended legal effect of CC0 on those rights.
39 |
40 | 1. Copyright and Related Rights. A Work made available under CC0 may be
41 | protected by copyright and related or neighboring rights ("Copyright and
42 | Related Rights"). Copyright and Related Rights include, but are not
43 | limited to, the following:
44 |
45 | i. the right to reproduce, adapt, distribute, perform, display,
46 | communicate, and translate a Work;
47 | ii. moral rights retained by the original author(s) and/or performer(s);
48 | iii. publicity and privacy rights pertaining to a person's image or
49 | likeness depicted in a Work;
50 | iv. rights protecting against unfair competition in regards to a Work,
51 | subject to the limitations in paragraph 4(a), below;
52 | v. rights protecting the extraction, dissemination, use and reuse of data
53 | in a Work;
54 | vi. database rights (such as those arising under Directive 96/9/EC of the
55 | European Parliament and of the Council of 11 March 1996 on the legal
56 | protection of databases, and under any national implementation
57 | thereof, including any amended or successor version of such
58 | directive); and
59 | vii. other similar, equivalent or corresponding rights throughout the
60 | world based on applicable law or treaty, and any national
61 | implementations thereof.
62 |
63 | 2. Waiver. To the greatest extent permitted by, but not in contravention
64 | of, applicable law, Affirmer hereby overtly, fully, permanently,
65 | irrevocably and unconditionally waives, abandons, and surrenders all of
66 | Affirmer's Copyright and Related Rights and associated claims and causes
67 | of action, whether now known or unknown (including existing as well as
68 | future claims and causes of action), in the Work (i) in all territories
69 | worldwide, (ii) for the maximum duration provided by applicable law or
70 | treaty (including future time extensions), (iii) in any current or future
71 | medium and for any number of copies, and (iv) for any purpose whatsoever,
72 | including without limitation commercial, advertising or promotional
73 | purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each
74 | member of the public at large and to the detriment of Affirmer's heirs and
75 | successors, fully intending that such Waiver shall not be subject to
76 | revocation, rescission, cancellation, termination, or any other legal or
77 | equitable action to disrupt the quiet enjoyment of the Work by the public
78 | as contemplated by Affirmer's express Statement of Purpose.
79 |
80 | 3. Public License Fallback. Should any part of the Waiver for any reason
81 | be judged legally invalid or ineffective under applicable law, then the
82 | Waiver shall be preserved to the maximum extent permitted taking into
83 | account Affirmer's express Statement of Purpose. In addition, to the
84 | extent the Waiver is so judged Affirmer hereby grants to each affected
85 | person a royalty-free, non transferable, non sublicensable, non exclusive,
86 | irrevocable and unconditional license to exercise Affirmer's Copyright and
87 | Related Rights in the Work (i) in all territories worldwide, (ii) for the
88 | maximum duration provided by applicable law or treaty (including future
89 | time extensions), (iii) in any current or future medium and for any number
90 | of copies, and (iv) for any purpose whatsoever, including without
91 | limitation commercial, advertising or promotional purposes (the
92 | "License"). The License shall be deemed effective as of the date CC0 was
93 | applied by Affirmer to the Work. Should any part of the License for any
94 | reason be judged legally invalid or ineffective under applicable law, such
95 | partial invalidity or ineffectiveness shall not invalidate the remainder
96 | of the License, and in such case Affirmer hereby affirms that he or she
97 | will not (i) exercise any of his or her remaining Copyright and Related
98 | Rights in the Work or (ii) assert any associated claims and causes of
99 | action with respect to the Work, in either case contrary to Affirmer's
100 | express Statement of Purpose.
101 |
102 | 4. Limitations and Disclaimers.
103 |
104 | a. No trademark or patent rights held by Affirmer are waived, abandoned,
105 | surrendered, licensed or otherwise affected by this document.
106 | b. Affirmer offers the Work as-is and makes no representations or
107 | warranties of any kind concerning the Work, express, implied,
108 | statutory or otherwise, including without limitation warranties of
109 | title, merchantability, fitness for a particular purpose, non
110 | infringement, or the absence of latent or other defects, accuracy, or
111 | the present or absence of errors, whether or not discoverable, all to
112 | the greatest extent permissible under applicable law.
113 | c. Affirmer disclaims responsibility for clearing rights of other persons
114 | that may apply to the Work or any use thereof, including without
115 | limitation any person's Copyright and Related Rights in the Work.
116 | Further, Affirmer disclaims responsibility for obtaining any necessary
117 | consents, permissions or other rights required for any use of the
118 | Work.
119 | d. Affirmer understands and acknowledges that Creative Commons is not a
120 | party to this document and has no duty or obligation with respect to
121 | this CC0 or use of the Work.
122 |
--------------------------------------------------------------------------------
/res/layout/fragment_media_player.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
11 |
12 |
17 |
18 |
24 |
25 |
31 |
32 |
38 |
39 |
40 |
41 |
46 |
47 |
53 |
54 |
60 |
61 |
67 |
68 |
69 |
70 |
74 |
75 |
81 |
82 |
88 |
89 |
95 |
96 |
97 |
98 |
103 |
104 |
110 |
111 |
117 |
118 |
124 |
125 |
126 |
127 |
131 |
132 |
138 |
139 |
145 |
146 |
152 |
153 |
160 |
161 |
162 |
163 |
169 |
170 |
171 |
181 |
182 |
183 |
190 |
191 |
201 |
202 |
203 |
210 |
211 |
218 |
219 |
226 |
227 |
233 |
234 |
240 |
241 |
248 |
249 |
254 |
255 |
256 |
257 |
258 |
259 |
260 |
--------------------------------------------------------------------------------
/src/com/connectsdk/sampler/fragments/TVFragment.java:
--------------------------------------------------------------------------------
1 | //
2 | // Connect SDK Sample App by LG Electronics
3 | //
4 | // To the extent possible under law, the person who associated CC0 with
5 | // this sample app has waived all copyright and related or neighboring rights
6 | // to the sample app.
7 | //
8 | // You should have received a copy of the CC0 legalcode along with this
9 | // work. If not, see http://creativecommons.org/publicdomain/zero/1.0/.
10 | //
11 |
12 | package com.connectsdk.sampler.fragments;
13 |
14 | import java.util.List;
15 |
16 | import android.content.Context;
17 | import android.os.Bundle;
18 | import android.view.LayoutInflater;
19 | import android.view.View;
20 | import android.view.ViewGroup;
21 | import android.widget.AdapterView;
22 | import android.widget.AdapterView.OnItemClickListener;
23 | import android.widget.Button;
24 | import android.widget.ListView;
25 |
26 | import com.connectsdk.core.ChannelInfo;
27 | import com.connectsdk.sampler.R;
28 | import com.connectsdk.sampler.util.TestResponseObject;
29 | import com.connectsdk.sampler.widget.ChannelAdapter;
30 | import com.connectsdk.service.capability.KeyControl;
31 | import com.connectsdk.service.capability.PowerControl;
32 | import com.connectsdk.service.capability.TVControl;
33 | import com.connectsdk.service.capability.KeyControl.KeyCode;
34 | import com.connectsdk.service.capability.TVControl.ChannelListListener;
35 | import com.connectsdk.service.capability.TVControl.ChannelListener;
36 | import com.connectsdk.service.command.ServiceCommandError;
37 | import com.connectsdk.service.command.ServiceSubscription;
38 |
39 | public class TVFragment extends BaseFragment {
40 | public Button channelUpButton;
41 | public Button channelDownButton;
42 | public Button powerOffButton;
43 | public Button mode3DButton;
44 |
45 | public Button[] numberButtons = new Button[10];
46 | public Button dashButton;
47 | public Button enterButton;
48 |
49 | public ListView channelListView;
50 | public ChannelAdapter adapter;
51 |
52 | boolean mode3DToggle;
53 | boolean incomingCallToggle;
54 | public TestResponseObject testResponse;
55 |
56 | private ServiceSubscription mCurrentChannelSubscription;
57 |
58 | public TVFragment() {};
59 |
60 | public TVFragment(Context context)
61 | {
62 | super(context);
63 | testResponse = new TestResponseObject();
64 | }
65 |
66 | @Override
67 | public View onCreateView(LayoutInflater inflater, ViewGroup container,
68 | Bundle savedInstanceState) {
69 | View rootView = inflater.inflate(
70 | R.layout.fragment_tv, container, false);
71 |
72 | numberButtons[0] = (Button) rootView.findViewById(R.id.numberButton0);
73 | numberButtons[1] = (Button) rootView.findViewById(R.id.numberButton1);
74 | numberButtons[2] = (Button) rootView.findViewById(R.id.numberButton2);
75 | numberButtons[3] = (Button) rootView.findViewById(R.id.numberButton3);
76 | numberButtons[4] = (Button) rootView.findViewById(R.id.numberButton4);
77 | numberButtons[5] = (Button) rootView.findViewById(R.id.numberButton5);
78 | numberButtons[6] = (Button) rootView.findViewById(R.id.numberButton6);
79 | numberButtons[7] = (Button) rootView.findViewById(R.id.numberButton7);
80 | numberButtons[8] = (Button) rootView.findViewById(R.id.numberButton8);
81 | numberButtons[9] = (Button) rootView.findViewById(R.id.numberButton9);
82 |
83 | dashButton = (Button) rootView.findViewById(R.id.dashButton);
84 | enterButton = (Button) rootView.findViewById(R.id.enterButton);
85 |
86 | channelUpButton = (Button) rootView.findViewById(R.id.channelUpButton);
87 | channelDownButton = (Button) rootView.findViewById(R.id.channelDownButton);
88 | powerOffButton = (Button) rootView.findViewById(R.id.powerOffButton);
89 | mode3DButton = (Button) rootView.findViewById(R.id.mode3DButton);
90 |
91 | channelListView = (ListView) rootView.findViewById(R.id.channelListView);
92 | adapter = new ChannelAdapter(getContext(), R.layout.channel_item);
93 |
94 | channelListView.setAdapter(adapter);
95 |
96 | buttons = new Button[] {
97 | numberButtons[0],
98 | numberButtons[1],
99 | numberButtons[2],
100 | numberButtons[3],
101 | numberButtons[4],
102 | numberButtons[5],
103 | numberButtons[6],
104 | numberButtons[7],
105 | numberButtons[8],
106 | numberButtons[9],
107 | dashButton,
108 | enterButton,
109 | channelUpButton,
110 | channelDownButton,
111 | powerOffButton,
112 | mode3DButton
113 | };
114 |
115 | mode3DToggle = false;
116 | incomingCallToggle = false;
117 |
118 | channelListView.setOnItemClickListener(new OnItemClickListener() {
119 |
120 | @Override
121 | public void onItemClick(AdapterView> arg0, View arg1, int arg2, long arg3) {
122 | ChannelInfo channelInfo = (ChannelInfo) arg0.getItemAtPosition(arg2);
123 | getTVControl().setChannel(channelInfo, null);
124 | }
125 | });
126 |
127 | return rootView;
128 | }
129 |
130 | @Override
131 | public void enableButtons()
132 | {
133 | super.enableButtons();
134 |
135 | if (getTv().hasAnyCapability(KeyControl.KeyCode)) {
136 | numberButtons[0].setOnClickListener(new View.OnClickListener() {
137 |
138 | @Override
139 | public void onClick(View v) {
140 | getKeyControl().sendKeyCode(KeyCode.NUM_0, null);;
141 | }
142 | });
143 |
144 | numberButtons[1].setOnClickListener(new View.OnClickListener() {
145 |
146 | @Override
147 | public void onClick(View v) {
148 | getKeyControl().sendKeyCode(KeyCode.NUM_1, null);;
149 | }
150 | });
151 |
152 | numberButtons[2].setOnClickListener(new View.OnClickListener() {
153 |
154 | @Override
155 | public void onClick(View v) {
156 | getKeyControl().sendKeyCode(KeyCode.NUM_2, null);;
157 | }
158 | });
159 |
160 | numberButtons[3].setOnClickListener(new View.OnClickListener() {
161 |
162 | @Override
163 | public void onClick(View v) {
164 | getKeyControl().sendKeyCode(KeyCode.NUM_3, null);;
165 | }
166 | });
167 |
168 | numberButtons[4].setOnClickListener(new View.OnClickListener() {
169 |
170 | @Override
171 | public void onClick(View v) {
172 | getKeyControl().sendKeyCode(KeyCode.NUM_4, null);;
173 | }
174 | });
175 |
176 | numberButtons[5].setOnClickListener(new View.OnClickListener() {
177 |
178 | @Override
179 | public void onClick(View v) {
180 | getKeyControl().sendKeyCode(KeyCode.NUM_5, null);;
181 | }
182 | });
183 |
184 | numberButtons[6].setOnClickListener(new View.OnClickListener() {
185 |
186 | @Override
187 | public void onClick(View v) {
188 | getKeyControl().sendKeyCode(KeyCode.NUM_6, null);;
189 | }
190 | });
191 |
192 | numberButtons[7].setOnClickListener(new View.OnClickListener() {
193 |
194 | @Override
195 | public void onClick(View v) {
196 | getKeyControl().sendKeyCode(KeyCode.NUM_7, null);;
197 | }
198 | });
199 |
200 | numberButtons[8].setOnClickListener(new View.OnClickListener() {
201 |
202 | @Override
203 | public void onClick(View v) {
204 | getKeyControl().sendKeyCode(KeyCode.NUM_8, null);;
205 | }
206 | });
207 |
208 | numberButtons[9].setOnClickListener(new View.OnClickListener() {
209 |
210 | @Override
211 | public void onClick(View v) {
212 | getKeyControl().sendKeyCode(KeyCode.NUM_9, null);;
213 | }
214 | });
215 |
216 | dashButton.setOnClickListener(new View.OnClickListener() {
217 |
218 | @Override
219 | public void onClick(View v) {
220 | getKeyControl().sendKeyCode(KeyCode.DASH, null);;
221 | }
222 | });
223 |
224 | enterButton.setOnClickListener(new View.OnClickListener() {
225 |
226 | @Override
227 | public void onClick(View v) {
228 | getKeyControl().sendKeyCode(KeyCode.ENTER, null);;
229 | }
230 | });
231 | }
232 | else {
233 | disableButton(numberButtons[0]);
234 | disableButton(numberButtons[1]);
235 | disableButton(numberButtons[2]);
236 | disableButton(numberButtons[3]);
237 | disableButton(numberButtons[4]);
238 | disableButton(numberButtons[5]);
239 | disableButton(numberButtons[6]);
240 | disableButton(numberButtons[7]);
241 | disableButton(numberButtons[8]);
242 | disableButton(numberButtons[9]);
243 | disableButton(dashButton);
244 | disableButton(enterButton);
245 | }
246 |
247 | if (getTv().hasCapability(TVControl.Channel_Up)) {
248 | channelUpButton.setOnClickListener(new View.OnClickListener() {
249 | @Override
250 | public void onClick(View view) {
251 | getTVControl().channelUp(null);
252 | }
253 | });
254 | }
255 | else {
256 | disableButton(channelUpButton);
257 | }
258 |
259 | if (getTv().hasCapability(TVControl.Channel_Down)) {
260 | channelDownButton.setOnClickListener(new View.OnClickListener() {
261 | @Override
262 | public void onClick(View view) {
263 | getTVControl().channelDown(null);
264 | }
265 | });
266 | }
267 | else {
268 | disableButton(channelDownButton);
269 | }
270 |
271 | if (getTv().hasCapability(PowerControl.Off)) {
272 | powerOffButton.setOnClickListener(new View.OnClickListener() {
273 |
274 | @Override
275 | public void onClick(View v) {
276 | testResponse = new TestResponseObject(true, TestResponseObject.SuccessCode, TestResponseObject.Power_OFF);
277 | getPowerControl().powerOff(null);
278 | }
279 | });
280 | }
281 | else {
282 | disableButton(powerOffButton);
283 | }
284 |
285 | if (getTv().hasCapability(TVControl.Set_3D)) {
286 | mode3DButton.setOnClickListener(new View.OnClickListener() {
287 |
288 | @Override
289 | public void onClick(View v) {
290 | if (getTv().hasCapability(TVControl.Set_3D)) {
291 | if (getTVControl() != null) {
292 | mode3DToggle = !mode3DToggle;
293 | getTVControl().set3DEnabled(mode3DToggle, null);
294 | }
295 | }
296 | }
297 | });
298 | }
299 | else {
300 | disableButton(mode3DButton);
301 | }
302 |
303 | if (getTv().hasCapability(TVControl.Channel_List)) {
304 | getTVControl().getChannelList(new ChannelListListener() {
305 |
306 | @Override
307 | public void onSuccess(List channelList) {
308 | adapter.clear();
309 | for (ChannelInfo channel : channelList)
310 | adapter.add(channel);
311 | adapter.sort();
312 | }
313 |
314 | @Override
315 | public void onError(ServiceCommandError arg0) {
316 |
317 | }
318 | });
319 | }
320 |
321 | if (getTv().hasCapability(TVControl.Channel_Subscribe)) {
322 | mCurrentChannelSubscription = getTVControl().subscribeCurrentChannel(new ChannelListener() {
323 |
324 | @Override
325 | public void onSuccess(final ChannelInfo ch) {
326 | adapter.setCurrentChannel(ch);
327 | adapter.notifyDataSetChanged();
328 |
329 | int position = adapter.getPosition(ch);
330 | channelListView.setSelection(position);
331 | }
332 |
333 | @Override
334 | public void onError(ServiceCommandError error) {
335 |
336 | }
337 | });
338 | }
339 | }
340 |
341 | @Override
342 | public void disableButtons()
343 | {
344 | adapter.clear();
345 |
346 | if (mCurrentChannelSubscription != null)
347 | {
348 | mCurrentChannelSubscription.unsubscribe();
349 | mCurrentChannelSubscription = null;
350 | }
351 |
352 | super.disableButtons();
353 | }
354 | }
355 |
--------------------------------------------------------------------------------
/src/com/connectsdk/sampler/fragments/SystemFragment.java:
--------------------------------------------------------------------------------
1 | //
2 | // Connect SDK Sample App by LG Electronics
3 | //
4 | // To the extent possible under law, the person who associated CC0 with
5 | // this sample app has waived all copyright and related or neighboring rights
6 | // to the sample app.
7 | //
8 | // You should have received a copy of the CC0 legalcode along with this
9 | // work. If not, see http://creativecommons.org/publicdomain/zero/1.0/.
10 | //
11 |
12 | package com.connectsdk.sampler.fragments;
13 |
14 | import java.util.List;
15 |
16 | import android.content.Context;
17 | import android.os.Bundle;
18 | import android.util.Log;
19 | import android.view.LayoutInflater;
20 | import android.view.View;
21 | import android.view.View.OnClickListener;
22 | import android.view.ViewGroup;
23 | import android.widget.AdapterView;
24 | import android.widget.AdapterView.OnItemClickListener;
25 | import android.widget.ArrayAdapter;
26 | import android.widget.Button;
27 | import android.widget.CheckBox;
28 | import android.widget.ListView;
29 | import android.widget.SeekBar;
30 |
31 | import com.connectsdk.core.ExternalInputInfo;
32 | import com.connectsdk.sampler.R;
33 | import com.connectsdk.sampler.util.TestResponseObject;
34 | import com.connectsdk.service.capability.ExternalInputControl;
35 | import com.connectsdk.service.capability.ExternalInputControl.ExternalInputListListener;
36 | import com.connectsdk.service.capability.Launcher;
37 | import com.connectsdk.service.capability.MediaControl;
38 | import com.connectsdk.service.capability.VolumeControl;
39 | import com.connectsdk.service.capability.VolumeControl.MuteListener;
40 | import com.connectsdk.service.capability.VolumeControl.VolumeListener;
41 | import com.connectsdk.service.command.ServiceCommandError;
42 | import com.connectsdk.service.command.ServiceSubscription;
43 | import com.connectsdk.service.sessions.LaunchSession;
44 |
45 | public class SystemFragment extends BaseFragment {
46 | public CheckBox muteToggleButton;
47 | public Button volumeUpButton;
48 | public Button volumeDownButton;
49 | public SeekBar volumeSlider;
50 |
51 | public Button playButton;
52 | public Button pauseButton;
53 | public Button stopButton;
54 | public Button rewindButton;
55 | public Button fastForwardButton;
56 |
57 | public Button inputPickerButton;
58 |
59 | public ListView inputListView;
60 | public ArrayAdapter adapter;
61 |
62 | public LaunchSession inputPickerSession;
63 |
64 | public TestResponseObject testResponse;
65 |
66 | private ServiceSubscription mVolumeSubscription;
67 | private ServiceSubscription mMuteSubscription;
68 |
69 | public SystemFragment() {};
70 |
71 | public SystemFragment(Context context)
72 | {
73 | super(context);
74 | testResponse = new TestResponseObject();
75 | }
76 |
77 | @Override
78 | public View onCreateView(LayoutInflater inflater, ViewGroup container,
79 | Bundle savedInstanceState) {
80 | View rootView = inflater.inflate(
81 | R.layout.fragment_system, container, false);
82 |
83 | muteToggleButton = (CheckBox) rootView.findViewById(R.id.muteToggle);
84 | volumeUpButton = (Button) rootView.findViewById(R.id.volumeUpButton);
85 | volumeDownButton = (Button) rootView.findViewById(R.id.volumeDownButton);
86 | inputListView = (ListView) rootView.findViewById(R.id.inputListView);
87 | playButton = (Button) rootView.findViewById(R.id.playButton);
88 | pauseButton = (Button) rootView.findViewById(R.id.pauseButton);
89 | stopButton = (Button) rootView.findViewById(R.id.stopButton);
90 | rewindButton = (Button) rootView.findViewById(R.id.rewindButton);
91 | fastForwardButton = (Button) rootView.findViewById(R.id.fastForwardButton);
92 | adapter = new ArrayAdapter(getContext(), android.R.layout.simple_list_item_1);
93 | inputListView.setAdapter(adapter);
94 |
95 | volumeSlider = (SeekBar) rootView.findViewById(R.id.volumeSlider);
96 | volumeSlider.setMax(100);
97 |
98 | inputListView.setOnItemClickListener(new OnItemClickListener() {
99 |
100 | @Override
101 | public void onItemClick(AdapterView> arg0, View arg1, int arg2, long arg3) {
102 | String input = (String) arg0.getItemAtPosition(arg2);
103 | if (getTv().hasCapability(ExternalInputControl.Set)) {
104 | ExternalInputInfo inputInfo = new ExternalInputInfo();
105 | inputInfo.setId(input);
106 | getExternalInputControl().setExternalInput(inputInfo, null);
107 | }
108 | }
109 | });
110 |
111 | inputPickerButton = (Button) rootView.findViewById(R.id.inputPickerButton);
112 |
113 | buttons = new Button[] {
114 | inputPickerButton,
115 | volumeUpButton,
116 | volumeDownButton,
117 | muteToggleButton,
118 | pauseButton,
119 | playButton,
120 | stopButton,
121 | rewindButton,
122 | fastForwardButton
123 | };
124 | buttons[0] = inputPickerButton;
125 |
126 | return rootView;
127 | }
128 |
129 | @Override
130 | public void enableButtons() {
131 | super.enableButtons();
132 |
133 | if (getTv().hasCapability(ExternalInputControl.List))
134 | getExternalInputControl().getExternalInputList(externalInputListener);
135 |
136 | volumeSlider.setEnabled(getTv().hasCapability(VolumeControl.Volume_Set));
137 | inputPickerButton.setEnabled(getTv().hasCapability(ExternalInputControl.Picker_Launch));
138 | muteToggleButton.setEnabled(getTv().hasCapability(VolumeControl.Mute_Set));
139 | volumeUpButton.setEnabled(getTv().hasCapability(VolumeControl.Volume_Up_Down));
140 | volumeDownButton.setEnabled(getTv().hasCapability(VolumeControl.Volume_Up_Down));
141 |
142 | playButton.setEnabled(getTv().hasCapability(MediaControl.Play));
143 | pauseButton.setEnabled(getTv().hasCapability(MediaControl.Pause));
144 | stopButton.setEnabled(getTv().hasCapability(MediaControl.Stop));
145 | rewindButton.setEnabled(getTv().hasCapability(MediaControl.Rewind));
146 | fastForwardButton.setEnabled(getTv().hasCapability(MediaControl.FastForward));
147 |
148 | if (getTv().hasCapability(VolumeControl.Volume_Subscribe))
149 | mVolumeSubscription = getVolumeControl().subscribeVolume(volumeListener);
150 |
151 | if (getTv().hasCapability(VolumeControl.Mute_Subscribe))
152 | mMuteSubscription = getVolumeControl().subscribeMute(muteListener);
153 |
154 | inputPickerButton.setOnClickListener(inputPickerClickListener);
155 | volumeUpButton.setOnClickListener(volumeChangedClickListener);
156 | volumeDownButton.setOnClickListener(volumeChangedClickListener);
157 | muteToggleButton.setOnClickListener(muteToggleClickListener);
158 | volumeSlider.setOnSeekBarChangeListener(volumeSeekListener);
159 |
160 | playButton.setOnClickListener(playClickListener);
161 | pauseButton.setOnClickListener(pauseClickListener);
162 | stopButton.setOnClickListener(stopClickListener);
163 | rewindButton.setOnClickListener(rewindClickListener);
164 | fastForwardButton.setOnClickListener(fastForwardClickListener);
165 | }
166 |
167 | private View.OnClickListener muteToggleClickListener = new View.OnClickListener() {
168 | @Override
169 | public void onClick(View view) {
170 | getVolumeControl().setMute(muteToggleButton.isChecked(), null);
171 | if(muteToggleButton.isChecked()) {
172 | testResponse = new TestResponseObject(true, TestResponseObject.SuccessCode, TestResponseObject.Muted_Media);
173 | } else if(!muteToggleButton.isChecked()){
174 | testResponse = new TestResponseObject(true, TestResponseObject.SuccessCode, TestResponseObject.UnMuted_Media);
175 | }
176 | }
177 | };
178 |
179 | private View.OnClickListener volumeChangedClickListener = new View.OnClickListener() {
180 |
181 | @Override
182 | public void onClick(View v) {
183 | switch (v.getId()) {
184 | case R.id.volumeDownButton:
185 | getVolumeControl().volumeDown(null);
186 | testResponse = new TestResponseObject(true, TestResponseObject.SuccessCode, TestResponseObject.VolumeDown);
187 | break;
188 | case R.id.volumeUpButton:
189 | getVolumeControl().volumeUp(null);
190 | testResponse = new TestResponseObject(true, TestResponseObject.SuccessCode, TestResponseObject.VolumeUp);
191 | break;
192 | }
193 | }
194 | };
195 |
196 | private View.OnClickListener inputPickerClickListener = new View.OnClickListener() {
197 |
198 | @Override
199 | public void onClick(View v) {
200 | if (inputPickerButton.isSelected()) {
201 | if (inputPickerSession != null) {
202 | inputPickerButton.setSelected(false);
203 | getExternalInputControl().closeInputPicker(inputPickerSession, null);
204 | }
205 | }
206 | else {
207 | inputPickerButton.setSelected(true);
208 | if (getExternalInputControl() != null) {
209 | getExternalInputControl().launchInputPicker(new Launcher.AppLaunchListener() {
210 |
211 | public void onError(ServiceCommandError error) { }
212 |
213 | public void onSuccess(LaunchSession object) {
214 | inputPickerSession = object;
215 | testResponse = new TestResponseObject(true, TestResponseObject.SuccessCode, TestResponseObject.InputPickerVisible);
216 | }
217 | });
218 | }
219 | }
220 | }
221 | };
222 |
223 | private ExternalInputListListener externalInputListener = new ExternalInputListListener() {
224 |
225 | @Override
226 | public void onSuccess(List externalInputList) {
227 | adapter.clear();
228 | for (int i = 0; i < externalInputList.size(); i++) {
229 | ExternalInputInfo input = externalInputList.get(i);
230 | final String deviceId = input.getId();
231 |
232 | adapter.add(deviceId);
233 | }
234 | }
235 |
236 | @Override
237 | public void onError(ServiceCommandError arg0) {
238 | }
239 | };
240 |
241 | private VolumeListener volumeListener = new VolumeListener() {
242 |
243 | public void onSuccess(Float volume) {
244 | volumeSlider.setProgress((int) (volume * 100));
245 | }
246 |
247 | @Override
248 | public void onError(ServiceCommandError error) {
249 | Log.d("LG", "Error subscribing to volume: " + error);
250 | }
251 | };
252 |
253 | private MuteListener muteListener = new MuteListener() {
254 |
255 | @Override
256 | public void onSuccess(Boolean object) {
257 | muteToggleButton.setChecked(object);
258 | }
259 |
260 | @Override
261 | public void onError(ServiceCommandError error) {
262 | Log.d("LG", "Error subscribing to mute: " + error);
263 | }
264 | };
265 |
266 | private SeekBar.OnSeekBarChangeListener volumeSeekListener = new SeekBar.OnSeekBarChangeListener() {
267 | @Override
268 | public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
269 | if (fromUser) {
270 | float fVol = (float)(progress / 100.0);
271 | getVolumeControl().setVolume(fVol, null);
272 | }
273 | }
274 |
275 | @Override public void onStartTrackingTouch(SeekBar seekBar) { }
276 | @Override public void onStopTrackingTouch(SeekBar seekBar) { }
277 | };
278 |
279 | private OnClickListener playClickListener = new OnClickListener() {
280 |
281 | @Override
282 | public void onClick(View v) {
283 | getMediaControl().play(null);
284 | }
285 | };
286 |
287 | private OnClickListener pauseClickListener = new OnClickListener() {
288 |
289 | @Override
290 | public void onClick(View v) {
291 | getMediaControl().pause(null);
292 | }
293 | };
294 |
295 | private OnClickListener stopClickListener = new OnClickListener() {
296 |
297 | @Override
298 | public void onClick(View v) {
299 | getMediaControl().stop(null);
300 | }
301 | };
302 |
303 | private OnClickListener rewindClickListener = new OnClickListener() {
304 |
305 | @Override
306 | public void onClick(View v) {
307 | getMediaControl().rewind(null);
308 | }
309 | };
310 |
311 | private OnClickListener fastForwardClickListener = new OnClickListener() {
312 |
313 | @Override
314 | public void onClick(View v) {
315 | getMediaControl().fastForward(null);
316 | }
317 | };
318 |
319 | @Override
320 | public void disableButtons() {
321 | adapter.clear();
322 | volumeSlider.setEnabled(false);
323 | volumeSlider.setOnSeekBarChangeListener(null);
324 |
325 | if (mVolumeSubscription != null)
326 | {
327 | mVolumeSubscription.unsubscribe();
328 | mVolumeSubscription = null;
329 | }
330 |
331 | if (mMuteSubscription != null) {
332 | mMuteSubscription.unsubscribe();
333 | mMuteSubscription = null;
334 | }
335 |
336 | super.disableButtons();
337 | }
338 | }
339 |
--------------------------------------------------------------------------------
/src/com/connectsdk/sampler/MainActivity.java:
--------------------------------------------------------------------------------
1 | //
2 | // Connect SDK Sample App by LG Electronics
3 | //
4 | // To the extent possible under law, the person who associated CC0 with
5 | // this sample app has waived all copyright and related or neighboring rights
6 | // to the sample app.
7 | //
8 | // You should have received a copy of the CC0 legalcode along with this
9 | // work. If not, see http://creativecommons.org/publicdomain/zero/1.0/.
10 | //
11 |
12 | package com.connectsdk.sampler;
13 |
14 | import android.app.AlertDialog;
15 | import android.content.Context;
16 | import android.content.DialogInterface;
17 | import android.os.Bundle;
18 | import android.os.Handler;
19 | import android.text.InputType;
20 | import android.util.Log;
21 | import android.view.Menu;
22 | import android.view.MenuItem;
23 | import android.view.View;
24 | import android.view.inputmethod.InputMethodManager;
25 | import android.widget.AdapterView;
26 | import android.widget.EditText;
27 | import android.widget.Toast;
28 |
29 | import androidx.appcompat.app.ActionBar;
30 | import androidx.appcompat.app.AppCompatActivity;
31 | import androidx.fragment.app.FragmentTransaction;
32 | import androidx.viewpager.widget.ViewPager;
33 |
34 | import com.connectsdk.device.ConnectableDevice;
35 | import com.connectsdk.device.ConnectableDeviceListener;
36 | import com.connectsdk.device.DevicePicker;
37 | import com.connectsdk.discovery.DiscoveryManager;
38 | import com.connectsdk.discovery.DiscoveryManager.PairingLevel;
39 | import com.connectsdk.discovery.DiscoveryProvider;
40 | import com.connectsdk.sampler.fragments.BaseFragment;
41 | import com.connectsdk.service.DeviceService;
42 | import com.connectsdk.service.DeviceService.PairingType;
43 | import com.connectsdk.service.capability.MediaPlayer;
44 | import com.connectsdk.service.command.ServiceCommandError;
45 |
46 | import java.util.ArrayList;
47 | import java.util.List;
48 |
49 | public class MainActivity extends AppCompatActivity implements ActionBar.TabListener {
50 |
51 | ConnectableDevice mTV;
52 | AlertDialog dialog;
53 | AlertDialog pairingAlertDialog;
54 | AlertDialog pairingCodeDialog;
55 | DevicePicker dp;
56 |
57 | MenuItem connectItem;
58 |
59 | SectionsPagerAdapter mSectionsPagerAdapter;
60 |
61 | private DiscoveryManager mDiscoveryManager;
62 |
63 | ViewPager mViewPager;
64 | ActionBar actionBar;
65 |
66 | private ConnectableDeviceListener deviceListener = new ConnectableDeviceListener() {
67 |
68 | @Override
69 | public void onPairingRequired(ConnectableDevice device, DeviceService service, PairingType pairingType) {
70 | Log.d("2ndScreenAPP", "Connected to " + mTV.getIpAddress());
71 |
72 | switch (pairingType) {
73 | case FIRST_SCREEN:
74 | Log.d("2ndScreenAPP", "First Screen");
75 | pairingAlertDialog.show();
76 | break;
77 |
78 | case PIN_CODE:
79 | case MIXED:
80 | Log.d("2ndScreenAPP", "Pin Code");
81 | pairingCodeDialog.show();
82 | break;
83 |
84 | case NONE:
85 | default:
86 | break;
87 | }
88 | }
89 |
90 | @Override
91 | public void onConnectionFailed(ConnectableDevice device, ServiceCommandError error) {
92 | Log.d("2ndScreenAPP", "onConnectFailed");
93 | connectFailed(mTV);
94 | }
95 |
96 | @Override
97 | public void onDeviceReady(ConnectableDevice device) {
98 | Log.d("2ndScreenAPP", "onPairingSuccess");
99 | if (pairingAlertDialog.isShowing()) {
100 | pairingAlertDialog.dismiss();
101 | }
102 | if (pairingCodeDialog.isShowing()) {
103 | pairingCodeDialog.dismiss();
104 | }
105 | registerSuccess(mTV);
106 | }
107 |
108 | @Override
109 | public void onDeviceDisconnected(ConnectableDevice device) {
110 | Log.d("2ndScreenAPP", "Device Disconnected");
111 | connectEnded(mTV);
112 | connectItem.setTitle("Connect");
113 |
114 | BaseFragment frag = mSectionsPagerAdapter.getFragment(mViewPager.getCurrentItem());
115 | if (frag != null) {
116 | Toast.makeText(getApplicationContext(), "Device Disconnected", Toast.LENGTH_SHORT).show();
117 | frag.disableButtons();
118 | }
119 | }
120 |
121 | @Override
122 | public void onCapabilityUpdated(ConnectableDevice device, List added, List removed) {
123 |
124 | }
125 | };
126 |
127 |
128 | @Override
129 | protected void onCreate(Bundle savedInstanceState) {
130 | super.onCreate(savedInstanceState);
131 |
132 | setContentView(R.layout.activity_main);
133 |
134 | actionBar = getSupportActionBar();
135 | actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
136 |
137 | mSectionsPagerAdapter = new SectionsPagerAdapter(this, getSupportFragmentManager());
138 |
139 | mViewPager = (ViewPager) findViewById(R.id.pager);
140 | mViewPager.setAdapter(mSectionsPagerAdapter);
141 |
142 | Handler handler = new Handler();
143 | handler.post(new Runnable() {
144 |
145 | @Override
146 | public void run() {
147 | mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
148 | @Override
149 | public void onPageSelected(int position) {
150 | actionBar.setSelectedNavigationItem(position);
151 | }
152 | });
153 |
154 | for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) {
155 | actionBar.addTab(actionBar.newTab()
156 | .setIcon(mSectionsPagerAdapter.getIcon(i))
157 | .setTabListener(MainActivity.this));
158 | }
159 | }
160 | });
161 |
162 | setupPicker();
163 |
164 | mDiscoveryManager = DiscoveryManager.getInstance();
165 | mDiscoveryManager.registerDefaultDeviceTypes();
166 | mDiscoveryManager.setPairingLevel(PairingLevel.ON);
167 |
168 | // To show all services in a device, a device item in DevicePickerList
169 | // mDiscoveryManager.setServiceIntegration(true);
170 |
171 | // To search devices with specific service types
172 | /*
173 | try {
174 | // AirPlay
175 | mDiscoveryManager.registerDeviceService((Class) Class.forName("com.connectsdk.service.AirPlayService"),
176 | (Class)Class.forName("com.connectsdk.discovery.provider.ZeroconfDiscoveryProvider"));
177 | // webOS SSAP (Simple Service Access Protocol)
178 | mDiscoveryManager.registerDeviceService((Class) Class.forName("com.connectsdk.service.WebOSTVService"),
179 | (Class)Class.forName("com.connectsdk.discovery.provider.SSDPDiscoveryProvider"));
180 | // DLNA
181 | mDiscoveryManager.registerDeviceService((Class) Class.forName("com.connectsdk.service.DLNAService"),
182 | (Class)Class.forName("com.connectsdk.discovery.provider.SSDPDiscoveryProvider"));
183 | } catch (ClassNotFoundException e) {
184 | e.printStackTrace();
185 | }
186 | */
187 |
188 | DiscoveryManager.getInstance().start();
189 | }
190 |
191 | public List getImageDevices() {
192 | List imageDevices = new ArrayList();
193 |
194 | for (ConnectableDevice device : DiscoveryManager.getInstance().getCompatibleDevices().values()) {
195 | if (device.hasCapability(MediaPlayer.Display_Image))
196 | imageDevices.add(device);
197 | }
198 |
199 | return imageDevices;
200 | }
201 |
202 | @Override
203 | protected void onDestroy() {
204 | super.onDestroy();
205 |
206 | if (dialog != null) {
207 | dialog.dismiss();
208 | }
209 |
210 | if (mTV != null) {
211 | mTV.disconnect();
212 | }
213 | }
214 |
215 | public void hConnectToggle()
216 | {
217 | if (!this.isFinishing()) {
218 | if (mTV != null)
219 | {
220 | if (mTV.isConnected())
221 | mTV.disconnect();
222 |
223 | connectItem.setTitle("Connect");
224 | mTV.removeListener(deviceListener);
225 | mTV = null;
226 | for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) {
227 | if (mSectionsPagerAdapter.getFragment(i) != null) {
228 | mSectionsPagerAdapter.getFragment(i).setTv(null);
229 | }
230 | }
231 | } else
232 | {
233 | dialog.show();
234 | }
235 | }
236 | }
237 |
238 | private void setupPicker() {
239 | dp = new DevicePicker(this);
240 | dialog = dp.getPickerDialog("Device List", new AdapterView.OnItemClickListener() {
241 |
242 | @Override
243 | public void onItemClick(AdapterView> arg0, View arg1, int arg2, long arg3) {
244 |
245 | mTV = (ConnectableDevice)arg0.getItemAtPosition(arg2);
246 | mTV.addListener(deviceListener);
247 | mTV.setPairingType(null);
248 | mTV.connect();
249 | connectItem.setTitle(mTV.getFriendlyName());
250 |
251 | dp.pickDevice(mTV);
252 | }
253 | });
254 |
255 | pairingAlertDialog = new AlertDialog.Builder(this)
256 | .setTitle("Pairing with TV")
257 | .setMessage("Please confirm the connection on your TV")
258 | .setPositiveButton("Okay", null)
259 | .setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
260 |
261 | @Override
262 | public void onClick(DialogInterface dialog, int which) {
263 | dp.cancelPicker();
264 |
265 | hConnectToggle();
266 | }
267 | })
268 | .create();
269 |
270 | final EditText input = new EditText(this);
271 | input.setInputType(InputType.TYPE_CLASS_TEXT);
272 |
273 | final InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
274 |
275 | pairingCodeDialog = new AlertDialog.Builder(this)
276 | .setTitle("Enter Pairing Code on TV")
277 | .setView(input)
278 | .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
279 |
280 | @Override
281 | public void onClick(DialogInterface arg0, int arg1) {
282 | if (mTV != null) {
283 | String value = input.getText().toString().trim();
284 | mTV.sendPairingKey(value);
285 | imm.hideSoftInputFromWindow(input.getWindowToken(), 0);
286 | }
287 | }
288 | })
289 | .setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
290 |
291 | @Override
292 | public void onClick(DialogInterface dialog, int whichButton) {
293 | dp.cancelPicker();
294 |
295 | hConnectToggle();
296 | imm.hideSoftInputFromWindow(input.getWindowToken(), 0);
297 | }
298 | })
299 | .create();
300 | }
301 |
302 | @Override
303 | protected void onResume() {
304 |
305 | super.onResume();
306 | }
307 |
308 | void registerSuccess(ConnectableDevice device) {
309 | Log.d("2ndScreenAPP", "successful register");
310 |
311 | BaseFragment frag = mSectionsPagerAdapter.getFragment(mViewPager.getCurrentItem());
312 | if (frag != null)
313 | frag.setTv(mTV);
314 | }
315 |
316 | void connectFailed(ConnectableDevice device) {
317 | if (device != null)
318 | Log.d("2ndScreenAPP", "Failed to connect to " + device.getIpAddress());
319 |
320 | if (mTV != null) {
321 | mTV.removeListener(deviceListener);
322 | mTV.disconnect();
323 | mTV = null;
324 | }
325 | }
326 |
327 | void connectEnded(ConnectableDevice device) {
328 | if (pairingAlertDialog.isShowing()) {
329 | pairingAlertDialog.dismiss();
330 | }
331 | if (pairingCodeDialog.isShowing()) {
332 | pairingCodeDialog.dismiss();
333 | }
334 |
335 | if (mTV.isConnecting == false) {
336 | mTV.removeListener(deviceListener);
337 | mTV = null;
338 | }
339 | }
340 |
341 | @Override
342 | public boolean onCreateOptionsMenu(Menu menu) {
343 | getMenuInflater().inflate(R.menu.main, menu);
344 | connectItem = menu.getItem(0);
345 |
346 | return super.onCreateOptionsMenu(menu);
347 | }
348 |
349 | @Override
350 | public boolean onOptionsItemSelected(MenuItem item) {
351 | switch (item.getItemId()) {
352 | case R.id.action_connect:
353 | hConnectToggle();
354 | return true;
355 | }
356 | return super.onOptionsItemSelected(item);
357 | }
358 |
359 | @Override public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) { }
360 | @Override public void onTabReselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) { }
361 |
362 | @Override
363 | public void onTabSelected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {
364 | mViewPager.setCurrentItem(tab.getPosition());
365 | setTitle(mSectionsPagerAdapter.getTitle(tab.getPosition()));
366 | BaseFragment frag = mSectionsPagerAdapter.getFragment(tab.getPosition());
367 | if (frag != null)
368 | frag.setTv(mTV);
369 | }
370 | }
371 |
--------------------------------------------------------------------------------
/src/com/connectsdk/sampler/fragments/AppsFragment.java:
--------------------------------------------------------------------------------
1 | //
2 | // Connect SDK Sample App by LG Electronics
3 | //
4 | // To the extent possible under law, the person who associated CC0 with
5 | // this sample app has waived all copyright and related or neighboring rights
6 | // to the sample app.
7 | //
8 | // You should have received a copy of the CC0 legalcode along with this
9 | // work. If not, see http://creativecommons.org/publicdomain/zero/1.0/.
10 | //
11 |
12 | package com.connectsdk.sampler.fragments;
13 |
14 | import java.util.List;
15 |
16 | import android.content.Context;
17 | import android.os.Bundle;
18 | import android.util.Log;
19 | import android.view.LayoutInflater;
20 | import android.view.View;
21 | import android.view.View.OnClickListener;
22 | import android.view.ViewGroup;
23 | import android.widget.AdapterView;
24 | import android.widget.AdapterView.OnItemClickListener;
25 | import android.widget.Button;
26 | import android.widget.ListView;
27 |
28 | import com.connectsdk.core.AppInfo;
29 | import com.connectsdk.sampler.R;
30 | import com.connectsdk.sampler.util.TestResponseObject;
31 | import com.connectsdk.sampler.widget.AppAdapter;
32 | import com.connectsdk.service.capability.Launcher;
33 | import com.connectsdk.service.capability.Launcher.AppInfoListener;
34 | import com.connectsdk.service.capability.Launcher.AppLaunchListener;
35 | import com.connectsdk.service.capability.Launcher.AppListListener;
36 | import com.connectsdk.service.capability.ToastControl;
37 | import com.connectsdk.service.capability.listeners.ResponseListener;
38 | import com.connectsdk.service.command.ServiceCommandError;
39 | import com.connectsdk.service.command.ServiceSubscription;
40 | import com.connectsdk.service.sessions.LaunchSession;
41 |
42 | public class AppsFragment extends BaseFragment {
43 | // public Button smartWorldButton;
44 | public Button browserButton;
45 | public Button myAppButton;
46 | public Button netflixButton;
47 | public Button appStoreButton;
48 | public Button youtubeButton;
49 | public Button toastButton;
50 |
51 | public ListView appListView;
52 | public AppAdapter adapter;
53 | LaunchSession runningAppSession;
54 | LaunchSession appStoreSession;
55 | LaunchSession myAppSession;
56 | public TestResponseObject testResponse;
57 |
58 | ServiceSubscription runningAppSubs;
59 |
60 | public AppsFragment() {
61 | testResponse = new TestResponseObject();
62 |
63 | };
64 |
65 | public AppsFragment(Context context)
66 | {
67 | super(context);
68 | testResponse = new TestResponseObject();
69 | }
70 |
71 | @Override
72 | public View onCreateView(LayoutInflater inflater, ViewGroup container,
73 | Bundle savedInstanceState) {
74 | View rootView = inflater.inflate(
75 | R.layout.fragment_apps, container, false);
76 |
77 | browserButton = (Button) rootView.findViewById(R.id.browserButton);
78 | myAppButton = (Button) rootView.findViewById(R.id.myApp);
79 | netflixButton = (Button) rootView.findViewById(R.id.deepLinkButton);
80 | appStoreButton = (Button) rootView.findViewById(R.id.appStoreButton);
81 | youtubeButton = (Button) rootView.findViewById(R.id.youtubeButton);
82 | toastButton = (Button) rootView.findViewById(R.id.toastButton);
83 |
84 | appListView = (ListView) rootView.findViewById(R.id.appListView);
85 | adapter = new AppAdapter(getContext(), R.layout.app_item);
86 | appListView.setAdapter(adapter);
87 |
88 | buttons = new Button[] {
89 | browserButton,
90 | netflixButton,
91 | youtubeButton,
92 | toastButton,
93 | myAppButton,
94 | appStoreButton
95 | };
96 |
97 | return rootView;
98 | }
99 |
100 | @Override
101 | public void enableButtons()
102 | {
103 | super.enableButtons();
104 |
105 | if (getTv().hasCapability(Launcher.Browser)
106 | || getTv().hasCapability(Launcher.Browser_Params))
107 | {
108 | browserButton.setOnClickListener(new View.OnClickListener() {
109 | @Override
110 | public void onClick(View view) {
111 | if (browserButton.isSelected()) {
112 | browserButton.setSelected(false);
113 | if (runningAppSession != null) {
114 | runningAppSession.close(null);
115 | }
116 | }
117 | else {
118 | browserButton.setSelected(true);
119 |
120 | getLauncher().launchBrowser("http://connectsdk.com/", new Launcher.AppLaunchListener() {
121 |
122 | public void onSuccess(LaunchSession session) {
123 | setRunningAppInfo(session);
124 | testResponse = new TestResponseObject(true, TestResponseObject.SuccessCode, TestResponseObject.Launched_Browser);
125 | }
126 |
127 | public void onError(ServiceCommandError error) {
128 | }
129 | });
130 | }
131 | }
132 | });
133 | }
134 | else {
135 | disableButton(browserButton);
136 | }
137 |
138 | if (getTv().hasCapability(ToastControl.Show_Toast)) {
139 | toastButton.setOnClickListener(new OnClickListener() {
140 |
141 | @Override
142 | public void onClick(View v) {
143 | getToastControl().showToast("Yeah, toast!", getToastIconData(), "png", null);
144 | testResponse = new TestResponseObject(true, TestResponseObject.SuccessCode, TestResponseObject.Show_Toast);
145 | }
146 | });
147 | }
148 | else {
149 | disableButton(toastButton);
150 | }
151 |
152 | if (getTv().hasCapability(Launcher.Netflix)
153 | || getTv().hasCapability(Launcher.Netflix_Params))
154 | {
155 | netflixButton.setOnClickListener(new View.OnClickListener() {
156 | @Override
157 | public void onClick(View view) {
158 | if (netflixButton.isSelected()) {
159 | netflixButton.setSelected(false);
160 | if (runningAppSession != null) {
161 | runningAppSession.close(null);
162 | }
163 | }
164 | else {
165 | netflixButton.setSelected(true);
166 | getLauncher().launchNetflix("70217913", new Launcher.AppLaunchListener() {
167 |
168 | @Override
169 | public void onSuccess(LaunchSession session) {
170 | setRunningAppInfo(session);
171 | testResponse = new TestResponseObject(true, TestResponseObject.SuccessCode, TestResponseObject.Launched_Netflix);
172 | }
173 |
174 | @Override
175 | public void onError(ServiceCommandError error) {
176 | }
177 | });
178 | }
179 | }
180 | });
181 | }
182 | else {
183 | disableButton(netflixButton);
184 | }
185 |
186 | if (getTv().hasCapability(Launcher.YouTube) ||
187 | getTv().hasCapability(Launcher.YouTube_Params)) {
188 | youtubeButton.setOnClickListener(new View.OnClickListener() {
189 | @Override
190 | public void onClick(View view) {
191 | if (youtubeButton.isSelected()) {
192 | youtubeButton.setSelected(false);
193 | if (runningAppSession != null) {
194 | runningAppSession.close(null);
195 | }
196 | }
197 | else {
198 | youtubeButton.setSelected(true);
199 | getLauncher().launchYouTube("eRsGyueVLvQ", new Launcher.AppLaunchListener() {
200 |
201 | @Override
202 | public void onSuccess(LaunchSession session) {
203 | setRunningAppInfo(session);
204 | testResponse = new TestResponseObject(true, TestResponseObject.SuccessCode, TestResponseObject.Launched_Youtube);
205 | }
206 |
207 | @Override
208 | public void onError(ServiceCommandError error) {
209 | }
210 | });
211 | }
212 | }
213 | });
214 | }
215 | else {
216 | disableButton(youtubeButton);
217 | }
218 |
219 | browserButton.setSelected(false);
220 | netflixButton.setSelected(false);
221 | youtubeButton.setSelected(false);
222 |
223 | if (getTv().hasCapability(Launcher.RunningApp_Subscribe)) {
224 | runningAppSubs = getLauncher().subscribeRunningApp(new AppInfoListener() {
225 |
226 | @Override
227 | public void onSuccess(AppInfo appInfo) {
228 | adapter.setRunningAppId(appInfo.getId());
229 | adapter.notifyDataSetChanged();
230 |
231 | int position = adapter.getPosition(appInfo);
232 | appListView.setSelection(position);
233 | }
234 |
235 | @Override
236 | public void onError(ServiceCommandError error) {
237 |
238 | }
239 | });
240 | }
241 |
242 | if (getTv().hasCapability(Launcher.Application_List)) {
243 | getLauncher().getAppList(new AppListListener() {
244 |
245 | @Override
246 | public void onSuccess(List appList) {
247 | adapter.clear();
248 | for (int i = 0; i < appList.size(); i++) {
249 | final AppInfo app = appList.get(i);
250 |
251 | adapter.add(app);
252 | }
253 |
254 | adapter.sort();
255 | }
256 |
257 | @Override public void onError(ServiceCommandError error) { }
258 | });
259 | }
260 |
261 | appListView.setOnItemClickListener(new OnItemClickListener() {
262 |
263 | @Override
264 | public void onItemClick(AdapterView> arg0, View arg1, int arg2, long arg3) {
265 | if (runningAppSession != null) {
266 | runningAppSession.close(null);
267 | }
268 | AppInfo appInfo = (AppInfo) arg0.getItemAtPosition(arg2);
269 |
270 | getLauncher().launchAppWithInfo(appInfo, null, new Launcher.AppLaunchListener() {
271 |
272 | @Override
273 | public void onSuccess(LaunchSession session) {
274 | setRunningAppInfo(session);
275 | }
276 |
277 | @Override
278 | public void onError(ServiceCommandError error) {
279 | }
280 | });
281 | }
282 | });
283 |
284 | if (getTv().hasCapability(Launcher.Browser)) {
285 | if (getTv().hasCapability(Launcher.Browser_Params)) {
286 | browserButton.setText("Open Google");
287 | }
288 | else {
289 | browserButton.setText("Open Browser");
290 | }
291 | }
292 |
293 | myAppButton.setEnabled(getTv().hasCapability("Launcher.Levak"));
294 | myAppButton.setOnClickListener(myAppLaunch);
295 |
296 | appStoreButton.setEnabled(getTv().hasCapability(Launcher.AppStore_Params));
297 | appStoreButton.setOnClickListener(launchAppStore);
298 | }
299 |
300 | public View.OnClickListener myAppLaunch = new View.OnClickListener() {
301 |
302 | @Override
303 | public void onClick(View v) {
304 | if (myAppSession != null) {
305 | myAppSession.close(null);
306 |
307 | myAppSession = null;
308 | myAppButton.setSelected(false);
309 | } else {
310 | getLauncher().launchApp("Levak", new AppLaunchListener() {
311 |
312 | @Override
313 | public void onError(ServiceCommandError error) {
314 | Log.d("LG", "My app failed: " + error);
315 | }
316 |
317 | @Override
318 | public void onSuccess(LaunchSession object) {
319 | myAppSession = object;
320 | myAppButton.setSelected(true);
321 | }
322 | });
323 | }
324 | }
325 | };
326 |
327 | public View.OnClickListener launchAppStore = new View.OnClickListener() {
328 |
329 | @Override
330 | public void onClick(View v) {
331 | if (appStoreSession != null) {
332 | appStoreSession.close(new ResponseListener