Example usage for android.view View getBackground

List of usage examples for android.view View getBackground

Introduction

In this page you can find the example usage for android.view View getBackground.

Prototype

public Drawable getBackground() 

Source Link

Document

Gets the background drawable

Usage

From source file:meizhi.meizhi.malin.utils.DestroyCleanUtil.java

@SuppressLint("ObsoleteSdkInt")
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
public static void unBindView(View view) {
    if (view == null)
        return;//from w  ww  . j a va2 s . com
    Drawable drawable;
    int i;
    //1.
    try {
        view.setOnClickListener(null);
    } catch (Throwable e) {
        CrashReport.postCatchedException(e);
    }

    //2.
    try {
        view.setOnCreateContextMenuListener(null);
    } catch (Throwable e) {
        CrashReport.postCatchedException(e);
    }

    //3.
    try {
        view.setOnFocusChangeListener(null);
    } catch (Throwable e) {
        CrashReport.postCatchedException(e);
    }

    //4.
    try {
        view.setOnKeyListener(null);
    } catch (Throwable e) {
        CrashReport.postCatchedException(e);
    }

    //5.
    try {
        view.setOnLongClickListener(null);
    } catch (Throwable e) {
        CrashReport.postCatchedException(e);
    }

    //6.
    try {
        view.setOnTouchListener(null);
    } catch (Throwable e) {
        CrashReport.postCatchedException(e);
    }

    //7.
    try {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) {
            view.setOnApplyWindowInsetsListener(null);
        }
    } catch (Throwable e) {
        CrashReport.postCatchedException(e);
    }

    //8.
    try {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            view.setOnContextClickListener(null);
        }
    } catch (Throwable e) {
        CrashReport.postCatchedException(e);
    }

    //9.
    try {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            view.setOnScrollChangeListener(null);
        }
    } catch (Throwable e) {
        CrashReport.postCatchedException(e);
    }

    //10.
    try {
        view.setOnDragListener(null);
    } catch (Throwable e) {
        CrashReport.postCatchedException(e);
    }

    //11.
    try {
        view.setOnGenericMotionListener(null);
    } catch (Throwable e) {
        CrashReport.postCatchedException(e);
    }

    //12.
    try {
        if (Build.VERSION.SDK_INT > Build.VERSION_CODES.HONEYCOMB_MR2) {//13
            view.setOnHoverListener(null);
        }
    } catch (Throwable e) {
        CrashReport.postCatchedException(e);
    }

    //13.
    try {
        view.setOnSystemUiVisibilityChangeListener(null);
    } catch (Throwable e) {
        CrashReport.postCatchedException(e);
    }

    /**
     * @see SwipeRefreshLayout#onDetachedFromWindow()
     */
    if (view.getBackground() != null && !view.getClass().getName().equals(CIRCLE_CLASS)) {
        try {
            view.getBackground().setCallback(null);
            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {//16
                view.setBackgroundDrawable(null);
            } else {
                view.setBackground(null);
            }
        } catch (Throwable e) {
            CrashReport.postCatchedException(e);
        }
    }

    //ImageView
    if (view instanceof ImageView) {
        try {
            ImageView imageView = (ImageView) view;
            drawable = imageView.getDrawable();
            if (drawable != null) {
                drawable.setCallback(null);
            }
            imageView.setImageDrawable(null);
            imageView.setImageBitmap(null);
        } catch (Throwable e) {
            CrashReport.postCatchedException(e);
        }
    }

    //TextView
    if (view instanceof TextView) {
        try {
            TextView textView = (TextView) view;
            textView.setCompoundDrawables(null, null, null, null);
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
                textView.setCompoundDrawablesRelative(null, null, null, null);
            }
            textView.setCursorVisible(false);
        } catch (Throwable e) {
            CrashReport.postCatchedException(e);
        }
    }

    //ImageButton
    if (view instanceof ImageButton) {
        try {
            ImageButton imageButton = (ImageButton) view;
            drawable = imageButton.getDrawable();
            if (drawable != null) {
                drawable.setCallback(null);
            }
            imageButton.setImageDrawable(null);
            imageButton.setImageBitmap(null);
        } catch (Throwable e) {
            CrashReport.postCatchedException(e);
        }
    }

    //ListView
    if (view instanceof ListView) {
        ListView listView = (ListView) view;

        try {
            listView.setAdapter(null);
        } catch (Throwable e) {
            CrashReport.postCatchedException(e);
        }

        try {
            listView.setOnScrollListener(null);
        } catch (Throwable e) {
            CrashReport.postCatchedException(e);
        }

        try {
            listView.setOnItemClickListener(null);
        } catch (Throwable e) {
            CrashReport.postCatchedException(e);
        }

        try {
            listView.setOnItemLongClickListener(null);
        } catch (Throwable e) {
            CrashReport.postCatchedException(e);
        }

        try {
            listView.setOnItemSelectedListener(null);
        } catch (Throwable e) {
            CrashReport.postCatchedException(e);
        }
    }

    //RecyclerView
    if (view instanceof RecyclerView) {
        try {
            RecyclerView recyclerView = (RecyclerView) view;
            recyclerView.setAdapter(null);
            recyclerView.setChildDrawingOrderCallback(null);
            recyclerView.setOnScrollListener(null);
            recyclerView.addOnScrollListener(null);
            recyclerView.removeOnScrollListener(null);
            recyclerView.setRecyclerListener(null);
        } catch (Throwable e) {
            CrashReport.postCatchedException(e);
        }
    }

    //WebView
    if (view instanceof WebView) {

        WebView webView = (WebView) view;
        try {
            webView.stopLoading();
        } catch (Throwable ignored) {
            CrashReport.postCatchedException(ignored);
        }

        try {
            webView.removeAllViews();
        } catch (Throwable ignored) {
            CrashReport.postCatchedException(ignored);
        }

        try {
            webView.setWebChromeClient(null);
        } catch (Throwable ignored) {
            CrashReport.postCatchedException(ignored);
        }

        try {
            webView.setWebViewClient(null);
        } catch (Throwable ignored) {
            CrashReport.postCatchedException(ignored);
        }

        try {
            webView.destroy();
        } catch (Throwable ignored) {
            CrashReport.postCatchedException(ignored);
        }

        try {
            if (null != view.getParent() && view.getParent() instanceof ViewGroup) {
                ((ViewGroup) view.getParent()).removeView(view);
            }
        } catch (Throwable ignored) {
            CrashReport.postCatchedException(ignored);
        }

    }

    //SurfaceView
    if (view instanceof SurfaceView) {
        try {
            SurfaceView surfaceView = (SurfaceView) view;
            SurfaceHolder holder = surfaceView.getHolder();
            if (holder != null) {
                Surface surface = holder.getSurface();
                if (surface != null) {
                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
                        surface.release();
                    }
                }
            }
        } catch (Throwable ignored) {
            CrashReport.postCatchedException(ignored);
        }
    }

    view.destroyDrawingCache();
    view.clearAnimation();

    if (view instanceof ViewGroup) {
        ViewGroup viewGroup = (ViewGroup) view;
        int childCount = (viewGroup).getChildCount();
        for (i = 0; i < childCount; i++) {
            unBindView((viewGroup).getChildAt(i));
        }
    }
}

