Example usage for android.os SystemClock sleep

List of usage examples for android.os SystemClock sleep

Introduction

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

Prototype

public static void sleep(long ms) 

Source Link

Document

Waits a given number of milliseconds (of uptimeMillis) before returning.

Usage

From source file:com.andrew.apolloMod.service.ApolloService.java

private void reloadQueue() {
    String q = null;/*from  w ww  .ja v  a2 s . c  o  m*/

    int id = mCardId;
    if (mPreferences.contains("cardid")) {
        id = mPreferences.getInt("cardid", ~mCardId);
    }
    if (id == mCardId) {
        // Only restore the saved playlist if the card is still
        // the same one as when the playlist was saved
        q = mPreferences.getString("queue", "");
    }
    int qlen = q != null ? q.length() : 0;
    if (qlen > 1) {
        // Log.i("@@@@ service", "loaded queue: " + q);
        int plen = 0;
        int n = 0;
        int shift = 0;
        for (int i = 0; i < qlen; i++) {
            char c = q.charAt(i);
            if (c == ';') {
                ensurePlayListCapacity(plen + 1);
                mPlayList[plen] = n;
                plen++;
                n = 0;
                shift = 0;
            } else {
                if (c >= '0' && c <= '9') {
                    n += ((c - '0') << shift);
                } else if (c >= 'a' && c <= 'f') {
                    n += ((10 + c - 'a') << shift);
                } else {
                    // bogus playlist data
                    plen = 0;
                    break;
                }
                shift += 4;
            }
        }
        mPlayListLen = plen;

        int pos = mPreferences.getInt("curpos", 0);
        if (pos < 0 || pos >= mPlayListLen) {
            // The saved playlist is bogus, discard it
            mPlayListLen = 0;
            return;
        }
        mPlayPos = pos;

        // When reloadQueue is called in response to a card-insertion,
        // we might not be able to query the media provider right away.
        // To deal with this, try querying for the current file, and if
        // that fails, wait a while and try again. If that too fails,
        // assume there is a problem and don't restore the state.
        Cursor crsr = MusicUtils.query(this, Audio.Media.EXTERNAL_CONTENT_URI, new String[] { "_id" },
                "_id=" + mPlayList[mPlayPos], null, null);
        if (crsr == null || crsr.getCount() == 0) {
            // wait a bit and try again
            SystemClock.sleep(3000);
            crsr = getContentResolver().query(Audio.Media.EXTERNAL_CONTENT_URI, mCursorCols,
                    "_id=" + mPlayList[mPlayPos], null, null);
        }
        if (crsr != null) {
            crsr.close();
        }

        // Make sure we don't auto-skip to the next song, since that
        // also starts playback. What could happen in that case is:
        // - music is paused
        // - go to UMS and delete some files, including the currently
        // playing one
        // - come back from UMS
        // (time passes)
        // - music app is killed for some reason (out of memory)
        // - music service is restarted, service restores state, doesn't
        // find
        // the "current" file, goes to the next and: playback starts on its
        // own, potentially at some random inconvenient time.
        mOpenFailedCounter = 20;
        mQuietMode = true;
        openCurrentAndNext();
        mQuietMode = false;
        if (!mPlayer.isInitialized()) {
            // couldn't restore the saved state
            mPlayListLen = 0;
            return;
        }

        long seekpos = mPreferences.getLong("seekpos", 0);
        seek(seekpos >= 0 && seekpos < duration() ? seekpos : 0);
        Log.d(LOGTAG, "restored queue, currently at position " + position() + "/" + duration() + " (requested "
                + seekpos + ")");

        int repmode = mPreferences.getInt("repeatmode", REPEAT_NONE);
        if (repmode != REPEAT_ALL && repmode != REPEAT_CURRENT) {
            repmode = REPEAT_NONE;
        }
        mRepeatMode = repmode;

        int shufmode = mPreferences.getInt("shufflemode", SHUFFLE_NONE);
        if (shufmode != SHUFFLE_AUTO && shufmode != SHUFFLE_NORMAL) {
            shufmode = SHUFFLE_NONE;
        }
        if (shufmode != SHUFFLE_NONE) {
            // in shuffle mode we need to restore the history too
            q = mPreferences.getString("history", "");
            qlen = q != null ? q.length() : 0;
            if (qlen > 1) {
                plen = 0;
                n = 0;
                shift = 0;
                mHistory.clear();
                for (int i = 0; i < qlen; i++) {
                    char c = q.charAt(i);
                    if (c == ';') {
                        if (n >= mPlayListLen) {
                            // bogus history data
                            mHistory.clear();
                            break;
                        }
                        mHistory.add(n);
                        n = 0;
                        shift = 0;
                    } else {
                        if (c >= '0' && c <= '9') {
                            n += ((c - '0') << shift);
                        } else if (c >= 'a' && c <= 'f') {
                            n += ((10 + c - 'a') << shift);
                        } else {
                            // bogus history data
                            mHistory.clear();
                            break;
                        }
                        shift += 4;
                    }
                }
            }
        }
        if (shufmode == SHUFFLE_AUTO) {
            if (!makeAutoShuffleList()) {
                shufmode = SHUFFLE_NONE;
            }
        }
        mShuffleMode = shufmode;
    }
}

