Example usage for android.app Activity getResources

List of usage examples for android.app Activity getResources

Introduction

In this page you can find the example usage for android.app Activity getResources.

Prototype

@Override
    public Resources getResources() 

Source Link

Usage

From source file:com.xandy.calendar.month.MonthByWeekFragment.java

@Override
public void onAttach(Activity activity) {
    super.onAttach(activity);
    mTZUpdater.run();/*from w w  w. j  a  va 2  s.  com*/
    if (mAdapter != null) {
        mAdapter.setSelectedDay(mSelectedDay);
    }
    mIsDetached = false;

    ViewConfiguration viewConfig = ViewConfiguration.get(activity);
    mMinimumTwoMonthFlingVelocity = viewConfig.getScaledMaximumFlingVelocity() / 2;
    Resources res = activity.getResources();
    mShowCalendarControls = Utils.getConfigBool(activity, R.bool.show_calendar_controls);
    // Synchronized the loading time of the month's events with the animation of the
    // calendar controls.
    if (mShowCalendarControls) {
        mEventsLoadingDelay = res.getInteger(R.integer.calendar_controls_animation_time);
    }
    mShowDetailsInMonth = res.getBoolean(R.bool.show_details_in_month);
}

From source file:com.android.calendar.month.MonthByWeekFragment.java

@Override
public void onAttach(Activity activity) {
    super.onAttach(activity);
    mTZUpdater.run();//from w  w  w  .  ja  v a2  s  .  c  om
    if (mAdapter != null) {
        mAdapter.setSelectedDay(mSelectedDay);
    }
    mIsDetached = false;

    ViewConfiguration viewConfig = ViewConfiguration.get(activity);
    mMinimumTwoMonthFlingVelocity = viewConfig.getScaledMaximumFlingVelocity() / 2;
    Resources res = activity.getResources();
    mShowCalendarControls = Utils.getConfigBool(activity, R.bool.show_calendar_controls);
    // Synchronized the loading time of the month's events with the
    // animation of the
    // calendar controls.
    if (mShowCalendarControls) {
        mEventsLoadingDelay = res.getInteger(R.integer.calendar_controls_animation_time);
    }
    mShowDetailsInMonth = res.getBoolean(R.bool.show_details_in_month);
}

From source file:com.hybris.mobile.lib.ui.view.Alert.java

/**
 * Configure the alert/*www  . j  av  a2s  .  c o m*/
 *
 * @param context       application-specific resources
 * @param configuration describes all device configuration information
 * @param messageType   CRITICAL, ERROR, SUCCESS, WARNING
 * @return Device configuration information
 */
private static Configuration setUpConfiguration(Activity context, Configuration configuration,
        Type messageType) {

    if (configuration == null) {
        configuration = new Configuration();
    }

    // Main configuration
    if (configuration.getHeight() == -1) {
        configuration.setHeight();
    }

    if (configuration.getDuration() == -1) {
        configuration.setDuration();
    }

    if (configuration.getIconResId() == -1 && configuration.isCloseable()) {
        configuration.setIconResId(R.drawable.alert_close_icon_white);
    }

    if (configuration.getIconPosition() == null) {
        configuration.setIconPosition(Position.RIGHT);
    }

    if (configuration.getOrientation() == null) {
        configuration.setOrientation(Orientation.TOP);
    }

    // Configuration specific to the message type
    if (messageType != null) {
        configuration.setMessageType(messageType.getType());

        switch (messageType) {
        case CRITICAL:
            configuration
                    .setUpBackgroundColor(context.getResources().getColor(R.color.background_alert_critical));
            configuration.setUpTextColor(context.getResources().getColor(R.color.text_alert_critical));
            break;

        case ERROR:
            configuration.setUpBackgroundColor(context.getResources().getColor(R.color.background_alert_error));
            configuration.setUpTextColor(context.getResources().getColor(R.color.text_alert_error));
            break;

        case WARNING:
            configuration
                    .setUpBackgroundColor(context.getResources().getColor(R.color.background_alert_warning));
            configuration.setUpTextColor(context.getResources().getColor(R.color.text_alert_warning));
            break;

        case SUCCESS:
            configuration
                    .setUpBackgroundColor(context.getResources().getColor(R.color.background_alert_success));
            configuration.setUpTextColor(context.getResources().getColor(R.color.text_alert_success));
            break;
        }
    }

    return configuration;
}

