Version für alte Androidversionen der Visiereinstellung für Recurvebogen.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

RBSMainActivity.java 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  1. package ch.spherIC.recurvebowsight;
  2. import android.app.Activity;
  3. import android.content.Intent;
  4. import android.os.Bundle;
  5. import android.view.Menu;
  6. import android.view.MenuItem;
  7. import android.view.MotionEvent;
  8. import android.view.View;
  9. import android.view.View.OnTouchListener;
  10. import android.widget.AdapterView;
  11. import android.widget.ArrayAdapter;
  12. import android.widget.ListView;
  13. import android.widget.ScrollView;
  14. import android.widget.Spinner;
  15. import android.widget.ViewFlipper;
  16. import ch.spherIC.recurvebowsight.components.FontArrayAdapter;
  17. import ch.spherIC.recurvebowsight.components.XSpinner;
  18. import ch.spherIC.recurvebowsight.components.XTextView;
  19. import ch.spherIC.recurvebowsight.database.RBSDatabaseHelper;
  20. import java.util.ArrayList;
  21. import java.util.Arrays;
  22. public class RBSMainActivity extends Activity {
  23. private static final int MIN_DISTANCE = 50;
  24. private ViewFlipper viewFlipper;
  25. private ScrollView paramsScrollView;
  26. private ScrollView sightCfgScrollView;
  27. private float lastX;
  28. private ListView listView1;
  29. private XTextView txtViewParams;
  30. private XTextView txtViewResults;
  31. private XTextView txtViewSight;
  32. private Spinner calcTimeIntervalCboBox;
  33. private XSpinner calcAccuracyCboBox;
  34. private Activity riserSightConfigActivity;
  35. @Override
  36. public void onCreate(final Bundle savedInstanceState) {
  37. super.onCreate(savedInstanceState);
  38. setContentView(R.layout.rbs_main);
  39. RBSDatabaseHelper.setContext(this);
  40. RBSDatabaseHelper helper = RBSDatabaseHelper.getInstance();
  41. helper.getWritableDatabase();
  42. this.viewFlipper = (ViewFlipper) findViewById(R.id.viewFlipper);
  43. this.paramsScrollView = (ScrollView) findViewById(R.id.paramsScrollView);
  44. this.sightCfgScrollView = (ScrollView) findViewById(R.id.sightCfgScrollView);
  45. this.txtViewParams = (XTextView) findViewById(R.id.viewParams);
  46. this.txtViewResults = (XTextView) findViewById(R.id.viewResults);
  47. this.txtViewSight = (XTextView) findViewById(R.id.viewSight);
  48. this.calcTimeIntervalCboBox = (Spinner) findViewById(R.id.deltaTimeCboBox);
  49. this.calcAccuracyCboBox = (XSpinner) findViewById(R.id.calcPrecisionCboBox);
  50. // Scrollview muss den Swipe selbst handeln
  51. this.paramsScrollView.setOnTouchListener(new OnTouchListener() {
  52. private float downX, downY, upX, upY;
  53. @Override
  54. public boolean onTouch(final View v, final MotionEvent event) {
  55. switch (event.getAction()) {
  56. case MotionEvent.ACTION_DOWN: {
  57. this.downX = event.getX();
  58. this.downY = event.getY();
  59. }
  60. case MotionEvent.ACTION_UP: {
  61. this.upX = event.getX();
  62. this.upY = event.getY();
  63. float deltaX = this.upX - this.downX;
  64. float deltaY = this.upY - this.downY;
  65. // swipe from right to left ?
  66. if (deltaX < 0 && Math.abs(deltaX) > MIN_DISTANCE && Math.abs(deltaY) < MIN_DISTANCE) {
  67. // set the required Animation type to ViewFlipper
  68. // The Next screen will come in form Right and current Screen will go OUT to Left
  69. RBSMainActivity.this.viewFlipper.setInAnimation(RBSMainActivity.this, R.anim.in_from_right);
  70. RBSMainActivity.this.viewFlipper.setOutAnimation(RBSMainActivity.this, R.anim.out_to_left);
  71. // Show The Next Screen
  72. RBSMainActivity.this.viewFlipper.showNext();
  73. deactivateXTextView(RBSMainActivity.this.txtViewParams);
  74. xTextViewUp(RBSMainActivity.this.txtViewResults);
  75. deactivateXTextView(RBSMainActivity.this.txtViewSight);
  76. }
  77. }
  78. }
  79. return false;
  80. }
  81. });
  82. // Scrollview muss den Swipe selbst handeln
  83. this.sightCfgScrollView.setOnTouchListener(new OnTouchListener() {
  84. private float downX, downY, upX, upY;
  85. @Override
  86. public boolean onTouch(final View v, final MotionEvent event) {
  87. switch (event.getAction()) {
  88. case MotionEvent.ACTION_DOWN: {
  89. this.downX = event.getX();
  90. this.downY = event.getY();
  91. }
  92. case MotionEvent.ACTION_UP: {
  93. this.upX = event.getX();
  94. this.upY = event.getY();
  95. float deltaX = this.upX - this.downX;
  96. float deltaY = this.upY - this.downY;
  97. // swipe from left to right?
  98. if (deltaX > 0 && Math.abs(deltaX) > MIN_DISTANCE && Math.abs(deltaY) < MIN_DISTANCE) {
  99. // set the required Animation type to ViewFlipper
  100. // The Next screen will come in form Right and current Screen will go OUT to Left
  101. RBSMainActivity.this.viewFlipper.setInAnimation(RBSMainActivity.this, R.anim.in_from_left);
  102. RBSMainActivity.this.viewFlipper.setOutAnimation(RBSMainActivity.this, R.anim.out_to_right);
  103. // Show The Next Screen
  104. RBSMainActivity.this.viewFlipper.showPrevious();
  105. deactivateXTextView(RBSMainActivity.this.txtViewSight);
  106. xTextViewUp(RBSMainActivity.this.txtViewResults);
  107. deactivateXTextView(RBSMainActivity.this.txtViewParams);
  108. }
  109. }
  110. }
  111. return false;
  112. }
  113. });
  114. // Touchlistener für die oberen 3 Tabs
  115. OnTouchListener tabListener = new OnTouchListener() {
  116. @Override
  117. public boolean onTouch(final View v, final MotionEvent event) {
  118. switch (event.getAction()) {
  119. case MotionEvent.ACTION_DOWN: {
  120. deactivateXTextView(RBSMainActivity.this.txtViewParams);
  121. deactivateXTextView(RBSMainActivity.this.txtViewResults);
  122. deactivateXTextView(RBSMainActivity.this.txtViewSight);
  123. xTextViewDown((XTextView) v);
  124. return true;
  125. }
  126. case MotionEvent.ACTION_UP: {
  127. RBSMainActivity.this.viewFlipper.setInAnimation(RBSMainActivity.this, R.anim.in_from_right);
  128. RBSMainActivity.this.viewFlipper.setOutAnimation(RBSMainActivity.this, R.anim.out_to_left);
  129. if (v == RBSMainActivity.this.txtViewParams) {
  130. if (RBSMainActivity.this.viewFlipper.getDisplayedChild() != 0) {
  131. RBSMainActivity.this.viewFlipper.setDisplayedChild(0);
  132. }
  133. } else if (v == RBSMainActivity.this.txtViewResults) {
  134. if (RBSMainActivity.this.viewFlipper.getDisplayedChild() != 1) {
  135. RBSMainActivity.this.viewFlipper.setDisplayedChild(1);
  136. }
  137. } else {
  138. if (RBSMainActivity.this.viewFlipper.getDisplayedChild() != 2) {
  139. RBSMainActivity.this.viewFlipper.setDisplayedChild(2);
  140. }
  141. }
  142. xTextViewUp((XTextView) v);
  143. return true;
  144. }
  145. }
  146. return false;
  147. }
  148. };
  149. // Touchlistener an Tabs anhängen
  150. this.txtViewParams.setOnTouchListener(tabListener);
  151. this.txtViewResults.setOnTouchListener(tabListener);
  152. this.txtViewSight.setOnTouchListener(tabListener);
  153. xTextViewUp(this.txtViewParams);
  154. this.calcTimeIntervalCboBox.setAdapter(new FontArrayAdapter<String>(this, R.layout.rbs_spinner,
  155. getResources().getStringArray(R.array.CalculationTimeIntervals),
  156. this.calcTimeIntervalCboBox));
  157. this.calcAccuracyCboBox.setAdapter(new FontArrayAdapter<String>(this, R.layout.rbs_spinner,
  158. getResources().getStringArray(R.array.CalculationAccuracies),
  159. this.calcAccuracyCboBox));
  160. // ************************************************************************
  161. // ** TEST WEISE AB HIER***************************************************
  162. // ************************************************************************
  163. this.listView1 = (ListView) findViewById(R.id.listView1);
  164. String[] values = new String[] { "Riser", "Sight", "General Config" };
  165. final ArrayList<String> list = new ArrayList<String>(Arrays.asList(values));
  166. final ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, list);
  167. this.listView1.setAdapter(adapter);
  168. this.listView1.setOnItemClickListener(new AdapterView.OnItemClickListener() {
  169. @Override
  170. public void onItemClick(final AdapterView<?> parent, final View view, final int position,
  171. final long id) {
  172. final String item = (String) parent.getItemAtPosition(position);
  173. if (item.equals("Riser")) {
  174. Intent intent = new Intent(RBSMainActivity.this, RiserSightConfigurationActivity.class);
  175. startActivity(intent);
  176. }
  177. }
  178. });
  179. }
  180. @Override
  181. public boolean onCreateOptionsMenu(final Menu menu) {
  182. getMenuInflater().inflate(R.menu.rbs_main, menu);
  183. getMenuInflater().inflate(R.menu.rbs_info_menu, menu.getItem(2).getSubMenu());
  184. return true;
  185. }
  186. @Override
  187. public boolean onOptionsItemSelected(MenuItem item) {
  188. return super.onOptionsItemSelected(item);
  189. }
  190. @Override
  191. public boolean onTouchEvent(final MotionEvent touchevent) {
  192. switch (touchevent.getAction()) {
  193. // when user first touches the screen to swap
  194. case MotionEvent.ACTION_DOWN: {
  195. this.lastX = touchevent.getX();
  196. break;
  197. }
  198. case MotionEvent.ACTION_UP: {
  199. float currentX = touchevent.getX();
  200. // if right to left swipe on screen
  201. if (this.lastX > currentX) {
  202. if (this.viewFlipper.getDisplayedChild() == 2) {
  203. break;
  204. }
  205. // set the required Animation type to ViewFlipper
  206. // The Next screen will come in form Right and current Screen will go OUT to Left
  207. this.viewFlipper.setInAnimation(this, R.anim.in_from_right);
  208. this.viewFlipper.setOutAnimation(this, R.anim.out_to_left);
  209. // Show The Next Screen
  210. this.viewFlipper.showNext();
  211. } else if (this.lastX < currentX) { // if left to right swipe on screen
  212. // If no more View/Child to flip
  213. if (this.viewFlipper.getDisplayedChild() == 0) {
  214. break;
  215. }
  216. // set the required Animation type to ViewFlipper
  217. // The Next screen will come in form Left and current Screen will go OUT to Right
  218. this.viewFlipper.setInAnimation(this, R.anim.in_from_left);
  219. this.viewFlipper.setOutAnimation(this, R.anim.out_to_right);
  220. // Show the previous Screen
  221. this.viewFlipper.showPrevious();
  222. }
  223. deactivateXTextView(RBSMainActivity.this.txtViewParams);
  224. deactivateXTextView(RBSMainActivity.this.txtViewResults);
  225. deactivateXTextView(RBSMainActivity.this.txtViewSight);
  226. switch (this.viewFlipper.getDisplayedChild()) {
  227. case 0:
  228. xTextViewUp(this.txtViewParams);
  229. break;
  230. case 1:
  231. xTextViewUp(this.txtViewResults);
  232. break;
  233. case 2:
  234. xTextViewUp(this.txtViewSight);
  235. break;
  236. default:
  237. break;
  238. }
  239. break;
  240. }
  241. }
  242. return false;
  243. }
  244. private void xTextViewDown(final XTextView view) {
  245. view.setDrawborderColor(getResources().getColor(R.color.android_blue_dark));
  246. view.setTextColor(getResources().getColor(R.color.android_blue_dark));
  247. }
  248. private void xTextViewUp(final XTextView view) {
  249. view.setDrawborderColor(getResources().getColor(R.color.android_blue));
  250. view.setTextColor(getResources().getColor(R.color.android_blue));
  251. }
  252. private void deactivateXTextView(final XTextView view) {
  253. view.setDrawborderColor(getResources().getColor(R.color.white));
  254. view.setTextColor(getResources().getColor(R.color.white));
  255. }
  256. }