Example usage for android.view View setBackgroundResource

List of usage examples for android.view View setBackgroundResource

Introduction

In this page you can find the example usage for android.view View setBackgroundResource.

Prototype

@RemotableViewMethod
public void setBackgroundResource(@DrawableRes int resid) 

Source Link

Document

Set the background to a given resource.

Usage

From source file:com.eccyan.widget.SpinningTabStrip.java

private void updateTabStyles() {
    for (int i = 0; i < realTabCount; i++) {
        View v = tabsContainer.getChildAt(i);
        if (!(pager.getAdapter() instanceof CustomTabProvider)) {
            v.setBackgroundResource(tabBackgroundResId);
        }//from  w ww .j  ava  2  s .c o m
        v.setPadding(tabPadding, v.getPaddingTop(), tabPadding, v.getPaddingBottom());

        TextView tabTitle = (TextView) v.findViewById(R.id.tab_title);
        if (tabTitle != null) {
            tabTitle.setTextSize(TypedValue.COMPLEX_UNIT_PX, tabTextSize);
            tabTitle.setTypeface(tabTypeface,
                    pager.getCurrentItem() == i ? tabTypefaceSelectedStyle : tabTypefaceStyle);
            if (tabTextColor != null) {
                tabTitle.setTextColor(tabTextColor);
            }
            // setAllCaps() is only available from API 14, so the upper case is made manually if we are on a
            // pre-ICS-build
            if (textAllCaps) {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
                    tabTitle.setAllCaps(true);
                } else {
                    tabTitle.setText(tabTitle.getText().toString().toUpperCase(locale));
                }
            }
        }
    }

}

From source file:com.frostwire.android.gui.adapters.FileListAdapter.java

private void populateSDState(View v, FileDescriptorItem item) {
    if (inGridMode()) {
        // gotta see what to do here
        return;/* w ww  .ja va 2  s .  c o m*/
    }
    ImageView img = findView(v, R.id.view_my_files_thumbnail_list_image_item_sd);

    if (item.inSD) {
        if (item.mounted) {
            v.setBackgroundResource(R.drawable.listview_item_background_selector);
            setNormalTextColors(v);
            img.setVisibility(View.GONE);
        } else {
            v.setBackgroundResource(R.drawable.my_files_listview_item_inactive_background);
            setInactiveTextColors(v);
            img.setVisibility(View.VISIBLE);
        }
    } else {
        v.setBackgroundResource(R.drawable.listview_item_background_selector);
        setNormalTextColors(v);
        img.setVisibility(View.GONE);
    }
}

From source file:scroll.com.rdemo.scroll.PagerSlidingTabStrip.java

private void updateTabStyles() {
    for (int i = 0; i < tabCount; i++) {

        View v = tabsContainer.getChildAt(i);

        if (v instanceof TextView) {

            TextView tab = (TextView) v;
            tab.setTextSize(TypedValue.COMPLEX_UNIT_PX, tabTextSize);
            tab.setTypeface(tabTypeface, tabTypefaceStyle);

            if (i == currentPosition) {
                v.setBackgroundResource(tabSelectBackgroundResId);
                tab.setTextColor(indicatorColor);
                tab.setTextSize(indicatorTextSize);
            } else {
                v.setBackgroundResource(tabBackgroundResId);
                tab.setTextColor(tabTextColor);
                tab.setTextSize(tabTextSize);
            }//from w w  w .jav a  2 s.c o  m

            // setAllCaps() is only available from API 14, so the upper case is made manually if we are on a
            // pre-ICS-build
            if (textAllCaps) {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
                    tab.setAllCaps(true);
                } else {
                    tab.setText(tab.getText().toString().toUpperCase(locale));
                }
            }
        } else if (v instanceof ImageButton) {
            ImageButton tab = (ImageButton) v;
            IconTabProvider iconTabProvider = (IconTabProvider) pager.getAdapter();
            ViewGroup.LayoutParams params = tab.getLayoutParams();

            if (i == currentPosition) {
                int[] wh = iconTabProvider.getPageIconResWidthAndHeight();
                if (params.width != wh[0] || params.height != wh[1]) {
                    params.width = wh[0];
                    params.height = wh[1];
                    tab.setLayoutParams(params);
                }
                tab.setBackgroundResource(iconTabProvider.getPageIconResId(i));
            } else {
                int[] wh = iconTabProvider.getPageUnSelectIconResWidthAndHeight();
                if (params.width != wh[0] || params.height != wh[1]) {
                    params.width = wh[0];
                    params.height = wh[1];
                    tab.setLayoutParams(params);
                }
                tab.setBackgroundResource(iconTabProvider.getPageUnSelectIconResId(i));
            }
        }
    }
}

