Example usage for android.os Handler sendMessage

List of usage examples for android.os Handler sendMessage

Introduction

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

Prototype

public final boolean sendMessage(Message msg) 

Source Link

Document

Pushes a message onto the end of the message queue after all pending messages before the current time.

Usage

From source file:net.networksaremadeofstring.cyllell.ViewRoles_Fragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    list = (ListView) this.getActivity().findViewById(R.id.rolesListView);
    settings = this.getActivity().getSharedPreferences("Cyllell", 0);
    try {//w w  w .ja  v  a 2s . co  m
        Cut = new Cuts(getActivity());
    } catch (Exception e) {
        e.printStackTrace();
    }

    dialog = new ProgressDialog(getActivity());
    dialog.setTitle("Contacting Chef");
    dialog.setMessage("Please wait: Prepping Authentication protocols");
    dialog.setIndeterminate(true);
    if (listOfRoles.size() < 1) {
        dialog.show();
    }

    updateListNotify = new Handler() {
        public void handleMessage(Message msg) {
            int tag = msg.getData().getInt("tag", 999999);

            if (msg.what == 0) {
                if (tag != 999999) {
                    listOfRoles.get(tag).SetSpinnerVisible();
                }
            } else if (msg.what == 1) {
                //Get rid of the lock
                CutInProgress = false;

                //the notifyDataSetChanged() will handle the rest
            } else if (msg.what == 99) {
                if (tag != 999999) {
                    Toast.makeText(ViewRoles_Fragment.this.getActivity(),
                            "An error occured during that operation.", Toast.LENGTH_LONG).show();
                    listOfRoles.get(tag).SetErrorState();
                }
            }
            RoleAdapter.notifyDataSetChanged();
        }
    };

    final Handler handler = new Handler() {
        public void handleMessage(Message msg) {
            //Once we've checked the data is good to use start processing it
            if (msg.what == 0) {
                OnClickListener listener = new OnClickListener() {
                    public void onClick(View v) {
                        GetMoreDetails((Integer) v.getTag());
                    }
                };

                OnLongClickListener listenerLong = new OnLongClickListener() {
                    public boolean onLongClick(View v) {
                        selectForCAB((Integer) v.getTag());
                        return true;
                    }
                };

                RoleAdapter = new RoleListAdaptor(getActivity(), listOfRoles, listener, listenerLong);
                list = (ListView) getView().findViewById(R.id.rolesListView);
                if (list != null) {
                    if (RoleAdapter != null) {
                        list.setAdapter(RoleAdapter);
                    } else {
                        //Log.e("CookbookAdapter","CookbookAdapter is null");
                    }
                } else {
                    //Log.e("List","List is null");
                }

                dialog.dismiss();
            } else if (msg.what == 200) {
                dialog.setMessage("Sending request to Chef...");
            } else if (msg.what == 201) {
                dialog.setMessage("Parsing JSON.....");
            } else if (msg.what == 202) {
                dialog.setMessage("Populating UI!");
            } else {
                //Close the Progress dialog
                dialog.dismiss();

                //Alert the user that something went terribly wrong
                AlertDialog alertDialog = new AlertDialog.Builder(getActivity()).create();
                alertDialog.setTitle("API Error");
                alertDialog.setMessage("There was an error communicating with the API:\n"
                        + msg.getData().getString("exception"));
                alertDialog.setButton2("Back", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        //getActivity().finish();
                    }
                });
                alertDialog.setIcon(R.drawable.icon);
                alertDialog.show();
            }
        }
    };

    Thread dataPreload = new Thread() {
        public void run() {
            if (listOfRoles.size() > 0) {
                handler.sendEmptyMessage(0);
            } else {
                try {
                    handler.sendEmptyMessage(200);
                    Roles = Cut.GetRoles();
                    handler.sendEmptyMessage(201);

                    JSONArray Keys = Roles.names();

                    for (int i = 0; i < Keys.length(); i++) {
                        listOfRoles.add(new Role(Keys.getString(i), Roles.getString(Keys.getString(i))
                                .replaceFirst("^(https://|http://).*/roles/", "")));
                    }

                    handler.sendEmptyMessage(202);
                    handler.sendEmptyMessage(0);
                } catch (Exception e) {
                    Message msg = new Message();
                    Bundle data = new Bundle();
                    data.putString("exception", e.getMessage());
                    msg.setData(data);
                    msg.what = 1;
                    handler.sendMessage(msg);
                }
            }
            return;
        }
    };

    dataPreload.start();
    return inflater.inflate(R.layout.roles_landing, container, false);
}

