Java Code Examples for android.view.View.OnTouchListener

The following code examples are extracted from open source projects. You can click to vote up the examples that are useful to you.

Example 1

From project android_packages_apps_Gallery, under directory /src/com/android/camera/.

Source file: ReviewImage.java

  25 
vote

private void setupOnTouchListeners(View rootView){
  mGestureDetector=new GestureDetector(this,new MyGestureListener());
  final OnTouchListener buttonListener=new OnTouchListener(){
    public boolean onTouch(    View v,    MotionEvent event){
      scheduleDismissOnScreenControls();
      return false;
    }
  }
;
  OnTouchListener rootListener=new OnTouchListener(){
    public boolean onTouch(    View v,    MotionEvent event){
      buttonListener.onTouch(v,event);
      mGestureDetector.onTouchEvent(event);
      return true;
    }
  }
;
  mNextImageView.setOnTouchListener(buttonListener);
  mPrevImageView.setOnTouchListener(buttonListener);
  rootView.setOnTouchListener(rootListener);
}
 

Example 2

From project Alerte-voirie-android, under directory /src/net/londatiga/android/.

Source file: CustomPopupWindow.java

  22 
vote

/** 
 * Create a QuickAction
 * @param anchor the view that the QuickAction will be displaying 'from'
 */
public CustomPopupWindow(View anchor){
  this.anchor=anchor;
  this.window=new PopupWindow(anchor.getContext());
  window.setTouchInterceptor(new OnTouchListener(){
    @Override public boolean onTouch(    View v,    MotionEvent event){
      if (event.getAction() == MotionEvent.ACTION_OUTSIDE) {
        CustomPopupWindow.this.window.dismiss();
        return true;
      }
      return false;
    }
  }
);
  windowManager=(WindowManager)anchor.getContext().getSystemService(Context.WINDOW_SERVICE);
  onCreate();
}
 

Example 3

From project Ebento, under directory /src/mobisocial/bento/ebento/ui/quickaction/.

Source file: PopupWindows.java

  22 
vote

/** 
 * Constructor.
 * @param context Context
 */
