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:com.android.screenspeak.contextmenu.RadialMenuView.java

public RadialMenuView(Context context, RadialMenu menu, boolean useNodeProvider) {
    super(context);

    mRootMenu = menu;//from ww  w  .ja v  a 2s.c  om
    mRootMenu.setLayoutListener(new RadialMenu.MenuLayoutListener() {
        @Override
        public void onLayoutChanged() {
            invalidate();
        }
    });

    mPaint = new Paint();
    mPaint.setAntiAlias(true);

    mHandler = new LongPressHandler(context);
    mHandler.setListener(new LongPressHandler.LongPressListener() {
        @Override
        public void onLongPress() {
            onItemLongPressed(mFocusedItem);
        }
    });

    final SurfaceHolder holder = getHolder();
    holder.setFormat(PixelFormat.TRANSLUCENT);
    holder.addCallback(new SurfaceHolder.Callback() {
        @Override
        public void surfaceCreated(SurfaceHolder holder) {
            mHolder = holder;
        }

        @Override
        public void surfaceDestroyed(SurfaceHolder holder) {
            mHolder = null;
        }

        @Override
        public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
            invalidate();
        }
    });

    final Resources res = context.getResources();
    final ViewConfiguration config = ViewConfiguration.get(context);

    mSingleTapRadiusSq = config.getScaledTouchSlop();

    // Dimensions.
    mInnerRadius = res.getDimensionPixelSize(R.dimen.inner_radius);
    mOuterRadius = res.getDimensionPixelSize(R.dimen.outer_radius);
    mCornerRadius = res.getDimensionPixelSize(R.dimen.corner_radius);
    mExtremeRadius = res.getDimensionPixelSize(R.dimen.extreme_radius);
    mSpacing = res.getDimensionPixelOffset(R.dimen.spacing);
    mTextSize = res.getDimensionPixelSize(R.dimen.text_size);
    mTextShadowRadius = res.getDimensionPixelSize(R.dimen.text_shadow_radius);
    mShadowRadius = res.getDimensionPixelSize(R.dimen.shadow_radius);

    // Colors.
    mOuterFillColor = res.getColor(R.color.outer_fill);
    mTextFillColor = res.getColor(R.color.text_fill);
    mCornerFillColor = res.getColor(R.color.corner_fill);
    mCornerTextFillColor = res.getColor(R.color.corner_text_fill);
    mDotFillColor = res.getColor(R.color.dot_fill);
    mDotStrokeColor = res.getColor(R.color.dot_stroke);
    mSelectionColor = res.getColor(R.color.selection_fill);
    mSelectionTextFillColor = res.getColor(R.color.selection_text_fill);
    mSelectionShadowColor = res.getColor(R.color.selection_shadow);
    mCenterFillColor = res.getColor(R.color.center_fill);
    mCenterTextFillColor = res.getColor(R.color.center_text_fill);
    mTextShadowColor = res.getColor(R.color.text_shadow);

    // Gradient colors.
    final int gradientInnerColor = res.getColor(R.color.gradient_inner);
    final int gradientOuterColor = res.getColor(R.color.gradient_outer);
    final int[] colors = new int[] { gradientInnerColor, gradientOuterColor };
    mGradientBackground = new GradientDrawable(Orientation.TOP_BOTTOM, colors);
    mGradientBackground.setGradientType(GradientDrawable.RADIAL_GRADIENT);
    mGradientBackground.setGradientRadius(mExtremeRadius * 2.0f);

    final int subMenuOverlayColor = res.getColor(R.color.submenu_overlay);

    // Lighting filters generated from colors.
    mSubMenuFilter = new PorterDuffColorFilter(subMenuOverlayColor, PorterDuff.Mode.SCREEN);

    mInnerRadiusSq = (mInnerRadius * mInnerRadius);
    mExtremeRadiusSq = (mExtremeRadius * mExtremeRadius);

    mUseNodeProvider = useNodeProvider;

    if (mUseNodeProvider) {
        // Lazily-constructed node provider helper.
        ViewCompat.setAccessibilityDelegate(this, new RadialMenuHelper(this));
    }

    // Corner shapes only need to be invalidated and cached once.
    initializeCachedShapes();
}

From source file:chinanurse.cn.nurse.list.WaveSwipeRefreshLayout.java

@Override
public boolean onInterceptTouchEvent(@NonNull MotionEvent event) {
    ensureTarget();/* w ww.  ja v  a 2s.  c o  m*/

    if (!isEnabled() || canChildScrollUp() || isRefreshing()) {
        return false;
    }

    final int action = MotionEventCompat.getActionMasked(event);

    switch (action) {
    case MotionEvent.ACTION_DOWN:
        mActivePointerId = MotionEventCompat.getPointerId(event, 0);
        mFirstTouchDownPointY = getMotionEventY(event, mActivePointerId);
        break;

    case MotionEvent.ACTION_MOVE:
        if (mActivePointerId == INVALID_POINTER) {
            return false;
        }

        final float currentY = getMotionEventY(event, mActivePointerId);

        if (currentY == -1) {
            return false;
        }

        if (mFirstTouchDownPointY == -1) {
            mFirstTouchDownPointY = currentY;
        }

        final float yDiff = currentY - mFirstTouchDownPointY;

        // State is changed to drag if over slop
        if (yDiff > ViewConfiguration.get(getContext()).getScaledTouchSlop() && !isRefreshing()) {
            mCircleView.makeProgressTransparent();
            return true;
        }

        break;

    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_CANCEL:
        mActivePointerId = INVALID_POINTER;
        break;
    }

    return false;
}

From source file:com.android.app.MediaPlaybackActivity.java

/**
 * Called when the activity is first created.
 *//*w ww . j  a v  a  2  s  .co m*/
@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);

    setVolumeControlStream(AudioManager.STREAM_MUSIC);

    mAlbumArtWorker = new Worker("album art worker");
    mAlbumArtHandler = new AlbumArtHandler(mAlbumArtWorker.getLooper());

    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.audio_player);

    mCurrentTime = (TextView) findViewById(R.id.currenttime);
    mTotalTime = (TextView) findViewById(R.id.totaltime);
    mProgress = (SeekBar) findViewById(R.id.seekbar_playback);
    mAlbum = (ImageView) findViewById(R.id.album);
    mArtistName = (TextView) findViewById(R.id.artistname);
    mAlbumName = (TextView) findViewById(R.id.albumname);
    mTrackName = (TextView) findViewById(R.id.trackname);

    View v = (View) mArtistName.getParent();
    v.setOnTouchListener(this);
    v.setOnLongClickListener(this);

    v = (View) mAlbumName.getParent();
    v.setOnTouchListener(this);
    v.setOnLongClickListener(this);

    v = (View) mTrackName.getParent();
    v.setOnTouchListener(this);
    v.setOnLongClickListener(this);

    mPrevButton = (RepeatingImageButton) findViewById(R.id.prev);
    mPrevButton.setOnClickListener(mPrevListener);
    mPrevButton.setRepeatListener(mRewListener, 260);
    mPauseButton = (ImageButton) findViewById(R.id.pause);
    mPauseButton.requestFocus();
    mPauseButton.setOnClickListener(mPauseListener);
    mNextButton = (RepeatingImageButton) findViewById(R.id.next);
    mNextButton.setOnClickListener(mNextListener);
    mNextButton.setRepeatListener(mFfwdListener, 260);
    seekmethod = 1;

    mDeviceHasDpad = (getResources().getConfiguration().navigation == Configuration.NAVIGATION_DPAD);

    mQueueButton = (ImageButton) findViewById(R.id.curplaylist);
    mQueueButton.setOnClickListener(mQueueListener);
    mShuffleButton = ((ImageButton) findViewById(R.id.shuffle));
    mShuffleButton.setOnClickListener(mShuffleListener);
    mRepeatButton = ((ImageView) findViewById(R.id.repeat));
    mRepeatButton.setOnClickListener(mRepeatListener);

    mIndicator_left = (ImageView) findViewById(R.id.indicator_circle_1);
    mIndicator_right = (ImageView) findViewById(R.id.indicator_circle_2);
    mIndicator_right.setEnabled(false);
    mTitleBack = (ImageButton) findViewById(R.id.title_back);
    mTitleBack.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            onBackPressed();
        }
    });
    mTitlePlaylist = (ImageButton) findViewById(R.id.title_playlist);
    mTitlePlaylist.setOnClickListener(mQueueListener);
    mTitlePlaying = (TextView) findViewById(R.id.title_playing);

    playlistPlayback = (ImageView) findViewById(R.id.playlist_iv_playback);
    playlistPlayback.setOnClickListener(mShowPlaylistListener);

    if (mProgress instanceof SeekBar) {
        SeekBar seeker = (SeekBar) mProgress;
        seeker.setOnSeekBarChangeListener(mSeekListener);
    }
    mProgress.setMax(1000);

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

    mViewPager = (ViewPager) findViewById(R.id.vp_play_container);
    initViewPagerContent();
    //        mViewPager.setPageTransformer(true, new PlayPageTransformer());
    //        mPagerIndicator.create(mViewPagerContent.size());
    mViewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

        }

        @Override
        public void onPageSelected(int position) {
            if (position == 0) {
                mIndicator_left.setEnabled(true);
                mIndicator_right.setEnabled(false);
            } else if (position == 1) {
                mIndicator_left.setEnabled(false);
                mIndicator_right.setEnabled(true);
            }
        }

        @Override
        public void onPageScrollStateChanged(int state) {

        }
    });
    mViewPager.setAdapter(mPagerAdapter);
}

From source file:com.daiv.android.twitter.ui.compose.Compose.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    overridePendingTransition(R.anim.fade_in, R.anim.fade_out);

    countHandler = new Handler();

    settings = AppSettings.getInstance(this);
    context = this;
    sharedPrefs = context.getSharedPreferences("com.daiv.android.twitter_world_preferences",
            Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE);

    try {/*from   w  w  w. j a  va 2s .c o  m*/
        ViewConfiguration config = ViewConfiguration.get(this);
        Field menuKeyField = ViewConfiguration.class.getDeclaredField("sHasPermanentMenuKey");
        if (menuKeyField != null) {
            menuKeyField.setAccessible(true);
            menuKeyField.setBoolean(config, false);
        }
    } catch (Exception ex) {
        // Ignore
    }

    int currentOrientation = getResources().getConfiguration().orientation;
    if (currentOrientation == Configuration.ORIENTATION_LANDSCAPE) {
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);
    } else {
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT);
    }

    currentAccount = sharedPrefs.getInt("current_account", 1);

    buildGoogleApiClient();

    Utils.setUpPopupTheme(context, settings);
    setUpWindow();
    setUpLayout();
    setUpActionBar();
    setUpReplyText();

    if (reply.getText().toString().contains(" RT @") || reply.getText().toString().contains("/status/")) {
        reply.setSelection(0);
    }

    if (getIntent().getBooleanExtra("start_attach", false)) {
        attachButton.performClick();
        //overflow.performClick();
    }

    if (notiId != 0) {
        HoloTextView replyTo = (HoloTextView) findViewById(R.id.reply_to);
        replyTo.setText(replyText);
        TextUtils.linkifyText(context, replyTo, null, true, "", true);
        replyTo.setVisibility(View.VISIBLE);
    }

    new Handler().postDelayed(new Runnable() {
        @Override
        public void run() {
            String text = reply.getText().toString();

            try {
                if (!android.text.TextUtils.isEmpty(text)
                        && !(text.startsWith(" RT @") || text.contains("/status/"))) {
                    //text = text.replaceAll("  ", " ");

                    reply.setText(text);
                    reply.setSelection(text.length());

                    if (!text.endsWith(" ")) {
                        reply.append(" ");
                    }
                }
            } catch (Exception e) {

            }
        }
    }, 250);
}

From source file:com.daskiworks.ghwatch.ActivityBase.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // hack to show menu overlay button in Action Bar even for phone with hardware menu buttons.
    try {//  w  w  w  .  j  av a  2s.  co m
        ViewConfiguration config = ViewConfiguration.get(this);
        Field menuKeyField = ViewConfiguration.class.getDeclaredField("sHasPermanentMenuKey");
        if (menuKeyField != null) {
            menuKeyField.setAccessible(true);
            menuKeyField.setBoolean(config, false);
        }
    } catch (Exception ex) {
        // Ignore
    }

}

From source file:bhav.swipeaction.SwipeAction.java

/**
 * Constructor that is called when inflating SwipeRefreshLayout from XML.
 *
 * @param context/*from ww  w.jav  a 2s .  co  m*/
 * @param attrs
 */
