Example usage for android.os Bundle getParcelableArrayList

List of usage examples for android.os Bundle getParcelableArrayList

Introduction

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

Prototype

@Nullable
public <T extends Parcelable> ArrayList<T> getParcelableArrayList(@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:de.mrapp.android.dialog.decorator.WizardDialogDecorator.java

@Override
public final void onRestoreInstanceState(@NonNull final Bundle savedInstanceState) {
    setTabPosition(TabPosition.fromValue(savedInstanceState.getInt(TAB_POSITION_EXTRA)));
    enableTabLayout(savedInstanceState.getBoolean(TAB_LAYOUT_ENABLED_EXTRA));
    showTabLayout(savedInstanceState.getBoolean(TAB_LAYOUT_SHOWN_EXTRA));
    setTabIndicatorHeight(savedInstanceState.getInt(TAB_INDICATOR_HEIGHT_EXTRA));
    setTabIndicatorColor(savedInstanceState.getInt(TAB_INDICATOR_COLOR_EXTRA));
    setTabTextColor(savedInstanceState.getInt(TAB_TEXT_COLOR_EXTRA));
    setTabSelectedTextColor(savedInstanceState.getInt(TAB_SELECTED_TEXT_COLOR_EXTRA));
    enableSwipe(savedInstanceState.getBoolean(SWIPE_ENABLED_EXTRA));
    showButtonBar(savedInstanceState.getBoolean(BUTTON_BAR_SHOWN_EXTRA));
    setButtonTextColor(savedInstanceState.getInt(BUTTON_TEXT_COLOR_EXTRA));
    showButtonBarDivider(savedInstanceState.getBoolean(SHOW_BUTTON_BAR_DIVIDER_EXTRA));
    setButtonBarDividerColor(savedInstanceState.getInt(BUTTON_BAR_DIVIDER_COLOR_EXTRA));
    CharSequence backButtonText = savedInstanceState.getCharSequence(BACK_BUTTON_TEXT_EXTRA);
    CharSequence nextButtonText = savedInstanceState.getCharSequence(NEXT_BUTTON_TEXT_EXTRA);
    CharSequence finishButtonText = savedInstanceState.getCharSequence(FINISH_BUTTON_TEXT_EXTRA);

    if (!TextUtils.isEmpty(backButtonText)) {
        setBackButtonText(backButtonText);
    }//ww w  .j  ava 2s .  c om

    if (!TextUtils.isEmpty(nextButtonText)) {
        setNextButtonText(nextButtonText);
    }

    if (!TextUtils.isEmpty(finishButtonText)) {
        setFinishButtonText(finishButtonText);
    }

    ArrayList<ViewPagerItem> viewPagerItems = savedInstanceState.getParcelableArrayList(VIEW_PAGER_ITEMS_EXTRA);

    if (viewPagerItems != null) {
        for (ViewPagerItem item : viewPagerItems) {
            addFragment(item.getTitle(), item.getFragmentClass(), item.getArguments());
        }
    }
}

From source file:com.bullmobi.base.ui.activities.SettingsActivity.java

@Override
protected void onCreate(Bundle savedState) {
    super.onCreate(savedState);

    // Should happen before any call to getIntent()
    getMetaData();//w w  w.  j  av  a2s  .c  om

    final Intent intent = getIntent();
    if (intent.hasExtra(EXTRA_UI_OPTIONS)) {
        getWindow().setUiOptions(intent.getIntExtra(EXTRA_UI_OPTIONS, 0));
    }

    // Getting Intent properties can only be done after the super.onCreate(...)
    final String initialFragmentName = intent.getStringExtra(EXTRA_SHOW_FRAGMENT);

    mIsShortcut = isShortCutIntent(intent) || isLikeShortCutIntent(intent)
            || intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SHORTCUT, false);

    final ComponentName cn = intent.getComponent();
    final String className = cn.getClassName();

    boolean isShowingDashboard = className.equals(Settings2.class.getName());

    // This is a "Sub Settings" when:
    // - this is a real SubSettings
    // - or :settings:show_fragment_as_subsetting is passed to the Intent
    final boolean isSubSettings = className.equals(SubSettings.class.getName())
            || intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SUBSETTING, false);

    // If this is a sub settings, then apply the SubSettings Theme for the ActionBar content insets
    if (isSubSettings) {
        // Check also that we are not a Theme Dialog as we don't want to override them
        /*
        final int themeResId = getTheme(). getThemeResId();
        if (themeResId != R.style.Theme_DialogWhenLarge &&
            themeResId != R.style.Theme_SubSettingsDialogWhenLarge) {
        setTheme(R.style.Theme_SubSettings);
        }
        */
    }

    setContentView(R.layout.settings_main_dashboard);

    mContent = (ViewGroup) findViewById(R.id.main_content);

    getSupportFragmentManager().addOnBackStackChangedListener(this);

    if (savedState != null) {
        // We are restarting from a previous saved state; used that to initialize, instead
        // of starting fresh.

        setTitleFromIntent(intent);

        ArrayList<DashboardCategory> categories = savedState.getParcelableArrayList(SAVE_KEY_CATEGORIES);
        if (categories != null) {
            mCategories.clear();
            mCategories.addAll(categories);
            setTitleFromBackStack();
        }

        mDisplayHomeAsUpEnabled = savedState.getBoolean(SAVE_KEY_SHOW_HOME_AS_UP);
    } else {
        if (!isShowingDashboard) {
            mDisplayHomeAsUpEnabled = isSubSettings;
            setTitleFromIntent(intent);

            Bundle initialArguments = intent.getBundleExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS);
            switchToFragment(initialFragmentName, initialArguments, true, false, mInitialTitleResId,
                    mInitialTitle, false);
        } else {
            mDisplayHomeAsUpEnabled = false;
            mInitialTitleResId = R.string.app_name;
            switchToFragment(DashboardFragment.class.getName(), null, false, false, mInitialTitleResId,
                    mInitialTitle, false);
        }
    }

    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(mDisplayHomeAsUpEnabled);
        actionBar.setHomeButtonEnabled(mDisplayHomeAsUpEnabled);
    }
}

