Example usage for android.content.res Resources getInteger

List of usage examples for android.content.res Resources getInteger

Introduction

In this page you can find the example usage for android.content.res Resources getInteger.

Prototype

public int getInteger(@IntegerRes int id) throws NotFoundException 

Source Link

Document

Return an integer associated with a particular resource ID.

Usage

From source file:com.android.launcher3.Workspace.java

/**
 * Used to inflate the Workspace from XML.
 *
 * @param context The application's context.
 * @param attrs The attributes set containing the Workspace's customization values.
 * @param defStyle Unused./* w  ww.j av  a2  s.co m*/
 */
public Workspace(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    mContentIsRefreshable = false;

    mOutlineHelper = HolographicOutlineHelper.obtain(context);

    mDragEnforcer = new DropTarget.DragEnforcer(context);
    // With workspace, data is available straight from the get-go
    setDataIsReady();

    mLauncher = (Launcher) context;
    final Resources res = getResources();
    mWorkspaceFadeInAdjacentScreens = LauncherAppState.getInstance().getDynamicGrid().getDeviceProfile()
            .shouldFadeAdjacentWorkspaceScreens();
    mFadeInAdjacentScreens = false;
    mWallpaperManager = WallpaperManager.getInstance(context);

    LauncherAppState app = LauncherAppState.getInstance();
    DeviceProfile grid = app.getDynamicGrid().getDeviceProfile();
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.Workspace, defStyle, 0);
    mSpringLoadedShrinkFactor = res.getInteger(R.integer.config_workspaceSpringLoadShrinkPercentage) / 100.0f;
    mOverviewModeShrinkFactor = grid.getOverviewModeScale();
    mCameraDistance = res.getInteger(R.integer.config_cameraDistance);
    mOriginalDefaultPage = mDefaultPage = a.getInt(R.styleable.Workspace_defaultScreen, 1);
    a.recycle();

    setOnHierarchyChangeListener(this);
    setHapticFeedbackEnabled(false);

    initWorkspace();

    // Disable multitouch across the workspace/all apps/customize tray
    setMotionEventSplittingEnabled(true);
    setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_YES);
}

From source file:com.tct.mail.utils.NotificationUtils.java

