Example usage for android.content Intent getLongExtra

List of usage examples for android.content Intent getLongExtra

Introduction

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

Prototype

public long getLongExtra(String name, long defaultValue) 

Source Link

Document

Retrieve extended data from the intent.

Usage

From source file:org.mariotaku.twidere.activity.CustomTabEditorActivity.java

@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mPreferences = getSharedPreferences(SHARED_PREFERENCES_NAME, MODE_PRIVATE);
    final Intent intent = getIntent();
    final String type = getTabType();
    final CustomTabConfiguration conf = getTabConfiguration(type);
    if (type == null || conf == null) {
        finish();/*from ww w  . jav a  2 s .  co m*/
        return;
    }
    mTabId = intent.getLongExtra(EXTRA_ID, -1);
    setTitle(isEditMode() ? R.string.edit_tab : R.string.add_tab);
    setContentView(R.layout.activity_custom_tab_editor);
    mEditTabName.setFloatingLabelText(getTabTypeName(this, type));
    mTabIconsAdapter = new CustomTabIconsAdapter(this);
    mTabIconsAdapter.setData(getIconMap());
    mAccountsAdapter = new AccountsSpinnerAdapter(this);
    mAccountSpinner.setAdapter(mAccountsAdapter);
    mTabIconSpinner.setAdapter(mTabIconsAdapter);
    final String iconKey;
    if (savedInstanceState != null) {
        mExtrasBundle.putAll(savedInstanceState.getBundle(EXTRA_EXTRAS));
    }
    if (!isEditMode()) {
        mTabConfiguration = conf;
        final boolean hasSecondaryField = conf
                .getSecondaryFieldType() != CustomTabConfiguration.FIELD_TYPE_NONE;
        final boolean accountIdNone = conf.getAccountRequirement() == CustomTabConfiguration.ACCOUNT_NONE;
        mAccountContainer.setVisibility(accountIdNone ? View.GONE : View.VISIBLE);
        mSecondaryFieldContainer.setVisibility(hasSecondaryField ? View.VISIBLE : View.GONE);
        final boolean accountIdRequired = conf
                .getAccountRequirement() == CustomTabConfiguration.ACCOUNT_REQUIRED;
        if (!accountIdRequired) {
            mAccountsAdapter.add(ParcelableAccount.dummyCredentials());
        }
        final boolean officialKeyOnly = intent.getBooleanExtra(EXTRA_OFFICIAL_KEY_ONLY, false);
        mAccountsAdapter.addAll(DataStoreUtils.getCredentialsList(this, false, officialKeyOnly));
        mAccountsAdapter.setDummyItemText(R.string.activated_accounts);
        switch (conf.getSecondaryFieldType()) {
        case CustomTabConfiguration.FIELD_TYPE_USER: {
            mSecondaryFieldLabel.setText(R.string.user);
            setExtraFieldSelectText(mSecondaryFieldContainer, R.string.select_user);
            break;
        }
        case CustomTabConfiguration.FIELD_TYPE_USER_LIST: {
            mSecondaryFieldLabel.setText(R.string.user_list);
            setExtraFieldSelectText(mSecondaryFieldContainer, R.string.select_user_list);
            break;
        }
        case CustomTabConfiguration.FIELD_TYPE_TEXT: {
            mSecondaryFieldLabel.setText(R.string.content);
            setExtraFieldSelectText(mSecondaryFieldContainer, R.string.input_text);
            break;
        }
        }
        if (conf.getSecondaryFieldTitle() != 0) {
            mSecondaryFieldLabel.setText(conf.getSecondaryFieldTitle());
        }
        iconKey = findTabIconKey(conf.getDefaultIcon());
        mEditTabName.setText(mTabConfiguration.getDefaultTitle());
    } else {
        if (mTabId < 0) {
            finish();
            return;
        }
        mAccountContainer.setVisibility(View.GONE);
        mSecondaryFieldContainer.setVisibility(View.GONE);
        iconKey = intent.getStringExtra(EXTRA_ICON);
        mEditTabName.setText(intent.getStringExtra(EXTRA_NAME));
        if (savedInstanceState == null && intent.hasExtra(EXTRA_EXTRAS)) {
            TabExtras extras = CustomTabUtils.parseTabExtras(type, intent.getStringExtra(EXTRA_EXTRAS));
            if (extras != null) {
                extras.copyToBundle(mExtrasBundle);
            }
        }
    }
    final int selection = mTabIconsAdapter.getIconPosition(iconKey);
    mTabIconSpinner.setSelection(selection > 0 ? selection : 0);
    final LayoutInflater inflater = getLayoutInflater();
    final ExtraConfiguration[] extraConfigurations = conf.getExtraConfigurations();
    if (extraConfigurations == null || extraConfigurations.length == 0) {
        mExtraConfigurationsContainer.setVisibility(View.GONE);
    } else {
        mExtraConfigurationsContainer.setVisibility(View.VISIBLE);
        for (final ExtraConfiguration config : extraConfigurations) {
            final boolean hasCheckBox = config.getType() == ExtraConfiguration.Type.BOOLEAN;
            final View view = inflater.inflate(R.layout.list_item_extra_config, mExtraConfigurationsContent,
                    false);
            final TextView title = (TextView) view.findViewById(android.R.id.title);
            final CheckBox checkBox = (CheckBox) view.findViewById(android.R.id.checkbox);
            title.setText(config.getTitleRes());
            checkBox.setVisibility(hasCheckBox ? View.VISIBLE : View.GONE);
            if (hasCheckBox) {
                checkBox.setChecked(mExtrasBundle.getBoolean(config.getKey(), config.defaultBoolean()));
            }
            view.setTag(config);
            view.setOnClickListener(mOnExtraConfigurationClickListener);
            mExtraConfigurationsContent.addView(view);
        }
    }
}