From source file:com.google.sample.cast.refplayer.Synchronization.java

/**
 *  Back to normal play mode//from ww  w. ja va2 s.  c om
 */
private void BackNormalPlay() {
    if (condition == 2 || condition == 3) {
        if (!previewMode) {
            mDisplayPreviewMode.setText("");
            playpause = false;
            mPlayPause.setImageDrawable(getResources().getDrawable(R.drawable.ic_av_play_dark));

            previewMode = true;

            if (timer != null) {
                timer.cancel();
            }

            if (condition == 2 || condition == 3) {
                if (Role == 1) {
                    seekBar.setVisibility(View.VISIBLE);
                }

                pseekBar.setVisibility(View.INVISIBLE);
            }

            if (Role == 1) {
                mProgressBar.setVisibility(View.VISIBLE);
            }
            previewSeek.setVisibility(View.INVISIBLE);
            mPlayPause.setVisibility(View.INVISIBLE);
        }

        mPreview.setVisibility(View.INVISIBLE);
        mSendClip.setVisibility(View.INVISIBLE);
    }

    if (Role == 1) {
        CurSysTime = System.currentTimeMillis();
        mCurTime = (int) (CurSysTime - SysStartTime);
        seekVideoView();
        mVideoView.start();
    }
    if (Role == 2) {
        mVideoView.seekTo(0);
        mVideoView.start();
        SystemClock.sleep(100);
        mVideoView.pause();
    }
    mClosebtn.setVisibility(View.INVISIBLE);
}

From source file:com.ubergeek42.WeechatAndroid.service.RelayServiceBackbone.java

@Override
public void onUpgrade() {
    // Don't do this twice
    if (upgrading != null && upgrading.isAlive())
        return;/*from   w  w w  .j a v  a  2 s. c om*/

    // Basically just reconnect on upgrade
    upgrading = new Thread(new Runnable() {
        @Override
        public void run() {
            showNotification(getString(R.string.notification_upgrading),
                    getString(R.string.notification_upgrading_details));
            startThreadedDisconnect();
            SystemClock.sleep(5000);
            startThreadedConnectLoop(true);
        }
    });
    upgrading.start();
}

From source file:com.google.sample.cast.refplayer.Synchronization.java

/**
 *  Setting the Previewing mode(Editing mode) clip bar (orange)
 */// ww w. jav  a  2s . c om
private void setPreviewClip() {

    if (pseekBar != null) {
        pseekBar.setVisibility(View.GONE);
    }

    prev_start_p_ForPreview = prev_start_p;
    prev_end_p_ForPreview = prev_end_p;

    pseekBar = new RangeSeekBar(prev_start_p_ForPreview, prev_end_p_ForPreview, this);
    pseekBar.setOnRangeSeekBarChangeListener(new OnRangeSeekBarChangeListener<Integer>() {
        @Override
        public void onRangeSeekBarValuesChanged(RangeSeekBar<?> bar, Integer start_p, Integer end_p) {
            // handle changed range values
            Log.i(TAG, "Selected new range values: MIN=" + start_p + ", MAX=" + end_p);
            mClipDuration.setText("  " + com.google.android.libraries.cast.companionlibrary.utils.Utils
                    .formatMillis(prev_end_p_ForPreview - prev_start_p_ForPreview) + "  ");

            playpause = false;
            mPlayPause.setImageDrawable(getResources().getDrawable(R.drawable.ic_av_play_dark));

            if (start_p != prev_start_p_ForPreview) {
                mVideoView.seekTo(start_p);
                mVideoView.start();
                SystemClock.sleep(100);
                mVideoView.pause();
                prev_start_p_ForPreview = start_p;
                prev_start_p = start_p;
            }
            if (end_p != prev_end_p_ForPreview) {
                mVideoView.seekTo(end_p);
                mVideoView.start();
                SystemClock.sleep(100);
                mVideoView.pause();
                prev_end_p_ForPreview = end_p;
                prev_end_p = end_p;
            }
        }
    });

    // add RangeSeekBar to pre-defined layout
    RelativeLayout layout = (RelativeLayout) findViewById(R.id.synchronization);
    RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);

    params.addRule(RelativeLayout.ALIGN_PARENT_LEFT, pseekBar.getId());
    params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, pseekBar.getId());
    params.addRule(RelativeLayout.BELOW, mVideoView.getId());
    pseekBar.setVisibility(View.VISIBLE);
    layout.addView(pseekBar, params);
}