From source file:com.example.zf_android.trade.ApplyDetailActivity.java

@Override
protected void onActivityResult(final int requestCode, int resultCode, final Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode != RESULT_OK)
        return;/* w  w  w.  j  ava  2  s  .  co m*/
    switch (requestCode) {
    case REQUEST_CHOOSE_MERCHANT: {

        mAgentId = mMerchantId = data.getIntExtra(AGENT_ID, 0);
        mAgentName = data.getStringExtra(AGENT_NAME);
        setItemValue(mMerchantKeys[0], mAgentName);

        getAgentInfo();

        break;
    }
    case REQUEST_CHOOSE_BANK: {

        mBankName = data.getStringExtra("bank_name");
        mBankNo = data.getStringExtra("bank_no");
        setItemValue(customTag, mBankName);
        setItemValue(mBankKeys[0], mBankName);

        //FIXME no 
        //                setItemValue(mBankKeys[1], mBankNo);

        break;
    }
    case REQUEST_CHOOSE_CITY: {
        mMerchantProvince = (Province) data.getSerializableExtra(SELECTED_PROVINCE);
        mMerchantCity = (City) data.getSerializableExtra(SELECTED_CITY);
        mCityId = mMerchantCity.getId();
        setItemValue(mMerchantKeys[8], mMerchantCity.getName());
        break;
    }
    case REQUEST_CHOOSE_CHANNEL: {
        mChannelId = data.getIntExtra("channelId", 0);
        mBillingId = data.getIntExtra("billId", 0);
        String channelName = data.getStringExtra("channelName");
        String billName = data.getStringExtra("billName");

        setItemValue(getString(R.string.apply_detail_channel), channelName + " " + billName);
        break;
    }
    case REQUEST_UPLOAD_IMAGE:
    case REQUEST_TAKE_PHOTO: {

        final Handler handler = new Handler() {
            @Override
            public void handleMessage(Message msg) {
                if (msg.what == 1) {
                    //                     CommonUtil.toastShort(ApplyDetailActivity.this, (String) msg.obj);
                    if (null != uploadingTextView) {
                        final String url = (String) msg.obj;
                        LinearLayout item = (LinearLayout) uploadingTextView.getParent().getParent();

                        updateCustomerDetails(item.getTag(), url);
                        uploadingTextView.setVisibility(View.GONE);

                        ImageView iv_view = (ImageView) item.findViewById(R.id.apply_detail_view);
                        iv_view.setVisibility(View.VISIBLE);
                        iv_view.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                Intent i = new Intent(ApplyDetailActivity.this, ImageViewer.class);
                                i.putExtra("url", url);
                                i.putExtra("justviewer", true);
                                startActivity(i);
                            }
                        });
                    }
                } else {
                    CommonUtil.toastShort(ApplyDetailActivity.this, getString(R.string.toast_upload_failed));
                    if (null != uploadingTextView) {
                        uploadingTextView.setText(getString(R.string.apply_upload_again));
                        uploadingTextView.setClickable(true);
                    }
                }

            }
        };
        if (null != uploadingTextView) {
            uploadingTextView.setText(getString(R.string.apply_uploading));
            uploadingTextView.setClickable(false);
        }
        new Thread() {
            @Override
            public void run() {
                String realPath = "";
                if (requestCode == REQUEST_TAKE_PHOTO) {
                    realPath = photoPath;
                } else {
                    Uri uri = data.getData();
                    if (uri != null) {
                        realPath = getRealPathFromURI(uri);
                    }
                }
                if (TextUtils.isEmpty(realPath)) {
                    handler.sendEmptyMessage(0);
                    return;
                }
                CommonUtil.uploadFile(realPath, "img", new CommonUtil.OnUploadListener() {
                    @Override
                    public void onSuccess(String result) {
                        try {
                            JSONObject jo = new JSONObject(result);
                            String url = jo.getString("result");
                            Message msg = new Message();
                            msg.what = 1;
                            msg.obj = url;
                            handler.sendMessage(msg);
                        } catch (JSONException e) {
                            handler.sendEmptyMessage(0);
                        }
                    }

                    @Override
                    public void onFailed(String message) {
                        handler.sendEmptyMessage(0);
                    }
                });
            }
        }.start();
        break;
    }
    }
}

From source file:net.networksaremadeofstring.cyllell.ViewEnvironments_Fragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    list = (ListView) this.getActivity().findViewById(R.id.environmentsListView);
    settings = this.getActivity().getSharedPreferences("Cyllell", 0);
    try {//from   w w w.ja  v  a2  s. c o m
        Cut = new Cuts(getActivity());
    } catch (Exception e) {
        e.printStackTrace();
    }

    dialog = new ProgressDialog(getActivity());
    dialog.setTitle("Contacting Chef");
    dialog.setMessage("Please wait: Prepping Authentication protocols");
    dialog.setIndeterminate(true);
    if (listOfEnvironments.size() < 1) {
        dialog.show();
    }

    updateListNotify = new Handler() {
        public void handleMessage(Message msg) {
            int tag = msg.getData().getInt("tag", 999999);

            if (msg.what == 0) {
                if (tag != 999999) {
                    listOfEnvironments.get(tag).SetSpinnerVisible();
                }
            } else if (msg.what == 1) {
                //Get rid of the lock
                CutInProgress = false;

                //the notifyDataSetChanged() will handle the rest
            } else if (msg.what == 99) {
                if (tag != 999999) {
                    Toast.makeText(ViewEnvironments_Fragment.this.getActivity(),
                            "An error occured during that operation.", Toast.LENGTH_LONG).show();
                    listOfEnvironments.get(tag).SetErrorState();
                }
            }
            EnvironmentAdapter.notifyDataSetChanged();
        }
    };

    final Handler handler = new Handler() {
        public void handleMessage(Message msg) {
            //Once we've checked the data is good to use start processing it
            if (msg.what == 0) {
                OnClickListener listener = new OnClickListener() {
                    public void onClick(View v) {
                        //Log.i("OnClick","Clicked");
                        GetMoreDetails((Integer) v.getTag());
                    }
                };

                OnLongClickListener listenerLong = new OnLongClickListener() {
                    public boolean onLongClick(View v) {
                        selectForCAB((Integer) v.getTag());
                        return true;
                    }
                };

                EnvironmentAdapter = new EnvironmentListAdaptor(getActivity().getBaseContext(),
                        listOfEnvironments, listener, listenerLong);
                list = (ListView) getView().findViewById(R.id.environmentsListView);
                if (list != null) {
                    if (EnvironmentAdapter != null) {
                        list.setAdapter(EnvironmentAdapter);
                    } else {
                        //Log.e("EnvironmentAdapter","EnvironmentAdapter is null");
                    }
                } else {
                    //Log.e("List","List is null");
                }

                dialog.dismiss();
            } else if (msg.what == 200) {
                dialog.setMessage("Sending request to Chef...");
            } else if (msg.what == 201) {
                dialog.setMessage("Parsing JSON.....");
            } else if (msg.what == 202) {
                dialog.setMessage("Populating UI!");
            } else {
                //Close the Progress dialog
                dialog.dismiss();

                //Alert the user that something went terribly wrong
                AlertDialog alertDialog = new AlertDialog.Builder(getActivity()).create();
                alertDialog.setTitle("API Error");
                alertDialog.setMessage("There was an error communicating with the API:\n"
                        + msg.getData().getString("exception"));
                alertDialog.setButton2("Back", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        getActivity().finish();
                    }
                });
                alertDialog.setIcon(R.drawable.icon);
                alertDialog.show();
            }
        }
    };

    Thread dataPreload = new Thread() {
        public void run() {
            if (listOfEnvironments.size() > 0) {
                handler.sendEmptyMessage(0);
            } else {
                try {
                    handler.sendEmptyMessage(200);
                    Environments = Cut.GetEnvironments();
                    handler.sendEmptyMessage(201);

                    JSONArray Keys = Environments.names();

                    for (int i = 0; i < Keys.length(); i++) {
                        listOfEnvironments.add(
                                new Environment(Keys.getString(i), Environments.getString(Keys.getString(i))
                                        .replaceFirst("^(https://|http://).*/environments/", "")));
                    }

                    handler.sendEmptyMessage(202);
                    handler.sendEmptyMessage(0);
                } catch (Exception e) {
                    Message msg = new Message();
                    Bundle data = new Bundle();
                    data.putString("exception", e.getMessage());
                    msg.setData(data);
                    msg.what = 1;
                    handler.sendMessage(msg);
                }
            }
            return;
        }
    };

    dataPreload.start();
    return inflater.inflate(R.layout.environments_landing, container, false);
}

