Example usage for android.os Bundle getLongArray

List of usage examples for android.os Bundle getLongArray

Introduction

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

Prototype

@Nullable
public long[] getLongArray(@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:io.jawg.osmcontributor.ui.fragments.MapFragment.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    if (savedInstanceState != null) {
        Integer creationModeInt = savedInstanceState.getInt(CREATION_MODE);
        savePoiTypeId = savedInstanceState.getLong(POI_TYPE_ID);

        markerSelectedId = savedInstanceState.getLong(SELECTED_MARKER_ID, -1);

        mapMode = MapMode.values()[creationModeInt];
        if (mapMode == MapMode.DETAIL_NOTE || mapMode == MapMode.DETAIL_POI
                || mapMode == MapMode.POI_POSITION_EDITION) {
            mapMode = MapMode.DEFAULT;/* w w  w  .ja v  a 2s .c o  m*/
        } else if (mapMode == MapMode.NODE_REF_POSITION_EDITION) {
            mapMode = MapMode.WAY_EDITION;
        }

        long[] hidden = savedInstanceState.getLongArray(HIDDEN_POI_TYPE);
        if (hidden != null) {
            for (long l : hidden) {
                poiTypeHidden.add(l);
            }
        }

        displayOpenNotes = savedInstanceState.getBoolean(DISPLAY_OPEN_NOTES);
        displayClosedNotes = savedInstanceState.getBoolean(DISPLAY_CLOSED_NOTES);
    }
}

From source file:org.getlantern.firetweet.util.Utils.java

public static long[] getAccountIds(Bundle args) {
    final long[] accountIds;
    if (args.containsKey(EXTRA_ACCOUNT_IDS)) {
        accountIds = args.getLongArray(EXTRA_ACCOUNT_IDS);
    } else if (args.containsKey(EXTRA_ACCOUNT_ID)) {
        accountIds = new long[] { args.getLong(EXTRA_ACCOUNT_ID, -1) };
    } else {/*from   ww  w.j av  a2  s  .  c  om*/
        accountIds = null;
    }
    return accountIds;
}

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