From source file:com.hzx.luoyechat.activity.ChatActivity.java

/**
 * ?//from   www.  j av  a 2  s. c o m
 */
@Override
public void onClick(View view) {
    String st1 = getResources().getString(R.string.not_connect_to_server);
    int id = view.getId();
    if (id == R.id.btn_send) {// ??(?)
        String s = mEditTextContent.getText().toString();
        sendText(s);
    } else if (id == R.id.btn_take_picture) {
        selectPicFromCamera();// 
    } else if (id == R.id.btn_picture) {
        selectPicFromLocal(); // 
    } else if (id == R.id.btn_location) { // ?
        startActivityForResult(new Intent(this, BaiduMapActivity.class), REQUEST_CODE_MAP);
    } else if (id == R.id.iv_emoticons_normal) { // 
        exeTask(new Runnable() {
            @Override
            public void run() {
                SystemClock.sleep(SLEEP_MILLIES);

                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        more.setVisibility(View.VISIBLE);
                        iv_emoticons_checked.setVisibility(View.VISIBLE);
                        btnContainer.setVisibility(View.GONE);
                        emojiIconContainer.setVisibility(View.VISIBLE);
                    }
                });
            }
        });

        iv_emoticons_normal.setVisibility(View.INVISIBLE);
        hideKeyboard();
    } else if (id == R.id.iv_emoticons_checked) { // ??
        iv_emoticons_normal.setVisibility(View.VISIBLE);
        iv_emoticons_checked.setVisibility(View.INVISIBLE);
        btnContainer.setVisibility(View.VISIBLE);
        emojiIconContainer.setVisibility(View.GONE);
        more.setVisibility(View.GONE);

    } else if (id == R.id.btn_video) {
        // ?
        Intent intent = new Intent(ChatActivity.this, ImageGridActivity.class);
        startActivityForResult(intent, REQUEST_CODE_SELECT_VIDEO);
    } else if (id == R.id.btn_file) { // 
        selectFileFromLocal();
    } else if (id == R.id.btn_voice_call) { // ?
        if (!EMChatManager.getInstance().isConnected())
            Toast.makeText(this, st1, Toast.LENGTH_SHORT).show();
        else {
            startActivity(new Intent(ChatActivity.this, VoiceCallActivity.class)
                    .putExtra("username", toChatUsername).putExtra("isComingCall", false));
            voiceCallBtn.setEnabled(false);
            toggleMore(null);
        }
    } else if (id == R.id.btn_video_call) { // ?
        if (!EMChatManager.getInstance().isConnected())
            Toast.makeText(this, st1, Toast.LENGTH_SHORT).show();
        else {
            startActivity(new Intent(this, VideoCallActivity.class).putExtra("username", toChatUsername)
                    .putExtra("isComingCall", false));
            videoCallBtn.setEnabled(false);
            toggleMore(null);
        }
    }
}

From source file:net.sourceforge.servestream.service.MediaPlaybackService.java

