Example usage for android.content.res Resources getDimensionPixelSize

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

Introduction

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

Prototype

public int getDimensionPixelSize(@DimenRes int id) throws NotFoundException 

Source Link

Document

Retrieve a dimensional for a particular resource ID for use as a size in raw pixels.

Usage

From source file:com.htc.dotdesign.ToolBoxService.java

private void setToolPanelVisibility(boolean bShow) {
    if (mCurrExtend != null) {
        mWindowManager.removeView(mCurrExtend);
        mCurrExtend = null;/*ww w  .  j  av  a2 s. c  o  m*/
    }

    if (bShow) {
        mIsToolBarExtend = true;
        if (mCurrFun == FunType.Fun_Palette) {
            Resources res = getResources();
            WindowManager.LayoutParams params = new WindowManager.LayoutParams(
                    WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT,
                    WindowManager.LayoutParams.TYPE_PHONE, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
                    PixelFormat.TRANSLUCENT);
            params.gravity = Gravity.START;
            if (mDragButtonParams.y < mScreenHeight / 2) {
                params.gravity = Gravity.TOP | params.gravity;
                params.y = mDragButtonParams.y + mDragButtonHeight;
                View top_arrow = mPalette.findViewById(R.id.top_arrow);
                top_arrow.setVisibility(View.VISIBLE);
                View bottom_arrow = mPalette.findViewById(R.id.bottom_arrow);
                bottom_arrow.setVisibility(View.GONE);
            } else {
                params.gravity = Gravity.BOTTOM | params.gravity;
                params.y = mScreenHeight - mDragButtonParams.y;
                View top_arrow = mPalette.findViewById(R.id.top_arrow);
                top_arrow.setVisibility(View.GONE);
                View bottom_arrow = mPalette.findViewById(R.id.bottom_arrow);
                bottom_arrow.setVisibility(View.VISIBLE);
            }
            int[] locations = new int[2];
            mBtnPalette.getLocationOnScreen(locations);
            int x = locations[0];
            params.x = (x + mBtnPalette.getWidth() / 2)
                    - (mArrowWidth / 2 + res.getDimensionPixelSize(R.dimen.h02));

            mPalette.setVisibility(View.VISIBLE);
            mWindowManager.addView(mPalette, params);
            mCurrExtend = mPalette;
            initBrushSize();
        } else if (mCurrFun == FunType.Fun_Eraser) {
            Resources res = getResources();
            WindowManager.LayoutParams params = new WindowManager.LayoutParams(
                    WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT,
                    WindowManager.LayoutParams.TYPE_PHONE, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
                    PixelFormat.TRANSLUCENT);
            params.gravity = Gravity.START;
            if (mDragButtonParams.y < mScreenHeight / 2) {
                params.gravity = Gravity.TOP | params.gravity;
                params.y = mDragButtonParams.y + mDragButtonHeight;
                View top_arrow = mEraser.findViewById(R.id.top_arrow);
                top_arrow.setVisibility(View.VISIBLE);
                View bottom_arrow = mEraser.findViewById(R.id.bottom_arrow);
                bottom_arrow.setVisibility(View.GONE);
            } else {
                params.gravity = Gravity.BOTTOM | params.gravity;
                params.y = mScreenHeight - mDragButtonParams.y;
                View top_arrow = mEraser.findViewById(R.id.top_arrow);
                top_arrow.setVisibility(View.GONE);
                View bottom_arrow = mEraser.findViewById(R.id.bottom_arrow);
                bottom_arrow.setVisibility(View.VISIBLE);
            }
            int[] locations = new int[2];
            mBtnEraser.getLocationOnScreen(locations);
            int x = locations[0];
            params.x = (x + mBtnEraser.getWidth() / 2)
                    - (mArrowWidth / 2 + res.getDimensionPixelSize(R.dimen.h02));

            mEraser.setVisibility(View.VISIBLE);
            mWindowManager.addView(mEraser, params);
            mCurrExtend = mEraser;
            initBrushSize();
        } else if (mCurrFun == FunType.Fun_VirtualDot) {

        } else if (mCurrFun == FunType.Fun_Menu) {
            Resources res = getResources();
            WindowManager.LayoutParams params = new WindowManager.LayoutParams(
                    WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT,
                    WindowManager.LayoutParams.TYPE_PHONE, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
                    PixelFormat.TRANSLUCENT);
            params.gravity = Gravity.END;
            if (mDragButtonParams.y < mScreenHeight / 2) {
                params.gravity = Gravity.TOP | params.gravity;
                params.y = mDragButtonParams.y + mDragButtonHeight;
                // Set top_arrow to visible and align to parent right.
                View top_arrow = mMenu.findViewById(R.id.top_arrow);
                top_arrow.setVisibility(View.VISIBLE);
                LinearLayout.LayoutParams arrowParams = (LinearLayout.LayoutParams) top_arrow.getLayoutParams();
                arrowParams.setMarginEnd(res.getDimensionPixelSize(R.dimen.h02));
                arrowParams.gravity = Gravity.END;
                top_arrow.setLayoutParams(arrowParams);
                // Set bottom_arrow to gone
                View bottom_arrow = mMenu.findViewById(R.id.bottom_arrow);
                bottom_arrow.setVisibility(View.GONE);
            } else {
                params.gravity = Gravity.BOTTOM | params.gravity;
                params.y = mScreenHeight - mDragButtonParams.y;
                // Set top_arrow to gone
                View top_arrow = mMenu.findViewById(R.id.top_arrow);
                top_arrow.setVisibility(View.GONE);
                // Set bottom_arrow to visible and align to parent right.
                View bottom_arrow = mMenu.findViewById(R.id.bottom_arrow);
                LinearLayout.LayoutParams arrowParams = (LinearLayout.LayoutParams) bottom_arrow
                        .getLayoutParams();
                arrowParams.setMarginEnd(res.getDimensionPixelSize(R.dimen.h02));
                arrowParams.gravity = Gravity.END;
                bottom_arrow.setLayoutParams(arrowParams);
                bottom_arrow.setVisibility(View.VISIBLE);
            }
            int[] locations = new int[2];
            mBtnMenu.getLocationOnScreen(locations);
            int x = locations[0];
            //params.x = (x + mBtnMenu.getWidth()/2) - (mArrowWidth/2 + res.getDimensionPixelSize(R.dimen.h02));
            params.x = mScreenWidth - (x + mBtnMenu.getWidth() / 2)
                    - (mArrowWidth / 2 + res.getDimensionPixelSize(R.dimen.h02));

            mMenu.setVisibility(View.VISIBLE);
            mWindowManager.addView(mMenu, params);
            mCurrExtend = mMenu;
        }
    } else {
        mIsToolBarExtend = false;
    }

    updateToolBarFunIconColor();
}

