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.mail.utils.NotificationUtils.java

/**
 * Configure the notification for one conversation.  When there are multiple conversations,
 * this method is used to configure bundled notification for Android Wear.
 *///from  w  w w  . j av a2 s .  c  om
private static ConfigResult configureNotifForOneConversation(Context context, Account account,
        FolderPreferences folderPreferences, NotificationCompat.Builder notificationBuilder,
        NotificationCompat.WearableExtender wearExtender, Cursor conversationCursor, Intent notificationIntent,
        Folder folder, long when, Resources res, boolean isInbox, String notificationLabelName,
        int notificationId, final ContactFetcher contactFetcher) {

    final ConfigResult result = new ConfigResult();

    final Conversation conversation = new Conversation(conversationCursor);

    // Set of all unique senders for unseen messages
    final HashSet<String> senderAddressesSet = new HashSet<String>();
    Cursor cursor = null;
    MessageCursor messageCursor = null;
    boolean multipleUnseenThread = false;
    String from = null;
    try {
        final Uri uri = conversation.messageListUri.buildUpon()
                .appendQueryParameter(UIProvider.LABEL_QUERY_PARAMETER, folder.persistentId).build();
        cursor = context.getContentResolver().query(uri, UIProvider.MESSAGE_PROJECTION, null, null, null);
        messageCursor = new MessageCursor(cursor);
        // Use the information from the last sender in the conversation that triggered
        // this notification.

        String fromAddress = "";
        if (messageCursor.moveToPosition(messageCursor.getCount() - 1)) {
            final Message message = messageCursor.getMessage();
            fromAddress = message.getFrom();
            if (fromAddress == null) {
                // No sender. Go back to default value.
                LogUtils.e(LOG_TAG, "No sender found for message: %d", message.getId());
                fromAddress = "";
            }
            from = getDisplayableSender(fromAddress);
            result.contactIconInfo = getContactIcon(context, account.getAccountManagerAccount().name, from,
                    getSenderAddress(fromAddress), folder, contactFetcher);
            addEmailAddressToSet(fromAddress, senderAddressesSet);
            notificationBuilder.setLargeIcon(result.contactIconInfo.icon);
        }

        // Assume that the last message in this conversation is unread
        int firstUnseenMessagePos = messageCursor.getPosition();
        while (messageCursor.moveToPosition(messageCursor.getPosition() - 1)) {
            final Message message = messageCursor.getMessage();
            final boolean unseen = !message.seen;
            if (unseen) {
                firstUnseenMessagePos = messageCursor.getPosition();
                addEmailAddressToSet(message.getFrom(), senderAddressesSet);
                if (!multipleUnseenThread && !fromAddress.contentEquals(message.getFrom())) {
                    multipleUnseenThread = true;
                }
            }
        }

        final String subject = ConversationItemView.filterTag(context, conversation.subject);

        // TODO(skennedy) Can we remove this check?
        if (Utils.isRunningJellybeanOrLater()) {
            // For a new-style notification

            if (multipleUnseenThread) {
                // The title of a single conversation is the list of senders.
                int sendersLength = res.getInteger(R.integer.swipe_senders_length);

                final SpannableStringBuilder sendersBuilder = getStyledSenders(context, conversationCursor,
                        sendersLength, account);

                notificationBuilder.setContentTitle(sendersBuilder);
                // For a single new conversation, the ticker is based on the sender's name.
                result.notificationTicker = sendersBuilder.toString();
            } else {
                from = getWrappedFromString(from);
                // The title of a single message the sender.
                notificationBuilder.setContentTitle(from);
                // For a single new conversation, the ticker is based on the sender's name.
                result.notificationTicker = from;
            }

            // The notification content will be the subject of the conversation.
            notificationBuilder.setContentText(getSingleMessageLittleText(context, subject));

            // The notification subtext will be the subject of the conversation for inbox
            // notifications, or will based on the the label name for user label
            // notifications.
            notificationBuilder.setSubText(isInbox ? account.getDisplayName() : notificationLabelName);

            final NotificationCompat.BigTextStyle bigText = new NotificationCompat.BigTextStyle(
                    notificationBuilder);

            // Seek the message cursor to the first unread message
            final Message message;
            if (messageCursor.moveToPosition(firstUnseenMessagePos)) {
                message = messageCursor.getMessage();
                bigText.bigText(getSingleMessageBigText(context, subject, message));
            } else {
                LogUtils.e(LOG_TAG, "Failed to load message");
                message = null;
            }

            if (message != null) {
                final Set<String> notificationActions = folderPreferences.getNotificationActions(account);

                NotificationActionUtils.addNotificationActions(context, notificationIntent, notificationBuilder,
                        wearExtender, account, conversation, message, folder, notificationId, when,
                        notificationActions);
            }
        } else {
            // For an old-style notification

            // The title of a single conversation notification is built from both the sender
            // and subject of the new message.
            notificationBuilder.setContentTitle(getSingleMessageNotificationTitle(context, from, subject));

            // The notification content will be the subject of the conversation for inbox
            // notifications, or will based on the the label name for user label
            // notifications.
            notificationBuilder.setContentText(isInbox ? account.getDisplayName() : notificationLabelName);

            // For a single new conversation, the ticker is based on the sender's name.
            result.notificationTicker = from;
        }

        tagNotificationsWithPeople(notificationBuilder, senderAddressesSet);
    } finally {
        if (messageCursor != null) {
            messageCursor.close();
        }
        if (cursor != null) {
            cursor.close();
        }
    }
    return result;
}

