Example usage for android.view ScaleGestureDetector ScaleGestureDetector

List of usage examples for android.view ScaleGestureDetector ScaleGestureDetector

Introduction

In this page you can find the example usage for android.view ScaleGestureDetector ScaleGestureDetector.

Prototype

public ScaleGestureDetector(Context context, OnScaleGestureListener listener) 

Source Link

Document

Creates a ScaleGestureDetector with the supplied listener.

Usage

From source file:joshuatee.wx.USWXOGLRadarActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    preferences = PreferenceManager.getDefaultSharedPreferences(this);
    //editor = preferences.edit();
    theme_blue_current = preferences.getString("THEME_BLUE", "");
    setTheme(Utility.Theme(theme_blue_current));

    //setContentView(R.layout.activity_uswxoglradar);

    if (!DataStore.loaded)
        DataStore.Init(this);

    space = Pattern.compile(" ");
    comma = Pattern.compile(",");
    colon = Pattern.compile(":");

    //mImageMap = (ImageMap) findViewById(R.id.map);
    //mImageMap.setVisibility(View.GONE);

    cod_warnings_default = preferences.getString("COD_WARNINGS_DEFAULT", "");
    cod_cities_default = preferences.getString("COD_CITIES_DEFAULT", "");
    cod_hw_default = preferences.getString("COD_HW_DEFAULT", "true");
    cod_locdot_default = preferences.getString("COD_LOCDOT_DEFAULT", "true");
    cod_lakes_default = preferences.getString("COD_LAKES_DEFAULT", "true");

    //delay = UtilityImg.GetAnimInterval(preferences);

    img = new TouchImageView2(getApplicationContext());
    img.setMaxZoom(max_zoom);//  ww w .  ja va2 s.co  m
    img.setZoom(init_zoom);

    dm = new DisplayMetrics();
    this.getWindowManager().getDefaultDisplay().getMetrics(dm);

    boolean isActionBarSplitted = ((dm.widthPixels / dm.density) < 400.00f);
    if (isActionBarSplitted) {
        ab_split = true;
    }

    int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
    statusBarHeight = getResources().getDimensionPixelSize(resourceId);

    TypedValue tv = new TypedValue();
    getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true);
    actionBarHeight = getResources().getDimensionPixelSize(tv.resourceId);
    actionBarHeight *= dm.density;

    screen_width = dm.widthPixels;
    screen_height = dm.heightPixels - statusBarHeight - actionBarHeight;

    turl = getIntent().getStringArrayExtra(RID);

    prod = "N0Q";

    view = new GLSurfaceView(this);
    view.setEGLContextClientVersion(2);
    mScaleDetector = new ScaleGestureDetector(this, new ScaleListener());
    mGestureDetector = new GestureDetectorCompat(this, this);

    OGLR = new OpenGLRenderRadar2Dv4(this);
    view.setRenderer(OGLR);
    view.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);

    density = (float) (OGLR.ort_int * 2) / dm.widthPixels;

    setContentView(view);
    ogl_in_view = true;

    rid1 = turl[0];
    state = turl[1];
    if (turl.length > 2) {
        prod = turl[2];
        if (prod.equals("N0R")) {
            prod = "N0Q";
        }
    }

    //rid_fav = preferences.getString(pref_token," : : :");
    //sector = preferences.getString("COD_SECTOR_"+state,"");
    //state = preferences.getString("STATE_CODE_"+state,"");
    //onek = preferences.getString("COD_1KM_"+rid1,"");

    setTitle(prod);

    rid_fav = preferences.getString(pref_token, " : : :");
    rid_arr_loc = UtilityFavorites.SetupFavMenu(preferences, rid_fav, turl[0], pref_token_location, colon);
    adapter = new ArrayAdapter<String>(getBaseContext(), android.R.layout.simple_spinner_dropdown_item,
            rid_arr_loc);
    getActionBar().setListNavigationCallbacks(adapter, navigationListener);
    getActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);

    navigationListener = new OnNavigationListener() {

        @Override
        public boolean onNavigationItemSelected(int itemPosition, long itemId) {

            if (itemPosition == 0 || itemPosition > 2) {
                rid1 = space.split(rid_arr_loc[itemPosition])[0];

                //rid_loc = preferences.getString("RID_LOC_"+rid1,"");
                //editor.putString("NEXRAD_LAST", rid1); 
                //editor.commit();

                old_state = state;
                old_sector = sector;
                old_onek = onek;
                state = comma.split(preferences.getString("RID_LOC_" + rid1, ""))[0];
                sector = preferences.getString("COD_SECTOR_" + state, "");
                state = preferences.getString("STATE_CODE_" + state, "");
                onek = preferences.getString("COD_1KM_" + rid1, "");

                if (prod.equals("2k")) {
                    img_url = img_url.replace(old_sector, sector);
                    img_url = img_url.replace(old_state, state);
                    img_url = img_url.replace(old_onek, onek);
                }
                if (!restarted) {
                    img.resetZoom();
                    img.setZoom(init_zoom);
                    OGLR.setZoom(1.0f);
                    mScaleFactor = 1.0f;
                    OGLR.mPositionX = 0.0f;
                    OGLR.mPositionY = 0.0f;
                }
                restarted = false;
                new GetContent().execute();
            } else if (itemPosition == 1) {
                Intent dtx_srm = new Intent(getApplicationContext(), RIDAddFavActivity.class);
                startActivity(dtx_srm);
            } else if (itemPosition == 2) {
                Intent dtx_srm2 = new Intent(getApplicationContext(), RIDRemoveFavActivity.class);
                startActivity(dtx_srm2);
            }

            return false;
        }
    };
    getActionBar().setListNavigationCallbacks(adapter, navigationListener);

}

