use of android.gesture.GestureOverlayView in project EngineDriver by JMRI.
the class throttle method onCreate.
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
@SuppressLint({ "Recycle", "SetJavaScriptEnabled" })
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (savedInstanceState != null) {
// direction indication while we wait for an update from WiT
if (savedInstanceState.getSerializable("dirT") != null)
dirT = (int) savedInstanceState.getSerializable("dirT");
if (savedInstanceState.getSerializable("dirS") != null)
dirS = (int) savedInstanceState.getSerializable("dirS");
if (savedInstanceState.getSerializable("dirT") != null)
dirG = (int) savedInstanceState.getSerializable("dirG");
}
mainapp = (threaded_application) this.getApplication();
prefs = getSharedPreferences("jmri.enginedriver_preferences", 0);
if (mainapp.isForcingFinish()) {
// expedite
return;
}
mainapp.applyTheme(this);
setContentView(R.layout.throttle);
// get all the common preferences
getCommonPrefs(true);
DIRECTION_BUTTON_LEFT_TEXT = getApplicationContext().getResources().getString(R.string.forward);
DIRECTION_BUTTON_RIGHT_TEXT = getApplicationContext().getResources().getString(R.string.reverse);
speedButtonLeftText = getApplicationContext().getResources().getString(R.string.LeftButton);
speedButtonRightText = getApplicationContext().getResources().getString(R.string.RightButton);
speedButtonUpText = getApplicationContext().getResources().getString(R.string.UpButton);
speedButtonDownText = getApplicationContext().getResources().getString(R.string.DownButton);
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 = (GestureOverlayView) 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;
// set listener for select loco buttons
bSelT = (Button) findViewById(R.id.button_select_loco_T);
bSelT.setClickable(true);
sfbt = new select_function_button_touch_listener('T');
bSelT.setOnClickListener(sfbt);
bSelT.setOnTouchListener(sfbt);
// Consist Light Edit
bSelT.setOnLongClickListener(sfbt);
tvLeftDirIndT = (TextView) findViewById(R.id.loco_left_direction_indicaton_T);
tvRightDirIndT = (TextView) findViewById(R.id.loco_right_direction_indicaton_T);
bSelS = (Button) findViewById(R.id.button_select_loco_S);
bSelS.setClickable(true);
sfbt = new select_function_button_touch_listener('S');
bSelS.setOnClickListener(sfbt);
bSelS.setOnTouchListener(sfbt);
// Consist Light Edit
bSelS.setOnLongClickListener(sfbt);
tvLeftDirIndS = (TextView) findViewById(R.id.loco_left_direction_indicaton_S);
tvRightDirIndS = (TextView) findViewById(R.id.loco_right_direction_indicaton_S);
bSelG = (Button) findViewById(R.id.button_select_loco_G);
bSelG.setClickable(true);
sfbt = new select_function_button_touch_listener('G');
bSelG.setOnClickListener(sfbt);
bSelG.setOnTouchListener(sfbt);
// Consist Light Edit
bSelG.setOnLongClickListener(sfbt);
tvLeftDirIndG = (TextView) findViewById(R.id.loco_left_direction_indicaton_G);
tvRightDirIndG = (TextView) findViewById(R.id.loco_right_direction_indicaton_G);
clearVolumeAndGamepadAdditionalIndicators();
// Arrow Keys
try {
// Throttle T speed buttons.
bRSpdT = (Button) findViewById(R.id.Right_speed_button_T);
bRSpdT.setClickable(true);
asbl = new arrow_speed_button_touch_listener('T', "right");
bRSpdT.setOnLongClickListener(asbl);
bRSpdT.setOnTouchListener(asbl);
bRSpdT.setOnClickListener(asbl);
bLSpdT = (Button) findViewById(R.id.Left_speed_button_T);
bLSpdT.setClickable(true);
asbl = new arrow_speed_button_touch_listener('T', "left");
bLSpdT.setOnLongClickListener(asbl);
bLSpdT.setOnTouchListener(asbl);
bLSpdT.setOnClickListener(asbl);
// Throttle S speed buttons
bRSpdS = (Button) findViewById(R.id.Right_speed_button_S);
bRSpdS.setClickable(true);
asbl = new arrow_speed_button_touch_listener('S', "right");
bRSpdS.setOnLongClickListener(asbl);
bRSpdS.setOnTouchListener(asbl);
bRSpdS.setOnClickListener(asbl);
bLSpdS = (Button) findViewById(R.id.Left_speed_button_S);
bLSpdS.setClickable(true);
asbl = new arrow_speed_button_touch_listener('S', "left");
bLSpdS.setOnLongClickListener(asbl);
bLSpdS.setOnTouchListener(asbl);
bLSpdS.setOnClickListener(asbl);
// Throttle G speed buttons.
bRSpdG = (Button) findViewById(R.id.Right_speed_button_G);
bRSpdG.setClickable(true);
asbl = new arrow_speed_button_touch_listener('G', "right");
bRSpdG.setOnLongClickListener(asbl);
bRSpdG.setOnTouchListener(asbl);
bRSpdG.setOnClickListener(asbl);
bLSpdG = (Button) findViewById(R.id.Left_speed_button_G);
bLSpdG.setClickable(true);
asbl = new arrow_speed_button_touch_listener('G', "left");
bLSpdG.setOnLongClickListener(asbl);
bLSpdG.setOnTouchListener(asbl);
bLSpdG.setOnClickListener(asbl);
} catch (Exception ex) {
Log.d("debug", "onCreate: " + ex.getMessage());
}
// set listeners for 3 direction buttons for each throttle
// ----------------------------------------
bFwdT = (Button) findViewById(R.id.button_fwd_T);
dbtl = new direction_button_touch_listener(direction_button.LEFT, 'T');
bFwdT.setOnClickListener(dbtl);
bFwdT.setOnLongClickListener(dbtl);
bStopT = (Button) findViewById(R.id.button_stop_T);
fbtl = new function_button_touch_listener(function_button.STOP, 'T');
bStopT.setOnTouchListener(fbtl);
bRevT = (Button) findViewById(R.id.button_rev_T);
dbtl = new direction_button_touch_listener(direction_button.RIGHT, 'T');
bRevT.setOnClickListener(dbtl);
bRevT.setOnLongClickListener(dbtl);
// ----------------------------------------
View v = findViewById(R.id.speed_cell_T);
fbtl = new function_button_touch_listener(function_button.SPEED_LABEL, 'T');
v.setOnTouchListener(fbtl);
bRevT.setOnLongClickListener(dbtl);
// ----------------------------------------
bFwdS = (Button) findViewById(R.id.button_fwd_S);
dbtl = new direction_button_touch_listener(direction_button.LEFT, 'S');
bFwdS.setOnClickListener(dbtl);
bFwdS.setOnLongClickListener(dbtl);
bStopS = (Button) findViewById(R.id.button_stop_S);
fbtl = new function_button_touch_listener(function_button.STOP, 'S');
bStopS.setOnTouchListener(fbtl);
bRevS = (Button) findViewById(R.id.button_rev_S);
dbtl = new direction_button_touch_listener(direction_button.RIGHT, 'S');
bRevS.setOnClickListener(dbtl);
bRevS.setOnLongClickListener(dbtl);
// ----------------------------------------
v = findViewById(R.id.speed_cell_S);
fbtl = new function_button_touch_listener(function_button.SPEED_LABEL, 'S');
v.setOnTouchListener(fbtl);
bRevS.setOnLongClickListener(dbtl);
// ----------------------------------------
bFwdG = (Button) findViewById(R.id.button_fwd_G);
dbtl = new direction_button_touch_listener(direction_button.LEFT, 'G');
bFwdG.setOnClickListener(dbtl);
bFwdG.setOnLongClickListener(dbtl);
bStopG = (Button) findViewById(R.id.button_stop_G);
fbtl = new function_button_touch_listener(function_button.STOP, 'G');
bStopG.setOnTouchListener(fbtl);
bRevG = (Button) findViewById(R.id.button_rev_G);
dbtl = new direction_button_touch_listener(direction_button.RIGHT, 'G');
bRevG.setOnClickListener(dbtl);
bRevG.setOnLongClickListener(dbtl);
// ----------------------------------------
v = findViewById(R.id.speed_cell_G);
fbtl = new function_button_touch_listener(function_button.SPEED_LABEL, 'G');
v.setOnTouchListener(fbtl);
// set all the direction button labels
setDirectionButtonLabels();
// set up listeners for all throttles
throttle_listener thl;
sbT = (SeekBar) findViewById(R.id.speed_T);
thl = new throttle_listener('T');
sbT.setOnSeekBarChangeListener(thl);
sbT.setOnTouchListener(thl);
sbS = (SeekBar) findViewById(R.id.speed_S);
thl = new throttle_listener('S');
sbS.setOnSeekBarChangeListener(thl);
sbS.setOnTouchListener(thl);
sbG = (SeekBar) findViewById(R.id.speed_G);
thl = new throttle_listener('G');
sbG.setOnSeekBarChangeListener(thl);
sbG.setOnTouchListener(thl);
max_throttle_change = 1;
// displaySpeedSteps = false;
// throttle layouts
vThrotScr = findViewById(R.id.throttle_screen);
vThrotScrWrap = findViewById(R.id.throttle_screen_wrapper);
llT = (LinearLayout) findViewById(R.id.throttle_T);
llG = (LinearLayout) findViewById(R.id.throttle_G);
llS = (LinearLayout) findViewById(R.id.throttle_S);
llTSetSpd = (LinearLayout) findViewById(R.id.Throttle_T_SetSpeed);
llSSetSpd = (LinearLayout) findViewById(R.id.Throttle_S_SetSpeed);
llGSetSpd = (LinearLayout) findViewById(R.id.Throttle_G_SetSpeed);
// SPDHT
llTLocoId = (LinearLayout) findViewById(R.id.loco_buttons_group_T);
llSLocoId = (LinearLayout) findViewById(R.id.loco_buttons_group_S);
llGLocoId = (LinearLayout) findViewById(R.id.loco_buttons_group_G);
//
llTLocoDir = (LinearLayout) findViewById(R.id.dir_buttons_table_T);
llSLocoDir = (LinearLayout) findViewById(R.id.dir_buttons_table_S);
llGLocoDir = (LinearLayout) findViewById(R.id.dir_buttons_table_G);
// SPDHT
// volume indicators
tvVolT = (TextView) findViewById(R.id.volume_indicator_T);
tvVolS = (TextView) findViewById(R.id.volume_indicator_S);
tvVolG = (TextView) findViewById(R.id.volume_indicator_G);
// gamepad indicators
tvGamePadT = (TextView) findViewById(R.id.gamepad_indicator_T);
tvGamePadS = (TextView) findViewById(R.id.gamepad_indicator_S);
tvGamePadG = (TextView) findViewById(R.id.gamepad_indicator_G);
// set_default_function_labels();
tvSpdLabT = (TextView) findViewById(R.id.speed_label_T);
tvSpdValT = (TextView) findViewById(R.id.speed_value_label_T);
tvSpdLabG = (TextView) findViewById(R.id.speed_label_G);
tvSpdValG = (TextView) findViewById(R.id.speed_value_label_G);
tvSpdLabS = (TextView) findViewById(R.id.speed_label_S);
tvSpdValS = (TextView) findViewById(R.id.speed_value_label_S);
fbT = (ViewGroup) findViewById(R.id.function_buttons_table_T);
fbS = (ViewGroup) findViewById(R.id.function_buttons_table_S);
fbG = (ViewGroup) findViewById(R.id.function_buttons_table_G);
// set label and dcc functions (based on settings) or hide if no label
setAllFunctionLabelsAndListeners();
if (mVelocityTracker == null) {
mVelocityTracker = VelocityTracker.obtain();
}
// set the throttle the volume keys control depending on the preference to the default 'T'
setActiveThrottle('T');
webView = (WebView) findViewById(R.id.throttle_webview);
String databasePath = webView.getContext().getDir("databases", Context.MODE_PRIVATE).getPath();
webView.getSettings().setDatabasePath(databasePath);
webView.getSettings().setJavaScriptEnabled(true);
// Enable Multitouch
webView.getSettings().setBuiltInZoomControls(true);
// if supported
// Enable greater
webView.getSettings().setUseWideViewPort(true);
// 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)
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) {
// reload if no saved state or no page had loaded when state was saved
load_webview();
}
// 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
changeTimerT = new ChangeDelay('T');
changeTimerG = new ChangeDelay('G');
changeTimerS = new ChangeDelay('S');
// tone generator for feedback sounds
tg = new ToneGenerator(AudioManager.STREAM_NOTIFICATION, preferences.getIntPrefValue(prefs, "prefGamePadFeedbackVolume", getApplicationContext().getResources().getString(R.string.prefGamePadFeedbackVolumeDefaultValue)));
// 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");
}
// setup the support for shake actions.
setupSensor();
setupTts();
}
use of android.gesture.GestureOverlayView in project AnyMemo by helloworld1.
the class QACardActivity method loadGestures.
private void loadGestures() {
gestureLibrary = GestureLibraries.fromRawResource(this, R.raw.gestures);
if (!gestureLibrary.load()) {
Log.e(TAG, "Gestures can not be load");
}
GestureOverlayView gestureOverlay = (GestureOverlayView) findViewById(R.id.gesture_overlay);
gestureOverlay.addOnGesturePerformedListener(onGesturePerformedListener);
// Set if gestures are enabled if set on preference
gestureOverlay.setEnabled(option.getGestureEnabled());
}
Aggregations