Example usage for java.lang NumberFormatException printStackTrace

List of usage examples for java.lang NumberFormatException printStackTrace

Introduction

In this page you can find the example usage for java.lang NumberFormatException printStackTrace.

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:com.ifeng.util.download.DownloadThread.java

/**
 * Handle a 503 Service Unavailable status by processing the Retry-After
 * header./*w w w  .  j  av  a 2 s.  c o m*/
 * 
 * @param state
 *            state
 * @param response
 *            response
 * @throws StopRequest
 *             StopRequest
 */
private void handleServiceUnavailable(State state, HttpResponse response) throws StopRequest {
    if (Constants.LOGVV) {
        Log.v(Constants.TAG, "got HTTP response code 503");
    }
    state.mCountRetry = true;
    Header header = response.getFirstHeader("Retry-After");
    if (header != null) {
        try {
            if (Constants.LOGVV) {
                Log.v(Constants.TAG, "Retry-After :" + header.getValue());
            }
            state.mRetryAfter = Integer.parseInt(header.getValue());
            if (state.mRetryAfter < 0) {
                state.mRetryAfter = 0;
            } else {
                if (state.mRetryAfter < Constants.MIN_RETRY_AFTER) {
                    state.mRetryAfter = Constants.MIN_RETRY_AFTER;
                } else if (state.mRetryAfter > Constants.MAX_RETRY_AFTER) {
                    state.mRetryAfter = Constants.MAX_RETRY_AFTER;
                }
                state.mRetryAfter += Helpers.RANDOM.nextInt(Constants.MIN_RETRY_AFTER + 1);
                state.mRetryAfter *= 1000; // SUPPRESS CHECKSTYLE
            }
        } catch (NumberFormatException ex) {
            // ignored - retryAfter stays 0 in this case.
            ex.printStackTrace();
        }
    }
    throw new StopRequest(Downloads.Impl.STATUS_WAITING_TO_RETRY,
            "got 503 Service Unavailable, will retry later");
}

From source file:org.eclipse.paho.android.service.MqttConnection.java

private void parseMqttMessageV2(String topic, MqttMessage mqttMessage) throws Exception {
    Log.v("mqtt", "parseMqttMessageV2");
    Context ctx = NanuService.getContext();
    byte origMqttMsgByte[] = mqttMessage.getPayload();
    int mqttIndex = 0;
    boolean processVTagSuccess = false;

    boolean processPTagSuccess = false;
    long mqttPacketValue = 0;

    boolean processTTagSuccess = false;
    long mqttTimestampValue = 0;

    boolean processLTagSuccess = false;
    int mqttMsgLengthValue = 0;

    boolean processMTagSuccess = false;
    String mqttMessageValue = "";
    String mqttMembersValue = "";

    boolean processGTagSuccess = false;
    long mqttGroupIDValue = 0;

    boolean processSTagSuccess = false;
    String mqttSubjectValue = "";

    boolean processCTagSuccess = false;
    int mqttMemberCountValue = 0;

    boolean processNTagSuccess = false;
    int mqttAdminCountValue = 0;

    boolean processATagSuccess = false;
    String mqttAdminsValue = "";

    String[] topicArray = topic.split("\\/");

    String sender = topicArray[2];
    if (topicArray.length == 4) {
        processGTagSuccess = true;//  www  . j av  a2 s .  c o  m
        try {
            mqttGroupIDValue = Long.parseLong(topicArray[3].toString().trim());
        } catch (NumberFormatException nfe) {
            processGTagSuccess = false;
            nfe.printStackTrace();
        }

        if (mqttGroupIDValue == 0) {
            try {
                mqttGroupIDValue = Long.valueOf(topicArray[3].trim());
            } catch (Exception err) {
                processGTagSuccess = false;
                err.printStackTrace();
            }
        }
    }

    String mqttMsgDateValue = "";
    for (int indexMqttCounter = 0; indexMqttCounter < origMqttMsgByte.length; indexMqttCounter++) {
        /*       Log.v(SettingsManager.TAG, "MqttService origMqttMsgByte[" + indexMqttCounter + "] = " + origMqttMsgByte[indexMqttCounter]); */
    }

    for (int indexMqttCounter = 0; indexMqttCounter < origMqttMsgByte.length; indexMqttCounter++) {
        if (indexMqttCounter == 0) {
            mqttIndex = indexMqttCounter;
            long mqttVTag = getMqttTag(origMqttMsgByte, mqttIndex);
            if (mqttVTag != -1) {
                if (mqttVTag == 86) // "V"
                {
                    processVTagSuccess = true;
                    mqttIndex = mqttIndex + 2;
                } else {
                    processVTagSuccess = false;
                    break;
                }
            }
        } else {
            if (mqttIndex == indexMqttCounter) {
                long mqttTag = getMqttTag(origMqttMsgByte, mqttIndex);
                if (mqttTag != -1) {
                    if (mqttTag == 80) /* "P" */ {
                        mqttIndex = mqttIndex + 1;
                        long mPValue = origMqttMsgByte[mqttIndex];
                        mqttPacketValue = mPValue;
                        mqttIndex = mqttIndex + 1;
                        processPTagSuccess = true;
                    } else if (mqttTag == 84) /* "T" */ {
                        mqttIndex = mqttIndex + 1;
                        byte timeStampArray[] = new byte[8];
                        for (int i = 0; i < 8; i++) {
                            timeStampArray[i] = origMqttMsgByte[mqttIndex + i];
                        }
                        mqttTimestampValue = ByteBuffer.wrap(timeStampArray).order(ByteOrder.LITTLE_ENDIAN)
                                .getLong();

                        SimpleDateFormat sdf = new SimpleDateFormat("yyyy");
                        String messageYear = sdf.format(mqttTimestampValue);
                        if (messageYear.length() != 4) {
                            mqttTimestampValue = ByteBuffer.wrap(timeStampArray).order(ByteOrder.BIG_ENDIAN)
                                    .getLong();
                        }
                        SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                        String messageDate = sdfDate.format(mqttTimestampValue);
                        processTTagSuccess = true;
                        mqttIndex = mqttIndex + 8;
                    } else if (mqttTag == 76) /* "L" */ {
                        if (processPTagSuccess) {
                            if (mqttPacketValue == -128 || (mqttPacketValue == -117)
                                    || (mqttPacketValue == -115) || (mqttPacketValue == -126)) {
                                mqttIndex = mqttIndex + 1;
                                mqttMsgLengthValue = origMqttMsgByte[mqttIndex];
                                processLTagSuccess = true;
                                mqttIndex = mqttIndex + 1;
                            } else if (mqttPacketValue == 0) {
                                mqttIndex = mqttIndex + 1;
                                byte msgLengthArray[] = new byte[4];
                                for (int i = 0; i < 4; i++) {
                                    msgLengthArray[i] = origMqttMsgByte[mqttIndex + i];
                                }
                                mqttMsgLengthValue = ByteBuffer.wrap(msgLengthArray)
                                        .order(ByteOrder.LITTLE_ENDIAN).getInt();
                                processLTagSuccess = true;
                                mqttIndex = mqttIndex + 4;
                            }
                        }
                    } else if (mqttTag == 77) /* "M" */ {
                        if (processPTagSuccess) {
                            if ((mqttPacketValue == -128) || (mqttPacketValue == -124)
                                    || (mqttPacketValue == -126) || (mqttPacketValue == -117)) {

                                if (processCTagSuccess) {
                                    mqttIndex = mqttIndex + 1;
                                    for (int i = 0; i < mqttMemberCountValue; i++) {
                                        byte groupMembersArray[] = new byte[8];
                                        for (int j = 0; j < 8; j++) {
                                            groupMembersArray[j] = origMqttMsgByte[mqttIndex + j];
                                        }
                                        long participants = ByteBuffer.wrap(groupMembersArray)
                                                .order(ByteOrder.LITTLE_ENDIAN).getLong();
                                        mqttIndex = mqttIndex + 8;
                                        if (i == (mqttMemberCountValue - 1)) {
                                            mqttMembersValue = mqttMembersValue + participants;
                                        } else {
                                            mqttMembersValue = mqttMembersValue + participants + ",";
                                        }
                                    }
                                    processMTagSuccess = true;
                                } else {
                                    break;
                                }
                            } else if (mqttPacketValue == 0) {
                                if (processLTagSuccess) {
                                    mqttIndex = mqttIndex + 1;
                                    if (mqttMsgLengthValue > 0) {
                                        byte messageArray[] = null;
                                        try {
                                            messageArray = new byte[mqttMsgLengthValue];
                                        } catch (Exception err) {
                                            err.printStackTrace();
                                            processMTagSuccess = false;
                                            break;
                                        }

                                        for (int i = 0; i < mqttMsgLengthValue; i++) {
                                            messageArray[i] = origMqttMsgByte[mqttIndex + i];
                                        }
                                        mqttMessageValue = new String(messageArray);
                                        processMTagSuccess = true;
                                        mqttIndex = mqttIndex + mqttMsgLengthValue + 1;
                                    }
                                } else {
                                    break;
                                }
                            }
                        }
                    } else if (mqttTag == 71) /* "G" */ {
                        mqttIndex = mqttIndex + 1;
                        byte groupIDArray[] = new byte[8];
                        for (int i = 0; i < 8; i++) {
                            groupIDArray[i] = origMqttMsgByte[mqttIndex + i];
                        }
                        mqttGroupIDValue = ByteBuffer.wrap(groupIDArray).order(ByteOrder.LITTLE_ENDIAN)
                                .getLong();
                        processGTagSuccess = true;
                        mqttIndex = mqttIndex + 8;
                    } else if (mqttTag == 83) /* "S" */ {
                        if (processLTagSuccess) {
                            mqttIndex = mqttIndex + 1;
                            if (mqttMsgLengthValue > 0) {
                                byte subjectArray[] = null;
                                try {
                                    subjectArray = new byte[mqttMsgLengthValue];
                                } catch (Exception err) {
                                    err.printStackTrace();
                                    processSTagSuccess = false;
                                    break;
                                }
                                for (int i = 0; i < mqttMsgLengthValue; i++) {
                                    subjectArray[i] = origMqttMsgByte[mqttIndex + i];
                                }
                                mqttSubjectValue = new String(subjectArray);
                                processSTagSuccess = true;
                                mqttIndex = mqttIndex + mqttMsgLengthValue;
                            }
                        } else {
                            break;
                        }
                    } else if (mqttTag == 67) /* "C" */ {
                        mqttIndex = mqttIndex + 1;
                        mqttMemberCountValue = origMqttMsgByte[mqttIndex];
                        processCTagSuccess = true;
                        mqttIndex = mqttIndex + 1;
                    } else if (mqttTag == 78) /* "N" */ {
                        mqttIndex = mqttIndex + 1;
                        mqttAdminCountValue = origMqttMsgByte[mqttIndex];
                        processNTagSuccess = true;
                        mqttIndex = mqttIndex + 1;
                    } else if (mqttTag == 65) /* "A" */ {
                        if (processPTagSuccess) {
                            if (mqttPacketValue == -117) {
                                if (processNTagSuccess) {
                                    mqttIndex = mqttIndex + 1;
                                    for (int i = 0; i < mqttAdminCountValue; i++) {
                                        byte groupAdminsArray[] = new byte[8];
                                        for (int j = 0; j < 8; j++) {
                                            groupAdminsArray[j] = origMqttMsgByte[mqttIndex + j];
                                        }
                                        long admins = ByteBuffer.wrap(groupAdminsArray)
                                                .order(ByteOrder.LITTLE_ENDIAN).getLong();
                                        mqttIndex = mqttIndex + 8;
                                        if (i == (mqttAdminCountValue - 1)) {
                                            mqttAdminsValue = mqttAdminsValue + admins;
                                        } else {
                                            mqttAdminsValue = mqttAdminsValue + admins + ",";
                                        }
                                    }
                                    processATagSuccess = true;
                                } else {
                                    break;
                                }
                            }
                        }
                    } else {
                        break;
                    }
                } else {
                    break;
                }
            }
        }
    }

    if (!processVTagSuccess) {
        return;
    }

    PowerManager pm = (PowerManager) ctx.getSystemService(Context.POWER_SERVICE);
    boolean isScreenOn = pm.isScreenOn();
    if (isScreenOn == false) {
        WakeLock wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP
                | PowerManager.ON_AFTER_RELEASE, "MyLock");
        if (wl.isHeld()) {
            wl.release();
        }
        wl.acquire(10000);
        WakeLock wl_cpu = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "MyCpuLock");
        if (wl_cpu.isHeld()) {
            wl_cpu.release();
        }
        wl_cpu.acquire(10000);
    }

    String message = mqttMessageValue;
    Log.v("mqtt", "from: " + sender);
    Log.v("mqtt", "message: " + message);
    Intent intent = new Intent();
    intent.setClassName(ctx, "org.eclipse.paho.android.service.sample.MainActivity");
    intent.putExtra("handle", clientHandle);
    String ns = Context.NOTIFICATION_SERVICE;
    NotificationManager mNotificationManager = (NotificationManager) ctx.getSystemService(ns);
    int messageNotificationId = 1;
    mNotificationManager.cancel(messageNotificationId);
    Calendar.getInstance().getTime().toString();
    long when = System.currentTimeMillis();
    String ticker = sender + " " + mqttMessageValue;
    PendingIntent pendingIntent = PendingIntent.getActivity(ctx, 3, intent, 0);
    NotificationCompat.Builder notificationCompat = new NotificationCompat.Builder(ctx);
    notificationCompat.setAutoCancel(true).setContentTitle(sender).setContentIntent(pendingIntent)
            .setContentText(mqttMessageValue).setTicker(ticker).setWhen(when)
            .setSmallIcon(R.drawable.ic_launcher);

    //  Notification notification = notificationCompat.build();
    Bitmap iconLarge = BitmapFactory.decodeResource(ctx.getResources(), R.drawable.ic_launcher);
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(ctx)
            .setSmallIcon(R.drawable.ic_launcher).setLargeIcon(iconLarge).setContentTitle(sender)
            .setContentText(mqttMessageValue);

    mBuilder.setContentIntent(pendingIntent);
    mBuilder.setTicker(message);
    mBuilder.setAutoCancel(true);
    mBuilder.setDefaults(
            Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE | Notification.DEFAULT_LIGHTS);
    mNotificationManager.notify(messageNotificationId, mBuilder.build());
}

