Search in sources :

Example 1 with TransitionDrawable

use of android.graphics.drawable.TransitionDrawable in project android_frameworks_base by ParanoidAndroid.

the class NavigationBarView method getIcons.

private void getIcons(Resources res) {
    mBackIcon = res.getDrawable(R.drawable.ic_sysbar_back);
    mBackLandIcon = res.getDrawable(R.drawable.ic_sysbar_back_land);
    mBackAltIcon = res.getDrawable(R.drawable.ic_sysbar_back_ime);
    mBackAltLandIcon = res.getDrawable(R.drawable.ic_sysbar_back_ime);
    mRecentsIcon = res.getDrawable(R.drawable.ic_sysbar_recent);
    mRecentsLandIcon = res.getDrawable(R.drawable.ic_sysbar_recent_land);
    mRecentsAltIcon = res.getDrawable(R.drawable.ic_sysbar_recent_clear);
    mRecentsAltLandIcon = res.getDrawable(R.drawable.ic_sysbar_recent_clear_land);
    // Only watch for per app color changes when the setting is in check
    if (ColorUtils.getPerAppColorState(mContext)) {
        // Reset all colors
        mCurrentBitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888);
        mCurrentCanvas = new Canvas(mCurrentBitmap);
        mCurrentCanvas.drawColor(0xFF000000);
        mCurrentBitmapDrawable = new BitmapDrawable(mCurrentBitmap);
        mNewBitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888);
        mNewCanvas = new Canvas(mNewBitmap);
        mNewCanvas.drawColor(0xFF000000);
        mNewBitmapDrawable = new BitmapDrawable(mNewBitmap);
        mTransition = new TransitionDrawable(new Drawable[] { mCurrentBitmapDrawable, mNewBitmapDrawable });
        setBackground(mTransition);
        mLastBackgroundColor = ColorUtils.getColorSettingInfo(mContext, Settings.System.NAV_BAR_COLOR);
        updateColor();
        mContext.getContentResolver().registerContentObserver(Settings.System.getUriFor(Settings.System.NAV_BAR_COLOR), false, new ContentObserver(new Handler()) {

            @Override
            public void onChange(boolean selfChange) {
                updateColor();
            }
        });
    }
}
Also used : TransitionDrawable(android.graphics.drawable.TransitionDrawable) Canvas(android.graphics.Canvas) ColorDrawable(android.graphics.drawable.ColorDrawable) Drawable(android.graphics.drawable.Drawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) TransitionDrawable(android.graphics.drawable.TransitionDrawable) Handler(android.os.Handler) BitmapDrawable(android.graphics.drawable.BitmapDrawable) ContentObserver(android.database.ContentObserver)

Example 2 with TransitionDrawable

use of android.graphics.drawable.TransitionDrawable in project android_frameworks_base by ParanoidAndroid.

the class BaseStatusBar method start.