From source file:com.limewoodmedia.nsdroid.activities.WorldAssembly.java

private void setUpChartRenderer(XYMultipleSeriesRenderer chartRenderer, XYSeriesRenderer forRenderer,
        XYSeriesRenderer againstRenderer) {
    Log.d(TAG, "Set up chart renderer");
    Resources r = getResources();
    float legendTextSize = r.getDimension(R.dimen.area_chart_legend_size);
    float labelTextSize = r.getDimension(R.dimen.area_chart_label_size);

    // For renderer
    forRenderer.setColor(r.getColor(R.color.wa_for));
    forRenderer.setChartValuesTextSize(legendTextSize);
    forRenderer.setDisplayChartValues(true);
    XYSeriesRenderer.FillOutsideLine line = new XYSeriesRenderer.FillOutsideLine(
            XYSeriesRenderer.FillOutsideLine.Type.BELOW);
    line.setColor(r.getColor(R.color.wa_for_below));
    forRenderer.addFillOutsideLine(line);

    againstRenderer.setColor(r.getColor(R.color.wa_against));
    againstRenderer.setChartValuesTextSize(legendTextSize);
    againstRenderer.setDisplayChartValues(true);
    line = new XYSeriesRenderer.FillOutsideLine(XYSeriesRenderer.FillOutsideLine.Type.BELOW);
    line.setColor(r.getColor(R.color.wa_against_below));
    againstRenderer.addFillOutsideLine(line);

    chartRenderer.setZoomButtonsVisible(false);
    chartRenderer.setClickEnabled(true);
    chartRenderer.setInScroll(true);//  w w  w.  j a v a  2  s  . c om
    chartRenderer.setAntialiasing(true);
    chartRenderer.setShowLegend(true);
    chartRenderer.setLegendTextSize(legendTextSize);
    chartRenderer.setLabelsTextSize(labelTextSize);
    chartRenderer.setTextTypeface(Typeface.DEFAULT);
    chartRenderer.setPanEnabled(false);
    chartRenderer.setShowLabels(true);
    chartRenderer.setXAxisMin(0);
    chartRenderer.setXAxisMax(24 * 4 + 1); // 1 per hour, 4 days, 1 at origo
    chartRenderer.setYAxisMin(0);
    chartRenderer.setXLabels(0);
    chartRenderer.setXLabelsAngle(-25);
    chartRenderer.setXLabelsAlign(Paint.Align.RIGHT);
    chartRenderer.setFitLegend(true);
    for (int i = 1; i < 5; i++) {
        chartRenderer.addXTextLabel(24 * i, i + " " + r.getQuantityString(R.plurals.days, i));
    }
    chartRenderer.setYLabels(0);
    chartRenderer.setGridColor(Color.WHITE);
    chartRenderer.setMarginsColor(Color.WHITE);
    chartRenderer.setMargins(new int[] { 0, 0, r.getDimensionPixelSize(R.dimen.area_chart_margin_bottom), 0 });
    chartRenderer.setBackgroundColor(Color.WHITE);
    chartRenderer.setApplyBackgroundColor(true);
    chartRenderer.removeAllRenderers();
    chartRenderer.addSeriesRenderer(forRenderer);
    chartRenderer.addSeriesRenderer(againstRenderer);
}

