Example usage for android.widget ImageView setOnTouchListener

List of usage examples for android.widget ImageView setOnTouchListener

Introduction

In this page you can find the example usage for android.widget ImageView setOnTouchListener.

Prototype

public void setOnTouchListener(OnTouchListener l) 

Source Link

Document

Register a callback to be invoked when a touch event is sent to this view.

Usage

From source file:com.kasungunathilaka.sarigama.ui.HomeActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home:
        onBackPressed();/*  w  w w  .  j  a va  2  s  .c om*/
        break;
    case R.id.action_search:
        setFragment(new SearchFragment());
        break;
    case R.id.action_about_developer:
        AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(HomeActivity.this);
        View dialogView = getLayoutInflater().inflate(R.layout.dialog_view_about_developer, null);
        alertDialogBuilder.setView(dialogView);
        ImageView ivClose = (ImageView) dialogView.findViewById(R.id.ivClose);
        TextView tvEmail = (TextView) dialogView.findViewById(R.id.tvEmail);
        final AlertDialog alertDialog = alertDialogBuilder.create();
        tvEmail.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                if (event.getAction() == MotionEvent.ACTION_DOWN) {
                    Intent emailIntent = new Intent(Intent.ACTION_SEND);
                    emailIntent.setType("plain/text");
                    emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,
                            new String[] { "developer.kasun.gunathilaka@gmail.com" });
                    emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Sarigama");
                    emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "");
                    startActivity(emailIntent);
                    alertDialog.dismiss();
                }
                return false;
            }
        });
        ivClose.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                if (event.getAction() == MotionEvent.ACTION_DOWN) {
                    alertDialog.dismiss();
                }
                return false;
            }
        });
        alertDialog.show();
        break;
    case R.id.action_exit:
        finish();
        NotificationManager notificationManager = (NotificationManager) getSystemService(
                Context.NOTIFICATION_SERVICE);
        notificationManager.cancel(9999);
        System.exit(0);
        break;
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.openarc.nirmal.mytrack.ContactActivity.java

private void showContactDialog(final Contact contact) {
    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(ContactActivity.this);
    View dialogView = getLayoutInflater().inflate(R.layout.dialog_view_contact, null);
    alertDialogBuilder.setView(dialogView);
    ImageView ivClose = (ImageView) dialogView.findViewById(R.id.ivClose);
    ImageView ivBackground = (ImageView) dialogView.findViewById(R.id.ivBackground);
    ImageView civContactImage = (CircleImageView) dialogView.findViewById(R.id.civContactImage);
    TextView tvContactName = (TextView) dialogView.findViewById(R.id.tvContactName);
    TextView tvCallNumber = (TextView) dialogView.findViewById(R.id.tvCallNumber);
    TextView tvMessageNumber = (TextView) dialogView.findViewById(R.id.tvMessageNumber);

    CardView callCardView = (CardView) dialogView.findViewById(R.id.cvCall);
    CardView smsCardView = (CardView) dialogView.findViewById(R.id.cvSMS);
    CardView emailCardView = (CardView) dialogView.findViewById(R.id.cvEmail);

    TextView tvEmail = (TextView) dialogView.findViewById(R.id.tvEmail);
    Picasso.with(ContactActivity.this).load(contact.image).into(ivBackground);
    Picasso.with(ContactActivity.this).load(contact.image).into(civContactImage);
    tvContactName.setText(contact.name);
    tvCallNumber.setText(contact.mobile);
    tvMessageNumber.setText(contact.mobile);
    tvEmail.setText(contact.email);/*from   w ww .  j a  va 2  s. c  o m*/
    final AlertDialog alertDialog = alertDialogBuilder.create();
    ivClose.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_DOWN) {
                alertDialog.dismiss();
            }
            return false;
        }
    });

    callCardView.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_DOWN) {
                if (!contact.mobile.contentEquals("")) {
                    Intent callIntent = new Intent(Intent.ACTION_CALL);
                    callIntent.setData(Uri.parse("tel:" + contact.mobile));
                    if (ActivityCompat.checkSelfPermission(ContactActivity.this,
                            Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
                        showToast("Cannot Make a Call");
                    } else {
                        startActivity(callIntent);
                        alertDialog.dismiss();
                    }
                } else {
                    showToast("Not a valid mobile");
                }
            }
            return false;
        }
    });

    smsCardView.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_DOWN) {
                if (!contact.mobile.contentEquals("")) {
                    Intent sendIntent = new Intent(Intent.ACTION_VIEW);
                    sendIntent.setData(Uri.parse("sms:" + contact.mobile));
                    startActivity(sendIntent);
                    alertDialog.dismiss();
                } else {
                    showToast("Not a valid mobile");
                }
            }
            return false;
        }
    });

    emailCardView.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_DOWN) {
                if (!contact.email.contentEquals("")) {
                    Intent emailIntent = new Intent(Intent.ACTION_SEND);
                    emailIntent.setType("plain/text");
                    emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[] { contact.email });
                    emailIntent.putExtra(Intent.EXTRA_SUBJECT, "");
                    emailIntent.putExtra(Intent.EXTRA_TEXT, "");
                    startActivity(emailIntent);
                    alertDialog.dismiss();
                } else {
                    showToast("Not a valid email");
                }
            }
            return false;
        }
    });
    alertDialog.show();
}

From source file:uk.co.senab.photoview.PhotoViewAttacher.java

