Example usage for android.view View getWidth

List of usage examples for android.view View getWidth

Introduction

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

Prototype

@ViewDebug.ExportedProperty(category = "layout")
public final int getWidth() 

Source Link

Document

Return the width of your view.

Usage

From source file:com.gizwits.framework.activity.BaseActivity.java

/**
 * ?EditText????????EditText???/*from  w  w  w  .  j a  va2 s .  c  o  m*/
 * 
 * @param v
 * @param event
 * @return
 */
private boolean isShouldHideInput(View v, MotionEvent event) {
    if (v != null && (v instanceof EditText)) {
        int[] l = { 0, 0 };
        v.getLocationInWindow(l);
        int left = l[0], top = l[1], bottom = top + v.getHeight(), right = left + v.getWidth();
        if (event.getX() > left && event.getX() < right && event.getY() > top && event.getY() < bottom) {
            // EditText
            return false;
        } else {
            return true;
        }
    }
    // ?EditText??EditView?
    return false;
}

From source file:net.kourlas.voipms_sms.activities.ConversationActivity.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.conversation);

    database = Database.getInstance(getApplicationContext());
    preferences = Preferences.getInstance(getApplicationContext());

    contact = getIntent().getStringExtra(getString(R.string.conversation_extra_contact));
    // Remove the leading one from a North American phone number (e.g. +1 (123) 555-4567)
    if ((contact.length() == 11) && (contact.charAt(0) == '1')) {
        contact = contact.substring(1);//from  w  ww.  ja v a  2  s  .c  o  m
    }

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    ViewCompat.setElevation(toolbar, getResources().getDimension(R.dimen.toolbar_elevation));
    setSupportActionBar(toolbar);
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        String contactName = Utils.getContactName(this, contact);
        if (contactName != null) {
            actionBar.setTitle(contactName);
        } else {
            actionBar.setTitle(Utils.getFormattedPhoneNumber(contact));
        }
        actionBar.setHomeButtonEnabled(true);
        actionBar.setDisplayHomeAsUpEnabled(true);
    }

    layoutManager = new LinearLayoutManager(this);
    layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
    layoutManager.setStackFromEnd(true);
    adapter = new ConversationRecyclerViewAdapter(this, layoutManager, contact);
    recyclerView = (RecyclerView) findViewById(R.id.list);
    recyclerView.setHasFixedSize(true);
    recyclerView.setLayoutManager(layoutManager);
    recyclerView.setAdapter(adapter);

    actionMode = null;
    actionModeEnabled = false;

    final EditText messageText = (EditText) findViewById(R.id.message_edit_text);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        messageText.setOutlineProvider(new ViewOutlineProvider() {
            @TargetApi(Build.VERSION_CODES.LOLLIPOP)
            @Override
            public void getOutline(View view, Outline outline) {
                outline.setRoundRect(0, 0, view.getWidth(), view.getHeight(), 15);
            }
        });
        messageText.setClipToOutline(true);
    }
    messageText.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            // Do nothing.
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            // Do nothing.
        }

        @Override
        public void afterTextChanged(Editable s) {
            ViewSwitcher viewSwitcher = (ViewSwitcher) findViewById(R.id.view_switcher);
            if (s.toString().equals("") && viewSwitcher.getDisplayedChild() == 1) {
                viewSwitcher.setDisplayedChild(0);
            } else if (viewSwitcher.getDisplayedChild() == 0) {
                viewSwitcher.setDisplayedChild(1);
            }
        }
    });
    messageText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if (hasFocus) {
                adapter.refresh();
            }
        }
    });
    String intentMessageText = getIntent().getStringExtra(getString(R.string.conversation_extra_message_text));
    if (intentMessageText != null) {
        messageText.setText(intentMessageText);
    }
    boolean intentFocus = getIntent().getBooleanExtra(getString(R.string.conversation_extra_focus), false);
    if (intentFocus) {
        messageText.requestFocus();
    }

    RelativeLayout messageSection = (RelativeLayout) findViewById(R.id.message_section);
    ViewCompat.setElevation(messageSection, 8);

    QuickContactBadge photo = (QuickContactBadge) findViewById(R.id.photo);
    Utils.applyCircularMask(photo);
    photo.assignContactFromPhone(preferences.getDid(), true);
    String photoUri = Utils.getContactPhotoUri(getApplicationContext(), preferences.getDid());
    if (photoUri != null) {
        photo.setImageURI(Uri.parse(photoUri));
    } else {
        photo.setImageToDefault();
    }

    final ImageButton sendButton = (ImageButton) findViewById(R.id.send_button);
    Utils.applyCircularMask(sendButton);
    sendButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            preSendMessage();
        }
    });
}

