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.wanikani.androidnotifier.MainActivity.java

/** 
 * Called when the activity is first created.  We register the
 * listeners and create the /* w w  w.  j a  v a2 s  .  c o  m*/
 * {@link com.wanikani.wklib.Connection} object that will perform the
 * queries for us.  In some cases (e.g. a change in the
 * orientation of the display), the activity is destroyed and
 * immediately recreated: to avoid querying the website, we
 * use the bundle to retains the stats. To make sure that the
 * bundle is actually valid (e.g. the previous instance of the
 * activity actually succeeded in retrieving the data), we
 * look for the {@link #BUNDLE_VALID} key.
 *    @see #onSaveInstanceState()
 *  @param bundle the bundle, or <code>null</code>
 */
@Override
public void onCreate(Bundle bundle) {
    super.onCreate(bundle);

    receiver = new Receiver();
    alarm = new Alarm();
    mh = new MenuHandler(this, new MenuListener());
    dbfixup = FixupState.NOT_RUNNING;

    /* Must be placed first, because fragments need this early */
    conn = SettingsActivity.newConnection(this);
    conn.cache = new ItemsDatabase(this).getCache();

    if (dsf == null)
        dsf = new DashboardStatsFragment();
    if (dashboardf == null)
        dashboardf = new DashboardFragment();
    if (itemsf == null)
        itemsf = new ItemsFragment();
    if (statsf == null)
        statsf = new StatsFragment();

    setContentView(R.layout.main);
    switchTo(R.id.f_splash);

    pager = (LowPriorityViewPager) findViewById(R.id.pager);
    pager.setMain(this);
    setLayout();

    registerIntents();

    if (!SettingsActivity.credentialsAreValid(this))
        mh.settings();

    if (bundle != null && bundle.containsKey(BUNDLE_VALID)) {
        dd = new DashboardData(bundle);
        pager.setCurrentItem(bundle.getInt(CURRENT_TAB));
        /* -- I'm temporarily keeping this code just in case we decide to make disk caching optional -- */
        /*
        try {
           conn.cache = (ItemsCache) bundle.getSerializable (ITEMS_CACHE);
        } catch (Throwable t) {
                   
        }
        */
        resumeRefresh = bundle.getBoolean(REFRESHING);

        dbfixup = (FixupState) bundle.getSerializable(FIXUP_STATE);
    } else
        pager.setCurrentItem(pad.getTabIndex(Tab.Contents.DASHBOARD), false);
}

From source file:com.example.shoe.DirectionsTest.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_directions_test);

    // Get handles to the UI view objects
    mLatLng = (TextView) findViewById(R.id.lat_lng);
    mAddress = (TextView) findViewById(R.id.address);
    mActivityIndicator = (ProgressBar) findViewById(R.id.address_progress);
    mConnectionState = (TextView) findViewById(R.id.text_connection_state);
    mConnectionStatus = (TextView) findViewById(R.id.text_connection_status);

    // Create a new global location parameters object
    mLocationRequest = LocationRequest.create();

    /*/*from  w  w w  .j  ava 2  s  .c  o m*/
     * Set the update interval
     */
    mLocationRequest.setInterval(LocationUtils.UPDATE_INTERVAL_IN_MILLISECONDS);

    // Use high accuracy
    mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);

    // Set the interval ceiling to one minute
    mLocationRequest.setFastestInterval(LocationUtils.FAST_INTERVAL_CEILING_IN_MILLISECONDS);

    // Note that location updates are off until the user turns them on
    mUpdatesRequested = false;

    // Open Shared Preferences
    mPrefs = getSharedPreferences(LocationUtils.SHARED_PREFERENCES, Context.MODE_PRIVATE);

    // Get an editor
    mEditor = mPrefs.edit();

    /*
     * Create a new location client, using the enclosing class to
     * handle callbacks.
     */
    mLocationClient = new LocationClient(this, this, this);

    //mapDisplay();

    // get the ID of the picture 
    Bundle extras;
    String newString = null;
    if (savedInstanceState == null) {
        extras = getIntent().getExtras();
        if (extras == null) {
            newString = null;
        } else {
            newString = extras.getString("PIC_ID");
        }
    } else {
        newString = (String) savedInstanceState.getSerializable("PIC_ID");
    }

    // call method to get latitude and longitude

    picID = newString;
    //getDestinationCoordinates(newString);

    //startPeriodicUpdates();
    //getLocation();
}

From source file:be.brunoparmentier.openbikesharing.app.activities.StationsListActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_stations_list);

    viewPager = (ViewPager) findViewById(R.id.viewPager);
    viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
        @Override/*from  ww  w  .  j a va  2  s . c o m*/
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

        }

        @Override
        public void onPageSelected(int position) {
            actionBar.setSelectedNavigationItem(position);
        }

        @Override
        public void onPageScrollStateChanged(int state) {

        }
    });

    stationsDataSource = new StationsDataSource(this);
    stations = stationsDataSource.getStations();
    favStations = stationsDataSource.getFavoriteStations();

    actionBar = getActionBar();
    actionBar.addTab(actionBar.newTab().setText(getString(R.string.all_stations)).setTabListener(this));
    actionBar.addTab(actionBar.newTab().setText(getString(R.string.favorite_stations)).setTabListener(this));
    actionBar.setHomeButtonEnabled(false);

    settings = PreferenceManager.getDefaultSharedPreferences(this);
    boolean firstRun = settings.getString(PREF_KEY_NETWORK_ID, "").isEmpty();

    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    tabsPagerAdapter = new TabsPagerAdapter(getSupportFragmentManager());
    viewPager.setAdapter(tabsPagerAdapter);

    setDBLastUpdateText();

    if (firstRun) {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setMessage(R.string.welcome_dialog_message);
        builder.setTitle(R.string.welcome_dialog_title);
        builder.setPositiveButton(R.string.welcome_dialog_ok, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                Intent intent = new Intent(StationsListActivity.this, BikeNetworksListActivity.class);
                startActivityForResult(intent, PICK_NETWORK_REQUEST);
            }
        });
        builder.setNegativeButton(R.string.welcome_dialog_cancel, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                finish();
            }
        });
        AlertDialog dialog = builder.create();
        dialog.show();
    } else {
        if (savedInstanceState != null) {
            bikeNetwork = (BikeNetwork) savedInstanceState.getSerializable("bikeNetwork");
            stations = (ArrayList<Station>) savedInstanceState.getSerializable("stations");
            favStations = (ArrayList<Station>) savedInstanceState.getSerializable("favStations");
        } else {
            String networkId = settings.getString(PREF_KEY_NETWORK_ID, "");
            String stationUrl = BASE_URL + "/" + networkId;
            new JSONDownloadTask().execute(stationUrl);
        }
    }
}

