joshuatee.wx.USWarningsWithRadarActivity.java Source code

Java tutorial

Introduction

Here is the source code for joshuatee.wx.USWarningsWithRadarActivity.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 android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.drawable.LayerDrawable;
import android.os.AsyncTask;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.view.Gravity;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.View;
import android.view.Window;
import android.view.ViewGroup.LayoutParams;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.ScrollView;
import android.widget.TextView;
import android.support.v4.app.ActionBarDrawerToggle;
import android.support.v4.widget.DrawerLayout;
import android.util.DisplayMetrics;
import android.util.TypedValue;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import java.util.regex.*;
import joshuatee.wx.R;
import android.widget.Button;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.view.ContextMenu;
import android.view.MenuItem;
import android.view.ContextMenu.ContextMenuInfo;

public class USWarningsWithRadarActivity extends Activity {

    public static final String URL = "";

    String sig_html_tmp = "";
    String debug_status_current = "";

    boolean us_downloaded = false;
    String original_filter = "";
    String us_data_str = "";

    Intent intent;

    String newline = "";

    List<String> rid_al = new ArrayList<String>();
    List<TouchImageView2> iv_al = new ArrayList<TouchImageView2>();
    List<TouchImageView2> iv_bv_al = new ArrayList<TouchImageView2>();
    List<TouchImageView2> iv_srm_al = new ArrayList<TouchImageView2>();

    String nws_office = "";
    String rid1 = "";
    String nws_loc = "";
    Integer freq;
    Integer freq3;

    ImageView iv_warn;
    Bitmap bm_warn;
    Button b_warn;
    Button b_radar_choice;

    String alert_cod_radar_current = "";

    int i;
    int j;
    int total_alerts_cnt = 0;
    LinearLayout dynamicview;
    String[] turl;
    String[] turl_local = new String[3];
    SharedPreferences preferences;
    SharedPreferences.Editor editor;
    LinearLayout.LayoutParams lprams;
    TextView tv_stats;

    int tornado_cnt = 0;
    int tstorm_cnt = 0;

    boolean warning_map_shown = false;
    boolean br_shown = false;
    boolean bv_shown = false;
    boolean srm_shown = false;

    DisplayMetrics dm;
    Map<String, Integer> map = new TreeMap<String, Integer>();
    Map<String, Integer> map_event = new TreeMap<String, Integer>();
    Map<String, Integer> map_state = new TreeMap<String, Integer>();
    Map<String, Integer> img_cache = new HashMap<String, Integer>();
    Map<Integer, String> map_button_nws = new HashMap<Integer, String>();
    Map<Integer, String> map_button_state = new HashMap<Integer, String>();
    Map<Integer, String> map_button_county = new HashMap<Integer, String>();
    Map<Integer, String> map_button_zone = new HashMap<Integer, String>();

    ArrayList<String> state_al = new ArrayList<String>(10);

    int highlight_color = Color.YELLOW;
    int background_color = Color.WHITE;
    String highlight_color_str = "yellow";
    String background_color_str = "white";

    MenuItem map_mi;
    int map_icon;

    private DrawerLayout mDrawerLayout;
    private ListView mDrawerList;
    private ActionBarDrawerToggle mDrawerToggle;

    String[] filter_array = new String[] {};
    String[] filter_array_label;
    String filter = "All";
    boolean first_run = true;

    String[] filter_array1 = new String[] {};
    String[] filter_array1_label;
    String[] filter_array2 = new String[] {};
    String[] filter_array2_label;

    String theme_blue_current;
    int padding;
    int padding_vertical;
    float text_size;

