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.android.mail.browse.ConversationItemViewCoordinates.java

private ConversationItemViewCoordinates(final Context context, final Config config,
        final CoordinatesCache cache) {
    Utils.traceBeginSection("CIV coordinates constructor");
    final Resources res = context.getResources();

    final int layoutId = R.layout.conversation_item_view;

    ViewGroup view = (ViewGroup) cache.getView(layoutId);
    if (view == null) {
        view = (ViewGroup) LayoutInflater.from(context).inflate(layoutId, null);
        cache.put(layoutId, view);/*  w  ww  . j  a  v  a 2  s .  c o m*/
    }

    // Show/hide optional views before measure/layout call
    final TextView folders = (TextView) view.findViewById(R.id.folders);
    folders.setVisibility(config.areFoldersVisible() ? View.VISIBLE : View.GONE);

    View contactImagesView = view.findViewById(R.id.contact_image);

    switch (config.getGadgetMode()) {
    case GADGET_CONTACT_PHOTO:
        contactImagesView.setVisibility(View.VISIBLE);
        break;
    case GADGET_CHECKBOX:
        contactImagesView.setVisibility(View.GONE);
        contactImagesView = null;
        break;
    default:
        contactImagesView.setVisibility(View.GONE);
        contactImagesView = null;
        break;
    }

    final View replyState = view.findViewById(R.id.reply_state);
    replyState.setVisibility(config.isReplyStateVisible() ? View.VISIBLE : View.GONE);

    final View personalIndicator = view.findViewById(R.id.personal_indicator);
    personalIndicator.setVisibility(config.isPersonalIndicatorVisible() ? View.VISIBLE : View.GONE);

    setFramePadding(context, view, config.useFullPadding());

    // Layout the appropriate view.
    ViewCompat.setLayoutDirection(view, config.getLayoutDirection());
    final int widthSpec = MeasureSpec.makeMeasureSpec(config.getWidth(), MeasureSpec.EXACTLY);
    final int heightSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);

    view.measure(widthSpec, heightSpec);
    view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight());

    // Once the view is measured, let's calculate the dynamic width variables.
    folderLayoutWidth = (int) (view.getWidth() * res.getInteger(R.integer.folder_max_width_proportion) / 100.0);
    folderCellWidth = (int) (view.getWidth() * res.getInteger(R.integer.folder_cell_max_width_proportion)
            / 100.0);

    //        Utils.dumpViewTree((ViewGroup) view);

    // Records coordinates.

    // Contact images view
    if (contactImagesView != null) {
        contactImagesWidth = contactImagesView.getWidth();
        contactImagesHeight = contactImagesView.getHeight();
        contactImagesX = getX(contactImagesView);
        contactImagesY = getY(contactImagesView);
    } else {
        contactImagesX = contactImagesY = contactImagesWidth = contactImagesHeight = 0;
    }

    final boolean isRtl = ViewUtils.isViewRtl(view);

    final View star = view.findViewById(R.id.star);
    final int starPadding = res.getDimensionPixelSize(R.dimen.conv_list_star_padding_start);
    starX = getX(star) + (isRtl ? 0 : starPadding);
    starY = getY(star);
    starWidth = star.getWidth();

    final TextView senders = (TextView) view.findViewById(R.id.senders);
    final int sendersTopAdjust = getLatinTopAdjustment(senders);
    sendersX = getX(senders);
    sendersY = getY(senders) + sendersTopAdjust;
    sendersWidth = senders.getWidth();
    sendersHeight = senders.getHeight();
    sendersLineCount = SINGLE_LINE;
    sendersFontSize = senders.getTextSize();

    final TextView subject = (TextView) view.findViewById(R.id.subject);
    final int subjectTopAdjust = getLatinTopAdjustment(subject);
    subjectX = getX(subject);
    subjectY = getY(subject) + subjectTopAdjust;
    subjectWidth = subject.getWidth();
    subjectHeight = subject.getHeight();
    subjectFontSize = subject.getTextSize();

    final TextView snippet = (TextView) view.findViewById(R.id.snippet);
    final int snippetTopAdjust = getLatinTopAdjustment(snippet);
    snippetX = getX(snippet);
    snippetY = getY(snippet) + snippetTopAdjust;
    maxSnippetWidth = snippet.getWidth();
    snippetHeight = snippet.getHeight();
    snippetFontSize = snippet.getTextSize();

    if (config.areFoldersVisible()) {
        foldersLeft = getX(folders);
        foldersRight = foldersLeft + folders.getWidth();
        foldersY = getY(folders);
        foldersTypeface = folders.getTypeface();
        foldersFontSize = folders.getTextSize();
    } else {
        foldersLeft = 0;
        foldersRight = 0;
        foldersY = 0;
        foldersTypeface = null;
        foldersFontSize = 0;
    }

    final View colorBlock = view.findViewById(R.id.color_block);
    if (config.isColorBlockVisible() && colorBlock != null) {
        colorBlockX = getX(colorBlock);
        colorBlockY = getY(colorBlock);
        colorBlockWidth = colorBlock.getWidth();
        colorBlockHeight = colorBlock.getHeight();
    } else {
        colorBlockX = colorBlockY = colorBlockWidth = colorBlockHeight = 0;
    }

    if (config.isReplyStateVisible()) {
        replyStateX = getX(replyState);
        replyStateY = getY(replyState);
    } else {
        replyStateX = replyStateY = 0;
    }

    if (config.isPersonalIndicatorVisible()) {
        personalIndicatorX = getX(personalIndicator);
        personalIndicatorY = getY(personalIndicator);
    } else {
        personalIndicatorX = personalIndicatorY = 0;
    }

    final View infoIcon = view.findViewById(R.id.info_icon);
    infoIconX = getX(infoIcon);
    infoIconXRight = infoIconX + infoIcon.getWidth();
    infoIconY = getY(infoIcon);

    final TextView date = (TextView) view.findViewById(R.id.date);
    dateX = getX(date);
    dateXRight = dateX + date.getWidth();
    dateY = getY(date);
    datePaddingStart = ViewUtils.getPaddingStart(date);
    dateFontSize = date.getTextSize();
    dateYBaseline = dateY + getLatinTopAdjustment(date) + date.getBaseline();

    final View paperclip = view.findViewById(R.id.paperclip);
    paperclipY = getY(paperclip);
    paperclipPaddingStart = ViewUtils.getPaddingStart(paperclip);

    height = view.getHeight() + sendersTopAdjust;
    Utils.traceEndSection();
}

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

public void animateClosed() {
    if (!(getParent() instanceof DragLayer))
        return;// w  w w  . jav a 2s. co  m
    /* YUNOS BEGIN PB*/
    //##modules(HomeShell): ##author:guoshuai.lgs
    //##BugID:(5221896) ##date:2014/09/03
    //##decrpition: support mainmenu feature, cancel drop feature, page management feature, and so on
    if (mInfo.isMainmenuFolder() && (LauncherApplication.isMainmenuMode())) {
        onCloseComplete();
        setLayerType(LAYER_TYPE_NONE, null);
        mState = STATE_SMALL;
        mLauncher.getAppsCustomizeTabHost().setVisibility(View.VISIBLE);
    } else {
        /* YUNOS BEGIN */
        // module(FolderAnimation)
        // ##date:2014/03/24 ##author:yaodi.yd ##BugID:104016
        // removed all old animation code to avoid animation conflict
        //PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0);
        //PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 0.9f);
        //PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 0.9f);
        //final ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(this, alpha, scaleX, scaleY);
        //oa.addListener(new AnimatorListenerAdapter() {
        //    @Override
        //    public void onAnimationEnd(Animator animation) {
        /* YUNOS END */
        onCloseComplete();
        setLayerType(LAYER_TYPE_NONE, null);
        mState = STATE_SMALL;
        /*YUNOS BEGIN*/
        // ##date:2014/3/10 ##author:yaodi.yd
        final Resources r = mLauncher.getResources();
        List<View> items = getItemsInReadingOrder();
        for (View item : items) {
            item.setVisibility(View.VISIBLE);
            item.setAlpha(1);
            item.setScaleX(1);
            item.setScaleY(1);
        }
        // added for BugID:102489
        final int height = LauncherApplication.getScreenHeight();
        final int width = LauncherApplication.getScreenWidth();
        mLauncher.getIndicatorView()
                .setY((width > height ? width : height)
                        - r.getDimensionPixelSize(R.dimen.page_indicator_workspace_marginbottom)
                        - r.getDimensionPixelSize(R.dimen.page_indicator_height));
        mLauncher.getWorkspace().setVisibility(View.VISIBLE);
        mLauncher.getWindow().getDecorView().setBackground(null);
        CellLayout hotseat = mLauncher.getHotseat().getLayout();
        ShortcutAndWidgetContainer hotseatContainer = hotseat.getShortcutAndWidgetContainer();
        int hotseatChildCount = hotseatContainer.getChildCount();
        for (int i = 0; i < hotseatChildCount; i++) {
            View child = hotseatContainer.getChildAt(i);
            if (child.getAlpha() < 1) { // Added for BugID:102954
                child.setAlpha(1);
                continue;
            }
            child.setY(0); // reset y to zero, it's original position
        }
        mLauncher.getWorkspace().setAllItemsOfCurrentPageVisibility(View.VISIBLE);
        /*YUNOS BEGIN*/
        //##date:2014/06/10 ##author:guoshuai.lgs ##BugID:
        //support the folder feature in mainmenu

        /*YUNOS END*/
        /*YUNOS END*/
        /* YUNOS BEGIN */
        // module(FolderAnimation)
        // ##date:2014/03/24 ##author:yaodi.yd ##BugID:104016
        // removed all old animation code to avoid animation conflict
        //    }
        //    @Override
        //    public void onAnimationStart(Animator animation) {
        //        sendCustomAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED,
        //                getContext().getString(R.string.folder_closed));
        //        mState = STATE_ANIMATING;
        //    }
        //});
        //oa.setDuration(mExpandDuration);
        //setLayerType(LAYER_TYPE_HARDWARE, null);
        //oa.start();
        /* YUNOS END */
    }
    /*YUNOS END PB*/
}

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

private Drawable.ConstantState updateTextButtonWithIconFromExternalActivity(int buttonId,
        ComponentName activityName, int fallbackDrawableId, String toolbarResourceName) {
    Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName);
    Resources r = getResources();
    int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width);
    int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height);

    TextView button = (TextView) findViewById(buttonId);
    // If we were unable to find the icon via the meta-data, use a generic one
    if (toolbarIcon == null) {
        toolbarIcon = r.getDrawable(fallbackDrawableId);
        toolbarIcon.setBounds(0, 0, w, h);
        if (button != null) {
            button.setCompoundDrawables(toolbarIcon, null, null, null);
        }//  w  w  w  . j a  v a  2 s .  c  o  m
        return null;
    } else {
        toolbarIcon.setBounds(0, 0, w, h);
        if (button != null) {
            button.setCompoundDrawables(toolbarIcon, null, null, null);
        }
        return toolbarIcon.getConstantState();
    }
}

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

private void updateAppMarketIcon(Drawable.ConstantState d) {
    // Ensure that the new drawable we are creating has the approprate toolbar icon bounds
    Resources r = getResources();
    Drawable marketIconDrawable = d.newDrawable(r);
    int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width);
    int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height);
    marketIconDrawable.setBounds(0, 0, w, h);

    updateTextButtonWithDrawable(R.id.market_button, marketIconDrawable);
}

From source file:org.mariotaku.twidere.provider.TwidereDataProvider.java

private void displayMentionsNotification(final Context context, final ContentValues[] values) {
    final Resources res = context.getResources();
    final NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
    final boolean display_screen_name = NAME_DISPLAY_OPTION_SCREEN_NAME
            .equals(mPreferences.getString(PREFERENCE_KEY_NAME_DISPLAY_OPTION, NAME_DISPLAY_OPTION_BOTH));
    final boolean display_hires_profile_image = res.getBoolean(R.bool.hires_profile_image);
    final Intent delete_intent = new Intent(BROADCAST_NOTIFICATION_CLEARED);
    final Bundle delete_extras = new Bundle();
    delete_extras.putInt(INTENT_KEY_NOTIFICATION_ID, NOTIFICATION_ID_MENTIONS);
    delete_intent.putExtras(delete_extras);
    final Intent content_intent;
    int notified_count = 0;
    // Add statuses that not filtered to list for future use.
    for (final ContentValues value : values) {
        final ParcelableStatus status = new ParcelableStatus(value);
        if (!isFiltered(mDatabase, status)) {
            mNewMentions.add(status);/*from w ww  .  ja v a 2  s .  c  o  m*/
            mNewMentionScreenNames.add(status.screen_name);
            mNewMentionAccounts.add(status.account_id);
            notified_count++;
        }
    }
    Collections.sort(mNewMentions);
    final int mentions_size = mNewMentions.size();
    if (notified_count == 0 || mentions_size == 0 || mNewMentionScreenNames.size() == 0)
        return;
    final String title;
    if (mentions_size > 1) {
        builder.setNumber(mentions_size);
    }
    final int screen_names_size = mNewMentionScreenNames.size();
    final ParcelableStatus status = mNewMentions.get(0);
    if (mentions_size == 1) {
        final Uri.Builder uri_builder = new Uri.Builder();
        uri_builder.scheme(SCHEME_TWIDERE);
        uri_builder.authority(AUTHORITY_STATUS);
        uri_builder.appendQueryParameter(QUERY_PARAM_ACCOUNT_ID, String.valueOf(status.account_id));
        uri_builder.appendQueryParameter(QUERY_PARAM_STATUS_ID, String.valueOf(status.status_id));
        content_intent = new Intent(Intent.ACTION_VIEW, uri_builder.build());
    } else {
        content_intent = new Intent(context, HomeActivity.class);
        content_intent.setAction(Intent.ACTION_MAIN);
        content_intent.addCategory(Intent.CATEGORY_LAUNCHER);
        final Bundle content_extras = new Bundle();
        content_extras.putInt(INTENT_KEY_INITIAL_TAB, HomeActivity.TAB_POSITION_MENTIONS);
        content_intent.putExtras(content_extras);
    }
    if (screen_names_size > 1) {
        title = res.getString(R.string.notification_mention_multiple,
                display_screen_name ? "@" + status.screen_name : status.name, screen_names_size - 1);
    } else {
        title = res.getString(R.string.notification_mention,
                display_screen_name ? "@" + status.screen_name : status.name);
    }
    final String profile_image_url_string = status.profile_image_url_string;
    final File profile_image_file = mProfileImageLoader.getCachedImageFile(
            display_hires_profile_image ? getBiggerTwitterProfileImage(profile_image_url_string)
                    : profile_image_url_string);
    final int w = res.getDimensionPixelSize(R.dimen.notification_large_icon_width);
    final int h = res.getDimensionPixelSize(R.dimen.notification_large_icon_height);
    final Bitmap profile_image = profile_image_file != null && profile_image_file.isFile()
            ? BitmapFactory.decodeFile(profile_image_file.getPath())
            : null;
    final Bitmap profile_image_fallback = BitmapFactory.decodeResource(res,
            R.drawable.ic_profile_image_default);
    builder.setLargeIcon(Bitmap
            .createScaledBitmap(profile_image != null ? profile_image : profile_image_fallback, w, h, true));
    buildNotification(builder, title, title, status.text_plain, R.drawable.ic_stat_mention, null,
            content_intent, delete_intent);
    if (mentions_size > 1) {
        final NotificationCompat.InboxStyle style = new NotificationCompat.InboxStyle(builder);
        final int max = Math.min(4, mentions_size);
        for (int i = 0; i < max; i++) {
            final ParcelableStatus s = mNewMentions.get(i);
            final String name = display_screen_name ? "@" + s.screen_name : s.name;
            style.addLine(Html.fromHtml("<b>" + name + "</b>: "
                    + stripMentionText(s.text_plain, getAccountScreenName(context, s.account_id))));
        }
        if (max == 4 && mentions_size - max > 0) {
            style.addLine(context.getString(R.string.and_more, mentions_size - max));
        }
        final StringBuilder summary = new StringBuilder();
        final int accounts_count = mNewMentionAccounts.size();
        if (accounts_count > 0) {
            for (int i = 0; i < accounts_count; i++) {
                final String name = display_screen_name
                        ? "@" + getAccountScreenName(context, mNewMentionAccounts.get(i))
                        : getAccountName(context, mNewMentionAccounts.get(i));
                summary.append(name);
                if (i != accounts_count - 1) {
                    summary.append(", ");
                }
            }
            style.setSummaryText(summary);
        }
        mNotificationManager.notify(NOTIFICATION_ID_MENTIONS, style.build());
    } else {
        final Intent reply_intent = new Intent(INTENT_ACTION_COMPOSE);
        final Bundle bundle = new Bundle();
        final List<String> mentions = new Extractor().extractMentionedScreennames(status.text_plain);
        mentions.remove(status.screen_name);
        mentions.add(0, status.screen_name);
        bundle.putInt(INTENT_KEY_NOTIFICATION_ID, NOTIFICATION_ID_MENTIONS);
        bundle.putStringArray(INTENT_KEY_MENTIONS, mentions.toArray(new String[mentions.size()]));
        bundle.putLong(INTENT_KEY_ACCOUNT_ID, status.account_id);
        bundle.putLong(INTENT_KEY_IN_REPLY_TO_ID, status.status_id);
        bundle.putString(INTENT_KEY_IN_REPLY_TO_SCREEN_NAME, status.screen_name);
        bundle.putString(INTENT_KEY_IN_REPLY_TO_NAME, status.name);
        reply_intent.putExtras(bundle);
        reply_intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        builder.addAction(R.drawable.ic_menu_reply, context.getString(R.string.reply),
                PendingIntent.getActivity(context, 0, reply_intent, PendingIntent.FLAG_UPDATE_CURRENT));
        final NotificationCompat.BigTextStyle style = new NotificationCompat.BigTextStyle(builder);
        style.bigText(stripMentionText(status.text_plain, getAccountScreenName(context, status.account_id)));
        mNotificationManager.notify(NOTIFICATION_ID_MENTIONS, style.build());
    }
}

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

private void doSetup() {
    // General Assembly overview
    generalAssembly.loadCouncil(WACouncil.GENERAL_ASSEMBLY, gaData);

    // Security Council overview
    securityCouncil.loadCouncil(WACouncil.SECURITY_COUNCIL, scData);

    // Happenings
    StringBuilder happText = null;
    for (WAHappening happ : gaData.happenings) {
        if (happText == null) {
            happText = new StringBuilder();
        } else {//ww  w  . ja  va2 s  . co  m
            happText.append("<br/><br/>");
        }
        happText.append("<i>" + TagParser.parseTimestamp(this, happ.timestamp) + ":</i> " + happ.text);
    }
    if (happText != null) {
        happenings.setText(Html.fromHtml(happText.toString()));
        happenings.setMovementMethod(LinkMovementMethod.getInstance());
    } else {
        happenings.setVisibility(View.GONE);
    }

    Resources r = getResources();

    // General Assembly
    if (gaData.resolution.name != null) {
        gaTitle.setText(gaData.resolution.name);
        String catText = gaData.resolution.category;
        if (catText.equals("Repeal")) {
            catText += " of GA#" + (Integer.parseInt(gaData.resolution.option) + 1);
        } else {
            catText += "; Strength: " + gaData.resolution.option;
        }
        gaCategory.setText(catText);
        gaProposer.setText(Html.fromHtml(getString(R.string.wa_proposed_by)
                + " <a href=\"com.limewoodMedia.nsdroid.nation://" + gaData.resolution.proposedBy + "\">"
                + TagParser.idToName(gaData.resolution.proposedBy) + "</a>"));
        gaProposer.setMovementMethod(LinkMovementMethod.getInstance());
        gaNation.setText(Html.fromHtml("<b>" + nationData.name + ":</b> " + nationData.generalAssemblyVote));
        gaText.setText(Html.fromHtml(TagParser.parseTags(gaData.resolution.desc.replace("\n", "<br/>"))));
        float total = gaData.resolution.votes.forVotes + gaData.resolution.votes.againstVotes;
        int[] daysHours = Utils.getWADaysHoursLeft(gaData.resolution.voteTrack.forVotes.length);
        int days = daysHours[0];
        int hours = daysHours[1];
        gaBelow.setText(Html
                .fromHtml("<b>" + getString(R.string.wa_votes_for) + ":</b> " + gaData.resolution.votes.forVotes
                        + " (" + format.format(gaData.resolution.votes.forVotes / total) + ")<br/><b>"
                        + getString(R.string.wa_votes_against) + ":</b> " + gaData.resolution.votes.againstVotes
                        + " (" + format.format(gaData.resolution.votes.againstVotes / total) + ")<br/><br/>"
                        + getString(R.string.voting_ends, days, hours,
                                r.getQuantityString(R.plurals.days, days),
                                r.getQuantityString(R.plurals.hours, hours))));

        // Chart
        gaSeries.clear();
        XYSeries forVotes = new XYSeries("For");
        XYSeries againstVotes = new XYSeries("Against");
        int i = 0;
        int forMax = 0;
        for (Integer f : gaData.resolution.voteTrack.forVotes) {
            forVotes.add(i++, f);
            if (f > forMax) {
                forMax = f;
            }
        }
        i = 0;
        int againstMax = 0;
        for (Integer a : gaData.resolution.voteTrack.againstVotes) {
            againstVotes.add(i++, a);
            if (a > againstMax) {
                againstMax = a;
            }
        }
        gaSeries.addSeries(forVotes);
        gaSeries.addSeries(againstVotes);

        gaForRenderer = new XYSeriesRenderer();
        gaAgainstRenderer = new XYSeriesRenderer();
        setUpChartRenderer(gaRenderer, gaForRenderer, gaAgainstRenderer);
        gaRenderer.setYAxisMax(Math.max(forMax, againstMax) * 1.2f);

        LinearLayout layout = (LinearLayout) gaPage.findViewById(R.id.chart);
        gaChart = ChartFactory.getLineChartView(this, gaSeries, gaRenderer);
        layout.addView(gaChart, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                r.getDimensionPixelSize(R.dimen.wa_area_chart_height)));

        gaChart.repaint();
    } else {
        gaTitle.setText(getString(R.string.none));
        gaCategory.setVisibility(View.GONE);
        gaProposer.setVisibility(View.GONE);
        gaText.setVisibility(View.GONE);
        gaBelow.setVisibility(View.GONE);
        gaPage.findViewById(R.id.chart).setVisibility(View.GONE);
    }

    // Security Council
    if (scData.resolution.name != null) {
        scTitle.setText(scData.resolution.name);
        String catText = scData.resolution.category + "; ";
        String[] arr = scData.resolution.option.split(":");
        if (arr[0].equals("N")) {
            catText += getString(R.string.nation) + " <a href=\"com.limewoodMedia.nsdroid.nation://" + arr[1]
                    + "\">" + TagParser.idToName(arr[1]) + "</a>";
        } else if (arr[0].equals("R")) {
            catText += getString(R.string.region) + " <a href=\"com.limewoodMedia.nsdroid.region://" + arr[1]
                    + "\">" + TagParser.idToName(arr[1]) + "</a>";
        } else {
            catText += scData.resolution.option;
        }
        scCategory.setText(Html.fromHtml(catText));
        scCategory.setMovementMethod(LinkMovementMethod.getInstance());
        scProposer.setText(Html.fromHtml(getString(R.string.wa_proposed_by)
                + " <a href=\"com.limewoodMedia.nsdroid.nation://" + scData.resolution.proposedBy + "\">"
                + TagParser.idToName(scData.resolution.proposedBy) + "</a>"));
        scProposer.setMovementMethod(LinkMovementMethod.getInstance());
        scNation.setText(Html.fromHtml("<b>" + nationData.name + ":</b> " + nationData.securityCouncilVote));
        scText.setText(Html.fromHtml(TagParser.parseTags(scData.resolution.desc.replace("\n", "<br/>"))));
        float total = scData.resolution.votes.forVotes + scData.resolution.votes.againstVotes;
        int[] daysHours = Utils.getWADaysHoursLeft(scData.resolution.voteTrack.forVotes.length);
        int days = daysHours[0];
        int hours = daysHours[1];
        scBelow.setText(Html
                .fromHtml("<b>" + getString(R.string.wa_votes_for) + ":</b> " + scData.resolution.votes.forVotes
                        + " (" + format.format(scData.resolution.votes.forVotes / total) + ")<br/><b>"
                        + getString(R.string.wa_votes_against) + ":</b> " + scData.resolution.votes.againstVotes
                        + " (" + format.format(scData.resolution.votes.againstVotes / total) + ")<br/><br/>"
                        + getString(R.string.voting_ends, days, hours,
                                r.getQuantityString(R.plurals.days, days),
                                r.getQuantityString(R.plurals.hours, hours))));

        // Chart
        scSeries.clear();
        XYSeries forVotes = new XYSeries("For");
        XYSeries againstVotes = new XYSeries("Against");
        int i = 0;
        int forMax = 0;
        for (Integer f : scData.resolution.voteTrack.forVotes) {
            forVotes.add(i++, f);
            if (f > forMax) {
                forMax = f;
            }
        }
        i = 0;
        int againstMax = 0;
        for (Integer a : scData.resolution.voteTrack.againstVotes) {
            againstVotes.add(i++, a);
            if (a > againstMax) {
                againstMax = a;
            }
        }
        scSeries.addSeries(forVotes);
        scSeries.addSeries(againstVotes);

        scForRenderer = new XYSeriesRenderer();
        scAgainstRenderer = new XYSeriesRenderer();
        setUpChartRenderer(scRenderer, scForRenderer, scAgainstRenderer);
        scRenderer.setYAxisMax(Math.max(forMax, againstMax) * 1.2f);

        LinearLayout layout = (LinearLayout) scPage.findViewById(R.id.chart);
        scChart = ChartFactory.getLineChartView(this, scSeries, scRenderer);
        layout.addView(scChart, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                r.getDimensionPixelSize(R.dimen.wa_area_chart_height)));

        scChart.repaint();
    } else {
        scTitle.setText(getString(R.string.none));
        scCategory.setVisibility(View.GONE);
        scProposer.setVisibility(View.GONE);
        scText.setVisibility(View.GONE);
        scBelow.setVisibility(View.GONE);
        scPage.findViewById(R.id.chart).setVisibility(View.GONE);
    }

    supportInvalidateOptionsMenu();
}

From source file:com.appeaser.sublimepickerlibrary.timepicker.RadialTimePickerView.java

private void init(AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    Context context = getContext();

    // Pull disabled alpha from theme.
    final TypedValue outValue = new TypedValue();
    context.getTheme().resolveAttribute(android.R.attr.disabledAlpha, outValue, true);
    mDisabledAlpha = outValue.getFloat();

    // process style attributes
    final Resources res = getResources();
    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.RadialTimePickerView, defStyleAttr,
            defStyleRes);/*from   w w  w  .ja v  a  2  s .  c  o m*/

    mTypeface = Typeface.create("sans-serif", Typeface.NORMAL);

    // Initialize all alpha values to opaque.
    for (int i = 0; i < mAlpha.length; i++) {
        mAlpha[i] = new IntHolder(ALPHA_OPAQUE);
    }

    mTextColor[HOURS] = a.getColorStateList(R.styleable.RadialTimePickerView_spNumbersTextColor);
    mTextColor[HOURS_INNER] = a.getColorStateList(R.styleable.RadialTimePickerView_spNumbersInnerTextColor);
    mTextColor[MINUTES] = mTextColor[HOURS];

    mPaint[HOURS] = new Paint();
    mPaint[HOURS].setAntiAlias(true);
    mPaint[HOURS].setTextAlign(Paint.Align.CENTER);

    mPaint[MINUTES] = new Paint();
    mPaint[MINUTES].setAntiAlias(true);
    mPaint[MINUTES].setTextAlign(Paint.Align.CENTER);

    final ColorStateList selectorColors = a
            .getColorStateList(R.styleable.RadialTimePickerView_spNumbersSelectorColor);

    int selectorActivatedColor = Color.BLACK;
    if (selectorColors != null) {
        selectorActivatedColor = selectorColors
                .getColorForState(SUtils.resolveStateSet(SUtils.STATE_ENABLED | SUtils.STATE_ACTIVATED), 0);
    }

    mPaintCenter.setColor(selectorActivatedColor);
    mPaintCenter.setAntiAlias(true);

    final int[] activatedStateSet = SUtils.resolveStateSet(SUtils.STATE_ENABLED | SUtils.STATE_ACTIVATED);

    mSelectorColor = selectorActivatedColor;
    mSelectorDotColor = mTextColor[HOURS].getColorForState(activatedStateSet, 0);

    mPaintSelector[HOURS][SELECTOR_CIRCLE] = new Paint();
    mPaintSelector[HOURS][SELECTOR_CIRCLE].setAntiAlias(true);

    mPaintSelector[HOURS][SELECTOR_DOT] = new Paint();
    mPaintSelector[HOURS][SELECTOR_DOT].setAntiAlias(true);

    mPaintSelector[HOURS][SELECTOR_LINE] = new Paint();
    mPaintSelector[HOURS][SELECTOR_LINE].setAntiAlias(true);
    mPaintSelector[HOURS][SELECTOR_LINE].setStrokeWidth(2);

    mPaintSelector[MINUTES][SELECTOR_CIRCLE] = new Paint();
    mPaintSelector[MINUTES][SELECTOR_CIRCLE].setAntiAlias(true);

    mPaintSelector[MINUTES][SELECTOR_DOT] = new Paint();
    mPaintSelector[MINUTES][SELECTOR_DOT].setAntiAlias(true);

    mPaintSelector[MINUTES][SELECTOR_LINE] = new Paint();
    mPaintSelector[MINUTES][SELECTOR_LINE].setAntiAlias(true);
    mPaintSelector[MINUTES][SELECTOR_LINE].setStrokeWidth(2);

    mPaintBackground.setColor(a.getColor(R.styleable.RadialTimePickerView_spNumbersBackgroundColor,
            ContextCompat.getColor(context, R.color.timepicker_default_numbers_background_color_material)));
    mPaintBackground.setAntiAlias(true);

    mSelectorRadius = res.getDimensionPixelSize(R.dimen.sp_timepicker_selector_radius);
    mSelectorStroke = res.getDimensionPixelSize(R.dimen.sp_timepicker_selector_stroke);
    mSelectorDotRadius = res.getDimensionPixelSize(R.dimen.sp_timepicker_selector_dot_radius);
    mCenterDotRadius = res.getDimensionPixelSize(R.dimen.sp_timepicker_center_dot_radius);

    mTextSize[HOURS] = res.getDimensionPixelSize(R.dimen.sp_timepicker_text_size_normal);
    mTextSize[MINUTES] = res.getDimensionPixelSize(R.dimen.sp_timepicker_text_size_normal);
    mTextSize[HOURS_INNER] = res.getDimensionPixelSize(R.dimen.sp_timepicker_text_size_inner);

    mTextInset[HOURS] = res.getDimensionPixelSize(R.dimen.sp_timepicker_text_inset_normal);
    mTextInset[MINUTES] = res.getDimensionPixelSize(R.dimen.sp_timepicker_text_inset_normal);
    mTextInset[HOURS_INNER] = res.getDimensionPixelSize(R.dimen.sp_timepicker_text_inset_inner);

    mShowHours = true;
    mIs24HourMode = false;
    mAmOrPm = AM;

    // Set up accessibility components.
    mTouchHelper = new RadialPickerTouchHelper();
    ViewCompat.setAccessibilityDelegate(this, mTouchHelper);

    if (ViewCompat.getImportantForAccessibility(this) == ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_AUTO) {
        ViewCompat.setImportantForAccessibility(this, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES);
    }

    initHoursAndMinutesText();
    initData();

    a.recycle();

    // Initial values
    final Calendar calendar = Calendar.getInstance(Locale.getDefault());
    final int currentHour = calendar.get(Calendar.HOUR_OF_DAY);
    final int currentMinute = calendar.get(Calendar.MINUTE);

    setCurrentHourInternal(currentHour, false, false);
    setCurrentMinuteInternal(currentMinute, false);

    setHapticFeedbackEnabled(true);
}

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

/**
 * Initializes various states for this workspace.
 *///w ww . j  av  a 2 s  .co  m
protected void initWorkspace() {
    Context context = getContext();
    mCurrentPage = mDefaultPage;
    Launcher.setScreen(mCurrentPage);
    LauncherApplication app = (LauncherApplication) context.getApplicationContext();
    mIconCache = app.getIconCache();
    setWillNotDraw(false);
    setChildrenDrawnWithCacheEnabled(true);

    final Resources res = getResources();
    try {
        mBackground = res.getDrawable(R.drawable.apps_customize_bg);
    } catch (Resources.NotFoundException e) {
        // In this case, we will skip drawing background protection
    }

    mWallpaperOffset = new WallpaperOffsetInterpolator();
    Display display = mLauncher.getWindowManager().getDefaultDisplay();
    display.getSize(mDisplaySize);
    mWallpaperTravelWidth = (int) (mDisplaySize.x
            * wallpaperTravelToScreenWidthRatio(mDisplaySize.x, mDisplaySize.y));

    mMaxDistanceForFolderCreation = (0.55f * res.getDimensionPixelSize(R.dimen.app_icon_size));
    mFlingThresholdVelocity = (int) (FLING_THRESHOLD_VELOCITY * mDensity);
}

From source file:org.mariotaku.twidere.provider.TwidereDataProvider.java

private void displayMessagesNotification(final Context context, final ContentValues[] values) {
    final Resources res = context.getResources();
    final NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
    final boolean display_screen_name = NAME_DISPLAY_OPTION_SCREEN_NAME
            .equals(mPreferences.getString(PREFERENCE_KEY_NAME_DISPLAY_OPTION, NAME_DISPLAY_OPTION_BOTH));
    final boolean display_hires_profile_image = res.getBoolean(R.bool.hires_profile_image);
    final Intent delete_intent = new Intent(BROADCAST_NOTIFICATION_CLEARED);
    final Bundle delete_extras = new Bundle();
    delete_extras.putInt(INTENT_KEY_NOTIFICATION_ID, NOTIFICATION_ID_DIRECT_MESSAGES);
    delete_intent.putExtras(delete_extras);
    final Intent content_intent;
    int notified_count = 0;
    for (final ContentValues value : values) {
        final String screen_name = value.getAsString(DirectMessages.SENDER_SCREEN_NAME);
        final ParcelableDirectMessage message = new ParcelableDirectMessage(value);
        mNewMessages.add(message);/*  w w w  .  ja va2 s  .  co  m*/
        mNewMessageScreenNames.add(screen_name);
        mNewMessageAccounts.add(message.account_id);
        notified_count++;
    }
    Collections.sort(mNewMessages);
    final int messages_size = mNewMessages.size();
    if (notified_count == 0 || messages_size == 0 || mNewMessageScreenNames.size() == 0)
        return;
    final String title;
    if (messages_size > 1) {
        builder.setNumber(messages_size);
    }
    final int screen_names_size = mNewMessageScreenNames.size();
    final ParcelableDirectMessage message = mNewMessages.get(0);
    if (messages_size == 1) {
        final Uri.Builder uri_builder = new Uri.Builder();
        final long account_id = message.account_id;
        final long conversation_id = message.sender_id;
        uri_builder.scheme(SCHEME_TWIDERE);
        uri_builder.authority(AUTHORITY_DIRECT_MESSAGES_CONVERSATION);
        uri_builder.appendQueryParameter(QUERY_PARAM_ACCOUNT_ID, String.valueOf(account_id));
        uri_builder.appendQueryParameter(QUERY_PARAM_CONVERSATION_ID, String.valueOf(conversation_id));
        content_intent = new Intent(Intent.ACTION_VIEW, uri_builder.build());
    } else {
        content_intent = new Intent(context, HomeActivity.class);
        content_intent.setAction(Intent.ACTION_MAIN);
        content_intent.addCategory(Intent.CATEGORY_LAUNCHER);
        final Bundle content_extras = new Bundle();
        content_extras.putInt(INTENT_KEY_INITIAL_TAB, HomeActivity.TAB_POSITION_MESSAGES);
        content_intent.putExtras(content_extras);
    }
    if (screen_names_size > 1) {
        title = res.getString(R.string.notification_direct_message_multiple,
                display_screen_name ? "@" + message.sender_screen_name : message.sender_name,
                screen_names_size - 1);
    } else {
        title = res.getString(R.string.notification_direct_message,
                display_screen_name ? "@" + message.sender_screen_name : message.sender_name);
    }
    final String text_plain = message.text_plain;
    final String profile_image_url_string = message.sender_profile_image_url_string;
    final File profile_image_file = mProfileImageLoader.getCachedImageFile(
            display_hires_profile_image ? getBiggerTwitterProfileImage(profile_image_url_string)
                    : profile_image_url_string);
    final int w = res.getDimensionPixelSize(R.dimen.notification_large_icon_width);
    final int h = res.getDimensionPixelSize(R.dimen.notification_large_icon_height);
    final Bitmap profile_image = profile_image_file != null && profile_image_file.isFile()
            ? BitmapFactory.decodeFile(profile_image_file.getPath())
            : null;
    final Bitmap profile_image_fallback = BitmapFactory.decodeResource(res,
            R.drawable.ic_profile_image_default);
    builder.setLargeIcon(Bitmap
            .createScaledBitmap(profile_image != null ? profile_image : profile_image_fallback, w, h, true));
    buildNotification(builder, title, title, text_plain, R.drawable.ic_stat_direct_message, null,
            content_intent, delete_intent);
    final StringBuilder summary = new StringBuilder();
    final int accounts_count = mNewMessageAccounts.size();
    if (accounts_count > 0) {
        for (int i = 0; i < accounts_count; i++) {
            final String name = display_screen_name
                    ? "@" + getAccountScreenName(context, mNewMessageAccounts.get(i))
                    : getAccountName(context, mNewMessageAccounts.get(i));
            summary.append(name);
            if (i != accounts_count - 1) {
                summary.append(", ");
            }
        }
    }
    if (messages_size > 1) {
        final NotificationCompat.InboxStyle style = new NotificationCompat.InboxStyle(builder);
        final int max = Math.min(4, messages_size);
        for (int i = 0; i < max; i++) {
            final ParcelableDirectMessage s = mNewMessages.get(i);
            final String name = display_screen_name ? "@" + s.sender_screen_name : s.sender_name;
            style.addLine(Html.fromHtml("<b>" + name + "</b>: " + s.text_plain));
        }
        if (max == 4 && messages_size - max > 0) {
            style.addLine(context.getString(R.string.and_more, messages_size - max));
        }
        style.setSummaryText(summary);
        mNotificationManager.notify(NOTIFICATION_ID_DIRECT_MESSAGES, style.build());
    } else {
        final NotificationCompat.BigTextStyle style = new NotificationCompat.BigTextStyle(builder);
        style.bigText(message.text_plain);
        style.setSummaryText(summary);
        mNotificationManager.notify(NOTIFICATION_ID_DIRECT_MESSAGES, style.build());
    }
}

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

