Example usage for android.content Intent getCharExtra

List of usage examples for android.content Intent getCharExtra

Introduction

In this page you can find the example usage for android.content Intent getCharExtra.

Prototype

public char getCharExtra(String name, char defaultValue) 

Source Link

Document

Retrieve extended data from the intent.

Usage

From source file:Main.java

public static char getCharExtra(Intent intent, String name, char defaultValue) {
    if (!hasIntent(intent) || !hasExtra(intent, name))
        return defaultValue;
    return intent.getCharExtra(name, defaultValue);
}

From source file:com.fenlisproject.elf.core.framework.ElfBinder.java

public static void bindIntentExtra(Object receiver) {
    Field[] fields = receiver.getClass().getDeclaredFields();
    for (Field field : fields) {
        field.setAccessible(true);/* www.  jav  a 2 s .c o  m*/
        IntentExtra intentExtra = field.getAnnotation(IntentExtra.class);
        if (intentExtra != null) {
            try {
                Intent intent = null;
                if (receiver instanceof Activity) {
                    intent = ((Activity) receiver).getIntent();
                } else if (receiver instanceof Fragment) {
                    intent = ((Fragment) receiver).getActivity().getIntent();
                }
                if (intent != null) {
                    Class<?> type = field.getType();
                    if (type == Boolean.class || type == boolean.class) {
                        field.set(receiver, intent.getBooleanExtra(intentExtra.value(), false));
                    } else if (type == Byte.class || type == byte.class) {
                        field.set(receiver, intent.getByteExtra(intentExtra.value(), (byte) 0));
                    } else if (type == Character.class || type == char.class) {
                        field.set(receiver, intent.getCharExtra(intentExtra.value(), '\u0000'));
                    } else if (type == Double.class || type == double.class) {
                        field.set(receiver, intent.getDoubleExtra(intentExtra.value(), 0.0d));
                    } else if (type == Float.class || type == float.class) {
                        field.set(receiver, intent.getFloatExtra(intentExtra.value(), 0.0f));
                    } else if (type == Integer.class || type == int.class) {
                        field.set(receiver, intent.getIntExtra(intentExtra.value(), 0));
                    } else if (type == Long.class || type == long.class) {
                        field.set(receiver, intent.getLongExtra(intentExtra.value(), 0L));
                    } else if (type == Short.class || type == short.class) {
                        field.set(receiver, intent.getShortExtra(intentExtra.value(), (short) 0));
                    } else if (type == String.class) {
                        field.set(receiver, intent.getStringExtra(intentExtra.value()));
                    } else if (type == Boolean[].class || type == boolean[].class) {
                        field.set(receiver, intent.getBooleanArrayExtra(intentExtra.value()));
                    } else if (type == Byte[].class || type == byte[].class) {
                        field.set(receiver, intent.getByteArrayExtra(intentExtra.value()));
                    } else if (type == Character[].class || type == char[].class) {
                        field.set(receiver, intent.getCharArrayExtra(intentExtra.value()));
                    } else if (type == Double[].class || type == double[].class) {
                        field.set(receiver, intent.getDoubleArrayExtra(intentExtra.value()));
                    } else if (type == Float[].class || type == float[].class) {
                        field.set(receiver, intent.getFloatArrayExtra(intentExtra.value()));
                    } else if (type == Integer[].class || type == int[].class) {
                        field.set(receiver, intent.getIntArrayExtra(intentExtra.value()));
                    } else if (type == Long[].class || type == long[].class) {
                        field.set(receiver, intent.getLongArrayExtra(intentExtra.value()));
                    } else if (type == Short[].class || type == short[].class) {
                        field.set(receiver, intent.getShortArrayExtra(intentExtra.value()));
                    } else if (type == String[].class) {
                        field.set(receiver, intent.getStringArrayExtra(intentExtra.value()));
                    } else if (Serializable.class.isAssignableFrom(type)) {
                        field.set(receiver, intent.getSerializableExtra(intentExtra.value()));
                    } else if (type == Bundle.class) {
                        field.set(receiver, intent.getBundleExtra(intentExtra.value()));
                    }
                }
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            }
        }
    }
}