From source file:ch.teamuit.android.soundplusplus.LibraryActivity.java

/**
 * If the given intent has album data, set a limiter built from that
 * data.//  ww w  .ja v  a  2s  .co m
 */
private void loadAlbumIntent(Intent intent) {
    long albumId = intent.getLongExtra("albumId", -1);
    if (albumId != -1) {
        String[] fields = { intent.getStringExtra("artist"), intent.getStringExtra("album") };
        String data = String.format("album_id=%d", albumId);
        Limiter limiter = new Limiter(MediaUtils.TYPE_ALBUM, fields, data);
        int tab = mPagerAdapter.setLimiter(limiter);
        if (tab == -1 || tab == mViewPager.getCurrentItem())
            updateLimiterViews();
        else
            mViewPager.setCurrentItem(tab);

    }
}

From source file:fr.paug.droidcon.service.SessionAlarmService.java

@Override
protected void onHandleIntent(Intent intent) {
    mGoogleApiClient.blockingConnect(2000, TimeUnit.MILLISECONDS);
    final String action = intent.getAction();

    LOGD(TAG, "SessionAlarmService handling " + action);

    if (ACTION_SCHEDULE_ALL_STARRED_BLOCKS.equals(action)) {
        LOGD(TAG, "Scheduling all starred blocks.");
        scheduleAllStarredBlocks();/*from ww  w . ja  v  a  2s .  c  om*/
        return;
    }

    final long sessionEnd = intent.getLongExtra(SessionAlarmService.EXTRA_SESSION_END, UNDEFINED_VALUE);
    if (sessionEnd == UNDEFINED_VALUE) {
        LOGD(TAG, "IGNORING ACTION -- missing sessionEnd parameter");
        return;
    }

    final long sessionAlarmOffset = intent.getLongExtra(SessionAlarmService.EXTRA_SESSION_ALARM_OFFSET,
            UNDEFINED_ALARM_OFFSET);
    LOGD(TAG, "Session alarm offset is: " + sessionAlarmOffset);

    final long sessionStart = intent.getLongExtra(SessionAlarmService.EXTRA_SESSION_START, UNDEFINED_VALUE);
    if (sessionStart == UNDEFINED_VALUE) {
        LOGD(TAG, "IGNORING ACTION -- no session start parameter.");
        return;
    }

    if (ACTION_NOTIFY_SESSION.equals(action)) {
        LOGD(TAG, "Notifying about sessions starting at " + sessionStart + " = "
                + (new Date(sessionStart)).toString());
        LOGD(TAG, "-> Alarm offset: " + sessionAlarmOffset);
        notifySession(sessionStart, sessionAlarmOffset);
    } else if (ACTION_SCHEDULE_STARRED_BLOCK.equals(action)) {
        LOGD(TAG, "Scheduling session alarm.");
        LOGD(TAG, "-> Session start: " + sessionStart + " = " + (new Date(sessionStart)).toString());
        LOGD(TAG, "-> Session end: " + sessionEnd + " = " + (new Date(sessionEnd)).toString());
        LOGD(TAG, "-> Alarm offset: " + sessionAlarmOffset);
        scheduleAlarm(sessionStart, sessionEnd, sessionAlarmOffset);
    }
}

