List of usage examples for android.view MotionEvent ACTION_UP
int ACTION_UP
To view the source code for android.view MotionEvent ACTION_UP.
Click Source Link
From source file:com.echlabsw.android.drawertab.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Log.i(TAG, "onCreate"); setContentView(R.layout.activity_main); createStubTab();/*from w ww . ja v a 2 s.c om*/ mActionBar = getActionBar(); mHorizontalTabScrollView = (HorizontalScrollView) findViewById(R.id.hscroll_tab_host); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawerListView = (ListView) findViewById(R.id.left_drawer); mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START); mActionBar.setHomeButtonEnabled(true); mActionBar.setDisplayHomeAsUpEnabled(true); mDrawerToggle = createDrawerToggleListener(); mDrawerLayout.setDrawerListener(mDrawerToggle); mTabHost = (TabHost) findViewById(android.R.id.tabhost); mTabHost.setup(); for (String tag : mTabMap.keySet()) { Tab tab = mTabMap.get(tag); TabHost.TabSpec spec = mTabHost.newTabSpec(tag); spec.setContent(this); spec.setIndicator(tab.title); mTabHost.addTab(spec); } mViewPager = (ViewPager) findViewById(R.id.pager); mAdapter = new TabsPagerAdapter(getSupportFragmentManager(), mTabMap.size()); mViewPager.setAdapter(mAdapter); mTabHost.setOnTabChangedListener(this); mViewPager.setOnPageChangeListener(this); if (!TAB_SCROLL_ENABLED) { mHorizontalTabScrollView.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: break; case MotionEvent.ACTION_UP: v.performClick(); break; } return true; } }); } mArrayNavigationDrawerAdapter = new ArrayAdapter<Tab>(this, android.R.layout.simple_list_item_1, mTabMap.values().toArray(new Tab[0])); mDrawerListView.setAdapter(mArrayNavigationDrawerAdapter); mDrawerListView.setOnItemClickListener(this); /* Create AsyncTaskLoader */ getSupportLoaderManager().initLoader(0, null, this); }
From source file:co.taqat.call.CallIncomingActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (getResources().getBoolean(R.bool.orientation_portrait_only)) { setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); }//from ww w . j av a 2s . c o m getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); setContentView(R.layout.call_incoming); name = (TextView) findViewById(R.id.contact_name); number = (TextView) findViewById(R.id.contact_number); contactPicture = (ImageView) findViewById(R.id.contact_picture); // set this flag so this activity will stay in front of the keyguard int flags = WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON; getWindow().addFlags(flags); PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); final int screenWidth = getResources().getDisplayMetrics().widthPixels; acceptUnlock = (LinearLayout) findViewById(R.id.acceptUnlock); declineUnlock = (LinearLayout) findViewById(R.id.declineUnlock); accept = (ImageView) findViewById(R.id.accept); decline = (ImageView) findViewById(R.id.decline); accept.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { decline.setVisibility(View.GONE); acceptUnlock.setVisibility(View.VISIBLE); } }); accept.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View view, MotionEvent motionEvent) { float curX; switch (motionEvent.getAction()) { case MotionEvent.ACTION_DOWN: acceptUnlock.setVisibility(View.VISIBLE); decline.setVisibility(View.GONE); answerX = motionEvent.getX(); break; case MotionEvent.ACTION_MOVE: curX = motionEvent.getX(); if ((answerX - curX) >= 0) view.scrollBy((int) (answerX - curX), view.getScrollY()); answerX = curX; if (curX < screenWidth / 4) { answer(); return true; } break; case MotionEvent.ACTION_UP: view.scrollTo(0, view.getScrollY()); decline.setVisibility(View.VISIBLE); acceptUnlock.setVisibility(View.GONE); break; } return true; } }); decline.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View view, MotionEvent motionEvent) { float curX; switch (motionEvent.getAction()) { case MotionEvent.ACTION_DOWN: declineUnlock.setVisibility(View.VISIBLE); accept.setVisibility(View.GONE); declineX = motionEvent.getX(); break; case MotionEvent.ACTION_MOVE: curX = motionEvent.getX(); view.scrollBy((int) (declineX - curX), view.getScrollY()); declineX = curX; Log.w(curX); if (curX > (screenWidth / 2)) { decline(); return true; } break; case MotionEvent.ACTION_UP: view.scrollTo(0, view.getScrollY()); accept.setVisibility(View.VISIBLE); declineUnlock.setVisibility(View.GONE); break; } return true; } }); decline.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { accept.setVisibility(View.GONE); acceptUnlock.setVisibility(View.VISIBLE); } }); mListener = new LinphoneCoreListenerBase() { @Override public void callState(LinphoneCore lc, LinphoneCall call, State state, String message) { if (call == mCall && State.CallEnd == state) { finish(); } if (state == State.StreamsRunning) { // The following should not be needed except some devices need it (e.g. Galaxy S). LinphoneManager.getLc().enableSpeaker(LinphoneManager.getLc().isSpeakerEnabled()); } } }; super.onCreate(savedInstanceState); instance = this; }
From source file:cn.ieclipse.af.view.AutoPlayView.java
@Override public boolean onTouch(View v, MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: case MotionEvent.ACTION_MOVE: case MotionEvent.ACTION_SCROLL: stop();/* w w w . j av a2s. c om*/ break; case MotionEvent.ACTION_UP: start(); break; } return false; }
From source file:com.tony.casthelloworld.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ActionBar actionBar = getSupportActionBar(); actionBar.setBackgroundDrawable(new ColorDrawable(android.R.color.transparent)); //Current Card Text currentCard = (TextView) findViewById(R.id.currentCard); //Remaining Cards Text remainingCards = (TextView) findViewById(R.id.cardsRemaining); //Start/Reset Game Button startGame = (Button) findViewById(R.id.startGame); startGame.setOnClickListener(new View.OnClickListener() { @Override//from w w w . j av a 2 s . c o m public void onClick(View v) { initializeGame(); updateCast(); } }); //Next Card Button nextCard = (Button) findViewById(R.id.nextCard); nextCard.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { //pop the card off //Update the current card getNextCard(); updateCast(); } }); //Show Card Button showCard = (Button) findViewById(R.id.showCard); showCard.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: //Make the card visible if (deck.peek() != null) { currentCard.setText(prettyPrintCard(deck.peek())); } else { currentCard.setText("No more Cards!"); } return true; case MotionEvent.ACTION_UP: // No longer down if (deck.peek() != null) { currentCard.setText(CARD_HIDDEN_TEXT); } else { currentCard.setText("No more Cards!"); } return true; } return false; } }); // Configure Cast device discovery mMediaRouter = MediaRouter.getInstance(getApplicationContext()); mMediaRouteSelector = new MediaRouteSelector.Builder().addControlCategory( CastMediaControlIntent.categoryForCast(getResources().getString(R.string.app_id))).build(); mMediaRouterCallback = new MyMediaRouterCallback(); }
From source file:android.support.design.widget.HeaderBehavior.java
@Override public boolean onTouchEvent(CoordinatorLayout parent, V child, MotionEvent ev) { if (mTouchSlop < 0) { mTouchSlop = ViewConfiguration.get(parent.getContext()).getScaledTouchSlop(); }// w w w. j a va 2 s. co m switch (MotionEventCompat.getActionMasked(ev)) { case MotionEvent.ACTION_DOWN: { final int x = (int) ev.getX(); final int y = (int) ev.getY(); if (parent.isPointInChildBounds(child, x, y) && canDragView(child)) { mLastMotionY = y; mActivePointerId = ev.getPointerId(0); ensureVelocityTracker(); } else { return false; } break; } case MotionEvent.ACTION_MOVE: { final int activePointerIndex = ev.findPointerIndex(mActivePointerId); if (activePointerIndex == -1) { return false; } final int y = (int) ev.getY(activePointerIndex); int dy = mLastMotionY - y; if (!mIsBeingDragged && Math.abs(dy) > mTouchSlop) { mIsBeingDragged = true; if (dy > 0) { dy -= mTouchSlop; } else { dy += mTouchSlop; } } if (mIsBeingDragged) { mLastMotionY = y; // We're being dragged so scroll the ABL scroll(parent, child, dy, getMaxDragOffset(child), 0); } break; } case MotionEvent.ACTION_UP: if (mVelocityTracker != null) { mVelocityTracker.addMovement(ev); mVelocityTracker.computeCurrentVelocity(1000); float yvel = VelocityTrackerCompat.getYVelocity(mVelocityTracker, mActivePointerId); fling(parent, child, -getScrollRangeForDragFling(child), 0, yvel); } // $FALLTHROUGH case MotionEvent.ACTION_CANCEL: { mIsBeingDragged = false; mActivePointerId = INVALID_POINTER; if (mVelocityTracker != null) { mVelocityTracker.recycle(); mVelocityTracker = null; } break; } } if (mVelocityTracker != null) { mVelocityTracker.addMovement(ev); } return true; }
From source file:com.app.blockydemo.content.bricks.SetVariableBrick.java
@Override public View getView(final Context context, int brickId, BaseAdapter baseAdapter) { if (animationState) { return view; }/*from w w w . jav a 2 s . c om*/ if (view == null) { alphaValue = 255; } view = View.inflate(context, R.layout.brick_set_variable, null); view = getViewWithAlpha(alphaValue); setCheckboxView(R.id.brick_set_variable_checkbox); final Brick brickInstance = this; checkbox.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { checked = isChecked; adapter.handleCheck(brickInstance, isChecked); } }); TextView prototypeText = (TextView) view.findViewById(R.id.brick_set_variable_prototype_view); TextView textField = (TextView) view.findViewById(R.id.brick_set_variable_edit_text); prototypeText.setVisibility(View.GONE); variableFormula.setTextFieldId(R.id.brick_set_variable_edit_text); variableFormula.refreshTextField(view); textField.setVisibility(View.VISIBLE); textField.setOnClickListener(this); Spinner variableSpinner = (Spinner) view.findViewById(R.id.set_variable_spinner); UserVariableAdapter userVariableAdapter = ProjectManager.getInstance().getCurrentProject() .getUserVariables().createUserVariableAdapter(context, sprite); UserVariableAdapterWrapper userVariableAdapterWrapper = new UserVariableAdapterWrapper(context, userVariableAdapter); userVariableAdapterWrapper.setItemLayout(android.R.layout.simple_spinner_item, android.R.id.text1); variableSpinner.setAdapter(userVariableAdapterWrapper); if (!(checkbox.getVisibility() == View.VISIBLE)) { variableSpinner.setClickable(true); variableSpinner.setEnabled(true); } else { variableSpinner.setClickable(false); variableSpinner.setFocusable(false); } setSpinnerSelection(variableSpinner, null); variableSpinner.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View view, MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_UP) { if (((Spinner) view).getSelectedItemPosition() == 0 && ((Spinner) view).getAdapter().getCount() == 1) { NewVariableDialog dialog = new NewVariableDialog((Spinner) view); dialog.addVariableDialogListener(SetVariableBrick.this); dialog.show(((FragmentActivity) view.getContext()).getSupportFragmentManager(), NewVariableDialog.DIALOG_FRAGMENT_TAG); return true; } } return false; } }); variableSpinner.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { if (position == 0 && ((UserVariableAdapterWrapper) parent.getAdapter()).isTouchInDropDownView()) { NewVariableDialog dialog = new NewVariableDialog((Spinner) parent); dialog.addVariableDialogListener(SetVariableBrick.this); dialog.show(((FragmentActivity) view.getContext()).getSupportFragmentManager(), NewVariableDialog.DIALOG_FRAGMENT_TAG); } ((UserVariableAdapterWrapper) parent.getAdapter()).resetIsTouchInDropDownView(); userVariable = (UserVariable) parent.getItemAtPosition(position); adapterView = parent; } @Override public void onNothingSelected(AdapterView<?> arg0) { userVariable = null; } }); return view; }
From source file:android.support.designox.widget.HeaderBehavior.java
@Override public boolean onTouchEvent(CoordinatorLayout parent, V child, MotionEvent ev) { if (mTouchSlop < 0) { mTouchSlop = ViewConfiguration.get(parent.getContext()).getScaledTouchSlop(); }//from w w w.j a v a 2 s . c o m switch (MotionEventCompat.getActionMasked(ev)) { case MotionEvent.ACTION_DOWN: { final int x = (int) ev.getX(); final int y = (int) ev.getY(); if (parent.isPointInChildBounds(child, x, y) && canDragView(child)) { mLastMotionY = y; mActivePointerId = MotionEventCompat.getPointerId(ev, 0); ensureVelocityTracker(); } else { return false; } break; } case MotionEvent.ACTION_MOVE: { final int activePointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId); if (activePointerIndex == -1) { return false; } final int y = (int) MotionEventCompat.getY(ev, activePointerIndex); int dy = mLastMotionY - y; if (!mIsBeingDragged && Math.abs(dy) > mTouchSlop) { mIsBeingDragged = true; if (dy > 0) { dy -= mTouchSlop; } else { dy += mTouchSlop; } } if (mIsBeingDragged) { mLastMotionY = y; // We're being dragged so scroll the ABL scroll(parent, child, dy, getMaxDragOffset(child), 0); } break; } case MotionEvent.ACTION_UP: if (mVelocityTracker != null) { mVelocityTracker.addMovement(ev); mVelocityTracker.computeCurrentVelocity(1000); float yvel = VelocityTrackerCompat.getYVelocity(mVelocityTracker, mActivePointerId); fling(parent, child, -getScrollRangeForDragFling(child), 0, yvel); } // $FALLTHROUGH case MotionEvent.ACTION_CANCEL: { mIsBeingDragged = false; mActivePointerId = INVALID_POINTER; if (mVelocityTracker != null) { mVelocityTracker.recycle(); mVelocityTracker = null; } break; } } if (mVelocityTracker != null) { mVelocityTracker.addMovement(ev); } return true; }
From source file:com.egloos.hyunyi.musicinfo.LinkPopUp.java
@Override public void onCreate(Bundle saveInstanceState) { super.onCreate(saveInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); Bundle b = getIntent().getExtras();/*from w ww.ja v a 2s . c o m*/ SharedPreferences prefs = getSharedPreferences("settings", MODE_PRIVATE); imageOptions = new DisplayImageOptions.Builder().cacheInMemory(false).cacheOnDisk(true) .bitmapConfig(Bitmap.Config.RGB_565).imageScaleType(ImageScaleType.EXACTLY) .showImageOnLoading(R.drawable.connecting_anim).build(); config = new ImageLoaderConfiguration.Builder(getApplicationContext()).diskCacheExtraOptions(480, 320, null) .defaultDisplayImageOptions(imageOptions).build(); if (imageLoader == null) imageLoader = ImageLoader.getInstance(); if (!imageLoader.isInited()) imageLoader.init(config); setContentView(R.layout.link_dialog); imageFrame = (FrameLayout) findViewById(R.id.image_frame); iBottomPanel = (ImageView) findViewById(R.id.bottom_panel); lArtistLink = (RelativeLayout) findViewById(R.id.l_artist_link); bPopUpClose = (ImageView) findViewById(R.id.b_popup_close); bPopUpClose.setOnClickListener(this); tEchoNest = (TextView) findViewById(R.id.t_echo_nest); tAttribution = (TextView) findViewById(R.id.t_attribution); tArtistName = (TextView) findViewById(R.id.t_artist_name); tArtistName.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: //isMove = false; mTouchX = event.getRawX(); mTouchY = event.getRawY(); break; case MotionEvent.ACTION_UP: //Log.i("musicInfo", "ACTION_UP! TouchY:" + mTouchY + " UpY: " + event.getRawY() + " Move: " + (mTouchY - event.getRawY())); int RawY = (int) event.getRawY(); int dY = (int) (mTouchY - event.getRawY()); if (dY > 200) { imageLoader.resume(); //Log.i("musicInfo", "mGridView TOP = " + mGridView.getTop() + " mGridView TransitionY =" + mGridView.getTranslationY()); while (mGridView.getTranslationY() > tArtistName.getHeight()) { //Log.i("musicInfo", "Moving UP! mGridView: " + mGridView.getTranslationY() + " tArtistName: " + tArtistName.getTranslationY()); mGridView.setTranslationY(mGridView.getTranslationY() - 1); tArtistName.setTranslationY(tArtistName.getTranslationY() - 1); } } else if (dY > 5 && dY <= 200 || (dY <= 5 && tArtistName.getTranslationY() < 0)) { while (tArtistName.getTranslationY() < 0) { //Log.i("musicInfo", "Moving DOWN! mGridView: " + mGridView.getTranslationY() + " tArtistName: " + tArtistName.getTranslationY()); mGridView.setTranslationY(mGridView.getTranslationY() + 1); tArtistName.setTranslationY(tArtistName.getTranslationY() + 1); } imageLoader.pause(); } break; case MotionEvent.ACTION_MOVE: //isMove = true; //int top = tArtistName.getTop(); //int bottom = tArtistName.getBottom(); //int left = tArtistName.getLeft(); //int right = tArtistName.getRight(); int x = (int) (event.getRawX() - mTouchX); int y = (int) (event.getRawY() - mTouchY); final int num = 5; if (y > -num && y < num) { //isMove = false; break; } else if (y > 0) { } else { imageFrame.bringChildToFront(mGridView); tArtistName.setTranslationY((float) y); mGridView.setTranslationY((float) (SGVtransition + y)); //Log.i("musicInfo", String.format("T: %d, B: %d", mGridView.getTop(), mGridView.getBottom())); } break; } return true; } }); ArtistImage = (ImageView) findViewById(R.id.artist_image); lLinkList = (LinearLayout) findViewById(R.id.l_link_list); mGridView = (StaggeredGridView) findViewById(R.id.SG_view); SGVtransition = 900; mGridView.setTranslationY(SGVtransition); JSONObject artist_info = null; try { artist_info = new JSONObject(b.getString("artist_info")); Log.i("musicInfo", "LinkPopUp. OnCreate" + artist_info.toString()); displayArtistInfo(artist_info); } catch (JSONException e) { e.printStackTrace(); } if (artist_info != null) jArtists.put(artist_info); if (prefs.getBoolean("SimilarOn", false)) { getSimilarArtistsInfo((String) tArtistName.getText()); ArtistImage.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: //isMove = false; mTouchX = event.getRawX(); mTouchY = event.getRawY(); break; case MotionEvent.ACTION_UP: //Log.i("musicInfo", "ACTION_UP! TouchY:" + mTouchY + " UpY: " + event.getRawY() + " Move: " + (mTouchY - event.getRawY())); int dX = (int) (mTouchX - event.getRawX()); if (dX > 5) { if (jArtists.length() > 1) { imageLoader.stop(); try { if (artistNum == 0) { artistNum = jArtists.length() - 1; } else { artistNum--; } displayArtistInfo(jArtists.getJSONObject(artistNum)); imageLoader.resume(); } catch (JSONException e) { e.printStackTrace(); } } } else if (dX < -5) { if (jArtists.length() > 1) { imageLoader.stop(); try { if (artistNum == jArtists.length() - 1) { artistNum = 0; } else { artistNum++; } displayArtistInfo(jArtists.getJSONObject(artistNum)); imageLoader.resume(); } catch (JSONException e) { e.printStackTrace(); } } } break; case MotionEvent.ACTION_MOVE: break; } return true; } }); } mGridView.setOnScrollListener(new AbsListView.OnScrollListener() { @Override public void onScrollStateChanged(AbsListView view, int scrollState) { //Log.d("musicInfo", "SGV onScrollStateChanged:" + scrollState); } @Override public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { //Log.d("musicInfo", "SGV onScroll firstVisibleItem:" + firstVisibleItem + " visibleItemCount:" + visibleItemCount + " totalItemCount:" + totalItemCount); // our handling if (!mHasRequestedMore) { int lastInScreen = firstVisibleItem + visibleItemCount; if (lastInScreen >= totalItemCount) { //Log.d("musicInfo", "SGV onScroll lastInScreen - so load more"); mHasRequestedMore = true; onLoadMoreItems(); } } } private void onLoadMoreItems() { if (jVideoArray == null) return; final ArrayList<JSONObject> sampleData = generateImageData(jVideoArray); for (JSONObject data : sampleData) { mAdapter.add(data); } // stash all the data in our backing store mData.addAll(sampleData); // notify the adapter that we can update now mAdapter.notifyDataSetChanged(); mHasRequestedMore = false; } }); mGridView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Toast.makeText(getApplicationContext(), "Open the Video...", Toast.LENGTH_SHORT).show(); StaggeredViewAdapter.ViewHolder vh = (StaggeredViewAdapter.ViewHolder) view.getTag(); Intent intent = new Intent(); intent.setAction(Intent.ACTION_VIEW); intent.addCategory(Intent.CATEGORY_BROWSABLE); intent.setData(Uri.parse((String) vh.url)); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent); //finish(); } }); //int[] lArtistLinkPosition = new int[2]; //int[] tArtistNamePosition = new int[2]; //lArtistLink.getLocationOnScreen(lArtistLinkPosition); //tArtistName.getLocationOnScreen(tArtistNamePosition); //Log.d("musicInfo", "SGV transition = " + SGVtransition); }
From source file:com.app.blockydemo.content.bricks.ChangeVariableBrick.java
@Override public View getView(final Context context, int brickId, BaseAdapter baseAdapter) { if (animationState) { return view; }/* w w w .j a va 2s . c o m*/ view = View.inflate(context, R.layout.brick_change_variable_by, null); view = getViewWithAlpha(alphaValue); setCheckboxView(R.id.brick_change_variable_checkbox); final Brick brickInstance = this; checkbox.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { checked = isChecked; adapter.handleCheck(brickInstance, isChecked); } }); TextView prototypeText = (TextView) view.findViewById(R.id.brick_change_variable_prototype_view); TextView textField = (TextView) view.findViewById(R.id.brick_change_variable_edit_text); prototypeText.setVisibility(View.GONE); variableFormula.setTextFieldId(R.id.brick_change_variable_edit_text); variableFormula.refreshTextField(view); textField.setVisibility(View.VISIBLE); textField.setOnClickListener(this); Spinner variableSpinner = (Spinner) view.findViewById(R.id.change_variable_spinner); UserVariableAdapter userVariableAdapter = ProjectManager.getInstance().getCurrentProject() .getUserVariables().createUserVariableAdapter(context, sprite); UserVariableAdapterWrapper userVariableAdapterWrapper = new UserVariableAdapterWrapper(context, userVariableAdapter); userVariableAdapterWrapper.setItemLayout(android.R.layout.simple_spinner_item, android.R.id.text1); variableSpinner.setAdapter(userVariableAdapterWrapper); if (!(checkbox.getVisibility() == View.VISIBLE)) { variableSpinner.setClickable(true); variableSpinner.setEnabled(true); } else { variableSpinner.setClickable(false); variableSpinner.setFocusable(false); } setSpinnerSelection(variableSpinner, null); variableSpinner.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View view, MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_UP) { if (((Spinner) view).getSelectedItemPosition() == 0 && ((Spinner) view).getAdapter().getCount() == 1) { NewVariableDialog dialog = new NewVariableDialog((Spinner) view); dialog.addVariableDialogListener(ChangeVariableBrick.this); dialog.show(((FragmentActivity) view.getContext()).getSupportFragmentManager(), NewVariableDialog.DIALOG_FRAGMENT_TAG); return true; } } return false; } }); variableSpinner.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { if (position == 0 && ((UserVariableAdapterWrapper) parent.getAdapter()).isTouchInDropDownView()) { NewVariableDialog dialog = new NewVariableDialog((Spinner) parent); dialog.addVariableDialogListener(ChangeVariableBrick.this); dialog.show(((FragmentActivity) view.getContext()).getSupportFragmentManager(), NewVariableDialog.DIALOG_FRAGMENT_TAG); } ((UserVariableAdapterWrapper) parent.getAdapter()).resetIsTouchInDropDownView(); userVariable = (UserVariable) parent.getItemAtPosition(position); adapterView = parent; } @Override public void onNothingSelected(AdapterView<?> arg0) { userVariable = null; } }); return view; }
From source file:com.android.yijiang.kzx.widget.betterpickers.widget.UnderlinePageIndicatorPicker.java
public boolean onTouchEvent(MotionEvent ev) { if (super.onTouchEvent(ev)) { return true; }//from ww w .jav a 2 s.co m if ((mViewPager == null) || (mViewPager.getAdapter().getCount() == 0)) { return false; } final int action = ev.getAction() & MotionEventCompat.ACTION_MASK; switch (action) { case MotionEvent.ACTION_DOWN: mActivePointerId = MotionEventCompat.getPointerId(ev, 0); mLastMotionX = ev.getX(); break; case MotionEvent.ACTION_MOVE: { final int activePointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId); final float x = MotionEventCompat.getX(ev, activePointerIndex); final float deltaX = x - mLastMotionX; if (!mIsDragging) { if (Math.abs(deltaX) > mTouchSlop) { mIsDragging = true; } } if (mIsDragging) { mLastMotionX = x; if (mViewPager.isFakeDragging() || mViewPager.beginFakeDrag()) { mViewPager.fakeDragBy(deltaX); } } break; } case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_UP: if (!mIsDragging) { final int count = mViewPager.getAdapter().getCount(); final int width = getWidth(); final float halfWidth = width / 2f; final float sixthWidth = width / 6f; if ((mCurrentPage > 0) && (ev.getX() < halfWidth - sixthWidth)) { if (action != MotionEvent.ACTION_CANCEL) { mViewPager.setCurrentItem(mCurrentPage - 1); } return true; } else if ((mCurrentPage < count - 1) && (ev.getX() > halfWidth + sixthWidth)) { if (action != MotionEvent.ACTION_CANCEL) { mViewPager.setCurrentItem(mCurrentPage + 1); } return true; } } mIsDragging = false; mActivePointerId = INVALID_POINTER; if (mViewPager.isFakeDragging()) { mViewPager.endFakeDrag(); } break; case MotionEventCompat.ACTION_POINTER_DOWN: { final int index = MotionEventCompat.getActionIndex(ev); mLastMotionX = MotionEventCompat.getX(ev, index); mActivePointerId = MotionEventCompat.getPointerId(ev, index); break; } case MotionEventCompat.ACTION_POINTER_UP: final int pointerIndex = MotionEventCompat.getActionIndex(ev); final int pointerId = MotionEventCompat.getPointerId(ev, pointerIndex); if (pointerId == mActivePointerId) { final int newPointerIndex = pointerIndex == 0 ? 1 : 0; mActivePointerId = MotionEventCompat.getPointerId(ev, newPointerIndex); } mLastMotionX = MotionEventCompat.getX(ev, MotionEventCompat.findPointerIndex(ev, mActivePointerId)); break; } return true; }