From source file:com.audiokernel.euphonyrmt.MainMenuActivity.java

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

    if (mApp.hasGooglePlayDeathWarningBeenDisplayed() && !mApp.hasGooglePlayThankYouBeenDisplayed()) {
        new AlertDialog.Builder(this).setTitle(getString(R.string.gpThanksTitle))
                .setMessage(getString(R.string.gpThanksMessage))
                .setNegativeButton(getString(R.string.gpThanksOkButton), new DialogInterface.OnClickListener() {
                    @Override//from  w  w  w .  j a v a 2s  .  c o m
                    public void onClick(final DialogInterface dialogInterface, final int i) {
                        mApp.markGooglePlayThankYouAsRead();
                    }
                }).setCancelable(false).show();
    }

    mApp.setupServiceBinder();

    if (mApp.isTabletUiEnabled()) {
        setContentView(R.layout.main_activity_nagvigation_tablet);
    } else {
        setContentView(R.layout.main_activity_nagvigation);
    }

    mTextView = initializeTextView();

    mLibraryRootFrame = findViewById(R.id.library_root_frame);
    mOutputsRootFrame = findViewById(R.id.outputs_root_frame);

    mIsDualPaneMode = findViewById(R.id.nowplaying_dual_pane) != null;

    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);

    mDrawerToggle = initializeDrawerToggle();

    // Set the drawer toggle as the DrawerListener
    mDrawerLayout.setDrawerListener(mDrawerToggle);
    mDrawerList = initializeDrawerList();

    mFragmentManager = getSupportFragmentManager();
    mFragmentManager.addOnBackStackChangedListener(this);

    mLibraryFragment = initializeLibraryFragment();
    mOutputsFragment = initializeOutputsFragment();
    mQueueFragment = (QueueFragment) mFragmentManager.findFragmentById(R.id.queue_fragment);

    // Setup the pager
    mNowPlayingPager = initializeNowPlayingPager();

    if (savedInstanceState == null) {
        switchMode(DisplayMode.MODE_LIBRARY);
    } else {
        switchMode((DisplayMode) savedInstanceState.getSerializable(EXTRA_DISPLAY_MODE));
    }

    mHeaderTitle = (TextView) findViewById(R.id.header_title);
    mHeaderDragView = findViewById(R.id.header_dragview);
    mHeaderPlayQueue = initializeHeaderPlayQueue();

    final ImageButton headerOverflowMenu = (ImageButton) findViewById(R.id.header_overflow_menu);
    if (headerOverflowMenu != null) {
        mHeaderOverflowPopupMenu = initializeHeaderOverflowPopup(headerOverflowMenu);
    }

    // Sliding panel
    mSlidingLayout = initializeSlidingLayout(savedInstanceState);
    refreshQueueIndicator(false);

    /** Reset the persistent override when the application is reset. */
    mApp.setPersistentOverride(false);
}

From source file:dev.memento.MementoBrowser.java

