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.nextgis.mobile.map.LocalGeoJsonLayer.java

protected static void create(final MapBase map, String layerName, List<Feature> features, int layerType)
        throws JSONException, IOException {

    GeoEnvelope extents = new GeoEnvelope();
    for (Feature feature : features) {
        //update bbox
        extents.merge(feature.getGeometry().getEnvelope());
    }/*from  w  ww  .  j a v a  2 s . c o m*/

    Feature feature = features.get(0);
    int geometryType = feature.getGeometry().getType();
    List<Field> fields = feature.getFields();

    //create layer description file
    JSONObject oJSONRoot = new JSONObject();
    oJSONRoot.put(JSON_NAME_KEY, layerName);
    oJSONRoot.put(JSON_VISIBILITY_KEY, true);
    oJSONRoot.put(JSON_TYPE_KEY, layerType);
    oJSONRoot.put(JSON_MAXLEVEL_KEY, 50);
    oJSONRoot.put(JSON_MINLEVEL_KEY, 0);

    //add geometry type
    oJSONRoot.put(JSON_GEOMETRY_TYPE_KEY, geometryType);

    //add bbox
    JSONObject oJSONBBox = extents.toJSON();
    oJSONRoot.put(JSON_BBOX_KEY, oJSONBBox);

    //add fields description
    JSONArray oJSONFields = new JSONArray();
    for (Field field : fields) {
        oJSONFields.put(field.toJSON());
    }
    oJSONRoot.put(JSON_FIELDS_KEY, oJSONFields);

    // store layer description to file
    File outputPath = map.cretateLayerStorage();
    File file = new File(outputPath, LAYER_CONFIG);
    FileUtil.createDir(outputPath);
    FileUtil.writeToFile(file, oJSONRoot.toString());

    //store GeoJson to file
    store(features, outputPath);

    if (map.getMapEventsHandler() != null) {
        Bundle bundle = new Bundle();
        bundle.putBoolean(BUNDLE_HASERROR_KEY, false);
        bundle.putString(BUNDLE_MSG_KEY, map.getContext().getString(R.string.message_layer_added));
        bundle.putInt(BUNDLE_TYPE_KEY, MSGTYPE_LAYER_ADDED);
        bundle.putSerializable(BUNDLE_PATH_KEY, outputPath);

        Message msg = new Message();
        msg.setData(bundle);
        map.getMapEventsHandler().sendMessage(msg);
    }
}

From source file:net.evecom.androidecssp.gps.ResourceItemizedOverlayActivity.java

/**
 * //from  ww  w .j a  va  2s .  c  o m
 *  
 * 
 * @author Mars zhang
 * @created 2015-12-8 2:48:19
 */