public PopupWindows(Context context){
  mContext=context;
  mWindow=new PopupWindow(context);
  mWindow.setTouchInterceptor(new OnTouchListener(){
    @Override public boolean onTouch(    View v,    MotionEvent event){
      if (event.getAction() == MotionEvent.ACTION_OUTSIDE) {
        mWindow.dismiss();
        return true;
      }
      return false;
    }
  }
);
  mWindowManager=(WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
}
 

Example 4

From project FlickrCity, under directory /src/com/FlickrCity/FlickrCityAndroid/Overlays/.

Source file: BalloonItemizedOverlay.java

  22 
vote

/** 
 * Sets the onTouchListener for the balloon being displayed, calling the overridden onBalloonTap if implemented.
 * @param thisIndex - The index of the item whose balloon is tapped.
 */
private void setBalloonTouchListener(final int thisIndex){
  try {
    @SuppressWarnings("unused") Method m=this.getClass().getDeclaredMethod("onBalloonTap",int.class);
    clickRegion.setOnTouchListener(new OnTouchListener(){
      public boolean onTouch(      View v,      MotionEvent event){
        View l=((View)v.getParent()).findViewById(R.id.balloon_main_layout);
        Drawable d=l.getBackground();
        if (event.getAction() == MotionEvent.ACTION_DOWN) {
          int[] states={android.R.attr.state_pressed};
          if (d.setState(states)) {
            d.invalidateSelf();
          }
          return true;
        }
 else         if (event.getAction() == MotionEvent.ACTION_UP) {
          int newStates[]={};
          if (d.setState(newStates)) {
            d.invalidateSelf();
          }
          onBalloonTap(thisIndex);
          return true;
        }
 else {
          return false;
        }
      }
    }
);
  }
 catch (  SecurityException e) {
    Log.e("BalloonItemizedOverlay","setBalloonTouchListener reflection SecurityException");
    return;
  }
catch (  NoSuchMethodException e) {
    return;
  }
}
 

Example 5

From project gobandroid, under directory /src/org/ligi/gobandroid_hd/ui/.

Source file: BetterPopupWindow.java

  22 
vote

/** 
 * Create a BetterPopupWindow
 * @param anchor the view that the BetterPopupWindow will be displaying 'from'
 */
public BetterPopupWindow(View anchor){
  this.anchor=anchor;
  this.window=new PopupWindow(anchor.getContext());
  this.window.setTouchInterceptor(new OnTouchListener(){
    @Override public boolean onTouch(    View v,    MotionEvent event){
      if (event.getAction() == MotionEvent.ACTION_OUTSIDE) {
        BetterPopupWindow.this.window.dismiss();
        return true;
      }
      return false;
    }
  }
);
  this.windowManager=(WindowManager)this.anchor.getContext().getSystemService(Context.WINDOW_SERVICE);
  onCreate();
}
 

Example 6

From project maven-android-plugin-samples, under directory /apidemos-android-10/application/src/main/java/com/example/android/apis/view/.

Source file: SecureView.java

  22 
vote

private void setTouchFilter(Button button){
  button.setOnTouchListener(new OnTouchListener(){
    public boolean onTouch(    View v,    MotionEvent event){
      if ((event.getFlags() & MotionEvent.FLAG_WINDOW_IS_OBSCURED) != 0) {
        if (event.getAction() == MotionEvent.ACTION_UP) {
          new AlertDialog.Builder(SecureView.this).setTitle(R.string.secure_view_caught_dialog_title).setMessage(R.string.secure_view_caught_dialog_message).setNeutralButton(getResources().getString(R.string.secure_view_caught_dialog_dismiss),null).show();
        }
        return true;
      }
      return false;
    }
  }
);
}
 

Example 7

From project mediautilities, under directory /src/ac/robinson/util/.

Source file: UIUtilities.java

  22 
vote

/** 
 * Set colour filters for a button so that the standard resources can be used in different colours
 * @param button The button to set colour filters for
 * @param defaultColor The normal (untouched) colour for the button
 * @param touchedColor The touch colour - currently ignored. For API 11 and above the coloured filter is applied tothe touched button; for For API 10 and below the normal platform button touch colour is used
 */
public static void setButtonColorFilters(View button,final Integer defaultColor,final int touchedColor){
  final LightingColorFilter normalColour=new LightingColorFilter(defaultColor,0x00000000);
  button.getBackground().setColorFilter(normalColour);
  button.setOnTouchListener(new OnTouchListener(){
    Rect viewRect;
    private void setNormalColour(    View v){
      v.getBackground().setColorFilter(normalColour);
    }
    private void setTouchedColour(    View v){
      if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.HONEYCOMB) {
        v.getBackground().clearColorFilter();
      }
 else {
      }
    }
    @Override public boolean onTouch(    View v,    MotionEvent event){
      int eventAction=event.getAction();
      if (eventAction == MotionEvent.ACTION_DOWN) {
        viewRect=new Rect(v.getLeft(),v.getTop(),v.getRight(),v.getBottom());
        setTouchedColour(v);
      }
 else       if (eventAction == MotionEvent.ACTION_MOVE) {
        if (!viewRect.contains(v.getLeft() + (int)event.getX(),v.getTop() + (int)event.getY())) {
          setNormalColour(v);
        }
 else {
          setTouchedColour(v);
        }
      }
 else       if (eventAction == MotionEvent.ACTION_UP || eventAction == MotionEvent.ACTION_CANCEL) {
        setNormalColour(v);
      }
      return false;
    }
  }
);
}
 

Example 8

From project MIT-Mobile-for-Android, under directory /src/edu/mit/mitmobile2/maps/.

Source file: MITBaseItemizedOverlay.java

  22 
vote

/** 
 */
protected void makeBalloon(final PinItem p){
  GeoPoint gp=p.getPoint();
  mapView.removeView(balloonView);
  balloonView=new BalloonOverlayView(mContext,mBubbleOffset);
  clickableRegion=balloonView.findViewById(R.id.balloon_inner_layout);
  clickableRegion.setOnTouchListener(new OnTouchListener(){
    @Override public boolean onTouch(    View v,    MotionEvent event){
      View l=((View)v.getParent()).findViewById(R.id.balloon_main_layout);
      Drawable d=l.getBackground();
      if (event.getAction() == MotionEvent.ACTION_DOWN) {
        int[] states={android.R.attr.state_pressed};
        if (d.setState(states)) {
          d.invalidateSelf();
        }
        return true;
      }
 else       if (event.getAction() == MotionEvent.ACTION_UP) {
        int newStates[]={};
        if (d.setState(newStates)) {
          d.invalidateSelf();
        }
        handleTap(p);
        return true;
      }
 else {
        return false;
      }
    }
  }
);
  balloonView.setData(p);
  MapView.LayoutParams params=new MapView.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT,gp,MapView.LayoutParams.BOTTOM_CENTER);
  params.mode=MapView.LayoutParams.MODE_MAP;
  balloonView.setVisibility(View.VISIBLE);
  balloonView.setLayoutParams(params);
  mc.animateTo(gp);
  mapView.addView(balloonView);
}
 

Example 9

From project MyExpenses, under directory /src/org/example/qberticus/quickactions/.

Source file: BetterPopupWindow.java

  22 
vote

/** 
 * Create a BetterPopupWindow
 * @param anchor the view that the BetterPopupWindow will be displaying 'from'
 */
public BetterPopupWindow(View anchor){
  this.anchor=anchor;
  this.window=new PopupWindow(anchor.getContext());
  this.window.setTouchInterceptor(new OnTouchListener(){
    @Override public boolean onTouch(    View v,    MotionEvent event){
      if (event.getAction() == MotionEvent.ACTION_OUTSIDE) {
        BetterPopupWindow.this.window.dismiss();
        return true;
      }
      return false;
    }
  }
);
  this.windowManager=(WindowManager)this.anchor.getContext().getSystemService(Context.WINDOW_SERVICE);
  onCreate();
}
 

Example 10

From project ohmagePhone, under directory /src/org/ohmage/feedback/visualization/.

Source file: BalloonItemizedOverlay.java

  22 
vote

/** 
 * Sets the onTouchListener for the balloon being displayed, calling the overridden onBalloonTap if implemented.
 * @param thisIndex - The index of the item whose balloon is tapped.
 */
private void setBalloonTouchListener(final int thisIndex){
  try {
    @SuppressWarnings("unused") Method m=this.getClass().getDeclaredMethod("onBalloonTap",int.class);
    clickRegion.setOnTouchListener(new OnTouchListener(){
      @Override public boolean onTouch(      View v,      MotionEvent event){
        View l=((View)v.getParent()).findViewById(R.id.balloon_main_layout);
        Drawable d=l.getBackground();
        if (event.getAction() == MotionEvent.ACTION_DOWN) {
          int[] states={android.R.attr.state_pressed};
          if (d.setState(states)) {
            d.invalidateSelf();
          }
          return true;
        }
 else         if (event.getAction() == MotionEvent.ACTION_UP) {
          int newStates[]={};
          if (d.setState(newStates)) {
            d.invalidateSelf();
          }
          onBalloonTap(thisIndex);
          return true;
        }
 else {
          return false;
        }
      }
    }
);
  }
 catch (  SecurityException e) {
    Log.e(TAG,"setBalloonTouchListener reflection SecurityException");
    return;
  }
catch (  NoSuchMethodException e) {
    Log.e(TAG,"setBalloonTouchListener reflection NoSuchMethodException");
    return;
  }
}
 

Example 11

From project Ohmage_Phone, under directory /src/org/ohmage/feedback/visualization/.

Source file: BalloonItemizedOverlay.java

  22 
vote

/** 
 * Sets the onTouchListener for the balloon being displayed, calling the overridden onBalloonTap if implemented.
 * @param thisIndex - The index of the item whose balloon is tapped.
 */
private void setBalloonTouchListener(final int thisIndex){
  try {
    @SuppressWarnings("unused") Method m=this.getClass().getDeclaredMethod("onBalloonTap",int.class);
    clickRegion.setOnTouchListener(new OnTouchListener(){
      public boolean onTouch(      View v,      MotionEvent event){
        View l=((View)v.getParent()).findViewById(R.id.balloon_main_layout);
        Drawable d=l.getBackground();
        if (event.getAction() == MotionEvent.ACTION_DOWN) {
          int[] states={android.R.attr.state_pressed};
          if (d.setState(states)) {
            d.invalidateSelf();
          }
          return true;
        }
 else         if (event.getAction() == MotionEvent.ACTION_UP) {
          int newStates[]={};
          if (d.setState(newStates)) {
            d.invalidateSelf();
          }
          onBalloonTap(thisIndex);
          return true;
        }
 else {
          return false;
        }
      }
    }
);
  }
 catch (  SecurityException e) {
    Log.e("BalloonItemizedOverlay","setBalloonTouchListener reflection SecurityException");
    return;
  }
catch (  NoSuchMethodException e) {
    return;
  }
}
 