From source file:com.example.nitish.welcomapp.widgetpt.PeriodicTableView.java

public PeriodicTableView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    mSelectedPaint = new Paint();
    mSelectedPaint.setAntiAlias(true);// w  w  w  . j a v a 2s  . c  o  m
    mSelectedPaint.setStyle(Paint.Style.STROKE);
    mSelectedPaint.setStrokeJoin(Paint.Join.ROUND);
    mSelectedPaint.setColor(COLOR_SELECTED);

    mNumberPaint = new Paint();
    mNumberPaint.setAntiAlias(true);
    mNumberPaint.setColor(COLOR_BLOCK_FOREGROUND);

    mSymbolPaint = new Paint(mNumberPaint);
    mSymbolPaint.setTextAlign(Paint.Align.CENTER);

    mTitlePaint = new Paint(mSymbolPaint);
    mHeaderPaint = new Paint(mSymbolPaint);
    mSmallTextPaint = new Paint(mSymbolPaint);

    mNumberPaint.setSubpixelText(true);
    mSmallTextPaint.setSubpixelText(true);

    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.PeriodicTableView, defStyle, 0);

    mTitle = a.getText(R.styleable.PeriodicTableView_title);
    setFgColor(a.getColor(R.styleable.PeriodicTableView_fgColor, COLOR_DEFAULT_FOREGROUND));
    setBgColor(a.getColor(R.styleable.PeriodicTableView_bgColor, COLOR_DEFAULT_BACKGROUND));

    a.recycle();

    mLegend = new PeriodicTableLegend(context);

    mScaleGestureDetector = new ScaleGestureDetector(context, getOnScaleGestureListener());
    mGestureDetector = new GestureDetector(context, getOnGestureListener());

    mZoomer = new Zoomer(context);
    mScroller = new Scroller(context);

    mEdgeEffectLeft = new EdgeEffectCompat(context);
    mEdgeEffectTop = new EdgeEffectCompat(context);
    mEdgeEffectRight = new EdgeEffectCompat(context);
    mEdgeEffectBottom = new EdgeEffectCompat(context);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        mAccessibilityDelegate = new AccessibilityDelegate(this);
        ViewCompat.setAccessibilityDelegate(this, mAccessibilityDelegate);
    }
}

From source file:org.deviceconnect.android.deviceplugin.theta.fragment.ThetaShootingFragment.java

@Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container,
        final Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.theta_shooting_mode, null);
    ThetaDeviceApplication app = (ThetaDeviceApplication) getActivity().getApplication();
    ThetaDeviceManager deviceMgr = app.getDeviceManager();
    deviceMgr.registerDeviceEventListener(this);
    mDevice = deviceMgr.getConnectedDevice();
    if (mDevice == null) {
        ThetaDialogFragment.showAlert(getActivity(), getString(R.string.theta_ssid_prefix),
                getString(R.string.theta_error_disconnect_dialog_message),
                new DialogInterface.OnClickListener() {
                    @Override/*from   w  w  w .j  a  v a2s. com*/
                    public void onClick(DialogInterface dialogInterface, int i) {
                        getActivity().finish();
                    }
                });

        return rootView;
    }
    mShootingTime = (TextView) rootView.findViewById(R.id.shooting_time);
    mLiveView = (SphericalImageLiveView) rootView.findViewById(R.id.shooting_preview);
    mApi = app.getSphericalViewApi();
    mLiveView.setViewApi(mApi);
    mLiveView.setDeviceManager(deviceMgr);
    initShootingLayouts(rootView);
    mShootingMode = (Spinner) rootView.findViewById(R.id.theta_shooting_mode);
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(), R.layout.theta_shooting_mode_adapter,
            getResources().getStringArray(R.array.theta_shooting_mode));

    mShootingMode.setAdapter(adapter);
    setRetainInstance(true);
    if (mShootingTasker == null) {
        mShootingTasker = new DownloadThetaDataTask();
        ShootingModeGetTask shootingGetTask = new ShootingModeGetTask();
        mShootingTasker.execute(shootingGetTask);
    }
    mLiveView.setOnTouchListener(new View.OnTouchListener() {

        private boolean mIsEnabledLongTouch = true;

        @Override
        public boolean onTouch(final View view, final MotionEvent motionEvent) {
            if (motionEvent.getAction() == MotionEvent.ACTION_UP) {
                mIsEnabledLongTouch = true;
                return true;
            }
            if (motionEvent.getPointerCount() == 1) {
                if (mIsEnabledLongTouch && motionEvent.getEventTime() - motionEvent.getDownTime() >= 300) {
                    mLiveView.resetCameraDirection();
                }
            } else {
                mIsEnabledLongTouch = false;
                mScaleDetector.onTouchEvent(motionEvent);
            }
            return true;
        }
    });
    mScaleDetector = new ScaleGestureDetector(getActivity(),
            new ScaleGestureDetector.SimpleOnScaleGestureListener() {
                @Override
                public boolean onScale(final ScaleGestureDetector detector) {
                    mScaleFactor /= detector.getScaleFactor();
                    double scale = mScaleFactor;
                    if (scale > MAX_FOV) {
                        scale = MAX_FOV;
                        mScaleFactor = MAX_FOV;
                    }
                    if (scale < MIN_FOV) {
                        scale = MIN_FOV;
                        mScaleFactor = MIN_FOV;
                    }
                    mLiveView.setFOV(scale);

                    return true;
                }
            });
    rotateShootingButton(getActivity().getResources().getConfiguration());
    return rootView;
}

From source file:es.farfuteam.vncpp.controller.CanvasActivity.java

/**
 * @brief The Android onCreate method//from   w ww . j  a va2 s .  c o m
 * @details The Android onCreate method. Initializes the CanvasView, SlidingMenu, VncBridgeJNI.
 * Also calls the method to start the connection
 */
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    //No se muestra la barra de accion superior
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);

    setContentView(R.layout.canvas);
    canvas = (CanvasView) findViewById(R.id.vnc_canvas);

    Bundle info = getIntent().getExtras();

    progressDialog = new ProgressDialog(this);

    final String load = getString(R.string.loadingtext);
    final String loadImage = getString(R.string.loadingbodytext);

    progressDialog.setTitle(load);

    progressDialog.setMessage(loadImage);
    final String cancel = getString(R.string.cancel);

    progressDialog.setButton(cancel, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            vnc.finishVnc();
            finishConnection();
        }
    });

    progressDialog.show();
    progressDialog.setCancelable(false);

    menu = new SlidingMenu(this);
    startSlideMenu();

    runTimerConnection();

    String aux_quality = info.getString("color");
    QualityArray quality = QualityArray.valueOf(aux_quality);

    iniConnection(info.getString("ip"), info.getString("port"), info.getString("psw"), quality,
            info.getBoolean("wifi"));

    inputMgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);

    GestureListener gestureListener = new GestureListener();
    gesture = new GestureDetector(gestureListener);

    scaleGesture = new ScaleGestureDetector(this, gestureListener);

    endScrollRun = new Runnable() {

        @Override
        public void run() {
            while (drag || oneLoopMore) {
                oneLoopMore = false;
                try {
                    Thread.sleep(TIMER_SCROLL);
                } catch (InterruptedException e) {
                    // Auto-generated catch block

                }

            }

            canvas.endDrag();

        }
    };

}