From source file:com.gxapplications.android.gxsuite.launcher.Launcher.java

/**
 * Zoom the camera out from the workspace to reveal 'toView'.
 * Assumes that the view to show is anchored at either the very top or very bottom
 * of the screen./*  w  ww  .  j a  va 2s .c  o m*/
 */
private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded) {
    if (mStateAnimation != null) {
        mStateAnimation.cancel();
        mStateAnimation = null;
    }
    final Resources res = getResources();

    final int duration = res.getInteger(R.integer.config_appsCustomizeZoomInTime);
    final int fadeDuration = res.getInteger(R.integer.config_appsCustomizeFadeInTime);
    final float scale = (float) res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
    final View fromView = mWorkspace;
    final AppsCustomizeTabHost toView = mAppsCustomizeTabHost;
    final int startDelay = res.getInteger(R.integer.config_workspaceAppsCustomizeAnimationStagger);

    setPivotsForZoom(toView, scale);

    // Shrink workspaces away if going to AppsCustomize from workspace
    Animator workspaceAnim = mWorkspace.getChangeStateAnimation(Workspace.State.SMALL, animated);

    if (animated) {
        toView.setScaleX(scale);
        toView.setScaleY(scale);
        final LauncherViewPropertyAnimator scaleAnim = new LauncherViewPropertyAnimator(toView);
        scaleAnim.scaleX(1f).scaleY(1f).setDuration(duration)
                .setInterpolator(new Workspace.ZoomOutInterpolator());

        toView.setVisibility(View.VISIBLE);
        toView.setAlpha(0f);
        final ObjectAnimator alphaAnim = ObjectAnimator.ofFloat(toView, "alpha", 0f, 1f)
                .setDuration(fadeDuration);
        alphaAnim.setInterpolator(new DecelerateInterpolator(1.5f));
        alphaAnim.addUpdateListener(new AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                if (animation == null) {
                    throw new RuntimeException("animation is null");
                }
                float t = (Float) animation.getAnimatedValue();
                dispatchOnLauncherTransitionStep(fromView, t);
                dispatchOnLauncherTransitionStep(toView, t);
            }
        });

        // toView should appear right at the end of the workspace shrink
        // animation
        mStateAnimation = LauncherAnimUtils.createAnimatorSet();
        mStateAnimation.play(scaleAnim).after(startDelay);
        mStateAnimation.play(alphaAnim).after(startDelay);

        mStateAnimation.addListener(new AnimatorListenerAdapter() {
            boolean animationCancelled = false;

            @Override
            public void onAnimationStart(Animator animation) {
                updateWallpaperVisibility(true);
                // Prepare the position
                toView.setTranslationX(0.0f);
                toView.setTranslationY(0.0f);
                toView.setVisibility(View.VISIBLE);
                toView.bringToFront();
            }

            @Override
            public void onAnimationEnd(Animator animation) {
                dispatchOnLauncherTransitionEnd(fromView, animated, false);
                dispatchOnLauncherTransitionEnd(toView, animated, false);

                if (mWorkspace != null && !springLoaded && !LauncherApplication.isScreenLarge()) {
                    // Hide the workspace scrollbar
                    mWorkspace.hideScrollingIndicator(true);
                    hideDockDivider();
                }
                if (!animationCancelled) {
                    updateWallpaperVisibility(false);
                }

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

            @Override
            public void onAnimationCancel(Animator animation) {
                animationCancelled = true;
            }
        });

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

        boolean delayAnim = false;
        final ViewTreeObserver observer;

        dispatchOnLauncherTransitionPrepare(fromView, animated, false);
        dispatchOnLauncherTransitionPrepare(toView, animated, false);

        // If any of the objects being animated haven't been measured/laid out
        // yet, delay the animation until we get a layout pass
        if ((((LauncherTransitionable) toView).getContent().getMeasuredWidth() == 0)
                || (mWorkspace.getMeasuredWidth() == 0) || (toView.getMeasuredWidth() == 0)) {
            observer = mWorkspace.getViewTreeObserver();
            delayAnim = true;
        } else {
            observer = 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;
                setPivotsForZoom(toView, scale);
                dispatchOnLauncherTransitionStart(fromView, animated, false);
                dispatchOnLauncherTransitionStart(toView, animated, false);
                toView.post(new Runnable() {
                    public void run() {
                        // Check that mStateAnimation hasn't changed while
                        // we waited for a layout/draw pass
                        if (mStateAnimation != stateAnimation)
                            return;
                        mStateAnimation.start();
                    }
                });
            }
        };
        if (delayAnim) {
            final OnGlobalLayoutListener delayedStart = new OnGlobalLayoutListener() {
                public void onGlobalLayout() {
                    toView.post(startAnimRunnable);
                    observer.removeOnGlobalLayoutListener(this);
                }
            };
            observer.addOnGlobalLayoutListener(delayedStart);
        } else {
            startAnimRunnable.run();
        }
    } 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 && !LauncherApplication.isScreenLarge()) {
            // Hide the workspace scrollbar
            mWorkspace.hideScrollingIndicator(true);
            hideDockDivider();

            // 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);
        updateWallpaperVisibility(false);
    }
}

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