From source file:com.example.zf_android.activity.MerchantEdit.java

@Override
protected void onActivityResult(final int requestCode, int resultCode, final Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode != RESULT_OK) {
        return;/*w  ww . jav a2 s . c o m*/
    }
    String value = "";
    if (data != null) {
        value = data.getStringExtra("value");
    }
    switch (requestCode) {
    case TYPE_1:
        merchantEntity.setTitle(value);
        tv1.setText(value);
        break;
    case TYPE_2:
        merchantEntity.setLegalPersonName(value);
        tv2.setText(value);
        break;
    case TYPE_3:
        merchantEntity.setLegalPersonCardId(value);
        tv3.setText(value);
        break;
    case TYPE_4:
        merchantEntity.setBusinessLicenseNo(value);
        tv4.setText(value);
        break;
    case TYPE_5:
        merchantEntity.setTaxRegisteredNo(value);
        tv5.setText(value);
        break;
    case TYPE_6:
        merchantEntity.setOrganizationCodeNo(value);
        tv6.setText(value);
        break;
    case TYPE_7:
        Province province = (Province) data.getSerializableExtra(Constants.CityIntent.SELECTED_PROVINCE);
        City city = (City) data.getSerializableExtra(Constants.CityIntent.SELECTED_CITY);
        if (province == null || city == null) {
            merchantEntity.setCityId(0);
            tv7.setText("");
        } else {
            merchantEntity.setCityId(city.getId());
            tv7.setText(province.getName() + city.getName());
        }

        break;
    case TYPE_KHYH:
        merchantEntity.setAccountBankName(value);
        tvkhyh.setText(value);
        break;
    case TYPE_8:
        merchantEntity.setBankOpenAccount(value);
        tv8.setText(value);
        break;

    case REQUEST_UPLOAD_IMAGE:
    case REQUEST_TAKE_PHOTO: {
        final LinearLayout layout = linearLayout.get(MerchantEdit.this.type);
        final Handler handler = new Handler() {
            private int type;

            @Override
            public void handleMessage(Message msg) {
                this.type = MerchantEdit.this.type;
                if (msg.what == 1) {
                    // CommonUtil.toastShort(MerchantEdit.this,
                    // (String) msg.obj);
                    layout.setClickable(false);
                    layout.findViewById(R.id.imgView).setVisibility(View.VISIBLE);
                    layout.findViewById(R.id.textView).setVisibility(View.GONE);
                    String url = (String) msg.obj;
                    layout.setClickable(true);
                    switch (type) {
                    case TYPE_10:
                        merchantEntity.setCardIdFrontPhotoPath(url);
                        break;
                    case TYPE_11:
                        merchantEntity.setCardIdBackPhotoPath(url);
                        break;
                    case TYPE_12:
                        merchantEntity.setBodyPhotoPath(url);
                        break;
                    case TYPE_13:
                        merchantEntity.setLicenseNoPicPath(url);
                        break;
                    case TYPE_14:
                        merchantEntity.setTaxNoPicPath(url);
                        break;
                    case TYPE_15:
                        merchantEntity.setOrgCodeNoPicPath(url);
                        break;
                    case TYPE_16:
                        merchantEntity.setAccountPicPath(url);
                        break;
                    default:
                        break;
                    }
                } else {
                    CommonUtil.toastShort(MerchantEdit.this, getString(R.string.toast_upload_failed));
                    layout.setClickable(true);
                }

            }
        };
        if (null != layout) {
            ImageView imgView = (ImageView) layout.findViewById(R.id.imgView);
            TextView textView = (TextView) layout.findViewById(R.id.textView);
            imgView.setVisibility(View.GONE);
            textView.setVisibility(View.VISIBLE);
            textView.setText(getString(R.string.apply_uploading));
            layout.setClickable(false);
        }
        new Thread() {
            @Override
            public void run() {
                String realPath = "";
                if (requestCode == REQUEST_TAKE_PHOTO) {
                    realPath = photoPath;
                } else {
                    Uri uri = data.getData();
                    if (uri != null) {
                        realPath = Tools.getRealPathFromURI(MerchantEdit.this, uri);
                    }
                }
                if (TextUtils.isEmpty(realPath)) {
                    handler.sendEmptyMessage(0);
                    return;
                }
                CommonUtil.uploadFile(realPath, "img", new CommonUtil.OnUploadListener() {
                    @Override
                    public void onSuccess(String result) {
                        try {
                            JSONObject jo = new JSONObject(result);
                            String url = jo.getString("result");
                            Message msg = new Message();
                            msg.what = 1;
                            msg.obj = url;
                            handler.sendMessage(msg);
                        } catch (JSONException e) {
                            handler.sendEmptyMessage(0);
                        }
                    }

                    @Override
                    public void onFailed(String message) {
                        handler.sendEmptyMessage(0);
                    }
                });
            }
        }.start();
        break;
    }
    default:
        break;
    }
}

