1. #1
    Sencha User
    Join Date
    Aug 2011
    Posts
    39
    Answers
    1
    Vote Rating
    4
    MattUCG is on a distinguished road

      0  

    Default Answered: Ext.app.Application.setCurrentProfile

    Answered: Ext.app.Application.setCurrentProfile


    I am attempting to programatically switch the active profile and redraw the viewport whenever the orientation changes. I was hoping for something like ST1's determineProfile function, which would scan all profiles and switch to whichever is active, but ST2 does not seem to have that functionality. I wrote a simple controller, and the profile is being set (I can call getCurrentProfile afterwards to see the change), but the profile's launch function is not called and the viewport is not being redrawn. Can anyone tell what I am missing?

    Code:
    Ext.define('SenchaProfiles.controller.Main', {
        extend: 'Ext.app.Controller',
        
        config: {
            refs: {
                viewport: 'viewport',
            },
            control: {
                viewport: {
                    orientationchange: 'handleOrientationChange'
                }
            }
        },
        handleOrientationChange: function(viewport, orientation, width, height){
            var currOrientation = Ext.Viewport.determineOrientation();  
    
    
            if (currOrientation == 'portrait')
                SenchaProfiles.app.setCurrentProfile(Ext.create('SenchaProfiles.profile.TabletPortrait'));
            else if (currOrientation == 'landscape')
                SenchaProfiles.app.setCurrentProfile(Ext.create('SenchaProfiles.profile.TabletLandscape'));
        }
    });
    Last edited by MattUCG; 1 Aug 2012 at 12:12 PM. Reason: more specific question

  2. All I was missing was a manual call to the profile's launch function:

    Code:
    Ext.define('SenchaProfiles.controller.Main', {
        extend: 'Ext.app.Controller',
        
        config: {
            refs: {
                viewport: 'viewport',
            },
            control: {
                viewport: {
                    orientationchange: 'handleOrientationChange'
                }
            }
        },
        handleOrientationChange: function(viewport, orientation, width, height){
            var currOrientation = Ext.Viewport.determineOrientation();  
    
    
            if (currOrientation == 'portrait')
                SenchaProfiles.app.setCurrentProfile(Ext.create('SenchaProfiles.profile.TabletPortrait'));
            else if (currOrientation == 'landscape')
                SenchaProfiles.app.setCurrentProfile(Ext.create('SenchaProfiles.profile.TabletLandscape'));
    
    
            SenchaProfiles.app.getCurrentProfile().launch();
        }
    });

  3. #2
    Sencha User
    Join Date
    Aug 2011
    Posts
    39
    Answers
    1
    Vote Rating
    4
    MattUCG is on a distinguished road

      0  

    Default


    All I was missing was a manual call to the profile's launch function:

    Code:
    Ext.define('SenchaProfiles.controller.Main', {
        extend: 'Ext.app.Controller',
        
        config: {
            refs: {
                viewport: 'viewport',
            },
            control: {
                viewport: {
                    orientationchange: 'handleOrientationChange'
                }
            }
        },
        handleOrientationChange: function(viewport, orientation, width, height){
            var currOrientation = Ext.Viewport.determineOrientation();  
    
    
            if (currOrientation == 'portrait')
                SenchaProfiles.app.setCurrentProfile(Ext.create('SenchaProfiles.profile.TabletPortrait'));
            else if (currOrientation == 'landscape')
                SenchaProfiles.app.setCurrentProfile(Ext.create('SenchaProfiles.profile.TabletLandscape'));
    
    
            SenchaProfiles.app.getCurrentProfile().launch();
        }
    });

  4. #3
    Sencha User jerome76's Avatar
    Join Date
    Apr 2012
    Location
    New Jersey
    Posts
    1,132
    Answers
    128
    Vote Rating
    97
    jerome76 is just really nice jerome76 is just really nice jerome76 is just really nice jerome76 is just really nice jerome76 is just really nice

      1  

    Default


    Before you changed your code you checked to see if the profile was active, but you didn't call the function right.
    you had
    Code:
    if(profiles[i].isActive)
    when it should be
    Code:
    if(profiles[i].isActive())

  5. #4
    Sencha User
    Join Date
    Aug 2011
    Posts
    39
    Answers
    1
    Vote Rating
    4
    MattUCG is on a distinguished road

      0  

    Default


    That doesn't seem to work. The array returned by getProfiles() contains strings, not objects. When I call isActive() on profiles[i], i get:

    Uncaught TypeError: Object SenchaProfiles.profile.TabletPortrait has no method 'isActive'

  6. #5
    Sencha User jerome76's Avatar
    Join Date
    Apr 2012
    Location
    New Jersey
    Posts
    1,132
    Answers
    128
    Vote Rating
    97
    jerome76 is just really nice jerome76 is just really nice jerome76 is just really nice jerome76 is just really nice jerome76 is just really nice

      0  

    Default


    So the strings it passes you is SenchaProfiles.profile.TabletPortrait?

    If so, then it should not be adding the Object part

    Do you define the isActive function in your definition of SenchaProfiles.profile.TabletPortrait and other profiles?
    Code:
    //for Phone
    isActive: function(){
        return Ext.os.is.Phone;
    }

  7. #6
    Sencha User
    Join Date
    Aug 2011
    Posts
    39
    Answers
    1
    Vote Rating
    4
    MattUCG is on a distinguished road

      1  

    Default


    I am defining isActive in the profile.

    It's adding "object" because I am treating the string like an object. Running the following line of javascript demonstrates:

    "test".hello()

    TypeError: Object test has no method 'hello'

  8. #7
    Sencha User jerome76's Avatar
    Join Date
    Apr 2012
    Location
    New Jersey
    Posts
    1,132
    Answers
    128
    Vote Rating
    97
    jerome76 is just really nice jerome76 is just really nice jerome76 is just really nice jerome76 is just really nice jerome76 is just really nice

      0  

    Default


    True. I figured getProfiles() would return the actual Profile objects and not just what is declared in the 'profiles' config array. I see now how your new code will work.

film izle

hd film izle

film sitesi

takipci kazanma sitesi

takipci kazanma sitesi

güzel olan herşey

takipci alma sitesi

komik eğlenceli videolar