Example usage for android.widget LinearLayout getContext

List of usage examples for android.widget LinearLayout getContext

Introduction

In this page you can find the example usage for android.widget LinearLayout getContext.

Prototype

@ViewDebug.CapturedViewProperty
public final Context getContext() 

Source Link

Document

Returns the context the view is running in, through which it can access the current theme, resources, etc.

Usage

From source file:Main.java

public static View addSpacer(LinearLayout row) {
    View spacer = new View(row.getContext());
    //      if (DEBUG) spacer.setBackgroundColor(Color.GREEN);
    android.widget.LinearLayout.LayoutParams params = new android.widget.LinearLayout.LayoutParams(
            DEBUG ? 1 : 0, DEBUG ? 1 : 0, 1);
    row.addView(spacer, params);//from   w  w w .jav  a  2 s. c  o  m
    return spacer;
}

From source file:com.nagopy.android.xposed.utilities.ModBrightness.java

@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
@XMinSdkVersion(Build.VERSION_CODES.JELLY_BEAN_MR1)
@HandleInitPackageResources(targetPackage = XConst.PKG_SYSTEM_UI, summary = "??")
public static void brightnessDebugger(final String modulePath, final InitPackageResourcesParam resparam,
        final ModBrightnessSettingsGen settings) throws Throwable {
    if (!settings.brightnessDebugger) {
        return;//from  w  w  w .  j a  v  a 2  s  .c om
    }

    resparam.res.hookLayout(XConst.PKG_SYSTEM_UI, "layout", "super_status_bar", new XC_LayoutInflated() {
        @Override
        public void handleLayoutInflated(LayoutInflatedParam liparam) throws Throwable {
            LinearLayout parent = (LinearLayout) liparam.view
                    .findViewById(liparam.res.getIdentifier("system_icon_area", "id", XConst.PKG_SYSTEM_UI));

            // ?
            TextView luxTextView = new TextView(parent.getContext());
            luxTextView.setTextSize(8);
            luxTextView.setSingleLine(false);
            luxTextView.setTextColor(Color.WHITE);
            luxTextView.setText("");
            parent.setGravity(Gravity.CENTER_VERTICAL);
            parent.addView(luxTextView, 0);
            AutoBrightnessController autoBrightnessChangedReceiver = new AutoBrightnessController(luxTextView);
            IntentFilter intentFilter = new IntentFilter(
                    AutoBrightnessController.ACTION_AUTO_BRIGHTNESS_CHANGED);
            intentFilter.addAction(Intent.ACTION_SCREEN_OFF);
            parent.getContext().registerReceiver(autoBrightnessChangedReceiver, intentFilter);
        }
    });
}

From source file:syncthing.android.ui.sessionsettings.EditDevicePresenter.java

@BindingAdapter("addShareFolders")
public static void addSharedFolders(LinearLayout shareFoldersContainer, EditDevicePresenter presenter) {
    if (presenter == null)
        return;/*from ww  w. j  a va2  s .c o  m*/
    shareFoldersContainer.removeAllViews();
    for (Map.Entry<String, Boolean> e : presenter.sharedFolders.entrySet()) {
        final String id = e.getKey();
        CheckBox checkBox = new CheckBox(shareFoldersContainer.getContext());
        checkBox.setText(id);
        checkBox.setChecked(e.getValue());
        shareFoldersContainer.addView(checkBox);
        presenter.bindingSubscriptions().add(RxCompoundButton.checkedChanges(checkBox).subscribe(checked -> {
            presenter.setFolderShared(id, checked);
        }));
    }
}

From source file:it.jaschke.alexandria.model.view.BookDetailViewModel.java

/**
 * Removes all views from the {@link LinearLayout} and adds new ones for
 * the specified {@link Author}s.//from  www .  jav a 2s  . c  om
 *
 * @param container {@link LinearLayout} that will contain the authors.
 * @param authors the {@link Author}s to be placed in the container.
 */
