Example usage for android.os Message Message

List of usage examples for android.os Message Message

Introduction

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

Prototype

public Message() 

Source Link

Document

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

Usage

From source file:com.jerrellmardis.amphitheatre.task.DownloadTaskHelper.java

public static void traverseSmbFiles(SmbFile root, NtlmPasswordAuthentication auth)
        throws SmbException, MalformedURLException {
    int fileCount = 0;
    boolean video_folder = false;
    final Video v = new Video();
    Handler h = new Handler(Looper.getMainLooper()) {
        @Override//from  ww w . j  av a  2 s .c o m
        public void handleMessage(Message msg) {
            //                            super.handleMessage(msg);
            Video vid = (Video) msg.getData().getSerializable("VIDEO");
            Log.d(TAG, "Handle " + msg.getData().getInt("WHEN") + " " + vid.getName());
            updateSingleVideo(vid, null);
        }

    };

    for (SmbFile f : root.listFiles()) {
        if (f.getParent().contains("Entertainment Media")) {
            //                Log.d(TAG, "Discovered "+f.getPath()+" "+f.isDirectory());
        }
        if (f.isDirectory()) {
            try {
                //TODO Port VOB folder support to USB and internal storage
                SmbFile[] directoryContents = f.listFiles();
                //                    Log.d(TAG, "Going into directory "+f.getPath());
                //If this works, then we can explore
                //Let's do some quick name checking to for time savings
                if (f.getName().contains("Entertainment Media")) {
                    //                        Log.d(TAG, Arrays.asList(f.listFiles()).toString());
                }
                if (!f.getName().contains("iTunes") && !f.getName().contains("Digi Pix")
                        && !f.getName().contains("AppData") && !f.getName().startsWith(".")
                        && !f.getName().contains("Avid") && !f.getName().contains("Spotify")
                        && !f.getName().contains("audacity_temp") && !f.getName().contains("Media_previews")
                        && !f.getName().contains("GFX_previews")
                        && !f.getName().contains("Samsung Install Files") && !f.getName().contains("AE Renders")
                        && !f.getName().contains("LocalData") && !f.getName().contains("$RECYCLE")
                        && !f.getName().contains("Encore DVD") && !f.getName().contains("16 GB Photo card")
                        && !f.getName().contains("Ignore") && !f.getName().contains("Documents") //TEMP
                        && !f.getName().contains("Downloads") //TEMP
                        && !f.getName().contains("TypeGEMs") //TEMP
                        && !f.getName().contains("KofC7032Web") //TEMP
                        && !f.getName().contains("hype mobile docs") //TEMP
                        && !f.getName().contains("Thrive Music Video") //TEMP
                        /*&& f.getPath().contains("Entertainment") //TEMP*/
                        && !f.getName().contains("Preview Files")) {
                    Log.d(TAG, "Check " + f.getPath());
                    traverseSmbFiles(f, auth);
                } else {
                    //                        Log.d(TAG, "Don't check " + f.getPath());
                }
            } catch (Exception e) {
                //This folder isn't accessible
                Log.d(TAG, "Inaccessible: " + f.getName() + " " + e.getMessage());
                //This will save us time in the traversal
            }
        } else/* if(f.getPath().contains("Films"))*/ { //TEMP
            //Is this something we want to add?
            //                Log.d(TAG, "Non-directory "+f.getPath());
            if (VideoUtils.isVideoFile(f.getPath())) {
                Log.d(TAG, f.getName() + " is a video");
                //Perhaps. Let's do some checking.
                /* VOB check
                If the files are in a structure like:
                { Movie Name } -> VIDEO_TS -> VTS_nn_n.vob
                        
                Then use the movie name as the source, and each vob url will
                be added in a comma-separated list to the video url string
                */

                if (f.getPath().contains("VIDEO_TS")) {
                    Log.d(TAG, "Special case for " + f.getPath());
                    //We have a special case!
                    String grandparentPath = f.getPath().substring(0, f.getPath().indexOf("VIDEO_TS"));
                    SmbFile grandparent = new SmbFile(grandparentPath, auth);

                    //Let's delete this video and all like it from our video database
                    //TODO Makes more sense to not delete and replace a video, just to update in place
                    //                        Log.d(TAG, "Purge where video_url like "+"%" + grandparent.getPath().replace("'", "\'") + "%");
                    List<Video> videos = Select.from(Video.class).where(Condition.prop("video_url")
                            .like("%" + grandparent.getPath().replace("'", "\'") + "%")).list();
                    //                        Log.d(TAG, "Purging "+videos.size()+" item(s)");
                    for (Video vx : videos) {
                        //                            Log.d(TAG, "Deleting "+vx.getVideoUrl());
                        vx.delete();
                    }

                    v.setName(grandparent.getName().replace("/", "").replace("_", " ") + ".avi"); //FIXME VOB currently not supported
                    v.setSource(FileSource.SMB);
                    v.setIsMatched(true); //Kind of a lie, but we know it's a thing!
                    //Get all the video files
                    ArrayList<String> urls = new ArrayList<>();
                    for (SmbFile f2 : grandparent.listFiles()) {
                        for (SmbFile f3 : f2.listFiles()) {
                            if (VideoUtils.isVideoFile(f3.getPath())) {
                                //Presumably in order
                                urls.add(f3.getPath());
                            }
                        }
                    }
                    //                        Log.d(TAG, urls.toString()); //This works well
                    v.setVideoUrl(urls);
                    video_folder = true;
                } else {
                    //Add the video like normal
                    //Let's delete this video and all like it from our video database
                    List<Video> videos = Select.from(Video.class)
                            .where(Condition.prop("video_url").like("%" + f.getPath().replace("'", "''") + "%"))
                            .list();
                    //                        Log.d(TAG, "Purging "+videos.size()+" item(s)");
                    for (Video vx : videos) {
                        //                            Log.d(TAG, "Deleting "+vx.getVideoUrl());
                        vx.delete();
                    }

                    v.setName(f.getName());
                    v.setSource(FileSource.SMB);
                    v.setVideoUrl(f.getPath());

                    fileCount++;
                    //Send a request to update metadata every second, to prevent as many 429 errors and memory exceptions
                    Message m = new Message();
                    Bundle mBundle = new Bundle();
                    mBundle.putSerializable("VIDEO", v.clone());
                    mBundle.putInt("WHEN", (int) (1000 * fileCount + Math.round(Math.random() * 100)));
                    m.setData(mBundle);
                    //                        h.sendEmptyMessageDelayed(1000 * fileCount, 1000 * fileCount);
                    h.sendMessageDelayed(m, 1000 * fileCount);
                    Log.d(TAG, "Queued " + mBundle.getInt("WHEN") + "  -  " + v.getName());
                    v.save(); //Need to save here, otherwise purging won't work as expected
                }

                //                    Log.d(TAG, v.toString());

                //                    return;
            }
            //Ignore otherwise
        }
    }
    //Let's do VOB video
    if (video_folder) {
        //            Log.d(TAG, "Done rooting through "+root.getPath());
        Log.d(TAG, "Created info for VOB " + v.toString());
        fileCount++;
        //Send a request to update metadata every second, to prevent as many 429 errors and memory exceptions
        Message m = new Message();
        Bundle mBundle = new Bundle();
        mBundle.putSerializable("VIDEO", v.clone());
        m.setData(mBundle);
        //                        h.sendEmptyMessageDelayed(1000 * fileCount, 1000 * fileCount);
        h.sendMessageDelayed(m, 1000 * fileCount);
        Log.d(TAG, "Queued " + 1000 * fileCount + "  -  " + v.getName());
        v.save(); //Need to save here, otherwise purging won't work as expected
    }
}

