Example usage for android.os Message Message

List of usage examples for android.os Message Message

Introduction

In this page you can find the example usage for android.os Message Message.

Prototype

public Message() 

Source Link

Document

Constructor (but the preferred way to get a Message is to call #obtain() Message.obtain() ).

Usage

From source file:com.zoffcc.applications.zanavi.Navit.java

void convert_gpx_file_real(String gpx_file) {
    File tt2 = new File(gpx_file);
    p.PREF_last_selected_dir_gpxfiles = tt2.getParent();
    Log.e("Navit", "last_selected_dir_gpxfiles " + p.PREF_last_selected_dir_gpxfiles);
    setPrefs_selected_gpx_dir();/*from   w  w w  . java 2  s .  c om*/

    String out_ = MAP_FILENAME_PATH + "/gpxtracks.txt";
    Log.e("Navit", "onActivityResult 002 " + gpx_file + " " + out_);
    MainFrame.do_conversion(gpx_file, out_);

    // draw map no-async
    Message msg = new Message();
    Bundle b = new Bundle();
    b.putInt("Callback", 64);
    msg.setData(b);
    NavitGraphics.callback_handler.sendMessage(msg);
}

From source file:com.zoffcc.applications.zanavi.Navit.java

static void set_zoom_level(int want_zoom_level) {
    try {//from  w w w. j a  v  a  2 s . c o m
        Bundle b = new Bundle();
        Message msg = new Message();
        b.putInt("Callback", 33);
        b.putString("s", Integer.toString(want_zoom_level));
        msg.setData(b);
        NavitGraphics.callback_handler.sendMessage(msg);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.zoffcc.applications.zanavi.Navit.java

static void set_zoom_level_no_draw(int want_zoom_level) {
    try {/*  ww  w.j  a  v  a2s .c o  m*/
        Bundle b = new Bundle();
        Message msg = new Message();
        b.putInt("Callback", 105);
        b.putString("s", Integer.toString(want_zoom_level));
        msg.setData(b);
        NavitGraphics.callback_handler.sendMessage(msg);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.zoffcc.applications.zanavi.Navit.java

static void draw_map() {
    try {// ww  w  . j  a v  a 2s  .c o  m
        // draw map no-async
        Message msg = new Message();
        Bundle b = new Bundle();
        b.putInt("Callback", 64);
        msg.setData(b);
        NavitGraphics.callback_handler.sendMessage(msg);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.zoffcc.applications.zanavi.Navit.java

public static void route_offline_ZANavi(String addr, float lat_start, float lon_start,
        boolean start_coords_valid, double lat_end, double lon_end, boolean remember_dest) {
    if (remember_dest) {
        try {//from  w ww  .  j a v  a  2 s .  c  om
            Navit.remember_destination(addr, "" + lat_end, "" + lon_end);
            // save points
            write_map_points();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    // DEBUG: clear route rectangle list
    NavitGraphics.route_rects.clear();

    if (NavitGraphics.navit_route_status == 0) {
        short_toast(Navit.get_text("setting destination to") + "\n" + addr);

        Navit.destination_set();

        Message msg = new Message();
        Bundle b = new Bundle();
        b.putInt("Callback", 3);
        b.putString("lat", "" + lat_end);
        b.putString("lon", "" + lon_end);
        b.putString("q", addr);
        msg.setData(b);
        NavitGraphics.callback_handler.sendMessage(msg);
    } else {
        short_toast(Navit.get_text("new Waypoint") + "\n" + addr);

        Message msg = new Message();
        Bundle b = new Bundle();
        b.putInt("Callback", 48);
        b.putString("lat", "" + lat_end);
        b.putString("lon", "" + lon_end);
        b.putString("q", addr);
        msg.setData(b);
        NavitGraphics.callback_handler.sendMessage(msg);
    }

}

From source file:com.zoffcc.applications.zanavi.Navit.java

public static void route_online_OSRM(final String addr, float lat_start, float lon_start,
        boolean start_coords_valid, final double lat_end, final double lon_end, final boolean remember_dest) {
    // http://router.project-osrm.org/viaroute?loc=46.3456438,17.450&loc=47.34122,17.5332&instructions=false&alt=false

    if (!start_coords_valid) {
        location_coords cur_target = new location_coords();
        try {/*w  w w .ja v a 2 s  .  co  m*/
            geo_coord tmp = get_current_vehicle_position();
            cur_target.lat = tmp.Latitude;
            cur_target.lon = tmp.Longitude;
        } catch (Exception e) {
        }

        try {
            lat_start = (float) cur_target.lat;
            lon_start = (float) cur_target.lon;
        } catch (Exception e) {
            e.printStackTrace();
            Log.e("Navit", "problem with location!");
        }
    }

    final String request_url = String.format(Locale.US,
            "http://router.project-osrm.org/viaroute?loc=%4.6f,%4.6f&loc=%4.6f,%4.6f&instructions=true&alt=false",
            lat_start, lon_start, lat_end, lon_end);

    // StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
    // StrictMode.setThreadPolicy(policy);

    try {
        // System.out.println("XML:S:001 url=" + request_url);
        final URL url = new URL(request_url);
        // System.out.println("XML:S:002");
        //         SAXParserFactory factory = SAXParserFactory.newInstance();
        //         System.out.println("XML:S:003");
        //         SAXParser parser = factory.newSAXParser();
        //         System.out.println("XML:S:004");
        //         XMLReader xmlreader = parser.getXMLReader();
        //         System.out.println("XML:S:005");
        //         xmlreader.setContentHandler(new ZANaviXMLHandler());
        //         System.out.println("XML:S:006");

        final Thread add_to_route = new Thread() {
            @Override
            public void run() {
                try {

                    // --------------
                    // --------------
                    // --------------
                    // ------- allow this HTTPS cert ---
                    // --------------
                    // --------------
                    // --------------
                    //                  X509HostnameVerifier hnv = new X509HostnameVerifier()
                    //                  {
                    //
                    //                     @Override
                    //                     public void verify(String hostname, SSLSocket arg1) throws IOException
                    //                     {
                    //                        Log.d("SSL", "DANGER !!! trusted hostname=" + hostname + " DANGER !!!");
                    //                     }
                    //
                    //                     @Override
                    //                     public void verify(String hostname, X509Certificate cert) throws SSLException
                    //                     {
                    //                        Log.d("SSL", "DANGER !!! trusted hostname=" + hostname + " DANGER !!!");
                    //                     }
                    //
                    //                     @Override
                    //                     public void verify(String hostname, String[] cns, String[] subjectAlts) throws SSLException
                    //                     {
                    //                        Log.d("SSL", "DANGER !!! trusted hostname=" + hostname + " DANGER !!!");
                    //                     }
                    //
                    //                     @Override
                    //                     public boolean verify(String hostname, SSLSession session)
                    //                     {
                    //                        Log.d("SSL", "DANGER !!! trusted hostname=" + hostname + " DANGER !!!");
                    //                        return true;
                    //                     }
                    //                  };
                    //
                    //                  SSLContext context = SSLContext.getInstance("TLS");
                    //                  context.init(null, new X509TrustManager[] { new X509TrustManager()
                    //                  {
                    //                     public java.security.cert.X509Certificate[] getAcceptedIssuers()
                    //                     {
                    //                        return new java.security.cert.X509Certificate[0];
                    //                     }
                    //
                    //                     @Override
                    //                     public void checkClientTrusted(java.security.cert.X509Certificate[] chain, String authType) throws java.security.cert.CertificateException
                    //                     {
                    //                     }
                    //
                    //                     @Override
                    //                     public void checkServerTrusted(java.security.cert.X509Certificate[] chain, String authType) throws java.security.cert.CertificateException
                    //                     {
                    //                     }
                    //                  } }, new SecureRandom());
                    //                  javax.net.ssl.SSLSocketFactory sslf = context.getSocketFactory();
                    //
                    //                  HostnameVerifier hnv_default = HttpsURLConnection.getDefaultHostnameVerifier();
                    //                  javax.net.ssl.SSLSocketFactory sslf_default = HttpsURLConnection.getDefaultSSLSocketFactory();
                    //                  HttpsURLConnection.setDefaultHostnameVerifier(hnv);
                    //                  HttpsURLConnection.setDefaultSSLSocketFactory(sslf);
                    //
                    //                  DefaultHttpClient client = new DefaultHttpClient();
                    //
                    //                  SSLSocketFactory socketFactory = SSLSocketFactory.getSocketFactory();
                    //                  SchemeRegistry registry = new SchemeRegistry();
                    //                  registry.register(new Scheme("https", socketFactory, 443));
                    //                  ThreadSafeClientConnManager mgr = new ThreadSafeClientConnManager(client.getParams(), registry);
                    //                  DefaultHttpClient httpClient = new DefaultHttpClient(mgr, client.getParams());
                    //
                    //                  socketFactory.setHostnameVerifier(hnv);
                    //
                    //                  HttpGet get_request = new HttpGet(request_url);
                    //                  HttpResponse http_response = httpClient.execute(get_request);
                    //                  HttpEntity responseEntity = http_response.getEntity();
                    //
                    //                  HttpsURLConnection.setDefaultHostnameVerifier(hnv_default);
                    //                  HttpsURLConnection.setDefaultSSLSocketFactory(sslf_default);
                    // --------------
                    // --------------
                    // --------------
                    // ------- allow this HTTPS cert ---
                    // --------------
                    // --------------
                    // --------------

                    InputSource is = new InputSource();
                    is.setEncoding("utf-8");
                    // is.setByteStream(responseEntity.getContent());
                    is.setByteStream(url.openStream());
                    // System.out.println("XML:S:007");

                    String response = slurp(is.getByteStream(), 16384);
                    // response = response.replaceAll("&", "&");

                    // System.out.println("XML:S:007.a res=" + response);

                    final JSONObject obj = new JSONObject(response);

                    //   System.out.println(person.getInt("id"));

                    final String route_geometry = obj.getString("route_geometry");
                    final JSONArray route_instructions_array = obj.getJSONArray("route_instructions");

                    int loop_i = 0;
                    JSONArray instruction;
                    int[] instruction_pos = new int[route_instructions_array.length()];
                    for (loop_i = 0; loop_i < route_instructions_array.length(); loop_i++) {
                        instruction = (JSONArray) route_instructions_array.get(loop_i);
                        instruction_pos[loop_i] = Integer.parseInt(instruction.get(3).toString());
                        // System.out.println("XML:instr. pos=" + instruction_pos[loop_i]);
                    }

                    // System.out.println("XML:S:009 o=" + route_geometry);

                    List<geo_coord> gc_list = decode_function(route_geometry, 6);

                    if (gc_list.size() < 2) {
                        // no real route found!! (only 1 point)
                    } else {

                        Message msg = new Message();
                        Bundle b = new Bundle();

                        int loop = 0;

                        geo_coord cur = new geo_coord();
                        geo_coord old = new geo_coord();
                        geo_coord corr = new geo_coord();

                        cur.Latitude = gc_list.get(loop).Latitude;
                        cur.Longitude = gc_list.get(loop).Longitude;

                        int first_found = 1;

                        if (gc_list.size() > 2) {
                            int instr_count = 1;

                            for (loop = 1; loop < gc_list.size(); loop++) {

                                old.Latitude = cur.Latitude;
                                old.Longitude = cur.Longitude;
                                cur.Latitude = gc_list.get(loop).Latitude;
                                cur.Longitude = gc_list.get(loop).Longitude;

                                if ((instruction_pos[instr_count] == loop) || (loop == (gc_list.size() - 1))) {

                                    if (loop == (gc_list.size() - 1)) {
                                        corr = cur;
                                    } else {
                                        corr = get_point_on_line(old, cur, 70);
                                    }

                                    // -- add waypoint --
                                    //                           b.putInt("Callback", 55548);
                                    //                           b.putString("lat", "" + corr.Latitude);
                                    //                           b.putString("lon", "" + corr.Longitude);
                                    //                           b.putString("q", " ");
                                    //                           msg.setData(b);
                                    try {
                                        // NavitGraphics.callback_handler.sendMessage(msg);
                                        if (first_found == 1) {
                                            first_found = 0;
                                            NavitGraphics.CallbackMessageChannel(55503,
                                                    corr.Latitude + "#" + corr.Longitude + "#" + "");
                                            // System.out.println("XML:rR:" + loop + " " + corr.Latitude + " " + corr.Longitude);
                                        } else {
                                            NavitGraphics.CallbackMessageChannel(55548,
                                                    corr.Latitude + "#" + corr.Longitude + "#" + "");
                                            // System.out.println("XML:rw:" + loop + " " + corr.Latitude + " " + corr.Longitude);
                                        }
                                        // Thread.sleep(25);
                                    } catch (Exception e) {
                                        e.printStackTrace();
                                    }
                                    // -- add waypoint --

                                    instr_count++;

                                }

                            }
                        }

                        if (remember_dest) {
                            try {
                                Navit.remember_destination(addr, "" + lat_end, "" + lon_end);
                                // save points
                                write_map_points();
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                        }

                        b.putInt("Callback", 55599);
                        msg.setData(b);
                        try {
                            // System.out.println("XML:calc:");
                            Thread.sleep(10);
                            NavitGraphics.callback_handler.sendMessage(msg);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }

                    }

                } catch (Exception e2) {
                    e2.printStackTrace();
                }
            }
        };
        add_to_route.start();

        // convert to coords -------------
        // convert to coords -------------

    } catch (Exception e) {
        // System.out.println("XML:S:EEE");
        e.printStackTrace();
    }
}

From source file:com.zoffcc.applications.zanavi.Navit.java

public static void recalculate_route() {
    try {//w w  w.ja  v a 2s  .c  om
        // update route, if a route is set
        Message msg = new Message();
        Bundle b = new Bundle();
        b.putInt("Callback", 73);
        msg.setData(b);
        NavitGraphics.callback_handler.sendMessage(msg);
    } catch (Exception e) {
    }
}

From source file:com.zoffcc.applications.zanavi.Navit.java

static void static_show_route_graph(int v) {
    // DEBUG: toggle Routgraph on/off
    try {// ww w  .  ja va2 s . c  o  m
        if (v == 1) {
            Navit.Routgraph_enabled = 1;

            Message msg = new Message();
            Bundle b = new Bundle();
            b.putInt("Callback", 71);
            b.putString("s", "" + Navit.Routgraph_enabled);
            msg.setData(b);
            NavitGraphics.callback_handler.sendMessage(msg);
        } else if (v == 0) {
            Navit.Routgraph_enabled = 0;

            Message msg = new Message();
            Bundle b = new Bundle();
            b.putInt("Callback", 71);
            b.putString("s", "" + Navit.Routgraph_enabled);
            msg.setData(b);
            NavitGraphics.callback_handler.sendMessage(msg);
        } else {
            Navit.Routgraph_enabled = 0;

            Message msg = new Message();
            Bundle b = new Bundle();
            b.putInt("Callback", 71);
            b.putString("s", "" + Navit.Routgraph_enabled);
            msg.setData(b);
            NavitGraphics.callback_handler.sendMessage(msg);

            Thread.sleep(350);

            System.out.println("static_show_route_graph:v=" + v);

            msg = new Message();
            b = new Bundle();
            b.putInt("Callback", 71);
            b.putString("s", "" + v);
            msg.setData(b);
            NavitGraphics.callback_handler.sendMessage(msg);
        }
    } catch (Exception e) {
    }

}

From source file:com.zoffcc.applications.zanavi.Navit.java

static void executeSearch_with_values(String street, String town, String hn, boolean offline, boolean index,
        boolean partialmatch, boolean hide_dupl) {
    Intent search_intent = new Intent(Global_Navit_Object, NavitAddressSearchActivity.class);
    search_intent.putExtra("title", Navit.get_text("Enter: City and Street")); //TRANS
    String addr1 = "";
    String addr2 = "";

    if ((town != null) && (street != null)) {
        if (index) {
            search_intent.putExtra("address_string", street + " " + town);
            addr1 = street + " " + town;
            addr2 = street + " " + town;
        } else {/*from   www . j  av a  2s  . c  o m*/
            search_intent.putExtra("address_string", town + " " + street);
            addr1 = town + " " + street;
            addr2 = town + " " + street;
        }
    } else if (town != null) {
        search_intent.putExtra("address_string", town);
        addr1 = town;
        addr2 = town;
    } else if (street != null) {
        search_intent.putExtra("address_string", street);
        addr1 = street;
        addr2 = street;
    }

    if (hn != null) {
        search_intent.putExtra("hn_string", hn);
    }

    if (offline) {
        search_intent.putExtra("type", "offline");
    } else {
        search_intent.putExtra("type", "online");
    }

    String pm_temp = "0";
    if (partialmatch) {
        pm_temp = "1";
    }
    search_intent.putExtra("partial_match", pm_temp);

    if (index) {
        Navit_last_address_partial_match = partialmatch;
        Navit_last_address_search_string = addr2;
        Navit_last_address_hn_string = hn;
        Navit_last_address_full_file_search = false;
        search_hide_duplicates = hide_dupl;
        Global_Navit_Object.startActivityForResult(search_intent, NavitAddressSearch_id_offline);
    } else {
        Navit_last_address_partial_match = partialmatch;
        Navit_last_address_search_string = addr1;
        Navit_last_address_hn_string = hn;
        Navit_last_address_full_file_search = false;
        search_hide_duplicates = hide_dupl;

        // only from offline mask!
        // { "*A", "*AA", "*ALL*" }
        Navit_last_address_search_country_iso2_string = "*A";
        Navit_last_address_search_country_flags = 3;
        Navit_last_address_search_country_id = 1; // default=*ALL*
        p.PREF_search_country = Navit_last_address_search_country_id;
        setPrefs_search_country();

        // show duplicates in search ------------
        Message msg2 = new Message();
        Bundle b2 = new Bundle();
        b2.putInt("Callback", 44);
        msg2.setData(b2);
        NavitGraphics.callback_handler.sendMessage(msg2);
        // show duplicates in search ------------

        if (hide_dupl) {
            search_hide_duplicates = true;
            // hide duplicates when searching
            // hide duplicates when searching
            Message msg22 = new Message();
            Bundle b22 = new Bundle();
            b22.putInt("Callback", 45);
            msg22.setData(b22);
            NavitGraphics.callback_handler.sendMessage(msg22);
            // hide duplicates when searching
            // hide duplicates when searching
        }

        System.out.println("dialog -- 11:001");
        Message msg = Navit_progress_h.obtainMessage();
        Bundle b = new Bundle();
        msg.what = 11;
        b.putInt("dialog_num", Navit.SEARCHRESULTS_WAIT_DIALOG_OFFLINE);
        msg.setData(b);
        Navit_progress_h.sendMessage(msg);
    }
}