@Override
protected void onCreate(final Bundle savedInstanceState) {
    // requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    super.onCreate(savedInstanceState);
    mLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    mPreferences = SharedPreferencesWrapper.getInstance(this, SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE);
    mBottomSendButton = mPreferences.getBoolean(KEY_BOTTOM_SEND_BUTTON, false);
    mTwitterWrapper = getTwittnukerApplication().getTwitterWrapper();
    mResolver = getContentResolver();/*from  www .  j a  v  a 2s.c o m*/
    mValidator = new TwidereValidator(this);
    setContentView(getLayoutInflater().inflate(R.layout.activity_compose, null));
    setProgressBarIndeterminateVisibility(false);
    setFinishOnTouchOutside(false);
    mAccountIds = getAccountIds(this);
    if (mAccountIds.length <= 0) {
        final Intent intent = new Intent(INTENT_ACTION_TWITTER_LOGIN);
        intent.setClass(this, SignInActivity.class);
        startActivity(intent);
        finish();
        return;
    }
    mBottomMenuBar.setIsBottomBar(true);
    mBottomMenuBar.setOnMenuItemClickListener(this);
    mActionMenuBar.setOnMenuItemClickListener(this);
    mEditText.setOnEditorActionListener(mPreferences.getBoolean(KEY_QUICK_SEND, false) ? this : null);
    mEditText.addTextChangedListener(this);
    mAccountSelectorAdapter = new AccountSelectorAdapter(this);
    mAccountSelector.setAdapter(mAccountSelectorAdapter);
    mAccountSelector.setOnItemClickListener(this);
    mAccountSelector.setOnItemLongClickListener(this);
    mAccountSelector.setScrollAfterItemClickEnabled(false);
    mAccountSelector.setScrollRightSpacingEnabled(false);

    mMediaPreviewAdapter = new MediaPreviewAdapter(this);
    mMediasPreviewGrid.setAdapter(mMediaPreviewAdapter);

    final Intent intent = getIntent();

    if (savedInstanceState != null) {
        // Restore from previous saved state
        mSendAccountIds = savedInstanceState.getLongArray(EXTRA_ACCOUNT_IDS);
        mIsPossiblySensitive = savedInstanceState.getBoolean(EXTRA_IS_POSSIBLY_SENSITIVE);
        final ArrayList<ParcelableMediaUpdate> mediasList = savedInstanceState
                .getParcelableArrayList(EXTRA_MEDIAS);
        if (mediasList != null) {
            addMedias(mediasList);
        }
        mInReplyToStatus = savedInstanceState.getParcelable(EXTRA_STATUS);
        mInReplyToStatusId = savedInstanceState.getLong(EXTRA_STATUS_ID);
        mMentionUser = savedInstanceState.getParcelable(EXTRA_USER);
        mDraftItem = savedInstanceState.getParcelable(EXTRA_DRAFT);
        mShouldSaveAccounts = savedInstanceState.getBoolean(EXTRA_SHOULD_SAVE_ACCOUNTS);
        mOriginalText = savedInstanceState.getString(EXTRA_ORIGINAL_TEXT);
        mTempPhotoUri = savedInstanceState.getParcelable(EXTRA_TEMP_URI);
    } else {
        // The activity was first created
        final int notificationId = intent.getIntExtra(EXTRA_NOTIFICATION_ID, -1);
        final long notificationAccount = intent.getLongExtra(EXTRA_NOTIFICATION_ACCOUNT, -1);
        if (notificationId != -1) {
            mTwitterWrapper.clearNotificationAsync(notificationId, notificationAccount);
        }
        if (!handleIntent(intent)) {
            handleDefaultIntent(intent);
        }
        if (mSendAccountIds == null || mSendAccountIds.length == 0) {
            final long[] ids_in_prefs = ArrayUtils
                    .parseLongArray(mPreferences.getString(KEY_COMPOSE_ACCOUNTS, null), ',');
            final long[] intersection = ArrayUtils.intersection(ids_in_prefs, mAccountIds);
            mSendAccountIds = intersection.length > 0 ? intersection : mAccountIds;
        }
        mOriginalText = ParseUtils.parseString(mEditText.getText());
    }
    if (!setComposeTitle(intent)) {
        setTitle(R.string.compose);
    }

    final boolean useBottomMenu = isSingleAccount() || !mBottomSendButton;
    if (useBottomMenu) {
        mBottomMenuBar.inflate(R.menu.menu_compose);
    } else {
        mActionMenuBar.inflate(R.menu.menu_compose);
    }
    mBottomMenuBar.setVisibility(useBottomMenu ? View.VISIBLE : View.GONE);
    mActionMenuBar.setVisibility(useBottomMenu ? View.GONE : View.VISIBLE);
    mSendView.setVisibility(mBottomSendButton ? View.GONE : View.VISIBLE);
    mBottomSendDivider.setVisibility(mBottomSendButton ? View.VISIBLE : View.GONE);
    mBottomSendView.setVisibility(mBottomSendButton ? View.VISIBLE : View.GONE);
    mSendView.setOnClickListener(this);
    mBottomSendView.setOnClickListener(this);
    mSendView.setOnLongClickListener(this);
    mBottomSendView.setOnLongClickListener(this);
    final LinearLayout.LayoutParams bottomMenuContainerParams = (LinearLayout.LayoutParams) mBottomMenuContainer
            .getLayoutParams();
    final LinearLayout.LayoutParams accountSelectorParams = (LinearLayout.LayoutParams) mAccountSelector
            .getLayoutParams();
    final int maxItemsShown;
    final Resources res = getResources();
    if (isSingleAccount()) {
        accountSelectorParams.weight = 0;
        accountSelectorParams.width = ViewGroup.LayoutParams.WRAP_CONTENT;
        bottomMenuContainerParams.weight = 1;
        bottomMenuContainerParams.width = ViewGroup.LayoutParams.MATCH_PARENT;
        maxItemsShown = res.getInteger(R.integer.max_compose_menu_buttons_bottom_singleaccount);
        mAccountSelectorDivider.setVisibility(View.VISIBLE);
    } else {
        accountSelectorParams.weight = 1;
        accountSelectorParams.width = ViewGroup.LayoutParams.MATCH_PARENT;
        bottomMenuContainerParams.weight = 0;
        bottomMenuContainerParams.width = ViewGroup.LayoutParams.WRAP_CONTENT;
        maxItemsShown = res.getInteger(R.integer.max_compose_menu_buttons_bottom);
        mAccountSelectorDivider.setVisibility(mBottomSendButton ? View.GONE : View.VISIBLE);
    }
    mBottomMenuContainer.setLayoutParams(bottomMenuContainerParams);
    mBottomMenuBar.setMaxItemsShown(maxItemsShown);
    setMenu();
    updateAccountSelection();
    updateMediasPreview();
}

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

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

    preferences = getSharedPreferences("preferences", MODE_PRIVATE);
    cityId = preferences.getInt(NetworkQuery.Params.ID, NetworkQuery.Defaults.CITY_ID);
    cachingTimestamp = preferences.getLong(CACHE_TIMESTAMP, 0L);

    tvTemperatureLimit1 = (TextView) findViewById(R.id.tvTemperatureLimit1);
    tvTemperatureLimit2 = (TextView) findViewById(R.id.tvTemperatureLimit2);
    tvTime1Limit1 = (TextView) findViewById(R.id.tvTime1Limit1);
    tvTime1Limit2 = (TextView) findViewById(R.id.tvTime1Limit2);
    tvTime2Limit1 = (TextView) findViewById(R.id.tvTime2Limit1);
    tvTime2Limit2 = (TextView) findViewById(R.id.tvTime2Limit2);
    tvDayTemperatureSpan = (TextView) findViewById(R.id.tvDayTemperatureSpan);
    tvDayAverageTemperature = (TextView) findViewById(R.id.tvDayAverageTemperature);
    tvDayMedianTemperature = (TextView) findViewById(R.id.tvDayMedianTemperature);
    graphView = (GraphView) findViewById(R.id.graph);
    llLoader = (LinearLayout) findViewById(R.id.llLoader);
    ptrLayout = (PullToRefreshLayout) findViewById(R.id.ptr_layout);

    resetValues();/*w w  w. j  a v a 2 s  . com*/

    ActionBarPullToRefresh.from(this).allChildrenArePullable().listener(new OnRefreshListener() {
        @Override
        public void onRefreshStarted(View view) {
            networkQuery.cancelAllRequests(MainActivity.this);
            refreshWeatherData();
        }
    }).setup(ptrLayout);

    String appId = preferences.getString(NetworkQuery.Params.APPID, "");
    networkQuery = NetworkQuery.getInstance(getApplicationContext());
    networkQuery.setAppId(appId);

    registerDialog = new SettingsActivity.RegisterDialog(this, new DialogInterface.OnClickListener() {
        @Override
        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();
            cachingTimestamp = 0;
            refreshWeatherData();
        }
    });

    if (savedInstanceState == null) {
        refreshWeatherData();
        if (preferences.getBoolean(IS_FIRST_LAUNCH, true)) {
            registerDialog.show();
            preferences.edit().putBoolean(IS_FIRST_LAUNCH, false).apply();
        }
    } else {
        currentTime = savedInstanceState.getLong(SAVED_CURRENT_TIME);
        currentTimeMinus12h = savedInstanceState.getLong(SAVED_CURRENT_TIME_MINUS_12);
        currentTimeMinus24h = savedInstanceState.getLong(SAVED_CURRENT_TIME_MINUS_24);
        currentIsGained = savedInstanceState.getBoolean(SAVED_CURRENT_GAINED);
        historyIsGained = savedInstanceState.getBoolean(SAVED_HISTORY_GAINED);
        long[] timeArray = savedInstanceState.getLongArray(SAVED_TIME_ARRAY);
        double[] tempArray = savedInstanceState.getDoubleArray(SAVED_TEMP_ARRAY);
        boolean refreshWasRun = savedInstanceState.getBoolean(SAVED_LOADER_VISIBILITY) || refreshWasCancelled;
        if (refreshWasRun || (timeArray == null || tempArray == null))
            refreshWeatherData();
        else {
            temperatureMap.clear();
            for (int i = 0; i < timeArray.length && i < tempArray.length; i++)
                temperatureMap.put(timeArray[i], tempArray[i]);
            processValues(true);
        }
        if (savedInstanceState.getBoolean(SAVED_DIALOG_VISIBILITY)) {
            registerDialog.getEtAppId().setText(savedInstanceState.getString(SAVED_DIALOG_APPID));
            registerDialog.show();
        }
    }
}

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

