📄 s60internetradioview.cpp
字号:
/*
* ==============================================================================
* Name : S60InternetRadioView.cpp
* Part of : S60 Internet Radio Application
* Interface :
* Description : Implementation of the S60 Internet Radio Application view class
* Version : 1
*
* Copyright (c) 2006, Nokia Corporation All rights reserved. Redistribution
* and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met: Redistributions
* of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer. Redistributions in binary form
* must reproduce the above copyright notice, this list of conditions and the
* following disclaimer in the documentation and/or other materials provided
* with the distribution. Neither the name of the Nokia Corporation nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission. THIS
* SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
* ==============================================================================
*/
// INCLUDE FILES
#include <eikenv.h>
#include <eikdef.h>
#include <eiklabel.h>
#include <gulcolor.h>
#include <eikspane.h>
#include <aknnavi.h>
#include <aknnavide.h>
#include <AknUtils.h>
#include <MAudioadapter.h>
#include <S60InternetRadio.hrh>
#include "S60InternetRadio.pan"
#include "S60InternetRadioView.h"
#include "S60InternetRadioAppUi.h"
const TInt KVolumeLevelMax = 10;
// -----------------------------------------------------------------------------
// CS60InternetRadioView::NewL
// -----------------------------------------------------------------------------
//
CS60InternetRadioView* CS60InternetRadioView::NewL(
const TRect& aRect,
const TDesC& aMessage,
const TInt supportMetadata )
{
CS60InternetRadioView* self = CS60InternetRadioView::NewLC(aRect, aMessage, supportMetadata);
CleanupStack::Pop(self);
return self;
}
// -----------------------------------------------------------------------------
// CS60InternetRadioView::NewLC
// -----------------------------------------------------------------------------
//
CS60InternetRadioView* CS60InternetRadioView::NewLC(
const TRect& aRect,
const TDesC& aMessage,
const TInt supportMetadata )
{
CS60InternetRadioView* self = new (ELeave) CS60InternetRadioView();
CleanupStack::PushL(self);
self->ConstructL(aRect, aMessage, supportMetadata);
return self;
}
// -----------------------------------------------------------------------------
// CS60InternetRadioView::ConstructL
// -----------------------------------------------------------------------------
//
void CS60InternetRadioView::ConstructL(
const TRect& aRect,
const TDesC& aMessage,
const TInt supportMetadata )
{
// Create a window for this application view
CreateWindowL();
iBrushStyle = CGraphicsContext::ESolidBrush;
iBrushColor = iEikonEnv->ControlColor(EColorWindowBackground, *this);
//metadata
ResetLabelsL(aMessage, supportMetadata);
// Set the windows size
SetRect(aRect);
iNaviPane = static_cast<CAknNavigationControlContainer*>( CEikStatusPaneBase::Current()->ControlL( TUid::Uid( EEikStatusPaneUidNavi)));
iVolumeNavi = iNaviPane->CreateVolumeIndicatorL( R_AVKON_NAVI_PANE_VOLUME_INDICATOR );
// Activate the window, which makes it ready to be drawn
ActivateL();
}
// -----------------------------------------------------------------------------
// CS60InternetRadioView::~CS60InternetRadioView
// -----------------------------------------------------------------------------
//
CS60InternetRadioView::~CS60InternetRadioView()
{
delete iVolumeNavi;iVolumeNavi=NULL;
iMetadataLabels.ResetAndDestroy();
delete iAlarm;iAlarm=NULL;
}
// -----------------------------------------------------------------------------
// CS60InternetRadioView::CS60InternetRadioView
// -----------------------------------------------------------------------------
//
CS60InternetRadioView::CS60InternetRadioView()
: iMetadataLabels(5),
iCallback(&MoveLabel,this)
{
// No implementation required
}
// -----------------------------------------------------------------------------
// CS60InternetRadioView::Draw
// -----------------------------------------------------------------------------
//
void CS60InternetRadioView::Draw(
const TRect& /*aRect*/ ) const
{
CWindowGc& gc = SystemGc();
gc.Clear(Rect());
}
// -----------------------------------------------------------------------------
// CS60InternetRadioView::CountComponentControls
// -----------------------------------------------------------------------------
//
TInt CS60InternetRadioView::CountComponentControls() const
{
return iMetadataLabels.Count();
}
// -----------------------------------------------------------------------------
// CS60InternetRadioView::ComponentControl
// -----------------------------------------------------------------------------
//
CCoeControl* CS60InternetRadioView::ComponentControl(
TInt aIndex ) const
{
if( aIndex < iMetadataLabels.Count() )
{
return iMetadataLabels[aIndex];
}
else
{
User::Panic(KS60InternetRadio, KS60InternetRadioPanicBadParameter);
}
return 0;
}
// -----------------------------------------------------------------------------
// CS60InternetRadioView::SizeChanged
// All the labels needs to be re-sized according to the new dimesion.
// -----------------------------------------------------------------------------
//
void CS60InternetRadioView::SizeChanged()
{
TRect rect = Rect();
TSize labelSize = iMetadataLabels[0]->MinimumSize();
rect.iTl.iX += (rect.Width() - labelSize.iWidth) / 2;
rect.iTl.iY += (rect.Height() - labelSize.iHeight*(1+iMetadataLabels.Count())) / (2+iMetadataLabels.Count());
rect.iBr = rect.iTl + labelSize;
iMetadataLabels[KMetadataServer]->SetRect(rect);
//now for the metadata
TInt vertical = 10;
for ( TInt i = KMetadataGenre; i < iMetadataLabels.Count(); i++ ) // begining with KMetadataGenre
{
rect = Rect();
labelSize = iMetadataLabels[i]->MinimumSize();
// set X
switch( i )
{
case KMetadataGenre:
case KMetadataTechDetails:
rect.iTl.iX += (rect.Width() - labelSize.iWidth) / 2;
break;
case KMetadataArtistTitle:
rect.iTl.iX = 10;
break;
case KMetadataBytesRcvd:
case KMetadataBuffer:
rect.iTl.iX = 0;
break;
case KMetadataPrice:
case KMetadataConnectionBitRate:
rect.iTl.iX = rect.Width() - labelSize.iWidth;
break;
};
//set Y
vertical += (labelSize.iHeight + 5);
switch( i )
{
case KMetadataArtistTitle:
vertical += 20;
break;
case KMetadataBytesRcvd:
case KMetadataPrice:
vertical = rect.Height() - 2 * labelSize.iHeight;
break;
case KMetadataBuffer:
case KMetadataConnectionBitRate:
vertical = rect.Height() - labelSize.iHeight;
break;
};
rect.iTl.iY += vertical;
//done
rect.iBr = rect.iTl + labelSize;
iMetadataLabels[i]->SetRect(rect);
}
};
// -----------------------------------------------------------------------------
// CS60InternetRadioView::NotifyStatus
// -----------------------------------------------------------------------------
//
void CS60InternetRadioView::NotifyStatus(
const TDesC& aMessage,
const TInt aNumOfMetadata )
{
TRAPD(err, ResetLabelsL(aMessage, aNumOfMetadata));
if ( !err )
{
SizeChanged();
}
}
// -----------------------------------------------------------------------------
// CS60InternetRadioView::ResetLabels
// -----------------------------------------------------------------------------
//
void CS60InternetRadioView::ResetLabelsL(
const TDesC& aMessage,
const TInt aNumOfMetadata )
{
RDebug::Print(_L("ResetLabels, aNumOfMetadata = %d"), aNumOfMetadata);
CEikLabel *l;
iMetadataLabels.ResetAndDestroy();
l = new (ELeave) CEikLabel;
l->SetContainerWindowL(*this);
l->SetTextL(aMessage);
iMetadataLabels.Append(l);
if ( aNumOfMetadata > 0 )
{
for( TInt i = KMetadataGenre; i < aNumOfMetadata; i++ ) //we use the first label as metadata
{
l = new (ELeave) CEikLabel;
l->SetContainerWindowL(*this);
l->SetTextL(_L(""));
iMetadataLabels.Append(l);
}
}
}
// -----------------------------------------------------------------------------
// CS60InternetRadioView::UpdateMetadataLabel
// -----------------------------------------------------------------------------
//
void CS60InternetRadioView::UpdateMetadataLabel(
TInt aMetadataIndex,
const TDesC& aMessage,
TBool aCommit )
{
RDebug::Print(_L("UpdateMetadataLabel, aMedataIndex = %d"), aMetadataIndex);
if ( aMetadataIndex == KMetadataArtistTitle )//we have to start the periodic label rotation
{
TBuf8<10> str;
iLabelText.Copy(aMessage.Ptr(), aMessage.Length() < 128 ? aMessage.Length() : 128);
str.Copy(iLabelText.Left(9));
if(str.Compare(_L8("Buffering")))
{
iLabelText.Append(_L(" "));//if the label is NOT Buffering, we append some spaces
TRAP_IGNORE(iMetadataLabels[aMetadataIndex]->OverrideColorL( EColorLabelText, KRgbBlue));
}
else //make the label look nicer
{
TRAP_IGNORE(iMetadataLabels[aMetadataIndex]->OverrideColorL( EColorLabelText, KRgbRed));
}
TRAP_IGNORE(iMetadataLabels[aMetadataIndex]->SetTextL(iLabelText));
if( !iAlarm )
{
//start the alarm
iAlarm = CPeriodic::New(EPriorityLow);
if( iAlarm )
iAlarm->Start(500000,200000,iCallback);
};
}
else
{
RDebug::Print(_L("UpdateMetadataLabel 3"));
TRAP_IGNORE(iMetadataLabels[aMetadataIndex]->SetTextL(aMessage));
RDebug::Print(_L("UpdateMetadataLabel 4"));
}
if ( aCommit )
{
RDebug::Print(_L("UpdateMetadataLabel 5"));
SizeChanged();
RDebug::Print(_L("UpdateMetadataLabel 6"));
DrawNow();
};
RDebug::Print(_L("UpdateMetadataLabel 7"));
};
// -----------------------------------------------------------------------------
// CS60InternetRadioView::MoveLabel
// -----------------------------------------------------------------------------
//
TInt CS60InternetRadioView::MoveLabel(
TAny *obj )
{
CS60InternetRadioView *self = (CS60InternetRadioView*)obj;
if( self->iMetadataLabels.Count() < 4)
return 1;
//if we are here, we make the label move....
if( self->iLabelText.Find(_L("Buffering")) == 0 )
{
//this is for "Buffering"
if( self->iLabelText.Length() >= 15 )
{
self->iLabelText.Copy(_L("Buffering"));
}
else
{
self->iLabelText.Append('.');
}
}
else
{
//this is for song + artist
TSize labelSize = self->iMetadataLabels[KMetadataArtistTitle]->MinimumSize();
if( labelSize.iWidth < 176 )
{
return 1;
}
//if we are here, we have to move the label
TChar first=self->iLabelText[0];
self->iLabelText.Delete(0,1);
self->iLabelText.Append(first);
}
TRAPD(err, self->iMetadataLabels[KMetadataArtistTitle]->SetTextL(self->iLabelText));
if ( !err )
{
self->DrawNow();
}
return 1;
}
// -----------------------------------------------------------------------------
// CS60InternetRadioView::FocusChanged
// -----------------------------------------------------------------------------
//
void CS60InternetRadioView::FocusChanged(
TDrawNow aDrawNow)
{
if ( IsFocused() )
{
iVolume=iAppUi->AudioAdapter()->Volume();
if( iVolume <= 0 )
{
iMute = ETrue;
}
else
{
iMute = EFalse;
}
TRAPD(err, iNaviPane->PushL( *iVolumeNavi ));
if ( !err )
{
CAknVolumeControl* volume = static_cast<CAknVolumeControl*>(iVolumeNavi->DecoratedControl());
volume->SetValue( iVolume );
}
}
else
{
// Focus lost, remove navi panes
iNaviPane->Pop( iVolumeNavi );
}
if ( aDrawNow == EDrawNow )
{
DrawNow();
}
else
{
DrawDeferred();
}
};
// -----------------------------------------------------------------------------
// CS60InternetRadioView::OfferKeyEventL
// -----------------------------------------------------------------------------
//
TKeyResponse CS60InternetRadioView::OfferKeyEventL(
const TKeyEvent& aKeyEvent,
TEventCode /*aType*/ )
{
TKeyResponse ret = EKeyWasNotConsumed;
if ( aKeyEvent.iCode == EKeyOK )
{
//toggle Play/Pause
iAppUi->AudioAdapter()->TogglePlayPause();
ret = EKeyWasConsumed;
};
switch ( aKeyEvent.iCode )
{
case EKeyLeftArrow:
{
if ( iVolume > 1 )
{
iAppUi->AudioAdapter()->SetVolume(--iVolume);
CAknVolumeControl* volume = static_cast<CAknVolumeControl*>( iVolumeNavi->DecoratedControl() );
volume->SetValue( iVolume );
}
else if ( !iMute )
{
iMute = ETrue;
iVolume = 0;
iAppUi->AudioAdapter()->SetVolume(iVolume);
}
ret = EKeyWasConsumed;
break;
}
case EKeyRightArrow:
{
if ( iMute )
{
iMute = EFalse;
}
if ( iVolume < KVolumeLevelMax )
{
iAppUi->AudioAdapter()->SetVolume(++iVolume);
CAknVolumeControl* volume = static_cast<CAknVolumeControl*>( iVolumeNavi->DecoratedControl() );
volume->SetValue( iVolume );
}
ret = EKeyWasConsumed;
break;
}
default:
break;
}
return ret;
}
// End of File
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -