Example usage for android.os Bundle getShort

List of usage examples for android.os Bundle getShort

Introduction

In this page you can find the example usage for android.os Bundle getShort.

Prototype

@Override
public short getShort(String key) 

Source Link

Document

Returns the value associated with the given key, or (short) 0 if no mapping of the desired type exists for the given key.

Usage

From source file:com.wly.net.PortScannerActivity.java

public static void createPacketDatagram(Bundle pktDatagram) {
    ip = new IpHeader();
    ip.setIhl(pktDatagram.getChar("ihl"));
    ip.setVer(pktDatagram.getChar("version"));
    ip.setTos(pktDatagram.getChar("tos"));
    ip.setVer(pktDatagram.getChar("ttl"));
    ip.setTos(pktDatagram.getChar("protocol"));
    ip.setTotalLen(pktDatagram.getShort("tot_len"));
    ip.setId(pktDatagram.getShort("id"));
    ip.setTotalLen(pktDatagram.getShort("frag_off"));
    ip.setIpCheck(pktDatagram.getInt("ipCheck"));
    ip.setSourceAddress(pktDatagram.getInt("saddr"));
    ip.setDestAddress(pktDatagram.getInt("daddr"));
    tcp = new TcpHeader();
    tcp.setSource(pktDatagram.getShort("source"));
    tcp.setDest(pktDatagram.getShort("dest"));
    tcp.setDoff(pktDatagram.getShort("doff"));
    tcp.setRes1(pktDatagram.getShort("res1"));
    tcp.setCwr(pktDatagram.getShort("cwr"));
    tcp.setEce(pktDatagram.getShort("ece"));
    tcp.setUrg(pktDatagram.getShort("urg"));
    tcp.setAck(pktDatagram.getShort("ack"));
    tcp.setPsh(pktDatagram.getShort("psh"));
    tcp.setRst(pktDatagram.getShort("rst"));
    tcp.setSyn(pktDatagram.getShort("syn"));
    tcp.setFin(pktDatagram.getShort("fin"));
    tcp.setWindow(pktDatagram.getShort("window"));
    tcp.setCheck(pktDatagram.getShort("check"));
    tcp.setUrgPtr(pktDatagram.getShort("urg_ptr"));
    tcp.setSeq(pktDatagram.getLong("seq"));
    tcp.setAckSeq(pktDatagram.getLong("ack_seq"));

    datagramBundle.putAll(pktDatagram);/*from w  w  w.j a  v a2s.  c  om*/
}

From source file:de.zweipunktfuenf.crypdroid.activities.ActionChooserActivity.java

private void setProperties(Bundle b) {
    mode = b.getShort(EXTRA_MODE);
    if (0 == mode)
        Log.e(this.getClass().getSimpleName(), "Starting Intent does not contain a mode");
    //      /*from   w w w.jav  a2  s.  c  om*/
    //      filename = b.getString(EXTRA_FILENAME);
    //      if(mode == MODE_PLAIN && null == filename)
    //         Log.e(this.getClass().getSimpleName(),
    //            "Starting Intent does not contain a filename"
    //         );
    //      
    //      if(null != filename) {
    //         // tried to use MimeTypeMap.getFileExtensionFromUrl()
    //         // but this can only be used for URLs, see:
    //         // http://code.google.com/p/android/issues/detail?id=5510
    //         String ext = filename.substring(filename.lastIndexOf(".") + 1);
    //         mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(ext);
    //         
    //         Log.d(this.getClass().getSimpleName(), filename + ": " + ext + ": " + mimeType);
    //      }
}

From source file:com.untappedkegg.rally.home.ActivityMain.java

/**
 * This method is called after {@link #onStart} when the activity is
 * being re-initialized from a previously saved state, given here in
 * <var>savedInstanceState</var>.  Most implementations will simply use {@link #onCreate}
 * to restore their state, but it is sometimes convenient to do it here
 * after all of the initialization has been done or to allow subclasses to
 * decide whether to use your default implementation.  The default
 * implementation of this method performs a restore of any view state that
 * had previously been frozen by {@link #onSaveInstanceState}.
 * <p/>// ww w . j  a  v  a 2  s.  c o  m
 * <p>This method is called between {@link #onStart} and
 * {@link #onPostCreate}.
 *
 * @param savedInstanceState the data most recently supplied in {@link #onSaveInstanceState}.
 * @see #onCreate
 * @see #onPostCreate
 * @see #onResume
 * @see #onSaveInstanceState
 */