public PhotoViewAttacher(ImageView imageView, PdfiumCore pdfiumCore, PdfDocument pdfDocument, int pageIndex,
        float pageScale, boolean zoomable) {
    mImageView = new WeakReference<>(imageView);

    this.pdfiumCore = pdfiumCore;
    this.pdfDocument = pdfDocument;
    this.pageIndex = pageIndex;

    pdfiumCore.openPage(pdfDocument, pageIndex);
    originalBitmapSize.set((int) (pageScale * pdfiumCore.getPageWidthPoint(pdfDocument, pageIndex)),
            (int) (pageScale * pdfiumCore.getPageHeightPoint(pdfDocument, pageIndex)));

    imageView.setDrawingCacheEnabled(true);
    imageView.setOnTouchListener(this);

    ViewTreeObserver observer = imageView.getViewTreeObserver();
    if (null != observer)
        observer.addOnGlobalLayoutListener(this);

    // Make sure we using MATRIX Scale Type
    setImageViewScaleTypeMatrix(imageView);

    if (imageView.isInEditMode()) {
        return;/*  w w  w . ja  v a2  s  .co  m*/
    }
    // Create Gesture Detectors...
    mScaleDragDetector = VersionedGestureDetector.newInstance(imageView.getContext(), this);

    mGestureDetector = new GestureDetector(imageView.getContext(),
            new GestureDetector.SimpleOnGestureListener() {

                // forward long click listener
                @Override
                public void onLongPress(MotionEvent e) {
                    if (null != mLongClickListener) {
                        mLongClickListener.onLongClick(getImageView());
                    }
                }

                @Override
                public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
                    if (mSingleFlingListener != null) {
                        if (getScale() > DEFAULT_MIN_SCALE) {
                            return false;
                        }

                        if (MotionEventCompat.getPointerCount(e1) > SINGLE_TOUCH
                                || MotionEventCompat.getPointerCount(e2) > SINGLE_TOUCH) {
                            return false;
                        }

                        return mSingleFlingListener.onFling(e1, e2, velocityX, velocityY);
                    }
                    return false;
                }
            });

    mGestureDetector.setOnDoubleTapListener(new DefaultOnDoubleTapListener(this));
    // Finally, update the UI so that we're zoomable

    setZoomable(zoomable);
}

From source file:com.openarc.nirmal.mytrack.GatePassRequestActivity.java

private void showGatePassDialog() {
    mGatePassRequestDialogView = new GatePassRequestDialogView();
    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(GatePassRequestActivity.this);
    View dialogView = getLayoutInflater().inflate(R.layout.dialog_view_request_gate_pass, null);
    alertDialogBuilder.setView(dialogView);
    ImageView ivClose = (ImageView) dialogView.findViewById(R.id.ivClose);
    mGatePassRequestDialogView.tvDialogTitle = (TextView) dialogView.findViewById(R.id.tvDialogTitle);
    mGatePassRequestDialogView.etDate = (EditText) dialogView.findViewById(R.id.etDate);
    mGatePassRequestDialogView.etOut = (EditText) dialogView.findViewById(R.id.etOut);
    mGatePassRequestDialogView.etIn = (EditText) dialogView.findViewById(R.id.etIn);
    mGatePassRequestDialogView.etReason = (EditText) dialogView.findViewById(R.id.etReason);
    mGatePassRequestDialogView.tvDialogTitle.setText("Request Gate Pass");
    alertDialogBuilder.setPositiveButton("Request", new DialogInterface.OnClickListener() {
        @Override//from  w w w. j a  v  a2s. c om
        public void onClick(DialogInterface dialog, int which) {
        }
    });
    alertDialogBuilder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });
    final AlertDialog mAlertDialog = alertDialogBuilder.create();
    mGatePassRequestDialogView.etDate.setOnTouchListener(dateOnClick);
    mGatePassRequestDialogView.etIn.setOnTouchListener(inOnClick);
    mGatePassRequestDialogView.etOut.setOnTouchListener(outOnClick);
    ivClose.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_DOWN) {
                mAlertDialog.dismiss();
            }
            return false;
        }
    });
    mAlertDialog.show();
    Button mPositiveButton = mAlertDialog.getButton(DialogInterface.BUTTON_POSITIVE);
    mAlertDialog.getButton(DialogInterface.BUTTON_NEGATIVE)
            .setTextColor(getResources().getColor(R.color.colorAccent));
    mPositiveButton.setTextColor(getResources().getColor(R.color.colorPrimary));
    mPositiveButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            try {
                if (validate()) {
                    String date = mGatePassRequestDialogView.etDate.getText().toString();
                    String out = mGatePassRequestDialogView.etOut.getText().toString();
                    String in = mGatePassRequestDialogView.etIn.getText().toString();
                    String reason = mGatePassRequestDialogView.etReason.getText().toString();
                    String parameter;
                    try {
                        parameter = "DATE=" + date + "&TIMEOUT=" + URLEncoder.encode(out, "UTF-8") + "&TIMEIN="
                                + URLEncoder.encode(in, "UTF-8") + "&Reason="
                                + URLEncoder.encode(reason, "UTF-8");
                    } catch (UnsupportedEncodingException e) {
                        e.printStackTrace();
                        parameter = "";
                    }
                    new GatePassRequestTask("POST", parameter).execute();
                    showWaiting(GatePassRequestActivity.this);
                    mAlertDialog.dismiss();
                }
            } catch (ParseException e) {
                showToast("Time range validation error");
            }
        }
    });
}

