Example usage for android.content.res Resources getDrawable

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

Introduction

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

Prototype

@Deprecated
public Drawable getDrawable(@DrawableRes int id) throws NotFoundException 

Source Link

Document

Return a drawable object associated with a particular resource ID.

Usage

From source file:com.sonetel.plugins.sonetelcallthru.CallThru.java

@Override
public void onReceive(final Context context, Intent intent) {
    if (SipManager.ACTION_GET_PHONE_HANDLERS.equals(intent.getAction())) {
        // Retrieve and cache infos from the phone app 
        if (!sPhoneAppInfoLoaded) {
            Resources r = context.getResources();
            BitmapDrawable drawable = (BitmapDrawable) r.getDrawable(R.drawable.ic_wizard_sonetel);
            sPhoneAppBmp = drawable.getBitmap();

            sPhoneAppInfoLoaded = true;//from   w  w w  .j a  va  2 s.  co  m
        }

        Bundle results = getResultExtras(true);
        //if(pendingIntent != null) {
        //   results.putParcelable(CallHandlerPlugin.EXTRA_REMOTE_INTENT_TOKEN, pendingIntent);
        //}
        results.putString(Intent.EXTRA_TITLE, "Call thru");// context.getResources().getString(R.string.use_pstn));
        if (sPhoneAppBmp != null) {
            results.putParcelable(Intent.EXTRA_SHORTCUT_ICON, sPhoneAppBmp);
        }
        if (intent.getStringExtra(Intent.EXTRA_TEXT) == null)
            return;

        //final PendingIntent pendingIntent = null;
        final String callthrunum = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
        final String dialledNum = intent.getStringExtra(Intent.EXTRA_TEXT);
        // We must handle that clean way cause when call just to 
        // get the row in account list expect this to reply correctly
        if (callthrunum != null && PhoneCapabilityTester.isPhone(context)) {

            if (!callthrunum.equalsIgnoreCase("")) {
                DBAdapter dbAdapt = new DBAdapter(context);

                // Build pending intent

                SipAccount = dbAdapt.getAccount(1);

                if (SipAccount != null) {

                    Intent i = new Intent(Intent.ACTION_CALL);
                    i.setData(Uri.fromParts("tel", callthrunum, null));
                    final PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, i,
                            PendingIntent.FLAG_CANCEL_CURRENT);

                    NetWorkThread = new Thread() {
                        public void run() {
                            SendMsgToNetWork(dialledNum, context, pendingIntent);
                        };
                    };

                    NetWorkThread.start();

                }

                if (!dialledNum.equalsIgnoreCase("")) {
                    SipCallSessionImpl callInfo = new SipCallSessionImpl();

                    callInfo.setRemoteContact(dialledNum);
                    callInfo.setIncoming(false);
                    callInfo.callStart = System.currentTimeMillis();
                    callInfo.setAccId(3);
                    //callInfo.setLastStatusCode(pjsua.PJ_SUCCESS);

                    ContentValues cv = CallLogHelper.logValuesForCall(context, callInfo, callInfo.callStart);
                    context.getContentResolver().insert(SipManager.CALLLOG_URI, cv);

                }
            } else {
                Location_Finder LocFinder = new Location_Finder(context);
                if (LocFinder.getContryName().startsWith("your"))
                    Toast.makeText(context,
                            "Country of your current location unknown. Call thru not available.",
                            Toast.LENGTH_LONG).show();
                else
                    Toast.makeText(context,
                            "No Call thru access number available in " + LocFinder.getContryName(),
                            Toast.LENGTH_LONG).show();
                //Toast.makeText(context, "No Call thru access number available in ", Toast.LENGTH_LONG).show();
            }
        }

        // This will exclude next time tel:xxx is raised from csipsimple treatment which is wanted
        results.putString(Intent.EXTRA_PHONE_NUMBER, callthrunum);

    }

}

From source file:edu.htl3r.schoolplanner.gui.timetable.WeekView.java

private void initViewPager() {

    myViewPager = (ViewPager) findViewById(R.id.week_pager);
    indicator = (ViewPagerIndicator) findViewById(R.id.week_indicator);
    wvpageadapter = new WeekViewPageAdapter();

    wvpageadapter.setContext(this, downloadschlange, this, ((SchoolPlannerApp) getApplication()).getSettings());
    wvpageadapter.setDate(getMonday());//  w w  w.  j av  a 2 s . co m
    myViewPager.setAdapter(wvpageadapter);
    myViewPager.setOnPageChangeListener(indicator);
    indicator.init(50, wvpageadapter.getCount(), wvpageadapter);

    Resources res = getResources();
    Drawable prev = res.getDrawable(R.drawable.indicator_prev_arrow);
    Drawable next = res.getDrawable(R.drawable.indicator_next_arrow);

    indicator.setArrows(prev, next);
    myViewPager.setCurrentItem(50);
}

