List of usage examples for android.view ViewGroup setOnTouchListener
public void setOnTouchListener(OnTouchListener l)
From source file:org.telegram.ui.ChannelIntroActivity.java
@Override public View createView(Context context) { actionBar.setBackgroundColor(Theme.ACTION_BAR_CHANNEL_INTRO_COLOR); actionBar.setBackButtonImage(R.drawable.pl_back); actionBar.setItemsBackgroundColor(Theme.ACTION_BAR_CHANNEL_INTRO_SELECTOR_COLOR); actionBar.setCastShadows(false);//from w ww .j a v a 2 s .co m if (!AndroidUtilities.isTablet()) { actionBar.showActionModeTop(); } actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() { @Override public void onItemClick(int id) { if (id == -1) { finishFragment(); } } }); fragmentView = new ViewGroup(context) { @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int width = MeasureSpec.getSize(widthMeasureSpec); int height = MeasureSpec.getSize(heightMeasureSpec); if (width > height) { imageView.measure(MeasureSpec.makeMeasureSpec((int) (width * 0.45f), MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec((int) (height * 0.78f), MeasureSpec.EXACTLY)); whatIsChannelText.measure( MeasureSpec.makeMeasureSpec((int) (width * 0.6f), MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height, MeasureSpec.UNSPECIFIED)); descriptionText.measure(MeasureSpec.makeMeasureSpec((int) (width * 0.5f), MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height, MeasureSpec.UNSPECIFIED)); createChannelText.measure( MeasureSpec.makeMeasureSpec((int) (width * 0.6f), MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(24), MeasureSpec.EXACTLY)); } else { imageView.measure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec((int) (height * 0.44f), MeasureSpec.EXACTLY)); whatIsChannelText.measure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height, MeasureSpec.UNSPECIFIED)); descriptionText.measure(MeasureSpec.makeMeasureSpec((int) (width * 0.9f), MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height, MeasureSpec.UNSPECIFIED)); createChannelText.measure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(24), MeasureSpec.EXACTLY)); } setMeasuredDimension(width, height); } @Override protected void onLayout(boolean changed, int l, int t, int r, int b) { int width = r - l; int height = b - t; if (r > b) { int y = (int) (height * 0.05f); imageView.layout(0, y, imageView.getMeasuredWidth(), y + imageView.getMeasuredHeight()); int x = (int) (width * 0.4f); y = (int) (height * 0.14f); whatIsChannelText.layout(x, y, x + whatIsChannelText.getMeasuredWidth(), y + whatIsChannelText.getMeasuredHeight()); y = (int) (height * 0.61f); createChannelText.layout(x, y, x + createChannelText.getMeasuredWidth(), y + createChannelText.getMeasuredHeight()); x = (int) (width * 0.45f); y = (int) (height * 0.31f); descriptionText.layout(x, y, x + descriptionText.getMeasuredWidth(), y + descriptionText.getMeasuredHeight()); } else { int y = (int) (height * 0.05f); imageView.layout(0, y, imageView.getMeasuredWidth(), y + imageView.getMeasuredHeight()); y = (int) (height * 0.59f); whatIsChannelText.layout(0, y, whatIsChannelText.getMeasuredWidth(), y + whatIsChannelText.getMeasuredHeight()); y = (int) (height * 0.68f); int x = (int) (width * 0.05f); descriptionText.layout(x, y, x + descriptionText.getMeasuredWidth(), y + descriptionText.getMeasuredHeight()); y = (int) (height * 0.86f); createChannelText.layout(0, y, createChannelText.getMeasuredWidth(), y + createChannelText.getMeasuredHeight()); } } }; fragmentView.setBackgroundColor(ContextCompat.getColor(context, R.color.background)); ViewGroup viewGroup = (ViewGroup) fragmentView; viewGroup.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { return true; } }); imageView = new ImageView(context); imageView.setImageResource(R.drawable.channelintro); imageView.setScaleType(ImageView.ScaleType.FIT_CENTER); viewGroup.addView(imageView); whatIsChannelText = new TextView(context); whatIsChannelText.setTextColor(ContextCompat.getColor(context, R.color.primary_text)); whatIsChannelText.setGravity(Gravity.CENTER_HORIZONTAL); whatIsChannelText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 24); whatIsChannelText.setText(LocaleController.getString("ChannelAlertTitle", R.string.ChannelAlertTitle)); viewGroup.addView(whatIsChannelText); descriptionText = new TextView(context); descriptionText.setTextColor(ContextCompat.getColor(context, R.color.secondary_text)); descriptionText.setGravity(Gravity.CENTER_HORIZONTAL); descriptionText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16); descriptionText.setText(LocaleController.getString("ChannelAlertText", R.string.ChannelAlertText)); viewGroup.addView(descriptionText); createChannelText = new TextView(context); createChannelText.setTextColor(0xff4c8eca); createChannelText.setGravity(Gravity.CENTER); createChannelText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16); createChannelText.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf")); createChannelText.setText(LocaleController.getString("ChannelAlertCreate", R.string.ChannelAlertCreate)); viewGroup.addView(createChannelText); createChannelText.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Bundle args = new Bundle(); args.putInt("step", 0); presentFragment(new ChannelCreateActivity(args), true); } }); return fragmentView; }
From source file:com.capricorn.ArcMenu.java
private void init(Context context) { LayoutInflater li = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); li.inflate(R.layout.arc_menu, this); mArcLayout = (ArcLayout) findViewById(R.id.item_layout); final ViewGroup controlLayout = (ViewGroup) findViewById(R.id.control_layout); controlLayout.setClickable(true);/* ww w . ja va 2 s . c o m*/ controlLayout.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN) { if (userOnTouch != null) userOnTouch.onTouch(v, event); mHintView.startAnimation(createHintSwitchAnimation(mArcLayout.isExpanded())); mArcLayout.switchState(true); } return false; } }); mHintView = (ImageView) findViewById(R.id.control_hint); }
From source file:org.kei.android.phone.mangastore.AppFragment.java
@Override public View onCreateView(final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState) { final ViewGroup rootView = (ViewGroup) inflater.inflate(layout_id, container, false); swipeRefreshLayout = (SwipeRefreshLayout) rootView.findViewById(R.id.swipe_refresh_layout); listMangas = (ListView) rootView.findViewById(R.id.list); listMangas.setAdapter(adapter);// w w w.j a v a 2s .c o m indexer.initialize(rootView); multiChoice = new ListMultiChoice(((MangaStorePagerActivity) getActivity()), listMangas); gestureDetector = new GestureDetector(rootView.getContext(), indexer); listMangas.setOnItemClickListener(this); listMangas.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE_MODAL); listMangas.setMultiChoiceModeListener(multiChoice); rootView.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(final View v, final MotionEvent event) { if (gestureDetector.onTouchEvent(event)) return true; else return false; } }); swipeRefreshLayout.setOnRefreshListener(this); /** * Showing Swipe Refresh animation on activity create * As animation won't start on onCreate, post runnable is used */ swipeRefreshLayout.post(new Runnable() { @Override public void run() { swipeRefreshLayout.setRefreshing(true); fetch(); } }); return rootView; }
From source file:com.dahl.brendan.wordsearch.view.WordSearchActivity.java
/** * creates a grid of textViews from layout files based on the gridSize * and sets the new textViews to use the controller as their listener * /*from w w w. j a v a 2 s. c o m*/ * @param gridSize square size of the new grid to make * @param controller the onkeyListener used for the grid's textViews, also holds the gridView an array of the new textView's in the grid */ public void setupViewGrid() { control.setLetter(null); int gridSize = control.getGridSize(); TextViewGridController controller = control.getGridManager(); ViewGroup gridTable = (ViewGroup) this.findViewById(R.id.gridTable); if (gridTable.getChildCount() != gridSize) { if (gridTable.getChildCount() == 0) { gridTable.setKeepScreenOn(true); gridTable.setOnTouchListener(controller); } controller.clearPointDemension(); gridTable.removeAllViews(); Point point = new Point(); controller.setGridView(new TextView[gridSize][]); TextView[][] gridView = controller.getGridView(); for (point.y = 0; point.y < gridSize; point.y++) { this.getLayoutInflater().inflate(R.layout.grid_row, gridTable, true); ViewGroup row = (ViewGroup) gridTable.getChildAt(point.y); TextView[] rowText = new TextView[gridSize]; for (point.x = 0; point.x < gridSize; point.x++) { this.getLayoutInflater().inflate(R.layout.grid_text_view, row, true); TextView view = (TextView) row.getChildAt(point.x); view.setId(ConversionUtil.convertPointToID(point, control.getGridSize())); view.setOnKeyListener(controller); rowText[point.x] = view; } gridView[point.y] = rowText; } gridTable.requestLayout(); } }
From source file:ws.crandell.newspaperpuzzles.wordsearch.view.WordSearchActivity.java
/** * creates a grid of textViews from layout files based on the gridSize * and sets the new textViews to use the controller as their listener * /*from w w w . j a v a 2 s . c om*/ * @param gridSize square size of the new grid to make * @param controller the onkeyListener used for the grid's textViews, also holds the gridView an array of the new textView's in the grid */ public void setupViewGrid() { control.setLetter(null); int gridSize = control.getGridSize(); TextViewGridController controller = control.getGridManager(); ViewGroup gridTable = (ViewGroup) this.findViewById(R.id.gridTable); if (gridTable.getChildCount() != gridSize) { if (gridTable.getChildCount() == 0) { gridTable.setKeepScreenOn(true); gridTable.setOnTouchListener(controller); } controller.clearPointDemension(); gridTable.removeAllViews(); Point point = new Point(); controller.setGridView(new TextView[gridSize][]); TextView[][] gridView = controller.getGridView(); for (point.y = 0; point.y < gridSize; point.y++) { this.getLayoutInflater().inflate(R.layout.ws_grid_row, gridTable, true); ViewGroup row = (ViewGroup) gridTable.getChildAt(point.y); TextView[] rowText = new TextView[gridSize]; for (point.x = 0; point.x < gridSize; point.x++) { this.getLayoutInflater().inflate(R.layout.ws_grid_text_view, row, true); TextView view = (TextView) row.getChildAt(point.x); view.setId(ConversionUtil.convertPointToID(point, control.getGridSize())); view.setOnKeyListener(controller); rowText[point.x] = view; } gridView[point.y] = rowText; } gridTable.requestLayout(); } }
From source file:com.vuze.android.remote.fragment.TorrentListFragment.java
private void setupExpando(View view, int id_header, int id_body) { ViewGroup vgHeader = (ViewGroup) view.findViewById(id_header); final ViewGroup vgBody = (ViewGroup) view.findViewById(id_body); if (vgBody == null || vgHeader == null) { return;/*from ww w . j a v a2 s . co m*/ } listHeaderViewGroups.add(vgHeader); vgHeader.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { sidelistInFocus = true; // Consume touch event if user clicked the active sidelist view to // expand it // Otherwise, the active sidelist content would be collaped return expandSideListWidth(true) && sidebarViewActive == vgBody; } }); vgHeader.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (!sidelistIsExpanded && canSideListExpand()) { return; } boolean same = sidebarViewActive == vgBody; if (sidebarViewActive != null) { sidebarViewActive.setVisibility(View.GONE); } if (same) { sidebarViewActive = null; if (hideUnselectedSideHeaders) { for (ViewGroup vgHeader : listHeaderViewGroups) { vgHeader.setVisibility(View.VISIBLE); } } } else { vgBody.setVisibility(View.VISIBLE); sidebarViewActive = vgBody; if (hideUnselectedSideHeaders) { for (ViewGroup vgHeader : listHeaderViewGroups) { vgHeader.setVisibility(vgHeader == v ? View.VISIBLE : View.GONE); } } } if (tvSideFilterText != null && listSideFilter != null) { tvSideFilterText.setVisibility(tvSideFilterText.getText().length() == 0 && ((View) listSideFilter).getVisibility() == View.GONE ? View.GONE : View.VISIBLE); } } }); }
From source file:com.affectiva.affdexme.MainActivity.java
void initializeUI() { //Get handles to UI objects ViewGroup activityLayout = (ViewGroup) findViewById(android.R.id.content); progressBarLayout = (RelativeLayout) findViewById(R.id.progress_bar_cover); permissionsUnavailableLayout = (LinearLayout) findViewById(R.id.permissionsUnavialableLayout); metricViewLayout = (RelativeLayout) findViewById(R.id.metric_view_group); leftMetricsLayout = (LinearLayout) findViewById(R.id.left_metrics); rightMetricsLayout = (LinearLayout) findViewById(R.id.right_metrics); mainLayout = (RelativeLayout) findViewById(R.id.main_layout); fpsPct = (TextView) findViewById(R.id.fps_value); fpsName = (TextView) findViewById(R.id.fps_name); cameraView = (SurfaceView) findViewById(R.id.camera_preview); drawingView = (DrawingView) findViewById(R.id.drawing_view); settingsButton = (ImageButton) findViewById(R.id.settings_button); cameraButton = (ImageButton) findViewById(R.id.camera_button); screenshotButton = (ImageButton) findViewById(R.id.screenshot_button); progressBar = (ProgressBar) findViewById(R.id.progress_bar); pleaseWaitTextView = (TextView) findViewById(R.id.please_wait_textview); Button retryPermissionsButton = (Button) findViewById(R.id.retryPermissionsButton); //Initialize views to display metrics metricNames = new TextView[NUM_METRICS_DISPLAYED]; metricNames[0] = (TextView) findViewById(R.id.metric_name_0); metricNames[1] = (TextView) findViewById(R.id.metric_name_1); metricNames[2] = (TextView) findViewById(R.id.metric_name_2); metricNames[3] = (TextView) findViewById(R.id.metric_name_3); metricNames[4] = (TextView) findViewById(R.id.metric_name_4); metricNames[5] = (TextView) findViewById(R.id.metric_name_5); metricDisplays = new MetricDisplay[NUM_METRICS_DISPLAYED]; metricDisplays[0] = (MetricDisplay) findViewById(R.id.metric_pct_0); metricDisplays[1] = (MetricDisplay) findViewById(R.id.metric_pct_1); metricDisplays[2] = (MetricDisplay) findViewById(R.id.metric_pct_2); metricDisplays[3] = (MetricDisplay) findViewById(R.id.metric_pct_3); metricDisplays[4] = (MetricDisplay) findViewById(R.id.metric_pct_4); metricDisplays[5] = (MetricDisplay) findViewById(R.id.metric_pct_5); //Load Application Font and set UI Elements to use it Typeface face = Typeface.createFromAsset(getAssets(), "fonts/Square.ttf"); for (TextView textView : metricNames) { textView.setTypeface(face);/*from w ww. j ava 2s. c om*/ } for (MetricDisplay metricDisplay : metricDisplays) { metricDisplay.setTypeface(face); } fpsPct.setTypeface(face); fpsName.setTypeface(face); drawingView.setTypeface(face); pleaseWaitTextView.setTypeface(face); //Hide left and right metrics by default (will be made visible when face detection starts) leftMetricsLayout.setAlpha(0); rightMetricsLayout.setAlpha(0); /** * This app uses two SurfaceView objects: one to display the camera image and the other to draw facial tracking dots. * Since we want the tracking dots to appear over the camera image, we use SurfaceView.setZOrderMediaOverlay() to indicate that * cameraView represents our 'media', and drawingView represents our 'overlay', so that Android will render them in the * correct order. */ drawingView.setZOrderMediaOverlay(true); cameraView.setZOrderMediaOverlay(false); //Attach event listeners to the menu and edit box activityLayout.setOnTouchListener(this); //Attach event listerner to drawing view drawingView.setEventListener(this); /* * This app sets the View.SYSTEM_UI_FLAG_HIDE_NAVIGATION flag. Unfortunately, this flag causes * Android to steal the first touch event after the navigation bar has been hidden, a touch event * which should be used to make our menu visible again. Therefore, we attach a listener to be notified * when the navigation bar has been made visible again, which corresponds to the touch event that Android * steals. If the menu bar was not visible, we make it visible. */ activityLayout.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() { @Override public void onSystemUiVisibilityChange(int uiCode) { if ((uiCode == 0) && (!isMenuVisible)) { setMenuVisible(true); } } }); retryPermissionsButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { requestCameraPermissions(); } }); }