Example usage for android.widget Toast LENGTH_LONG

List of usage examples for android.widget Toast LENGTH_LONG

Introduction

In this page you can find the example usage for android.widget Toast LENGTH_LONG.

Prototype

int LENGTH_LONG

To view the source code for android.widget Toast LENGTH_LONG.

Click Source Link

Document

Show the view or text notification for a long period of time.

Usage

From source file:io.cloudmatch.demo.pinchandview.PAVServerEventListener.java

@Override
public void onMatchResponse(final MatchResponse response) {
    Log.d(TAG, "onMatchResponse: " + response);
    switch (response.mOutcome) {
    case ok:// w w  w.  jav  a2s . c  om
        final int groupSize = response.mGroupSize;

        // it's pinch. I know only two devices are involved.
        final PositionScheme scheme = response.mPositionScheme;
        if (scheme.mDevices.size() != 2) {
            // error, there should only be two devices!
            final String txt = "Error: matched in a group with more than 2 devices.";
            Toast.makeText(mActivity, txt, Toast.LENGTH_LONG).show();
            return;
        }

        // for this demo, devices are only paired horizontally

        int otherDeviceId = -1;
        for (final Integer i : response.mOthersInGroup) {
            if (i != response.mMyIdInGroup) {
                otherDeviceId = i;
                break;
            }
        }
        final DeviceInScheme myself = scheme.getDevicePerId(response.mMyIdInGroup);
        final DeviceInScheme other = scheme.getDevicePerId(otherDeviceId);

        if (myself != null && other != null) {
            final boolean xGreater = myself.mPosition.x > other.mPosition.x;
            final PAVScreenPositions position = xGreater ? PAVScreenPositions.right : PAVScreenPositions.left;
            mMatchedListener.onMatched(response.mGroupId, groupSize, position);
        }
        break;
    case fail:
        // is there a reason?
        switch (response.mReason) {
        case timeout:
        case uncertain:
            Toast.makeText(mActivity, "Match request timed out.", Toast.LENGTH_LONG).show();
            break;
        case error:
        case unknown:
        default:
            Toast.makeText(mActivity, "Match request failed.", Toast.LENGTH_LONG).show();
            break;
        }
    default:
        break;
    }
}

From source file:com.piggate.samples.PiggateLoginService.Activity_SingIn.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    _piggate = new Piggate(this, null); //Initialize the Piggate object

    setContentView(R.layout.activity_login);
    //EditTexts for user email and password
    editEmail = (EditText) findViewById(R.id.editText1);
    editPass = (EditText) findViewById(R.id.editText2);
    Button login = (Button) findViewById(R.id.buttonlogin2);
    final ImageButton return_button = (ImageButton) findViewById(R.id.return1);

    //Handles the top left back button of the activity
    return_button.setOnClickListener(new View.OnClickListener() {
        @Override/*from  w w  w.j a  v  a  2s  .co  m*/
        public void onClick(View v) {
            onBackPressed();
        }
    });

    //OnClick listener for the login button
    //Handles the login request to the server with the email and password fields
    login.setOnClickListener(new View.OnClickListener() {
        @Override
        synchronized public void onClick(View v) {
            if (!handledClick) {
                handledClick = true;
                String email = editEmail.getText().toString();
                String pass = editPass.getText().toString();

                //If the internet connection is working
                if (checkInternetConnection() == true) {
                    RequestParams params = new RequestParams();
                    params.put("email", email);
                    params.put("password", pass);

                    //Request of the Piggate object. Handles the login into the application with the user email and password
                    _piggate.RequestOpenSession(params).setListenerRequest(new Piggate.PiggateCallBack() {

                        //Method onComplete for JSONObject
                        //When the request is correct start Activity_Logged activity
                        @Override
                        public void onComplete(int statusCode, Header[] headers, String msg, JSONObject data) {
                            Toast.makeText(getApplicationContext(), msg, Toast.LENGTH_LONG).show();
                            Intent slideactivity = new Intent(Activity_SingIn.this, Activity_Logged.class);
                            Bundle bndlanimation = ActivityOptions
                                    .makeCustomAnimation(getApplicationContext(), R.anim.flip1, R.anim.flip2)
                                    .toBundle();
                            startActivity(slideactivity, bndlanimation);
                        }

                        //Method onError for JSONObject
                        //If there's an error with the request displays the error message to the user
                        @Override
                        public void onError(int statusCode, Header[] headers, String msg, JSONObject data) {
                            Toast.makeText(getApplicationContext(), msg, Toast.LENGTH_LONG).show();
                            handledClick = false;
                        }

                        //Method onComplete for JSONArray
                        @Override
                        public void onComplete(int statusCode, Header[] headers, String msg, JSONArray data) {
                            //Unused
                        }

                        //Method onError for JSONArray
                        @Override
                        public void onError(int statusCode, Header[] headers, String msg, JSONArray data) {
                            //Unused
                        }
                    }).exec();
                } else { //If the internet connection is not working
                    Toast.makeText(getApplicationContext(), "Network is not working", Toast.LENGTH_LONG).show();
                    handledClick = false;
                }
            }
        }
    });
}