From source file:mobisocial.musubi.ui.ViewProfileActivity.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_tabbed);

    Intent intent = getIntent();

    Long id = null;//from w  w w  .  j ava  2 s.  c o  m
    // intent from address book
    Intent is = getIntent();
    Uri data = getIntent().getData();
    String type = getIntent().getType();
    if (data != null) {
        if (type != null && type.equals(MusubiContentProvider.getType(Provided.IDENTITIES_ID))) {
            id = ContentUris.parseId(data);
        } else if (data.getAuthority().equals(ContactsContract.AUTHORITY)) {
            // intent sent from address book have null type
            long rawId = ContentUris.parseId(data);
            id = getMusubiId(rawId);
        }
    }
    if (id == null) {
        id = intent.getLongExtra(PROFILE_ID, -1);
    }

    setTitle("Relationships");
    mLabels.add("Profile");
    mFragments.add(ViewProfileFragment.newInstance(id));

    SQLiteOpenHelper helper = App.getDatabaseSource(this);
    IdentitiesManager im = new IdentitiesManager(helper);
    MIdentity identity = im.getIdentityForId(id);
    if (identity == null) {
        UsageMetrics.getUsageMetrics(this)
                .report(new Throwable("Invalid identity " + id + " passed tp ViewProfileActivity"));
        finish();
        return;
    }

    FeedManager fm = new FeedManager(helper);
    mFeedIds = fm.getFeedsForIdentityId(id);

    setTitle(identity.name_);

    if (!identity.owned_) {
        mLabels.add("Conversations");
        Bundle args = new Bundle();
        args.putLong(ConversationsFragment.ARG_IDENTITY_ID, identity.id_);
        ConversationsFragment f = new ConversationsFragment();
        f.setArguments(args);
        mFragments.add(f);
    } else {
        setTitle("Your profile");
    }

    PagerAdapter adapter = new ViewFragmentAdapter(getSupportFragmentManager(), mFragments, mLabels);
    mViewPager = (ViewPager) findViewById(R.id.feed_pager);
    mViewPager.setAdapter(adapter);

    //Bind the tab indicator to the adapter
    TabPageIndicator tabIndicator = (TabPageIndicator) findViewById(R.id.feed_titles);
    tabIndicator.setViewPager(mViewPager);
}

From source file:de.vanita5.twittnuker.activity.support.CustomTabEditorActivity.java

@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mPreferences = getSharedPreferences(SHARED_PREFERENCES_NAME, MODE_PRIVATE);
    mImageLoader = TwittnukerApplication.getInstance(this).getImageLoaderWrapper();
    final Intent intent = getIntent();
    final String type = mTabType = intent.getStringExtra(EXTRA_TYPE);
    final CustomTabConfiguration conf = getTabConfiguration(type);
    if (type == null || conf == null) {
        finish();//from w ww  .ja v a 2 s. c o  m
        return;
    }
    mTabId = intent.getLongExtra(EXTRA_ID, -1);
    setTitle(isEditMode() ? R.string.edit_tab : R.string.add_tab);
    setContentView(R.layout.activity_custom_tab_editor);
    mTabTypeName.setText(getTabTypeName(this, type));
    mTabIconsAdapter = new CustomTabIconsAdapter(this);
    mTabIconsAdapter.setData(getIconMap());
    mAccountsAdapter = new AccountsSpinnerAdapter(this);
    mAccountSpinner.setAdapter(mAccountsAdapter);
    mTabIconSpinner.setAdapter(mTabIconsAdapter);
    final String iconKey;
    if (savedInstanceState != null) {
        mExtrasBundle.putAll(savedInstanceState.getBundle(EXTRA_EXTRAS));
    }
    if (!isEditMode()) {
        mTabConfiguration = conf;
        final boolean has_secondary_field = conf
                .getSecondaryFieldType() != CustomTabConfiguration.FIELD_TYPE_NONE;
        final boolean account_id_none = conf.getAccountRequirement() == CustomTabConfiguration.ACCOUNT_NONE;
        mAccountContainer.setVisibility(account_id_none ? View.GONE : View.VISIBLE);
        mSecondaryFieldContainer.setVisibility(has_secondary_field ? View.VISIBLE : View.GONE);
        final boolean accountIdRequired = conf
                .getAccountRequirement() == CustomTabConfiguration.ACCOUNT_REQUIRED;
        if (!accountIdRequired) {
            mAccountsAdapter.add(Account.dummyInstance());
        }
        final boolean officialKeyOnly = intent.getBooleanExtra(EXTRA_OFFICIAL_KEY_ONLY, false);
        mAccountsAdapter.addAll(Account.getAccountsList(this, false, officialKeyOnly));
        switch (conf.getSecondaryFieldType()) {
        case CustomTabConfiguration.FIELD_TYPE_USER: {
            mSecondaryFieldLabel.setText(R.string.user);
            setExtraFieldSelectText(mSecondaryFieldContainer, R.string.select_user);
            break;
        }
        case CustomTabConfiguration.FIELD_TYPE_USER_LIST: {
            mSecondaryFieldLabel.setText(R.string.user_list);
            setExtraFieldSelectText(mSecondaryFieldContainer, R.string.select_user_list);
            break;
        }
        case CustomTabConfiguration.FIELD_TYPE_TEXT: {
            mSecondaryFieldLabel.setText(R.string.content);
            setExtraFieldSelectText(mSecondaryFieldContainer, R.string.input_text);
            break;
        }
        }
        if (conf.getSecondaryFieldTitle() != 0) {
            mSecondaryFieldLabel.setText(conf.getSecondaryFieldTitle());
        }
        iconKey = findTabIconKey(conf.getDefaultIcon());
        mEditTabName.setText(mTabConfiguration.getDefaultTitle());
    } else {
        if (mTabId < 0) {
            finish();
            return;
        }
        mAccountContainer.setVisibility(View.GONE);
        mSecondaryFieldContainer.setVisibility(View.GONE);
        iconKey = intent.getStringExtra(EXTRA_ICON);
        mEditTabName.setText(intent.getStringExtra(EXTRA_NAME));
        if (savedInstanceState == null && intent.hasExtra(EXTRA_EXTRAS)) {
            mExtrasBundle.putAll(ParseUtils.jsonToBundle(intent.getStringExtra(EXTRA_EXTRAS)));
        }
    }
    final int selection = mTabIconsAdapter.getIconPosition(iconKey);
    mTabIconSpinner.setSelection(selection > 0 ? selection : 0);
    final LayoutInflater inflater = getLayoutInflater();
    final ExtraConfiguration[] extraConfigurations = conf.getExtraConfigurations();
    if (extraConfigurations == null || extraConfigurations.length == 0) {
        mExtraConfigurationsContainer.setVisibility(View.GONE);
    } else {
        mExtraConfigurationsContainer.setVisibility(View.VISIBLE);
        for (final ExtraConfiguration config : extraConfigurations) {
            final boolean hasCheckBox = config.getType() == ExtraConfiguration.Type.BOOLEAN;
            final View view = inflater.inflate(R.layout.list_item_extra_config, mExtraConfigurationsContent,
                    false);
            final TextView title = (TextView) view.findViewById(android.R.id.title);
            final CheckBox checkBox = (CheckBox) view.findViewById(android.R.id.checkbox);
            title.setText(config.getTitleRes());
            checkBox.setVisibility(hasCheckBox ? View.VISIBLE : View.GONE);
            if (hasCheckBox) {
                checkBox.setChecked(mExtrasBundle.getBoolean(config.getKey(), config.defaultBoolean()));
            }
            view.setTag(config);
            view.setOnClickListener(mOnExtraConfigurationClickListener);
            mExtraConfigurationsContent.addView(view);
        }
    }
}