From source file:com.nextgis.mobile.fragment.MapFragment.java

private void fillStatusPanel(Location location) {
    if (mStatusPanelMode == 0)
        return;/*from   ww  w  . j a  va  2 s  .  c  o  m*/

    boolean needViewUpdate = true;
    boolean isCurrentOrientationOneLine = mStatusPanel.getChildCount() > 0
            && mStatusPanel.getChildAt(0).getId() == R.id.status_container_land;

    View panel;
    if (!isCurrentOrientationOneLine) {
        panel = mActivity.getLayoutInflater().inflate(R.layout.status_panel_land, mStatusPanel, false);
        defineTextViews(panel);
    } else {
        panel = mStatusPanel.getChildAt(0);
        needViewUpdate = false;
    }

    fillTextViews(location);

    if (!isFitOneLine()) {
        panel = mActivity.getLayoutInflater().inflate(R.layout.status_panel, mStatusPanel, false);
        defineTextViews(panel);
        fillTextViews(location);
        needViewUpdate = true;
    }

    if (needViewUpdate) {
        mStatusPanel.removeAllViews();
        panel.getBackground().setAlpha(128);
        mStatusPanel.addView(panel);
    }
}

From source file:org.telegram.ui.ActionBar.ActionBarLayout.java

public void showLastFragment() {
    if (fragmentsStack.isEmpty()) {
        return;//from  w  ww  . jav  a  2 s . co m
    }
    for (int a = 0; a < fragmentsStack.size() - 1; a++) {
        BaseFragment previousFragment = fragmentsStack.get(a);
        if (previousFragment.actionBar != null && previousFragment.actionBar.getAddToContainer()) {
            ViewGroup parent = (ViewGroup) previousFragment.actionBar.getParent();
            if (parent != null) {
                parent.removeView(previousFragment.actionBar);
            }
        }
        if (previousFragment.fragmentView != null) {
            ViewGroup parent = (ViewGroup) previousFragment.fragmentView.getParent();
            if (parent != null) {
                previousFragment.onPause();
                parent.removeView(previousFragment.fragmentView);
            }
        }
    }
    BaseFragment previousFragment = fragmentsStack.get(fragmentsStack.size() - 1);
    previousFragment.setParentLayout(this);
    View fragmentView = previousFragment.fragmentView;
    if (fragmentView == null) {
        fragmentView = previousFragment.createView(parentActivity);
    } else {
        ViewGroup parent = (ViewGroup) fragmentView.getParent();
        if (parent != null) {
            parent.removeView(fragmentView);
        }
    }
    if (previousFragment.actionBar != null && previousFragment.actionBar.getAddToContainer()) {
        if (removeActionBarExtraHeight) {
            previousFragment.actionBar.setOccupyStatusBar(false);
        }
        ViewGroup parent = (ViewGroup) previousFragment.actionBar.getParent();
        if (parent != null) {
            parent.removeView(previousFragment.actionBar);
        }
        containerView.addView(previousFragment.actionBar);
        previousFragment.actionBar.setTitleOverlayText(titleOverlayText);
    }
    containerView.addView(fragmentView);
    ViewGroup.LayoutParams layoutParams = fragmentView.getLayoutParams();
    layoutParams.width = LayoutHelper.MATCH_PARENT;
    layoutParams.height = LayoutHelper.MATCH_PARENT;
    fragmentView.setLayoutParams(layoutParams);
    previousFragment.onResume();
    currentActionBar = previousFragment.actionBar;
    if (!previousFragment.hasOwnBackground && fragmentView.getBackground() == null) {
        fragmentView.setBackgroundColor(ContextCompat.getColor(getContext(), R.color.background));
    }
}

