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.github.tetravex_android.fragment.HowToFragment.java

/**
 * Retrieves the drawable image to be used for this HowToFragment
 *
 * @return the appropriate drawable for the page to display
 *///from  w w  w. j  a  v  a2s.  c om
private Drawable getHowToDrawable() {
    Drawable drawable;

    Resources resources = TetravexApp.getApplication(this).getResources();
    switch (mPageNumber) {
    case 1:
        drawable = resources.getDrawable(R.drawable.solved3x3);
        break;
    case 2:
        drawable = resources.getDrawable(R.drawable.drag_highlighted);
        break;
    case 3:
        drawable = resources.getDrawable(R.drawable.victory_condition);
        break;
    default:
        drawable = null;
        Log.e(TAG, "Bad page number: " + String.valueOf(mPageNumber));
        break;
    }

    return drawable;
}

From source file:com.dimelo.sampleapp.google.IconSlidingTabLayout.java

private void updateIcon(ImageView iconImageView, int position) {
    if (mViewPager == null) {
        return;//from  w  ww.j  av a  2s  .  co m
    }
    int icon_id;
    ViewPagerIconAndTextAdapter adapter = (ViewPagerIconAndTextAdapter) mViewPager.getAdapter();
    if (position == mViewPager.getCurrentItem()) {
        icon_id = adapter.getSelectedPageIconId(position);
    } else {
        icon_id = adapter.getPageIconId(position);
    }
    Resources resources = getContext().getResources();
    Drawable icon = DrawableCompat.wrap(resources.getDrawable(icon_id));
    DrawableCompat.setTint(icon, resources.getColor(R.color.accent));
    iconImageView.setImageDrawable(icon);
}

From source file:project.pamela.slambench.fragments.SLAMResultAdapter.java

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    View row = convertView;/* w  w w. j av a2  s  .com*/
    SLAMResultHolder holder;

    if (row == null) {
        LayoutInflater inflater = ((Activity) context).getLayoutInflater();
        row = inflater.inflate(layoutResourceId, parent, false);

        holder = new SLAMResultHolder();
        holder.txtTitle = (TextView) row.findViewById(R.id.txtTitle);
        holder.txtDetail = (TextView) row.findViewById(R.id.txtDetail);
        holder.imgIcon = (ImageView) row.findViewById(R.id.icTest);
        row.setTag(holder);
    } else {
        holder = (SLAMResultHolder) row.getTag();
    }

    SLAMResult result = data.get(position);

    holder.txtTitle.setText(result.test.name);
    holder.txtDetail.setText(result.toString());
    if (!result.isFinished()) {
        holder.txtTitle.setTextColor(Color.GRAY);
        holder.txtDetail.setTextColor(Color.GRAY);
    } else {
        holder.txtTitle.setTextColor(Color.BLACK);
        holder.txtDetail.setTextColor(Color.BLACK);
    }

    Resources resources = this.context.getResources();
    holder.imgIcon.setImageDrawable(resources.getDrawable(getImplementationIcon(result.test.implementation)));

    return row;
}

From source file:net.alexjf.tmm.fragments.CategoryEditorFragment.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;/*from www.  j a  v a  2 s.com*/
    if (TextUtils.isEmpty(name)) {
        nameError = res.getString(R.string.error_name_not_empty);
    } else {
        try {
            // If we are adding a new category and the name already exists
            if (category == null && Category.hasCategoryWithName(name)) {
                nameError = res.getString(R.string.error_cat_name_already_exists);
            }
        } catch (DatabaseException e) {
            nameError = res.getString(R.string.error_cat_determine_exists);
        }
    }

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

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

    return !error;
}

From source file:net.alexjf.tmm.fragments.UserEditorFragment.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 = usernameText.getText().toString();

    String nameError = null;/*from   ww w  .j ava2s  .  co m*/
    if (TextUtils.isEmpty(name)) {
        nameError = res.getString(R.string.error_username_not_empty);
    } else {
        UserList userList = new UserList();
        if (user == null && userList.getUser(name) != null) {
            nameError = res.getString(R.string.error_username_already_exists);
        }
    }

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

    if (!passwordConfirmText.getText().toString().equals(passwordText.getText().toString())) {
        passwordConfirmText.setError(res.getString(R.string.error_password_confirmation), errorDrawable);
        error = true;
    }

    // If we are editing a user...
    if (user != null) {
        String username = user.getName();
        String passwordHash = Utils.sha1(oldPasswordText.getText().toString());
        if (!DatabaseManager.getInstance().login(username, passwordHash)) {
            oldPasswordText.setError(res.getString(R.string.error_wrong_password), errorDrawable);
            error = true;
        }
    }

    return !error;
}

From source file:com.jacr.instagramtrendreader.ImageDetails.java