From source file:org.solovyev.android.calculator.ActivityUi.java

private void addHelpInfo(@Nonnull Activity activity, @Nonnull View root) {
    if (CalculatorApplication.isMonkeyRunner(activity)) {
        if (root instanceof ViewGroup) {
            final TextView helperTextView = new TextView(activity);

            final DisplayMetrics dm = new DisplayMetrics();
            activity.getWindowManager().getDefaultDisplay().getMetrics(dm);

            helperTextView.setTextSize(15);
            helperTextView.setTextColor(Color.WHITE);

            final Configuration c = activity.getResources().getConfiguration();

            final StringBuilder helpText = new StringBuilder();
            helpText.append("Size: ");
            if (Views.isLayoutSizeAtLeast(Configuration.SCREENLAYOUT_SIZE_XLARGE, c)) {
                helpText.append("xlarge");
            } else if (Views.isLayoutSizeAtLeast(Configuration.SCREENLAYOUT_SIZE_LARGE, c)) {
                helpText.append("large");
            } else if (Views.isLayoutSizeAtLeast(Configuration.SCREENLAYOUT_SIZE_NORMAL, c)) {
                helpText.append("normal");
            } else if (Views.isLayoutSizeAtLeast(Configuration.SCREENLAYOUT_SIZE_SMALL, c)) {
                helpText.append("small");
            } else {
                helpText.append("unknown");
            }//from w  w w .j  ava  2s . co m

            helpText.append(" (").append(dm.widthPixels).append("x").append(dm.heightPixels).append(")");

            helpText.append(" Density: ");
            switch (dm.densityDpi) {
            case DisplayMetrics.DENSITY_LOW:
                helpText.append("ldpi");
                break;
            case DisplayMetrics.DENSITY_MEDIUM:
                helpText.append("mdpi");
                break;
            case DisplayMetrics.DENSITY_HIGH:
                helpText.append("hdpi");
                break;
            case DisplayMetrics.DENSITY_XHIGH:
                helpText.append("xhdpi");
                break;
            case DisplayMetrics.DENSITY_TV:
                helpText.append("tv");
                break;
            }

            helpText.append(" (").append(dm.densityDpi).append(")");

            helperTextView.setText(helpText);

            ((ViewGroup) root).addView(helperTextView, new ViewGroup.LayoutParams(
                    ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
        }
    }
}

From source file:com.vuze.android.remote.SessionInfo.java

public static void showUrlFailedDialog(final Activity activity, final String errMsg, final String url,
        final String sample) {
    if (activity == null) {
        Log.e(null, "No activity for error message " + errMsg);
        return;/*from w  ww . j av a2s.  c  om*/
    }
    activity.runOnUiThread(new Runnable() {
        public void run() {
            if (activity.isFinishing()) {
                return;
            }
            String s = activity.getResources().getString(R.string.torrent_url_add_failed, url, sample);

            Spanned msg = Html.fromHtml(s);
            Builder builder = new AlertDialog.Builder(activity).setMessage(msg).setCancelable(true)
                    .setNegativeButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) {
                        }
                    }).setNeutralButton(R.string.torrent_url_add_failed_openurl, new OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
                            activity.startActivity(intent);
                        }
                    });
            builder.show();
        }
    });

}

From source file:io.branch.sdk.BranchUniversalObjectProxy.java

@Kroll.method
public void showShareSheet(KrollDict options, KrollDict controlParams) {
    Log.d(LCAT, "start showShareSheet");
    final Activity activity = this.getActivity();

    String subject = "";
    String body = "";

    if (controlParams.containsKey("$email_subject")) {
        subject = controlParams.getString("$email_subject");
    }//from   ww w. ja v  a  2s  .  c  o m

    if (controlParams.containsKey("$email_body")) {
        body = controlParams.getString("$email_body");
    }

    final ShareSheetStyle shareSheetStyle = new ShareSheetStyle(activity, subject, body)
            .setCopyUrlStyle(activity.getResources().getDrawable(android.R.drawable.ic_menu_send), "Copy",
                    "Added to clipboard")
            .setMoreOptionStyle(activity.getResources().getDrawable(android.R.drawable.ic_menu_search),
                    "Show more")
            .addPreferredSharingOption(SharingHelper.SHARE_WITH.FACEBOOK)
            .addPreferredSharingOption(SharingHelper.SHARE_WITH.TWITTER)
            .addPreferredSharingOption(SharingHelper.SHARE_WITH.EMAIL);

    final LinkProperties linkProperties = createLinkPropertiesDict(options, controlParams);

    activity.runOnUiThread(new Runnable() {
        public void run() {
            branchUniversalObject.showShareSheet(activity, linkProperties, shareSheetStyle,
                    new ShowShareSheetListener());
        }
    });
}