/** Called when the activity is first created. */
@Override/*  www . ja  v a2 s.com*/
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);

    setContentView(R.layout.main);

    mUserAgent = getApplicationContext().getText(R.string.user_agent).toString();

    // Set the date and time format
    SimpleDateTime.mDateFormat = android.text.format.DateFormat.getDateFormat(getApplicationContext());
    SimpleDateTime.mTimeFormat = android.text.format.DateFormat.getTimeFormat(getApplicationContext());

    mDateChosenButton = (Button) findViewById(R.id.dateChosen);
    mDateDisplayedView = (TextView) findViewById(R.id.dateDisplayed);

    // Launch the DatePicker dialog box
    mDateChosenButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            showDialog(DIALOG_DATE);
        }
    });

    // Set the current date
    mToday = new SimpleDateTime();

    // Handle change in orientation gracefully
    if (savedInstanceState == null) {
        mCurrentUrl = getApplicationContext().getText(R.string.homepage).toString();
        mOriginalUrl = mCurrentUrl;

        setChosenDate(mToday);
        setDisplayedDate(mToday);

        mMementos = new MementoList();
    } else {
        mCurrentUrl = savedInstanceState.getString("mCurrentUrl");
        mDateChosen = (SimpleDateTime) savedInstanceState.getSerializable("mDateChosen");
        mDateDisplayed = (SimpleDateTime) savedInstanceState.getSerializable("mDateDisplayed");

        setChosenDate(mDateChosen);
        setDisplayedDate(mDateDisplayed);
    }

    mTimegateUris = getResources().getStringArray(R.array.listTimegates);

    // Add some favicons of web archives used by proxy server
    mFavicons = new HashMap<String, Bitmap>();
    mFavicons.put("ia", BitmapFactory.decodeResource(getResources(), R.drawable.ia_favicon));
    mFavicons.put("webcite", BitmapFactory.decodeResource(getResources(), R.drawable.webcite_favicon));
    mFavicons.put("national-archives",
            BitmapFactory.decodeResource(getResources(), R.drawable.national_archives_favicon));

    mProgressBar = (ProgressBar) findViewById(R.id.progressBar);
    mProgressBar.setVisibility(View.GONE);

    mLocation = (TextView) findViewById(R.id.locationEditText);
    mLocation.setSelectAllOnFocus(true);

    mLocation.setOnFocusChangeListener(new OnFocusChangeListener() {
        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            // Replace title with URL when focus is lost
            if (hasFocus)
                mLocation.setText(mCurrentUrl);
            else if (mPageTitle.length() > 0)
                mLocation.setText(mPageTitle);
        }
    });

    mLocation.setOnKeyListener(new OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            //Log.d(LOG_TAG, "keyCode = " + keyCode + "   event = " + event.getAction());

            // Go to URL if user presses Go button
            if (event.getAction() == KeyEvent.ACTION_DOWN && keyCode == KeyEvent.KEYCODE_ENTER) {

                mOriginalUrl = fixUrl(mLocation.getText().toString());

                // Access live version if date is today or in the future
                if (mToday.compareTo(mDateChosen) <= 0) {
                    Log.d(LOG_TAG, "Browsing to " + mOriginalUrl);
                    mWebview.loadUrl(mOriginalUrl);

                    // Clear since we are visiting a different page in the present
                    mMementos.clear();
                } else
                    makeMementoRequests();

                // Hide the virtual keyboard
                ((InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE))
                        .hideSoftInputFromWindow(mLocation.getWindowToken(), 0);
                return true;
            }

            return false;
        }

    });

    // TEST        
    /*
    Context context = getBaseContext();
    Drawable image = getImage(context, "http://web.archive.org/favicon.ico");
    if (image == null) {
       System.out.println("image is null !!");
    }
    else {
       //image.setBounds(5, 5, 5, 5);
     //ImageView imgView = new ImageView(context);
     //ImageView imgView = (ImageView)findViewById(R.id.imagetest);
     //imgView.setImageDrawable(image);
       mLocation.setCompoundDrawablesWithIntrinsicBounds(image, null, null, null);
    }
    */

    mNextButton = (Button) findViewById(R.id.next);
    mNextButton.setEnabled(false);
    mNextButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            // Advance to next Memento

            // This could happen if the index has not been set yet
            if (mMementos.getCurrentIndex() < 0) {
                int index = mMementos.getIndex(mDateDisplayed);
                if (index < 0) {
                    Log.d(LOG_TAG, "Could not find next Memento after date " + mDateDisplayed);
                    return;
                } else
                    mMementos.setCurrentIndex(index);
            }

            // Locate the next Memento in the list
            Memento nextMemento = mMementos.getNext();

            if (nextMemento == null) {
                Log.d(LOG_TAG, "Still could not find next Memento!");
                Log.d(LOG_TAG, "Current index is " + mMementos.getCurrentIndex());
            } else {
                SimpleDateTime date = nextMemento.getDateTime();
                setChosenDate(nextMemento.getDateTime());
                showToast("Time travelling to next Memento on " + mDateChosen.dateFormatted());

                mDateDisplayed = date;

                String redirectUrl = nextMemento.getUrl();
                Log.d(LOG_TAG, "Sending browser to " + redirectUrl);
                mWebview.loadUrl(redirectUrl);

                // Just in case it wasn't already enabled
                mPreviousButton.setEnabled(true);

                // If this is the last memento, disable button
                if (mMementos.isLast(date))
                    mNextButton.setEnabled(false);
            }
        }
    });
    mPreviousButton = (Button) findViewById(R.id.previous);
    mPreviousButton.setEnabled(false);
    mPreviousButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            // Advance to previous Memento

            // This could happen if the index has not been set yet
            if (mMementos.getCurrentIndex() < 0) {
                int index = mMementos.getIndex(mDateDisplayed);
                if (index < 0) {
                    Log.d(LOG_TAG, "Could not find previous Memento before date " + mDateDisplayed);
                    return;
                } else
                    mMementos.setCurrentIndex(index);
            }

            // Locate the prev Memento in the list
            Memento prevMemento = mMementos.getPrevious();

            if (prevMemento == null) {
                Log.d(LOG_TAG, "Still could not find previous Memento!");
                Log.d(LOG_TAG, "Current index is " + mMementos.getCurrentIndex());
            } else {
                SimpleDateTime date = prevMemento.getDateTime();
                setChosenDate(date);
                showToast("Time travelling to previous Memento on " + mDateChosen.dateFormatted());

                mDateDisplayed = date;

                String redirectUrl = prevMemento.getUrl();
                Log.d(LOG_TAG, "Sending browser to " + redirectUrl);
                mWebview.loadUrl(redirectUrl);

                // Just in case it wasn't already enabled
                mNextButton.setEnabled(true);

                // If this is the first memento, disable button
                if (mMementos.isFirst(date))
                    mPreviousButton.setEnabled(false);
            }
        }
    });

    mWebview = (WebView) findViewById(R.id.webview);
    mWebview.setWebViewClient(new MementoWebViewClient());
    mWebview.setWebChromeClient(new MementoWebChromClient());
    mWebview.getSettings().setJavaScriptEnabled(true);
    mWebview.loadUrl(mCurrentUrl);

    mWebview.setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {

            // Set focus here so focus is removed from the location text field
            // which will change the URL into the page's title.
            // There really should be a better way to do this, but it's a general
            // problem that other developers have ran into as well:
            // http://groups.google.com/group/android-developers/browse_thread/thread/9d1681a01f05e782?pli=1

            if (mLocation.hasFocus()) {
                mWebview.requestFocus();
                return true;
            }

            // Hide the virtual keyboard
            ((InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE))
                    .hideSoftInputFromWindow(mLocation.getWindowToken(), 0);

            return false;
        }
    });

    //testMementos();
}

From source file:com.nbplus.iotlib.IoTInterface.java