public void start() {
    mWindowManager = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
    mWindowManagerService = WindowManagerGlobal.getWindowManagerService();
    mDisplay = mWindowManager.getDefaultDisplay();
    // set up
    mProvisioningObserver.onChange(false);
    mContext.getContentResolver().registerContentObserver(Settings.Global.getUriFor(Settings.Global.DEVICE_PROVISIONED), true, mProvisioningObserver);
    mBarService = IStatusBarService.Stub.asInterface(ServiceManager.getService(Context.STATUS_BAR_SERVICE));
    mStatusBarContainer = new FrameLayout(mContext);
    mLocale = mContext.getResources().getConfiguration().locale;
    mLayoutDirection = TextUtils.getLayoutDirectionFromLocale(mLocale);
    // Connect in to the status bar manager service
    StatusBarIconList iconList = new StatusBarIconList();
    ArrayList<IBinder> notificationKeys = new ArrayList<IBinder>();
    ArrayList<StatusBarNotification> notifications = new ArrayList<StatusBarNotification>();
    mCommandQueue = new CommandQueue(this, iconList);
    int[] switches = new int[7];
    ArrayList<IBinder> binders = new ArrayList<IBinder>();
    try {
        mBarService.registerStatusBar(mCommandQueue, iconList, notificationKeys, notifications, switches, binders);
    } catch (RemoteException ex) {
    // If the system process isn't there we're doomed anyway.
    }
    mHaloActive = Settings.System.getInt(mContext.getContentResolver(), Settings.System.HALO_ACTIVE, 0) == 1;
    createAndAddWindows();
    disable(switches[0]);
    setSystemUiVisibility(switches[1], 0xffffffff);
    topAppWindowChanged(switches[2] != 0);
    // StatusBarManagerService has a back up of IME token and it's restored here.
    setImeWindowStatus(binders.get(0), switches[3], switches[4]);
    setHardKeyboardStatus(switches[5] != 0, switches[6] != 0);
    // Set up the initial icon state
    int N = iconList.size();
    int viewIndex = 0;
    for (int i = 0; i < N; i++) {
        StatusBarIcon icon = iconList.getIcon(i);
        if (icon != null) {
            addIcon(iconList.getSlot(i), i, viewIndex, icon);
            viewIndex++;
        }
    }
    // Set up the initial notification state
    N = notificationKeys.size();
    if (N == notifications.size()) {
        for (int i = 0; i < N; i++) {
            addNotification(notificationKeys.get(i), notifications.get(i));
        }
    } else {
        Log.wtf(TAG, "Notification list length mismatch: keys=" + N + " notifications=" + notifications.size());
    }
    if (DEBUG) {
        Slog.d(TAG, String.format("init: icons=%d disabled=0x%08x lights=0x%08x menu=0x%08x imeButton=0x%08x", iconList.size(), switches[0], switches[1], switches[2], switches[3]));
    }
    mCurrentUserId = ActivityManager.getCurrentUser();
    IntentFilter filter = new IntentFilter();
    filter.addAction(Intent.ACTION_USER_SWITCHED);
    mContext.registerReceiver(new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            if (Intent.ACTION_USER_SWITCHED.equals(action)) {
                mCurrentUserId = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, -1);
                if (true)
                    Slog.v(TAG, "userId " + mCurrentUserId + " is in the house");
                userSwitched(mCurrentUserId);
            }
        }
    }, filter);
    // Only watch for per app color changes when the setting is in check
    if (ColorUtils.getPerAppColorState(mContext)) {
        // Reset all colors
        Bitmap currentBitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888);
        mCurrentCanvas = new Canvas(currentBitmap);
        mCurrentCanvas.drawColor(0xFF000000);
        BitmapDrawable currentBitmapDrawable = new BitmapDrawable(currentBitmap);
        Bitmap newBitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888);
        mNewCanvas = new Canvas(newBitmap);
        mNewCanvas.drawColor(0xFF000000);
        BitmapDrawable newBitmapDrawable = new BitmapDrawable(newBitmap);
        mTransition = new TransitionDrawable(new Drawable[] { currentBitmapDrawable, newBitmapDrawable });
        mBarView.setBackground(mTransition);
        mLastIconColor = ColorUtils.getColorSettingInfo(mContext, Settings.System.STATUS_ICON_COLOR);
        mLastBackgroundColor = ColorUtils.getColorSettingInfo(mContext, ExtendedPropertiesUtils.isTablet() ? Settings.System.NAV_BAR_COLOR : Settings.System.STATUS_BAR_COLOR);
        updateIconColor();
        updateBackgroundColor();
        // Listen for status bar icon color changes
        mContext.getContentResolver().registerContentObserver(Settings.System.getUriFor(Settings.System.STATUS_ICON_COLOR), false, new ContentObserver(new Handler()) {

            @Override
            public void onChange(boolean selfChange) {
                updateIconColor();
            }
        });
        // Listen for status bar background color changes
        mContext.getContentResolver().registerContentObserver(Settings.System.getUriFor(ExtendedPropertiesUtils.isTablet() ? Settings.System.NAV_BAR_COLOR : Settings.System.STATUS_BAR_COLOR), false, new ContentObserver(new Handler()) {

            @Override
            public void onChange(boolean selfChange) {
                updateBackgroundColor();
            }
        });
        // Listen for per-app-color state changes, this one will revert to stock colors all over
        mContext.getContentResolver().registerContentObserver(Settings.System.getUriFor(Settings.System.PER_APP_COLOR), false, new ContentObserver(new Handler()) {

            @Override
            public void onChange(boolean selfChange) {
                if (!ColorUtils.getPerAppColorState(mContext)) {
                    for (int i = 0; i < ExtendedPropertiesUtils.PARANOID_COLORS_COUNT; i++) {
                        ColorUtils.ColorSettingInfo colorInfo = ColorUtils.getColorSettingInfo(mContext, Settings.System.STATUS_ICON_COLOR);
                        ColorUtils.setColor(mContext, ExtendedPropertiesUtils.PARANOID_COLORS_SETTINGS[i], colorInfo.systemColorString, "NULL", 1, 250);
                    }
                }
            }
        });
    }
    attachPie();
    // Listen for PIE gravity
    mContext.getContentResolver().registerContentObserver(Settings.System.getUriFor(Settings.System.PIE_GRAVITY), false, new ContentObserver(new Handler()) {

        @Override
        public void onChange(boolean selfChange) {
            updatePieControls();
        }
    });
    // Listen for HALO state
    mContext.getContentResolver().registerContentObserver(Settings.System.getUriFor(Settings.System.HALO_ACTIVE), false, new ContentObserver(new Handler()) {

        @Override
        public void onChange(boolean selfChange) {
            updateHalo();
        }
    });
    mContext.getContentResolver().registerContentObserver(Settings.System.getUriFor(Settings.System.HALO_SIZE), false, new ContentObserver(new Handler()) {

        @Override
        public void onChange(boolean selfChange) {
            restartHalo();
        }
    });
    updateHalo();
    SettingsObserver settingsObserver = new SettingsObserver(new Handler());
    settingsObserver.observe();
}
Also used : ArrayList(java.util.ArrayList) IBinder(android.os.IBinder) Bitmap(android.graphics.Bitmap) StatusBarNotification(android.service.notification.StatusBarNotification) StatusBarIcon(com.android.internal.statusbar.StatusBarIcon) ContentObserver(android.database.ContentObserver) Context(android.content.Context) IntentFilter(android.content.IntentFilter) TransitionDrawable(android.graphics.drawable.TransitionDrawable) StatusBarIconList(com.android.internal.statusbar.StatusBarIconList) Canvas(android.graphics.Canvas) Drawable(android.graphics.drawable.Drawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) TransitionDrawable(android.graphics.drawable.TransitionDrawable) Handler(android.os.Handler) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) BitmapDrawable(android.graphics.drawable.BitmapDrawable) BroadcastReceiver(android.content.BroadcastReceiver) Paint(android.graphics.Paint) FrameLayout(android.widget.FrameLayout) RemoteException(android.os.RemoteException)

Example 3 with TransitionDrawable

use of android.graphics.drawable.TransitionDrawable in project android_frameworks_base by ResurrectionRemix.

the class AbsListView method onTouchUp.

private void onTouchUp(MotionEvent ev) {
    switch(mTouchMode) {
        case TOUCH_MODE_DOWN:
        case TOUCH_MODE_TAP:
        case TOUCH_MODE_DONE_WAITING:
            final int motionPosition = mMotionPosition;
            final View child = getChildAt(motionPosition - mFirstPosition);
            if (child != null) {
                if (mTouchMode != TOUCH_MODE_DOWN) {
                    child.setPressed(false);
                }
                final float x = ev.getX();
                final boolean inList = x > mListPadding.left && x < getWidth() - mListPadding.right;
                if (inList && !child.hasFocusable()) {
                    if (mPerformClick == null) {
                        mPerformClick = new PerformClick();
                    }
                    final AbsListView.PerformClick performClick = mPerformClick;
                    performClick.mClickMotionPosition = motionPosition;
                    performClick.rememberWindowAttachCount();
                    mResurrectToPosition = motionPosition;
                    if (mTouchMode == TOUCH_MODE_DOWN || mTouchMode == TOUCH_MODE_TAP) {
                        removeCallbacks(mTouchMode == TOUCH_MODE_DOWN ? mPendingCheckForTap : mPendingCheckForLongPress);
                        mLayoutMode = LAYOUT_NORMAL;
                        if (!mDataChanged && mAdapter.isEnabled(motionPosition)) {
                            mTouchMode = TOUCH_MODE_TAP;
                            setSelectedPositionInt(mMotionPosition);
                            layoutChildren();
                            child.setPressed(true);
                            positionSelector(mMotionPosition, child);
                            setPressed(true);
                            if (mSelector != null) {
                                Drawable d = mSelector.getCurrent();
                                if (d != null && d instanceof TransitionDrawable) {
                                    ((TransitionDrawable) d).resetTransition();
                                }
                                mSelector.setHotspot(x, ev.getY());
                            }
                            if (mTouchModeReset != null) {
                                removeCallbacks(mTouchModeReset);
                            }
                            mTouchModeReset = new Runnable() {

                                @Override
                                public void run() {
                                    mTouchModeReset = null;
                                    mTouchMode = TOUCH_MODE_REST;
                                    child.setPressed(false);
                                    setPressed(false);
                                    if (!mDataChanged && !mIsDetaching && isAttachedToWindow()) {
                                        performClick.run();
                                    }
                                }
                            };
                            postDelayed(mTouchModeReset, ViewConfiguration.getPressedStateDuration());
                        } else {
                            mTouchMode = TOUCH_MODE_REST;
                            updateSelectorState();
                        }
                        return;
                    } else if (!mDataChanged && mAdapter.isEnabled(motionPosition)) {
                        performClick.run();
                    }
                }
            }
            mTouchMode = TOUCH_MODE_REST;
            updateSelectorState();
            break;
        case TOUCH_MODE_SCROLL:
            final int childCount = getChildCount();
            if (childCount > 0) {
                final int firstChildTop = getChildAt(0).getTop();
                final int lastChildBottom = getChildAt(childCount - 1).getBottom();
                final int contentTop = mListPadding.top;
                final int contentBottom = getHeight() - mListPadding.bottom;
                if (mFirstPosition == 0 && firstChildTop >= contentTop && mFirstPosition + childCount < mItemCount && lastChildBottom <= getHeight() - contentBottom) {
                    mTouchMode = TOUCH_MODE_REST;
                    reportScrollStateChange(OnScrollListener.SCROLL_STATE_IDLE);
                } else {
                    final VelocityTracker velocityTracker = mVelocityTracker;
                    velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity);
                    final int initialVelocity = (int) (velocityTracker.getYVelocity(mActivePointerId) * mVelocityScale);
                    // Fling if we have enough velocity and we aren't at a boundary.
                    // Since we can potentially overfling more than we can overscroll, don't
                    // allow the weird behavior where you can scroll to a boundary then
                    // fling further.
                    boolean flingVelocity = Math.abs(initialVelocity) > mMinimumVelocity;
                    if (flingVelocity && !((mFirstPosition == 0 && firstChildTop == contentTop - mOverscrollDistance) || (mFirstPosition + childCount == mItemCount && lastChildBottom == contentBottom + mOverscrollDistance))) {
                        if (!dispatchNestedPreFling(0, -initialVelocity)) {
                            if (mFlingRunnable == null) {
                                mFlingRunnable = new FlingRunnable();
                            }
                            reportScrollStateChange(OnScrollListener.SCROLL_STATE_FLING);
                            mFlingRunnable.start(-initialVelocity);
                            dispatchNestedFling(0, -initialVelocity, true);
                        } else {
                            mTouchMode = TOUCH_MODE_REST;
                            reportScrollStateChange(OnScrollListener.SCROLL_STATE_IDLE);
                        }
                    } else {
                        mTouchMode = TOUCH_MODE_REST;
                        reportScrollStateChange(OnScrollListener.SCROLL_STATE_IDLE);
                        if (mFlingRunnable != null) {
                            mFlingRunnable.endFling();
                        }
                        if (mPositionScroller != null) {
                            mPositionScroller.stop();
                        }
                        if (flingVelocity && !dispatchNestedPreFling(0, -initialVelocity)) {
                            dispatchNestedFling(0, -initialVelocity, false);
                        }
                    }
                }
            } else {
                mTouchMode = TOUCH_MODE_REST;
                reportScrollStateChange(OnScrollListener.SCROLL_STATE_IDLE);
            }
            break;
        case TOUCH_MODE_OVERSCROLL:
            if (mFlingRunnable == null) {
                mFlingRunnable = new FlingRunnable();
            }
            final VelocityTracker velocityTracker = mVelocityTracker;
            velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity);
            final int initialVelocity = (int) velocityTracker.getYVelocity(mActivePointerId);
            reportScrollStateChange(OnScrollListener.SCROLL_STATE_FLING);
            if (Math.abs(initialVelocity) > mMinimumVelocity) {
                mFlingRunnable.startOverfling(-initialVelocity);
            } else {
                mFlingRunnable.startSpringback();
            }
            break;
    }
    setPressed(false);
    if (mEdgeGlowTop != null) {
        mEdgeGlowTop.onRelease();
        mEdgeGlowBottom.onRelease();
    }
    // Need to redraw since we probably aren't drawing the selector anymore
    invalidate();
    removeCallbacks(mPendingCheckForLongPress);
    recycleVelocityTracker();
    mActivePointerId = INVALID_POINTER;
    if (PROFILE_SCROLLING) {
        if (mScrollProfilingStarted) {
            Debug.stopMethodTracing();
            mScrollProfilingStarted = false;
        }
    }
    if (mScrollStrictSpan != null) {
        mScrollStrictSpan.finish();
        mScrollStrictSpan = null;
    }
}
Also used : TransitionDrawable(android.graphics.drawable.TransitionDrawable) VelocityTracker(android.view.VelocityTracker) Drawable(android.graphics.drawable.Drawable) TransitionDrawable(android.graphics.drawable.TransitionDrawable) View(android.view.View)

Example 4 with TransitionDrawable

use of android.graphics.drawable.TransitionDrawable in project AndroidTraining by mixi-inc.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    final Handler handler = new Handler();
    final Timer timer = new Timer();
    // 5秒ごとにレベルを変更するタスク
    final Drawable levelListDrawable = findViewById(R.id.LevelListButton).getBackground();
    timer.scheduleAtFixedRate(new TimerTask() {

        @Override
        public void run() {
            final int level = levelListDrawable.getLevel();
            handler.post(new Runnable() {

                @Override
                public void run() {
                    if (level == 0) {
                        levelListDrawable.setLevel(1);
                    } else {
                        levelListDrawable.setLevel(0);
                    }
                }
            });
        }
    }, TIMER_TASK_DELAY, TIMER_TASK_PERIOD);
    // クロスフェードを開始する
    final TransitionDrawable transition = (TransitionDrawable) findViewById(R.id.TransitionView).getBackground();
    transition.startTransition(TRANSITION_DURATION);
    // 5秒ごとにレベルを変更し、クリップの範囲を変化させるタスク
    final ClipDrawable clipDrawable = (ClipDrawable) findViewById(R.id.ClipView).getBackground();
    timer.scheduleAtFixedRate(new TimerTask() {

        @Override
        public void run() {
            handler.post(new Runnable() {

                @Override
                public void run() {
                    clipDrawable.setLevel(clipDrawable.getLevel() + 1000);
                }
            });
        }
    }, TIMER_TASK_DELAY, TIMER_TASK_PERIOD);
    // スケールのレベルを変更する
    ScaleDrawable scale = (ScaleDrawable) findViewById(R.id.ScaleView).getBackground();
    scale.setLevel(1);
}
Also used : ScaleDrawable(android.graphics.drawable.ScaleDrawable) TransitionDrawable(android.graphics.drawable.TransitionDrawable) Timer(java.util.Timer) TimerTask(java.util.TimerTask) TransitionDrawable(android.graphics.drawable.TransitionDrawable) ClipDrawable(android.graphics.drawable.ClipDrawable) Drawable(android.graphics.drawable.Drawable) ScaleDrawable(android.graphics.drawable.ScaleDrawable) Handler(android.os.Handler) ClipDrawable(android.graphics.drawable.ClipDrawable)