From source file:com.hannesdorfmann.FeedAdapter.java

public FeedAdapter(Activity hostActivity, int columns, boolean pocketInstalled) {
    this.host = hostActivity;
    this.columns = columns;
    this.pocketIsInstalled = pocketInstalled;
    layoutInflater = LayoutInflater.from(host);
    comparator = new PlaidItemComparator();
    items = new ArrayList<>();
    setHasStableIds(true);//  w  ww.java 2  s . c  o  m
    TypedArray placeholderColors = hostActivity.getResources().obtainTypedArray(R.array.loading_placeholders);
    shotLoadingPlaceholders = new ColorDrawable[placeholderColors.length()];
    for (int i = 0; i < placeholderColors.length(); i++) {
        shotLoadingPlaceholders[i] = new ColorDrawable(placeholderColors.getColor(i, Color.DKGRAY));
    }
}

From source file:com.limecreativelabs.sherlocksupport.ActionBarDrawerToggleCompat.java

/**
 * Construct a new ActionBarDrawerToggle.
 * <p/>/*from www  .  jav a  2 s  .  c om*/
 * <p>The given {@link android.app.Activity} will be linked to the specified {@link android.support.v4.widget.DrawerLayout}.
 * The provided drawer indicator drawable will animate slightly off-screen as the drawer
 * is opened, indicating that in the open state the drawer will move off-screen when pressed
 * and in the closed state the drawer will move on-screen when pressed.</p>
 * <p/>
 * <p>String resources must be provided to describe the open/close drawer actions for
 * accessibility services.</p>
 *
 * @param activity                  The Activity hosting the drawer
 * @param drawerLayout              The DrawerLayout to link to the given Activity's ActionBar
 * @param drawerImageRes            A Drawable resource to use as the drawer indicator
 * @param openDrawerContentDescRes  A String resource to describe the "open drawer" action
 *                                  for accessibility
 * @param closeDrawerContentDescRes A String resource to describe the "close drawer" action
 *                                  for accessibility
 */
public ActionBarDrawerToggleCompat(Activity activity, DrawerLayout drawerLayout, int drawerImageRes,
        int openDrawerContentDescRes, int closeDrawerContentDescRes) {
    mActivity = activity;
    mDrawerLayout = drawerLayout;
    mDrawerImageResource = drawerImageRes;
    mOpenDrawerContentDescRes = openDrawerContentDescRes;
    mCloseDrawerContentDescRes = closeDrawerContentDescRes;

    mThemeImage = IMPL.getThemeUpIndicator(activity);
    mDrawerImage = activity.getResources().getDrawable(drawerImageRes);
    mSlider = new SlideDrawable(mDrawerImage);
    mSlider.setOffsetBy(1.f / 3);
}

From source file:at.flack.FacebookMainActivity.java

