Change WorkSpace PageScroll Effect

Source: Internet
Author: User

These effects are taken out of the CM, the code that needs to be modified, add some code to the Workspace.java. To modify a step:

Define several variables and constants:

    /*****************************tangxuankai Add start**************************/protected TransitionEffect   Mtransitioneffect;     Protected Boolean            Musetransitioneffect       = true;    Private   boolean            mscrolltransformsset;          Protected static final Float transition_screen_rotation = 35f;protected static float       camera_distance            = 6500; Protected static final float Transition_scale_factor    = 0.5f;/*****************************tangxuankai Add end*** ***********************/

In the Screenscrolled function, add:

protected void screenscrolled (int screencenter) {..../************tangxuankai add to change scroll animation start****, ..... TODO Change Screenscroll Animation Boolean isinoverscroll = false; Moverscrollx < 0 | | MOVERSCROLLX > mmaxscrollx;////Apply transition effect and adjacent screen fade if enabled//sharedpreferen Ces sp = GetContext (). Getsharedpreferences (//"Com.android.launcher3.prefs", context.mode_private); int Screeneffectnum = 4;//sp.getint ("Screeneffect", 0); for (int i = 0; i < Getchildcount (); i++) {View v = getpageat (i); if (v! = null) {Float scrollprogress = getscrollprogress (Screencenter, V, i); switch (screeneffectnum) {case 0:changescreeneffect ( Isinoverscroll, I, V, scrollprogress, "none"), Break;case 1:changescreeneffect (Isinoverscroll, I, V, scrollprogress, " Cube-out "); break;case 2:changescreeneffect (Isinoverscroll, I, V, scrollprogress," zoom-in "); Break;case 3: Changescreeneffect (Isinoverscroll, I, V, scrollprogress, "stack"); BreAk;case 4:changescreeneffect (Isinoverscroll, I, V, scrollprogress, "Flip"); Break;case 5:changescreeneffect ( Isinoverscroll, I, V, scrollprogress, "cylinder-in"); break;case 6:changescreeneffect (Isinoverscroll, I, V, Scrollprogress, "Rotate-down"); break;case 7:changescreeneffect (Isinoverscroll, I, V, scrollprogress, "accordion"); Break;default:break;}}} /************tangxuankai Add to change scroll animation end*************************/}
Then add in the code:

