Example usage for android.os Handler sendEmptyMessage

List of usage examples for android.os Handler sendEmptyMessage

Introduction

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

Prototype

public final boolean sendEmptyMessage(int what) 

Source Link

Document

Sends a Message containing only the what value.

Usage

From source file:cl.droid.transantiago.activity.TransChooseServiceActivity.java

public void launch(final String paradero, final String description) {
    //         final String paradero = item.mTitle;
    SearchRecentSuggestions suggestions = new SearchRecentSuggestions(TransChooseServiceActivity.this,
            MySuggestionProvider.AUTHORITY, MySuggestionProvider.MODE);
    suggestions.saveRecentQuery(paradero, null);

    //         final ProgressDialog progress = ProgressDialog.show(
    //               TransChooseServiceActivity.this, TransChooseServiceActivity.this.getResources().getText(
    //                     R.string.please_wait), TransChooseServiceActivity.this.getResources().getText(
    //                           R.string.searching), true, true);
    showRefreshSpinner(true);/* w w  w .  j a  v a  2s.c  o m*/
    final Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            if (progress != null && progress.isShowing())
                try {
                    progress.dismiss();
                    //                     backgroundThreadComplete = true;
                } catch (IllegalArgumentException e) {
                    // if orientation change, thread continue but the dialog cannot be dismissed without exception
                }
            if (locations != null && locations.containsKey("names")
                    && locations.getStringArray("names").length > 0) {
                locationInfo = locations.getStringArray("info");
                locationNames = locations.getStringArray("names");
                setListAdapter(la);

                if (locations.containsKey("ads"))
                    loadImage(locations.getString("ads"), bmOptions);
                //                     Intent intent = new Intent(SatNavActivity.this,
                //                           //                        org.opensatnav.android.ServiceActivity.class);
                //                           cl.droid.transantiago.TransChooseServiceActivity.class);
                //                     intent.putExtra("fromLocation", from.toDoubleString());
                //                     intent.putExtra("locations", locations);
                //                     intent.putExtra("paradero", paradero);
                //
                //                     String urlstring = "http://m.ibus.cl/index.jsp?paradero="+paradero+"&servicio=&boton.x=0&boton.y=0";
                //                     //                  Log.i(OpenSatNavConstants.LOG_TAG, urlstring);
                //                     intent.putExtra("url", urlstring);
                //                     startActivityForResult(intent,0);

            } else if (locations != null && locations.containsKey("names")
                    && locations.getStringArray("names").length == 0)
                Toast.makeText(TransChooseServiceActivity.this,
                        String.format(TransChooseServiceActivity.this.getResources().getText(
                                //                                    R.string.could_not_find_poi
                                R.string.place_not_found).toString(), "paradero")
                //                              + " " + stringValue
                , Toast.LENGTH_LONG).show();
            if (locations == null)
                Toast.makeText(TransChooseServiceActivity.this,
                        TransChooseServiceActivity.this.getResources().getText(
                                //                           R.string.could_not_find_poi
                                R.string.error_no_server_conn).toString(),
                        Toast.LENGTH_LONG).show();

            //               TransChooseLocationServiceActivity.this.finish();
            showRefreshSpinner(false);
        }
    };
    new Thread(new Runnable() {
        public void run() {
            // put long running operations here
            TransantiagoGeoCoder geoCoder = null;

            geoCoder = new TransantiagoGeoCoder();

            //               if (selectedPoi == -1) { // text search, rank results within an area
            locations = geoCoder.queryService(paradero, from, GeoCoder.IN_AREA, 25,
                    TransChooseServiceActivity.this);
            //               }
            //               else {  //POI search, just find the nearest matching POI
            //               locations = geoCoder.queryService("", from, GeoCoder.FROM_POINT, 25,
            //                     TransChooseLocationServiceActivity.this);
            //               }
            // ok, we are done
            handler.sendEmptyMessage(0);

        }
    }).start();

}

From source file:com.owncloud.android.ui.adapter.FileListListAdapter.java

@Override
public View getView(final int position, View convertView, ViewGroup parent) {
    View view = convertView;//from www .j  a  v a 2s  . c o m
    if (view == null) {
        LayoutInflater inflator = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        view = inflator.inflate(R.layout.list_item, null);
    }

    if (mFiles != null && mFiles.size() > position) {
        OCFile file = mFiles.get(position);
        TextView fileName = (TextView) view.findViewById(R.id.Filename);
        String name = file.getFileName();
        if (dataSourceShareFile == null)
            dataSourceShareFile = new DbShareFile(mContext);

        Account account = AccountUtils.getCurrentOwnCloudAccount(mContext);
        String[] accountNames = account.name.split("@");

        if (accountNames.length > 2) {
            accountName = accountNames[0] + "@" + accountNames[1];
            url = accountNames[2];
        }
        Map<String, String> fileSharers = dataSourceShareFile.getUsersWhoSharedFilesWithMe(accountName);
        TextView sharer = (TextView) view.findViewById(R.id.sharer);
        ImageView shareButton = (ImageView) view.findViewById(R.id.shareItem);
        fileName.setText(name);
        ImageView fileIcon = (ImageView) view.findViewById(R.id.imageView1);
        fileIcon.setImageResource(DisplayUtils.getResourceId(file.getMimetype()));
        ImageView localStateView = (ImageView) view.findViewById(R.id.imageView2);
        FileDownloaderBinder downloaderBinder = mTransferServiceGetter.getFileDownloaderBinder();
        FileUploaderBinder uploaderBinder = mTransferServiceGetter.getFileUploaderBinder();
        if (fileSharers.size() != 0 && (!file.equals("Shared") && file.getRemotePath().contains("Shared"))) {
            if (fileSharers.containsKey(name)) {
                sharer.setText(fileSharers.get(name));
                fileSharers.remove(name);
            } else {
                sharer.setText(" ");
            }
        } else {
            sharer.setText(" ");
        }

        if (downloaderBinder != null && downloaderBinder.isDownloading(mAccount, file)) {
            localStateView.setImageResource(R.drawable.downloading_file_indicator);
            localStateView.setVisibility(View.VISIBLE);
        } else if (uploaderBinder != null && uploaderBinder.isUploading(mAccount, file)) {
            localStateView.setImageResource(R.drawable.uploading_file_indicator);
            localStateView.setVisibility(View.VISIBLE);
        } else if (file.isDown()) {
            localStateView.setImageResource(R.drawable.local_file_indicator);
            localStateView.setVisibility(View.VISIBLE);
        } else {
            localStateView.setVisibility(View.INVISIBLE);
        }

        TextView fileSizeV = (TextView) view.findViewById(R.id.file_size);
        TextView lastModV = (TextView) view.findViewById(R.id.last_mod);
        ImageView checkBoxV = (ImageView) view.findViewById(R.id.custom_checkbox);
        shareButton.setOnClickListener(new OnClickListener() {
            String shareStatusDisplay;
            int flagShare = 0;

            @Override
            public void onClick(View v) {
                final Dialog dialog = new Dialog(mContext);
                final OCFile fileToBeShared = (OCFile) getItem(position);
                final ArrayAdapter<String> shareWithFriends;
                final ArrayAdapter<String> shareAdapter;
                final String filePath;
                sharedWith = new ArrayList<String>();
                dataSource = new DbFriends(mContext);
                dataSourceShareFile = new DbShareFile(mContext);
                dialog.setContentView(R.layout.share_file_with);
                dialog.setTitle("Share");
                Account account = AccountUtils.getCurrentOwnCloudAccount(mContext);
                String[] accountNames = account.name.split("@");

                if (accountNames.length > 2) {
                    accountName = accountNames[0] + "@" + accountNames[1];
                    url = accountNames[2];
                }

                final AutoCompleteTextView textView = (AutoCompleteTextView) dialog
                        .findViewById(R.id.autocompleteshare);
                Button shareBtn = (Button) dialog.findViewById(R.id.ShareBtn);
                Button doneBtn = (Button) dialog.findViewById(R.id.ShareDoneBtn);
                final ListView listview = (ListView) dialog.findViewById(R.id.alreadySharedWithList);

                textView.setThreshold(2);
                final String itemType;

                filePath = "files" + String.valueOf(fileToBeShared.getRemotePath());
                final String fileName = fileToBeShared.getFileName();
                final String fileRemotePath = fileToBeShared.getRemotePath();
                if (dataSourceShareFile == null)
                    dataSourceShareFile = new DbShareFile(mContext);
                sharedWith = dataSourceShareFile.getUsersWithWhomIhaveSharedFile(fileName, fileRemotePath,
                        accountName, String.valueOf(1));
                shareAdapter = new ArrayAdapter<String>(mContext, android.R.layout.simple_list_item_1,
                        sharedWith);
                listview.setAdapter(shareAdapter);
                final String itemSource;
                if (fileToBeShared.isDirectory()) {
                    itemType = "folder";
                    int lastSlashInFolderPath = filePath.lastIndexOf('/');
                    itemSource = filePath.substring(0, lastSlashInFolderPath);
                } else {
                    itemType = "file";
                    itemSource = filePath;
                }

                //Permissions disabled with friends app
                ArrayList<String> friendList = dataSource.getFriendList(accountName);
                dataSource.close();
                shareWithFriends = new ArrayAdapter<String>(mContext, android.R.layout.simple_list_item_1,
                        friendList);
                textView.setAdapter(shareWithFriends);
                textView.setFocusableInTouchMode(true);
                dialog.show();
                textView.setOnItemClickListener(new OnItemClickListener() {

                    @Override
                    public void onItemClick(AdapterView<?> parent, View v, int position, long id) {

                    }
                });
                final Handler finishedHandler = new Handler() {
                    @Override
                    public void handleMessage(Message msg) {
                        shareAdapter.notifyDataSetChanged();
                        Toast.makeText(mContext, shareStatusDisplay, Toast.LENGTH_SHORT).show();

                    }
                };
                shareBtn.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        final String shareWith = textView.getText().toString();

                        if (shareWith.equals("")) {
                            textView.setHint("Share With");
                            Toast.makeText(mContext,
                                    "Please enter the friends name with whom you want to share",
                                    Toast.LENGTH_SHORT).show();
                        } else if (sharedWith.contains(shareWith)) {
                            textView.setHint("Share With");
                            Toast.makeText(mContext, "You have shared the file with that person",
                                    Toast.LENGTH_SHORT).show();
                        } else {

                            textView.setText("");
                            Runnable runnable = new Runnable() {
                                @Override
                                public void run() {
                                    HttpPost post = new HttpPost(
                                            "http://" + url + "/owncloud/androidshare.php");
                                    final ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();

                                    params.add(new BasicNameValuePair("itemType", itemType));
                                    params.add(new BasicNameValuePair("itemSource", itemSource));
                                    params.add(new BasicNameValuePair("shareType", shareType));
                                    params.add(new BasicNameValuePair("shareWith", shareWith));
                                    params.add(new BasicNameValuePair("permission", permissions));
                                    params.add(new BasicNameValuePair("uidOwner", accountName));
                                    HttpEntity entity;
                                    String shareSuccess = "false";
                                    try {
                                        entity = new UrlEncodedFormEntity(params, "utf-8");
                                        HttpClient client = new DefaultHttpClient();
                                        post.setEntity(entity);
                                        HttpResponse response = client.execute(post);

                                        if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
                                            HttpEntity entityresponse = response.getEntity();
                                            String jsonentity = EntityUtils.toString(entityresponse);
                                            JSONObject obj = new JSONObject(jsonentity);
                                            shareSuccess = obj.getString("SHARE_STATUS");
                                            flagShare = 1;
                                            if (shareSuccess.equals("true")) {
                                                dataSourceShareFile.putNewShares(fileName, fileRemotePath,
                                                        accountName, shareWith);
                                                sharedWith.add(shareWith);
                                                shareStatusDisplay = "File share succeeded";
                                            } else if (shareSuccess.equals("INVALID_FILE")) {
                                                shareStatusDisplay = "File you are trying to share does not exist";
                                            } else if (shareSuccess.equals("INVALID_SHARETYPE")) {
                                                shareStatusDisplay = "File Share type is invalid";
                                            } else {
                                                shareStatusDisplay = "Share did not succeed. Please check your internet connection";
                                            }

                                            finishedHandler.sendEmptyMessage(flagShare);

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

                                }
                            };
                            new Thread(runnable).start();

                        }

                        if (flagShare == 1) {
                        }

                    }

                });
                doneBtn.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        dialog.dismiss();
                        //dataSourceShareFile.close();
                    }
                });
            }

        });
        //dataSourceShareFile.close();
        if (!file.isDirectory()) {
            fileSizeV.setVisibility(View.VISIBLE);
            fileSizeV.setText(DisplayUtils.bytesToHumanReadable(file.getFileLength()));
            lastModV.setVisibility(View.VISIBLE);
            lastModV.setText(DisplayUtils.unixTimeToHumanReadable(file.getModificationTimestamp()));
            // this if-else is needed even thoe fav icon is visible by default
            // because android reuses views in listview
            if (!file.keepInSync()) {
                view.findViewById(R.id.imageView3).setVisibility(View.GONE);
            } else {
                view.findViewById(R.id.imageView3).setVisibility(View.VISIBLE);
            }

            ListView parentList = (ListView) parent;
            if (parentList.getChoiceMode() == ListView.CHOICE_MODE_NONE) {
                checkBoxV.setVisibility(View.GONE);
            } else {
                if (parentList.isItemChecked(position)) {
                    checkBoxV.setImageResource(android.R.drawable.checkbox_on_background);
                } else {
                    checkBoxV.setImageResource(android.R.drawable.checkbox_off_background);
                }
                checkBoxV.setVisibility(View.VISIBLE);
            }

        } else {

            fileSizeV.setVisibility(View.VISIBLE);
            fileSizeV.setText(DisplayUtils.bytesToHumanReadable(file.getFileLength()));
            lastModV.setVisibility(View.VISIBLE);
            lastModV.setText(DisplayUtils.unixTimeToHumanReadable(file.getModificationTimestamp()));
            checkBoxV.setVisibility(View.GONE);
            view.findViewById(R.id.imageView3).setVisibility(View.GONE);
        }
    }

    return view;
}