private void handleDeviceListNotification(Bundle b) {
    mEmergencyDeviceList.clear();/*w w  w. jav a 2 s  . c  om*/
    HashMap<String, IoTDevice> scannedDevices = new HashMap<>();
    if (b == null) {
        Log.w(TAG, "bundle data is null");
        //return; // ?  ?     .
    } else {
        b.setClassLoader(IoTDevice.class.getClassLoader());
        scannedDevices = (HashMap<String, IoTDevice>) b.getSerializable(IoTServiceCommand.KEY_DATA);
        if (scannedDevices == null) {
            scannedDevices = new HashMap<>();
        }
    }

    if (scannedDevices == null || scannedDevices.size() == 0) {
        Log.w(TAG, "empty device list");
        //return; // ?  ?     .
    }

    boolean changed = false;
    Iterator<String> iter = scannedDevices.keySet().iterator();
    Log.d(TAG, "IoTServiceCommand.GET_DEVICE_LIST added size = " + scannedDevices.size());
    while (iter.hasNext()) {
        String key = iter.next();
        IoTDevice bondedDevice = mBondedWithServerList.get(key);

        IoTDevice scannedDevice = scannedDevices.get(key);
        Log.d(TAG, "check " + key + " is exist or new...");
        // ? ?? ? ?? ? ?  ? ?.
        if (bondedDevice == null) {
            continue;
        }

        //            if (bondedDevice != null) {           // already exist
        if (scannedDevice.getUuids() == null || scannedDevice.getUuids().size() == 0) {
            Log.e(TAG, ">>> xx device name " + bondedDevice.getDeviceName() + " has no uuid advertisement");
            continue;
        }
        ArrayList<String> deviceUuids = bondedDevice.getUuids();
        if (deviceUuids == null || deviceUuids.size() == 0) {
            if (bondedDevice.getDeviceTypeId() == IoTDevice.DEVICE_TYPE_ID_BT) {
                bondedDevice.setAdRecordHashMap(scannedDevice.getAdRecordHashMap());
                bondedDevice.setUuids(scannedDevice.getUuids());
                bondedDevice.setUuidLen(scannedDevice.getUuidLen());
            }
            bondedDevice.setIsKnownDevice(isKnownScenarioDevice(bondedDevice.getDeviceTypeId(),
                    bondedDevice.getUuids(), bondedDevice.getUuidLen()));
            mBondedWithServerList.put(key, bondedDevice);
            changed = true;
        } else {
            if (!scannedDevice.getUuids().equals(deviceUuids)) {
                if (bondedDevice.getDeviceTypeId() == IoTDevice.DEVICE_TYPE_ID_BT) {
                    bondedDevice.setAdRecordHashMap(scannedDevice.getAdRecordHashMap());
                    bondedDevice.setUuids(scannedDevice.getUuids());
                    bondedDevice.setUuidLen(scannedDevice.getUuidLen());
                }
                bondedDevice.setIsKnownDevice(isKnownScenarioDevice(bondedDevice.getDeviceTypeId(),
                        bondedDevice.getUuids(), bondedDevice.getUuidLen()));
                mBondedWithServerList.put(key, bondedDevice);
                changed = true;
            }
        }
        // do nothing...
        // ? ?? ? ?? ? ?  ? ?.
        //            } else {
        //                ArrayList<String> uuids = DataParser.getUuids(scannedDevice.getAdRecordHashMap());
        //                if (uuids == null || uuids.size() == 0) {
        //                    Log.e(TAG, ">>> device name " + scannedDevice.getDeviceName() + " has no uuid advertisement");
        //                    continue;
        //                }
        //                scannedDevice.setUuids(uuids);
        //                scannedDevice.setUuidLen(DataParser.getUuidLength(scannedDevice.getAdRecordHashMap()));
        //                scannedDevice.setIsKnownDevice(isKnownScenarioDevice(scannedDevice.getDeviceTypeId(), scannedDevice.getUuids(), scannedDevice.getUuidLen()));
        //
        //                bondedDevice = scannedDevice;
        //                mBondedWithServerList.put(bondedDevice.getDeviceId(), bondedDevice);
        //                changed = true;
        //            }

        // ??  ?? .
        if (bondedDevice.isBondedWithServer() && isEmergencyCallDevice(bondedDevice.getDeviceTypeId(),
                bondedDevice.getUuids(), bondedDevice.getUuidLen())) {
            Log.d(TAG, "Emergency call device broadcast received : " + bondedDevice.getDeviceId());

            mEmergencyDeviceList.add(bondedDevice);
        }

        //   ? ?  ?? Notification  ?.
        if (bondedDevice.isBondedWithServer() && isKeepAliveDevice(bondedDevice)) {
            Log.d(TAG, "Smart sensor device found device ID = " + bondedDevice.getDeviceId());

            if (!mKeepAliveDeviceList.containsKey(bondedDevice.getDeviceId())) {
                // ? ? ?  3 .
                if (mKeepAliveDeviceList.size() >= MAX_KEEP_ALIVE_CONNECTED_DEVICE_SIZE) {
                    Log.d(TAG, "MAX_KEEP_ALIVE_CONNECTED_DEVICE_SIZE reached....");
                    // do nothing.
                } else {
                    mKeepAliveDeviceList.put(bondedDevice.getDeviceId(), bondedDevice);
                    Bundle extras = new Bundle();
                    IoTHandleData data = new IoTHandleData();
                    data.setDeviceId(bondedDevice.getDeviceId());
                    data.setDeviceTypeId(bondedDevice.getDeviceTypeId());
                    data.setIsKeepAliveDevice(true);

                    extras.putParcelable(IoTServiceCommand.KEY_DATA, data);
                    sendMessageToService(IoTServiceCommand.DEVICE_CONNECT, extras);
                }
            } else {
                Log.d(TAG, "This device already connected. and collecting data... ");
            }
        }
    }

    if (changed) {
        // save to preference.
        String json = mGson.toJson(mBondedWithServerList);
        if (json != null) {
            IoTServicePreference.setIoTDevicesList(mCtx, json);
        }
    }
    Log.d(TAG, "Current device size = " + mBondedWithServerList.size());
    if (mEmergencyDeviceList.size() > 0) {
        // ??  ?  
        long currTimeMs = System.currentTimeMillis();
        //if (currTimeMs - mLastEmergencyDeviceFoundTimeMs > 1 * 60 * 1000) {
        mIsEmergencyDataCollecting = true;

        //   ?  ?? ? .
        Bundle extras = new Bundle();
        extras.putBoolean(IoTServiceCommand.KEY_DATA, false);
        sendMessageToService(IoTServiceCommand.SCANNING_STOP, extras);

        mHandler.removeMessages(HANDLER_RETRIEVE_IOT_DEVICES);
        sendMessageToService(IoTServiceCommand.DEVICE_DISCONNECT_ALL, null);
        //            } else {
        //                Log.d(TAG, ">>> Already emergency device retrive.. before = " + (currTimeMs - mLastEmergencyDeviceFoundTimeMs));
        //                mIsEmergencyDataCollecting = false;
        //                mEmergencyDeviceList.clear();
        //            }
    }

    if (mForceRescanCallback == null) {
        return;
    }

    final IoTServiceStatusNotification responseCallback = mForceRescanCallback.get();
    if (responseCallback != null) {
        Bundle extras = new Bundle();
        ArrayList<IoTDevice> devicesList = null;
        // 2015.12.09
        // ?? ? BT  .
        // ? ?? ? ???  ?  .

        //if (mBondedWithServerList != null && mBondedWithServerList.size() > 0) {
        //    devicesList = new ArrayList<>(mBondedWithServerList.values());
        //} else {
        //    devicesList = new ArrayList<>();
        //}
        if (mKeepAliveDeviceList != null && mKeepAliveDeviceList.size() > 0) {
            devicesList = new ArrayList<>(mKeepAliveDeviceList.values());
        } else {
            devicesList = new ArrayList<>();
        }

        // 
        ArrayList<String> deviceIdList = new ArrayList<>();
        for (int i = 0; i < devicesList.size(); i++) {
            deviceIdList.add(devicesList.get(i).getDeviceId());
        }

        ArrayList<IoTDevice> scannedDevicesList = new ArrayList<>(scannedDevices.values());
        for (int i = 0; i < scannedDevicesList.size(); i++) {
            if (deviceIdList.contains(scannedDevicesList.get(i).getDeviceId())) {
                Log.d(TAG, "mForceRescanCallback device id " + scannedDevicesList.get(i).getDeviceId()
                        + " is already added.");
                continue;
            }
            devicesList.add(scannedDevicesList.get(i));
        }
        extras.putParcelableArrayList(IoTServiceCommand.KEY_DATA, devicesList);
        responseCallback.onResult(IoTServiceCommand.GET_DEVICE_LIST, mServiceStatus, mErrorCodes, extras);
    }
    mForceRescanCallback = null;
    // TODO : log
    if (BuildConfig.DEBUG) {
        iter = mBondedWithServerList.keySet().iterator();
        while (iter.hasNext()) {
            String key = iter.next();
            IoTDevice device = mBondedWithServerList.get(key);

            printScanDeviceInformation(device);
        }
    }

}