From source file:net.homelinux.penecoptero.android.citybikes.donation.app.MainActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);/*from  w  ww  . j a  v  a2s  . co m*/
    PreferenceManager.setDefaultValues(this, R.xml.preferences, false);
    mapView = (MapView) findViewById(R.id.mapview);
    mSlidingDrawer = (StationSlidingDrawer) findViewById(R.id.drawer);
    infoLayer = (InfoLayer) findViewById(R.id.info_layer);
    scale = getResources().getDisplayMetrics().density;
    //Log.i("CityBikes","ON CREATEEEEEEEEE!!!!!");
    infoLayerPopulator = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            if (msg.what == InfoLayer.POPULATE) {
                infoLayer.inflateStation(stations.getCurrent());

            }
            if (msg.what == CityBikes.BOOKMARK_CHANGE) {
                int id = msg.arg1;
                boolean bookmarked;
                if (msg.arg2 == 0) {
                    bookmarked = false;
                } else {
                    bookmarked = true;
                }
                StationOverlay station = stations.getById(id);
                try {
                    BookmarkManager bm = new BookmarkManager(getApplicationContext());
                    bm.setBookmarked(station.getStation(), !bookmarked);
                } catch (Exception e) {
                    Log.i("CityBikes", "Error bookmarking station");
                    e.printStackTrace();
                }

                if (!view_all) {
                    view_near();
                }
                mapView.postInvalidate();
            }
        }
    };

    infoLayer.setHandler(infoLayerPopulator);
    RelativeLayout.LayoutParams zoomControlsLayoutParams = new RelativeLayout.LayoutParams(
            android.view.ViewGroup.LayoutParams.WRAP_CONTENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT);
    zoomControlsLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
    zoomControlsLayoutParams.addRule(RelativeLayout.CENTER_HORIZONTAL);

    mapView.addView(mapView.getZoomControls(), zoomControlsLayoutParams);

    modeButton = (ToggleButton) findViewById(R.id.mode_button);

    modeButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            changeMode(!getBike);
        }

    });

    applyMapViewLongPressListener(mapView);

    settings = getSharedPreferences(CityBikes.PREFERENCES_NAME, 0);

    List<Overlay> mapOverlays = mapView.getOverlays();

    locator = new Locator(this, new Handler() {
        @Override
        public void handleMessage(Message msg) {
            if (msg.what == Locator.LOCATION_CHANGED) {
                GeoPoint point = new GeoPoint(msg.arg1, msg.arg2);
                hOverlay.moveCenter(point);
                mapView.getController().animateTo(point);
                mDbHelper.setCenter(point);
                // Location has changed
                try {
                    mDbHelper.updateDistances(point);
                    infoLayer.update();
                    if (!view_all) {
                        view_near();
                    }
                } catch (Exception e) {

                }
                ;
            }
        }
    });

    hOverlay = new HomeOverlay(locator.getCurrentGeoPoint(), new Handler() {
        @Override
        public void handleMessage(Message msg) {
            if (msg.what == HomeOverlay.MOTION_CIRCLE_STOP) {
                try {
                    if (!view_all) {
                        view_near();
                    }
                    mapView.postInvalidate();
                } catch (Exception e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        }
    });

    stations = new StationOverlayList(mapOverlays, new Handler() {
        @Override
        public void handleMessage(Message msg) {
            //Log.i("CityBikes","Message: "+Integer.toString(msg.what)+" "+Integer.toString(msg.arg1));
            if (msg.what == StationOverlay.TOUCHED && msg.arg1 != -1) {
                // One station has been touched
                stations.setCurrent(msg.arg1, getBike);
                infoLayer.inflateStation(stations.getCurrent());
                //Log.i("CityBikes","Station touched: "+Integer.toString(msg.arg1));
            }
        }
    });

    stations.addOverlay(hOverlay);

    mNDBAdapter = new NetworksDBAdapter(getApplicationContext());

    mDbHelper = new StationsDBAdapter(this, mapView, new Handler() {
        @Override
        public void handleMessage(Message msg) {
            switch (msg.what) {
            case StationsDBAdapter.FETCH:
                break;
            case StationsDBAdapter.UPDATE_MAP:
                progressDialog.dismiss();
                SharedPreferences.Editor editor = settings.edit();
                editor.putBoolean("reload_network", false);
                editor.commit();
            case StationsDBAdapter.UPDATE_DATABASE:
                StationOverlay current = stations.getCurrent();
                if (current == null) {
                    infoLayer.inflateMessage(getString(R.string.no_bikes_around));
                }
                if (current != null) {
                    current.setSelected(true, getBike);
                    infoLayer.inflateStation(current);
                    if (view_all)
                        view_all();
                    else
                        view_near();
                } else {

                }
                mapView.invalidate();
                infoLayer.update();
                ////Log.i("openBicing", "Database updated");
                break;
            case StationsDBAdapter.NETWORK_ERROR:
                ////Log.i("openBicing", "Network error, last update from " + mDbHelper.getLastUpdated());
                Toast toast = Toast.makeText(getApplicationContext(),
                        getString(R.string.network_error) + " " + mDbHelper.getLastUpdated(),
                        Toast.LENGTH_LONG);
                toast.show();
                break;
            }
        }
    }, stations);

    mDbHelper.setCenter(locator.getCurrentGeoPoint());

    mSlidingDrawer.setHandler(new Handler() {
        @Override
        public void handleMessage(Message msg) {
            switch (msg.what) {
            case StationSlidingDrawer.ITEMCLICKED:
                StationOverlay clicked = (StationOverlay) msg.obj;
                stations.setCurrent(msg.arg1, getBike);
                Message tmp = new Message();
                tmp.what = InfoLayer.POPULATE;
                tmp.arg1 = msg.arg1;
                infoLayerPopulator.dispatchMessage(tmp);
                mapView.getController().animateTo(clicked.getCenter());
            }
        }
    });

    if (savedInstanceState != null) {
        locator.unlockCenter();
        hOverlay.setRadius(savedInstanceState.getInt("homeRadius"));
        this.view_all = savedInstanceState.getBoolean("view_all");
    } else {
        updateHome();
    }

    try {
        mDbHelper.loadStations();
        if (savedInstanceState == null) {
            String strUpdated = mDbHelper.getLastUpdated();

            Boolean dirty = settings.getBoolean("reload_network", false);

            if (strUpdated == null || dirty) {
                this.fillData(view_all);
            } else {
                Toast toast = Toast.makeText(this.getApplicationContext(),
                        "Last Updated: " + mDbHelper.getLastUpdated(), Toast.LENGTH_LONG);
                toast.show();
                Calendar cal = Calendar.getInstance();
                long now = cal.getTime().getTime();
                if (Math.abs(now - mDbHelper.getLastUpdatedTime()) > 60000 * 5)
                    this.fillData(view_all);
            }
        }

    } catch (Exception e) {
        ////Log.i("openBicing", "SHIT ... SUCKS");
    }
    ;

    if (view_all)
        view_all();
    else
        view_near();
    ////Log.i("openBicing", "CREATE!");
}

From source file:com.xpg.gokit.activity.GokitControlActivity.java

@Override
public boolean didReceiveData(XPGWifiDevice device,
        java.util.concurrent.ConcurrentHashMap<String, Object> dataMap, int result) {
    if (dataMap.get("data") != null) {
        Log.i("info", (String) dataMap.get("data"));
        Message msg = new Message();
        msg.obj = dataMap.get("data");
        msg.what = RESP;/*from   w ww  .j av  a2s.c om*/
        handler.sendMessage(msg);
    }

    if (dataMap.get("alters") != null) {
        Log.i("info", (String) dataMap.get("alters"));
        Message msg = new Message();
        msg.obj = dataMap.get("alters");
        msg.what = LOG;
        handler.sendMessage(msg);
    }

    if (dataMap.get("faults") != null) {
        Log.i("info", (String) dataMap.get("faults"));
        Message msg = new Message();
        msg.obj = dataMap.get("faults");
        msg.what = LOG;
        handler.sendMessage(msg);
    }

    if (dataMap.get("binary") != null) {
        Log.i("info", "Binary data:" + bytesToHex((byte[]) dataMap.get("binary")));
    }

    return true;
}

From source file:com.pipi.studio.dev.net.AsyncHttpGet.java

@Override
public void run() {
    String ret = "";
    try {//from w  w  w  .  j a v a  2 s .  c  om
        if (parameter != null && parameter.size() > 0) {
            StringBuilder bulider = new StringBuilder();
            for (RequestParameter p : parameter) {
                if (bulider.length() != 0) {
                    bulider.append("&");
                }

                bulider.append(Utils.encode(p.getName()));
                bulider.append("=");
                bulider.append(Utils.encode(p.getValue()));
            }
            url += "?" + bulider.toString();
        }
        LogUtil.d(AsyncHttpGet.class.getName(), "AsyncHttpGet  request to url :" + url);
        request = new HttpGet(url);
        /*if(Constants.isGzip){
        request.addHeader("Accept-Encoding", "gzip");
          }else{
        request.addHeader("Accept-Encoding", "default");
          }*/
        //  
        httpClient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, connectTimeout);
        // ? 
        httpClient.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT, readTimeout);
        HttpResponse response = httpClient.execute(request);
        int statusCode = response.getStatusLine().getStatusCode();
        if (statusCode == HttpStatus.SC_OK) {
            InputStream is = response.getEntity().getContent();
            BufferedInputStream bis = new BufferedInputStream(is);
            bis.mark(2);
            // ??
            byte[] header = new byte[2];
            int result = bis.read(header);
            // reset??
            bis.reset();
            // ?GZIP?
            int headerData = getShort(header);
            // Gzip ? ? 0x1f8b
            if (result != -1 && headerData == 0x1f8b) {
                LogUtil.d("HttpTask", " use GZIPInputStream  ");
                is = new GZIPInputStream(bis);
            } else {
                LogUtil.d("HttpTask", " not use GZIPInputStream");
                is = bis;
            }
            InputStreamReader reader = new InputStreamReader(is, "utf-8");
            char[] data = new char[100];
            int readSize;
            StringBuffer sb = new StringBuffer();
            while ((readSize = reader.read(data)) > 0) {
                sb.append(data, 0, readSize);
            }
            ret = sb.toString();
            bis.close();
            reader.close();

            //            ByteArrayOutputStream content = new ByteArrayOutputStream();
            //            response.getEntity().writeTo(content);
            //            ret = new String(content.toByteArray()).trim();
            //            content.close();
        } else {
            RequestException exception = new RequestException(RequestException.IO_EXCEPTION,
                    "??,??" + statusCode);
            ret = ErrorUtil.errorJson("ERROR.HTTP.001", exception.getMessage());
        }

        LogUtil.d(AsyncHttpGet.class.getName(), "AsyncHttpGet  request to url :" + url + "  finished !");

    } catch (java.lang.IllegalArgumentException e) {

        RequestException exception = new RequestException(RequestException.IO_EXCEPTION,
                Constants.ERROR_MESSAGE);
        ret = ErrorUtil.errorJson("ERROR.HTTP.002", exception.getMessage());
        LogUtil.d(AsyncHttpGet.class.getName(),
                "AsyncHttpGet  request to url :" + url + "  onFail  " + e.getMessage());
    } catch (org.apache.http.conn.ConnectTimeoutException e) {
        RequestException exception = new RequestException(RequestException.SOCKET_TIMEOUT_EXCEPTION,
                Constants.ERROR_MESSAGE);
        ret = ErrorUtil.errorJson("ERROR.HTTP.003", exception.getMessage());
        LogUtil.d(AsyncHttpGet.class.getName(),
                "AsyncHttpGet  request to url :" + url + "  onFail  " + e.getMessage());
    } catch (java.net.SocketTimeoutException e) {
        RequestException exception = new RequestException(RequestException.SOCKET_TIMEOUT_EXCEPTION,
                Constants.ERROR_MESSAGE);
        ret = ErrorUtil.errorJson("ERROR.HTTP.004", exception.getMessage());
        LogUtil.d(AsyncHttpGet.class.getName(),
                "AsyncHttpGet  request to url :" + url + "  onFail  " + e.getMessage());
    } catch (UnsupportedEncodingException e) {
        RequestException exception = new RequestException(RequestException.UNSUPPORTED_ENCODEING_EXCEPTION,
                "?");
        ret = ErrorUtil.errorJson("ERROR.HTTP.005", exception.getMessage());
        LogUtil.d(AsyncHttpGet.class.getName(),
                "AsyncHttpGet  request to url :" + url + "  UnsupportedEncodingException  " + e.getMessage());
    } catch (org.apache.http.conn.HttpHostConnectException e) {
        RequestException exception = new RequestException(RequestException.CONNECT_EXCEPTION,
                Constants.ERROR_MESSAGE);
        ret = ErrorUtil.errorJson("ERROR.HTTP.006", exception.getMessage());
        LogUtil.d(AsyncHttpGet.class.getName(),
                "AsyncHttpGet  request to url :" + url + "  HttpHostConnectException  " + e.getMessage());
    } catch (ClientProtocolException e) {
        RequestException exception = new RequestException(RequestException.CLIENT_PROTOL_EXCEPTION,
                "??");
        ret = ErrorUtil.errorJson("ERROR.HTTP.007", exception.getMessage());
        e.printStackTrace();
        LogUtil.d(AsyncHttpGet.class.getName(),
                "AsyncHttpGet  request to url :" + url + "  ClientProtocolException " + e.getMessage());
    } catch (IOException e) {
        RequestException exception = new RequestException(RequestException.IO_EXCEPTION, "??");
        ret = ErrorUtil.errorJson("ERROR.HTTP.008", exception.getMessage());
        e.printStackTrace();
        LogUtil.d(AsyncHttpGet.class.getName(),
                "AsyncHttpGet  request to url :" + url + "  IOException  " + e.getMessage());
    } finally {
        if (!Constants.IS_STOP_REQUEST) {
            Message msg = new Message();
            msg.obj = ret;
            LogUtil.d("result", ret);
            msg.getData().putSerializable("callback", callBack);
            resultHandler.sendMessage(msg);
        }
        //request.//
        if (customLoadingDialog != null && customLoadingDialog.isShowing()) {
            customLoadingDialog.dismiss();
            customLoadingDialog = null;
        }
    }
    super.run();
}