private static void configureLatestEventInfoFromConversation(final Context context, final Account account,
        final FolderPreferences folderPreferences, final NotificationCompat.Builder notification,
        final NotificationCompat.WearableExtender wearableExtender,
        final Map<Integer, NotificationBuilders> msgNotifications, final int summaryNotificationId,
        final Cursor conversationCursor, final PendingIntent clickIntent, final Intent notificationIntent,
        final int unreadCount, final int unseenCount, final Folder folder, final long when,
        final ContactPhotoFetcher photoFetcher) {
    final Resources res = context.getResources();
    final String notificationAccountDisplayName = account.getDisplayName();
    final String notificationAccountEmail = account.getEmailAddress();
    final boolean multipleUnseen = unseenCount > 1;

    LogUtils.i(LOG_TAG, "Showing notification with unreadCount of %d and unseenCount of %d", unreadCount,
            unseenCount);//from  w  w w. j  ava  2  s  .c om

    String notificationTicker = null;

    // Boolean indicating that this notification is for a non-inbox label.
    final boolean isInbox = folder.folderUri.fullUri.equals(account.settings.defaultInbox);

    // Notification label name for user label notifications.
    final String notificationLabelName = isInbox ? null : folder.name;

    if (multipleUnseen) {
        // Build the string that describes the number of new messages
        final String newMessagesString = createTitle(context, unseenCount);

        // Use the default notification icon
        notification
                .setLargeIcon(getDefaultNotificationIcon(context, folder, true /* multiple new messages */));

        // The ticker initially start as the new messages string.
        notificationTicker = newMessagesString;

        // The title of the notification is the new messages string
        notification.setContentTitle(newMessagesString);

        // TODO(skennedy) Can we remove this check?
        if (com.tct.mail.utils.Utils.isRunningJellybeanOrLater()) {
            // For a new-style notification
            final int maxNumDigestItems = context.getResources()
                    .getInteger(R.integer.max_num_notification_digest_items);

            // The body of the notification is the account name, or the label name.
            notification.setSubText(isInbox ? notificationAccountDisplayName : notificationLabelName);

            final NotificationCompat.InboxStyle digest = new NotificationCompat.InboxStyle(notification);

            // Group by account and folder
            final String notificationGroupKey = createGroupKey(account, folder);
            notification.setGroup(notificationGroupKey).setGroupSummary(true);

            ConfigResult firstResult = null;
            int numDigestItems = 0;
            do {
                final Conversation conversation = new Conversation(conversationCursor);

                if (!conversation.read) {
                    boolean multipleUnreadThread = false;
                    // TODO(cwren) extract this pattern into a helper

                    Cursor cursor = null;
                    MessageCursor messageCursor = null;
                    try {
                        final Uri.Builder uriBuilder = conversation.messageListUri.buildUpon();
                        uriBuilder.appendQueryParameter(UIProvider.LABEL_QUERY_PARAMETER,
                                notificationLabelName);
                        cursor = context.getContentResolver().query(uriBuilder.build(),
                                UIProvider.MESSAGE_PROJECTION, null, null, null);
                        messageCursor = new MessageCursor(cursor);

                        String from = "";
                        String fromAddress = "";
                        if (messageCursor.moveToPosition(messageCursor.getCount() - 1)) {
                            final Message message = messageCursor.getMessage();
                            fromAddress = message.getFrom();
                            if (fromAddress == null) {
                                fromAddress = "";
                            }
                            from = getDisplayableSender(fromAddress);
                        }
                        while (messageCursor.moveToPosition(messageCursor.getPosition() - 1)) {
                            final Message message = messageCursor.getMessage();
                            if (!message.read && !fromAddress.contentEquals(message.getFrom())) {
                                multipleUnreadThread = true;
                                break;
                            }
                        }
                        final SpannableStringBuilder sendersBuilder;
                        if (multipleUnreadThread) {
                            final int sendersLength = res.getInteger(R.integer.swipe_senders_length);

                            sendersBuilder = getStyledSenders(context, conversationCursor, sendersLength,
                                    notificationAccountEmail);
                        } else {
                            sendersBuilder = new SpannableStringBuilder(getWrappedFromString(from));
                        }
                        //TS: zheng.zou 2015-03-20 EMAIL BUGFIX_-954980 MOD_S
                        CharSequence digestLine = getSingleMessageInboxLine(context, sendersBuilder.toString(),
                                ConversationItemView.filterTag(context, conversation.subject),
                                conversation.getSnippet());
                        if (digestLine == null) {
                            digestLine = "";
                        }
                        //TS: zheng.zou 2015-03-20 EMAIL BUGFIX_-954980 MOD_E
                        digest.addLine(digestLine);
                        numDigestItems++;

                        // Adding conversation notification for Wear.
                        NotificationCompat.Builder conversationNotif = new NotificationCompat.Builder(context);

                        // TODO(shahrk) - fix for multiple mail
                        // Check that the group's folder is assigned an icon res (one of the
                        // 4 sections). If it is, we can add the gmail badge. If not, it is
                        // accompanied by the multiple_mail_24dp icon and we don't want a badge
                        // if (folder.notificationIconResId != 0) {
                        conversationNotif.setSmallIcon(R.drawable.ic_notification_mail_24dp);

                        if (com.tct.mail.utils.Utils.isRunningLOrLater()) {
                            conversationNotif.setColor(
                                    context.getResources().getColor(R.color.notification_icon_mail_orange));
                        }
                        conversationNotif.setContentText(digestLine);
                        Intent conversationNotificationIntent = createViewConversationIntent(context, account,
                                folder, conversationCursor);
                        PendingIntent conversationClickIntent = createClickPendingIntent(context,
                                conversationNotificationIntent);
                        conversationNotif.setContentIntent(conversationClickIntent);
                        conversationNotif.setAutoCancel(true);

                        // Conversations are sorted in descending order, but notification sort
                        // key is in ascending order.  Invert the order key to get the right
                        // order.  Left pad 19 zeros because it's a long.
                        String groupSortKey = String.format("%019d", (Long.MAX_VALUE - conversation.orderKey));
                        conversationNotif.setGroup(notificationGroupKey);
                        conversationNotif.setSortKey(groupSortKey);

                        int conversationNotificationId = getNotificationId(summaryNotificationId,
                                conversation.hashCode());

                        final NotificationCompat.WearableExtender conversationWearExtender = new NotificationCompat.WearableExtender();
                        final ConfigResult result = configureNotifForOneConversation(context, account,
                                folderPreferences, conversationNotif, conversationWearExtender,
                                conversationCursor, notificationIntent, folder, when, res,
                                notificationAccountDisplayName, notificationAccountEmail, isInbox,
                                notificationLabelName, conversationNotificationId, photoFetcher);
                        // TS: chenyanhua 2015-02-11 EMAIL BUGFIX-926747 ADD_S
                        result.contactIconInfo = getContactIcon(context, folder, photoFetcher);
                        notification.setLargeIcon(result.contactIconInfo.icon);
                        // TS: chenyanhua 2015-02-11 EMAIL BUGFIX-926747 ADD_E
                        msgNotifications.put(conversationNotificationId,
                                NotificationBuilders.of(conversationNotif, conversationWearExtender));

                        if (firstResult == null) {
                            firstResult = result;
                        }
                    } finally {
                        if (messageCursor != null) {
                            messageCursor.close();
                        }
                        if (cursor != null) {
                            cursor.close();
                        }
                    }
                }
            } while (numDigestItems <= maxNumDigestItems && conversationCursor.moveToNext());

            if (firstResult != null && firstResult.contactIconInfo != null) {
                wearableExtender.setBackground(firstResult.contactIconInfo.wearableBg);
            } else {
                LogUtils.w(LOG_TAG, "First contact icon is null!");
                wearableExtender.setBackground(getDefaultWearableBg(context));
            }
        } else {
            // The body of the notification is the account name, or the label name.
            notification.setContentText(isInbox ? notificationAccountDisplayName : notificationLabelName);
        }
    } else {
        // For notifications for a single new conversation, we want to get the information
        // from the conversation

        // Move the cursor to the most recent unread conversation
        seekToLatestUnreadConversation(conversationCursor);

        final ConfigResult result = configureNotifForOneConversation(context, account, folderPreferences,
                notification, wearableExtender, conversationCursor, notificationIntent, folder, when, res,
                notificationAccountDisplayName, notificationAccountEmail, isInbox, notificationLabelName,
                summaryNotificationId, photoFetcher);
        notificationTicker = result.notificationTicker;

        if (result.contactIconInfo != null) {
            wearableExtender.setBackground(result.contactIconInfo.wearableBg);
        } else {
            wearableExtender.setBackground(getDefaultWearableBg(context));
        }
    }

    // Build the notification ticker
    if (notificationLabelName != null && notificationTicker != null) {
        // This is a per label notification, format the ticker with that information
        notificationTicker = res.getString(R.string.label_notification_ticker, notificationLabelName,
                notificationTicker);
    }

    if (notificationTicker != null) {
        // If we didn't generate a notification ticker, it will default to account name
        notification.setTicker(notificationTicker);
    }

    // Set the number in the notification
    if (unreadCount > 1) {
        notification.setNumber(unreadCount);
    }

    notification.setContentIntent(clickIntent);
}

From source file:g7.bluesky.launcher3.Launcher.java

private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded,
        final AppsCustomizePagedView.ContentType contentType) {
    if (mStateAnimation != null) {
        mStateAnimation.setDuration(0);//from   w ww . jav  a 2 s  . c  o m
        mStateAnimation.cancel();
        mStateAnimation = null;
    }

    boolean material = Utilities.isLmpOrAbove();

    final Resources res = getResources();

    final int duration = res.getInteger(R.integer.config_appsCustomizeZoomInTime);
    final int fadeDuration = res.getInteger(R.integer.config_appsCustomizeFadeInTime);
    final int revealDuration = res.getInteger(R.integer.config_appsCustomizeRevealTime);
    final int itemsAlphaStagger = res.getInteger(R.integer.config_appsCustomizeItemsAlphaStagger);

    final float scale = (float) res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
    final View fromView = mWorkspace;
    final AppsCustomizeTabHost toView = mAppsCustomizeTabHost;

    final ArrayList<View> layerViews = new ArrayList<View>();

    Workspace.State workspaceState = contentType == AppsCustomizePagedView.ContentType.Widgets
            ? Workspace.State.OVERVIEW_HIDDEN
            : Workspace.State.NORMAL_HIDDEN;
    Animator workspaceAnim = mWorkspace.getChangeStateAnimation(workspaceState, animated, layerViews);
    if (!LauncherAppState.isDisableAllApps() || contentType == AppsCustomizePagedView.ContentType.Widgets) {
        // Set the content type for the all apps/widgets space
        mAppsCustomizeTabHost.setContentTypeImmediate(contentType);
    }

    // If for some reason our views aren't initialized, don't animate
    boolean initialized = getAllAppsButton() != null;

    if (animated && initialized) {
        mStateAnimation = LauncherAnimUtils.createAnimatorSet();
        final AppsCustomizePagedView content = (AppsCustomizePagedView) toView
                .findViewById(R.id.apps_customize_pane_content);

        final View page = content.getPageAt(content.getCurrentPage());
        final View revealView = toView.findViewById(R.id.fake_page);

        final boolean isWidgetTray = contentType == AppsCustomizePagedView.ContentType.Widgets;
        if (isWidgetTray) {
            revealView.setBackground(ContextCompat.getDrawable(this, R.drawable.quantum_panel_dark));
        } else {
            revealView.setBackground(currentBgDrawable);
        }

        // Hide the real page background, and swap in the fake one
        content.setPageBackgroundsVisible(false);
        revealView.setVisibility(View.VISIBLE);
        // We need to hide this view as the animation start will be posted.
        revealView.setAlpha(0);

        int width = revealView.getMeasuredWidth();
        int height = revealView.getMeasuredHeight();
        float revealRadius = (float) Math.sqrt((width * width) / 4 + (height * height) / 4);

        revealView.setTranslationY(0);
        revealView.setTranslationX(0);

        // Get the y delta between the center of the page and the center of the all apps button
        int[] allAppsToPanelDelta = Utilities.getCenterDeltaInScreenSpace(revealView, getAllAppsButton(), null);

        float alpha = 0;
        float xDrift = 0;
        float yDrift = 0;
        if (material) {
            alpha = isWidgetTray ? 0.3f : 1f;
            yDrift = isWidgetTray ? height / 2 : allAppsToPanelDelta[1];
            xDrift = isWidgetTray ? 0 : allAppsToPanelDelta[0];
        } else {
            yDrift = 2 * height / 3;
            xDrift = 0;
        }
        final float initAlpha = alpha;

        revealView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
        layerViews.add(revealView);
        PropertyValuesHolder panelAlpha = PropertyValuesHolder.ofFloat("alpha", initAlpha, 1f);
        PropertyValuesHolder panelDriftY = PropertyValuesHolder.ofFloat("translationY", yDrift, 0);
        PropertyValuesHolder panelDriftX = PropertyValuesHolder.ofFloat("translationX", xDrift, 0);

        ObjectAnimator panelAlphaAndDrift = ObjectAnimator.ofPropertyValuesHolder(revealView, panelAlpha,
                panelDriftY, panelDriftX);

        panelAlphaAndDrift.setDuration(revealDuration);
        panelAlphaAndDrift.setInterpolator(new LogDecelerateInterpolator(100, 0));

        mStateAnimation.play(panelAlphaAndDrift);

        if (page != null) {
            page.setVisibility(View.VISIBLE);
            page.setLayerType(View.LAYER_TYPE_HARDWARE, null);
            layerViews.add(page);

            ObjectAnimator pageDrift = ObjectAnimator.ofFloat(page, "translationY", yDrift, 0);
            page.setTranslationY(yDrift);
            pageDrift.setDuration(revealDuration);
            pageDrift.setInterpolator(new LogDecelerateInterpolator(100, 0));
            pageDrift.setStartDelay(itemsAlphaStagger);
            mStateAnimation.play(pageDrift);

            page.setAlpha(0f);
            ObjectAnimator itemsAlpha = ObjectAnimator.ofFloat(page, "alpha", 0f, 1f);
            itemsAlpha.setDuration(revealDuration);
            itemsAlpha.setInterpolator(new AccelerateInterpolator(1.5f));
            itemsAlpha.setStartDelay(itemsAlphaStagger);
            mStateAnimation.play(itemsAlpha);
        }

        View pageIndicators = toView.findViewById(R.id.apps_customize_page_indicator);
        pageIndicators.setAlpha(0.01f);
        ObjectAnimator indicatorsAlpha = ObjectAnimator.ofFloat(pageIndicators, "alpha", 1f);
        indicatorsAlpha.setDuration(revealDuration);
        mStateAnimation.play(indicatorsAlpha);

        if (material) {
            final View allApps = getAllAppsButton();
            int allAppsButtonSize = LauncherAppState.getInstance().getDynamicGrid()
                    .getDeviceProfile().allAppsButtonVisualSize;
            float startRadius = isWidgetTray ? 0 : allAppsButtonSize / 2;
            Animator reveal = ViewAnimationUtils.createCircularReveal(revealView, width / 2, height / 2,
                    startRadius, revealRadius);
            reveal.setDuration(revealDuration);
            reveal.setInterpolator(new LogDecelerateInterpolator(100, 0));

            reveal.addListener(new AnimatorListenerAdapter() {
                public void onAnimationStart(Animator animation) {
                    if (!isWidgetTray) {
                        allApps.setVisibility(View.INVISIBLE);
                    }
                }

                public void onAnimationEnd(Animator animation) {
                    if (!isWidgetTray) {
                        allApps.setVisibility(View.VISIBLE);
                    }
                }
            });
            mStateAnimation.play(reveal);
        }

        mStateAnimation.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                dispatchOnLauncherTransitionEnd(fromView, animated, false);
                dispatchOnLauncherTransitionEnd(toView, animated, false);

                revealView.setVisibility(View.INVISIBLE);
                revealView.setLayerType(View.LAYER_TYPE_NONE, null);
                if (page != null) {
                    page.setLayerType(View.LAYER_TYPE_NONE, null);
                }
                content.setPageBackgroundsVisible(true);

                // Hide the search bar
                if (mSearchDropTargetBar != null) {
                    mSearchDropTargetBar.hideSearchBar(false);
                }

                // This can hold unnecessary references to views.
                mStateAnimation = null;
            }

        });

        if (workspaceAnim != null) {
            mStateAnimation.play(workspaceAnim);
        }

        dispatchOnLauncherTransitionPrepare(fromView, animated, false);
        dispatchOnLauncherTransitionPrepare(toView, animated, false);
        final AnimatorSet stateAnimation = mStateAnimation;
        final Runnable startAnimRunnable = new Runnable() {
            public void run() {
                // Check that mStateAnimation hasn't changed while
                // we waited for a layout/draw pass
                if (mStateAnimation != stateAnimation)
                    return;
                dispatchOnLauncherTransitionStart(fromView, animated, false);
                dispatchOnLauncherTransitionStart(toView, animated, false);

                revealView.setAlpha(initAlpha);
                if (Utilities.isLmpOrAbove()) {
                    for (int i = 0; i < layerViews.size(); i++) {
                        View v = layerViews.get(i);
                        if (v != null) {
                            if (Utilities.isViewAttachedToWindow(v))
                                v.buildLayer();
                        }
                    }
                }
                mStateAnimation.start();
            }
        };
        toView.bringToFront();
        toView.setVisibility(View.VISIBLE);
        toView.post(startAnimRunnable);
    } else {
        toView.setTranslationX(0.0f);
        toView.setTranslationY(0.0f);
        toView.setScaleX(1.0f);
        toView.setScaleY(1.0f);
        toView.setVisibility(View.VISIBLE);
        toView.bringToFront();

        if (!springLoaded && !LauncherAppState.getInstance().isScreenLarge()) {
            // Hide the search bar
            if (mSearchDropTargetBar != null) {
                mSearchDropTargetBar.hideSearchBar(false);
            }
        }
        dispatchOnLauncherTransitionPrepare(fromView, animated, false);
        dispatchOnLauncherTransitionStart(fromView, animated, false);
        dispatchOnLauncherTransitionEnd(fromView, animated, false);
        dispatchOnLauncherTransitionPrepare(toView, animated, false);
        dispatchOnLauncherTransitionStart(toView, animated, false);
        dispatchOnLauncherTransitionEnd(toView, animated, false);
    }
}

From source file:g7.bluesky.launcher3.Launcher.java

/**
 * Zoom the camera back into the workspace, hiding 'fromView'.
 * This is the opposite of showAppsCustomizeHelper.
 * @param animated If true, the transition will be animated.
 *//*w  ww. j  a  v a  2 s .c  o  m*/
private void hideAppsCustomizeHelper(Workspace.State toState, final boolean animated,
        final boolean springLoaded, final Runnable onCompleteRunnable) {

    if (mStateAnimation != null) {
        mStateAnimation.setDuration(0);
        mStateAnimation.cancel();
        mStateAnimation = null;
    }

    boolean material = Utilities.isLmpOrAbove();
    Resources res = getResources();

    final int duration = res.getInteger(R.integer.config_appsCustomizeZoomOutTime);
    final int fadeOutDuration = res.getInteger(R.integer.config_appsCustomizeFadeOutTime);
    final int revealDuration = res.getInteger(R.integer.config_appsCustomizeConcealTime);
    final int itemsAlphaStagger = res.getInteger(R.integer.config_appsCustomizeItemsAlphaStagger);

    final float scaleFactor = (float) res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
    final View fromView = mAppsCustomizeTabHost;
    final View toView = mWorkspace;
    Animator workspaceAnim = null;
    final ArrayList<View> layerViews = new ArrayList<View>();

    if (toState == Workspace.State.NORMAL) {
        workspaceAnim = mWorkspace.getChangeStateAnimation(toState, animated, layerViews);
    } else if (toState == Workspace.State.SPRING_LOADED || toState == Workspace.State.OVERVIEW) {
        workspaceAnim = mWorkspace.getChangeStateAnimation(toState, animated, layerViews);
    }

    // If for some reason our views aren't initialized, don't animate
    boolean initialized = getAllAppsButton() != null;

    if (animated && initialized) {
        mStateAnimation = LauncherAnimUtils.createAnimatorSet();
        if (workspaceAnim != null) {
            mStateAnimation.play(workspaceAnim);
        }

        final AppsCustomizePagedView content = (AppsCustomizePagedView) fromView
                .findViewById(R.id.apps_customize_pane_content);

        final View page = content.getPageAt(content.getNextPage());

        // We need to hide side pages of the Apps / Widget tray to avoid some ugly edge cases
        int count = content.getChildCount();
        for (int i = 0; i < count; i++) {
            View child = content.getChildAt(i);
            if (child != page) {
                child.setVisibility(View.INVISIBLE);
            }
        }
        final View revealView = fromView.findViewById(R.id.fake_page);

        // hideAppsCustomizeHelper is called in some cases when it is already hidden
        // don't perform all these no-op animations. In particularly, this was causing
        // the all-apps button to pop in and out.
        if (fromView.getVisibility() == View.VISIBLE) {
            AppsCustomizePagedView.ContentType contentType = content.getContentType();
            final boolean isWidgetTray = contentType == AppsCustomizePagedView.ContentType.Widgets;

            if (isWidgetTray) {
                revealView.setBackground(ContextCompat.getDrawable(this, R.drawable.quantum_panel_dark));
            } else {
                revealView.setBackground(currentBgDrawable);
            }

            int width = revealView.getMeasuredWidth();
            int height = revealView.getMeasuredHeight();
            float revealRadius = (float) Math.sqrt((width * width) / 4 + (height * height) / 4);

            // Hide the real page background, and swap in the fake one
            revealView.setVisibility(View.VISIBLE);
            content.setPageBackgroundsVisible(false);

            final View allAppsButton = getAllAppsButton();
            revealView.setTranslationY(0);
            int[] allAppsToPanelDelta = Utilities.getCenterDeltaInScreenSpace(revealView, allAppsButton, null);

            float xDrift = 0;
            float yDrift = 0;
            if (material) {
                yDrift = isWidgetTray ? height / 2 : allAppsToPanelDelta[1];
                xDrift = isWidgetTray ? 0 : allAppsToPanelDelta[0];
            } else {
                yDrift = 2 * height / 3;
                xDrift = 0;
            }

            revealView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
            TimeInterpolator decelerateInterpolator = material ? new LogDecelerateInterpolator(100, 0)
                    : new DecelerateInterpolator(1f);

            // The vertical motion of the apps panel should be delayed by one frame
            // from the conceal animation in order to give the right feel. We correpsondingly
            // shorten the duration so that the slide and conceal end at the same time.
            ObjectAnimator panelDriftY = LauncherAnimUtils.ofFloat(revealView, "translationY", 0, yDrift);
            panelDriftY.setDuration(revealDuration - SINGLE_FRAME_DELAY);
            panelDriftY.setStartDelay(itemsAlphaStagger + SINGLE_FRAME_DELAY);
            panelDriftY.setInterpolator(decelerateInterpolator);
            mStateAnimation.play(panelDriftY);

            ObjectAnimator panelDriftX = LauncherAnimUtils.ofFloat(revealView, "translationX", 0, xDrift);
            panelDriftX.setDuration(revealDuration - SINGLE_FRAME_DELAY);
            panelDriftX.setStartDelay(itemsAlphaStagger + SINGLE_FRAME_DELAY);
            panelDriftX.setInterpolator(decelerateInterpolator);
            mStateAnimation.play(panelDriftX);

            if (isWidgetTray || !material) {
                float finalAlpha = material ? 0.4f : 0f;
                revealView.setAlpha(1f);
                ObjectAnimator panelAlpha = LauncherAnimUtils.ofFloat(revealView, "alpha", 1f, finalAlpha);
                panelAlpha.setDuration(material ? revealDuration : 150);
                panelAlpha.setInterpolator(decelerateInterpolator);
                panelAlpha.setStartDelay(material ? 0 : itemsAlphaStagger + SINGLE_FRAME_DELAY);
                mStateAnimation.play(panelAlpha);
            }

            if (page != null) {
                page.setLayerType(View.LAYER_TYPE_HARDWARE, null);

                ObjectAnimator pageDrift = LauncherAnimUtils.ofFloat(page, "translationY", 0, yDrift);
                page.setTranslationY(0);
                pageDrift.setDuration(revealDuration - SINGLE_FRAME_DELAY);
                pageDrift.setInterpolator(decelerateInterpolator);
                pageDrift.setStartDelay(itemsAlphaStagger + SINGLE_FRAME_DELAY);
                mStateAnimation.play(pageDrift);

                page.setAlpha(1f);
                ObjectAnimator itemsAlpha = LauncherAnimUtils.ofFloat(page, "alpha", 1f, 0f);
                itemsAlpha.setDuration(100);
                itemsAlpha.setInterpolator(decelerateInterpolator);
                mStateAnimation.play(itemsAlpha);
            }

            View pageIndicators = fromView.findViewById(R.id.apps_customize_page_indicator);
            pageIndicators.setAlpha(1f);
            ObjectAnimator indicatorsAlpha = LauncherAnimUtils.ofFloat(pageIndicators, "alpha", 0f);
            indicatorsAlpha.setDuration(revealDuration);
            indicatorsAlpha.setInterpolator(new DecelerateInterpolator(1.5f));
            mStateAnimation.play(indicatorsAlpha);

            width = revealView.getMeasuredWidth();

            if (material) {
                if (!isWidgetTray) {
                    allAppsButton.setVisibility(View.INVISIBLE);
                }
                int allAppsButtonSize = LauncherAppState.getInstance().getDynamicGrid()
                        .getDeviceProfile().allAppsButtonVisualSize;
                float finalRadius = isWidgetTray ? 0 : allAppsButtonSize / 2;
                Animator reveal = LauncherAnimUtils.createCircularReveal(revealView, width / 2, height / 2,
                        revealRadius, finalRadius);
                reveal.setInterpolator(new LogDecelerateInterpolator(100, 0));
                reveal.setDuration(revealDuration);
                reveal.setStartDelay(itemsAlphaStagger);

                reveal.addListener(new AnimatorListenerAdapter() {
                    public void onAnimationEnd(Animator animation) {
                        revealView.setVisibility(View.INVISIBLE);
                        if (!isWidgetTray) {
                            allAppsButton.setVisibility(View.VISIBLE);
                        }
                    }
                });

                mStateAnimation.play(reveal);
            }

            dispatchOnLauncherTransitionPrepare(fromView, animated, true);
            dispatchOnLauncherTransitionPrepare(toView, animated, true);
            mAppsCustomizeContent.stopScrolling();
        }

        mStateAnimation.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                fromView.setVisibility(View.GONE);
                dispatchOnLauncherTransitionEnd(fromView, animated, true);
                dispatchOnLauncherTransitionEnd(toView, animated, true);
                if (onCompleteRunnable != null) {
                    onCompleteRunnable.run();
                }

                revealView.setLayerType(View.LAYER_TYPE_NONE, null);
                if (page != null) {
                    page.setLayerType(View.LAYER_TYPE_NONE, null);
                }
                content.setPageBackgroundsVisible(true);
                // Unhide side pages
                int count = content.getChildCount();
                for (int i = 0; i < count; i++) {
                    View child = content.getChildAt(i);
                    child.setVisibility(View.VISIBLE);
                }

                // Reset page transforms
                if (page != null) {
                    page.setTranslationX(0);
                    page.setTranslationY(0);
                    page.setAlpha(1);
                }
                content.setCurrentPage(content.getNextPage());

                mAppsCustomizeContent.updateCurrentPageScroll();

                // This can hold unnecessary references to views.
                mStateAnimation = null;
            }
        });

        final AnimatorSet stateAnimation = mStateAnimation;
        final Runnable startAnimRunnable = new Runnable() {
            public void run() {
                // Check that mStateAnimation hasn't changed while
                // we waited for a layout/draw pass
                if (mStateAnimation != stateAnimation)
                    return;
                dispatchOnLauncherTransitionStart(fromView, animated, false);
                dispatchOnLauncherTransitionStart(toView, animated, false);

                if (Utilities.isLmpOrAbove()) {
                    for (int i = 0; i < layerViews.size(); i++) {
                        View v = layerViews.get(i);
                        if (v != null) {
                            if (Utilities.isViewAttachedToWindow(v))
                                v.buildLayer();
                        }
                    }
                }
                mStateAnimation.start();
            }
        };
        fromView.post(startAnimRunnable);
    } else {
        fromView.setVisibility(View.GONE);
        dispatchOnLauncherTransitionPrepare(fromView, animated, true);
        dispatchOnLauncherTransitionStart(fromView, animated, true);
        dispatchOnLauncherTransitionEnd(fromView, animated, true);
        dispatchOnLauncherTransitionPrepare(toView, animated, true);
        dispatchOnLauncherTransitionStart(toView, animated, true);
        dispatchOnLauncherTransitionEnd(toView, animated, true);
    }
}

From source file:com.androzic.Androzic.java

@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
    Resources resources = getResources();

    if (getString(R.string.pref_folder_data).equals(key)) {
        setDataPath(Androzic.PATH_DATA,//ww  w.  j av  a2 s  .  c o  m
                sharedPreferences.getString(key, resources.getString(R.string.def_folder_data)));
    } else if (getString(R.string.pref_folder_icon).equals(key)) {
        setDataPath(Androzic.PATH_ICONS,
                sharedPreferences.getString(key, resources.getString(R.string.def_folder_icon)));
    } else if (getString(R.string.pref_unitcoordinate).equals(key)) {
        StringFormatter.coordinateFormat = Integer.parseInt(sharedPreferences.getString(key, "0"));
    } else if (getString(R.string.pref_unitdistance).equals(key)) {
        int distanceIdx = Integer.parseInt(sharedPreferences.getString(key, "0"));
        StringFormatter.distanceFactor = Double
                .parseDouble(resources.getStringArray(R.array.distance_factors)[distanceIdx]);
        StringFormatter.distanceAbbr = resources.getStringArray(R.array.distance_abbrs)[distanceIdx];
        StringFormatter.distanceShortFactor = Double
                .parseDouble(resources.getStringArray(R.array.distance_factors_short)[distanceIdx]);
        StringFormatter.distanceShortAbbr = resources.getStringArray(R.array.distance_abbrs_short)[distanceIdx];
    } else if (getString(R.string.pref_unitspeed).equals(key)) {
        int speedIdx = Integer.parseInt(sharedPreferences.getString(key, "0"));
        StringFormatter.speedFactor = Double
                .parseDouble(resources.getStringArray(R.array.speed_factors)[speedIdx]);
        StringFormatter.speedAbbr = resources.getStringArray(R.array.speed_abbrs)[speedIdx];
    } else if (getString(R.string.pref_unitelevation).equals(key)) {
        int elevationIdx = Integer.parseInt(sharedPreferences.getString(key, "0"));
        StringFormatter.elevationFactor = Double
                .parseDouble(resources.getStringArray(R.array.elevation_factors)[elevationIdx]);
        StringFormatter.elevationAbbr = resources.getStringArray(R.array.elevation_abbrs)[elevationIdx];
    } else if (getString(R.string.pref_unitangle).equals(key)) {
        int angleIdx = Integer.parseInt(sharedPreferences.getString(key, "0"));
        StringFormatter.angleFactor = Double
                .parseDouble(resources.getStringArray(R.array.angle_factors)[angleIdx]);
        StringFormatter.angleAbbr = resources.getStringArray(R.array.angle_abbrs)[angleIdx];
    } else if (getString(R.string.pref_unitanglemagnetic).equals(key)) {
        angleMagnetic = sharedPreferences.getBoolean(key, resources.getBoolean(R.bool.def_unitanglemagnetic));
    } else if (getString(R.string.pref_unitsunrise).equals(key)) {
        sunriseType = Integer.parseInt(sharedPreferences.getString(key, "0"));
    } else if (getString(R.string.pref_unitprecision).equals(key)) {
        boolean precision = sharedPreferences.getBoolean(key, resources.getBoolean(R.bool.def_unitprecision));
        StringFormatter.precisionFormat = precision ? "%.1f" : "%.0f";
    } else if (getString(R.string.pref_grid_mapshow).equals(key)) {
        overlayManager.mapGrid = sharedPreferences.getBoolean(key, false);
        if (currentMap instanceof OzfMap)
            overlayManager.initGrids((OzfMap) currentMap);
    } else if (getString(R.string.pref_grid_usershow).equals(key)) {
        overlayManager.userGrid = sharedPreferences.getBoolean(key, false);
        if (currentMap instanceof OzfMap)
            overlayManager.initGrids((OzfMap) currentMap);
    } else if (getString(R.string.pref_grid_preference).equals(key)) {
        overlayManager.gridPrefer = Integer.parseInt(sharedPreferences.getString(key, "0"));
        if (currentMap instanceof OzfMap)
            overlayManager.initGrids((OzfMap) currentMap);
    } else if (getString(R.string.pref_grid_userscale).equals(key)
            || getString(R.string.pref_grid_userunit).equals(key)
            || getString(R.string.pref_grid_usermpp).equals(key)) {
        if (currentMap instanceof OzfMap)
            overlayManager.initGrids((OzfMap) currentMap);
    } else if (getString(R.string.pref_vectormap_theme).equals(key)
            || getString(R.string.pref_vectormap_poi).equals(key)) {
        initializeRenderTheme();
        ForgeMap.onRenderThemeChanged();
    } else if (getString(R.string.pref_vectormap_textscale).equals(key)) {
        ForgeMap.textScale = Float
                .parseFloat(sharedPreferences.getString(getString(R.string.pref_vectormap_textscale), "1.0"));
        ForgeMap.onRenderThemeChanged();
    } else if (getString(R.string.pref_onlinemap).equals(key)
            || getString(R.string.pref_onlinemapscale).equals(key)) {
        setOnlineMaps(sharedPreferences.getString(getString(R.string.pref_onlinemap),
                resources.getString(R.string.def_onlinemap)));
    } else if (getString(R.string.pref_mapadjacent).equals(key)) {
        adjacentMaps = sharedPreferences.getBoolean(key, resources.getBoolean(R.bool.def_mapadjacent));
    } else if (getString(R.string.pref_onlinemapprescalefactor).equals(key)) {
        onlineMapPrescaleFactor = sharedPreferences.getInt(key,
                resources.getInteger(R.integer.def_onlinemapprescalefactor));
        if (maps != null)
            for (BaseMap map : maps.getMaps())
                if (map instanceof OnlineMap)
                    ((OnlineMap) map).setPrescaleFactor(onlineMapPrescaleFactor);
        // Hack to recalculate cache and mpp
        if (currentMap != null && currentMap instanceof OnlineMap)
            currentMap.setZoom(currentMap.getZoom());
    } else if (getString(R.string.pref_onlinemapexpiration).equals(key)) {
        // in weeks
        onlineMapTileExpiration = sharedPreferences.getInt(key,
                resources.getInteger(R.integer.def_onlinemapexpiration));
        // in milliseconds
        onlineMapTileExpiration *= 1000 * 3600 * 24 * 7;
        if (onlineMaps != null) {
            for (TileProvider provider : onlineMaps)
                provider.tileExpiration = onlineMapTileExpiration;
        }
    } else if (getString(R.string.pref_mapcropborder).equals(key)) {
        cropMapBorder = sharedPreferences.getBoolean(key, resources.getBoolean(R.bool.def_mapcropborder));
    } else if (getString(R.string.pref_mapdrawborder).equals(key)) {
        drawMapBorder = sharedPreferences.getBoolean(key, resources.getBoolean(R.bool.def_mapdrawborder));
    } else if (getString(R.string.pref_showwaypoints).equals(key)) {
        overlayManager.setWaypointsOverlayEnabled(sharedPreferences.getBoolean(key, true));
    } else if (getString(R.string.pref_showcurrenttrack).equals(key)) {
        overlayManager.setCurrentTrackOverlayEnabled(sharedPreferences.getBoolean(key, true));
    } else if (getString(R.string.pref_showaccuracy).equals(key)) {
        overlayManager.setAccuracyOverlayEnabled(sharedPreferences.getBoolean(key, true));
    } else if (getString(R.string.pref_showdistance_int).equals(key)) {
        int showDistance = Integer
                .parseInt(sharedPreferences.getString(key, getString(R.string.def_showdistance)));
        overlayManager.setDistanceOverlayEnabled(showDistance > 0);
    }
    overlayManager.onPreferencesChanged(sharedPreferences);
    if (mapHolder != null)
        mapHolder.refreshMap();
}