From source file:com.first.akashshrivastava.showernow.ShowerActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main_shower_activity);

    /*Launching BootReceiver to test
    Intent playIntent = new Intent(getApplicationContext(), BootReceiver.class);
    startActivity(playIntent);//  w  ww  .  j a  va2  s .c  o  m
    */

    //Mobile ads initialization....The long number is the AdID, can be found on AdMob -  ca-app-pub-8782530512283806/2988799979
    MobileAds.initialize(getApplicationContext(), "ca-app-pub-8782530512283806/2988799979");
    AdView mAdView = (AdView) findViewById(R.id.adView);
    AdRequest adRequest = new AdRequest.Builder().build();
    mAdView.loadAd(adRequest);

    //Facebook SDK initialization...
    FacebookSdk.sdkInitialize(getApplicationContext());
    AppEventsLogger.activateApp(this);

    shareDialog = new ShareDialog(this);

    mDatabaseReference = FirebaseDatabase.getInstance().getReference();
    mFirebaseAuth = FirebaseAuth.getInstance();

    final ImageView genderImage = (ImageView) findViewById(R.id.imageGender);

    guyText = (TextView) findViewById(R.id.guyText);

    topText = (TextView) findViewById(R.id.textView2);

    SharedPreferences prefs = getSharedPreferences("myPrefs", Context.MODE_PRIVATE);

    extraAge = prefs.getInt("age", 0);
    extraFluffiness = prefs.getString("fluffiness", "");
    extraGender = prefs.getString("gender", "");
    extraOldTime = prefs.getLong("time", 0);
    extraSteps = prefs.getFloat("stepsBoot", 0);

    switch (extraGender) {
    case "male":
        genderImage.setImageResource(R.drawable.male_white_outline);
        break;
    case "female":
        genderImage.setImageResource(R.drawable.female_white_outline);
        break;
    case "other":
        genderImage.setImageResource(R.drawable.other_white_outline);
        break;
    }

    genderImage.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) { //set alarm
            //Swith ccase
            switch (event.getAction()) {

            case MotionEvent.ACTION_UP:
                // PRESSED ..PRESSED

                if (genderImage.getDrawable().getConstantState() == getResources()
                        .getDrawable(R.drawable.female_white_outline_pressed).getConstantState()) {
                    genderImage.setImageResource(R.drawable.female_white_outline);
                } else if (genderImage.getDrawable().getConstantState() == getResources()
                        .getDrawable(R.drawable.male_white_outline_pressed).getConstantState()) {
                    genderImage.setImageResource(R.drawable.male_white_outline);
                } else if (genderImage.getDrawable().getConstantState() == getResources()
                        .getDrawable(R.drawable.other_white_outline_pressed).getConstantState()) {
                    genderImage.setImageResource(R.drawable.other_white_outline);
                }

                //Resets the wave after shower..this is not getting called for some reason....
                waveProgressbar.setCurrent(0, "");
                guyText.setText("0 %");
                waveProgressbar.setVisibility(View.INVISIBLE);

                topText.setText("You have showered! \n When the wave hits 100% its time for your next shower ");

                if (fluffiness != null && gotSteps) {
                    Calendar cal = Calendar.getInstance();
                    Intent activate = new Intent(ShowerActivity.this, AlarmReceiver.class);
                    activate.putExtra("age", age);
                    activate.putExtra("fluffiness", fluffiness);
                    activate.putExtra("gender", gender);
                    activate.putExtra("steps", steps);
                    activate.putExtra("time", System.currentTimeMillis());

                    AlarmManager alarms;
                    PendingIntent alarmIntent = PendingIntent.getBroadcast(ShowerActivity.this, 0, activate,
                            FLAG_CANCEL_CURRENT);
                    alarms = (AlarmManager) getSystemService(ALARM_SERVICE);
                    alarms.cancel(alarmIntent);

                    alarms.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis() + 5000, 1000 * 60,
                            alarmIntent);//sets the alarm

                    mDatabaseReference.child("User").child(mFirebaseAuth.getCurrentUser().getUid())
                            .child("Steps").setValue(steps);//sets old steps
                    oldSteps = steps;
                    mDatabaseReference.child("User").child(mFirebaseAuth.getCurrentUser().getUid())
                            .child("Time").setValue(System.currentTimeMillis());
                    oldTime = System.currentTimeMillis();
                    newUser = false;

                    SharedPreferences sharedPref = getSharedPreferences("myPrefs", Context.MODE_PRIVATE);
                    SharedPreferences.Editor editor = sharedPref.edit();
                    editor.putInt("age", age);
                    editor.putString("fluffiness", fluffiness);
                    editor.putString("gender", gender);
                    editor.putFloat("steps", steps);
                    editor.putLong("time", System.currentTimeMillis());
                    editor.putFloat("stepsBoot", 0);
                    editor.putBoolean("bootStart", true);
                    editor.apply();

                } else if (!gotSteps) {
                    Toast.makeText(getApplicationContext(), "Waiting for steps", Toast.LENGTH_SHORT).show();
                }
                return true; // if you want to handle the touch event

            case MotionEvent.ACTION_DOWN:
                // RELEASED..RELEASED..

                if (genderImage.getDrawable().getConstantState() == getResources()
                        .getDrawable(R.drawable.female_white_outline).getConstantState()) {
                    genderImage.setImageResource(R.drawable.female_white_outline_pressed);

                } else if (genderImage.getDrawable().getConstantState() == getResources()
                        .getDrawable(R.drawable.male_white_outline).getConstantState()) {
                    genderImage.setImageResource(R.drawable.male_white_outline_pressed);

                } else if (genderImage.getDrawable().getConstantState() == getResources()
                        .getDrawable(R.drawable.other_white_outline).getConstantState()) {
                    genderImage.setImageResource(R.drawable.other_white_outline_pressed);

                }

                return true; // if you want to handle the touch event
            }
            //Switch case end bracket

            return false;
        }

    });

    createWave();
    setMenuColor();
    setupStepcount();
    setWaveHeight();

    FloatingActionButton editDetails = (FloatingActionButton) findViewById(R.id.menu_item4); //edit user information. Goes to main activity
    editDetails.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {

            /*
            Fragment fragment = new Fragment();
            FragmentTransaction transaction = manager.beginTransaction();
            transaction.add(ShowerActivity.java);
            transaction.addToBackStack(ShowerActivity.java);
            transaction.commit();
                    
            */
            //Fragment B at pos 2 should open when edit details is pressed..
            Intent i = new Intent(ShowerActivity.this, MainActivity.class);
            i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            startActivity(i);
        }
    });

    FloatingActionButton fabmenuDeleteAccount = (FloatingActionButton) findViewById(R.id.delete_Account);
    fabmenuDeleteAccount.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            dialog();
        }
    });

    FloatingActionButton fabMenuItem1 = (FloatingActionButton) findViewById(R.id.menu_item);
    fabMenuItem1.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            /*ComponentName receiver = new ComponentName(ShowerActivity.this, AlarmReceiver.class); // alarms.cancel(alarmIntent);??
            PackageManager pm = ShowerActivity.this.getPackageManager();
            pm.setComponentEnabledSetting(receiver,
                PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
                PackageManager.DONT_KILL_APP);
                    
            stopService(new Intent(StepCountService.STEP_COUNT_SERVICE));*/

            //mFirebaseAuth.getCurrentUser().getUid() =null;

            SharedPreferences sharedPref = getSharedPreferences("myPrefs", Context.MODE_PRIVATE);
            SharedPreferences.Editor editor = sharedPref.edit();
            editor.putInt("age", 0);
            editor.putString("fluffiness", "");
            editor.putString("gender", "");
            editor.putFloat("steps", 0);
            editor.putLong("time", 0);
            editor.putFloat("stepsBoot", 0);
            editor.putBoolean("bootStart", false);
            editor.apply();

            Intent activate = new Intent(ShowerActivity.this, AlarmReceiver.class);
            PendingIntent alarmIntent = PendingIntent.getBroadcast(ShowerActivity.this, 0, activate,
                    FLAG_CANCEL_CURRENT);

            AlarmManager alarms = (AlarmManager) getSystemService(ALARM_SERVICE);
            alarms.cancel(alarmIntent);

            stopService(new Intent(ShowerActivity.this, StepCountService.class));

            mFirebaseAuth.getInstance().signOut();
            Intent i = new Intent(ShowerActivity.this, LoginActivity.class);
            startActivity(i);
        }
    });

    final FloatingActionButton shareButton = (FloatingActionButton) findViewById(R.id.shareButton);
    shareButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {

            Intent shareIntent = new Intent(Intent.ACTION_SEND);
            shareIntent.setType("text/plain");
            String shareBody = "Check out this showering app at: https://play.google.com/store/apps/details?id=com.first.akashshrivastava.showernow \n";
            String shareSubString = "An app that tells you when you should shower and apparently keeps you clean";
            shareIntent.putExtra(Intent.EXTRA_SUBJECT, shareSubString);
            shareIntent.putExtra(Intent.EXTRA_TEXT, shareBody);
            startActivity(Intent.createChooser(shareIntent, " Share using the following"));

        }
    });

    mDatabaseReference.addListenerForSingleValueEvent(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot snap) {

            try {
                if ((!(mFirebaseAuth.getCurrentUser().getUid().isEmpty()))
                        && snap.child("User").child(mFirebaseAuth.getCurrentUser().getUid()).child("gender")
                                .getValue().toString().equalsIgnoreCase("female")) {
                    genderImage.setImageResource(R.drawable.female_white_outline);
                } else if (snap.child("User").child(mFirebaseAuth.getCurrentUser().getUid()).child("gender")
                        .getValue().toString().equalsIgnoreCase("male")) {
                    genderImage.setImageResource(R.drawable.male_white_outline);
                } else if (snap.child("User").child(mFirebaseAuth.getCurrentUser().getUid()).child("gender")
                        .getValue().toString().equalsIgnoreCase("other")) {
                    genderImage.setImageResource(R.drawable.other_white_outline);
                }

            } catch (Exception e) {
                e.printStackTrace();
            }
            age = Integer.parseInt(snap.child("User").child(mFirebaseAuth.getCurrentUser().getUid())
                    .child("Age").getValue().toString());//gotta get int

            fluffiness = snap.child("User").child(mFirebaseAuth.getCurrentUser().getUid()).child("gender")
                    .getValue().toString();
            gender = snap.child("User").child(mFirebaseAuth.getCurrentUser().getUid()).child("gender")
                    .getValue().toString();

            if (snap.child("User").child(mFirebaseAuth.getCurrentUser().getUid()).child("Time").exists()) {
                oldTime = snap.child("User").child(mFirebaseAuth.getCurrentUser().getUid()).child("Time")
                        .getValue(Long.class);
                oldSteps = snap.child("User").child(mFirebaseAuth.getCurrentUser().getUid()).child("Steps")
                        .getValue(float.class);

            } else {
                newUser = true;
            }
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {

        }
    });
}