From source file:ch.ethz.twimight.activities.TwimightBaseActivity.java

/**
 * on Resume//ww  w . j  av a 2 s.c  om
 */
@Override
public void onResume() {
    super.onResume();
    instance = this;

    if (dd == null || dn == null) {
        Log.i(TAG, "loading action bar backgrounds");
        Resources resources = getResources();
        dd = resources.getDrawable(R.drawable.top_bar_background_disaster);
        dn = resources.getDrawable(R.drawable.top_bar_background);
    }

    // bottom status bar (can't do it in onCreate because layout is not set yet)
    bottomStatusBar = findViewById(R.id.bottomStatusBar);
    tvNeighborCount = (TextView) findViewById(R.id.tvNeighborCount);
    tvStatus = (TextView) findViewById(R.id.tvStatus);

    actionBar.setBackgroundDrawable(dn);
    Log.i(TAG, "setting normal background");
    if (bottomStatusBar != null) {
        bottomStatusBar.setVisibility(View.GONE);
    }

    // actionbar hack to make sure the background drawable is applied
    // http://stackoverflow.com/questions/11002691/actionbar-setbackgrounddrawable-nulling-background-from-thread-handler
    actionBar.setDisplayShowTitleEnabled(false);
    actionBar.setDisplayShowTitleEnabled(true);
}

From source file:com.achep.base.ui.DialogBuilder.java

/**
 * Sets the icon of the title./* w  ww.j a va2  s  . c  o m*/
 *
 * @see #setIcon(android.graphics.drawable.Drawable)
 */
@NonNull
public DialogBuilder setIcon(@DrawableRes int drawableResource) {
    Resources res = mContext.getResources();
    return setIcon(drawableResource == 0 ? null : res.getDrawable(drawableResource));
}

From source file:org.immopoly.android.widget.ImmoscoutPlacesOverlay.java

public ImmoscoutPlacesOverlay(Fragment fragment, MapView mapView, LayoutInflater inflator,
        boolean isPortfolio) {
    super(boundCenter(fragment.getResources().getDrawable(R.drawable.map_marker_icon)));
    mMapView = mapView;/*from   w  w w.j a  v a2s  .  co m*/
    this.isPortfolio = isPortfolio;
    mMapFragment = fragment;
    Resources resources = fragment.getResources();
    mapMarkerIcon = boundCenter(resources.getDrawable(R.drawable.map_marker_icon));
    mapMarkerIcon_new = boundCenter(resources.getDrawable(R.drawable.map_marker_icon_new));
    mapMarkerIcon_old = boundCenter(resources.getDrawable(R.drawable.map_marker_icon_old));
    mapMarkerIcon_owned = boundCenter(resources.getDrawable(R.drawable.map_marker_property_icon));
    mapMarkerIcon_cluster = boundCenter(resources.getDrawable(R.drawable.map_marker_icon_cluster));

    markerBounds = mapMarkerIcon.getBounds();

    MIN_INTERSECTION_AREA = (int) (markerBounds.width() * markerBounds.height() * MIN_INTERSECTION_AMOUNT);

    ClusterMarker.init(resources.getDisplayMetrics(), mapMarkerIcon.getIntrinsicHeight());
    gestureDetector = new GestureDetector(new GestureDetector.SimpleOnGestureListener() {
        public boolean onDoubleTap(MotionEvent e) {
            if (System.currentTimeMillis() - itemTapTime > 500) // hack to prevent zoom for double tap on item
                mMapView.getController().zoomInFixing((int) e.getX(), (int) e.getY());
            return super.onDoubleTap(e);
        }
    });
}

From source file:net.alexjf.tmm.fragments.MoneyNodeEditorFragment.java

private boolean validateInputFields() {
    boolean error = false;

    Resources res = getResources();
    Drawable errorDrawable = res.getDrawable(R.drawable.indicator_input_error);
    errorDrawable.setBounds(0, 0, errorDrawable.getIntrinsicWidth(), errorDrawable.getIntrinsicHeight());
    String name = nameText.getText().toString();

    String nameError = null;/*  www.j a va  2s.  com*/
    if (TextUtils.isEmpty(name)) {
        nameError = res.getString(R.string.error_name_not_empty);
    } else {
        try {
            // If we are adding a new node and name already exists
            if (node == null && MoneyNode.hasMoneyNodeWithName(name)) {
                nameError = res.getString(R.string.error_moneynode_name_already_exists);
            }
        } catch (DatabaseException e) {
            nameError = res.getString(R.string.error_moneynode_determine_exists);
        }
    }

    if (nameError != null) {
        nameText.setError(nameError, errorDrawable);
        error = true;
    }

    if (TextUtils.isEmpty(selectedDrawableName)) {
        iconSelectorButton.setError(true);
        error = true;
    }

    return !error;
}