From source file:com.cypress.cysmart.BLEServiceFragments.SensorHubService.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final View rootView = inflater.inflate(R.layout.sensor_hub, container, false);
    LinearLayout parent = (LinearLayout) rootView.findViewById(R.id.parent_sensorhub);
    parent.setOnClickListener(new OnClickListener() {

        @Override//  w w  w . j a  v a2  s  .c  o  m
        public void onClick(View v) {

        }
    });
    accX = (TextView) rootView.findViewById(R.id.acc_x_value);
    accY = (TextView) rootView.findViewById(R.id.acc_y_value);
    accZ = (TextView) rootView.findViewById(R.id.acc_z_value);
    BAT = (TextView) rootView.findViewById(R.id.bat_value);
    STEMP = (TextView) rootView.findViewById(R.id.temp_value);
    mProgressDialog = new ProgressDialog(getActivity());
    Spressure = (TextView) rootView.findViewById(R.id.pressure_value);

    // Locate device button listener
    Button locateDevice = (Button) rootView.findViewById(R.id.locate_device);
    locateDevice.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            Button btn = (Button) v;
            String buttonText = btn.getText().toString();
            String startText = getResources().getString(R.string.sen_hub_locate);
            String stopText = getResources().getString(R.string.sen_hub_locate_stop);
            if (buttonText.equalsIgnoreCase(startText)) {
                btn.setText(stopText);
                if (mWriteAlertCharacteristic != null) {
                    byte[] convertedBytes = convertingTobyteArray(IMM_HIGH_ALERT);
                    BluetoothLeService.writeCharacteristicNoresponse(mWriteAlertCharacteristic, convertedBytes);
                }

            } else {
                btn.setText(startText);
                if (mWriteAlertCharacteristic != null) {
                    byte[] convertedBytes = convertingTobyteArray(IMM_NO_ALERT);
                    BluetoothLeService.writeCharacteristicNoresponse(mWriteAlertCharacteristic, convertedBytes);
                }
            }

        }
    });
    final ImageButton acc_more = (ImageButton) rootView.findViewById(R.id.acc_more);
    final ImageButton stemp_more = (ImageButton) rootView.findViewById(R.id.stemp_more);
    final ImageButton spressure_more = (ImageButton) rootView.findViewById(R.id.spressure_more);

    final LinearLayout acc_layLayout = (LinearLayout) rootView.findViewById(R.id.acc_context_menu);
    final LinearLayout stemp_layLayout = (LinearLayout) rootView.findViewById(R.id.stemp_context_menu);
    final LinearLayout spressure_layLayout = (LinearLayout) rootView.findViewById(R.id.spressure_context_menu);

    // expand listener
    acc_more.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            if (acc_layLayout.getVisibility() != View.VISIBLE) {
                acc_more.setRotation(90);
                CustomSlideAnimation a = new CustomSlideAnimation(acc_layLayout, CustomSlideAnimation.EXPAND);
                a.setHeight(height);
                acc_layLayout.startAnimation(a);
                acc_scan_interval = (EditText) rootView.findViewById(R.id.acc_sensor_scan_interval);
                if (ACCSensorScanCharacteristic != null) {
                    acc_scan_interval.setText(ACCSensorScanCharacteristic);
                }
                acc_sensortype = (TextView) rootView.findViewById(R.id.acc_sensor_type);
                if (ACCSensorTypeCharacteristic != null) {
                    acc_sensortype.setText(ACCSensorTypeCharacteristic);
                }
                acc_scan_interval.setOnEditorActionListener(new OnEditorActionListener() {

                    @Override
                    public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                        if (actionId == EditorInfo.IME_ACTION_DONE) {
                            int myNum = 0;

                            try {
                                myNum = Integer.parseInt(acc_scan_interval.getText().toString());
                            } catch (NumberFormatException nfe) {
                                nfe.printStackTrace();
                            }
                            byte[] convertedBytes = convertingTobyteArray(Integer.toString(myNum));
                            BluetoothLeService.writeCharacteristicNoresponse(mReadACCSensorScanCharacteristic,
                                    convertedBytes);
                        }
                        return false;
                    }
                });
                Spinner spinner_filterconfiguration = (Spinner) rootView
                        .findViewById(R.id.acc_filter_configuration);
                // Create an ArrayAdapter using the string array and a
                // default
                // spinner layout
                ArrayAdapter<CharSequence> adapter_filterconfiguration = ArrayAdapter.createFromResource(
                        getActivity(), R.array.filter_configuration_alert_array,
                        android.R.layout.simple_spinner_item);
                // Specify the layout to use when the list of choices
                // appears
                adapter_filterconfiguration
                        .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
                // Apply the adapter to the spinner
                spinner_filterconfiguration.setAdapter(adapter_filterconfiguration);

            } else {
                acc_more.setRotation(-90);

                acc_scan_interval.setText("");
                acc_sensortype.setText("");
                CustomSlideAnimation a = new CustomSlideAnimation(acc_layLayout, CustomSlideAnimation.COLLAPSE);
                height = a.getHeight();
                acc_layLayout.startAnimation(a);
            }
        }
    });
    // expand listener
    stemp_more.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            if (stemp_layLayout.getVisibility() != View.VISIBLE) {
                stemp_more.setRotation(90);
                CustomSlideAnimation a = new CustomSlideAnimation(stemp_layLayout, CustomSlideAnimation.EXPAND);
                a.setHeight(height);
                stemp_layLayout.startAnimation(a);
                stemp_scan_interval = (EditText) rootView.findViewById(R.id.stemp_sensor_scan_interval);
                if (STEMPSensorScanCharacteristic != null) {
                    stemp_scan_interval.setText(STEMPSensorScanCharacteristic);
                }
                stemp_sensortype = (TextView) rootView.findViewById(R.id.stemp_sensor_type);
                if (STEMPSensorTypeCharacteristic != null) {
                    stemp_sensortype.setText(STEMPSensorTypeCharacteristic);
                }
                stemp_scan_interval.setOnEditorActionListener(new OnEditorActionListener() {

                    @Override
                    public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                        if (actionId == EditorInfo.IME_ACTION_DONE) {
                            int myNum = 0;

                            try {
                                myNum = Integer.parseInt(stemp_scan_interval.getText().toString());
                            } catch (NumberFormatException nfe) {
                                nfe.printStackTrace();
                            }
                            byte[] convertedBytes = convertingTobyteArray(Integer.toString(myNum));
                            BluetoothLeService.writeCharacteristicNoresponse(mReadSTEMPSensorScanCharacteristic,
                                    convertedBytes);
                        }
                        return false;
                    }
                });

            } else {
                stemp_more.setRotation(-90);
                stemp_scan_interval.setText("");
                stemp_sensortype.setText("");
                CustomSlideAnimation a = new CustomSlideAnimation(stemp_layLayout,
                        CustomSlideAnimation.COLLAPSE);
                height = a.getHeight();
                stemp_layLayout.startAnimation(a);
            }
        }
    });
    // expand listener
    spressure_more.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            if (spressure_layLayout.getVisibility() != View.VISIBLE) {
                spressure_more.setRotation(90);
                CustomSlideAnimation a = new CustomSlideAnimation(spressure_layLayout,
                        CustomSlideAnimation.EXPAND);
                a.setHeight(height);
                spressure_layLayout.startAnimation(a);
                spressure_scan_interval = (EditText) rootView.findViewById(R.id.spressure_sensor_scan_interval);
                if (SPRESSURESensorScanCharacteristic != null) {
                    spressure_scan_interval.setText(SPRESSURESensorScanCharacteristic);
                }
                spressure_sensortype = (TextView) rootView.findViewById(R.id.spressure_sensor_type);
                if (SPRESSURESensorTypeCharacteristic != null) {
                    spressure_sensortype.setText(SPRESSURESensorTypeCharacteristic);
                }
                spressure_scan_interval.setOnEditorActionListener(new OnEditorActionListener() {

                    @Override
                    public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                        if (actionId == EditorInfo.IME_ACTION_DONE) {
                            int myNum = 0;

                            try {
                                myNum = Integer.parseInt(stemp_scan_interval.getText().toString());
                            } catch (NumberFormatException nfe) {
                                nfe.printStackTrace();
                            }
                            byte[] convertedBytes = convertingTobyteArray(Integer.toString(myNum));
                            BluetoothLeService.writeCharacteristicNoresponse(
                                    mReadSPRESSURESensorScanCharacteristic, convertedBytes);
                        }
                        return false;
                    }
                });
                Spinner spinner_filterconfiguration = (Spinner) rootView
                        .findViewById(R.id.spressure_filter_configuration);
                // Create an ArrayAdapter using the string array and a
                // default
                // spinner layout
                ArrayAdapter<CharSequence> adapter_filterconfiguration = ArrayAdapter.createFromResource(
                        getActivity(), R.array.filter_configuration_alert_array,
                        android.R.layout.simple_spinner_item);
                // Specify the layout to use when the list of choices
                // appears
                adapter_filterconfiguration
                        .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
                // Apply the adapter to the spinner
                spinner_filterconfiguration.setAdapter(adapter_filterconfiguration);
                spressure_threshold_value = (EditText) rootView.findViewById(R.id.spressure_threshold);
                spressure_threshold_value.setOnEditorActionListener(new OnEditorActionListener() {

                    @Override
                    public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                        if (actionId == EditorInfo.IME_ACTION_DONE) {
                            int myNum = 0;

                            try {
                                myNum = Integer.parseInt(spressure_threshold_value.getText().toString());
                            } catch (NumberFormatException nfe) {
                                nfe.printStackTrace();
                            }
                            byte[] convertedBytes = convertingTobyteArray(Integer.toString(myNum));
                            BluetoothLeService.writeCharacteristicNoresponse(
                                    mReadSPRESSUREThresholdCharacteristic, convertedBytes);
                        }
                        return false;
                    }
                });

            } else {
                spressure_more.setRotation(-90);
                spressure_scan_interval.setText("");
                spressure_sensortype.setText("");
                spressure_threshold_value.setText("");
                CustomSlideAnimation a = new CustomSlideAnimation(spressure_layLayout,
                        CustomSlideAnimation.COLLAPSE);
                height = a.getHeight();
                spressure_layLayout.startAnimation(a);
            }

        }
    });
    ImageButton acc_graph = (ImageButton) rootView.findViewById(R.id.acc_graph);
    setupAccChart(rootView);

    acc_graph.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            if (mACCGraphLayoutParent.getVisibility() != View.VISIBLE) {
                mACCGraphLayoutParent.setVisibility(View.VISIBLE);

            } else {
                mACCGraphLayoutParent.setVisibility(View.GONE);
            }

        }
    });
    ImageButton stemp_graph = (ImageButton) rootView.findViewById(R.id.temp_graph);
    setupTempGraph(rootView);
    stemp_graph.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            if (mTemperatureGraphLayoutParent.getVisibility() != View.VISIBLE) {
                mTemperatureGraphLayoutParent.setVisibility(View.VISIBLE);
            } else {
                mTemperatureGraphLayoutParent.setVisibility(View.GONE);
            }

        }
    });
    ImageButton spressure_graph = (ImageButton) rootView.findViewById(R.id.pressure_graph);
    setupPressureGraph(rootView);

    spressure_graph.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            if (mPressureGraphLayoutParent.getVisibility() != View.VISIBLE) {
                mPressureGraphLayoutParent.setVisibility(View.VISIBLE);

            } else {

                mPressureGraphLayoutParent.setVisibility(View.GONE);
            }

        }
    });
    setHasOptionsMenu(true);
    return rootView;
}