From source file:com.openarc.nirmal.mytrack.MeetingRoomActivity.java

private void showMeetingRoomDialog() {
    mMeetingRoomDialogView = new MeetingRoomDialogView();
    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(MeetingRoomActivity.this);
    View dialogView = getLayoutInflater().inflate(R.layout.dialog_view_meeting_room, null);
    alertDialogBuilder.setView(dialogView);
    ImageView ivClose = (ImageView) dialogView.findViewById(R.id.ivClose);
    mMeetingRoomDialogView.tvDialogTitle = (TextView) dialogView.findViewById(R.id.tvDialogTitle);
    mMeetingRoomDialogView.spLocation = (Spinner) dialogView.findViewById(R.id.spLocation);
    mMeetingRoomDialogView.etDate = (EditText) dialogView.findViewById(R.id.etDate);
    mMeetingRoomDialogView.etFrom = (EditText) dialogView.findViewById(R.id.etFrom);
    mMeetingRoomDialogView.etTo = (EditText) dialogView.findViewById(R.id.etTo);
    mMeetingRoomDialogView.etReason = (EditText) dialogView.findViewById(R.id.etReason);
    mMeetingRoomDialogView.tvDialogTitle.setText("Reserve Meeting Room");
    alertDialogBuilder.setPositiveButton("Reserve", new DialogInterface.OnClickListener() {
        @Override//  w  w w . j a v  a2s .  co m
        public void onClick(DialogInterface dialog, int which) {
        }
    });
    alertDialogBuilder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });
    final AlertDialog mAlertDialog = alertDialogBuilder.create();
    mMeetingRoomDialogView.etDate.setOnTouchListener(dateOnClick);
    mMeetingRoomDialogView.etFrom.setOnTouchListener(fromOnClick);
    mMeetingRoomDialogView.etTo.setOnTouchListener(toOnClick);
    ivClose.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_DOWN) {
                mAlertDialog.dismiss();
            }
            return false;
        }
    });
    mAlertDialog.show();
    Button mPositiveButton = mAlertDialog.getButton(DialogInterface.BUTTON_POSITIVE);
    mAlertDialog.getButton(DialogInterface.BUTTON_NEGATIVE)
            .setTextColor(getResources().getColor(R.color.colorAccent));
    mPositiveButton.setTextColor(getResources().getColor(R.color.colorPrimary));
    mPositiveButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            try {
                if (validate()) {
                    String ReserveDate = mMeetingRoomDialogView.etDate.getText().toString();
                    String ReserveTimeFrom = mMeetingRoomDialogView.etFrom.getText().toString();
                    String ReserveTimeTo = mMeetingRoomDialogView.etTo.getText().toString();
                    String Reason = mMeetingRoomDialogView.etReason.getText().toString();
                    String roomId = "1";
                    switch (mMeetingRoomDialogView.spLocation.getSelectedItem().toString()) {
                    case "2nd Floor Auditorium":
                        roomId = "1";
                        break;
                    case "3rd Floor Auditorium":
                        roomId = "2";
                        break;
                    case "4th Floor Meeting Room":
                        roomId = "3";
                        break;
                    }
                    String parameter;
                    try {
                        parameter = "roomId=" + roomId + "&ReserveDate="
                                + URLEncoder.encode(ReserveDate, "UTF-8") + "&ReserveTimeFrom="
                                + URLEncoder.encode(ReserveTimeFrom, "UTF-8") + "&ReserveTimeTo="
                                + URLEncoder.encode(ReserveTimeTo, "UTF-8") + "&Reason="
                                + URLEncoder.encode(Reason, "UTF-8");
                    } catch (UnsupportedEncodingException e) {
                        e.printStackTrace();
                        parameter = "";
                    }
                    new MeetingTask("POST", parameter).execute();
                    showWaiting(MeetingRoomActivity.this);
                    mAlertDialog.dismiss();
                }
            } catch (ParseException e) {
                showToast("Time range validation error");
            }
        }
    });
}

