Example usage for android.view ViewConfiguration get

List of usage examples for android.view ViewConfiguration get

Introduction

In this page you can find the example usage for android.view ViewConfiguration get.

Prototype

public static ViewConfiguration get(Context context) 

Source Link

Document

Returns a configuration for the specified context.

Usage

From source file:cf.obsessiveorange.rhcareerfairlayout.ui.fragments.VPParentFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_parent, container, false);

    final MainActivity parentActivity = MainActivity.instance;
    mPagerAdapter = new NavigationAdapter(getChildFragmentManager());
    mPager = (ViewPager) view.findViewById(R.id.pager);
    ViewPager.SimpleOnPageChangeListener pageChangeListener = new ViewPager.SimpleOnPageChangeListener() {
        @Override/*from   w w w  .  ja va  2  s  .co  m*/
        public void onPageSelected(int position) {
            Log.d(RHCareerFairLayout.RH_CFL, "Selected page:" + position);

            if (getCurrentFragment() != null) {
                // If position is layout fragment, and scale is at base, show the toolbar. Otherwise, hide it.
                if (position == 0) {
                    if (((VPLayoutContainerFragment) getCurrentFragment()).getLayoutView()
                            .getScaleFactor() == 1.0) {
                        showToolbar();
                    } else {
                        hideToolbar();
                    }
                }

                // Push to the backStack.
                parentActivity.pushToBackStack(mLastPage);
            }

            // Send tracking info
            RHCareerFairLayoutApplication application = (RHCareerFairLayoutApplication) parentActivity
                    .getApplication();
            Tracker tracker = application.getDefaultTracker();
            Log.i(RHCareerFairLayout.RH_CFL,
                    "Setting screen name: " + RHCareerFairLayout.tabs.get(position).getTitle());
            tracker.setScreenName(RHCareerFairLayout.tabs.get(position).getTitle());
            tracker.send(new HitBuilders.ScreenViewBuilder().build());

            // Set trailing marker.
            mLastPage = position;
        }
    };

    // Configure adapter.
    mPager.addOnPageChangeListener(pageChangeListener);
    mPager.setOffscreenPageLimit(2);
    mPager.setAdapter(mPagerAdapter);

    // Trigger first change, so that backStack and tracker code fires the first time.
    pageChangeListener.onPageSelected(0);

    // Create sliding tab layout for viewpager
    SlidingTabLayout slidingTabLayout = (SlidingTabLayout) view.findViewById(R.id.sliding_tabs);
    slidingTabLayout.setCustomTabView(R.layout.tab_indicator, android.R.id.text1);
    slidingTabLayout.setSelectedIndicatorColors(getResources().getColor(R.color.primaryLight));
    slidingTabLayout.setDistributeEvenly(true);
    slidingTabLayout.setViewPager(mPager);

    // Set touch boundary slopes to differentiate between vertical and horizontal swipes.
    // Set scrolling listeners.
    ViewConfiguration vc = ViewConfiguration.get(parentActivity);
    mSlop = vc.getScaledTouchSlop();
    mInterceptionLayout = (TouchInterceptionFrameLayout) view.findViewById(R.id.container);
    mInterceptionLayout.setScrollInterceptionListener(mInterceptionListener);

    return view;
}

From source file:biz.laenger.android.vpbs.ViewPagerBottomSheetBehavior.java

/**
 * Default constructor for inflating ViewPagerBottomSheetBehaviors from layout.
 *
 * @param context The {@link Context}.//www  .ja  va 2s .c o m
 * @param attrs   The {@link AttributeSet}.
 */
