List of usage examples for android.os Bundle getLong
public long getLong(String key)
From source file:com.xargsgrep.portknocker.activity.HostListActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.host_list);/*w ww. ja va2s .c o m*/ getSupportActionBar().setHomeButtonEnabled(false); FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); Fragment hostListFragment = getSupportFragmentManager().findFragmentByTag(HostListFragment.TAG); if (hostListFragment == null) { hostListFragment = HostListFragment.newInstance(); ft.add(R.id.fragment_content, hostListFragment, HostListFragment.TAG); } ft.show(hostListFragment); ft.commit(); Bundle extras = getIntent().getExtras(); if (BundleUtils.contains(extras, EditHostActivity.KEY_SAVE_HOST_RESULT) && savedInstanceState == null) { Boolean saveResult = extras.getBoolean(EditHostActivity.KEY_SAVE_HOST_RESULT); Toast.makeText(this, getResources().getString( saveResult ? R.string.toast_msg_save_success : R.string.toast_msg_save_failure), Toast.LENGTH_SHORT).show(); } if (BundleUtils.contains(extras, "hostId") && savedInstanceState == null) { // clicked on widget databaseManager = new DatabaseManager(this); Long hostId = extras.getLong("hostId"); Host host = databaseManager.getHost(hostId); KnockerAsyncTask knockerAsyncTask = new KnockerAsyncTask(this, host.getPorts().size()); knockerAsyncTask.execute(host); } else if (savedInstanceState != null) { if (savedInstanceState.getBoolean(KEY_SHOW_DELETE_DIALOG)) ((HostListFragment) hostListFragment).showDeleteDialog(); } }
From source file:com.narkii.security.info.BaseDataFragment.java
@Override public Loader<Cursor> onCreateLoader(int id, Bundle bundle) { // TODO Auto-generated method stub DbCursorLoader cursorLoader = null;//ww w. j a v a 2 s. c o m final DbOperations operations = DbOperations.getInstance(getActivity()); if (id == Constants.ENTERPRISE_INFO_ID) { final long rowId = bundle.getLong("id"); cursorLoader = new DbCursorLoader(getActivity()) { @Override public Cursor getDbCursor() { // TODO Auto-generated method stub String[] columns = { Enterprise.COLUMN_NAME, Enterprise.COLUMN_ADDRESS, Enterprise.COLUMN_ORGANIZATION_CODE, Enterprise.COLUMN_FILE_NUMBER, Enterprise.COLUMN_AREA, Enterprise.COLUMN_FK_ENTERPRISE_TYPE, Enterprise.COLUMN_TELEPHONE, Enterprise.COLUMN_FAX, Enterprise.COLUMN_EMAIL, Enterprise.COLUMN_SPECIAL }; Cursor cursor = operations.query(Enterprise.TABLE_NAME, columns, Enterprise._ID + "=?", new String[] { "" + rowId }); return cursor; } }; } else if (id == Constants.ENTERPRISE_PERSON_ID) { final long rowId = bundle.getLong("id"); cursorLoader = new DbCursorLoader(getActivity()) { @Override public Cursor getDbCursor() { // TODO Auto-generated method stub Cursor cursor = operations.query(EnterprisePerson.TABLE_NAME, null, EnterprisePerson.COLUMN_FK_ENTERPRISE_ID + "=?", new String[] { "" + rowId }); return cursor; } }; } else if (id == Constants.SPINNER_AREA_ID) { cursorLoader = new DbCursorLoader(getActivity()) { @Override public Cursor getDbCursor() { // TODO Auto-generated method stub return operations.query(Area.TABLE_NAME, null, null, null); } }; } else if (id == Constants.SPINNER_ENTERPRISE_TYPE_ID) { cursorLoader = new DbCursorLoader(getActivity()) { @Override public Cursor getDbCursor() { // TODO Auto-generated method stub return operations.query(EnterpriseType.TABLE_NAME, null, null, null); } }; } return cursorLoader; }
From source file:de.spiritcroc.ownlog.ui.fragment.LogFilterEditFragment.java
private boolean restoreValues(Bundle savedInstanceState) { if (savedInstanceState == null) { return false; }//from w ww. ja v a2 s .c o m try { if (savedInstanceState.containsKey(KEY_ADD_ITEM)) { mAddItem = savedInstanceState.getBoolean(KEY_ADD_ITEM); mEditItemId = savedInstanceState.getLong(KEY_EDIT_ITEM_ID); mInitName = savedInstanceState.getString(KEY_INIT_NAME); mEditName.setText(savedInstanceState.getString(KEY_SET_NAME)); mInitStrictFilterTags = savedInstanceState.getBoolean(KEY_INIT_STRICT_TAG_FILTER); mCheckStrictFilterTags.setChecked(savedInstanceState.getBoolean(KEY_SET_STRICT_TAG_FILTER)); mInitSortOrder = savedInstanceState.getString(KEY_INIT_SORT_ORDER); mSortOrder = savedInstanceState.getInt(KEY_SORT_ORDER); mInitTags = new ArrayList<>( Arrays.asList((TagItem[]) savedInstanceState.getParcelableArray(KEY_INIT_TAGS))); mInitExcludedTags = new ArrayList<>( Arrays.asList((TagItem[]) savedInstanceState.getParcelableArray(KEY_INIT_EXCLUDED_TAGS))); mSetTags = new ArrayList<>( Arrays.asList((TagItem[]) savedInstanceState.getParcelableArray(KEY_SET_TAGS))); mExcludedTags = new ArrayList<>( Arrays.asList((TagItem[]) savedInstanceState.getParcelableArray(KEY_EXCLUDED_TAGS))); mAvailableTags = new ArrayList<>( Arrays.asList((TagItem[]) savedInstanceState.getParcelableArray(KEY_AVAILABLE_TAGS))); mSortOrder = Arrays.asList(mSortOrderValues).indexOf(mInitSortOrder); if (mSortOrder < 0) { // Select default sort order mSortOrder = 0; } mSpinSortOrder.setSelection(mSortOrder); mEditTagsView.updateContent(); mEditExcludedTagsView.updateContent(); updateStrictFilterTagsInfo(); return true; } } catch (Exception e) { e.printStackTrace(); } return false; }
From source file:li.barter.fragments.AbstractBarterLiFragment.java
/** * Call this method in the onCreateView() of any subclasses * * @param container The container passed into onCreateView() * @param savedInstanceState The Instance state bundle passed into the onCreateView() method *///from w w w .ja v a 2 s.com protected void init(final ViewGroup container, final Bundle savedInstanceState) { mContainerViewId = container.getId(); long lastScreenTime = 0l; if (savedInstanceState != null) { mAddUserInfoDialogFragment = (AddUserInfoDialogFragment) getFragmentManager() .findFragmentByTag(FragmentTags.DIALOG_ADD_NAME); lastScreenTime = savedInstanceState.getLong(Keys.LAST_SCREEN_TIME); } if (Utils.shouldReportScreenHit(lastScreenTime)) { mShouldReportScreenHit = true; } else { mShouldReportScreenHit = false; } }
From source file:com.evandroid.musica.broadcastReceiver.MusicBroadcastReceiver.java
@Override public void onReceive(Context context, Intent intent) { /** Google Play Music //bool streaming long position //long albumId String album //bool currentSongLoaded String track //long ListPosition long ListSize //long id bool playing //long duration int previewPlayType //bool supportsRating int domain //bool albumArtFromService String artist //int rating bool local //bool preparing bool inErrorState *///from w w w. j a v a2 s . co m Bundle extras = intent.getExtras(); SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(context); boolean lengthFilter = sharedPref.getBoolean("pref_filter_20min", true); if (extras != null) try { extras.getInt("state"); } catch (BadParcelableException e) { return; } if (extras == null || extras.getInt("state") > 1 //Tracks longer than 20min are presumably not songs || (lengthFilter && (extras.get("duration") instanceof Long && extras.getLong("duration") > 1200000) || (extras.get("duration") instanceof Double && extras.getDouble("duration") > 1200000) || (extras.get("duration") instanceof Integer && extras.getInt("duration") > 1200)) || (lengthFilter && (extras.get("secs") instanceof Long && extras.getLong("secs") > 1200000) || (extras.get("secs") instanceof Double && extras.getDouble("secs") > 1200000) || (extras.get("secs") instanceof Integer && extras.getInt("secs") > 1200))) return; String artist = extras.getString("artist"); String track = extras.getString("track"); long position = extras.containsKey("position") ? extras.getLong("position") : -1; if (extras.get("position") instanceof Double) position = Double.valueOf(extras.getDouble("position")).longValue(); boolean isPlaying = extras.getBoolean("playing", true); if (intent.getAction().equals("com.amazon.mp3.metachanged")) { artist = extras.getString("com.amazon.mp3.artist"); track = extras.getString("com.amazon.mp3.track"); } else if (intent.getAction().equals("com.spotify.music.metadatachanged")) isPlaying = spotifyPlaying; else if (intent.getAction().equals("com.spotify.music.playbackstatechanged")) spotifyPlaying = isPlaying; if ((artist == null || "".equals(artist)) //Could be problematic || (track == null || "".equals(track) || track.startsWith("DTNS"))) // Ignore one of my favorite podcasts return; SharedPreferences current = context.getSharedPreferences("current_music", Context.MODE_PRIVATE); String currentArtist = current.getString("artist", ""); String currentTrack = current.getString("track", ""); SharedPreferences.Editor editor = current.edit(); editor.putString("artist", artist); editor.putString("track", track); editor.putLong("position", position); editor.putBoolean("playing", isPlaying); if (isPlaying) { long currentTime = System.currentTimeMillis(); editor.putLong("startTime", currentTime); } editor.apply(); autoUpdate = autoUpdate || sharedPref.getBoolean("pref_auto_refresh", false); int notificationPref = Integer.valueOf(sharedPref.getString("pref_notifications", "0")); if (autoUpdate && App.isActivityVisible()) { Intent internalIntent = new Intent("Broadcast"); internalIntent.putExtra("artist", artist).putExtra("track", track); LyricsViewFragment.sendIntent(context, internalIntent); forceAutoUpdate(false); } SQLiteDatabase db = new DatabaseHelper(context).getReadableDatabase(); boolean inDatabase = DatabaseHelper.presenceCheck(db, new String[] { artist, track, artist, track }); db.close(); if (notificationPref != 0 && isPlaying && (inDatabase || OnlineAccessVerifier.check(context))) { Intent activityIntent = new Intent("com.geecko.QuickLyric.getLyrics").putExtra("TAGS", new String[] { artist, track }); Intent wearableIntent = new Intent("com.geecko.QuickLyric.SEND_TO_WEARABLE").putExtra("artist", artist) .putExtra("track", track); PendingIntent openAppPending = PendingIntent.getActivity(context, 0, activityIntent, PendingIntent.FLAG_CANCEL_CURRENT); PendingIntent wearablePending = PendingIntent.getBroadcast(context, 8, wearableIntent, PendingIntent.FLAG_CANCEL_CURRENT); NotificationCompat.Action wearableAction = new NotificationCompat.Action.Builder(R.drawable.ic_watch, context.getString(R.string.wearable_prompt), wearablePending).build(); NotificationCompat.Builder notifBuilder = new NotificationCompat.Builder(context); NotificationCompat.Builder wearableNotifBuilder = new NotificationCompat.Builder(context); if ("0".equals(sharedPref.getString("pref_theme", "0"))) notifBuilder.setColor(context.getResources().getColor(R.color.primary)); notifBuilder.setSmallIcon(R.drawable.ic_notif).setContentTitle(context.getString(R.string.app_name)) .setContentText(String.format("%s - %s", artist, track)).setContentIntent(openAppPending) .setVisibility(-1) // Notification.VISIBILITY_SECRET .setGroup("Lyrics_Notification").setGroupSummary(true); wearableNotifBuilder.setSmallIcon(R.drawable.ic_notif) .setContentTitle(context.getString(R.string.app_name)) .setContentText(String.format("%s - %s", artist, track)).setContentIntent(openAppPending) .setVisibility(-1) // Notification.VISIBILITY_SECRET .setGroup("Lyrics_Notification").setOngoing(false).setGroupSummary(false) .extend(new NotificationCompat.WearableExtender().addAction(wearableAction)); if (notificationPref == 2) { notifBuilder.setOngoing(true).setPriority(-2); // Notification.PRIORITY_MIN } else notifBuilder.setPriority(-1); // Notification.PRIORITY_LOW Notification notif = notifBuilder.build(); Notification wearableNotif = wearableNotifBuilder.build(); if (notificationPref == 2) notif.flags |= Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT; else notif.flags |= Notification.FLAG_AUTO_CANCEL; NotificationManagerCompat.from(context).notify(0, notif); try { context.getPackageManager().getPackageInfo("com.google.android.wearable.app", PackageManager.GET_META_DATA); NotificationManagerCompat.from(context).notify(8, wearableNotif); } catch (PackageManager.NameNotFoundException ignored) { } } else if (track.equals(current.getString("track", ""))) NotificationManagerCompat.from(context).cancel(0); }
From source file:com.vuze.android.remote.fragment.OpenOptionsTagsFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { if (AndroidUtils.DEBUG) { Log.d(TAG, "onCreateview " + this); }/*from w w w . j ava 2 s .co m*/ FragmentActivity activity = getActivity(); Intent intent = activity.getIntent(); final Bundle extras = intent.getExtras(); if (extras == null) { Log.e(TAG, "No extras!"); } else { String remoteProfileID = extras.getString(SessionInfoManager.BUNDLE_KEY); if (remoteProfileID != null) { sessionInfo = SessionInfoManager.getSessionInfo(remoteProfileID, activity); } torrentID = extras.getLong("TorrentID"); } final Map<?, ?> torrent = sessionInfo.getTorrent(torrentID); if (torrent == null) { Log.e(TAG, "No torrent!"); // In theory TorrentOpenOptionsActivity handled this NPE already return null; } if (activity instanceof TorrentOpenOptionsActivity) { ourActivity = (TorrentOpenOptionsActivity) activity; } View topView = inflater.inflate(R.layout.frag_torrent_tags, container, false); tvTags = (TextView) topView.findViewById(R.id.openoptions_tags); Button btnNew = (Button) topView.findViewById(R.id.torrent_tags_new); if (btnNew != null) { btnNew.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { AlertDialog.Builder builder = AndroidUtilsUI.createTextBoxDialog(getContext(), R.string.create_new_tag, R.string.newtag_name, new AndroidUtilsUI.OnTextBoxDialogClick() { @Override public void onClick(DialogInterface dialog, int which, EditText editText) { final String newName = editText.getText().toString(); spanTags.addTagNames(Collections.singletonList(newName)); ourActivity.flipTagState(null, newName); updateTags(); sessionInfo.executeRpc(new SessionInfo.RpcExecuter() { @Override public void executeRpc(TransmissionRPC rpc) { rpc.addTagToTorrents(TAG, new long[] { torrentID }, new Object[] { newName }); } }); } }); builder.create().show(); } }); } if (!tagLookupCalled) { tagLookupCalled = true; sessionInfo.executeRpc(new SessionInfo.RpcExecuter() { @Override public void executeRpc(final TransmissionRPC rpc) { Map<String, Object> map = new HashMap<>(); map.put("ids", new Object[] { torrent.get("hashString") }); rpc.simpleRpcCall("tags-lookup-start", map, new ReplyMapReceivedListener() { @Override public void rpcSuccess(String id, Map<?, ?> optionalMap) { if (ourActivity.isFinishing()) { return; } if (OpenOptionsTagsFragment.this.isRemoving()) { if (AndroidUtils.DEBUG) { Log.e(TAG, "isRemoving"); } return; } Object tagSearchID = optionalMap.get("id"); final Map<String, Object> mapResultsRequest = new HashMap<>(); mapResultsRequest.put("id", tagSearchID); if (tagSearchID != null) { rpc.simpleRpcCall("tags-lookup-get-results", mapResultsRequest, new ReplyMapReceivedListener() { @Override public void rpcSuccess(String id, Map<?, ?> optionalMap) { if (ourActivity.isFinishing()) { return; } if (OpenOptionsTagsFragment.this.isRemoving()) { if (AndroidUtils.DEBUG) { Log.e(TAG, "isRemoving"); } return; } if (AndroidUtils.DEBUG) { Log.d(TAG, "tag results: " + optionalMap); } boolean complete = MapUtils.getMapBoolean(optionalMap, "complete", true); if (!complete) { try { Thread.sleep(1500); } catch (InterruptedException ignored) { } if (ourActivity.isFinishing()) { return; } rpc.simpleRpcCall("tags-lookup-get-results", mapResultsRequest, this); } updateSuggestedTags(optionalMap); } @Override public void rpcFailure(String id, String message) { } @Override public void rpcError(String id, Exception e) { } }); } } @Override public void rpcFailure(String id, String message) { } @Override public void rpcError(String id, Exception e) { } }); } }); } return topView; }
From source file:com.andryr.musicplayer.MainActivity.java
private Artist getArtistFromBundle(Bundle bundle) { long id = bundle.getLong(ARTIST_ARTIST_ID); String name = bundle.getString(ARTIST_ARTIST_NAME); int albumCount = bundle.getInt(ARTIST_ALBUM_COUNT); int trackCount = bundle.getInt(ARTIST_TRACK_COUNT); return new Artist(id, name, albumCount, trackCount); }
From source file:com.todoroo.astrid.repeats.RepeatControlSet.java
@Nullable @Override/*from w w w.ja v a2s .c o m*/ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = super.onCreateView(inflater, container, savedInstanceState); if (savedInstanceState != null) { recurrence = savedInstanceState.getString(EXTRA_RECURRENCE); repeatUntilValue = savedInstanceState.getLong(EXTRA_REPEAT_UNTIL); repeatAfterCompletion = savedInstanceState.getBoolean(EXTRA_REPEAT_AFTER_COMPLETION); } dialogView = inflater.inflate(R.layout.control_set_repeat, null); value = (Button) dialogView.findViewById(R.id.repeatValue); Spinner interval = (Spinner) dialogView.findViewById(R.id.repeatInterval); ArrayAdapter<String> intervalAdapter = new ArrayAdapter<>(context, android.R.layout.simple_spinner_item, getResources().getStringArray(R.array.repeat_interval)); intervalAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); interval.setAdapter(intervalAdapter); Spinner type = (Spinner) dialogView.findViewById(R.id.repeatType); ArrayAdapter<String> typeAdapter = new ArrayAdapter<>(context, android.R.layout.simple_spinner_item, getResources().getStringArray(R.array.repeat_type)); typeAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); type.setAdapter(typeAdapter); type.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { repeatAfterCompletion = position == TYPE_COMPLETION_DATE; } @Override public void onNothingSelected(AdapterView<?> parent) { } }); daysOfWeekContainer = (LinearLayout) dialogView.findViewById(R.id.repeatDayOfWeekContainer); repeatUntil = (Spinner) dialogView.findViewById(R.id.repeat_until); repeatUntilAdapter = new ArrayAdapter<>(context, android.R.layout.simple_spinner_item, repeatUntilOptions); repeatUntilAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); repeatUntil.setAdapter(repeatUntilAdapter); // set up days of week DateFormatSymbols dfs = new DateFormatSymbols(); Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.DAY_OF_WEEK, calendar.getFirstDayOfWeek()); CompoundButton[] daysOfWeek = new CompoundButton[7]; for (int i = 0; i < 7; i++) { final int index = i; CheckBox checkBox = (CheckBox) daysOfWeekContainer.getChildAt(i); checkBox.setOnCheckedChangeListener( (buttonView, isChecked1) -> RepeatControlSet.this.isChecked[index] = isChecked1); int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK); checkBox.setText(dfs.getShortWeekdays()[dayOfWeek].substring(0, 1)); daysOfWeek[i] = checkBox; weekdays[i] = Weekday.values()[dayOfWeek - 1]; calendar.add(Calendar.DATE, 1); } // set up listeners value.setOnClickListener(v -> repeatValueClick()); setRepeatValue(1); interval.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parentView, View view, int position, long id) { daysOfWeekContainer.setVisibility(position == INTERVAL_WEEKS ? View.VISIBLE : View.GONE); intervalValue = position; } @Override public void onNothingSelected(AdapterView<?> arg0) { // } }); setRepeatUntilValue(repeatUntilValue); repeatUntil.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) { if (repeatUntilOptions.size() == 2) { if (i == 0) { setRepeatUntilValue(0); } else { repeatUntilClick(); } } else { if (i == 1) { setRepeatUntilValue(0); } else if (i == 2) { repeatUntilClick(); } } } @Override public void onNothingSelected(AdapterView<?> adapterView) { // } }); daysOfWeekContainer.setVisibility(View.GONE); type.setSelection(repeatAfterCompletion ? TYPE_COMPLETION_DATE : TYPE_DUE_DATE); doRepeat = !Strings.isNullOrEmpty(recurrence); if (doRepeat) { // read recurrence rule try { RRule rrule = new RRule(recurrence); setRepeatValue(rrule.getInterval()); for (WeekdayNum day : rrule.getByDay()) { for (int i = 0; i < 7; i++) { if (weekdays[i].equals(day.wday)) { daysOfWeek[i].setChecked(true); } } } switch (rrule.getFreq()) { case DAILY: intervalValue = INTERVAL_DAYS; break; case WEEKLY: intervalValue = INTERVAL_WEEKS; break; case MONTHLY: intervalValue = INTERVAL_MONTHS; break; case HOURLY: intervalValue = INTERVAL_HOURS; break; case MINUTELY: intervalValue = INTERVAL_MINUTES; break; case YEARLY: intervalValue = INTERVAL_YEARS; break; default: Timber.e(new Exception("Unhandled rrule frequency: " + recurrence), "repeat-unhandled-rule"); } interval.setSelection(intervalValue); } catch (Exception e) { // invalid RRULE recurrence = ""; //$NON-NLS-1$ Timber.e(e, e.getMessage()); } } refreshDisplayView(); return view; }
From source file:com.andryr.musicplayer.MainActivity.java
private Album getAlbumFromBundle(Bundle bundle) { long id = bundle.getLong(ALBUM_ID); String title = bundle.getString(ALBUM_NAME); String artist = bundle.getString(ALBUM_ARTIST); int year = bundle.getInt(ALBUM_YEAR); int trackCount = bundle.getInt(ALBUM_TRACK_COUNT); return new Album(id, title, artist, year, trackCount); }
From source file:com.andryr.musicplayer.MainActivity.java
private Song getSongFromBundle(Bundle bundle) { long id = bundle.getLong(SONG_ID); String title = bundle.getString(SONG_TITLE); String artist = bundle.getString(SONG_ARTIST); String album = bundle.getString(SONG_ALBUM); long albumId = bundle.getLong(SONG_ALBUM_ID); int trackNumber = bundle.getInt(SONG_TRACK_NUMBER); long duration = bundle.getLong(SONG_DURATION); return new Song(id, title, artist, album, albumId, trackNumber, duration); }