From source file:org.telegram.ui.ActionBar.ActionBarLayout.java

private void prepareForMoving(MotionEvent ev) {
    maybeStartTracking = false;/*from ww  w  . j  a  v  a 2  s.co m*/
    startedTracking = true;
    startedTrackingX = (int) ev.getX();
    containerViewBack.setVisibility(View.VISIBLE);
    beginTrackingSent = false;

    BaseFragment lastFragment = fragmentsStack.get(fragmentsStack.size() - 2);
    View fragmentView = lastFragment.fragmentView;
    if (fragmentView == null) {
        fragmentView = lastFragment.createView(parentActivity);
    } else {
        ViewGroup parent = (ViewGroup) fragmentView.getParent();
        if (parent != null) {
            parent.removeView(fragmentView);
        }
    }
    ViewGroup parent = (ViewGroup) fragmentView.getParent();
    if (parent != null) {
        parent.removeView(fragmentView);
    }
    if (lastFragment.actionBar != null && lastFragment.actionBar.getAddToContainer()) {
        parent = (ViewGroup) lastFragment.actionBar.getParent();
        if (parent != null) {
            parent.removeView(lastFragment.actionBar);
        }
        if (removeActionBarExtraHeight) {
            lastFragment.actionBar.setOccupyStatusBar(false);
        }
        containerViewBack.addView(lastFragment.actionBar);
        lastFragment.actionBar.setTitleOverlayText(titleOverlayText);
    }
    containerViewBack.addView(fragmentView);
    ViewGroup.LayoutParams layoutParams = fragmentView.getLayoutParams();
    layoutParams.width = LayoutHelper.MATCH_PARENT;
    layoutParams.height = LayoutHelper.MATCH_PARENT;
    fragmentView.setLayoutParams(layoutParams);
    if (!lastFragment.hasOwnBackground && fragmentView.getBackground() == null) {
        fragmentView.setBackgroundColor(ContextCompat.getColor(getContext(), R.color.background));
    }
    lastFragment.onResume();
}

From source file:org.telegram.ui.ActionBar.ActionBarLayout.java

