Example usage for android.view View getBackground

List of usage examples for android.view View getBackground

Introduction

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

Prototype

public Drawable getBackground() 

Source Link

Document

Gets the background drawable

Usage

From source file:biz.easymenu.easymenung.MenuPagerAdapter.java

private void unbindDrawables(View view) {
    if (view.getBackground() != null) {
        view.getBackground().setCallback(null);
    }//from  w ww  . j  a v  a 2 s  .co m
    if (view instanceof ViewGroup) {
        for (int i = 0; i < ((ViewGroup) view).getChildCount(); i++) {
            unbindDrawables(((ViewGroup) view).getChildAt(i));
        }
        //((ViewGroup) view).removeAllViews();
    }
}

From source file:com.simas.vc.editor.tree_view.AttributeTreeAdapter.java

private void selectView(final View view, final Object parentNode) {
    view.post(new Runnable() {
        @Override//  w w w.  j  a  v  a  2 s .c  o  m
        public void run() {
            mSelectedChildren.put(parentNode, view);
            view.getBackground().setColorFilter(Color.GRAY, PorterDuff.Mode.DARKEN);
        }
    });
}

From source file:com.app.blockydemo.content.bricks.ChangeVariableBrick.java

@Override
public View getViewWithAlpha(int alphaValue) {

    if (view != null) {

        View layout = view.findViewById(R.id.brick_change_variable_layout);
        Drawable background = layout.getBackground();
        background.setAlpha(alphaValue);

        TextView textSetVariable = (TextView) view.findViewById(R.id.brick_change_variable_label);
        TextView textTo = (TextView) view.findViewById(R.id.brick_change_variable_by);
        TextView editVariable = (TextView) view.findViewById(R.id.brick_change_variable_edit_text);
        Spinner variablebrickSpinner = (Spinner) view.findViewById(R.id.change_variable_spinner);

        ColorStateList color = textSetVariable.getTextColors().withAlpha(alphaValue);
        variablebrickSpinner.getBackground().setAlpha(alphaValue);
        if (adapterView != null) {
            ((TextView) adapterView.getChildAt(0)).setTextColor(color);
        }/*  www.  j  a  va 2s.c  om*/
        textSetVariable.setTextColor(textSetVariable.getTextColors().withAlpha(alphaValue));
        textTo.setTextColor(textTo.getTextColors().withAlpha(alphaValue));
        editVariable.setTextColor(editVariable.getTextColors().withAlpha(alphaValue));
        editVariable.getBackground().setAlpha(alphaValue);

        this.alphaValue = (alphaValue);

    }
    return view;
}

From source file:com.simas.vc.editor.tree_view.AttributeTreeAdapter.java

@Override
View getNodeView(int level, int position, final Object node, final Object parentNode, ViewGroup parent) {
    View view;/*ww w . j a v a 2s . com*/
    switch (level) {
    case 0:
        view = getInflater().inflate(R.layout.tree_group, parent, false);
        TextView root = (TextView) view;
        if (position == 0) {
            root.setText(Utils.getString(R.string.audio));
        } else if (position == 1) {
            root.setText(Utils.getString(R.string.video));
        }
        break;
    case 1:
        view = getInflater().inflate(R.layout.tree_group, parent, false);
        ((TextView) view).setText(String.valueOf(position));

        // If this audio/video stream is selected, add a color filter to the view
        if (mItem.getSelectedAudioStream() == node || mItem.getSelectedVideoStream() == node) {
            selectView(view, parentNode);
        }

        // Register a listener that will select this stream in the item and deselect all
        // the other views of this parent
        view.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                // Find this parent's selected view
                View selected = mSelectedChildren.get(parentNode);
                if (selected != null) {
                    // Remove the color filter
                    selected.getBackground().clearColorFilter();
                }

                // Add the color filter on the (newly) selected view
                selectView(v, parentNode);

                // Select stream in NavItem
                if (node instanceof AudioStream) {
                    // Make sure it's a new stream so setSelectedAudioStream doesn't loop all
                    AudioStream audioStream = (AudioStream) node;
                    if (mItem.getSelectedAudioStream() != audioStream) {
                        mItem.setSelectedAudioStream((AudioStream) node);
                    }
                } else if (node instanceof VideoStream) {
                    // Make sure it's a new stream so setSelectedAudioStream doesn't loop all
                    VideoStream videoStream = (VideoStream) node;
                    if (mItem.getSelectedVideoStream() != videoStream) {
                        mItem.setSelectedVideoStream((VideoStream) node);
                    }
                } else {
                    Log.e(TAG, "Unrecognized child in level 1! Node: " + node);
                }

                return true;
            }
        });
        break;
    case 2:
        view = getInflater().inflate(R.layout.tree_child, parent, false);
        TextView key = (TextView) view.findViewById(R.id.key);
        TextView value = (TextView) view.findViewById(R.id.value);

        @SuppressWarnings("unchecked")
        Pair<String, Object> attribute = (Pair<String, Object>) node;
        key.setText(attribute.first);
        value.setText(String.valueOf(attribute.second));
        break;
    default:
        view = null;
    }

    return view;
}