From source file:carnero.cgeo.original.libs.Base.java

public void dropCache(App app, Activity activity, Cache cache, Handler handler) {
    try {/* ww w  . j  ava  2 s.  c om*/
        app.markDropped(cache.geocode);
        app.removeCacheFromCache(cache.geocode);

        handler.sendMessage(new Message());
    } catch (Exception e) {
        Log.e(Settings.tag, "cgBase.dropCache: " + e.toString());
    }
}

From source file:cgeo.geocaching.cgBase.java

public void storeCache(cgeoapplication app, Activity activity, cgCache cache, String geocode, int listId,
        Handler handler) {
    try {/*from  w  ww  . jav a  2s . com*/
        // get cache details, they may not yet be complete
        if (cache != null) {
            // only reload the cache, if it was already stored or has not all details (by checking the description)
            if (cache.reason > 0 || StringUtils.isBlank(cache.description)) {
                final Map<String, String> params = new HashMap<String, String>();
                params.put("geocode", cache.geocode);
                final UUID searchId = searchByGeocode(params, listId, false);
                cache = app.getCache(searchId);
            }
        } else if (StringUtils.isNotBlank(geocode)) {
            final Map<String, String> params = new HashMap<String, String>();
            params.put("geocode", geocode);
            final UUID searchId = searchByGeocode(params, listId, false);
            cache = app.getCache(searchId);
        }

        if (cache == null) {
            if (handler != null) {
                handler.sendMessage(new Message());
            }

            return;
        }

        final cgHtmlImg imgGetter = new cgHtmlImg(activity, cache.geocode, false, listId, true);

        // store images from description
        if (StringUtils.isNotBlank(cache.description)) {
            Html.fromHtml(cache.description, imgGetter, null);
        }

        // store spoilers
        if (CollectionUtils.isNotEmpty(cache.spoilers)) {
            for (cgImage oneSpoiler : cache.spoilers) {
                imgGetter.getDrawable(oneSpoiler.url);
            }
        }

        // store images from logs
        if (settings.storelogimages) {
            for (cgLog log : cache.logs) {
                if (CollectionUtils.isNotEmpty(log.logImages)) {
                    for (cgImage oneLogImg : log.logImages) {
                        imgGetter.getDrawable(oneLogImg.url);
                    }
                }
            }
        }

        // store map previews
        StaticMapsProvider.downloadMaps(cache, settings, activity);

        app.markStored(cache.geocode, listId);
        app.removeCacheFromCache(cache.geocode);

        if (handler != null) {
            handler.sendMessage(new Message());
        }
    } catch (Exception e) {
        Log.e(cgSettings.tag, "cgBase.storeCache: " + e.toString());
    }
}