@Override
protected void onCreate(final Bundle savedInstanceState) {
    // requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    super.onCreate(savedInstanceState);
    mLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    mPreferences = SharedPreferencesWrapper.getInstance(this, SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE);

    final FiretweetApplication app = FiretweetApplication.getInstance(this);
    mTwitterWrapper = app.getTwitterWrapper();
    mResolver = getContentResolver();/* ww  w.  jav  a 2s  .  c  om*/
    mValidator = new FiretweetValidator(this);
    mImageLoader = app.getMediaLoaderWrapper();
    setContentView(R.layout.activity_compose);
    //        setSupportProgressBarIndeterminateVisibility(false);
    setFinishOnTouchOutside(false);
    final long[] defaultAccountIds = getAccountIds(this);
    if (defaultAccountIds.length <= 0) {
        final Intent intent = new Intent(INTENT_ACTION_TWITTER_LOGIN);
        intent.setClass(this, SignInActivity.class);
        startActivity(intent);
        finish();
        return;
    }
    //        mMenuBar.setIsBottomBar(true);
    mMenuBar.setOnMenuItemClickListener(this);
    mEditText.setOnEditorActionListener(mPreferences.getBoolean(KEY_QUICK_SEND, false) ? this : null);
    mEditText.addTextChangedListener(this);
    mEditText.setCustomSelectionActionModeCallback(this);
    mAccountSelectorContainer.setOnClickListener(this);
    mAccountSelectorButton.setOnClickListener(this);
    mLocationContainer.setOnClickListener(this);

    final LinearLayoutManager linearLayoutManager = new FixedLinearLayoutManager(this);
    linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
    linearLayoutManager.setStackFromEnd(true);
    mAccountSelector.setLayoutManager(linearLayoutManager);
    mAccountSelector.addItemDecoration(new SpacingItemDecoration(this));
    mAccountsAdapter = new AccountIconsAdapter(this);
    mAccountSelector.setAdapter(mAccountsAdapter);
    mAccountsAdapter.setAccounts(ParcelableAccount.getAccounts(this, false, false));

    mMediaPreviewAdapter = new MediaPreviewAdapter(this);
    mMediaPreviewGrid.setAdapter(mMediaPreviewAdapter);

    final Intent intent = getIntent();

    if (savedInstanceState != null) {
        // Restore from previous saved state
        mAccountsAdapter.setSelectedAccountIds(savedInstanceState.getLongArray(EXTRA_ACCOUNT_IDS));
        mIsPossiblySensitive = savedInstanceState.getBoolean(EXTRA_IS_POSSIBLY_SENSITIVE);
        final ArrayList<ParcelableMediaUpdate> mediaList = savedInstanceState
                .getParcelableArrayList(EXTRA_MEDIA);
        if (mediaList != null) {
            addMedia(mediaList);
        }
        mInReplyToStatus = savedInstanceState.getParcelable(EXTRA_STATUS);
        mInReplyToStatusId = savedInstanceState.getLong(EXTRA_STATUS_ID);
        mMentionUser = savedInstanceState.getParcelable(EXTRA_USER);
        mDraftItem = savedInstanceState.getParcelable(EXTRA_DRAFT);
        mShouldSaveAccounts = savedInstanceState.getBoolean(EXTRA_SHOULD_SAVE_ACCOUNTS);
        mOriginalText = savedInstanceState.getString(EXTRA_ORIGINAL_TEXT);
        mTempPhotoUri = savedInstanceState.getParcelable(EXTRA_TEMP_URI);
    } else {
        // The context was first created
        final int notificationId = intent.getIntExtra(EXTRA_NOTIFICATION_ID, -1);
        final long notificationAccount = intent.getLongExtra(EXTRA_NOTIFICATION_ACCOUNT, -1);
        if (notificationId != -1) {
            mTwitterWrapper.clearNotificationAsync(notificationId, notificationAccount);
        }
        if (!handleIntent(intent)) {
            handleDefaultIntent(intent);
        }
        final long[] accountIds = mAccountsAdapter.getSelectedAccountIds();
        if (accountIds.length == 0) {
            final long[] idsInPrefs = FiretweetArrayUtils
                    .parseLongArray(mPreferences.getString(KEY_COMPOSE_ACCOUNTS, null), ',');
            final long[] intersection = FiretweetArrayUtils.intersection(idsInPrefs, defaultAccountIds);
            mAccountsAdapter.setSelectedAccountIds(intersection.length > 0 ? intersection : defaultAccountIds);
        }
        mOriginalText = ParseUtils.parseString(mEditText.getText());
    }
    if (!setComposeTitle(intent)) {
        setTitle(R.string.compose);
    }

    final Menu menu = mMenuBar.getMenu();
    getMenuInflater().inflate(R.menu.menu_compose, menu);
    ThemeUtils.wrapMenuIcon(mMenuBar);

    mSendView.setOnClickListener(this);
    mSendView.setOnLongClickListener(this);
    final Intent composeExtensionsIntent = new Intent(INTENT_ACTION_EXTENSION_COMPOSE);
    addIntentToMenu(this, menu, composeExtensionsIntent, MENU_GROUP_COMPOSE_EXTENSION);
    final Intent imageExtensionsIntent = new Intent(INTENT_ACTION_EXTENSION_EDIT_IMAGE);
    final MenuItem mediaMenuItem = menu.findItem(R.id.media_menu);
    if (mediaMenuItem != null && mediaMenuItem.hasSubMenu()) {
        addIntentToMenu(this, mediaMenuItem.getSubMenu(), imageExtensionsIntent, MENU_GROUP_IMAGE_EXTENSION);
    }
    setMenu();
    updateLocationState();
    updateMediaPreview();
    notifyAccountSelectionChanged();
}