public boolean presentFragment(final BaseFragment fragment, final boolean removeLast,
        boolean forceWithoutAnimation, boolean check) {
    if (checkTransitionAnimation()
            || delegate != null && check
                    && !delegate.needPresentFragment(fragment, removeLast, forceWithoutAnimation, this)
            || !fragment.onFragmentCreate()) {
        return false;
    }//  ww  w.j a v a  2 s  .com
    if (parentActivity.getCurrentFocus() != null) {
        AndroidUtilities.hideKeyboard(parentActivity.getCurrentFocus());
    }
    boolean needAnimation = !forceWithoutAnimation && parentActivity
            .getSharedPreferences("mainconfig", Activity.MODE_PRIVATE).getBoolean("view_animations", true);

    final BaseFragment currentFragment = !fragmentsStack.isEmpty()
            ? fragmentsStack.get(fragmentsStack.size() - 1)
            : null;

    fragment.setParentLayout(this);
    View fragmentView = fragment.fragmentView;
    if (fragmentView == null) {
        fragmentView = fragment.createView(parentActivity);
    } else {
        ViewGroup parent = (ViewGroup) fragmentView.getParent();
        if (parent != null) {
            parent.removeView(fragmentView);
        }
    }
    if (fragment.actionBar != null && fragment.actionBar.getAddToContainer()) {
        if (removeActionBarExtraHeight) {
            fragment.actionBar.setOccupyStatusBar(false);
        }
        ViewGroup parent = (ViewGroup) fragment.actionBar.getParent();
        if (parent != null) {
            parent.removeView(fragment.actionBar);
        }
        containerViewBack.addView(fragment.actionBar);
        fragment.actionBar.setTitleOverlayText(titleOverlayText);
    }

    containerViewBack.addView(fragmentView);
    ViewGroup.LayoutParams layoutParams = fragmentView.getLayoutParams();
    layoutParams.width = LayoutHelper.MATCH_PARENT;
    layoutParams.height = LayoutHelper.MATCH_PARENT;
    fragmentView.setLayoutParams(layoutParams);
    fragmentsStack.add(fragment);
    fragment.onResume();
    currentActionBar = fragment.actionBar;
    if (!fragment.hasOwnBackground && fragmentView.getBackground() == null) {
        fragmentView.setBackgroundColor(ContextCompat.getColor(getContext(), R.color.background));
    }

    LinearLayoutContainer temp = containerView;
    containerView = containerViewBack;
    containerViewBack = temp;
    containerView.setVisibility(View.VISIBLE);
    setInnerTranslationX(0);

    bringChildToFront(containerView);
    if (!needAnimation) {
        presentFragmentInternalRemoveOld(removeLast, currentFragment);
        if (backgroundView != null) {
            backgroundView.setVisibility(VISIBLE);
        }
    }

    if (needAnimation) {
        if (useAlphaAnimations && fragmentsStack.size() == 1) {
            presentFragmentInternalRemoveOld(removeLast, currentFragment);

            transitionAnimationStartTime = System.currentTimeMillis();
            transitionAnimationInProgress = true;
            onOpenAnimationEndRunnable = new Runnable() {
                @Override
                public void run() {
                    fragment.onTransitionAnimationEnd(true, false);
                    fragment.onBecomeFullyVisible();
                }
            };
            ArrayList<Animator> animators = new ArrayList<>();
            animators.add(ObjectAnimator.ofFloat(this, "alpha", 0.0f, 1.0f));
            if (backgroundView != null) {
                backgroundView.setVisibility(VISIBLE);
                animators.add(ObjectAnimator.ofFloat(backgroundView, "alpha", 0.0f, 1.0f));
            }

            fragment.onTransitionAnimationStart(true, false);
            currentAnimation = new AnimatorSet();
            currentAnimation.playTogether(animators);
            currentAnimation.setInterpolator(accelerateDecelerateInterpolator);
            currentAnimation.setDuration(200);
            currentAnimation.addListener(new AnimatorListenerAdapterProxy() {
                @Override
                public void onAnimationEnd(Animator animation) {
                    onAnimationEndCheck(false);
                }
            });
            currentAnimation.start();
        } else {
            transitionAnimationStartTime = System.currentTimeMillis();
            transitionAnimationInProgress = true;
            onOpenAnimationEndRunnable = new Runnable() {
                @Override
                public void run() {
                    if (Build.VERSION.SDK_INT > 15) {
                        containerView.setLayerType(LAYER_TYPE_NONE, null);
                        containerViewBack.setLayerType(LAYER_TYPE_NONE, null);
                    }
                    presentFragmentInternalRemoveOld(removeLast, currentFragment);
                    fragment.onTransitionAnimationEnd(true, false);
                    fragment.onBecomeFullyVisible();
                    containerView.setTranslationX(0);
                }
            };
            fragment.onTransitionAnimationStart(true, false);
            AnimatorSet animation = fragment.onCustomTransitionAnimation(true, new Runnable() {
                @Override
                public void run() {
                    onAnimationEndCheck(false);
                }
            });
            if (animation == null) {
                containerView.setAlpha(0.0f);
                containerView.setTranslationX(48.0f);
                if (containerView.isKeyboardVisible || containerViewBack.isKeyboardVisible) {
                    waitingForKeyboardCloseRunnable = new Runnable() {
                        @Override
                        public void run() {
                            if (waitingForKeyboardCloseRunnable != this) {
                                return;
                            }
                            startLayoutAnimation(true, true);
                        }
                    };
                    AndroidUtilities.runOnUIThread(waitingForKeyboardCloseRunnable, 200);
                } else if (fragment.needDelayOpenAnimation()) {
                    delayedOpenAnimationRunnable = new Runnable() {
                        @Override
                        public void run() {
                            if (delayedOpenAnimationRunnable != this) {
                                return;
                            }
                            delayedOpenAnimationRunnable = null;
                            startLayoutAnimation(true, true);
                        }
                    };
                    AndroidUtilities.runOnUIThread(delayedOpenAnimationRunnable, 200);
                } else {
                    startLayoutAnimation(true, true);
                }
            } else {
                if (Build.VERSION.SDK_INT > 15) {
                    //containerView.setLayerType(LAYER_TYPE_HARDWARE, null);
                    //containerViewBack.setLayerType(LAYER_TYPE_HARDWARE, null);
                }
                containerView.setAlpha(1.0f);
                containerView.setTranslationX(0.0f);
                currentAnimation = animation;
            }
        }
    } else {
        if (backgroundView != null) {
            backgroundView.setAlpha(1.0f);
            backgroundView.setVisibility(VISIBLE);
        }
        fragment.onTransitionAnimationStart(true, false);
        fragment.onTransitionAnimationEnd(true, false);
        fragment.onBecomeFullyVisible();
    }
    return true;
}

From source file:org.telegram.ui.ActionBar.ActionBarLayout.java

