Example usage for android.os Message getData

List of usage examples for android.os Message getData

Introduction

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

Prototype

public Bundle getData() 

Source Link

Document

Obtains a Bundle of arbitrary data associated with this event, lazily creating it if necessary.

Usage

From source file:org.zywx.wbpalmstar.engine.universalex.EUExWindow.java

@Override
public void onHandleMessage(Message msg) {
    if (mBrwView == null || mBrwView.getBrowserWindow() == null || msg == null) {
        return;//from  ww  w.  jav a 2  s  .  co m
    }
    EBrowserWindow eBrwWin = mBrwView.getBrowserWindow();
    String[] param = msg.getData().getStringArray(TAG_BUNDLE_PARAM);
    switch (msg.what) {
    case MSG_FUNCTION_CLOSE:
        if (param != null)
            closeMsg(param);
        break;
    case MSG_FUNCTION_CLOSE_ABOVE_WND_BY_NAME:
        String windowName = msg.getData().getString(TAG_BUNDLE_PARAM_NAME);
        eBrwWin.closeAboveWndByName(windowName);
        break;
    case MSG_FUNCTION_OPEN:
        if (param != null)
            openMsg(param);
        break;
    case MSG_FUNCTION_OPEN_POP:
        if (param != null)
            openPopoverMsg(param);
        break;
    case MSG_FUNCTION_FORWARD:
        eBrwWin.goForward();
        break;
    case MSG_FUNCTION_BACK:
        eBrwWin.goBack();
        break;
    case MSG_FUNCTION_PAGEFORWARD:
        mBrwView.goForward();
        break;
    case MSG_FUNCTION_PAGEBACK:
        mBrwView.goBack();
        break;
    case MSG_FUNCTION_WINDOWFORWARD:
        if (param != null)
            windowForwardMsg(param);
        break;
    case MSG_FUNCTION_WINDOWBACK:
        if (param != null)
            windowBackMsg(param);
        break;
    case MSG_FUNCTION_SETWINDOWFRAME:
        if (param != null)
            setWindowFrameMsg(param);
        break;
    case MSG_FUNCTION_OPENSLIBING:
        if (param != null)
            openSlibingMsg(param);
        break;
    case MSG_FUNCTION_CLOSESLIBING:
        if (param != null)
            closeSlibingMsg(param);
        break;
    case MSG_FUNCTION_SHOWSLIBING:
        if (param != null)
            showSlibingMsg(param);
        break;
    case MSG_FUNCTION_LOADOBFUSCATIONDATA:
        if (param != null)
            loadObfuscationDataMsg(param);
        break;
    case MSG_FUNCTION_TOAST:
        if (param != null)
            toastMsg(param);
        break;
    case MSG_FUNCTION_CLOSETOAST:
        eBrwWin.closeToast();
        break;
    case MSG_FUNCTION_CLOSEPOPOVER:
        if (param != null)
            closePopoverMsg(param);
        break;
    case MSG_FUNCTION_SETPOPOVERFRAME:
        if (param != null)
            setPopoverFrameMsg(param);
        break;
    case MSG_FUNCTION_OPENMULTIPOPOVER:
        if (param != null)
            openMultiPopoverMsg(param);
        break;
    case MSG_FUNCTION_CLOSEMULTIPOPOVER:
        if (param != null)
            closeMultiPopoverMsg(param);
        break;
    case MSG_FUNCTION_SETMULTIPOPOVERFRAME:
        if (param != null)
            setMultiPopoverFrameMsg(param);
        break;
    case MSG_FUNCTION_SETSELECTEDPOPOVERINMULTIWINDOW:
        if (param != null)
            setSelectedPopOverInMultiWindowMsg(param);
        break;
    case MSG_FUNCTION_BRINGTOFRONT:
        eBrwWin.bringToFront(mBrwView);
        break;
    case MSG_FUNCTION_SENDTOBACK:
        eBrwWin.sendToBack(mBrwView);
        break;
    case MSG_FUNCTION_INSERTABOVE:
        if (param != null)
            insertAboveMsg(param);
        break;
    case MSG_FUNCTION_INSERTBELOW:
        if (param != null)
            insertBelowMsg(param);
        break;
    case MSG_FUNCTION_BRINGPOPOVERTOFRONT:
        if (param != null)
            bringPopoverToFrontMsg(param);
        break;
    case MSG_FUNCTION_SENDPOPOVERTOBACK:
        if (param != null)
            sendPopoverToBackMsg(param);
        break;
    case MSG_FUNCTION_INSERTPOPOVERABOVEPOPOVER:
        if (param != null)
            insertPopoverAbovePopoverMsg(param);
        break;
    case MSG_FUNCTION_INSERTPOPOVERBELOWPOPOVER:
        if (param != null)
            insertPopoverBelowPopoverMsg(param);
        break;
    case MSG_FUNCTION_INSERTWINDOWABOVEWINDOW:
        if (param != null)
            insertWindowAboveWindowMsg(param);
        break;
    case MSG_FUNCTION_INSERTWINDOWBELOWWINDOW:
        if (param != null)
            insertWindowBelowWindowMsg(param);
        break;
    case MSG_FUNCTION_SETORIENTATION:
        if (param != null)
            setOrientationMsg(param);
        break;
    case MSG_FUNCTION_SETAUTOROTATEENABLE:
        if (param != null)
            setAutorotateEnableMsg(param);
        break;
    case MSG_FUNCTION_SETSLIDINGWIN:
        handleSetSlidingWin(param);
        break;
    case MSG_FUNCTION_SETSLIDINGWIN_ENABLE:
        hanldeSetSlidingWindowEnabled(param);
        break;
    case MSG_FUNCTION_TOGGLE_SLIDINGWIN:
        hanldeToggleSlidingWindow(param);
        break;
    case MSG_FUNCTION_GET_SLIDING_WINDOW_STATE:
        hanldeGetSlidingWindowState();
        break;
    case MSG_FUNCTION_REFRESH:
        String url = mBrwView.getRelativeUrl();
        mBrwView.loadUrl(url);
        mBrwView.postDelayed(new Runnable() {
            @Override
            public void run() {
                mBrwView.clearHistory();
            }
        }, 1000);
        break;
    case MSG_FUNCTION_RELOAD:
        mBrwView.reload();
        break;
    case MSG_SET_WINDOW_HIDDEN:
        setWindowHiddenMsg(param);
        break;
    case MSG_OPEN_AD:
        openAdMsg(param);
        break;
    case MSG_SHOW_SOFT_KEYBOARD:
        showSoftKeyboardMsg();
        break;
    case MSG_ACTION_SHEET:
        actionSheetMsg(param);
        break;
    case MSG_STATUS_BAR_NOTIFICATION:
        statusBarNotificationMsg(param);
        break;
    case MSG_CREATE_PROGRESS_DIALOG:
        createProgressDialogMsg(param);
        break;
    case MSG_DESTROY_PROGRESS_DIALOG:
        destroyProgressDialogMsg();
        break;
    case MSG_POST_GLOBAL_NOTIFICATION:
        postGlobalNotificationMsg(param);
        break;
    case MSG_SUBSCRIBE_CHANNEL_NOTIFICATION:
        subscribeChannelNotificationMsg(param);
        break;
    case MSG_PUBLISH_CHANNEL_NOTIFICATION:
        publishChannelNotificationMsg(param);
        break;
    case MSG_PUBLISH_CHANNEL_NOTIFICATION_FOR_JSON:
        publishChannelNotificationForJsonMsg(param);
        break;
    case MSG_SET_IS_SUPPORT_SLIDE_CALLBACK:
        setIsSupportSlideCallbackMsg(param);
        break;
    case MSG_SET_IS_SUPPORT_SWIPE_CALLBACK:
        setIsSupportSwipeCallbackMsg(param);
        break;
    case MSG_DISTURB_LONG_PRESS_GESTURE:
        disturbLongPressGestureMsg(param);
        break;
    case MSG_PLUGINVIEW_CONTAINER_CREATE:
        createPluginViewContainerMsg(param);
        break;
    case MSG_PLUGINVIEW_CONTAINER_CLOSE:
        closePluginViewContainerMsg(param);
        break;
    case MSG_PLUGINVIEW_CONTAINER_SET:
        setPageInContainerMsg(param);
        break;
    case MSG_PLUGINVIEW_CONTAINER_SHOW:
        showPluginViewContainerMsg(param);
        break;
    case MSG_PLUGINVIEW_CONTAINER_HIDE:
        hidePluginViewContainerMsg(param);
        break;
    default:
        break;
    }
}

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

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

    try {// w w w .  j  a va 2 s. c o  m
        dialog = new ProgressDialog(getActivity());
        dialog.setTitle("");
        dialog.setMessage("Checking Details.....");
        dialog.setCancelable(true);
        dialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
            @Override
            public void onCancel(DialogInterface dialogInterface) {
                Intent in = new Intent();
                getActivity().setResult(2, in);
                getActivity().finish();
            }
        });
    } catch (Exception e) {
        BugSenseHandler.sendExceptionMessage("ZaasSettingsFragment", "onCreate", e);
    }

    settings = PreferenceManager.getDefaultSharedPreferences(getActivity());

    handler = new Handler() {
        public void handleMessage(Message msg) {
            if (msg.what == RhybuddHandlers.msg_initial_login_successful && API != null)// && API.getLoggedInStatus() == true
            {
                SharedPreferences.Editor editor = settings.edit();
                editor.putBoolean("credentialsSuccess", true);
                editor.commit();

                try {
                    dialog.setMessage("Logged in successfully.\n\nPreparing database...");
                } catch (Exception e) {
                    BugSenseHandler.sendExceptionMessage("ZaasSettingsFragment", "OnCreate", e);
                    Toast.makeText(getActivity(), "Logged in Successfully. Preparing Database!",
                            Toast.LENGTH_SHORT).show();
                }

                try {
                    zenossCredentials.Zaas = true;
                    zenossCredentials.saveCredentials(getActivity());
                    handler.sendEmptyMessage(RhybuddHandlers.msg_caching_complete);
                } catch (Exception e) {
                    BugSenseHandler.sendExceptionMessage("ZaasSettingsFragment", "General success path", e);
                    //HandleException(e, "Initialising the Database failed. An error message has been logged.");
                }
            } else if (msg.what == RhybuddHandlers.msg_events_cached) {
                dialog.setMessage("Events Cached! Now caching Devices.\r\nPlease wait...");
            } else if (msg.what == RhybuddHandlers.msg_caching_complete) {
                try {
                    dialog.dismiss();
                } catch (Exception e) {
                    //Not much else we can do here :/
                    BugSenseHandler.sendExceptionMessage("ZaasSettingsFragment",
                            "Dismissing dialog in msg_caching_complete", e);
                }

                try {
                    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
                    builder.setMessage(
                            "Would you like to configure Rhybudd Push to enable instant alert delivery?")
                            .setTitle("Extra Configuration").setCancelable(false)
                            .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog, int id) {
                                    ((FirstRunSettings) getActivity()).setPushTab(2);
                                    alertDialog.cancel();
                                }
                            }).setNegativeButton("No", new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog, int id) {
                                    alertDialog.cancel();
                                    Intent in = new Intent();
                                    in.putExtra("forceRefresh", true);
                                    getActivity().setResult(1, in);
                                    getActivity().finish();
                                }
                            });
                    alertDialog = builder.create();
                    alertDialog.show();
                } catch (Exception e) {
                    BugSenseHandler.sendExceptionMessage("ZaasSettingsFragment", "handler", e);
                }

            } else if (msg.what == RhybuddHandlers.msg_caching_complete) {
                try {
                    dialog.setMessage("Caching complete!\r\nVerifying.");
                } catch (Exception e) {
                    BugSenseHandler.sendExceptionMessage("ZaasSettingsFragment", "handler msg_caching_complete",
                            e);
                }
            } else if (msg.what == RhybuddHandlers.msg_initial_verify_debug_output) {
                try {
                    debugOutput.setText(debugOutput.getText() + s.format(new Date()) + " "
                            + msg.getData().getString(ZenossAPI.MSG_DEBUG) + "\r\n");
                } catch (Exception e) {
                    BugSenseHandler.sendExceptionMessage("ZaasSettingsFragment",
                            "handler msg_initial_verify_debug_output", e);
                }
            } else if (msg.what == RhybuddHandlers.msg_initial_verify_error) {
                try {
                    dialog.dismiss();
                } catch (Exception e) {
                    //Not much else we can do here :/
                    BugSenseHandler.sendExceptionMessage("ZaasSettingsFragment",
                            "Dismissing dialog in msg_initial_verify_error", e);
                }

                try {
                    Toast.makeText(getActivity(),
                            "An error was encountered. The debug output can be seen below", Toast.LENGTH_SHORT)
                            .show();
                    debugLabel.startAnimation(
                            AnimationUtils.loadAnimation(getActivity(), android.R.anim.fade_in));
                    debugLabel.setVisibility(View.VISIBLE);
                    debugOutput.startAnimation(
                            AnimationUtils.loadAnimation(getActivity(), android.R.anim.fade_in));
                    debugOutput.setVisibility(View.VISIBLE);
                } catch (Exception e) {
                    BugSenseHandler.sendExceptionMessage("ZaasSettingsFragment", "setting debug", e);
                    try {
                        Toast.makeText(getActivity(), "An unknown error occured. It has been reported.",
                                Toast.LENGTH_SHORT).show();
                    } catch (Exception e1) {
                        BugSenseHandler.sendExceptionMessage("ZaasSettingsFragment",
                                "Displaying toast with error message", e1);
                    }
                }
            } else {
                try {
                    dialog.dismiss();
                } catch (Exception e) {
                    //Not much else we can do here :/
                    BugSenseHandler.sendExceptionMessage("ZaasSettingsFragment",
                            "Dismissing dialog in final handler else", e);
                }

                try {
                    Toast.makeText(getActivity(), "Login Failed - Please check details.", Toast.LENGTH_SHORT)
                            .show();
                    debugOutput.setVisibility(View.VISIBLE);
                } catch (Exception e) {
                    BugSenseHandler.sendExceptionMessage("ZaasSettingsFragment", "setting debug", e);
                }
            }
        }
    };
}

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

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

    try {//from   w ww.j a v  a2  s . c o m
        dialog = new ProgressDialog(getActivity());
        dialog.setTitle("");
        dialog.setMessage("Checking Details.....");
        dialog.setCancelable(true);
        dialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
            @Override
            public void onCancel(DialogInterface dialogInterface) {
                Intent in = new Intent();
                getActivity().setResult(2, in);
                getActivity().finish();
            }
        });
    } catch (Exception e) {
        BugSenseHandler.sendExceptionMessage("CoreSettingsFragment", "onCreate", e);
    }

    try {
        settings = PreferenceManager.getDefaultSharedPreferences(getActivity());
    } catch (Exception e) {
        BugSenseHandler.sendExceptionMessage("CoreSettingsFragment", "onCreate", e);
    }

    handler = new Handler() {
        public void handleMessage(Message msg) {
            if (msg.what == RhybuddHandlers.msg_initial_login_successful && API != null)// && API.getLoggedInStatus() == true
            {
                if (null != settings) {
                    SharedPreferences.Editor editor = settings.edit();
                    editor.putBoolean("credentialsSuccess", true);
                    editor.commit();
                }

                try {
                    dialog.setMessage("Logged in successfully.\n\nPreparing database...");
                } catch (Exception e) {
                    //BugSenseHandler.log("InitialSettings", e);
                    Toast.makeText(getActivity(), "Logged in Successfully. Preparing Database!",
                            Toast.LENGTH_SHORT).show();
                }

                try {
                    zenossCredentials.saveCredentials(getActivity());
                    handler.sendEmptyMessage(RhybuddHandlers.msg_caching_complete);
                } catch (Exception e) {
                    BugSenseHandler.sendExceptionMessage("CoreSettingsFragment", "General success path", e);
                    //HandleException(e, "Initialising the Database failed. An error message has been logged.");
                }
            } else if (msg.what == RhybuddHandlers.msg_events_cached) {
                try {
                    dialog.setMessage("Events Cached! Now caching Devices.\r\nPlease wait...");
                } catch (Exception e) {
                    BugSenseHandler.sendExceptionMessage("CoreSettingsFragment", "onCreate", e);
                }
            } else if (msg.what == RhybuddHandlers.msg_caching_complete) {
                try {
                    dialog.dismiss();
                } catch (Exception e) {
                    //Not much else we can do here :/
                    BugSenseHandler.sendExceptionMessage("CoreSettingsFragment",
                            "Dismissing dialog in msg_caching_complete", e);
                }
                String pushKey = "";

                try {
                    pushKey = PreferenceManager.getDefaultSharedPreferences(getActivity())
                            .getString(ZenossAPI.PREFERENCE_PUSHKEY, "");
                } catch (Exception e) {
                    BugSenseHandler.sendExceptionMessage("CoreSettingsFragment", "onCreate", e);
                    pushKey = "";
                }

                if (pushKey.equals("")) {
                    try {
                        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
                        builder.setMessage(
                                "Would you like to configure Rhybudd Push to enable instant alert delivery?")
                                .setTitle("Extra Configuration").setCancelable(false)
                                .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                                    public void onClick(DialogInterface dialog, int id) {
                                        ((FirstRunSettings) getActivity()).setPushTab(2);
                                        alertDialog.cancel();
                                    }
                                }).setNegativeButton("No", new DialogInterface.OnClickListener() {
                                    public void onClick(DialogInterface dialog, int id) {
                                        alertDialog.cancel();
                                        Intent in = new Intent();
                                        in.putExtra("forceRefresh", true);
                                        getActivity().setResult(1, in);
                                        getActivity().finish();
                                    }
                                });
                        alertDialog = builder.create();
                        alertDialog.show();
                    } catch (Exception e) {
                        BugSenseHandler.sendExceptionMessage("CoreSettingsFragment", "onCreate", e);
                    }
                } else {
                    Intent in = new Intent();
                    in.putExtra("forceRefresh", true);
                    getActivity().setResult(1, in);
                    getActivity().finish();
                }
            } else if (msg.what == RhybuddHandlers.msg_caching_complete) {
                try {
                    dialog.setMessage("Caching complete!\r\nVerifying.");
                } catch (Exception e) {
                    BugSenseHandler.sendExceptionMessage("CoreSettingsFragment", "onCreate", e);
                }
            } else if (msg.what == RhybuddHandlers.msg_initial_verify_debug_output) {
                try {
                    EditText debugOutput = (EditText) getActivity().findViewById(R.id.debugOutput);
                    debugOutput.setText(debugOutput.getText() + s.format(new Date()) + " "
                            + msg.getData().getString(ZenossAPI.MSG_DEBUG) + "\r\n");
                } catch (NullPointerException npe) {
                    BugSenseHandler.sendExceptionMessage("CoreSettingsFragment",
                            "Displaying toast with error message", npe);
                    try {
                        Toast.makeText(getActivity(),
                                "An unknown error occured trying to display some debug output. It has been reported",
                                Toast.LENGTH_LONG).show();
                    } catch (Exception ie) {
                        BugSenseHandler.sendExceptionMessage("CoreSettingsFragment", "Error Displaying toast",
                                ie);
                    }
                } catch (Exception e) {
                    BugSenseHandler.sendExceptionMessage("CoreSettingsFragment",
                            "msg_initial_verify_debug_output went very wrong", e);
                }
            } else if (msg.what == RhybuddHandlers.msg_initial_verify_error) {
                //((TextView) getActivity().findViewById(R.id.debugOutput)).setText(msg.getData().getString("exception") + "\n");

                try {
                    dialog.dismiss();
                } catch (Exception e) {
                    //Not much else we can do here :/
                    BugSenseHandler.sendExceptionMessage("CoreSettingsFragment",
                            "Dismissing dialog in msg_initial_verify_error", e);
                }

                try {
                    Toast.makeText(getActivity(),
                            "An error was encountered. The debug output can be seen below", Toast.LENGTH_SHORT)
                            .show();
                    ((TextView) getActivity().findViewById(R.id.debugLabel)).startAnimation(
                            AnimationUtils.loadAnimation(getActivity(), android.R.anim.fade_in));
                    ((TextView) getActivity().findViewById(R.id.debugLabel)).setVisibility(View.VISIBLE);
                    ((EditText) getActivity().findViewById(R.id.debugOutput)).startAnimation(
                            AnimationUtils.loadAnimation(getActivity(), android.R.anim.fade_in));
                    ((EditText) getActivity().findViewById(R.id.debugOutput)).setVisibility(View.VISIBLE);
                } catch (Exception e) {
                    BugSenseHandler.sendExceptionMessage("CoreSettingsFragment",
                            "Displaying toast with error message", e);
                    Toast.makeText(getActivity(), "An unknown error occured. It has been reported.",
                            Toast.LENGTH_SHORT).show();
                }
            } else {
                try {
                    dialog.dismiss();
                } catch (Exception e) {
                    //Not much else we can do here :/
                    BugSenseHandler.sendExceptionMessage("CoreSettingsFragment",
                            "Dismissing dialog in final handler else", e);
                }

                Toast.makeText(getActivity(), "Login Failed - Please check details.", Toast.LENGTH_SHORT)
                        .show();
                ((EditText) getActivity().findViewById(R.id.debugOutput)).setVisibility(View.VISIBLE);
            }
        }
    };
}

