List of usage examples for android.widget RelativeLayout startAnimation
public void startAnimation(Animation animation)
From source file:com.rnd.snapsplit.view.OcrCaptureFragment.java
private void createNewThread() { t = new Thread() { @Override//w w w. j a va 2s. c o m public void run() { try { while (shouldContinue) { Thread.sleep(1); if (getActivity() == null) { return; } getActivity().runOnUiThread(new Runnable() { @Override public void run() { if (mGraphicOverlay.amountItem != null) { final ImageView upArrow = (ImageView) getView().findViewById(R.id.arrow_up); upArrow.animate().rotation(180).setDuration(500).start(); rotationAngle = 180; TextView amountTV = (TextView) getView().findViewById(R.id.text_amount_value); String amount = mGraphicOverlay.amountItem.getTextBlock().getValue(); amount = amount.replaceAll("\\s+", ""); amount = amount.replaceAll("[$]", ""); amountTV.setText(amount); RelativeLayout box = (RelativeLayout) getView() .findViewById(R.id.recognition_box); box.setVisibility(View.VISIBLE); Animation slide_up = AnimationUtils .loadAnimation(getActivity().getApplicationContext(), R.anim.slide_up); box.startAnimation(slide_up); onPause(); t.interrupt(); } } }); } } catch (InterruptedException e) { } } }; }
From source file:com.rnd.snapsplit.view.OcrCaptureFragment.java
/** * Initializes the UI and creates the detector pipeline. *///from ww w . jav a 2s . c o m // @Override // public void onActivityResult(int requestCode, int resultCode, Intent data) { // super.onActivityResult(requestCode, resultCode, data); // // if (requestCode == TAKE_PHOTO_CODE && resultCode == RESULT_OK) { // Toast.makeText(getContext(), "pic saved", Toast.LENGTH_LONG).show(); // Log.d("CameraDemo", "Pic saved"); // } // } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final View view = inflater.inflate(R.layout.view_ocr_capture, container, false); final Activity activity = getActivity(); final Context context = getContext(); ((Toolbar) activity.findViewById(R.id.tool_bar_hamburger)) .setBackgroundColor(ContextCompat.getColor(context, android.R.color.transparent)); final String dir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES) + "/picFolder/"; File newdir = new File(dir); newdir.mkdirs(); mPreview = (CameraSourcePreview) view.findViewById(R.id.preview); mGraphicOverlay = (GraphicOverlay<OcrGraphic>) view.findViewById(R.id.graphicOverlay); StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder(); StrictMode.setVmPolicy(builder.build()); // Set good defaults for capturing text. boolean autoFocus = true; boolean useFlash = false; // createNewThread(); // t.start(); final ImageView upArrow = (ImageView) view.findViewById(R.id.arrow_up); upArrow.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (rotationAngle == 0) { // arrow up //mCameraSource.takePicture(null, mPicture); //mGraphicOverlay.clear(); // mGraphicOverlay.clear(); // mGraphicOverlay.amountItem = null; onPause(); //shouldContinue = false; //mCamera.takePicture(null, null, mPicture); File pictureFile = getOutputMediaFile(); if (pictureFile == null) { return; } try { FileOutputStream fos = new FileOutputStream(pictureFile); Bitmap receiptBitmap = byteStreamToBitmap(mCameraSource.mostRecentBitmap); receiptBitmap.compress(Bitmap.CompressFormat.JPEG, 80, fos); picPath = pictureFile.getAbsolutePath(); //fos.write(mCameraSource.mostRecentBitmap); fos.close(); } catch (FileNotFoundException e) { } catch (IOException e) { } upArrow.animate().rotation(180).setDuration(500).start(); TextView amount = (TextView) view.findViewById(R.id.text_amount_value); if (mGraphicOverlay.amountItem == null) { amount.setText("0.00"); } else { amount.setText(String.format("%.2f", mGraphicOverlay.amountItemAfterFormat)); } TextView desc = (TextView) view.findViewById(R.id.text_name_value); desc.setText(mGraphicOverlay.description); RelativeLayout box = (RelativeLayout) view.findViewById(R.id.recognition_box); box.setVisibility(View.VISIBLE); Animation slide_up = AnimationUtils.loadAnimation(activity.getApplicationContext(), R.anim.slide_up); box.startAnimation(slide_up); rotationAngle = 180; } else { // t.interrupt(); // t = null; RelativeLayout box = (RelativeLayout) view.findViewById(R.id.recognition_box); Animation slide_down = AnimationUtils.loadAnimation(activity.getApplicationContext(), R.anim.slide_down); upArrow.animate().rotation(0).setDuration(500).start(); box.startAnimation(slide_down); box.setVisibility(View.INVISIBLE); //shouldContinue = true; mGraphicOverlay.amountItem = null; mGraphicOverlay.amountItemAfterFormat = 0f; mGraphicOverlay.description = ""; onResume(); // createNewThread(); // t.start(); rotationAngle = 0; } } }); ImageView addButton = (ImageView) view.findViewById(R.id.add_icon); addButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // takePicture(); EditText description = (EditText) view.findViewById(R.id.text_name_value); EditText amount = (EditText) view.findViewById(R.id.text_amount_value); float floatAmount = Float.parseFloat(amount.getText().toString()); Summary t = new Summary(description.getText().toString(), floatAmount); Bundle bundle = new Bundle(); bundle.putSerializable("splitTransaction", t); // ByteArrayOutputStream stream = new ByteArrayOutputStream(); // mCameraSource.mostRecentBitmap.compress(Bitmap.CompressFormat.PNG, 80, stream); // byte[] byteArray = stream.toByteArray(); //Bitmap receiptBitmap = byteStreamToBitmap(mCameraSource.mostRecentBitmap); //bundle.putParcelable("receiptPicture",receiptBitmap); bundle.putString("receiptPicture", picPath); FriendsSelectionFragment fragment = new FriendsSelectionFragment(); fragment.setArguments(bundle); ((Toolbar) activity.findViewById(R.id.tool_bar_hamburger)).setVisibility(View.INVISIBLE); getActivity().getSupportFragmentManager().beginTransaction() .add(R.id.fragment_holder, fragment, "FriendsSelectionFragment").addToBackStack(null) .commit(); } }); // Check for the camera permission before accessing the camera. If the // permission is not granted yet, request permission. int rc = ActivityCompat.checkSelfPermission(context, Manifest.permission.CAMERA); if (rc == PackageManager.PERMISSION_GRANTED) { createCameraSource(autoFocus, useFlash); } else { requestCameraPermission(); } gestureDetector = new GestureDetector(context, new CaptureGestureListener()); scaleGestureDetector = new ScaleGestureDetector(context, new ScaleListener()); // Snackbar.make(mGraphicOverlay, "Tap to Speak. Pinch/Stretch to zoom", // Snackbar.LENGTH_LONG) // .show(); // Set up the Text To Speech engine. TextToSpeech.OnInitListener listener = new TextToSpeech.OnInitListener() { @Override public void onInit(final int status) { if (status == TextToSpeech.SUCCESS) { Log.d("OnInitListener", "Text to speech engine started successfully."); tts.setLanguage(Locale.US); } else { Log.d("OnInitListener", "Error starting the text to speech engine."); } } }; tts = new TextToSpeech(activity.getApplicationContext(), listener); return view; }
From source file:de.uni_weimar.m18.anatomiederstadt.element.SliderFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment View view = inflater.inflate(R.layout.fragment_slider, container, false); SeekBar sb = (SeekBar) view.findViewById(R.id.seekBar); // scale mMin and mMax mMin = (int) (mMin / mGranularity); mMax = (int) (mMax / mGranularity); sb.setMax(mMax - mMin);//from www .j a v a 2s . co m sb.setProgress((mMax - mMin) / 2); final RelativeLayout balloon = (RelativeLayout) view.findViewById(R.id.indicatorBalloon); final Space space = (Space) view.findViewById(R.id.balloonSpace); final Context context = getActivity(); final TextView balloonText = (TextView) view.findViewById(R.id.indicatorTextView); final float[] value = { 0.0f }; sb.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { RelativeLayout.LayoutParams p = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); p.addRule(RelativeLayout.ABOVE, seekBar.getId()); Rect thumbRect = seekBar.getThumb().getBounds(); value[0] = mMin + progress * mGranularity; String valueString = new DecimalFormat("#.##").format(value[0]); balloonText.setText(String.valueOf(valueString) + " " + mSuffix); int balloonWidth = balloonText.getWidth(); p.setMargins(thumbRect.centerX() - balloonWidth / 2, 0, 0, 0); balloon.setLayoutParams(p); balloon.setVisibility(View.VISIBLE); final Animation animFadeOut = AnimationUtils.loadAnimation(context, R.anim.fade_out); balloon.startAnimation(animFadeOut); animFadeOut.setStartOffset(1000); animFadeOut.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { } @Override public void onAnimationEnd(Animation animation) { balloon.setVisibility(View.INVISIBLE); } @Override public void onAnimationRepeat(Animation animation) { } }); } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onStopTrackingTouch(SeekBar seekBar) { LevelStateManager stateManager = ((AnatomieDerStadtApplication) getActivity() .getApplicationContext()).getStateManager(getActivity()); stateManager.saveFloat(mVar, value[0]); } }); return view; }
From source file:Steps.StepsFragment.java
/** * Animate the new sticker rotating them on left and right and back again * * @param sticker//from w w w.j a v a 2 s . c o m * @param durationMillis */ private void animate(final RelativeLayout sticker, long durationMillis) { //final AnimationSet as = new AnimationSet(true); as.setFillEnabled(true); as.setFillAfter(true); //left rotations final RotateAnimation rotateLeft = new RotateAnimation((float) 320, (float) 375, RotateAnimation.RELATIVE_TO_SELF, 0.5f, RotateAnimation.RELATIVE_TO_SELF, 0.5f); rotateLeft.setDuration(durationMillis); rotateLeft.setFillEnabled(true); if (firstTime) as.addAnimation(rotateLeft); //right rotations Animation rotateRight = new RotateAnimation((float) 375, (float) 320, RotateAnimation.RELATIVE_TO_SELF, 0.5f, RotateAnimation.RELATIVE_TO_SELF, 0.5f); rotateRight.setStartOffset(durationMillis); rotateRight.setDuration(durationMillis); rotateRight.setFillEnabled(true); rotateRight.setFillAfter(true); if (firstTime) as.addAnimation(rotateRight); //sticker.clearAnimation(); sticker.startAnimation(as); firstTime = false; }
From source file:com.dvn.vindecoder.ui.seller.AddVehicalAndPayment.java
private void setScrollContent() { final CollapsingToolbarLayout collapsingToolbarLayout = (CollapsingToolbarLayout) findViewById( R.id.collapsing_toolbar);//from w w w. j ava2 s. com AppBarLayout appBarLayout = (AppBarLayout) findViewById(R.id.appBarLayout); final RelativeLayout img_container1 = (RelativeLayout) findViewById(R.id.img_container1); // load the animation final Animation animFadein = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.fadein); // start the animation // set animation listener animFadein.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { } @Override public void onAnimationEnd(Animation animation) { /* if(img_container1.getVisibility() == View.VISIBLE) { img_container1.setVisibility(View.GONE); }*/ } @Override public void onAnimationRepeat(Animation animation) { } }); appBarLayout.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() { boolean isShow = false; int scrollRange = -1; @Override public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) { if (scrollRange == -1) { scrollRange = appBarLayout.getTotalScrollRange(); // Log.e("val","-1 choti imge ko hide kerna h"); img_container1.setVisibility(View.GONE); } if (scrollRange + verticalOffset == 0) { // collapsingToolbarLayout.setTitle("Title"); // Log.e("val","0 choti imge ko show kerna h"); img_container1.setVisibility(View.VISIBLE); img_container1.startAnimation(animFadein); isShow = true; } else if (isShow) { // collapsingToolbarLayout.setTitle(" ");//carefull there should a space between double quote otherwise it wont work //Log.e("val","Showing choti imge ko hide kerna h"); img_container1.setVisibility(View.GONE); isShow = false; } } }); }
From source file:com.dvn.vindecoder.ui.seller.GetAllVehicalSellerDetails.java
private void setScrollContent() { collapsingToolbarLayout = (CollapsingToolbarLayout) findViewById(R.id.collapsing_toolbar); AppBarLayout appBarLayout = (AppBarLayout) findViewById(R.id.appBarLayout); final RelativeLayout img_container1 = (RelativeLayout) findViewById(R.id.img_container1); // load the animation final Animation animFadein = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.fadein); // start the animation // set animation listener animFadein.setAnimationListener(new Animation.AnimationListener() { @Override//from w ww .j a va2 s .co m public void onAnimationStart(Animation animation) { } @Override public void onAnimationEnd(Animation animation) { /* if(img_container1.getVisibility() == View.VISIBLE) { img_container1.setVisibility(View.GONE); }*/ } @Override public void onAnimationRepeat(Animation animation) { } }); appBarLayout.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() { boolean isShow = false; int scrollRange = -1; @Override public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) { if (scrollRange == -1) { scrollRange = appBarLayout.getTotalScrollRange(); // Log.e("val","-1 choti imge ko hide kerna h"); img_container1.setVisibility(View.GONE); } if (scrollRange + verticalOffset == 0) { // collapsingToolbarLayout.setTitle("Title"); // Log.e("val","0 choti imge ko show kerna h"); img_container1.setVisibility(View.VISIBLE); img_container1.startAnimation(animFadein); isShow = true; } else if (isShow) { // collapsingToolbarLayout.setTitle(" ");//carefull there should a space between double quote otherwise it wont work //Log.e("val","Showing choti imge ko hide kerna h"); img_container1.setVisibility(View.GONE); isShow = false; } } }); }
From source file:com.sociablue.nanodegree_p1.MovieListFragment.java
private void initializeFab(View rootView) { final RelativeLayout buttonContainer = (RelativeLayout) rootView.findViewById(R.id.menu_button_container); final FloatingActionButton Fab = (FloatingActionButton) rootView.findViewById(R.id.fab); final ImageView bottomBar = (ImageView) rootView.findViewById(R.id.menu_bottom_bar); final ImageView topBar = (ImageView) rootView.findViewById(R.id.menu_top_bar); Fab.setOnClickListener(new View.OnClickListener() { @TargetApi(Build.VERSION_CODES.LOLLIPOP) @Override/*from w ww . j a va 2s.c o m*/ public void onClick(View v) { //Menu Button Icon Animation //Setting up necessary variables long animationDuration = 500; float containerHeight = buttonContainer.getHeight(); float containerCenterY = containerHeight / 2; float containerCenterX = buttonContainer.getWidth() / 2; float topBarCenter = topBar.getTop() + topBar.getHeight() / 2; float widthOfBar = topBar.getWidth(); float heightOfBar = topBar.getHeight(); final float distanceBetweenBars = (containerCenterY - topBarCenter); /** *TODO: Refactor block of code to use Value Property Animator. Should be more efficient to animate multiple properties *and objects at the same time. Also, will try to break intialization into smaller functions. */ //Setting up animations of hamburger bars and rotation /** * Animation For Top Menu Button Icon Bar. Sliding from the top to rest on top of the middle bar. * Y Translation is 1/2 the height of the hamburger bar minus the distance. * Subtracting the distance from the height because the distance between bars is * calculated of the exact center of the button. * With out the subtraction the bar would translate slightly below the middle bar. */ float yTranslation = heightOfBar / 2 - distanceBetweenBars; float xTranslation = widthOfBar / 2 + heightOfBar / 2; TranslateAnimation topBarTranslationAnim = new TranslateAnimation(Animation.ABSOLUTE, 0f, Animation.ABSOLUTE, 0F, Animation.ABSOLUTE, 0f, Animation.ABSOLUTE, distanceBetweenBars); topBarTranslationAnim.setDuration((long) (animationDuration * 0.8)); topBarTranslationAnim.setFillAfter(true); //Animation for bottom hamburger bar. Translates and Rotates to create 'X' AnimationSet bottomBarAnimation = new AnimationSet(true); bottomBarAnimation.setFillAfter(true); //Rotate to create cross. (The cross becomes the X after the button rotation completes" RotateAnimation bottomBarRotationAnimation = new RotateAnimation(0f, 90f, Animation.RELATIVE_TO_SELF, 1f, Animation.RELATIVE_TO_SELF, 1f); bottomBarRotationAnimation.setDuration(animationDuration); bottomBarAnimation.addAnimation(bottomBarRotationAnimation); //Translate to correct X alignment TranslateAnimation bottomBarTranslationAnimation = new TranslateAnimation(Animation.ABSOLUTE, 0f, Animation.ABSOLUTE, -xTranslation, Animation.ABSOLUTE, 0f, Animation.ABSOLUTE, -yTranslation); bottomBarTranslationAnimation.setDuration(animationDuration); bottomBarAnimation.addAnimation(bottomBarTranslationAnimation); //Button Specific Animations //Rotate Button Container RotateAnimation containerRotationAnimation = new RotateAnimation(0, 135f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); containerRotationAnimation.setDuration(animationDuration); containerRotationAnimation.setFillAfter(true); //Animate change of button color between Active and Disabled colors that have been //defined in color.xml int activeColor = getResources().getColor(R.color.active_button); int disabledColor = getResources().getColor(R.color.disabled_button); //Need to use ValueAnimator because property animator does not support BackgroundTint ValueAnimator buttonColorAnimation = ValueAnimator.ofArgb(activeColor, disabledColor); buttonColorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { Fab.setBackgroundTintList(ColorStateList.valueOf((int) animation.getAnimatedValue())); } }); buttonColorAnimation.setDuration(animationDuration); //Start all the animations topBar.startAnimation(topBarTranslationAnim); bottomBar.startAnimation(bottomBarAnimation); buttonContainer.startAnimation(containerRotationAnimation); buttonColorAnimation.start(); //Toogle mMenu open and closed if (mMenu.isOpen()) { //If mMenu is open, do the reverse of the animation containerRotationAnimation .setInterpolator(new ReverseInterpolator(new AccelerateInterpolator())); topBarTranslationAnim.setInterpolator(new ReverseInterpolator(new AccelerateInterpolator())); bottomBarAnimation.setInterpolator(new ReverseInterpolator(new AccelerateInterpolator())); buttonColorAnimation.setInterpolator(new ReverseInterpolator(new LinearInterpolator())); mMenu.close(); } else { bottomBarAnimation.setInterpolator(new AccelerateInterpolator()); mMenu.open(); } } }); }
From source file:org.connectbot.ConsoleFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final View v = inflater.inflate(R.layout.frg_console, container, false); this.inflater = inflater; flip = (ViewFlipper) v.findViewById(R.id.console_flip); empty = (TextView) v.findViewById(android.R.id.empty); stringPromptGroup = (RelativeLayout) v.findViewById(R.id.console_password_group); stringPromptInstructions = (TextView) v.findViewById(R.id.console_password_instructions); stringPrompt = (EditText) v.findViewById(R.id.console_password); stringPrompt.setOnKeyListener(new OnKeyListener() { public boolean onKey(View v, int keyCode, KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_UP) return false; if (keyCode != KeyEvent.KEYCODE_ENTER) return false; // pass collected password down to current terminal String value = stringPrompt.getText().toString(); PromptHelper helper = getCurrentPromptHelper(); if (helper == null) return false; helper.setResponse(value);//from w ww. j a v a2s . co m // finally clear password for next user stringPrompt.setText(""); updatePromptVisible(); return true; } }); booleanPromptGroup = (RelativeLayout) v.findViewById(R.id.console_boolean_group); booleanPrompt = (TextView) v.findViewById(R.id.console_prompt); booleanYes = (Button) v.findViewById(R.id.console_prompt_yes); booleanYes.setOnClickListener(new OnClickListener() { public void onClick(View v) { PromptHelper helper = getCurrentPromptHelper(); if (helper == null) return; helper.setResponse(Boolean.TRUE); updatePromptVisible(); } }); booleanNo = (Button) v.findViewById(R.id.console_prompt_no); booleanNo.setOnClickListener(new OnClickListener() { public void onClick(View v) { PromptHelper helper = getCurrentPromptHelper(); if (helper == null) return; helper.setResponse(Boolean.FALSE); updatePromptVisible(); } }); // preload animations for terminal switching slide_left_in = AnimationUtils.loadAnimation(getActivity(), R.anim.slide_left_in); slide_left_out = AnimationUtils.loadAnimation(getActivity(), R.anim.slide_left_out); slide_right_in = AnimationUtils.loadAnimation(getActivity(), R.anim.slide_right_in); slide_right_out = AnimationUtils.loadAnimation(getActivity(), R.anim.slide_right_out); fade_out_delayed = AnimationUtils.loadAnimation(getActivity(), R.anim.fade_out_delayed); fade_stay_hidden = AnimationUtils.loadAnimation(getActivity(), R.anim.fade_stay_hidden); // Preload animation for keyboard button keyboard_fade_in = AnimationUtils.loadAnimation(getActivity(), R.anim.keyboard_fade_in); keyboard_fade_out = AnimationUtils.loadAnimation(getActivity(), R.anim.keyboard_fade_out); inputManager = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE); final RelativeLayout keyboardGroup = (RelativeLayout) v.findViewById(R.id.keyboard_group); mKeyboardButton = (ImageView) v.findViewById(R.id.button_keyboard); mKeyboardButton.setOnClickListener(new OnClickListener() { public void onClick(View view) { View flip = findCurrentView(R.id.console_flip); if (flip == null) return; inputManager.showSoftInput(flip, InputMethodManager.SHOW_FORCED); keyboardGroup.setVisibility(View.GONE); } }); final ImageView ctrlButton = (ImageView) v.findViewById(R.id.button_ctrl); ctrlButton.setOnClickListener(new OnClickListener() { public void onClick(View view) { View flip = findCurrentView(R.id.console_flip); if (flip == null) return; TerminalView terminal = (TerminalView) flip; TerminalKeyListener handler = terminal.bridge.getKeyHandler(); handler.metaPress(TerminalKeyListener.META_CTRL_ON); keyboardGroup.setVisibility(View.GONE); } }); final ImageView escButton = (ImageView) v.findViewById(R.id.button_esc); escButton.setOnClickListener(new OnClickListener() { public void onClick(View view) { View flip = findCurrentView(R.id.console_flip); if (flip == null) return; TerminalView terminal = (TerminalView) flip; TerminalKeyListener handler = terminal.bridge.getKeyHandler(); handler.sendEscape(); keyboardGroup.setVisibility(View.GONE); } }); // detect fling gestures to switch between terminals final GestureDetector detect = new GestureDetector(new GestureDetector.SimpleOnGestureListener() { private float totalY = 0; @Override public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { final float distx = e2.getRawX() - e1.getRawX(); final float disty = e2.getRawY() - e1.getRawY(); final int goalwidth = flip.getWidth() / 2; // need to slide across half of display to trigger console change // make sure user kept a steady hand horizontally if (Math.abs(disty) < (flip.getHeight() / 4)) { if (distx > goalwidth) { shiftCurrentTerminal(SHIFT_RIGHT); return true; } if (distx < -goalwidth) { shiftCurrentTerminal(SHIFT_LEFT); return true; } } return false; } @Override public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { // if copying, then ignore if (copySource != null && copySource.isSelectingForCopy()) return false; if (e1 == null || e2 == null) return false; // if releasing then reset total scroll if (e2.getAction() == MotionEvent.ACTION_UP) { totalY = 0; } // activate consider if within x tolerance if (Math.abs(e1.getX() - e2.getX()) < ViewConfiguration.getTouchSlop() * 4) { View flip = findCurrentView(R.id.console_flip); if (flip == null) return false; TerminalView terminal = (TerminalView) flip; // estimate how many rows we have scrolled through // accumulate distance that doesn't trigger immediate scroll totalY += distanceY; final int moved = (int) (totalY / terminal.bridge.charHeight); // consume as scrollback only if towards right half of screen if (e2.getX() > flip.getWidth() / 2) { if (moved != 0) { int base = terminal.bridge.buffer.getWindowBase(); terminal.bridge.buffer.setWindowBase(base + moved); totalY = 0; return true; } } else { // otherwise consume as pgup/pgdown for every 5 lines if (moved > 5) { ((vt320) terminal.bridge.buffer).keyPressed(vt320.KEY_PAGE_DOWN, ' ', 0); terminal.bridge.tryKeyVibrate(); totalY = 0; return true; } else if (moved < -5) { ((vt320) terminal.bridge.buffer).keyPressed(vt320.KEY_PAGE_UP, ' ', 0); terminal.bridge.tryKeyVibrate(); totalY = 0; return true; } } } return false; } }); flip.setLongClickable(true); flip.setOnTouchListener(new OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { // when copying, highlight the area if (copySource != null && copySource.isSelectingForCopy()) { int row = (int) Math.floor(event.getY() / copySource.charHeight); int col = (int) Math.floor(event.getX() / copySource.charWidth); SelectionArea area = copySource.getSelectionArea(); switch (event.getAction()) { case MotionEvent.ACTION_DOWN: // recording starting area if (area.isSelectingOrigin()) { area.setRow(row); area.setColumn(col); lastTouchRow = row; lastTouchCol = col; copySource.redraw(); } return true; case MotionEvent.ACTION_MOVE: /* ignore when user hasn't moved since last time so * we can fine-tune with directional pad */ if (row == lastTouchRow && col == lastTouchCol) return true; // if the user moves, start the selection for other corner area.finishSelectingOrigin(); // update selected area area.setRow(row); area.setColumn(col); lastTouchRow = row; lastTouchCol = col; copySource.redraw(); return true; case MotionEvent.ACTION_UP: /* If they didn't move their finger, maybe they meant to * select the rest of the text with the directional pad. */ if (area.getLeft() == area.getRight() && area.getTop() == area.getBottom()) { return true; } // copy selected area to clipboard String copiedText = area.copyFrom(copySource.buffer); clipboard.setText(copiedText); Toast.makeText(getActivity(), getString(R.string.console_copy_done, copiedText.length()), Toast.LENGTH_LONG).show(); // fall through to clear state case MotionEvent.ACTION_CANCEL: // make sure we clear any highlighted area area.reset(); copySource.setSelectingForCopy(false); copySource.redraw(); return true; } } Configuration config = getResources().getConfiguration(); if (event.getAction() == MotionEvent.ACTION_DOWN) { lastX = event.getX(); lastY = event.getY(); } else if (event.getAction() == MotionEvent.ACTION_UP && keyboardGroup.getVisibility() == View.GONE && event.getEventTime() - event.getDownTime() < CLICK_TIME && Math.abs(event.getX() - lastX) < MAX_CLICK_DISTANCE && Math.abs(event.getY() - lastY) < MAX_CLICK_DISTANCE) { keyboardGroup.startAnimation(keyboard_fade_in); keyboardGroup.setVisibility(View.VISIBLE); mUIHandler.postDelayed(new Runnable() { public void run() { if (keyboardGroup.getVisibility() == View.GONE) return; keyboardGroup.startAnimation(keyboard_fade_out); keyboardGroup.setVisibility(View.GONE); } }, KEYBOARD_DISPLAY_TIME); } // pass any touch events back to detector return detect.onTouchEvent(event); } }); return v; }