@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
    if (savedInstanceState != null) {
        curPosition = savedInstanceState.getShort("pos");
        getActionBar().setTitle(mActionBarDrawer[curPosition]);
    }
    super.onRestoreInstanceState(savedInstanceState);
}

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

public static void bindFragmentArgument(Fragment receiver) {
    Field[] fields = receiver.getClass().getDeclaredFields();
    for (Field field : fields) {
        field.setAccessible(true);/*from  w  w w. j  ava2 s . co m*/
        FragmentArgument fragmentArgument = field.getAnnotation(FragmentArgument.class);
        if (fragmentArgument != null) {
            try {
                Bundle bundle = receiver.getArguments();
                if (bundle != null) {
                    Class<?> type = field.getType();
                    if (type == Boolean.class || type == boolean.class) {
                        field.set(receiver, bundle.getBoolean(fragmentArgument.value()));
                    } else if (type == Byte.class || type == byte.class) {
                        field.set(receiver, bundle.getByte(fragmentArgument.value()));
                    } else if (type == Character.class || type == char.class) {
                        field.set(receiver, bundle.getChar(fragmentArgument.value()));
                    } else if (type == Double.class || type == double.class) {
                        field.set(receiver, bundle.getDouble(fragmentArgument.value()));
                    } else if (type == Float.class || type == float.class) {
                        field.set(receiver, bundle.getFloat(fragmentArgument.value()));
                    } else if (type == Integer.class || type == int.class) {
                        field.set(receiver, bundle.getInt(fragmentArgument.value()));
                    } else if (type == Long.class || type == long.class) {
                        field.set(receiver, bundle.getLong(fragmentArgument.value()));
                    } else if (type == Short.class || type == short.class) {
                        field.set(receiver, bundle.getShort(fragmentArgument.value()));
                    } else if (type == String.class) {
                        field.set(receiver, bundle.getString(fragmentArgument.value()));
                    } else if (type == Boolean[].class || type == boolean[].class) {
                        field.set(receiver, bundle.getBooleanArray(fragmentArgument.value()));
                    } else if (type == Byte[].class || type == byte[].class) {
                        field.set(receiver, bundle.getByteArray(fragmentArgument.value()));
                    } else if (type == Character[].class || type == char[].class) {
                        field.set(receiver, bundle.getCharArray(fragmentArgument.value()));
                    } else if (type == Double[].class || type == double[].class) {
                        field.set(receiver, bundle.getDoubleArray(fragmentArgument.value()));
                    } else if (type == Float[].class || type == float[].class) {
                        field.set(receiver, bundle.getFloatArray(fragmentArgument.value()));
                    } else if (type == Integer[].class || type == int[].class) {
                        field.set(receiver, bundle.getIntArray(fragmentArgument.value()));
                    } else if (type == Long[].class || type == long[].class) {
                        field.set(receiver, bundle.getLongArray(fragmentArgument.value()));
                    } else if (type == Short[].class || type == short[].class) {
                        field.set(receiver, bundle.getShortArray(fragmentArgument.value()));
                    } else if (type == String[].class) {
                        field.set(receiver, bundle.getStringArray(fragmentArgument.value()));
                    } else if (Serializable.class.isAssignableFrom(type)) {
                        field.set(receiver, bundle.getSerializable(fragmentArgument.value()));
                    } else if (type == Bundle.class) {
                        field.set(receiver, bundle.getBundle(fragmentArgument.value()));
                    }
                }
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            }
        }
    }
}

From source file:com.nextgis.maplibui.SelectNGWResourceDialog.java

