Example usage for android.gesture GestureOverlayView setGestureVisible

List of usage examples for android.gesture GestureOverlayView setGestureVisible

Introduction

In this page you can find the example usage for android.gesture GestureOverlayView setGestureVisible.

Prototype

public void setGestureVisible(boolean visible) 

Source Link

Usage

From source file:Main.java

/**
 * add GestureOverlayView to an activity
 * @param activity// w  w w .  j  av a  2  s. c  o m
 * @return added GestureOverlayView
 */
public static GestureOverlayView addGestureViewToActivity(Activity activity) {
    View contentView = getContentView(activity);
    GestureOverlayView view = new GestureOverlayView(activity);
    view.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
            LinearLayout.LayoutParams.MATCH_PARENT, 1));

    activity.setContentView(view);
    view.addView(contentView); // adds the PhoneGap browser
    view.getChildAt(0).setLayoutParams(new FrameLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
            FrameLayout.LayoutParams.MATCH_PARENT, 1));

    activity.setContentView(view);
    view.setGestureVisible(false);

    return view;
}

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

@Override
protected void onCreate(Bundle savedInstanceState) {
    mIsSmsEnabled = MmsConfig.isSmsEnabled(this);
    super.onCreate(savedInstanceState);

    resetConfiguration(getResources().getConfiguration());

    SharedPreferences prefs = PreferenceManager
            .getDefaultSharedPreferences((Context) ComposeMessageActivity.this);
    mGestureSensitivity = prefs.getInt(MessagingPreferenceActivity.GESTURE_SENSITIVITY_VALUE, 3);
    mEnableEmoticons = prefs.getBoolean(MessagingPreferenceActivity.ENABLE_EMOTICONS, true);
    boolean showGesture = prefs.getBoolean(MessagingPreferenceActivity.SHOW_GESTURE, false);
    int unicodeStripping = prefs.getInt(MessagingPreferenceActivity.UNICODE_STRIPPING_VALUE,
            MessagingPreferenceActivity.UNICODE_STRIPPING_LEAVE_INTACT);
    mInputMethod = Integer.parseInt(prefs.getString(MessagingPreferenceActivity.INPUT_TYPE,
            Integer.toString(InputType.TYPE_TEXT_VARIATION_SHORT_MESSAGE)));

    mLibrary = TemplateGesturesLibrary.getStore(this);

    int layout = R.layout.compose_message_activity;

    GestureOverlayView gestureOverlayView = new GestureOverlayView(this);
    View inflate = getLayoutInflater().inflate(layout, null);
    gestureOverlayView.addView(inflate);
    gestureOverlayView.setEventsInterceptionEnabled(true);
    gestureOverlayView.setGestureVisible(showGesture);
    gestureOverlayView.addOnGesturePerformedListener(this);
    setContentView(gestureOverlayView);//from  www  .  j  a  v a  2 s  .co  m
    setProgressBarVisibility(false);

    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE
            | WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);

    // Initialize members for UI elements.
    initResourceRefs();

    LengthFilter lengthFilter = new LengthFilter(MmsConfig.getMaxTextLimit());
    mTextEditor.setFilters(new InputFilter[] { lengthFilter });

    if (unicodeStripping != MessagingPreferenceActivity.UNICODE_STRIPPING_LEAVE_INTACT) {
        boolean stripNonDecodableOnly = unicodeStripping == MessagingPreferenceActivity.UNICODE_STRIPPING_NON_DECODABLE;
        mUnicodeFilter = new UnicodeFilter(stripNonDecodableOnly);
    }

    mContentResolver = getContentResolver();
    mBackgroundQueryHandler = new BackgroundQueryHandler(mContentResolver);

    initialize(savedInstanceState, 0);

    mMultiSensorManager = new MultiSensorManager((Context) ComposeMessageActivity.this, this);

    if (TRACE) {
        android.os.Debug.startMethodTracing("compose");
    }
}

From source file:jmri.enginedriver.throttle.java