private void Changescreeneffect (Boolean isinoverscroll, int i, View v,float scrollprogress,string effect) { Transitioneffect.setfromstring (this, effect); if (mtransitioneffect! = null && musetransitioneffect && !isinoverscroll) {mtransitioneffect.screenscrolled (V, I, scrollprogress);} else if (mscrolltransformsset) {V.setPi    Votx (V.getmeasuredwidth () * 0.5f);    V.setpivoty (V.getmeasuredheight () * 0.5f);    V.setrotation (0);    V.setrotationx (0);    V.setrotationy (0);    V.setscalex (1f);    V.setscaley (1f);    V.settranslationx (0f);    V.settranslationy (0f);    V.setvisibility (VISIBLE);    Setchildalpha (v, 1f); V.setalpha (1.0f);}}    public Boolean Islayoutrtl () {return Utilities.isrtl (mlauncher.getresources ());}    Public TransitionEffect Gettransitioneffect () {return mtransitioneffect;        }public void Settransitioneffect (TransitionEffect effect) {mtransitioneffect = effect;         Reset Scroll transforms if (mscrolltransformsset) {   for (int i = 0; i < Getchildcount (); i++) {View v = getpageat (i);                    if (v! = null) {V.setpivotx (V.getmeasuredwidth () * 0.5f);                    V.setpivoty (V.getmeasuredheight () * 0.5f);                    V.setrotation (0);                    V.setrotationx (0);                    V.setrotationy (0);                    V.setscalex (1f);                    V.setscaley (1f);                    V.settranslationx (0f);                    V.settranslationy (0f);                    V.setvisibility (VISIBLE);                Setchildalpha (v, 1f);        }} Mscrolltransformsset = false;    }}protected void Setchildalpha (View child, float Alpha) {Child.setalpha (alpha);        }protected static abstract class TransitionEffect {public static final String Transition_effect_none = "NONE";        public static final String transition_effect_zoom_in = "zoom-in"; public static final String TRANsition_effect_zoom_out = "Zoom-out";        public static final String transition_effect_rotate_up = "rotate-up";        public static final String Transition_effect_rotate_down = "Rotate-down";        public static final String transition_effect_cube_in = "cube-in";        public static final String transition_effect_cube_out = "Cube-out";        public static final String transition_effect_stack = "STACK";        public static final String transition_effect_accordion = "ACCORDION";        public static final String transition_effect_flip = "FLIP";        public static final String transition_effect_cylinder_in = "cylinder-in";        public static final String transition_effect_cylinder_out = "Cylinder-out";        public static final String Transition_effect_crossfade = "Crossfade";        public static final String Transition_effect_overview = "Overview";        Protected final Workspace Mworkspace;        Private final String Mname; Public TransitionEffect (Workspace WORKSPAce, String name) {mworkspace = workspace;        Mname = name;        } public abstract void screenscrolled (View v, int i, float scrollprogress);        Public final String GetName () {return mname; } public static void Setfromstring (Workspace Workspace, String effect) {if (Effect.equals (workspace.tr            Ansitioneffect.transition_effect_none)) {workspace.settransitioneffect (null); } else if (Effect.equals (Workspace.TransitionEffect.TRANSITION_EFFECT_ZOOM_IN)) {WORKSPACE.SETTRANSITIONEF            Fect (New Workspace.TransitionEffect.Zoom (Workspace, true)); } else if (Effect.equals (Workspace.TransitionEffect.TRANSITION_EFFECT_ZOOM_OUT)) {Workspace.settransitione            Ffect (New Workspace.TransitionEffect.Zoom (Workspace, false)); } else if (Effect.equals (Workspace.TransitionEffect.TRANSITION_EFFECT_CUBE_IN)) {WORKSPACE.SETTRANSITIONEF Fect (New Workspace.traNsitioneffect.cube (workspace, true)); } else if (Effect.equals (Workspace.TransitionEffect.TRANSITION_EFFECT_CUBE_OUT)) {Workspace.settransitione            Ffect (New Workspace.TransitionEffect.Cube (Workspace, false)); } else if (Effect.equals (Workspace.TransitionEffect.TRANSITION_EFFECT_ROTATE_UP)) {workspace.settransition            Effect (New Workspace.TransitionEffect.Rotate (Workspace, true)); } else if (Effect.equals (Workspace.TransitionEffect.TRANSITION_EFFECT_ROTATE_DOWN)) {Workspace.settransiti            Oneffect (New Workspace.TransitionEffect.Rotate (Workspace, false)); } else if (Effect.equals (Workspace.TransitionEffect.TRANSITION_EFFECT_STACK)) {Workspace.settransitioneffe            CT (new Workspace.TransitionEffect.Stack (Workspace)); } else if (Effect.equals (Workspace.TransitionEffect.TRANSITION_EFFECT_ACCORDION)) {workspace.settransition Effect (New Workspace.TransitionEffect.Accordion (WORKspace)); } else if (Effect.equals (Workspace.TransitionEffect.TRANSITION_EFFECT_FLIP)) {WORKSPACE.SETTRANSITIONEFFEC            T (new Workspace.TransitionEffect.Flip (Workspace)); } else if (Effect.equals (Workspace.TransitionEffect.TRANSITION_EFFECT_CYLINDER_IN)) {Workspace.settransiti            Oneffect (New Workspace.TransitionEffect.Cylinder (Workspace, true)); } else if (Effect.equals (Workspace.TransitionEffect.TRANSITION_EFFECT_CYLINDER_OUT)) {Workspace.settransit            Ioneffect (New Workspace.TransitionEffect.Cylinder (Workspace, false)); } else if (Effect.equals (Workspace.TransitionEffect.TRANSITION_EFFECT_CROSSFADE)) {workspace.settransition            Effect (New Workspace.TransitionEffect.Crossfade (Workspace)); } else if (Effect.equals (Workspace.TransitionEffect.TRANSITION_EFFECT_OVERVIEW)) {Workspace.settransitione            Ffect (New Workspace.TransitionEffect.Overview (Workspace));    }    } public static class Zoom extends TransitionEffect {private Boolean mIn; Public Zoom (Workspace Workspace, Boolean in) {Super (Workspace, in?)                Transition_effect_zoom_in:transition_effect_zoom_out);            MIn = in; } @Override public void screenscrolled (View v, int i, float scrollprogress) {float s                Cale = 1.0f + (mIn. -0.8f:0.4f) * Math.Abs (scrollprogress); Extra translation to account for the increase in size if (!min) {float Translationx                    = V.getmeasuredwidth () * 0.1f *-scrollprogress;                V.settranslationx (Translationx);                } v.setscalex (scale);            V.setscaley (scale);            }} public static class Rotate extends TransitionEffect {private Boolean mUp; Public Rotate (Workspace Pagedview, Boolean up) {super (Pagedview, up?                Transition_effect_rotate_up:transition_effect_rotate_down);            MUp = up; } @Override public void screenscrolled (View v, int i, float scrollprogress) {float R Otation = (mUp?                Transition_screen_rotation:-transition_screen_rotation) * scrollprogress;                float Translationx = v.getmeasuredwidth () * scrollprogress; float Rotatepoint = (v.getmeasuredwidth () * 0.5f)/(float) Math.tan                (Math.toradians (double) (transition_screen_rotation * 0.5f));                V.setpivotx (V.getmeasuredwidth () * 0.5f);                if (mUp) {v.setpivoty (-rotatepoint);                } else {V.setpivoty (v.getmeasuredheight () + rotatepoint);                } v.setrotation (rotation);            V.settranslationx (Translationx); }} public static class CubeExtends TransitionEffect {private Boolean mIn; Public Cube (Workspace Workspace, Boolean in) {Super (Workspace, in?)                Transition_effect_cube_in:transition_effect_cube_out);            MIn = in; } @Override public void screenscrolled (View v, int i, float scrollprogress) {float R                Otation = (mIn. 90.0f: -90.0f) * scrollprogress;                V.setpivotx (scrollprogress < 0 0:v.getmeasuredwidth ());                V.setpivoty (V.getmeasuredheight () * 0.5f);            V.setrotationy (rotation); }} public static class Stack extends TransitionEffect {private Zinterpolator Mzinterpolator = n            EW Zinterpolator (0.5f);            Private Decelerateinterpolator Mleftscreenalphainterpolator = new Decelerateinterpolator (4);            protected Accelerateinterpolator malphainterpolator = new Accelerateinterpolator (0.9f); Public Stack (Workspace Workspace) {Super (workspace, transition_effect_stack);                            } @Override public void screenscrolled (View v, int i, float scrollprogress) {                Final Boolean Isrtl = Mworkspace.islayoutrtl ();                float interpolatedprogress;                float Translationx;                float maxscrollprogress = Math.max (0, scrollprogress);                float minscrollprogress = math.min (0, scrollprogress);                    if (Mworkspace.islayoutrtl ()) {Translationx = maxscrollprogress * V.getmeasuredwidth ();                interpolatedprogress = Mzinterpolator.getinterpolation (Math.Abs (maxscrollprogress));                    } else {Translationx = minscrollprogress * V.getmeasuredwidth ();                interpolatedprogress = Mzinterpolator.getinterpolation (Math.Abs (minscrollprogress)); } Float scale = (1-interpolatedprogress) + InterPolatedprogress * Transition_scale_factor;                float Alpha; if (Isrtl && (scrollprogress > 0)) {alpha = Malphainterpolator.getinterpolation (1-math.ab                S (maxscrollprogress));  } else if (!isrtl && (scrollprogress < 0)) {alpha = malphainterpolator.getinterpolation (1-                Math.Abs (scrollprogress));                    } else {//on large screens we need to fade the page as it nears its leftmost position                Alpha = mleftscreenalphainterpolator.getinterpolation (1-scrollprogress);                } v.settranslationx (Translationx);                V.setscalex (scale);                V.setscaley (scale);                if (v instanceof celllayout) {((celllayout) v). Getshortcutsandwidgets (). Setalpha (Alpha);                } else {V.setalpha (alpha); }//If The view has 0 alpha, we set It to is invisible so as to prevent//it from accepting touches if (alpha = = 0) {                V.setvisibility (INVISIBLE);                } else if (v.getvisibility ()! = visible) {v.setvisibility (visible); }}} public static class Accordion extends TransitionEffect {public Accordion (WORKSP            Ace Workspace) {Super (workspace, transition_effect_accordion); } @Override public void screenscrolled (View v, int i, float scrollprogress) {float s                Cale = 1.0f-math.abs (scrollprogress);                V.setscalex (scale);                V.setpivotx (scrollprogress < 0 0:v.getmeasuredwidth ());            V.setpivoty (V.getmeasuredheight ()/2f);                }} public static class Flip extends TransitionEffect {public Flip (Workspace Workspace) { Super (workspace, Transition_effect_fLIP); } @Override public void screenscrolled (View v, int i, float scrollprogress) {float R                otation = -180.0f * Math.max ( -1f, Math.min (1f, scrollprogress));                V.setcameradistance (mworkspace.mdensity * workspace.camera_distance);                V.setpivotx (V.getmeasuredwidth () * 0.5f);                V.setpivoty (V.getmeasuredheight () * 0.5f);                V.setrotationy (rotation); if (scrollprogress >= -0.5f && scrollprogress <= 0.5f) {V.settranslationx (V.getmeasuredw                Idth () * scrollprogress);                } else {V.settranslationx (0f);            }}} public static class Cylinder extends TransitionEffect {private Boolean mIn; Public Cylinder (Workspace Workspace, Booleans) {super (Workspace, in?)                Transition_effect_cylinder_in:transition_effect_cylinder_out);    MIn = in;        } @Override public void screenscrolled (View v, int i, float scrollprogress) { float rotation = (mIn?)                Transition_screen_rotation:-transition_screen_rotation) * scrollprogress;                V.setpivotx ((scrollprogress + 1) * V.getmeasuredwidth () * 0.5f);                V.setpivoty (V.getmeasuredheight () * 0.5f);            V.setrotationy (rotation); }} public static class Crossfade extends TransitionEffect {public Crossfade (Workspace Workspace            ) {Super (workspace, Transition_effect_crossfade); } @Override public void screenscrolled (View v, int i, float scrollprogress) {float A                Lpha = 1-math.abs (scrollprogress);                V.setpivotx (V.getmeasuredwidth () * 0.5f);                V.setpivoty (V.getmeasuredheight () * 0.5f);            V.setalpha (Alpha); }} public static class overview extends TransitioneffeCT {private Acceleratedecelerateinterpolator mscaleinterpolator = new Acceleratedecelerateinterpolator ();            Public Overview (Workspace Workspace) {super (Workspace, Transition_effect_overview); } @Override public void screenscrolled (View v, int i, float scrollprogress) {float s  Cale = 1.0f-0.1f * Mscaleinterpolator.getinterpolation (Math.min (0.3f, Math.Abs (scrollprogress))/                0.3F);                V.setpivotx (scrollprogress < 0 0:v.getmeasuredwidth ());                V.setpivoty (V.getmeasuredheight () * 0.5f);                V.setscalex (scale);                V.setscaley (scale);            Mworkspace.setchildalpha (v, scale); }        }    }

Some effects also need to be adjusted according to their needs slowly.

Change WorkSpace PageScroll Effect

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.