private void initAroundDialog() {
    View dialogView = LayoutInflater.from(ResourceItemizedOverlayActivity.this)
            .inflate(R.layout.base_wheel_view, null);
    dialogNameEd = (EditText) dialogView.findViewById(R.id.base_wheel_view_name_ed);

    WheelView wheelView = (WheelView) dialogView.findViewById(R.id.country);
    wheelView.setVisibleItems(1);
    wheelView.setViewAdapter(new CountryAdapter(ResourceItemizedOverlayActivity.this, aroundNum));
    wheelView.addScrollingListener(new OnWheelScrollListener() {
        public void onScrollingStarted(WheelView wheel) {

        }

        public void onScrollingFinished(WheelView wheel) {
            aroundChouseValue = aroundNum[tempindex];
        }
    });
    wheelView.addChangingListener(new OnWheelChangedListener() {
        public void onChanged(WheelView wheel, int oldValue, int newValue) {
            tempindex = newValue;
        }
    });
    wheelView.setCurrentItem(0);
    aroundChouseValue = aroundNum[1];
    tempindex = 0;

    // 
    resourceType = resourceTypehashmap.keySet().toArray(new String[resourceTypehashmap.size()]);
    WheelView resourceWheelView = (WheelView) dialogView.findViewById(R.id.country_resource_type);
    resourceWheelView.setVisibleItems(1);
    resourceWheelView.setViewAdapter(new CountryAdapter(ResourceItemizedOverlayActivity.this, resourceType));
    resourceWheelView.addScrollingListener(new OnWheelScrollListener() {
        public void onScrollingStarted(WheelView wheel) {

        }

        public void onScrollingFinished(WheelView wheel) {
            resourceTypeChouseValue = resourceType[resourceTypetempindex];
        }
    });
    resourceWheelView.addChangingListener(new OnWheelChangedListener() {
        public void onChanged(WheelView wheel, int oldValue, int newValue) {
            resourceTypetempindex = newValue;
        }
    });
    if (resourceType.length > 1) {
        resourceWheelView.setCurrentItem(0);
        resourceTypeChouseValue = resourceType[1];
        resourceTypetempindex = 0;
    }

    delDia = new AlertDialog.Builder(ResourceItemizedOverlayActivity.this)
            .setIcon(R.drawable.qq_dialog_default_icon).setTitle("").setView(dialogView)
            .setPositiveButton("", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dia, int which) {
                    final Message message = new Message();
                    new Thread(new Runnable() {
                        @Override
                        public void run() {
                            if (null == centerGpsPoint) {
                                return;
                            }
                            HashMap<String, String> mEntityMap = new HashMap<String, String>();
                            int maround = Integer.parseInt(aroundChouseValue);
                            double longdiffer = GpsUtil.getLongDifferFromMeters(mMapView, maround,
                                    ResourceItemizedOverlayActivity.this, centerGpsPoint);
                            double latdiffer = GpsUtil.getLatDifferFromMeters(mMapView, maround,
                                    ResourceItemizedOverlayActivity.this, centerGpsPoint);

                            mEntityMap.put("longdiffer", longdiffer + "");
                            mEntityMap.put("latdiffer", latdiffer + "");
                            mEntityMap.put("centergisy", centerGpsPoint.getLatitudeE6() / 1E6 + "");
                            mEntityMap.put("centergisx", centerGpsPoint.getLongitudeE6() / 1E6 + "");
                            mEntityMap.put("pagesize", HttpUtil.getPageSize(instance));
                            mEntityMap.put("resourcename",
                                    ifnull(dialogNameEd.getText().toString().trim(), ""));
                            mEntityMap.put("resourcetype",
                                    ifnull(resourceTypehashmap.get(resourceTypeChouseValue), ""));
                            try {
                                String mResult = connServerForResultPost(
                                        "jfs/ecssp/mobile/eventCtr/searchResourceAround", mEntityMap);
                                resourceModels = getObjsInfo(mResult);
                                message.what = MESSAGETYPE_01;
                            } catch (ClientProtocolException e) {
                                message.what = MESSAGETYPE_02;
                            } catch (IOException e) {
                                message.what = MESSAGETYPE_02;
                            } catch (JSONException e) {
                                message.what = MESSAGETYPE_02;
                            }
                            pubhandler.sendMessage(message);

                        }
                    }).start();
                    dia.dismiss();
                }
            }).setNegativeButton("", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dia, int which) {
                    dia.dismiss();
                }
            }).create();
}

From source file:dk.kk.ibikecphlib.util.HttpUtils.java

public static Message JSONtoUserDataMessage(JsonNode result, UserData userData) {
    Message ret = new Message();
    Bundle data = new Bundle();
    if (result != null) {
        data.putBoolean("success", result.get("success").asBoolean());
        data.putString("info", result.get("info").asText());
        if (result.has("invalid_token")) {
            if (result.get("invalid_token").asBoolean()) {
                data.putBoolean("invalid_token", result.get("invalid_token").asBoolean());
                IBikeApplication.logoutWrongToken();
            }//from   w w  w  . j a  v  a 2s.co  m
        }
        if (result != null && result.has("data")) {
            JsonNode dataNode = result.get("data");
            if (dataNode != null) {
                data.putInt("id", dataNode.get("id").asInt());
                data.putString("name", dataNode.get("name").asText());
                data.putString("email", dataNode.get("email").asText());
                if (dataNode.has("image_url"))
                    data.putString("image_url", dataNode.get("image_url").asText());
            }
        }
        ret.setData(data);
    }
    return ret;
}

From source file:org.iotivity.base.examples.fridgeclient.FridgeClient.java

@Override
public void logMessage(final String text) {
    if (StringConstants.ENABLE_PRINTING) {
        runOnUiThread(new Runnable() {
            public void run() {
                final Message msg = new Message();
                msg.obj = text;/*from  w w  w  .  ja  va 2 s .  c  o  m*/
                mEventsTextView.append("\n");
                mEventsTextView.append(text);
            }
        });
        Log.i(TAG, text);
    }
}

From source file:cm.aptoide.pt.DownloadQueueService.java