@SuppressWarnings({ "unchecked" })
@Override/*from w  w  w. j  a v a 2 s . c  om*/
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activitiy_image_details);

    if (getIntent() != null) {
        Bundle b = getIntent().getExtras();
        listThumbnailKeys = (ArrayList<Integer>) b.get(KEY_THUMBNAIL_KEYS);
        listThumbnailData = (ArrayList<List<String>>) b.get(KEY_THUMBNAIL_DATA);
        final int currentKey = b.getInt(KEY_THUMBNAIL_ACTUAL_KEY);

        /* Views */
        ViewPager mPager = (ViewPager) findViewById(R.id.pagerMain);
        CirclePageIndicator mIndicator = (CirclePageIndicator) findViewById(R.id.indicator);

        /* ActionBar */
        Resources r = getResources();
        actionBar = super.getActionBar(true);
        actionBar.setIcon(r.getDrawable(R.drawable.ic_menu_gallery));

        /* Viewpager and Indicator */
        mAdapter = new ViewPagerAdapter<ImageDetailsFragment>(getSupportFragmentManager());

        /*
         * With the name of the image, extract the hash for the Associated
         * data (we don't use listThumbnailKeys for now).
         */
        File[] imageList = Util.readFilesFromFileDirectory(this);
        for (int i = 0; i < imageList.length; i++) {
            int keyIterator = Integer.parseInt(imageList[i].getName());
            String date = Util.nulo2Vacio(getThumbnailDataByKey(keyIterator, FeedReader.THUMBNAIL_DATE));
            String author = Util.nulo2Vacio(getThumbnailDataByKey(keyIterator, FeedReader.THUMBNAIL_AUTHOR));
            String tags = Util.nulo2Vacio(getThumbnailDataByKey(keyIterator, FeedReader.THUMBNAIL_TAGS));
            String urlImage = Util.nulo2Vacio(getThumbnailDataByKey(keyIterator, FeedReader.THUMBNAIL_URL));
            mAdapter.addFragment(ImageDetailsFragment.newInstance(imageList[i], urlImage, date, author, tags));

        }
        mPager.setAdapter(mAdapter);
        mIndicator.setViewPager(mPager);
        mIndicator.setHorizontalScrollBarEnabled(true);
        mIndicator.setHorizontalFadingEdgeEnabled(true);
        mIndicator.setBackgroundColor(r.getColor(R.color.white));
        mIndicator.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {

            @Override
            public void onPageSelected(int arg0) {
                setDataRelationshipViewPager(arg0);
            }

            @Override
            public void onPageScrolled(int arg0, float arg1, int arg2) {

            }

            @Override
            public void onPageScrollStateChanged(int arg0) {

            }
        });

        // Show image
        int idxKey = listThumbnailKeys.indexOf(currentKey);
        mPager.setCurrentItem(idxKey);
        setDataRelationshipViewPager(idxKey);

    }

}

From source file:com.sonetel.plugins.sonetelcallback.CallBack.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 ww. ja  va  2  s.c o  m
        }

        Bundle results = getResultExtras(true);
        //if(pendingIntent != null) {
        //   results.putParcelable(CallHandlerPlugin.EXTRA_REMOTE_INTENT_TOKEN, pendingIntent);
        //}
        results.putString(Intent.EXTRA_TITLE, "Call back");// 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 String dialledNum = intent.getStringExtra(Intent.EXTRA_TEXT);
        final String callthrunum = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
        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, callthrunum, context, null);
                };
            };

            NetWorkThread.start();

        } else if (SipAccount.acc_id != "1")
            Toast.makeText(context, "Unable to find Sonetel account. Please sign in using your Sonetel account",
                    Toast.LENGTH_LONG).show();

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

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

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

        }
        //}
        //else
        //{

        //}
    }

    // 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:com.balch.mocktrade.TradeApplication.java

@Override
public void configureActivity(TemplateActivity activity, NavBar navBar, Bundle savedInstanceState) {
    activity.showProgress();/* w  w  w .j  a  v  a2  s  .  c om*/
    this.activity = activity;

    Resources resources = activity.getResources();

    activity.setBackground(resources.getDrawable(R.drawable.main_bmp_rpt));

    navBar.setBackground(resources.getDrawable(R.drawable.navbar_bkg));

    navBar.configure(resources.getColor(R.color.nav_on_color), resources.getColor(R.color.nav_off_color));

    Fragment mainFragment = new PortfolioFragment();
    this.buttonMap.put(navBar.addButton(R.string.nav_money_center, R.drawable.ic_nav_money_center),
            mainFragment);
    this.buttonMap.put(navBar.addButton(R.string.nav_research, R.drawable.ic_nav_research),
            new YourContentHereFragment().setCustomArguments("http://www.cnbc.com/"));
    this.buttonMap.put(navBar.addButton(R.string.nav_ideas, R.drawable.ic_nav_ideas),
            new YourContentHereFragment()
                    .setCustomArguments("http://wallstcheatsheet.com/category/investing/"));
    this.buttonMap.put(navBar.addButton(R.string.nav_settings, R.drawable.ic_nav_settings),
            new SettingsFragment());

    navBar.setOnNavClickListener(new NavBar.OnNavClickListener() {
        @Override
        public void onClick(NavButton button) {
            Fragment fragment = TradeApplication.this.buttonMap.get(button);
            if (fragment != null) {
                TradeApplication.this.activity.showView(fragment);
            }
        }
    });

    if (savedInstanceState == null) {
        this.activity.showView(mainFragment);
    }

    // not sure if we need this here for the first time the app launches
    FinanceModel financeModel = this.getModelFactory().getModel(FinanceModel.class);
    financeModel.setQuoteServiceAlarm();
}

From source file:com.keepassdroid.icons.DrawableFactory.java

public Drawable getIconDrawable(Resources res, PwIconStandard icon) {
    int resId = Icons.iconToResId(icon.iconId);

    Drawable draw = (Drawable) standardIconMap.get(resId);
    if (draw == null) {
        draw = res.getDrawable(resId);
        standardIconMap.put(resId, draw);
    }//from  w w  w  .  ja  va 2 s  . c o  m

    return draw;
}

From source file:com.lee.sdk.widget.viewpager.PointPageIndicator.java

/**
 * Set the point drawable //from ww w . j  a  va2s.  com
 * 
 * @param normalResId normalResId
 * @param selectResId selectResId
 * @return this
 */
public PointPageIndicator setPointDrawableResId(int normalResId, int selectResId) {
    Resources res = getResources();
    return setPointDrawable(res.getDrawable(normalResId), res.getDrawable(selectResId));
}