From source file:com.aretha.slidemenu.SlideMenu.java

/**
 * Resolve the attribute slideMode// w ww . j  av a 2s. c  om
 */
protected void resolveSlideMode() {
    final ViewGroup decorView = (ViewGroup) getRootView();
    final ViewGroup contentContainer = (ViewGroup) decorView.findViewById(android.R.id.content);
    final View content = mContent;
    if (null == decorView || null == content || 0 == getChildCount()) {
        return;
    }

    TypedValue value = new TypedValue();
    getContext().getTheme().resolveAttribute(android.R.attr.windowBackground, value, true);

    switch (mSlideMode) {
    case MODE_SLIDE_WINDOW: {
        // remove this view from parent
        removeViewFromParent(this);
        // copy the layoutparams of content
        LayoutParams contentLayoutParams = new LayoutParams(content.getLayoutParams());
        // remove content view from this view
        removeViewFromParent(content);
        // add content to layout root view
        contentContainer.addView(content);

        // get window with ActionBar
        View decorChild = decorView.getChildAt(0);
        decorChild.setBackgroundResource(0);
        removeViewFromParent(decorChild);
        addView(decorChild, contentLayoutParams);

        // add this view to root view
        decorView.addView(this);
        setBackgroundResource(value.resourceId);
    }
        break;
    case MODE_SLIDE_CONTENT: {
        // remove this view from decor view
        setBackgroundResource(0);
        removeViewFromParent(this);
        // get the origin content view from the content wrapper
        View originContent = contentContainer.getChildAt(0);
        // this is the decor child remove from decor view
        View decorChild = mContent;
        LayoutParams layoutParams = (LayoutParams) decorChild.getLayoutParams();
        // remove the origin content from content wrapper
        removeViewFromParent(originContent);
        // remove decor child from this view
        removeViewFromParent(decorChild);
        // restore the decor child to decor view
        decorChild.setBackgroundResource(value.resourceId);
        decorView.addView(decorChild);
        // add this view to content wrapper
        contentContainer.addView(this);
        // add the origin content to this view
        addView(originContent, layoutParams);
    }
        break;
    }
}

From source file:SwipeListViewTouchListener.java

/**
 * Draw cell for display if item is selected or not
 *
 * @param frontView view to draw//  ww  w  .j a v a2s  . co  m
 * @param position  position in list
 */
protected void reloadChoiceStateInView(View frontView, int position) {
    if (isChecked(position)) {
        if (swipeDrawableChecked > 0)
            frontView.setBackgroundResource(swipeDrawableChecked);
    } else {
        if (swipeDrawableUnchecked > 0)
            frontView.setBackgroundResource(swipeDrawableUnchecked);
    }
}

From source file:com.appstu.sattafestival.swipe_list.SwipeListViewTouchListener.java

/**
 * Draw cell for display if item is selected or not
 *
 * @param frontView view to draw//  ww  w.  ja  va 2  s  .  co m
 * @param position  position in list
 */
public void reloadChoiceStateInView(View frontView, int position) {
    if (isChecked(position)) {
        if (swipeDrawableChecked > 0)
            frontView.setBackgroundResource(swipeDrawableChecked);
    } else {
        if (swipeDrawableUnchecked > 0)
            frontView.setBackgroundResource(swipeDrawableUnchecked);
    }
}

From source file:at.alladin.rmbt.android.adapter.result.RMBTResultPagerAdapter.java

