List of usage examples for android.util Pair create
public static <A, B> Pair<A, B> create(A a, B b)
From source file:dev.drsoran.moloko.fragments.dialogs.RecurrencePickerDialogFragment.java
public Pair<String, Boolean> getPattern() { return Pair.create(getPatternString(), isEvery()); }
From source file:com.android.emergency.view.ViewInfoActivity.java
private ArrayList<Pair<String, Fragment>> setUpFragments() { // Return only the fragments that have at least one piece of information set: ArrayList<Pair<String, Fragment>> fragments = new ArrayList<>(2); if (PreferenceUtils.hasAtLeastOnePreferenceSet(this)) { fragments.add(Pair.create(getResources().getString(R.string.tab_title_info), ViewEmergencyInfoFragment.newInstance())); }//w w w. j a v a 2 s . c o m if (PreferenceUtils.hasAtLeastOneEmergencyContact(this)) { fragments.add(Pair.create(getResources().getString(R.string.tab_title_contacts), ViewEmergencyContactsFragment.newInstance())); } return fragments; }
From source file:org.openhab.habdroid.ui.activity.ContentController.java
/** * Restore instance state previously saved by onSaveInstanceState * To be called from the onRestoreInstanceState or onCreate callbacks of the activity * * @param state Bundle including previously saved state *//*w w w .j a va2s . c om*/ public void onRestoreInstanceState(Bundle state) { mCurrentSitemap = state.getParcelable("controllerSitemap"); if (mCurrentSitemap != null) { mSitemapFragment = (OpenHABWidgetListFragment) mFm.getFragment(state, "sitemapFragment"); if (mSitemapFragment == null) { mSitemapFragment = makeSitemapFragment(mCurrentSitemap); } } Fragment progressFragment = mFm.getFragment(state, "progressFragment"); if (progressFragment != null) { mDefaultProgressFragment = progressFragment; } ArrayList<OpenHABLinkedPage> oldStack = state.getParcelableArrayList("controllerPages"); mPageStack.clear(); for (OpenHABLinkedPage page : oldStack) { OpenHABWidgetListFragment f = (OpenHABWidgetListFragment) mFm.getFragment(state, "pageFragment-" + page.link()); mPageStack.add(Pair.create(page, f != null ? f : makePageFragment(page))); } mTemporaryPage = mFm.getFragment(state, "temporaryPage"); }
From source file:com.google.android.dialer.reverselookup.PeopleJsonParser.java
public static Pair<Integer, String> parseAddressType(String s, String s2) { if (s == null) { return Pair.create(null, null); }//from w ww . ja v a 2 s . c o m Integer n = ADDRESS_TYPE_MAP.get(s); if (n != null && n != 0) { return Pair.create(n, null); } else { return Pair.create(n, s2); } }
From source file:io.romain.passport.ui.fragments.CityListFragment.java
@Override public void onCityClicked(final View v, final City city) { Intent intent = new Intent(getContext(), CityDetailActivity.class); intent.putExtra(CityDetailActivity.EXTRA_CITY, city); ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(getActivity(), // Pair.create((View) image, getContext().getString(R.string.transition_picture)), (Pair<View, String>) Pair.create(v, getContext().getString(R.string.transition_detail_background))); getContext().startActivity(intent, options.toBundle()); }
From source file:com.nextgis.maplib.map.VectorLayer.java
public String createFromGeoJSON(JSONObject geoJSONObject) { try {//from w w w .ja v a2 s . c o m //check crs boolean isWGS84 = true; //if no crs tag - WGS84 CRS if (geoJSONObject.has(GEOJSON_CRS)) { JSONObject crsJSONObject = geoJSONObject.getJSONObject(GEOJSON_CRS); //the link is unsupported yet. if (!crsJSONObject.getString(GEOJSON_TYPE).equals(GEOJSON_NAME)) { return mContext.getString(R.string.error_crs_unsuported); } JSONObject crsPropertiesJSONObject = crsJSONObject.getJSONObject(GEOJSON_PROPERTIES); String crsName = crsPropertiesJSONObject.getString(GEOJSON_NAME); if (crsName.equals("urn:ogc:def:crs:OGC:1.3:CRS84")) { // WGS84 isWGS84 = true; } else if (crsName.equals("urn:ogc:def:crs:EPSG::3857") || crsName.equals("EPSG:3857")) { //Web Mercator isWGS84 = false; } else { return mContext.getString(R.string.error_crs_unsuported); } } //load contents to memory and reproject if needed JSONArray geoJSONFeatures = geoJSONObject.getJSONArray(GEOJSON_TYPE_FEATURES); if (0 == geoJSONFeatures.length()) { return mContext.getString(R.string.error_empty_dataset); } List<Feature> features = new ArrayList<>(); List<Pair<String, Integer>> fields = new ArrayList<>(); int geometryType = GTNone; for (int i = 0; i < geoJSONFeatures.length(); i++) { JSONObject jsonFeature = geoJSONFeatures.getJSONObject(i); //get geometry JSONObject jsonGeometry = jsonFeature.getJSONObject(GEOJSON_GEOMETRY); GeoGeometry geometry = GeoGeometry.fromJson(jsonGeometry); if (geometryType == GTNone) { geometryType = geometry.getType(); } else if (!Geo.isGeometryTypeSame(geometryType, geometry.getType())) { //skip different geometry type continue; } //reproject if needed if (isWGS84) { geometry.setCRS(CRS_WGS84); geometry.project(CRS_WEB_MERCATOR); } else { geometry.setCRS(CRS_WEB_MERCATOR); } int nId = i; if (jsonFeature.has(GEOJSON_ID)) nId = jsonFeature.getInt(GEOJSON_ID); Feature feature = new Feature(nId, fields); // ID == i feature.setGeometry(geometry); //normalize attributes JSONObject jsonAttributes = jsonFeature.getJSONObject(GEOJSON_PROPERTIES); Iterator<String> iter = jsonAttributes.keys(); while (iter.hasNext()) { String key = iter.next(); Object value = jsonAttributes.get(key); int nType = NOT_FOUND; //check type if (value instanceof Integer || value instanceof Long) { nType = FTInteger; } else if (value instanceof Double || value instanceof Float) { nType = FTReal; } else if (value instanceof Date) { nType = FTDateTime; } else if (value instanceof String) { nType = FTString; } else if (value instanceof JSONObject) { nType = NOT_FOUND; //the some list - need to check it type FTIntegerList, FTRealList, FTStringList } if (nType != NOT_FOUND) { int fieldIndex = NOT_FOUND; for (int j = 0; j < fields.size(); j++) { if (fields.get(j).first.equals(key)) { fieldIndex = j; } } if (fieldIndex == NOT_FOUND) { //add new field Pair<String, Integer> fieldKey = Pair.create(key, nType); fieldIndex = fields.size(); fields.add(fieldKey); } feature.setFieldValue(fieldIndex, value); } } features.add(feature); } String tableCreate = "CREATE TABLE IF NOT EXISTS " + mPath.getName() + " ( " + //table name is the same as the folder of the layer "_ID INTEGER PRIMARY KEY, " + "GEOM BLOB"; for (int i = 0; i < fields.size(); ++i) { Pair<String, Integer> field = fields.get(i); tableCreate += ", " + field.first + " "; switch (field.second) { case FTString: tableCreate += "TEXT"; break; case FTInteger: tableCreate += "INTEGER"; break; case FTReal: tableCreate += "REAL"; break; case FTDateTime: tableCreate += "TIMESTAMP"; break; } } tableCreate += " );"; GeoEnvelope extents = new GeoEnvelope(); for (Feature feature : features) { //update bbox extents.merge(feature.getGeometry().getEnvelope()); } //1. create table and populate with values MapContentProviderHelper map = (MapContentProviderHelper) MapBase.getInstance(); SQLiteDatabase db = map.getDatabase(true); db.execSQL(tableCreate); for (Feature feature : features) { ContentValues values = new ContentValues(); values.put("_ID", feature.getId()); try { values.put("GEOM", feature.getGeometry().toBlob()); } catch (IOException e) { e.printStackTrace(); } for (int i = 0; i < fields.size(); ++i) { if (!feature.isValuePresent(i)) continue; switch (fields.get(i).second) { case FTString: values.put(fields.get(i).first, feature.getFieldValueAsString(i)); break; case FTInteger: values.put(fields.get(i).first, (int) feature.getFieldValue(i)); break; case FTReal: values.put(fields.get(i).first, (double) feature.getFieldValue(i)); break; case FTDateTime: values.put(fields.get(i).first, feature.getFieldValueAsString(i)); break; } } db.insert(mPath.getName(), "", values); } //2. save the layer properties to config.json mGeometryType = geometryType; mExtents = extents; mIsInitialized = true; setDefaultRenderer(); save(); //3. fill the geometry and labels array mVectorCacheItems = new ArrayList<>(); for (Feature feature : features) { mVectorCacheItems.add(new VectorCacheItem(feature.getGeometry(), feature.getId())); } if (null != mParent) { //notify the load is over LayerGroup layerGroup = (LayerGroup) mParent; layerGroup.onLayerChanged(this); } return ""; } catch (JSONException e) { e.printStackTrace(); return e.getLocalizedMessage(); } }
From source file:us.phyxsi.gameshelf.ui.FeedAdapter.java
@NonNull private BoardgameHolder createBoardgameHolder(ViewGroup parent) { final BoardgameHolder holder = new BoardgameHolder( layoutInflater.inflate(R.layout.boardgame_item, parent, false)); holder.image.setOnClickListener(new View.OnClickListener() { @Override/*from ww w . ja v a2 s. com*/ public void onClick(View view) { holder.itemView .setTransitionName(holder.itemView.getResources().getString(R.string.transition_game)); holder.itemView.setBackgroundColor(ContextCompat.getColor(host, R.color.background_light)); Intent intent = new Intent(); intent.setClass(host, BoardgameDetails.class); intent.putExtra(BoardgameDetails.EXTRA_BOARDGAME, (Boardgame) getItem(holder.getAdapterPosition())); setGridItemContentTransitions(holder.itemView); ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(host, Pair.create(view, host.getString(R.string.transition_game)), Pair.create(view, host.getString(R.string.transition_game_background))); host.startActivity(intent, options.toBundle()); } }); // show deletion confirmation holder.image.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { new AlertDialog.Builder(context).setTitle(host.getString(R.string.remove_game_title)) .setMessage(host.getString(R.string.remove_game_message)) .setPositiveButton(host.getString(R.string.dialog_remove), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { BoardgameDbHelper bgHelper = new BoardgameDbHelper(context); bgHelper.delete((Boardgame) getItem(holder.getAdapterPosition())); items.remove(getItem(holder.getAdapterPosition())); notifyDataSetChanged(); } }) .setNegativeButton(host.getString(R.string.dialog_cancel), null).show(); return false; } }); return holder; }
From source file:com.hannesdorfmann.FeedAdapter.java
private void bindDesignerNewsStory(final Story story, final DesignerNewsStoryHolder holder) { holder.title.setText(story.title);//from w ww . ja v a 2s . co m holder.itemView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { CustomTabActivityHelper.openCustomTab(host, DesignerNewsStory.getCustomTabIntent(host, story, null).build(), Uri.parse(story.url)); } }); holder.comments.setText(String.valueOf(story.comment_count)); holder.comments.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View commentsView) { final Intent intent = new Intent(); intent.setClass(host, DesignerNewsStory.class); intent.putExtra(DesignerNewsStory.EXTRA_STORY, story); final ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(host, Pair.create(holder.itemView, host.getString(R.string.transition_story_title_background)), Pair.create(holder.itemView, host.getString(R.string.transition_story_background))); host.startActivity(intent, options.toBundle()); } }); if (pocketIsInstalled) { holder.pocket.setImageAlpha(178); // grumble... no xml setter, grumble... holder.pocket.setOnClickListener(new View.OnClickListener() { @Override public void onClick(final View view) { final ImageButton pocketButton = (ImageButton) view; // actually add to pocket PocketUtils.addToPocket(host, story.url); // setup for anim holder.itemView.setHasTransientState(true); ((ViewGroup) pocketButton.getParent().getParent()).setClipChildren(false); final int initialLeft = pocketButton.getLeft(); final int initialTop = pocketButton.getTop(); final int translatedLeft = (holder.itemView.getWidth() - pocketButton.getWidth()) / 2; final int translatedTop = initialTop - ((holder.itemView.getHeight() - pocketButton.getHeight()) / 2); final ArcMotion arc = new ArcMotion(); // animate the title & pocket icon up, scale the pocket icon up PropertyValuesHolder pvhTitleUp = PropertyValuesHolder.ofFloat(View.TRANSLATION_Y, -(holder.itemView.getHeight() / 5)); PropertyValuesHolder pvhTitleFade = PropertyValuesHolder.ofFloat(View.ALPHA, 0.54f); Animator titleMoveFadeOut = ObjectAnimator.ofPropertyValuesHolder(holder.title, pvhTitleUp, pvhTitleFade); Animator pocketMoveUp = ObjectAnimator.ofFloat(pocketButton, View.TRANSLATION_X, View.TRANSLATION_Y, arc.getPath(initialLeft, initialTop, translatedLeft, translatedTop)); PropertyValuesHolder pvhPocketScaleUpX = PropertyValuesHolder.ofFloat(View.SCALE_X, 3f); PropertyValuesHolder pvhPocketScaleUpY = PropertyValuesHolder.ofFloat(View.SCALE_Y, 3f); Animator pocketScaleUp = ObjectAnimator.ofPropertyValuesHolder(pocketButton, pvhPocketScaleUpX, pvhPocketScaleUpY); ObjectAnimator pocketFadeUp = ObjectAnimator.ofInt(pocketButton, ViewUtils.IMAGE_ALPHA, 255); AnimatorSet up = new AnimatorSet(); up.playTogether(titleMoveFadeOut, pocketMoveUp, pocketScaleUp, pocketFadeUp); up.setDuration(300); up.setInterpolator( AnimationUtils.loadInterpolator(host, android.R.interpolator.fast_out_slow_in)); // animate everything back into place PropertyValuesHolder pvhTitleMoveUp = PropertyValuesHolder.ofFloat(View.TRANSLATION_Y, 0f); PropertyValuesHolder pvhTitleFadeUp = PropertyValuesHolder.ofFloat(View.ALPHA, 1f); Animator titleMoveFadeIn = ObjectAnimator.ofPropertyValuesHolder(holder.title, pvhTitleMoveUp, pvhTitleFadeUp); Animator pocketMoveDown = ObjectAnimator.ofFloat(pocketButton, View.TRANSLATION_X, View.TRANSLATION_Y, arc.getPath(translatedLeft, translatedTop, 0, 0)); PropertyValuesHolder pvhPocketScaleDownX = PropertyValuesHolder.ofFloat(View.SCALE_X, 1f); PropertyValuesHolder pvhPocketScaleDownY = PropertyValuesHolder.ofFloat(View.SCALE_Y, 1f); Animator pvhPocketScaleDown = ObjectAnimator.ofPropertyValuesHolder(pocketButton, pvhPocketScaleDownX, pvhPocketScaleDownY); ObjectAnimator pocketFadeDown = ObjectAnimator.ofInt(pocketButton, ViewUtils.IMAGE_ALPHA, 138); AnimatorSet down = new AnimatorSet(); down.playTogether(titleMoveFadeIn, pocketMoveDown, pvhPocketScaleDown, pocketFadeDown); down.setDuration(300); down.setInterpolator( AnimationUtils.loadInterpolator(host, android.R.interpolator.fast_out_slow_in)); down.setStartDelay(500); // play it AnimatorSet upDown = new AnimatorSet(); upDown.playSequentially(up, down); // clean up upDown.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { ((ViewGroup) pocketButton.getParent().getParent()).setClipChildren(true); holder.itemView.setHasTransientState(false); } }); upDown.start(); } }); } }
From source file:dev.drsoran.moloko.sync.SyncAdapter.java
private Pair<String, String> getCredentials(Account account) { final AccountManager accountManager = AccountManager.get(context); final String apiKey = accountManager.getUserData(account, Constants.FEAT_API_KEY); final String sharedSecret = accountManager.getUserData(account, Constants.FEAT_SHARED_SECRET); return Pair.create(apiKey, sharedSecret); }
From source file:com.adkdevelopment.e_contact.ui.TasksFragment.java
@Override public void onItemClicked(TaskRealm item, View view) { Intent intent = new Intent(getContext(), DetailActivity.class); intent.putExtra(TaskRealm.TASK_EXTRA, item); intent.putExtra(TaskRealm.TASK_EXTRA_TITLE, String.valueOf(item.getId())); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { Pair pair = Pair.create(view.findViewById(R.id.task_item_card), view.findViewById(R.id.task_item_card).getTransitionName()); Bundle bundle = ActivityOptions.makeSceneTransitionAnimation(getActivity(), pair).toBundle(); startActivity(intent, bundle);// www. j a va 2s .c om } else { startActivity(intent); } }