Commit 82d0f0eea44d74e54333ff8876b0ebff261ad047
Committed by
JIYUN YANG
1 parent
2cb8dafa
Add WebView example
Change-Id: I15cf79251793eaffb2e54a750528acfb9b3bc95e Signed-off-by: Jiyun Yang <ji.yang@samsung.com>
Showing
6 changed files
with
152 additions
and
0 deletions
com.samsung.dali-demo.xml
| @@ -272,6 +272,9 @@ | @@ -272,6 +272,9 @@ | ||
| 272 | <ui-application appid="pre-render-callback.example" exec="/usr/apps/com.samsung.dali-demo/bin/pre-render-callback.example" nodisplay="true" multiple="false" type="c++app" taskmanage="true"> | 272 | <ui-application appid="pre-render-callback.example" exec="/usr/apps/com.samsung.dali-demo/bin/pre-render-callback.example" nodisplay="true" multiple="false" type="c++app" taskmanage="true"> |
| 273 | <label>Frame Callback</label> | 273 | <label>Frame Callback</label> |
| 274 | </ui-application> | 274 | </ui-application> |
| 275 | + <ui-application appid="web-view.example" exec="/usr/apps/com.samsung.dali-demo/bin/web-view.example" nodisplay="true" multiple="false" type="c++app" taskmanage="true"> | ||
| 276 | + <label>Web View</label> | ||
| 277 | + </ui-application> | ||
| 275 | 278 | ||
| 276 | <privileges> | 279 | <privileges> |
| 277 | <privilege>http://tizen.org/privilege/mediastorage</privilege> | 280 | <privilege>http://tizen.org/privilege/mediastorage</privilege> |
examples-reel/dali-examples-reel.cpp
| @@ -89,6 +89,7 @@ int DALI_EXPORT_API main(int argc, char **argv) | @@ -89,6 +89,7 @@ int DALI_EXPORT_API main(int argc, char **argv) | ||
| 89 | demo.AddExample(Example("tilt.example", DALI_DEMO_STR_TITLE_TILT_SENSOR)); | 89 | demo.AddExample(Example("tilt.example", DALI_DEMO_STR_TITLE_TILT_SENSOR)); |
| 90 | demo.AddExample(Example("tooltip.example", DALI_DEMO_STR_TITLE_TOOLTIP)); | 90 | demo.AddExample(Example("tooltip.example", DALI_DEMO_STR_TITLE_TOOLTIP)); |
| 91 | demo.AddExample(Example("transitions.example", DALI_DEMO_STR_TITLE_VISUAL_TRANSITIONS)); | 91 | demo.AddExample(Example("transitions.example", DALI_DEMO_STR_TITLE_VISUAL_TRANSITIONS)); |
| 92 | + demo.AddExample(Example("web-view.example", DALI_DEMO_STR_TITLE_WEB_VIEW)); | ||
| 92 | 93 | ||
| 93 | demo.SortAlphabetically( true ); | 94 | demo.SortAlphabetically( true ); |
| 94 | 95 |
examples/web-view/web-view-example.cpp
0 → 100644
| 1 | +/* | ||
| 2 | + * Copyright (c) 2018 Samsung Electronics Co., Ltd. | ||
| 3 | + * | ||
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | + * you may not use this file except in compliance with the License. | ||
| 6 | + * You may obtain a copy of the License at | ||
| 7 | + * | ||
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | + * | ||
| 10 | + * Unless required by applicable law or agreed to in writing, software | ||
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | + * See the License for the specific language governing permissions and | ||
| 14 | + * limitations under the License. | ||
| 15 | + * | ||
| 16 | + */ | ||
| 17 | + | ||
| 18 | +#include <dali-toolkit/dali-toolkit.h> | ||
| 19 | +#include "dali-toolkit/devel-api/controls/web-view/web-view.h" | ||
| 20 | +#include <dali/integration-api/debug.h> | ||
| 21 | +#include <unistd.h> | ||
| 22 | + | ||
| 23 | +using namespace Dali; | ||
| 24 | + | ||
| 25 | +namespace{ | ||
| 26 | + | ||
| 27 | +} | ||
| 28 | + | ||
| 29 | +class WebViewController : public ConnectionTracker | ||
| 30 | +{ | ||
| 31 | +public: | ||
| 32 | + | ||
| 33 | + WebViewController( Application& application ) | ||
| 34 | + : mApplication( application ) | ||
| 35 | + , mUrlPointer( 0 ) | ||
| 36 | + { | ||
| 37 | + // Connect to the Application's Init signal | ||
| 38 | + mApplication.InitSignal().Connect( this, &WebViewController::Create ); | ||
| 39 | + } | ||
| 40 | + | ||
| 41 | + ~WebViewController() | ||
| 42 | + { | ||
| 43 | + // Nothing to do here; | ||
| 44 | + } | ||
| 45 | + | ||
| 46 | + const char* GetNextUrl() | ||
| 47 | + { | ||
| 48 | + static const unsigned int kUrlSize = 3; | ||
| 49 | + static const char* kUrls[kUrlSize] = { | ||
| 50 | + "https://webkit.org/blog-files/3d-transforms/poster-circle.html", | ||
| 51 | + "https://www.amazon.com", | ||
| 52 | + "https://www.google.com" | ||
| 53 | + }; | ||
| 54 | + mUrlPointer %= kUrlSize; | ||
| 55 | + return kUrls[mUrlPointer++]; | ||
| 56 | + } | ||
| 57 | + | ||
| 58 | + // The Init signal is received once (only) during the Application lifetime | ||
| 59 | + void Create( Application& application ) | ||
| 60 | + { | ||
| 61 | + // Get a handle to the stage | ||
| 62 | + Stage stage = Stage::GetCurrent(); | ||
| 63 | + stage.SetBackgroundColor( Vector4(0.2, 0.6, 1, 1) ); | ||
| 64 | + | ||
| 65 | + float width = stage.GetSize().width; | ||
| 66 | + float height = stage.GetSize().height; | ||
| 67 | + float fontSize = width * 0.02f; | ||
| 68 | + | ||
| 69 | + mWebView = Toolkit::WebView::New( "ko-KR", "Asia/Seoul" ); | ||
| 70 | + mWebView.SetParentOrigin( Dali::ParentOrigin::CENTER ); | ||
| 71 | + mWebView.SetAnchorPoint( Dali::AnchorPoint::CENTER ); | ||
| 72 | + mWebView.SetPosition( 0, 0 ); | ||
| 73 | + mWebView.SetSize( width, height ); | ||
| 74 | + mWebView.PageLoadStartedSignal().Connect( this, &WebViewController::OnPageLoadStarted ); | ||
| 75 | + mWebView.PageLoadFinishedSignal().Connect( this, &WebViewController::OnPageLoadFinished ); | ||
| 76 | + | ||
| 77 | + std::string url = GetNextUrl(); | ||
| 78 | + mWebView.LoadUrl( url ); | ||
| 79 | + stage.Add(mWebView); | ||
| 80 | + | ||
| 81 | + mAddressLabel = Toolkit::TextLabel::New( url ); | ||
| 82 | + mAddressLabel.SetAnchorPoint( AnchorPoint::TOP_LEFT ); | ||
| 83 | + mAddressLabel.SetProperty( Toolkit::TextLabel::Property::POINT_SIZE, fontSize ); | ||
| 84 | + mAddressLabel.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE ); | ||
| 85 | + mAddressLabel.SetBackgroundColor( Vector4( 0, 0, 0, 0.5f ) ); | ||
| 86 | + mAddressLabel.TouchedSignal().Connect( this, &WebViewController::OnTouchText ); | ||
| 87 | + stage.Add( mAddressLabel ); | ||
| 88 | + | ||
| 89 | + // Respond to key events | ||
| 90 | + stage.KeyEventSignal().Connect( this, &WebViewController::OnKeyEvent ); | ||
| 91 | + Toolkit::KeyboardFocusManager::Get().SetCurrentFocusActor( mWebView ); | ||
| 92 | + } | ||
| 93 | + | ||
| 94 | + void OnPageLoadStarted( Toolkit::WebView view, const std::string& url ) | ||
| 95 | + { | ||
| 96 | + mAddressLabel.SetProperty( Toolkit::TextLabel::Property::TEXT, "Loading" ); | ||
| 97 | + } | ||
| 98 | + | ||
| 99 | + void OnPageLoadFinished( Toolkit::WebView view, const std::string& url ) | ||
| 100 | + { | ||
| 101 | + mAddressLabel.SetProperty( Toolkit::TextLabel::Property::TEXT, url.c_str() ); | ||
| 102 | + } | ||
| 103 | + | ||
| 104 | + bool OnTouchText( Actor actor, const TouchEvent& event ) | ||
| 105 | + { | ||
| 106 | + if ( event.GetPoint( 0 ).state == TouchPoint::Up ) | ||
| 107 | + { | ||
| 108 | + std::string url = GetNextUrl(); | ||
| 109 | + mAddressLabel.SetProperty(Toolkit::TextLabel::Property::TEXT, "Waiting" ); | ||
| 110 | + mWebView.LoadUrl( url ); | ||
| 111 | + } | ||
| 112 | + | ||
| 113 | + return true; | ||
| 114 | + } | ||
| 115 | + | ||
| 116 | + void OnKeyEvent( const KeyEvent& event ) | ||
| 117 | + { | ||
| 118 | + if( event.state == KeyEvent::Down ) | ||
| 119 | + { | ||
| 120 | + if ( IsKey( event, Dali::DALI_KEY_ESCAPE ) || IsKey( event, Dali::DALI_KEY_BACK ) ) | ||
| 121 | + { | ||
| 122 | + mApplication.Quit(); | ||
| 123 | + } | ||
| 124 | + } | ||
| 125 | + } | ||
| 126 | + | ||
| 127 | +private: | ||
| 128 | + Application& mApplication; | ||
| 129 | + Toolkit::WebView mWebView; | ||
| 130 | + Toolkit::TextLabel mAddressLabel; | ||
| 131 | + unsigned int mUrlPointer; | ||
| 132 | +}; | ||
| 133 | + | ||
| 134 | +int DALI_EXPORT_API main( int argc, char **argv ) | ||
| 135 | +{ | ||
| 136 | + Application application = Application::New( &argc, &argv ); | ||
| 137 | + WebViewController test( application ); | ||
| 138 | + application.MainLoop(); | ||
| 139 | + return 0; | ||
| 140 | +} |
resources/po/en_GB.po
resources/po/en_US.po
shared/dali-demo-strings.h
| @@ -114,6 +114,7 @@ extern "C" | @@ -114,6 +114,7 @@ extern "C" | ||
| 114 | #define DALI_DEMO_STR_TITLE_TILT_SENSOR dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_TILT_SENSOR") | 114 | #define DALI_DEMO_STR_TITLE_TILT_SENSOR dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_TILT_SENSOR") |
| 115 | #define DALI_DEMO_STR_TITLE_TOOLTIP dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_TOOLTIP") | 115 | #define DALI_DEMO_STR_TITLE_TOOLTIP dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_TOOLTIP") |
| 116 | #define DALI_DEMO_STR_TITLE_VISUAL_TRANSITIONS dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_VISUAL_TRANSITIONS") | 116 | #define DALI_DEMO_STR_TITLE_VISUAL_TRANSITIONS dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_VISUAL_TRANSITIONS") |
| 117 | +#define DALI_DEMO_STR_TITLE_WEB_VIEW dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_WEB_VIEW") | ||
| 117 | 118 | ||
| 118 | #else // !INTERNATIONALIZATION_ENABLED | 119 | #else // !INTERNATIONALIZATION_ENABLED |
| 119 | 120 | ||
| @@ -199,6 +200,7 @@ extern "C" | @@ -199,6 +200,7 @@ extern "C" | ||
| 199 | #define DALI_DEMO_STR_TITLE_TILT_SENSOR "Tilt Sensor" | 200 | #define DALI_DEMO_STR_TITLE_TILT_SENSOR "Tilt Sensor" |
| 200 | #define DALI_DEMO_STR_TITLE_TOOLTIP "Tooltip" | 201 | #define DALI_DEMO_STR_TITLE_TOOLTIP "Tooltip" |
| 201 | #define DALI_DEMO_STR_TITLE_VISUAL_TRANSITIONS "Visual Transitions" | 202 | #define DALI_DEMO_STR_TITLE_VISUAL_TRANSITIONS "Visual Transitions" |
| 203 | +#define DALI_DEMO_STR_TITLE_WEB_VIEW "Web View" | ||
| 202 | #endif | 204 | #endif |
| 203 | 205 | ||
| 204 | #ifdef __cplusplus | 206 | #ifdef __cplusplus |