/**
 * /*  w  ww .j av  a  2s. c o m*/
 * @param view
 */
private void displayResult(View view, LayoutInflater inflater, ViewGroup vg) {
    /*
     final Button shareButton = (Button) view.findViewById(R.id.resultButtonShare);
     if (shareButton != null)
    shareButton.setEnabled(false);
    */

    //final LinearLayout measurementLayout = (LinearLayout) view.findViewById(R.id.resultMeasurementList);
    measurementLayout = (LinearLayout) view.findViewById(R.id.resultMeasurementList);
    measurementLayout.setVisibility(View.GONE);

    final LinearLayout resultLayout = (LinearLayout) view.findViewById(R.id.result_layout);
    resultLayout.setVisibility(View.INVISIBLE);

    final LinearLayout netLayout = (LinearLayout) view.findViewById(R.id.resultNetList);
    netLayout.setVisibility(View.GONE);

    final TextView measurementHeader = (TextView) view.findViewById(R.id.resultMeasurement);
    measurementHeader.setVisibility(View.GONE);

    final TextView netHeader = (TextView) view.findViewById(R.id.resultNet);
    netHeader.setVisibility(View.GONE);

    final TextView emptyView = (TextView) view.findViewById(R.id.infoText);
    emptyView.setVisibility(View.GONE);
    final float scale = activity.getResources().getDisplayMetrics().density;

    final ProgressBar progessBar = (ProgressBar) view.findViewById(R.id.progressBar);

    if (testResult != null && testResult.length() > 0) {

        JSONObject resultListItem;

        try {
            resultListItem = testResult.getJSONObject(0);

            openTestUuid = resultListItem.optString("open_test_uuid");
            if (graphView != null) {
                graphView.setOpenTestUuid(openTestUuid);
                graphView.initialize(graphViewEndTaskListener);
            }

            JSONObject testResultItem;
            try {
                testResultItem = testResult.getJSONObject(0);
                if (testResultItem.has("geo_lat") && testResultItem.has("geo_long") && !hasMap) {
                    hasMap = true;
                    if (dataChangedListener != null) {
                        dataChangedListener.onChange(false, true, "HAS_MAP");
                    }
                    notifyDataSetChanged();
                } else if (!testResultItem.has("geo_lat") && !testResultItem.has("geo_long") && hasMap) {
                    System.out.println("hasMap = " + hasMap);
                    hasMap = false;
                    if (dataChangedListener != null) {
                        dataChangedListener.onChange(true, false, "HAS_MAP");
                    }
                    notifyDataSetChanged();
                }
            } catch (JSONException e) {
                hasMap = false;
                e.printStackTrace();
            }

            if (completeListener != null) {
                completeListener.onComplete(OnCompleteListener.DATA_LOADED, this);
            }

            final JSONArray measurementArray = resultListItem.getJSONArray("measurement");

            final JSONArray netArray = resultListItem.getJSONArray("net");

            final int leftRightDiv = Helperfunctions.dpToPx(0, scale);
            final int topBottomDiv = Helperfunctions.dpToPx(0, scale);
            final int heightDiv = Helperfunctions.dpToPx(1, scale);

            for (int i = 0; i < measurementArray.length(); i++) {

                final View measurementItemView = inflater.inflate(R.layout.classification_list_item, vg, false);

                final JSONObject singleItem = measurementArray.getJSONObject(i);

                final TextView itemTitle = (TextView) measurementItemView
                        .findViewById(R.id.classification_item_title);
                itemTitle.setText(singleItem.getString("title"));

                final ImageView itemClassification = (ImageView) measurementItemView
                        .findViewById(R.id.classification_item_color);
                itemClassification.setImageResource(
                        Helperfunctions.getClassificationColor(singleItem.getInt("classification")));

                itemClassification.setOnClickListener(new OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        activity.showHelp(R.string.url_help_result, false);
                    }
                });

                final TextView itemValue = (TextView) measurementItemView
                        .findViewById(R.id.classification_item_value);
                itemValue.setText(singleItem.getString("value"));

                measurementLayout.addView(measurementItemView);

                final View divider = new View(activity);
                divider.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, heightDiv, 1));
                divider.setPadding(leftRightDiv, topBottomDiv, leftRightDiv, topBottomDiv);

                divider.setBackgroundResource(R.drawable.bg_trans_light_10);

                measurementLayout.addView(divider);

                measurementLayout.invalidate();
            }

            for (int i = 0; i < netArray.length(); i++) {

                final JSONObject singleItem = netArray.getJSONObject(i);

                addResultListItem(singleItem.getString("title"), singleItem.optString("value", null),
                        netLayout);
            }

            addQoSResultItem();

        } catch (final JSONException e) {
            e.printStackTrace();
        }

        progessBar.setVisibility(View.GONE);
        emptyView.setVisibility(View.GONE);

        resultLayout.setVisibility(View.VISIBLE);
        measurementHeader.setVisibility(View.VISIBLE);
        netHeader.setVisibility(View.VISIBLE);

        measurementLayout.setVisibility(View.VISIBLE);
        netLayout.setVisibility(View.VISIBLE);

    } else {
        Log.i(DEBUG_TAG, "LEERE LISTE");
        progessBar.setVisibility(View.GONE);
        emptyView.setVisibility(View.VISIBLE);
        emptyView.setText(activity.getString(R.string.error_no_data));
        emptyView.invalidate();
    }
}