From source file:cgeo.geocaching.cgBase.java

public String getMapUserToken(Handler noTokenHandler) {
    final cgResponse response = request(false, "www.geocaching.com", "/map/default.aspx", "GET", "", 0, false);
    final String data = response.getData();
    String usertoken = null;//w  ww  . ja va 2s .com

    if (StringUtils.isNotBlank(data)) {
        final Pattern pattern = Pattern.compile("var userToken[^=]*=[^']*'([^']+)';",
                Pattern.CASE_INSENSITIVE | Pattern.MULTILINE);

        final Matcher matcher = pattern.matcher(data);
        while (matcher.find()) {
            if (matcher.groupCount() > 0) {
                usertoken = matcher.group(1);
            }
        }
    }

    if (noTokenHandler != null && StringUtils.isBlank(usertoken)) {
        noTokenHandler.sendEmptyMessage(0);
    }

    return usertoken;
}

From source file:org.anurag.file.quest.TaskerActivity.java

/**
 * THIS FUNCTION SETS THE ADPATER FOR ALL THE PANELS,AFTER CERTAIN OPERATIONS... 
 *//*from   w ww .  j a va2s .c  o m*/
private static void setAdapter(final int ITEM) {
    final Handler handle = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            // TODO Auto-generated method stub
            switch (msg.what) {
            case 1:
                root.setAdapter(
                        new EmptyAdapter(mContext.getApplicationContext(), R.layout.empty_adapter, EMPTY));
                root.setEnabled(false);
                mViewPager.setAdapter(mSectionsPagerAdapter);
                mViewPager.setCurrentItem(ITEM);
                break;

            case 2:

                simple.setAdapter(
                        new EmptyAdapter(mContext.getApplicationContext(), R.layout.empty_adapter, EMPTY));
                simple.setEnabled(false);
                mViewPager.setAdapter(mSectionsPagerAdapter);
                mViewPager.setCurrentItem(ITEM);
                break;

            case 3:
                mViewPager.setAdapter(mSectionsPagerAdapter);
                mViewPager.setCurrentItem(ITEM);
                break;
            case 4:
                mViewPager.setAdapter(mSectionsPagerAdapter);
                mViewPager.setCurrentItem(ITEM);
                APP_LIST_VIEW.setAdapter(nAppAdapter);
                APP_LIST_VIEW.setSelection(pos);
                break;
            case 5:
                load_FIle_Gallery(fPos);
                break;
            }
            super.handleMessage(msg);
        }
    };

    Thread thread = new Thread(new Runnable() {
        @Override
        public void run() {
            // TODO Auto-generated method stub
            if (SHOW_HIDDEN_FOLDERS) {
                RFileManager.SHOW_HIDDEN_FOLDER = true;
                SFileManager.SHOW_HIDDEN_FOLDER = true;
            }

            try {//TRY BLOCK IS USED BECAUSE I NOTICED THAT WHEN NEW FOLDER
                 //WITH HINDI LANGAUGE IS CREATED THROWS INDEXOUTOFBOUND EXCEPTION 
                 //I THINK IT IS APPLICABLE TO OTHER LANGUAGES ALSO
                nFiles = RFileManager.giveMeFileList();
                sFiles = SFileManager.giveMeFileList();
                if (ITEM == 0)
                    loadMediaList(pos);
            } catch (IndexOutOfBoundsException e) {
                nFiles = RFileManager.giveMeFileList();
                sFiles = SFileManager.giveMeFileList();
            }

            if (RootAdapter.MULTI_SELECT) {
                RootAdapter.thumbselection = new boolean[nFiles.size()];
                RootAdapter.MULTI_FILES = new ArrayList<File>();
                RootAdapter.C = 0;
            }
            if (SimpleAdapter.MULTI_SELECT) {
                SimpleAdapter.thumbselection = new boolean[sFiles.size()];
                SimpleAdapter.MULTI_FILES = new ArrayList<File>();
                SimpleAdapter.c = 0;
            }
            rSize = nFiles.size();
            sSize = sFiles.size();
            mSize = mediaFileList.size();
            mUseBackKey = false;

            if (rSize == 0 && ITEM == 2)
                handle.sendEmptyMessage(1);//LIST IS EMPTY....IN SDCARD PANEL
            else if (sSize == 0 && ITEM == 1)
                handle.sendEmptyMessage(2);//list IS EMPTY...IN "/" PANEL
            else if ((rSize != 0 && ITEM == 2) || (sSize != 0 && ITEM == 1))//NON OF THE LIST IS EMPTY....
                handle.sendEmptyMessage(3);
            else if (ITEM == 3) {
                if (MULTI_SELECT_APPS) {
                    nAppAdapter = new AppAdapter(mContext, R.layout.row_list_1, nList);
                    nAppAdapter.MULTI_SELECT = true;
                    handle.sendEmptyMessage(4);
                } else if (!MULTI_SELECT_APPS) {
                    nAppAdapter = new AppAdapter(mContext, R.layout.row_list_1, nList);
                    nAppAdapter.MULTI_SELECT = false;
                    handle.sendEmptyMessage(4);
                }
            } else if (ITEM == 0 && elementInFocus)
                handle.sendEmptyMessage(5);
        }
    });
    thread.start();
}