/**
 * Configure the notification for one conversation.  When there are multiple conversations,
 * this method is used to configure bundled notification for Android Wear.
 *///from  www  . j  av  a2s . co  m
private static ConfigResult configureNotifForOneConversation(Context context, Account account,
        FolderPreferences folderPreferences, NotificationCompat.Builder notification,
        NotificationCompat.WearableExtender wearExtender, Cursor conversationCursor, Intent notificationIntent,
        Folder folder, long when, Resources res, String notificationAccountDisplayName,
        String notificationAccountEmail, boolean isInbox, String notificationLabelName, int notificationId,
        final ContactPhotoFetcher photoFetcher) {

    final ConfigResult result = new ConfigResult();

    final Conversation conversation = new Conversation(conversationCursor);

    Cursor cursor = null;
    MessageCursor messageCursor = null;
    boolean multipleUnseenThread = false;
    String from = null;
    try {
        final Uri uri = conversation.messageListUri.buildUpon()
                .appendQueryParameter(UIProvider.LABEL_QUERY_PARAMETER, folder.persistentId).build();
        cursor = context.getContentResolver().query(uri, UIProvider.MESSAGE_PROJECTION, null, null, null);
        messageCursor = new MessageCursor(cursor);
        // Use the information from the last sender in the conversation that triggered
        // this notification.

        String fromAddress = "";
        if (messageCursor.moveToPosition(messageCursor.getCount() - 1)) {
            final Message message = messageCursor.getMessage();
            fromAddress = message.getFrom();
            if (fromAddress == null) {
                // No sender. Go back to default value.
                LogUtils.e(LOG_TAG, "No sender found for message: %d", message.getId());
                fromAddress = "";
            }
            from = getDisplayableSender(fromAddress);
            result.contactIconInfo = getContactIcon(context, account.getAccountManagerAccount().name, from,
                    getSenderAddress(fromAddress), folder, photoFetcher);
            notification.setLargeIcon(result.contactIconInfo.icon);
        }

        // Assume that the last message in this conversation is unread
        int firstUnseenMessagePos = messageCursor.getPosition();
        while (messageCursor.moveToPosition(messageCursor.getPosition() - 1)) {
            final Message message = messageCursor.getMessage();
            final boolean unseen = !message.seen;
            if (unseen) {
                firstUnseenMessagePos = messageCursor.getPosition();
                if (!multipleUnseenThread && !fromAddress.contentEquals(message.getFrom())) {
                    multipleUnseenThread = true;
                }
            }
        }

        final String subject = ConversationItemView.filterTag(context, conversation.subject);

        // TODO(skennedy) Can we remove this check?
        if (Utils.isRunningJellybeanOrLater()) {
            // For a new-style notification

            if (multipleUnseenThread) {
                // The title of a single conversation is the list of senders.
                int sendersLength = res.getInteger(R.integer.swipe_senders_length);

                final SpannableStringBuilder sendersBuilder = getStyledSenders(context, conversationCursor,
                        sendersLength, notificationAccountEmail);

                from = sendersBuilder.toString();
                notification.setContentText(sendersBuilder);
                // For a single new conversation, the ticker is based on the sender's name.
                result.notificationTicker = sendersBuilder.toString();
            } else {
                from = getWrappedFromString(from);
                // The title of a single message the sender.
                notification.setContentText(from);
                // For a single new conversation, the ticker is based on the sender's name.
                result.notificationTicker = from;
            }

            // The notification content will be the subject of the conversation.

            /*TS: linzhou 2016-01-06 EMAIL 1271037 DEL_S*/
            notification.setContentTitle(getSingleMessageLittleText(context, subject));
            /*TS: linzhou 2016-01-06 EMAIL 1271037 DEL_S*/

            // The notification subtext will be the subject of the conversation for inbox
            // notifications, or will based on the the label name for user label
            // notifications.
            notification.setSubText(isInbox ? notificationAccountDisplayName : notificationLabelName);

            if (multipleUnseenThread) {
                notification.setLargeIcon(getDefaultNotificationIcon(context, folder, true));
            }
            final NotificationCompat.BigTextStyle bigText = new NotificationCompat.BigTextStyle(notification);

            // Seek the message cursor to the first unread message
            final Message message;
            if (messageCursor.moveToPosition(firstUnseenMessagePos)) {
                message = messageCursor.getMessage();
                bigText.bigText(getSingleMessageBigText(context, message, from));
            } else {
                LogUtils.e(LOG_TAG, "Failed to load message");
                message = null;
            }

            if (message != null) {
                // TS: zhaotianyong 2015-05-1003318 EMAIL BUGFIX_1003318 MOD_S
                final Set<String> notificationActions = folderPreferences.getNotificationActions(account,
                        message);
                // TS: zhaotianyong 2015-05-1003318 EMAIL BUGFIX_1003318 MOD_E

                NotificationActionUtils.addNotificationActions(context, notificationIntent, notification,
                        wearExtender, account, conversation, message, folder, notificationId, when,
                        notificationActions);
            }
        } else {
            // For an old-style notification

            // The title of a single conversation notification is built from both the sender
            // and subject of the new message.
            notification.setContentTitle(getSingleMessageNotificationTitle(context, from, subject));

            // The notification content will be the subject of the conversation for inbox
            // notifications, or will based on the the label name for user label
            // notifications.
            notification.setContentText(isInbox ? notificationAccountDisplayName : notificationLabelName);

            // For a single new conversation, the ticker is based on the sender's name.
            result.notificationTicker = from;
        }
    } finally {
        if (messageCursor != null) {
            messageCursor.close();
        }
        if (cursor != null) {
            cursor.close();
        }
    }
    return result;
}

