Example usage for android.widget RelativeLayout setBackground

List of usage examples for android.widget RelativeLayout setBackground

Introduction

In this page you can find the example usage for android.widget RelativeLayout setBackground.

Prototype

public void setBackground(Drawable background) 

Source Link

Document

Set the background to a given Drawable, or remove the background.

Usage

From source file:com.luseen.spacenavigation.BadgeHelper.java

/**
 * Force show badge without animation/*from www .  j a  v  a 2  s.co m*/
 *
 * @param view      target budge
 * @param badgeItem BadgeItem object
 */
static void forceShowBadge(RelativeLayout view, BadgeItem badgeItem) {
    Utils.changeViewVisibilityVisible(view);
    view.setBackground(makeShapeDrawable(badgeItem.getBadgeColor()));
    TextView badgeTextView = (TextView) view.findViewById(R.id.badge_text_view);
    badgeTextView.setText(badgeItem.getBadgeText());
}

From source file:org.proninyaroslav.libretorrent.core.utils.Utils.java

public static void showActionModeStatusBar(Activity activity, boolean mode) {
    int color = (mode ? R.color.action_mode_dark : R.color.primary_dark);
    if (Build.VERSION.SDK_INT == Build.VERSION_CODES.KITKAT) {
        RelativeLayout statusBar = (RelativeLayout) activity.findViewById(R.id.statusBarKitKat);
        statusBar.setBackground(ContextCompat.getDrawable(activity, color));
        statusBar.setVisibility(View.VISIBLE);

    } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        activity.getWindow().setStatusBarColor(ContextCompat.getColor(activity, color));
    }//  w  w w. jav a2  s .com
}

From source file:com.ogunwale.android.app.yaps.ui.PhotosSimpleCursorAdapter.java

private void setLayoutBackground(Context context, RelativeLayout v, byte[] value) {
    Bitmap bitmap = BitmapFactory.decodeByteArray(value, 0, value.length);
    v.setBackground(new BitmapDrawable(v.getContext().getResources(), bitmap));
}