From source file:com.actionbarsherlock.internal.widget.ScrollingTabContainerView.java

public void animateToTab(final int position) {
    final View tabView = mTabLayout.getChildAt(position);
    if (mTabSelector != null) {
        removeCallbacks(mTabSelector);/*from www.j av  a 2s  .  c o m*/
    }
    mTabSelector = new Runnable() {
        public void run() {
            final int scrollPos = tabView.getLeft() - (getWidth() - tabView.getWidth()) / 2;
            smoothScrollTo(scrollPos, 0);
            mTabSelector = null;
        }
    };
    post(mTabSelector);
}

From source file:com.aibasis.parent.widget.PagerSlidingTabStrip.java

/**
 * ViewPager/*  w  w  w.  j  a v  a  2 s .c om*/
 * 
 * @param viewPager
 *            ViewPager
 */
public void setViewPager(ViewPager viewPager) {
    if (disableViewPager)
        return;
    this.viewPager = viewPager;
    this.viewPager.setOnPageChangeListener(new OnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            selectedTab(position);
            if (onPageChangeListener != null) {
                onPageChangeListener.onPageSelected(position);
            }
            if (listener != null)
                listener.onChanged(position);
        }

        @Override
        public void onPageScrolled(int nextPagePosition, float positionOffset, int positionOffsetPixels) {
            ViewGroup tabsLayout = getTabsLayout();
            if (nextPagePosition < tabsLayout.getChildCount()) {
                View view = tabsLayout.getChildAt(nextPagePosition);
                if (view != null) {
                    currentPosition = nextPagePosition;
                    currentPositionOffset = positionOffset;
                    scrollToChild(nextPagePosition, (int) (positionOffset * view.getWidth()));
                    invalidate();
                }
            }
            if (onPageChangeListener != null) {
                onPageChangeListener.onPageScrolled(nextPagePosition, positionOffset, positionOffsetPixels);
            }
        }

        @Override
        public void onPageScrollStateChanged(int arg0) {
            if (onPageChangeListener != null) {
                onPageChangeListener.onPageScrollStateChanged(arg0);
            }
        }
    });
    requestLayout();
}

From source file:cn.org.eshow.framwork.view.sliding.AbSlidingTabView.java

/**
 * Animate to tab./* w ww  . j  a  va2 s.c o  m*/
 *
 * @param position the position
 */
private void animateToTab(final int position) {
    final View tabView = mTabLayout.getChildAt(position);
    if (mTabSelector != null) {
        removeCallbacks(mTabSelector);
    }
    mTabSelector = new Runnable() {
        public void run() {
            final int scrollPos = tabView.getLeft() - (getWidth() - tabView.getWidth()) / 2;
            mTabScrollView.smoothScrollTo(scrollPos, 0);
            mTabSelector = null;
        }
    };
    post(mTabSelector);
}

From source file:com.cicada.startup.common.ui.view.indicator.ViewPagerIndicator.java

/**
 * ViewPager//from   w  ww .j a  va 2 s. c o  m
 *
 * @param viewPager ViewPager
 */
public void setViewPager(ViewPager viewPager) {
    if (disableViewPager)
        return;
    this.viewPager = viewPager;
    this.viewPager.setOnPageChangeListener(new OnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            selectedTab(position);
            if (onPageChangeListener != null) {
                onPageChangeListener.onPageSelected(position);
            }
            if (listener != null)
                listener.onChanged(position);
        }

        @Override
        public void onPageScrolled(int nextPagePosition, float positionOffset, int positionOffsetPixels) {

            ViewGroup tabsLayout = getTabsLayout();
            if (nextPagePosition < tabsLayout.getChildCount()) {
                View view = tabsLayout.getChildAt(nextPagePosition);
                if (view != null) {
                    currentPosition = nextPagePosition;
                    currentPositionOffset = positionOffset;
                    scrollToChild(nextPagePosition, (int) (positionOffset * view.getWidth()));
                    invalidate();
                }
            }
            if (onPageChangeListener != null) {
                onPageChangeListener.onPageScrolled(nextPagePosition, positionOffset, positionOffsetPixels);
            }
        }

        @Override
        public void onPageScrollStateChanged(int arg0) {
            if (onPageChangeListener != null) {
                onPageChangeListener.onPageScrollStateChanged(arg0);
            }
        }
    });
    requestLayout();
}

