Example usage for android.os Bundle getSerializable

List of usage examples for android.os Bundle getSerializable

Introduction

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

Prototype

@Override
@Nullable
public Serializable getSerializable(@Nullable String key) 

Source Link

Document

Returns the value associated with the given key, or null if no mapping of the desired type exists for the given key or a null value is explicitly associated with the key.

Usage

From source file:com.nextgis.maplibui.activity.FormBuilderModifyAttributesActivity.java

@Override
protected void fillControls(LinearLayout layout, Bundle savedState) {
    //TODO: add location control via fragment only defined by user space

    Bundle extras = getIntent().getExtras(); // null != extras
    File form = (File) extras.getSerializable(KEY_FORM_PATH);

    int orientation = getResources().getConfiguration().orientation;
    boolean isLand = orientation == Configuration.ORIENTATION_LANDSCAPE;

    try {// w  w w  .j a v a2  s .  c o  m
        String formString = FileUtil.readFromFile(form);
        if (TextUtils.indexOf(formString, "tabs") == -1) {
            JSONArray elements = new JSONArray(formString);
            if (elements.length() > 0) {
                fillTabControls(layout, savedState, elements);
            }
        } else {
            JSONObject jsonFormContents = new JSONObject(formString);
            JSONArray tabs = jsonFormContents.getJSONArray(JSON_TABS_KEY);

            for (int i = 0; i < tabs.length(); i++) {
                JSONObject tab = tabs.getJSONObject(i);
                JSONArray elements = null;

                if (isLand && !tab.isNull(JSON_ALBUM_ELEMENTS_KEY)) {
                    elements = tab.getJSONArray(JSON_ALBUM_ELEMENTS_KEY);
                }

                if (null == elements) {
                    if (!isLand && !tab.isNull(JSON_PORTRAIT_ELEMENTS_KEY)) {
                        elements = tab.getJSONArray(JSON_PORTRAIT_ELEMENTS_KEY);
                    }
                }

                if (null == elements) {
                    if (!tab.isNull(JSON_ALBUM_ELEMENTS_KEY)) {
                        elements = tab.getJSONArray(JSON_ALBUM_ELEMENTS_KEY);
                    }

                    if (!tab.isNull(JSON_PORTRAIT_ELEMENTS_KEY)) {
                        elements = tab.getJSONArray(JSON_ALBUM_ELEMENTS_KEY);
                    }
                }

                if (null != elements && elements.length() > 0) {
                    fillTabControls(layout, savedState, elements);
                }
            }
        }

    } catch (JSONException | IOException e) {
        e.printStackTrace();
        Toast.makeText(this, getString(R.string.error_form_create), Toast.LENGTH_SHORT).show();
    }
}

From source file:com.eugene.fithealthmaingit.UI.MealView.MealViewActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_meal_view);
    setAdapter(new Date());
    Bundle extras = getIntent().getExtras();
    if (extras != null) {
        mealType = extras.getString(Globals.MEAL_TYPE); // Meal Type (Snack, Breakfast, Lunch, Dinner)
        position = extras.getInt(Globals.MEAL_POSITION); // Meal Position
        mDate = (Date) extras.getSerializable(Globals.MEAL_DATE); // Meal Position
    }/* w ww.ja va  2s .c o m*/
    mLogMealAdapter = new LogAdapterAll(this, 0, LogMeal.logSortByMealChoice(mealType, mDate)); // Set adapter based on (Snack, Breakfast, Lunch, Dinner) and Date
    toolbar_meal_view = (Toolbar) findViewById(R.id.toolbar_meal_view);
    mViewPager = (ViewPager) findViewById(R.id.pager);
    tabs = (TabLayout) findViewById(R.id.tabs);
    InitializeToolbar();
    InitializePagerTabs();

    tabs.setupWithViewPager(mViewPager);
    mViewPager.setCurrentItem(position);
}

From source file:com.makotogo.mobile.datetimepickerexample.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // Bundle exists if we are being recreated
    if (savedInstanceState != null) {
        mLocalDateTime = (LocalDateTime) savedInstanceState.getSerializable(STATE_LOCAL_DATE_TIME);
    }/*from  w  ww . j  a  v  a 2 s . c o  m*/

    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    FloatingActionButton fab = (FloatingActionButton) safeFindViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            String text = RawTextFileUtils.readRawTextFile(MainActivity.this, R.raw.snackbar);
            if (text == null) {
                text = "TEXT FROM FILE RESOURCE " + R.raw.snackbar + " NOT FOUND!";
            }
            Snackbar.make(view, text, Snackbar.LENGTH_LONG).setAction("Action", null).show();
        }
    });

    DrawerLayout drawer = (DrawerLayout) safeFindViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar,
            R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.addDrawerListener(toggle);
    toggle.syncState();

    NavigationView navigationView = (NavigationView) safeFindViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);

    // Create the Info text view (header)
    createTextViewExampleInfoHeader();

    // Create the Date/Time text view
    createTextViewDateTime();

    // Create the choose date/time button
    createButtonChooseDateTime();

    // Create the Info text view (footer)
    createTextViewExampleInfoFooter();
}