From source file:com.achep.base.ui.activities.SettingsActivity.java

@Override
protected void onCreate(Bundle savedState) {
    super.onCreate(savedState);

    // Should happen before any call to getIntent()
    getMetaData();/* w w  w  . j  ava 2s.c  om*/

    final Intent intent = getIntent();
    if (intent.hasExtra(EXTRA_UI_OPTIONS)) {
        getWindow().setUiOptions(intent.getIntExtra(EXTRA_UI_OPTIONS, 0));
    }

    // Getting Intent properties can only be done after the super.onCreate(...)
    final String initialFragmentName = intent.getStringExtra(EXTRA_SHOW_FRAGMENT);

    mIsShortcut = isShortCutIntent(intent) || isLikeShortCutIntent(intent)
            || intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SHORTCUT, false);

    final ComponentName cn = intent.getComponent();
    final String className = cn.getClassName();

    boolean isShowingDashboard = className.equals(Settings2.class.getName());

    // This is a "Sub Settings" when:
    // - this is a real SubSettings
    // - or :settings:show_fragment_as_subsetting is passed to the Intent
    final boolean isSubSettings = className.equals(SubSettings.class.getName())
            || intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SUBSETTING, false);

    // If this is a sub settings, then apply the SubSettings Theme for the ActionBar content insets
    if (isSubSettings) {
        // Check also that we are not a Theme Dialog as we don't want to override them
        /*
        final int themeResId = getTheme(). getThemeResId();
        if (themeResId != R.style.Theme_DialogWhenLarge &&
            themeResId != R.style.Theme_SubSettingsDialogWhenLarge) {
        setTheme(R.style.Theme_SubSettings);
        }
        */
    }

    setContentView(R.layout.settings_main_dashboard);

    mContent = (ViewGroup) findViewById(android.R.id.content);

    getSupportFragmentManager().addOnBackStackChangedListener(this);

    if (savedState != null) {
        // We are restarting from a previous saved state; used that to initialize, instead
        // of starting fresh.

        setTitleFromIntent(intent);

        ArrayList<DashboardCategory> categories = savedState.getParcelableArrayList(SAVE_KEY_CATEGORIES);
        if (categories != null) {
            mCategories.clear();
            mCategories.addAll(categories);
            setTitleFromBackStack();
        }

        mDisplayHomeAsUpEnabled = savedState.getBoolean(SAVE_KEY_SHOW_HOME_AS_UP);
    } else {
        if (!isShowingDashboard) {
            mDisplayHomeAsUpEnabled = isSubSettings;
            setTitleFromIntent(intent);

            Bundle initialArguments = intent.getBundleExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS);
            switchToFragment(initialFragmentName, initialArguments, true, false, mInitialTitleResId,
                    mInitialTitle, false);
        } else {
            mDisplayHomeAsUpEnabled = false;
            mInitialTitleResId = R.string.app_name;
            switchToFragment(DashboardFragment.class.getName(), null, false, false, mInitialTitleResId,
                    mInitialTitle, false);
        }
    }

    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(mDisplayHomeAsUpEnabled);
        actionBar.setHomeButtonEnabled(mDisplayHomeAsUpEnabled);
    }
}

From source file:de.sourcestream.movieDB.controller.MovieDetailsInfo.java

/**
 * Fired when are restoring from backState or orientation has changed.
 *
 * @param args our bundle with saved state. Our parent fragment handles the saving.
 *///from   w w  w  . j a va  2  s  . co  m