public void closeLastFragment(boolean animated) {
    if (delegate != null && !delegate.needCloseLastFragment(this) || checkTransitionAnimation()
            || fragmentsStack.isEmpty()) {
        return;/*ww  w .j a  va2 s . co m*/
    }
    if (parentActivity.getCurrentFocus() != null) {
        AndroidUtilities.hideKeyboard(parentActivity.getCurrentFocus());
    }
    setInnerTranslationX(0);
    boolean needAnimation = animated && parentActivity.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE)
            .getBoolean("view_animations", true);
    final BaseFragment currentFragment = fragmentsStack.get(fragmentsStack.size() - 1);
    BaseFragment previousFragment = null;
    if (fragmentsStack.size() > 1) {
        previousFragment = fragmentsStack.get(fragmentsStack.size() - 2);
    }

    if (previousFragment != null) {
        LinearLayoutContainer temp = containerView;
        containerView = containerViewBack;
        containerViewBack = temp;
        containerView.setVisibility(View.VISIBLE);

        previousFragment.setParentLayout(this);
        View fragmentView = previousFragment.fragmentView;
        if (fragmentView == null) {
            fragmentView = previousFragment.createView(parentActivity);
        } else {
            ViewGroup parent = (ViewGroup) fragmentView.getParent();
            if (parent != null) {
                parent.removeView(fragmentView);
            }
        }
        if (previousFragment.actionBar != null && previousFragment.actionBar.getAddToContainer()) {
            if (removeActionBarExtraHeight) {
                previousFragment.actionBar.setOccupyStatusBar(false);
            }
            ViewGroup parent = (ViewGroup) previousFragment.actionBar.getParent();
            if (parent != null) {
                parent.removeView(previousFragment.actionBar);
            }
            containerView.addView(previousFragment.actionBar);
            previousFragment.actionBar.setTitleOverlayText(titleOverlayText);
        }
        containerView.addView(fragmentView);
        ViewGroup.LayoutParams layoutParams = fragmentView.getLayoutParams();
        layoutParams.width = LayoutHelper.MATCH_PARENT;
        layoutParams.height = LayoutHelper.MATCH_PARENT;
        fragmentView.setLayoutParams(layoutParams);
        previousFragment.onTransitionAnimationStart(true, true);
        currentFragment.onTransitionAnimationStart(false, false);
        previousFragment.onResume();
        currentActionBar = previousFragment.actionBar;
        if (!previousFragment.hasOwnBackground && fragmentView.getBackground() == null) {
            fragmentView.setBackgroundColor(ContextCompat.getColor(getContext(), R.color.background));
        }

        if (!needAnimation) {
            closeLastFragmentInternalRemoveOld(currentFragment);
        }

        if (needAnimation) {
            transitionAnimationStartTime = System.currentTimeMillis();
            transitionAnimationInProgress = true;
            final BaseFragment previousFragmentFinal = previousFragment;
            onCloseAnimationEndRunnable = new Runnable() {
                @Override
                public void run() {
                    if (Build.VERSION.SDK_INT > 15) {
                        containerView.setLayerType(LAYER_TYPE_NONE, null);
                        containerViewBack.setLayerType(LAYER_TYPE_NONE, null);
                    }
                    closeLastFragmentInternalRemoveOld(currentFragment);
                    containerViewBack.setTranslationX(0);
                    currentFragment.onTransitionAnimationEnd(false, false);
                    previousFragmentFinal.onTransitionAnimationEnd(true, true);
                    previousFragmentFinal.onBecomeFullyVisible();
                }
            };
            AnimatorSet animation = currentFragment.onCustomTransitionAnimation(false, new Runnable() {
                @Override
                public void run() {
                    onAnimationEndCheck(false);
                }
            });
            if (animation == null) {
                if (containerView.isKeyboardVisible || containerViewBack.isKeyboardVisible) {
                    waitingForKeyboardCloseRunnable = new Runnable() {
                        @Override
                        public void run() {
                            if (waitingForKeyboardCloseRunnable != this) {
                                return;
                            }
                            startLayoutAnimation(false, true);
                        }
                    };
                    AndroidUtilities.runOnUIThread(waitingForKeyboardCloseRunnable, 200);
                } else {
                    startLayoutAnimation(false, true);
                }
            } else {
                if (Build.VERSION.SDK_INT > 15) {
                    //containerView.setLayerType(LAYER_TYPE_HARDWARE, null);
                    //containerViewBack.setLayerType(LAYER_TYPE_HARDWARE, null);
                }
                currentAnimation = animation;
            }
        } else {
            currentFragment.onTransitionAnimationEnd(false, false);
            previousFragment.onTransitionAnimationEnd(true, true);
            previousFragment.onBecomeFullyVisible();
        }
    } else {
        if (useAlphaAnimations) {
            transitionAnimationStartTime = System.currentTimeMillis();
            transitionAnimationInProgress = true;

            onCloseAnimationEndRunnable = new Runnable() {
                @Override
                public void run() {
                    removeFragmentFromStackInternal(currentFragment);
                    setVisibility(GONE);
                    if (backgroundView != null) {
                        backgroundView.setVisibility(GONE);
                    }
                    if (drawerLayoutContainer != null) {
                        drawerLayoutContainer.setAllowOpenDrawer(true, false);
                    }
                }
            };

            ArrayList<Animator> animators = new ArrayList<>();
            animators.add(ObjectAnimator.ofFloat(this, "alpha", 1.0f, 0.0f));
            if (backgroundView != null) {
                animators.add(ObjectAnimator.ofFloat(backgroundView, "alpha", 1.0f, 0.0f));
            }

            currentAnimation = new AnimatorSet();
            currentAnimation.playTogether(animators);
            currentAnimation.setInterpolator(accelerateDecelerateInterpolator);
            currentAnimation.setDuration(200);
            currentAnimation.addListener(new AnimatorListenerAdapterProxy() {
                @Override
                public void onAnimationStart(Animator animation) {
                    transitionAnimationStartTime = System.currentTimeMillis();
                }

                @Override
                public void onAnimationEnd(Animator animation) {
                    onAnimationEndCheck(false);
                }
            });
            currentAnimation.start();
        } else {
            removeFragmentFromStackInternal(currentFragment);
            setVisibility(GONE);
            if (backgroundView != null) {
                backgroundView.setVisibility(GONE);
            }
        }
    }
}

