Search in sources :

Example 16 with StateListDrawable

use of android.graphics.drawable.StateListDrawable in project Signal-Android by WhisperSystems.

the class TargetDrawable method isActive.

//    public boolean hasState(int [] state) {
//        if (mDrawable instanceof StateListDrawable) {
//            StateListDrawable d = (StateListDrawable) mDrawable;
//            // TODO: this doesn't seem to work
//            return d.getStateDrawableIndex(state) != -1;
//        }
//        return false;
//    }
/**
     * Returns true if the drawable is a StateListDrawable and is in the focused state.
     *
     * @return
     */
public boolean isActive() {
    if (mDrawable instanceof StateListDrawable) {
        StateListDrawable d = (StateListDrawable) mDrawable;
        int[] states = d.getState();
        for (int i = 0; i < states.length; i++) {
            if (states[i] == android.R.attr.state_focused) {
                return true;
            }
        }
    }
    return false;
}
Also used : StateListDrawable(android.graphics.drawable.StateListDrawable)

Example 17 with StateListDrawable

use of android.graphics.drawable.StateListDrawable in project Signal-Android by WhisperSystems.

the class TargetDrawable method setState.

public void setState(int[] state) {
    if (mDrawable instanceof StateListDrawable) {
        StateListDrawable d = (StateListDrawable) mDrawable;
        d.setState(state);
    }
}
Also used : StateListDrawable(android.graphics.drawable.StateListDrawable)

Example 18 with StateListDrawable

use of android.graphics.drawable.StateListDrawable in project actor-platform by actorapp.

the class SignEmailFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.fragment_sign_email, container, false);
    TextView buttonCotinueText = (TextView) v.findViewById(R.id.button_continue_text);
    StateListDrawable states = SelectorFactory.get(ActorSDK.sharedActor().style.getMainColor(), getActivity());
    buttonCotinueText.setBackgroundDrawable(states);
    buttonCotinueText.setTypeface(Fonts.medium());
    buttonCotinueText.setTextColor(ActorSDK.sharedActor().style.getTextPrimaryInvColor());
    keyboardHelper = new KeyboardHelper(getActivity());
    initView(v);
    //        Get domain logo
    //        logoActor = ActorSystem.system().actorOf(Props.create(LogoActor.class, new ActorCreator<LogoActor>() {
    //            @Override
    //            public LogoActor create() {
    //                return new LogoActor();
    //            }
    //        }), "actor/logo_actor");
    //
    //        logoActor.send(new LogoActor.AddCallback(new LogoActor.LogoCallBack() {
    //            @Override
    //            public void onDownloaded(final Drawable logoDrawable) {
    //                getActivity().runOnUiThread(new Runnable() {
    //                    @Override
    //                    public void run() {
    //                        if (logoDrawable != null) {
    //                            logo.setImageDrawable(logoDrawable);
    //                            logo.measure(0, 0);
    //                            expand(logo, logo.getMeasuredHeight());
    //                        } else {
    //                            expand(logo, 0);
    //                        }
    //                    }
    //                });
    //            }
    //        }));
    v.findViewById(R.id.divider).setBackgroundColor(style.getDividerColor());
    setTosAndPrivacy((TextView) v.findViewById(R.id.disclaimer));
    return v;
}
Also used : TextView(android.widget.TextView) StateListDrawable(android.graphics.drawable.StateListDrawable) KeyboardHelper(im.actor.sdk.util.KeyboardHelper) TextView(android.widget.TextView) View(android.view.View)

Example 19 with StateListDrawable

use of android.graphics.drawable.StateListDrawable in project actor-platform by actorapp.