From source file:ch.teamuit.android.soundplusplus.LibraryActivity.java

/**
 * Creates a context menu for an adapter row.
 *
 * @param menu The menu to create./*from ww w . j  ava  2 s  .  c om*/
 * @param rowData Data for the adapter row.
 */
public void onCreateContextMenu(ContextMenu menu, Intent rowData) {
    if (rowData.getLongExtra(LibraryAdapter.DATA_ID, LibraryAdapter.INVALID_ID) == LibraryAdapter.HEADER_ID) {
        menu.setHeaderTitle(getString(R.string.all_songs));
        menu.add(0, CTX_MENU_PLAY_ALL, 0, R.string.play_all).setIntent(rowData);
        menu.add(0, CTX_MENU_ENQUEUE_ALL, 0, R.string.enqueue_all).setIntent(rowData);
        menu.addSubMenu(0, CTX_MENU_ADD_TO_PLAYLIST, 0, R.string.add_to_playlist).getItem().setIntent(rowData);
    } else {
        int type = rowData.getIntExtra(LibraryAdapter.DATA_TYPE, MediaUtils.TYPE_INVALID);

        menu.setHeaderTitle(rowData.getStringExtra(LibraryAdapter.DATA_TITLE));

        if (FileUtils.canDispatchIntent(rowData))
            menu.add(0, CTX_MENU_OPEN_EXTERNAL, 0, R.string.open).setIntent(rowData);
        menu.add(0, CTX_MENU_PLAY, 0, R.string.play).setIntent(rowData);
        if (type <= MediaUtils.TYPE_SONG) {
            menu.add(0, CTX_MENU_PLAY_ALL, 0, R.string.play_all).setIntent(rowData);
        }
        menu.add(0, CTX_MENU_ENQUEUE_AS_NEXT, 0, R.string.enqueue_as_next).setIntent(rowData);
        menu.add(0, CTX_MENU_ENQUEUE, 0, R.string.enqueue).setIntent(rowData);
        if (type == MediaUtils.TYPE_PLAYLIST) {
            menu.add(0, CTX_MENU_RENAME_PLAYLIST, 0, R.string.rename).setIntent(rowData);
        } else if (rowData.getBooleanExtra(LibraryAdapter.DATA_EXPANDABLE, false)) {
            menu.add(0, CTX_MENU_EXPAND, 0, R.string.expand).setIntent(rowData);
        }
        if (type == MediaUtils.TYPE_ALBUM || type == MediaUtils.TYPE_SONG)
            menu.add(0, CTX_MENU_MORE_FROM_ARTIST, 0, R.string.more_from_artist).setIntent(rowData);
        if (type == MediaUtils.TYPE_SONG)
            menu.add(0, CTX_MENU_MORE_FROM_ALBUM, 0, R.string.more_from_album).setIntent(rowData);
        menu.addSubMenu(0, CTX_MENU_ADD_TO_PLAYLIST, 0, R.string.add_to_playlist).getItem().setIntent(rowData);
        menu.add(0, CTX_MENU_DELETE, 0, R.string.delete).setIntent(rowData);
    }
}