From source file:org.cirdles.chroni.AliquotMenuActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    //Sets up activity layout
    super.onCreate(savedInstanceState);
    setTheme(android.R.style.Theme_Holo);
    setContentView(R.layout.aliquot_select);

    RelativeLayout aliquotMenuLayout = (RelativeLayout) findViewById(R.id.aliquotSelectBackground);

    //Places background image on layout after theme overriding
    aliquotMenuLayout.setBackground(getResources().getDrawable(R.drawable.background));

    Button aliquotFileSelectButton = (Button) findViewById(R.id.aliquotFileSelectButton);
    aliquotFileSelectButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            // Opens file picker activity to main menu
            Intent openFilePicker = new Intent("android.intent.action.FILEPICKER");
            openFilePicker.putExtra("Default_Directory", "From_Aliquot_Directory");
            startActivityForResult(openFilePicker, 1); // Opens FilePicker and waits for it to return an Extra (SEE onActivityResult())
        }/*from  w ww .  j av  a 2  s . co m*/
    });

    aliquotSelectedFileText = (EditText) findViewById(R.id.aliquotFileSelectText); // Contains selected aliquot file name

    // sets the Aliquot file when one has already been selected (through "View Files" menu)
    if (getIntent().hasExtra("AliquotXMLFileName")) {
        String aliquotPath = getIntent().getStringExtra("AliquotXMLFileName");
        aliquotSelectedFileText.setText(splitReportSettingsName(aliquotPath));
    }

    Button aliquotFileSubmitButton = (Button) findViewById(R.id.aliquotFileSubmitButton);
    aliquotFileSubmitButton.setOnClickListener(new View.OnClickListener() {
        // Submits aliquot file to display activity for parsing and displaying in table
        public void onClick(View v) {

            if (aliquotSelectedFileText.getText().length() != 0) {

                // if coming from a previously created table, change the aliquot
                if (getIntent().hasExtra("From_Table")) {
                    if (getIntent().getStringExtra("From_Table").equals("true")) {

                        // if the Aliquot selected is valid, return to the new table
                        if (validateFile(getIntent().getStringExtra("AliquotXMLFileName"))) {
                            Toast.makeText(AliquotMenuActivity.this, "Changing Aliquot...", Toast.LENGTH_LONG)
                                    .show(); // lets user know table is opening
                            Intent returnAliquot = new Intent("android.intent.action.DISPLAY");
                            returnAliquot.putExtra("newAliquot", "true"); // tells if a new Aliquot has been chosen

                            // tells Intent that it is from a previous table that was opened via the History table
                            if (getIntent().hasExtra("fromHistory")) {
                                returnAliquot.putExtra("fromHistory",
                                        getIntent().getStringExtra("fromHistory"));
                                returnAliquot.putExtra("historyAliquot",
                                        getIntent().getStringExtra("AliquotXMLFileName"));

                                if (!getIntent().getStringExtra("fromHistory").equals("true"))
                                    saveCurrentAliquot(); // saves Aliquot if Intent was NOT originally from the History table
                            }

                            else // saves Aliquot if Intent was NOT originally from the History table (and doesn't have extra)
                                saveCurrentAliquot();

                            setResult(RESULT_OK, returnAliquot);
                            finish();

                        } else // if it is not valid, display a message
                            Toast.makeText(AliquotMenuActivity.this, "ERROR: Invalid Aliquot XML file.",
                                    Toast.LENGTH_LONG).show();

                    }

                } else {

                    // if the Aliquot selected is valid, return to the new table
                    if (validateFile(getIntent().getStringExtra("AliquotXMLFileName"))) {
                        // Makes sure there is a file selected
                        Toast.makeText(AliquotMenuActivity.this, "Opening table...", Toast.LENGTH_LONG).show(); // lets user know table is opening
                        Intent openDisplayTable = new Intent("android.intent.action.DISPLAY"); // Opens display table
                        openDisplayTable.putExtra("fromHistory", "false"); // tells Intent that it is not from History table

                        saveCurrentAliquot();

                        startActivity(openDisplayTable); // Starts display activity

                    } else // if it is not valid, display a message
                        Toast.makeText(AliquotMenuActivity.this, "ERROR: Invalid Aliquot XML file.",
                                Toast.LENGTH_LONG).show();

                }

            } else
                // Tells user to select a file for viewing
                Toast.makeText(AliquotMenuActivity.this, "Please select an aliquot file to view.",
                        Toast.LENGTH_LONG).show(); // lets user know table is opening

        }
    });

    igsnText = (EditText) findViewById(R.id.aliquotIGSNText);
    // Checks to see if user profile information has been authenticated for private file access
    // Sets appropriate hint based on if credentials are stored or not
    retrieveCredentials();
    if (!getGeochronUsername().contentEquals("None") && !getGeochronPassword().contentEquals("None"))
        igsnText.setHint("Profile information stored. Private files enabled!");
    else
        igsnText.setHint("No profile information stored. Private files disabled.");

    Button igsnDownloadButton = (Button) findViewById(R.id.aliquotIGSNSubmitButton);
    igsnDownloadButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {

            // Hides SoftKeyboard When Download Button is Pressed
            InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(igsnText.getWindowToken(), 0);

            // Checks internet connection before downloading files
            ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(
                    Context.CONNECTIVITY_SERVICE);
            NetworkInfo mobileWifi = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);

            if (mobileWifi.isConnected()) {
                if (igsnText.getText().length() != 0) {
                    downloadAliquot();
                    igsnText.setText("");
                }
            } else {//Handles lack of wifi connection
                new AlertDialog.Builder(AliquotMenuActivity.this)
                        .setMessage("You are not connected to WiFi, mobile data rates may apply. "
                                + "Do you wish to continue?")
                        // if user selects yes, continue with validation
                        .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialogInterface, int i) {
                                downloadAliquot();
                                igsnText.setText("");
                            }
                        })
                        // if user selects no, just go back
                        .setNegativeButton("No", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialogInterface, int i) {
                                dialogInterface.dismiss();
                            }
                        }).show();
            }
        }

    });

    // displays the current Report Settings
    TextView currentReportSettingsLabel = (TextView) findViewById(R.id.aliquotCurrentReportSettingsLabel);
    currentReportSettingsLabel
            .setText("Current Report Settings:\n" + splitReportSettingsName(retrieveReportSettingsFileName()));

    // if no file permissions, asks for them
    if (ContextCompat.checkSelfPermission(this,
            android.Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
        ActivityCompat.requestPermissions(this,
                new String[] { android.Manifest.permission.WRITE_EXTERNAL_STORAGE }, 1);
    }
}