From source file:com.lastsoft.plog.PlaysFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final View rootView = inflater.inflate(R.layout.fragment_plays, container, false);

    rootView.setTag(TAG);/*from   w  ww. j  a va  2s  .  c  o m*/

    // BEGIN_INCLUDE(initializeRecyclerView)
    mRecyclerView = (RecyclerView) rootView.findViewById(R.id.recyclerView);
    mRecyclerView.setBackgroundColor(getResources().getColor(R.color.cardview_initial_background));
    RecyclerFastScroller fastScroller = (RecyclerFastScroller) rootView.findViewById(R.id.fastscroller);

    // Connect the recycler to the scroller (to let the scroller scroll the list)
    fastScroller.attachRecyclerView(mRecyclerView);

    addPlay = (FloatingActionButton) rootView.findViewById(R.id.add_play);
    if (fromDrawer && playListType != 2) {
        addPlay.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int viewXY[] = new int[2];
                v.getLocationOnScreen(viewXY);
                /*if (mListener != null) {
                mListener.onFragmentInteraction("add_play", viewXY[0], viewXY[1]);
                }*/
                ((MainActivity) mActivity).usedFAB = true;
                ((MainActivity) mActivity).openGames("", true, 0, getString(R.string.title_games),
                        MainActivity.CurrentYear);
            }
        });
    } else {
        addPlay.setVisibility(View.GONE);
    }

    fabMargin = getResources().getDimensionPixelSize(R.dimen.fab_margin);
    mRecyclerView.addOnScrollListener(new MyRecyclerScroll() {
        @Override
        public void show() {
            addPlay.animate().translationY(0).setInterpolator(new DecelerateInterpolator(2)).start();
        }

        @Override
        public void hide() {
            addPlay.animate().translationY(addPlay.getHeight() + fabMargin)
                    .setInterpolator(new AccelerateInterpolator(2)).start();
        }
    });

    // Connect the scroller to the recycler (to let the recycler scroll the scroller's handle)
    //mRecyclerView.addOnScrollListener(fastScroller.getOnScrollListener());

    // LinearLayoutManager is used here, this will layout the elements in a similar fashion
    // to the way ListView would layout elements. The RecyclerView.LayoutManager defines how
    // elements are laid out.
    mLayoutManager = new LinearLayoutManager(mActivity);

    mCurrentLayoutManagerType = LayoutManagerType.LINEAR_LAYOUT_MANAGER;

    if (savedInstanceState != null) {
        // Restore saved layout manager type.
        mCurrentLayoutManagerType = (LayoutManagerType) savedInstanceState.getSerializable(KEY_LAYOUT_MANAGER);
    }
    setRecyclerViewLayoutManager(mCurrentLayoutManagerType);

    //mAdapter = new PlayAdapter(mActivity, this);

    /*if (((MainActivity)mActivity).mPlayAdapter != null) {
    mAdapter = ((MainActivity) mActivity).mPlayAdapter;
    }else{*/
    mAdapter = ((MainActivity) mActivity).initPlayAdapter(mSearchQuery, fromDrawer, playListType, currentYear);
    //}
    // Set CustomAdapter as the adapter for RecyclerView.
    mRecyclerView.setAdapter(mAdapter);
    // END_INCLUDE(initializeRecyclerView)

    if (mSearch != null) {
        mSearch.setHint(
                getString(R.string.filter) + mAdapter.getItemCount() + getString(R.string.filter_plays));
    }

    /*boolean pauseOnScroll = true; // or true
    boolean pauseOnFling = true; // or false
    NewPauseOnScrollListener listener = new NewPauseOnScrollListener(ImageLoader.getInstance(), pauseOnScroll, pauseOnFling);
    mRecyclerView.addOnScrollListener(listener);*/

    if (!fromDrawer) {
        RelativeLayout playsLayout = (RelativeLayout) rootView.findViewById(R.id.playsLayout);
        final SwipeDismissBehavior<LinearLayout> behavior = new SwipeDismissBehavior();
        behavior.setSwipeDirection(SwipeDismissBehavior.SWIPE_DIRECTION_START_TO_END);
        behavior.setStartAlphaSwipeDistance(1.0f);
        behavior.setSensitivity(0.15f);
        behavior.setListener(new SwipeDismissBehavior.OnDismissListener() {
            @Override
            public void onDismiss(final View view) {
                PlaysFragment myFragC1 = (PlaysFragment) getFragmentManager().findFragmentByTag("plays");
                FragmentTransaction transaction = getFragmentManager().beginTransaction();
                transaction.remove(myFragC1);
                transaction.commitAllowingStateLoss();
                getFragmentManager().executePendingTransactions();
                mActivity.onBackPressed();
            }

            @Override
            public void onDragStateChanged(int i) {

            }
        });

        CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) playsLayout.getLayoutParams();
        params.setBehavior(behavior);
    }

    if (mSearch != null) {
        mSearch.addTextChangedListener(new TextWatcher() {

            @Override
            public void onTextChanged(CharSequence cs, int arg1, int arg2, int arg3) {
                // When user changed the Text
                if (mActivity != null) {
                    mSearchQuery = cs.toString();
                    //initDataset();
                    //mAdapter = new GameAdapter(PlaysFragment.this, mActivity,mSearchQuery);
                    mAdapter = ((MainActivity) mActivity).initPlayAdapter(mSearchQuery, fromDrawer,
                            playListType, currentYear);
                    // Set CustomAdapter as the adapter for RecyclerView.
                    mRecyclerView.setAdapter(mAdapter);
                }
            }

            @Override
            public void afterTextChanged(Editable editable) {
            }

            @Override
            public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
            }
        });

        mCancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (!mSearch.getText().toString().equals("")) {
                    mSearchQuery = "";
                    ((MainActivity) mActivity).initPlayAdapter(mSearchQuery, fromDrawer, playListType,
                            currentYear);
                    mSearch.setText(mSearchQuery);

                    //mActivity.onBackPressed();
                }

                InputMethodManager inputManager = (InputMethodManager) mActivity
                        .getSystemService(Context.INPUT_METHOD_SERVICE);

                inputManager.hideSoftInputFromWindow(mActivity.getCurrentFocus().getWindowToken(),
                        InputMethodManager.HIDE_NOT_ALWAYS);
                mSearch.clearFocus();
                mRecyclerView.requestFocus();

                refreshDataset();
            }
        });
    }

    return rootView;
}