From source file:org.anurag.file.quest.TaskerActivity.java

/**
 * FUNCTION MAKE 3d LIST VIEW VISIBLE OR GONE AS PER REQUIREMENT
 * @param mode/*from  w ww  .j  a v a  2s .  co  m*/
 * @param con
 */
public static void load_FIle_Gallery(final int mode) {
    final Dialog pDialog = new Dialog(mContext, R.style.custom_dialog_theme);
    final Handler handle = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            switch (msg.what) {
            case 0:
                try {
                    pDialog.setContentView(R.layout.p_dialog);
                    pDialog.setCancelable(false);
                    pDialog.getWindow().getAttributes().width = size.x * 4 / 5;
                    WebView web = (WebView) pDialog.findViewById(R.id.p_Web_View);
                    web.loadUrl("file:///android_asset/Progress_Bar_HTML/index.html");
                    web.setEnabled(false);
                    pDialog.show();
                } catch (InflateException e) {
                    error = true;
                    Toast.makeText(mContext,
                            "An exception encountered please wait while loading" + " file list",
                            Toast.LENGTH_SHORT).show();
                }
                break;
            case 1:
                if (pDialog != null)
                    if (pDialog.isShowing())
                        pDialog.dismiss();

                if (mediaFileList.size() > 0) {
                    FILE_GALLEY.setVisibility(View.GONE);
                    LIST_VIEW_3D.setVisibility(View.VISIBLE);
                    element = new MediaElementAdapter(mContext, R.layout.row_list_1, mediaFileList);
                    //AT THE PLACE OF ELEMENT YOU CAN USE MUSIC ADAPTER....
                    // AND SEE WHAT HAPPENS
                    if (mediaFileList.size() > 0) {
                        LIST_VIEW_3D.setAdapter(element);
                        LIST_VIEW_3D.setEnabled(true);
                    } else if (mediaFileList.size() == 0) {
                        LIST_VIEW_3D.setAdapter(new EmptyAdapter(mContext, R.layout.row_list_3, EMPTY));
                        LIST_VIEW_3D.setEnabled(false);
                    }
                    LIST_VIEW_3D.setDynamics(new SimpleDynamics(0.7f, 0.6f));
                    if (!elementInFocus) {
                        mFlipperBottom.showPrevious();
                        mFlipperBottom.setAnimation(prevAnim());
                        elementInFocus = true;
                    }
                    if (SEARCH_FLAG) {
                        mVFlipper.showPrevious();
                        mVFlipper.setAnimation(nextAnim());
                    }
                } else {
                    LIST_VIEW_3D.setVisibility(View.GONE);
                    FILE_GALLEY.setVisibility(View.VISIBLE);
                    Toast.makeText(mContext, R.string.empty, Toast.LENGTH_SHORT).show();
                    if (elementInFocus) {
                        mFlipperBottom.showNext();
                        mFlipperBottom.setAnimation(nextAnim());
                    }
                    elementInFocus = false;
                }
                break;
            }
        }
    };
    Thread thread = new Thread(new Runnable() {
        @Override
        public void run() {
            // TODO Auto-generated method stub
            handle.sendEmptyMessage(0);
            while (!Utils.loaded) {
                //STOPPING HERE WHILE FILES ARE BEING LOADED IN BACKGROUND....
            }
            if (mode == 0)
                mediaFileList = Utils.music;
            else if (mode == 1)
                mediaFileList = Utils.apps;
            else if (mode == 2)
                mediaFileList = Utils.doc;
            else if (mode == 3)
                mediaFileList = Utils.img;
            else if (mode == 4)
                mediaFileList = Utils.vids;
            else if (mode == 5)
                mediaFileList = Utils.zip;
            else if (mode == 6)
                mediaFileList = Utils.mis;
            handle.sendEmptyMessage(1);
        }
    });
    thread.start();
}

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