@NonNull
@Override/* www .j ava2 s .c o m*/
public Dialog onCreateDialog(Bundle savedInstanceState) {
    LayoutInflater inflater = getActivity().getLayoutInflater();

    mListAdapter = new NGWResourcesListAdapter(this);

    if (null == savedInstanceState) {
        //first launch, lets fill connections array
        Connections connections = fillConnections();
        mListAdapter.setConnections(connections);
        mListAdapter.setCurrentResourceId(connections.getId());
        mListAdapter.setCheckState(new ArrayList<CheckState>());
    } else {
        mTitle = savedInstanceState.getString(KEY_TITLE);
        mTypeMask = savedInstanceState.getInt(KEY_MASK);
        short id = savedInstanceState.getShort(KEY_ID);
        MapBase map = MapBase.getInstance();
        if (null != map) {
            ILayer iLayer = map.getLayerById(id);
            if (iLayer instanceof LayerGroup)
                mGroupLayer = (LayerGroup) iLayer;
        }

        mListAdapter.setConnections((Connections) savedInstanceState.getParcelable(KEY_CONNECTIONS));
        mListAdapter.setCurrentResourceId(savedInstanceState.getInt(KEY_RESOURCEID));
        mListAdapter.setCheckState(savedInstanceState.<CheckState>getParcelableArrayList(KEY_STATES));
    }

    View view = inflater.inflate(R.layout.layout_ngw_resources, null);
    ListView dialogListView = (ListView) view.findViewById(R.id.listView);
    mListAdapter.setTypeMask(mTypeMask);
    dialogListView.setAdapter(mListAdapter);
    dialogListView.setOnItemClickListener(mListAdapter);

    LinearLayout pathView = (LinearLayout) view.findViewById(R.id.path);
    mListAdapter.setPathLayout(pathView);

    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setTitle(mTitle).setIcon(R.drawable.ic_ngw).setView(view)
            .setPositiveButton(R.string.select, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    createLayers();
                }
            }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    // User cancelled the dialog
                }
            });
    // Create the AlertDialog object and return it
    mDialog = builder.create();
    return mDialog;
}

From source file:com.cyanogenmod.effem.FmRadio.java

@Override
public void onRdsDataAvailable(Bundle rdsData) {
    if (rdsData.containsKey("PSN")) {
        mStationNameTextView.setText(rdsData.getString("PSN").trim());
    }/*from w  w  w . jav  a2 s.c o  m*/

    if (rdsData.containsKey("RT")) {
        String text = rdsData.getString("RT").trim();

        // only update if the text differs, otherwise this messes
        // up the marquee
        if (!mStationInfoTextView.getText().equals(text))
            mStationInfoTextView.setText(text);
    }

    if (rdsData.containsKey("PTY")) {
        int pty = rdsData.getShort("PTY");
        if (pty > 0)
            mProgramTypeTextView.setText(FmUtils.getPTYName(this, pty));
        else
            mProgramTypeTextView.setText("");
    }
}

From source file:com.ecoplayer.beta.MainActivity.java

@Override
protected void onCreate(Bundle arg0) {
    Debug.startMethodTracing();//from w w  w. j  ava 2s .  c  o  m
    super.onCreate(arg0);
    setContentView(R.layout.main);
    // Get sharedPreferences
    preferences = PreferenceManager.getDefaultSharedPreferences(this);
    playQueue = PlayQueue.getInstance();
    fragmentManager = getSupportFragmentManager();
    initialEnergySettings = InitialEnergySettings.getInstance();
    short fragmentId = FRAGMENT_ALBUMS;
    // Register broadcast
    IntentFilter intentFilter = new IntentFilter(MusicService.MUSIC_UPDATE);
    intentFilter.addAction(EnergyService.ENERGY_MODE_SET);
    intentFilter.addAction(EnergyService.ENERGY_STATE_GET);
    registerReceiver(broadcastReceiver, intentFilter);
    if (arg0 != null) {
        album = (Album) arg0.getParcelable(EXTRA_ALBUM);
        fragmentId = arg0.getShort(EXTRA_FRAGMENT_ID);
    }
    // Start energy service to save initial energy settings
    if (!AppState.isEnergyStateSaved()) {
        Intent intentEnergyService = new Intent(getApplicationContext(), EnergyService.class);
        intentEnergyService.setAction(EnergyService.ACTION_GET_ENERGY_STATE);
        startService(intentEnergyService);
    }
    // Load a fragment depending on the ID sent in the Intent.
    if (isFragmentIdValid(fragmentId)) {
        switch (fragmentId) {
        case FRAGMENT_ALBUMS:
            addAlbumFragment();
            break;
        case FRAGMENT_SONGS_ALBUM:
            if (album != null) {
                addSongsByAlbumFragment(album);
                break;
            }
            // if null won't break and will load the default one.
        case FRAGMENT_PLAY_QUEUE:
            addPlayQueueFragment();
            break;
        default:
            addAlbumFragment();
        }
    }
}