From source file:com.example.main.ViewPagerActivity.java

private void getTalkDataArrays(String decode) {
    // TODO Auto-generated method stub
    try {//  w  w  w  . ja v a  2 s.  c o  m
        JSONArray jsonArray = new JSONArray(decode);
        if (jsonArray.length() == 0) {
            return;
        } else {
            for (int i = 0; i < jsonArray.length(); i++) {
                JSONObject jsonObject = jsonArray.getJSONObject(i);

                TalkEntity entity = new TalkEntity(Boolean.valueOf(jsonObject.optString("isMsg")),
                        Boolean.valueOf(jsonObject.optString("isSend"))

                        , Html.fromHtml(jsonObject.optString("detail")).toString(),
                        jsonObject.optString("PostTime"), jsonObject.optString("ark_id"),
                        jsonObject.optString("send_user_id"), jsonObject.optString("msg_id"));

                entity.setState(Integer.valueOf(jsonObject.optString("state")));

                LogHelper.trace(jsonObject.optString("detail"));
                LogHelper.trace(Html.fromHtml(jsonObject.optString("detail")).toString());

                if (jsonObject.optString("isMsg").equals("false")) {
                    String pic = jsonObject.optString("detail");
                    GlobalID globalID = ((GlobalID) getApplication());
                    Bitmap bit = FuntionUtil
                            .downloadPic("http://" + globalID.getDBurl() + "/user/images" + pic);
                    if (bit != null) {
                        entity.setImage_picture(bit);
                    } else {
                        Bitmap default_Img = BitmapFactory.decodeResource(getResources(),
                                R.drawable.ic_launcher);
                        entity.setImage_picture(default_Img);
                    }
                }

                //               TalkDataArrays.add(entity);
                Message msg = new Message();
                msg.what = 1;
                msg.obj = entity;
                add_handler.sendMessage(msg);
            }
        }
    } catch (JSONException e) {
        e.printStackTrace();
        return;
    }
}