public String getMapUserToken(Handler noTokenHandler) {
    final Response response = request(false, "www.geocaching.com", "/map/default.aspx", "GET", "", 0, false);
    final String data = response.getData();
    String usertoken = null;//from  w  ww  . j a v  a 2  s.c  o m

    if (data != null && data.length() > 0) {
        final Pattern pattern = Pattern.compile("var userToken[^=]*=[^']*'([^']+)';",
                Pattern.CASE_INSENSITIVE | Pattern.MULTILINE);

        final Matcher matcher = pattern.matcher(data);
        while (matcher.find()) {
            if (matcher.groupCount() > 0) {
                usertoken = matcher.group(1);
            }
        }
    }

    if (noTokenHandler != null && (usertoken == null || usertoken.length() == 0)) {
        noTokenHandler.sendEmptyMessage(0);
    }

    return usertoken;
}

From source file:carnero.cgeo.cgBase.java

public String getMapUserToken(Handler noTokenHandler) {
    final cgResponse response = request(false, "www.geocaching.com", "/map/default.aspx", "GET", "", 0, false);
    final String data = response.getData();
    String usertoken = null;/* w w  w  . j a  v a  2  s .c o m*/

    if (data != null && data.length() > 0) {
        final Pattern pattern = Pattern.compile("var userToken[^=]*=[^']*'([^']+)';",
                Pattern.CASE_INSENSITIVE | Pattern.MULTILINE);

        final Matcher matcher = pattern.matcher(data);
        while (matcher.find()) {
            if (matcher.groupCount() > 0) {
                usertoken = matcher.group(1);
            }
        }
    }

    if (noTokenHandler != null && (usertoken == null || usertoken.length() == 0)) {
        noTokenHandler.sendEmptyMessage(0);
    }

    return usertoken;
}

