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:net.networksaremadeofstring.rhybudd.DeviceList.java

public void Refresh() {
    if (dialog != null) {
        dialog.setTitle("Contacting Zenoss...");
        dialog.setMessage("Please wait:\nLoading Infrastructure....");
        dialog.setCancelable(false);/*w w w .j a  v a2  s.  co m*/

        if (!dialog.isShowing()) {
            dialog.show();
        }
    } else {
        dialog = new ProgressDialog(this);
        dialog.setTitle("Contacting Zenoss...");
        dialog.setMessage("Please wait:\nLoading Infrastructure....");
        dialog.setCancelable(false);
        dialog.show();
    }

    if (listOfZenossDevices != null)
        listOfZenossDevices.clear();

    ((Thread) new Thread() {
        public void run() {
            String MessageExtra = "";
            try {
                Message msg = new Message();
                Bundle bundle = new Bundle();

                ZenossAPI API = null;
                try {

                    if (PreferenceManager.getDefaultSharedPreferences(DeviceList.this)
                            .getBoolean(ZenossAPI.PREFERENCE_IS_ZAAS, false)) {
                        API = new ZenossAPIZaas();
                    } else {
                        API = new ZenossAPICore();
                    }

                    ZenossCredentials credentials = new ZenossCredentials(DeviceList.this);
                    API.Login(credentials);
                } catch (ConnectTimeoutException cte) {
                    if (cte.getMessage() != null) {

                        bundle.putString("exception",
                                "The connection timed out;\r\n" + cte.getMessage().toString());
                        msg.setData(bundle);
                        msg.what = 0;
                        handler.sendMessage(msg);
                        //Toast.makeText(DeviceList.this, "The connection timed out;\r\n" + cte.getMessage().toString(), Toast.LENGTH_LONG).show();
                    } else {
                        bundle.putString("exception",
                                "A time out error was encountered but the exception thrown contains no further information.");
                        msg.setData(bundle);
                        msg.what = 0;
                        handler.sendMessage(msg);
                        //Toast.makeText(DeviceList.this, "A time out error was encountered but the exception thrown contains no further information.", Toast.LENGTH_LONG).show();
                    }
                } catch (Exception e) {
                    if (e.getMessage() != null) {
                        bundle.putString("exception",
                                "An error was encountered;\r\n" + e.getMessage().toString());
                        msg.setData(bundle);
                        msg.what = 0;
                        handler.sendMessage(msg);
                        //Toast.makeText(DeviceList.this, "An error was encountered;\r\n" + e.getMessage().toString(), Toast.LENGTH_LONG).show();
                    } else {
                        bundle.putString("exception",
                                "An error was encountered but the exception thrown contains no further information.");
                        msg.setData(bundle);
                        msg.what = 0;
                        handler.sendMessage(msg);
                        //Toast.makeText(DeviceList.this, "An error was encountered but the exception thrown contains no further information.", Toast.LENGTH_LONG).show();
                    }
                }

                try {
                    if (API != null) {
                        listOfZenossDevices = API.GetRhybuddDevices();
                    } else {
                        listOfZenossDevices = null;
                    }
                } catch (Exception e) {
                    if (e.getMessage() != null)
                        MessageExtra = e.getMessage();

                    listOfZenossDevices = null;
                }

                if (listOfZenossDevices != null && listOfZenossDevices.size() > 0) {
                    DeviceCount = listOfZenossDevices.size();
                    Message.obtain();
                    handler.sendEmptyMessage(1);

                    RhybuddDataSource datasource = new RhybuddDataSource(DeviceList.this);
                    datasource.open();
                    datasource.UpdateRhybuddDevices(listOfZenossDevices);
                    datasource.close();
                } else {
                    //Message msg = new Message();
                    //Bundle bundle = new Bundle();
                    bundle.putString("exception",
                            "A query to both the local DB and Zenoss API returned no devices. " + MessageExtra);
                    msg.setData(bundle);
                    msg.what = 0;
                    handler.sendMessage(msg);
                }

            } catch (Exception e) {
                //BugSenseHandler.log("DeviceList", e);
                Message msg = new Message();
                Bundle bundle = new Bundle();
                bundle.putString("exception", e.getMessage());
                msg.setData(bundle);
                msg.what = 0;
                handler.sendMessage(msg);
            }
        }
    }).start();
}