From source file:com.kenmeidearu.materialdatetimepicker.date.DatePickerDialog.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    // All options have been set at this point: round the initial selection if necessary
    setToNearestDate(mCalendar);//from w  w  w  . j a v  a2s  .c  o m

    View view = inflater.inflate(R.layout.mdtp_date_picker_dialog, container, false);
    timeDisplayView = (RelativeLayout) view.findViewById(R.id.time_display);
    mDayOfWeekView = (TextView) view.findViewById(R.id.date_picker_header);
    mMonthAndDayView = (LinearLayout) view.findViewById(R.id.date_picker_month_and_year);
    mSelectedMonthTextView = (TextView) view.findViewById(R.id.date_picker_month);
    mSelectedMonthTextView.setOnClickListener(this);
    mSelectedDayTextView = (TextView) view.findViewById(R.id.date_picker_day);
    mSelectedDayTextView.setOnClickListener(this);

    mYearView = (TextView) view.findViewById(R.id.date_picker_year);
    mYearView.setOnClickListener(this);

    int listPosition = -1;
    int listPositionOffset = 0;
    int currentView = mDefaultView;
    if (savedInstanceState != null) {
        mWeekStart = savedInstanceState.getInt(KEY_WEEK_START);
        mMinYear = savedInstanceState.getInt(KEY_YEAR_START);
        mMaxYear = savedInstanceState.getInt(KEY_YEAR_END);
        currentView = savedInstanceState.getInt(KEY_CURRENT_VIEW);
        listPosition = savedInstanceState.getInt(KEY_LIST_POSITION);
        listPositionOffset = savedInstanceState.getInt(KEY_LIST_POSITION_OFFSET);
        mMinDate = (Calendar) savedInstanceState.getSerializable(KEY_MIN_DATE);
        mMaxDate = (Calendar) savedInstanceState.getSerializable(KEY_MAX_DATE);
        highlightedDays = (Calendar[]) savedInstanceState.getSerializable(KEY_HIGHLIGHTED_DAYS);
        selectableDays = (Calendar[]) savedInstanceState.getSerializable(KEY_SELECTABLE_DAYS);
        disabledDays = (Calendar[]) savedInstanceState.getSerializable(KEY_DISABLED_DAYS);
        mThemeDark = savedInstanceState.getBoolean(KEY_THEME_DARK);
        mThemeDarkChanged = savedInstanceState.getBoolean(KEY_THEME_DARK_CHANGED);
        mAccentColor = savedInstanceState.getInt(KEY_ACCENT);
        mVibrate = savedInstanceState.getBoolean(KEY_VIBRATE);
        mDismissOnPause = savedInstanceState.getBoolean(KEY_DISMISS);
        mAutoDismiss = savedInstanceState.getBoolean(KEY_AUTO_DISMISS);
        mTitle = savedInstanceState.getString(KEY_TITLE);
        mOkResid = savedInstanceState.getInt(KEY_OK_RESID);
        mOkString = savedInstanceState.getString(KEY_OK_STRING);
        mCancelResid = savedInstanceState.getInt(KEY_CANCEL_RESID);
        mCancelString = savedInstanceState.getString(KEY_CANCEL_STRING);
    }

    final Activity activity = getActivity();
    mDayPickerView = new SimpleDayPickerView(activity, this);
    mYearPickerView = new YearPickerView(activity, this);
    mMonthPickerView = new MonthPickerView(activity, this);
    mHourPickerView = new TimePickerView(activity, this, "HOUR", mIs24HourMode);
    mMinutePickerView = new TimePickerView(activity, this, "MINUTE", mIs24HourMode);
    mSecondPickerView = new TimePickerView(activity, this, "SECOND", mIs24HourMode);

    // if theme mode has not been set by java code, check if it is specified in Style.xml
    if (!mThemeDarkChanged) {
        mThemeDark = Utils.isDarkTheme(activity, mThemeDark);
    }

    Resources res = getResources();
    mDayPickerDescription = res.getString(R.string.mdtp_day_picker_description);
    mSelectDay = res.getString(R.string.mdtp_select_day);
    mMonthPickerDescription = res.getString(R.string.mdtp_month_picker_description);
    mSelectMonth = res.getString(R.string.mdtp_select_month);
    mYearPickerDescription = res.getString(R.string.mdtp_year_picker_description);
    mSelectYear = res.getString(R.string.mdtp_select_year);
    //add for timer dialog
    mHourPickerDescription = res.getString(R.string.mdtp_hour_picker_description);
    mSelectHours = res.getString(R.string.mdtp_select_hours);
    mMinutePickerDescription = res.getString(R.string.mdtp_minute_picker_description);
    mSelectMinutes = res.getString(R.string.mdtp_select_minutes);
    mSecondPickerDescription = res.getString(R.string.mdtp_second_picker_description);
    mSelectSeconds = res.getString(R.string.mdtp_select_seconds);

    mHourView = (TextView) view.findViewById(R.id.hours);
    mHourView.setOnClickListener(this);
    mHourSpaceView = (TextView) view.findViewById(R.id.hour_space);
    mMinuteSpaceView = (TextView) view.findViewById(R.id.minutes_space);
    mMinuteView = (TextView) view.findViewById(R.id.minutes);
    mMinuteView.setOnClickListener(this);
    mSecondSpaceView = (TextView) view.findViewById(R.id.seconds_space);
    mSecondView = (TextView) view.findViewById(R.id.seconds);
    mSecondView.setOnClickListener(this);
    mAmPmTextView = (TextView) view.findViewById(R.id.ampm_label);
    mAmPmTextView.setOnClickListener(this);
    String[] amPmTexts = new DateFormatSymbols().getAmPmStrings();
    mAmText = amPmTexts[0];
    mPmText = amPmTexts[1];

    // Enable or disable the AM/PM view.
    mAmPmHitspace = view.findViewById(R.id.ampm_hitspace);
    if (mIs24HourMode) {
        mAmPmTextView.setVisibility(View.GONE);
    } else {
        mAmPmTextView.setVisibility(View.VISIBLE);
        updateAmPmDisplay(mInitialTime.isAM() ? AM : PM);
        mAmPmHitspace.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {

                tryVibrate();
                int amOrPm = getIsCurrentlyAmOrPm();
                if (amOrPm == AM) {
                    amOrPm = PM;
                } else if (amOrPm == PM) {
                    amOrPm = AM;
                }
                setAmOrPm(amOrPm);
            }
        });
    }

    // Disable seconds picker
    if (!mEnableSeconds) {
        mSecondView.setVisibility(View.GONE);
        view.findViewById(R.id.separator_seconds).setVisibility(View.GONE);
    }

    // Disable minutes picker
    if (!mEnableMinutes) {
        mMinuteSpaceView.setVisibility(View.GONE);
        view.findViewById(R.id.separator).setVisibility(View.GONE);
    }

    // Center stuff depending on what's visible
    //only enable date
    if (mOnlyDate) {
        timeDisplayView.setVisibility(View.GONE);
    }
    if (mIs24HourMode && !mEnableSeconds && mEnableMinutes) {
        // center first separator
        RelativeLayout.LayoutParams paramsSeparator = new RelativeLayout.LayoutParams(
                ActionBar.LayoutParams.WRAP_CONTENT, ActionBar.LayoutParams.WRAP_CONTENT);
        paramsSeparator.addRule(RelativeLayout.CENTER_IN_PARENT);
        TextView separatorView = (TextView) view.findViewById(R.id.separator);
        separatorView.setLayoutParams(paramsSeparator);
    } else if (!mEnableMinutes && !mEnableSeconds) {
        // center the hour
        RelativeLayout.LayoutParams paramsHour = new RelativeLayout.LayoutParams(
                ActionBar.LayoutParams.WRAP_CONTENT, ActionBar.LayoutParams.WRAP_CONTENT);
        paramsHour.addRule(RelativeLayout.CENTER_IN_PARENT);
        mHourSpaceView.setLayoutParams(paramsHour);

        if (!mIs24HourMode) {
            RelativeLayout.LayoutParams paramsAmPm = new RelativeLayout.LayoutParams(
                    ActionBar.LayoutParams.WRAP_CONTENT, ActionBar.LayoutParams.WRAP_CONTENT);
            paramsAmPm.addRule(RelativeLayout.RIGHT_OF, R.id.hour_space);
            paramsAmPm.addRule(RelativeLayout.ALIGN_BASELINE, R.id.hour_space);
            mAmPmTextView.setLayoutParams(paramsAmPm);
        }
    } else if (mEnableSeconds) {
        // link separator to minutes
        final View separator = view.findViewById(R.id.separator);
        RelativeLayout.LayoutParams paramsSeparator = new RelativeLayout.LayoutParams(
                ActionBar.LayoutParams.WRAP_CONTENT, ActionBar.LayoutParams.WRAP_CONTENT);
        paramsSeparator.addRule(RelativeLayout.LEFT_OF, R.id.minutes_space);
        paramsSeparator.addRule(RelativeLayout.CENTER_VERTICAL, RelativeLayout.TRUE);
        separator.setLayoutParams(paramsSeparator);

        if (!mIs24HourMode) {
            // center minutes
            RelativeLayout.LayoutParams paramsMinutes = new RelativeLayout.LayoutParams(
                    ActionBar.LayoutParams.WRAP_CONTENT, ActionBar.LayoutParams.WRAP_CONTENT);
            paramsMinutes.addRule(RelativeLayout.CENTER_IN_PARENT);
            mMinuteSpaceView.setLayoutParams(paramsMinutes);
        } else {
            // move minutes to right of center
            RelativeLayout.LayoutParams paramsMinutes = new RelativeLayout.LayoutParams(
                    ActionBar.LayoutParams.WRAP_CONTENT, ActionBar.LayoutParams.WRAP_CONTENT);
            paramsMinutes.addRule(RelativeLayout.RIGHT_OF, R.id.center_view);
            mMinuteSpaceView.setLayoutParams(paramsMinutes);
        }
    }

    //end timer
    int bgColorResource = mThemeDark ? R.color.mdtp_date_picker_view_animator_dark_theme
            : R.color.mdtp_date_picker_view_animator;
    view.setBackgroundColor(ContextCompat.getColor(activity, bgColorResource));

    mAnimator = (AccessibleDateAnimator) view.findViewById(R.id.animator);
    mAnimator.addView(mDayPickerView);
    mAnimator.addView(mYearPickerView);
    mAnimator.addView(mMonthPickerView);
    mAnimator.addView(mHourPickerView);
    mAnimator.addView(mMinutePickerView);
    mAnimator.addView(mSecondPickerView);
    mAnimator.setTimeMilis(mInitialTime);
    mAnimator.setDateMillis(mCalendar.getTimeInMillis());
    // TODO: Replace with animation decided upon by the design team.
    Animation animation = new AlphaAnimation(0.0f, 1.0f);
    animation.setDuration(ANIMATION_DURATION);
    mAnimator.setInAnimation(animation);
    // TODO: Replace with animation decided upon by the design team.
    Animation animation2 = new AlphaAnimation(1.0f, 0.0f);
    animation2.setDuration(ANIMATION_DURATION);
    mAnimator.setOutAnimation(animation2);

    Button okButton = (Button) view.findViewById(R.id.ok);
    okButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            tryVibrate();
            notifyOnDateListener();
            dismiss();
        }
    });
    okButton.setTypeface(TypefaceHelper.get(activity, "Roboto-Medium"));
    if (mOkString != null)
        okButton.setText(mOkString);
    else
        okButton.setText(mOkResid);

    Button cancelButton = (Button) view.findViewById(R.id.cancel);
    cancelButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            tryVibrate();
            if (getDialog() != null)
                getDialog().cancel();
        }
    });
    cancelButton.setTypeface(TypefaceHelper.get(activity, "Roboto-Medium"));
    if (mCancelString != null)
        cancelButton.setText(mCancelString);
    else
        cancelButton.setText(mCancelResid);
    cancelButton.setVisibility(isCancelable() ? View.VISIBLE : View.GONE);

    // If an accent color has not been set manually, get it from the context
    if (mAccentColor == -1) {
        mAccentColor = Utils.getAccentColorFromThemeIfAvailable(getActivity());
    }
    if (mDayOfWeekView != null)
        mDayOfWeekView.setBackgroundColor(Utils.darkenColor(mAccentColor));
    view.findViewById(R.id.day_picker_selected_date_layout).setBackgroundColor(mAccentColor);
    okButton.setTextColor(mAccentColor);
    cancelButton.setTextColor(mAccentColor);

    if (getDialog() == null) {
        view.findViewById(R.id.done_background).setVisibility(View.GONE);
    }

    updateDisplay(false);
    setCurrentView(currentView);

    if (listPosition != -1) {
        if (currentView == MONTH_AND_DAY_VIEW) {
            mDayPickerView.postSetSelection(listPosition);
        } else if (currentView == MONTH_VIEW) {
            mMonthPickerView.postSetSelectionFromTop(listPosition, listPositionOffset);
        } else if (currentView == YEAR_VIEW) {
            mYearPickerView.postSetSelectionFromTop(listPosition, listPositionOffset);
        } else if (currentView == HOUR_INDEX) {
            mHourPickerView.postSetSelectionFromTop(listPosition, listPositionOffset);
        } else if (currentView == MINUTE_INDEX) {
            mMinutePickerView.postSetSelectionFromTop(listPosition, listPositionOffset);
        } else if (currentView == SECOND_INDEX) {
            mSecondPickerView.postSetSelectionFromTop(listPosition, listPositionOffset);
        }
    }

    mHapticFeedbackController = new HapticFeedbackController(activity);
    return view;
}