public ViewPagerBottomSheetBehavior(Context context, AttributeSet attrs) {
    super(context, attrs);
    scrollableViews = new ArrayList<>();
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.BottomSheetBehavior_Layout);
    TypedValue value = a.peekValue(R.styleable.BottomSheetBehavior_Layout_behavior_peekHeight);
    if (value != null && value.data == PEEK_HEIGHT_AUTO) {
        setPeekHeight(value.data);
    } else {
        setPeekHeight(a.getDimensionPixelSize(R.styleable.BottomSheetBehavior_Layout_behavior_peekHeight,
                PEEK_HEIGHT_AUTO));
    }
    setHideable(a.getBoolean(R.styleable.BottomSheetBehavior_Layout_behavior_hideable, false));
    setSkipCollapsed(a.getBoolean(R.styleable.BottomSheetBehavior_Layout_behavior_skipCollapsed, false));
    a.recycle();
    ViewConfiguration configuration = ViewConfiguration.get(context);
    mMaximumVelocity = configuration.getScaledMaximumFlingVelocity();
}

From source file:com.doomy.library.DiscreteSeekBar.java

public DiscreteSeekBar(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    setFocusable(true);//from w ww  . j  a v  a  2  s .  c  o m
    setWillNotDraw(false);

    mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();
    float density = context.getResources().getDisplayMetrics().density;
    mTrackHeight = (int) (1 * density);
    mScrubberHeight = (int) (4 * density);
    int thumbSize = (int) (density * ThumbDrawable.DEFAULT_SIZE_DP);

    //Extra pixels for a touch area of 48dp
    int touchBounds = (int) (density * 32);
    mAddedTouchBounds = (touchBounds - thumbSize) / 2;

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.DiscreteSeekBar,
            R.attr.discreteSeekBarStyle, defStyle);

    int max = 100;
    int min = 0;
    int value = 0;
    mMirrorForRtl = a.getBoolean(R.styleable.DiscreteSeekBar_dsb_mirrorForRtl, mMirrorForRtl);
    mAllowTrackClick = a.getBoolean(R.styleable.DiscreteSeekBar_dsb_allowTrackClickToDrag, mAllowTrackClick);

    int indexMax = R.styleable.DiscreteSeekBar_dsb_max;
    int indexMin = R.styleable.DiscreteSeekBar_dsb_min;
    int indexValue = R.styleable.DiscreteSeekBar_dsb_value;
    final TypedValue out = new TypedValue();
    //Not sure why, but we wanted to be able to use dimensions here...
    if (a.getValue(indexMax, out)) {
        if (out.type == TypedValue.TYPE_DIMENSION) {
            max = a.getDimensionPixelSize(indexMax, max);
        } else {
            max = a.getInteger(indexMax, max);
        }
    }
    if (a.getValue(indexMin, out)) {
        if (out.type == TypedValue.TYPE_DIMENSION) {
            min = a.getDimensionPixelSize(indexMin, min);
        } else {
            min = a.getInteger(indexMin, min);
        }
    }
    if (a.getValue(indexValue, out)) {
        if (out.type == TypedValue.TYPE_DIMENSION) {
            value = a.getDimensionPixelSize(indexValue, value);
        } else {
            value = a.getInteger(indexValue, value);
        }
    }

    mMin = min;
    mMax = Math.max(min + 1, max);
    mValue = Math.max(min, Math.min(max, value));
    updateKeyboardRange();

    mIndicatorFormatter = a.getString(R.styleable.DiscreteSeekBar_dsb_indicatorFormatter);

    ColorStateList trackColor = a.getColorStateList(R.styleable.DiscreteSeekBar_dsb_trackColor);
    ColorStateList progressColor = a.getColorStateList(R.styleable.DiscreteSeekBar_dsb_progressColor);
    ColorStateList rippleColor = a.getColorStateList(R.styleable.DiscreteSeekBar_dsb_rippleColor);
    boolean editMode = isInEditMode();
    if (editMode && rippleColor == null) {
        rippleColor = new ColorStateList(new int[][] { new int[] {} }, new int[] { Color.DKGRAY });
    }
    if (editMode && trackColor == null) {
        trackColor = new ColorStateList(new int[][] { new int[] {} }, new int[] { Color.GRAY });
    }
    if (editMode && progressColor == null) {
        progressColor = new ColorStateList(new int[][] { new int[] {} }, new int[] { 0xff009688 });
    }
    mRipple = SeekBarCompat.getRipple(rippleColor);
    if (isLollipopOrGreater) {
        SeekBarCompat.setBackground(this, mRipple);
    } else {
        mRipple.setCallback(this);
    }

    TrackRectDrawable shapeDrawable = new TrackRectDrawable(trackColor);
    mTrack = shapeDrawable;
    mTrack.setCallback(this);

    shapeDrawable = new TrackRectDrawable(progressColor);
    mScrubber = shapeDrawable;
    mScrubber.setCallback(this);

    ThumbDrawable thumbDrawable = new ThumbDrawable(progressColor, thumbSize);
    mThumb = thumbDrawable;
    mThumb.setCallback(this);
    mThumb.setBounds(0, 0, mThumb.getIntrinsicWidth(), mThumb.getIntrinsicHeight());

    if (!editMode) {
        mIndicator = new PopupIndicator(context, attrs, defStyle, convertValueToMessage(mMax));
        mIndicator.setListener(mFloaterListener);
    }
    a.recycle();

    setNumericTransformer(new DefaultNumericTransformer());

}