From source file:com.firesoft.member.Activity.C1_PublishOrderActivity.java

@Override
public void OnMessageResponse(String url, JSONObject jo, AjaxStatus status) throws JSONException {
    // TODO Auto-generated method stub
    if (url.endsWith(ApiInterface.MEMBER_ADD)) {
        memberaddResponse response = new memberaddResponse();
        response.fromJson(jo);/*from w  w w .ja  va2 s .  co m*/
        if (response.succeed == 1) {
            /*Intent intent = new Intent(this, MainActivity.class);
            startActivity(intent);*/
            ToastShow("??");
            finish();
            Message msg = new Message();
            msg.what = MessageConstant.REFRESH_LIST;
            EventBus.getDefault().post(msg);
        } else {
            if (response.error_code == APIErrorCode.NICKNAME_EXIST) {
                member_no.requestFocus();
            }
        }
    }

}

From source file:com.ubiLive.GameCloud.Browser.WebBrowser.java

/**
 * web Javascript call client/*from   w w  w.j a  v  a2  s. c o  m*/
 * @param functionName
 * @param jsonData
 * @return
 */
public void ubiGCPlayerInvoke(String functionName, String jsonData) {
    DebugLog.v(TAG,
            "ubiGCPlayerInvoke() functionName = " + functionName + ",jsonData = " + jsonData + "---------");
    DebugLog.v(TAG, "ubiGCPlayerInvoke() useUbGcWeb = " + mPlayer.useUbGcWeb());
    DebugLog.v(TAG, "ubiGCPlayerInvoke() checkUbiGCPlayerInvokeFunForJava(functionName) = "
            + checkUbiGCPlayerInvokeFunForJava(functionName));

    final boolean isShowdialog = !"disableToolbar".equalsIgnoreCase(functionName)
            && !"getClientCapability".equalsIgnoreCase(functionName);
    ((LoadWebJsActivity) mWebviewActivity).setWebProgressBarVisibility(isShowdialog ? View.VISIBLE : View.GONE);

    if (Constants.sEnable_networkType_workflow) {
        if (functionName.equals("checkAvailableNetwork")) {
            DebugLog.d(TAG, "getNetworkType = " + Utils.getNetworkType());
            Utils.readStoredLteCfgStatus(mContext);
            if (Constants.sIsEnableNetworkLte) {
                GameActivity.m_player.setAllowLteFlag(1);
            } else {
                GameActivity.m_player.setAllowLteFlag(0);
            }

            WebBrowser.sGameExitStatus = 0;

            if (Constants.NETWORKTYPE_3G == Utils.getNetworkType()) {
                DebugLog.d(TAG, "====prohibit 3G network type====");
                //Only allow LTE/WIFI to play game
                Message msg = new Message();
                msg.what = HANDLE_PROHIBIT_CHECKAVAILABLENETWORK;
                msg.obj = jsonData;
                if (mHandler != null)
                    mHandler.sendMessage(msg);
                return;
            }

            if (Constants.NETWORKTYPE_LTE == Utils.getNetworkType()) {
                readStoredAcceptUseLteCfgStatus();
                if (!Constants.sIsEnableNetworkLte || !Constants.sIsAcceptLteUsage) {
                    Message msg = new Message();
                    msg.what = HANDLE_CHECKAVAILABLENETWORK_LTE;
                    msg.obj = jsonData;
                    if (mHandler != null)
                        mHandler.sendMessage(msg);
                    return;
                }
            }

            /*For temp test.
             *  if (Constants.NETWORKTYPE_WIFI == Utils.getNetworkType()) {
            Message msg = new Message();
            msg.what = 1111;
            msg.obj = jsonData;
            if (mHandler != null)
                mHandler.sendMessage(msg);
            return;
                    
             }*/

        } else if (functionName.equals("play")
                && Constants.GAMEACTIVITY_ALERT_DIALOG_TYPE_NOT_LTEWIFI == WebBrowser.sGameExitStatus) {
            notifyProhibitPlay(jsonData);
            WebBrowser.sGameExitStatus = 0;
            return;
        }
    }

    if (("playOnCast".equalsIgnoreCase(functionName)) && (isCastSet(jsonData) == true)) {

        chromecast.setChromecastWebMode(true);
        selectChromecastDevice();

    }

    if (("enableToolbar".equalsIgnoreCase(functionName))) {

        chromecast.setLoginStatus(true);
    }

    if (("disableToolbar".equalsIgnoreCase(functionName))) {

        chromecast.setLoginStatus(false);
    }

    if ("checkAvailableNetwork".equalsIgnoreCase(functionName)) {
        DebugLog.d(TAG, "ubiGCPlayerInvoke checkAvailableNetwork StartGameActivity");
        Utils.startGameActivity(mContext, mWebviewActivity, null, null, null);
    }

    Class<?> clazz = checkUbiGCPlayerInvokeFunForJava(functionName);
    if (0 == mPlayer.useUbGcWeb() || clazz != null) {
        DebugLog.i(TAG, "ubiGCPlayerInvoke used JAVA Layer json functionName = " + functionName);
        try {
            Method method = null;
            String result = null;
            if (jsonData == null || jsonData.length() == 0 || jsonData.equals("")) {
                method = clazz.getDeclaredMethod(functionName);
                result = (String) method.invoke(this);
            } else {
                method = clazz.getDeclaredMethod(functionName, String.class);
                result = (String) method.invoke(this, jsonData);
            }
        } catch (Exception e) {
            DebugLog.d(TAG, "exception = " + e.getMessage());
        }
    } else if (1 == mPlayer.useUbGcWeb()) {

        mPlayer.ubiGCPlayerInvoke(functionName, jsonData);
    }
}