From source file:com.grottworkshop.gwsmaterialdaterangepicker.date.MonthView.java

@SuppressWarnings("deprecation")
public MonthView(Context context, AttributeSet attr, DatePickerController controller) {
    super(context, attr);
    mController = controller;//from ww w  .  j  a v a  2  s .c om
    Resources res = context.getResources();

    mDayLabelCalendar = Calendar.getInstance();
    mCalendar = Calendar.getInstance();

    mDayOfWeekTypeface = res.getString(R.string.mdtp_day_of_week_label_typeface);
    mMonthTitleTypeface = res.getString(R.string.mdtp_sans_serif);

    boolean darkTheme = mController != null && mController.isThemeDark();
    if (darkTheme) {
        //TODO: getColor(int) depreciated
        mDayTextColor = res.getColor(R.color.mdtp_date_picker_text_normal_dark_theme);
        //TODO: getColor(int) depreciated
        mMonthDayTextColor = res.getColor(R.color.mdtp_date_picker_month_day_dark_theme);
        //TODO: getColor(int) depreciated
        mDisabledDayTextColor = res.getColor(R.color.mdtp_date_picker_text_disabled_dark_theme);
        //TODO: getColor(int) depreciated
        mHighlightedDayTextColor = res.getColor(R.color.mdtp_date_picker_text_highlighted_dark_theme);
    } else {
        //TODO: getColor(int) depreciated
        mDayTextColor = res.getColor(R.color.mdtp_date_picker_text_normal);
        //TODO: getColor(int) depreciated
        mMonthDayTextColor = res.getColor(R.color.mdtp_date_picker_month_day);
        //TODO: getColor(int) depreciated
        mDisabledDayTextColor = res.getColor(R.color.mdtp_date_picker_text_disabled);
        //TODO: getColor(int) depreciated
        mHighlightedDayTextColor = res.getColor(R.color.mdtp_date_picker_text_highlighted);
    }
    //TODO: getColor(int) depreciated
    mSelectedDayTextColor = res.getColor(R.color.mdtp_white);
    //TODO: getColor(int) depreciated
    mTodayNumberColor = res.getColor(R.color.mdtp_accent_color);
    //TODO: getColor(int) depreciated
    mMonthTitleColor = res.getColor(R.color.mdtp_white);

    mStringBuilder = new StringBuilder(50);
    mFormatter = new Formatter(mStringBuilder, Locale.getDefault());

    MINI_DAY_NUMBER_TEXT_SIZE = res.getDimensionPixelSize(R.dimen.mdtp_day_number_size);
    MONTH_LABEL_TEXT_SIZE = res.getDimensionPixelSize(R.dimen.mdtp_month_label_size);
    MONTH_DAY_LABEL_TEXT_SIZE = res.getDimensionPixelSize(R.dimen.mdtp_month_day_label_text_size);
    MONTH_HEADER_SIZE = res.getDimensionPixelOffset(R.dimen.mdtp_month_list_item_header_height);
    DAY_SELECTED_CIRCLE_SIZE = res.getDimensionPixelSize(R.dimen.mdtp_day_number_select_circle_radius);

    mRowHeight = (res.getDimensionPixelOffset(R.dimen.mdtp_date_picker_view_animator_height)
            - getMonthHeaderSize()) / MAX_NUM_ROWS;

    // Set up accessibility components.
    mTouchHelper = getMonthViewTouchHelper();
    ViewCompat.setAccessibilityDelegate(this, mTouchHelper);
    ViewCompat.setImportantForAccessibility(this, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES);
    mLockAccessibilityDelegate = true;

    // Sets up any standard paints that will be used
    initView();
}

From source file:com.aliyun.homeshell.Folder.java