From source file:com.github.chenxiaolong.dualbootpatcher.switcher.InAppFlashingFragment.java

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

    if (savedInstanceState != null) {
        ArrayList<MbtoolAction> savedActions = savedInstanceState.getParcelableArrayList(EXTRA_PENDING_ACTIONS);
        mPendingActions.addAll(savedActions);
    }//w  w w  .ja  v  a 2  s  . com

    mProgressBar = (ProgressBar) getActivity().findViewById(R.id.card_list_loading);
    RecyclerView cardListView = (RecyclerView) getActivity().findViewById(R.id.card_list);

    mAdapter = new PendingActionCardAdapter(getActivity(), mPendingActions);
    cardListView.setHasFixedSize(true);
    cardListView.setAdapter(mAdapter);

    DragSwipeItemTouchCallback itemTouchCallback = new DragSwipeItemTouchCallback(this);
    ItemTouchHelper itemTouchHelper = new ItemTouchHelper(itemTouchCallback);
    itemTouchHelper.attachToRecyclerView(cardListView);

    LinearLayoutManager llm = new LinearLayoutManager(getActivity());
    llm.setOrientation(LinearLayoutManager.VERTICAL);
    cardListView.setLayoutManager(llm);

    final FloatingActionMenu fabMenu = (FloatingActionMenu) getActivity().findViewById(R.id.fab_add_item_menu);
    FloatingActionButton fabAddPatchedFile = (FloatingActionButton) getActivity()
            .findViewById(R.id.fab_add_patched_file);
    FloatingActionButton fabAddBackup = (FloatingActionButton) getActivity().findViewById(R.id.fab_add_backup);

    fabAddPatchedFile.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            addPatchedFile();
            fabMenu.close(true);
        }
    });
    fabAddBackup.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            addBackup();
            fabMenu.close(true);
        }
    });

    if (savedInstanceState != null) {
        mSelectedUri = savedInstanceState.getParcelable(EXTRA_SELECTED_URI);
        mSelectedUriFileName = savedInstanceState.getString(EXTRA_SELECTED_URI_FILE_NAME);
        mSelectedBackupDirUri = savedInstanceState.getParcelable(EXTRA_SELECTED_BACKUP_DIR_URI);
        mSelectedBackupName = savedInstanceState.getString(EXTRA_SELECTED_BACKUP_NAME);
        mSelectedBackupTargets = savedInstanceState.getStringArray(EXTRA_SELECTED_BACKUP_TARGETS);
        mSelectedRomId = savedInstanceState.getString(EXTRA_SELECTED_ROM_ID);
        mZipRomId = savedInstanceState.getString(EXTRA_ZIP_ROM_ID);
        mAddType = (Type) savedInstanceState.getSerializable(EXTRA_ADD_TYPE);
        mTaskIdVerifyZip = savedInstanceState.getInt(EXTRA_TASK_ID_VERIFY_ZIP);
        mQueryingMetadata = savedInstanceState.getBoolean(EXTRA_QUERYING_METADATA);
    }

    try {
        mActivityCallback = (OnReadyStateChangedListener) getActivity();
    } catch (ClassCastException e) {
        throw new ClassCastException(getActivity().toString() + " must implement OnReadyStateChangedListener");
    }

    mActivityCallback.onReady(!mPendingActions.isEmpty());

    mPrefs = getActivity().getSharedPreferences("settings", 0);

    if (savedInstanceState == null) {
        boolean shouldShow = mPrefs.getBoolean(PREF_SHOW_FIRST_USE_DIALOG, true);
        if (shouldShow) {
            FirstUseDialog d = FirstUseDialog.newInstance(this, R.string.in_app_flashing_title,
                    R.string.in_app_flashing_dialog_first_use);
            d.show(getFragmentManager(), CONFIRM_DIALOG_FIRST_USE);
        }
    }

    getActivity().getLoaderManager().initLoader(0, null, this);
}