From source file:com.mobilinkd.tncconfig.TncConfig.java

private void createHandler() {
    // The Handler that gets information back from the BluetoothTncService
    mHandler = new Handler() {
        @Override//from w w  w .j a v  a  2  s  .c o m
        public void handleMessage(Message msg) {
            byte[] buffer = null;
            switch (msg.what) {
            case MESSAGE_STATE_CHANGE:
                if (D)
                    Log.i(TAG, "MESSAGE_STATE_CHANGE: " + msg.arg1);
                switch (msg.arg1) {
                case BluetoothTncService.STATE_CONNECTED:
                    onBluetoothConnected();
                    break;
                case BluetoothTncService.STATE_CONNECTING:
                    onBluetoothConnecting();
                    break;
                case BluetoothTncService.STATE_NONE:
                    onBluetoothDisconnected();
                    break;
                }
                break;
            case MESSAGE_OUTPUT_VOLUME:
                mOutputVolume = msg.arg1;
                if (D)
                    Log.d(TAG, "output volume: " + mOutputVolume);
                break;
            case MESSAGE_TX_DELAY:
                TncConfig.this.mTxDelay = msg.arg1;
                if (D)
                    Log.d(TAG, "tx delay: " + msg.arg1);
                break;
            case MESSAGE_PERSISTENCE:
                TncConfig.this.mPersistence = msg.arg1;
                if (D)
                    Log.d(TAG, "persistence: " + msg.arg1);
                break;
            case MESSAGE_SLOT_TIME:
                TncConfig.this.mSlotTime = msg.arg1;
                if (D)
                    Log.d(TAG, "slot time: " + msg.arg1);
                break;
            case MESSAGE_TX_TAIL:
                TncConfig.this.mTxTail = msg.arg1;
                if (D)
                    Log.d(TAG, "tx tail: " + msg.arg1);
                break;
            case MESSAGE_DUPLEX:
                TncConfig.this.mDuplex = (msg.arg1 != 0);
                if (D)
                    Log.d(TAG, "duplex: " + TncConfig.this.mDuplex);
                break;
            case MESSAGE_SQUELCH_LEVEL:
                TncConfig.this.mDcd = (msg.arg1 == 0);
                if (D)
                    Log.d(TAG, "DCD: " + TncConfig.this.mDcd);
                break;
            case MESSAGE_VERBOSITY:
                TncConfig.this.mVerbose = (msg.arg1 != 0);
                if (D)
                    Log.d(TAG, "info: " + TncConfig.this.mVerbose);
                break;
            case MESSAGE_BT_CONN_TRACK:
                TncConfig.this.mHasConnTrack = true;
                TncConfig.this.mConnTrack = (msg.arg1 != 0);
                if (D)
                    Log.d(TAG, "bt conn track: " + TncConfig.this.mConnTrack);
                break;
            case MESSAGE_INPUT_ATTEN:
                TncConfig.this.mHasInputAtten = true;
                TncConfig.this.mInputAtten = (msg.arg1 != 0);
                if (D)
                    Log.d(TAG, "input atten: " + msg.arg1);
                break;
            case MESSAGE_BATTERY_LEVEL:
                TncConfig.this.mPowerMenuItem.setEnabled(true);
                buffer = (byte[]) msg.obj;
                TncConfig.this.mBatteryLevel = buffer[0] * 256 + buffer[1];
                if (D)
                    Log.d(TAG, "battery level: " + TncConfig.this.mBatteryLevel + "mV");
                break;
            case MESSAGE_HW_VERSION:
                buffer = (byte[]) msg.obj;
                String hwVersion = new String(buffer);
                TncConfig.this.hwVersion = hwVersion;
                if (D)
                    Log.d(TAG, "hw version: " + hwVersion);
                break;
            case MESSAGE_FW_VERSION:
                buffer = (byte[]) msg.obj;
                String fwVersion = new String(buffer);
                TncConfig.this.mFirmwareVersion = fwVersion;
                TncConfig.this.mFirmwareVersionView.setText(TncConfig.this.mFirmwareVersion);
                if (D)
                    Log.d(TAG, "fw version: " + fwVersion);
                break;
            case MESSAGE_INPUT_VOLUME:
                synchronized (this) {
                    if (TncConfig.this.mAudioInputFragment != null) {
                        int inputVolume = msg.arg1;
                        double level = (Math.log((double) inputVolume) / Math.log(2.0)) / 8.0;
                        TncConfig.this.mAudioInputFragment.setInputVolume(level);
                        // if(D) Log.d(TAG, "input volume: " + level);
                    }
                }
                break;
            case MESSAGE_DEVICE_NAME:
                // save the connected device's name
                mConnectedDeviceName = msg.getData().getString(DEVICE_NAME);
                Toast.makeText(getApplicationContext(), "Connected to " + mConnectedDeviceName,
                        Toast.LENGTH_SHORT).show();
                break;
            case MESSAGE_USB_POWER_ON:
                mPowerControl = true;
                TncConfig.this.mPowerOn = (msg.arg1 == 1);
                if (D)
                    Log.d(TAG, "power on: " + TncConfig.this.mPowerOn);
                break;
            case MESSAGE_USB_POWER_OFF:
                mPowerControl = true;
                TncConfig.this.mPowerOff = (msg.arg1 == 1);
                if (D)
                    Log.d(TAG, "power off: " + TncConfig.this.mPowerOff);
                break;
            case MESSAGE_PTT_STYLE:
                TncConfig.this.mHasPttStyle = true;
                TncConfig.this.mPttStyle = msg.arg1;
                if (D)
                    Log.d(TAG, "ptt style: " + TncConfig.this.mPttStyle);
                break;
            case MESSAGE_CAPABILITIES:
                buffer = (byte[]) msg.obj;
                if (buffer.length > 1) {
                    TncConfig.this.mHasEeprom = ((buffer[1] & 0x02) == 0x02);
                    TncConfig.this.mSaveButton
                            .setVisibility(TncConfig.this.mHasEeprom ? Button.VISIBLE : Button.GONE);
                    if (D)
                        Log.d(TAG, "eeprom save:" + TncConfig.this.mHasEeprom);
                }
                break;
            case MESSAGE_TOAST:
                Toast.makeText(getApplicationContext(), msg.getData().getString(TOAST), Toast.LENGTH_SHORT)
                        .show();
                break;
            }
        }
    };
}

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

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

    //Log.e("onCreate","onCreate");
    setHasOptionsMenu(true);/*  w ww .  j  a v a2  s .co  m*/
    if (null != getArguments() && getArguments().containsKey("checkZPImmediately"))
        checkZPImmediately = getArguments().getBoolean("checkZPImmediately");

    // Check for available NFC Adapter
    mNfcAdapter = NfcAdapter.getDefaultAdapter(getActivity());

    if (null != mNfcAdapter) {
        // Register callback
        mNfcAdapter.setNdefPushMessageCallback(this, getActivity());
    }

    checkZPHandler = new Handler() {
        public void handleMessage(Message msg) {
            try {
                if (null != progressbar) {
                    progressbar.startAnimation(
                            AnimationUtils.loadAnimation(getActivity(), android.R.anim.fade_out));
                    progressbar.setVisibility(View.GONE);
                }
            } catch (NullPointerException npe) {
                npe.printStackTrace();
            } catch (Exception e) {
                BugSenseHandler.sendExceptionMessage("PushSettingsFragment", "checkZPHandler", e);
            }

            switch (msg.what) {
            /*case RhybuddHandlers.msg_push_show_undo:
            {
                FilterKey.setText(msg.getData().getString("newfilterkey"));
                try
                {
                    if(null == undoMenuItem)
                    {
                        menu.add(Menu.NONE,MENU_UNDO,Menu.NONE,"Undo");
                        undoMenuItem = menu.findItem(MENU_UNDO);
                        undoMenuItem.setIcon(R.drawable.ic_action_content_undo);
                        undoMenuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
                    }
                    
                    getActivity().invalidateOptionsMenu();
                }
                catch(Exception e)
                {
                    e.printStackTrace();
                    BugSenseHandler.sendExceptionMessage("PushSettingsFragment","processIntent",e);
                }
            }
            break;*/

            case RhybuddHandlers.msg_generic_http_transport_error: {
                try {
                    Toast.makeText(getActivity(), getActivity().getString(R.string.PushZPNoHost),
                            Toast.LENGTH_LONG).show();
                } catch (Exception e) {
                    BugSenseHandler.sendExceptionMessage("PushSettingsFragment",
                            "checkZPHandler msg_generic_http_transport_error", e);
                }
            }
                break;

            case RhybuddHandlers.msg_zp_is_installed: {
                try {
                    hasZenPack = true;
                    ZPInstalledImg.setImageResource(R.drawable.ic_acknowledged);
                    ZPDeviceRegistered.setImageResource(R.drawable.ic_unacknowledged);
                    ZPVersion.setText("1.0.1");
                    enabledSwitch.setEnabled(hasZenPack);
                    registerWithZenPack.setEnabled(hasZenPack);

                    if (checkZPImmediately) {
                        RegisterWithZenPack();
                    } else {
                        checkZenPack.setVisibility(View.VISIBLE);
                        registerWithZenPack.setVisibility(View.GONE);
                    }
                } catch (Exception e) {
                    BugSenseHandler.sendExceptionMessage("PushSettingsFragment",
                            "checkZPHandler msg_zp_is_installed", e);
                }
            }
                break;

            case RhybuddHandlers.msg_zp_not_installed: {
                try {
                    hasZenPack = false;
                    ZPInstalledImg.setImageResource(R.drawable.ic_unacknowledged);
                    ZPDeviceRegistered.setImageResource(R.drawable.ic_unacknowledged);
                    ZPVersion.setText("----");
                    enabledSwitch.setEnabled(hasZenPack);
                    registerWithZenPack.setEnabled(hasZenPack);
                } catch (Exception e) {
                    BugSenseHandler.sendExceptionMessage("PushSettingsFragment",
                            "checkZPHandler msg_zp_not_installed", e);
                }
            }
                break;

            case RhybuddHandlers.msg_zp_registered: {
                try {
                    ZPDeviceRegistered.setImageResource(R.drawable.ic_acknowledged);
                } catch (Exception e) {
                    BugSenseHandler.sendExceptionMessage("PushSettingsFragment",
                            "checkZPHandler msg_zp_registered", e);
                }
            }
                break;

            case RhybuddHandlers.msg_zp_not_registered: {
                try {
                    ZPDeviceRegistered.setImageResource(R.drawable.ic_unacknowledged);
                } catch (Exception e) {
                    BugSenseHandler.sendExceptionMessage("PushSettingsFragment",
                            "checkZPHandler msg_zp_not_registered", e);
                }
            }
                break;
            }
        }
    };

    getIDhandler = new Handler() {
        public void handleMessage(Message msg) {
            switch (msg.what) {
            case RhybuddHandlers.msg_generic_success: {
                try {
                    String pushKey = msg.getData().getString(ZenossAPI.PREFERENCE_PUSHKEY);

                    progressbar.setVisibility(View.GONE);
                    //PushKey.startAnimation(AnimationUtils.loadAnimation(getActivity(), android.R.anim.fade_in));
                    //PushKey.setVisibility(View.VISIBLE);
                    PushKeyDesc.startAnimation(
                            AnimationUtils.loadAnimation(getActivity(), android.R.anim.fade_in));
                    PushKeyDesc.setVisibility(View.VISIBLE);
                    //PushKey.setText(pushKey);

                    SharedPreferences.Editor editor = PreferenceManager
                            .getDefaultSharedPreferences(getActivity()).edit();
                    editor.putString(ZenossAPI.PREFERENCE_PUSHKEY, pushKey);
                    editor.commit();
                } catch (Exception e) {
                    BugSenseHandler.sendExceptionMessage("PushSettingsFragment",
                            "getIDhandler msg_generic_success", e);
                }
            }
                break;

            case RhybuddHandlers.msg_json_error: {
                try {
                    progressbar.setVisibility(View.GONE);
                    Toast.makeText(getActivity(), getString(R.string.JSONExceptionMessage), Toast.LENGTH_LONG)
                            .show();
                } catch (Exception e) {
                    BugSenseHandler.sendExceptionMessage("PushSettingsFragment", "getIDhandler msg_json_error",
                            e);
                }
            }
                break;

            case RhybuddHandlers.msg_generic_http_transport_error: {
                try {
                    progressbar.setVisibility(View.GONE);
                    Toast.makeText(getActivity(), getString(R.string.HttpTransportExceptionMessage),
                            Toast.LENGTH_LONG).show();
                } catch (Exception e) {
                    BugSenseHandler.sendExceptionMessage("PushSettingsFragment", "getIDhandler msg_json_error",
                            e);
                }
            }
                break;

            case RhybuddHandlers.msg_generic_failure: {
                try {
                    progressbar.setVisibility(View.GONE);
                    Toast.makeText(getActivity(), getString(R.string.GenericExceptionMessage),
                            Toast.LENGTH_LONG).show();
                } catch (Exception e) {
                    BugSenseHandler.sendExceptionMessage("PushSettingsFragment",
                            "getIDhandler msg_generic_failure", e);
                }
            }
                break;
            }
        }
    };
}