private void updateFolderLayout(boolean supportCardIcon) {
    final int w, h, wg, hg, l, t, r, b, countX, countY;
    Resources res = getResources();
    if (supportCardIcon) {
        w = res.getDimensionPixelSize(R.dimen.folder_cell_width);
        h = res.getDimensionPixelSize(R.dimen.folder_cell_height);
        wg = res.getDimensionPixelSize(R.dimen.folder_cell_width_gap);
        hg = res.getDimensionPixelSize(R.dimen.folder_cell_height_gap);
        l = mContent.getPaddingLeft();/*w w  w . j a v a  2  s.  c  o  m*/
        t = res.getDimensionPixelSize(R.dimen.folder_cell_layout_top_padding);
        r = mContent.getPaddingRight();
        b = res.getDimensionPixelSize(R.dimen.folder_cell_layout_bottom_padding);
        countX = mMaxCountX;
        countY = ConfigManager.getCardFolderMaxCountY();
    } else {
        w = res.getDimensionPixelSize(R.dimen.folder_cell_width_small);
        h = res.getDimensionPixelSize(R.dimen.folder_cell_height_small);
        wg = res.getDimensionPixelSize(R.dimen.folder_cell_width_gap_small);
        hg = res.getDimensionPixelSize(R.dimen.folder_cell_height_gap_small);
        l = mContent.getPaddingLeft();
        t = 0;
        r = mContent.getPaddingRight();
        b = 0;
        countX = mMaxCountX;
        countY = ConfigManager.getFolderMaxCountY();
    }
    mContentWidth = countX * w + (countX - 1) * wg + l + r;
    mContentHeight = countY * h + (countY - 1) * hg + t + b;
    for (CellLayout mContent : mContentList) {
        mContent.setCellSize(w, h, wg, hg, true);
        mContent.setPadding(l, t, r, b);
    }
}

From source file:com.android.mail.browse.ConversationItemView.java

private static synchronized void getItemViewResources(Context context) {
    if (sConfigurationChangedReceiver == null) {
        sConfigurationChangedReceiver = new BroadcastReceiver() {
            @Override// ww  w .  j  av  a2s. c o m
            public void onReceive(Context context, Intent intent) {
                STAR_OFF = null;
                getItemViewResources(context);
            }
        };
        context.registerReceiver(sConfigurationChangedReceiver,
                new IntentFilter(Intent.ACTION_CONFIGURATION_CHANGED));
    }
    if (STAR_OFF == null) {
        final Resources res = context.getResources();
        // Initialize static bitmaps.
        STAR_OFF = BitmapFactory.decodeResource(res, R.drawable.ic_star_outline_20dp);
        STAR_ON = BitmapFactory.decodeResource(res, R.drawable.ic_star_20dp);
        ATTACHMENT = BitmapFactory.decodeResource(res, R.drawable.ic_attach_file_18dp);
        ONLY_TO_ME = BitmapFactory.decodeResource(res, R.drawable.ic_email_caret_double);
        TO_ME_AND_OTHERS = BitmapFactory.decodeResource(res, R.drawable.ic_email_caret_single);
        IMPORTANT_ONLY_TO_ME = BitmapFactory.decodeResource(res,
                R.drawable.ic_email_caret_double_important_unread);
        IMPORTANT_TO_ME_AND_OTHERS = BitmapFactory.decodeResource(res,
                R.drawable.ic_email_caret_single_important_unread);
        IMPORTANT = BitmapFactory.decodeResource(res, R.drawable.ic_email_caret_none_important_unread);
        STATE_REPLIED = BitmapFactory.decodeResource(res, R.drawable.ic_badge_reply_holo_light);
        STATE_FORWARDED = BitmapFactory.decodeResource(res, R.drawable.ic_badge_forward_holo_light);
        STATE_REPLIED_AND_FORWARDED = BitmapFactory.decodeResource(res,
                R.drawable.ic_badge_reply_forward_holo_light);
        STATE_CALENDAR_INVITE = BitmapFactory.decodeResource(res, R.drawable.ic_badge_invite_holo_light);
        FOCUSED_CONVERSATION_HIGHLIGHT = res.getDrawable(R.drawable.visible_conversation_highlight);

        // Initialize colors.
        sActivatedTextSpan = CharacterStyle
                .wrap(new ForegroundColorSpan(res.getColor(R.color.senders_text_color)));
        sSendersTextColor = res.getColor(R.color.senders_text_color);
        sSubjectTextUnreadSpan = new TextAppearanceSpan(context, R.style.SubjectAppearanceUnreadStyle);
        sSubjectTextReadSpan = new TextAppearanceSpan(context, R.style.SubjectAppearanceReadStyle);

        sBadgeTextSpan = new TextAppearanceSpan(context, R.style.BadgeTextStyle);
        sBadgeBackgroundSpan = new BackgroundColorSpan(res.getColor(R.color.badge_background_color));
        sDateTextColorRead = res.getColor(R.color.date_text_color_read);
        sDateTextColorUnread = res.getColor(R.color.date_text_color_unread);
        sStarTouchSlop = res.getDimensionPixelSize(R.dimen.star_touch_slop);
        sSenderImageTouchSlop = res.getDimensionPixelSize(R.dimen.sender_image_touch_slop);
        sShrinkAnimationDuration = res.getInteger(R.integer.shrink_animation_duration);
        sSlideAnimationDuration = res.getInteger(R.integer.slide_animation_duration);
        // Initialize static color.
        sSendersSplitToken = res.getString(R.string.senders_split_token);
        sElidedPaddingToken = res.getString(R.string.elided_padding_token);
        sScrollSlop = res.getInteger(R.integer.swipeScrollSlop);
        sFoldersMaxCount = res.getInteger(R.integer.conversation_list_max_folder_count);
        sCabAnimationDuration = res.getInteger(R.integer.conv_item_view_cab_anim_duration);
        sBadgePaddingExtraWidth = res.getDimensionPixelSize(R.dimen.badge_padding_extra_width);
        sBadgeRoundedCornerRadius = res.getDimensionPixelSize(R.dimen.badge_rounded_corner_radius);
        sDividerPaint.setColor(res.getColor(R.color.divider_color));
        sDividerHeight = res.getDimensionPixelSize(R.dimen.divider_height);
    }
}

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