From source file:com.androzic.MapActivity.java

@Override
protected void onResume() {
    super.onResume();
    Log.e(TAG, "onResume()");

    SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this);
    Resources resources = getResources();

    // update some preferences
    int speedIdx = Integer.parseInt(settings.getString(getString(R.string.pref_unitspeed), "0"));
    speedFactor = Double.parseDouble(resources.getStringArray(R.array.speed_factors)[speedIdx]);
    speedAbbr = resources.getStringArray(R.array.speed_abbrs)[speedIdx];
    speedUnit.setText(speedAbbr);/*  w  w  w  . j  a va2 s  .c  o m*/
    int distanceIdx = Integer.parseInt(settings.getString(getString(R.string.pref_unitdistance), "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];
    int elevationIdx = Integer.parseInt(settings.getString(getString(R.string.pref_unitelevation), "0"));
    elevationFactor = Double.parseDouble(resources.getStringArray(R.array.elevation_factors)[elevationIdx]);
    elevationAbbr = resources.getStringArray(R.array.elevation_abbrs)[elevationIdx];
    elevationUnit.setText(elevationAbbr);
    application.angleType = Integer.parseInt(settings.getString(getString(R.string.pref_unitangle), "0"));
    trackUnit.setText((application.angleType == 0 ? "deg" : getString(R.string.degmag)));
    bearingUnit.setText((application.angleType == 0 ? "deg" : getString(R.string.degmag)));
    application.coordinateFormat = Integer
            .parseInt(settings.getString(getString(R.string.pref_unitcoordinate), "0"));
    application.sunriseType = Integer.parseInt(settings.getString(getString(R.string.pref_unitsunrise), "0"));

    renderInterval = settings.getInt(getString(R.string.pref_maprenderinterval),
            resources.getInteger(R.integer.def_maprenderinterval)) * 100;
    followOnLocation = settings.getBoolean(getString(R.string.pref_mapfollowonloc),
            resources.getBoolean(R.bool.def_mapfollowonloc));
    magInterval = resources.getInteger(R.integer.def_maginterval) * 1000;
    showDistance = Integer.parseInt(settings.getString(getString(R.string.pref_showdistance_int),
            getString(R.string.def_showdistance)));
    showAccuracy = settings.getBoolean(getString(R.string.pref_showaccuracy), true);
    autoDim = settings.getBoolean(getString(R.string.pref_mapdim), resources.getBoolean(R.bool.def_mapdim));
    dimInterval = settings.getInt(getString(R.string.pref_mapdiminterval),
            resources.getInteger(R.integer.def_mapdiminterval)) * 1000;
    dimValue = settings.getInt(getString(R.string.pref_mapdimvalue),
            resources.getInteger(R.integer.def_mapdimvalue));

    map.setHideOnDrag(settings.getBoolean(getString(R.string.pref_maphideondrag),
            resources.getBoolean(R.bool.def_maphideondrag)));
    map.setStrictUnfollow(!settings.getBoolean(getString(R.string.pref_unfollowontap),
            resources.getBoolean(R.bool.def_unfollowontap)));
    map.setLookAhead(
            settings.getInt(getString(R.string.pref_lookahead), resources.getInteger(R.integer.def_lookahead)));
    map.setBestMapEnabled(
            settings.getBoolean(getString(R.string.pref_mapbest), resources.getBoolean(R.bool.def_mapbest)));
    map.setBestMapInterval(settings.getInt(getString(R.string.pref_mapbestinterval),
            resources.getInteger(R.integer.def_mapbestinterval)) * 1000);
    map.setCursorVector(
            Integer.parseInt(settings.getString(getString(R.string.pref_cursorvector),
                    getString(R.string.def_cursorvector))),
            settings.getInt(getString(R.string.pref_cursorvectormlpr),
                    resources.getInteger(R.integer.def_cursorvectormlpr)));
    map.setProximity(Integer.parseInt(settings.getString(getString(R.string.pref_navigation_proximity),
            getString(R.string.def_navigation_proximity))));

    // prepare views
    customizeLayout(settings);
    findViewById(R.id.editroute).setVisibility(application.editingRoute != null ? View.VISIBLE : View.GONE);
    if (application.editingTrack != null) {
        startEditTrack(application.editingTrack);
    }
    updateGPSStatus();
    updateNavigationStatus();
    // prepare overlays
    updateOverlays(settings, false);

    if (settings.getBoolean(getString(R.string.ui_drawer_open), false)) {
        Panel panel = (Panel) findViewById(R.id.panel);
        panel.setOpen(true, false);
    }

    onSharedPreferenceChanged(settings, getString(R.string.pref_wakelock));
    map.setKeepScreenOn(keepScreenOn);

    // TODO move into application
    if (lastKnownLocation != null) {
        if (lastKnownLocation.getProvider().equals(LocationManager.GPS_PROVIDER)) {
            updateMovingInfo(lastKnownLocation, true);
            updateNavigationInfo();
            dimScreen(lastKnownLocation);
        } else if (lastKnownLocation.getProvider().equals(LocationManager.NETWORK_PROVIDER)) {
            dimScreen(lastKnownLocation);
        }
    }

    bindService(new Intent(this, LocationService.class), locationConnection, BIND_AUTO_CREATE);
    bindService(new Intent(this, NavigationService.class), navigationConnection, BIND_AUTO_CREATE);

    registerReceiver(broadcastReceiver, new IntentFilter(NavigationService.BROADCAST_NAVIGATION_STATUS));
    registerReceiver(broadcastReceiver, new IntentFilter(NavigationService.BROADCAST_NAVIGATION_STATE));
    registerReceiver(broadcastReceiver, new IntentFilter(LocationService.BROADCAST_LOCATING_STATUS));
    registerReceiver(broadcastReceiver, new IntentFilter(LocationService.BROADCAST_TRACKING_STATUS));
    registerReceiver(broadcastReceiver, new IntentFilter(Intent.ACTION_SCREEN_OFF));
    registerReceiver(broadcastReceiver, new IntentFilter(Intent.ACTION_SCREEN_ON));

    if (application.hasEnsureVisible()) {
        setFollowing(false);
        double[] loc = application.getEnsureVisible();
        application.setMapCenter(loc[0], loc[1], true, false);
        application.clearEnsureVisible();
    } else {
        application.updateLocationMaps(true, map.isBestMapEnabled());
    }
    updateMapViewArea();
    map.resume();
    map.updateMapInfo();
    map.update();
    map.requestFocus();
}

From source file:com.chen.mail.ui.AbstractActivityController.java

public AbstractActivityController(MailActivity activity, ViewMode viewMode) {
    mActivity = activity;//from w  ww  . j  a va  2s . c  o m
    mFragmentManager = mActivity.getFragmentManager();
    mViewMode = viewMode;
    mContext = activity.getApplicationContext();
    mRecentFolderList = new RecentFolderList(mContext);
    mTracker = new ConversationPositionTracker(this);
    // Allow the fragment to observe changes to its own selection set. No other object is
    // aware of the selected set.
    mSelectedSet.addObserver(this);

    final Resources r = mContext.getResources();
    mFolderItemUpdateDelayMs = r.getInteger(R.integer.folder_item_refresh_delay_ms);
    mShowUndoBarDelay = r.getInteger(R.integer.show_undo_bar_delay_ms);
    mVeiledMatcher = VeiledAddressMatcher.newInstance(activity.getResources());
    mIsTablet = Utils.useTabletUI(r);
    mConversationListLoadFinishedIgnored = false;
}

From source file:com.android.leanlauncher.CellLayout.java

public CellLayout(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    mDragEnforcer = new DropTarget.DragEnforcer(context);

    // A ViewGroup usually does not draw, but CellLayout needs to draw a rectangle to show
    // the user where a dragged item will land when dropped.
    setWillNotDraw(false);//from www  . j  a va2 s  .  c  om
    setClipToPadding(false);
    mLauncher = (Launcher) context;

    LauncherAppState app = LauncherAppState.getInstance();
    DeviceProfile grid = app.getDynamicGrid().getDeviceProfile();
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CellLayout, defStyle, 0);

    mCellWidth = mCellHeight = -1;
    mFixedCellWidth = mFixedCellHeight = -1;
    mWidthGap = mOriginalWidthGap = 0;
    mHeightGap = mOriginalHeightGap = 0;
    mMaxGap = Integer.MAX_VALUE;
    mCountX = (int) grid.numColumns;
    mCountY = (int) grid.numRows;
    mOccupied = new boolean[mCountX][mCountY];
    mTmpOccupied = new boolean[mCountX][mCountY];
    mPreviousReorderDirection[0] = INVALID_DIRECTION;
    mPreviousReorderDirection[1] = INVALID_DIRECTION;

    a.recycle();

    setAlwaysDrawnWithCacheEnabled(false);

    final Resources res = getResources();

    mNormalBackground = res.getDrawable(R.drawable.screenpanel);
    mActiveGlowBackground = res.getDrawable(R.drawable.screenpanel_hover);

    mOverScrollLeft = res.getDrawable(R.drawable.overscroll_glow_left);
    mOverScrollRight = res.getDrawable(R.drawable.overscroll_glow_right);
    mForegroundPadding = res.getDimensionPixelSize(R.dimen.workspace_overscroll_drawable_padding);

    mReorderPreviewAnimationMagnitude = (REORDER_PREVIEW_MAGNITUDE * grid.iconSizePx);

    mNormalBackground.setFilterBitmap(true);
    mActiveGlowBackground.setFilterBitmap(true);

    // Initialize the data structures used for the drag visualization.
    TimeInterpolator easeOutInterpolator = new DecelerateInterpolator(2.5f);
    mDragCell[0] = mDragCell[1] = -1;
    for (int i = 0; i < mDragOutlines.length; i++) {
        mDragOutlines[i] = new Rect(-1, -1, -1, -1);
    }

    // When dragging things around the home screens, we show a green outline of
    // where the item will land. The outlines gradually fade out, leaving a trail
    // behind the drag path.
    // Set up all the animations that are used to implement this fading.
    final int duration = res.getInteger(R.integer.config_dragOutlineFadeTime);
    final float fromAlphaValue = 0;
    final float toAlphaValue = (float) res.getInteger(R.integer.config_dragOutlineMaxAlpha);

    Arrays.fill(mDragOutlineAlphas, fromAlphaValue);

    for (int i = 0; i < mDragOutlineAnims.length; i++) {
        final InterruptibleInOutAnimator anim = new InterruptibleInOutAnimator(this, duration, fromAlphaValue,
                toAlphaValue);
        anim.getAnimator().setInterpolator(easeOutInterpolator);
        final int thisIndex = i;
        anim.getAnimator().addUpdateListener(new AnimatorUpdateListener() {
            public void onAnimationUpdate(ValueAnimator animation) {
                final Bitmap outline = (Bitmap) anim.getTag();

                // If an animation is started and then stopped very quickly, we can still
                // get spurious updates we've cleared the tag. Guard against this.
                if (outline == null) {
                    @SuppressWarnings("all") // suppress dead code warning
                    final boolean debug = false;
                    if (debug) {
                        Object val = animation.getAnimatedValue();
                        Log.d(TAG, "anim " + thisIndex + " update: " + val + ", isStopped " + anim.isStopped());
                    }
                    // Try to prevent it from continuing to run
                    animation.cancel();
                } else {
                    mDragOutlineAlphas[thisIndex] = (Float) animation.getAnimatedValue();
                    CellLayout.this.invalidate(mDragOutlines[thisIndex]);
                }
            }
        });
        // The animation holds a reference to the drag outline bitmap as long is it's
        // running. This way the bitmap can be GCed when the animations are complete.
        anim.getAnimator().addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                if ((Float) ((ValueAnimator) animation).getAnimatedValue() == 0f) {
                    anim.setTag(null);
                }
            }
        });
        mDragOutlineAnims[i] = anim;
    }

    mBackgroundRect = new Rect();
    mForegroundRect = new Rect();

    mShortcutsAndWidgets = new ShortcutAndWidgetContainer(context);
    mShortcutsAndWidgets.setCellDimensions(mCellWidth, mCellHeight, mWidthGap, mHeightGap, mCountX, mCountY);

    mTouchFeedbackView = new FastBitmapView(context);
    // Make the feedback view large enough to hold the blur bitmap.
    addView(mTouchFeedbackView, (int) (grid.cellWidthPx * 1.2), (int) (grid.cellHeightPx * 1.2));
    addView(mShortcutsAndWidgets);
}