From source file:com.untappedkegg.rally.home.ActivityMain.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    BaseDbAccessor.open();//from  w ww. j  av  a 2  s  . c o  m
    mActionBarDrawer = getResources().getStringArray(R.array.action_bar_modules);
    setContentView(R.layout.activity_main2);

    mNavDrawerFragment = (NavDrawerFragment) getSupportFragmentManager().findFragmentById(R.id.left_drawer);
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mNavDrawerFragment.setUp(R.id.left_drawer, mDrawerLayout);

    if (savedInstanceState == null) {
        Bundle bundle = new Bundle();
        bundle.putInt(AppState.KEY_POSITION, 0);
        Fragment home = new HomeFragment();
        home.setArguments(bundle);
        getSupportFragmentManager().beginTransaction().replace(R.id.content_frame, home).commit();
    } else {
        curPosition = savedInstanceState.getShort("pos");
    }

    AppState.getSettings().registerOnSharedPreferenceChangeListener(this);

}

From source file:com.nextgis.maplibui.CreateRemoteTMSLayerDialog.java

@NonNull
@Override/*from   w w w  .ja  v a2  s.  c o  m*/
public Dialog onCreateDialog(Bundle savedInstanceState) {
    final Context context = getActivity();
    LayoutInflater inflater = getActivity().getLayoutInflater();

    View view = inflater.inflate(R.layout.layout_create_tms, null);

    final ArrayAdapter<CharSequence> adapter = new ArrayAdapter<>(context,
            android.R.layout.simple_spinner_item);
    mSpinner = (Spinner) view.findViewById(R.id.layer_type);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    mSpinner.setAdapter(adapter);

    adapter.add(context.getString(R.string.tmstype_osm));
    adapter.add(context.getString(R.string.tmstype_normal));

    mInput = (EditText) view.findViewById(R.id.layer_name);
    mUrl = (EditText) view.findViewById(R.id.layer_url);

    mLogin = (EditText) view.findViewById(R.id.login);
    mPassword = (EditText) view.findViewById(R.id.password);

    if (null == savedInstanceState) {
        //mInput.setText(context.getResources().getText(R.string.osm));
        //mUrl.setText(context.getResources().getText(R.string.osm_url));
        //mSpinner.setSelection(0);
    } else {
        mInput.setText(savedInstanceState.getString(KEY_NAME));
        mUrl.setText(savedInstanceState.getString(KEY_URL));
        mLogin.setText(savedInstanceState.getString(KEY_LOGIN));
        mPassword.setText(savedInstanceState.getString(KEY_PASSWORD));
        mSpinner.setSelection(savedInstanceState.getInt(KEY_POSITION));
        mTitle = savedInstanceState.getString(KEY_TITLE);
        short id = savedInstanceState.getShort(KEY_ID);
        MapBase map = MapBase.getInstance();
        if (null != map) {
            ILayer iLayer = map.getLayerById(id);
            if (iLayer instanceof LayerGroup)
                mGroupLayer = (LayerGroup) iLayer;
        }
    }

    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setTitle(mTitle).setIcon(R.drawable.ic_remote_tms).setView(view)
            .setPositiveButton(R.string.create, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    int tmsType = 0;
                    switch (mSpinner.getSelectedItemPosition()) {
                    case 0:
                        tmsType = TMSTYPE_OSM;
                        break;
                    case 1:
                        tmsType = TMSTYPE_NORMAL;
                        break;
                    }
                    String layerName = mInput.getText().toString();
                    String layerURL = mUrl.getText().toString();
                    String layerLogin = mLogin.getText().toString();
                    String layerPassword = mPassword.getText().toString();

                    //check if {x}, {y} or {z} present
                    if (!layerURL.contains("{x}") || !layerURL.contains("{y}") || !layerURL.contains("{z}")) {
                        Toast.makeText(context, R.string.error_invalid_url, Toast.LENGTH_SHORT).show();
                        return;
                    }

                    if (!layerURL.startsWith("http"))
                        layerURL = "http://" + layerURL;

                    //create new layer and store it and add it to the map
                    RemoteTMSLayerUI layer = new RemoteTMSLayerUI(mGroupLayer.getContext(),
                            mGroupLayer.cretateLayerStorage());
                    layer.setName(layerName);
                    layer.setURL(layerURL);
                    layer.setLogin(layerLogin);
                    layer.setPassword(layerPassword);
                    layer.setTMSType(tmsType);
                    layer.setVisible(true);

                    mGroupLayer.addLayer(layer);
                    mGroupLayer.save();
                }
            }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    // Do nothing.
                }
            });
    // Create the AlertDialog object and return it
    return builder.create();
}