private void downloadFile(final int apkidHash) {

    try {//from   ww w .j  a  va  2s.  c o  m

        new Thread() {
            public void run() {
                this.setPriority(Thread.MAX_PRIORITY);

                if (!keepScreenOn.isHeld()) {
                    keepScreenOn.acquire();
                }
                int threadApkidHash = apkidHash;

                String remotePath = notifications.get(threadApkidHash).get("remotePath");
                String md5hash = notifications.get(threadApkidHash).get("md5hash");

                String localPath = notifications.get(threadApkidHash).get("localPath");
                Log.d("Aptoide-DownloadQueuService",
                        "thread apkidHash: " + threadApkidHash + " localPath: " + localPath);

                Message downloadArguments = new Message();
                try {

                    // If file exists, removes it...
                    File f_chk = new File(localPath);
                    if (f_chk.exists()) {
                        f_chk.delete();
                    }
                    f_chk = null;

                    FileOutputStream saveit = new FileOutputStream(localPath);
                    DefaultHttpClient mHttpClient = new DefaultHttpClient();
                    HttpGet mHttpGet = new HttpGet(remotePath);

                    if (Boolean.parseBoolean(notifications.get(threadApkidHash).get("loginRequired"))) {
                        URL mUrl = new URL(remotePath);
                        mHttpClient.getCredentialsProvider().setCredentials(
                                new AuthScope(mUrl.getHost(), mUrl.getPort()),
                                new UsernamePasswordCredentials(
                                        notifications.get(threadApkidHash).get("username"),
                                        notifications.get(threadApkidHash).get("password")));

                    }

                    HttpResponse mHttpResponse = mHttpClient.execute(mHttpGet);

                    if (mHttpResponse == null) {
                        Log.d("Aptoide", "Problem in network... retry...");
                        mHttpResponse = mHttpClient.execute(mHttpGet);
                        if (mHttpResponse == null) {
                            Log.d("Aptoide", "Major network exception... Exiting!");
                            /*msg_al.arg1= 1;
                            download_error_handler.sendMessage(msg_al);*/
                            throw new TimeoutException();
                        }
                    }

                    if (mHttpResponse.getStatusLine().getStatusCode() == 401) {
                        throw new TimeoutException();
                    } else {
                        InputStream getit = mHttpResponse.getEntity().getContent();
                        byte data[] = new byte[8096];
                        int red;
                        red = getit.read(data, 0, 8096);

                        int progressNotificationUpdate = 200;
                        int intermediateProgress = 0;
                        while (red != -1) {
                            if (progressNotificationUpdate == 0) {
                                if (!keepScreenOn.isHeld()) {
                                    keepScreenOn.acquire();
                                }
                                progressNotificationUpdate = 200;
                                Message progressArguments = new Message();
                                progressArguments.arg1 = threadApkidHash;
                                progressArguments.arg2 = intermediateProgress;
                                downloadProgress.sendMessage(progressArguments);
                                intermediateProgress = 0;
                            } else {
                                intermediateProgress += red;
                                progressNotificationUpdate--;
                            }

                            saveit.write(data, 0, red);
                            red = getit.read(data, 0, 8096);
                        }
                        Log.d("Aptoide",
                                "Download done! apkidHash: " + threadApkidHash + " localPath: " + localPath);
                        saveit.flush();
                        saveit.close();
                        getit.close();
                    }

                    if (keepScreenOn.isHeld()) {
                        keepScreenOn.release();
                    }

                    File f = new File(localPath);
                    Md5Handler hash = new Md5Handler();
                    if (md5hash == null || md5hash.equalsIgnoreCase(hash.md5Calc(f))) {
                        downloadArguments.arg1 = 1;
                        downloadArguments.arg2 = threadApkidHash;
                        downloadArguments.obj = localPath;
                        downloadHandler.sendMessage(downloadArguments);
                    } else {
                        Log.d("Aptoide", md5hash + " VS " + hash.md5Calc(f));
                        downloadArguments.arg1 = 0;
                        downloadArguments.arg2 = threadApkidHash;
                        downloadErrorHandler.sendMessage(downloadArguments);
                    }

                } catch (Exception e) {
                    if (keepScreenOn.isHeld()) {
                        keepScreenOn.release();
                    }
                    downloadArguments.arg1 = 1;
                    downloadArguments.arg2 = threadApkidHash;
                    downloadErrorHandler.sendMessage(downloadArguments);
                }
            }
        }.start();

    } catch (Exception e) {
    }
}

From source file:cn.xiaocool.android_etong.net.constant.request.MainRequest.java

public void updatauserphone(final String phone) {
    new Thread() {
        Message msg = new Message();

        public void run() {
            String data = "&userid=" + user.getUserId() + "&phone=" + phone;
            Log.e("data is ", data);
            String result_data = NetUtil.getResponse(WebAddress.UPDATAUSERPHONE, data);
            Log.e("successful", result_data);
            try {
                JSONObject obj = new JSONObject(result_data);
                msg.what = CommunalInterfaces.UPDATAUSERPHONE;
                msg.obj = obj;/*from   w  w  w .j  a va 2  s.co m*/
            } catch (JSONException e) {
                e.printStackTrace();
            } finally {
                handler.sendMessage(msg);
            }
        }
    }.start();
}

From source file:net.networksaremadeofstring.rhybudd.ViewZenossDevice.java