From source file:com.android.mail.ui.AbstractActivityController.java

public AbstractActivityController(MailActivity activity, ViewMode viewMode) {
    mActivity = activity;// ww  w.ja  v a  2s.c  om
    mFragmentManager = mActivity.getFragmentManager();
    mViewMode = viewMode;
    mContext = activity.getApplicationContext();
    mRecentFolderList = new RecentFolderList(mContext);
    mTracker = new ConversationPositionTracker(this);
    // Allow the fragment to observe changes to its own selection set. No other object is
    // aware of the selected set.
    mCheckedSet.addObserver(this);

    final Resources r = mContext.getResources();
    mFolderItemUpdateDelayMs = r.getInteger(R.integer.folder_item_refresh_delay_ms);
    mShowUndoBarDelay = r.getInteger(R.integer.show_undo_bar_delay_ms);
    mVeiledMatcher = VeiledAddressMatcher.newInstance(activity.getResources());
    mIsTablet = Utils.useTabletUI(r);
    mConversationListLoadFinishedIgnored = false;
}

From source file:ac.robinson.mediaphone.MediaPhoneActivity.java

private void loadAllPreferences() {
    SharedPreferences mediaPhoneSettings = PreferenceManager
            .getDefaultSharedPreferences(MediaPhoneActivity.this);
    Resources res = getResources();

    // bluetooth observer
    configureBluetoothObserver(mediaPhoneSettings, res);

    // importing confirmation
    boolean confirmImporting = res.getBoolean(R.bool.default_confirm_importing);
    try {/*from  w  ww. ja va2 s. com*/
        confirmImporting = mediaPhoneSettings.getBoolean(getString(R.string.key_confirm_importing),
                confirmImporting);
    } catch (Exception e) {
        confirmImporting = res.getBoolean(R.bool.default_confirm_importing);
    }
    MediaPhone.IMPORT_CONFIRM_IMPORTING = confirmImporting;

    // delete after import
    boolean deleteAfterImport = res.getBoolean(R.bool.default_delete_after_importing);
    try {
        deleteAfterImport = mediaPhoneSettings.getBoolean(getString(R.string.key_delete_after_importing),
                deleteAfterImport);
    } catch (Exception e) {
        deleteAfterImport = res.getBoolean(R.bool.default_delete_after_importing);
    }
    MediaPhone.IMPORT_DELETE_AFTER_IMPORTING = deleteAfterImport;

    // minimum frame duration
    TypedValue resourceValue = new TypedValue();
    res.getValue(R.attr.default_minimum_frame_duration, resourceValue, true);
    float minimumFrameDuration;
    try {
        minimumFrameDuration = mediaPhoneSettings.getFloat(getString(R.string.key_minimum_frame_duration),
                resourceValue.getFloat());
        if (minimumFrameDuration <= 0) {
            throw new NumberFormatException();
        }
    } catch (Exception e) {
        minimumFrameDuration = resourceValue.getFloat();
    }
    MediaPhone.PLAYBACK_EXPORT_MINIMUM_FRAME_DURATION = Math.round(minimumFrameDuration * 1000);

    // word duration
    res.getValue(R.attr.default_word_duration, resourceValue, true);
    float wordDuration;
    try {
        wordDuration = mediaPhoneSettings.getFloat(getString(R.string.key_word_duration),
                resourceValue.getFloat());
        if (wordDuration <= 0) {
            throw new NumberFormatException();
        }
    } catch (Exception e) {
        wordDuration = resourceValue.getFloat();
    }
    MediaPhone.PLAYBACK_EXPORT_WORD_DURATION = Math.round(wordDuration * 1000);

    // screen orientation
    int requestedOrientation = res.getInteger(R.integer.default_screen_orientation);
    try {
        String requestedOrientationString = mediaPhoneSettings
                .getString(getString(R.string.key_screen_orientation), null);
        requestedOrientation = Integer.valueOf(requestedOrientationString);
    } catch (Exception e) {
        requestedOrientation = res.getInteger(R.integer.default_screen_orientation);
    }
    setRequestedOrientation(requestedOrientation);

    // other preferences
    loadPreferences(mediaPhoneSettings);
}