From source file:com.dwdesign.tweetings.activity.ComposeActivity.java

@Override
public void onActivityResult(final int requestCode, final int resultCode, final Intent intent) {

    switch (requestCode) {
    case REQUEST_SCHEDULE_DATE: {
        if (resultCode == Activity.RESULT_OK) {
            Bundle bundle = intent.getExtras();
            mScheduleDate = bundle.getString(INTENT_KEY_SCHEDULE_DATE_TIME);
        } else {//from  w ww . ja va2 s .  com
            if (mScheduleDate != null) {
                mScheduleDate = null;
            }
        }
        setMenu();
        break;
    }
    case REQUEST_TAKE_PHOTO: {
        if (resultCode == Activity.RESULT_OK) {
            final File file = new File(mImageUri.getPath());
            if (file.exists()) {
                mIsImageAttached = false;
                mIsPhotoAttached = true;
                mImageThumbnailPreview.setVisibility(View.VISIBLE);
                reloadAttachedImageThumbnail(file);
            } else {
                mIsPhotoAttached = false;
            }
            setMenu();
            boolean isAutoUpload = mPreferences.getBoolean(PREFERENCE_KEY_AUTO_UPLOAD, false);
            if (!isNullOrEmpty(mUploadProvider) && mIsPhotoAttached && isAutoUpload) {
                postMedia();
            }
        }
        break;
    }
    case REQUEST_PICK_IMAGE: {
        if (resultCode == Activity.RESULT_OK) {
            final Uri uri = intent.getData();
            final File file = uri == null ? null : new File(getImagePathFromUri(this, uri));
            if (file != null && file.exists()) {
                mImageUri = Uri.fromFile(file);
                mIsPhotoAttached = false;
                mIsImageAttached = true;
                mImageThumbnailPreview.setVisibility(View.VISIBLE);
                reloadAttachedImageThumbnail(file);
            } else {
                mIsImageAttached = false;
            }
            setMenu();
            boolean isAutoUpload = mPreferences.getBoolean(PREFERENCE_KEY_AUTO_UPLOAD, false);
            if (!isNullOrEmpty(mUploadProvider) && mIsImageAttached && isAutoUpload) {
                postMedia();
            }
        }
        break;
    }
    case REQUEST_SELECT_ACCOUNT: {
        if (resultCode == Activity.RESULT_OK) {
            final Bundle bundle = intent.getExtras();
            if (bundle == null) {
                break;
            }
            final long[] account_ids = bundle.getLongArray(INTENT_KEY_IDS);
            if (account_ids != null) {
                mAccountIds = account_ids;
                if (mInReplyToStatusId <= 0 && !Intent.ACTION_SEND.equals(getIntent().getAction())) {
                    final SharedPreferences.Editor editor = mPreferences.edit();
                    editor.putString(PREFERENCE_KEY_COMPOSE_ACCOUNTS,
                            ArrayUtils.toString(mAccountIds, ',', false));
                    editor.commit();
                }
                mColorIndicator.setColor(getAccountColors(this, account_ids));
            }
        }
        break;
    }
    case REQUEST_EDIT_IMAGE: {
        if (resultCode == Activity.RESULT_OK) {
            final Uri uri = intent.getData();
            final File file = uri == null ? null : new File(getImagePathFromUri(this, uri));
            if (file != null && file.exists()) {
                mImageUri = Uri.fromFile(file);
                reloadAttachedImageThumbnail(file);
            } else {
                break;
            }
            setMenu();
        }
        break;
    }
    case REQUEST_EXTENSION_COMPOSE: {
        if (resultCode == Activity.RESULT_OK) {
            final Bundle extras = intent.getExtras();
            if (extras == null) {
                break;
            }
            final String text = extras.getString(INTENT_KEY_TEXT);
            final String append = extras.getString(INTENT_KEY_APPEND_TEXT);
            if (text != null) {
                mEditText.setText(text);
                mText = parseString(mEditText.getText());
            } else if (append != null) {
                mEditText.append(append);
                mText = parseString(mEditText.getText());
            }
        }
        break;
    }
    case ACTION_REQUEST_FEATHER:
        if (resultCode == RESULT_OK) {
            final Uri uri = intent.getData();
            final File file = uri == null ? null : new File(getImagePathFromUri(this, uri));
            if (file != null && file.exists()) {
                mImageUri = Uri.fromFile(file);
                reloadAttachedImageThumbnail(file);
            } else {
                break;
            }
            setMenu();
        }
        break;
    }

}