From source file:carnero.cgeo.cgBase.java

public void dropCache(cgeoapplication app, Activity activity, cgCache cache, Handler handler) {
    try {//  w w  w . j a  va  2 s .c  o  m
        app.markDropped(cache.geocode);
        app.removeCacheFromCache(cache.geocode);

        handler.sendMessage(new Message());
    } catch (Exception e) {
        Log.e(cgSettings.tag, "cgBase.dropCache: " + e.toString());
    }
}

From source file:carnero.cgeo.original.libs.Base.java

public void storeCache(App app, Activity activity, Cache cache, String geocode, int listId, Handler handler) {
    try {//from   w  w  w  . j a va2 s  .  c  om
        // cache details
        if (cache != null) {
            final HashMap<String, String> params = new HashMap<String, String>();
            params.put("geocode", cache.geocode);
            final Long searchId = searchByGeocode(params, listId, false);
            cache = app.getCache(searchId);
        } else if (geocode != null) {
            final HashMap<String, String> params = new HashMap<String, String>();
            params.put("geocode", geocode);
            final Long searchId = searchByGeocode(params, listId, false);
            cache = app.getCache(searchId);
        }

        if (cache == null) {
            if (handler != null) {
                handler.sendMessage(new Message());
            }

            return;
        }

        final HtmlImg imgGetter = new HtmlImg(activity, settings, cache.geocode, false, listId, true);

        // store images from description
        if (cache.description != null) {
            Html.fromHtml(cache.description, imgGetter, null);
        }

        // store spoilers
        if (cache.spoilers != null && cache.spoilers.isEmpty() == false) {
            for (Spoiler oneSpoiler : cache.spoilers) {
                imgGetter.getDrawable(oneSpoiler.url);
            }
        }

        // store map previews
        if (settings.storeOfflineMaps == 1 && cache.latitude != null && cache.longitude != null) {
            final String latlonMap = String.format((Locale) null, "%.6f", cache.latitude) + ","
                    + String.format((Locale) null, "%.6f", cache.longitude);
            final Display display = ((WindowManager) activity.getSystemService(Context.WINDOW_SERVICE))
                    .getDefaultDisplay();
            final int maxWidth = display.getWidth() - 25;
            final int maxHeight = display.getHeight() - 25;
            int edge = 0;
            if (maxWidth > maxHeight) {
                edge = maxWidth;
            } else {
                edge = maxHeight;
            }

            String type = "mystery";
            if (cache.found == true) {
                type = cache.type + "_found";
            } else if (cache.disabled == true) {
                type = cache.type + "_disabled";
            } else {
                type = cache.type;
            }

            final String markerUrl = urlencode_rfc3986(
                    "http://cgeo.carnero.cc/_markers/marker_cache_" + type + ".png");
            final StringBuilder waypoints = new StringBuilder();
            if (cache.waypoints != null && cache.waypoints.size() > 0) {
                for (Waypoint waypoint : cache.waypoints) {
                    if (waypoint.latitude == null && waypoint.longitude == null) {
                        continue;
                    }

                    waypoints.append("&markers=icon%3Ahttp://cgeo.carnero.cc/_markers/marker_waypoint_");
                    waypoints.append(waypoint.type);
                    waypoints.append(".png%7C");
                    waypoints.append(String.format((Locale) null, "%.6f", waypoint.latitude));
                    waypoints.append(",");
                    waypoints.append(String.format((Locale) null, "%.6f", waypoint.longitude));
                }
            }

            // download map images in separate background thread for higher performance
            final String code = cache.geocode;
            final int finalEdge = edge;
            Thread staticMapsThread = new Thread("getting static map") {
                @Override
                public void run() {
                    MapImg mapGetter = new MapImg(settings, code);

                    mapGetter.getDrawable(
                            "http://maps.google.com/maps/api/staticmap?center=" + latlonMap + "&zoom=20&size="
                                    + finalEdge + "x" + finalEdge + "&maptype=satellite&markers=icon%3A"
                                    + markerUrl + "%7C" + latlonMap + waypoints.toString() + "&sensor=false",
                            1);
                    mapGetter.getDrawable(
                            "http://maps.google.com/maps/api/staticmap?center=" + latlonMap + "&zoom=18&size="
                                    + finalEdge + "x" + finalEdge + "&maptype=satellite&markers=icon%3A"
                                    + markerUrl + "%7C" + latlonMap + waypoints.toString() + "&sensor=false",
                            2);
                    mapGetter.getDrawable(
                            "http://maps.google.com/maps/api/staticmap?center=" + latlonMap + "&zoom=16&size="
                                    + finalEdge + "x" + finalEdge + "&maptype=roadmap&markers=icon%3A"
                                    + markerUrl + "%7C" + latlonMap + waypoints.toString() + "&sensor=false",
                            3);
                    mapGetter.getDrawable(
                            "http://maps.google.com/maps/api/staticmap?center=" + latlonMap + "&zoom=14&size="
                                    + finalEdge + "x" + finalEdge + "&maptype=roadmap&markers=icon%3A"
                                    + markerUrl + "%7C" + latlonMap + waypoints.toString() + "&sensor=false",
                            4);
                    mapGetter.getDrawable(
                            "http://maps.google.com/maps/api/staticmap?center=" + latlonMap + "&zoom=11&size="
                                    + finalEdge + "x" + finalEdge + "&maptype=roadmap&markers=icon%3A"
                                    + markerUrl + "%7C" + latlonMap + waypoints.toString() + "&sensor=false",
                            5);
                }
            };
            staticMapsThread.setPriority(Thread.MIN_PRIORITY);
            staticMapsThread.start();
        }

        app.markStored(cache.geocode, listId);
        app.removeCacheFromCache(cache.geocode);

        if (handler != null) {
            handler.sendMessage(new Message());
        }
    } catch (Exception e) {
        Log.e(Settings.tag, "cgBase.storeCache: " + e.toString());
    }
}