From source file:com.guerinet.materialtabs.TabLayout.java

/**
 * Adds the tabs based on a list of Strings to use as tab titles
 *
 * @param listener   The {@link TabClickListener} to use when a tab is clicked
 * @param initialTab The initial tab to show
 * @param titles     The titles for the tabs
 *//*from   w w w. j a v a  2  s.  c o  m*/
private void addTabs(TabClickListener listener, int initialTab, List<String> titles) {
    //Clear any existing tabs
    clear();
    //Reset the current position
    mCurrentPosition = -1;
    View initialTabView = null;

    //Go through the titles
    for (int i = 0; i < titles.size(); i++) {
        View tabView;
        TextView tabTitleView = null;

        //If there is a custom tab view layout id set, try and inflate it
        if (mTabViewLayoutId != 0) {
            tabView = LayoutInflater.from(getContext()).inflate(mTabViewLayoutId, mTabStrip, false);
            //Set the default selector if we should use the default selector
            if (mDefaultSelector) {
                tabView.setBackgroundResource(getTabBackground());
            }

            tabTitleView = (TextView) tabView.findViewById(mTabViewTextViewId);
            prepareTextView(tabTitleView);

            //Set up the icon if needed
            if (mTabViewIconId != null) {
                ImageView iconView = (ImageView) tabView.findViewById(mTabViewIconId);
                //Wrap through the icons
                iconView.setImageResource(mIconIds[i % mIconIds.length]);
            }
        } else {
            //If not, just use the default tab view
            tabView = createDefaultTabView();
        }

        //If there is no tab title and the tab view is a TextView, use that
        if (tabTitleView == null) {
            if (!TextView.class.isInstance(tabView)) {
                //If there is no tab title, throw an exception
                throw new IllegalStateException("Could not find the title TextView");
            }
            tabTitleView = (TextView) tabView;
        }

        //Set equal weights if we are to distribute these tabs evenly
        if (mDistributeEvenly) {
            LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) tabView.getLayoutParams();
            lp.width = 0;
            lp.weight = 1;
        }

        //Set the text and the listener
        tabTitleView.setText(titles.get(i));
        tabView.setOnClickListener(listener);

        //Set the content description if there is one
        String desc = mContentDescriptions.get(i, null);
        if (desc != null) {
            tabView.setContentDescription(desc);
        }

        //Add it to the strip
        mTabStrip.addView(tabView);

        //If we found the initial tab, store it
        if (i == initialTab) {
            initialTabView = tabView;
        }
    }

    //Click on the first tab if there is one. This will set the initial position
    if (initialTabView != null) {
        initialTabView.performClick();
    }
}