@BindingAdapter({ "bind:authors" })
public static void loadAuthorViews(LinearLayout container, List<Author> authors) {
    container.removeAllViews();
    if (authors == null || authors.isEmpty()) {
        return;
    }
    LayoutInflater inflater = (LayoutInflater) container.getContext()
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    for (Author author : authors) {
        AuthorListItemBinding binding = DataBindingUtil.inflate(inflater, R.layout.list_item_author, container,
                false);
        AuthorListItemViewModel itemViewModel = new AuthorListItemViewModel();
        itemViewModel.setAuthor(author);
        binding.setViewModel(itemViewModel);
        container.addView(binding.getRoot());
    }
}

From source file:it.jaschke.alexandria.model.view.BookDetailViewModel.java

/**
 * Removes all views from the {@link LinearLayout} and adds new ones for
 * the specified instances of {@link Category}.
 *
 * @param container {@link LinearLayout} that will contain the categories.
 * @param categories the instances of {@link Category} to be placed in the
 *                   container.// w  w  w .  ja va2s  .  c o m
 */
@BindingAdapter({ "bind:categories" })
public static void loadCategoryViews(LinearLayout container, List<Category> categories) {
    container.removeAllViews();
    if (categories == null || categories.isEmpty()) {
        return;
    }
    LayoutInflater inflater = (LayoutInflater) container.getContext()
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    for (Category category : categories) {
        CategoryListItemBinding binding = DataBindingUtil.inflate(inflater, R.layout.list_item_category,
                container, false);
        CategoryListItemViewModel itemViewModel = new CategoryListItemViewModel();
        itemViewModel.setCategory(category);
        binding.setViewModel(itemViewModel);
        container.addView(binding.getRoot());
    }
}

From source file:mx.com.adolfogarcia.popularmovies.model.view.MovieDetailViewModel.java

/**
 * Removes all views from the {@link LinearLayout} and adds new ones for
 * the specified {@link Review}s.//from   www . jav  a2 s. c om
 *
 * @param container {@link LinearLayout} that will contain the reviews.
 * @param reviews the {@link Review}s to be placed in the container.
 */
@BindingAdapter({ "bind:reviews" })
public static void loadReviewViews(LinearLayout container, List<Review> reviews) {
    container.removeAllViews();
    if (reviews == null || reviews.isEmpty()) {
        return;
    }
    LayoutInflater inflater = (LayoutInflater) container.getContext()
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    for (Review review : reviews) {
        MovieReviewListItemBinding binding = DataBindingUtil.inflate(inflater, R.layout.list_item_movie_review,
                container, false);
        MovieReviewListItemViewModel itemViewModel = new MovieReviewListItemViewModel();
        itemViewModel.setReview(review);
        binding.setViewModel(itemViewModel);
        container.addView(binding.getRoot());
    }
}

From source file:mx.com.adolfogarcia.popularmovies.model.view.MovieDetailViewModel.java

/**
 * Removes all views from the {@link LinearLayout} and adds new ones for
 * the specified {@link Trailer}s./*  w  ww  . ja  v  a  2s .co m*/
 *
 * @param container {@link LinearLayout} that will contain the trailers.
 * @param trailers the {@link Trailer}s to be placed in the container.
 */
@BindingAdapter({ "bind:trailers" })
public static void loadTrailerViews(LinearLayout container, List<Trailer> trailers) {
    container.removeAllViews();
    if (trailers == null || trailers.isEmpty()) {
        return;
    }
    LayoutInflater inflater = (LayoutInflater) container.getContext()
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    for (Trailer trailer : trailers) {
        MovieTrailerListItemBinding binding = DataBindingUtil.inflate(inflater,
                R.layout.list_item_movie_trailer, container, false);
        MovieTrailerListItemViewModel itemViewModel = new MovieTrailerListItemViewModel();
        itemViewModel.setTrailer(trailer);
        binding.setViewModel(itemViewModel);
        container.addView(binding.getRoot());
    }
}