From source file:com.ickphum.android.isoview.InteractiveLineGraphView.java

public InteractiveLineGraphView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.InteractiveLineGraphView,
            defStyle, defStyle);/*w  w  w .  j a  v a  2  s  .c om*/

    try {
        mLabelTextColor = a.getColor(R.styleable.InteractiveLineGraphView_labelTextColor, mLabelTextColor);
        mLabelTextSize = a.getDimension(R.styleable.InteractiveLineGraphView_labelTextSize, mLabelTextSize);
        mLabelSeparation = a.getDimensionPixelSize(R.styleable.InteractiveLineGraphView_labelSeparation,
                mLabelSeparation);

        mGridThickness = a.getDimension(R.styleable.InteractiveLineGraphView_gridThickness, mGridThickness);
        mGridColor = a.getColor(R.styleable.InteractiveLineGraphView_gridColor, mGridColor);

        mAxisThickness = a.getDimension(R.styleable.InteractiveLineGraphView_axisThickness, mAxisThickness);
        mAxisColor = a.getColor(R.styleable.InteractiveLineGraphView_axisColor, mAxisColor);

        mDataThickness = a.getDimension(R.styleable.InteractiveLineGraphView_dataThickness, mDataThickness);
        mDataColor = a.getColor(R.styleable.InteractiveLineGraphView_dataColor, mDataColor);
    } finally {
        a.recycle();
    }

    initPaints();

    // Sets up interactions
    if (!this.isInEditMode()) {
        mScaleGestureDetector = new ScaleGestureDetector(context, mScaleGestureListener);
        mGestureDetector = new GestureDetectorCompat(context, mGestureListener);
    }

    mScroller = new OverScroller(context);
    mZoomer = new Zoomer(context);

    // Sets up edge effects
    mEdgeEffectLeft = new EdgeEffectCompat(context);
    mEdgeEffectTop = new EdgeEffectCompat(context);
    mEdgeEffectRight = new EdgeEffectCompat(context);
    mEdgeEffectBottom = new EdgeEffectCompat(context);
}

From source file:cn.androidy.androiddevelopmentpatterns.interactivechart.InteractiveLineGraphView.java

public InteractiveLineGraphView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.InteractiveLineGraphView,
            defStyle, defStyle);//ww  w.j  a va2s . c  om

    try {
        mLabelTextColor = a.getColor(R.styleable.InteractiveLineGraphView_labelTextColor, mLabelTextColor);
        mLabelTextSize = a.getDimension(R.styleable.InteractiveLineGraphView_labelTextSize, mLabelTextSize);
        mLabelSeparation = a.getDimensionPixelSize(R.styleable.InteractiveLineGraphView_labelSeparation,
                mLabelSeparation);

        mGridThickness = a.getDimension(R.styleable.InteractiveLineGraphView_gridThickness, mGridThickness);
        mGridColor = a.getColor(R.styleable.InteractiveLineGraphView_gridColor, mGridColor);

        mAxisThickness = a.getDimension(R.styleable.InteractiveLineGraphView_axisThickness, mAxisThickness);
        mAxisColor = a.getColor(R.styleable.InteractiveLineGraphView_axisColor, mAxisColor);

        mDataThickness = a.getDimension(R.styleable.InteractiveLineGraphView_dataThickness, mDataThickness);
        mDataColor = a.getColor(R.styleable.InteractiveLineGraphView_dataColor, mDataColor);
    } finally {
        a.recycle();
    }

    initPaints();

    // Sets up interactions
    mScaleGestureDetector = new ScaleGestureDetector(context, mScaleGestureListener);
    mGestureDetector = new GestureDetectorCompat(context, mGestureListener);

    mScroller = new OverScroller(context);
    mZoomer = new Zoomer(context);

    // Sets up edge effects
    mEdgeEffectLeft = new EdgeEffectCompat(context);
    mEdgeEffectTop = new EdgeEffectCompat(context);
    mEdgeEffectRight = new EdgeEffectCompat(context);
    mEdgeEffectBottom = new EdgeEffectCompat(context);
}