From source file:org.tigase.mobile.roster.RosterFragment.java

@Override
public View onCreateView(final LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    if (DEBUG)//from w  w w .  j ava2 s .  c  o m
        Log.d(TAG + "_rf", "onCreateView()");

    if (getArguments() != null) {
        this.rosterLayout = getArguments().getString("layout");
    }

    View layout;
    if ("groups".equals(this.rosterLayout)) {
        layout = inflater.inflate(R.layout.roster_list, null);
    } else if ("flat".equals(this.rosterLayout)) {
        layout = inflater.inflate(R.layout.roster_list_flat, null);
    } else if ("grid".equals(this.rosterLayout)) {
        layout = inflater.inflate(R.layout.roster_list_grid, null);
    } else {
        throw new RuntimeException("Unknown roster layout");
    }

    listView = (AbsListView) layout.findViewById(R.id.rosterList);
    listView.setTextFilterEnabled(true);
    registerForContextMenu(listView);

    if (listView instanceof ExpandableListView) {
        if (c != null) {
            getActivity().stopManagingCursor(c);
        }
        this.c = inflater.getContext().getContentResolver().query(Uri.parse(RosterProvider.GROUP_URI), null,
                null, null, null);
        getActivity().startManagingCursor(c);
        GroupsRosterAdapter.staticContext = inflater.getContext();

        this.adapter = new GroupsRosterAdapter(inflater.getContext(), c);

        ((ExpandableListView) listView).setAdapter((ExpandableListAdapter) adapter);
        ((ExpandableListView) listView).setOnChildClickListener(new OnChildClickListener() {

            @Override
            public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition,
                    long id) {

                Log.i(TAG, "Clicked on id=" + id);

                Intent intent = new Intent();
                intent.setAction(TigaseMobileMessengerActivity.ROSTER_CLICK_MSG);
                intent.putExtra("id", id);

                getActivity().getApplicationContext().sendBroadcast(intent);
                return true;
            }
        });
    } else if (listView instanceof ListView || listView instanceof GridView) {
        if (c != null) {
            getActivity().stopManagingCursor(c);
        }
        this.c = inflater.getContext().getContentResolver().query(Uri.parse(RosterProvider.CONTENT_URI), null,
                null, null, null);

        getActivity().startManagingCursor(c);
        // FlatRosterAdapter.staticContext = inflater.getContext();

        if (listView instanceof ListView) {
            this.adapter = new FlatRosterAdapter(inflater.getContext(), c, R.layout.roster_item);
            ((ListView) listView).setAdapter((ListAdapter) adapter);
        } else if (listView instanceof GridView) {
            this.adapter = new FlatRosterAdapter(inflater.getContext(), c, R.layout.roster_grid_item);
            ((GridView) listView).setAdapter((ListAdapter) adapter);
        }
        listView.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Log.i(TAG, "Clicked on id=" + id);

                Intent intent = new Intent();
                intent.setAction(TigaseMobileMessengerActivity.ROSTER_CLICK_MSG);
                intent.putExtra("id", id);

                getActivity().getApplicationContext().sendBroadcast(intent);
            }
        });

    }
    // there can be no connection status icon - we have notifications and
    // accounts view in Android >= 3.0
    this.connectionStatus = (ImageView) layout.findViewById(R.id.connection_status);
    this.progressBar = (ProgressBar) layout.findViewById(R.id.progressBar1);

    if (DEBUG)
        Log.d(TAG + "_rf", "layout created");

    long[] expandedIds = savedInstanceState == null ? null : savedInstanceState.getLongArray("ExpandedIds");
    if (expandedIds != null) {
        restoreExpandedState(expandedIds);
    }

    return layout;
}