protected void exportContent(final String narrativeId, final boolean isTemplate) {
    if (MediaPhone.DIRECTORY_TEMP == null) {
        UIUtilities.showToast(MediaPhoneActivity.this, R.string.export_missing_directory, true);
        return;/*  ww w  .j  a  va2 s .c o m*/
    }
    if (IOUtilities.isInternalPath(MediaPhone.DIRECTORY_TEMP.getAbsolutePath())) {
        UIUtilities.showToast(MediaPhoneActivity.this, R.string.export_potential_problem, true);
    }

    // important to keep awake to export because we only have one chance to display the export options
    // after creating mov or smil file (will be cancelled on screen unlock; Android is weird)
    // TODO: move to a better (e.g. notification bar) method of exporting?
    UIUtilities.acquireKeepScreenOn(getWindow());

    final CharSequence[] items = { getString(R.string.export_mov), getString(R.string.export_html),
            getString(R.string.export_smil, getString(R.string.app_name)) };

    AlertDialog.Builder builder = new AlertDialog.Builder(MediaPhoneActivity.this);
    builder.setTitle(R.string.export_narrative_title);
    // builder.setMessage(R.string.send_narrative_hint); //breaks dialog
    builder.setIcon(android.R.drawable.ic_dialog_info);
    builder.setNegativeButton(android.R.string.cancel, null);
    builder.setItems(items, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int item) {
            ContentResolver contentResolver = getContentResolver();

            NarrativeItem thisNarrative;
            if (isTemplate) {
                thisNarrative = NarrativesManager.findTemplateByInternalId(contentResolver, narrativeId);
            } else {
                thisNarrative = NarrativesManager.findNarrativeByInternalId(contentResolver, narrativeId);
            }
            final ArrayList<FrameMediaContainer> contentList = thisNarrative.getContentList(contentResolver);

            // random name to counter repeat sending name issues
            String exportId = MediaPhoneProvider.getNewInternalId().substring(0, 8);
            final String exportName = String.format(Locale.ENGLISH, "%s-%s",
                    getString(R.string.app_name).replaceAll("[^a-zA-Z0-9]+", "-").toLowerCase(Locale.ENGLISH),
                    exportId);

            Resources res = getResources();
            final Map<Integer, Object> settings = new Hashtable<Integer, Object>();
            settings.put(MediaUtilities.KEY_AUDIO_RESOURCE_ID, R.raw.ic_audio_playback);

            // some output settings (TODO: make sure HTML version respects these)
            settings.put(MediaUtilities.KEY_BACKGROUND_COLOUR, res.getColor(R.color.export_background));
            settings.put(MediaUtilities.KEY_TEXT_COLOUR_NO_IMAGE, res.getColor(R.color.export_text_no_image));
            settings.put(MediaUtilities.KEY_TEXT_COLOUR_WITH_IMAGE,
                    res.getColor(R.color.export_text_with_image));
            settings.put(MediaUtilities.KEY_TEXT_BACKGROUND_COLOUR,
                    res.getColor(R.color.export_text_background));
            // TODO: do we want to do getDimensionPixelSize for export?
            settings.put(MediaUtilities.KEY_TEXT_SPACING,
                    res.getDimensionPixelSize(R.dimen.export_icon_text_padding));
            settings.put(MediaUtilities.KEY_TEXT_CORNER_RADIUS,
                    res.getDimensionPixelSize(R.dimen.export_icon_text_corner_radius));
            settings.put(MediaUtilities.KEY_TEXT_BACKGROUND_SPAN_WIDTH,
                    Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB);
            settings.put(MediaUtilities.KEY_MAX_TEXT_FONT_SIZE,
                    res.getDimensionPixelSize(R.dimen.export_maximum_text_size));
            settings.put(MediaUtilities.KEY_MAX_TEXT_CHARACTERS_PER_LINE,
                    res.getInteger(R.integer.export_maximum_text_characters_per_line));
            settings.put(MediaUtilities.KEY_MAX_TEXT_HEIGHT_WITH_IMAGE,
                    res.getDimensionPixelSize(R.dimen.export_maximum_text_height_with_image));

            if (contentList != null && contentList.size() > 0) {
                switch (item) {
                case 0:
                    settings.put(MediaUtilities.KEY_OUTPUT_WIDTH, res.getInteger(R.integer.export_mov_width));
                    settings.put(MediaUtilities.KEY_OUTPUT_HEIGHT, res.getInteger(R.integer.export_mov_height));
                    settings.put(MediaUtilities.KEY_IMAGE_QUALITY,
                            res.getInteger(R.integer.camera_jpeg_save_quality));

                    // all image files are compatible - we just convert to JPEG when writing the movie,
                    // but we need to check for incompatible audio that we can't convert to PCM
                    boolean incompatibleAudio = false;
                    for (FrameMediaContainer frame : contentList) {
                        for (String audioPath : frame.mAudioPaths) {
                            if (!AndroidUtilities.arrayContains(MediaUtilities.MOV_AUDIO_FILE_EXTENSIONS,
                                    IOUtilities.getFileExtension(audioPath))) {
                                incompatibleAudio = true;
                                break;
                            }
                        }
                        if (incompatibleAudio) {
                            break;
                        }
                    }

                    if (incompatibleAudio) {
                        AlertDialog.Builder builder = new AlertDialog.Builder(MediaPhoneActivity.this);
                        builder.setTitle(android.R.string.dialog_alert_title);
                        builder.setMessage(R.string.mov_export_mov_incompatible);
                        builder.setIcon(android.R.drawable.ic_dialog_alert);
                        builder.setNegativeButton(android.R.string.cancel, null);
                        builder.setPositiveButton(R.string.button_continue,
                                new DialogInterface.OnClickListener() {
                                    @Override
                                    public void onClick(DialogInterface dialog, int whichButton) {
                                        exportMovie(settings, exportName, contentList);
                                    }
                                });
                        AlertDialog alert = builder.create();
                        alert.show();
                    } else {
                        exportMovie(settings, exportName, contentList);
                    }
                    break;

                case 1:
                    settings.put(MediaUtilities.KEY_OUTPUT_WIDTH, res.getInteger(R.integer.export_html_width));
                    settings.put(MediaUtilities.KEY_OUTPUT_HEIGHT,
                            res.getInteger(R.integer.export_html_height));
                    runExportNarrativesTask(new BackgroundRunnable() {
                        private int mTaskResult = 0;

                        @Override
                        public int getTaskId() {
                            return mTaskResult;
                        }

                        @Override
                        public boolean getShowDialog() {
                            return true;
                        }

                        @Override
                        public void run() {
                            ArrayList<Uri> filesToSend = HTMLUtilities.generateNarrativeHTML(getResources(),
                                    new File(MediaPhone.DIRECTORY_TEMP,
                                            exportName + MediaUtilities.HTML_FILE_EXTENSION),
                                    contentList, settings);

                            if (filesToSend == null || filesToSend.size() <= 0) {
                                mTaskResult = R.id.export_creation_failed;
                            } else {
                                sendFiles(filesToSend);
                            }
                        }
                    });
                    break;

                case 2:
                    settings.put(MediaUtilities.KEY_OUTPUT_WIDTH, res.getInteger(R.integer.export_smil_width));
                    settings.put(MediaUtilities.KEY_OUTPUT_HEIGHT,
                            res.getInteger(R.integer.export_smil_height));
                    settings.put(MediaUtilities.KEY_PLAYER_BAR_ADJUSTMENT,
                            res.getInteger(R.integer.export_smil_player_bar_adjustment));
                    runExportNarrativesTask(new BackgroundRunnable() {
                        private int mTaskResult = 0;

                        @Override
                        public int getTaskId() {
                            return mTaskResult;
                        }

                        @Override
                        public boolean getShowDialog() {
                            return true;
                        }

                        @Override
                        public void run() {
                            ArrayList<Uri> filesToSend = SMILUtilities.generateNarrativeSMIL(getResources(),
                                    new File(MediaPhone.DIRECTORY_TEMP,
                                            exportName + MediaUtilities.SMIL_FILE_EXTENSION),
                                    contentList, settings);

                            if (filesToSend == null || filesToSend.size() <= 0) {
                                mTaskResult = R.id.export_creation_failed;
                            } else {
                                sendFiles(filesToSend);
                            }
                        }
                    });
                    break;
                }
            } else {
                UIUtilities.showToast(MediaPhoneActivity.this,
                        (isTemplate ? R.string.export_template_failed : R.string.export_narrative_failed));
            }
            dialog.dismiss();
        }
    });
    AlertDialog alert = builder.create();
    alert.show();
}

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