From source file:syncthing.android.ui.sessionsettings.EditFolderPresenter.java

@BindingAdapter("addShareDevices")
public static void addShareDevices(LinearLayout shareDevicesContainer, EditFolderPresenter presenter) {
    if (presenter == null)
        return;//from  w w w.j  av a 2s .c o m
    shareDevicesContainer.removeAllViews();
    for (Map.Entry<String, Boolean> e : presenter.sharedDevices.entrySet()) {
        final String id = e.getKey();
        CheckBox checkBox = new CheckBox(shareDevicesContainer.getContext());
        DeviceConfig device = presenter.controller.getDevice(id);
        if (device == null) {
            device = new DeviceConfig();
            device.deviceID = id;
        }
        checkBox.setText(SyncthingUtils.getDisplayName(device));
        checkBox.setChecked(e.getValue());
        shareDevicesContainer.addView(checkBox);
        presenter.bindingSubscriptions().add(RxCompoundButton.checkedChanges(checkBox).subscribe(b -> {
            presenter.setDeviceShared(id, b);
        }));
    }
}

From source file:com.h6ah4i.android.example.materialshadowninepatch.ProgrammaticallyAddDemoFragment.java

private void addItem() {
    LinearLayout parent = mItemsContainer;
    Context context = parent.getContext();
    float density = context.getResources().getDisplayMetrics().density;

    AppCompatTextView itemView = new AppCompatTextView(context);

    // Need to specify type of the shadow. Specify one of the following to the fourth parameter.
    ////from   ww  w .  j a v  a  2s .  co m
    // - R.style.ms9_DefaultShadowStyle[Z6|Z9|Z18]
    // - R.style.ms9_DefaultShadowStyle[Z6|Z9|Z18]CompatOnly
    // - R.style.ms9_NoDisplayedPositionAffectShadowStyle[Z6|Z9|Z18]
    // - R.style.ms9_NoDisplayedPositionAffectShadowStyle[Z6|Z9|Z18]CompatOnly
    // - R.style.ms9_CompositeShadowStyle[Z6|Z9|Z18]
    // - R.style.ms9_CompositeShadowStyle[Z6|Z9|Z18]CompatOnly
    MaterialShadowContainerView shadowView = new MaterialShadowContainerView(context, null, 0,
            R.style.ms9_DefaultShadowStyle);

    // Setup the itemView
    {
        MaterialShadowContainerView.LayoutParams layoutParams = new MaterialShadowContainerView.LayoutParams(
                ViewGroup.LayoutParams.MATCH_PARENT, (int) (density * 56));

        // Need to set background color and margins
        itemView.setBackgroundColor(Color.WHITE);
        layoutParams.setMargins((int) (8 * density), (int) (8 * density), (int) (8 * density),
                (int) (8 * density));
        itemView.setLayoutParams(layoutParams);

        itemView.setText("Item " + (parent.getChildCount() + 1));
        itemView.setGravity(Gravity.CENTER);

    }

    // Setup the shadowView
    {
        LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
                ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);

        shadowView.setLayoutParams(layoutParams);

        shadowView.setShadowElevation(density * 4);
        shadowView.setForceUseCompatShadow(mCheckBoxForceUseCompatMode.isChecked());
    }

    // Add views
    shadowView.addView(itemView);
    parent.addView(shadowView);
}

From source file:com.team3.classical.slidingtabs.SlidingTabsBasicFragment.java

void setNoClass(LinearLayout ll, int classes, int color) {
    TextView blank = new TextView(ll.getContext());
    if (color == 0)
        blank.setMinHeight(dip2px(ll.getContext(), classes * 25));
    blank.setBackgroundColor(Color.parseColor("#F0FFFF"));
    ll.addView(blank);//from   w  w  w. j  ava2  s  . c  o m
}