From source file:com.ota.updates.receivers.AppReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    String action = intent.getAction();
    Bundle extras = intent.getExtras();
    long mRomDownloadID = Preferences.getDownloadID(context);

    if (action.equals(DownloadManager.ACTION_DOWNLOAD_COMPLETE)) {
        long id = extras.getLong(DownloadManager.EXTRA_DOWNLOAD_ID);
        boolean isAddonDownload = false;
        int keyForAddonDownload = 0;

        Set<Integer> set = OtaUpdates.getAddonDownloadKeySet();
        Iterator<Integer> iterator = set.iterator();

        while (iterator.hasNext() && isAddonDownload != true) {
            int nextValue = iterator.next();
            if (id == OtaUpdates.getAddonDownload(nextValue)) {
                isAddonDownload = true;/*from  w w  w  .j  a v  a 2s .  c o m*/
                keyForAddonDownload = nextValue;
                if (DEBUGGING) {
                    Log.d(TAG, "Checking ID " + nextValue);
                }
            }
        }

        if (isAddonDownload) {
            DownloadManager downloadManager = (DownloadManager) context
                    .getSystemService(Context.DOWNLOAD_SERVICE);
            DownloadManager.Query query = new DownloadManager.Query();
            query.setFilterById(id);
            Cursor cursor = downloadManager.query(query);

            // it shouldn't be empty, but just in case
            if (!cursor.moveToFirst()) {
                if (DEBUGGING)
                    Log.e(TAG, "Addon Download Empty row");
                return;
            }

            int statusIndex = cursor.getColumnIndex(DownloadManager.COLUMN_STATUS);
            if (DownloadManager.STATUS_SUCCESSFUL != cursor.getInt(statusIndex)) {
                if (DEBUGGING)
                    Log.w(TAG, "Download Failed");
                Log.d(TAG, "Removing Addon download with id " + keyForAddonDownload);
                OtaUpdates.removeAddonDownload(keyForAddonDownload);
                AddonActivity.AddonsArrayAdapter.updateProgress(keyForAddonDownload, 0, true);
                AddonActivity.AddonsArrayAdapter.updateButtons(keyForAddonDownload, false);
                return;
            } else {
                if (DEBUGGING)
                    Log.v(TAG, "Download Succeeded");
                Log.d(TAG, "Removing Addon download with id " + keyForAddonDownload);
                OtaUpdates.removeAddonDownload(keyForAddonDownload);
                AddonActivity.AddonsArrayAdapter.updateButtons(keyForAddonDownload, true);
                return;
            }
        } else {
            if (DEBUGGING)
                Log.v(TAG, "Receiving " + mRomDownloadID);

            if (id != mRomDownloadID) {
                if (DEBUGGING)
                    Log.v(TAG, "Ignoring unrelated non-ROM download " + id);
                return;
            }

            DownloadManager downloadManager = (DownloadManager) context
                    .getSystemService(Context.DOWNLOAD_SERVICE);
            DownloadManager.Query query = new DownloadManager.Query();
            query.setFilterById(id);
            Cursor cursor = downloadManager.query(query);

            // it shouldn't be empty, but just in case
            if (!cursor.moveToFirst()) {
                if (DEBUGGING)
                    Log.e(TAG, "Rom download Empty row");
                return;
            }

            int statusIndex = cursor.getColumnIndex(DownloadManager.COLUMN_STATUS);
            if (DownloadManager.STATUS_SUCCESSFUL != cursor.getInt(statusIndex)) {
                if (DEBUGGING)
                    Log.w(TAG, "Download Failed");
                Preferences.setDownloadFinished(context, false);
                if (Utils.isLollipop()) {
                    AvailableActivity.setupMenuToolbar(context); // Reset options menu
                } else {
                    AvailableActivity.invalidateMenu();
                }
                return;
            } else {
                if (DEBUGGING)
                    Log.v(TAG, "Download Succeeded");
                Preferences.setDownloadFinished(context, true);
                AvailableActivity.setupProgress(context);
                if (Utils.isLollipop()) {
                    AvailableActivity.setupMenuToolbar(context); // Reset options menu
                } else {
                    AvailableActivity.invalidateMenu();
                }
                return;
            }
        }
    }

    if (action.equals(DownloadManager.ACTION_NOTIFICATION_CLICKED)) {

        long[] ids = extras.getLongArray(DownloadManager.EXTRA_NOTIFICATION_CLICK_DOWNLOAD_IDS);

        for (long id : ids) {
            if (id != mRomDownloadID) {
                if (DEBUGGING)
                    Log.v(TAG, "mDownloadID is " + mRomDownloadID + " and ID is " + id);
                return;
            } else {
                Intent i = new Intent(context, AvailableActivity.class);
                i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                context.startActivity(i);
            }
        }
    }

    if (action.equals(MANIFEST_CHECK_BACKGROUND)) {
        if (DEBUGGING)
            Log.d(TAG, "Receiving background check confirmation");

        boolean updateAvailable = RomUpdate.getUpdateAvailability(context);
        String filename = RomUpdate.getFilename(context);

        if (updateAvailable) {
            Utils.setupNotification(context, filename);
            Utils.scheduleNotification(context, !Preferences.getBackgroundService(context));
        }
    }

    if (action.equals(START_UPDATE_CHECK)) {
        if (DEBUGGING)
            Log.d(TAG, "Update check started");
        new LoadUpdateManifest(context, false).execute();
    }

    if (action.equals(Intent.ACTION_BOOT_COMPLETED)) {
        if (DEBUGGING) {
            Log.d(TAG, "Boot received");
        }
        boolean backgroundCheck = Preferences.getBackgroundService(context);
        if (backgroundCheck) {
            if (DEBUGGING)
                Log.d(TAG, "Starting background check alarm");
            Utils.scheduleNotification(context, !Preferences.getBackgroundService(context));
        }
    }

    if (action.equals(IGNORE_RELEASE)) {
        if (DEBUGGING) {
            Log.d(TAG, "Ignore release");
        }
        Preferences.setIgnoredRelease(context, Integer.toString(RomUpdate.getVersionNumber(context)));
        final NotificationManager mNotifyManager = (NotificationManager) context
                .getSystemService(Context.NOTIFICATION_SERVICE);
        Builder mBuilder = new NotificationCompat.Builder(context);
        mBuilder.setContentTitle(context.getString(R.string.main_release_ignored))
                .setSmallIcon(R.drawable.ic_notif)
                .setContentIntent(PendingIntent.getActivity(context, 0, new Intent(), 0));
        mNotifyManager.notify(NOTIFICATION_ID, mBuilder.build());

        Handler h = new Handler();
        long delayInMilliseconds = 1500;
        h.postDelayed(new Runnable() {

            public void run() {
                mNotifyManager.cancel(NOTIFICATION_ID);
            }
        }, delayInMilliseconds);
    }
}

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