From source file:com.bitants.wally.views.swipeclearlayout.SwipeClearLayout.java

/**
 * Constructor that is called when inflating SwipeRefreshLayout from XML.
 * @param context//from  w  ww .j  a  v a2s  .c om
 * @param attrs
 */
public SwipeClearLayout(Context context, AttributeSet attrs) {
    super(context, attrs);

    touchSlop = ViewConfiguration.get(context).getScaledTouchSlop();

    mediumAnimationDuration = getResources().getInteger(android.R.integer.config_mediumAnimTime);

    setWillNotDraw(false);
    final DisplayMetrics metrics = getResources().getDisplayMetrics();

    circle = generateCircle(context, attrs, metrics);
    progressBar = new ProgressBar(context, attrs);

    decelerateInterpolator = new DecelerateInterpolator(DECELERATE_INTERPOLATION_FACTOR);
    accelerateInterpolator = new AccelerateInterpolator(ACCELERATE_INTERPOLATION_FACTOR);

    final TypedArray a = context.obtainStyledAttributes(attrs, LAYOUT_ATTRS);
    setEnabled(a.getBoolean(0, true));
    initAttrs(context, attrs);
    a.recycle();
}

From source file:org.artoolkit.ar.samples.ARMovie.ARMovieActivity.java

/** Called when the activity is first created. */
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Override/*from  ww  w.j a  va  2 s .  com*/
public void onCreate(Bundle savedInstanceState) {
    Log.i(TAG, "onCreate()");
    super.onCreate(savedInstanceState);

    boolean needActionBar = false;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
            if (!ViewConfiguration.get(this).hasPermanentMenuKey())
                needActionBar = true;
        } else {
            needActionBar = true;
        }
    }
    if (needActionBar) {
        requestWindowFeature(Window.FEATURE_ACTION_BAR);
    } else {
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
    }
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

    //setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); // Force landscape-only.
    updateNativeDisplayParameters();

    //Bundle extras = getIntent().getExtras();
    //String baseFolderPath = extras.getString("baseFolderPath");

    //int markerID = ARToolKit.getInstance().addMarker("multi;"+baseFolderPath +"/marker.dat");

    setContentView(R.layout.main_video);
    mButton = (Button) findViewById(R.id.button_capture);
    mButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            //Toast.makeText(ARCloud.this, "Take picture", Toast.LENGTH_LONG).show();
            LinearLayout linearLayoutResultWrapper = (LinearLayout) findViewById(R.id.result_wrapper);
            if (linearLayoutResultWrapper.getChildCount() > 0) {
                linearLayoutResultWrapper.removeViewAt(0);
                linearLayoutResultWrapper.removeAllViews();
            }

            camSurface.getCamera().takePicture(null, null, mPicture);
            ;
        }
    });

    ARMovieActivity.nativeCreate(this);
}

From source file:SwipeListView.java