From source file:org.mariotaku.twidere.activity.support.CustomTabEditorActivity.java

@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mPreferences = getSharedPreferences(SHARED_PREFERENCES_NAME, MODE_PRIVATE);
    mImageLoader = TwidereApplication.getInstance(this).getMediaLoaderWrapper();
    final Intent intent = getIntent();
    final String type = mTabType = intent.getStringExtra(EXTRA_TYPE);
    final CustomTabConfiguration conf = getTabConfiguration(type);
    if (type == null || conf == null) {
        finish();/* www . j av a2 s . com*/
        return;
    }
    mTabId = intent.getLongExtra(EXTRA_ID, -1);
    setTitle(isEditMode() ? R.string.edit_tab : R.string.add_tab);
    setContentView(R.layout.activity_custom_tab_editor);
    mEditTabName.setFloatingLabelText(getTabTypeName(this, type));
    mTabIconsAdapter = new CustomTabIconsAdapter(this);
    mTabIconsAdapter.setData(getIconMap());
    mAccountsAdapter = new AccountsSpinnerAdapter(this);
    mAccountSpinner.setAdapter(mAccountsAdapter);
    mTabIconSpinner.setAdapter(mTabIconsAdapter);
    final String iconKey;
    if (savedInstanceState != null) {
        mExtrasBundle.putAll(savedInstanceState.getBundle(EXTRA_EXTRAS));
    }
    if (!isEditMode()) {
        mTabConfiguration = conf;
        final boolean hasSecondaryField = conf
                .getSecondaryFieldType() != CustomTabConfiguration.FIELD_TYPE_NONE;
        final boolean accountIdNone = conf.getAccountRequirement() == CustomTabConfiguration.ACCOUNT_NONE;
        mAccountContainer.setVisibility(accountIdNone ? View.GONE : View.VISIBLE);
        mSecondaryFieldContainer.setVisibility(hasSecondaryField ? View.VISIBLE : View.GONE);
        final boolean accountIdRequired = conf
                .getAccountRequirement() == CustomTabConfiguration.ACCOUNT_REQUIRED;
        if (!accountIdRequired) {
            mAccountsAdapter.add(ParcelableAccount.dummyCredentials());
        }
        final boolean officialKeyOnly = intent.getBooleanExtra(EXTRA_OFFICIAL_KEY_ONLY, false);
        final boolean forcePrivateAPIs = intent.getBooleanExtra(KEY_FORCE_USING_PRIVATE_APIS, false);
        mAccountsAdapter.addAll(
                ParcelableAccount.getCredentialsList(this, false, !forcePrivateAPIs && officialKeyOnly));
        mAccountsAdapter.setDummyItemText(R.string.activated_accounts);
        switch (conf.getSecondaryFieldType()) {
        case CustomTabConfiguration.FIELD_TYPE_USER: {
            mSecondaryFieldLabel.setText(R.string.user);
            setExtraFieldSelectText(mSecondaryFieldContainer, R.string.select_user);
            break;
        }
        case CustomTabConfiguration.FIELD_TYPE_USER_LIST: {
            mSecondaryFieldLabel.setText(R.string.user_list);
            setExtraFieldSelectText(mSecondaryFieldContainer, R.string.select_user_list);
            break;
        }
        case CustomTabConfiguration.FIELD_TYPE_TEXT: {
            mSecondaryFieldLabel.setText(R.string.content);
            setExtraFieldSelectText(mSecondaryFieldContainer, R.string.input_text);
            break;
        }
        }
        if (conf.getSecondaryFieldTitle() != 0) {
            mSecondaryFieldLabel.setText(conf.getSecondaryFieldTitle());
        }
        iconKey = findTabIconKey(conf.getDefaultIcon());
        mEditTabName.setText(mTabConfiguration.getDefaultTitle());
    } else {
        if (mTabId < 0) {
            finish();
            return;
        }
        mAccountContainer.setVisibility(View.GONE);
        mSecondaryFieldContainer.setVisibility(View.GONE);
        iconKey = intent.getStringExtra(EXTRA_ICON);
        mEditTabName.setText(intent.getStringExtra(EXTRA_NAME));
        if (savedInstanceState == null && intent.hasExtra(EXTRA_EXTRAS)) {
            mExtrasBundle.putAll(ParseUtils.jsonToBundle(intent.getStringExtra(EXTRA_EXTRAS)));
        }
    }
    final int selection = mTabIconsAdapter.getIconPosition(iconKey);
    mTabIconSpinner.setSelection(selection > 0 ? selection : 0);
    final LayoutInflater inflater = getLayoutInflater();
    final ExtraConfiguration[] extraConfigurations = conf.getExtraConfigurations();
    if (extraConfigurations == null || extraConfigurations.length == 0) {
        mExtraConfigurationsContainer.setVisibility(View.GONE);
    } else {
        mExtraConfigurationsContainer.setVisibility(View.VISIBLE);
        for (final ExtraConfiguration config : extraConfigurations) {
            final boolean hasCheckBox = config.getType() == ExtraConfiguration.Type.BOOLEAN;
            final View view = inflater.inflate(R.layout.list_item_extra_config, mExtraConfigurationsContent,
                    false);
            final TextView title = (TextView) view.findViewById(android.R.id.title);
            final CheckBox checkBox = (CheckBox) view.findViewById(android.R.id.checkbox);
            title.setText(config.getTitleRes());
            checkBox.setVisibility(hasCheckBox ? View.VISIBLE : View.GONE);
            if (hasCheckBox) {
                checkBox.setChecked(mExtrasBundle.getBoolean(config.getKey(), config.defaultBoolean()));
            }
            view.setTag(config);
            view.setOnClickListener(mOnExtraConfigurationClickListener);
            mExtraConfigurationsContent.addView(view);
        }
    }
}