From source file:com.pixby.texo.EditTools.ColorTool.java

private void drawBackground(View v) {
    int color = mSampleColors.get(v.getId());
    LayerDrawable layerDrawable = (LayerDrawable) v.getBackground();
    if (layerDrawable != null) {

        GradientDrawable shape = (GradientDrawable) layerDrawable.findDrawableByLayerId(R.id.color_fill);
        shape.setColorFilter(color, PorterDuff.Mode.MULTIPLY);

        shape = (GradientDrawable) layerDrawable.findDrawableByLayerId(R.id.color_focus);
        int alpha = v.hasFocus() ? 255 : 0;
        shape.setAlpha(alpha);//w  w w.jav a2 s .  co  m
    }
}

From source file:android.support.v7.preference.PreferenceGroupAdapter.java

@Override
public PreferenceViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    final PreferenceLayout pl = mPreferenceLayouts.get(viewType);
    final LayoutInflater inflater = LayoutInflater.from(parent.getContext());
    TypedArray a = parent.getContext().obtainStyledAttributes(null, R.styleable.BackgroundStyle);
    Drawable background = a.getDrawable(R.styleable.BackgroundStyle_android_selectableItemBackground);
    if (background == null) {
        background = parent.getContext().getResources()
                .getDrawable(android.R.drawable.list_selector_background);
    }//from  w w w .  j  av a2  s . co m
    a.recycle();

    final View view = inflater.inflate(pl.resId, parent, false);
    if (view.getBackground() == null) {
        ViewCompat.setBackground(view, background);
    }

    final ViewGroup widgetFrame = (ViewGroup) view.findViewById(android.R.id.widget_frame);
    if (widgetFrame != null) {
        if (pl.widgetResId != 0) {
            inflater.inflate(pl.widgetResId, widgetFrame);
        } else {
            widgetFrame.setVisibility(View.GONE);
        }
    }

    return new PreferenceViewHolder(view);
}

From source file:com.android.dialer.widget.OverlappingPaneLayout.java

private static boolean viewIsOpaque(View v) {
    if (ViewCompat.isOpaque(v))
        return true;

    final Drawable bg = v.getBackground();
    if (bg != null) {
        return bg.getOpacity() == PixelFormat.OPAQUE;
    }//from w  w  w  . ja va 2 s .com
    return false;
}

From source file:com.example.linhdq.test.documents.creation.crop.CropImageActivity.java

private void unbindDrawables(View view) {
    if (view.getBackground() != null) {
        view.getBackground().setCallback(null);
    }// ww w. ja  v  a 2s . co  m
    if (view instanceof ViewGroup && !(view instanceof AdapterView)) {
        for (int i = 0; i < ((ViewGroup) view).getChildCount(); i++) {
            unbindDrawables(((ViewGroup) view).getChildAt(i));
        }
        ((ViewGroup) view).removeAllViews();
    }
}