From source file:carnero.cgeo.cgBase.java

public void storeCache(cgeoapplication app, Activity activity, cgCache cache, String geocode, int listId,
        Handler handler) {
    try {// w  w w  .  j a  v a  2  s  .  c  om
        // cache details
        if (cache != null) {
            final HashMap<String, String> params = new HashMap<String, String>();
            params.put("geocode", cache.geocode);
            final Long searchId = searchByGeocode(params, listId, false);
            cache = app.getCache(searchId);
        } else if (geocode != null) {
            final HashMap<String, String> params = new HashMap<String, String>();
            params.put("geocode", geocode);
            final Long searchId = searchByGeocode(params, listId, false);
            cache = app.getCache(searchId);
        }

        if (cache == null) {
            if (handler != null) {
                handler.sendMessage(new Message());
            }

            return;
        }

        final cgHtmlImg imgGetter = new cgHtmlImg(activity, settings, cache.geocode, false, listId, true);

        // store images from description
        if (cache.description != null) {
            Html.fromHtml(cache.description, imgGetter, null);
        }

        // store spoilers
        if (cache.spoilers != null && cache.spoilers.isEmpty() == false) {
            for (cgSpoiler oneSpoiler : cache.spoilers) {
                imgGetter.getDrawable(oneSpoiler.url);
            }
        }

        // store map previews
        if (settings.storeOfflineMaps == 1 && cache.latitude != null && cache.longitude != null) {
            final String latlonMap = String.format((Locale) null, "%.6f", cache.latitude) + ","
                    + String.format((Locale) null, "%.6f", cache.longitude);
            final Display display = ((WindowManager) activity.getSystemService(Context.WINDOW_SERVICE))
                    .getDefaultDisplay();
            final int maxWidth = display.getWidth() - 25;
            final int maxHeight = display.getHeight() - 25;
            int edge = 0;
            if (maxWidth > maxHeight) {
                edge = maxWidth;
            } else {
                edge = maxHeight;
            }

            String type = "mystery";
            if (cache.found == true) {
                type = cache.type + "_found";
            } else if (cache.disabled == true) {
                type = cache.type + "_disabled";
            } else {
                type = cache.type;
            }

            final String markerUrl = urlencode_rfc3986(
                    "http://cgeo.carnero.cc/_markers/marker_cache_" + type + ".png");
            final StringBuilder waypoints = new StringBuilder();
            if (cache.waypoints != null && cache.waypoints.size() > 0) {
                for (cgWaypoint waypoint : cache.waypoints) {
                    if (waypoint.latitude == null && waypoint.longitude == null) {
                        continue;
                    }

                    waypoints.append("&markers=icon%3Ahttp://cgeo.carnero.cc/_markers/marker_waypoint_");
                    waypoints.append(waypoint.type);
                    waypoints.append(".png%7C");
                    waypoints.append(String.format((Locale) null, "%.6f", waypoint.latitude));
                    waypoints.append(",");
                    waypoints.append(String.format((Locale) null, "%.6f", waypoint.longitude));
                }
            }

            // download map images in separate background thread for higher performance
            final String code = cache.geocode;
            final int finalEdge = edge;
            Thread staticMapsThread = new Thread("getting static map") {
                @Override
                public void run() {
                    cgMapImg mapGetter = new cgMapImg(settings, code);

                    mapGetter.getDrawable(
                            "http://maps.google.com/maps/api/staticmap?center=" + latlonMap + "&zoom=20&size="
                                    + finalEdge + "x" + finalEdge + "&maptype=satellite&markers=icon%3A"
                                    + markerUrl + "%7C" + latlonMap + waypoints.toString() + "&sensor=false",
                            1);
                    mapGetter.getDrawable(
                            "http://maps.google.com/maps/api/staticmap?center=" + latlonMap + "&zoom=18&size="
                                    + finalEdge + "x" + finalEdge + "&maptype=satellite&markers=icon%3A"
                                    + markerUrl + "%7C" + latlonMap + waypoints.toString() + "&sensor=false",
                            2);
                    mapGetter.getDrawable(
                            "http://maps.google.com/maps/api/staticmap?center=" + latlonMap + "&zoom=16&size="
                                    + finalEdge + "x" + finalEdge + "&maptype=roadmap&markers=icon%3A"
                                    + markerUrl + "%7C" + latlonMap + waypoints.toString() + "&sensor=false",
                            3);
                    mapGetter.getDrawable(
                            "http://maps.google.com/maps/api/staticmap?center=" + latlonMap + "&zoom=14&size="
                                    + finalEdge + "x" + finalEdge + "&maptype=roadmap&markers=icon%3A"
                                    + markerUrl + "%7C" + latlonMap + waypoints.toString() + "&sensor=false",
                            4);
                    mapGetter.getDrawable(
                            "http://maps.google.com/maps/api/staticmap?center=" + latlonMap + "&zoom=11&size="
                                    + finalEdge + "x" + finalEdge + "&maptype=roadmap&markers=icon%3A"
                                    + markerUrl + "%7C" + latlonMap + waypoints.toString() + "&sensor=false",
                            5);
                }
            };
            staticMapsThread.setPriority(Thread.MIN_PRIORITY);
            staticMapsThread.start();
        }

        app.markStored(cache.geocode, listId);
        app.removeCacheFromCache(cache.geocode);

        if (handler != null) {
            handler.sendMessage(new Message());
        }
    } catch (Exception e) {
        Log.e(cgSettings.tag, "cgBase.storeCache: " + e.toString());
    }
}