    Pattern space, semicolon;

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {

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

        if (theme_blue_current.contains("white")) {
            map_icon = R.drawable.map_dark;

        } else {
            map_icon = R.drawable.map;

        }

        map_mi = menu.findItem(R.id.action_map);
        map_mi.setIcon(map_icon);

        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", "");
        if (theme_blue_current.contains("white")) {
            highlight_color = Color.BLUE;
            background_color = Color.BLACK;
            highlight_color_str = "blue";
            background_color_str = "black";

        }
        setTheme(Utility.Theme(theme_blue_current));
        setContentView(R.layout.activity_uswarnings_with_radar_v3);

        Resources res = getResources();
        padding = (int) res.getDimension(R.dimen.padding);
        padding_vertical = (int) res.getDimension(R.dimen.padding_vertical);
        text_size = res.getDimension(R.dimen.listitem_text);

        newline = System.getProperty("line.separator");
        space = Pattern.compile(" ");
        semicolon = Pattern.compile(";");

        turl = getIntent().getStringArrayExtra(URL);
        turl_local[0] = turl[0];
        turl_local[1] = turl[1];
        original_filter = turl[0];

        alert_cod_radar_current = preferences.getString("ALERT_COD_RADAR", "");
        debug_status_current = preferences.getString("DEBUG_STATUS", "");

        dynamicview = (LinearLayout) findViewById(R.id.ll);
        lprams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
                LinearLayout.LayoutParams.WRAP_CONTENT);

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

        mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
        mDrawerList = (ListView) findViewById(R.id.left_drawer);
        mDrawerList.setAdapter(new ArrayAdapter<String>(this, R.layout.drawer_list_item, filter_array));
        mDrawerList.setOnItemClickListener(new DrawerItemClickListener());
        mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.drawable.drawer, R.string.drawer_open,
                R.string.drawer_close) {
            public void onDrawerClosed(View view) {
                super.onDrawerClosed(view);
            }

            public void onDrawerOpened(View drawerView) {
                super.onDrawerOpened(drawerView);
            }
        };

        mDrawerLayout.setDrawerListener(mDrawerToggle);
        getActionBar().setDisplayHomeAsUpEnabled(true);
        getActionBar().setHomeButtonEnabled(true);

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

    }

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

        List<LayerDrawable> layerDrawable_al = new ArrayList<LayerDrawable>();

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

            if (!br_shown) {
                for (j = 0; j < i; j++) // used to be j=1 and j<=i
                {

                    layerDrawable_al
                            .add(UtilityUSImg.GetPreferredLayeredImg(getBaseContext(), rid_al.get(j), "ref"));

                }

            }

            return "Executed";
        }

        @Override
        protected void onPostExecute(String result) {

            if (br_shown) {
                for (j = 0; j < i; j++) // used to be j = 1
                {

                    iv_al.get(j).setVisibility(View.GONE);
                    br_shown = false;

                }

            } else {

                for (j = 0; j < i; j++) // used to be j = 1
                {

                    int width = dm.widthPixels;
                    int height = width * layerDrawable_al.get(j).getIntrinsicHeight()
                            / layerDrawable_al.get(j).getIntrinsicWidth();

                    LayoutParams params_iv = (LayoutParams) iv_al.get(j).getLayoutParams();
                    params_iv.height = height;
                    params_iv.width = width;
                    iv_al.get(j).setLayoutParams(params_iv);
                    iv_al.get(j).setImageDrawable(layerDrawable_al.get(j));

                    br_shown = true;
                    iv_al.get(j).setVisibility(View.VISIBLE);

                }

            }
            setProgressBarIndeterminateVisibility(false);

        }

        @Override
        protected void onPreExecute() {

            setProgressBarIndeterminateVisibility(true);

        }

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

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

        List<LayerDrawable> layerDrawable_al = new ArrayList<LayerDrawable>();

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

            if (!bv_shown) {

                for (j = 0; j < i; j++) {

                    layerDrawable_al
                            .add(UtilityUSImg.GetPreferredLayeredImg(getBaseContext(), rid_al.get(j), "vel"));

                }

            }

            return "Executed";
        }

        @Override
        protected void onPostExecute(String result) {

            if (bv_shown) {
                for (j = 0; j < i; j++) {

                    iv_bv_al.get(j).setVisibility(View.GONE);
                    bv_shown = false;

                }

            } else {

                for (j = 0; j < i; j++) {

                    int width = dm.widthPixels;
                    int height = width * layerDrawable_al.get(j).getIntrinsicHeight()
                            / layerDrawable_al.get(j).getIntrinsicWidth();

                    LayoutParams params_iv = (LayoutParams) iv_bv_al.get(j).getLayoutParams();
                    params_iv.height = height;
                    params_iv.width = width;
                    iv_bv_al.get(j).setLayoutParams(params_iv);
                    iv_bv_al.get(j).setImageDrawable(layerDrawable_al.get(j));

                    bv_shown = true;
                    iv_bv_al.get(j).setVisibility(View.VISIBLE);

                }

            }

            setProgressBarIndeterminateVisibility(false);

        }

        @Override
        protected void onPreExecute() {

            setProgressBarIndeterminateVisibility(true);

        }

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

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

        List<LayerDrawable> layerDrawable_al = new ArrayList<LayerDrawable>();

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

            if (!srm_shown) {

                for (j = 0; j < i; j++) {

                    layerDrawable_al
                            .add(UtilityUSImg.GetPreferredLayeredImg(getBaseContext(), rid_al.get(j), "N0S"));

                }

            }

            return "Executed";
        }

        @Override
        protected void onPostExecute(String result) {

            if (srm_shown) {
                for (j = 0; j < i; j++) {

                    iv_srm_al.get(j).setVisibility(View.GONE);
                    srm_shown = false;

                }

            } else {

                for (j = 0; j < i; j++) {

                    int width = dm.widthPixels;
                    int height = width * layerDrawable_al.get(j).getIntrinsicHeight()
                            / layerDrawable_al.get(j).getIntrinsicWidth();

                    LayoutParams params_iv = (LayoutParams) iv_srm_al.get(j).getLayoutParams();
                    params_iv.height = height;
                    params_iv.width = width;
                    iv_srm_al.get(j).setLayoutParams(params_iv);
                    iv_srm_al.get(j).setImageDrawable(layerDrawable_al.get(j));

                    srm_shown = true;
                    iv_srm_al.get(j).setVisibility(View.VISIBLE);

                }

            }

            setProgressBarIndeterminateVisibility(false);

        }

        @Override
        protected void onPreExecute() {

            setProgressBarIndeterminateVisibility(true);

        }

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

    @Override
    public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
        super.onCreateContextMenu(menu, v, menuInfo);

        String zone = map_button_zone.get(v.getId());
        menu.add(0, v.getId(), 0, "Open radar interface");
        menu.add(0, v.getId(), 0, "Open radar mosaic");
        menu.add(0, v.getId(), 0, "Show radar products");
        menu.add(0, v.getId(), 0, "Add new location for this warning (" + zone + ")");

    }

    @Override
    public boolean onContextItemSelected(MenuItem item) {

        if (item.getTitle().equals("Show radar products")) {
            RadarProdShow(item.getItemId());
        } else if (item.getTitle().equals("Open radar interface")) {
            RadarInterface(item.getItemId());
        } else if (item.getTitle().equals("Open radar mosaic")) {
            RadarMosaic(item.getItemId());
        } else if (((String) item.getTitle()).contains("Add new location for this warning")) {
            LocationAdd(item.getItemId());
        } else {
            return false;
        }
        return true;

    }

    public void RadarProdShow(int id) {

        String rid11 = preferences.getString("NWS_RID_" + map_button_nws.get(id), "");
        intent = new Intent(getBaseContext(), RadarSixActivity.class);
        intent.putExtra(RadarSixActivity.URL, rid11);
        startActivity(intent);

    }

    public void RadarInterface(int id) {

        String rid11 = preferences.getString("NWS_RID_" + map_button_nws.get(id), "");

        intent = new Intent(getBaseContext(), UtilityUSImg.getRadarClass(preferences));
        intent.putExtra(UtilityUSImg.getRadarClassExtra(preferences),
                new String[] { rid11, map_button_state.get(i) });
        startActivity(intent);

    }

    public void RadarMosaic(int id) {

        intent = new Intent(this, USNWSGOESActivity.class);
        intent.putExtra(USNWSGOESActivity.RID,
                new String[] { "nws", map_button_nws.get(id).toLowerCase(Locale.US), "nws_warn" });
        startActivity(intent);

    }

    public void LocationAdd(int id) {

        new SaveLocFromZone().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, id);

    }

    private class SaveLocFromZone extends AsyncTask<Integer, String, String> {

        String toast_str = "";
        String[] coord;

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

            String loc_num_to_save_str = "";
            Integer loc_num_int_current = preferences.getInt("LOC_NUM_INT", -1);
            loc_num_int_current++;
            loc_num_to_save_str = loc_num_int_current.toString();
            String zone = map_button_zone.get(params[0]);
            String state = map_button_state.get(params[0]);
            String county = map_button_county.get(params[0]);

            if (zone.length() > 3) {
                if (zone.matches("[A-Z][A-Z]C.*?")) {
                    coord = UtilityLocation.GetXYFromAddressOSM(county + "," + zone.substring(0, 2));
                } else {
                    coord = UtilityLocation.GetXYFromNWSZone(zone);
                }
                state = zone.substring(0, 2);
            }

            String x = coord[0];
            String y = coord[1];

            toast_str = UtilityLocation.LocationSave(getBaseContext(), loc_num_to_save_str, x, y,
                    state + "_" + county);

            return "Executed";
        }

        @Override
        protected void onPostExecute(String result) {

            Utility.MakeToast(getBaseContext(), toast_str);
            setProgressBarIndeterminateVisibility(false);

        }

        @Override
        protected void onPreExecute() {

            setProgressBarIndeterminateVisibility(true);

        }

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

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {

        if (mDrawerToggle.onOptionsItemSelected(item)) {
            return true;
        }

        switch (item.getItemId()) {

        case R.id.action_br:
            new GetRadar().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
            return true;
        case R.id.action_bv:
            new GetRadarBV().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
            return true;
        case R.id.action_srm:
            new GetRadarSRM().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
            return true;
        case R.id.action_map:
            new GetMap().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
            return true;

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

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

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

            try {

                if (turl_local[1].equals("us") && us_downloaded) {
                    sig_html_tmp = us_data_str;
                } else {
                    sig_html_tmp = Utility
                            .GetStringFromURL("http://alerts.weather.gov/cap/" + turl_local[1] + ".php?x=1");
                    if (turl_local[1].equals("us")) {
                        us_data_str = sig_html_tmp;
                        us_downloaded = true;
                    }
                }

            } catch (Exception e) {

            }

            return "Executed";
        }

        @Override
        protected void onPostExecute(String result) {

            try {

                Pattern p = Pattern.compile(
                        "<entry>.*?<id>(.+?)</id>.*?<title>(.+?)</title>.*?<summary>(.*?)</summary>.*?<cap:event>(.*?)</cap:event>.*?<cap:areaDesc>(.*?)</cap:areaDesc>.*?<valueName>UGC</valueName>.*?<value>(.*?)</value>.*?<valueName>VTEC</valueName>.*?<value>(.*?)</value>.*?</entry>.*?");
                Matcher m = p.matcher(sig_html_tmp);

                String url = "";
                String title = "";
                String event = "";
                String area = "";

                String html = "";
                String zones = "";
                String vtec = "";

                dynamicview = (LinearLayout) findViewById(R.id.ll);
                lprams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
                        LinearLayout.LayoutParams.WRAP_CONTENT);

                String[] county_arr;
                String[] zone_arr;
                String first_county = "";
                String first_zone = "";
                Integer freq2 = 0;
                String button_txt = "";
                String tmp_str = "";

                while (m.find()) {
                    url = m.group(1);
                    title = m.group(2);
                    event = m.group(4);
                    area = m.group(5).replace("&apos;", "'"); // ex Queen Anne's MD
                    zones = m.group(6);
                    vtec = m.group(7);

                    county_arr = semicolon.split(area);

                    if (county_arr.length > 0) {
                        first_county = county_arr[0];
                    }

                    zone_arr = space.split(zones);

                    if (zone_arr.length > 0) {
                        first_zone = zone_arr[0];
                    }
                    total_alerts_cnt++;

                    // The old method of calculating warnings per start would simply look at the NWS office and then total
                    // The new method looks at the zone or counties and strips off the first 2 chars 
                    //int z_cnt=0;

                    List<String> tmp_state_list = new ArrayList<String>();
                    for (int z_cnt = 0; z_cnt < zone_arr.length; z_cnt++) {
                        if (zone_arr[z_cnt].length() > 1) {
                            tmp_state_list.add(zone_arr[z_cnt].substring(0, 2));
                        }
                    }
                    Set<String> unique_states = new HashSet<String>(tmp_state_list);
                    for (String s : unique_states) {
                        freq3 = map_state.get(s);
                        map_state.put(s, (freq3 == null) ? 1 : freq3 + 1);
                    }

                    freq2 = map_event.get(event);
                    map_event.put(event, (freq2 == null) ? 1 : freq2 + 1);

                    if (event.matches(turl_local[0])) // added  "^" +  and was matches
                    {

                        if (title.contains("Tornado")) {
                            tornado_cnt++;
                        }
                        if (title.contains("Thunder")) {
                            tstorm_cnt++;
                        }

                        html = html + "<b>" + title + "</b><br>";
                        html = html + "<b>Counties: " + area + "</b><br>";
                        html = html + vtec + "<br><br>";

                        /*String nws_office = "";
                        String rid1 = "";
                        String nws_loc = "";*/

                        if (vtec.length() > 15) {
                            nws_office = vtec.substring(8, 11);
                            rid1 = preferences.getString("NWS_RID_" + nws_office, "DTX");
                            nws_loc = preferences.getString("NWS_LOCATION_" + nws_office, "MI");

                        }

                        // The old method of calculating warnings per start would simply look at the NWS office and then total
                        // The new method looks at the zone or counties and strips off the first 2 chars 
                        //int z2_cnt=0;

                        List<String> tmp2_state_list = new ArrayList<String>();
                        for (int z2_cnt = 0; z2_cnt < zone_arr.length; z2_cnt++) {
                            if (zone_arr[z2_cnt].length() > 1) {
                                tmp2_state_list.add(zone_arr[z2_cnt].substring(0, 2));
                            }
                        }
                        Set<String> unique2_states = new HashSet<String>(tmp2_state_list);
                        for (String s : unique2_states) {
                            freq = map.get(s);
                            map.put(s, (freq == null) ? 1 : freq + 1);
                            map_button_state.put(i, s);
                            state_al.add(s); // formerly add(state_tmp)
                        }

                        Button btn = new Button(getBaseContext(), null, android.R.attr.borderlessButtonStyle);
                        btn.setId(i);
                        btn.setTextColor(background_color);
                        registerForContextMenu(btn);

                        map_button_nws.put(i, nws_office);
                        map_button_county.put(i, first_county);
                        map_button_zone.put(i, first_zone);

                        tmp_str = title.replace("issued", newline + "Issued");

                        if (debug_status_current.equals("true")) {
                            button_txt = nws_office + ": " + nws_loc + newline + tmp_str + newline + area + newline
                                    + zones;
                        } else {

                            button_txt = nws_office + ": " + nws_loc + newline + tmp_str + newline + area;

                        }
                        btn.setText(button_txt);
                        btn.setGravity(Gravity.LEFT);
                        btn.setTextSize(TypedValue.COMPLEX_UNIT_PX, text_size);
                        btn.setPadding(padding, padding_vertical, padding, padding_vertical);

                        if (title.matches(".*?Tornado.*?")) {
                            btn.setTextColor(Color.RED);
                        }

                        btn.setLayoutParams(lprams);

                        iv_al.add(new TouchImageView2(getBaseContext()));
                        iv_bv_al.add(new TouchImageView2(getBaseContext()));
                        iv_srm_al.add(new TouchImageView2(getBaseContext()));

                        rid_al.add(rid1);

                        final int index = i;
                        final String url_str = url;

                        btn.setOnClickListener(new OnClickListener() {
                            public void onClick(View v) {
                                intent = new Intent(getBaseContext(), USAlertsDetailActivity.class);
                                intent.putExtra(USAlertsDetailActivity.URL, url_str);
                                startActivity(intent);
                            }
                        });

                        iv_al.get(i).setOnClickListener(new OnClickListener() {
                            public void onClick(View v) {

                                intent = new Intent(getBaseContext(), UtilityUSImg.getRadarClass(preferences));
                                intent.putExtra(UtilityUSImg.getRadarClassExtra(preferences),
                                        new String[] { rid_al.get(index), map_button_state.get(i) });
                                startActivity(intent);

                            }
                        });

                        iv_bv_al.get(i).setOnClickListener(new OnClickListener() {
                            public void onClick(View v) {

                                intent = new Intent(getBaseContext(), UtilityUSImg.getRadarClass(preferences));
                                intent.putExtra(UtilityUSImg.getRadarClassExtra(preferences),
                                        new String[] { rid_al.get(index), map_button_state.get(i) });
                                startActivity(intent);

                            }
                        });

                        iv_srm_al.get(i).setOnClickListener(new OnClickListener() {
                            public void onClick(View v) {

                                intent = new Intent(getBaseContext(), UtilityUSImg.getRadarClass(preferences));
                                intent.putExtra(UtilityUSImg.getRadarClassExtra(preferences),
                                        new String[] { rid_al.get(index), map_button_state.get(i) });
                                startActivity(intent);

                            }
                        });

                        dynamicview.addView(btn);
                        dynamicview.addView(iv_al.get(i));
                        dynamicview.addView(iv_bv_al.get(i));
                        dynamicview.addView(iv_srm_al.get(i));

                        i++;

                    }

                }

            } catch (Exception e) {

            }
            String map_out = map.toString();
            String map_event_out = map_event.toString();
            map_out = map_out.replaceAll("\\{|\\}", "");
            map_event_out = map_event_out.replace(",", newline);
            String filter = turl_local[0];
            filter = filter.replaceAll("\\||\\*|\\?|\\.", " ");
            tv_stats.setText("Filter: " + filter.replaceAll("\\^", "") + " (" + Integer.toString(i) + ")" + newline
                    + map_out);
            setTitle("(" + total_alerts_cnt + ") " + turl_local[1].toUpperCase(Locale.US) + " Alerts");

            if (first_run) {
                Object[] obj = map_event.keySet().toArray();
                Object[] obj2 = map_state.keySet().toArray();

                filter_array1 = Arrays.copyOf(obj, obj.length, String[].class);
                filter_array1_label = Arrays.copyOf(filter_array1, filter_array1.length, String[].class);
                for (j = 0; j < filter_array1_label.length; j++) {
                    filter_array1_label[j] = filter_array1_label[j] + ": " + map_event.get(filter_array1[j]);
                }
                filter_array2 = Arrays.copyOf(obj2, obj2.length, String[].class);
                filter_array2_label = Arrays.copyOf(filter_array2, filter_array2.length, String[].class);
                for (j = 0; j < filter_array2_label.length; j++) {
                    filter_array2_label[j] = filter_array2_label[j] + ": " + map_state.get(filter_array2[j]);
                }

                filter_array = new String[filter_array1.length + filter_array2.length];
                System.arraycopy(filter_array1, 0, filter_array, 0, filter_array1.length);
                System.arraycopy(filter_array2, 0, filter_array, filter_array1.length, filter_array2.length);

                filter_array_label = new String[filter_array1_label.length + filter_array2_label.length];
                System.arraycopy(filter_array1_label, 0, filter_array_label, 0, filter_array1_label.length);
                System.arraycopy(filter_array2_label, 0, filter_array_label, filter_array1_label.length,
                        filter_array2_label.length);

                mDrawerList.setAdapter(
                        new ArrayAdapter<String>(getBaseContext(), R.layout.drawer_list_item, filter_array_label));
                first_run = false;

            }

            setProgressBarIndeterminateVisibility(false);

        }

        @Override
        protected void onPreExecute() {

            setProgressBarIndeterminateVisibility(true);

            dynamicview.removeAllViews();

            ScrollView sv = (ScrollView) findViewById(R.id.sv);
            sv.smoothScrollTo(0, 0);

            tv_stats = new TextView(getBaseContext(), null, android.R.attr.borderlessButtonStyle);
            tv_stats.setLayoutParams(lprams);
            tv_stats.setGravity(Gravity.LEFT);
            tv_stats.setTextColor(background_color);
            tv_stats.setPadding(padding, 10, padding, 10);
            dynamicview.addView(tv_stats);

            tv_stats.setOnClickListener(new OnClickListener() {
                public void onClick(View v) {

                    turl_local[0] = original_filter;
                    turl_local[1] = "us";
                    new GetContent().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
                }
            });

            iv_warn = new TouchImageView2(getBaseContext());
            dynamicview.addView(iv_warn);

            map.clear();
            map_event.clear();
            map_state.clear();
            img_cache.clear();
            map_button_nws.clear();
            ;
            map_button_state.clear();
            map_button_county.clear();
            map_button_zone.clear();
            state_al.clear();
            total_alerts_cnt = 0;
            i = 0;

            rid_al.clear();
            iv_al.clear();
            iv_bv_al.clear();
            iv_srm_al.clear();
            br_shown = false;
            bv_shown = false;
            srm_shown = false;

        }

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

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

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

            if (!warning_map_shown)

            {
                if (alert_cod_radar_current.equals("true")) {
                    bm_warn = Utility.getBitmapFromURL(
                            "http://climate.cod.edu/data/satellite/regional/usa/current/usa-ww.gif");
                } else {
                    bm_warn = Utility.getBitmapFromURL("http://forecast.weather.gov/wwamap/png/US.png");
                }

            }

            return "Executed";
        }

        @Override
        protected void onPostExecute(String result) {
            if (warning_map_shown) {
                iv_warn.setImageDrawable(null);
                LayoutParams params_iv = (LayoutParams) iv_warn.getLayoutParams();
                params_iv = (LayoutParams) iv_warn.getLayoutParams();
                params_iv.height = 0;
                params_iv.width = 0;
                iv_warn.setLayoutParams(params_iv);
                warning_map_shown = false;
            } else {
                ScrollView sv = (ScrollView) findViewById(R.id.sv);
                sv.smoothScrollTo(0, 0);
                UtilityImg.ResizeViewSetImg(dm, bm_warn, iv_warn);
                warning_map_shown = true;
            }

            setProgressBarIndeterminateVisibility(false);

        }

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

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

    private class DrawerItemClickListener implements ListView.OnItemClickListener {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            selectItem(position);
        }
    }

    private void selectItem(int position) {

        mDrawerList.setItemChecked(position, false);
        mDrawerLayout.closeDrawer(mDrawerList);

        if (filter_array[position].length() != 2) {
            turl_local[0] = "^" + filter_array[position];
            turl_local[1] = "us";
        } else {
            turl_local[0] = ".*?";
            turl_local[1] = filter_array[position].toLowerCase(Locale.US);
        }
        new GetContent().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);

    }

    protected void onPostCreate(Bundle savedInstanceState) {
        super.onPostCreate(savedInstanceState);
        mDrawerToggle.syncState();
    }

    @Override

    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        mDrawerToggle.onConfigurationChanged(newConfig);
    }

}