@SuppressWarnings("ConstantConditions")
private void onOrientationChange(Bundle args) {
    // BackDrop path
    backDropCheck = args.getInt("backDropCheck");
    if (backDropCheck == 0) {
        activity.setBackDropImage(backDropPath, args.getString("backDropUrl"));
        backDropPath.setTag(args.getString("backDropUrl"));
    }

    // Title
    activity.setText(titleText, args.getString("titleText"));

    // Release date
    activity.setText(releaseDate, args.getString("releaseDate"));

    // Status
    activity.setText(statusText, args.getString("status"));

    // Tag line
    if (!args.getString("tagline").isEmpty())
        tagline.setText(args.getString("tagline"));
    else
        activity.hideTextView(tagline);

    // RunTime
    if (!args.getString("runTime").isEmpty())
        activity.setText(runtime, args.getString("runTime"));
    else
        activity.hideView(runtime);

    // Genres
    if (!args.getString("genres").isEmpty())
        activity.setText(genres, args.getString("genres"));
    else
        activity.hideView(genres);

    // Production Countries
    if (!args.getString("productionCountries").isEmpty())
        activity.setText(countries, args.getString("productionCountries"));
    else
        activity.hideView(countries);

    // Production Companies
    if (!args.getString("productionCompanies").isEmpty()) {
        activity.setText(companies, args.getString("productionCompanies"));
        if (args.getString("productionCountries").isEmpty()) {
            ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) companies.getLayoutParams();
            lp.setMargins(0, (int) (28 * getResources().getDisplayMetrics().density), 0, 0);
        }
    } else
        activity.hideView(companies);

    // Poster path
    if (args.getString("posterPathURL") != null) {
        activity.setImage(posterPath, args.getString("posterPathURL"));
        activity.setImageTag(posterPath, args.getString("posterPathURL"));
    }

    // Rating
    if (args.getString("voteCount").isEmpty()) {
        activity.hideRatingBar(ratingBar);
        activity.hideTextView(voteCount);
    } else {
        ratingBar.setRating(args.getFloat("rating"));
        activity.setText(voteCount, args.getString("voteCount"));
    }

    // Similar list
    similarList = args.getParcelableArrayList("similarList");
    if (similarList != null && similarList.size() > 0)
        setSimilarList(similarList);
    else
        activity.hideView(similarHolder);

}

From source file:com.android.messaging.datamodel.action.SyncMessagesAction.java

/**
 * Perform local database updates and schedule follow on sync actions
 *//*from   w ww .ja  v  a 2  s  . c om*/