static Rect getCellLayoutMetrics(Launcher launcher, int orientation) {
    Resources res = launcher.getResources();
    Display display = launcher.getWindowManager().getDefaultDisplay();
    Point smallestSize = new Point();
    Point largestSize = new Point();
    DisplayCompt.getCurrentSizeRange(display, smallestSize, largestSize);
    if (orientation == CellLayout.LANDSCAPE) {
        if (mLandscapeCellLayoutMetrics == null) {
            int paddingLeft = res.getDimensionPixelSize(R.dimen.workspace_left_padding_land);
            int paddingRight = res.getDimensionPixelSize(R.dimen.workspace_right_padding_land);
            int paddingTop = res.getDimensionPixelSize(R.dimen.workspace_top_padding_land);
            int paddingBottom = res.getDimensionPixelSize(R.dimen.workspace_bottom_padding_land);
            int width = largestSize.x - paddingLeft - paddingRight;
            int height = smallestSize.y - paddingTop - paddingBottom;
            mLandscapeCellLayoutMetrics = new Rect();
            CellLayout.getMetrics(mLandscapeCellLayoutMetrics, res, width, height,
                    LauncherModel.getCellCountX(), LauncherModel.getCellCountY(), orientation);
        }//from w  ww .  j av a2 s  . c  om
        return mLandscapeCellLayoutMetrics;
    } else if (orientation == CellLayout.PORTRAIT) {
        if (mPortraitCellLayoutMetrics == null) {
            int paddingLeft = res.getDimensionPixelSize(R.dimen.workspace_left_padding_land);
            int paddingRight = res.getDimensionPixelSize(R.dimen.workspace_right_padding_land);
            int paddingTop = res.getDimensionPixelSize(R.dimen.workspace_top_padding_land);
            int paddingBottom = res.getDimensionPixelSize(R.dimen.workspace_bottom_padding_land);
            int width = smallestSize.x - paddingLeft - paddingRight;
            int height = largestSize.y - paddingTop - paddingBottom;
            mPortraitCellLayoutMetrics = new Rect();
            CellLayout.getMetrics(mPortraitCellLayoutMetrics, res, width, height, LauncherModel.getCellCountX(),
                    LauncherModel.getCellCountY(), orientation);
        }
        return mPortraitCellLayoutMetrics;
    }
    return null;
}