private void reloadQueue() {
    String q = null;//www.j  a va  2s  . co m

    boolean newstyle = false;
    int id = mCardId;
    if (mPreferences.contains("cardid")) {
        newstyle = true;
        id = mPreferences.getInt("cardid", ~mCardId);
    }
    if (id == mCardId) {
        // Only restore the saved playlist if the card is still
        // the same one as when the playlist was saved
        q = mPreferences.getString("queue", "");
    }
    int qlen = q != null ? q.length() : 0;
    if (qlen > 1) {
        //Log.i("@@@@ service", "loaded queue: " + q);
        int plen = 0;
        int n = 0;
        int shift = 0;
        for (int i = 0; i < qlen; i++) {
            char c = q.charAt(i);
            if (c == ';') {
                ensurePlayListCapacity(plen + 1);
                mPlayList[plen] = n;
                plen++;
                n = 0;
                shift = 0;
            } else {
                if (c >= '0' && c <= '9') {
                    n += ((c - '0') << shift);
                } else if (c >= 'a' && c <= 'f') {
                    n += ((10 + c - 'a') << shift);
                } else {
                    // bogus playlist data
                    plen = 0;
                    break;
                }
                shift += 4;
            }
        }
        mPlayListLen = plen;

        int pos = mPreferences.getInt("curpos", 0);
        if (pos < 0 || pos >= mPlayListLen) {
            // The saved playlist is bogus, discard it
            mPlayListLen = 0;
            return;
        }
        mPlayPos = pos;

        // When reloadQueue is called in response to a card-insertion,
        // we might not be able to query the media provider right away.
        // To deal with this, try querying for the current file, and if
        // that fails, wait a while and try again. If that too fails,
        // assume there is a problem and don't restore the state.
        Cursor crsr = MusicUtils.query(this, Media.MediaColumns.CONTENT_URI, new String[] { "_id" },
                "_id=" + mPlayList[mPlayPos], null, null);
        if (crsr == null || crsr.getCount() == 0) {
            // wait a bit and try again
            SystemClock.sleep(3000);
            crsr = getContentResolver().query(Media.MediaColumns.CONTENT_URI, mCursorCols,
                    "_id=" + mPlayList[mPlayPos], null, null);
        }
        if (crsr != null) {
            crsr.close();
        }

        // Make sure we don't auto-skip to the next song, since that
        // also starts playback. What could happen in that case is:
        // - music is paused
        // - go to UMS and delete some files, including the currently playing one
        // - come back from UMS
        // (time passes)
        // - music app is killed for some reason (out of memory)
        // - music service is restarted, service restores state, doesn't find
        //   the "current" file, goes to the next and: playback starts on its
        //   own, potentially at some random inconvenient time.
        mOpenFailedCounter = 20;
        mQuietMode = true;
        //openCurrentAndNext();
        mQuietMode = false;
        /*if (!mPlayer.isInitialized()) {
        // couldn't restore the saved state
        mPlayListLen = 0;
        return;
        }
                
        long seekpos = mPreferences.getLong("seekpos", 0);
        seek(seekpos >= 0 && seekpos < duration() ? seekpos : 0);
        Log.d(LOGTAG, "restored queue, currently at position "
            + position() + "/" + duration()
            + " (requested " + seekpos + ")");*/

        int repmode = mPreferences.getInt("repeatmode", REPEAT_NONE);
        if (repmode != REPEAT_ALL && repmode != REPEAT_CURRENT) {
            repmode = REPEAT_NONE;
        }
        mRepeatMode = repmode;

        int shufmode = mPreferences.getInt("shufflemode", SHUFFLE_NONE);
        if (shufmode != SHUFFLE_ON) {
            shufmode = SHUFFLE_NONE;
        }
        if (shufmode != SHUFFLE_NONE) {
            // in shuffle mode we need to restore the history too
            q = mPreferences.getString("history", "");
            qlen = q != null ? q.length() : 0;
            if (qlen > 1) {
                plen = 0;
                n = 0;
                shift = 0;
                mHistory.clear();
                for (int i = 0; i < qlen; i++) {
                    char c = q.charAt(i);
                    if (c == ';') {
                        if (n >= mPlayListLen) {
                            // bogus history data
                            mHistory.clear();
                            break;
                        }
                        mHistory.add(n);
                        n = 0;
                        shift = 0;
                    } else {
                        if (c >= '0' && c <= '9') {
                            n += ((c - '0') << shift);
                        } else if (c >= 'a' && c <= 'f') {
                            n += ((10 + c - 'a') << shift);
                        } else {
                            // bogus history data
                            mHistory.clear();
                            break;
                        }
                        shift += 4;
                    }
                }
            }
        }
        /*if (shufmode == SHUFFLE_AUTO) {
        if (! makeAutoShuffleList()) {
            shufmode = SHUFFLE_NONE;
        }
        }*/
        mShuffleMode = shufmode;
    }
}