@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    mPreferences = SharedPreferencesWrapper.getInstance(this, SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE,
            SharedPreferenceConstants.class);

    final TwidereApplication app = TwidereApplication.getInstance(this);
    mTwitterWrapper = app.getTwitterWrapper();
    mResolver = getContentResolver();/*from w  w  w  . j av a 2 s  .co  m*/
    mValidator = new TwidereValidator(this);
    mImageLoader = app.getMediaLoaderWrapper();
    setContentView(R.layout.activity_compose);
    setFinishOnTouchOutside(false);
    final long[] defaultAccountIds = Utils.getAccountIds(this);
    if (defaultAccountIds.length <= 0) {
        final Intent intent = new Intent(INTENT_ACTION_TWITTER_LOGIN);
        intent.setClass(this, SignInActivity.class);
        startActivity(intent);
        finish();
        return;
    }
    mMenuBar.setOnMenuItemClickListener(this);
    setupEditText();
    mAccountSelectorContainer.setOnClickListener(this);
    mAccountSelectorButton.setOnClickListener(this);
    mLocationContainer.setOnClickListener(this);

    final LinearLayoutManager linearLayoutManager = new FixedLinearLayoutManager(this);
    linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
    linearLayoutManager.setStackFromEnd(true);
    mAccountSelector.setLayoutManager(linearLayoutManager);
    mAccountSelector.addItemDecoration(new SpacingItemDecoration(this));
    mAccountSelector.setItemAnimator(new RecyclerView.ItemAnimator() {
        @Override
        public void runPendingAnimations() {

        }

        @Override
        public boolean animateRemove(ViewHolder holder) {
            return false;
        }

        @Override
        public boolean animateAdd(ViewHolder holder) {
            return false;
        }

        @Override
        public boolean animateMove(ViewHolder holder, int fromX, int fromY, int toX, int toY) {
            Log.d(LOGTAG, String.format("animateMove"));
            return false;
        }

        @Override
        public boolean animateChange(ViewHolder oldHolder, ViewHolder newHolder, int fromLeft, int fromTop,
                int toLeft, int toTop) {
            Log.d(LOGTAG, String.format("animateChange"));
            return false;
        }

        @Override
        public void endAnimation(ViewHolder item) {
            Log.d(LOGTAG, String.format("endAnimation"));
        }

        @Override
        public void endAnimations() {

        }

        @Override
        public boolean isRunning() {
            return false;
        }
    });
    mAccountsAdapter = new AccountIconsAdapter(this);
    mAccountSelector.setAdapter(mAccountsAdapter);
    mAccountsAdapter.setAccounts(ParcelableAccount.getAccounts(this, false, false));

    mMediaPreviewAdapter = new MediaPreviewAdapter(this);
    mMediaPreviewGrid.setAdapter(mMediaPreviewAdapter);

    final Intent intent = getIntent();

    if (savedInstanceState != null) {
        // Restore from previous saved state
        mAccountsAdapter.setSelectedAccountIds(savedInstanceState.getLongArray(EXTRA_ACCOUNT_IDS));
        mIsPossiblySensitive = savedInstanceState.getBoolean(EXTRA_IS_POSSIBLY_SENSITIVE);
        final ArrayList<ParcelableMediaUpdate> mediaList = savedInstanceState
                .getParcelableArrayList(EXTRA_MEDIA);
        if (mediaList != null) {
            addMedia(mediaList);
        }
        mInReplyToStatus = savedInstanceState.getParcelable(EXTRA_STATUS);
        mInReplyToStatusId = savedInstanceState.getLong(EXTRA_STATUS_ID);
        mMentionUser = savedInstanceState.getParcelable(EXTRA_USER);
        mDraftItem = savedInstanceState.getParcelable(EXTRA_DRAFT);
        mShouldSaveAccounts = savedInstanceState.getBoolean(EXTRA_SHOULD_SAVE_ACCOUNTS);
        mOriginalText = savedInstanceState.getString(EXTRA_ORIGINAL_TEXT);
    } else {
        // The context was first created
        final int notificationId = intent.getIntExtra(EXTRA_NOTIFICATION_ID, -1);
        final long notificationAccount = intent.getLongExtra(EXTRA_NOTIFICATION_ACCOUNT, -1);
        if (notificationId != -1) {
            mTwitterWrapper.clearNotificationAsync(notificationId, notificationAccount);
        }
        if (!handleIntent(intent)) {
            handleDefaultIntent(intent);
        }
        final long[] accountIds = mAccountsAdapter.getSelectedAccountIds();
        if (accountIds.length == 0) {
            final long[] idsInPrefs = TwidereArrayUtils
                    .parseLongArray(mPreferences.getString(KEY_COMPOSE_ACCOUNTS, null), ',');
            final long[] intersection = TwidereArrayUtils.intersection(idsInPrefs, defaultAccountIds);
            mAccountsAdapter.setSelectedAccountIds(intersection.length > 0 ? intersection : defaultAccountIds);
        }
        mOriginalText = ParseUtils.parseString(mEditText.getText());
    }
    if (!setComposeTitle(intent)) {
        setTitle(R.string.compose);
    }

    final Menu menu = mMenuBar.getMenu();
    getMenuInflater().inflate(R.menu.menu_compose, menu);
    ThemeUtils.wrapMenuIcon(mMenuBar);

    mSendView.setOnClickListener(this);
    mSendView.setOnLongClickListener(this);
    final Intent composeExtensionsIntent = new Intent(INTENT_ACTION_EXTENSION_COMPOSE);
    Utils.addIntentToMenu(this, menu, composeExtensionsIntent, MENU_GROUP_COMPOSE_EXTENSION);
    final Intent imageExtensionsIntent = new Intent(INTENT_ACTION_EXTENSION_EDIT_IMAGE);
    final MenuItem mediaMenuItem = menu.findItem(R.id.media_menu);
    if (mediaMenuItem != null && mediaMenuItem.hasSubMenu()) {
        Utils.addIntentToMenu(this, mediaMenuItem.getSubMenu(), imageExtensionsIntent,
                MENU_GROUP_IMAGE_EXTENSION);
    }
    setMenu();
    updateLocationState();
    updateMediaPreview();
    notifyAccountSelectionChanged();

    mTextChanged = false;
}