@Override
protected Object processBackgroundResponse(final Bundle response) {
    final long lastTimestampMillis = response.getLong(BUNDLE_KEY_LAST_TIMESTAMP);
    final long lowerBoundTimeMillis = actionParameters.getLong(KEY_LOWER_BOUND);
    final long upperBoundTimeMillis = actionParameters.getLong(KEY_UPPER_BOUND);
    final int maxMessagesToUpdate = actionParameters.getInt(KEY_MAX_UPDATE);
    final long startTimestamp = actionParameters.getLong(KEY_START_TIMESTAMP);

    // Check with the sync manager if any conflicting updates have been made to databases
    final SyncManager syncManager = DataModel.get().getSyncManager();
    final boolean orphan = !syncManager.isSyncing(upperBoundTimeMillis);

    // lastTimestampMillis used to indicate failure
    if (orphan) {
        // This batch does not match current in progress timestamp.
        LogUtil.w(TAG, "SyncMessagesAction: Ignoring orphan sync batch for messages from "
                + lowerBoundTimeMillis + " to " + upperBoundTimeMillis);
    } else {
        final boolean dirty = syncManager.isBatchDirty(lastTimestampMillis);
        if (lastTimestampMillis == SYNC_FAILED) {
            LogUtil.e(TAG, "SyncMessagesAction: Sync failed - terminating");

            // Failed - update last sync times to throttle our failure rate
            final BuglePrefs prefs = BuglePrefs.getApplicationPrefs();
            // Save sync completion time so next sync will start from here
            prefs.putLong(BuglePrefsKeys.LAST_SYNC_TIME, startTimestamp);
            // Remember last full sync so that don't start background full sync right away
            prefs.putLong(BuglePrefsKeys.LAST_FULL_SYNC_TIME, startTimestamp);

            syncManager.complete();
        } else if (dirty) {
            LogUtil.w(TAG, "SyncMessagesAction: Redoing dirty sync batch of messages from "
                    + lowerBoundTimeMillis + " to " + upperBoundTimeMillis);

            // Redo this batch
            final SyncMessagesAction nextBatch = new SyncMessagesAction(lowerBoundTimeMillis,
                    upperBoundTimeMillis, maxMessagesToUpdate, startTimestamp);

            syncManager.startSyncBatch(upperBoundTimeMillis);
            requestBackgroundWork(nextBatch);
        } else {
            // Succeeded
            final ArrayList<SmsMessage> smsToAdd = response.getParcelableArrayList(BUNDLE_KEY_SMS_MESSAGES);
            final ArrayList<MmsMessage> mmsToAdd = response.getParcelableArrayList(BUNDLE_KEY_MMS_MESSAGES);
            final ArrayList<LocalDatabaseMessage> messagesToDelete = response
                    .getParcelableArrayList(BUNDLE_KEY_MESSAGES_TO_DELETE);

            final int messagesUpdated = smsToAdd.size() + mmsToAdd.size() + messagesToDelete.size();

            // Perform local database changes in one transaction
            long txnTimeMillis = 0;
            if (messagesUpdated > 0) {
                final long startTimeMillis = SystemClock.elapsedRealtime();
                final SyncMessageBatch batch = new SyncMessageBatch(smsToAdd, mmsToAdd, messagesToDelete,
                        syncManager.getThreadInfoCache());
                batch.updateLocalDatabase();
                final long endTimeMillis = SystemClock.elapsedRealtime();
                txnTimeMillis = endTimeMillis - startTimeMillis;

                LogUtil.i(TAG,
                        "SyncMessagesAction: Updated local database " + "(took " + txnTimeMillis
                                + " ms). Added " + smsToAdd.size() + " SMS, added " + mmsToAdd.size()
                                + " MMS, deleted " + messagesToDelete.size() + " messages.");

                // TODO: Investigate whether we can make this more fine-grained.
                MessagingContentProvider.notifyEverythingChanged();
            } else {
                if (LogUtil.isLoggable(TAG, LogUtil.DEBUG)) {
                    LogUtil.d(TAG, "SyncMessagesAction: No local database updates to make");
                }

                if (!syncManager.getHasFirstSyncCompleted()) {
                    // If we have never completed a sync before (fresh install) and there are
                    // no messages, still inform the UI of a change so it can update syncing
                    // messages shown to the user
                    MessagingContentProvider.notifyConversationListChanged();
                    MessagingContentProvider.notifyPartsChanged();
                }
            }
            // Determine if there are more messages that need to be scanned
            if (lastTimestampMillis >= 0 && lastTimestampMillis >= lowerBoundTimeMillis) {
                if (LogUtil.isLoggable(TAG, LogUtil.DEBUG)) {
                    LogUtil.d(TAG,
                            "SyncMessagesAction: More messages to sync; scheduling next " + "sync batch now.");
                }

                // Include final millisecond of last sync in next sync
                final long newUpperBoundTimeMillis = lastTimestampMillis + 1;
                final int newMaxMessagesToUpdate = nextBatchSize(messagesUpdated, txnTimeMillis);

                final SyncMessagesAction nextBatch = new SyncMessagesAction(lowerBoundTimeMillis,
                        newUpperBoundTimeMillis, newMaxMessagesToUpdate, startTimestamp);

                // Proceed with next batch
                syncManager.startSyncBatch(newUpperBoundTimeMillis);
                requestBackgroundWork(nextBatch);
            } else {
                final BuglePrefs prefs = BuglePrefs.getApplicationPrefs();
                // Save sync completion time so next sync will start from here
                prefs.putLong(BuglePrefsKeys.LAST_SYNC_TIME, startTimestamp);
                if (lowerBoundTimeMillis < 0) {
                    // Remember last full sync so that don't start another full sync right away
                    prefs.putLong(BuglePrefsKeys.LAST_FULL_SYNC_TIME, startTimestamp);
                }

                final long now = System.currentTimeMillis();

                // After any sync check if new messages have arrived
                final SyncCursorPair recents = new SyncCursorPair(startTimestamp, now);
                final SyncCursorPair olders = new SyncCursorPair(-1L, startTimestamp);
                final DatabaseWrapper db = DataModel.get().getDatabase();
                if (!recents.isSynchronized(db)) {
                    LogUtil.i(TAG, "SyncMessagesAction: Changed messages after sync; "
                            + "scheduling an incremental sync now.");

                    // Just add a new batch for recent messages
                    final SyncMessagesAction nextBatch = new SyncMessagesAction(startTimestamp, now, 0,
                            startTimestamp);
                    syncManager.startSyncBatch(now);
                    requestBackgroundWork(nextBatch);
                    // After partial sync verify sync state
                } else if (lowerBoundTimeMillis >= 0 && !olders.isSynchronized(db)) {
                    // Add a batch going back to start of time
                    LogUtil.w(TAG, "SyncMessagesAction: Changed messages before sync batch; "
                            + "scheduling a full sync now.");

                    final SyncMessagesAction nextBatch = new SyncMessagesAction(-1L, startTimestamp, 0,
                            startTimestamp);

                    syncManager.startSyncBatch(startTimestamp);
                    requestBackgroundWork(nextBatch);
                } else {
                    LogUtil.i(TAG, "SyncMessagesAction: All messages now in sync");

                    // All done, in sync
                    syncManager.complete();
                }
            }
            // Either sync should be complete or we should have a follow up request
            Assert.isTrue(hasBackgroundActions() || !syncManager.isSyncing());
        }
    }

    return null;
}

From source file:com.example.android.scopeddirectoryaccess.ScopedDirectoryAccessFragment.java