From source file:com.openarc.nirmal.mytrack.AttendancesSubmitActivity.java

private void showAttendanceSubmitDialog() {
    mAttendancesSubmitDialogView = new AttendancesSubmitDialogView();
    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
    View dialogView = getLayoutInflater().inflate(R.layout.dialog_view_attendance_submit, null);
    alertDialogBuilder.setView(dialogView);
    ImageView ivClose = (ImageView) dialogView.findViewById(R.id.ivClose);
    mAttendancesSubmitDialogView.tvDialogTitle = (TextView) dialogView.findViewById(R.id.tvDialogTitle);
    mAttendancesSubmitDialogView.etDate = (EditText) dialogView.findViewById(R.id.etDate);
    mAttendancesSubmitDialogView.etOut = (EditText) dialogView.findViewById(R.id.etOut);
    mAttendancesSubmitDialogView.swOverNight = (Switch) dialogView.findViewById(R.id.swOverNight);
    mAttendancesSubmitDialogView.etIn = (EditText) dialogView.findViewById(R.id.etIn);
    mAttendancesSubmitDialogView.etReason = (EditText) dialogView.findViewById(R.id.etReason);
    mAttendancesSubmitDialogView.tvDialogTitle.setText("Attendance Submit");
    alertDialogBuilder.setPositiveButton("Submit", new DialogInterface.OnClickListener() {
        @Override//from   www .java  2  s  .com
        public void onClick(DialogInterface dialog, int which) {
        }
    });
    alertDialogBuilder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });
    final AlertDialog mAlertDialog = alertDialogBuilder.create();
    mAttendancesSubmitDialogView.etDate.setOnTouchListener(dateOnClick);
    mAttendancesSubmitDialogView.etIn.setOnTouchListener(inOnClick);
    mAttendancesSubmitDialogView.etOut.setOnTouchListener(outOnClick);
    ivClose.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_DOWN) {
                mAlertDialog.dismiss();
            }
            return false;
        }
    });
    mAlertDialog.show();
    Button mPositiveButton = mAlertDialog.getButton(DialogInterface.BUTTON_POSITIVE);
    mAlertDialog.getButton(DialogInterface.BUTTON_NEGATIVE)
            .setTextColor(getResources().getColor(R.color.colorAccent));
    mPositiveButton.setTextColor(getResources().getColor(R.color.colorPrimary));
    mPositiveButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (validate()) {
                String EEENO = MyTrackConfig.getInstance().LoggedUserCode;
                String REPORTDATE = mAttendancesSubmitDialogView.etDate.getText().toString();
                String REPORTTIMEOUT = mAttendancesSubmitDialogView.etOut.getText().toString();
                String REPORTTIMEIN = mAttendancesSubmitDialogView.etIn.getText().toString();
                boolean overnight = mAttendancesSubmitDialogView.swOverNight.isChecked() ? true : false;
                String REMARK = mAttendancesSubmitDialogView.etReason.getText().toString();
                String parameter;
                try {
                    if (overnight) {
                        parameter = "EEENO=" + EEENO + "&REPORTDATE=" + URLEncoder.encode(REPORTDATE, "UTF-8")
                                + "&REPORTTIMEIN=" + URLEncoder.encode(REPORTTIMEIN, "UTF-8")
                                + "&REPORTTIMEOUT=" + URLEncoder.encode(REPORTTIMEOUT, "UTF-8") + "&REMARK="
                                + URLEncoder.encode(REMARK, "UTF-8");
                    } else {
                        parameter = "EEENO=" + EEENO + "&REPORTDATE=" + URLEncoder.encode(REPORTDATE, "UTF-8")
                                + "&REPORTTIMEIN=" + URLEncoder.encode(REPORTTIMEIN, "UTF-8") + "&overnight="
                                + URLEncoder.encode("on", "UTF-8") + "&REPORTTIMEOUT="
                                + URLEncoder.encode(REPORTTIMEOUT, "UTF-8") + "&REMARK="
                                + URLEncoder.encode(REMARK, "UTF-8");
                    }
                } catch (UnsupportedEncodingException e) {
                    e.printStackTrace();
                    parameter = "";
                }
                new AttendanceSubmitTask("POST", parameter).execute();
                showWaiting(AttendancesSubmitActivity.this);
                mAlertDialog.dismiss();
            }
        }
    });
}

