Update progress bar example
[platform/core/uifw/dali-demo.git] / examples / progress-bar / progress-bar-example.cpp
index aca1a53..f12fd28 100644 (file)
@@ -53,6 +53,8 @@ public:
   {
     // Connect to the Application's Init signal
     mProgressValue = 0.0f;
+    mSecondaryProgressValue = 0.1f;
+    isDefaultTheme = true;
     mApplication.InitSignal().Connect( this, &ProgressBarExample::Create );
   }
 
@@ -80,20 +82,7 @@ private:
     mProgressBarDefault.SetAnchorPoint(AnchorPoint::TOP_CENTER);
     mProgressBarDefault.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH);
     mProgressBarDefault.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT);
-
-    mProgressBarCustomStyle1 = ProgressBar::New();
-    mProgressBarCustomStyle1.SetStyleName( "ProgressBarCustomStyle1" );
-    mProgressBarCustomStyle1.SetParentOrigin(ParentOrigin::TOP_CENTER);
-    mProgressBarCustomStyle1.SetAnchorPoint(AnchorPoint::TOP_CENTER);
-    mProgressBarCustomStyle1.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH);
-    mProgressBarCustomStyle1.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT);
-
-    mProgressBarCustomStyle2 = ProgressBar::New();
-    mProgressBarCustomStyle2.SetStyleName( "ProgressBarCustomStyle2" );
-    mProgressBarCustomStyle2.SetParentOrigin(ParentOrigin::TOP_CENTER);
-    mProgressBarCustomStyle2.SetAnchorPoint(AnchorPoint::TOP_CENTER);
-    mProgressBarCustomStyle2.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH);
-    mProgressBarCustomStyle2.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT);
+    mProgressBarDefault.ValueChangedSignal().Connect( this, &ProgressBarExample::OnValueChanged );
 
     Toolkit::TableView contentTable = Toolkit::TableView::New(2, 1);
     contentTable.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH);
@@ -111,7 +100,7 @@ private:
     mContentLayer.Add( contentTable );
 
     // Image selector for progress bar
-    Toolkit::TableView progressBackground = Toolkit::TableView::New( 3, 1 );
+    Toolkit::TableView progressBackground = Toolkit::TableView::New( 1, 1 );
     progressBackground.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
     progressBackground.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT );
     progressBackground.SetBackgroundColor( BACKGROUND_COLOUR );
@@ -125,11 +114,9 @@ private:
 
     contentTable.Add( progressBackground );
     progressBackground.Add( mProgressBarDefault );
-    progressBackground.Add( mProgressBarCustomStyle1 );
-    progressBackground.Add( mProgressBarCustomStyle2 );
 
     // Create buttons
-    Toolkit::TableView buttonBackground = Toolkit::TableView::New( 1, 1 );
+    Toolkit::TableView buttonBackground = Toolkit::TableView::New( 3, 1 );
     buttonBackground.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
     buttonBackground.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT );
     buttonBackground.SetBackgroundColor( BACKGROUND_COLOUR );
@@ -150,6 +137,22 @@ private:
 
     buttonBackground.Add( mResetProgressButton );
 
+    mSetIndeterminateButton = Toolkit::PushButton::New();
+    mSetIndeterminateButton.SetProperty( Toolkit::Button::Property::LABEL, "Toggle Indeterminate" );
+    mSetIndeterminateButton.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
+    mSetIndeterminateButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT );
+    mSetIndeterminateButton.ClickedSignal().Connect( this, &ProgressBarExample::OnSetIndeterminateButtonSelected );
+
+    buttonBackground.Add( mSetIndeterminateButton );
+
+    mChangeThemeButton = Toolkit::PushButton::New();
+    mChangeThemeButton.SetProperty( Toolkit::Button::Property::LABEL, "Change Theme" );
+    mChangeThemeButton.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
+    mChangeThemeButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT );
+    mChangeThemeButton.ClickedSignal().Connect( this, &ProgressBarExample::OnChangeThemeButtonSelected );
+
+    buttonBackground.Add( mChangeThemeButton );
+
     // Create a timer to update the progress of all progress bars
     mTimer = Timer::New( TIMER_TIMEOUT_TIME );
     mTimer.TickSignal().Connect( this, &ProgressBarExample::OnTimerTick );