From source file:com.insthub.O2OMobile.View.A0_RequestListView.java

public void hideView() {
    mFilterBg.setVisibility(View.GONE);
    mFilterView.setVisibility(View.GONE);
    AnimationUtil.backAnimationFromBottom(mFilterView);

    Message msg = new Message();
    msg.what = MessageConstant.HIDE_SEARCH_VIEW;
    EventBus.getDefault().post(msg);//from   w w  w.j a  va  2  s.  com
}

From source file:com.app.jdy.ui.MyFaceActivity.java

private void getDate() {
    Thread thread = new Thread(new Runnable() {

        @Override/*from w  w w  . j  a va  2  s .  c om*/
        public void run() {
            Message msg = new Message();
            dataJson = HttpUtils.request(null,
                    URLs.MY_FACE + "memberId=" + ID + "&year=" + Constants.SELECT_YEAR);
            if (dataJson.length() != 0 && !dataJson.equals("0x110")) {
                if (!dataJson.equals("false")) {
                    msg.what = 1;
                } else {
                    msg.what = 2;
                }
            } else {
                msg.what = 0;
            }
            handler.sendMessage(msg);
        }
    });
    thread.start();
}

From source file:com.gdpi.app.UpdateManager.java

public void checkUpdate(boolean b) {
    try {/*from   w  ww . j a  v a 2s .  c  o m*/
        p = b;
        if (b) {
            loading = AlertUtils.showLoading(mContext);
            loading.show();
        }
        Map<String, String> paras = new HashMap<>();
        paras.put("enterprise", URLs.ENTERPRISE);
        HttpMultipartPost httpMultipartPost = new HttpMultipartPost(mContext, URLs.URL_UPDATE, paras, false);
        httpMultipartPost.setCallback(new HttpMultipartPost.HttpConnectionCallback() {

            @Override
            public void result(String result) {

                Message message = new Message();
                message.what = CHECKE_UPDATE;
                message.obj = result;
                mHandler.sendMessage(message);
            }

            @Override
            public void progressUpdate(Integer... progress) {

            }
        });
        httpMultipartPost.execute();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

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 {/*from  ww w.j  ava  2s. 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 (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:eu.liveGov.gordexola.urbanplanning.activities.MainActivity.java

@SuppressLint("NewApi")
@Override/*w ww .  j a  v a 2  s . c o  m*/
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    try {
        Process process = Runtime.getRuntime().exec("logcat -c");
    } catch (IOException e) {
        Log.e("MainActivity", "I was unable to clear LogCat");
    }
    _savedInstanceState = savedInstanceState;
    configureLogbackDirectly();

    tracker = EasyTracker.getInstance(this);
    setContentView(R.layout.activity_main);
    initialiseTabHost();
    initialisePager();
    ctx = this;

    //------ Location Service Start --------------------
    Functions.startLocationService(ctx);

    //------------ Measure kb downloaded ----------------
    uid = this.getApplicationInfo().uid;
    mStartRX = TrafficStats.getUidRxBytes(uid);
    mStartTX = TrafficStats.getUidTxBytes(uid);

    //------------ Menu hard or soft key ------------------
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        boolean hasMenuKey = ViewConfiguration.get(ctx).hasPermanentMenuKey();

        ActionBar actionBar = getActionBar();
        if (!hasMenuKey) {
            actionBar.show();
        } else {
            actionBar.hide();

        }
    }

    //------------------ Temperature -----------------------------------
    mReceiver_Temperature = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            int temperature = intent.getIntExtra(BatteryManager.EXTRA_TEMPERATURE, 0);
            if (temperature > 450) {
                String mes = getString(R.string.tempwarn);
                int fullstopIndex = mes.indexOf(".");

                mes = mes.replace("XXXXX", Float.toString((((float) temperature) / 10)) + "\u2103");
                String mesA = mes.substring(0, fullstopIndex);
                Toast.makeText(ctx, mesA, Toast.LENGTH_LONG).show();
                String mesB = mes.substring(fullstopIndex + 2);
                Toast.makeText(ctx, mesB, Toast.LENGTH_LONG).show();
            }
        }
    };

    //--------------- Remove Transparency and Enable -------------------------------
    intentFilter = new IntentFilter("android.intent.action.MAIN"); // DataCh
    mReceiverARFinished = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            String ARFINISHED = intent.getStringExtra("ARFINISHED");
            Integer ARDATAPLUSVal = intent.getIntExtra("DataPlus", 0);

            if (ARFINISHED != null) {
                Log.e("AR Finished", "ok 2");

                if (pbarGeneral != null)
                    pbarGeneral.setProgress(90);

                Message msg = new Message();
                msg.arg1 = 2;
                handlerDialog.sendMessage(msg);

            } else if (ARDATAPLUSVal != 0) {
                if (pbarGeneral != null) {

                    if (ARDATAPLUSVal > 90)
                        ARDATAPLUSVal = 90;

                    pbarGeneral.setProgress(ARDATAPLUSVal);
                } else {
                    if (ARDATAPLUSVal < 15) {
                        Message msg = new Message();
                        msg.arg1 = 1;
                        handlerDialog.sendMessage(msg);
                    }
                }
            }
        }
    };
    registerReceiver(mReceiverARFinished, intentFilter);

    //----- Handler for Redrawing Markers from update thread ------------
    handlerDialog = new Handler() {
        public void handleMessage(Message msg) {
            if (msg.arg1 == 1) {
                if (progressReceiving == null) {
                    progressReceiving = ProgressDialog.show(ctx, "", "", true);
                    progressReceiving.setContentView(R.layout.dialog_transparent_progress);
                    pbarGeneral = (ProgressBar) progressReceiving.findViewById(R.id.allprogress);
                }
            } else {
                if (progressReceiving != null && progressReceiving.isShowing())
                    progressReceiving.dismiss();

                progressReceiving = null;
            }
            super.handleMessage(msg);
        }
    };

    if (Functions.checkInternetConnection(this) && Functions.hasNetLocationProviderEnabled(this)
            && Functions.hasGPSLocationProviderEnabled(this)) {
        // Show progress transparency
        Message msg = new Message();
        msg.arg1 = 1;
        handlerDialog.sendMessage(msg);
    }
}