From source file:com.licubeclub.zionhs.MainActivity.java

void networkTask() {
    SRL.setRefreshing(true);/* w  w w  .j  av a 2  s .  co m*/
    final Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
        }
    };

    final Handler mHandler = new Handler();
    new Thread() {

        public void run() {
            mHandler.post(new Runnable() {

                public void run() {
                    // SRL.setRefreshing(true);
                }
            });
            try {
                lunchstring = MealLoadHelper.getMeal("goe.go.kr", "J100000659", "4", "04", "2"); //Get Lunch Menu Date
                dinnerstring = MealLoadHelper.getMeal("goe.go.kr", "J100000659", "4", "04", "3"); //Get Dinner Menu Date
            } catch (Exception e) {
            }

            try {
                int skipcount = 0;
                boolean skipped = false;
                schedulearray = new ArrayList<String>();
                dayarray = new ArrayList<String>();

                //                    ? ?? ? ??  
                Document doc = Jsoup.connect(URL).get();

                Elements rawdaydata = doc.select(".listDay"); //Get contents from the class,"listDay"
                for (Element el : rawdaydata) {
                    String daydata = el.text();
                    if (daydata.equals("") | daydata == null) {
                        if (skipped) {
                        } else {
                            skipcount++;
                        }
                    } else {
                        dayarray.add(daydata); // add value to ArrayList
                        skipped = true;
                    }
                }
                Log.d("Schedule", "Parsed Day Array" + dayarray);

                Elements rawscheduledata = doc.select(".listData"); //Get contents from tags,"a" which are in the class,"ellipsis"
                for (Element el : rawscheduledata) {
                    String scheduledata = el.text();
                    if (skipcount > 0) {
                        skipcount--;
                    } else {
                        schedulearray.add(scheduledata); // add value to ArrayList
                    }
                }
                Log.d("Schedule", "Parsed Schedule Array" + schedulearray);
                //                    SRL.setRefreshing(false);
            } catch (IOException e) {
                e.printStackTrace();
                //                    SRL.setRefreshing(false);

            }
            try {
                titlearray_np = new ArrayList<String>();
                Document doc = Jsoup.connect(
                        "http://www.zion.hs.kr/main.php?menugrp=110100&master=bbs&act=list&master_sid=59")
                        .get();
                Elements rawdata = doc.select(".listbody a"); //Get contents from tags,"a" which are in the class,"listbody"
                String titlestring = rawdata.toString();
                Log.i("Notices", "Parsed Strings" + titlestring);

                for (Element el : rawdata) {
                    String titledata = el.attr("title");
                    titlearray_np.add(titledata); // add value to ArrayList
                }
                Log.i("Notices", "Parsed Array Strings" + titlearray_np);

            } catch (IOException e) {
                e.printStackTrace();

            }
            //Notices URL
            try {
                titlearray_n = new ArrayList<String>();
                // ? URL
                Document doc = Jsoup.connect(
                        "http://www.zion.hs.kr/main.php?" + "menugrp=110100&master=bbs&act=list&master_sid=58")
                        .get();
                //Get contents from tags,"a" which are in the class,"listbody"
                Elements rawmaindata = doc.select(".listbody a");
                String titlestring = rawmaindata.toString();
                Log.i("Notices", "Parsed Strings" + titlestring);

                // ??  ?
                for (Element el : rawmaindata) {
                    String titledata = el.attr("title");
                    titlearray_n.add(titledata); // add value to ArrayList
                }
                Log.i("Notices", "Parsed Array Strings" + titlearray_n);

            } catch (IOException e) {
                e.printStackTrace();

            }

            mHandler.post(new Runnable() {
                public void run() {
                    //                        progressDialog.dismiss();
                    //                        SRL.setRefreshing(false);
                    if (AMorPM == Calendar.AM) {
                        MealString = lunchstring[DAYofWEEK - 1];
                    } else {
                        MealString = dinnerstring[DAYofWEEK - 1];
                    }
                    try {
                        ScheduleString = schedulearray.get(DAYofMONTH - 1);
                        NoticesParentString = titlearray_np.get(0);
                        NoticeString = titlearray_n.get(0);
                    } catch (Exception e) {
                        ScheduleString = getResources().getString(R.string.error);
                        NoticesParentString = getResources().getString(R.string.error);
                        NoticeString = getResources().getString(R.string.error);
                    }

                    if (MealString == null) {
                        MealString = getResources().getString(R.string.nodata);
                    } else if (MealString.equals("")) {
                        MealString = getResources().getString(R.string.nodata);
                    }
                    if (ScheduleString == null) {
                        ScheduleString = getResources().getString(R.string.nodata);
                    } else if (ScheduleString.equals("")) {
                        ScheduleString = getResources().getString(R.string.nodata);
                    }
                    SRL.setRefreshing(false);
                    handler.sendEmptyMessage(0);
                    setContentData();
                }
            });

        }
    }.start();

}