@Override
public void onViewCreated(final View rootView, Bundle savedInstanceState) {
    super.onViewCreated(rootView, savedInstanceState);

    mCurrentDirectoryTextView = (TextView) rootView.findViewById(R.id.textview_current_directory);
    mNothingInDirectoryTextView = (TextView) rootView.findViewById(R.id.textview_nothing_in_directory);
    mPrimaryVolumeNameTextView = (TextView) rootView.findViewById(R.id.textview_primary_volume_name);

    // Set onClickListener for the primary volume
    Button openPictureButton = (Button) rootView.findViewById(R.id.button_open_directory_primary_volume);
    openPictureButton.setOnClickListener(new View.OnClickListener() {
        @Override//from   w  ww  .jav  a  2 s .  c  om
        public void onClick(View view) {
            String selected = mDirectoriesSpinner.getSelectedItem().toString();
            String directoryName = getDirectoryName(selected);
            StorageVolume storageVolume = mStorageManager.getPrimaryStorageVolume();
            Intent intent = storageVolume.createAccessIntent(directoryName);
            startActivityForResult(intent, OPEN_DIRECTORY_REQUEST_CODE);
        }
    });

    // Set onClickListener for the external volumes if exists
    List<StorageVolume> storageVolumes = mStorageManager.getStorageVolumes();
    LinearLayout containerVolumes = (LinearLayout) mActivity.findViewById(R.id.container_volumes);
    for (final StorageVolume volume : storageVolumes) {
        String volumeDescription = volume.getDescription(mActivity);
        if (volume.isPrimary()) {
            // Primary volume area is already added...
            if (volumeDescription != null) {
                // ...but with a default name: set it to the real name when available.
                mPrimaryVolumeNameTextView.setText(volumeDescription);
            }
            continue;
        }
        LinearLayout volumeArea = (LinearLayout) mActivity.getLayoutInflater().inflate(R.layout.volume_entry,
                containerVolumes);
        TextView volumeName = (TextView) volumeArea.findViewById(R.id.textview_volume_name);
        volumeName.setText(volumeDescription);
        Button button = (Button) volumeArea.findViewById(R.id.button_open_directory);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String selected = mDirectoriesSpinner.getSelectedItem().toString();
                String directoryName = getDirectoryName(selected);
                Intent intent = volume.createAccessIntent(directoryName);
                startActivityForResult(intent, OPEN_DIRECTORY_REQUEST_CODE);
            }
        });
    }
    RecyclerView recyclerView = (RecyclerView) rootView.findViewById(R.id.recyclerview_directory_entries);
    if (savedInstanceState != null) {
        mDirectoryEntries = savedInstanceState.getParcelableArrayList(DIRECTORY_ENTRIES_KEY);
        mCurrentDirectoryTextView.setText(savedInstanceState.getString(SELECTED_DIRECTORY_KEY));
        mAdapter = new DirectoryEntryAdapter(mDirectoryEntries);
        if (mAdapter.getItemCount() == 0) {
            mNothingInDirectoryTextView.setVisibility(View.VISIBLE);
        }
    } else {
        mDirectoryEntries = new ArrayList<>();
        mAdapter = new DirectoryEntryAdapter();
    }
    recyclerView.setAdapter(mAdapter);
    recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
    mDirectoriesSpinner = (Spinner) rootView.findViewById(R.id.spinner_directories);
    ArrayAdapter<CharSequence> directoriesAdapter = ArrayAdapter.createFromResource(getActivity(),
            R.array.directories, android.R.layout.simple_spinner_item);
    directoriesAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    mDirectoriesSpinner.setAdapter(directoriesAdapter);
}