From source file:fr.natoine.model_annotation.AnnotationStatus.java

/**
 * Returns the content of an HTMLForm as describe by the descriptor.
 * This is a default HTMLForm, you should define your own.
 * @return//from  w ww.j a  va 2  s . c  om
 */
public String getHTMLForm(String unique_id) {
    if (descripteur != null) {
        JSONArray _descripteur = getDescripteur();
        int nb_elts = _descripteur.length();
        String _html = "";
        try {
            JSONObject _elt;
            for (int i = 0; i < nb_elts; i++) {
                _elt = _descripteur.getJSONObject(i);
                String _type = _elt.getString("type");
                if (_type.equalsIgnoreCase("ADDED")) //Dans cette version on ne traite pas les ANNOTATED
                {
                    String status = _elt.getString("status");
                    _html = _html.concat("<div class=formelt>");
                    _html = _html.concat("<span class=eltheader>" + status + " : </span>");
                    String className = _elt.getString("className");
                    _html = _html.concat("<div class=formfield name=\"formfield_" + className + "_" + unique_id
                            + "\" id=\"formfield_" + status + "_" + i + "_" + unique_id + "\" >");
                    if (className.equalsIgnoreCase(Post.class.getSimpleName())) {
                        _html = _html.concat(
                                "<textarea rows=3 onfocus=\"this.value=''; this.onfocus=null\" name=\"annotation_added_simpletext_"
                                        + status + "\" >Tapez ici votre texte</textarea>");
                    } else {
                        String cardinalite = _elt.getString("cardinalite");
                        String true_cardinalite = cardinalite.substring(1);
                        true_cardinalite = true_cardinalite.substring(0, true_cardinalite.length() - 1);
                        //System.out.println("[AnnotationStatus.getHTMLForm] true_cardinalite : " + true_cardinalite);
                        int card = 0;
                        if (!true_cardinalite.equalsIgnoreCase("n")) {
                            try {
                                card = Integer.parseInt(true_cardinalite);
                            } catch (NumberFormatException e) {
                                System.out.println(
                                        "[AnnotationStatus.getHTMLForm] true_cardinalite is not a number ...");
                            }
                        }
                        if (className.equalsIgnoreCase(Mood.class.getSimpleName()))
                            _html = formMood(_html, className, status, unique_id, i, _elt, true_cardinalite,
                                    card);
                        else if (className.equalsIgnoreCase(Tag.class.getSimpleName())
                                || className.equalsIgnoreCase(Domain.class.getSimpleName())
                                || className.equalsIgnoreCase(Judgment.class.getSimpleName()))
                            _html = formTags(_html, className, status, unique_id, i, _elt, true_cardinalite,
                                    card);
                    }
                    _html = _html.concat("</div>");
                    _html = _html.concat("</div>");
                }
            }
            return _html;
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            return "";
        }
    } else
        return "";
}