From source file:org.getlantern.firetweet.activity.support.CustomTabEditorActivity.java

@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mPreferences = getSharedPreferences(SHARED_PREFERENCES_NAME, MODE_PRIVATE);
    mImageLoader = FiretweetApplication.getInstance(this).getMediaLoaderWrapper();
    final Intent intent = getIntent();
    final String type = mTabType = intent.getStringExtra(EXTRA_TYPE);
    final CustomTabConfiguration conf = getTabConfiguration(type);
    if (type == null || conf == null) {
        finish();//from ww w  . jav  a 2s.c  om
        return;
    }
    mTabId = intent.getLongExtra(EXTRA_ID, -1);
    setTitle(isEditMode() ? R.string.edit_tab : R.string.add_tab);
    setContentView(R.layout.activity_custom_tab_editor);
    mTabTypeName.setText(getTabTypeName(this, type));
    mTabIconsAdapter = new CustomTabIconsAdapter(this);
    mTabIconsAdapter.setData(getIconMap());
    mAccountsAdapter = new AccountsSpinnerAdapter(this);
    mAccountSpinner.setAdapter(mAccountsAdapter);
    mTabIconSpinner.setAdapter(mTabIconsAdapter);
    final String iconKey;
    if (savedInstanceState != null) {
        mExtrasBundle.putAll(savedInstanceState.getBundle(EXTRA_EXTRAS));
    }
    if (!isEditMode()) {
        mTabConfiguration = conf;
        final boolean hasSecondaryField = conf
                .getSecondaryFieldType() != CustomTabConfiguration.FIELD_TYPE_NONE;
        final boolean accountIdNone = conf.getAccountRequirement() == CustomTabConfiguration.ACCOUNT_NONE;
        mAccountContainer.setVisibility(accountIdNone ? View.GONE : View.VISIBLE);
        mSecondaryFieldContainer.setVisibility(hasSecondaryField ? View.VISIBLE : View.GONE);
        final boolean accountIdRequired = conf
                .getAccountRequirement() == CustomTabConfiguration.ACCOUNT_REQUIRED;
        if (!accountIdRequired) {
            mAccountsAdapter.add(ParcelableAccount.dummyInstance());
        }
        final boolean officialKeyOnly = intent.getBooleanExtra(EXTRA_OFFICIAL_KEY_ONLY, false);
        final boolean forcePrivateAPIs = intent.getBooleanExtra(KEY_FORCE_USING_PRIVATE_APIS, false);
        mAccountsAdapter
                .addAll(ParcelableAccount.getAccountsList(this, false, !forcePrivateAPIs && officialKeyOnly));
        mAccountsAdapter.setDummyItemText(R.string.activated_accounts);
        switch (conf.getSecondaryFieldType()) {
        case CustomTabConfiguration.FIELD_TYPE_USER: {
            mSecondaryFieldLabel.setText(R.string.user);
            setExtraFieldSelectText(mSecondaryFieldContainer, R.string.select_user);
            break;
        }
        case CustomTabConfiguration.FIELD_TYPE_USER_LIST: {
            mSecondaryFieldLabel.setText(R.string.user_list);
            setExtraFieldSelectText(mSecondaryFieldContainer, R.string.select_user_list);
            break;
        }
        case CustomTabConfiguration.FIELD_TYPE_TEXT: {
            mSecondaryFieldLabel.setText(R.string.content);
            setExtraFieldSelectText(mSecondaryFieldContainer, R.string.input_text);
            break;
        }
        }
        if (conf.getSecondaryFieldTitle() != 0) {
            mSecondaryFieldLabel.setText(conf.getSecondaryFieldTitle());
        }
        iconKey = findTabIconKey(conf.getDefaultIcon());
        mEditTabName.setText(mTabConfiguration.getDefaultTitle());
    } else {
        if (mTabId < 0) {
            finish();
            return;
        }
        mAccountContainer.setVisibility(View.GONE);
        mSecondaryFieldContainer.setVisibility(View.GONE);
        iconKey = intent.getStringExtra(EXTRA_ICON);
        mEditTabName.setText(intent.getStringExtra(EXTRA_NAME));
        if (savedInstanceState == null && intent.hasExtra(EXTRA_EXTRAS)) {
            mExtrasBundle.putAll(ParseUtils.jsonToBundle(intent.getStringExtra(EXTRA_EXTRAS)));
        }
    }
    final int selection = mTabIconsAdapter.getIconPosition(iconKey);
    mTabIconSpinner.setSelection(selection > 0 ? selection : 0);
    final LayoutInflater inflater = getLayoutInflater();
    final ExtraConfiguration[] extraConfigurations = conf.getExtraConfigurations();
    if (extraConfigurations == null || extraConfigurations.length == 0) {
        mExtraConfigurationsContainer.setVisibility(View.GONE);
    } else {
        mExtraConfigurationsContainer.setVisibility(View.VISIBLE);
        for (final ExtraConfiguration config : extraConfigurations) {
            final boolean hasCheckBox = config.getType() == ExtraConfiguration.Type.BOOLEAN;
            final View view = inflater.inflate(R.layout.list_item_extra_config, mExtraConfigurationsContent,
                    false);
            final TextView title = (TextView) view.findViewById(android.R.id.title);
            final CheckBox checkBox = (CheckBox) view.findViewById(android.R.id.checkbox);
            title.setText(config.getTitleRes());
            checkBox.setVisibility(hasCheckBox ? View.VISIBLE : View.GONE);
            if (hasCheckBox) {
                checkBox.setChecked(mExtrasBundle.getBoolean(config.getKey(), config.defaultBoolean()));
            }
            view.setTag(config);
            view.setOnClickListener(mOnExtraConfigurationClickListener);
            mExtraConfigurationsContent.addView(view);
        }
    }
}