the class TourActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.tour_activity);
    final VerticalViewPager viewPager = (VerticalViewPager) findViewById(R.id.viewpager);
    final View backToTopText = findViewById(R.id.back_to_top);
    final View backToTopArrow = findViewById(R.id.back_to_top_arrow);
    final View paralax = findViewById(R.id.paralax);
    final View paralaxImage = findViewById(R.id.paralax_image);
    final View background = findViewById(R.id.background);
    final View loginHolder = findViewById(R.id.login_holder);
    final View welcomeImage = findViewById(R.id.welcome_logo);
    final View welcomeText = findViewById(R.id.welcome_text);
    background.findViewById(R.id.background_colored).setBackgroundColor(ActorSDK.sharedActor().style.getMainColor());
    TextView signupButtonText = (TextView) findViewById(R.id.signUpButtonText);
    StateListDrawable states = SelectorFactory.get(ActorSDK.sharedActor().style.getPrimaryAltColor(), this);
    signupButtonText.setBackgroundDrawable(states);
    signupButtonText.setTextColor(ActorSDK.sharedActor().style.getTextPrimaryInvColor());
    signupButtonText.setTypeface(Fonts.medium());
    TextView buttonSignUp = (TextView) findViewById(R.id.signIn);
    buttonSignUp.setTextColor(ActorSDK.sharedActor().style.getTextPrimaryInvColor());
    buttonSignUp.setTypeface(Fonts.medium());
    ((TextView) findViewById(R.id.app_name)).setTextColor(ActorSDK.sharedActor().style.getTextPrimaryInvColor());
    ((TextView) findViewById(R.id.tour_welcome_subtitle)).setTextColor(ActorSDK.sharedActor().style.getTextPrimaryInvColor());
    findViewById(R.id.signUpButton).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Bundle authExtras = new Bundle();
            authExtras.putInt(AuthActivity.SIGN_TYPE_KEY, AuthActivity.SIGN_TYPE_UP);
            ActorSDK.sharedActor().startAuthActivity(TourActivity.this, authExtras);
            finish();
        }
    });
    findViewById(R.id.signIn).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Bundle authExtras = new Bundle();
            authExtras.putInt(AuthActivity.SIGN_TYPE_KEY, AuthActivity.SIGN_TYPE_IN);
            ActorSDK.sharedActor().startAuthActivity(TourActivity.this, authExtras);
            finish();
        }
    });
    View.OnClickListener jumpToTopListener = new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            backToTopArrow.animate().alpha(0).setDuration(0).start();
            backToTopText.animate().alpha(0).setDuration(0).start();
            viewPager.setCurrentItem(0, true);
        }
    };
    backToTopText.setOnClickListener(jumpToTopListener);
    backToTopArrow.setOnClickListener(jumpToTopListener);
    viewPager.setAdapter(new FragmentStatePagerAdapter(getSupportFragmentManager()) {

        @Override
        public Fragment getItem(int position) {
            if (position == 0 || position == lastPageIndex + 1)
                return new Fragment();
            return TourFragment.getInstance(position);
        }

        @Override
        public int getCount() {
            //6;
            return 4;
        }
    });
    //Necessary or the pager will only have one extra page to show
    // make this at least however many pages you can see
    viewPager.setOffscreenPageLimit(3);
    //A little space between pages
    viewPager.setPageMargin(-Screen.dp(165));
    //If hardware acceleration is enabled, you should also remove
    // clipping on the pager for its children.
    viewPager.setClipChildren(false);
    viewPager.setOnScrollListener(new ScrollListener() {

        public static final int LOGINHOLDER_STATUS_OUT = 1;

        public static final int LOGINHOLDER_STATUS_VISIBLE = 2;

        public int loginHolderStatus;

        public boolean welcomeShowed = false;

        public boolean mainContentHidden = false;

        public boolean loginHolderBackgroundVisible = false;

        @Override
        public void onScroll(int y, float page) {
            if (page < 1) {
                float alpha = 1 - page * 2;
                backToTopArrow.animate().alpha(alpha).setDuration(0).start();
                //status1.setText("alpha:" + alpha);
                if (loginHolder.getTop() != 0) {
                    float loginY = (float) loginHolder.getTop() * ((float) 1 - (page));
                    loginHolder.animate().y(loginY).setDuration(0).setStartDelay(0).start();
                    background.animate().y(loginY - background.getHeight() + loginHolder.getHeight() + Screen.dp(8)).setDuration(0).start();
                    /*if(loginHolderBackgroundVisible){
                            loginHolderBackgroundVisible = false;
                            loginHolderBackground.animate().alpha(0).setDuration(0).start();
                        } else {

                        }*/
                    //loginHolderBackground.animate().alpha(page).setDuration(0).start();
                    background.animate().alpha(page).setDuration(0).start();
                    loginHolderStatus = LOGINHOLDER_STATUS_VISIBLE;
                    float welcomeImageY = welcomeImage.getTop() - y / 2;
                    float welcomeTextY = welcomeText.getTop() - y / 2;
                    if (alpha > 0) {
                        welcomeImage.animate().alpha(alpha).y(welcomeImageY).setDuration(0).start();
                        welcomeText.animate().alpha(alpha).y(welcomeTextY).setDuration(0).start();
                    } else {
                        welcomeImage.animate().alpha(0).setDuration(0).start();
                        welcomeText.animate().alpha(0).setDuration(0).start();
                    }
                }
                mainContentHidden = false;
            } else {
                if (page >= 1 && page <= lastPageIndex) {
                    // todo freeze?
                    if (!mainContentHidden) {
                        mainContentHidden = true;
                        loginHolderBackgroundVisible = true;
                        //signinLastView.setEnabled(false);
                        //signinView.setEnabled(false);
                        //signupLastView.setEnabled(false);
                        //signupView.setEnabled(false);
                        loginHolder.animate().y(0).setDuration(0).start();
                        //loginHolderBackground.animate().alpha(1).setDuration(0).start();
                        background.animate().y(-loginHolder.getTop() + Screen.dp(8)).alpha(1).setDuration(0).start();
                        welcomeImage.animate().alpha(0).setDuration(0).start();
                        welcomeText.animate().alpha(0).setDuration(0).start();
                        backToTopArrow.animate().alpha(0).setDuration(0).start();
                        backToTopText.animate().alpha(0).setDuration(0).start();
                    }
                    if (page > lastPageIndex - 1) {
                        float alpha = (page - (lastPageIndex - 1)) * 3 - 2;
                        if (alpha > 0) {
                            backToTopText.animate().scaleX(alpha).scaleY(alpha).alpha(alpha).setDuration(0).start();
                        } else {
                            backToTopText.animate().scaleX(0).scaleY(0).alpha(0).setDuration(0).start();
                        }
                    }
                } else {
                    if (page > lastPageIndex) {
                        float progress = page - lastPageIndex;
                        if (progress > 0.5) {
                            if (loginHolderStatus == LOGINHOLDER_STATUS_VISIBLE) {
                                loginHolderStatus = LOGINHOLDER_STATUS_OUT;
                                loginHolder.animate().y(-loginHolder.getHeight()).setDuration(200).setInterpolator(new AccelerateDecelerateInterpolator()).setStartDelay(0).start();
                            }
                            mainContentHidden = false;
                        } else {
                            if (loginHolderStatus == LOGINHOLDER_STATUS_OUT) {
                                loginHolderStatus = LOGINHOLDER_STATUS_VISIBLE;
                                loginHolder.animate().y(0).setInterpolator(new AccelerateDecelerateInterpolator()).setDuration(200).setStartDelay(0).start();
                            }
                            if (!mainContentHidden) {
                                backToTopArrow.animate().alpha(0).setDuration(0).start();
                                backToTopText.animate().alpha(0).setDuration(0).start();
                            }
                        }
                    }
                }
            }
            int paralaxHolderHeight = paralax.getHeight();
            int paralaxImageHeight = paralaxImage.getHeight();
            float paralaxY = -(((float) paralaxImageHeight - paralaxHolderHeight) * ((float) page / (lastPageIndex)));
            paralaxImage.animate().y(paralaxY).setDuration(0).setStartDelay(0).start();
        }
    });
    if (Build.VERSION.SDK_INT >= 19) {
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS, WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        contentTopPadding = Screen.getStatusBarHeight();
        RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) findViewById(R.id.pager_container).getLayoutParams();
        params.topMargin = contentTopPadding;
        findViewById(R.id.pager_container).setLayoutParams(params);
        params = (RelativeLayout.LayoutParams) backToTopArrow.getLayoutParams();
        params.topMargin = contentTopPadding + params.topMargin;
        backToTopArrow.setLayoutParams(params);
        params = (RelativeLayout.LayoutParams) welcomeImage.getLayoutParams();
        params.topMargin = contentTopPadding + params.topMargin;
        welcomeImage.setLayoutParams(params);
        params = (RelativeLayout.LayoutParams) welcomeText.getLayoutParams();
        params.topMargin = contentTopPadding + params.topMargin;
        welcomeText.setLayoutParams(params);
        params = (RelativeLayout.LayoutParams) backToTopText.getLayoutParams();
        params.topMargin = contentTopPadding + params.topMargin;
        backToTopText.setLayoutParams(params);
    }
}
Also used : FragmentStatePagerAdapter(android.support.v4.app.FragmentStatePagerAdapter) Bundle(android.os.Bundle) StateListDrawable(android.graphics.drawable.StateListDrawable) TextView(android.widget.TextView) View(android.view.View) Fragment(android.support.v4.app.Fragment) RelativeLayout(android.widget.RelativeLayout) AccelerateDecelerateInterpolator(android.view.animation.AccelerateDecelerateInterpolator) TextView(android.widget.TextView)