Example 5 with TransitionDrawable

use of android.graphics.drawable.TransitionDrawable in project UltimateAndroid by cymcsg.

the class ViewpagerSlidingTabsActivity method changeColor.

private void changeColor(int newColor) {
    tabs.setIndicatorColor(newColor);
    // change ActionBar color just if an ActionBar is available
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        Drawable colorDrawable = new ColorDrawable(newColor);
        Drawable bottomDrawable = getResources().getDrawable(R.drawable.view_sliding_tab_actionbar_bottom);
        LayerDrawable ld = new LayerDrawable(new Drawable[] { colorDrawable, bottomDrawable });
        if (oldBackground == null) {
            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
                ld.setCallback(drawableCallback);
            } else {
                getActionBar().setBackgroundDrawable(ld);
            }
        } else {
            TransitionDrawable td = new TransitionDrawable(new Drawable[] { oldBackground, ld });
            // https://github.com/android/platform_frameworks_base/commit/a7cc06d82e45918c37429a59b14545c6a57db4e4
            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
                td.setCallback(drawableCallback);
            } else {
                getActionBar().setBackgroundDrawable(td);
            }
            td.startTransition(200);
        }
        oldBackground = ld;
        // http://stackoverflow.com/questions/11002691/actionbar-setbackgrounddrawable-nulling-background-from-thread-handler
        getActionBar().setDisplayShowTitleEnabled(false);
        getActionBar().setDisplayShowTitleEnabled(true);
    }
    currentColor = newColor;
}
Also used : TransitionDrawable(android.graphics.drawable.TransitionDrawable) ColorDrawable(android.graphics.drawable.ColorDrawable) LayerDrawable(android.graphics.drawable.LayerDrawable) LayerDrawable(android.graphics.drawable.LayerDrawable) ColorDrawable(android.graphics.drawable.ColorDrawable) Drawable(android.graphics.drawable.Drawable) TransitionDrawable(android.graphics.drawable.TransitionDrawable)

Aggregations

TransitionDrawable (android.graphics.drawable.TransitionDrawable)96 Drawable (android.graphics.drawable.Drawable)61 ColorDrawable (android.graphics.drawable.ColorDrawable)35 BitmapDrawable (android.graphics.drawable.BitmapDrawable)31 View (android.view.View)28 VelocityTracker (android.view.VelocityTracker)11 ImageView (android.widget.ImageView)10 Rect (android.graphics.Rect)9 Handler (android.os.Handler)8 Test (org.junit.Test)6 Bitmap (android.graphics.Bitmap)5 LayerDrawable (android.graphics.drawable.LayerDrawable)5 GradientDrawable (android.graphics.drawable.GradientDrawable)3 RippleDrawable (android.graphics.drawable.RippleDrawable)3 SuppressLint (android.annotation.SuppressLint)2 Intent (android.content.Intent)2 ColorStateList (android.content.res.ColorStateList)2 Resources (android.content.res.Resources)2 ContentObserver (android.database.ContentObserver)2 Canvas (android.graphics.Canvas)2