From source file:com.eleybourn.bookcatalogue.dialogs.StandardDialogs.java

/**
 * Select a custom item from a list, and call halder when/if item is selected.
 *///from  w  ww.  j  a  v  a2 s  .com
public static void selectItemDialog(LayoutInflater inflater, String message, ArrayList<SimpleDialogItem> items,
        SimpleDialogItem selectedItem, final SimpleDialogOnClickListener handler) {
    // Get the view and the radio group
    final View root = inflater.inflate(R.layout.select_list_dialog, null);
    TextView msg = (TextView) root.findViewById(R.id.message);

    // Build the base dialog
    final AlertDialog.Builder builder = new AlertDialog.Builder(inflater.getContext()).setView(root);
    if (message != null && !message.equals("")) {
        msg.setText(message);
    } else {
        msg.setVisibility(View.GONE);
    }

    final AlertDialog dialog = builder.create();

    // Create the listener for each item
    OnClickListener listener = new OnClickListener() {
        @Override
        public void onClick(View v) {
            SimpleDialogItem item = (SimpleDialogItem) ViewTagger.getTag(v, R.id.TAG_DIALOG_ITEM);
            // For a consistent UI, make sure the selector is checked as well. NOT mandatory from
            // a functional point of view, just consistent
            if (!(v instanceof RadioButton)) {
                RadioButton btn = item.getSelector(v);
                if (btn != null) {
                    btn.setChecked(true);
                    btn.invalidate();
                }
            }
            //
            // It would be nice to have the other radio buttons reflect the new state before it
            // disappears, but not really worth the effort. Esp. since the code below does not work...
            // and the dialog disappears too fast to make this worthwhile.
            //
            //LinearLayout list = (LinearLayout)root.findViewById(R.id.list);
            //for(int i = 0; i < list.getChildCount(); i++) {
            //   View child = list.getChildAt(i);
            //   SimpleDialogItem other = (SimpleDialogItem)ViewTagger.getTag(child, R.id.TAG_DIALOG_ITEM);
            //   RadioButton btn = other.getSelector(child);
            //   btn.setSelected(other == item);
            //   btn.invalidate();
            //}
            dialog.dismiss();
            handler.onClick(item);
        }
    };

    // Add the items to the dialog
    LinearLayout list = (LinearLayout) root.findViewById(R.id.list);
    for (SimpleDialogItem item : items) {
        View v = item.getView(inflater);
        v.setBackgroundResource(android.R.drawable.list_selector_background);
        ViewTagger.setTag(v, R.id.TAG_DIALOG_ITEM, item);
        list.addView(v);
        v.setOnClickListener(listener);
        RadioButton btn = item.getSelector(v);
        if (btn != null) {
            ViewTagger.setTag(btn, R.id.TAG_DIALOG_ITEM, item);
            btn.setChecked(item == selectedItem);
            btn.setOnClickListener(listener);
        }
    }
    dialog.show();
}

From source file:com.breadwallet.tools.adapter.TransactionListAdapter.java