From source file:com.project.merauke.CustomItemizedOverlay.java

@Override
protected boolean onBalloonTap(int index, CustomOverlayItem item) {
    Toast.makeText(c, "onBalloonTap for overlay index " + index, Toast.LENGTH_LONG).show();
    return true;/*from   w ww . ja  va  2 s.co  m*/
}

From source file:pl.bcichecki.rms.client.android.fragments.DevicesListFragment.java

private void downloadData() {
    Log.d(TAG, "Downloading devices list...");

    if (!AppUtils.checkInternetConnection(getActivity())) {
        Log.d(TAG, "There is NO network connected!");
        return;//from   w w w.j av a2  s  . c  o  m
    }

    devicesRestClient.getAllDevices(new GsonHttpResponseHandler<List<Device>>(new TypeToken<List<Device>>() {
    }.getType(), true) {

        @Override
        public void onFailure(Throwable error, String content) {
            Log.d(TAG, "Retrieving devices failed. [error=" + error + ", content=" + content + "]");
            if (error instanceof HttpResponseException) {
                if (((HttpResponseException) error).getStatusCode() == HttpStatus.SC_UNAUTHORIZED) {
                    AppUtils.showCenteredToast(getActivity(), R.string.general_unathorized_error_message_title,
                            Toast.LENGTH_LONG);
                } else {
                    AppUtils.showCenteredToast(getActivity(), R.string.general_unknown_error_message_title,
                            Toast.LENGTH_LONG);
                }
            } else {
                AppUtils.showCenteredToast(getActivity(), R.string.general_unknown_error_message_title,
                        Toast.LENGTH_LONG);
            }
        }

        @Override
        public void onFinish() {
            devicesListAdapter.refresh();
            hideLoadingMessage();
            Log.d(TAG, "Retrieving devices finished.");
        }

        @Override
        public void onStart() {
            Log.d(TAG, "Retrieving devices started.");
            showLoadingMessage();
            devices.clear();
        }

        @Override
        public void onSuccess(int statusCode, List<Device> object) {
            Log.d(TAG, "Retrieving devices successful. Retrieved " + object.size() + " objects.");
            devices.addAll(object);
        }
    });
}

From source file:io.cloudmatch.demo.swipeandcolor.SACServerEventListener.java