From source file:com.zns.comicdroid.activity.Comics.java

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

    mLvComics = (ListView) findViewById(R.id.comics_lvComics);
    mTvHeading = (TextView) findViewById(R.id.comics_txtHeading);
    mTvEmpty = (TextView) findViewById(R.id.comics_tvEmpty);
    mElvAmazon = (ExpandableListView) findViewById(R.id.comics_elvBooks);
    mElvAmazon.setOnChildClickListener(this);

    mAdapter = new ComicAdapter(this, getImagePath(true));
    mLvComics.setAdapter(mAdapter);//from w  w  w.  j a  va2 s  .c o m
    mLvComics.setOnItemClickListener(new android.widget.AdapterView.OnItemClickListener() {
        public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
            int comicId = mAdapter.getComicId(position);
            Intent intent = new Intent(Comics.this, ComicView.class);
            intent.putExtra(ComicView.INTENT_COMIC_ID, comicId);
            startActivity(intent);
        }
    });

    Intent intent = getIntent();
    mViewType = intent.getIntExtra(INTENT_COMICS_TYPE, 0);
    mViewWhereValue = intent.getCharSequenceExtra(INTENT_COMICS_VALUE).toString();
    mHeading = intent.getCharSequenceExtra(INTENT_COMICS_HEADING).toString();
    if (mHeading.length() == 0) {
        mHeading = getString(R.string.list_name_na);
    }
    mTvHeading.setText(mHeading);

    if (mViewType == VIEWTYPE_GROUP) {
        mGroupId = intent.getIntExtra(INTENT_COMICS_ID, 0);
        mCurrentGroup = getDBHelper().getGroup(mGroupId);
        mCbIsWatched = (CheckBox) findViewById(R.id.comics_cbWatched);
        mCbIsWatched.setChecked(mCurrentGroup.getIsWatched());
        mCbIsWatched.setOnCheckedChangeListener(this);
        mCbIsFinished = (CheckBox) findViewById(R.id.comics_cbFinished);
        mCbIsFinished.setChecked(mCurrentGroup.getIsFinished());
        mCbIsFinished.setOnCheckedChangeListener(this);
        mCbIsComplete = (CheckBox) findViewById(R.id.comics_cbComplete);
        mCbIsComplete.setChecked(mCurrentGroup.getIsComplete());
        mCbIsComplete.setOnCheckedChangeListener(this);
        mAdapter.mRenderTitle = false;
        findViewById(R.id.comics_group_alts).setVisibility(View.VISIBLE);
        registerForContextMenu(mLvComics);
    } else if (mViewType == VIEWTYPE_READ) {
        findViewById(R.id.comics_ivAmazonsearch).setVisibility(View.GONE);
    }

    //Amazon
    AssociatesAPI.initialize(new AssociatesAPI.Config(getString(R.string.key_amazon_appkey), this));

    //Restore State
    if (savedInstanceState != null && savedInstanceState.containsKey(STATE_BOOKS)) {
        ArrayList<Book> books = savedInstanceState.getParcelableArrayList(STATE_BOOKS);
        if (books != null) {
            mAmazonAdapter = new ExpandableAmazonAdapter(this, books);
            mElvAmazon.setAdapter(mAmazonAdapter);
            mElvAmazon.setVisibility(View.VISIBLE);
        }
    }
}

From source file:ru.moscow.tuzlukov.sergey.weatherlog.SettingsActivity.java

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

    tvRegisterAppId = (TextView) findViewById(R.id.tvRegisterAppId);
    tvSelectedCityInfo = (TextView) findViewById(R.id.tvSelectedCityInfo);
    etCityName = (EditText) findViewById(R.id.etCityName);
    ibSearch = (ImageButton) findViewById(R.id.ibSearch);
    lvVariants = (ListView) findViewById(R.id.lvVariants);
    tvErrorMessage = (TextView) findViewById(R.id.tvErrorMessage);
    llLoader = (LinearLayout) findViewById(R.id.llLoader);

    preferences = getSharedPreferences("preferences", MODE_PRIVATE);
    networkQuery = NetworkQuery.getInstance(getApplicationContext());
    registerDialog = new RegisterDialog(this, new DialogInterface.OnClickListener() {
        @Override/*from   www  .j  av a  2 s  .  c o  m*/
        public void onClick(DialogInterface dialog, int which) {
            String appId = registerDialog.getEtAppId().getText().toString().trim();
            networkQuery.setAppId(appId);
            preferences.edit().putString(NetworkQuery.Params.APPID, appId).apply();
            resultCode = RESULT_OK;
            setResult(resultCode);
            if (!appId.isEmpty())
                tvRegisterAppId.setText(getString(R.string.current_appid_caption) + " " + appId);
            else
                tvRegisterAppId.setText(getString(R.string.register_appid_label));
        }
    });

    String appId = preferences.getString(NetworkQuery.Params.APPID, "");
    if (!appId.isEmpty()) {
        tvRegisterAppId.setText(getString(R.string.current_appid_caption) + " " + appId);
        registerDialog.getEtAppId().setText(appId);
        //networkQuery.setAppId();
    }
    tvSelectedCityInfo.setText(String.format(getString(R.string.current_city_selected_label),
            preferences.getString("city", NetworkQuery.Defaults.CITY_NAME),
            preferences.getString("country", NetworkQuery.Defaults.CITY_COUNTRY),
            preferences.getInt("id", NetworkQuery.Defaults.CITY_ID),
            preferences.getFloat("lat", NetworkQuery.Defaults.CITY_LAT),
            preferences.getFloat("lon", NetworkQuery.Defaults.CITY_LON)));
    ibSearch.setOnClickListener(this);
    lvVariants.setOnItemClickListener(this);
    etCityName.setOnEditorActionListener(this);
    tvRegisterAppId.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            registerDialog.getEtAppId().setText(preferences.getString(NetworkQuery.Params.APPID, ""));
            registerDialog.show();
        }
    });

    if (savedInstanceState != null) {
        etCityName.setText(savedInstanceState.getString(SAVED_CITY_NAME_REQUESTED));
        cityList = savedInstanceState.getParcelableArrayList(SAVED_CITY_LIST);
        lvVariants
                .setVisibility(savedInstanceState.getBoolean(SAVED_LIST_VISIBILITY) ? View.VISIBLE : View.GONE);
        tvErrorMessage.setVisibility(
                savedInstanceState.getBoolean(SAVED_MESSAGE_VISIBILITY) ? View.VISIBLE : View.GONE);
        lvVariants.setAdapter(makeAdapter());
        resultCode = savedInstanceState.getInt(SAVED_RESULT_CODE, RESULT_CANCELED);
        setResult(resultCode);
        boolean refreshWasRun = savedInstanceState.getBoolean(SAVED_LOADER_VISIBILITY) || refreshWasCancelled;
        if (refreshWasRun)
            onClick(etCityName);
        if (savedInstanceState.getBoolean(SAVED_DIALOG_VISIBILITY)) {
            registerDialog.getEtAppId().setText(savedInstanceState.getString(SAVED_DIALOG_APPID));
            registerDialog.show();
        }
    }
}