From source file:com.nbplus.vbroadlauncher.fragment.LauncherFragment.java

public void handleMessage(Message msg) {
    if (msg == null) {
        return;/*from   w  ww. ja  v  a2 s  .  c  o  m*/
    }
    switch (msg.what) {
    case HANDLER_MESSAGE_CONNECTIVITY_CHANGED:
        Log.d(TAG, "HANDLER_MESSAGE_CONNECTIVITY_CHANGED received !!!");
        final boolean networkStatus = NetworkUtils.isConnected(getActivity());
        if (mLastNetworkStatus == networkStatus) {
            Log.d(TAG, ">> current and previous are same status. ignore it...");
            return;
        }
        mLastNetworkStatus = networkStatus;

        mWeatherView.onNetworkConnected(mLastNetworkStatus);
        if (mLastNetworkStatus) {
            // start push agent service
            VBroadcastServer serverInfo = LauncherSettings.getInstance(getActivity()).getServerInformation();
            if (serverInfo != null && StringUtils.isEmptyString(serverInfo.getPushInterfaceServer()) == false) {
                Intent intent = new Intent(getActivity(), PushService.class);
                intent.setAction(PushConstants.ACTION_START_SERVICE);
                intent.putExtra(PushConstants.EXTRA_START_SERVICE_IFADDRESS,
                        serverInfo.getPushInterfaceServer());
                getActivity().startService(intent);
            }
        }
        break;

    case Constants.HANDLER_MESSAGE_PUSH_STATUS_CHANGED:
        int status = msg.arg1;
        Log.d(TAG, "HANDLER_MESSAGE_PUSH_STATUS_CHANGED received. status = " + status);
        if (status == PushConstants.PUSH_STATUS_VALUE_CONNECTED) {
            mPushServiceStatus.setImageResource(R.drawable.ic_nav_wifi_on);
        } else {
            mPushServiceStatus.setImageResource(R.drawable.ic_nav_wifi_off);
        }

        //                int what = msg.arg2;
        //                if (what == PushConstants.PUSH_STATUS_WHAT_NETORSERVER) {
        //                    new AlertDialog.Builder(getActivity()).setMessage("? ? ? ? ?  ?? ? ?.")
        //                            //.setTitle(R.string.alert_network_title)
        //                            .setCancelable(true)
        //                            .setPositiveButton(R.string.alert_ok,
        //                                    new DialogInterface.OnClickListener() {
        //                                        public void onClick(DialogInterface dialog, int whichButton) {
        //                                            dialog.dismiss();
        //                                        }
        //                                    })
        //                            .show();
        //                }
        break;
    case Constants.HANDLER_MESSAGE_PUSH_MESAGE_RECEIVED:
        PushPayloadData payloadData = (PushPayloadData) msg.obj;
        if (payloadData == null) {
            Log.d(TAG, "empty push message string !!");
            return;
        }

        Log.d(TAG, "HANDLER_MESSAGE_PUSH_MESAGE_RECEIVED received = " + payloadData.getServiceType());
        String type = payloadData.getServiceType();
        switch (type) {
        // 
        case Constants.PUSH_PAYLOAD_TYPE_REALTIME_BROADCAST:
        case Constants.PUSH_PAYLOAD_TYPE_NORMAL_BROADCAST:
        case Constants.PUSH_PAYLOAD_TYPE_TEXT_BROADCAST: {
            // , ?? ?,  ? ?? ..
            //  .
            View btnShortcut = null;
            for (int i = 0; i < mPushNotifiableShorcuts.size(); i++) {
                ShortcutData shortcut = mPushNotifiableShorcuts.get(i);
                String[] pushType = shortcut.getPushType();
                if (pushType != null && pushType.length > 0 && Arrays.asList(pushType).indexOf(type) >= 0) {
                    btnShortcut = shortcut.getLauncherButton();
                    break;
                }
            }
            // push notification badge  .
            if (btnShortcut != null) {
                TextView badgeView = (TextView) btnShortcut.findViewById(R.id.launcher_menu_badge);
                if (badgeView != null) {
                    badgeView.setVisibility(View.VISIBLE);
                }
            }

            break;
        }
        // 
        case Constants.PUSH_PAYLOAD_TYPE_EMERGENCY_CALL:
            break;
        // 
        case Constants.PUSH_PAYLOAD_TYPE_INHABITANTS_POLL:
            // ?
        case Constants.PUSH_PAYLOAD_TYPE_COOPERATIVE_BUYING: {
            View btnShortcut = null;
            for (int i = 0; i < mPushNotifiableShorcuts.size(); i++) {
                ShortcutData shortcut = mPushNotifiableShorcuts.get(i);
                String[] pushType = shortcut.getPushType();
                if (pushType != null && pushType.length > 0 && Arrays.asList(pushType).indexOf(type) >= 0) {
                    btnShortcut = shortcut.getLauncherButton();
                    break;
                }
            }
            // push notification badge  .
            if (btnShortcut != null) {
                TextView badgeView = (TextView) btnShortcut.findViewById(R.id.launcher_menu_badge);
                if (badgeView != null) {
                    badgeView.setVisibility(View.VISIBLE);
                }
            }
            break;
        }
        default:
            Log.d(TAG, "Unknown push payload type !!!");
            break;
        }
        break;

    case Constants.HANDLER_MESSAGE_SEND_EMERGENCY_CALL_COMPLETE_TASK: {
        BaseApiResult result = (BaseApiResult) msg.obj;
        Toast toast;
        dismissProgressDialog();
        if (result != null) {
            Log.d(TAG, ">> EMERGENCY CALL result code = " + result.getResultCode() + ", message = "
                    + result.getResultMessage());
            if (Constants.RESULT_OK.equals(result.getResultCode())) {
                toast = Toast.makeText(getActivity(), R.string.emergency_call_success_message,
                        Toast.LENGTH_SHORT);
                toast.setGravity(Gravity.CENTER, 0, 0);
                toast.show();
            } else {
                toast = Toast.makeText(getActivity(), result.getResultMessage(), Toast.LENGTH_SHORT);
                toast.setGravity(Gravity.CENTER, 0, 0);
                toast.show();
            }
        } else {
            toast = Toast.makeText(getActivity(), R.string.emergency_call_fail_message, Toast.LENGTH_SHORT);
            toast.setGravity(Gravity.CENTER, 0, 0);
            toast.show();
        }
        break;
    }
    case HANDLER_MESSAGE_SET_VILLAGE_NAME:
        if (mVillageName != null) {
            mVillageName.setText(LauncherSettings.getInstance(getActivity()).getVillageName());
        }
        if (mWeatherView != null) {
            mWeatherView.onChangedVillageName();
        }
        break;

    // ?? ?
    case HANDLER_IOT_DATA_SYNC_COMPLETED: {
        if (!mIsProcessingIoTDataSync) {
            return;
        }
        mIsProcessingIoTDataSync = false;
        mHandler.postDelayed(new Runnable() {
            @Override
            public void run() {
                dismissProgressDialog();
            }
        }, 1000);
        Toast toast;
        toast = Toast.makeText(getActivity(), R.string.toast_iot_data_sync, Toast.LENGTH_SHORT);
        toast.setGravity(Gravity.CENTER, 0, 0);
        toast.show();
        mIoTDataSyncText.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_cached_white, 0, 0, 0);
        mIoTDataSyncText.setTextColor(getResources().getColor(R.color.white));
        break;
    }

    case HANDLER_IOT_SERVICE_STATUS_CHANGED: {
        Bundle extras = msg.getData();
        if (extras == null) {
            return;
        }

        boolean serviceStatus = extras.getBoolean(IoTConstants.EXTRA_SERVICE_STATUS);
        if (serviceStatus) {
            mIoTDataSyncText.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_cached_white, 0, 0, 0);
            mIoTDataSyncText.setTextColor(getResources().getColor(R.color.white));

            mIoTDataSync.setOnClickListener(mIoTSyncClickListener);
            mIoTDataSync.setClickable(true);
            mIoTDataSync.setEnabled(true);
        } else {
            mIoTDataSyncText.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_cached_grey600, 0, 0, 0);
            mIoTDataSyncText.setTextColor(getResources().getColor(R.color.btn_color_absentia_off));

            mIoTDataSync.setOnClickListener(null);
            mIoTDataSync.setClickable(false);
            mIoTDataSync.setEnabled(false);
        }
    }
    }
}

