List of usage examples for android.view View setOnTouchListener
public void setOnTouchListener(OnTouchListener l)
From source file:org.xbmc.kore.ui.RemoteFragment.java
private void setupRepeatButton(View button, final ApiMethod<String> action) { button.setOnTouchListener(new RepeatListener(UIUtils.initialButtonRepeatInterval, UIUtils.buttonRepeatInterval, new View.OnClickListener() { @Override//w w w . j av a2 s . c om public void onClick(View v) { action.execute(hostManager.getConnection(), defaultActionCallback, callbackHandler); } }, buttonInAnim, buttonOutAnim, getActivity().getApplicationContext())); }
From source file:com.ape.emoji.keyboard.emoji.EmojiKeyboard.java
@Override protected View createView() { final View emojiPagerView = LayoutInflater.from(activity).inflate(R.layout.emoji_smiles_pager, null); final ViewPager emojiPager = (ViewPager) emojiPagerView.findViewById(R.id.emoji_pager); final PagerSlidingTabStrip emojiPagerIndicator = (PagerSlidingTabStrip) emojiPagerView .findViewById(R.id.emoji_pager_indicator); View backspace = emojiPagerView.findViewById(R.id.backspace); final View indicatorContainer = emojiPagerView.findViewById(R.id.indicator_container); emojiPagerIndicator.setIndicatorHeight(Screen.dp(activity.getApplicationContext(), 2)); emojiPagerIndicator.setDividerColor(0x00000000); emojiPagerIndicator.setUnderlineHeight(0); emojiPagerIndicator.setTabLayoutParams(new LinearLayout.LayoutParams( Screen.dp(activity.getApplicationContext(), 48), Screen.dp(activity.getApplicationContext(), 48))); backspace.setOnTouchListener(new RepeatListener(500, 100, new OnClickListener() { @Override// ww w .j a v a 2 s . co m public void onClick(View v) { onBackspaceClick(v); } })); mEmojisAdapter = new SmilePagerAdapter(this); mEmojisAdapter.setTabs(emojiPagerIndicator); emojiPager.setAdapter(mEmojisAdapter); emojiPagerIndicator.setViewPager(emojiPager); //emojiPagerIndicator.setLayoutParams(new RelativeLayout.LayoutParams(Screen.dp(58 * mEmojisAdapter.getCount()), Screen.dp(48))); // emojiPager.postDelayed(new Runnable() { // @Override // public void run() { // emojiPager.setAlpha(0f); // emojiPagerIndicator.setAlpha(0f); // animateView(emojiPager); // animateView(emojiPagerIndicator); // emojiPager.setAdapter(mEmojisAdapter); // emojiPagerIndicator.setViewPager(emojiPager); // } // }, BINDING_DELAY); if (SmilesPack.getRecent(activity.getApplicationContext()).size() == 0) { emojiPager.setCurrentItem(1); } return emojiPagerView; }
From source file:de.Maxr1998.xposed.maxlock.ui.LockFragment.java
@SuppressWarnings("deprecation") private void setupKnockCodeLayout() { final View container = rootView.findViewById(R.id.container); LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) container.getLayoutParams(); params.setMargins(0, 0, 0, 0);// w w w. j a v a2 s .com container.setLayoutParams(params); container.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent e) { if (e.getActionMasked() == MotionEvent.ACTION_DOWN) { mInputText.append("\u2022"); // Center values int[] loc = new int[2]; container.getLocationOnScreen(loc); int viewCenterX = loc[0] + container.getWidth() / 2; int viewCenterY = loc[1] + container.getHeight() / 2; // Track touch positions knockCodeX.add(e.getRawX()); knockCodeY.add(e.getRawY()); if (knockCodeX.size() != knockCodeY.size()) { throw new RuntimeException("The amount of the X and Y coordinates doesn't match!"); } // Calculate center float centerX; float differenceX = Collections.max(knockCodeX) - Collections.min(knockCodeX); if (differenceX > 50) { centerX = Collections.min(knockCodeX) + differenceX / 2; } else centerX = viewCenterX; float centerY; float differenceY = Collections.max(knockCodeY) - Collections.min(knockCodeY); if (differenceY > 50) { centerY = Collections.min(knockCodeY) + differenceY / 2; } else centerY = viewCenterY; // Calculate key key.setLength(0); for (int i = 0; i < knockCodeX.size(); i++) { float x = knockCodeX.get(i), y = knockCodeY.get(i); if (x < centerX && y < centerY) key.append("1"); else if (x > centerX && y < centerY) key.append("2"); else if (x < centerX && y > centerY) key.append("3"); else if (x > centerX && y > centerY) key.append("4"); } checkInput(); return true; } return false; } }); divider = new View(getActivity()); divider.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, Math.round(getResources().getDisplayMetrics().density))); divider.setBackgroundColor(getResources().getColor(R.color.light_white)); ((ViewGroup) container).addView(divider); if (prefs.getBoolean(Common.INVERT_COLOR, false) && prefs.getBoolean(Common.KC_SHOW_DIVIDERS, true)) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) divider.setBackground(getResources().getDrawable(android.R.color.black)); else divider.setBackgroundDrawable(getResources().getDrawable(android.R.color.black)); } else if (!prefs.getBoolean(Common.KC_SHOW_DIVIDERS, true) || screenWidth > screenHeight) { divider.setVisibility(View.GONE); } }
From source file:demo.camera.library.ui.CameraCaptureActivity.java
private void setUpTouchInterceptor(View interceptorView) { interceptorView.setOnTouchListener(new View.OnTouchListener() { private long lastRecordingRequestedTime = 0; @Override// w w w.j av a 2 s. c o m public boolean onTouch(View v, MotionEvent event) { int action = MotionEventCompat.getActionMasked(event); boolean retVal = false; switch (action) { case (MotionEvent.ACTION_DOWN): Log.d(TAG, "Action was DOWN"); lastRecordingRequestedTime = System.currentTimeMillis(); startRecording(); retVal = true; break; case (MotionEvent.ACTION_UP): Log.d(TAG, "Action was UP"); if (System.currentTimeMillis() - lastRecordingRequestedTime > mCancelMsgDelay) { stopRecording(); } retVal = true; break; default: retVal = false; } return retVal; } }); }
From source file:group.pals.android.lib.ui.filechooser.utils.ui.history.HistoryFragment.java
/** * Loads content view from XML and init controls. * //w ww . j a v a2 s .com * @param inflater * {@link LayoutInflater}. * @param container * {@link ViewGroup}. */ private View initContentView(LayoutInflater inflater, ViewGroup container) { /* * LOADS CONTROLS */ View mainView = inflater.inflate(R.layout.afc_viewgroup_history, container, false); mBtnSearch = mainView.findViewById(R.id.afc_button_search); mViewGroupListView = mainView.findViewById(R.id.afc_viewgroup_listview); mListView = (ExpandableListView) mainView.findViewById(R.id.afc_listview); mSearchView = (AfcSearchView) mainView.findViewById(R.id.afc_afc_search_view); mBtnNext = mainView.findViewById(R.id.afc_button_go_forward); mBtnPrev = mainView.findViewById(R.id.afc_button_go_back); mViewLoading = mainView.findViewById(R.id.afc_view_loading); /* * INITIALIZES CONTROLS */ if (mBtnSearch != null) { mBtnSearch.setOnClickListener(mBtnSearchOnClickListener); mBtnSearch.setVisibility(View.VISIBLE); } mSearchView.setOnQueryTextListener(mSearchViewOnQueryTextListener); mSearchView.setOnStateChangeListener(mSearchViewOnStateChangeListener); mListView.setEmptyView(mainView.findViewById(R.id.afc_empty_view)); mListView.setOnChildClickListener(mListViewOnChildClickListener); mListView.setOnItemLongClickListener(mListViewOnItemLongClickListener); initListViewGestureListener(); mHistoryCursorAdapter = new HistoryCursorAdapter(getActivity()); mListView.setAdapter(mHistoryCursorAdapter); /* * Default states of button navigators in XML are disabled, so we just * set their listeners here. */ for (View v : new View[] { mBtnNext, mBtnPrev }) v.setOnTouchListener(mBtnNextPrevOnTouchListener); return mainView; }
From source file:org.noise_planet.noisecapture.CommentActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_comment); View mainView = findViewById(R.id.mainLayout); if (mainView != null) { mainView.setOnTouchListener(new MainOnTouchListener(this)); }//w w w. ja va2s . co m // Read record activity parameter // Use last record of no parameter provided this.measurementManager = new MeasurementManager(this); Intent intent = getIntent(); // Read the last stored record List<Storage.Record> recordList = measurementManager.getRecords(); if (intent != null && intent.hasExtra(COMMENT_RECORD_ID)) { record = measurementManager.getRecord(intent.getIntExtra(COMMENT_RECORD_ID, -1)); } else { if (!recordList.isEmpty()) { record = recordList.get(0); } else { // Message for starting a record Toast.makeText(getApplicationContext(), getString(R.string.no_results), Toast.LENGTH_LONG).show(); return; } } if (record != null) { View addPhoto = findViewById(R.id.btn_add_photo); addPhoto.setOnClickListener(new OnAddPhotoClickListener(this)); View resultsBtn = findViewById(R.id.resultsBtn); resultsBtn.setOnClickListener(new OnGoToResultPage(this)); View deleteBts = findViewById(R.id.deleteBtn); deleteBts.setOnClickListener(new OnDeleteMeasurement(this)); TextView noisePartyTag = (TextView) findViewById(R.id.edit_noiseparty_tag); noisePartyTag.setEnabled(record.getUploadId().isEmpty()); noisePartyTag.setFilters(new InputFilter[] { new InputFilter.AllCaps(), new InputFilter() { @Override public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) { // [^A-Za-z0-9_] StringBuilder stringBuilder = new StringBuilder(); for (int i = start; i < end; i++) { char c = source.charAt(i); if (Character.isLetterOrDigit(c) || c == '_') { stringBuilder.append(c); } } // keep original if unchanged or return swapped chars boolean modified = (stringBuilder.length() == end - start); return modified ? null : stringBuilder.toString(); } } }); if (record.getNoisePartyTag() == null) { // Read last stored NoiseParty id for (Storage.Record recordItem : recordList) { if (recordItem.getId() != record.getId()) { if (recordItem.getNoisePartyTag() != null) { noisePartyTag.setText(recordItem.getNoisePartyTag()); } break; } } } else { noisePartyTag.setText(record.getNoisePartyTag()); } } initDrawer(record != null ? record.getId() : null); SeekBar seekBar = (SeekBar) findViewById(R.id.pleasantness_slider); // Load stored user comment // Pleasantness and tags are read only if the record has been uploaded Map<String, Storage.TagInfo> tagToIndex = new HashMap<>(Storage.TAGS_INFO.length); for (Storage.TagInfo sysTag : Storage.TAGS_INFO) { tagToIndex.put(sysTag.name, sysTag); } View thumbnail = findViewById(R.id.image_thumbnail); thumbnail.setOnClickListener(new OnImageClickListener(this)); if (record != null) { // Load selected tags for (String sysTag : measurementManager.getTags(record.getId())) { Storage.TagInfo tagInfo = tagToIndex.get(sysTag); if (tagInfo != null) { checkedTags.add(tagInfo.id); } } // Load description if (record.getDescription() != null) { TextView description = (TextView) findViewById(R.id.edit_description); description.setText(record.getDescription()); } Integer pleasantness = record.getPleasantness(); if (pleasantness != null) { seekBar.setProgress((int) (Math.round((pleasantness / 100.0) * seekBar.getMax()))); seekBar.setThumb( seekBar.getResources().getDrawable(R.drawable.seekguess_scrubber_control_normal_holo)); userInputSeekBar.set(true); } else { seekBar.setThumb( seekBar.getResources().getDrawable(R.drawable.seekguess_scrubber_control_disabled_holo)); } photo_uri = record.getPhotoUri(); // User can only update not uploaded data seekBar.setEnabled(record.getUploadId().isEmpty()); } else { // Message for starting a record Toast.makeText(getApplicationContext(), getString(R.string.no_results), Toast.LENGTH_LONG).show(); } thumbnailImageLayoutDoneObserver = new OnThumbnailImageLayoutDoneObserver(this); thumbnail.getViewTreeObserver().addOnGlobalLayoutListener(thumbnailImageLayoutDoneObserver); seekBar.setOnSeekBarChangeListener(new OnSeekBarUserInput(userInputSeekBar)); // Fill tags grid Resources r = getResources(); String[] tags = r.getStringArray(R.array.tags); // Append tags items for (Storage.TagInfo tagInfo : Storage.TAGS_INFO) { ViewGroup tagContainer = (ViewGroup) findViewById(tagInfo.location); if (tagContainer != null && tagInfo.id < tags.length) { addTag(tags[tagInfo.id], tagInfo.id, tagContainer, tagInfo.color != -1 ? r.getColor(tagInfo.color) : -1); } } }
From source file:com.haibison.android.anhuu.utils.ui.history.HistoryFragment.java
/** * Loads content view from XML and init controls. * //from ww w . j a v a2 s . c om * @param inflater * {@link LayoutInflater}. * @param container * {@link ViewGroup}. */ private View initContentView(LayoutInflater inflater, ViewGroup container) { /* * LOADS CONTROLS */ View mainView = inflater.inflate(R.layout.anhuu_f5be488d_viewgroup_history, container, false); mBtnSearch = mainView.findViewById(R.id.anhuu_f5be488d_button_search); mViewGroupListView = mainView.findViewById(R.id.anhuu_f5be488d_viewgroup_listview); mListView = (ExpandableListView) mainView.findViewById(R.id.anhuu_f5be488d_listview); mSearchView = (AnHuuSearchView) mainView.findViewById(R.id.anhuu_f5be488d_search_view); mBtnNext = mainView.findViewById(R.id.anhuu_f5be488d_button_go_forward); mBtnPrev = mainView.findViewById(R.id.anhuu_f5be488d_button_go_back); mViewLoading = mainView.findViewById(R.id.anhuu_f5be488d_view_loading); /* * INITIALIZES CONTROLS */ if (mBtnSearch != null) { mBtnSearch.setOnClickListener(mBtnSearchOnClickListener); mBtnSearch.setVisibility(View.VISIBLE); } mSearchView.setOnQueryTextListener(mSearchViewOnQueryTextListener); mSearchView.setOnStateChangeListener(mSearchViewOnStateChangeListener); mListView.setEmptyView(mainView.findViewById(R.id.anhuu_f5be488d_empty_view)); mListView.setOnChildClickListener(mListViewOnChildClickListener); mListView.setOnItemLongClickListener(mListViewOnItemLongClickListener); initListViewGestureListener(); mHistoryCursorAdapter = new HistoryCursorAdapter(getActivity()); mListView.setAdapter(mHistoryCursorAdapter); /* * Default states of button navigators in XML are disabled, so we just * set their listeners here. */ for (View v : new View[] { mBtnNext, mBtnPrev }) v.setOnTouchListener(mBtnNextPrevOnTouchListener); return mainView; }
From source file:me.xiaopan.psts.PagerSlidingTabStrip.java
private void setTabClickEvent() { ViewGroup tabViewGroup = getTabsLayout(); if (tabViewGroup != null && tabViewGroup.getChildCount() > 0) { //?tab?Pager for (int w = 0; w < tabViewGroup.getChildCount(); w++) { View itemView = tabViewGroup.getChildAt(w); itemView.setTag(w);//ww w.j a v a 2s . c om itemView.setOnClickListener(tabViewClickListener); itemView.setOnTouchListener(tabViewDoubleClickGestureDetector); } } }
From source file:asu.edu.msse.gpeddabu.moviedescriptions.MovieListAdapter.java
@Override public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {/* w ww. j av a 2s . co m*/ final String childText = (String) getChild(groupPosition, childPosition); if (convertView == null) { android.util.Log.d(this.getClass().getSimpleName(), "in getChildView null so creating new view"); LayoutInflater inflater = (LayoutInflater) this.parent .getSystemService(Context.LAYOUT_INFLATER_SERVICE); convertView = inflater.inflate(R.layout.movie_list, null); } TextView txtListChild = (TextView) convertView.findViewById(R.id.movieTitle); convertView.setOnTouchListener(this); convertView.setBackgroundResource(R.color.light_blue); txtListChild.setText(childText); return convertView; }
From source file:ca.frozen.curlingtv.activities.VideoFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_video, container, false); view.setOnTouchListener(new View.OnTouchListener() { @Override/* w ww. j a v a2 s . c om*/ public boolean onTouch(View v, MotionEvent event) { simpleDetector.onTouchEvent(event); scaleDetector.onTouchEvent(event); return true; } }); // configure the name nameView = (TextView) view.findViewById(R.id.video_name); nameView.setText(camera.name); // initialize the message messageView = (TextView) view.findViewById(R.id.video_message); messageView.setTextColor(App.getClr(R.color.good_text)); messageView.setText(R.string.initializing_video); // set the texture listener textureView = (TextureView) view.findViewById(R.id.video_surface); textureView.setSurfaceTextureListener(this); // create the snapshot button snapshotButton = (Button) view.findViewById(R.id.video_snapshot); snapshotButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Bitmap image = textureView.getBitmap(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy_MM_dd_hh_mm_ss"); String name = camera.network + "_" + camera.name.replaceAll("\\s+", "") + "_" + sdf.format(new Date()) + ".jpg"; String url = Utils.saveImage(getActivity().getContentResolver(), image, name, null); MediaActionSound sound = new MediaActionSound(); sound.play(MediaActionSound.SHUTTER_CLICK); } }); // move the snapshot button over to account for the navigation bar if (fullScreen) { float scale = getContext().getResources().getDisplayMetrics().density; int margin = (int) (5 * scale + 0.5f); int extra = Utils.getNavigationBarHeight(getContext(), Configuration.ORIENTATION_LANDSCAPE); ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) snapshotButton.getLayoutParams(); lp.setMargins(margin, margin, margin + extra, margin); } return view; }