From source file:com.taobao.weex.dom.transition.WXTransition.java

/**
 *  transform, opacity, backgroundcolor which not effect layout use android system animation in main thread.
 * */// w w w . j  ava  2 s .co m
private void doPendingTransformAnimation(int token) {
    if (transformAnimator != null) {
        transformAnimator.cancel();
        transformAnimator = null;
    }
    if (transformPendingUpdates.size() == 0) {
        return;
    }
    final View taregtView = getTargetView();
    if (taregtView == null) {
        return;
    }
    List<PropertyValuesHolder> holders = new ArrayList<>(8);
    String transform = WXUtils.getString(transformPendingUpdates.remove(Constants.Name.TRANSFORM), null);
    if (!TextUtils.isEmpty(transform)) {
        Map<Property<View, Float>, Float> properties = TransformParser.parseTransForm(transform,
                (int) domObject.getLayoutWidth(), (int) domObject.getLayoutHeight(),
                domObject.getViewPortWidth());
        PropertyValuesHolder[] transformHolders = TransformParser.toHolders(properties);
        for (PropertyValuesHolder holder : transformHolders) {
            holders.add(holder);
        }
        synchronized (targetStyles) {
            targetStyles.put(Constants.Name.TRANSFORM, transform);
        }
    }

    for (String property : properties) {
        if (!TRANSFORM_PROPERTIES.contains(property)) {
            continue;
        }
        if (!transformPendingUpdates.containsKey(property)) {
            continue;
        }
        Object value = transformPendingUpdates.remove(property);
        synchronized (targetStyles) {
            targetStyles.put(property, value);
        }
        switch (property) {
        case Constants.Name.OPACITY: {
            holders.add(PropertyValuesHolder.ofFloat(View.ALPHA, taregtView.getAlpha(),
                    WXUtils.getFloat(value, 1.0f)));
            taregtView.setLayerType(View.LAYER_TYPE_SOFTWARE, null); //hardware or none has bug on some platform
        }
            break;
        case Constants.Name.BACKGROUND_COLOR: {
            int fromColor = WXResourceUtils
                    .getColor(WXUtils.getString(domObject.getStyles().getBackgroundColor(), null), 0);
            int toColor = WXResourceUtils.getColor(WXUtils.getString(value, null), 0);
            if (WXViewUtils.getBorderDrawable(taregtView) != null) {
                fromColor = WXViewUtils.getBorderDrawable(taregtView).getColor();
            } else if (taregtView.getBackground() instanceof ColorDrawable) {
                fromColor = ((ColorDrawable) taregtView.getBackground()).getColor();
            }
            holders.add(PropertyValuesHolder.ofObject(new BackgroundColorProperty(), new ArgbEvaluator(),
                    fromColor, toColor));
        }
            break;
        default:
            break;
        }
    }

    if (token == lockToken.get()) {
        transformPendingUpdates.clear();
    }
    transformAnimator = ObjectAnimator.ofPropertyValuesHolder(taregtView,
            holders.toArray(new PropertyValuesHolder[holders.size()]));
    transformAnimator.setDuration((long) duration);
    if ((long) delay > 0) {
        transformAnimator.setStartDelay((long) delay);
    }
    if (interpolator != null) {
        transformAnimator.setInterpolator(interpolator);
    }
    transformAnimator.addListener(new AnimatorListenerAdapter() {
        boolean hasCancel = false;

        @Override
        public void onAnimationCancel(Animator animation) {
            super.onAnimationCancel(animation);
            hasCancel = true;
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            if (hasCancel) {
                return;
            }
            super.onAnimationEnd(animation);
            WXTransition.this.onTransitionAnimationEnd();
            if (WXEnvironment.isApkDebugable()) {
                WXLogUtils.d("WXTransition transform onTransitionAnimationEnd " + domObject.getRef());
            }
        }
    });
    transformAnimator.start();
}

From source file:com.t2.compassionMeditation.DeviceManagerActivity.java

/**
 * Handles UI button clicks/*  w  ww  .java2  s . c o m*/
 * @param v
 */