Example 12

From project OpenBike, under directory /src/fr/openbike/android/ui/.

Source file: BalloonItemizedOverlay.java

  22 
vote

/** 
 * Sets the onTouchListener for the balloon being displayed, calling the overridden  {@link #onBalloonTap} method.
 */
private OnTouchListener createBalloonTouchListener(){
  return new OnTouchListener(){
    public boolean onTouch(    View v,    MotionEvent event){
      View l=((View)v.getParent()).findViewById(R.id.balloon_main_layout);
      Drawable d=l.getBackground();
      if (event.getAction() == MotionEvent.ACTION_DOWN) {
        int[] states={android.R.attr.state_pressed};
        if (d.setState(states)) {
          d.invalidateSelf();
        }
        return true;
      }
 else       if (event.getAction() == MotionEvent.ACTION_UP) {
        int newStates[]={};
        if (d.setState(newStates)) {
          d.invalidateSelf();
        }
        onBalloonTap(currentFocussedIndex,currentFocussedItem);
        return true;
      }
 else {
        return false;
      }
    }
  }
;
}
 

Example 13

From project platform_packages_apps_Gallery, under directory /src/com/android/camera/.

Source file: ViewImage.java

  22 
vote

private void setupOnTouchListeners(View rootView){
  mGestureDetector=new GestureDetector(this,new MyGestureListener());
  final OnTouchListener buttonListener=new OnTouchListener(){
    public boolean onTouch(    View v,    MotionEvent event){
      scheduleDismissOnScreenControls();
      return false;
    }
  }
;
  OnTouchListener rootListener=new OnTouchListener(){
    public boolean onTouch(    View v,    MotionEvent event){
      buttonListener.onTouch(v,event);
      mGestureDetector.onTouchEvent(event);
      return true;
    }
  }
;
  mNextImageView.setOnTouchListener(buttonListener);
  mPrevImageView.setOnTouchListener(buttonListener);
  rootView.setOnTouchListener(rootListener);
}
 

Example 14

From project randgen, under directory /src/app/randgen/backend/.

Source file: TouchSeeder.java

  22 
vote

@Override public void getNewSeed(Activity myActivity){
  final Dialog dialog=new Dialog(myActivity);
  dialog.setContentView(R.layout.touchseedview);
  dialog.setTitle("Seeding...");
  seedSamples=0;
  final ProgressBar seedProgress=(ProgressBar)dialog.findViewById(R.id.touchSeedingProgress);
  seedProgress.setMax(numSeedSamples);
  final LinearLayout touchField=(LinearLayout)dialog.findViewById(R.id.touchField);
  touchField.setOnTouchListener(new OnTouchListener(){
    private float prevX=0, prevY=0;
    @Override public boolean onTouch(    View v,    MotionEvent event){
      if (seedSamples > numSeedSamples) {
        touchField.setOnTouchListener(null);
        dialog.setTitle("Seed Generated");
        touchField.setVisibility(View.INVISIBLE);
        touchField.setMinimumHeight(0);
        TextView infoText=(TextView)dialog.findViewById(R.id.touchInfo);
        infoText.setText("Press Back to continue...");
        RandGenApp.getRandomGenerator().getSeed();
      }
 else {
        seed=seed - Math.round((event.getX() - prevX) * (event.getY() - prevY));
        prevX=event.getX();
        prevY=event.getY();
        seedSamples++;
        seedProgress.setProgress(seedSamples);
      }
      return true;
    }
  }
);
  dialog.show();
}
 

Example 15

From project RA_Launcher, under directory /src/com/dympy/QuickAction/.

Source file: PopupWindows.java

  22 
vote

/** 
 * Constructor.
 * @param context Context
 */