@Override
public void onMatchResponse(final MatchResponse response) {
    Log.d(TAG, "onMatchResponse: " + response);
    switch (response.mOutcome) {
    case ok:/*w  ww  .  j  av  a  2s. c  om*/
        final int groupSize = response.mGroupSize;
        final int myIdInGroup = response.mMyIdInGroup;
        final String groupId = response.mGroupId;
        mMatchedListener.onMatched(groupId, groupSize, myIdInGroup);
        break;
    case fail:
        // is there a reason?
        switch (response.mReason) {
        case timeout:
        case uncertain:
            Toast.makeText(mActivity, "Match request timed out.", Toast.LENGTH_LONG).show();
            break;
        case error:
        case unknown:
        default:
            Toast.makeText(mActivity, "Match request failed.", Toast.LENGTH_LONG).show();
            break;
        }
    default:
        break;
    }
}

From source file:com.hua.goddess.activites.RegisterActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.activity_register);
    pd = new ProgressDialog(RegisterActivity.this);
    // DeviceUuidFactory uuid = new DeviceUuidFactory(this);
    // uid = uuid.getDeviceUuid().toString();

    emailEditText = (EditText) findViewById(R.id.email);
    emailEditText.setInputType(InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS);// ??
    userNameEditText = (EditText) findViewById(R.id.username);
    passwordEditText = (EditText) findViewById(R.id.password);
    confirmPwdEditText = (EditText) findViewById(R.id.confirm_password);

    rg = (RadioGroup) findViewById(R.id.sex);
    b1 = (RadioButton) findViewById(R.id.male);
    b2 = (RadioButton) findViewById(R.id.female);
    wh = new WsRequestHelper(new WsRequestHelper.InterfaceCallBack() {
        @Override//from w  w w.j  a  v  a2s.c  om
        public void RequestCallBack(Object result) {
            // TODO Auto-generated method stub
            pd.dismiss();
            // Toast.makeText(RegisterActivity.this, result.toString(),
            // Toast.LENGTH_SHORT).show();
            if (result.toString().equals("?")) {
                Intent intent = new Intent(RegisterActivity.this, LoginActivity.class);
                Bundle bundle = new Bundle();
                bundle.putString("username", userNameEditText.getText().toString().trim());

                intent.putExtras(bundle);
                setResult(100, intent);
                finish();
            }

        }
    });

    rg.setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId) {
            // TODO Auto-generated method stub
            if (checkedId == b1.getId()) {
                sex = "1";
                Toast.makeText(RegisterActivity.this, "", Toast.LENGTH_LONG).show();
            }
            if (checkedId == b2.getId()) {
                sex = "2";
                Toast.makeText(RegisterActivity.this, "", Toast.LENGTH_LONG).show();
            }

        }

    });
}