From source file:fr.cph.chicago.core.adapter.NearbyAdapter.java

private View handleBuses(final int position, @NonNull final ViewGroup parent) {
    final LayoutInflater vi = (LayoutInflater) parent.getContext()
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    final View convertView = vi.inflate(R.layout.list_nearby, parent, false);

    // Bus/*from ww w .j a  va  2  s .  c o m*/
    final int index = position - stations.size();
    final BusStop busStop = busStops.get(index);

    final ImageView imageView = (ImageView) convertView.findViewById(R.id.icon);
    imageView.setImageDrawable(
            ContextCompat.getDrawable(parent.getContext(), R.drawable.ic_directions_bus_white_24dp));

    final TextView routeView = (TextView) convertView.findViewById(R.id.station_name);
    routeView.setText(busStop.getName());

    final LinearLayout resultLayout = (LinearLayout) convertView.findViewById(R.id.nearby_results);

    final Map<String, List<BusArrival>> arrivalsForStop = busArrivals.get(busStop.getId(), new HashMap<>());

    Stream.of(arrivalsForStop.entrySet()).forEach(entry -> {
        final LinearLayout.LayoutParams leftParam = new LinearLayout.LayoutParams(
                ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        final RelativeLayout insideLayout = new RelativeLayout(context);
        insideLayout.setLayoutParams(leftParam);
        insideLayout.setPadding(line1PaddingColor * 2, stopsPaddingTop, 0, 0);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            insideLayout.setBackground(ContextCompat.getDrawable(parent.getContext(), R.drawable.any_selector));
        }

        final RelativeLayout lineIndication = LayoutUtil.createColoredRoundForFavorites(context, TrainLine.NA);
        int lineId = Util.generateViewId();
        lineIndication.setId(lineId);

        final RelativeLayout.LayoutParams stopParam = new RelativeLayout.LayoutParams(
                ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        stopParam.addRule(RelativeLayout.RIGHT_OF, lineId);
        stopParam.setMargins(Util.convertDpToPixel(context, 10), 0, 0, 0);

        final LinearLayout stopLayout = new LinearLayout(context);
        stopLayout.setOrientation(LinearLayout.VERTICAL);
        stopLayout.setLayoutParams(stopParam);
        int stopId = Util.generateViewId();
        stopLayout.setId(stopId);

        final RelativeLayout.LayoutParams boundParam = new RelativeLayout.LayoutParams(
                ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        boundParam.addRule(RelativeLayout.RIGHT_OF, stopId);

        final LinearLayout boundLayout = new LinearLayout(context);
        boundLayout.setOrientation(LinearLayout.HORIZONTAL);

        final String direction = entry.getKey();
        final List<BusArrival> busArrivals = entry.getValue();
        final String routeId = busArrivals.get(0).getRouteId();

        final TextView bound = new TextView(context);
        final String routeIdText = routeId + " (" + direction + "): ";
        bound.setText(routeIdText);
        bound.setTextColor(ContextCompat.getColor(context, R.color.grey_5));
        boundLayout.addView(bound);

        Stream.of(busArrivals).forEach(busArrival -> {
            final TextView timeView = new TextView(context);
            final String timeLeftDueDelay = busArrival.getTimeLeftDueDelay() + " ";
            timeView.setText(timeLeftDueDelay);
            timeView.setTextColor(ContextCompat.getColor(context, R.color.grey));
            timeView.setLines(1);
            timeView.setEllipsize(TruncateAt.END);
            boundLayout.addView(timeView);
        });

        stopLayout.addView(boundLayout);

        insideLayout.addView(lineIndication);
        insideLayout.addView(stopLayout);
        resultLayout.addView(insideLayout);
    });

    convertView.setOnClickListener(new NearbyOnClickListener(googleMap, markers, busStop.getId(),
            busStop.getPosition().getLatitude(), busStop.getPosition().getLongitude()));
    return convertView;
}

From source file:com.github.rutvijkumar.twittfuse.fragments.ProfileImageViewFragment.java

private void setBackGround(User user, ImageLoader imageLoader, final RelativeLayout profileInfoLayout,
        String url) {/* ww w . j  a  v  a 2 s .co m*/
    imageLoader.loadImage(url, new ImageLoadingListener() {

        @Override
        public void onLoadingStarted(String arg0, View arg1) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onLoadingFailed(String arg0, View arg1, FailReason arg2) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onLoadingComplete(String arg0, View arg1, Bitmap bitmap) {
            // TODO Auto-generated method stub
            BitmapDrawable bg = new BitmapDrawable(getResources(), bitmap);
            profileInfoLayout.setBackground(bg);

        }

        @Override
        public void onLoadingCancelled(String arg0, View arg1) {
            // TODO Auto-generated method stub

        }
    });

}

From source file:com.luseen.spacenavigation.SpaceNavigationView.java

/**
 * Show badge at index/*from   ww  w  .  ja  va 2 s  . co m*/
 *
 * @param itemIndex index
 * @param badgeText badge count text
 */
public void showBadgeAtIndex(int itemIndex, int badgeText, @ColorInt int badgeColor) {
    if (itemIndex < 0 || itemIndex > spaceItems.size()) {
        throw new ArrayIndexOutOfBoundsException("Your item index can't be 0 or greater than space item size,"
                + " your items size is " + spaceItems.size() + ", your current index is :" + itemIndex);
    } else {
        RelativeLayout badgeView = badgeList.get(itemIndex);

        /**
         * Set circle background to badge view
         */
        badgeView.setBackground(BadgeHelper.makeShapeDrawable(badgeColor));

        BadgeItem badgeItem = new BadgeItem(itemIndex, badgeText, badgeColor);
        BadgeHelper.showBadge(badgeView, badgeItem);
        badgeSaveInstanceHashMap.put(itemIndex, badgeItem);
    }
}

From source file:com.amazon.android.tv.tenfoot.ui.fragments.ContentSearchFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    final View view = super.onCreateView(inflater, container, savedInstanceState);

    if (view != null) {
        // Set background color and drawable.
        view.setBackgroundColor(ContextCompat.getColor(getActivity(), android.R.color.transparent));
        view.setBackground(ContextCompat.getDrawable(getActivity(), R.drawable.search_background));

        final SearchBar searchBar = (SearchBar) view.findViewById(R.id.lb_search_bar);
        if (searchBar != null) {

            // Set the left margin of the search bar.
            ViewGroup.MarginLayoutParams layoutParams = (ViewGroup.MarginLayoutParams) searchBar
                    .getLayoutParams();//from ww  w.j a  v a  2 s .  co m

            layoutParams.setMarginStart((int) getResources().getDimension(R.dimen.search_bar_margin_left));

            searchBar.setLayoutParams(layoutParams);

            // Move the search bar items next to the search icon.
            RelativeLayout searchBarItems = (RelativeLayout) searchBar.findViewById(R.id.lb_search_bar_items);

            if (searchBarItems != null) {

                RelativeLayout.LayoutParams searchBarItemsLayoutParams = (RelativeLayout.LayoutParams) searchBarItems
                        .getLayoutParams();

                searchBarItemsLayoutParams.setMarginStart(
                        (int) getResources().getDimension(R.dimen.search_bar_items_margin_left));

                searchBarItems.setLayoutParams(searchBarItemsLayoutParams);

                // Set the search bar items background selector.
                searchBarItems.setBackground(ContextCompat.getDrawable(getActivity(),
                        R.drawable.search_edit_text_bg_color_selector));
            }

            // Set speech orb icon.
            mSpeechOrbView = (SpeechOrbView) searchBar.findViewById(R.id.lb_search_bar_speech_orb);

            if (mSpeechOrbView != null) {
                mSpeechOrbView.setOrbIcon(ContextCompat.getDrawable(getActivity(), R.drawable.search_icon));
            }

            final SearchEditText searchEditText = (SearchEditText) searchBar
                    .findViewById(R.id.lb_search_text_editor);

            if (searchEditText != null) {

                mSearchEditText = searchEditText;

                // Handle keyboard being dismissed to prevent focus going to SearchOrb
                // If user presses back from keyboard, you don't get KeyboardDismissListener
                // so handle that here.
                searchEditText.setOnEditorActionListener((textView, actionId, keyEvent) -> {

                    // Track search if keyboard is closed with IME_ACTION_PREVIOUS or
                    // if IME_ACTION_SEARCH occurs.
                    if (actionId == EditorInfo.IME_ACTION_SEARCH
                            || actionId == EditorInfo.IME_ACTION_PREVIOUS) {

                        if (mQuery != null) {
                            AnalyticsHelper.trackSearchQuery(mQuery);
                        }
                    }

                    if (actionId == EditorInfo.IME_ACTION_PREVIOUS) {

                        // Prevent highlighting SearchOrb
                        mSpeechOrbView.setFocusable(false);
                        mSpeechOrbView.clearFocus();
                        // If there are results allow first result to be selected
                        if (mHasResults) {
                            mSearchEditText.clearFocus();
                        }

                        // Hide keyboard since we are handling the action
                        if (isAdded()) {
                            // Ensure we are added before calling getActivity
                            InputMethodManager inputManager = (InputMethodManager) getActivity()
                                    .getSystemService(Context.INPUT_METHOD_SERVICE);
                            if (inputManager != null) {
                                inputManager.hideSoftInputFromWindow(
                                        getActivity().getCurrentFocus().getWindowToken(),
                                        InputMethodManager.HIDE_NOT_ALWAYS);
                            }
                        } else {
                            Log.e(TAG, "Cannot find activity, can't dismiss keyboard");
                            // Couldn't handle action.
                            // Will expose other focus issues potentially.
                            return false;
                        }
                        // No more processing of this action.
                        return true;
                    }
                    // Someone else needs to handle this action.
                    return false;
                });

                // Override the dismiss listener to get around keyboard issue where dismissing
                // keyboard takes user into first search result's
                // content_details_activity_layout page.
                searchEditText.setOnKeyboardDismissListener(() -> {
                    // If search returns results, focus on the first item in the result list.
                    // If search doesn't have results, this will focus on searchEditText again.
                    mSpeechOrbView.setFocusable(false);
                    mSpeechOrbView.clearFocus();
                    // We don't need to clearFocus on SearchEditText here, the first
                    // result will be selected already.
                });
            }
        }
    }
    return view;
}

From source file:com.ibm.mil.readyapps.physio.fragments.PainLocationFragment.java

/**
 * Pulls the bitmap image of the body part out of its RelativeLayout, colors it appropriatly,
 * and then tells the zoomLayout where it needs to zoom to. Also swaps the FRONT/BACK buttons
 * for the ADD/DELETE buttons./*from  w w w . j a va  2s  .  c  o m*/
 *
 * @param image the body part the touch occured in.
 */
private void zoomOnImage(RelativeLayout image) {

    Bitmap bitm = ((BitmapDrawable) image.getBackground()).getBitmap();

    Bitmap temp = bitm.copy(bitm.getConfig(), true);
    int[] pixels = new int[temp.getHeight() * temp.getWidth()];

    temp.getPixels(pixels, 0, temp.getWidth(), 0, 0, temp.getWidth(), temp.getHeight());

    for (int i = 0; i < temp.getHeight() * temp.getWidth(); i++) {

        if (pixels[i] != 0) {

            int r, g, b;

            if (!blue) {
                r = Color.red(pixels[i]) + 100;
                if (r > 255) {
                    r = 255;
                }
                g = Color.green(pixels[i]) - 50;
                b = Color.blue(pixels[i]) - 50;
            } else {
                r = Color.red(pixels[i]) - 30;
                g = Color.green(pixels[i]) + 15;
                b = Color.blue(pixels[i]) + 100;
                if (b > 255) {
                    b = 255;
                }

            }
            pixels[i] = Color.argb(Color.alpha(pixels[i]), r, g, b);
        }
    }

    temp.setPixels(pixels, 0, temp.getWidth(), 0, 0, temp.getWidth(), temp.getHeight());
    image.setBackground(new BitmapDrawable(getResources(), temp));

    Rect rect = new Rect();
    image.getGlobalVisibleRect(rect);

    zoomLayout.zoomToRect(rect, 0, getYOffset());
    current = image;
    zoomed = true;
    swapButtons();

    placePointer(rect.centerX(), rect.centerY());

}