From source file:org.chromium.chrome.browser.tab.Tab.java

/**
 * Creates an instance of a {@link Tab}.
 *
 * This constructor can be called before the native library has been loaded, so any additions
 * must be vetted for library calls./*from   w  w w. j a  v  a2s .c  o  m*/
 *
 * @param id          The id this tab should be identified with.
 * @param parentId    The id id of the tab that caused this tab to be opened.
 * @param incognito   Whether or not this tab is incognito.
 * @param context     An instance of a {@link Context}.
 * @param window      An instance of a {@link WindowAndroid}.
 * @param creationState State in which the tab is created, needed to initialize TabUma
 *                      accounting. When null, TabUma will not be initialized.
 * @param frozenState State containing information about this Tab, if it was persisted.
 */
@SuppressLint("HandlerLeak")
public Tab(int id, int parentId, boolean incognito, Context context, WindowAndroid window, TabLaunchType type,
        TabCreationState creationState, TabState frozenState) {
    mId = TabIdManager.getInstance().generateValidId(id);
    mParentId = parentId;
    mIncognito = incognito;
    mThemedApplicationContext = context != null
            ? new ContextThemeWrapper(context.getApplicationContext(), ChromeActivity.getThemeId())
            : null;
    mWindowAndroid = window;
    mLaunchType = type;
    if (mThemedApplicationContext != null) {
        Resources resources = mThemedApplicationContext.getResources();
        mIdealFaviconSize = resources.getDimensionPixelSize(R.dimen.default_favicon_size);
        mDefaultThemeColor = mIncognito
                ? ApiCompatibilityUtils.getColor(resources, R.color.incognito_primary_color)
                : ApiCompatibilityUtils.getColor(resources, R.color.default_primary_color);
        mThemeColor = calculateThemeColor(false);
    } else {
        mIdealFaviconSize = 16;
        mDefaultThemeColor = 0;
        mThemeColor = mDefaultThemeColor;
    }

    // Restore data from the TabState, if it existed.
    if (frozenState != null) {
        assert type == TabLaunchType.FROM_RESTORE;
        restoreFieldsFromState(frozenState);
    }

    setContentViewClient(new TabContentViewClient());

    mTabRedirectHandler = new TabRedirectHandler(mThemedApplicationContext);
    addObserver(mTabObserver);

    if (incognito) {
        CipherFactory.getInstance().triggerKeyGeneration();
    }

    ContextualSearchTabHelper.createForTab(this);
    MediaSessionTabHelper.createForTab(this);

    if (creationState != null) {
        mTabUma = new TabUma(creationState);
        if (frozenState == null) {
            assert creationState != TabCreationState.FROZEN_ON_RESTORE;
        } else {
            assert type == TabLaunchType.FROM_RESTORE && creationState == TabCreationState.FROZEN_ON_RESTORE;
        }
    }
}