From source file:net.sf.diningout.content.SyncAdapter.java

/**
 * Get the device's cloud ID and upload it to the server.
 *
 * @return null if the cloud ID could not be retrieved or sent to the server successfully
 *//*  w w  w . j  a  va2  s  .  co m*/
private String uploadCloudId(Context context) {
    int retries = 5;
    for (int i = 0; i < retries; i++) {
        try {
            String id = InstanceID.getInstance(context).getToken(PROJECT_ID, INSTANCE_ID_SCOPE);
            Boolean synced = Server.syncCloudId(id);
            if (synced != null) {
                return synced ? id : null;
            }
        } catch (IOException e) {
            Log.e(TAG, "getting GCM token", e);
            exception(e);
        }
        if (i + 1 < retries) {
            SystemClock.sleep((1 << i) * 1000); // wait and retry, getToken can error
            event("gms", "gcm token retry", i + 1);
        } else {
            event("gms", "couldn't get gcm token after retries", retries);
        }
    }
    return null;
}

From source file:com.google.sample.cast.refplayer.Synchronization.java

private void previewing() {
    mVideoView.seekTo(mCurTime);
    mVideoView.start();
    SystemClock.sleep(100);
    mVideoView.pause();
}

From source file:org.mortbay.ijetty.IJetty.java

License:asdf