From source file:cn.edu.zafu.corepage.base.BaseActivity.java

/**
 * ???/* w ww .  j a  va 2 s .  co m*/
 *
 * @param savedInstanceState Bundle
 */
private void loadActivitySavedData(Bundle savedInstanceState) {
    Field[] fields = this.getClass().getDeclaredFields();
    Field.setAccessible(fields, true);
    Annotation[] ans;
    for (Field f : fields) {
        ans = f.getDeclaredAnnotations();
        for (Annotation an : ans) {
            if (an instanceof SaveWithActivity) {
                try {
                    String fieldName = f.getName();
                    @SuppressWarnings("rawtypes")
                    Class cls = f.getType();
                    if (cls == int.class || cls == Integer.class) {
                        f.setInt(this, savedInstanceState.getInt(fieldName));
                    } else if (String.class.isAssignableFrom(cls)) {
                        f.set(this, savedInstanceState.getString(fieldName));
                    } else if (Serializable.class.isAssignableFrom(cls)) {
                        f.set(this, savedInstanceState.getSerializable(fieldName));
                    } else if (cls == long.class || cls == Long.class) {
                        f.setLong(this, savedInstanceState.getLong(fieldName));
                    } else if (cls == short.class || cls == Short.class) {
                        f.setShort(this, savedInstanceState.getShort(fieldName));
                    } else if (cls == boolean.class || cls == Boolean.class) {
                        f.setBoolean(this, savedInstanceState.getBoolean(fieldName));
                    } else if (cls == byte.class || cls == Byte.class) {
                        f.setByte(this, savedInstanceState.getByte(fieldName));
                    } else if (cls == char.class || cls == Character.class) {
                        f.setChar(this, savedInstanceState.getChar(fieldName));
                    } else if (CharSequence.class.isAssignableFrom(cls)) {
                        f.set(this, savedInstanceState.getCharSequence(fieldName));
                    } else if (cls == float.class || cls == Float.class) {
                        f.setFloat(this, savedInstanceState.getFloat(fieldName));
                    } else if (cls == double.class || cls == Double.class) {
                        f.setDouble(this, savedInstanceState.getDouble(fieldName));
                    } else if (String[].class.isAssignableFrom(cls)) {
                        f.set(this, savedInstanceState.getStringArray(fieldName));
                    } else if (Parcelable.class.isAssignableFrom(cls)) {
                        f.set(this, savedInstanceState.getParcelable(fieldName));
                    } else if (Bundle.class.isAssignableFrom(cls)) {
                        f.set(this, savedInstanceState.getBundle(fieldName));
                    }
                } catch (IllegalArgumentException e) {
                    e.printStackTrace();
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}