public PopupWindows(Context context){
  mContext=context;
  mWindow=new PopupWindow(context);
  mWindow.setTouchInterceptor(new OnTouchListener(){
    @Override public boolean onTouch(    View v,    MotionEvent event){
      if (event.getAction() == MotionEvent.ACTION_OUTSIDE) {
        mWindow.dismiss();
        return true;
      }
      return false;
    }
  }
);
  mWindowManager=(WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
}
 

Example 16

From project RingPack, under directory /src/com/cryclops/ringpack/actionitems/.

Source file: CustomPopupWindow.java

  22 
vote

/** 
 * Create a QuickAction
 * @param anchor the view that the QuickAction will be displaying 'from'
 */
public CustomPopupWindow(View anchor){
  this.anchor=anchor;
  this.window=new PopupWindow(anchor.getContext());
  window.setTouchInterceptor(new OnTouchListener(){
    @Override public boolean onTouch(    View v,    MotionEvent event){
      if (event.getAction() == MotionEvent.ACTION_OUTSIDE) {
        CustomPopupWindow.this.window.dismiss();
        return true;
      }
      return false;
    }
  }
);
  windowManager=(WindowManager)anchor.getContext().getSystemService(Context.WINDOW_SERVICE);
  onCreate();
}
 

Example 17

From project roman10-android-tutorial, under directory /dash/src/roman10/quickactionwindow/.

Source file: CustomPopupWindow3.java

  22 
vote

/** 
 * Constructor.
 * @param context Context
 */
public CustomPopupWindow3(Context context){
  mContext=context;
  mWindow=new PopupWindow(context);
  mWindow.setTouchInterceptor(new OnTouchListener(){
    public boolean onTouch(    View v,    MotionEvent event){
      if (event.getAction() == MotionEvent.ACTION_OUTSIDE) {
        mWindow.dismiss();
        return true;
      }
      return false;
    }
  }
);
  mWindowManager=(WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
}
 

Example 18

From project speech_trainer, under directory /app/src/mixedbit/speechtrainer/view/.

Source file: TrainingActivity.java

  22 
vote

private void configureButtons(){
  recordButton.setOnTouchListener(new OnTouchListener(){
    @Override public boolean onTouch(    View v,    MotionEvent event){
      if (event.getAction() == MotionEvent.ACTION_DOWN) {
        interactiveTrainingController.record();
      }
 else       if (event.getAction() == MotionEvent.ACTION_UP) {
        interactiveTrainingController.play();
      }
      return false;
    }
  }
);
  replayButton.setOnClickListener(new OnClickListener(){
    @Override public void onClick(    View arg){
      if (replayButton.isEnabled()) {
        interactiveTrainingController.play();
      }
    }
  }
);
}
 

Example 19

From project SVQCOM, under directory /Core/src/com/ushahidi/android/app/checkin/.

Source file: CheckinItemizedOverlay.java

  22 
vote

/** 
 * Sets the onTouchListener for the balloon being displayed, calling the overridden onBalloonTap if implemented.
 * @param thisIndex - The index of the item whose balloon is tapped.
 */
private void setBalloonTouchListener(final int thisIndex){
  try {
    @SuppressWarnings("unused") Method m=this.getClass().getDeclaredMethod("onBalloonTap",int.class);
    clickRegion.setOnTouchListener(new OnTouchListener(){
      public boolean onTouch(      View v,      MotionEvent event){
        View l=((View)v.getParent()).findViewById(R.id.balloon_main_layout);
        Drawable d=l.getBackground();
        if (event.getAction() == MotionEvent.ACTION_DOWN) {
          int[] states={android.R.attr.state_pressed};
          if (d.setState(states)) {
            d.invalidateSelf();
          }
          return true;
        }
 else         if (event.getAction() == MotionEvent.ACTION_UP) {
          int newStates[]={};
          if (d.setState(newStates)) {
            d.invalidateSelf();
          }
          onBalloonTap(thisIndex);
          return true;
        }
 else {
          return false;
        }
      }
    }
);
  }
 catch (  SecurityException e) {
    return;
  }
catch (  NoSuchMethodException e) {
    return;
  }
}
 

Example 20

From project android-bankdroid, under directory /src/com/liato/bankdroid/.

Source file: BetterPopupWindow.java

  21 
vote

/** 
 * Create a BetterPopupWindow
 * @param anchor the view that the BetterPopupWindow will be displaying 'from'
 */
public BetterPopupWindow(View anchor){
  this.anchor=anchor;
  this.window=new PopupWindow(anchor.getContext());
  this.window.setTouchInterceptor(new OnTouchListener(){
    @Override public boolean onTouch(    View v,    MotionEvent event){
      if (event.getAction() == MotionEvent.ACTION_OUTSIDE) {
        BetterPopupWindow.this.window.dismiss();
        return true;
      }
      return false;
    }
  }
);
  this.windowManager=(WindowManager)this.anchor.getContext().getSystemService(Context.WINDOW_SERVICE);
  onCreate();
}
 

Example 21

From project android-mapviewballoons, under directory /android-mapviewballoons/src/com/readystatesoftware/mapviewballoons/.

Source file: BalloonItemizedOverlay.java

  21 
vote

/** 
 * Sets the onTouchListener for the balloon being displayed, calling the overridden  {@link #onBalloonTap} method.
 */
private OnTouchListener createBalloonTouchListener(){
  return new OnTouchListener(){
    float startX;
    float startY;
    public boolean onTouch(    View v,    MotionEvent event){
      View l=((View)v.getParent()).findViewById(R.id.balloon_main_layout);
      Drawable d=l.getBackground();
      if (event.getAction() == MotionEvent.ACTION_DOWN) {
        if (d != null) {
          int[] states={android.R.attr.state_pressed};
          if (d.setState(states)) {
            d.invalidateSelf();
          }
        }
        startX=event.getX();
        startY=event.getY();
        return true;
      }
 else       if (event.getAction() == MotionEvent.ACTION_UP) {
        if (d != null) {
          int newStates[]={};
          if (d.setState(newStates)) {
            d.invalidateSelf();
          }
        }
        if (Math.abs(startX - event.getX()) < 40 && Math.abs(startY - event.getY()) < 40) {
          onBalloonTap(currentFocusedIndex,currentFocusedItem);
        }
        return true;
      }
 else {
        return false;
      }
    }
  }
;
}
 

Example 22

From project android_packages_apps_Superuser, under directory /src/com/noshufou/android/su/widget/.

Source file: BetterPopupWindow.java

  21 
vote

/** 
 * Create a BetterPopupWindow
 * @param anchor the view that the BetterPopupWindow will be displaying 'from'
 */
public BetterPopupWindow(View anchor){
  this.anchor=anchor;
  this.window=new PopupWindow(anchor.getContext());
  this.window.setTouchInterceptor(new OnTouchListener(){
    @Override public boolean onTouch(    View v,    MotionEvent event){
      if (event.getAction() == MotionEvent.ACTION_OUTSIDE) {
        BetterPopupWindow.this.window.dismiss();
        return true;
      }
      return false;
    }
  }
);
  this.windowManager=(WindowManager)this.anchor.getContext().getSystemService(Context.WINDOW_SERVICE);
  onCreate();
}
 

Example 23

From project CityBikes, under directory /src/net/homelinux/penecoptero/android/citybikes/app/.

Source file: MainActivity.java

  21 
vote

protected void applyMapViewLongPressListener(MapView mapView){
  final MapView finalMapView=mapView;
  final GestureDetector gd=new GestureDetector(new GestureDetector.SimpleOnGestureListener(){
    @Override public void onLongPress(    MotionEvent e){
      Projection astral=finalMapView.getProjection();
      GeoPoint center=astral.fromPixels((int)e.getX(),(int)e.getY());
      locator.lockCenter(center);
    }
    @Override public boolean onDoubleTap(    MotionEvent e){
      Projection astral=finalMapView.getProjection();
      GeoPoint center=astral.fromPixels((int)e.getX(),(int)e.getY());
      locator.lockCenter(center);
      return super.onDoubleTap(e);
    }
  }
);
  mapView.setOnTouchListener(new OnTouchListener(){
    @Override public boolean onTouch(    View v,    MotionEvent ev){
      return gd.onTouchEvent(ev);
    }
  }
);
}
 

Example 24

From project dungbeetle, under directory /src/edu/stanford/mobisocial/dungbeetle/.

Source file: CustomPopupWindow.java

  21 
vote

/** 
 * Create a QuickAction
 * @param anchor the view that the QuickAction will be displaying 'from'
 */
public CustomPopupWindow(View anchor){
  this.anchor=anchor;
  this.window=new PopupWindow(anchor.getContext());
  window.setTouchInterceptor(new OnTouchListener(){
    @Override public boolean onTouch(    View v,    MotionEvent event){
      if (event.getAction() == MotionEvent.ACTION_OUTSIDE) {
        CustomPopupWindow.this.window.dismiss();
        return true;
      }
      return false;
    }
  }
);
  windowManager=(WindowManager)anchor.getContext().getSystemService(Context.WINDOW_SERVICE);
  onCreate();
}
 

Example 25

From project SMSSync, under directory /smssync/src/org/addhen/smssync/views/.

Source file: AddSyncUrl.java

  21 
vote

/** 
 * Handles views for the add dialog box
 * @param dialogViews
 */
public AddSyncUrl(final android.view.View dialogViews){
  title=(EditText)dialogViews.findViewById(R.id.sync_url_title);
  keywords=(EditText)dialogViews.findViewById(R.id.sync_url_keyword);
  secret=(EditText)dialogViews.findViewById(R.id.sync_url_secret);
  url=(EditText)dialogViews.findViewById(R.id.sync_url);
  url.setOnTouchListener(new OnTouchListener(){
    public boolean onTouch(    View v,    MotionEvent event){
      if (TextUtils.isEmpty(url.getText().toString())) {
        url.setText(dialogViews.getContext().getString(R.string.http_text));
      }
      return false;
    }
  }
);
}
 

Example 26

From project tramhunter, under directory /android/TramHunter/src/com/andybotting/tramhunter/ui/.

Source file: BalloonItemizedOverlay.java

  21 
vote

/** 
 * Sets the onTouchListener for the balloon being displayed, calling the overridden onBalloonTap if implemented.
 * @param thisIndex - The index of the item whose balloon is tapped.
 */
private void setBalloonTouchListener(final int thisIndex){
  try {
    @SuppressWarnings("unused") Method m=this.getClass().getDeclaredMethod("onBalloonTap",int.class);
    clickRegion.setOnTouchListener(new OnTouchListener(){
      public boolean onTouch(      View v,      MotionEvent event){
        View l=((View)v.getParent()).findViewById(R.id.balloon_main_layout);
        Drawable d=l.getBackground();
        if (event.getAction() == MotionEvent.ACTION_DOWN) {
          int[] states={android.R.attr.state_pressed};
          if (d.setState(states)) {
            d.invalidateSelf();
          }
          return true;
        }
 else         if (event.getAction() == MotionEvent.ACTION_UP) {
          int newStates[]={};
          if (d.setState(newStates)) {
            d.invalidateSelf();
          }
          onBalloonTap(thisIndex);
          return true;
        }
 else {
          return false;
        }
      }
    }
);
  }
 catch (  SecurityException e) {
    Log.e("BalloonItemizedOverlay","setBalloonTouchListener reflection SecurityException");
    return;
  }
catch (  NoSuchMethodException e) {
    return;
  }
}
 

Example 27

From project Ushahidi_Android, under directory /Core/src/com/ushahidi/android/app/.

Source file: MapItemizedOverlay.java

  20 
vote

/** 
 * Sets the onTouchListener for the balloon being displayed, calling the overridden  {@link #onBalloonTap} method.
 */
private OnTouchListener createBalloonTouchListener(){
  return new OnTouchListener(){
    float startX;
    float startY;
    public boolean onTouch(    View v,    MotionEvent event){
      View l=((View)v.getParent()).findViewById(R.id.balloon_main_layout);
      Drawable d=l.getBackground();
      if (event.getAction() == MotionEvent.ACTION_DOWN) {
        int[] states={android.R.attr.state_pressed};
        if (d.setState(states)) {
          d.invalidateSelf();
        }
        startX=event.getX();
        startY=event.getY();
        return true;
      }
 else       if (event.getAction() == MotionEvent.ACTION_UP) {
        int newStates[]={};
        if (d.setState(newStates)) {
          d.invalidateSelf();
        }
        if (Math.abs(startX - event.getX()) < 40 && Math.abs(startY - event.getY()) < 40) {
          onBalloonTap(currentFocusedIndex,currentFocusedItem);
        }
        return true;
      }
 else {
        return false;
      }
    }
  }
;
}
 

Example 28

From project aksunai, under directory /src/org/androidnerds/app/aksunai/ui/.

Source file: ChatActivity.java

  19 
vote

@Override public void onCreate(Bundle appState){
  super.onCreate(appState);
  setContentView(R.layout.chat);
  slideLeftIn=AnimationUtils.loadAnimation(this,R.anim.slide_left_in);
  slideLeftOut=AnimationUtils.loadAnimation(this,R.anim.slide_left_out);
  slideRightIn=AnimationUtils.loadAnimation(this,R.anim.slide_right_in);
  slideRightOut=AnimationUtils.loadAnimation(this,R.anim.slide_right_out);
  mFlipper=(ViewFlipper)findViewById(R.id.chat_flipper);
  entry=(EditText)findViewById(R.id.ircedit);
  entry.setSingleLine();
  entry.setOnKeyListener(mKeyListener);
  Button btnSend=(Button)findViewById(R.id.btnSend);
  btnSend.setOnClickListener(mClickListener);
  gestureDetector=new GestureDetector(new MyGestureDetector());
  gestureListener=new View.OnTouchListener(){
    public boolean onTouch(    View v,    MotionEvent event){
      return gestureDetector.onTouchEvent(event);
    }
  }
;
  mFlipper.setOnTouchListener(gestureListener);
  mNotificationManager=(NotificationManager)getSystemService(NOTIFICATION_SERVICE);
}
 

Example 29

From project droid-fu, under directory /src/main/java/com/github/droidfu/activities/.

Source file: BetterMapActivity.java

  19 
vote

protected void setMapGestureListener(MapGestureListener mapGestureListener){
  tapDetector=new GestureDetector(mapGestureListener);
  tapListener=new View.OnTouchListener(){
    public boolean onTouch(    View v,    MotionEvent event){
      if (tapDetector.onTouchEvent(event)) {
        return true;
      }
      return false;
    }
  }
;
  mapView.setOnTouchListener(tapListener);
}
 

Example 30

From project Gingerbread-Keyboard, under directory /src/com/android/inputmethod/latin/.

Source file: Tutorial.java

  19 
vote

void show(int offx,int offy){
  int textHeight=chooseSize(window,inputView,text,textView);
  offy-=textView.getPaddingTop() + textHeight;
  if (inputView.getVisibility() == View.VISIBLE && inputView.getWindowVisibility() == View.VISIBLE) {
    try {
      if ((gravity & Gravity.BOTTOM) == Gravity.BOTTOM)       offy-=window.getHeight();
      if ((gravity & Gravity.RIGHT) == Gravity.RIGHT)       offx-=window.getWidth();
      textView.setOnTouchListener(new View.OnTouchListener(){
        public boolean onTouch(        View view,        MotionEvent me){
          Tutorial.this.next();
          return true;
        }
      }
);
      window.showAtLocation(inputView,Gravity.NO_GRAVITY,x + offx,y + offy);
    }
 catch (    Exception e) {
    }
  }
}
 

Example 31

From project TeclaAccess, under directory /source/src/ca/idi/tekla/ime/.

Source file: Tutorial.java

  19 
vote

void show(int offx,int offy){
  int textHeight=chooseSize(window,inputView,text,textView);
  offy-=textView.getPaddingTop() + textHeight;
  if (inputView.getVisibility() == View.VISIBLE && inputView.getWindowVisibility() == View.VISIBLE) {
    try {
      if ((gravity & Gravity.BOTTOM) == Gravity.BOTTOM)       offy-=window.getHeight();
      if ((gravity & Gravity.RIGHT) == Gravity.RIGHT)       offx-=window.getWidth();
      textView.setOnTouchListener(new View.OnTouchListener(){
        public boolean onTouch(        View view,        MotionEvent me){
          Tutorial.this.next();
          return true;
        }
      }
);
      window.showAtLocation(inputView,Gravity.NO_GRAVITY,x + offx,y + offy);
    }
 catch (    Exception e) {
    }
  }
}