public void onButtonClick(final View v) {
    final int id = v.getId();
    switch (id) {

    // Present a list of all parameter types to allow the user
    // to associate a specific device (address) to a specific parameter
    // This association will be used in the main activities so that they
    // know the BT address of particular sensors to tell them to start/stop

    // The associations are stored in Shared pref
    //   key = param name (See R.array.parameter_names)
    //   value = BT address

    case R.id.parameter:
        final String address = (String) v.getTag();
        AlertDialog.Builder alertParamChooser = new AlertDialog.Builder(mInstance);
        alertParamChooser.setTitle("Select parameter for this device");
        //             mParamChooserAlert = alertParamChooser.create();

        alertParamChooser.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
            }
        });
        alertParamChooser.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
            }
        });
        alertParamChooser.setSingleChoiceItems(R.array.parameter_names, -1,
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, final int which) {
                        String[] paramNamesStringArray = getResources().getStringArray(R.array.parameter_names);
                        final String name = paramNamesStringArray[which];

                        // See which pamrameter is associated with this name
                        String device = SharedPref.getDeviceForParam(mInstance, name);
                        if (device != null && which != 0) {
                            AlertDialog.Builder alertWarning = new AlertDialog.Builder(mInstance);
                            String message = String.format(
                                    "Another sensor (%s) currently feeds this parameter. Please change this previous mapping before trying again",
                                    device);
                            alertWarning.setMessage(message);

                            alertWarning.setPositiveButton("OK", new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog, int whichButton) {
                                    mParamChooserAlert.dismiss();
                                }

                            });
                            alertWarning.setNegativeButton("Select Anyway",
                                    new DialogInterface.OnClickListener() {
                                        public void onClick(DialogInterface dialog, int whichButton) {
                                            Log.d(TAG, "param name = " + name + ", address = " + address);
                                            if (which != 0) {
                                                SharedPref.setParamForDevice(mInstance, name, address);
                                                v.getBackground().setColorFilter(Color.GREEN,
                                                        PorterDuff.Mode.MULTIPLY);
                                                ((Button) v.findViewById(R.id.parameter)).setText(name);
                                            } else {
                                                SharedPref.setParamForDevice(mInstance, name, address);
                                                v.getBackground().setColorFilter(Color.LTGRAY,
                                                        PorterDuff.Mode.MULTIPLY);
                                                ((Button) v.findViewById(R.id.parameter)).setText("Parameter");

                                            }

                                        }

                                    });

                            alertWarning.show();

                        } else {
                            // The parameter is currently not mapped to a sensor, so we can go ahead and map it
                            Log.d(TAG, "param name = " + name + ", address = " + address);
                            if (which != 0) {
                                SharedPref.setParamForDevice(mInstance, name, address);
                                v.getBackground().setColorFilter(Color.GREEN, PorterDuff.Mode.MULTIPLY);
                                ((Button) v.findViewById(R.id.parameter)).setText(name);
                            } else {
                                SharedPref.setParamForDevice(mInstance, name, address);
                                v.getBackground().setColorFilter(Color.LTGRAY, PorterDuff.Mode.MULTIPLY);
                                ((Button) v.findViewById(R.id.parameter)).setText("Parameter");

                            }
                        }
                    }
                });
        //            alert.show();   
        mParamChooserAlert = alertParamChooser.create();

        mParamChooserAlert.show();

        break;

    }
}

From source file:com.landenlabs.all_devtool.IconBaseFragment.java

/**
 * Display icon (drawable) information/*from w  ww. j  a  v a2 s. c  o  m*/
 *
 * @param iconInfo
 */