public void updateContacts(Activity activity) {
    if (MainActivity.getFbcontacts() == null || MainActivity.getFbcontacts().size() <= 0) {
        showErrorMessage(activity, true);
        if (getProgressbar() != null)
            getProgressbar().setVisibility(View.INVISIBLE);
        return;//from   w w  w  .j  a v a2 s . c o  m
    }
    showErrorMessage(activity, false);

    MainActivity.setFblistItems(new ArrayList<ContactModel>());
    ContactModel model = null;
    Resources res = activity.getResources();
    for (FacebookContact fbc : MainActivity.getFbcontacts()) {
        model = new ContactModel(ProfilePictureCache.getInstance(activity).get(fbc.getName()),
                shortName(fbc.getName()), fbc.getLastMessage(), fbc.getTime(), fbc.isUnread(), fbc.isOnline(),
                fbc.isMobile());
        if (KeySafe.getInstance(activity).contains(fbc.getTid())) {
            KeyEntity key = KeySafe.getInstance(activity).get(fbc.getTid());
            if (key.getVersion() != KeyEntity.ECDH_PRIVATE_KEY) {
                model.setEncrypted(View.VISIBLE);
                try {
                    model.setLastMessage(new Message(model.getLastMessage()).decryptedMessage(key));
                } catch (MessageDecrypterException e) {
                }
            }
        }
        // Pre Shared Exchange
        if ((fbc.getLastMessage().toString().length() == 10 || fbc.getLastMessage().toString().length() == 9)
                && fbc.getLastMessage().toString().charAt(0) == '%') { // 4
            if (Base64.isPureBase64(fbc.getLastMessage().toString().substring(1, 9))) {
                model.setLastMessage(res.getString(R.string.handshake_message));
            }
        }
        // DH Exchange
        if (fbc.getLastMessage().toString().length() >= 120 && fbc.getLastMessage().toString().length() < 125
                && fbc.getLastMessage().toString().charAt(0) == '%') { // DH
            // Exchange!
            if (Base64.isPureBase64(fbc.getLastMessage().toString().substring(1,
                    fbc.getLastMessage().toString().lastIndexOf("=")))) {
                model.setLastMessage(res.getString(R.string.handshake_message));
            }
        }
        if (smiley_helper != null)
            model.setLastMessage(smiley_helper.parseAndroid(model.getLastMessage()));
        MainActivity.getFblistItems().add(model);
    }

    if (contactList != null && contactList.getAdapter() == null) {
        ContactAdapter arrayAdapter = new ContactAdapter(activity, MainActivity.getFblistItems(), 1);
        contactList.setAdapter(arrayAdapter);
        contactList.setSelection(0);

    } else {
        if (contactList != null) {
            ((ContactAdapter) ((HeaderViewListAdapter) contactList.getAdapter()).getWrappedAdapter())
                    .refill(MainActivity.getFblistItems(), 1);

        }
    }
    if (swipe != null)
        swipe.setRefreshing(false);
    if (getProgressbar() != null)
        getProgressbar().setVisibility(View.INVISIBLE);
    if (loadmore != null)
        loadmore.setEnabled(true);

}

From source file:com.actionbarsherlock.app.ActionBarSherlockDrawerToggle.java

/**
 * Construct a new ActionBarDrawerToggle.
 * /*w ww .j a  v a  2  s .co  m*/
 * <p>
 * The given {@link Activity} will be linked to the specified
 * {@link DrawerLayout}. The provided drawer indicator drawable will animate
 * slightly off-screen as the drawer is opened, indicating that in the open
 * state the drawer will move off-screen when pressed and in the closed
 * state the drawer will move on-screen when pressed.
 * </p>
 * 
 * <p>
 * String resources must be provided to describe the open/close drawer
 * actions for accessibility services.
 * </p>
 * 
 * @param activity
 *            The Activity hosting the drawer
 * @param drawerLayout
 *            The DrawerLayout to link to the given Activity's ActionBar
 * @param drawerImageRes
 *            A Drawable resource to use as the drawer indicator
 * @param openDrawerContentDescRes
 *            A String resource to describe the "open drawer" action for
 *            accessibility
 * @param closeDrawerContentDescRes
 *            A String resource to describe the "close drawer" action for
 *            accessibility
 */
public ActionBarSherlockDrawerToggle(Activity activity, DrawerLayout drawerLayout, int drawerImageRes,
        int openDrawerContentDescRes, int closeDrawerContentDescRes) {
    mActivity = activity;
    mDrawerLayout = drawerLayout;
    mDrawerImageResource = drawerImageRes;
    mOpenDrawerContentDescRes = openDrawerContentDescRes;
    mCloseDrawerContentDescRes = closeDrawerContentDescRes;

    mThemeImage = IMPL.getThemeUpIndicator(activity);
    mDrawerImage = activity.getResources().getDrawable(drawerImageRes);
    mSlider = new SlideDrawable(mDrawerImage);
    mSlider.setOffsetBy(1.f / 3);
}