From source file:com.groksolutions.grok.mobile.metric.MetricListFragment.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {

    switch (requestCode) {
    case MetricListFragment.METRIC_DETAIL_REQUEST:
        if (resultCode == Activity.RESULT_OK) {
            // Check if clicked on "InstanceAnomalyChartFragment"
            char type = data.getCharExtra(AbstractAnomalyChartFragment.EXTRA_TYPE, ' ');
            if (InstanceAnomalyChartData.CHART_TYPE == type) {
                // If clicked on instance chart then close this activity
                // and
                // go back to instance list
                if (isAdded()) {
                    getActivity().finish();
                }//from  w w w  .  j  a v  a  2s  .  co  m
            }
        }
        break;

    default:
        break;
    }
    super.onActivityResult(requestCode, resultCode, data);
}

From source file:eu.power_switch.gui.fragment.configure_receiver.ConfigureReceiverDialogPage4TabbedSummaryFragment.java

@Nullable
@Override/*w w  w .j a v  a2s  . c om*/
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    rootView = inflater.inflate(R.layout.dialog_fragment_configure_receiver_page_4_summary, container, false);

    // BroadcastReceiver to get notifications from background service if room data has changed
    broadcastReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            if (intent.getAction().equals(LocalBroadcastConstants.INTENT_BRAND_MODEL_CHANGED)) {
                String brand = intent.getStringExtra("brand");
                String model = intent.getStringExtra("model");

                currentBrand = Receiver.Brand.getEnum(brand);
                currentModel = model;

                try {
                    Receiver receiver = ReceiverReflectionMagic.getDummy(getActivity(),
                            Receiver.getJavaPath(currentModel));
                    currentType = receiver.getType();
                } catch (Exception e) {
                    StatusMessageHandler.showErrorMessage(getActivity(), e);
                }
            } else if (intent.getAction().equals(LocalBroadcastConstants.INTENT_NAME_ROOM_CHANGED)) {
                String name = intent.getStringExtra("name");
                String roomName = intent.getStringExtra("roomName");

                currentName = name;
                currentRoomName = roomName;
            } else if (intent.getAction().equals(LocalBroadcastConstants.INTENT_CHANNEL_DETAILS_CHANGED)) {
                char channelMaster = intent.getCharExtra("channelMaster", 'A');
                int channelSlave = intent.getIntExtra("channelSlave", 0);
                ArrayList<DipSwitch> dips = (ArrayList<DipSwitch>) intent.getSerializableExtra("dips");

                long seed = intent.getLongExtra("seed", -1);

                ArrayList<UniversalButton> universalButtons = (ArrayList<UniversalButton>) intent
                        .getSerializableExtra("universalButtons");

                currentMaster = channelMaster;
                currentSlave = channelSlave;
                currentDips = dips;
                currentSeed = seed;
                currentUniversalButtons = universalButtons;
            }

            updateUi();
            notifyConfigurationChanged();
        }
    };

    name = (TextView) rootView.findViewById(R.id.textView_name);
    roomName = (TextView) rootView.findViewById(R.id.textView_roomName);
    brand = (TextView) rootView.findViewById(R.id.textView_brand);
    model = (TextView) rootView.findViewById(R.id.textView_model);
    channelMaster = (TextView) rootView.findViewById(R.id.textView_channelMaster);
    channelSlave = (TextView) rootView.findViewById(R.id.textView_channelSlave);

    linearLayoutMasterSlaveReceiver = (LinearLayout) rootView
            .findViewById(R.id.linearLayout_masterSlaveReceiver);

    linearLayoutDipReceiver = (LinearLayout) rootView.findViewById(R.id.linearLayout_dipReceiver);
    linearLayoutDips = (LinearLayout) rootView.findViewById(R.id.linearLayout_dips);

    linearLayoutAutoPairReceiver = (LinearLayout) rootView.findViewById(R.id.linearLayout_autoPair);
    seed = (TextView) rootView.findViewById(R.id.textView_seed);

    linearLayoutUniversalReceiver = (LinearLayout) rootView.findViewById(R.id.linearLayout_universalReceiver);
    linearLayoutUniversalButtons = (LinearLayout) rootView.findViewById(R.id.linearLayout_universalButtons);

    updateUi();

    Bundle args = getArguments();
    if (args != null && args.containsKey(ConfigureReceiverDialog.RECEIVER_ID_KEY)) {
        long receiverId = args.getLong(ConfigureReceiverDialog.RECEIVER_ID_KEY);
        currentId = receiverId;
        initializeReceiverData(receiverId);
    }

    return rootView;
}