PageRenderTime 18ms CodeModel.GetById 10ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/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
 14package com.nimbits.android.activity;
 15
 16import android.app.Activity;
 17import android.content.Intent;
 18import android.os.Bundle;
 19import android.view.GestureDetector;
 20import android.view.MotionEvent;
 21import android.webkit.CookieManager;
 22import android.webkit.CookieSyncManager;
 23import android.webkit.WebView;
 24import android.webkit.WebViewClient;
 25import com.nimbits.android.R;
 26import com.nimbits.android.dao.LocalDatabaseDaoFactory;
 27import com.nimbits.android.json.GsonFactory;
 28import com.nimbits.client.model.Const;
 29import com.nimbits.client.model.diagram.Diagram;
 30import com.nimbits.client.model.diagram.DiagramModel;
 31
 32/**
 33 * Created by bsautner
 34 * User: benjamin
 35 * Date: 7/13/11
 36 * Time: 12:33 PM
 37 */
 38public class DiagramActivity extends Activity implements GestureDetector.OnGestureListener {
 39    private WebView mWebView;
 40    public void onCreate(Bundle savedInstanceState) {
 41
 42        super.onCreate(savedInstanceState);
 43        setContentView(R.layout.diagram_view);
 44        Bundle b = getIntent().getExtras();
 45        final String baseURL = b.getString(Const.PARAM_BASE_URL);
 46        String cookie = b.getString(Const.PARAM_COOKIE);
 47        String diagramName = b.getString(Const.PARAM_DIAGRAM);
 48        //String category = b.getString(Const.PARAM_CATEGORY);
 49        String json = b.getString(Const.PARAM_JSON);
 50        this.setTitle(diagramName);
 51        CookieSyncManager.createInstance(this);
 52        CookieManager cookieManager = CookieManager.getInstance();
 53        cookieManager.removeSessionCookie();
 54        cookieManager.setCookie(baseURL, cookie);
 55
 56        CookieSyncManager.getInstance().sync();
 57
 58        if (json != null)  {
 59            final Diagram diagram = GsonFactory.getInstance().fromJson(json, DiagramModel.class);
 60            mWebView = (WebView) findViewById(R.id.webview);
 61            mWebView.setWebViewClient(new WebViewClient() {
 62                @Override
 63                public boolean shouldOverrideUrlLoading(WebView view, String url)  {
 64                    if (url.contains("?" + Const.PARAM_CLIENT + "=" + Const.WORD_ANDROID)) {
 65                        processPointClickedResponse(url, baseURL);
 66                        return true;
 67
 68                    }
 69                    else {
 70                    view.loadUrl(url);
 71                    return true;
 72                    }
 73
 74                }
 75            });
 76            mWebView.getSettings().setJavaScriptEnabled(true);
 77//            Map<String, String> headers = new HashMap<String, String>();
 78//            headers.put("Cookie", cookie);
 79            mWebView.loadUrl(baseURL + "?" + Const.PARAM_DIAGRAM + "=" + diagram.getUuid() + "&" + Const.PARAM_CLIENT + "=" + Const.WORD_ANDROID);
 80        }
 81
 82    }
 83
 84    private void processPointClickedResponse(final String url,final  String baseURL) {
 85        String[] parts = url.split("&");
 86        if (parts.length > 1) {
 87            String s = parts[1];
 88            String[] x = s.split("=");
 89            if (x.length > 1) {
 90                String pointName = x[1];
 91                if (! (pointName == null)) {
 92                    final String json = LocalDatabaseDaoFactory.getInstance().getSelectedChildTableJsonByName(this,pointName);
 93                    final Bundle b = new Bundle();
 94                    final Intent intent = new Intent();
 95                    b.putString(Const.PARAM_CATEGORY, "");
 96                    b.putString(Const.PARAM_POINT,pointName);
 97                    b.putString(Const.PARAM_JSON,json);
 98                    b.putString(Const.PARAM_BASE_URL,baseURL);
 99                    intent.putExtras(b);
100                    intent.setClass(this, PointActivity.class );
101                    finish();
102                    startActivity(intent);
103                }
104            }
105        }
106    }
107
108    @Override
109    public boolean onDown(MotionEvent motionEvent) {
110        return false;  //To change body of implemented methods use File | Settings | File Templates.
111    }
112
113    @Override
114    public void onShowPress(MotionEvent motionEvent) {
115        //To change body of implemented methods use File | Settings | File Templates.
116    }
117
118    @Override
119    public boolean onSingleTapUp(MotionEvent motionEvent) {
120        return false;  //To change body of implemented methods use File | Settings | File Templates.
121    }
122
123    @Override
124    public boolean onScroll(MotionEvent motionEvent, MotionEvent motionEvent1, float v, float v1) {
125        return false;  //To change body of implemented methods use File | Settings | File Templates.
126    }
127
128    @Override
129    public void onLongPress(MotionEvent motionEvent) {
130        //To change body of implemented methods use File | Settings | File Templates.
131    }
132
133    @Override
134    public boolean onFling(MotionEvent motionEvent, MotionEvent motionEvent1, float v, float v1) {
135        return false;  //To change body of implemented methods use File | Settings | File Templates.
136    }
137}