From source file:com.otaupdater.DownloadReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    String action = intent.getAction();
    if (action == null)
        return;//from  w ww .j a va2 s  . c om

    if (action.equals(DL_ROM_ACTION)) {
        RomInfo.FACTORY.clearUpdateNotif(context);
        RomInfo.FACTORY.fromIntent(intent).startDownload(context);
    } else if (action.equals(DL_KERNEL_ACTION)) {
        KernelInfo.FACTORY.clearUpdateNotif(context);
        KernelInfo.FACTORY.fromIntent(intent).startDownload(context);
    } else if (action.equals(CLEAR_DL_ACTION)) {
        if (intent.hasExtra(DownloadManager.EXTRA_DOWNLOAD_ID)) {
            DownloadManager dm = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
            dm.remove(intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1));
            DownloadBarFragment.notifyActiveFragment();
        }
    } else if (action.equals(DownloadManager.ACTION_DOWNLOAD_COMPLETE)) {
        DownloadStatus status = DownloadStatus.forDownloadID(context,
                intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1));
        if (status == null)
            return;

        BaseInfo info = status.getInfo();
        if (info == null)
            return;

        int error = status.getStatus() == DownloadManager.STATUS_SUCCESSFUL ? info.checkDownloadedFile()
                : status.getReason();

        NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

        if (error == 0) {
            Intent mainIntent = new Intent(context, OTAUpdaterActivity.class);
            mainIntent.setAction(info.getNotifAction());
            mainIntent.putExtra(OTAUpdaterActivity.EXTRA_FLAG_DOWNLOAD_DIALOG, true);
            PendingIntent mainPIntent = PendingIntent.getActivity(context, 0, mainIntent,
                    PendingIntent.FLAG_CANCEL_CURRENT);

            Intent flashIntent = new Intent(context, DownloadsActivity.class);
            flashIntent.setAction(info.getFlashAction());
            info.addToIntent(flashIntent);
            PendingIntent flashPIntent = PendingIntent.getActivity(context, 0, flashIntent,
                    PendingIntent.FLAG_CANCEL_CURRENT);

            Notification notif = new NotificationCompat.Builder(context)
                    .setTicker(context.getString(info.getDownloadDoneTitle()))
                    .setContentTitle(context.getString(info.getDownloadDoneTitle()))
                    .setSmallIcon(R.drawable.ic_stat_av_download)
                    .setContentText(context.getString(R.string.notif_completed)).setContentIntent(mainPIntent)
                    .addAction(R.drawable.ic_action_system_update, context.getString(R.string.install),
                            flashPIntent)
                    .build();
            nm.notify(info.getFlashNotifID(), notif);
        } else {
            Intent mainIntent = new Intent(context, OTAUpdaterActivity.class);
            mainIntent.setAction(info.getNotifAction());
            info.addToIntent(mainIntent);
            PendingIntent mainPIntent = PendingIntent.getActivity(context, 0, mainIntent,
                    PendingIntent.FLAG_CANCEL_CURRENT);

            Intent dlIntent = new Intent(context, DownloadReceiver.class);
            dlIntent.setAction(info.getDownloadAction());
            info.addToIntent(dlIntent);
            PendingIntent dlPIntent = PendingIntent.getBroadcast(context, 1, dlIntent,
                    PendingIntent.FLAG_CANCEL_CURRENT);

            Intent clearIntent = new Intent(context, DownloadReceiver.class);
            clearIntent.setAction(CLEAR_DL_ACTION);
            clearIntent.putExtra(DownloadManager.EXTRA_DOWNLOAD_ID, status.getId());
            PendingIntent clearPIntent = PendingIntent.getBroadcast(context, 2, clearIntent,
                    PendingIntent.FLAG_CANCEL_CURRENT);

            Notification notif = new NotificationCompat.Builder(context)
                    .setTicker(context.getString(info.getDownloadFailedTitle()))
                    .setContentTitle(context.getString(info.getDownloadFailedTitle()))
                    .setContentText(status.getErrorString(context)).setSmallIcon(R.drawable.ic_stat_warning)
                    .setContentIntent(mainPIntent).setDeleteIntent(clearPIntent)
                    .addAction(R.drawable.ic_action_refresh, context.getString(R.string.retry), dlPIntent)
                    .build();
            nm.notify(info.getFailedNotifID(), notif);
        }
    } else if (action.equals(DownloadManager.ACTION_NOTIFICATION_CLICKED)) {
        long[] ids = intent.getLongArrayExtra(DownloadManager.EXTRA_NOTIFICATION_CLICK_DOWNLOAD_IDS);
        if (ids.length == 0)
            return;

        DownloadStatus status = DownloadStatus.forDownloadID(context, ids[0]);
        if (status == null)
            return;

        BaseInfo info = status.getInfo();
        if (info == null)
            return;

        Intent i = new Intent(context, OTAUpdaterActivity.class);
        i.setAction(info.getNotifAction());
        i.putExtra(OTAUpdaterActivity.EXTRA_FLAG_DOWNLOAD_DIALOG, true);
        i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(i);
    }
}

