List of usage examples for android.os Bundle containsKey
public boolean containsKey(String key)
From source file:org.quantumbadger.redreader.activities.PostSubmitActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { PrefsUtility.applyTheme(this); super.onCreate(savedInstanceState); final LinearLayout layout = (LinearLayout) getLayoutInflater().inflate(R.layout.post_submit); typeSpinner = (Spinner) layout.findViewById(R.id.post_submit_type); usernameSpinner = (Spinner) layout.findViewById(R.id.post_submit_username); subredditEdit = (EditText) layout.findViewById(R.id.post_submit_subreddit); titleEdit = (EditText) layout.findViewById(R.id.post_submit_title); textEdit = (EditText) layout.findViewById(R.id.post_submit_body); final Intent intent = getIntent(); if (intent != null) { if (intent.hasExtra("subreddit")) { final String subreddit = intent.getStringExtra("subreddit"); if (subreddit != null && subreddit.length() > 0 && !subreddit.matches("/?(r/)?all/?") && subreddit.matches("/?(r/)?\\w+/?")) { subredditEdit.setText(subreddit); }//from www .ja v a 2 s .co m } else if (intent.getAction().equalsIgnoreCase(Intent.ACTION_SEND) && intent.hasExtra(Intent.EXTRA_TEXT)) { final String url = intent.getStringExtra(Intent.EXTRA_TEXT); textEdit.setText(url); } } else if (savedInstanceState != null && savedInstanceState.containsKey("post_title")) { titleEdit.setText(savedInstanceState.getString("post_title")); textEdit.setText(savedInstanceState.getString("post_body")); subredditEdit.setText(savedInstanceState.getString("subreddit")); typeSpinner.setSelection(savedInstanceState.getInt("post_type")); } final ArrayList<RedditAccount> accounts = RedditAccountManager.getInstance(this).getAccounts(); final ArrayList<String> usernames = new ArrayList<String>(); for (RedditAccount account : accounts) { if (!account.isAnonymous()) { usernames.add(account.username); } } if (usernames.size() == 0) { General.quickToast(this, R.string.error_toast_notloggedin); finish(); } usernameSpinner.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, usernames)); typeSpinner.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, postTypes)); // TODO remove the duplicate code here setHint(); typeSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { setHint(); } public void onNothingSelected(AdapterView<?> parent) { } }); final ScrollView sv = new ScrollView(this); sv.addView(layout); setContentView(sv); }
From source file:com.gimranov.zandy.app.data.Item.java
/** * Makes ArrayList<Bundle> from the present item. This was moved from * ItemDataActivity, but it's most likely to be used by such display * activities//from w ww . j a v a 2 s . c o m */ public ArrayList<Bundle> toBundleArray(Database db) { JSONObject itemContent = this.content; /* * Here we walk through the data and make Bundles to send to the * ArrayAdapter. There should be no real risk of JSON exceptions, since * the JSON was checked when initialized in the Item object. * * Each Bundle has two keys: "label" and "content" */ JSONArray fields = itemContent.names(); ArrayList<Bundle> rows = new ArrayList<Bundle>(); Bundle b; try { JSONArray values = itemContent.toJSONArray(fields); for (int i = 0; i < itemContent.length(); i++) { b = new Bundle(); /* Special handling for some types */ if (fields.getString(i).equals("tags")) { // We display the tags semicolon-delimited StringBuilder sb = new StringBuilder(); try { JSONArray tagArray = values.getJSONArray(i); for (int j = 0; j < tagArray.length(); j++) { sb.append(tagArray.getJSONObject(j).getString("tag")); if (j < tagArray.length() - 1) sb.append("; "); } b.putString("content", sb.toString()); } catch (JSONException e) { // Fall back to empty Log.e(TAG, "Exception parsing tags, with input: " + values.getString(i), e); b.putString("content", ""); } } else if (fields.getString(i).equals("notes")) { // TODO handle notes continue; } else if (fields.getString(i).equals("creators")) { /* * Creators should be labeled with role and listed nicely * This logic isn't as good as it could be. */ JSONArray creatorArray = values.getJSONArray(i); JSONObject creator; StringBuilder sb = new StringBuilder(); for (int j = 0; j < creatorArray.length(); j++) { creator = creatorArray.getJSONObject(j); if (creator.getString("creatorType").equals("author")) { if (creator.has("name")) sb.append(creator.getString("name")); else sb.append(creator.getString("firstName") + " " + creator.getString("lastName")); } else { if (creator.has("name")) sb.append(creator.getString("name")); else sb.append(creator.getString("firstName") + " " + creator.getString("lastName") + " (" + Item.localizedStringForString(creator.getString("creatorType")) + ")"); } if (j < creatorArray.length() - 1) sb.append(", "); } b.putString("content", sb.toString()); } else if (fields.getString(i).equals("itemType")) { // We want to show the localized or human-readable type b.putString("content", Item.localizedStringForString(values.getString(i))); } else { // All other data is treated as just text b.putString("content", values.getString(i)); } b.putString("label", fields.getString(i)); b.putString("itemKey", getKey()); rows.add(b); } b = new Bundle(); int notes = 0; int atts = 0; ArrayList<Attachment> attachments = Attachment.forItem(this, db); for (Attachment a : attachments) { if ("note".equals(a.getType())) notes++; else atts++; } b.putInt("noteCount", notes); b.putInt("attachmentCount", atts); b.putString("content", "not-empty-so-sorting-works"); b.putString("label", "children"); b.putString("itemKey", getKey()); rows.add(b); b = new Bundle(); int collectionCount = ItemCollection.getCollectionCount(this, db); b.putInt("collectionCount", collectionCount); b.putString("content", "not-empty-so-sorting-works"); b.putString("label", "collections"); b.putString("itemKey", getKey()); rows.add(b); } catch (JSONException e) { /* * We could die here, but I'd rather not, since this shouldn't be * possible. */ Log.e(TAG, "JSON parse exception making bundles!", e); } /* We'd like to put these in a certain order, so let's try! */ Collections.sort(rows, new Comparator<Bundle>() { @Override public int compare(Bundle b1, Bundle b2) { boolean mt1 = (b1.containsKey("content") && b1.getString("content").equals("")); boolean mt2 = (b2.containsKey("content") && b2.getString("content").equals("")); /* Put the empty fields at the bottom, same order */ return (Item.sortValueForLabel(b1.getString("label")) - Item.sortValueForLabel(b2.getString("label")) - (mt2 ? 300 : 0) + (mt1 ? 300 : 0)); } }); return rows; }
From source file:org.planetmono.dcuploader.ActivityUploader.java
@SuppressWarnings("unchecked") @Override/*from w w w . ja v a 2 s . c o m*/ public void onCreate(Bundle savedState) { super.onCreate(savedState); initViews(); if (formLocation) queryLocation(true); if (savedState != null) { if (savedState.containsKey("tempfile")) tempFile = new File(savedState.getString("tempfile")); if (savedState.containsKey("target")) resolveTarget(savedState.getString("target")); if (savedState.containsKey("tempfiles")) tempFiles = savedState.getStringArrayList("tempfiles"); if (savedState.containsKey("contents")) { contents = new ArrayList<Uri>(); String[] carr = savedState.getStringArray("contents"); for (String s : carr) contents.add(Uri.parse(s)); } } postfix = "from <a href=\"http://palladium.planetmono.org/dcuploader\">DCUploader</a>"; Button uploadVisit = (Button) findViewById(R.id.upload_visit); if (passThrough || target == null) uploadVisit.setEnabled(false); else uploadVisit.setEnabled(true); /* populate data by getting STREAM parameter */ Intent i = getIntent(); Bundle b = i.getExtras(); String action = i.getAction(); if (action.equals(Intent.ACTION_SEND) || action.equals(Intent.ACTION_SEND_MULTIPLE)) { called = true; if (i.hasExtra(Intent.EXTRA_STREAM)) { Object o = b.get(Intent.EXTRA_STREAM); /* quick and dirty. any better idea? */ try { contents.add((Uri) o); } catch (Exception e1) { try { contents = (ArrayList<Uri>) ((ArrayList<Uri>) o).clone(); } catch (Exception e2) { } } boolean exceeded = false; if (contents.size() > 5) { exceeded = true; do { contents.remove(5); } while (contents.size() > 5); } galleryChanged = true; updateImageButtons(); resetThumbnails(); updateGallery(); if (exceeded) Toast.makeText(this, " 5 . 5 ??? ? ?.", Toast.LENGTH_LONG).show(); } if (i.hasExtra(Intent.EXTRA_TEXT)) { ((EditText) findViewById(R.id.upload_text)).setText(b.getString(Intent.EXTRA_TEXT)); } } else if (action.equals("share")) { called = true; /* HTC web browser uses non-standard intent */ ((EditText) findViewById(R.id.upload_text)).setText(b.getString(Intent.EXTRA_TITLE)); } else if (action.equals(Intent.ACTION_VIEW)) { Uri uri = i.getData(); if (i.getCategories().contains(Intent.CATEGORY_BROWSABLE)) { passThrough = true; Pattern p = Pattern.compile("id=([\\-a-zA-Z0-9_]+)"); Matcher m = p.matcher(uri.toString()); if (m.find()) { resolveTarget(m.group(1)); } else { passThrough = false; } if (uri.getHost().equals(Application.HOST_DCMYS)) { destination = Application.DESTINATION_DCMYS; postfix = "from dc.m.dcmys.kr w/ <a href=\"http://palladium.planetmono.org/dcuploader\">DCUploader</a>"; } else if (uri.getHost().equals(Application.HOST_MOOLZO)) { destination = Application.DESTINATION_MOOLZO; postfix = "- From m.oolzo.com w/ <a href=\"http://palladium.planetmono.org/dcuploader\">DCUploader</a>"; } else if (uri.getHost().equals(Application.HOST_DCINSIDE)) { destination = Application.DESTINATION_DCINSIDE; } setDefaultImage(); } } reloadConfigurations(); }
From source file:android.support.v17.leanback.app.BrowseFragment.java
private void readArguments(Bundle args) { if (args == null) { return;/* w w w .ja va 2 s . c o m*/ } if (args.containsKey(ARG_TITLE)) { setTitle(args.getString(ARG_TITLE)); } if (args.containsKey(ARG_HEADERS_STATE)) { setHeadersState(args.getInt(ARG_HEADERS_STATE)); } }
From source file:at.tm.android.fitacity.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar);/*w w w . ja v a 2 s.c o m*/ final ActionBar ab = getSupportActionBar(); ab.setHomeAsUpIndicator(R.drawable.ic_menu); ab.setDisplayHomeAsUpEnabled(true); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mNavigationView = (NavigationView) findViewById(R.id.nav_view); if (mNavigationView != null) { mNavigationView.setNavigationItemSelectedListener(this); } AdView mAdView = (AdView) findViewById(R.id.adView); // Create an ad request. Check logcat output for the hashed device ID to // get test ads on a physical device. e.g. // "Use AdRequest.Builder.addTestDevice("ABCDEF012345") to get test ads on this device." AdRequest adRequest = new AdRequest.Builder().addTestDevice(AdRequest.DEVICE_ID_EMULATOR).build(); mAdView.loadAd(adRequest); // Setup the recycler view with it's adapter RecyclerView rv = (RecyclerView) findViewById(R.id.recyclerview); rv.setLayoutManager(new LinearLayoutManager(rv.getContext())); mEmptyRecyclerView = (TextView) findViewById(R.id.tvEmptyRecylcerView); if ((savedInstanceState != null) && (savedInstanceState.containsKey(EXERCISE_LIST_KEY)) && (savedInstanceState.containsKey(SELECTED_CATEGORY_ID_KEY)) && (savedInstanceState.containsKey(SELECTED_CATEGORY_ID_KEY))) { // Set the selected category id mSelectedCategoryId = savedInstanceState.getInt(SELECTED_CATEGORY_ID_KEY); // If there is a previous category list stored, update the menu items List<Category> previousCategoryList = savedInstanceState.getParcelableArrayList(CATEGORY_LIST_KEY); setCategoriesMenu(previousCategoryList); System.out.println("Saved exercises"); // Set the stored exercise list to the recycler view adapter mExerciseRecyclerViewAdapter = new ExerciseRecyclerViewAdapter(); if (mSelectedCategoryId == FAVORITE_CATEGORY_ID) { // Set the favorite exercises evertime the favorite category is selected getSupportLoaderManager().initLoader(FAVORITE_CATEGORY_ID, null, this); } else { // If there is a previous exercise list stored, update the exercise list adapter List<Exercise> previousExerciseList = savedInstanceState.getParcelableArrayList(EXERCISE_LIST_KEY); setExerciseData(previousExerciseList); } } else { // Set the default category id to the favorite category mSelectedCategoryId = FAVORITE_CATEGORY_ID; // Fetch the category data when no categories stored new FetchCategoryDataTask().execute(); // load the favorite exercises and put it into the recycler view adapter mExerciseRecyclerViewAdapter = new ExerciseRecyclerViewAdapter(); getSupportLoaderManager().initLoader(FAVORITE_CATEGORY_ID, null, this); } // Set the adapter to the recycler view rv.setAdapter(mExerciseRecyclerViewAdapter); }
From source file:com.dycody.android.idealnote.ListFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { if (savedInstanceState != null) { if (savedInstanceState.containsKey("listViewPosition")) { listViewPosition = savedInstanceState.getInt("listViewPosition"); listViewPositionOffset = savedInstanceState.getInt("listViewPositionOffset"); searchQuery = savedInstanceState.getString("searchQuery"); searchTags = savedInstanceState.getString("searchTags"); }//from w ww .ja v a 2 s . c o m keepActionMode = false; } View view = inflater.inflate(R.layout.fragment_list, container, false); ButterKnife.bind(this, view); return view; }
From source file:terse.a1.TerseActivity.java
@Override public void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); glSurfaceView = null; // Forget gl on new activity. requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); if (savedInstanceState != null && savedInstanceState.containsKey("TerseActivity")) { taSaveMe = savedInstanceState.getString("TerseActivity"); } else {//from w w w . j a va 2s .com taSaveMe = null; } Runnable bg = new Runnable() { @Override public void run() { resetTerp(); } }; Runnable fg = new Runnable() { @Override public void run() { Intent intent = getIntent(); Uri uri = intent.getData(); Bundle extras = intent.getExtras(); String path = uri == null ? "/" : uri.getPath(); String query = uri == null ? "" : uri.getQuery(); viewPath(path, query, extras, savedInstanceState); } }; if (terp == null) { TextView tv = new TextView(TerseActivity.this); tv.setText(Static.fmt("Building new TerseTalk VM for world <%s>...", world)); tv.setTextAppearance(this, R.style.teletype); tv.setBackgroundColor(Color.BLACK); tv.setTextColor(Color.DKGRAY); tv.setTextSize(24); setContentView(tv); setContentViewThenBgThenFg("ResetSplash", tv, bg, fg); } else { fg.run(); } }
From source file:biz.bokhorst.xprivacy.ActivityApp.java
@Override protected void onNewIntent(Intent intent) { Bundle extras = intent.getExtras(); if (extras != null && extras.containsKey(cAction) && extras.getInt(cAction) == cActionRefresh) { // Update on demand check box ImageView imgCbOnDemand = (ImageView) findViewById(R.id.imgCbOnDemand); boolean ondemand = PrivacyManager.getSettingBool(-mAppInfo.getUid(), PrivacyManager.cSettingOnDemand, false);// w ww . j a v a 2 s . com imgCbOnDemand.setImageBitmap(ondemand ? getOnDemandCheckBox() : getOffCheckBox()); // Update restriction list if (mPrivacyListAdapter != null) mPrivacyListAdapter.notifyDataSetChanged(); } else { setIntent(intent); recreate(); } }
From source file:com.openerp.services.MessageSyncService.java
/** * Perform sync./*from w ww . j ava 2 s .co m*/ * * @param context the context * @param account the account * @param extras the extras * @param authority the authority * @param provider the provider * @param syncResult the sync result */ public void performSync(Context context, Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) { Intent intent = new Intent(); Intent updateWidgetIntent = new Intent(); updateWidgetIntent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE); updateWidgetIntent.putExtra(MessageWidget.ACTION_MESSAGE_WIDGET_UPDATE, true); intent.setAction(SyncFinishReceiver.SYNC_FINISH); OEUser user = OpenERPAccountManager.getAccountDetail(context, account.name); try { MessageDB msgDb = new MessageDB(context); msgDb.setAccountUser(user); OEHelper oe = msgDb.getOEInstance(); if (oe == null) { return; } int user_id = user.getUser_id(); // Updating User Context for OE-JSON-RPC JSONObject newContext = new JSONObject(); newContext.put("default_model", "res.users"); newContext.put("default_res_id", user_id); OEArguments arguments = new OEArguments(); // Param 1 : ids arguments.addNull(); // Param 2 : domain OEDomain domain = new OEDomain(); // Data limit. PreferenceManager mPref = new PreferenceManager(context); int data_limit = mPref.getInt("sync_data_limit", 60); domain.add("create_date", ">=", OEDate.getDateBefore(data_limit)); if (!extras.containsKey("group_ids")) { // Last id JSONArray msgIds = new JSONArray(); for (OEDataRow row : msgDb.select()) { msgIds.put(row.getInt("id")); } domain.add("id", "not in", msgIds); domain.add("|"); // Argument for check partner_ids.user_id is current user domain.add("partner_ids.user_ids", "in", new JSONArray().put(user_id)); domain.add("|"); // Argument for check notification_ids.partner_ids.user_id // is // current user domain.add("notification_ids.partner_id.user_ids", "in", new JSONArray().put(user_id)); // Argument for check author id is current user domain.add("author_id.user_ids", "in", new JSONArray().put(user_id)); } else { JSONArray group_ids = new JSONArray(extras.getString("group_ids")); // Argument for group model check domain.add("model", "=", "mail.group"); // Argument for group model res id domain.add("res_id", "in", group_ids); } arguments.add(domain.getArray()); // Param 3 : message_unload_ids arguments.add(new JSONArray()); // Param 4 : thread_level arguments.add(true); // Param 5 : context arguments.add(oe.updateContext(newContext)); // Param 6 : parent_id arguments.addNull(); // Param 7 : limit arguments.add(50); List<Integer> ids = msgDb.ids(); if (oe.syncWithMethod("message_read", arguments)) { int affected_rows = oe.getAffectedRows(); List<Integer> affected_ids = oe.getAffectedIds(); boolean notification = true; ActivityManager am = (ActivityManager) context.getSystemService(ACTIVITY_SERVICE); List<ActivityManager.RunningTaskInfo> taskInfo = am.getRunningTasks(1); ComponentName componentInfo = taskInfo.get(0).topActivity; if (componentInfo.getPackageName().equalsIgnoreCase("com.openerp")) { notification = false; } if (notification && affected_rows > 0) { OENotificationHelper mNotification = new OENotificationHelper(); Intent mainActiivty = new Intent(context, MainActivity.class); mNotification.setResultIntent(mainActiivty, context); String notify_title = context.getResources().getString(R.string.messages_sync_notify_title); notify_title = String.format(notify_title, affected_rows); String notify_body = context.getResources().getString(R.string.messages_sync_notify_body); notify_body = String.format(notify_body, affected_rows); mNotification.showNotification(context, notify_title, notify_body, authority, R.drawable.ic_oe_notification); } intent.putIntegerArrayListExtra("new_ids", (ArrayList<Integer>) affected_ids); } List<Integer> updated_ids = updateOldMessages(msgDb, oe, user, ids); intent.putIntegerArrayListExtra("updated_ids", (ArrayList<Integer>) updated_ids); } catch (Exception e) { e.printStackTrace(); } if (user.getAndroidName().equals(account.name)) { context.sendBroadcast(intent); context.sendBroadcast(updateWidgetIntent); } }