/**
 * Init ListView// ww  w  .  j a v  a  2 s  . c  o  m
 *
 * @param attrs AttributeSet
 */
private void init(AttributeSet attrs) {

    int swipeMode = SWIPE_MODE_BOTH;
    boolean swipeOpenOnLongPress = true;
    boolean swipeCloseAllItemsWhenMoveList = true;
    long swipeAnimationTime = 0;
    float swipeOffsetLeft = 0;
    float swipeOffsetRight = 0;
    int swipeDrawableChecked = 0;
    int swipeDrawableUnchecked = 0;

    int swipeActionLeft = SWIPE_ACTION_REVEAL;
    int swipeActionRight = SWIPE_ACTION_REVEAL;

    if (attrs != null) {
        TypedArray styled = getContext().obtainStyledAttributes(attrs, R.styleable.SwipeListView);
        swipeMode = styled.getInt(R.styleable.SwipeListView_swipeMode, SWIPE_MODE_BOTH);
        swipeActionLeft = styled.getInt(R.styleable.SwipeListView_swipeActionLeft, SWIPE_ACTION_REVEAL);
        swipeActionRight = styled.getInt(R.styleable.SwipeListView_swipeActionRight, SWIPE_ACTION_REVEAL);
        swipeOffsetLeft = styled.getDimension(R.styleable.SwipeListView_swipeOffsetLeft, 0);
        swipeOffsetRight = styled.getDimension(R.styleable.SwipeListView_swipeOffsetRight, 0);
        swipeOpenOnLongPress = styled.getBoolean(R.styleable.SwipeListView_swipeOpenOnLongPress, true);
        swipeAnimationTime = styled.getInteger(R.styleable.SwipeListView_swipeAnimationTime, 0);
        swipeCloseAllItemsWhenMoveList = styled
                .getBoolean(R.styleable.SwipeListView_swipeCloseAllItemsWhenMoveList, true);
        swipeDrawableChecked = styled.getResourceId(R.styleable.SwipeListView_swipeDrawableChecked, 0);
        swipeDrawableUnchecked = styled.getResourceId(R.styleable.SwipeListView_swipeDrawableUnchecked, 0);
        swipeFrontView = styled.getResourceId(R.styleable.SwipeListView_swipeFrontView, 0);
        swipeBackView = styled.getResourceId(R.styleable.SwipeListView_swipeBackView, 0);
    }

    if (swipeFrontView == 0 || swipeBackView == 0) {
        swipeFrontView = getContext().getResources().getIdentifier(SWIPE_DEFAULT_FRONT_VIEW, "id",
                getContext().getPackageName());
        swipeBackView = getContext().getResources().getIdentifier(SWIPE_DEFAULT_BACK_VIEW, "id",
                getContext().getPackageName());

        if (swipeFrontView == 0 || swipeBackView == 0) {
            throw new RuntimeException(String.format(
                    "You forgot the attributes swipeFrontView or swipeBackView. You can add this attributes or use '%s' and '%s' identifiers",
                    SWIPE_DEFAULT_FRONT_VIEW, SWIPE_DEFAULT_BACK_VIEW));
        }
    }

    final ViewConfiguration configuration = ViewConfiguration.get(getContext());
    touchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration);
    touchListener = new SwipeListViewTouchListener(this, swipeFrontView, swipeBackView);
    if (swipeAnimationTime > 0) {
        touchListener.setAnimationTime(swipeAnimationTime);
    }
    touchListener.setRightOffset(swipeOffsetRight);
    touchListener.setLeftOffset(swipeOffsetLeft);
    touchListener.setSwipeActionLeft(swipeActionLeft);
    touchListener.setSwipeActionRight(swipeActionRight);
    touchListener.setSwipeMode(swipeMode);
    touchListener.setSwipeClosesAllItemsWhenListMoves(swipeCloseAllItemsWhenMoveList);
    touchListener.setSwipeOpenOnLongPress(swipeOpenOnLongPress);
    touchListener.setSwipeDrawableChecked(swipeDrawableChecked);
    touchListener.setSwipeDrawableUnchecked(swipeDrawableUnchecked);
    setOnTouchListener(touchListener);
    setOnScrollListener(touchListener.makeScrollListener());
}