public View getTxView(View tmpLayout, int position) {
    TextView sentReceivedTextView = (TextView) tmpLayout.findViewById(R.id.transaction_sent_received_label);
    TextView dateTextView = (TextView) tmpLayout.findViewById(R.id.transaction_date);
    TextView bitsTextView = (TextView) tmpLayout.findViewById(R.id.transaction_amount_bits);
    TextView dollarsTextView = (TextView) tmpLayout.findViewById(R.id.transaction_amount_dollars);
    TextView bitsTotalTextView = (TextView) tmpLayout.findViewById(R.id.transaction_amount_bits_total);
    TextView dollarsTotalTextView = (TextView) tmpLayout.findViewById(R.id.transaction_amount_dollars_total);
    Utils.overrideFonts(sentReceivedTextView, dateTextView, bitsTextView, dollarsTextView, bitsTotalTextView,
            dollarsTotalTextView);//from w ww.  j  a  v  a2s  . c  o  m
    tmpLayout.setBackgroundResource(R.drawable.clickable_layout);

    bitsTextView.setVisibility(BreadWalletApp.unlocked ? View.VISIBLE : View.INVISIBLE);
    bitsTotalTextView.setVisibility(BreadWalletApp.unlocked ? View.VISIBLE : View.INVISIBLE);
    dollarsTextView.setVisibility(BreadWalletApp.unlocked ? View.VISIBLE : View.INVISIBLE);
    dollarsTotalTextView.setVisibility(BreadWalletApp.unlocked ? View.VISIBLE : View.INVISIBLE);

    final TransactionListItem item = data.get(position);

    tmpLayout.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (BRAnimator.checkTheMultipressingAvailability()) {
                FragmentSettingsAll fragmentSettingsAll = (FragmentSettingsAll) activity.getFragmentManager()
                        .findFragmentByTag(FragmentSettingsAll.class.getName());
                FragmentTransactionExpanded fragmentTransactionExpanded = new FragmentTransactionExpanded();
                fragmentTransactionExpanded.setCurrentObject(item);
                BRAnimator.animateSlideToLeft((MainActivity) activity, fragmentTransactionExpanded,
                        fragmentSettingsAll);
            }
        }
    });

    boolean received = item.getSent() == 0;
    int blockHeight = item.getBlockHeight();

    int confirms = blockHeight == Integer.MAX_VALUE ? 0
            : SharedPreferencesManager.getLastBlockHeight(activity) - blockHeight + 1;

    if (item.getSent() > 0 && item.getSent() == item.getReceived()) {
        sentReceivedTextView.setBackgroundResource(R.drawable.unconfirmed_label);
        sentReceivedTextView.setText(R.string.moved);
        sentReceivedTextView.setTextColor(unconfirmedColor);
    } else if (blockHeight != Integer.MAX_VALUE && confirms >= 6) {
        sentReceivedTextView
                .setBackgroundResource(received ? R.drawable.received_label : R.drawable.sent_label);
        sentReceivedTextView.setText(received ? R.string.received : R.string.sent);
        sentReceivedTextView.setTextColor(received ? receivedColor : sentColor);
    } else {
        sentReceivedTextView.setBackgroundResource(R.drawable.unconfirmed_label);
        sentReceivedTextView.setTextColor(unconfirmedColor);
        if (!BRWalletManager.getInstance(activity).transactionIsVerified(item.getHexId())) {
            sentReceivedTextView.setText(R.string.unverified);
        } else {
            int confsNr = confirms >= 0 && confirms <= 5 ? confirms : 0;
            String message = confsNr == 0 ? activity.getString(R.string.nr_confirmations0)
                    : (confsNr == 1 ? activity.getString(R.string.nr_confirmations1)
                            : String.format(activity.getString(R.string.nr_confirmations), confsNr));

            sentReceivedTextView.setText(message);
        }
    }

    long itemTimeStamp = item.getTimeStamp();
    dateTextView.setText(itemTimeStamp != 0 ? Utils.getFormattedDateFromLong(itemTimeStamp * 1000)
            : Utils.getFormattedDateFromLong(System.currentTimeMillis()));

    long satoshisAmount = received ? item.getReceived() : (item.getSent() - item.getReceived()) * -1;

    bitsTextView.setText(BRStringFormatter.getFormattedCurrencyString("BTC", satoshisAmount));
    dollarsTextView.setText(String.format("(%s)",
            BRStringFormatter.getExchangeForAmount(SharedPreferencesManager.getRate(activity),
                    SharedPreferencesManager.getIso(activity), new BigDecimal(satoshisAmount), activity)));
    long satoshisAfterTx = item.getBalanceAfterTx();

    bitsTotalTextView.setText(BRStringFormatter.getFormattedCurrencyString("BTC", satoshisAfterTx));
    dollarsTotalTextView.setText(String.format("(%s)",
            BRStringFormatter.getExchangeForAmount(SharedPreferencesManager.getRate(activity),
                    SharedPreferencesManager.getIso(activity), new BigDecimal(satoshisAfterTx), activity)));
    return tmpLayout;
}