@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);

    this.requestWindowFeature(Window.FEATURE_NO_TITLE);//?
    this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);//??

    MainApplication.getInstance().setAppHandler(mHandler);

    instance = this;
    mWebView = new HTML5WebView(this);
    mWebView.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_OVERLAY);
    mWebView.setHorizontalScrollBarEnabled(false);//?
    mWebView.setVerticalScrollBarEnabled(false); //?

    mPropertiesUtil = new PropertiesUtils();

    //?/*w ww .  j a  v a  2  s. c  o  m*/
    Intent autoStarIntent = new Intent("com.mortbay.ijetty.IJetty");
    autoStarIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    autoStarIntent.addFlags(32);
    sendBroadcast(autoStarIntent);

    //??
    //DisplayMetrics dm = new DisplayMetrics();
    //getWindowManager().getDefaultDisplay().getMetrics(dm);
    AppConstants.RESOLUTION = getDisplayScreenSize(); //String.valueOf(dm.widthPixels) + "*" + String.valueOf(getDisplayScreenHeight());    //dm.widthPixels,dm.heightPixels

    //??
    File clientProps = new File(IJetty.__JETTY_DIR + "/" + IJetty.__ETC_DIR + "/properties.xml");
    try {
        if (clientProps.exists() && clientProps.length() != 0) {
            //?assets??
            mPropertiesUtil.readPropertiesFileFromXML(
                    IJetty.getInstance().getBaseContext().getAssets().open("properties.xml"));
            //String propVersion = mPropertiesUtil.getVersion();
            Log.w("smallstar-defaultPropVersion", mPropertiesUtil.getVersion());
            int defaultPropVersion = Integer.parseInt(mPropertiesUtil.getVersion());
            mPropertiesUtil.readPropertiesFileFromXML(clientProps.getAbsolutePath());
            Log.w("smallstar-curPropVersion", mPropertiesUtil.getVersion());
            int curPropVersion = Integer.parseInt(mPropertiesUtil.getVersion());
            if (defaultPropVersion > curPropVersion) {
                //????????
                //TODO???
                mPropertiesUtil.readPropertiesFileFromXML(
                        IJetty.getInstance().getBaseContext().getAssets().open("properties.xml"));
                mPropertiesUtil.writePropertiesFileToXML(clientProps.getAbsolutePath());
                //?console.war
                Log.w(TAG, "copy console.warSD??");
                InputStream is = IJetty.getInstance().getBaseContext().getAssets().open("console.war");
                FileOutputStream fos = new FileOutputStream(AppConstants.getMediaSdFolder() + "/console.war");
                byte[] buffer = new byte[1024];
                int count = 0;
                while ((count = is.read(buffer)) > 0) {
                    fos.write(buffer, 0, count);
                }
                fos.close();
                is.close();
            }
            Log.w(TAG, "===========================================================");
            AppConstants.CLIENT_CUR_PLAYURL = mPropertiesUtil.getPlayUrl();
            Log.w(TAG, AppConstants.CLIENT_CUR_PLAYURL);
            Log.w(TAG, "===========================================================");
            //                Toast.makeText(IJetty.getInstance().getApplicationContext(), AppConstants.CLIENT_CUR_PLAYURL,
            //                        Toast.LENGTH_SHORT).show();

            PlayListUtil.playListVersion = mPropertiesUtil.getPlayListVersion();
            ApkUtils.apkPushVersion = mPropertiesUtil.getApkPushVersion();
        }
    } catch (IOException e) {
        // TODO Auto-generated catch block
        Log.w("smallstar------>", "!clientProps.exists() error!!!!!!");
        e.printStackTrace();
    }

    //??:(?)
    startService(new Intent(this, DaemonService.class));

    //js?
    ProxyBridge jsBridge = new ProxyBridge(this);
    mWebView.addJavascriptInterface(jsBridge, "ia");

    mWebView.setHorizontalScrollBarEnabled(false);

    setContentView(R.layout.jetty_controller);

    startButton = (Button) findViewById(R.id.start);
    startButton.setVisibility(View.GONE);//??
    stopButton = (Button) findViewById(R.id.stop);
    stopButton.setVisibility(View.GONE);//??
    configButton = (Button) findViewById(R.id.config);
    configButton.setVisibility(View.GONE);//??
    final Button downloadButton = (Button) findViewById(R.id.download);
    downloadButton.setVisibility(View.GONE);//??

    IntentFilter filter = new IntentFilter();
    filter.addAction(__START_ACTION);
    filter.addAction(__STOP_ACTION);
    filter.addAction(__START_MOVIE_ACTION);
    filter.addCategory("default");

    bcastReceiver = new BroadcastReceiver() {
        public void onReceive(Context context, Intent intent) {
            if (__START_ACTION.equalsIgnoreCase(intent.getAction())) {
                startButton.setEnabled(false);
                configButton.setEnabled(false);
                stopButton.setEnabled(true);
                consolePrint("<br/>Started Jetty at %s", new Date());
                String[] connectors = intent.getExtras().getStringArray("connectors");
                if (null != connectors) {
                    for (int i = 0; i < connectors.length; i++)
                        consolePrint(connectors[i]);
                }

                printNetworkInterfaces();

                if (AndroidInfo.isOnEmulator(IJetty.this))
                    consolePrint("Set up port forwarding to see i-jetty outside of the emulator.");

                //warFile = new File("file:///android_asset/console.war");
                File file = new File(IJetty.__JETTY_DIR + "/" + IJetty.__WEBAPP_DIR + "/"
                        + "console/settings/basicsettings.html");
                if (file.exists()) {
                    if (file.length() > 0) {
                        //Not empty, do something here.
                        //i-jetty???web?
                        setContentView(mWebView.getLayout());
                        //TODO?????
                        int onlineTimeout = 0;
                        do {
                            if (onlineTimeout > 10)
                                break;
                            SystemClock.sleep(1000);
                            onlineTimeout++;
                        } while (!AppConstants.ONLINE_STATUS);

                        if (AppConstants.ONLINE_STATUS)//
                        {
                            mWebView.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
                            //mWebView.getSettings().setCacheMode( WebSettings.LOAD_NO_CACHE);
                            mWebView.clearHistory();
                            mWebView.clearFormData();
                            mWebView.clearCache(true);
                            mWebView.loadUrl(AppConstants.CLIENT_CUR_PLAYURL);
                        } else
                            mWebView.loadUrl("http://localhost:8080/console/settings/basicsettings.html");
                    }
                }
            } else if (__STOP_ACTION.equalsIgnoreCase(intent.getAction())) {
                startButton.setEnabled(true);
                configButton.setEnabled(true);
                stopButton.setEnabled(false);
                consolePrint("<br/> Jetty stopped at %s", new Date());
            } else if (__START_MOVIE_ACTION.equalsIgnoreCase(intent.getAction())) {
                //service?onCreate()?onStartCommand().
                Log.i(TAG, "onReceive() get Broadcast org.mortbay.ijetty.movie.start");
                Intent mIntent = new Intent("createUI");
                mIntent.setClass(context, MediaPlaybackService.class);
                context.startService(mIntent);
            }
        }

    };

    registerReceiver(bcastReceiver, filter);

    // Watch for button clicks.
    startButton.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            if (isUpdateNeeded())
                IJettyToast.showQuickToast(IJetty.this, R.string.loading);
            else {
                //TODO get these values from editable UI elements
                Intent intent = new Intent(IJetty.this, IJettyService.class);
                intent.putExtra(__PORT, __PORT_DEFAULT);
                intent.putExtra(__NIO, __NIO_DEFAULT);
                intent.putExtra(__SSL, __SSL_DEFAULT);
                intent.putExtra(__CONSOLE_PWD, __CONSOLE_PWD_DEFAULT);
                startService(intent);
            }
        }
    });

    stopButton.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            stopService(new Intent(IJetty.this, IJettyService.class));
        }
    });

    configButton.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            IJettyEditor.show(IJetty.this);
        }
    });

    downloadButton.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            IJettyDownloader.show(IJetty.this);
        }
    });

    info = (TextView) findViewById(R.id.info);
    info.setVisibility(View.GONE);
    footer = (TextView) findViewById(R.id.footer);
    footer.setVisibility(View.GONE);
    console = (TextView) findViewById(R.id.console);
    console.setVisibility(View.GONE);
    consoleScroller = (ScrollView) findViewById(R.id.consoleScroller);
    consoleScroller.setVisibility(View.GONE);

    StringBuilder infoBuffer = new StringBuilder();
    try {
        PackageInfo pi = getPackageManager().getPackageInfo(getPackageName(), 0);
        infoBuffer.append(formatJettyInfoLine("i-jetty version %s (%s)", pi.versionName, pi.versionCode));
    } catch (NameNotFoundException e) {
        infoBuffer.append(formatJettyInfoLine("i-jetty version unknown"));
    }
    infoBuffer.append(formatJettyInfoLine("On %s using Android version %s", AndroidInfo.getDeviceModel(),
            AndroidInfo.getOSVersion()));
    info.setText(Html.fromHtml(infoBuffer.toString()));

    StringBuilder footerBuffer = new StringBuilder();
    footerBuffer.append(
            "<b>Project:</b> <a href=\"http://code.google.com/p/i-jetty\">http://code.google.com/p/i-jetty</a> <br/>");
    footerBuffer.append("<b>Server:</b> http://www.eclipse.org/jetty <br/>");
    footerBuffer.append("<b>Support:</b> http://www.intalio.com/jetty/services <br/>");
    footer.setText(Html.fromHtml(footerBuffer.toString()));

    //??WEB?
    Intent intent = new Intent(IJetty.this, IJettyService.class);
    intent.putExtra(__PORT, __PORT_DEFAULT);
    intent.putExtra(__NIO, __NIO_DEFAULT);
    intent.putExtra(__SSL, __SSL_DEFAULT);
    intent.putExtra(__CONSOLE_PWD, __CONSOLE_PWD_DEFAULT);
    startService(intent);
}