private void showIconDialog(IconInfo iconInfo) {
    Drawable iconD = iconInfo.getDrawable();
    String iconType = iconD.getClass().getSimpleName();

    LayoutInflater inflater = m_context.getLayoutInflater();
    final View dialogLayout = inflater.inflate(R.layout.icon_dlg, null);

    View shareBtn = dialogLayout.findViewById(R.id.icon_dlg_share);
    shareBtn.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            Utils.shareScreen(dialogLayout, "iconDetail", null);
        }
    });

    final TextView imageName = Ui.viewById(dialogLayout, R.id.icon_dlg_name);
    final TextView imageSize = Ui.viewById(dialogLayout, R.id.icon_dlg_size);
    final TextView imageType = Ui.viewById(dialogLayout, R.id.icon_dlg_type);
    final TextView imageExtra = Ui.viewById(dialogLayout, R.id.icon_dlg_extra);

    imageName.setText(iconInfo.fieldStr());
    imageSize.setText(String.format("Size: %d x %d", iconD.getIntrinsicWidth(), iconD.getIntrinsicHeight()));
    imageType.setText(iconType);

    final ImageView imageView = Ui.viewById(dialogLayout, R.id.icon_dlg_image);
    // imageView.setImageDrawable(iconD);
    boolean hasStates = iconD.isStateful();

    final View stateTitle = dialogLayout.findViewById(R.id.icon_dlg_state_title);
    stateTitle.setVisibility(hasStates ? View.VISIBLE : View.GONE);

    final TableRow row1 = Ui.viewById(dialogLayout, R.id.icon_dlg_state_row1);
    row1.removeAllViews();

    final TableRow row2 = Ui.viewById(dialogLayout, R.id.icon_dlg_state_row2);
    row2.removeAllViews();

    boolean showRows = false;
    String extraInfo = "";

    if (hasStates) {
        extraInfo = "StateFul";
        showRows = true;

        StateListDrawable stateListDrawable = (StateListDrawable) iconD;
        Set<Drawable> stateIcons = new HashSet<Drawable>();
        showStateIcon(imageView, row1, row2, stateListDrawable, android.R.attr.state_enabled, "Enabled",
                stateIcons);
        showStateIcon(imageView, row1, row2, stateListDrawable, android.R.attr.state_pressed, "Pressed",
                stateIcons);
        showStateIcon(imageView, row1, row2, stateListDrawable, android.R.attr.state_checked, "Checked",
                stateIcons);
        showStateIcon(imageView, row1, row2, stateListDrawable, android.R.attr.state_selected, "Selected",
                stateIcons);
    }

    if (iconType.equals(LayerDrawable.class.getSimpleName())) {
        showRows = true;
        LayerDrawable layerDrawable = (LayerDrawable) iconD;
        int layerCnt = layerDrawable.getNumberOfLayers();
        extraInfo = String.format(Locale.getDefault(), "Layers:%d", layerCnt);
        for (int layerIdx = 0; layerIdx < Math.min(layerCnt, 3); layerIdx++) {
            showLayerIcon(imageView, row1, row2, layerDrawable.getDrawable(layerIdx), layerIdx);
        }
    } else if (iconType.equals(AnimationDrawable.class.getSimpleName())) {
        final AnimationDrawable animationDrawable = (AnimationDrawable) iconD;
        extraInfo = String.format(Locale.getDefault(), "Frames:%d", animationDrawable.getNumberOfFrames());
        showRows = true;
        showAnimationBtns(imageView, animationDrawable, row1, row2);

        // Can't control animation at this time, drawable not rendered yet.
        // animationDrawable.stop();
    }

    row1.setVisibility(showRows ? View.VISIBLE : View.GONE);
    row2.setVisibility(showRows ? View.VISIBLE : View.GONE);

    imageExtra.setText(extraInfo);
    imageView.setImageDrawable(iconD);

    dialogLayout.findViewById(R.id.icon_dlg_whiteBtn).setOnClickListener(new View.OnClickListener() {
        @SuppressWarnings("deprecation")
        @Override
        public void onClick(View v) {
            imageView.setBackgroundDrawable(v.getBackground());
        }
    });

    dialogLayout.findViewById(R.id.icon_dlg_grayBtn).setOnClickListener(new View.OnClickListener() {
        @SuppressWarnings("deprecation")
        @Override
        public void onClick(View v) {
            imageView.setBackgroundDrawable(v.getBackground());
        }
    });

    dialogLayout.findViewById(R.id.icon_dlg_blackBtn).setOnClickListener(new View.OnClickListener() {
        @SuppressWarnings("deprecation")
        @Override
        public void onClick(View v) {
            imageView.setBackgroundDrawable(v.getBackground());
        }
    });

    dialogLayout.findViewById(R.id.icon_dlg_squaresBtn).setOnClickListener(new View.OnClickListener() {
        @SuppressWarnings("deprecation")
        @Override
        public void onClick(View v) {
            imageView.setBackgroundDrawable(v.getBackground());
        }
    });

    AlertDialog.Builder builder = new AlertDialog.Builder(m_context);
    builder.setView(dialogLayout);

    builder.setMessage("Icon").setCancelable(false).setPositiveButton("Close",
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    // if this button is clicked, close
                    dialog.cancel();
                }
            });

    builder.show();
}

From source file:com.cognizant.trumobi.PersonaLauncher.java

/**
 * ADW: Load the specified theme resource
 * /*from ww  w .ja v  a2s  .  co m*/
 * @param themeResources
 *            Resources from the theme package
 * @param themePackage
 *            the theme's package name
 * @param item_name
 *            the theme item name to load
 * @param item
 *            the View Item to apply the theme into
 * @param themeType
 *            Specify if the themed element will be a background or a
 *            foreground item
 */
public static void loadThemeResource(Resources themeResources, String themePackage, String item_name, View item,
        int themeType) {
    Drawable d = null;
    if (themeResources != null) {
        int resource_id = themeResources.getIdentifier(item_name, "drawable", themePackage);
        if (resource_id != 0) {
            try {
                d = themeResources.getDrawable(resource_id);
            } catch (Resources.NotFoundException e) {
                return;
            }
            if (themeType == THEME_ITEM_FOREGROUND && item instanceof ImageView) {
                // ADW remove the old drawable
                Drawable tmp = ((ImageView) item).getDrawable();
                if (tmp != null) {
                    tmp.setCallback(null);
                    tmp = null;
                }
                ((ImageView) item).setImageDrawable(d);
            } else {
                // ADW remove the old drawable
                Drawable tmp = item.getBackground();
                if (tmp != null) {
                    tmp.setCallback(null);
                    tmp = null;
                }
                item.setBackgroundDrawable(d);
            }
        }
    }
}