Example usage for android.view ViewGroup getResources

List of usage examples for android.view ViewGroup getResources

Introduction

In this page you can find the example usage for android.view ViewGroup getResources.

Prototype

public Resources getResources() 

Source Link

Document

Returns the resources associated with this view.

Usage

From source file:com.tmall.ultraviewpager.UltraViewPagerAdapter.java

@Override
public Object instantiateItem(ViewGroup container, int position) {
    int realPosition = position;
    //TODO/*from w w w . ja va 2 s.  c o  m*/
    if (enableLoop && adapter.getCount() != 0) {
        realPosition = position % adapter.getCount();
    }

    Object item = adapter.instantiateItem(container, realPosition);
    //TODO
    View childView = null;
    if (item instanceof View)
        childView = (View) item;
    if (item instanceof RecyclerView.ViewHolder)
        childView = ((RecyclerView.ViewHolder) item).itemView;

    ViewPager viewPager = (ViewPager) container;
    int childCount = viewPager.getChildCount();
    for (int i = 0; i < childCount; i++) {
        View child = viewPager.getChildAt(i);
        if (isViewFromObject(child, item)) {
            viewArray.put(realPosition, child);
            break;
        }
    }

    if (isEnableMultiScr()) {
        if (scrWidth == 0) {
            scrWidth = container.getResources().getDisplayMetrics().widthPixels;
        }
        RelativeLayout relativeLayout = new RelativeLayout(container.getContext());

        if (childView.getLayoutParams() != null) {
            RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(
                    (int) (scrWidth * multiScrRatio), ViewGroup.LayoutParams.MATCH_PARENT);

            layoutParams.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);
            childView.setLayoutParams(layoutParams);
        }

        container.removeView(childView);
        relativeLayout.addView(childView);

        container.addView(relativeLayout);
        return relativeLayout;
    }

    return item;
}

From source file:com.qs.qswlw.view.Mypager.UltraViewPagerAdapter.java

@Override
public Object instantiateItem(ViewGroup container, int position) {
    int realPosition = position;
    //TODO/* w  ww.  java2 s .  co m*/
    if (enableLoop && adapter.getCount() != 0) {
        realPosition = position % adapter.getCount();
    }

    Object item = adapter.instantiateItem(container, realPosition);
    //TODO
    View childView = null;
    if (item instanceof View)
        childView = (View) item;
    //        if (item instanceof RecyclerView.ViewHolder)
    //            childView = ((RecyclerView.ViewHolder) item).itemView;

    ViewPager viewPager = (ViewPager) container;
    int childCount = viewPager.getChildCount();
    for (int i = 0; i < childCount; i++) {
        View child = viewPager.getChildAt(i);
        if (isViewFromObject(child, item)) {
            viewArray.put(realPosition, child);
            break;
        }
    }

    if (isEnableMultiScr()) {
        if (scrWidth == 0) {
            scrWidth = container.getResources().getDisplayMetrics().widthPixels;
        }
        RelativeLayout relativeLayout = new RelativeLayout(container.getContext());

        if (childView.getLayoutParams() != null) {
            RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(
                    (int) (scrWidth * multiScrRatio), ViewGroup.LayoutParams.MATCH_PARENT);

            layoutParams.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);
            childView.setLayoutParams(layoutParams);
        }

        container.removeView(childView);
        relativeLayout.addView(childView);

        container.addView(relativeLayout);
        return relativeLayout;
    }

    return item;
}

From source file:org.chromium.chrome.browser.payments.ui.PaymentRequestSection.java

private Button createAndAddEditButton(ViewGroup parent) {
    Resources resources = parent.getResources();
    Button view = DualControlLayout.createButtonForLayout(parent.getContext(), true,
            resources.getString(R.string.select), this);
    view.setId(R.id.payments_section);/*from w  w  w  . j a  v  a  2 s  . c o m*/

    LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    ApiCompatibilityUtils.setMarginStart(params, mLargeSpacing);
    parent.addView(view, params);
    return view;
}