From source file:cc.flydev.launcher.Workspace.java

public void animateWidgetDrop(ItemInfo info, CellLayout cellLayout, DragView dragView,
        final Runnable onCompleteRunnable, int animationType, final View finalView, boolean external) {
    Rect from = new Rect();
    mLauncher.getDragLayer().getViewRectRelativeToSelf(dragView, from);

    int[] finalPos = new int[2];
    float scaleXY[] = new float[2];
    boolean scalePreview = !(info instanceof PendingAddShortcutInfo);
    getFinalPositionForDropAnimation(finalPos, scaleXY, dragView, cellLayout, info, mTargetCell, external,
            scalePreview);// w ww  . j  a  v a  2 s .  co m

    Resources res = mLauncher.getResources();
    int duration = res.getInteger(R.integer.config_dropAnimMaxDuration) - 200;

    // In the case where we've prebound the widget, we remove it from the DragLayer
    if (finalView instanceof AppWidgetHostView && external) {
        Log.d(TAG, "6557954 Animate widget drop, final view is appWidgetHostView");
        mLauncher.getDragLayer().removeView(finalView);
    }
    if ((animationType == ANIMATE_INTO_POSITION_AND_RESIZE || external) && finalView != null) {
        Bitmap crossFadeBitmap = createWidgetBitmap(info, finalView);
        dragView.setCrossFadeBitmap(crossFadeBitmap);
        dragView.crossFade((int) (duration * 0.8f));
    } else if (info.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET && external) {
        scaleXY[0] = scaleXY[1] = Math.min(scaleXY[0], scaleXY[1]);
    }

    DragLayer dragLayer = mLauncher.getDragLayer();
    if (animationType == CANCEL_TWO_STAGE_WIDGET_DROP_ANIMATION) {
        mLauncher.getDragLayer().animateViewIntoPosition(dragView, finalPos, 0f, 0.1f, 0.1f,
                DragLayer.ANIMATION_END_DISAPPEAR, onCompleteRunnable, duration);
    } else {
        int endStyle;
        if (animationType == ANIMATE_INTO_POSITION_AND_REMAIN) {
            endStyle = DragLayer.ANIMATION_END_REMAIN_VISIBLE;
        } else {
            endStyle = DragLayer.ANIMATION_END_DISAPPEAR;
            ;
        }

        Runnable onComplete = new Runnable() {
            @Override
            public void run() {
                if (finalView != null) {
                    finalView.setVisibility(VISIBLE);
                }
                if (onCompleteRunnable != null) {
                    onCompleteRunnable.run();
                }
            }
        };
        dragLayer.animateViewIntoPosition(dragView, from.left, from.top, finalPos[0], finalPos[1], 1, 1, 1,
                scaleXY[0], scaleXY[1], onComplete, endStyle, duration, this);
    }
}

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