From source file:de.tu_dortmund.ub.api.daia.DaiaOpenUrlEndpoint.java

private String cleanup(String input) {

    String output = "";

    try {//from  ww  w .  j  a  v a 2 s.  co m
        // Quelle: http://la.remifa.so/unicode/latin1.html oder http://www.starkeffects.com/html-symbol-codes.shtml
        output = input;
        output = output.replaceAll("&#x79;", "");
        output = output.replaceAll("&#127;", "'");

        output = output.replaceAll("&#x80;", " EUR");
        output = output.replaceAll("&#128;", " EUR");

        output = output.replaceAll("&#x81;", "");
        output = output.replaceAll("&#129;", "");

        output = output.replaceAll("&#x82;", ",");
        output = output.replaceAll("&#130;", ",");

        output = output.replaceAll("&#x83;", "");
        output = output.replaceAll("&#131;", "");

        output = output.replaceAll("&#x84;", "'");
        output = output.replaceAll("&#132;", "'");

        output = output.replaceAll("&#x85;", "...");
        output = output.replaceAll("&#133;", "...");

        output = output.replaceAll("&#x86;", "");
        output = output.replaceAll("&#134;", "");

        output = output.replaceAll("&#x87;", "");
        output = output.replaceAll("&#135;", "");

        output = output.replaceAll("&#x88;", "");
        output = output.replaceAll("&#136;", "");

        output = output.replaceAll("&#x89;", "");
        output = output.replaceAll("&#137;", "");

        output = output.replaceAll("&#x90;", "");
        output = output.replaceAll("&#144;", "");

        output = output.replaceAll("&#x91;", "'");
        output = output.replaceAll("&#145;", "'");

        output = output.replaceAll("&#x92;", "'");
        output = output.replaceAll("&#146;", "'");

        output = output.replaceAll("&#x93;", "'");
        output = output.replaceAll("&#147;", "'");

        output = output.replaceAll("&#x94;", "'");
        output = output.replaceAll("&#148;", "'");

        output = output.replaceAll("&#x95;", "*");
        output = output.replaceAll("&#149;", "*");
        output = output.replaceAll("\u0095", "*");

        output = output.replaceAll("&#x96;", "-");
        output = output.replaceAll("&#150;", "-");
        output = output.replaceAll("\u0096", "-");

        output = output.replaceAll("&#x97;", "--");
        output = output.replaceAll("&#151;", "--");
        output = output.replaceAll("\u0097", "--");

        output = output.replaceAll("&#x98;", "~");
        output = output.replaceAll("&#152;", "~");
        output = output.replaceAll("\u0098", "~");

        output = output.replaceAll("&#x99;", "&#x2122;");
        output = output.replaceAll("&#153;", "&#x2122;");
        output = output.replaceAll("\u0099", "&#x2122;");

        output = output.replaceAll("&#x9A;", "S");
        output = output.replaceAll("&#154;", "S");
        output = output.replaceAll("\u009A", "S");

        output = output.replaceAll("&#x9B;", ">");
        output = output.replaceAll("&#155;", ">");
        output = output.replaceAll("\u009B", ">");

        output = output.replaceAll("&#x9C;", "");
        output = output.replaceAll("&#156;", "");
        output = output.replaceAll("\u009C", "");

        output = output.replaceAll("&#x9D;", " ");
        output = output.replaceAll("&#156;", " ");
        output = output.replaceAll("\u009D", " ");

        output = output.replaceAll("&#x9E;", "Z");
        output = output.replaceAll("&#157;", "Z");
        output = output.replaceAll("\u009E", "Z");

        output = output.replaceAll("&#x9F;", "Y");
        output = output.replaceAll("&#158;", "Y");
        output = output.replaceAll("\u009F", "Y");
    } catch (NumberFormatException e) {
        e.printStackTrace();
    }

    return output;
}