From source file:org.chromium.chrome.browser.payments.ui.PaymentRequestSection.java

private ImageView createAndAddChevron(ViewGroup parent) {
    Resources resources = parent.getResources();
    TintedDrawable chevron = TintedDrawable.constructTintedDrawable(resources, R.drawable.ic_expanded,
            R.color.payments_section_chevron);

    ImageView view = new ImageView(parent.getContext());
    view.setImageDrawable(chevron);//from ww w .  j  av  a 2  s .co  m

    // Wrap whatever image is passed in.
    LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    ApiCompatibilityUtils.setMarginStart(params, mLargeSpacing);
    parent.addView(view, params);
    return view;
}

From source file:org.exobel.routerkeygen.ui.WifiListAdapter.java

public View getView(int position, View convertView, ViewGroup parent) {
    final Item wifi = getItem(position);
    if (convertView == null) {
        if (wifi.type == Item.ITEM) {
            convertView = getItemView(parent);
        } else {//from  w  w  w.j  av a2  s  .c  o m
            convertView = getSectionView(parent);
        }
    } else {
        switch (wifi.type) {
        case Item.ITEM:
            if (convertView.getTag() == null) {
                convertView = getItemView(parent);
            }
            break;
        case Item.SECTION:
            if (convertView.getTag() != null) {
                convertView = getSectionView(parent);
            }
            break;
        }
    }

    if (wifi.type == Item.ITEM) {
        final ViewHolder holder = (ViewHolder) convertView.getTag();
        if (holder != null) {
            holder.ssid.setText(wifi.wifiNetwork.getSsidName());
            holder.mac.setText(wifi.wifiNetwork.getMacAddress());
            final int strenght = wifi.wifiNetwork.getLevel();
            if (wifi.wifiNetwork.isLocked()) {
                holder.networkStrength.setImageDrawable(wifiSignalLocked[strenght]);
            } else {
                holder.networkStrength.setImageDrawable(wifiSignal[strenght]);
            }
        }
    } else {
        TextView view = (TextView) convertView;
        view.setText(wifi.text);
        view.setBackgroundColor(parent.getResources().getColor(wifi.color));
    }
    return convertView;
}

From source file:com.android.inputmethod.latin.suggestions.SuggestionStripLayoutHelper.java

public void layoutAddToDictionaryHint(final String word, final ViewGroup addToDictionaryStrip) {
    final boolean shouldShowUiToAcceptTypedWord = Settings.getInstance()
            .getCurrent().mShouldShowUiToAcceptTypedWord;
    final int stripWidth = addToDictionaryStrip.getWidth();
    final int width = shouldShowUiToAcceptTypedWord ? stripWidth : stripWidth - mDividerWidth - mPadding * 2;

    final TextView wordView = (TextView) addToDictionaryStrip.findViewById(R.id.word_to_save);
    wordView.setTextColor(mColorTypedWord);
    final int wordWidth = (int) (width * mCenterSuggestionWeight);
    final CharSequence wordToSave = getEllipsizedText(word, wordWidth, wordView.getPaint());
    final float wordScaleX = wordView.getTextScaleX();
    wordView.setText(wordToSave);/*from   w w w.  ja  va2 s  .c  o  m*/
    wordView.setTextScaleX(wordScaleX);
    setLayoutWeight(wordView, mCenterSuggestionWeight, ViewGroup.LayoutParams.MATCH_PARENT);
    final int wordVisibility = shouldShowUiToAcceptTypedWord ? View.GONE : View.VISIBLE;
    wordView.setVisibility(wordVisibility);
    addToDictionaryStrip.findViewById(R.id.word_to_save_divider).setVisibility(wordVisibility);

    final Resources res = addToDictionaryStrip.getResources();
    final CharSequence hintText;
    final int hintWidth;
    final float hintWeight;
    final TextView hintView = (TextView) addToDictionaryStrip.findViewById(R.id.hint_add_to_dictionary);
    if (shouldShowUiToAcceptTypedWord) {
        hintText = res.getText(R.string.hint_add_to_dictionary_without_word);
        hintWidth = width;
        hintWeight = 1.0f;
        hintView.setGravity(Gravity.CENTER);
    } else {
        final boolean isRtlLanguage = (ViewCompat
                .getLayoutDirection(addToDictionaryStrip) == ViewCompat.LAYOUT_DIRECTION_RTL);
        final String arrow = isRtlLanguage ? RIGHTWARDS_ARROW : LEFTWARDS_ARROW;
        final boolean isRtlSystem = SubtypeLocaleUtils.isRtlLanguage(res.getConfiguration().locale);
        final CharSequence hint = res.getText(R.string.hint_add_to_dictionary);
        hintText = (isRtlLanguage == isRtlSystem) ? (arrow + hint) : (hint + arrow);
        hintWidth = width - wordWidth;
        hintWeight = 1.0f - mCenterSuggestionWeight;
        hintView.setGravity(Gravity.CENTER_VERTICAL | Gravity.START);
    }
    hintView.setTextColor(mColorAutoCorrect);
    final float hintScaleX = getTextScaleX(hintText, hintWidth, hintView.getPaint());
    hintView.setText(hintText);
    hintView.setTextScaleX(hintScaleX);
    setLayoutWeight(hintView, hintWeight, ViewGroup.LayoutParams.MATCH_PARENT);
}