From source file:com.app.jdy.ui.MyCommunityActivity.java

private void getDate() {
    Thread thread = new Thread(new Runnable() {

        @Override/*from www.  j  av  a 2  s  . c o m*/
        public void run() {
            Message msg = new Message();
            dataJson = HttpUtils.request(null,
                    URLs.MY_COMMUNITY + "memberId=" + ID + "&year=" + Constants.SELECT_YEAR);
            if (dataJson.length() != 0 && !dataJson.equals("0x110")) {
                if (!dataJson.equals("false")) {
                    msg.what = 1;
                } else {
                    msg.what = 2;
                }
            } else {
                msg.what = 0;
            }
            handler.sendMessage(msg);
        }
    });
    thread.start();
}

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  ww . j  a  v  a2  s.c om
        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.xmobileapp.rockplayer.LastFmAlbumArtImporter.java

/*********************************
 * //from ww  w.  j ava 2  s.  c o m
 * Get AlbumArt
 * @throws SAXException 
 * @throws ParserConfigurationException 
 *
 *********************************/
public void getAlbumArt() throws SAXException, ParserConfigurationException {
    /*
     * Initialize Album Cursor
     */
    albumCursor = ((RockPlayer) context).contentResolver.query(MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI,
            ((RockPlayer) context).ALBUM_COLS, // we should minimize the number of columns
            null, // all albums 
            null, // parameters to the previous parameter - which is null also 
            null // sort order, SQLite-like
    );

    /*
     * Declare & Initialize some vars
     */
    String artistName = null;
    String albumName = null;
    SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
    SAXParser saxParser = saxParserFactory.newSAXParser();
    XMLReader xmlReader = saxParser.getXMLReader();
    XMLAlbumArtHandler xmlHandler = new XMLAlbumArtHandler();
    //        XMLGoogleAlbumArtHandler xmlGoogleHandler = new XMLGoogleAlbumArtHandler();

    /*
     * Give feedback to the user
     */
    Bundle data = new Bundle();
    Message msg = new Message();
    data.putString("info", "Looking for missing art...");
    msg.setData(data);
    ((RockPlayer) context).getAlbumArtHandler.sendMessage(msg);

    /*
     * Loop through the albums
     */
    albumCursor.moveToFirst();
    for (int i = 0; i < albumCursor.getCount(); i++) {
        System.gc();
        /*
         * Get Album Details
         */
        artistName = albumCursor.getString(albumCursor.getColumnIndex(MediaStore.Audio.Albums.ARTIST));
        albumName = albumCursor.getString(albumCursor.getColumnIndex(MediaStore.Audio.Albums.ALBUM));

        /*
         * If no Art is available fetch it
         */
        if (getAlbumArtPath(artistName, albumName) == null) {
            Log.i("LastFM", "Album with no Art " + albumName);
            try {
                if ((artistName.equals("<unknown>") && albumName.equals("<unknown>"))) {
                    Log.i("ALBUMART", "Unknown album");
                    albumCursor.moveToNext();
                    continue;
                }
            } catch (Exception e) {
                Log.i("ALBUMART", "Null album or artist");
                albumCursor.moveToNext();
                continue;
            }

            /*
             * Give feedback to the user
             */
            data = new Bundle();
            msg = new Message();
            data.putString("info", albumName);
            msg.setData(data);
            ((RockPlayer) context).getAlbumArtHandler.sendMessage(msg);

            String albumArtURL = null;
            try {
                /*
                 * Get album URL from Last.FM
                 */
                String artistNameFiltered = filterString(artistName);
                String albumNameFiltered = filterString(albumName);

                if (USE_GOOGLE_IMAGES) {
                    //                    xmlReader.setContentHandler(xmlGoogleHandler);

                    URL googleImagesRequest = new URL(
                            this.GOOGLE_IMAGES_SEARCH_URL + URLEncoder.encode(artistNameFiltered) + "+"
                                    + URLEncoder.encode(albumNameFiltered));
                    //                    Log.i("GOOGLEIMAGES", googleImagesRequest.toString());

                    //                    DefaultHttpClientConnection httpCon = createGoogleImageConnection(
                    //                          googleImagesRequest.toString());
                    /*
                     * retreive URL
                     */
                    BasicHttpParams params = new BasicHttpParams();
                    HttpConnectionParams.setConnectionTimeout(params, 10000);
                    DefaultHttpClient httpClient = new DefaultHttpClient();

                    // Get cookies from the login page (not the address same of the form post)
                    HttpGet httpGet = new HttpGet(googleImagesRequest.toString());

                    HttpResponse response;

                    try {
                        /*
                         * Get the page
                         */
                        response = httpClient.execute(httpGet);
                        HttpEntity entity = response.getEntity();
                        BufferedReader in = new BufferedReader(new InputStreamReader(entity.getContent()));

                        /*
                         * Parse 1st existing image on the result page
                         */
                        String line;
                        int idxStart = 0;
                        int idxStop;
                        do {
                            line = in.readLine();
                            if (line != null) {
                                //                           Log.i("GIMAGES", line);
                                if (line.startsWith("<table")) {
                                    boolean found = false;
                                    int tries = 0;
                                    while (!found) {
                                        tries++;
                                        if (tries > 12)
                                            break;
                                        idxStart = line.indexOf("<a href=", idxStart);

                                        if (idxStart == -1) {
                                            line = in.readLine();
                                            if (line == null)
                                                break;
                                            continue;
                                        }

                                        idxStart = line.indexOf("http://", idxStart);
                                        idxStop = line.indexOf("&imgrefurl=", idxStart);
                                        albumArtURL = line.substring(idxStart, idxStop);
                                        Log.i("GIMAGE", line.substring(idxStart, idxStop));

                                        try {
                                            //URL albumArt = new URL(URLEncoder.encode(albumArtURL));
                                            //                                    URL albumArt = new URL(albumArtURL);
                                            //                                    InputStream albumArtURLStream = albumArt.openStream();
                                            //                                    albumArtURLStream.close();
                                            if (albumArtURL != null) {
                                                if (createAlbumArt(artistName, albumName,
                                                        albumArtURL) == null) {
                                                    albumArtURL = null;
                                                    found = false;
                                                    Log.i("GIMAGES", "createAlbumArt FAIL");
                                                } else {
                                                    found = true;
                                                    Log.i("GIMAGES", "createAlbumArt WIN");
                                                }
                                            } else {
                                                albumArtURL = null;
                                                found = false;
                                                Log.i("GIMAGES", "albumArt URL FAIL!");
                                            }
                                        } catch (Exception e) {
                                            e.printStackTrace();
                                            albumArtURL = null;
                                            found = false;
                                        }
                                    }
                                    break;
                                }
                            }
                        } while (line != null);

                        //                     xmlReader.parse(new InputSource(in));

                        entity.consumeContent();

                        //                     for(int j = 0; j < xmlGoogleHandler.MAX_IMAGES; j++){
                        //                        if(xmlGoogleHandler.albumArtUrl[j] != null){
                        //                           albumArtURL = xmlGoogleHandler.albumArtUrl[j];
                        //                           break;
                        //                        }
                        //                     }

                        /*
                         * No luck with the duck
                         */
                        //                     if(albumArtURL == null){
                        //                        Log.i("GOOGLEIMAGES", "Absolutely no luck");
                        //                        // mark this as a problematic album... 
                        //                        // so we dont refetch it all the time
                        //                         createSmallAlbumArt(artistName, albumName, false);
                        //                        albumCursor.moveToNext();
                        //                        continue;
                        //                     } else {
                        //                        Log.i("GOOGLEIMAGES", albumArtURL);
                        //                     }

                        /*
                         * Clear up the Handler
                         */
                        //                     xmlGoogleHandler.clear();

                    } catch (MalformedURLException e) {
                        e.printStackTrace();
                    } catch (IOException e) {
                        e.printStackTrace();
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    //                  
                    //                  /*
                    //                  * No Album Art available
                    //                  *  1. try going by the album name
                    //                  *  2. get some artist pic and thats it
                    //                  */
                    //                  if(albumArtURL == null){
                    //                  Log.i("LASTFM", "Could not get album art immediately");
                    //                  Log.i("LASTFM", "Trying sole album search");
                    //                  
                    //                  albumArtURL = getAlbumArtByAlbumName(albumName, artistName);
                    //                  if(albumArtURL == null){
                    //                  Log.i("LASTFM", "Trying to get artist Art");
                    //                  albumArtURL = getArtistArt(artistName);
                    //                  }
                    //                  /*
                    //                  * No luck with the duck
                    //                  */
                    //                  if(albumArtURL == null){
                    //                  Log.i("LASTFM", "Absolutely no luck");
                    //                  // mark this as a problematic album... 
                    //                  // so we dont refetch it all the time
                    //                  createSmallAlbumArt(artistName, albumName, false);
                    //                  albumCursor.moveToNext();
                    //                  continue;
                    //                  }
                    //                  }
                }

                /*
                 * If google images failed try last.fm
                 */
                if (albumArtURL == null) {
                    xmlReader.setContentHandler(xmlHandler);

                    URL lastFmApiRequest = new URL(
                            this.LAST_FM_ALBUM_GETINFO_URL + "&artist=" + URLEncoder.encode(artistNameFiltered)
                                    + "&album=" + URLEncoder.encode(albumNameFiltered));
                    try {
                        BufferedReader in = new BufferedReader(
                                new InputStreamReader(lastFmApiRequest.openStream()));
                        xmlReader.parse(new InputSource(in));

                        if (xmlHandler.xlargeAlbumArt != null) {
                            albumArtURL = xmlHandler.xlargeAlbumArt;
                        } else if (xmlHandler.largeAlbumArt != null) {
                            albumArtURL = xmlHandler.largeAlbumArt;
                        } else if (xmlHandler.mediumAlbumArt != null) {
                            albumArtURL = xmlHandler.mediumAlbumArt;
                        }
                    } catch (MalformedURLException e) {
                        e.printStackTrace();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }

                    /*
                     * No Album Art available
                     *  1. try going by the album name
                     *  2. get some artist pic and thats it
                     */
                    if (albumArtURL == null) {
                        Log.i("LASTFM", "Could not get album art immediately");
                        Log.i("LASTFM", "Trying sole album search");

                        albumArtURL = getAlbumArtByAlbumName(albumName, artistName);
                        if (albumArtURL == null) {
                            Log.i("LASTFM", "Trying to get artist Art");
                            albumArtURL = getArtistArt(artistName);
                        }
                        /*
                         * No luck with the duck
                         */
                        if (albumArtURL == null) {
                            Log.i("LASTFM", "Absolutely no luck");
                            // mark this as a problematic album... 
                            // so we dont refetch it all the time
                            createSmallAlbumArt(artistName, albumName, false);
                            albumCursor.moveToNext();
                            continue;
                        }
                    }

                    /* only reaches here if not FAIL */
                    createAlbumArt(artistName, albumName, albumArtURL);

                }

                /*
                 * reset xml handler
                 */
                xmlHandler.smallAlbumArt = null;
                xmlHandler.mediumAlbumArt = null;
                xmlHandler.largeAlbumArt = null;
                xmlHandler.xlargeAlbumArt = null;

            } catch (MalformedURLException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            } catch (SAXException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (NullPointerException e) {
                e.printStackTrace();
            }
        }
        /*
         * Create small album art
         */
        createSmallAlbumArt(artistName, albumName, true);

        /*
        * Give feedback to the user
        */
        //Bundle data = new Bundle();
        //Message msg = new Message();
        //data.putString("info", "Creating Thumbnail");
        //msg.setData(data);
        //((Filex) context).getAlbumArtHandler.sendMessage(msg);

        albumCursor.moveToNext();
    }

    /*
     * Give feedback to the user
     */
    data = new Bundle();
    msg = new Message();
    data.putString("info", "Done!");
    msg.setData(data);
    ((RockPlayer) context).getAlbumArtHandler.sendMessage(msg);

    /*
     * Set the last import date on preferences
     */
    //        SharedPreferences settings = ((Filex) this.context).getSharedPreferences(((Filex) this.context).PREFS_NAME, 0);
    //        Editor editor = settings.edit();
    //        editor.putLong("artImportDate", System.currentTimeMillis());
    //        editor.commit();
    RockOnPreferenceManager settings = new RockOnPreferenceManager(
            ((RockPlayer) context).FILEX_PREFERENCES_PATH);
    settings.putLong("artImportDate", System.currentTimeMillis());

    //settings.
    //   long lastAlbumArtImportDate = settings.getLong("artImportDate", 0);
}

From source file:com.huison.DriverAssistant_Web.util.LoginHelper.java

private static void sendMsg(int flag) {
    if (HomeActivity.handler == null)
        return;/*www .  jav a 2s. c  o m*/
    Message msg = new Message();
    msg.what = flag;
    HomeActivity.handler.sendMessage(msg);
}