From source file:com.amaze.carbonfilemanager.fragments.ZipViewer.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    Sp = PreferenceManager.getDefaultSharedPreferences(getActivity());
    s = getArguments().getString(KEY_PATH);
    Uri uri = Uri.parse(s);// www . j  a v  a2  s  . c  om
    f = new File(uri.getPath());
    mToolbarContainer = getActivity().findViewById(R.id.lin);
    mToolbarContainer.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View view, MotionEvent motionEvent) {
            if (stopAnims) {
                if ((!rarAdapter.stoppedAnimation)) {
                    stopAnim();
                }
                rarAdapter.stoppedAnimation = true;

            }
            stopAnims = false;
            return false;
        }
    });
    hidemode = Sp.getInt("hidemode", 0);
    listView.setVisibility(View.VISIBLE);
    mLayoutManager = new LinearLayoutManager(getActivity());
    listView.setLayoutManager(mLayoutManager);
    res = getResources();
    mainActivity.supportInvalidateOptionsMenu();
    if (utilsProvider.getAppTheme().equals(AppTheme.DARK))
        rootView.setBackgroundColor(Utils.getColor(getContext(), R.color.holo_dark_background));
    else
        listView.setBackgroundColor(Utils.getColor(getContext(), android.R.color.background_light));

    gobackitem = Sp.getBoolean("goBack_checkbox", false);
    coloriseIcons = Sp.getBoolean("coloriseIcons", true);
    Calendar calendar = Calendar.getInstance();
    showSize = Sp.getBoolean("showFileSize", false);
    showLastModified = Sp.getBoolean("showLastModified", true);
    showDividers = Sp.getBoolean("showDividers", true);
    year = ("" + calendar.get(Calendar.YEAR)).substring(2, 4);
    skin = mainActivity.getColorPreference().getColorAsString(ColorUsage.PRIMARY);
    accentColor = mainActivity.getColorPreference().getColorAsString(ColorUsage.ACCENT);
    iconskin = mainActivity.getColorPreference().getColorAsString(ColorUsage.ICON_SKIN);

    //mainActivity.findViewById(R.id.buttonbarframe).setBackgroundColor(Color.parseColor(skin));

    if (savedInstanceState == null && f != null) {

        files = new ArrayList<>();
        // adding a cache file to delete where any user interaction elements will be cached
        String fileName = f.getName().substring(0, f.getName().lastIndexOf("."));
        files.add(new BaseFile(getActivity().getExternalCacheDir().getPath() + "/" + fileName));
        if (f.getPath().endsWith(".rar")) {
            openmode = 1;
            SetupRar(null);
        } else {
            openmode = 0;
            SetupZip(null);
        }
    } else {

        f = new File(savedInstanceState.getString(KEY_FILE));
        s = savedInstanceState.getString(KEY_URI);
        uri = Uri.parse(s);
        f = new File(uri.getPath());
        files = savedInstanceState.getParcelableArrayList(KEY_CACHE_FILES);
        isOpen = savedInstanceState.getBoolean(KEY_OPEN);
        if (f.getPath().endsWith(".rar")) {
            openmode = 1;
            SetupRar(savedInstanceState);
        } else {
            openmode = 0;
            SetupZip(savedInstanceState);
        }

    }
    String fileName = null;
    try {
        if (uri.getScheme().equals(KEY_FILE)) {
            fileName = uri.getLastPathSegment();
        } else {
            Cursor cursor = null;
            try {
                cursor = getActivity().getContentResolver().query(uri,
                        new String[] { MediaStore.Images.ImageColumns.DISPLAY_NAME }, null, null, null);

                if (cursor != null && cursor.moveToFirst()) {
                    fileName = cursor
                            .getString(cursor.getColumnIndex(MediaStore.Images.ImageColumns.DISPLAY_NAME));
                }
            } finally {

                if (cursor != null) {
                    cursor.close();
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    if (fileName == null || fileName.trim().length() == 0)
        fileName = f.getName();
    try {
        mainActivity.setActionBarTitle(fileName);
    } catch (Exception e) {
        mainActivity.setActionBarTitle(getResources().getString(R.string.zip_viewer));
    }
    mainActivity.supportInvalidateOptionsMenu();
    mToolbarHeight = getToolbarHeight(getActivity());
    paddingTop = (mToolbarHeight) + dpToPx(72);
    mToolbarContainer.getViewTreeObserver()
            .addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
                @Override
                public void onGlobalLayout() {
                    paddingTop = mToolbarContainer.getHeight();
                    mToolbarHeight = mainActivity.toolbar.getHeight();

                    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN) {
                        mToolbarContainer.getViewTreeObserver().removeOnGlobalLayoutListener(this);
                    } else {
                        mToolbarContainer.getViewTreeObserver().removeGlobalOnLayoutListener(this);
                    }
                }

            });

}