From source file:com.achep.acdisplay.ui.components.MediaWidget.java

@Override
protected ViewGroup onCreateView(@NonNull LayoutInflater inflater, @NonNull ViewGroup container,
        @Nullable ViewGroup sceneView) {
    boolean initialize = sceneView == null;
    if (initialize) {
        sceneView = (ViewGroup) inflater.inflate(R.layout.acdisplay_scene_music, container, false);
        assert sceneView != null;
    }/*w  ww .j  av  a 2  s  .  c  o m*/

    mArtworkView = (ImageView) sceneView.findViewById(R.id.artwork);
    ViewGroup infoLayout = (ViewGroup) sceneView.findViewById(R.id.metadata);
    mTitleView = (TextView) infoLayout.findViewById(R.id.media_title);
    mSubtitleView = (TextView) infoLayout.findViewById(R.id.media_subtitle);
    mButtonPrevious = (ImageButton) sceneView.findViewById(R.id.previous);
    mButtonPlayPause = (ImageButton) sceneView.findViewById(R.id.play);
    mButtonNext = (ImageButton) sceneView.findViewById(R.id.next);
    mSeekLayout = (ViewGroup) sceneView.findViewById(R.id.seek_layout);
    mSeekBar = (SeekBar) mSeekLayout.findViewById(R.id.seek_bar);
    mPositionText = (TextView) mSeekLayout.findViewById(R.id.playback_position);
    mDurationText = (TextView) mSeekLayout.findViewById(R.id.duration);

    if (!initialize) {
        return sceneView;
    }

    mSeekBar.setOnSeekBarChangeListener(this);
    mButtonPrevious.setOnClickListener(this);
    mButtonPlayPause.setImageDrawable(mPlayPauseDrawable);
    mButtonPlayPause.setOnClickListener(this);
    mButtonPlayPause.setOnLongClickListener(this);
    mButtonNext.setOnClickListener(this);

    // Show the seek-panel on long click.
    infoLayout.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {
            // Don't allow seeking on a weird song.
            if (mMediaController.getMetadata().duration <= 0 || mMediaController.getPlaybackPosition() < 0) {
                if (mSeekUiAtomic.isRunning()) {
                    toggleSeekUiVisibility();
                    return true;
                }
                return false;
            }

            toggleSeekUiVisibility();
            return true;
        }

        private void toggleSeekUiVisibility() {
            ViewGroup vg = getView();
            if (Device.hasKitKatApi() && vg.isLaidOut() && getFragment().isAnimatable()) {
                TransitionManager.beginDelayedTransition(vg);
            }
            mSeekUiAtomic.react(!mSeekUiAtomic.isRunning());
            mCallback.requestTimeoutRestart(MediaWidget.this);
        }
    });

    if (Device.hasLollipopApi()) {
        // FIXME: Ripple doesn't work if the background is set (masked ripple works fine, but ugly).
        // Apply our own ripple drawable with slightly extended abilities, such
        // as setting color filter.
        ColorStateList csl = container.getResources().getColorStateList(R.color.ripple_dark);
        mButtonPlayPause.setBackground(new RippleDrawable2(csl, null, null));
    } else {
        RippleUtils.makeFor(false, true, mButtonNext, mButtonPlayPause, mButtonPrevious);
    }

    updatePlayPauseButtonColor(mArtworkColor);
    updateSeekBarColor(mArtworkColor);

    return sceneView;
}