From source file:org.de.jmg.learn._MainActivity.java

private void SetTouchListener(ImageView iv) {
    if (iv != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        mScaleDetector = new ScaleGestureDetector(context, new ScaleListener());
        iv.setOnTouchListener(new OnTouchListener() {
            @TargetApi(Build.VERSION_CODES.FROYO)
            @Override/*from  w w  w . j a  v a 2s . c  o m*/
            public boolean onTouch(View v, MotionEvent event) {
                return mScaleDetector.onTouchEvent(event);
            }
        });
    }
}

From source file:com.thousandthoughts.tutorials.SensorFusionActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);/*from  w w w .java  2 s. co m*/
    layout = (RelativeLayout) findViewById(R.id.mainlayout);
    IP1 = "";
    IP2 = "";
    angle1 = 0.0f;
    angle2 = 0.0f;
    gyroOrientation[0] = 0.0f;
    gyroOrientation[1] = 0.0f;
    gyroOrientation[2] = 0.0f;

    // initialise gyroMatrix with identity matrix
    gyroMatrix[0] = 1.0f;
    gyroMatrix[1] = 0.0f;
    gyroMatrix[2] = 0.0f;
    gyroMatrix[3] = 0.0f;
    gyroMatrix[4] = 1.0f;
    gyroMatrix[5] = 0.0f;
    gyroMatrix[6] = 0.0f;
    gyroMatrix[7] = 0.0f;
    gyroMatrix[8] = 1.0f;

    // get sensorManager and initialise sensor listeners
    mSensorManager = (SensorManager) this.getSystemService(SENSOR_SERVICE);
    initListeners();

    // wait for one second until gyroscope and magnetometer/accelerometer
    // data is initialised then scedule the complementary filter task
    fuseTimer.scheduleAtFixedRate(new calculateFusedOrientationTask(), 1000, TIME_CONSTANT);

    // GUI stuff
    try {
        client1 = new MyCoapClient(this.IP1);
        client2 = new MyCoapClient(this.IP2);
    } catch (UnknownHostException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    json = new JSONObject();
    mHandler = new Handler();
    radioSelection = 0;
    d.setRoundingMode(RoundingMode.HALF_UP);
    d.setMaximumFractionDigits(3);
    d.setMinimumFractionDigits(3);

    /// Application layout here only

    RelativeLayout.LayoutParams left = new RelativeLayout.LayoutParams(
            android.view.ViewGroup.LayoutParams.WRAP_CONTENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT);
    RelativeLayout.LayoutParams right = new RelativeLayout.LayoutParams(
            android.view.ViewGroup.LayoutParams.WRAP_CONTENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT);
    RelativeLayout.LayoutParams up = new RelativeLayout.LayoutParams(
            android.view.ViewGroup.LayoutParams.WRAP_CONTENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT);
    RelativeLayout.LayoutParams down = new RelativeLayout.LayoutParams(
            android.view.ViewGroup.LayoutParams.WRAP_CONTENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT);
    RelativeLayout.LayoutParams button1 = new RelativeLayout.LayoutParams(
            android.view.ViewGroup.LayoutParams.WRAP_CONTENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT);
    RelativeLayout.LayoutParams button2 = new RelativeLayout.LayoutParams(
            android.view.ViewGroup.LayoutParams.WRAP_CONTENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT);
    RelativeLayout.LayoutParams text1 = new RelativeLayout.LayoutParams(
            android.view.ViewGroup.LayoutParams.WRAP_CONTENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT);
    RelativeLayout.LayoutParams text2 = new RelativeLayout.LayoutParams(
            android.view.ViewGroup.LayoutParams.WRAP_CONTENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT);
    ImageView img_left = new ImageView(this);
    ImageView img_right = new ImageView(this);
    ImageView img_up = new ImageView(this);
    ImageView img_down = new ImageView(this);
    ImageView img_button1 = new ImageView(this);
    ImageView img_button2 = new ImageView(this);
    final EditText edittext1 = new EditText(this);
    final EditText edittext2 = new EditText(this);
    img_left.setImageResource(R.drawable.left_button);
    img_right.setImageResource(R.drawable.right_button);
    img_up.setImageResource(R.drawable.up);
    img_down.setImageResource(R.drawable.down);
    img_button1.setImageResource(R.drawable.button);
    img_button2.setImageResource(R.drawable.button);

    left.setMargins(0, 66, 0, 0);
    right.setMargins(360, 66, 0, 0);
    up.setMargins(240, 90, 0, 0);
    down.setMargins(240, 240, 0, 0);
    button1.setMargins(440, 800, 0, 0);
    button2.setMargins(440, 900, 0, 0);
    text1.setMargins(5, 800, 0, 0);
    text2.setMargins(5, 900, 0, 0);

    layout.addView(img_left, left);
    layout.addView(img_right, right);
    layout.addView(img_up, up);
    layout.addView(img_down, down);
    layout.addView(img_button1, button1);
    layout.addView(edittext1, text1);
    layout.addView(img_button2, button2);
    layout.addView(edittext2, text2);

    img_left.getLayoutParams().height = 560;
    img_left.getLayoutParams().width = 280;
    img_right.getLayoutParams().height = 560;
    img_right.getLayoutParams().width = 280;
    img_up.getLayoutParams().height = 150;
    img_up.getLayoutParams().width = 150;
    img_down.getLayoutParams().height = 150;
    img_down.getLayoutParams().width = 150;
    img_button1.getLayoutParams().height = 100;
    img_button1.getLayoutParams().width = 200;
    edittext1.getLayoutParams().width = 400;
    edittext1.setText("84.248.76.84");
    edittext2.setText("84.248.76.84");
    img_button2.getLayoutParams().height = 100;
    img_button2.getLayoutParams().width = 200;
    edittext2.getLayoutParams().width = 400;

    /////////// Define and Remember Position for EACH PHYSICAL OBJECTS (LAPTOPS) /////////////////////
    img_button1.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View view, MotionEvent event) {
            // TODO Auto-generated method stub
            switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                // POSITION OF LAPTOP 1 IS REMEMBERED
                angle1 = fusedOrientation[0];
                IP1 = edittext1.getText().toString();
                try {
                    // CREATE CLIENT CONNECT TO FIRST LAPTOP
                    client1 = new MyCoapClient(IP1);
                } catch (UnknownHostException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                break;
            case MotionEvent.ACTION_MOVE:
                break;
            case MotionEvent.ACTION_UP:
                //view.setImageResource(R.drawable.left_button);
                break;
            }
            return true;
        }

    });

    img_button2.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View view, MotionEvent event) {
            // TODO Auto-generated method stub
            switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                // POSITION OF LAPTOP 2 IS REMEMBERED
                angle2 = fusedOrientation[0];
                IP2 = edittext2.getText().toString();
                try {
                    // CREATE CLIENT CONNECT TO SECOND LAPTOP
                    client2 = new MyCoapClient(IP2);
                } catch (UnknownHostException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                break;
            case MotionEvent.ACTION_MOVE:
                break;
            case MotionEvent.ACTION_UP:
                break;
            }
            return true;
        }

    });

    img_left.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            ImageView view = (ImageView) v;
            switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                view.setImageResource(R.drawable.left_button_press);

                ///////////////////// PERFORM CLICK ACTION BASED ON POSITION OF 2 PHYSICAL OBJECTS (LAPTOPs) HERE/////////////////////////

                // PHONE's ANGLE WITHIN FIRST LAPTOP//
                if (angle1 != 0.0f) {
                    if (angle1 * 180 / Math.PI - 40.0 < fusedOrientation[0] * 180 / Math.PI
                            && fusedOrientation[0] * 180 / Math.PI < angle1 * 180 / Math.PI + 40.0) {
                        client1.runClient("left pressed");
                    }
                }
                //PHONE's ANGLE WITHIN SECOND LAPTOP//
                if (angle2 != 0.0f) {
                    if (angle2 * 180 / Math.PI - 40.0 < fusedOrientation[0] * 180 / Math.PI
                            && fusedOrientation[0] * 180 / Math.PI < angle2 * 180 / Math.PI + 40.0) {
                        client2.runClient("left pressed");
                    }
                }
                break;
            case MotionEvent.ACTION_MOVE:
                break;
            case MotionEvent.ACTION_UP:
                view.setImageResource(R.drawable.left_button);
                // PHONE's ANGLE WITHIN FIRST LAPTOP//
                if (angle1 != 0.0f) {
                    if (angle1 * 180 / Math.PI - 40.0f < fusedOrientation[0] * 180 / Math.PI
                            && fusedOrientation[0] * 180 / Math.PI < angle1 * 180 / Math.PI + 40.0f) {
                        client1.runClient("left released");
                    }
                }
                //PHONE's ANGLE WITHIN SECOND LAPTOP//
                if (angle2 != 0.0f) {
                    if (angle2 * 180 / Math.PI - 40.0f < fusedOrientation[0] * 180 / Math.PI
                            && fusedOrientation[0] * 180 / Math.PI < angle2 * 180 / Math.PI + 40.0f) {
                        client2.runClient("left released");
                    }
                }
                break;
            }
            return true;
        }
    });

    img_right.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            ImageView view = (ImageView) v;
            switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                view.setImageResource(R.drawable.right_button_press);
                // PHONE's ANGLE WITHIN FIRST LAPTOP//
                if (angle1 != 0.0f) {
                    if (angle1 * 180 / Math.PI - 40.0f < fusedOrientation[0] * 180 / Math.PI
                            && fusedOrientation[0] * 180 / Math.PI < angle1 * 180 / Math.PI + 40.0f) {
                        client1.runClient("right pressed");
                    }
                }
                //PHONE's ANGLE WITHIN SECOND LAPTOP//
                if (angle2 != 0.0f) {
                    if (angle2 * 180 / Math.PI - 40.0f < fusedOrientation[0] * 180 / Math.PI
                            && fusedOrientation[0] * 180 / Math.PI < angle2 * 180 / Math.PI + 40.0f) {
                        client2.runClient("right pressed");
                    }
                }
                break;
            case MotionEvent.ACTION_MOVE:
                break;
            case MotionEvent.ACTION_UP:
                view.setImageResource(R.drawable.right_button);
                break;
            }
            return true;
        }
    });

    img_up.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            ImageView view = (ImageView) v;
            switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                view.setImageResource(R.drawable.up_press);
                // PHONE's ANGLE WITHIN FIRST LAPTOP//
                if (angle1 != 0.0f) {
                    if (angle1 * 180 / Math.PI - 40.0f < fusedOrientation[0] * 180 / Math.PI
                            && fusedOrientation[0] * 180 / Math.PI < angle1 * 180 / Math.PI + 40.0f) {
                        client1.runClient("up pressed");
                    }
                }
                //PHONE's ANGLE WITHIN SECOND LAPTOP//
                if (angle2 != 0.0f) {
                    if (angle2 * 180 / Math.PI - 40.0f < fusedOrientation[0] * 180 / Math.PI
                            && fusedOrientation[0] * 180 / Math.PI < angle2 * 180 / Math.PI + 40.0f) {
                        client2.runClient("up pressed");
                    }
                }
                break;
            case MotionEvent.ACTION_MOVE:
                break;
            case MotionEvent.ACTION_UP:
                view.setImageResource(R.drawable.up);
                break;
            }
            return true;
        }
    });

    img_down.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            ImageView view = (ImageView) v;
            switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                view.setImageResource(R.drawable.down_press);
                // PHONE's ANGLE WITHIN FIRST LAPTOP//
                if (angle1 != 0.0f) {
                    if (angle1 * 180 / Math.PI - 40.0f < fusedOrientation[0] * 180 / Math.PI
                            && fusedOrientation[0] * 180 / Math.PI < angle1 * 180 / Math.PI + 40.0f) {
                        client1.runClient("down pressed");
                    }
                }
                //PHONE's ANGLE WITHIN SECOND LAPTOP//
                if (angle2 != 0.0f) {
                    if (angle2 * 180 / Math.PI - 40.0f < fusedOrientation[0] * 180 / Math.PI
                            && fusedOrientation[0] * 180 / Math.PI < angle2 * 180 / Math.PI + 40.0f) {
                        client2.runClient("down pressed");
                    }
                }
                break;
            case MotionEvent.ACTION_MOVE:
                break;
            case MotionEvent.ACTION_UP:
                view.setImageResource(R.drawable.down);
                break;
            }
            return true;
        }
    });
}