joshuatee.wx.USWXOGLRadarActivity.java Source code

Java tutorial

Introduction

Here is the source code for joshuatee.wx.USWXOGLRadarActivity.java

Source

/*
    
Copyright 2013, 2014 joshua.tee@gmail.com
    
This file is part of wX.
    
wX is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
    
wX is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
    
You should have received a copy of the GNU General Public License
along with wX.  If not, see <http://www.gnu.org/licenses/>.
    
 */

package joshuatee.wx;

import java.io.File;
import java.util.regex.Pattern;

import joshuatee.wx.R;
import android.app.ActionBar;
import android.app.AlertDialog;
import android.app.ActionBar.OnNavigationListener;
import android.app.Activity;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.graphics.drawable.AnimationDrawable;
import android.opengl.GLSurfaceView;
import android.os.AsyncTask;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.view.GestureDetector;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.ScaleGestureDetector;
import android.view.View;
import android.view.Window;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.SpinnerAdapter;
import android.support.v4.view.GestureDetectorCompat;
import android.util.DisplayMetrics;
import android.util.TypedValue;

public class USWXOGLRadarActivity extends Activity
        implements GestureDetector.OnGestureListener, GestureDetector.OnDoubleTapListener {

    // This activity is a general purpose viewer of nexrad and mosaic content
    // nexrad data is downloaded from NWS FTP, decoded and drawn using OpenGL ES

    public static final String RID = "";

    float density = 0.0f;

    //String previous_rid = "";
    String[] anim_array = null;

    float mScaleFactor = 1.0f;
    boolean ogl_in_view = true;

    ScaleGestureDetector mScaleDetector;
    GestureDetectorCompat mGestureDetector;

    OpenGLRenderRadar2Dv4 OGLR;

    boolean restarted = false;
    boolean tilt_option = true;

    GLSurfaceView view;

    float init_zoom = 1.50f;
    float max_zoom = 6.0f; // was 4

    float x, y, x_middle, y_middle;
    boolean panned = false;
    float old_scalefactor;

    float diff_x, diff_y, ppd, new_x, new_y;
    String x_str, y_str, rid_tmp;
    double test2;
    float center_x = 0.0f;
    float center_y = 0.0f;

    String tilt = "0";

    String[] turl;
    String img_url = "";
    DisplayMetrics dm;
    String prod = "";

    AnimationDrawable animDrawable;

    SpinnerAdapter adapter;
    OnNavigationListener navigationListener;
    String[] rid_arr_loc;
    String rid1 = "";
    String state = "";
    String sector = "";

    String onek = "";

    boolean hw = false;
    //boolean spotters = false;

    int zoom_level_wv = 1;
    int zoom_level_ir = 1;
    int zoom_level_vis = 1;
    int zoom_level_radar = 0;

    ImageMap mImageMap;

    boolean map_shown = false;

    int star_icon;
    int star_outline_icon;
    MenuItem star;
    MenuItem map;
    int map_icon;
    MenuItem tv0;
    MenuItem tdwr;
    MenuItem anim;
    MenuItem tilt_menu;

    String rid_fav = "";
    TouchImageView2 img;

    SharedPreferences preferences;
    //SharedPreferences.Editor editor;

    String cod_warnings_default = "";
    String cod_cities_default = "";
    String cod_hw_default = "";
    String cod_locdot_default = "";
    String cod_lakes_default = "";

    int screen_width, screen_height;

    int statusBarHeight = 0;
    int actionBarHeight = 0;
    int navPanelHeight = 0;

    boolean ab_split = false;

    String tdwr_s = "";

    int delay;

    String theme_blue_current;

    final String pref_token_location = "RID_LOC_";
    final String pref_token = "RID_FAV";

    String old_state;
    String old_sector;
    String old_onek;
    //String rid_loc;

    Pattern space, comma;
    Pattern colon;

    Bitmap bitmap;
    String frame_cnt_str;

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {

        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.uswxoglradar, menu);

        if (theme_blue_current.contains("white")) {
            star_icon = R.drawable.star_dark;
            star_outline_icon = R.drawable.star_outline_dark;
            map_icon = R.drawable.map_dark;

        } else {
            star_icon = R.drawable.star;
            star_outline_icon = R.drawable.star_outline;
            map_icon = R.drawable.map;

        }

        star = menu.findItem(R.id.action_fav);
        map = menu.findItem(R.id.action_ridmap);
        map.setIcon(map_icon);

        tv0 = menu.findItem(R.id.action_tv0);
        tdwr = menu.findItem(R.id.action_tdwr);
        anim = menu.findItem(R.id.action_animate);
        tilt_menu = menu.findItem(R.id.action_tilt);

        if (rid_fav.contains(":" + rid1 + ":")) {
            star.setIcon(star_icon);

        } else {
            star.setIcon(star_outline_icon);
        }

        return true;
    }

    @Override
    public boolean onPrepareOptionsMenu(Menu menu) {

        tdwr_s = UtilityNexrad.GetTDWRFromRID(rid1);

        if (tdwr_s.equals("")) {
            tdwr.setVisible(false);

        } else {
            tdwr.setVisible(true);
        }

        if (tilt_option) {
            tilt_menu.setVisible(true);
        } else {
            tilt_menu.setVisible(false);
        }

        return true;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
        preferences = PreferenceManager.getDefaultSharedPreferences(this);
        //editor = preferences.edit();
        theme_blue_current = preferences.getString("THEME_BLUE", "");
        setTheme(Utility.Theme(theme_blue_current));

        //setContentView(R.layout.activity_uswxoglradar);

        if (!DataStore.loaded)
            DataStore.Init(this);

        space = Pattern.compile(" ");
        comma = Pattern.compile(",");
        colon = Pattern.compile(":");

        //mImageMap = (ImageMap) findViewById(R.id.map);
        //mImageMap.setVisibility(View.GONE);

        cod_warnings_default = preferences.getString("COD_WARNINGS_DEFAULT", "");
        cod_cities_default = preferences.getString("COD_CITIES_DEFAULT", "");
        cod_hw_default = preferences.getString("COD_HW_DEFAULT", "true");
        cod_locdot_default = preferences.getString("COD_LOCDOT_DEFAULT", "true");
        cod_lakes_default = preferences.getString("COD_LAKES_DEFAULT", "true");

        //delay = UtilityImg.GetAnimInterval(preferences);

        img = new TouchImageView2(getApplicationContext());
        img.setMaxZoom(max_zoom);
        img.setZoom(init_zoom);

        dm = new DisplayMetrics();
        this.getWindowManager().getDefaultDisplay().getMetrics(dm);

        boolean isActionBarSplitted = ((dm.widthPixels / dm.density) < 400.00f);
        if (isActionBarSplitted) {
            ab_split = true;
        }

        int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
        statusBarHeight = getResources().getDimensionPixelSize(resourceId);

        TypedValue tv = new TypedValue();
        getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true);
        actionBarHeight = getResources().getDimensionPixelSize(tv.resourceId);
        actionBarHeight *= dm.density;

        screen_width = dm.widthPixels;
        screen_height = dm.heightPixels - statusBarHeight - actionBarHeight;

        turl = getIntent().getStringArrayExtra(RID);

        prod = "N0Q";

        view = new GLSurfaceView(this);
        view.setEGLContextClientVersion(2);
        mScaleDetector = new ScaleGestureDetector(this, new ScaleListener());
        mGestureDetector = new GestureDetectorCompat(this, this);

        OGLR = new OpenGLRenderRadar2Dv4(this);
        view.setRenderer(OGLR);
        view.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);

        density = (float) (OGLR.ort_int * 2) / dm.widthPixels;

        setContentView(view);
        ogl_in_view = true;

        rid1 = turl[0];
        state = turl[1];
        if (turl.length > 2) {
            prod = turl[2];
            if (prod.equals("N0R")) {
                prod = "N0Q";
            }
        }

        //rid_fav = preferences.getString(pref_token," : : :");
        //sector = preferences.getString("COD_SECTOR_"+state,"");
        //state = preferences.getString("STATE_CODE_"+state,"");
        //onek = preferences.getString("COD_1KM_"+rid1,"");

        setTitle(prod);

        rid_fav = preferences.getString(pref_token, " : : :");
        rid_arr_loc = UtilityFavorites.SetupFavMenu(preferences, rid_fav, turl[0], pref_token_location, colon);
        adapter = new ArrayAdapter<String>(getBaseContext(), android.R.layout.simple_spinner_dropdown_item,
                rid_arr_loc);
        getActionBar().setListNavigationCallbacks(adapter, navigationListener);
        getActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);

        navigationListener = new OnNavigationListener() {

            @Override
            public boolean onNavigationItemSelected(int itemPosition, long itemId) {

                if (itemPosition == 0 || itemPosition > 2) {
                    rid1 = space.split(rid_arr_loc[itemPosition])[0];

                    //rid_loc = preferences.getString("RID_LOC_"+rid1,"");
                    //editor.putString("NEXRAD_LAST", rid1); 
                    //editor.commit();

                    old_state = state;
                    old_sector = sector;
                    old_onek = onek;
                    state = comma.split(preferences.getString("RID_LOC_" + rid1, ""))[0];
                    sector = preferences.getString("COD_SECTOR_" + state, "");
                    state = preferences.getString("STATE_CODE_" + state, "");
                    onek = preferences.getString("COD_1KM_" + rid1, "");

                    if (prod.equals("2k")) {
                        img_url = img_url.replace(old_sector, sector);
                        img_url = img_url.replace(old_state, state);
                        img_url = img_url.replace(old_onek, onek);
                    }
                    if (!restarted) {
                        img.resetZoom();
                        img.setZoom(init_zoom);
                        OGLR.setZoom(1.0f);
                        mScaleFactor = 1.0f;
                        OGLR.mPositionX = 0.0f;
                        OGLR.mPositionY = 0.0f;
                    }
                    restarted = false;
                    new GetContent().execute();
                } else if (itemPosition == 1) {
                    Intent dtx_srm = new Intent(getApplicationContext(), RIDAddFavActivity.class);
                    startActivity(dtx_srm);
                } else if (itemPosition == 2) {
                    Intent dtx_srm2 = new Intent(getApplicationContext(), RIDRemoveFavActivity.class);
                    startActivity(dtx_srm2);
                }

                return false;
            }
        };
        getActionBar().setListNavigationCallbacks(adapter, navigationListener);

    }

    protected void onRestart() {

        restarted = true;
        rid_fav = preferences.getString(pref_token, " : : :");
        rid_arr_loc = UtilityFavorites.SetupFavMenu(preferences, rid_fav, rid1, pref_token_location, colon);
        adapter = new ArrayAdapter<String>(getBaseContext(), android.R.layout.simple_spinner_dropdown_item,
                rid_arr_loc);

        getActionBar().setListNavigationCallbacks(adapter, navigationListener);

        super.onRestart();

    }

    private class GetContent extends AsyncTask<String, String, String> {

        @Override
        protected String doInBackground(String... params) {

            //if ( ! prod.equals("2k"))
            if (!prod.startsWith("2")) {

                OGLR.ConstructPolygons(rid1, prod, "");
                OGLR.ConstructStateLines(rid1, prod);

                if (cod_lakes_default.startsWith("t"))
                    OGLR.ConstructLakes(rid1, prod);

                if (cod_hw_default.startsWith("t"))
                    OGLR.ConstructHWLines(rid1, prod);

                if (cod_warnings_default.startsWith("t"))
                    OGLR.ConstructWarningFFWLines(rid1, prod);

                if (cod_locdot_default.startsWith("t"))
                    OGLR.ConstructLocationDot(rid1, prod);

                if (cod_cities_default.startsWith("t"))
                    OGLR.ConstructCities(rid1, prod);

            } else {

                if (img_url.equals("NVW"))
                    img_url = UtilityUSImgCOD.GetCODNVW(rid1, "NVW");

                bitmap = Utility.getBitmapFromURL(img_url);
            }

            return "Executed";
        }

        @Override
        protected void onPostExecute(String result) {

            //if ( ! prod.equals("2k"))
            if (!prod.startsWith("2")) {
                if (!ogl_in_view) {
                    setContentView(view);
                    ogl_in_view = true;
                }
                view.requestRender();

            } else {
                img.setImageBitmap(bitmap);
                setContentView(img);
                ogl_in_view = false;
            }

            if (rid_fav.contains(":" + rid1 + ":")) {
                star.setIcon(star_icon);

            } else {
                star.setIcon(star_outline_icon);
            }

            setProgressBarIndeterminateVisibility(false);

        }

        @Override
        protected void onPreExecute() {
            setProgressBarIndeterminateVisibility(true);

        }

        @Override
        protected void onProgressUpdate(String... values) {
        }
    }

    private class AnimateRadar extends AsyncTask<String, String, String> {

        @Override
        protected String doInBackground(String... params) {

            frame_cnt_str = params[0];
            anim_array = OGLR.GetRadarByFTPAnimation(getBaseContext(), frame_cnt_str);

            return "Executed";
        }

        @Override
        protected void onPostExecute(String result) {

            setProgressBarIndeterminateVisibility(false);
            if (!ogl_in_view) {
                setContentView(view);
                ogl_in_view = true;

            }

            int r = 0;
            //long time_milli;
            //long prior_time = System.currentTimeMillis();

            File fh;

            for (r = 0; r < anim_array.length; r++) {

                OGLR.ConstructPolygons(rid1, prod, anim_array[r]);
                view.requestRender();
                fh = new File(getBaseContext().getFilesDir(), anim_array[r]);
                getBaseContext().deleteFile("nexrad_anim" + Integer.toString(r));
                fh.renameTo(new File(getBaseContext().getFilesDir(), "nexrad_anim" + Integer.toString(r)));

                // code below doesn't work so well, seems choppy probably due to multitasking, etc
                /*   time_milli = System.currentTimeMillis();
                    
                if ( (time_milli-prior_time) < delay)
                {
                   SystemClock.sleep( delay - ((time_milli-prior_time)));
                }
                    
                prior_time = time_milli;*/

            }

        }

        @Override
        protected void onPreExecute() {

            setProgressBarIndeterminateVisibility(true);

        }

        @Override
        protected void onProgressUpdate(String... values) {
        }
    }

    private class AnimationRepeat extends AsyncTask<String, String, String> {

        @Override
        protected String doInBackground(String... params) {

            return "Executed";
        }

        @Override
        protected void onPostExecute(String result) {

            if (anim_array != null) {
                for (int r = 0; r < anim_array.length; r++) {
                    OGLR.ConstructPolygons(rid1, prod, "nexrad_anim" + Integer.toString(r));
                    view.requestRender();
                }
            }

        }

        @Override
        protected void onPreExecute() {

        }

        @Override
        protected void onProgressUpdate(String... values) {
        }
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {

        switch (item.getItemId()) {

        case R.id.action_n0q:
            prod = "N" + tilt + "Q";
            setTitle(prod);
            tilt_option = true;
            new GetContent().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
            return true;
        case R.id.action_n0u:
            prod = "N" + tilt + "U";
            setTitle(prod);
            tilt_option = true;
            new GetContent().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
            return true;

        case R.id.action_tv0:
            prod = "TV0";
            setTitle(prod);
            tilt_option = false;
            new GetContent().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
            return true;
        case R.id.action_tzl:
            prod = "TZL";
            setTitle(prod);
            tilt_option = false;
            new GetContent().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
            return true;

        case R.id.action_n0s:
            prod = "N" + tilt + "S";
            setTitle(prod);
            tilt_option = false;
            new GetContent().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
            return true;
        case R.id.action_net:
            prod = "EET";
            setTitle(prod);
            tilt_option = false;

            new GetContent().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
            return true;
        case R.id.action_DVL:
            prod = "DVL";
            setTitle(prod);
            tilt_option = false;

            new GetContent().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
            return true;

        case R.id.action_N0X:
            prod = "N" + tilt + "X";
            setTitle(prod);
            tilt_option = true;

            new GetContent().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
            return true;
        case R.id.action_N0C:
            prod = "N" + tilt + "C";
            setTitle(prod);
            tilt_option = true;

            new GetContent().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
            return true;
        case R.id.action_N0K:
            prod = "N" + tilt + "K";
            setTitle(prod);
            tilt_option = true;

            new GetContent().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
            return true;

        case R.id.action_about:
            ShowRadarScanInfo();
            return true;

        case R.id.action_vil:
            prod = "DVL";
            setTitle(prod);
            tilt_option = false;

            new GetContent().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
            return true;

        case R.id.action_dsp:
            prod = "DSP";
            setTitle(prod);
            tilt_option = false;
            new GetContent().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
            return true;

        case R.id.action_n0r:
            prod = "N0R";
            setTitle(prod);
            tilt_option = false;
            new GetContent().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
            return true;
        case R.id.action_n0v:
            prod = "N0V";
            setTitle(prod);
            tilt_option = false;
            new GetContent().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
            return true;

        case R.id.action_l2vel:
            prod = "L2VEL";
            setTitle(prod);
            tilt_option = false;
            new GetContent().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
            return true;

        case R.id.action_l2ref:
            prod = "L2REF";
            setTitle(prod);
            tilt_option = false;

            new GetContent().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
            return true;

        case R.id.action_tilt1:
            tilt = "0";
            prod = prod.replaceAll("N[0-3]", "N" + tilt);
            setTitle(prod);
            new GetContent().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
            return true;
        case R.id.action_tilt2:
            tilt = "1";
            prod = prod.replaceAll("N[0-3]", "N" + tilt);
            setTitle(prod);
            new GetContent().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
            return true;
        case R.id.action_tilt3:
            tilt = "2";
            prod = prod.replaceAll("N[0-3]", "N" + tilt);
            setTitle(prod);
            new GetContent().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
            return true;
        case R.id.action_tilt4:
            tilt = "3";
            prod = prod.replaceAll("N[0-3]", "N" + tilt);
            setTitle(prod);
            new GetContent().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
            return true;

        case R.id.action_animate_repeat:

            if (prod.equals("2k")) {

            } else {
                new AnimationRepeat().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
            }
            return true;

        case R.id.action_a12:
            setTitle(prod);
            if (prod.equals("2k")) {
                new AnimateRadarMosaic().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, "12", prod);

            } else {
                new AnimateRadar().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, "12", prod);
            }
            return true;
        case R.id.action_a18:
            setTitle(prod);
            if (prod.equals("2k")) {
                new AnimateRadarMosaic().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, "18", prod);

            } else {
                new AnimateRadar().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, "18", prod);
            }
            return true;
        case R.id.action_a6:
            setTitle(prod);
            if (prod.equals("2k")) {
                new AnimateRadarMosaic().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, "6", prod);

            } else {
                new AnimateRadar().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, "6", prod);
            }
            return true;

        case R.id.action_a36:
            setTitle(prod);
            if (prod.equals("2k")) {
                new AnimateRadarMosaic().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, "36", prod);

            } else {
                new AnimateRadar().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, "36", prod);
            }
            return true;

        case R.id.action_a3:
            setTitle(prod);
            if (prod.equals("2k")) {
                new AnimateRadarMosaic().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, "3", prod);

            } else {
                new AnimateRadar().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, "3", prod);
            }
            return true;

        case R.id.action_zoomout:
            setTitle(state + " Radar");
            img.resetZoom();
            if (zoom_level_radar == 0) {
                img_url = "http://climate.cod.edu/data/satellite/1km/" + onek + "/current/" + onek + ".rad.gif";
                zoom_level_radar++;
            } else if (zoom_level_radar == 1) {
                img_url = "http://climate.cod.edu/data/satellite/2km/" + state + "/current/" + state + ".rad.gif";
                zoom_level_radar++;
            } else if (zoom_level_radar == 2) {
                img_url = "http://climate.cod.edu/data/satellite/regional/" + sector + "/current/" + sector
                        + ".rad.gif";
                zoom_level_radar++;
            } else if (zoom_level_radar == 3) {
                img_url = "http://climate.cod.edu/data/satellite/regional/usa/current/usa.rad.gif";
                zoom_level_radar = 0;
            }
            prod = "2k";
            new GetContent().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
            return true;
        case R.id.action_vis:
            setTitle(state + " Vis");
            tilt_option = false;

            img.resetZoom();
            if (state.equals("HI") || state.equals("AK")) {
                zoom_level_vis = 3;
            }

            if (zoom_level_vis == 1) {
                img_url = "http://climate.cod.edu/data/satellite/1km/" + onek + "/current/" + onek + ".vis.gif";
                zoom_level_vis++;
            } else if (zoom_level_vis == 2) {
                img_url = "http://climate.cod.edu/data/satellite/2km/" + state + "/current/" + state + ".vis.gif";
                zoom_level_vis++;
            } else if (zoom_level_vis == 3) {
                img_url = "http://climate.cod.edu/data/satellite/regional/" + sector + "/current/" + sector
                        + ".vis.gif";
                zoom_level_vis++;
            } else if (zoom_level_vis == 4) {
                img_url = "http://climate.cod.edu/data/satellite/regional/usa/current/usa.vis.gif";
                zoom_level_vis = 1;
            }
            prod = "2k";
            new GetContent().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
            return true;
        case R.id.action_ir:
            setTitle(state + " IR");
            tilt_option = false;

            img.resetZoom();
            if (state.equals("HI") || state.equals("AK")) {
                zoom_level_ir = 2;
            }
            if (zoom_level_ir == 1) {
                img_url = "http://climate.cod.edu/data/satellite/2km/" + state + "/current/" + state + ".ir.gif";
                zoom_level_ir++;
            } else if (zoom_level_ir == 2) {
                img_url = "http://climate.cod.edu/data/satellite/regional/" + sector + "/current/" + sector
                        + ".ir.gif";
                zoom_level_ir++;
            } else if (zoom_level_ir == 3) {
                img_url = "http://climate.cod.edu/data/satellite/regional/usa/current/usa.ir.gif";
                zoom_level_ir = 1;
            }
            prod = "2k";
            new GetContent().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
            return true;
        case R.id.action_wv:
            setTitle(state + " WV");
            tilt_option = false;

            img.resetZoom();
            if (state.equals("HI") || state.equals("AK")) {
                zoom_level_wv = 2;
            }
            if (zoom_level_wv == 1) {
                img_url = "http://climate.cod.edu/data/satellite/2km/" + state + "/current/" + state + ".wv.gif";
                zoom_level_wv++;
            } else if (zoom_level_wv == 2) {
                img_url = "http://climate.cod.edu/data/satellite/regional/" + sector + "/current/" + sector
                        + ".wv.gif";
                zoom_level_wv++;
            } else if (zoom_level_wv == 3) {
                img_url = "http://climate.cod.edu/data/satellite/regional/usa/current/usa.wv.gif";
                zoom_level_wv = 1;
            }
            prod = "2k";
            new GetContent().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
            return true;

        case R.id.action_NVW:
            prod = "2k";
            img_url = "NVW";
            setTitle("NVW");
            new GetContent().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
            return true;

        case R.id.action_fav:
            ToggleFavorite();
            return true;

        case R.id.action_CMH:
            rid1 = "CMH";
            prod = "TZL";
            setTitle(prod);
            RIDMapSwitch(rid1);
            new GetContent().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
            return true;
        case R.id.action_CVG:
            rid1 = "CVG";
            prod = "TZL";
            setTitle(prod);
            RIDMapSwitch(rid1);
            new GetContent().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
            return true;
        case R.id.action_DAL:
            rid1 = "DAL";
            prod = "TZL";
            setTitle(prod);
            RIDMapSwitch(rid1);
            new GetContent().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
            return true;
        case R.id.action_DAY:
            rid1 = "DAY";
            prod = "TZL";
            setTitle(prod);
            new GetContent().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
            return true;
        case R.id.action_EWR:
            rid1 = "EWR";
            prod = "TZL";
            RIDMapSwitch(rid1);
            setTitle(prod);
            new GetContent().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
            return true;
        case R.id.action_FLL:
            rid1 = "FLL";
            prod = "TZL";
            RIDMapSwitch(rid1);
            new GetContent().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
            return true;
        case R.id.action_IAD:
            rid1 = "IAD";
            prod = "TZL";
            RIDMapSwitch(rid1);
            setTitle(prod);
            new GetContent().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
            return true;

        case R.id.action_IAH:
            rid1 = "IAH";
            prod = "TZL";
            RIDMapSwitch(rid1);
            setTitle(prod);
            new GetContent().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
            return true;
        case R.id.action_MDW:
            rid1 = "MDW";
            prod = "TZL";
            RIDMapSwitch(rid1);
            setTitle(prod);
            new GetContent().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
            return true;
        case R.id.action_PBI:
            rid1 = "PBI";
            prod = "TZL";
            setTitle(prod);
            new GetContent().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
            return true;

        /*case R.id.action_spotters:
        if ( spotters )
        {
        spotters=false;
        new GetContent().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
        } else
        {
        spotters=true;
        new GetContent().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
        }
        return true;*/

        case R.id.action_ridmap:

            if (!map_shown) {
                map_shown = true;

                setContentView(R.layout.activity_uswxoglradar);
                mImageMap = (ImageMap) findViewById(R.id.map);
                mImageMap.setVisibility(View.VISIBLE);
                ogl_in_view = false;

                mImageMap.addOnImageMapClickedHandler(new ImageMap.OnImageMapClickedHandler() {
                    @Override
                    public void onImageMapClicked(int id, ImageMap im2) {

                        switch (id) {

                        case R.id.CBW:
                            RIDMapSwitch("CBW");
                            break;
                        case R.id.GYX:
                            RIDMapSwitch("GYX");
                            break;
                        case R.id.CXX:
                            RIDMapSwitch("CXX");
                            break;
                        case R.id.BOX:
                            RIDMapSwitch("BOX");
                            break;
                        case R.id.ENX:
                            RIDMapSwitch("ENX");
                            break;
                        case R.id.BGM:
                            RIDMapSwitch("BGM");
                            break;
                        case R.id.BUF:
                            RIDMapSwitch("BUF");
                            break;
                        case R.id.TYX:
                            RIDMapSwitch("TYX");
                            break;
                        case R.id.OKX:
                            RIDMapSwitch("OKX");
                            break;
                        case R.id.DOX:
                            RIDMapSwitch("DOX");
                            break;
                        case R.id.DIX:
                            RIDMapSwitch("DIX");
                            break;
                        case R.id.PBZ:
                            RIDMapSwitch("PBZ");
                            break;
                        case R.id.CCX:
                            RIDMapSwitch("CCX");
                            break;
                        case R.id.RLX:
                            RIDMapSwitch("RLX");
                            break;
                        case R.id.AKQ:
                            RIDMapSwitch("AKQ");
                            break;
                        case R.id.FCX:
                            RIDMapSwitch("FCX");
                            break;
                        case R.id.LWX:
                            RIDMapSwitch("LWX");
                            break;
                        case R.id.MHX:
                            RIDMapSwitch("MHX");
                            break;
                        case R.id.RAX:
                            RIDMapSwitch("RAX");
                            break;
                        case R.id.LTX:
                            RIDMapSwitch("LTX");
                            break;
                        case R.id.CLX:
                            RIDMapSwitch("CLX");
                            break;
                        case R.id.CAE:
                            RIDMapSwitch("CAE");
                            break;
                        case R.id.GSP:
                            RIDMapSwitch("GSP");
                            break;
                        case R.id.FFC:
                            RIDMapSwitch("FFC");
                            break;
                        case R.id.VAX:
                            RIDMapSwitch("VAX");
                            break;
                        case R.id.JGX:
                            RIDMapSwitch("JGX");
                            break;
                        case R.id.EVX:
                            RIDMapSwitch("EVX");
                            break;
                        case R.id.JAX:
                            RIDMapSwitch("JAX");
                            break;
                        case R.id.BYX:
                            RIDMapSwitch("BYX");
                            break;
                        case R.id.MLB:
                            RIDMapSwitch("MLB");
                            break;
                        case R.id.AMX:
                            RIDMapSwitch("AMX");
                            break;
                        case R.id.TLH:
                            RIDMapSwitch("TLH");
                            break;
                        case R.id.TBW:
                            RIDMapSwitch("TBW");
                            break;
                        case R.id.BMX:
                            RIDMapSwitch("BMX");
                            break;
                        case R.id.EOX:
                            RIDMapSwitch("EOX");
                            break;
                        case R.id.HTX:
                            RIDMapSwitch("HTX");
                            break;
                        case R.id.MXX:
                            RIDMapSwitch("MXX");
                            break;
                        case R.id.MOB:
                            RIDMapSwitch("MOB");
                            break;
                        case R.id.DGX:
                            RIDMapSwitch("DGX");
                            break;
                        case R.id.GWX:
                            RIDMapSwitch("GWX");
                            break;
                        case R.id.MRX:
                            RIDMapSwitch("MRX");
                            break;
                        case R.id.NQA:
                            RIDMapSwitch("NQA");
                            break;
                        case R.id.OHX:
                            RIDMapSwitch("OHX");
                            break;
                        case R.id.HPX:
                            RIDMapSwitch("HPX");
                            break;
                        case R.id.JKL:
                            RIDMapSwitch("JKL");
                            break;
                        case R.id.LVX:
                            RIDMapSwitch("LVX");
                            break;
                        case R.id.PAH:
                            RIDMapSwitch("PAH");
                            break;
                        case R.id.ILN:
                            RIDMapSwitch("ILN");
                            break;
                        case R.id.CLE:
                            RIDMapSwitch("CLE");
                            break;
                        case R.id.DTX:
                            RIDMapSwitch("DTX");
                            break;
                        case R.id.APX:
                            RIDMapSwitch("APX");
                            break;
                        case R.id.GRR:
                            RIDMapSwitch("GRR");
                            break;
                        case R.id.MQT:
                            RIDMapSwitch("MQT");
                            break;
                        case R.id.VWX:
                            RIDMapSwitch("VWX");
                            break;
                        case R.id.IND:
                            RIDMapSwitch("IND");
                            break;
                        case R.id.IWX:
                            RIDMapSwitch("IWX");
                            break;
                        case R.id.LOT:
                            RIDMapSwitch("LOT");
                            break;
                        case R.id.ILX:
                            RIDMapSwitch("ILX");
                            break;
                        case R.id.GRB:
                            RIDMapSwitch("GRB");
                            break;
                        case R.id.ARX:
                            RIDMapSwitch("ARX");
                            break;
                        case R.id.MKX:
                            RIDMapSwitch("MKX");
                            break;
                        case R.id.DLH:
                            RIDMapSwitch("DLH");
                            break;
                        case R.id.MPX:
                            RIDMapSwitch("MPX");
                            break;
                        case R.id.DVN:
                            RIDMapSwitch("DVN");
                            break;
                        case R.id.DMX:
                            RIDMapSwitch("DMX");
                            break;
                        case R.id.EAX:
                            RIDMapSwitch("EAX");
                            break;
                        case R.id.SGF:
                            RIDMapSwitch("SGF");
                            break;
                        case R.id.LSX:
                            RIDMapSwitch("LSX");
                            break;
                        case R.id.SRX:
                            RIDMapSwitch("SRX");
                            break;
                        case R.id.LZK:
                            RIDMapSwitch("LZK");
                            break;
                        case R.id.POE:
                            RIDMapSwitch("POE");
                            break;
                        case R.id.LCH:
                            RIDMapSwitch("LCH");
                            break;
                        case R.id.LIX:
                            RIDMapSwitch("LIX");
                            break;
                        case R.id.SHV:
                            RIDMapSwitch("SHV");
                            break;
                        case R.id.AMA:
                            RIDMapSwitch("AMA");
                            break;
                        case R.id.EWX:
                            RIDMapSwitch("EWX");
                            break;
                        case R.id.BRO:
                            RIDMapSwitch("BRO");
                            break;
                        case R.id.CRP:
                            RIDMapSwitch("CRP");
                            break;
                        case R.id.FWS:
                            RIDMapSwitch("FWS");
                            break;
                        case R.id.DYX:
                            RIDMapSwitch("DYX");
                            break;
                        case R.id.EPZ:
                            RIDMapSwitch("EPZ");
                            break;
                        case R.id.GRK:
                            RIDMapSwitch("GRK");
                            break;
                        case R.id.HGX:
                            RIDMapSwitch("HGX");
                            break;
                        case R.id.DFX:
                            RIDMapSwitch("DFX");
                            break;
                        case R.id.LBB:
                            RIDMapSwitch("LBB");
                            break;
                        case R.id.MAF:
                            RIDMapSwitch("MAF");
                            break;
                        case R.id.SJT:
                            RIDMapSwitch("SJT");
                            break;
                        case R.id.FDR:
                            RIDMapSwitch("FDR");
                            break;
                        case R.id.TLX:
                            RIDMapSwitch("TLX");
                            break;
                        case R.id.INX:
                            RIDMapSwitch("INX");
                            break;
                        case R.id.VNX:
                            RIDMapSwitch("VNX");
                            break;
                        case R.id.DDC:
                            RIDMapSwitch("DDC");
                            break;
                        case R.id.GLD:
                            RIDMapSwitch("GLD");
                            break;
                        case R.id.TWX:
                            RIDMapSwitch("TWX");
                            break;
                        case R.id.ICT:
                            RIDMapSwitch("ICT");
                            break;
                        case R.id.UEX:
                            RIDMapSwitch("UEX");
                            break;
                        case R.id.LNX:
                            RIDMapSwitch("LNX");
                            break;
                        case R.id.OAX:
                            RIDMapSwitch("OAX");
                            break;
                        case R.id.ABR:
                            RIDMapSwitch("ABR");
                            break;
                        case R.id.UDX:
                            RIDMapSwitch("UDX");
                            break;
                        case R.id.FSD:
                            RIDMapSwitch("FSD");
                            break;
                        case R.id.BIS:
                            RIDMapSwitch("BIS");
                            break;
                        case R.id.MVX:
                            RIDMapSwitch("MVX");
                            break;
                        case R.id.MBX:
                            RIDMapSwitch("MBX");
                            break;
                        case R.id.BLX:
                            RIDMapSwitch("BLX");
                            break;
                        case R.id.GGW:
                            RIDMapSwitch("GGW");
                            break;
                        case R.id.TFX:
                            RIDMapSwitch("TFX");
                            break;
                        case R.id.MSX:
                            RIDMapSwitch("MSX");
                            break;
                        case R.id.CYS:
                            RIDMapSwitch("CYS");
                            break;
                        case R.id.RIW:
                            RIDMapSwitch("RIW");
                            break;
                        case R.id.FTG:
                            RIDMapSwitch("FTG");
                            break;
                        case R.id.GJX:
                            RIDMapSwitch("GJX");
                            break;
                        case R.id.PUX:
                            RIDMapSwitch("PUX");
                            break;
                        case R.id.ABX:
                            RIDMapSwitch("ABX");
                            break;
                        case R.id.FDX:
                            RIDMapSwitch("FDX");
                            break;
                        case R.id.HDX:
                            RIDMapSwitch("HDX");
                            break;
                        case R.id.FSX:
                            RIDMapSwitch("FSX");
                            break;
                        case R.id.IWA:
                            RIDMapSwitch("IWA");
                            break;
                        case R.id.EMX:
                            RIDMapSwitch("EMX");
                            break;
                        case R.id.YUX:
                            RIDMapSwitch("YUX");
                            break;
                        case R.id.ICX:
                            RIDMapSwitch("ICX");
                            break;
                        case R.id.MTX:
                            RIDMapSwitch("MTX");
                            break;
                        case R.id.CBX:
                            RIDMapSwitch("CBX");
                            break;
                        case R.id.SFX:
                            RIDMapSwitch("SFX");
                            break;
                        case R.id.LRX:
                            RIDMapSwitch("LRX");
                            break;
                        case R.id.ESX:
                            RIDMapSwitch("ESX");
                            break;
                        case R.id.RGX:
                            RIDMapSwitch("RGX");
                            break;
                        case R.id.BBX:
                            RIDMapSwitch("BBX");
                            break;
                        case R.id.EYX:
                            RIDMapSwitch("EYX");
                            break;
                        case R.id.BHX:
                            RIDMapSwitch("BHX");
                            break;
                        case R.id.VTX:
                            RIDMapSwitch("VTX");
                            break;
                        case R.id.DAX:
                            RIDMapSwitch("DAX");
                            break;
                        case R.id.NKX:
                            RIDMapSwitch("NKX");
                            break;
                        case R.id.MUX:
                            RIDMapSwitch("MUX");
                            break;
                        case R.id.HNX:
                            RIDMapSwitch("HNX");
                            break;
                        case R.id.SOX:
                            RIDMapSwitch("SOX");
                            break;
                        case R.id.VBX:
                            RIDMapSwitch("VBX");
                            break;
                        case R.id.HKI:
                            RIDMapSwitch("HKI");
                            break;
                        case R.id.HKM:
                            RIDMapSwitch("HKM");
                            break;
                        case R.id.HMO:
                            RIDMapSwitch("HMO");
                            break;
                        case R.id.HWA:
                            RIDMapSwitch("HWA");
                            break;
                        case R.id.MAX:
                            RIDMapSwitch("MAX");
                            break;
                        case R.id.PDT:
                            RIDMapSwitch("PDT");
                            break;
                        case R.id.RTX:
                            RIDMapSwitch("RTX");
                            break;
                        case R.id.LGX:
                            RIDMapSwitch("LGX");
                            break;
                        case R.id.ATX:
                            RIDMapSwitch("ATX");
                            break;
                        case R.id.OTX:
                            RIDMapSwitch("OTX");
                            break;
                        case R.id.ABC:
                            RIDMapSwitch("ABC");
                            break;
                        case R.id.APD:
                            RIDMapSwitch("APD");
                            break;
                        case R.id.AHG:
                            RIDMapSwitch("AHG");
                            break;
                        case R.id.AKC:
                            RIDMapSwitch("AKC");
                            break;
                        case R.id.AIH:
                            RIDMapSwitch("AIH");
                            break;
                        case R.id.AEC:
                            RIDMapSwitch("AEC");
                            break;
                        case R.id.ACG:
                            RIDMapSwitch("ACG");
                            break;
                        case R.id.GUA:
                            RIDMapSwitch("GUA");
                            break;
                        case R.id.JUA:
                            RIDMapSwitch("JUA");
                            break;

                        }

                    }

                    @Override
                    public void onBubbleClicked(int id) {

                    }
                });

            } else {
                map_shown = false;
                mImageMap.setVisibility(View.GONE);

                setContentView(view);
                ogl_in_view = true;
            }

            return true;

        default:
            return super.onOptionsItemSelected(item);
        }
    } // end onOptionsItemSelected

    private class AnimateRadarMosaic extends AsyncTask<String, String, String> {

        @Override
        protected String doInBackground(String... params) {

            animDrawable = UtilityImgAnim.GetCODMosaicAnim(getBaseContext(), img_url, "rad", params[0]);

            return "Executed";
        }

        @Override
        protected void onPostExecute(String result) {

            setContentView(R.layout.activity_uswxoglradar);
            ImageView iv = (ImageView) findViewById(R.id.iv);

            setProgressBarIndeterminateVisibility(false);
            ogl_in_view = false;

            if (rid_fav.contains(":" + rid1 + ":")) {
                star.setIcon(star_icon);

            } else {
                star.setIcon(star_outline_icon);
            }

            mImageMap = (ImageMap) findViewById(R.id.map);
            mImageMap.setVisibility(View.GONE);

            UtilityImgAnim.ResizeViewAnim(dm, animDrawable, iv);

            iv.setImageBitmap(null);
            iv.setBackground(animDrawable);
            animDrawable.setOneShot(false);
            animDrawable.start();

        }

        @Override
        protected void onPreExecute() {
            setProgressBarIndeterminateVisibility(true);

        }

        @Override
        protected void onProgressUpdate(String... values) {
        }
    }

    private void RIDMapSwitch(String r) {

        rid1 = r;
        map_shown = false;
        rid_fav = preferences.getString(pref_token, " : : :");
        rid_arr_loc = UtilityFavorites.SetupFavMenu(preferences, rid_fav, rid1, pref_token_location, colon);
        adapter = new ArrayAdapter<String>(getBaseContext(), android.R.layout.simple_spinner_dropdown_item,
                rid_arr_loc);
        getActionBar().setListNavigationCallbacks(adapter, navigationListener);

    }

    private void ToggleFavorite() {

        rid_fav = UtilityFavorites.ToggleFavorite(this, rid1, star, star_outline_icon, star_icon, pref_token);
        rid_arr_loc = UtilityFavorites.SetupFavMenu(preferences, rid_fav, rid1, pref_token_location, colon);
        adapter = new ArrayAdapter<String>(getBaseContext(), android.R.layout.simple_spinner_dropdown_item,
                rid_arr_loc);
        getActionBar().setListNavigationCallbacks(adapter, navigationListener);

    }

    private void ShowRadarScanInfo() {
        String info = preferences.getString("WX_RADAR_CURRENT_INFO", "");
        AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
        alertDialogBuilder.setMessage(info).setIcon(R.drawable.wx).setCancelable(false).setNegativeButton("OK",
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        dialog.cancel();
                    }
                });
        AlertDialog alertDialog = alertDialogBuilder.create();
        alertDialog.show();

    }

    public boolean onTouchEvent(MotionEvent event) {
        boolean retVal = mScaleDetector.onTouchEvent(event);
        retVal = mGestureDetector.onTouchEvent(event) || retVal;
        return retVal || super.onTouchEvent(event);
    }

    private class ScaleListener extends ScaleGestureDetector.SimpleOnScaleGestureListener {
        @Override
        public boolean onScale(ScaleGestureDetector detector) {

            old_scalefactor = mScaleFactor;
            mScaleFactor = mScaleFactor * detector.getScaleFactor();

            OGLR.mPositionX = OGLR.mPositionX * (mScaleFactor / old_scalefactor);
            OGLR.mPositionY = OGLR.mPositionY * (mScaleFactor / old_scalefactor);

            OGLR.setZoom(mScaleFactor);
            view.requestRender();

            return true;
        }

    }

    @Override
    public boolean onDown(MotionEvent event) {
        return true;
    }

    @Override
    public boolean onFling(MotionEvent event1, MotionEvent event2, float velocityX, float velocityY) {
        return true;
    }

    @Override
    public void onLongPress(MotionEvent event) {

        x = event.getX();
        //y=0.0f;
        y = event.getY() - statusBarHeight - actionBarHeight;

        x_middle = screen_width / 2;
        y_middle = (screen_height - statusBarHeight - actionBarHeight) / 2;

        diff_x = density * (x_middle - x) / mScaleFactor;
        diff_y = density * (y_middle - y) / mScaleFactor;

        x_str = preferences.getString("RID_" + rid1 + "_X", "0.00");
        y_str = preferences.getString("RID_" + rid1 + "_Y", "0.00");

        //Float center_x = 0.0f;
        //Float center_y = 0.0f;

        try {
            center_x = Float.parseFloat(x_str);
            center_y = Float.parseFloat(y_str);
        } catch (Exception e) {
        }

        ppd = OGLR.one_degree_scale_factor;
        new_x = center_y + ((OGLR.mPositionX) / mScaleFactor + diff_x) / ppd;
        test2 = 180 / Math.PI * Math.log(Math.tan(Math.PI / 4 + center_x * (Math.PI / 180) / 2));
        new_y = (float) test2 + ((-OGLR.mPositionY) / mScaleFactor + diff_y) / ppd;
        new_y = (float) (180 / Math.PI * (2 * Math.atan(Math.exp(new_y * Math.PI / 180)) - Math.PI / 2));

        rid_tmp = UtilityLocation.GetNearestRid(getBaseContext(), Float.toString(new_y),
                Float.toString(new_x * -1));

        if (!rid1.equals(rid_tmp))
            RIDMapSwitch(rid_tmp);

    }

    @Override
    public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {

        panned = false;

        if (distanceX != 0) {
            OGLR.mPositionX = OGLR.mPositionX + -1f * distanceX;
            panned = true;
        }

        if (distanceY != 0) {
            OGLR.mPositionY = OGLR.mPositionY + distanceY;
            panned = true;
        }

        if (panned) {
            view.requestRender();
        }

        return panned;
    }

    @Override
    public void onShowPress(MotionEvent event) {
    }

    @Override
    public boolean onSingleTapUp(MotionEvent event) {

        return true;
    }

    @Override
    public boolean onDoubleTap(MotionEvent event) {

        x = event.getX();
        y = event.getY() - statusBarHeight - actionBarHeight;

        x_middle = screen_width / 2;
        y_middle = (screen_height - statusBarHeight - actionBarHeight) / 2;

        OGLR.mPositionX = OGLR.mPositionX * 2 + (x - x_middle) * -2 * density;
        OGLR.mPositionY = OGLR.mPositionY * 2 + (y_middle - y) * -2 * density;

        mScaleFactor = mScaleFactor * 2.0f;

        OGLR.setZoom(mScaleFactor);
        view.requestRender();

        return true;
    }

    @Override
    public boolean onDoubleTapEvent(MotionEvent event) {
        return true;
    }

    @Override
    public boolean onSingleTapConfirmed(MotionEvent event) {

        mScaleFactor = mScaleFactor / 2.0f;

        OGLR.mPositionX = OGLR.mPositionX / 2;
        OGLR.mPositionY = OGLR.mPositionY / 2;

        OGLR.setZoom(mScaleFactor);
        view.requestRender();

        return true;
    }

}