From source file:com.duy.ascii.sharedcode.image.ImageToAsciiActivity.java

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (savedInstanceState != null) {
        mResultFile = (File) savedInstanceState.getSerializable("result_file");
        mOriginalUri = savedInstanceState.getParcelable("origin_uri");
    }/*from  ww w  . j  a va  2  s. c  o  m*/
    setContentView(R.layout.activity_image_to_ascii);
    setSupportActionBar((Toolbar) findViewById(R.id.toolbar));
    setTitle(R.string.image_to_ascii);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    mPreview = (ImageView) findViewById(R.id.image_preview);
    findViewById(R.id.btn_select).setOnClickListener(this);
    mProgressBar = (ProgressBar) findViewById(R.id.progress_bar);
    mProgressBar.setVisibility(View.GONE);
    mSpinnerType = (Spinner) findViewById(R.id.spinner_type);
    mSpinnerType.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
            if (mOriginalUri != null) {
                convertImageToAsciiFromIntent(mOriginalUri);
            }
        }

        @Override
        public void onNothingSelected(AdapterView<?> adapterView) {

        }
    });
}

From source file:com.fimagena.filepicker.FilePickerFragment.java

@Override
public void onInflate(Activity activity, AttributeSet attrs, Bundle savedInstanceState) {
    super.onInflate(activity, attrs, savedInstanceState);

    if ((savedInstanceState != null) && savedInstanceState.containsKey(KEY_PARAMS)) {
        mParams = (BitSet) savedInstanceState.getSerializable(KEY_PARAMS);
        mStartPath = new File(savedInstanceState.getString(KEY_CURRENT_PATH));
    } else {// w  ww  . j a  v a  2  s  .  co m
        // read xml custom-attributes
        TypedArray attrArray = activity.obtainStyledAttributes(attrs, R.styleable.FilePickerFragment);

        mParams = new BitSet(4);
        mParams.set(SELECT_FILE, attrArray.getBoolean(R.styleable.FilePickerFragment_select_file, false));
        mParams.set(SELECT_DIR, attrArray.getBoolean(R.styleable.FilePickerFragment_select_dir, false));
        mParams.set(ALLOW_CREATE_DIR,
                attrArray.getBoolean(R.styleable.FilePickerFragment_allow_dir_create, false));
        mParams.set(ALLOW_MULTIPLE_SELECT,
                attrArray.getBoolean(R.styleable.FilePickerFragment_allow_multiple, false));
        if (!mParams.get(SELECT_FILE) && !mParams.get(SELECT_DIR))
            mParams.set(SELECT_FILE, true);

        if (attrArray.hasValue(R.styleable.FilePickerFragment_start_path))
            mStartPath = new File(attrArray.getText(R.styleable.FilePickerFragment_start_path).toString());
        else
            mStartPath = Environment.getExternalStorageDirectory();

        attrArray.recycle();
    }
}

From source file:de.grobox.transportr.locations.LocationFragment.java

@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
        @Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Bundle args = getArguments();
    if (args == null)
        throw new IllegalStateException();
    location = (WrapLocation) args.getSerializable(WRAP_LOCATION);
    if (location == null)
        throw new IllegalArgumentException("No location");

    View v = inflater.inflate(R.layout.fragment_location, container, false);
    getComponent().inject(this);

    if (getActivity() == null)
        throw new IllegalStateException();
    viewModel = ViewModelProviders.of(getActivity(), viewModelFactory).get(MapViewModel.class);
    viewModel.nearbyStationsFound().observe(this, found -> onNearbyStationsLoaded());

    // Location/* ww w . j a va2 s .  c  o  m*/
    locationIcon = v.findViewById(R.id.locationIcon);
    locationName = v.findViewById(R.id.locationName);
    locationIcon.setOnClickListener(view -> onLocationClicked());
    locationName.setOnClickListener(view -> onLocationClicked());

    // Lines
    linesLayout = v.findViewById(R.id.linesLayout);
    linesLayout.setVisibility(GONE);
    linesLayout.setAdapter(adapter);
    linesLayout.setLayoutManager(new LinearLayoutManager(getContext(), HORIZONTAL, false));
    linesLayout.setOnClickListener(view -> onLocationClicked());

    // Location Info
    locationInfo = v.findViewById(R.id.locationInfo);
    showLocation();

    if (location.getLocation().type == COORD) {
        ReverseGeocoder geocoder = new ReverseGeocoder(getActivity(), this);
        geocoder.findLocation(location.getLocation());
    }

    // Departures
    Button departuresButton = v.findViewById(R.id.departuresButton);
    if (location.hasId()) {
        departuresButton.setOnClickListener(view -> {
            Intent intent = new Intent(getContext(), DeparturesActivity.class);
            intent.putExtra(WRAP_LOCATION, location);
            startActivity(intent);
        });
    } else {
        departuresButton.setVisibility(GONE);
    }

    // Nearby Stations
    nearbyStationsButton = v.findViewById(R.id.nearbyStationsButton);
    nearbyStationsProgress = v.findViewById(R.id.nearbyStationsProgress);
    nearbyStationsButton.setOnClickListener(view -> {
        nearbyStationsButton.setVisibility(INVISIBLE);
        nearbyStationsProgress.setVisibility(VISIBLE);
        IntentUtils.findNearbyStations(getContext(), location);
    });

    // Share Location
    Button shareButton = v.findViewById(R.id.shareButton);
    shareButton.setOnClickListener(view -> startGeoIntent(getActivity(), location));

    // Overflow Button
    ImageButton overflowButton = v.findViewById(R.id.overflowButton);
    overflowButton.setOnClickListener(view -> new LocationPopupMenu(getContext(), view, location).show());

    v.getViewTreeObserver().addOnGlobalLayoutListener(this);

    return v;
}