From source file:com.bullmobi.message.ui.components.MediaWidget.java

@Override
protected ViewGroup onCreateView(@NonNull LayoutInflater inflater, @NonNull ViewGroup container,
        @Nullable ViewGroup sceneView) {
    boolean initialize = sceneView == null;
    if (initialize) {
        sceneView = (ViewGroup) inflater.inflate(R.layout.easynotification_scene_music, container, false);
        assert sceneView != null;
    }//from   w  w w  .j a  v  a2  s.  c om

    mArtworkView = (ImageView) sceneView.findViewById(R.id.artwork);
    ViewGroup infoLayout = (ViewGroup) sceneView.findViewById(R.id.metadata);
    mTitleView = (TextView) infoLayout.findViewById(R.id.media_title);
    mSubtitleView = (TextView) infoLayout.findViewById(R.id.media_subtitle);
    mButtonPrevious = (ImageButton) sceneView.findViewById(R.id.previous);
    mButtonPlayPause = (ImageButton) sceneView.findViewById(R.id.play);
    mButtonNext = (ImageButton) sceneView.findViewById(R.id.next);
    mSeekLayout = (ViewGroup) sceneView.findViewById(R.id.seek_layout);
    mSeekBar = (SeekBar) mSeekLayout.findViewById(R.id.seek_bar);
    mPositionText = (TextView) mSeekLayout.findViewById(R.id.playback_position);
    mDurationText = (TextView) mSeekLayout.findViewById(R.id.duration);

    if (!initialize) {
        return sceneView;
    }

    mSeekBar.setOnSeekBarChangeListener(this);
    mButtonPrevious.setOnClickListener(this);
    mButtonPlayPause.setImageDrawable(mPlayPauseDrawable);
    mButtonPlayPause.setOnClickListener(this);
    mButtonPlayPause.setOnLongClickListener(this);
    mButtonNext.setOnClickListener(this);

    // Show the seek-panel on long click.
    infoLayout.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {
            // Don't allow seeking on a weird song.
            if (mMediaController.getMetadata().duration <= 0 || mMediaController.getPlaybackPosition() < 0) {
                if (mSeekUiAtomic.isRunning()) {
                    toggleSeekUiVisibility();
                    return true;
                }
                return false;
            }

            toggleSeekUiVisibility();
            return true;
        }

        private void toggleSeekUiVisibility() {
            ViewGroup vg = getView();
            if (Device.hasKitKatApi() && vg.isLaidOut() && getFragment().isAnimatable()) {
                TransitionManager.beginDelayedTransition(vg);
            }
            mSeekUiAtomic.react(!mSeekUiAtomic.isRunning());
            mCallback.requestTimeoutRestart(MediaWidget.this);
        }
    });

    if (Device.hasLollipopApi()) {
        // FIXME: Ripple doesn't work if the background is set (masked ripple works fine, but ugly).
        // Apply our own ripple drawable with slightly extended abilities, such
        // as setting color filter.
        ColorStateList csl = container.getResources().getColorStateList(R.color.ripple_dark);
        mButtonPlayPause.setBackground(new RippleDrawable2(csl, null, null));
    } else {
        RippleUtils.makeFor(false, true, mButtonNext, mButtonPlayPause, mButtonPrevious);
    }

    updatePlayPauseButtonColor(mArtworkColor);
    updateSeekBarColor(mArtworkColor);

    return sceneView;
}