From source file:com.rnd.snapsplit.view.OcrCaptureFragment.java

/**
 * Initializes the UI and creates the detector pipeline.
 *//*from www.  j av a2 s  .  c om*/
//    @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:taylorandtanner.gasscanmk1.OcrCaptureActivity.java

/**
 * Initializes the UI and creates the detector pipeline.
 *///from   w  w w .  jav  a  2  s. c  o  m
@Override
public void onCreate(Bundle bundle) {
    super.onCreate(bundle);
    setContentView(R.layout.ocr_capture);

    Button next = (Button) findViewById(R.id.button3);
    next.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            Intent myIntent = new Intent(view.getContext(), MainActivity.class);
            startActivityForResult(myIntent, 0);
        }

    });
    TextView tv1 = (TextView) findViewById(R.id.forStation);
    TextView tv1a = (TextView) findViewById(R.id.station);
    TextView tv2 = (TextView) findViewById(R.id.forPrice);
    TextView tv2a = (TextView) findViewById(R.id.totalPrice);
    TextView tv3 = (TextView) findViewById(R.id.forGallons);
    TextView tv3a = (TextView) findViewById(R.id.gallons);
    TextView tv4 = (TextView) findViewById(R.id.forPriceGal);
    TextView tv4a = (TextView) findViewById(R.id.priceGal);
    TextView tv5 = (TextView) findViewById(R.id.forMileage);
    TextView tv5a = (TextView) findViewById(R.id.mileage);

    tv1.setTextColor(Color.RED);
    tv1a.setTextColor(Color.BLACK);
    //Set others black
    tv3.setTextColor(Color.argb(0, 0, 0, 0));
    tv4.setTextColor(Color.argb(0, 0, 0, 0));
    tv5.setTextColor(Color.argb(0, 0, 0, 0));
    tv2.setTextColor(Color.argb(0, 0, 0, 0));
    tv3a.setTextColor(Color.argb(0, 0, 0, 0));
    tv4a.setTextColor(Color.argb(0, 0, 0, 0));
    tv5a.setTextColor(Color.argb(0, 0, 0, 0));
    tv2a.setTextColor(Color.argb(0, 0, 0, 0));

    final Button acceptOCRButton = (Button) findViewById(R.id.acceptOCRButton);
    acceptOCRButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            System.out.println("CLICKED!!1");

            String outputGal = ((TextView) findViewById(R.id.forGallons)).getText().toString();
            String outputPriceGal = ((TextView) findViewById(R.id.forPriceGal)).getText().toString();
            String outputMileage = ((TextView) findViewById(R.id.forMileage)).getText().toString();
            String outputPrice = ((TextView) findViewById(R.id.forPrice)).getText().toString();
            String outputStation = ((TextView) findViewById(R.id.forStation)).getText().toString();
            ReceiptEntry outputReceipt = new ReceiptEntry(outputPrice, outputGal, outputPriceGal, outputMileage,
                    "unassigned", outputStation);

            SerializeMethod(outputReceipt);
            // Intent activityChangeIntent = new Intent(OcrCaptureActivity.this, ReceiptForm.class);
            // OcrCaptureActivity.this.startActivity(activityChangeIntent);

        }
    });

    final SeekBar seekBar = (SeekBar) findViewById(R.id.seekBar);
    seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
            // TODO Auto-generated method stub
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
            // TODO Auto-generated method stub
        }

        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            // TODO Auto-generated method stub

            TextView t1 = (TextView) findViewById(R.id.forStation);
            TextView t1a = (TextView) findViewById(R.id.station);
            TextView t2 = (TextView) findViewById(R.id.forPrice);
            TextView t2a = (TextView) findViewById(R.id.totalPrice);
            TextView t3 = (TextView) findViewById(R.id.forGallons);
            TextView t3a = (TextView) findViewById(R.id.gallons);
            TextView t4 = (TextView) findViewById(R.id.forPriceGal);
            TextView t4a = (TextView) findViewById(R.id.priceGal);
            TextView t5 = (TextView) findViewById(R.id.forMileage);
            TextView t5a = (TextView) findViewById(R.id.mileage);

            if (seekBar.getProgress() >= 0 && seekBar.getProgress() < 20) {
                if (t1.getText().toString().equals("00"))
                    t1.setTextColor(Color.RED);
                else
                    t1.setTextColor(Color.BLUE);
                t1a.setTextColor(Color.BLACK);
                //Set others black
                t3.setTextColor(Color.argb(0, 0, 0, 0));
                t4.setTextColor(Color.argb(0, 0, 0, 0));
                t5.setTextColor(Color.argb(0, 0, 0, 0));
                t2.setTextColor(Color.argb(0, 0, 0, 0));
                t3a.setTextColor(Color.argb(0, 0, 0, 0));
                t4a.setTextColor(Color.argb(0, 0, 0, 0));
                t5a.setTextColor(Color.argb(0, 0, 0, 0));
                t2a.setTextColor(Color.argb(0, 0, 0, 0));
            }
            if (seekBar.getProgress() >= 20 && seekBar.getProgress() < 40) {
                if (t2.getText().toString().equals("00"))
                    t2.setTextColor(Color.RED);
                else
                    t2.setTextColor(Color.BLUE);
                t2a.setTextColor(Color.BLACK);
                //Set others black
                t3.setTextColor(Color.argb(0, 0, 0, 0));
                t4.setTextColor(Color.argb(0, 0, 0, 0));
                t5.setTextColor(Color.argb(0, 0, 0, 0));
                t1.setTextColor(Color.argb(0, 0, 0, 0));
                t3a.setTextColor(Color.argb(0, 0, 0, 0));
                t4a.setTextColor(Color.argb(0, 0, 0, 0));
                t5a.setTextColor(Color.argb(0, 0, 0, 0));
                t1a.setTextColor(Color.argb(0, 0, 0, 0));
            } else if (seekBar.getProgress() >= 40 && seekBar.getProgress() < 60) {
                if (t3.getText().toString().equals("00"))
                    t3.setTextColor(Color.RED);
                else
                    t3.setTextColor(Color.BLUE);
                t3a.setTextColor(Color.BLACK);
                //Set others black
                t2.setTextColor(Color.argb(0, 0, 0, 0));
                t4.setTextColor(Color.argb(0, 0, 0, 0));
                t5.setTextColor(Color.argb(0, 0, 0, 0));
                t1.setTextColor(Color.argb(0, 0, 0, 0));
                t2a.setTextColor(Color.argb(0, 0, 0, 0));
                t4a.setTextColor(Color.argb(0, 0, 0, 0));
                t5a.setTextColor(Color.argb(0, 0, 0, 0));
                t1a.setTextColor(Color.argb(0, 0, 0, 0));
            } else if (seekBar.getProgress() >= 60 && seekBar.getProgress() < 80) {
                if (t4.getText().toString().equals("00"))
                    t4.setTextColor(Color.RED);
                else
                    t4.setTextColor(Color.BLUE);
                t4a.setTextColor(Color.BLACK);
                //Set others black
                t2.setTextColor(Color.argb(0, 0, 0, 0));
                t3.setTextColor(Color.argb(0, 0, 0, 0));
                t5.setTextColor(Color.argb(0, 0, 0, 0));
                t1.setTextColor(Color.argb(0, 0, 0, 0));
                t2a.setTextColor(Color.argb(0, 0, 0, 0));
                t3a.setTextColor(Color.argb(0, 0, 0, 0));
                t5a.setTextColor(Color.argb(0, 0, 0, 0));
                t1a.setTextColor(Color.argb(0, 0, 0, 0));
            } else if (seekBar.getProgress() >= 80 && seekBar.getProgress() <= 100) {
                if (t5.getText().toString().equals("00"))
                    t5.setTextColor(Color.RED);
                else
                    t5.setTextColor(Color.BLUE);
                t5a.setTextColor(Color.BLACK);
                //Set others black
                t2.setTextColor(Color.argb(0, 0, 0, 0));
                t4.setTextColor(Color.argb(0, 0, 0, 0));
                t3.setTextColor(Color.argb(0, 0, 0, 0));
                t1.setTextColor(Color.argb(0, 0, 0, 0));
                t2a.setTextColor(Color.argb(0, 0, 0, 0));
                t4a.setTextColor(Color.argb(0, 0, 0, 0));
                t3a.setTextColor(Color.argb(0, 0, 0, 0));
                t1a.setTextColor(Color.argb(0, 0, 0, 0));
            }

        }
    });

    mPreview = (CameraSourcePreview) findViewById(R.id.preview);
    mGraphicOverlay = (GraphicOverlay<OcrGraphic>) findViewById(R.id.graphicOverlay);

    // Set good defaults for capturing text.
    boolean autoFocus = true;
    boolean useFlash = false;

    // Check for the camera permission before accessing the camera.  If the
    // permission is not granted yet, request permission.
    int rc = ActivityCompat.checkSelfPermission(this, Manifest.permission.CAMERA);
    if (rc == PackageManager.PERMISSION_GRANTED) {
        createCameraSource(autoFocus, useFlash);
    } else {
        requestCameraPermission();
    }

    gestureDetector = new GestureDetector(this, new CaptureGestureListener());
    scaleGestureDetector = new ScaleGestureDetector(this, new ScaleListener());

    /*Snackbar.make(mGraphicOverlay, "Tap the text to place into the desired field. \n Select" +
        " 'confirm' when you are happy with the selection.",
        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(this.getApplicationContext(), listener);*/
}