From source file:com.rfo.basic.Run.java

public boolean handleBTMessage(Message msg) {
    switch (msg.what) {
    case MESSAGE_STATE_CHANGE:
        bt_state = msg.arg1;/*from  w w  w  .j av  a  2 s  .  c om*/
        break;
    case MESSAGE_WRITE:
        //            byte[] writeBuf = (byte[]) msg.obj;
        // construct a string from the buffer
        //            String writeMessage = new String(writeBuf);
        break;
    case MESSAGE_READ:
        byte[] readBuf = (byte[]) msg.obj;
        String readMessage = "";
        // construct a string from the valid bytes in the buffer
        //            String readMessage = new String(readBuf, 0, msg.arg1);
        try {
            readMessage = new String(readBuf, "ISO-8859-1");
        } catch (Exception e) {
            errorToConsole("Error: " + e.getMessage());
        }
        readMessage = readMessage.substring(0, msg.arg1);
        synchronized (BT_Read_Buffer) {
            if (BT_Read_Buffer.size() == 0) {
                triggerInterrupt(Interrupt.BT_READY_BIT);
            }
            BT_Read_Buffer.add(readMessage);
        }
        break;
    case MESSAGE_DEVICE_NAME:
        // save the connected device's name
        mConnectedDeviceName = msg.getData().getString(DEVICE_NAME);
        break;
    default:
        return false; // message not recognized
    }
    return true; // message handled
}