From source file:com.quarterfull.newsAndroid.services.DownloadImagesService.java

@Override
protected void onHandleIntent(Intent intent) {
    DownloadMode downloadMode = (DownloadMode) intent.getSerializableExtra(DOWNLOAD_MODE_STRING);

    DatabaseConnectionOrm dbConn = new DatabaseConnectionOrm(this);
    Notification notify = BuildNotification();

    if (downloadMode.equals(DownloadMode.FAVICONS_ONLY)) {
        List<Feed> feedList = dbConn.getListOfFeeds();
        FavIconHandler favIconHandler = new FavIconHandler(this);
        for (Feed feed : feedList) {
            favIconHandler.PreCacheFavIcon(feed);
        }/*  w  w  w  .  j  a  v  a 2s. com*/
    } else if (downloadMode.equals(DownloadMode.FAVICONS_AND_PICTURES)
            || downloadMode.equals(DownloadMode.PICTURES_ONLY)) {
        long lastId = intent.getLongExtra(LAST_ITEM_ID, 0);
        List<RssItem> rssItemList = dbConn.getAllItemsWithIdHigher(lastId);
        List<String> links = new ArrayList<>();
        for (RssItem rssItem : rssItemList) {
            String body = rssItem.getBody();
            links.addAll(ImageHandler.getImageLinksFromText(body));

            if (links.size() > 10000) {
                notificationManager.notify(123, GetNotificationLimitImagesReached(10000));
                break;
            }
        }
        ((LazyList) rssItemList).close();

        maxCount = links.size();

        if (maxCount > 0) {
            notificationManager.notify(NOTIFICATION_ID, notify);
        }

        linksToImages.addAll(links);

        StartNextDownloadInQueue();
    }
}