From source file:com.github.hobbe.android.openkarotz.fragment.RadioTabFragment.java

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

    if (savedInstanceState != null) {
        this.group = (RadioGroupModel) savedInstanceState.getSerializable(KEY_GROUP);
    }// w w  w.j  a  v  a  2  s.co m
}

From source file:com.ibuildapp.romanblack.MultiContactsPlugin.MultiContactsActivity.java

@Override
public void create() {
    try {/*from ww w. j a v  a  2 s .c  om*/
        setContentView(R.layout.grouped_contacts_main);

        setTopBarLeftButtonTextAndColor(getResources().getString(R.string.common_back_upper),
                getResources().getColor(android.R.color.black), true, new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        finish();
                        return;
                    }
                });
        setTopBarTitleColor(getResources().getColor(android.R.color.black));
        setTopBarBackgroundColor(Statics.color1);

        LinearLayout inputSearchLayout = (LinearLayout) findViewById(R.id.grouped_contacts_search_layout);
        inputSearchLayout.setVisibility(View.GONE);

        resources = getResources();

        Intent currentIntent = getIntent();
        Bundle store = currentIntent.getExtras();
        widget = (Widget) store.getSerializable("Widget");
        category = store.getString("category");
        setTopBarTitle(category);

        if (widget == null) {
            handler.sendEmptyMessage(INITIALIZATION_FAILED);
            return;
        }

        cachePath = widget.getCachePath() + "/contacts-" + widget.getOrder();

        root = (LinearLayout) findViewById(R.id.grouped_contacts_main_root);
        listView = (ListView) findViewById(R.id.grouped_contacts_list);
        separator = findViewById(R.id.gc_head_separator);
        backSeparator = findViewById(R.id.gc_back_separator);

        backSeparator.setBackgroundColor(Statics.color1);
        if (Statics.isLight) {
            separator.setBackgroundColor(Color.parseColor("#4d000000"));
        } else {
            separator.setBackgroundColor(Color.parseColor("#4dFFFFFF"));
        }

        handler.sendEmptyMessage(SET_ROOT_BACKGROUND);
    } catch (Exception e) {
    }
}

From source file:com.nextgis.libngui.dialog.LocalResourceSelectDialog.java

@Override
public void onCreate(Bundle savedInstanceState) {
    setKeepInstance(true);//w w w . j  av a 2 s. c om
    setThemeDark(ThemeUtil.isDarkTheme(getActivity()));

    super.onCreate(savedInstanceState);

    if (null != savedInstanceState) {
        mPath = (File) savedInstanceState.getSerializable(KEY_PATH);
        mTypeMask = savedInstanceState.getInt(KEY_MASK);
        mCanSelectMulti = savedInstanceState.getBoolean(KEY_CAN_SEL_MULTI);
        mCanWrite = savedInstanceState.getBoolean(KEY_WRITABLE);
        mSavedPathList = savedInstanceState.getStringArrayList(KEY_SELECTED_ITEMS);
    }

    mAdapter = new LocalResourceListAdapter();
    mAdapter.setSingleSelectable(!mCanSelectMulti);
    mAdapter.setOnChangePathListener(this);
    mAdapter.addOnSelectionChangedListener(this);

    runLoader();
}

From source file:de.grobox.transportr.locations.LocationView.java

@Override
public void onRestoreInstanceState(Parcelable state) {
    if (state instanceof Bundle) { // implicit null check
        Bundle bundle = (Bundle) state;
        WrapLocation loc = (WrapLocation) bundle.getSerializable(LOCATION);
        String text = bundle.getString(TEXT);
        if (loc != null) {
            setLocation(loc);/*w  w w .  j av  a  2s  .  c om*/
        } else if (text != null && text.length() > 0) {
            ui.location.setText(text);
            ui.clear.setVisibility(View.VISIBLE);
        }
        int position = bundle.getInt(TEXT_POSITION);
        ui.location.setSelection(position);

        // replace state by super state
        state = bundle.getParcelable(SUPER_STATE);
    }
    super.onRestoreInstanceState(state);
}