public SwipeAction(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);
    initStyle(context, attrs);
    //        final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SwipeAction);
    ////        setEnabled(a.getBoolean(0, true));
    //        icon = a.getDrawable(R.styleable.SwipeAction_src);
    ////        if(icon == null) {
    ////            icon = getResources().getDrawable(android.R.drawable.ic_delete);
    ////        }
    //        a.recycle();
    final DisplayMetrics metrics = getResources().getDisplayMetrics();
    //todo : changeable size v.
    mCircleWidth = (int) (CIRCLE_DIAMETER * metrics.density);
    mCircleHeight = (int) (CIRCLE_DIAMETER * metrics.density);
    createProgressView();
    ViewCompat.setChildrenDrawingOrderEnabled(this, true);
    // the absolute offset has to take into account that the circle starts at an offset
    mSpinnerFinalOffset = DEFAULT_CIRCLE_TARGET * metrics.density;
    mTotalDragDistance = mSpinnerFinalOffset;
    mNestedScrollingParentHelper = new NestedScrollingParentHelper(this);
    mNestedScrollingChildHelper = new NestedScrollingChildHelper(this);
    setNestedScrollingEnabled(true);
}

From source file:com.dgmltn.ranger.internal.AbsRangeBar.java

public AbsRangeBar(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);

    mUiThreadId = Thread.currentThread().getId();
    mScaledTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();

    mFirstPinView = new PinView(context);
    mFirstPinView.setName("mFirstPinView");
    mSecondPinView = new PinView(context);
    mSecondPinView.setName("mSecondPinView");

    TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.AbsRangeBar);
    initialize(ta);/*from ww  w  . ja  v  a2  s. c om*/
}

From source file:bk.vinhdo.taxiads.utils.view.SlidingLayer.java

private void init() {
    setWillNotDraw(false);/*from   ww  w  .  j  a va  2  s  . c  om*/
    setDescendantFocusability(FOCUS_AFTER_DESCENDANTS);
    setFocusable(true);
    final Context context = getContext();
    mScroller = new Scroller(context, sMenuInterpolator);
    final ViewConfiguration configuration = ViewConfiguration.get(context);
    mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration);
    mMinimumVelocity = configuration.getScaledMinimumFlingVelocity();
    mMaximumVelocity = configuration.getScaledMaximumFlingVelocity();

    final float density = context.getResources().getDisplayMetrics().density;
    mFlingDistance = (int) (MIN_DISTANCE_FOR_FLING * density);
}

From source file:cn.org.eshow.framwork.view.slidingmenu.CustomViewAbove.java

/**
 * Inits the custom view above./*from  w  w w .  j  av  a 2  s .  c om*/
 */
void initCustomViewAbove() {
    setWillNotDraw(false);
    setDescendantFocusability(FOCUS_AFTER_DESCENDANTS);
    setFocusable(true);
    final Context context = getContext();
    mScroller = new Scroller(context, sInterpolator);
    final ViewConfiguration configuration = ViewConfiguration.get(context);
    mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration);
    mMinimumVelocity = configuration.getScaledMinimumFlingVelocity();
    mMaximumVelocity = configuration.getScaledMaximumFlingVelocity();
    setInternalPageChangeListener(new SimpleOnPageChangeListener() {
        public void onPageSelected(int position) {
            if (mViewBehind != null) {
                switch (position) {
                case 0:
                case 2:
                    mViewBehind.setChildrenEnabled(true);
                    break;
                case 1:
                    mViewBehind.setChildrenEnabled(false);
                    break;
                }
            }
        }
    });

    final float density = context.getResources().getDisplayMetrics().density;
    mFlingDistance = (int) (MIN_DISTANCE_FOR_FLING * density);
}

From source file:com.android.ex.widget.StaggeredGridView.java

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

    final ViewConfiguration vc = ViewConfiguration.get(context);
    mTouchSlop = vc.getScaledTouchSlop();
    mMaximumVelocity = vc.getScaledMaximumFlingVelocity();
    mFlingVelocity = vc.getScaledMinimumFlingVelocity();
    mScroller = ScrollerCompat.from(context);

    mTopEdge = new EdgeEffectCompat(context);
    mBottomEdge = new EdgeEffectCompat(context);
    setWillNotDraw(false);/*from ww  w  .  j  a  v a  2  s .  co m*/
    setClipToPadding(false);
}