@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
@SuppressLint({ "Recycle", "SetJavaScriptEnabled", "ClickableViewAccessibility" })
@Override/*from   www. ja va2s  . co  m*/
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (savedInstanceState != null) {
        try {
            // restore the requested throttle direction so we can update the
            // direction indication while we wait for an update from WiT
            for (int throttleIndex = 0; throttleIndex < mainapp.maxThrottlesCurrentScreen; throttleIndex++) {
                if (savedInstanceState
                        .getSerializable("dir" + mainapp.throttleIntToString(throttleIndex)) != null)
                    dirs[throttleIndex] = (int) savedInstanceState.getSerializable("dir" + throttleIndex);
            }
        } catch (Exception ignored) { // log the error, but otherwise keep going.
            Log.d("Engine_Driver",
                    "Restore of saved instance state failed " + android.os.Build.VERSION.SDK_INT);
        }
    }

    mainapp = (threaded_application) this.getApplication();

    prefs = getSharedPreferences("jmri.enginedriver_preferences", 0);

    if (mainapp.isForcingFinish()) { // expedite
        mainapp.appIsFinishing = true;
        return;
    }

    mainapp.applyTheme(this);
    setTitle(getApplicationContext().getResources().getString(R.string.app_name_throttle)); // needed in case the language was changed from the default

    //        setContentView(R.layout.throttle);
    setContentView(layoutViewId);

    getCommonPrefs(true); // get all the common preferences
    setThottleNumLimits();

    getDirectionButtonPrefs();

    webViewIsOn = !webViewLocation.equals(WEB_VIEW_LOCATION_NONE);
    keepWebViewLocation = webViewLocation;

    isScreenLocked = false;

    // get the screen brightness on create
    screenBrightnessOriginal = getScreenBrightness();
    screenBrightnessModeOriginal = getScreenBrightnessMode();

    // myGesture = new GestureDetector(this);
    GestureOverlayView ov = findViewById(R.id.throttle_overlay);
    ov.addOnGestureListener(this);
    ov.setGestureVisible(false);

    direction_button_touch_listener dbtl;
    function_button_touch_listener fbtl;
    select_function_button_touch_listener sfbt;
    arrow_speed_button_touch_listener asbl;

    bSels = new Button[mainapp.maxThrottles];
    bRSpds = new Button[mainapp.maxThrottles];
    bLSpds = new Button[mainapp.maxThrottles];

    tvLeftDirInds = new TextView[mainapp.maxThrottles];
    tvRightDirInds = new TextView[mainapp.maxThrottles];

    bFwds = new Button[mainapp.maxThrottles];
    bStops = new Button[mainapp.maxThrottles];
    bRevs = new Button[mainapp.maxThrottles];
    sbs = new SeekBar[mainapp.maxThrottles];

    tvGamePads = new TextView[mainapp.maxThrottles];
    tvSpdLabs = new TextView[mainapp.maxThrottles];
    tvSpdVals = new TextView[mainapp.maxThrottles];
    tvVols = new TextView[mainapp.maxThrottles];

    lls = new LinearLayout[mainapp.maxThrottles];
    llSetSpds = new LinearLayout[mainapp.maxThrottles];
    llLocoIds = new LinearLayout[mainapp.maxThrottles];
    llLocoDirs = new LinearLayout[mainapp.maxThrottles];

    fbs = new ViewGroup[mainapp.maxThrottles];

    tops = new int[mainapp.maxThrottles];
    bottoms = new int[mainapp.maxThrottles];

    functionMaps = (LinkedHashMap<Integer, Button>[]) new LinkedHashMap<?, ?>[mainapp.maxThrottles];

    displayUnitScales = new double[mainapp.maxThrottles];

    changeTimers = new ChangeDelay[mainapp.maxThrottles];

    // throttle layouts
    vThrotScr = findViewById(R.id.throttle_screen);
    vThrotScrWrap = findViewById(R.id.throttle_screen_wrapper);

    for (int i = 0; i < mainapp.maxThrottles; i++) {
        // set listener for select loco buttons
        Button bSel = findViewById(R.id.button_select_loco_0);
        TextView tvLeft = findViewById(R.id.loco_left_direction_indicaton_0);
        TextView tvRight = findViewById(R.id.loco_right_direction_indicaton_0);
        switch (i) {
        case 1:
            bSel = findViewById(R.id.button_select_loco_1);
            tvLeft = findViewById(R.id.loco_left_direction_indicaton_1);
            tvRight = findViewById(R.id.loco_right_direction_indicaton_1);
            break;
        case 2:
            bSel = findViewById(R.id.button_select_loco_2);
            tvLeft = findViewById(R.id.loco_left_direction_indicaton_2);
            tvRight = findViewById(R.id.loco_right_direction_indicaton_2);
            break;
        case 3:
            bSel = findViewById(R.id.button_select_loco_3);
            tvLeft = findViewById(R.id.loco_left_direction_indicaton_3);
            tvRight = findViewById(R.id.loco_right_direction_indicaton_3);
            break;
        case 4:
            bSel = findViewById(R.id.button_select_loco_4);
            tvLeft = findViewById(R.id.loco_left_direction_indicaton_4);
            tvRight = findViewById(R.id.loco_right_direction_indicaton_4);
            break;
        case 5:
            bSel = findViewById(R.id.button_select_loco_5);
            tvLeft = findViewById(R.id.loco_left_direction_indicaton_5);
            tvRight = findViewById(R.id.loco_right_direction_indicaton_5);
            break;
        }
        bSels[i] = bSel;
        bSels[i].setClickable(true);
        sfbt = new select_function_button_touch_listener(i);
        bSels[i].setOnClickListener(sfbt);
        bSels[i].setOnTouchListener(sfbt);
        bSels[i].setOnLongClickListener(sfbt); // Consist Light Edit
        tvLeftDirInds[i] = tvLeft;
        tvRightDirInds[i] = tvRight;

        // Arrow Keys
        try {

            Button bRight = findViewById(R.id.right_speed_button_0);
            Button bLeft = findViewById(R.id.left_speed_button_0);
            switch (i) {
            case 1:
                bRight = findViewById(R.id.right_speed_button_1);
                bLeft = findViewById(R.id.left_speed_button_1);
                break;
            case 2:
                bRight = findViewById(R.id.right_speed_button_2);
                bLeft = findViewById(R.id.left_speed_button_2);
                break;
            case 3:
                bRight = findViewById(R.id.right_speed_button_3);
                bLeft = findViewById(R.id.left_speed_button_3);
                break;
            case 4:
                bRight = findViewById(R.id.right_speed_button_4);
                bLeft = findViewById(R.id.left_speed_button_4);
                break;
            case 5:
                bRight = findViewById(R.id.right_speed_button_5);
                bLeft = findViewById(R.id.left_speed_button_5);
                break;
            }
            bRSpds[i] = bRight;
            bRSpds[i].setClickable(true);
            asbl = new arrow_speed_button_touch_listener(i, "right");
            bRSpds[i].setOnLongClickListener(asbl);
            bRSpds[i].setOnTouchListener(asbl);
            bRSpds[i].setOnClickListener(asbl);

            bLSpds[i] = bLeft;
            bLSpds[i].setClickable(true);
            asbl = new arrow_speed_button_touch_listener(i, "left");
            bLSpds[i].setOnLongClickListener(asbl);
            bLSpds[i].setOnTouchListener(asbl);
            bLSpds[i].setOnClickListener(asbl);

        } catch (Exception ex) {
            Log.d("debug", "onCreate: " + ex.getMessage());
        }

        // set listeners for 3 direction buttons for each throttle
        //----------------------------------------
        Button bFwd = findViewById(R.id.button_fwd_0);
        Button bStop = findViewById(R.id.button_stop_0);
        Button bRev = findViewById(R.id.button_rev_0);
        View v = findViewById(R.id.speed_cell_0);
        switch (i) {
        case 1:
            bFwd = findViewById(R.id.button_fwd_1);
            bStop = findViewById(R.id.button_stop_1);
            bRev = findViewById(R.id.button_rev_1);
            v = findViewById(R.id.speed_cell_1);
            break;
        case 2:
            bFwd = findViewById(R.id.button_fwd_2);
            bStop = findViewById(R.id.button_stop_2);
            bRev = findViewById(R.id.button_rev_2);
            v = findViewById(R.id.speed_cell_2);
            break;
        case 3:
            bFwd = findViewById(R.id.button_fwd_3);
            bStop = findViewById(R.id.button_stop_3);
            bRev = findViewById(R.id.button_rev_3);
            v = findViewById(R.id.speed_cell_3);
            break;
        case 4:
            bFwd = findViewById(R.id.button_fwd_4);
            bStop = findViewById(R.id.button_stop_4);
            bRev = findViewById(R.id.button_rev_4);
            v = findViewById(R.id.speed_cell_4);
            break;
        case 5:
            bFwd = findViewById(R.id.button_fwd_5);
            bStop = findViewById(R.id.button_stop_5);
            bRev = findViewById(R.id.button_rev_5);
            v = findViewById(R.id.speed_cell_5);
            break;
        }

        bFwds[i] = bFwd;
        dbtl = new direction_button_touch_listener(direction_button.LEFT, i);
        bFwds[i].setOnTouchListener(dbtl);

        bStops[i] = bStop;
        fbtl = new function_button_touch_listener(function_button.STOP, i);
        bStops[i].setOnTouchListener(fbtl);

        bRevs[i] = bRev;
        dbtl = new direction_button_touch_listener(direction_button.RIGHT, i);
        bRevs[i].setOnTouchListener(dbtl);

        fbtl = new function_button_touch_listener(function_button.SPEED_LABEL, i);
        v.setOnTouchListener(fbtl);

        // set up listeners for all throttles
        SeekBar s = findViewById(R.id.speed_0);
        switch (i) {
        case 1:
            s = findViewById(R.id.speed_1);
            break;
        case 2:
            s = findViewById(R.id.speed_2);
            break;
        case 3:
            s = findViewById(R.id.speed_3);
            break;
        case 4:
            s = findViewById(R.id.speed_4);
            break;
        case 5:
            s = findViewById(R.id.speed_5);
            break;
        }
        throttle_listener thl;
        sbs[i] = s;
        thl = new throttle_listener(i);
        sbs[i].setOnSeekBarChangeListener(thl);
        sbs[i].setOnTouchListener(thl);

        max_throttle_change = 1;
        //          displaySpeedSteps = false;

        switch (i) {
        case 0:
            lls[i] = findViewById(R.id.throttle_0);
            //                    llSetSpds[i] = (LinearLayout) findViewById(R.id.throttle_0_setspeed);
            llLocoIds[i] = findViewById(R.id.loco_buttons_group_0);
            llLocoDirs[i] = findViewById(R.id.dir_buttons_table_0);
            tvVols[i] = findViewById(R.id.volume_indicator_0); // volume indicators
            tvGamePads[i] = findViewById(R.id.gamepad_indicator_0); // gamepad indicators
            tvSpdLabs[i] = findViewById(R.id.speed_label_0); // set_default_function_labels();
            tvSpdVals[i] = findViewById(R.id.speed_value_label_0);
            //**//                    fbs[i] = (ViewGroup) findViewById(R.id.function_buttons_table_0);
            break;
        case 1:
            lls[i] = findViewById(R.id.throttle_1);
            //                    llSetSpds[i] = (LinearLayout) findViewById(R.id.throttle_1_setspeed);
            llLocoIds[i] = findViewById(R.id.loco_buttons_group_1);
            llLocoDirs[i] = findViewById(R.id.dir_buttons_table_1);
            tvVols[i] = findViewById(R.id.volume_indicator_1); // volume indicators
            tvGamePads[i] = findViewById(R.id.gamepad_indicator_1); // gamepad indicators
            tvSpdLabs[i] = findViewById(R.id.speed_label_1); // set_default_function_labels();
            tvSpdVals[i] = findViewById(R.id.speed_value_label_1);
            //**//                    fbs[i] = (ViewGroup) findViewById(R.id.function_buttons_table_1);
            break;
        case 2:
            lls[i] = findViewById(R.id.throttle_2);
            //                    llSetSpds[i] = (LinearLayout) findViewById(R.id.throttle_2_setspeed);
            llLocoIds[i] = findViewById(R.id.loco_buttons_group_2);
            llLocoDirs[i] = findViewById(R.id.dir_buttons_table_2);
            tvVols[i] = findViewById(R.id.volume_indicator_2); // volume indicators
            tvGamePads[i] = findViewById(R.id.gamepad_indicator_2); // gamepad indicators
            tvSpdLabs[i] = findViewById(R.id.speed_label_2); // set_default_function_labels();
            tvSpdVals[i] = findViewById(R.id.speed_value_label_2);
            //**//                    fbs[i] = (ViewGroup) findViewById(R.id.function_buttons_table_2);
            break;
        case 3:
            lls[i] = findViewById(R.id.throttle_3);
            //                    llSetSpds[i] = (LinearLayout) findViewById(R.id.throttle_3_setspeed);
            llLocoIds[i] = findViewById(R.id.loco_buttons_group_3);
            llLocoDirs[i] = findViewById(R.id.dir_buttons_table_3);
            tvVols[i] = findViewById(R.id.volume_indicator_3); // volume indicators
            tvGamePads[i] = findViewById(R.id.gamepad_indicator_3); // gamepad indicators
            tvSpdLabs[i] = findViewById(R.id.speed_label_3); // set_default_function_labels();
            tvSpdVals[i] = findViewById(R.id.speed_value_label_3);
            //**//                    fbs[i] = (ViewGroup) findViewById(R.id.function_buttons_table_3);
            break;
        case 4:
            lls[i] = findViewById(R.id.throttle_4);
            //                    llSetSpds[i] = (LinearLayout) findViewById(R.id.throttle_4_setspeed);
            llLocoIds[i] = findViewById(R.id.loco_buttons_group_4);
            llLocoDirs[i] = findViewById(R.id.dir_buttons_table_4);
            tvVols[i] = findViewById(R.id.volume_indicator_4); // volume indicators
            tvGamePads[i] = findViewById(R.id.gamepad_indicator_4); // gamepad indicators
            tvSpdLabs[i] = findViewById(R.id.speed_label_4); // set_default_function_labels();
            tvSpdVals[i] = findViewById(R.id.speed_value_label_4);
            //**//                    fbs[i] = (ViewGroup) findViewById(R.id.function_buttons_table_4);
            break;
        case 5:
            lls[i] = findViewById(R.id.throttle_5);
            //                    llSetSpds[i] = (LinearLayout) findViewById(R.id.throttle_5_setspeed);
            llLocoIds[i] = findViewById(R.id.loco_buttons_group_5);
            llLocoDirs[i] = findViewById(R.id.dir_buttons_table_5);
            tvVols[i] = findViewById(R.id.volume_indicator_5); // volume indicators
            tvGamePads[i] = findViewById(R.id.gamepad_indicator_5); // gamepad indicators
            tvSpdLabs[i] = findViewById(R.id.speed_label_5); // set_default_function_labels();
            tvSpdVals[i] = findViewById(R.id.speed_value_label_5);
            //**//                    fbs[i] = (ViewGroup) findViewById(R.id.function_buttons_table_5);
            break;
        }

        // set throttle change delay timers
        changeTimers[i] = new ChangeDelay(i);

    }

    clearVolumeAndGamepadAdditionalIndicators();

    setDirectionButtonLabels(); // set all the direction button labels

    // set label and dcc functions (based on settings) or hide if no label
    setAllFunctionLabelsAndListeners();

    if (mVelocityTracker == null) {
        mVelocityTracker = VelocityTracker.obtain();
    }

    setActiveThrottle(0); // set the throttle the volume keys control depending on the preference to the default 0

    webView = findViewById(R.id.throttle_webview);
    String databasePath = webView.getContext().getDir("databases", Context.MODE_PRIVATE).getPath();
    webView.getSettings().setDatabasePath(databasePath);
    webView.getSettings().setJavaScriptEnabled(true);
    webView.getSettings().setBuiltInZoomControls(true); // Enable Multitouch
    // if supported
    webView.getSettings().setUseWideViewPort(true); // Enable greater
    // zoom-out
    webView.getSettings().setDefaultZoom(WebSettings.ZoomDensity.FAR);
    webView.setInitialScale((int) (100 * scale));
    // webView.getSettings().setLoadWithOverviewMode(true); // size image to
    // fill width

    // open all links inside the current view (don't start external web
    // browser)
    noUrl = getApplicationContext().getResources().getString(R.string.blank_page_url);

    WebViewClient EDWebClient = new WebViewClient() {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            return false;
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);
            if (!noUrl.equals(url)) { // if url is legit
                currentUrl = url;
                if (firstUrl == null) { // if this is the first legit url 
                    firstUrl = url;
                    clearHistory = true;
                }
                if (clearHistory) { // keep clearing history until off this page
                    if (url.equals(firstUrl)) { // (works around Android bug)
                        webView.clearHistory();
                    } else {
                        clearHistory = false;
                    }
                }
            }
        }
    };

    webView.setWebViewClient(EDWebClient);
    if (currentUrl == null || savedInstanceState == null || webView.restoreState(savedInstanceState) == null) {
        load_webview(); // reload if no saved state or no page had loaded when state was saved
    }
    // put pointer to this activity's handler in main app's shared variable
    mainapp.throttle_msg_handler = new throttle_handler();

    // set throttle change delay timers
    for (int throttleIndex = 0; throttleIndex < mainapp.maxThrottles; throttleIndex++) {
        changeTimers[throttleIndex] = new ChangeDelay(throttleIndex);
    }
    // tone generator for feedback sounds
    try {
        tg = new ToneGenerator(AudioManager.STREAM_NOTIFICATION,
                preferences.getIntPrefValue(prefs, "prefGamePadFeedbackVolume", getApplicationContext()
                        .getResources().getString(R.string.prefGamePadFeedbackVolumeDefaultValue)));
    } catch (RuntimeException e) {
        Log.e("Engine_Driver", "new ToneGenerator failed. Runtime Exception, OS "
                + android.os.Build.VERSION.SDK_INT + " Message: " + e);
    }
    // set GamePad Support
    setGamepadKeys();

    // initialise ESU MCII
    if (IS_ESU_MCII) {
        Log.d("Engine_Driver", "ESU_MCII: Initialise fragments...");
        int zeroTrim = preferences.getIntPrefValue(prefs, "prefEsuMc2ZeroTrim",
                getApplicationContext().getResources().getString(R.string.prefEsuMc2ZeroTrimDefaultValue));
        esuThrottleFragment = ThrottleFragment.newInstance(zeroTrim);
        esuThrottleFragment.setOnThrottleListener(esuOnThrottleListener);
        esuStopButtonFragment = StopButtonFragment.newInstance();
        esuStopButtonFragment.setOnStopButtonListener(esuOnStopButtonListener);
        Log.d("Engine_Driver", "ESU_MCII: ...fragments initialised");

        getSupportFragmentManager().beginTransaction().add(esuThrottleFragment, "mc2:throttle")
                .add(esuStopButtonFragment, "mc2:stopKey").commit();
        esuMc2Led.setState(EsuMc2Led.RED, EsuMc2LedState.OFF, true);
        esuMc2Led.setState(EsuMc2Led.GREEN, EsuMc2LedState.STEADY_FLASH, true);

        // Now apply knob zero trim
        updateEsuMc2ZeroTrim();
        Log.d("Engine_Driver", "ESU_MCII: Initialisation complete");
    }

    setupSensor(); // setup the support for shake actions.

    setupTts();

    if (prefs.getBoolean("prefImportServerAuto",
            getApplicationContext().getResources().getBoolean(R.bool.prefImportServerAutoDefaultValue))) {
        autoImportFromURL();
    }

}