From source file:no.ntnu.idi.socialhitchhiking.myAccount.MyAccountCar.java

@Override
public void onStop() {
    if (isCarInitialized) {
        // Checks to see what is changed
        if (!seatsAvailable.toString().equals(seatsText.getText().toString())) {
            seatsChanged = true;/*from  www  .j a v a 2s .co m*/
        }
        if (!carName.getText().toString().equals(carNameString) || bar.getRating() != comfort) {
            carChanged = true;
        }

        // If the user has entered a new number of available seats
        if (seatsText.getText().length() > 0) {
            try {
                seatsAvailable = Integer.parseInt(seatsText.getText().toString());
            } catch (NumberFormatException e) {
                Toast.makeText(this, "Please enter an integer value in Available seats", Toast.LENGTH_SHORT)
                        .show();
                return;
            }
        } else {
            seatsAvailable = 0;
        }
        // Getting car ID
        id = user.getCarId();
        // Setting new car name
        if (carName.getText().toString().length() > 0) {
            carNameString = carName.getText().toString();
        } else {
            carNameString = "";
        }
        // Setting new comfort
        comfort = bar.getRating();

        // Adds the picture of the car if a picture exists
        if (btm != null && carChanged) {
            try {
                ByteArrayOutputStream stream = new ByteArrayOutputStream();
                btm.compress(Bitmap.CompressFormat.PNG, 100, stream);
                byteArray = stream.toByteArray();
                stream.close();
                stream = null;
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

        // Update seats in the database if it is changed
        if (seatsChanged) {
            TripPreferences preferences = prefRes.getPreferences();
            preferences.setSeatsAvailable(seatsAvailable);
            Request prefReq = new PreferenceRequest(RequestType.UPDATE_PREFERENCE, user, preferences);
            try {
                RequestTask.sendRequest(prefReq, getApp());
            } catch (ClientProtocolException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (ExecutionException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
        // If the user has a car, update the info if it has changed
        if (user.getCarId() != 0 && carChanged) {
            // Updating the car info to the database
            car = new Car(id, carNameString, comfort, byteArray);
            Request req = new CarRequest(RequestType.UPDATE_CAR, getApp().getUser(), car);
            try {
                RequestTask.sendRequest(req, getApp());
            } catch (ClientProtocolException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (ExecutionException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
        // If the user doesn't have a car, create one and add it to the database
        else if (user.getCarId() == 0 && carChanged) {
            // Adding the new car to the database
            car = new Car(id, carNameString, comfort, byteArray);
            Request req = new CarRequest(RequestType.CREATE_CAR, getApp().getUser(), car);
            try {
                RequestTask.sendRequest(req, getApp());
            } catch (ClientProtocolException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (ExecutionException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }
    super.onStop();
}

From source file:org.monome.pages.MIDISequencerPage.java

public void actionPerformed(ActionEvent e) {
    System.out.println(e.getActionCommand());
    if (e.getActionCommand().equals("Set MIDI Output")) {
        String[] midiOutOptions = this.monome.getMidiOutOptions();
        String deviceName = (String) JOptionPane.showInputDialog(this.monome, "Choose a MIDI Output to use",
                "Set MIDI Output", JOptionPane.PLAIN_MESSAGE, null, midiOutOptions, "");

        if (deviceName == null) {
            return;
        }/*from  ww  w.j  a  v a2 s.co  m*/

        this.addMidiOutDevice(deviceName);
    }
    if (e.getActionCommand().equals("Update Preferences")) {
        this.noteNumbers[0] = this.noteToMidiNumber(this.row1tf.getText());
        this.noteNumbers[1] = this.noteToMidiNumber(this.row2tf.getText());
        this.noteNumbers[2] = this.noteToMidiNumber(this.row3tf.getText());
        this.noteNumbers[3] = this.noteToMidiNumber(this.row4tf.getText());
        this.noteNumbers[4] = this.noteToMidiNumber(this.row5tf.getText());
        this.noteNumbers[5] = this.noteToMidiNumber(this.row6tf.getText());
        this.noteNumbers[6] = this.noteToMidiNumber(this.row7tf.getText());
        this.noteNumbers[7] = this.noteToMidiNumber(this.row8tf.getText());
        this.noteNumbers[8] = this.noteToMidiNumber(this.row9tf.getText());
        this.noteNumbers[9] = this.noteToMidiNumber(this.row10tf.getText());
        this.noteNumbers[10] = this.noteToMidiNumber(this.row11tf.getText());
        this.noteNumbers[11] = this.noteToMidiNumber(this.row12tf.getText());
        this.noteNumbers[12] = this.noteToMidiNumber(this.row13tf.getText());
        this.noteNumbers[13] = this.noteToMidiNumber(this.row14tf.getText());
        this.noteNumbers[14] = this.noteToMidiNumber(this.row15tf.getText());
        this.midiChannel = this.channelTF.getText();
        try {
            this.setBankSize(Integer.parseInt(this.bankSizeTF.getText()));
        } catch (NumberFormatException nfe) {
            nfe.printStackTrace();
        }
    }
}

From source file:com.znsx.cms.web.controller.UserController.java

@InterfaceDescription(logon = true, method = "Update_User_Info", cmd = "1022")
@RequestMapping("/update_user_info.xml")
public void updateUserInfo(HttpServletRequest request, HttpServletResponse response) throws Exception {
    String userId = request.getParameter("userId");
    if (StringUtils.isBlank(userId)) {
        throw new BusinessException(ErrorCode.PARAMETER_NOT_FOUND, "missing [userId]");
    }/*from  w w w  .  j a va2 s .c  o m*/

    String password = request.getParameter("password");

    String name = request.getParameter("name");
    if (null != name && StringUtils.isBlank(name)) {
        throw new BusinessException(ErrorCode.PARAMETER_INVALID, "Can not modify name to empty !");
    }

    Short sex = null;
    String sexString = request.getParameter("sex");
    if (StringUtils.isNotBlank(sexString)) {
        try {
            sex = Short.parseShort(sexString);
        } catch (NumberFormatException e) {
            e.printStackTrace();
            throw new BusinessException(ErrorCode.PARAMETER_INVALID,
                    "Parameter sex[" + sexString + "] invalid !");
        }
    }

    String email = request.getParameter("email");

    String phone = request.getParameter("phone");

    String address = request.getParameter("address");

    userManager.updateUserInfo(userId, password, name, sex, email, phone, address);

    BaseDTO dto = new BaseDTO();
    dto.setCmd("1022");
    dto.setMethod("Update_User_Info");
    Document doc = new Document();
    Element root = ElementUtil.createElement("Response", dto, null, null);
    doc.setRootElement(root);
    writePageWithContentLength(response, doc);
}

From source file:com.znsx.cms.web.controller.UserController.java

@InterfaceDescription(logon = true, method = "List_User", cmd = "2005")
@RequestMapping("/list_user.json")
public void listUser(HttpServletRequest request, HttpServletResponse response) throws Exception {
    String organId = request.getParameter("organId");

    String name = request.getParameter("name");
    String logonName = request.getParameter("logonName");
    Integer startIndex = 0;//from w w  w  .  ja v  a2  s. c o m
    String start = request.getParameter("startIndex");
    if (StringUtils.isNotBlank(start)) {
        try {
            startIndex = Integer.parseInt(start);
        } catch (NumberFormatException n) {
            n.printStackTrace();
            throw new BusinessException(ErrorCode.PARAMETER_INVALID,
                    "Parameter startIndex[" + start + "] invalid !");
        }
    }

    Integer limit = 1000;
    String limitString = request.getParameter("limit");
    if (StringUtils.isNotBlank(limitString)) {
        try {
            limit = Integer.parseInt(limitString);
        } catch (NumberFormatException n) {
            n.printStackTrace();
            throw new BusinessException(ErrorCode.PARAMETER_INVALID,
                    "Parameter limit[" + limitString + "] invalid !");
        }
    }

    Integer totalCount = userManager.userTotalCount(organId, name, logonName);
    // omc?????
    if (startIndex != 0 && totalCount.intValue() != 0) {
        if (startIndex.intValue() >= totalCount.intValue()) {
            startIndex -= ((startIndex.intValue() - totalCount.intValue()) / limit + 1) * limit;
        }
    }
    List<GetUserVO> userList = userManager.listUser(organId, name, logonName, startIndex, limit);

    ListUserDTO dto = new ListUserDTO();
    dto.setCmd("2005");
    dto.setMethod("List_User");
    dto.setUserList(userList);
    dto.setTotalCount(totalCount + "");
    writePage(response, dto);
}

From source file:com.znsx.cms.web.controller.UserController.java

@InterfaceDescription(logon = true, method = "List_Online_User_By_User_Id", cmd = "2021")
@RequestMapping("/list_online_user_by_user_id.json")
public void listOnlineUserByUserId(HttpServletRequest request, HttpServletResponse response) throws Exception {
    String userId = request.getParameter("userId");
    if (StringUtils.isBlank(userId)) {
        throw new BusinessException(ErrorCode.PARAMETER_NOT_FOUND, "missing [userId]");
    }/*from w  w  w .j a va  2  s  .c om*/
    Integer startIndex = 0;
    String startIndexString = request.getParameter("startIndex");
    if (StringUtils.isNotBlank(startIndexString)) {
        try {
            startIndex = Integer.parseInt(startIndexString);
        } catch (NumberFormatException be) {
            be.printStackTrace();
            throw new BusinessException(ErrorCode.PARAMETER_INVALID,
                    "Parameter startIndex[" + startIndexString + "] invalid !");
        }
    }
    Integer limit = 1000;
    String limitString = request.getParameter("limit");
    if (StringUtils.isNotBlank(limitString)) {
        try {
            limit = Integer.parseInt(limitString);
        } catch (NumberFormatException be) {
            be.printStackTrace();
            throw new BusinessException(ErrorCode.PARAMETER_INVALID,
                    "Parameter limit[" + limitString + "] invalid !");
        }
    }

    int totalCount = userManager.countOnlineUserByUserId(userId);

    // omc?????
    if (startIndex != 0 && totalCount != 0) {
        if (startIndex.intValue() >= totalCount) {
            startIndex -= ((startIndex.intValue() - totalCount) / limit + 1) * limit;
        }
    }

    List<ListOnlineUsersVO> list = userManager.listOnlineUserByUserId(userId, startIndex, limit);

    ListOnlineUsersDTO dto = new ListOnlineUsersDTO();
    dto.setUserList(list);
    dto.setTotalCount(totalCount + "");

    dto.setCmd("2021");
    dto.setMethod("List_Online_User_By_User_Id");
    writePage(response, dto);
}