From source file:de.uni_koblenz_landau.apow.LoginActivity.java

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

    // Re-attach Tasks.
    TaskActivityReference.getInstance().attach(LoginTask.TASK_ID, this);
    TaskActivityReference.getInstance().attach(SetupTask.TASK_ID, this);
    TaskActivityReference.getInstance().attach(NFCTagReaderTask.TASK_ID, this);
    TaskActivityReference.getInstance().attach(LocationWebTask.TASK_ID, this);

    // Create UI references.
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        Window window = this.getWindow();
        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        window.setStatusBarColor(this.getResources().getColor(R.color.color_primary_dark));
    }//from   w  w w .jav a  2  s  .com
    setContentView(R.layout.login_activity);
    mToolbar = (Toolbar) findViewById(R.id.toolbar);
    if (mToolbar != null) {
        setSupportActionBar(mToolbar);
    }

    mSetupLocationView = (Spinner) findViewById(R.id.login_setup_locations);
    mStatusView = findViewById(R.id.login_status);
    mStatusMessageView = (TextView) findViewById(R.id.login_status_message);
    mLoginFormView = findViewById(R.id.login_login);
    mLoginPasswordView = (EditText) findViewById(R.id.login_login_password);
    mLoginPasswordView.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView textView, int id, KeyEvent keyEvent) {
            if (id == R.id.login || id == EditorInfo.IME_NULL) {
                login(textView);
                return true;
            }
            return false;
        }
    });
    mLoginNFCText = (TextView) findViewById(R.id.login_login_nfc);
    mSetupFormView = findViewById(R.id.login_setup);
    mSetupNFCText = (TextView) findViewById(R.id.login_setup_nfc);

    mSetupDatabasePasswordView = (EditText) findViewById(R.id.login_setup_database_password);
    mSetupDatabaseConfirmView = (EditText) findViewById(R.id.login_setup_database_password_confirm);
    mSetupServerUsernameView = (EditText) findViewById(R.id.login_login_server_user);
    mSetupServerPasswordView = (EditText) findViewById(R.id.login_login_server_password);

    //mFirstRun = true;
    mFirstRun = getSharedPreferences(Constants.PREFERENCE, MODE_PRIVATE).getBoolean(ARG_FIRST_RUN, true);
    mNfcAdapter = NfcAdapter.getDefaultAdapter(this);

    // Restore UI from saved instance or load data.
    if (savedInstanceState != null) {
        mNFCTag = savedInstanceState.getString(ARG_NFC);
        mNFCTextDrawable = savedInstanceState.getInt(ARG_NFC_STATE);
        mAutoSignOffDismissed = savedInstanceState.getBoolean(ARG_AUTO_SIGN_OFF_DISMISSED);
        mProgress = savedInstanceState.getBoolean(ARG_PROGRESS);
        if (mFirstRun) {
            mLocations = savedInstanceState.getParcelableArrayList(ARG_LOCATIONS);
            if (mLocations != null) {
                ArrayAdapter<ListViewItem> adapter = new ArrayAdapter<>(this,
                        android.R.layout.simple_spinner_item, mLocations);
                adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
                mSetupLocationView.setAdapter(adapter);
                mSetupLocationView.setSelection(savedInstanceState.getInt(ARG_LOCATION_SELECTION));
            }
        }
    } else {
        mProgress = false;
        mAutoSignOffDismissed = false;
        mNFCTag = "";
        mNFCTextDrawable = R.drawable.empty;
        if (mFirstRun) {
            loadLocations();
        }
    }
    mLoginNFCText.setCompoundDrawablesWithIntrinsicBounds(0, 0, mNFCTextDrawable, 0);
    mSetupNFCText.setCompoundDrawablesWithIntrinsicBounds(0, 0, mNFCTextDrawable, 0);

    if (mFirstRun) {
        mSetupFormView.setVisibility(View.VISIBLE);
        mLoginFormView.setVisibility(View.GONE);
        this.setTitle(R.string.login_setup_title);
    } else {
        mSetupFormView.setVisibility(View.GONE);
        mLoginFormView.setVisibility(View.VISIBLE);
        this.setTitle(R.string.login_login_title);
    }

    if (getIntent().getBooleanExtra(ARG_AUTO_LOGOUT, false) && !mAutoSignOffDismissed) {
        SignedOffDialog dialog = new SignedOffDialog();
        dialog.show(getSupportFragmentManager(), SIGNED_OFF_DIALOG_ID);
        mAutoSignOffDismissed = true;
    }
    showProgress(mProgress);
    setNFCState();
}