Example 20 with StateListDrawable

use of android.graphics.drawable.StateListDrawable in project actor-platform by actorapp.

the class ShareMenuButtonFactory method get.

public static StateListDrawable get(int color, Context context) {
    ShapeDrawable bg = new ShapeDrawable(new OvalShape());
    int padding = Screen.dp(5);
    bg.getPaint().setColor(color);
    ShapeDrawable bgPressed = new ShapeDrawable(new OvalShape());
    bgPressed.getPaint().setColor(ActorStyle.getDarkenArgb(color, 0.95));
    StateListDrawable states = new StateListDrawable();
    states.addState(new int[] { android.R.attr.state_pressed }, new InsetDrawable(bgPressed, padding));
    states.addState(StateSet.WILD_CARD, new InsetDrawable(bg, padding));
    return states;
}
Also used : ShapeDrawable(android.graphics.drawable.ShapeDrawable) InsetDrawable(android.graphics.drawable.InsetDrawable) OvalShape(android.graphics.drawable.shapes.OvalShape) StateListDrawable(android.graphics.drawable.StateListDrawable)

Aggregations

StateListDrawable (android.graphics.drawable.StateListDrawable)163 Drawable (android.graphics.drawable.Drawable)43 LayerDrawable (android.graphics.drawable.LayerDrawable)24 BitmapDrawable (android.graphics.drawable.BitmapDrawable)21 GradientDrawable (android.graphics.drawable.GradientDrawable)21 ColorDrawable (android.graphics.drawable.ColorDrawable)15 Bitmap (android.graphics.Bitmap)13 TextView (android.widget.TextView)12 ShapeDrawable (android.graphics.drawable.ShapeDrawable)11 View (android.view.View)11 AnimationDrawable (android.graphics.drawable.AnimationDrawable)9 ClipDrawable (android.graphics.drawable.ClipDrawable)9 SuppressLint (android.annotation.SuppressLint)8 Paint (android.graphics.Paint)8 ColorStateList (android.content.res.ColorStateList)7 RippleDrawable (android.graphics.drawable.RippleDrawable)7 TargetApi (android.annotation.TargetApi)6 TypedArray (android.content.res.TypedArray)6 TextPaint (android.text.TextPaint)5 Button (android.widget.Button)5