From source file:com.eusecom.saminveantory.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main_inveantory);

    /* Assinging the toolbar object ot the view
    and setting the the Action bar to our toolbar
     *//*from  w  w w  . ja  v a  2 s. c o m*/
    toolbar = (Toolbar) findViewById(R.id.tool_bar);
    setSupportActionBar(toolbar);

    View backgroundImage = findViewById(R.id.background);
    Drawable background = backgroundImage.getBackground();
    background.setAlpha(20);

    incomplet = "0";
    String serverx = SettingsActivity.getServerName(this);
    if (serverx != null && !serverx.isEmpty()) {
        // doSomething
    } else {
        serverx = "www.ala.sk/androideshop";
    }

    String delims = "[/]+";
    String[] serverxxx = serverx.split(delims);

    if (serverxxx.length < 2) {
        serverx = "www.ala.sk/androideshop";
        serverxxx = serverx.split(delims);
    }

    //Create Folder
    File folder = new File(
            Environment.getExternalStorageDirectory().toString() + "/eusecom/" + serverxxx[1] + "/inventura");
    if (!folder.exists()) {
        folder.mkdirs();
    }

    navMenuTitles = getResources().getStringArray(R.array.nav_drawer_items);
    String TITLES[] = { navMenuTitles[0], navMenuTitles[1], navMenuTitles[2], navMenuTitles[3],
            navMenuTitles[4], navMenuTitles[5] };

    mRecyclerView = (RecyclerView) findViewById(R.id.RecyclerView); // Assigning the RecyclerView Object to the xml View

    mRecyclerView.setHasFixedSize(true); // Letting the system know that the list objects are of fixed size
    mRecyclerView.setLayoutManager(new LinearLayoutManager(this));

    mAdapter = new MyAdapter(this, TITLES, ICONS, NAME, EMAIL, PROFILE); // Creating the Adapter of MyAdapter class(which we are going to see in a bit)
    // And passing the titles,icons,header view name, header view email,
    // and header view profile picture
    mRecyclerView.setAdapter(mAdapter); // Setting the adapter to RecyclerView

    Drawer = (DrawerLayout) findViewById(R.id.DrawerLayout); // Drawer object Assigned to the view
    mDrawerToggle = new ActionBarDrawerToggle(this, Drawer, toolbar, R.string.drawer_open,
            R.string.drawer_close) {

        @Override
        public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);
            // code here will execute once the drawer is opened( As I dont want anything happened whe drawer is
            // open I am not going to put anything here)
        }

        @Override
        public void onDrawerClosed(View drawerView) {
            super.onDrawerClosed(drawerView);
            // Code here will execute once drawer is closed
        }

    }; // Drawer Toggle Object Made
    Drawer.setDrawerListener(mDrawerToggle); // Drawer Listener set to the Drawer toggle
    mDrawerToggle.syncState(); // Finally we set the drawer toggle sync State

    // btn ean control stock
    btnEan = (Button) findViewById(R.id.btnEan);
    btnEan.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            // Launching All products Activity
            Intent i = new Intent(getApplicationContext(), InventuraSDnewActivity.class);
            startActivity(i);

        }
    });

    // btn ean no stock
    btnEanno = (Button) findViewById(R.id.btnEanno);
    btnEanno.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            // Launching All products Activity
            Intent i = new Intent(getApplicationContext(), InventuraNOnewActivity.class);
            startActivity(i);

        }
    });

    // btn qrcode
    btnQrcode = (Button) findViewById(R.id.btnQrcode);
    btnQrcode.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            // Launching All products Activity
            Intent i = new Intent(getApplicationContext(), QrcodeActivity.class);
            startActivity(i);

        }
    });

}

From source file:android.car.ui.provider.CarDrawerLayout.java

private static boolean hasOpaqueBackground(View v) {
    final Drawable bg = v.getBackground();
    return bg != null && bg.getOpacity() == PixelFormat.OPAQUE;
}