public void animateWidgetDrop(ItemInfo info, CellLayout cellLayout, DragView dragView,
        final Runnable onCompleteRunnable, int animationType, final View finalView, boolean external) {
    Rect from = new Rect();
    mLauncher.getDragLayer().getViewRectRelativeToSelf(dragView, from);

    int[] finalPos = new int[2];
    float scaleXY[] = new float[2];
    boolean scalePreview = !(info instanceof PendingAddShortcutInfo);
    getFinalPositionForDropAnimation(finalPos, scaleXY, dragView, cellLayout, info, mTargetCell, external,
            scalePreview);//from   w  w w  . j a  v a 2s  .  com

    Resources res = mLauncher.getResources();
    int duration = res.getInteger(R.integer.config_dropAnimMaxDuration) - 200;

    // In the case where we've prebound the widget, we remove it from the
    // DragLayer
    if (finalView instanceof AppWidgetHostView && external) {
        Log.d(TAG, "6557954 Animate widget drop, final view is appWidgetHostView");
        mLauncher.getDragLayer().removeView(finalView);
    }
    if ((animationType == ANIMATE_INTO_POSITION_AND_RESIZE || external) && finalView != null) {
        Bitmap crossFadeBitmap = createWidgetBitmap(info, finalView);
        dragView.setCrossFadeBitmap(crossFadeBitmap);
        dragView.crossFade((int) (duration * 0.8f));
    } else if (info.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET && external) {
        scaleXY[0] = scaleXY[1] = Math.min(scaleXY[0], scaleXY[1]);
    }

    DragLayer dragLayer = mLauncher.getDragLayer();
    if (animationType == CANCEL_TWO_STAGE_WIDGET_DROP_ANIMATION) {
        mLauncher.getDragLayer().animateViewIntoPosition(dragView, finalPos, 0f, 0.1f, 0.1f,
                DragLayer.ANIMATION_END_DISAPPEAR, onCompleteRunnable, duration);
    } else {
        int endStyle;
        if (animationType == ANIMATE_INTO_POSITION_AND_REMAIN) {
            endStyle = DragLayer.ANIMATION_END_REMAIN_VISIBLE;
        } else {
            endStyle = DragLayer.ANIMATION_END_DISAPPEAR;
            ;
        }

        Runnable onComplete = new Runnable() {
            @Override
            public void run() {
                if (finalView != null) {
                    finalView.setVisibility(VISIBLE);
                }
                if (onCompleteRunnable != null) {
                    onCompleteRunnable.run();
                }
            }
        };
        dragLayer.animateViewIntoPosition(dragView, from.left, from.top, finalPos[0], finalPos[1], 1, 1, 1,
                scaleXY[0], scaleXY[1], onComplete, endStyle, duration, this);
    }
}