From source file:com.siahmsoft.soundroid.sdk7.provider.tracks.TracksStore.java

public void uploadTrack(Bundle bundle, ResultListener<Track> listener) {

    Track track = TracksStore.Track.fromBundle(bundle);

    SystemClock.sleep(1500);

    if (track.getmIdTrack() == 0) {

        MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE, null,
                Charset.forName(HTTP.UTF_8));

        try {/*from   ww  w  . ja v  a2 s  .  co m*/

            if (track.getmTrackPath() != null && !"".equals(track.getmTrackPath())) {
                ContentBody asset_Data = new FileBody(new File(track.getmTrackPath()));
                entity.addPart("track[asset_data]", asset_Data);
            }

            if (track.getmArtworkPath() != null && !"".equals(track.getmArtworkPath())) {
                ContentBody artworkData = new FileBody(new File(track.getmArtworkPath()));
                entity.addPart("track[artwork_data]", artworkData);
            }

            if (track.getmTitle() != null && !"".equals(track.getmTitle())) {
                entity.addPart("track[title]", new StringBody(track.getmTitle()));
            }

            if (track.getmDescription() != null && !"".equals(track.getmDescription())) {
                entity.addPart("track[description]", new StringBody(track.getmDescription()));
            }

            if (track.getmDownloadable() != null && !"".equals(track.getmDownloadable())) {
                entity.addPart("track[downloadable]", new StringBody(track.getmDownloadable()));
            }

            if (track.getmSharing() != null && !"".equals(track.getmSharing())) {
                entity.addPart("track[sharing]", new StringBody(track.getmSharing()));
            }

            if (!"".equals(track.getmBpm())) {
                entity.addPart("track[bpm]", new StringBody(String.valueOf(track.getmBpm())));
            }

            if (track.getmTagList() != null && !"".equals(track.getmTagList())) {
                entity.addPart("track[tag_list]", new StringBody(track.getmTagList()));
            }

            if (track.getmGenre() != null && !"".equals(track.getmGenre())) {
                entity.addPart("track[genre]", new StringBody(track.getmGenre()));
            }

            if (track.getmLicense() != null && !"".equals(track.getmLicense())) {
                entity.addPart("track[license]", new StringBody(track.getmLicense()));
            }

            if (track.getmLabelName() != null && !"".equals(track.getmLabelName())) {
                entity.addPart("track[label_name]", new StringBody(track.getmLabelName()));
            }

            if (track.getmTrackType() != null && !"".equals(track.getmTrackType())) {
                entity.addPart("track[track_type]", new StringBody(track.getmTrackType()));
            }

            HttpPost filePost = new HttpPost("http://api.soundcloud.com/tracks");
            signRequest(filePost);
            filePost.setEntity(entity);

            executeRequestNotSigned(filePost, new ResponseHandler() {
                public void handleResponse(InputStream in) throws IOException {
                    parseSingleResponse(in, new ResponseParserSingle() {
                        @Override
                        public void parseResponse(JSONObject parser) throws JSONException {
                            int i = 0;
                            i++;
                        }
                    });
                }
            });
        } catch (Exception e) {

        }
        /* mBoundUploadService = Soundroid.getUploadService();
        mBoundUploadService.uploadTrack(track);*/
    } else {//Edicin de la cancin

        MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE, null,
                Charset.forName(HTTP.UTF_8));

        try {

            if (track.getmTrackPath() != null && !"".equals(track.getmTrackPath())) {
                ContentBody asset_Data = new FileBody(new File(track.getmTrackPath()));
                entity.addPart("track[asset_data]", asset_Data);
            }

            if (track.getmArtworkPath() != null && !"".equals(track.getmArtworkPath())) {
                ContentBody artworkData = new FileBody(new File(track.getmArtworkPath()));
                entity.addPart("track[artwork_data]", artworkData);
            }

            if (track.getmTitle() != null) {
                entity.addPart("track[title]", new StringBody(track.getmTitle()));
            }

            if (track.getmDescription() != null) {
                entity.addPart("track[description]", new StringBody(track.getmDescription()));
            }

            if (track.getmDownloadable() != null) {
                entity.addPart("track[downloadable]", new StringBody(track.getmDownloadable()));
            }

            if (track.getmSharing() != null) {
                entity.addPart("track[sharing]", new StringBody(track.getmSharing()));
            }

            entity.addPart("track[bpm]", new StringBody(String.valueOf(track.getmBpm())));

            if (track.getmTagList() != null) {
                entity.addPart("track[tag_list]", new StringBody(track.getmTagList()));
            }

            if (track.getmGenre() != null) {
                entity.addPart("track[genre]", new StringBody(track.getmGenre()));
            }

            if (track.getmLicense() != null) {
                entity.addPart("track[license]", new StringBody(track.getmLicense()));
            }

            if (track.getmLabelName() != null) {
                entity.addPart("track[label_name]", new StringBody(track.getmLabelName()));
            }

            if (track.getmTrackType() != null) {
                entity.addPart("track[track_type]", new StringBody(track.getmTrackType()));
            }

            HttpPut filePut = new HttpPut("http://api.soundcloud.com/tracks/" + track.getmIdTrack() + ".json");
            signRequest(filePut);

            filePut.setEntity(entity);

            executeRequestNotSigned(filePut, new ResponseHandler() {
                public void handleResponse(InputStream in) throws IOException {
                    parseSingleResponse(in, new ResponseParserSingle() {
                        @Override
                        public void parseResponse(JSONObject parser) throws JSONException {
                            int i = 0;
                            i++;
                        }
                    });
                }
            });
        } catch (Exception e) {

        }
    }
}