public void beginDragShared(View child, DragSource source) {
    Resources r = getResources();

    // The drag bitmap follows the touch point around on the screen
    final Bitmap b = createDragBitmap(child, new Canvas(), DRAG_BITMAP_PADDING);

    final int bmpWidth = b.getWidth();
    final int bmpHeight = b.getHeight();

    float scale = mLauncher.getDragLayer().getLocationInDragLayer(child, mTempXY);
    int dragLayerX = Math.round(mTempXY[0] - (bmpWidth - scale * child.getWidth()) / 2);
    int dragLayerY = Math.round(mTempXY[1] - (bmpHeight - scale * bmpHeight) / 2 - DRAG_BITMAP_PADDING / 2);

    Point dragVisualizeOffset = null;
    Rect dragRect = null;/*from  ww  w .jav a 2 s  .  c  o  m*/
    if (child instanceof BubbleTextView || child instanceof PagedViewIcon) {
        int iconSize = r.getDimensionPixelSize(R.dimen.app_icon_size);
        int iconPaddingTop = r.getDimensionPixelSize(R.dimen.app_icon_padding_top);
        int top = child.getPaddingTop();
        int left = (bmpWidth - iconSize) / 2;
        int right = left + iconSize;
        int bottom = top + iconSize;
        dragLayerY += top;
        // Note: The drag region is used to calculate drag layer offsets, but the
        // dragVisualizeOffset in addition to the dragRect (the size) to position the outline.
        dragVisualizeOffset = new Point(-DRAG_BITMAP_PADDING / 2, iconPaddingTop - DRAG_BITMAP_PADDING / 2);
        dragRect = new Rect(left, top, right, bottom);
    } else if (child instanceof FolderIcon) {
        int previewSize = r.getDimensionPixelSize(R.dimen.folder_preview_size);
        dragRect = new Rect(0, 0, child.getWidth(), previewSize);
    }

    // Clear the pressed state if necessary
    if (child instanceof BubbleTextView) {
        BubbleTextView icon = (BubbleTextView) child;
        icon.clearPressedOrFocusedBackground();
    }

    mDragController.startDrag(b, dragLayerX, dragLayerY, source, child.getTag(),
            DragController.DRAG_ACTION_MOVE, dragVisualizeOffset, dragRect, scale);
    b.recycle();

    // Show the scrolling indicator when you pick up an item
    showScrollingIndicator(false);
}