From source file:com.hippo.widget.BothScrollView.java

private void initBothScrollView(Context context) {
    mScroller = new SmoothOverScroller(context);
    setFocusable(true);//from w w  w  .ja  va  2 s. c  o m
    setDescendantFocusability(FOCUS_AFTER_DESCENDANTS);
    setWillNotDraw(false);
    final ViewConfiguration configuration = ViewConfiguration.get(context);
    mTouchSlop = configuration.getScaledTouchSlop();
    mMinimumVelocity = configuration.getScaledMinimumFlingVelocity();
    mMaximumVelocity = configuration.getScaledMaximumFlingVelocity();
    mOverscrollDistance = configuration.getScaledOverscrollDistance();
    mOverflingDistance = configuration.getScaledOverflingDistance();
}

From source file:com.gome.haoyuangong.views.SwipeRefreshLayout.java

/**
 * Constructor that is called when inflating SwipeRefreshLayout from XML.
 * /* w w  w  .  ja  v  a  2  s  .c  om*/
 * @param context
 * @param attrs
 */
public SwipeRefreshLayout(Context context, AttributeSet attrs) {
    super(context, attrs);

    mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();

    mMediumAnimationDuration = getResources().getInteger(android.R.integer.config_mediumAnimTime);

    setWillNotDraw(false);
    mDecelerateInterpolator = new DecelerateInterpolator(DECELERATE_INTERPOLATION_FACTOR);
    mAccelerateInterpolator = new AccelerateInterpolator(ACCELERATE_INTERPOLATION_FACTOR);

    final TypedArray a = context.obtainStyledAttributes(attrs, LAYOUT_ATTRS);
    setEnabled(a.getBoolean(0, true));
    a.recycle();

    animation = new RotateAnimation(0, -180, RotateAnimation.RELATIVE_TO_SELF, 0.5f,
            RotateAnimation.RELATIVE_TO_SELF, 0.5f);
    animation.setInterpolator(new LinearInterpolator());
    animation.setDuration(250);
    animation.setFillAfter(true);

    reverseAnimation = new RotateAnimation(-180, 0, RotateAnimation.RELATIVE_TO_SELF, 0.5f,
            RotateAnimation.RELATIVE_TO_SELF, 0.5f);
    reverseAnimation.setInterpolator(new LinearInterpolator());
    reverseAnimation.setDuration(200);
    reverseAnimation.setFillAfter(true);

    state = DONE;
    headView = (LinearLayout) LayoutInflater.from(context).inflate(R.layout.list_head, null);
    arrowImageView = (ImageView) headView.findViewById(R.id.head_arrowImageView);
    //      arrowImageView.setMinimumWidth(70);
    //      arrowImageView.setMinimumHeight(50);
    progressBar = (ProgressBar) headView.findViewById(R.id.head_progressBar);
    tipsTextview = (TextView) headView.findViewById(R.id.head_tipsTextView);
    lastUpdatedTextView = (TextView) headView.findViewById(R.id.head_lastUpdatedTextView);
    measureView(headView);
    mHeaderHeight = headView.getMeasuredHeight();
    headView.setPadding(0, -mHeaderHeight, 0, 0);
    addView(headView);

}