@@ -159,9 +162,9 @@ private:
   bool OnTimerTick()
   {
     mProgressValue += PROGRESS_INCREMENT_VALUE;
+    mSecondaryProgressValue = mProgressValue + 0.1f;
     mProgressBarDefault.SetProperty(ProgressBar::Property::PROGRESS_VALUE, mProgressValue);
-    mProgressBarCustomStyle1.SetProperty(ProgressBar::Property::PROGRESS_VALUE, mProgressValue);
-    mProgressBarCustomStyle2.SetProperty(ProgressBar::Property::PROGRESS_VALUE, mProgressValue);
+    mProgressBarDefault.SetProperty(ProgressBar::Property::SECONDARY_PROGRESS_VALUE, mSecondaryProgressValue);
 
     return ( mProgressValue < 1.0f ); // Only call again if progress has NOT got to the end
   }
@@ -169,13 +172,51 @@ private:
   bool OnResetProgressButtonSelected( Toolkit::Button button )
   {
     mProgressValue = 0.0f;
+    mSecondaryProgressValue = 0.1f;
     mProgressBarDefault.SetProperty(ProgressBar::Property::PROGRESS_VALUE, 0.0f);
-    mProgressBarCustomStyle1.SetProperty(ProgressBar::Property::PROGRESS_VALUE, 0.0f);
-    mProgressBarCustomStyle2.SetProperty(ProgressBar::Property::PROGRESS_VALUE, 0.0f);
+    mProgressBarDefault.SetProperty(ProgressBar::Property::SECONDARY_PROGRESS_VALUE, 0.1f);
     mTimer.Start();
     return true;
   }
 
+  void OnValueChanged( ProgressBar progressBar, float value, float secondaryValue )
+  {
+    std::stringstream newLabel;
+    newLabel.precision( 2 );
+    newLabel << std::fixed << "current : " << value << " / loaded : "  << secondaryValue;
+
+    mProgressBarDefault.SetProperty(ProgressBar::Property::LABEL_VISUAL, newLabel.str() );
+  }
+
+  bool OnSetIndeterminateButtonSelected( Toolkit::Button button )
+  {
+    if( mProgressBarDefault.GetProperty<bool>(ProgressBar::Property::INDETERMINATE))
+    {
+      mProgressBarDefault.SetProperty(ProgressBar::Property::INDETERMINATE, false);
+    }
+    else
+    {
+      mProgressBarDefault.SetProperty(ProgressBar::Property::INDETERMINATE, true);
+    }
+    return true;
+  }
+
+  bool OnChangeThemeButtonSelected( Toolkit::Button button )
+  {
+    StyleManager styleManager = StyleManager::Get();
+
+    if( isDefaultTheme )
+    {
+      styleManager.ApplyTheme( THEME_PATH );
+      isDefaultTheme = false;
+    }
+    else
+    {
+      styleManager.ApplyDefaultTheme();
+      isDefaultTheme = true;
+    }
+    return true;
+  }
   void OnKeyEvent( const KeyEvent& event )
   {
     if( event.state == KeyEvent::Down )
@@ -196,15 +237,17 @@ private:
   Toolkit::ToolBar  mToolBar;                           ///< The View's Toolbar.
   Layer             mContentLayer;                      ///< Content layer.
   ProgressBar       mProgressBarDefault;
-  ProgressBar       mProgressBarCustomStyle1;
-  ProgressBar       mProgressBarCustomStyle2;
   Toolkit::PushButton mResetProgressButton;
+  Toolkit::PushButton mSetIndeterminateButton;
+  Toolkit::PushButton mChangeThemeButton;
   float mProgressValue;
+  float mSecondaryProgressValue;
+  bool isDefaultTheme;
 };
 
 int DALI_EXPORT_API main( int argc, char **argv )
 {
-  Application application = Application::New( &argc, &argv, THEME_PATH );
+  Application application = Application::New( &argc, &argv );
   ProgressBarExample test( application );
   application.MainLoop();
   return 0;