From source file:com.appunite.scroll.ScaleImageView.java

@SuppressWarnings("UnusedDeclaration")
public ScaleImageView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    final ViewConfiguration viewConfiguration = ViewConfiguration.get(context);
    mMinEdge = viewConfiguration.getScaledEdgeSlop();

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ScaleImageView, defStyle, defStyle);
    assert a != null;

    Drawable src = null;/*from   www .  j a va  2  s .c o m*/
    try {
        mMinWidth = a.getDimensionPixelSize(R.styleable.ScaleImageView_android_minWidth, 0);
        mMinHeight = a.getDimensionPixelSize(R.styleable.ScaleImageView_android_minHeight, 0);
        src = a.getDrawable(R.styleable.ScaleImageView_android_src);
    } finally {
        a.recycle();
    }

    ScaleGestureDetector.OnScaleGestureListener scaleGestureListener = new ScaleGestureDetector.SimpleOnScaleGestureListener() {
        /**
         * This is the active focal point in terms of the viewport. Could be a local
         * variable but kept here to minimize per-frame allocations.
         */
        private PointF viewportFocus = new PointF();

        @Override
        public boolean onScaleBegin(ScaleGestureDetector scaleGestureDetector) {
            final ViewParent parent = getParent();
            if (parent != null) {
                parent.requestDisallowInterceptTouchEvent(true);
            }
            return true;
        }

        @Override
        public boolean onScale(ScaleGestureDetector scaleGestureDetector) {
            float focusX = scaleGestureDetector.getFocusX();
            float focusY = scaleGestureDetector.getFocusY();
            float scaleFactor = scaleGestureDetector.getScaleFactor();
            float previousScale = mScale;
            mScale *= scaleFactor;

            doScale(focusX, focusY, scaleFactor);
            return true;
        }

    };
    GestureDetector.SimpleOnGestureListener gestureListener = new GestureDetector.SimpleOnGestureListener() {
        @Override
        public boolean onDown(MotionEvent e) {

            releaseEdgeEffects();
            mScroller.forceFinished(true);
            ViewCompat.postInvalidateOnAnimation(ScaleImageView.this);
            return true;
        }

        @Override
        public boolean onSingleTapConfirmed(MotionEvent e) {
            return performClick();
        }

        @Override
        public boolean onDoubleTap(MotionEvent e) {
            mZoomer.forceFinished(true);
            mZoomStartScale = mScale;
            mZoomFocalPoint.set(e.getX(), e.getY());
            mZoomer.startZoom(ZOOM_AMOUNT);
            ViewCompat.postInvalidateOnAnimation(ScaleImageView.this);
            return true;
        }

        @Override
        public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
            getRealTranslation(mTranslation, mRealTranslation);
            mRealTranslation.offset(-distanceX, -distanceY);
            getTranslation(mRealTranslation, mTranslation);

            computeMaxScrollSize(mMaxScrollBuffer);
            getImageRect(mRectF);
            float scrolledX = -mRectF.left;
            float scrolledY = -mRectF.top;
            boolean canScrollX = mRectF.left > mContentRect.left || mRectF.right < mContentRect.right;
            boolean canScrollY = mRectF.top > mContentRect.top || mRectF.bottom < mContentRect.bottom;
            validateTranslation();

            disallowParentInterceptWhenOnEdge(distanceX, distanceY);

            if (mScale > mMinScale) {
                if (canScrollX && scrolledX < 0) {
                    mEdgeEffectLeft.onPull(scrolledX / (float) mContentRect.width());
                    mEdgeEffectLeftActive = true;
                }
                if (canScrollY && scrolledY < 0) {
                    mEdgeEffectTop.onPull(scrolledY / (float) mContentRect.height());
                    mEdgeEffectTopActive = true;
                }
                if (canScrollX && scrolledX > mMaxScrollBuffer.x) {
                    mEdgeEffectRight.onPull((scrolledX - mMaxScrollBuffer.x) / (float) mContentRect.width());
                    mEdgeEffectRightActive = true;
                }
                if (canScrollY && scrolledY > mMaxScrollBuffer.y) {
                    mEdgeEffectBottom.onPull((scrolledY - mMaxScrollBuffer.y) / (float) mContentRect.height());
                    mEdgeEffectBottomActive = true;
                }
            }

            ViewCompat.postInvalidateOnAnimation(ScaleImageView.this);
            return true;
        }

        private void disallowParentInterceptWhenOnEdge(float directionX, float directionY) {
            final ViewParent parent = getParent();
            if (parent != null && (mAllowParentHorizontalScroll || mAllowParentVerticalScroll)) {
                getImageRect(mRectF);
                if (mAllowParentHorizontalScroll) {
                    if (directionX > 0 && Math.abs(mRectF.right - mContentRect.right) > mMinEdge) {
                        parent.requestDisallowInterceptTouchEvent(true);
                    }
                    if (directionX < 0 && Math.abs(mRectF.left - mContentRect.left) > mMinEdge) {
                        parent.requestDisallowInterceptTouchEvent(true);
                    }
                }
                if (mAllowParentVerticalScroll) {
                    if (directionY > 0 && Math.abs(mRectF.bottom - mContentRect.bottom) > mMinEdge) {
                        parent.requestDisallowInterceptTouchEvent(true);
                    }
                    if (directionY < 0 && Math.abs(mRectF.top - mContentRect.top) > mMinEdge) {
                        parent.requestDisallowInterceptTouchEvent(true);
                    }
                }
            }
        }

        @Override
        public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
            disallowParentInterceptWhenOnEdge(velocityX, velocityY);
            fling((int) -velocityX, (int) -velocityY);
            return true;
        }
    };

    mScaleGestureDetector = new ScaleGestureDetector(context, scaleGestureListener);
    mGestureDetector = new GestureDetectorCompat(context, gestureListener);

    mScroller = new OverScroller(context);
    mZoomer = new Zoomer(context);

    // Sets up edge effects
    mEdgeEffectLeft = new EdgeEffectCompat(context);
    mEdgeEffectTop = new EdgeEffectCompat(context);
    mEdgeEffectRight = new EdgeEffectCompat(context);
    mEdgeEffectBottom = new EdgeEffectCompat(context);

    setSrcDrawable(src);
}

From source file:com.android.mms.ui.MailBoxMessageContent.java

private void initUi() {
    setProgressBarIndeterminateVisibility(true);

    mScaleDetector = new ScaleGestureDetector(this, new MyScaleListener());

    Cursor cursor = moveCursorToCurrentMsg(mCursor, mMsgId);
    if (cursor != null) {
        mPagerAdapter = new MessageDetailAdapter(this, cursor);
        mPagerAdapter.setScaleTextList(mSlidePaperItemTextViews);
        mContentPager = (ViewPager) findViewById(R.id.details_view_pager);
        mContentPager.setAdapter(mPagerAdapter);
        mContentPager.setCurrentItem(cursor.getPosition());
    }/*from   ww w  .j  ava  2s . com*/

    ActionBar actionBar = getActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);
}