From source file:com.cs.test_recycview3.MyAnimator.java

private void animateRemoveImpl(final ViewHolder holder) {
    final View view = holder.itemView;
    final ViewPropertyAnimatorCompat animation = ViewCompat.animate(view);
    mRemoveAnimations.add(holder);//from  w w w.  j  av  a  2 s .  c o m
    animation.setDuration(getRemoveDuration()).translationX(view.getWidth() / 2)
            .setListener(new VpaListenerAdapter() {
                @Override
                public void onAnimationStart(View view) {
                    dispatchRemoveStarting(holder);
                }

                @Override
                public void onAnimationEnd(View view) {
                    animation.setListener(null);
                    ViewCompat.setTranslationX(view, 0);
                    dispatchRemoveFinished(holder);
                    mRemoveAnimations.remove(holder);
                    dispatchFinishedWhenDone();
                }
            }).start();
}

From source file:com.ftinc.kit.attributr.ui.widget.StickyRecyclerHeadersElevationDecoration.java

/**
 * Returns the first item currently in the recyclerview that's not obscured by a header.
 * @param parent//from   w  ww  .j a v  a 2s .c om
 * @return
 */
private View getNextView(RecyclerView parent) {
    View firstView = parent.getChildAt(0);

    // draw the first visible child's header at the top of the view
    int firstPosition = parent.getChildPosition(firstView);
    View firstHeader = getHeaderView(parent, firstPosition);

    for (int i = 0; i < parent.getChildCount(); i++) {

        View child = parent.getChildAt(i);
        RecyclerView.LayoutParams layoutParams = (RecyclerView.LayoutParams) child.getLayoutParams();

        if (getOrientation(parent) == LinearLayoutManager.VERTICAL) {

            if (child.getTop() - layoutParams.topMargin > firstHeader.getHeight()) {
                return child;
            }

        } else {

            if (child.getLeft() - layoutParams.leftMargin > firstHeader.getWidth()) {
                return child;
            }

        }
    }
    return null;
}

From source file:com.bwie.myrecyclerviewdemo1.MyitemAnimator.java

private void animateRemoveImpl(final ViewHolder holder) {
    final View view = holder.itemView;
    final ViewPropertyAnimatorCompat animation = ViewCompat.animate(view);
    mRemoveAnimations.add(holder);//w  w  w . jav a2  s. co m
    animation.setDuration(getRemoveDuration()).translationX(view.getWidth())
            .setListener(new VpaListenerAdapter() {
                @Override
                public void onAnimationStart(View view) {
                    dispatchRemoveStarting(holder);
                }

                @Override
                public void onAnimationEnd(View view) {
                    animation.setListener(null);
                    //ViewCompat.setAlpha(view, 1);
                    ViewCompat.setTranslationX(view, 0);
                    dispatchRemoveFinished(holder);
                    mRemoveAnimations.remove(holder);
                    dispatchFinishedWhenDone();
                }
            }).start();
}

From source file:com.example.lulu.recyclerviewdemo.MyItemAnimator.java

private void animateRemoveImpl(final ViewHolder holder) {
    //?/*from  ww w  . j a  v a2s  .  c o m*/
    final View view = holder.itemView;
    final ViewPropertyAnimatorCompat animation = ViewCompat.animate(view);
    mRemoveAnimations.add(holder);
    animation.setDuration(getRemoveDuration()).translationX(view.getWidth())
            .setListener(new VpaListenerAdapter() {
                @Override
                public void onAnimationStart(View view) {
                    dispatchRemoveStarting(holder);
                }

                @Override
                public void onAnimationEnd(View view) {
                    animation.setListener(null);
                    ViewCompat.setTranslationX(view, 0);
                    dispatchRemoveFinished(holder);
                    mRemoveAnimations.remove(holder);
                    dispatchFinishedWhenDone();
                }
            }).start();
}