From source file:com.custom.music.MusicBrowserActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Log.i(TAG, ">>> onCreate", Log.APP);
    setContentView(R.layout.main);/*ww w. j  a v  a 2 s  . co m*/
    setVolumeControlStream(AudioManager.STREAM_MUSIC);
    mToken = MusicUtils.bindToService(this, this);
    mHasMenukey = ViewConfiguration.get(this).hasPermanentMenuKey();
    mActivityManager = new LocalActivityManager(this, false);
    mActivityManager.dispatchCreate(savedInstanceState);

    mTabHost = getTabHost();
    initTab();
    mCurrentTab = MusicUtils.getIntPref(this, SAVE_TAB, ARTIST_INDEX);
    Log.i(TAG, "onCreate mCurrentTab: " + mCurrentTab, Log.APP);
    if ((mCurrentTab < 0) || (mCurrentTab >= mTabCount)) {
        mCurrentTab = ARTIST_INDEX;
    }
    /// M: reset the defalt tab value
    if (mCurrentTab == ARTIST_INDEX) {
        mTabHost.setCurrentTab(ALBUM_INDEX);
    }
    mTabHost.setOnTabChangedListener(this);

    initPager();
    mViewPager = (ViewPager) findViewById(R.id.viewpage);
    mViewPager.setAdapter(new MusicPagerAdapter());
    mViewPager.setOnPageChangeListener(this);

    //add by zjw
    categories = (TextView) findViewById(R.id.categorisetab);
    categories.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            showPupopMenu(categories);
        }
    });

    IntentFilter f = new IntentFilter();
    f.addAction(MusicUtils.SDCARD_STATUS_UPDATE);
    registerReceiver(mSdcardstatustListener, f);

    createFakeMenu();

    /// M: Init search button click listener in nowplaying.
    //        initSearchButton();

    Log.i(TAG, "onCreate >>>", Log.APP);
}

From source file:com.example.anumbrella.viewpager.CirclePagerIndicator.java

public CirclePagerIndicator(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    ////w w  w .  ja v  a 2  s .c  o m
    if (isInEditMode()) {
        return;
    }

    //??
    final Resources res = getResources();

    //
    //?

    //??
    final int defaultPageColor = res.getColor(R.color.default_circle_indicator_page_color);
    //
    final int defaultFillColor = res.getColor(R.color.default_circle_indicator_fill_color);
    //?
    final int defaultOrientation = res.getInteger(R.integer.default_circle_indicator_orientation);
    //
    final int defaultStrokeColor = res.getColor(R.color.default_circle_indicator_stroke_color);
    //
    final float defaultStrokeWidth = res.getDimension(R.dimen.default_circle_indicator_stroke_width);
    //??
    final float defaultRadius = res.getDimension(R.dimen.default_circle_indicator_radius);
    //??
    final boolean defaultCentered = res.getBoolean(R.bool.default_circle_indicator_centered);
    //?(?())
    final boolean defaultSnap = res.getBoolean(R.bool.default_circle_indicator_snap);

    //xml
    TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.CirclePagerIndicator, defStyle, 0);

    mCentered = array.getBoolean(R.styleable.CirclePagerIndicator_centered, defaultCentered);
    mOrientation = array.getInteger(R.styleable.CirclePagerIndicator_android_orientation, defaultOrientation);
    //
    mPaintPageFill.setStyle(Paint.Style.FILL);
    //
    mPaintPageFill.setColor(array.getColor(R.styleable.CirclePagerIndicator_pageColor, defaultPageColor));
    //
    mPaintFill.setStyle(Paint.Style.FILL);
    //
    mPaintFill.setColor(array.getColor(R.styleable.CirclePagerIndicator_fillColor, defaultFillColor));
    //
    mPaintStroke.setColor(array.getColor(R.styleable.CirclePagerIndicator_strokeColor, defaultStrokeColor));
    //(??)
    mPaintStroke.setStyle(Paint.Style.STROKE);
    //
    mPaintStroke.setStrokeWidth(
            array.getDimension(R.styleable.CirclePagerIndicator_strokeWidth, defaultStrokeWidth));
    //???
    mRadius = array.getDimension(R.styleable.CirclePagerIndicator_radius, defaultRadius);
    //?
    mSnap = array.getBoolean(R.styleable.CirclePagerIndicator_snap, defaultSnap);
    Drawable background = array.getDrawable(R.styleable.CirclePagerIndicator_android_background);
    if (background != null) {
        setBackgroundDrawable(background);
    }
    array.recycle();
    final ViewConfiguration configuration = ViewConfiguration.get(context);
    mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration);

}