/v3.2/nimbits-android/src/com/nimbits/android/activity/DiagramActivity.java

http://nimbits-server.googlecode.com/ · Java · 137 lines · 98 code · 16 blank · 23 comment · 8 complexity · a48eeb062ca8d074d67677eb6ab9f0bf MD5 · raw file

  1. /*
  2. * Copyright (c) 2010 Tonic Solutions LLC.
  3. *
  4. * http://www.nimbits.com
  5. *
  6. *
  7. * Licensed under the GNU GENERAL PUBLIC LICENSE, Version 3.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
  8. *
  9. * http://www.gnu.org/licenses/gpl.html
  10. *
  11. * Unless required by applicable law or agreed to in writing, software distributed under the license is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
  12. */
  13. package com.nimbits.android.activity;
  14. import android.app.Activity;
  15. import android.content.Intent;
  16. import android.os.Bundle;
  17. import android.view.GestureDetector;
  18. import android.view.MotionEvent;
  19. import android.webkit.CookieManager;
  20. import android.webkit.CookieSyncManager;
  21. import android.webkit.WebView;
  22. import android.webkit.WebViewClient;
  23. import com.nimbits.android.R;
  24. import com.nimbits.android.dao.LocalDatabaseDaoFactory;
  25. import com.nimbits.android.json.GsonFactory;
  26. import com.nimbits.client.model.Const;
  27. import com.nimbits.client.model.diagram.Diagram;
  28. import com.nimbits.client.model.diagram.DiagramModel;
  29. /**
  30. * Created by bsautner
  31. * User: benjamin
  32. * Date: 7/13/11
  33. * Time: 12:33 PM
  34. */
  35. public class DiagramActivity extends Activity implements GestureDetector.OnGestureListener {
  36. private WebView mWebView;
  37. public void onCreate(Bundle savedInstanceState) {
  38. super.onCreate(savedInstanceState);
  39. setContentView(R.layout.diagram_view);
  40. Bundle b = getIntent().getExtras();
  41. final String baseURL = b.getString(Const.PARAM_BASE_URL);
  42. String cookie = b.getString(Const.PARAM_COOKIE);
  43. String diagramName = b.getString(Const.PARAM_DIAGRAM);
  44. //String category = b.getString(Const.PARAM_CATEGORY);
  45. String json = b.getString(Const.PARAM_JSON);
  46. this.setTitle(diagramName);
  47. CookieSyncManager.createInstance(this);
  48. CookieManager cookieManager = CookieManager.getInstance();
  49. cookieManager.removeSessionCookie();
  50. cookieManager.setCookie(baseURL, cookie);
  51. CookieSyncManager.getInstance().sync();
  52. if (json != null) {
  53. final Diagram diagram = GsonFactory.getInstance().fromJson(json, DiagramModel.class);
  54. mWebView = (WebView) findViewById(R.id.webview);
  55. mWebView.setWebViewClient(new WebViewClient() {
  56. @Override
  57. public boolean shouldOverrideUrlLoading(WebView view, String url) {
  58. if (url.contains("?" + Const.PARAM_CLIENT + "=" + Const.WORD_ANDROID)) {
  59. processPointClickedResponse(url, baseURL);
  60. return true;
  61. }
  62. else {
  63. view.loadUrl(url);
  64. return true;
  65. }
  66. }
  67. });
  68. mWebView.getSettings().setJavaScriptEnabled(true);
  69. // Map<String, String> headers = new HashMap<String, String>();
  70. // headers.put("Cookie", cookie);
  71. mWebView.loadUrl(baseURL + "?" + Const.PARAM_DIAGRAM + "=" + diagram.getUuid() + "&" + Const.PARAM_CLIENT + "=" + Const.WORD_ANDROID);
  72. }
  73. }
  74. private void processPointClickedResponse(final String url,final String baseURL) {
  75. String[] parts = url.split("&");
  76. if (parts.length > 1) {
  77. String s = parts[1];
  78. String[] x = s.split("=");
  79. if (x.length > 1) {
  80. String pointName = x[1];
  81. if (! (pointName == null)) {
  82. final String json = LocalDatabaseDaoFactory.getInstance().getSelectedChildTableJsonByName(this,pointName);
  83. final Bundle b = new Bundle();
  84. final Intent intent = new Intent();
  85. b.putString(Const.PARAM_CATEGORY, "");
  86. b.putString(Const.PARAM_POINT,pointName);
  87. b.putString(Const.PARAM_JSON,json);
  88. b.putString(Const.PARAM_BASE_URL,baseURL);
  89. intent.putExtras(b);
  90. intent.setClass(this, PointActivity.class );
  91. finish();
  92. startActivity(intent);
  93. }
  94. }
  95. }
  96. }
  97. @Override
  98. public boolean onDown(MotionEvent motionEvent) {
  99. return false; //To change body of implemented methods use File | Settings | File Templates.
  100. }
  101. @Override
  102. public void onShowPress(MotionEvent motionEvent) {
  103. //To change body of implemented methods use File | Settings | File Templates.
  104. }
  105. @Override
  106. public boolean onSingleTapUp(MotionEvent motionEvent) {
  107. return false; //To change body of implemented methods use File | Settings | File Templates.
  108. }
  109. @Override
  110. public boolean onScroll(MotionEvent motionEvent, MotionEvent motionEvent1, float v, float v1) {
  111. return false; //To change body of implemented methods use File | Settings | File Templates.
  112. }
  113. @Override
  114. public void onLongPress(MotionEvent motionEvent) {
  115. //To change body of implemented methods use File | Settings | File Templates.
  116. }
  117. @Override
  118. public boolean onFling(MotionEvent motionEvent, MotionEvent motionEvent1, float v, float v1) {
  119. return false; //To change body of implemented methods use File | Settings | File Templates.
  120. }
  121. }