Java Code Examples for android.widget.LinearLayout#setOnTouchListener()
The following examples show how to use
android.widget.LinearLayout#setOnTouchListener() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PreviewFragment.java From kolabnotes-android with GNU Lesser General Public License v3.0 | 6 votes |
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); webView = (WebView) getActivity().findViewById(R.id.preview_html); textView = (EditText) getActivity().findViewById(R.id.preview_text); musicView = (LinearLayout) getActivity().findViewById(R.id.main_audio_view); videoView = (VideoView) getActivity().findViewById(R.id.preview_video); emptyView = (TextView) getActivity().findViewById(R.id.empty_view_preview); imageView = (ImageView) getActivity().findViewById(R.id.preview_picture); nowPlayingView = (TextView) getActivity().findViewById(R.id.now_playing_text); musicView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { mediaController.show(0); return true; } }); final ActiveAccount activeAccount = this.accountRepository.getActiveAccount(); //final Attachment attachment = this.attachmentRepository.getAttachmentWithAttachmentID(activeAccount.getAccount(), activeAccount.getRootFolder(), noteUID, attachmentID); displayPreview(activeAccount, noteUID, null); }
Example 2
Source File: LoadingLayout.java From ImageChooser with Apache License 2.0 | 6 votes |
/** * 初始化布局 */ private void initView() { mLoadingProgressBar = (ProgressBar)findViewById(R.id.loading_pb); mRetryLayout = (LinearLayout)findViewById(R.id.loading_fail_layout); mRetryLayout.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { if (!canRetry) { return false; } // onTouch down的时候才触发重试异步线程,否则会多次触发的。 if (event.getAction() == MotionEvent.ACTION_DOWN) { if (mRetryListener != null) { mRetryListener.onRetry(); } } return true; } }); mErrorTv = (TextView)findViewById(R.id.loading_fail_tv); }
Example 3
Source File: ArcTipViewController.java From timecat with Apache License 2.0 | 5 votes |
private void initView() { showTimeCat = SPHelper.getBoolean(Constants.TOTAL_SWITCH, true); isStick = SPHelper.getBoolean(Constants.FLOATVIEW_IS_STICK, false); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) { Point point = new Point(); mWindowManager.getDefaultDisplay().getSize(point); mScreenWidth = point.x; mScreenHeight = point.y; } else { mScreenWidth = mWindowManager.getDefaultDisplay().getWidth(); mScreenHeight = mWindowManager.getDefaultDisplay().getHeight(); } if (showTimeCat) { mCurrentIconAlpha = SPHelper.getInt(Constants.FLOATVIEW_ALPHA, 70) / 100f; } else { mCurrentIconAlpha = 0.6f * SPHelper.getInt(Constants.FLOATVIEW_ALPHA, 70) / 100f; } iconFloatView = (LinearLayout) View.inflate(mContext, R.layout.arc_float_icon, null); floatImageView = iconFloatView.findViewById(R.id.float_image); acrFloatView = (RelativeLayout) View.inflate(mContext, R.layout.arc_view_float, null); archMenu = acrFloatView.findViewById(R.id.arc_menu); initIcon(); archMenu.setOnModeSelectedListener(new ArcMenu.OnModeSelectedListener() { @Override public void onModeSelected() { showFloatImageView(); } @Override public void onNothing() { } }); // event listeners acrFloatView.setOnTouchListener(this); iconFloatView.setOnTouchListener(this); }
Example 4
Source File: CallIncomingDeclineButton.java From linphone-android with GNU General Public License v3.0 | 5 votes |
private void init() { inflate(getContext(), R.layout.call_incoming_decline_button, this); LinearLayout root = findViewById(R.id.root); root.setOnClickListener(this); root.setOnTouchListener(this); mScreenWidth = getResources().getDisplayMetrics().widthPixels; }
Example 5
Source File: AudioVideoCameraActivity.java From coursera-android with MIT License | 5 votes |
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mFrame = (LinearLayout) findViewById(R.id.frame); // Disable touches on mFrame mFrame.setEnabled(false); // Setup touch listener for taking pictures mFrame.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { // Only respond to ACTION_UP if (event.getActionMasked() == (MotionEvent.ACTION_UP)) { // Take picture // Pass in shutterCallback and PictureCallback Objects mCamera.takePicture(mShutterCallback, null, mPictureCallback); } return true; } }); // Setup SurfaceView for previewing camera image SurfaceView surfaceView = (SurfaceView) findViewById(R.id.cameraView); // Get SurfaceHolder for accessing the SurfaceView's Surface mSurfaceHolder = surfaceView.getHolder(); // Set callback Object for the SurfaceHolder mSurfaceHolder.addCallback(mSurfaceHolderCallback); }
Example 6
Source File: EUExWidget.java From appcan-android with GNU Lesser General Public License v3.0 | 5 votes |
private void showLoadingPage(WidgetConfigVO configVO, EBrowserWindow curWind) { LayoutInflater layoutInflater = LayoutInflater.from(mContext); inflate = (LinearLayout) layoutInflater.inflate(EUExUtil.getResLayoutID("platform_mp_window_middle_loadding"), null); inflate.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { return true; } }); ImageView platform_mp_loadding_close = (ImageView) inflate.findViewById(EUExUtil.getResIdID("platform_mp_loadding_close")); TextView platformName = (TextView) inflate.findViewById(EUExUtil.getResIdID("platform_mp_loadding_iconname")); platformName.setText(configVO.widgetName); platform_mp_loadding_close.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { //回调前端方法去关闭子应用 callBackPluginJs("uexWidget.cbCloseLoading", "0"); mBrwView.removeView(inflate); } }); ImageButton platform_mp_loadding_icon = (ImageButton) inflate.findViewById(EUExUtil.getResIdID("platform_mp_loadding_icon")); curWind.showButtonIcon(platform_mp_loadding_icon, configVO.appIcon); TranslateAnimation anim = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 1.0f, Animation.RELATIVE_TO_PARENT, 0.0f); anim.setDuration(500); inflate.startAnimation(anim); ViewGroup.LayoutParams param=new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); mBrwView.addView(inflate, -1,param); Log.e("TAG", "显示过度界面完成================"); }
Example 7
Source File: SettingFragment.java From Social with Apache License 2.0 | 4 votes |
@Nullable @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.setting_fragment_layout,container,false); ll_modify_user_data = (LinearLayout)view.findViewById(R.id.id_setting_fg_ll_modify_user_data); ll_modify_user_data.setOnClickListener(this); ll_modify_user_data.setOnTouchListener(this); rl_general_setting = (RelativeLayout)view.findViewById(R.id.id_setting_fg_rl_gegeral_setting); rl_general_setting.setOnClickListener(this); rl_general_setting.setOnTouchListener(this); rl_private = (RelativeLayout)view.findViewById(R.id.id_setting_fg_rl_private); rl_private.setOnClickListener(this); rl_private.setOnTouchListener(this); rl_feedback = (RelativeLayout)view.findViewById(R.id.id_setting_fg_rl_feedback); rl_feedback.setOnClickListener(this); rl_feedback.setOnTouchListener(this); rl_about = (RelativeLayout)view.findViewById(R.id.id_setting_fg_rl_about); rl_about.setOnClickListener(this); rl_about.setOnTouchListener(this); rv_account_and_secure = (RippleView)view.findViewById(R.id.id_setting_fg_rv_account_and_souce); rv_account_and_secure.setOnRippleCompleteListener(this); iv_head = (CircleImageView)view.findViewById(R.id.id_setting_fg_iv_head); tv_nickname = (TextView)view.findViewById(R.id.id_setting_fg_tv_nickname); tv_username = (TextView)view.findViewById(R.id.id_setting_fg_tv_username); if (OkhttpUtil.checkLogin()){ tv_username.setText("账号:" + SharedPreferenceUtil.getUserName()); tv_nickname.setText(SharedPreferenceUtil.getNickname()); //Picasso.with(getActivity()).load(WebUtil.HTTP_ADDRESS + SharedPreferenceUtil.getHeadpath()).into(iv_head); } intentFilter = new IntentFilter(); intentFilter.addAction("com.allever.modifyUserHead"); intentFilter.addAction("com.allever.modifyUserData"); intentFilter.addAction("com.allever.afterlogin"); afterModifyUserDataReceiver = new AfterModifyUserDataReceiver(); afterLoginReceiver = new AfterLoginaReceiver(); getActivity().registerReceiver(afterLoginReceiver,intentFilter); getActivity().registerReceiver(afterModifyUserDataReceiver,intentFilter); handler = new Handler(){ @Override public void handleMessage(Message msg) { //super.handleMessage(msg); switch (msg.what){ case OkhttpUtil.MESSAGE_AUTO_LOGIN: handleAutoLogin(msg); break; case OkhttpUtil.MESSAGE_LOGOUT: handleLogout(msg); break; } } }; btn_logout = (ButtonRectangle)view.findViewById(R.id.id_setting_fg_btn_logout); btn_logout.setOnClickListener(this); if (OkhttpUtil.checkLogin()){ btn_logout.setVisibility(View.VISIBLE); }else{ btn_logout.setVisibility(View.INVISIBLE); } return view; }
Example 8
Source File: FloatingControlService.java From screenrecorder with GNU Affero General Public License v3.0 | 4 votes |
@Override public int onStartCommand(Intent intent, int flags, int startId) { windowManager = (WindowManager) getSystemService(WINDOW_SERVICE); //Inflate the layout using LayoutInflater LayoutInflater li = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE); floatingControls = (LinearLayout) li.inflate(R.layout.layout_floating_controls, null); controls = floatingControls.findViewById(R.id.controls); //Initialize imageButtons ImageButton stopIB = controls.findViewById(R.id.stop); pauseIB = controls.findViewById(R.id.pause); resumeIB = controls.findViewById(R.id.resume); resumeIB.setEnabled(false); stopIB.setOnClickListener(this); //Get floating control icon size from sharedpreference SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(this); //Pause/Resume doesnt work below SDK version 24. Remove them if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) { pauseIB.setVisibility(View.GONE); resumeIB.setVisibility(View.GONE); controls.findViewById(R.id.divider1).setVisibility(View.GONE); controls.findViewById(R.id.divider2).setVisibility(View.GONE); } else { pauseIB.setOnClickListener(this); resumeIB.setOnClickListener(this); } //Set layout params to display the controls over any screen. final WindowManager.LayoutParams params = new WindowManager.LayoutParams( WindowManager.LayoutParams.WRAP_CONTENT, dpToPx(pref.getInt(getString(R.string.preference_floating_control_size_key), 100)), WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, PixelFormat.TRANSLUCENT); // From API26, TYPE_PHONE depricated. Use TYPE_APPLICATION_OVERLAY for O if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) params.type = WindowManager.LayoutParams.TYPE_PHONE; //Initial position of the floating controls params.gravity = Gravity.TOP | Gravity.START; params.x = 0; params.y = 100; //Add the controls view to windowmanager windowManager.addView(floatingControls, params); //Add touch listerner to floating controls view to move/close/expand the controls try { floatingControls.setOnTouchListener(new View.OnTouchListener() { boolean isMoving = false; private WindowManager.LayoutParams paramsF = params; private int initialX; private int initialY; private float initialTouchX; private float initialTouchY; @Override public boolean onTouch(View v, MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: isMoving = false; initialX = paramsF.x; initialY = paramsF.y; initialTouchX = event.getRawX(); initialTouchY = event.getRawY(); break; case MotionEvent.ACTION_UP: if (!isMoving) { if (controls.getVisibility() == View.INVISIBLE) { expandFloatingControls(); } else { collapseFloatingControls(); } } break; case MotionEvent.ACTION_MOVE: int xDiff = (int) (event.getRawX() - initialTouchX); int yDiff = (int) (event.getRawY() - initialTouchY); paramsF.x = initialX + xDiff; paramsF.y = initialY + yDiff; /* Set an offset of 10 pixels to determine controls moving. Else, normal touches * could react as moving the control window around */ if (Math.abs(xDiff) > 10 || Math.abs(yDiff) > 10) isMoving = true; windowManager.updateViewLayout(floatingControls, paramsF); break; } return false; } }); } catch (Exception e) { // TODO: handle exception } return START_STICKY; }
Example 9
Source File: ClickableToast.java From Dashchan with Apache License 2.0 | 4 votes |
private ClickableToast(Holder holder) { this.holder = holder; Context context = holder.context; float density = ResourceUtils.obtainDensity(context); int innerPadding = (int) (8f * density); LayoutInflater inflater = LayoutInflater.from(context); View toast1 = inflater.inflate(LAYOUT_ID, null); View toast2 = inflater.inflate(LAYOUT_ID, null); TextView message1 = toast1.findViewById(android.R.id.message); TextView message2 = toast2.findViewById(android.R.id.message); View backgroundSource = null; Drawable backgroundDrawable = toast1.getBackground(); if (backgroundDrawable == null) { backgroundDrawable = message1.getBackground(); if (backgroundDrawable == null) { View messageParent = (View) message1.getParent(); if (messageParent != null) { backgroundDrawable = messageParent.getBackground(); backgroundSource = messageParent; } } else { backgroundSource = message1; } } else { backgroundSource = toast1; } StringBuilder builder = new StringBuilder(); for (int i = 0; i < 100; i++) builder.append('W'); // Make long text message1.setText(builder); // Avoid minimum widths int measureSize = (int) (context.getResources().getConfiguration().screenWidthDp * density + 0.5f); toast1.measure(View.MeasureSpec.makeMeasureSpec(measureSize, View.MeasureSpec.AT_MOST), View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED)); toast1.layout(0, 0, toast1.getMeasuredWidth(), toast1.getMeasuredHeight()); Rect backgroundSourceTotalPadding = getViewTotalPadding(toast1, backgroundSource); Rect messageTotalPadding = getViewTotalPadding(toast1, message1); messageTotalPadding.left -= backgroundSourceTotalPadding.left; messageTotalPadding.top -= backgroundSourceTotalPadding.top; messageTotalPadding.right -= backgroundSourceTotalPadding.right; messageTotalPadding.bottom -= backgroundSourceTotalPadding.bottom; int horizontalPadding = Math.max(messageTotalPadding.left, messageTotalPadding.right) + Math.max(message1.getPaddingLeft(), message1.getPaddingRight()); int verticalPadding = Math.max(messageTotalPadding.top, messageTotalPadding.bottom) + Math.max(message1.getPaddingTop(), message1.getPaddingBottom()); ViewUtils.removeFromParent(message1); ViewUtils.removeFromParent(message2); LinearLayout linearLayout = new LinearLayout(context); linearLayout.setOrientation(LinearLayout.HORIZONTAL); linearLayout.setDividerDrawable(new ToastDividerDrawable(0xccffffff, (int) (density + 0.5f))); linearLayout.setShowDividers(LinearLayout.SHOW_DIVIDER_MIDDLE); linearLayout.setDividerPadding((int) (4f * density)); linearLayout.setTag(this); linearLayout.addView(message1, LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); linearLayout.addView(message2, LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); ((LinearLayout.LayoutParams) message1.getLayoutParams()).weight = 1f; linearLayout.setPadding(horizontalPadding, verticalPadding, horizontalPadding, verticalPadding); partialClickDrawable = new PartialClickDrawable(backgroundDrawable); message1.setBackground(null); message2.setBackground(null); linearLayout.setBackground(partialClickDrawable); linearLayout.setOnTouchListener(partialClickDrawable); message1.setPadding(0, 0, 0, 0); message2.setPadding(innerPadding, 0, 0, 0); message1.setSingleLine(true); message2.setSingleLine(true); message1.setEllipsize(TextUtils.TruncateAt.END); message2.setEllipsize(TextUtils.TruncateAt.END); container = linearLayout; message = message1; button = message2; windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); }
Example 10
Source File: ClickableMenuElement.java From gravitydefied with GNU General Public License v2.0 | 4 votes |
protected void createAllViews() { final ClickableMenuElement self = this; Context context = getGDActivity(); layout = new LinearLayout(context); layout.setOrientation(LinearLayout.HORIZONTAL); layout.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT)); helmet = new MenuHelmetView(context); helmet.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.MATCH_PARENT)); /*if (!isSDK11OrHigher()) { helmet.setMeasuredHeight(true); }*/ onTouchListener = new View.OnTouchListener() { @Override public boolean onTouch(View view, MotionEvent motionEvent) { if (disabled) return false; switch (motionEvent.getAction()) { case MotionEvent.ACTION_DOWN: view.setSelected(true); helmet.setShow(true); if (onMenuElementHighlightListener != null) onMenuElementHighlightListener.onElementHighlight(self); setHighlighted(true); break; case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_UP: view.setSelected(false); if (motionEvent.getAction() == MotionEvent.ACTION_UP && inViewBounds(view, (int) motionEvent.getRawX(), (int) motionEvent.getRawY())) { performAction(MenuScreen.KEY_FIRE); } setHighlighted(false); break; case MotionEvent.ACTION_MOVE: if (!inViewBounds(view, (int) motionEvent.getRawX(), (int) motionEvent.getRawY())) { view.setSelected(false); setHighlighted(false); } else { view.setSelected(true); setHighlighted(true); } break; } return true; } }; textView = createMainView(); layout.addView(helmet); layout.addView(textView); layout.setOnTouchListener(onTouchListener); }
Example 11
Source File: MarketListHeader.java From bither-android with Apache License 2.0 | 4 votes |
private void initView() { removeAllViews(); imm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE); parent = LayoutInflater.from(getContext()).inflate(R.layout.layout_market_list_header, null); addView(parent, LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); flContainer = findViewById(R.id.fl_container); vContainer = findViewById(R.id.ll_container); ivLight = findViewById(R.id.iv_light); tvName = (TextView) findViewById(R.id.tv_market_name); tvSymbol = (TextView) findViewById(R.id.tv_currency_symbol); tvPrice = (TextView) findViewById(R.id.tv_new_price); tvHigh = (TextView) findViewById(R.id.tv_high); tvLow = (TextView) findViewById(R.id.tv_low); tvVolume = (TextView) findViewById(R.id.tv_volume); tvSell = (TextView) findViewById(R.id.tv_sell); tvBuy = (TextView) findViewById(R.id.tv_buy); ivVolumeSymbol = (ImageView) findViewById(R.id.iv_volume_symbol); vTrending = (TrendingGraphicView) findViewById(R.id.v_trending); llTrending = (LinearLayout) findViewById(R.id.ll_trending); llAlert = (LinearLayout) findViewById(R.id.ll_alert); etAlertHigh = (EditText) findViewById(R.id.et_alert_high); etAlertLow = (EditText) findViewById(R.id.et_alert_low); btnPriceAlertOk = (Button) findViewById(R.id.btn_ok); gestureDetector = new GestureDetector(getContext(), new SwipeDetector()); bottomHolder = new ContainerBottomPaddingHolder(); getViewTreeObserver().addOnGlobalLayoutListener(this); alertTextViewListener = new TextViewListener(); etAlertHigh.setOnEditorActionListener(alertTextViewListener); etAlertHigh.addTextChangedListener(alertTextViewListener); etAlertHigh.setOnFocusChangeListener(alertTextViewListener); etAlertLow.setOnEditorActionListener(alertTextViewListener); etAlertLow.addTextChangedListener(alertTextViewListener); etAlertLow.setOnFocusChangeListener(alertTextViewListener); btnPriceAlertOk.setOnClickListener(new PriceAlertOkClick()); refreshAnim.setDuration(LightScanInterval); refreshAnim.setFillBefore(false); refreshAnim.setRepeatCount(0); refreshAnim.setFillAfter(false); ivVolumeSymbol.setImageBitmap(UnitUtilWrapper.getBtcSymbol(tvVolume, UnitUtilWrapper.BitcoinUnitWrapper.BTC)); llTrending.setOnClickListener(new MarketDetailClick()); llTrending.setOnTouchListener(new TrendingTouch()); setMarket(MarketUtil.getDefaultMarket()); }