/** Called when the activity is first created. */
@Override/*from  w ww  .ja va  2 s .c  o  m*/
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    settings = PreferenceManager.getDefaultSharedPreferences(this);

    setContentView(R.layout.view_zenoss_device3);

    actionbar = getActionBar();
    actionbar.setDisplayHomeAsUpEnabled(true);
    actionbar.setHomeButtonEnabled(true);

    list = (ListView) findViewById(R.id.ZenossEventsList);

    errorHandler = new Handler() {
        public void handleMessage(Message msg) {
            try {
                Toast.makeText(ViewZenossDevice.this, msg.getData().getString("exception"), Toast.LENGTH_LONG)
                        .show();
            } catch (Exception e) {
                ////BugSenseHandler.sendException("ViewZenossDevice-ErrorHandler", e);
            }
        }
    };

    loadAverageHandler = new Handler() {
        public void handleMessage(Message msg) {
            try {
                ((ImageView) findViewById(R.id.loadAverageGraph)).setImageDrawable(loadAverageGraph);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    };

    CPUGraphHandler = new Handler() {
        public void handleMessage(Message msg) {
            try {
                ((ImageView) findViewById(R.id.CPUGraph)).setImageDrawable(CPUGraph);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    };

    MemoryGraphHandler = new Handler() {
        public void handleMessage(Message msg) {
            try {
                ((ImageView) findViewById(R.id.MemoryGraph)).setImageDrawable(MemoryGraph);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    };

    eventsHandler = new Handler() {
        public void handleMessage(Message msg) {
            try {
                //((ProgressBar) findViewById(R.id.eventsProgressBar)).setVisibility(4);
            } catch (Exception e) {
                ////BugSenseHandler.sendException("ViewZenossDevice", e);
            }

            if (EventCount > 0 && msg.what == 1) {
                try {
                    adapter = new ZenossEventsAdaptor(ViewZenossDevice.this, listOfZenossEvents, false);
                    list.setAdapter(adapter);
                } catch (Exception e) {
                    ////BugSenseHandler.sendException("ViewZenossDevice", e);
                }
            } else {
                list = null;
            }
        }
    };

    firstLoadHandler = new Handler() {
        public void handleMessage(Message msg) {
            if (dialog != null)
                dialog.dismiss();

            try {
                if (DeviceObject != null && msg.what == 1
                        && DeviceObject.getJSONObject("result").getBoolean("success") == true) {
                    //Log.i("DeviceDetails",DeviceObject.toString());
                    DeviceDetails = DeviceObject.getJSONObject("result").getJSONObject("data");

                    try {
                        String Name = DeviceDetails.getString("snmpSysName").toUpperCase();
                        if (Name.equals("")) {
                            Name = DeviceDetails.getString("name").toUpperCase();
                        }

                        ((TextView) findViewById(R.id.deviceID)).setText(Name);
                        //actionbar.setTitle(DeviceDetails.getString("snmpSysName"));
                        actionbar.setSubtitle(Name);
                    } catch (Exception e) {
                        ((TextView) findViewById(R.id.deviceID)).setText("--");
                    }

                    try {
                        ((TextView) findViewById(R.id.modelTime))
                                .setText(DeviceDetails.getString("lastCollected"));
                    } catch (Exception e) {
                        ((TextView) findViewById(R.id.modelTime)).setText("Unknown");
                    }

                    try {
                        ((TextView) findViewById(R.id.firstSeen)).setText(DeviceDetails.getString("firstSeen"));
                    } catch (Exception e) {
                        ((TextView) findViewById(R.id.firstSeen)).setText("");
                    }

                    try {
                        ((TextView) findViewById(R.id.location))
                                .setText(DeviceDetails.getString("snmpLocation"));
                    } catch (Exception e) {
                        ((TextView) findViewById(R.id.location)).setText("Unknown Location");
                    }

                    try {
                        ((TextView) findViewById(R.id.uptime)).setText(DeviceDetails.getString("uptime"));
                    } catch (Exception e) {
                        //Already got a placeholder
                    }

                    try {
                        ((TextView) findViewById(R.id.productionState))
                                .setText(DeviceDetails.getString("productionState"));
                    } catch (Exception e) {
                        //Already got a placeholder
                    }

                    try {
                        ((TextView) findViewById(R.id.memorySwap))
                                .setText(DeviceDetails.getJSONObject("memory").getString("ram") + " / "
                                        + DeviceDetails.getJSONObject("memory").getString("swap"));
                    } catch (Exception e) {
                        //Already got a placeholder
                    }

                    String Groups = "";
                    try {
                        for (int i = 0; i < DeviceDetails.getJSONArray("groups").length(); i++) {
                            if (i > 0)
                                Groups += ", ";
                            try {
                                Groups += DeviceDetails.getJSONArray("groups").getJSONObject(i)
                                        .getString("name");
                            } catch (Exception e) {
                                ////BugSenseHandler.sendException("ViewZenossDevice", e);
                            }
                        }

                        ((TextView) findViewById(R.id.groups)).setText(Groups);

                    } catch (Exception e) {
                        ////BugSenseHandler.sendException("ViewZenossDevice", e);
                    }

                    String Systems = "";
                    try {
                        for (int i = 0; i < DeviceDetails.getJSONArray("systems").length(); i++) {
                            if (i > 0)
                                Systems += ", ";

                            Systems += DeviceDetails.getJSONArray("systems").getJSONObject(i).getString("name");
                        }

                        ((TextView) findViewById(R.id.systems)).setText(Systems);

                    } catch (Exception e) {
                        //Already got a placeholder
                        ////BugSenseHandler.sendException("ViewZenossDevice", e);
                    }

                    //etc
                } else {
                    Toast.makeText(ViewZenossDevice.this, "There was an error loading the Device details",
                            Toast.LENGTH_LONG).show();
                    //finish();
                }
            } catch (Exception e) {
                //e.printStackTrace();
                Toast.makeText(ViewZenossDevice.this, "An error was encountered parsing the JSON.",
                        Toast.LENGTH_LONG).show();
                ////BugSenseHandler.sendException("ViewZenossDevice", e);
            }
        }
    };

    dialog = new ProgressDialog(this);
    dialog.setTitle("Contacting Zenoss");
    dialog.setMessage("Please wait:\nLoading Device details....");
    dialog.show();
    dataPreload = new Thread() {
        public void run() {
            try {
                Message msg = new Message();
                Bundle bundle = new Bundle();

                if (API == null) {
                    try {
                        /*if(settings.getBoolean("httpBasicAuth", false))
                        {
                           API = new ZenossAPIv2(settings.getString("userName", ""), settings.getString("passWord", ""), settings.getString("URL", ""),settings.getString("BAUser", ""), settings.getString("BAPassword", ""));
                        }
                        else
                        {
                           API = new ZenossAPIv2(settings.getString("userName", ""), settings.getString("passWord", ""), settings.getString("URL", ""));
                        }*/
                    }
                    /*catch(ConnectTimeoutException cte)
                    {
                       if(cte.getMessage() != null)
                       {
                          //Toast.makeText(ViewZenossDevice.this, "An error was encountered;\r\n" + cte.getMessage().toString(), Toast.LENGTH_LONG).show();
                          bundle.putString("exception","The connection timed out;\r\n" + cte.getMessage().toString());
                          msg.setData(bundle);
                          msg.what = 0;
                          errorHandler.sendMessage(msg);
                       }
                       else
                       {
                          bundle.putString("exception","A time out error was encountered but the exception thrown contains no further information.");
                          msg.setData(bundle);
                          msg.what = 0;
                          errorHandler.sendMessage(msg);
                          //Toast.makeText(ViewZenossDevice.this, "An error was encountered but the exception thrown contains no further information.", Toast.LENGTH_LONG).show();
                       }
                    }*/
                    catch (Exception e) {
                        if (e.getMessage() != null) {
                            bundle.putString("exception",
                                    "An error was encountered;\r\n" + e.getMessage().toString());
                            msg.setData(bundle);
                            msg.what = 0;
                            errorHandler.sendMessage(msg);
                            //Toast.makeText(ViewZenossDevice.this, "An error was encountered;\r\n" + e.getMessage().toString(), Toast.LENGTH_LONG).show();
                        } else {
                            bundle.putString("exception",
                                    "An error was encountered but the exception thrown contains no further information.");
                            msg.setData(bundle);
                            msg.what = 0;
                            errorHandler.sendMessage(msg);
                            //Toast.makeText(ViewZenossDevice.this, "An error was encountered but the exception thrown contains no further information.", Toast.LENGTH_LONG).show();
                        }
                    }

                    DeviceObject = API.GetDevice(getIntent().getStringExtra("UID"));
                }
            } catch (Exception e) {
                //e.printStackTrace();
                //BugSenseHandler.sendException("updateDevices-dataPreload",e);
                firstLoadHandler.sendEmptyMessage(0);
            }

            firstLoadHandler.sendEmptyMessage(1);
        }
    };

    dataPreload.start();

    loadAvgGraphLoad = new Thread() {
        public void run() {
            try {
                if (API == null) {
                    Message msg = new Message();
                    Bundle bundle = new Bundle();

                    try {
                        /*if(settings.getBoolean("httpBasicAuth", false))
                        {
                           API = new ZenossAPIv2(settings.getString("userName", ""), settings.getString("passWord", ""), settings.getString("URL", ""),settings.getString("BAUser", ""), settings.getString("BAPassword", ""));
                        }
                        else
                        {
                           API = new ZenossAPIv2(settings.getString("userName", ""), settings.getString("passWord", ""), settings.getString("URL", ""));
                        }*/
                        if (PreferenceManager.getDefaultSharedPreferences(ViewZenossDevice.this)
                                .getBoolean(ZenossAPI.PREFERENCE_IS_ZAAS, false)) {
                            API = new ZenossAPIZaas();
                        } else {
                            API = new ZenossAPICore();
                        }

                        ZenossCredentials credentials = new ZenossCredentials(ViewZenossDevice.this);
                        API.Login(credentials);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }

                JSONObject graphURLs = API.GetDeviceGraphs(getIntent().getStringExtra("UID"));

                //Log.e("graphURLs",graphURLs.toString(3));
                int urlCount = graphURLs.getJSONObject("result").getJSONArray("data").length();

                for (int i = 0; i < urlCount; i++) {
                    JSONObject currentGraph = null;
                    try {
                        currentGraph = graphURLs.getJSONObject("result").getJSONArray("data").getJSONObject(i);

                        if (currentGraph.getString("title").equals("Load Average")) {
                            loadAverageGraph = API.GetGraph(currentGraph.getString("url"));
                            loadAverageHandler.sendEmptyMessage(1);
                        } else if (currentGraph.getString("title").equals("CPU Utilization")) {
                            CPUGraph = API.GetGraph(currentGraph.getString("url"));
                            CPUGraphHandler.sendEmptyMessage(1);
                        } else if (currentGraph.getString("title").equals("Memory Utilization")) {
                            MemoryGraph = API.GetGraph(currentGraph.getString("url"));
                            MemoryGraphHandler.sendEmptyMessage(1);
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }

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

    eventsLoad = new Thread() {
        public void run() {
            try {
                if (API == null) {
                    Message msg = new Message();
                    Bundle bundle = new Bundle();

                    try {
                        /*if(settings.getBoolean("httpBasicAuth", false))
                        {
                           API = new ZenossAPIv2(settings.getString("userName", ""), settings.getString("passWord", ""), settings.getString("URL", ""),settings.getString("BAUser", ""), settings.getString("BAPassword", ""));
                        }
                        else
                        {
                           API = new ZenossAPIv2(settings.getString("userName", ""), settings.getString("passWord", ""), settings.getString("URL", ""));
                        }*/
                        if (PreferenceManager.getDefaultSharedPreferences(ViewZenossDevice.this)
                                .getBoolean(ZenossAPI.PREFERENCE_IS_ZAAS, false)) {
                            API = new ZenossAPIZaas();
                        } else {
                            API = new ZenossAPICore();
                        }

                        ZenossCredentials credentials = new ZenossCredentials(ViewZenossDevice.this);
                        API.Login(credentials);
                    } catch (ConnectTimeoutException cte) {
                        if (cte.getMessage() != null) {
                            //Toast.makeText(ViewZenossDevice.this, , Toast.LENGTH_LONG).show();
                            bundle.putString("exception",
                                    "An error was encountered;\r\n" + cte.getMessage().toString());
                        } else {
                            //Toast.makeText(ViewZenossDevice.this, "An error was encountered but the exception thrown contains no further information.", Toast.LENGTH_LONG).show();
                            bundle.putString("exception",
                                    "An error was encountered but the exception thrown contains no further information.");
                        }
                        msg.setData(bundle);
                        msg.what = 0;
                        errorHandler.sendMessage(msg);
                    } catch (Exception e) {
                        if (e.getMessage() != null) {
                            //Toast.makeText(ViewZenossDevice.this, "An error was encountered;\r\n" + e.getMessage().toString(), Toast.LENGTH_LONG).show();
                            bundle.putString("exception",
                                    "An error was encountered;\r\n" + e.getMessage().toString());
                        } else {
                            //Toast.makeText(ViewZenossDevice.this, "An error was encountered but the exception thrown contains no further information.", Toast.LENGTH_LONG).show();
                            bundle.putString("exception",
                                    "An error was encountered but the exception thrown contains no further information.");
                        }

                        msg.setData(bundle);
                        msg.what = 0;
                        errorHandler.sendMessage(msg);
                    }
                }

                /*try
                {   
                   EventsObject = API.GetDeviceEvents(getIntent().getStringExtra("UID"),false);
                }
                catch(Exception e)
                {
                   e.printStackTrace();
                }*/

                /*try
                {
                   if((EventsObject.has("type") && EventsObject.get("type").equals("exception")) || !EventsObject.getJSONObject("result").has("totalCount") )
                   {
                      EventsObject = API.GetDeviceEvents(getIntent().getStringExtra("UID"),true);
                   }
                }
                catch(Exception e)
                {
                   e.printStackTrace();
                }*/

                if (null != EventsObject && EventsObject.has("result")
                        && EventsObject.getJSONObject("result").getInt("totalCount") > 0) {
                    Events = EventsObject.getJSONObject("result").getJSONArray("events");

                    try {
                        if (EventsObject != null) {
                            EventCount = EventsObject.getJSONObject("result").getInt("totalCount");

                            for (int i = 0; i < EventCount; i++) {
                                //JSONObject CurrentEvent = null;
                                try {
                                    //CurrentEvent = Events.getJSONObject(i);
                                    listOfZenossEvents.add(new ZenossEvent(Events.getJSONObject(i)));
                                    //Log.i("ForLoop",CurrentEvent.getString("summary"));
                                } catch (JSONException e) {
                                    //Log.e("API - Stage 2 - Inner", e.getMessage());
                                } catch (Exception e) {
                                    //BugSenseHandler.sendException("ViewZenossDevice-EventsLoop", e);
                                }
                            }

                            eventsHandler.sendEmptyMessage(1);
                        } else {
                            //Log.i("eventsLoad","Had a problem; EventsObject was null");
                            //eventsHandler.sendEmptyMessage(0);
                        }
                    } catch (JSONException e) {
                        e.printStackTrace();
                        //BugSenseHandler.sendException("ViewZenossDevice-Events", e);
                        eventsHandler.sendEmptyMessage(0);
                    }
                } else {
                    eventsHandler.sendEmptyMessage(0);
                }
            } catch (Exception e) {
                //Log.e("API - Stage 1", e.getMessage());
                //BugSenseHandler.sendException("ViewZenossDevice-Events", e);
                eventsHandler.sendEmptyMessage(0);
            }
        }
    };
    eventsLoad.start();
}

From source file:net.evecom.androidecssp.activity.taskresponse.TaskResponseAddActivity.java

/**
 * /*  ww w.j a  v  a  2s . co m*/
 * 
 * 
 * @author Mars zhang
 * @created 2016-1-27 9:21:54
 */
private void postStrForm(final HashMap<String, String> entity) {
    new Thread(new Runnable() {
        @Override
        public void run() {
            Message message = new Message();
            try {
                saveResult = connServerForResultPost("jfs/ecssp/mobile/taskresponseCtr/taskResponseAdd",
                        entity);
            } catch (ClientProtocolException e) {
                message.what = MESSAGETYPE_02;
                Log.e("mars", e.getMessage());
            } catch (IOException e) {
                message.what = MESSAGETYPE_02;
                Log.e("mars", e.getMessage());
            }
            if (saveResult.length() > 0) {
                message.what = MESSAGETYPE_01;
                /*String responseid = "";
                try {
                TaskResponseInfo taskResponseInfo = getTaskResponseInfo(saveResult);
                if (null != taskResponseInfo) {
                    responseid = taskResponseInfo.getId();
                }
                } catch (JSONException e) {
                }*/
            } else {
                message.what = MESSAGETYPE_02;
            }
            saveHandler.sendMessage(message);
        }
    }).start();
}

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

public void find_password() {
    String phone = back_password_username.getText().toString().trim();
    String new_password = back_new_password.getText().toString().trim();
    String new_repassword = back_new_repassword.getText().toString().trim();
    params = new ArrayList<NameValuePair>();
    params.add(new BasicNameValuePair("phone", phone));
    params.add(new BasicNameValuePair("password", new_password));

    if (new_password.equals("") || new_repassword.equals("")) {
        Toast.makeText(CallBackPasswordActivity.this, "??", Toast.LENGTH_SHORT).show();
    } else if (new_password.length() < 6) {
        Toast.makeText(CallBackPasswordActivity.this, "??6?", Toast.LENGTH_SHORT).show();
    } else {/*  w w w. j av a2 s .c  o  m*/
        if (new_password.equals(new_repassword)) {
            Thread thread = new Thread(new Runnable() {

                @Override
                public void run() {
                    dataJson = HttpUtils.request(params, URLs.FING_PASSWORD);
                    Message msg = new Message();
                    if (dataJson.length() != 0 && !dataJson.equals("0x110")) {
                        try {
                            jsonObject = new JSONObject(dataJson);
                            if (jsonObject.getBoolean("success")) {
                                msg.what = 5;
                            } else {
                                msg.what = 6;
                            }
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    } else {
                        msg.what = 0;
                    }
                    handler.sendMessage(msg);
                }
            });
            thread.start();
        } else {
            Toast.makeText(CallBackPasswordActivity.this, "??", Toast.LENGTH_SHORT)
                    .show();
        }
    }
}

From source file:com.oasis.sdk.activity.GooglePlayBillingActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(BaseUtils.getResourceValue("layout", "oasisgames_sdk_pay_google"));

    myHandler = new MyHandler(this);

    /* base64EncodedPublicKey should be YOUR APPLICATION'S PUBLIC KEY
     * (that you got from the Google Play developer console). This is not your
     * developer public key, it's the *app-specific* public key.
     *//from  w  ww.j  a v a2s .c om
     * Instead of just storing the entire literal string here embedded in the
     * program,  construct the key at runtime from pieces or
     * use bit manipulation (for example, XOR with some other string) to hide
     * the actual key.  The key itself is not secret information, but we don't
     * want to make it easy for an attacker to replace the public key with one
     * of their own and then fake messages from the server.
     */
    //        String base64EncodedPublicKey = "CONSTRUCT_YOUR_KEY_AND_PLACE_IT_HERE";

    if (TextUtils.isEmpty(base64EncodedPublicKey)) {
        ApplicationInfo appInfo;
        try {
            appInfo = getPackageManager().getApplicationInfo(getPackageName(), PackageManager.GET_META_DATA);
            base64EncodedPublicKey = appInfo.metaData.getString("com.googleplay.ApplicationId");
        } catch (NameNotFoundException e) {
            BaseUtils.logDebug(TAG, "Please put your app's public key in AndroidManifest.xml.");
        }
    }
    if (TextUtils.isEmpty(base64EncodedPublicKey)) {
        BaseUtils.logError(TAG, "Please put your app's public key in AndroidManifest.xml.");
        complain("Please put your app's public key in AndroidManifest.xml.");
        return;
    }

    productID = getIntent().getStringExtra("inAppProductID");
    ext = getIntent().getStringExtra("ext");
    oasOrderid = getIntent().getStringExtra("oasOrderid");
    if (TextUtils.isEmpty(productID)) {
        BaseUtils.logError(TAG, "Please put product id.");
        complain("Please put product id.");
        return;
    }

    if (SystemCache.userInfo == null || TextUtils.isEmpty(SystemCache.userInfo.serverID)
            || TextUtils.isEmpty(SystemCache.userInfo.roleID)) {
        BaseUtils.logError(TAG, "Please put game serverid or roleid.");
        complain("Please put game server id.");
        return;
    }

    //        revenue = getRevenueAndCurrency();// ?productid?????
    //        if(TextUtils.isEmpty(revenue)){
    //           BaseUtils.logError(TAG, "This product id does not exist, please contact customer support");
    //           setResult(OASISPlatformConstant.RESULT_EXCEPTION);
    //           Message msg = new Message();
    //           msg.what = 0;
    //           msg.obj = getResources().getString(BaseUtils.getResourceValue("string", "oasisgames_sdk_pay_google_notice_2")); 
    //            myHandler.sendMessage(msg);
    //           return;
    //        }
    setWaitScreen(true);

    if (SystemCache.OASISSDK_ENVIRONMENT_SANDBOX) {
        initSandBox();
        //1  ? ??
        //2 ???
        //3 ??
        return;
    }
    // Create the helper, passing it our context and the public key to verify signatures with
    BaseUtils.logDebug(TAG, "Creating IAB helper.");
    mHelper = new IabHelper(this.getApplicationContext(), base64EncodedPublicKey);

    // enable debug logging (for a production application, you should set this to false).
    mHelper.enableDebugLogging(SystemCache.OASISSDK_ENVIRONMENT_SANDBOX);

    int isGoolgePlayAvail = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this.getApplicationContext());
    if (isGoolgePlayAvail == ConnectionResult.SUCCESS) {
        // Start setup. This is asynchronous and the specified listener
        // will be called once setup completes.
        BaseUtils.logDebug(TAG, "Starting setup.");
        mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
            public void onIabSetupFinished(IabResult result) {
                if (isPageClose()) {
                    isPageCloseHandler();
                    return;
                }
                BaseUtils.logDebug(TAG, "Setup finished.");

                if (!result.isSuccess()) {
                    // Oh noes, there was a problem.
                    BaseUtils.logError(TAG, "Problem setting up in-app billing: "
                            + IabHelper.getResponseDesc(result.getResponse()));
                    Message msg = new Message();
                    msg.what = 0;
                    msg.obj = getResources().getString(
                            BaseUtils.getResourceValue("string", "oasisgames_sdk_pay_google_notice_1"));
                    myHandler.sendMessage(msg);
                    return;
                }

                // Have we been disposed of in the meantime? If so, quit.
                if (mHelper == null)
                    return;

                // IAB is fully set up. Now, Start purchase.
                try {
                    oldOrderList = GoogleBillingUtils.getPurchasedList();
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                //                queryInventory();
                checkALLOrder(0);
            }
        });
    } else {

        Dialog d = GooglePlayServicesUtil.getErrorDialog(isGoolgePlayAvail, this, RC_VERIFYGOOGLEPLAY);
        d.setOnDismissListener(new OnDismissListener() {

            @Override
            public void onDismiss(DialogInterface arg0) {
                BaseUtils.logError(TAG, "GooglePlayServicesUtil.showErrorDialogFragment");
                arg0.dismiss();

                myHandler.sendEmptyMessageDelayed(-1, 500);
            }
        });
        d.show();

    }
}