From source file:com.cettco.buycar.dealer.activity.OrderDetailActivity.java

protected void getData() {
    // String url = GlobalData.getBaseUrl() + "/cars/list.json";
    // httpCache.clear();
    String url = GlobalData.getBaseUrl() + "/tenders/" + bargain_id + "/show_bargain.json";
    System.out.println("url:" + url);
    Gson gson = new Gson();
    StringEntity entity = null;/*from  ww  w . ja  v a  2s  .  c  om*/
    String cookieStr = null;
    String cookieName = null;
    PersistentCookieStore myCookieStore = new PersistentCookieStore(this);
    if (myCookieStore == null) {
        System.out.println("cookie store null");
        return;
    }
    List<Cookie> cookies = myCookieStore.getCookies();
    for (Cookie cookie : cookies) {
        String name = cookie.getName();
        cookieName = name;
        System.out.println(name);
        if (name.equals("_JustBidIt_session")) {
            cookieStr = cookie.getValue();
            System.out.println("value:" + cookieStr);
            break;
        }
    }
    if (cookieStr == null || cookieStr.equals("")) {
        System.out.println("cookie null");
        return;
    }
    loadingLayout.setVisibility(View.VISIBLE);
    HttpConnection.getClient().addHeader("Cookie", cookieName + "=" + cookieStr);
    // HttpConnection.setCookie(getApplicationContext());
    progressBar.setProgress(40);
    HttpConnection.get(url, new AsyncHttpResponseHandler() {

        @Override
        public void onFailure(int arg0, Header[] arg1, byte[] arg2, Throwable arg3) {
            // TODO Auto-generated method stub
            loadingLayout.setVisibility(View.GONE);
            loadingFailureLayout.setVisibility(View.VISIBLE);
            progressBar.setProgress(60);
            progressBar.setProgress(100);
            progressBar.setVisibility(View.GONE);
            System.out.println("fail");
            Message message = new Message();
            message.what = 2;
            mHandler.sendMessage(message);
        }

        @Override
        public void onSuccess(int arg0, Header[] arg1, byte[] arg2) {
            // TODO Auto-generated method stub
            loadingLayout.setVisibility(View.GONE);
            progressBar.setProgress(60);
            progressBar.setProgress(100);
            progressBar.setVisibility(View.GONE);
            try {
                String result = new String(arg2, "UTF-8");
                System.out.println("result2:" + result);
                // Type listType = new
                // TypeToken<ArrayList<OrderItemEntity>>() {
                // }.getType();
                // list = new Gson().fromJson(result, listType);
                // //System.out.println("size:"+dealerList.size());
                detailEntity = new Gson().fromJson(result, OrderDetailEntity.class);
                Message message = new Message();
                message.what = 1;
                mHandler.sendMessage(message);
            } catch (UnsupportedEncodingException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

    });
}

From source file:net.homelinux.penecoptero.android.citybikes.app.MainActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);/*from  w ww  .j av  a 2  s.  c  o  m*/
    PreferenceManager.setDefaultValues(this, R.xml.preferences, false);
    mapView = (MapView) findViewById(R.id.mapview);
    mSlidingDrawer = (StationSlidingDrawer) findViewById(R.id.drawer);
    infoLayer = (InfoLayer) findViewById(R.id.info_layer);
    scale = getResources().getDisplayMetrics().density;
    //Log.i("CityBikes","ON CREATEEEEEEEEE!!!!!");
    infoLayerPopulator = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            if (msg.what == InfoLayer.POPULATE) {
                infoLayer.inflateStation(stations.getCurrent());

            }
            if (msg.what == CityBikes.BOOKMARK_CHANGE) {
                int id = msg.arg1;
                boolean bookmarked;
                if (msg.arg2 == 0) {
                    bookmarked = false;
                } else {
                    bookmarked = true;
                }
                StationOverlay station = stations.getById(id);
                try {
                    BookmarkManager bm = new BookmarkManager(getApplicationContext());
                    bm.setBookmarked(station.getStation(), !bookmarked);
                } catch (Exception e) {
                    Log.i("CityBikes", "Error bookmarking station");
                    e.printStackTrace();
                }

                if (!view_all) {
                    view_near();
                }
                mapView.postInvalidate();
            }
        }
    };

    infoLayer.setHandler(infoLayerPopulator);
    RelativeLayout.LayoutParams zoomControlsLayoutParams = new RelativeLayout.LayoutParams(
            android.view.ViewGroup.LayoutParams.WRAP_CONTENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT);
    zoomControlsLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
    zoomControlsLayoutParams.addRule(RelativeLayout.CENTER_HORIZONTAL);

    mapView.addView(mapView.getZoomControls(), zoomControlsLayoutParams);

    modeButton = (ToggleButton) findViewById(R.id.mode_button);

    modeButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            changeMode(!getBike);
        }

    });

    applyMapViewLongPressListener(mapView);

    settings = getSharedPreferences(CityBikes.PREFERENCES_NAME, 0);

    List<Overlay> mapOverlays = mapView.getOverlays();

    locator = new Locator(this, new Handler() {
        @Override
        public void handleMessage(Message msg) {
            if (msg.what == Locator.LOCATION_CHANGED) {
                GeoPoint point = new GeoPoint(msg.arg1, msg.arg2);
                hOverlay.moveCenter(point);
                mapView.getController().animateTo(point);
                mDbHelper.setCenter(point);
                // Location has changed
                try {
                    mDbHelper.updateDistances(point);
                    infoLayer.update();
                    if (!view_all) {
                        view_near();
                    }
                } catch (Exception e) {

                }
                ;
            }
        }
    });

    hOverlay = new HomeOverlay(locator.getCurrentGeoPoint(), new Handler() {
        @Override
        public void handleMessage(Message msg) {
            if (msg.what == HomeOverlay.MOTION_CIRCLE_STOP) {
                try {
                    if (!view_all) {
                        view_near();
                    }
                    mapView.postInvalidate();
                } catch (Exception e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        }
    });

    stations = new StationOverlayList(mapOverlays, new Handler() {
        @Override
        public void handleMessage(Message msg) {
            //Log.i("CityBikes","Message: "+Integer.toString(msg.what)+" "+Integer.toString(msg.arg1));
            if (msg.what == StationOverlay.TOUCHED && msg.arg1 != -1) {
                // One station has been touched
                stations.setCurrent(msg.arg1, getBike);
                infoLayer.inflateStation(stations.getCurrent());
                //Log.i("CityBikes","Station touched: "+Integer.toString(msg.arg1));
            }
        }
    });

    stations.addOverlay(hOverlay);

    mNDBAdapter = new NetworksDBAdapter(getApplicationContext());

    mDbHelper = new StationsDBAdapter(this, mapView, new Handler() {
        @Override
        public void handleMessage(Message msg) {
            switch (msg.what) {
            case StationsDBAdapter.FETCH:
                break;
            case StationsDBAdapter.UPDATE_MAP:
                progressDialog.dismiss();
                SharedPreferences.Editor editor = settings.edit();
                editor.putBoolean("reload_network", false);
                editor.commit();
            case StationsDBAdapter.UPDATE_DATABASE:
                StationOverlay current = stations.getCurrent();
                if (current == null) {
                    infoLayer.inflateMessage(getString(R.string.no_bikes_around));
                }
                if (current != null) {
                    infoLayer.inflateStation(current);
                    if (view_all)
                        view_all();
                    else
                        view_near();
                } else {

                }
                mapView.invalidate();
                infoLayer.update();
                ////Log.i("openBicing", "Database updated");
                break;
            case StationsDBAdapter.NETWORK_ERROR:
                ////Log.i("openBicing", "Network error, last update from " + mDbHelper.getLastUpdated());
                Toast toast = Toast.makeText(getApplicationContext(),
                        getString(R.string.network_error) + " " + mDbHelper.getLastUpdated(),
                        Toast.LENGTH_LONG);
                toast.show();
                break;
            }
        }
    }, stations);

    mDbHelper.setCenter(locator.getCurrentGeoPoint());

    mSlidingDrawer.setHandler(new Handler() {
        @Override
        public void handleMessage(Message msg) {
            switch (msg.what) {
            case StationSlidingDrawer.ITEMCLICKED:
                StationOverlay clicked = (StationOverlay) msg.obj;
                stations.setCurrent(msg.arg1, getBike);
                Message tmp = new Message();
                tmp.what = InfoLayer.POPULATE;
                tmp.arg1 = msg.arg1;
                infoLayerPopulator.dispatchMessage(tmp);
                mapView.getController().animateTo(clicked.getCenter());
            }
        }
    });

    if (savedInstanceState != null) {
        locator.unlockCenter();
        hOverlay.setRadius(savedInstanceState.getInt("homeRadius"));
        this.view_all = savedInstanceState.getBoolean("view_all");
    } else {
        updateHome();
    }

    try {
        mDbHelper.loadStations();
        if (savedInstanceState == null) {
            String strUpdated = mDbHelper.getLastUpdated();

            Boolean dirty = settings.getBoolean("reload_network", false);

            if (strUpdated == null || dirty) {
                this.fillData(view_all);
            } else {
                Toast toast = Toast.makeText(this.getApplicationContext(),
                        "Last Updated: " + mDbHelper.getLastUpdated(), Toast.LENGTH_LONG);
                toast.show();
                Calendar cal = Calendar.getInstance();
                long now = cal.getTime().getTime();
                if (Math.abs(now - mDbHelper.getLastUpdatedTime()) > 60000 * 5)
                    this.fillData(view_all);
            }
        }

    } catch (Exception e) {
        ////Log.i("openBicing", "SHIT ... SUCKS");
    }
    ;

    if (view_all)
        view_all();
    else
        view_near();
    ////Log.i("openBicing", "CREATE!");
}

From source file:net.evecom.androidecssp.activity.WelcomeActivity.java

/**
 * //from   w  w w .j a v  a2s .c om
 */
private void loginsubmit(final String username, final String password) {
    if (islogining) {
        return;
    }

    /**  */
    final Editor editor = passnameSp.edit();
    editor.putString("username", username);
    editor.putString("password", password);
    editor.commit();

    //
    loginProgressDialog = ProgressDialog.show(this, "", "...");
    loginProgressDialog.setCancelable(true);

    //
    new Thread(new Runnable() {
        @Override
        public void run() {
            Log.v("mars", EncryptUtil.getInstance().AESencode(password.trim()));
            try {
                //  
                Message loginMessage = new Message();
                HashMap<String, String> hashMap = new HashMap<String, String>();
                hashMap.put("pwd", password.trim());
                loginResult = connServerForResultPost("jfs/ecssp/mobile/accessCtr/login", hashMap);

                // 
                if (loginResult.length() > 0) {
                    try {
                        BaseModel resultObj = getObjInfo(loginResult);
                        Boolean success = resultObj.get("sys_success");
                        if (null != success && success) {
                            loginMessage.what = MESSAGETYPE_01;// 
                            BaseModel organization = getObjInfo(resultObj.get("organization").toString());
                            BaseModel userdata = getObjInfo(resultObj.get("userdata").toString());
                            BaseModel userInfo = getObjInfo(resultObj.get("userInfo").toString());
                            String code = resultObj.get("code").toString();
                            //--
                            String username = userNmaeEditText.getText().toString();
                            editor.putString("username", userdata.getStr("loginname"));
                            editor.putString("userid", userdata.getStr("id"));
                            editor.putString("usernameCN", userInfo.getStr("name"));
                            editor.putString("sex", userInfo.get("sex") + "");
                            editor.putString("mobile_In_clound", userInfo.get("mobile") + "");
                            editor.putString("orgid", organization.getStr("id"));
                            editor.putString("orgname", organization.getStr("name"));
                            editor.putString("code", code);
                            editor.commit();
                        } else {
                            loginMessage.what = MESSAGETYPE_02;// 
                        }
                    } catch (JSONException e) {
                        loginMessage.what = MESSAGETYPE_02;// 
                    }
                } else {
                    loginMessage.what = MESSAGETYPE_03;//  
                }
                loginRequestHandler.sendMessage(loginMessage);

            } catch (ClientProtocolException e) {
            } catch (IOException e) {
            }
        }
    }).start();
}