From source file:com.yohpapa.research.simplemusicplayer.PlaybackService.java

public void onEventAsync(NotificationPrepareEvent event) {
    Log.d(TAG, "onEventAsync: NotificationPrepareEvent");

    Context context = getApplicationContext();
    ContentResolver resolver = context.getContentResolver();
    Resources resources = context.getResources();

    Cursor trackCursor = null;//from w  ww. j a  v  a  2s .c  o m
    Cursor albumCursor = null;
    try {
        Uri uri = ContentUris.withAppendedId(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, event.getTrackId());
        if (uri == null) {
            eventBus.post(new NotificationPreparedEvent(event.getTrackId(), null, null, null, null));
            return;
        }

        trackCursor = resolver
                .query(uri,
                        new String[] { MediaStore.Audio.Media.TITLE, MediaStore.Audio.Media.ARTIST,
                                MediaStore.Audio.Media.ALBUM, MediaStore.Audio.Media.ALBUM_ID, },
                        null, null, null);

        if (trackCursor == null || !trackCursor.moveToFirst() || trackCursor.getCount() != 1) {
            eventBus.post(new NotificationPreparedEvent(event.getTrackId(), null, null, null, null));
            return;
        }

        String title = CursorHelper.getString(trackCursor, MediaStore.Audio.Media.TITLE);
        String artist = CursorHelper.getString(trackCursor, MediaStore.Audio.Media.ARTIST);
        String album = CursorHelper.getString(trackCursor, MediaStore.Audio.Media.ALBUM);
        long albumId = CursorHelper.getLong(trackCursor, MediaStore.Audio.Media.ALBUM_ID);
        Bitmap artwork = null;

        if (albumId != -1L) {
            uri = ContentUris.withAppendedId(MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI, albumId);
            if (uri == null) {
                eventBus.post(new NotificationPreparedEvent(event.getTrackId(), null, null, null, null));
                return;
            }
            albumCursor = resolver.query(uri, new String[] { MediaStore.Audio.Albums.ALBUM_ART, }, null, null,
                    null);

            if (albumCursor == null || !albumCursor.moveToFirst() || albumCursor.getCount() != 1) {
                eventBus.post(new NotificationPreparedEvent(event.getTrackId(), title, artist, album, null));
                return;
            }

            String artworkPath = CursorHelper.getString(albumCursor, MediaStore.Audio.Albums.ALBUM_ART);
            Bitmap buffer = BitmapFactory.decodeFile(artworkPath);
            artwork = Bitmap.createScaledBitmap(buffer,
                    resources.getDimensionPixelSize(android.R.dimen.notification_large_icon_width),
                    resources.getDimensionPixelSize(android.R.dimen.notification_large_icon_height), false);
            if (artwork != buffer) {
                buffer.recycle();
            }
        }

        eventBus.post(new NotificationPreparedEvent(event.getTrackId(), title, artist, album, artwork));

    } finally {
        if (trackCursor != null) {
            trackCursor.close();
        }
        if (albumCursor != null) {
            albumCursor.close();
        }
    }
}

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 w w w .j  a v a2s. 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);
}