From source file:com.craftingmobile.alertdialogusage.LoginDialogFragment.java

/**
 * Returns an error icon for use with/*from  w w w  . j a v a  2s .  c o m*/
 * {@link EditText#setError(CharSequence)}
 * 
 * @return A {@link Drawable} of the error icon
 */
public Drawable getErrorDrawable() {
    Resources r = getActivity().getResources();
    Drawable drawable = r.getDrawable(R.drawable.custom_indicator_input_error);

    /**
     * We have to set the bounds here because they will default
     * to zero for all values, meaning our icon will not display
     */
    drawable.setBounds(0, // Left 
            0, // Top
            drawable.getIntrinsicWidth(), // Right
            drawable.getIntrinsicHeight()); // Bottom

    return drawable;

}

From source file:com.example.android.leanback.DetailsFragment.java

public void setItem(PhotoItem photoItem) {
    mPhotoItem = photoItem;/*from w  ww .j  a  va 2 s. c  o  m*/

    mRowsAdapter.clear();
    new Handler().postDelayed(new Runnable() {
        public void run() {
            Resources res = getActivity().getResources();
            DetailsOverviewRow dor = new DetailsOverviewRow(mPhotoItem.getTitle());
            dor.setImageDrawable(res.getDrawable(mPhotoItem.getImageResourceId()));
            SparseArrayObjectAdapter adapter = new SparseArrayObjectAdapter();
            adapter.set(ACTION_RENT, mActionRent);
            adapter.set(ACTION_BUY, mActionBuy);
            dor.setActionsAdapter(adapter);
            mRowsAdapter.add(0, dor);
            setSelectedPosition(0, false);
        }
    }, TIME_TO_LOAD_OVERVIEW_ROW_MS);

    new Handler().postDelayed(new Runnable() {
        public void run() {
            for (int i = 0; i < NUM_ROWS; ++i) {
                ArrayObjectAdapter listRowAdapter = new ArrayObjectAdapter(cardPresenter);
                listRowAdapter.add(new PhotoItem("Hello world", R.drawable.gallery_photo_1));
                listRowAdapter.add(new PhotoItem("This is a test", R.drawable.gallery_photo_2));
                listRowAdapter.add(new PhotoItem("Android TV", R.drawable.gallery_photo_3));
                listRowAdapter.add(new PhotoItem("Leanback", R.drawable.gallery_photo_4));
                HeaderItem header = new HeaderItem(i, "Row " + i);
                mRowsAdapter.add(new ListRow(header, listRowAdapter));
            }
            if (TEST_ENTRANCE_TRANSITION) {
                startEntranceTransition();
            }
        }
    }, TIME_TO_LOAD_RELATED_ROWS_MS);
    setAdapter(mRowsAdapter);
}

From source file:com.appsimobile.appsii.module.home.SunriseDrawable.java

void customTheme(int drawableResId, int colorPrimary, int textColor, int tintColor) {
    Resources res = mContext.getResources();
    mSunImage = res.getDrawable(drawableResId);
    DrawableCompat.setTintColorCompat(mSunImage, tintColor);
    mArcFillPaint.setColor(colorPrimary);
    mArcFillPaint.setColor(ColorUtils.setAlphaComponent(colorPrimary, 128));
    mLinePaint.setColor(textColor);//  ww  w  .  j  a va 2s .c  o  m
    mDotPaint.setColor(tintColor);

    float density = res.getDisplayMetrics().density;
    int sunBounds = (int) (density * 16);
    mSunImage.setBounds(0, 0, sunBounds, sunBounds);

    Callback callback = getCallback();
    if (callback != null) {
        callback.invalidateDrawable(this);
    }
}

From source file:com.jungle.toolbaractivity.layout.HorizontalSwipeBackLayout.java

private void initLayout(Context context) {
    Resources res = getResources();
    mShadowWidth = res.getDimensionPixelSize(R.dimen.activity_edge_shadow_width);
    mEdgeShadowDrawable = res.getDrawable(R.drawable.activity_left_edge_shadow);
    mTriggerSlideSlop = (int) (1.5f
            * ViewConfigurationCompat.getScaledPagingTouchSlop(ViewConfiguration.get(getContext())));
}