From source file:net.networksaremadeofstring.cyllell.ViewEnvironments_Fragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    list = (ListView) this.getActivity().findViewById(R.id.environmentsListView);
    settings = this.getActivity().getSharedPreferences("Cyllell", 0);
    try {/*from w w w . ja  va  2s. com*/
        Cut = new Cuts(getActivity());
    } catch (Exception e) {
        e.printStackTrace();
    }

    dialog = new ProgressDialog(getActivity());
    dialog.setTitle("Contacting Chef");
    dialog.setMessage("Please wait: Prepping Authentication protocols");
    dialog.setIndeterminate(true);
    if (listOfEnvironments.size() < 1) {
        dialog.show();
    }

    updateListNotify = new Handler() {
        public void handleMessage(Message msg) {
            int tag = msg.getData().getInt("tag", 999999);

            if (msg.what == 0) {
                if (tag != 999999) {
                    listOfEnvironments.get(tag).SetSpinnerVisible();
                }
            } else if (msg.what == 1) {
                //Get rid of the lock
                CutInProgress = false;

                //the notifyDataSetChanged() will handle the rest
            } else if (msg.what == 99) {
                if (tag != 999999) {
                    Toast.makeText(ViewEnvironments_Fragment.this.getActivity(),
                            "An error occured during that operation.", Toast.LENGTH_LONG).show();
                    listOfEnvironments.get(tag).SetErrorState();
                }
            }
            EnvironmentAdapter.notifyDataSetChanged();
        }
    };

    final Handler handler = new Handler() {
        public void handleMessage(Message msg) {
            //Once we've checked the data is good to use start processing it
            if (msg.what == 0) {
                OnClickListener listener = new OnClickListener() {
                    public void onClick(View v) {
                        //Log.i("OnClick","Clicked");
                        GetMoreDetails((Integer) v.getTag());
                    }
                };

                OnLongClickListener listenerLong = new OnLongClickListener() {
                    public boolean onLongClick(View v) {
                        selectForCAB((Integer) v.getTag());
                        return true;
                    }
                };

                EnvironmentAdapter = new EnvironmentListAdaptor(getActivity().getBaseContext(),
                        listOfEnvironments, listener, listenerLong);
                list = (ListView) getView().findViewById(R.id.environmentsListView);
                if (list != null) {
                    if (EnvironmentAdapter != null) {
                        list.setAdapter(EnvironmentAdapter);
                    } else {
                        //Log.e("EnvironmentAdapter","EnvironmentAdapter is null");
                    }
                } else {
                    //Log.e("List","List is null");
                }

                dialog.dismiss();
            } else if (msg.what == 200) {
                dialog.setMessage("Sending request to Chef...");
            } else if (msg.what == 201) {
                dialog.setMessage("Parsing JSON.....");
            } else if (msg.what == 202) {
                dialog.setMessage("Populating UI!");
            } else {
                //Close the Progress dialog
                dialog.dismiss();

                //Alert the user that something went terribly wrong
                AlertDialog alertDialog = new AlertDialog.Builder(getActivity()).create();
                alertDialog.setTitle("API Error");
                alertDialog.setMessage("There was an error communicating with the API:\n"
                        + msg.getData().getString("exception"));
                alertDialog.setButton2("Back", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        getActivity().finish();
                    }
                });
                alertDialog.setIcon(R.drawable.icon);
                alertDialog.show();
            }
        }
    };

    Thread dataPreload = new Thread() {
        public void run() {
            if (listOfEnvironments.size() > 0) {
                handler.sendEmptyMessage(0);
            } else {
                try {
                    handler.sendEmptyMessage(200);
                    Environments = Cut.GetEnvironments();
                    handler.sendEmptyMessage(201);

                    JSONArray Keys = Environments.names();

                    for (int i = 0; i < Keys.length(); i++) {
                        listOfEnvironments.add(
                                new Environment(Keys.getString(i), Environments.getString(Keys.getString(i))
                                        .replaceFirst("^(https://|http://).*/environments/", "")));
                    }

                    handler.sendEmptyMessage(202);
                    handler.sendEmptyMessage(0);
                } catch (Exception e) {
                    Message msg = new Message();
                    Bundle data = new Bundle();
                    data.putString("exception", e.getMessage());
                    msg.setData(data);
                    msg.what = 1;
                    handler.sendMessage(msg);
                }
            }
            return;
        }
    };

    dataPreload.start();
    return inflater.inflate(R.layout.environments_landing, container, false);
}

From source file:com.example.android.donebar.DoneBarActivity.java

public void checkAvailability(int id, String number, String information) {
    if (Utility.isNotNull(number) && Utility.isNotNull(information)) {
        JSONObject json = new JSONObject();
        try {//from  w  ww  .  jav  a  2  s . c  o m
            json.put("id", id);
            json.put("number", number);
            json.put("information", information);
        } catch (Exception e) {
            Toast.makeText(getApplicationContext(), "Failed to create JSON Object.", Toast.LENGTH_LONG).show();
        }

        sendJSON(json);

    } else {
        Toast.makeText(getApplicationContext(), "Please fill out all the blanks", Toast.LENGTH_LONG).show();
    }
}

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

/** Called when the activity is first created. */
@Override/* w w w.j a  v  a 2 s .c  om*/
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:edu.rit.csh.androidwebnews.ComposeActivity.java

public void abandon(View view) {
    Toast.makeText(getApplicationContext(), "Post abandoned", Toast.LENGTH_LONG).show();
    finish();
}