List of usage examples for android.text Spannable length
int length();
From source file:com.cesarsk.say_it.ui.fragments.SettingsFragment.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preferences); // Use an activity context to get the rewarded video instance. mRewardedVideoAd = MobileAds.getRewardedVideoAdInstance(getActivity()); mRewardedVideoAd.setRewardedVideoAdListener(this); loadRewardedVideoAd();//from w ww. jav a2 s .co m PackageInfo pInfo = null; try { pInfo = getActivity().getPackageManager().getPackageInfo(getActivity().getPackageName(), 0); } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } String version = pInfo.versionName; final Preference app_version = getPreferenceManager().findPreference("app_version"); app_version.setSummary("Version: " + version + " (Click for Privacy Policy)"); final Context context = getActivity(); if (context instanceof Callback) { mCallback = (Callback) context; } else { throw new IllegalStateException("Owner must implement URLCallback interface"); } // add listeners for non-default actions Preference preference = findPreference(KEY_1); preference.setOnPreferenceClickListener(this); Preference open_source_licenses = findPreference(KEY_2); open_source_licenses.setOnPreferenceClickListener(this); Preference rate_us = getPreferenceManager().findPreference("rate_us"); rate_us.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { rateUs(getActivity()); return false; } }); Preference contact_us = getPreferenceManager().findPreference("contact_us"); contact_us.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { shareToMail(emails, "[CONTACT US - SAY IT!]", getActivity()); return false; } }); Preference bug_report = getPreferenceManager().findPreference("bug_report"); bug_report.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { shareToMail(emails, "[CONTACT US - SAY IT!]", getActivity()); return false; } }); Preference donate_ad = getPreferenceManager().findPreference("donation_ad"); donate_ad.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { //Launch AD if (mRewardedVideoAd.isLoaded()) { mRewardedVideoAd.show(); } return false; } }); final Preference about_us = getPreferenceManager().findPreference("about_us"); about_us.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { Utility.openURL(getActivity(), "https://lucacesaranoblog.wordpress.com/2017/07/18/about-us/"); return false; } }); final Preference eula = getPreferenceManager().findPreference("eula"); eula.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { Utility.openURL(getActivity(), "https://lucacesaranoblog.wordpress.com/2017/04/28/say-it-eula-agreement/"); return false; } }); /*final Preference github = getPreferenceManager().findPreference("github"); github.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { Utility.openURL(getActivity(), "https://github.com/Cesarsk/Say_it"); return false; } });*/ final Preference other_apps = getPreferenceManager().findPreference("other_apps"); other_apps.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { Utility.openURL(getActivity(), "https://play.google.com/store/apps/developer?id=Cesarsk+Dev+Team"); return false; } }); final Preference voice_settings = getPreferenceManager().findPreference("tts_settings"); voice_settings.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { Intent intent = new Intent(); intent.setAction("com.android.settings.TTS_SETTINGS"); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(intent); return false; } }); // compute your public key and store it in base64EncodedPublicKey mHelper = new IabHelper(getActivity(), LCSecurity.base64EncodedPublicKey); mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() { public void onIabSetupFinished(IabResult result) { if (!result.isSuccess()) { // Oh no, there was a problem. if (MainActivity.isLoggingEnabled) Log.d("Say It!", "Problem setting up In-app Billing: " + result); } // Hooray, IAB is fully set up! if (MainActivity.isLoggingEnabled) Log.d("Say It!", "Hooray. IAB is fully set up!" + result); } }); mIabPurchaseFinishedListener = new IabHelper.OnIabPurchaseFinishedListener() { @Override public void onIabPurchaseFinished(IabResult result, Purchase info) { if (result.isFailure()) { Toast.makeText(getActivity(), "Purchase Failed! Perhaps have you already purchased the item?", Toast.LENGTH_SHORT).show(); } else if (info.getSku().equals(PlayActivity.no_ads_in_app)) { UtilitySharedPrefs.loadAdsStatus(getActivity()); UtilitySharedPrefs.savePrefs(getActivity(), true, MainActivity.NO_ADS_STATUS_KEY); } } }; mQueryFinishedListener = new IabHelper.QueryInventoryFinishedListener() { public void onQueryInventoryFinished(IabResult result, Inventory inventory) { if (result.isFailure()) { if (MainActivity.isLoggingEnabled) Toast.makeText(getActivity(), "Query Failed!", Toast.LENGTH_SHORT).show(); return; } //Open Purchase Dialog try { mHelper.flagEndAsync(); mHelper.launchPurchaseFlow(getActivity(), PlayActivity.no_ads_in_app, 64000, mIabPurchaseFinishedListener); } catch (IabHelper.IabAsyncInProgressException e) { e.printStackTrace(); } } }; final Preference remove_ads = getPreferenceManager().findPreference("remove_ads"); if (MainActivity.NO_ADS) { remove_ads.setEnabled(false); remove_ads.setSummary("Thank you for supporting us ?"); } else { remove_ads.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { //helper to remove ads List<String> additionalSkuList = new ArrayList<>(); additionalSkuList.add(PlayActivity.no_ads_in_app); try { mHelper.flagEndAsync(); mHelper.queryInventoryAsync(true, additionalSkuList, mQueryFinishedListener); } catch (IabHelper.IabAsyncInProgressException e) { e.printStackTrace(); } return false; } }); } final Preference reset_tutorial = getPreferenceManager().findPreference("reset_showcase"); reset_tutorial.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { Random rand = new Random(); int randomNum = rand.nextInt((10000 - 10) + 1) + 10; //(max - min) + 1 + min MainActivity.id_showcase_playactivity = "" + randomNum; Toast.makeText(getActivity(), "Tutorial has been reset", Toast.LENGTH_SHORT).show(); //MainActivity.id_showcase_fragments = "" + randomNum2; //int randomNum2 = rand.nextInt((10000 - 10) + 1) + 10; //(max - min) + 1 + min //These two statements are commented because MaterialShowCase often crashes on fragments and while pressing the back button. return false; } }); //setting an own Alert Dialog's title color final Spannable title = new SpannableString("Delete Recordings"); title.setSpan(new ForegroundColorSpan(Color.DKGRAY), 0, title.length(), 0); final Spannable message = new SpannableString("Are you sure you want to delete all recordings?"); message.setSpan(new ForegroundColorSpan(Color.GRAY), 0, message.length(), 0); final Preference delete_recordings = getPreferenceManager().findPreference("delete_recordings"); delete_recordings.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { new AlertDialog.Builder(getActivity()).setTitle(title).setMessage(message) .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { Utility.delete_recordings(getActivity()); Toast.makeText(getActivity(), "Recordings deleted!", Toast.LENGTH_SHORT).show(); } }).setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { //do nothing } }).show(); return true; } }); final ListPreference button_vibration = (ListPreference) getPreferenceManager() .findPreference("button_vibration"); button_vibration.setSummary(button_vibration.getEntry()); final Spannable default_vibration_settings_title = new SpannableString("Vibration Settings"); default_vibration_settings_title.setSpan(new ForegroundColorSpan(Color.DKGRAY), 0, default_vibration_settings_title.length(), 0); button_vibration.setDialogTitle(default_vibration_settings_title); button_vibration.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { String new_value = newValue.toString(); index_default_vibration = button_vibration.findIndexOfValue(new_value); CharSequence[] entries = button_vibration.getEntries(); UtilitySharedPrefs.savePrefs(getActivity(), new_value, MainActivity.DEFAULT_VIBRATION_KEY); button_vibration .setSummary(button_vibration.getEntries()[button_vibration.findIndexOfValue(new_value)]); Toast.makeText(getActivity(), String.valueOf(entries[index_default_vibration]), Toast.LENGTH_SHORT) .show(); UtilitySharedPrefs.loadSettingsPrefs(context); return true; } }); final ListPreference default_accent = (ListPreference) getPreferenceManager() .findPreference("default_accent"); default_accent.setSummary(default_accent.getEntry()); final Spannable default_accent_title = new SpannableString("Default Accent"); default_accent_title.setSpan(new ForegroundColorSpan(Color.DKGRAY), 0, default_accent_title.length(), 0); default_accent.setDialogTitle(default_accent_title); default_accent.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { String new_value = newValue.toString(); index_default_accent = default_accent.findIndexOfValue(new_value); CharSequence[] entries = default_accent.getEntries(); UtilitySharedPrefs.savePrefs(getActivity(), new_value, MainActivity.DEFAULT_ACCENT_KEY); default_accent.setSummary(default_accent.getEntries()[default_accent.findIndexOfValue(new_value)]); //Toast.makeText(getActivity(), String.valueOf(entries[index_default_accent]), Toast.LENGTH_SHORT).show(); UtilitySharedPrefs.loadSettingsPrefs(context); return true; } }); final ListPreference theme_selector = (ListPreference) getPreferenceManager() .findPreference("theme_selector"); final Spannable theme_selector_title = new SpannableString("Theme"); theme_selector_title.setSpan(new ForegroundColorSpan(Color.DKGRAY), 0, theme_selector_title.length(), 0); theme_selector.setDialogTitle(theme_selector_title); theme_selector.setSummary(theme_selector.getEntry()); theme_selector.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { String new_value = newValue.toString(); index_default_theme = theme_selector.findIndexOfValue(new_value); CharSequence[] entries = theme_selector.getEntries(); UtilitySharedPrefs.savePrefs(getActivity(), new_value, MainActivity.DEFAULT_THEME_KEY); theme_selector.setSummary(theme_selector.getEntries()[theme_selector.findIndexOfValue(new_value)]); //Toast.makeText(getActivity(), String.valueOf(entries[index_default_theme]), Toast.LENGTH_SHORT).show(); UtilitySharedPrefs.loadSettingsPrefs(context); Toast.makeText(getActivity(), "Done! Reboot to see changes.", Toast.LENGTH_SHORT).show(); return true; } }); Preference acknowledgements = getPreferenceManager().findPreference("acknowledgements"); acknowledgements.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { final Intent preference_intent = new Intent(getActivity(), FileTextActivity.class); Bundle args = new Bundle(); args.putString(FileTextActivity.PREFERENCE, "acknowledgements"); preference_intent.putExtras(args); startActivity(preference_intent, ActivityOptions.makeSceneTransitionAnimation(getActivity()).toBundle()); return false; } }); app_version.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { Utility.openURL(getActivity(), "https://lucacesaranoblog.wordpress.com/2017/04/18/privacy-policy/"); return false; } }); }
From source file:net.idlesoft.android.apps.github.activities.Repository.java
public void loadRepoInfo() { try {// w w w. j a va 2s .com // TextView title = // (TextView)findViewById(R.id.tv_top_bar_title); // title.setText(m_jsonData.getString("name")); final TextView repo_name = (TextView) findViewById(R.id.tv_repository_info_name); repo_name.setText(mJson.getString("name")); repo_name.requestFocus(); final TextView repo_desc = (TextView) findViewById(R.id.tv_repository_info_description); repo_desc.setText(mJson.getString("description")); final TextView repo_owner = (TextView) findViewById(R.id.tv_repository_info_owner); repo_owner.setText(mJson.getString("owner")); final TextView repo_watcher_count = (TextView) findViewById(R.id.tv_repository_info_watchers); if (mJson.getInt("watchers") == 1) { repo_watcher_count.setText(mJson.getInt("watchers") + " watcher"); } else { repo_watcher_count.setText(mJson.getInt("watchers") + " watchers"); } final TextView repo_fork_count = (TextView) findViewById(R.id.tv_repository_info_forks); if (mJson.getInt("forks") == 1) { repo_fork_count.setText(mJson.getInt("forks") + " fork"); } else { repo_fork_count.setText(mJson.getInt("forks") + " forks"); } final TextView repo_website = (TextView) findViewById(R.id.tv_repository_info_website); if (mJson.getString("homepage") != "") { repo_website.setText(mJson.getString("homepage")); } else { repo_website.setText("N/A"); } /* Make the repository owner text link to his/her profile */ repo_owner.setMovementMethod(LinkMovementMethod.getInstance()); final Spannable spans = (Spannable) repo_owner.getText(); final ClickableSpan clickSpan = new ClickableSpan() { @Override public void onClick(final View widget) { final Intent i = new Intent(Repository.this, Profile.class); try { i.putExtra("username", mJson.getString("owner")); } catch (final JSONException e) { e.printStackTrace(); } startActivity(i); } }; spans.setSpan(clickSpan, 0, spans.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } catch (final JSONException e) { e.printStackTrace(); } ((Button) findViewById(R.id.btn_repository_info_branches)).setOnClickListener(new OnClickListener() { public void onClick(final View v) { final Intent intent = new Intent(Repository.this, BranchesList.class); intent.putExtra("repo_name", mRepositoryName); intent.putExtra("repo_owner", mRepositoryOwner); startActivity(intent); } }); ((Button) findViewById(R.id.btn_repository_info_issues)).setOnClickListener(new OnClickListener() { public void onClick(final View v) { final Intent intent = new Intent(Repository.this, Issues.class); intent.putExtra("repo_name", mRepositoryName); intent.putExtra("repo_owner", mRepositoryOwner); startActivity(intent); } }); ((Button) findViewById(R.id.btn_repository_info_network)).setOnClickListener(new OnClickListener() { public void onClick(final View v) { final Intent intent = new Intent(Repository.this, NetworkList.class); intent.putExtra("repo_name", mRepositoryName); intent.putExtra("username", mRepositoryOwner); startActivity(intent); } }); }
From source file:com.taobao.weex.dom.WXTextDomObject.java
/** * Adjust span range after truncate due to the wrong span range during span copy and slicing. * @param beforeTruncate The span before truncate * @param afterTruncate The span after truncate *///from ww w .j a va 2 s. c om private void adjustSpansRange(@NonNull Spanned beforeTruncate, @NonNull Spannable afterTruncate) { Object[] spans = beforeTruncate.getSpans(0, beforeTruncate.length(), Object.class); for (Object span : spans) { int start = beforeTruncate.getSpanStart(span); int end = beforeTruncate.getSpanEnd(span); if (start == 0 && end == beforeTruncate.length()) { afterTruncate.removeSpan(span); afterTruncate.setSpan(span, 0, afterTruncate.length(), beforeTruncate.getSpanFlags(span)); } } }
From source file:com.nearnotes.NoteEdit.java
public void toggleChecklist() { if (mChecklist) { Toast.makeText(getActivity(), "Checklist off", Toast.LENGTH_SHORT).show(); mChecklist = false;//from w ww.j a v a2 s .c o m mTblAddLayout.removeAllViews(); mBodyText.removeTextChangedListener(bodyTextWatcher); Spannable spannable = (Spannable) mBodyText.getText(); Object spansToRemove[] = spannable.getSpans(0, spannable.length(), Object.class); for (Object span : spansToRemove) { if (span instanceof CharacterStyle) spannable.removeSpan(span); } } else { Toast.makeText(getActivity(), "Checklist on", Toast.LENGTH_SHORT).show(); mChecklist = true; mBodyText.addTextChangedListener(bodyTextWatcher); String tempBoxes = mBodyText.getText().toString(); if (mBodyText.getLayout() != null) { mRealRow = populateBoxes(tempBoxes); int row = 0; for (NoteRow line : mRealRow) { switch (line.getType()) { case 0: TableRow inflate = (TableRow) View.inflate(getActivity(), R.layout.table_row_invisible, null); mTblAddLayout.addView(inflate); break; case 1: TableRow checkRow = (TableRow) View.inflate(getActivity(), R.layout.table_row, null); CheckBox temp = (CheckBox) checkRow.getChildAt(0); temp.setTag(Integer.valueOf(row)); mTblAddLayout.addView(checkRow); temp.setOnClickListener(checkBoxListener); break; case 2: TableRow checkRow1 = (TableRow) View.inflate(getActivity(), R.layout.table_row, null); CheckBox temp1 = (CheckBox) checkRow1.getChildAt(0); temp1.setTag(Integer.valueOf(row)); temp1.setChecked(true); mTblAddLayout.addView(checkRow1); temp1.setOnClickListener(checkBoxListener); break; } for (int k = 1; line.getSize() > k; k++) { TableRow inflate = (TableRow) View.inflate(getActivity(), R.layout.table_row_invisible, null); mTblAddLayout.addView(inflate); } row++; } } } }
From source file:com.nkahoang.screenstandby.Main.java
private void warning() { try {/*from w ww. ja v a 2 s .c om*/ String build = android.os.Build.MODEL.toLowerCase(); if (build.contains("i535") || build.contains("d2vzw") || build.contains("d2spr") || build.contains("d2tmo")) { TextView tv = (TextView) this.findViewById(R.id.textView1); Spannable warning = new SpannableString( "IMPORTANT! This app is currently has compatibility problem with your device (" + build + ") as it may freezes up the screen. I am sorry for the problem and is trying my best to fix this"); warning.setSpan(new ForegroundColorSpan(Color.RED), 0, warning.length(), 0); tv.setText(warning); } } catch (Exception ex) { } }
From source file:com.bt.heliniumstudentapp.SettingsActivity.java
private void setTitles() { final Spannable prefGeneral = new SpannableString(getString(R.string.general)); final Spannable prefCustomization = new SpannableString(getString(R.string.customization)); final Spannable prefSchedule = new SpannableString(getString(R.string.schedule)); final Spannable prefGrades = new SpannableString(getString(R.string.grades)); final Spannable prefUpdate = new SpannableString(getString(R.string.updates)); if (Build.VERSION.SDK_INT > Build.VERSION_CODES.GINGERBREAD_MR1) { prefGeneral.setSpan(//from w w w . j a v a 2 s. c o m new ForegroundColorSpan(ContextCompat.getColor(this, MainActivity.accentSecondaryColor)), 0, prefGeneral.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); prefCustomization.setSpan( new ForegroundColorSpan(ContextCompat.getColor(this, MainActivity.accentSecondaryColor)), 0, prefCustomization.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); prefSchedule.setSpan( new ForegroundColorSpan(ContextCompat.getColor(this, MainActivity.accentSecondaryColor)), 0, prefSchedule.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); prefGrades.setSpan( new ForegroundColorSpan(ContextCompat.getColor(this, MainActivity.accentSecondaryColor)), 0, prefGrades.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); prefUpdate.setSpan( new ForegroundColorSpan(ContextCompat.getColor(this, MainActivity.accentSecondaryColor)), 0, prefUpdate.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } else { prefGeneral.setSpan(new ForegroundColorSpan(ContextCompat.getColor(this, R.color.dark_grey_dark)), 0, prefGeneral.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); prefCustomization.setSpan(new ForegroundColorSpan(ContextCompat.getColor(this, R.color.dark_grey_dark)), 0, prefCustomization.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); prefSchedule.setSpan(new ForegroundColorSpan(ContextCompat.getColor(this, R.color.dark_grey_dark)), 0, prefSchedule.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); prefGrades.setSpan(new ForegroundColorSpan(ContextCompat.getColor(this, R.color.dark_grey_dark)), 0, prefGrades.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); prefUpdate.setSpan(new ForegroundColorSpan(ContextCompat.getColor(this, R.color.dark_grey_dark)), 0, prefUpdate.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } findPreference("pref_general").setTitle(prefGeneral); findPreference("pref_customization").setTitle(prefCustomization); findPreference("pref_schedule").setTitle(prefSchedule); findPreference("pref_grades").setTitle(prefGrades); findPreference("pref_updates").setTitle(prefUpdate); }
From source file:android.melbournehistorymap.MapsActivity.java
/** * Manipulates the map once available.// www . j av a 2 s . c o m * This callback is triggered when the map is ready to be used. * This is where we can add markers or lines, add listeners or move the camera. In this case, * we just add a marker near Sydney, Australia. * If Google Play services is not installed on the device, the user will be prompted to install * it inside the SupportMapFragment. This method will only be triggered once the user has * installed Google Play services and returned to the app. */ @Override public void onMapReady(GoogleMap googleMap) { mMap = googleMap; spinner = (ProgressBar) findViewById(R.id.prograssSpinner); //check if permission has been granted if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { // Permission has already been granted return; } mMap.setMyLocationEnabled(true); mMap.getUiSettings().setZoomControlsEnabled(false); double lat; double lng; final int radius; int zoom; lat = Double.parseDouble(CurrLat); lng = Double.parseDouble(CurrLong); //build current location LatLng currentLocation = new LatLng(lat, lng); final LatLng realLocation = currentLocation; if (MELBOURNE.contains(currentLocation)) { mMap.getUiSettings().setMyLocationButtonEnabled(true); zoom = 17; } else { mMap.getUiSettings().setMyLocationButtonEnabled(false); lat = -37.81161508043379; lng = 144.9647320434451; zoom = 15; currentLocation = new LatLng(lat, lng); } mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(currentLocation, 13)); CameraPosition cameraPosition = new CameraPosition.Builder().target(currentLocation) // Sets the center of the map to location user .zoom(zoom) // Sets the zoom .bearing(0) // Sets the orientation of the camera to east .tilt(25) // Sets the tilt of the camera to 30 degrees .build(); // Creates a CameraPosition from the builder //Animate user to map location, if in Melbourne or outside of Melbourne bounds mMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition), new GoogleMap.CancelableCallback() { @Override public void onFinish() { updateMap(); } @Override public void onCancel() { } }); final TextView placeTitle = (TextView) findViewById(R.id.placeTitle); final TextView placeVic = (TextView) findViewById(R.id.placeVic); final TextView expPlaceTitle = (TextView) findViewById(R.id.expPlaceTitle); final TextView expPlaceVic = (TextView) findViewById(R.id.expPlaceVic); final TextView expPlaceDescription = (TextView) findViewById(R.id.placeDescription); final TextView wikiLicense = (TextView) findViewById(R.id.wikiLicense); final TextView expPlaceDistance = (TextView) findViewById(R.id.expPlaceDistance); final RelativeLayout tile = (RelativeLayout) findViewById(R.id.tile); final TextView fab = (TextView) findViewById(R.id.fab); final RelativeLayout distanceCont = (RelativeLayout) findViewById(R.id.distanceContainer); // String license = "Text is available under the <a rel=\"license\" href=\"//en.wikipedia.org/wiki/Wikipedia:Text_of_Creative_Commons_Attribution-ShareAlike_3.0_Unported_License\">Creative Commons Attribution-ShareAlike License</a><a rel=\"license\" href=\"//creativecommons.org/licenses/by-sa/3.0/\" style=\"display:none;\"></a>;\n" + // "additional terms may apply."; // wikiLicense.setText(Html.fromHtml(license)); // wikiLicense.setMovementMethod(LinkMovementMethod.getInstance()); //Marker click mMap.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() { @Override public boolean onMarkerClick(Marker marker) { String title = marker.getTitle(); mMap.setPadding(0, 0, 0, 620); //set clicked marker to full opacity marker.setAlpha(1f); //set previous marker back to partial opac (if there is a prevMarker if (dirtyMarker == 1) { prevMarker.setAlpha(0.6f); } prevMarker = marker; dirtyMarker = 1; //Set DB helper DBHelper myDBHelper = new DBHelper(MapsActivity.this, WikiAPI.DB_NAME, null, WikiAPI.VERSION); //Only search for Wiki API requests if no place article returned. // ** //Open DB as readable only. SQLiteDatabase db = myDBHelper.getReadableDatabase(); //Set the query String dbFriendlyName = title.replace("\'", "\'\'"); //Limit by 1 rows Cursor cursor = db.query(DBHelper.TABLE_NAME, null, "PLACE_NAME = '" + dbFriendlyName + "'", null, null, null, null, "1"); //move through each row returned in the query results while (cursor.moveToNext()) { String place_ID = cursor.getString(cursor.getColumnIndex("PLACE_ID")); String placeName = cursor.getString(cursor.getColumnIndex("PLACE_NAME")); String placeLoc = cursor.getString(cursor.getColumnIndex("PLACE_LOCATION")); String placeArticle = cursor.getString(cursor.getColumnIndex("ARTICLE")); String placeLat = cursor.getString(cursor.getColumnIndex("LAT")); String placeLng = cursor.getString(cursor.getColumnIndex("LNG")); //Get Google Place photos //Source: https://developers.google.com/places/android-api/photos final String placeId = place_ID; Places.GeoDataApi.getPlacePhotos(mGoogleApiClient, placeId) .setResultCallback(new ResultCallback<PlacePhotoMetadataResult>() { @Override public void onResult(PlacePhotoMetadataResult photos) { if (!photos.getStatus().isSuccess()) { return; } ImageView mImageView = (ImageView) findViewById(R.id.imageView); ImageView mImageViewExpanded = (ImageView) findViewById(R.id.headerImage); TextView txtAttribute = (TextView) findViewById(R.id.photoAttribute); TextView expTxtAttribute = (TextView) findViewById(R.id.expPhotoAttribute); PlacePhotoMetadataBuffer photoMetadataBuffer = photos.getPhotoMetadata(); if (photoMetadataBuffer.getCount() > 0) { // Display the first bitmap in an ImageView in the size of the view photoMetadataBuffer.get(0).getScaledPhoto(mGoogleApiClient, 600, 200) .setResultCallback(mDisplayPhotoResultCallback); //get photo attributions PlacePhotoMetadata photo = photoMetadataBuffer.get(0); CharSequence attribution = photo.getAttributions(); if (attribution != null) { txtAttribute.setText(Html.fromHtml(String.valueOf(attribution))); expTxtAttribute.setText(Html.fromHtml(String.valueOf(attribution))); //http://stackoverflow.com/questions/4303160/how-can-i-make-links-in-fromhtml-clickable-android txtAttribute.setMovementMethod(LinkMovementMethod.getInstance()); expTxtAttribute.setMovementMethod(LinkMovementMethod.getInstance()); } else { txtAttribute.setText(" "); expTxtAttribute.setText(" "); } } else { //Reset image view as no photo was identified mImageView.setImageResource(android.R.color.transparent); mImageViewExpanded.setImageResource(android.R.color.transparent); txtAttribute.setText(R.string.no_photos); expTxtAttribute.setText(R.string.no_photos); } photoMetadataBuffer.release(); } }); LatLng destLocation = new LatLng(Double.parseDouble(placeLat), Double.parseDouble(placeLng)); //Work out distance between current location and place location //Source Library: https://github.com/googlemaps/android-maps-utils double distance = SphericalUtil.computeDistanceBetween(realLocation, destLocation); distance = Math.round(distance); distance = distance * 0.001; String strDistance = String.valueOf(distance); String[] arrDistance = strDistance.split("\\."); String unit = "km"; if (arrDistance[0] == "0") { unit = "m"; strDistance = arrDistance[1]; } else { strDistance = arrDistance[0] + "." + arrDistance[1].substring(0, 1); } placeArticle = placeArticle .replaceAll("(<div class=\"thumb t).*\\s.*\\s.*\\s.*\\s.*\\s<\\/div>\\s<\\/div>", " "); Spannable noUnderlineMessage = new SpannableString(Html.fromHtml(placeArticle)); //http://stackoverflow.com/questions/4096851/remove-underline-from-links-in-textview-android for (URLSpan u : noUnderlineMessage.getSpans(0, noUnderlineMessage.length(), URLSpan.class)) { noUnderlineMessage.setSpan(new UnderlineSpan() { public void updateDrawState(TextPaint tp) { tp.setUnderlineText(false); } }, noUnderlineMessage.getSpanStart(u), noUnderlineMessage.getSpanEnd(u), 0); } placeArticle = String.valueOf(noUnderlineMessage); placeArticle = placeArticle.replaceAll("(\\[\\d\\])", " "); placeTitle.setText(placeName); expPlaceTitle.setText(placeName); placeVic.setText(placeLoc); expPlaceVic.setText(placeLoc); expPlaceDescription.setText(placeArticle); if (MELBOURNE.contains(realLocation)) { expPlaceDistance.setText("Distance: " + strDistance + unit); distanceCont.setVisibility(View.VISIBLE); } } tile.setVisibility(View.VISIBLE); fab.setVisibility(View.VISIBLE); //Set to true to not show default behaviour. return false; } }); mMap.setOnMapClickListener(new GoogleMap.OnMapClickListener() { @Override public void onMapClick(LatLng latLng) { int viewStatus = tile.getVisibility(); if (viewStatus == View.VISIBLE) { tile.setVisibility(View.INVISIBLE); fab.setVisibility(View.INVISIBLE); //set previous marker back to partial opac (if there is a prevMarker if (dirtyMarker == 1) { prevMarker.setAlpha(0.6f); } } mMap.setPadding(0, 0, 0, 0); } }); FloatingActionButton shareIcon = (FloatingActionButton) findViewById(R.id.shareIcon); shareIcon.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { //https://www.google.com.au/maps/place/Federation+Square/@-37.8179789,144.9668635,15z //Build implicit intent by triggering a SENDTO action, which will capture applications that allow for messages //that allow for messages to be sent to a specific user with data //http://developer.android.com/reference/android/content/Intent.html#ACTION_SENDTO Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/plain"); //Build SMS String encodedPlace = "empty"; try { encodedPlace = URLEncoder.encode(String.valueOf(expPlaceTitle.getText()), "UTF-8"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } intent.putExtra(Intent.EXTRA_TEXT, String.valueOf(expPlaceTitle.getText()) + " \n\nhttps://www.google.com.au/maps/place/" + encodedPlace); Intent sms = Intent.createChooser(intent, null); startActivity(sms); } }); TextView fullArticle = (TextView) findViewById(R.id.fullArticle); fullArticle.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { String wikiPlace = WikiPlace.getName(String.valueOf(expPlaceTitle.getText())); String url = "https://en.wikipedia.org/wiki/" + wikiPlace; Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); startActivity(browserIntent); } }); }
From source file:com.glandorf1.joe.wsprnetviewer.app.WsprFragment.java
@Override public Loader<Cursor> onCreateLoader(int id, Bundle args) { // This is called when a new Loader needs to be created. This // fragment only uses one loader, so we don't care about checking the id. // TODO: Filter the query to only return data from today and the previous N days. // Calendar cal = Calendar.getInstance(); // cal.setTime(new Date()); // cal.add(Calendar.DATE, -7); // N= 7 // Date cutoffDate = cal.getTime(); // String startTimestamp = WsprNetContract.getDbTimestampString(cutoffDate); // Sort order: Descending, by timestamp. String sortOrder = WsprNetContract.SignalReportEntry.COLUMN_TIMESTAMPTEXT + " DESC"; String txCall = Utility.getFilterCallsign(getActivity(), true), rxCall = Utility.getFilterCallsign(getActivity(), false); String txGridsquare = Utility.getFilterGridsquare(getActivity(), true), rxGridsquare = Utility.getFilterGridsquare(getActivity(), false); txCall = Utility.filterCleanupForSQL(txCall); rxCall = Utility.filterCleanupForSQL(rxCall); txGridsquare = Utility.filterCleanupForSQL(txGridsquare); rxGridsquare = Utility.filterCleanupForSQL(rxGridsquare); mSelection = ""; if (Utility.isFiltered(getActivity())) { // When adding filters, be sure to update onResume(), and save the preference value below, too. String prefAndOr = Utility.isFilterAnd(getActivity()) ? " and " : " or "; String sAndOr = " "; if (txCall.length() > 0) { sAndOr = (mSelection.length() > 0) ? prefAndOr : ""; mSelection += sAndOr + "(" + WsprNetContract.SignalReportEntry.COLUMN_TX_CALLSIGN + " like '" + txCall + "')"; }/*from w w w .j a v a 2 s .c o m*/ if (rxCall.length() > 0) { sAndOr = (mSelection.length() > 0) ? prefAndOr : ""; mSelection += sAndOr + "(" + WsprNetContract.SignalReportEntry.COLUMN_RX_CALLSIGN + " like '" + rxCall + "')"; } if (txGridsquare.length() > 0) { sAndOr = (mSelection.length() > 0) ? prefAndOr : ""; mSelection += sAndOr + "(" + WsprNetContract.SignalReportEntry.COLUMN_TX_GRIDSQUARE + " like '" + txGridsquare + "')"; } if (rxGridsquare.length() > 0) { sAndOr = (mSelection.length() > 0) ? prefAndOr : ""; mSelection += sAndOr + "(" + WsprNetContract.SignalReportEntry.COLUMN_RX_GRIDSQUARE + " like '" + rxGridsquare + "')"; } // Examples of resulting 'selection' clause: // tx_callsign like 'D%' // (tx_gridsquare like 'D%') and (rx_callsign like 'N%') // (tx_gridsquare like 'D%') or (rx_callsign like 'N%') if (mSelection.length() > 0) { // Remind user that items are filtered, in case the result is not what they expect. Toast.makeText(getActivity(), getActivity().getString(R.string.toast_filter_items), Toast.LENGTH_LONG).show(); } } int mainDisplayPreference = Utility.getMainDisplayPreference(getActivity()); if (mWsprAdapter.mainDisplayFormat != mainDisplayPreference) { // Update the gridsquare/callsign heading text based on the display layout. switch (mainDisplayPreference) { case Utility.MAIN_DISPLAY_CALLSIGN: // fit everything into 2 lines of display mTVGridCallHeader.setText(getActivity().getString(R.string.callsign)); mTVGridCallHeader.setTextColor(getResources().getColor(R.color.wspr_brown)); break; case Utility.MAIN_DISPLAY_GRIDCALL: // fit everything into 4 lines of display String g = getActivity().getString(R.string.grid); String c = getActivity().getString(R.string.call); Spannable s = new SpannableString(g + "/" + c); // In "Grid/Call", make "grid" black, "Call" brown, and "/" somewhere between. // Release: For "Grid", set the span to be 1 extra character. s.setSpan(new ForegroundColorSpan(Color.BLACK), 0, g.length() + 0, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); // Debug: For the "/", set the span to be 2 characters; it will won't display in the color if the span is only 1 character. s.setSpan(new ForegroundColorSpan(getResources().getColor(R.color.wspr_brown2)), g.length() + 0, g.length() + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); s.setSpan(new ForegroundColorSpan(getResources().getColor(R.color.wspr_brown)), g.length() + 1, s.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); mTVGridCallHeader.setText(s); break; case Utility.MAIN_DISPLAY_GRIDSQUARE: // fit everything into 2 lines of display default: mTVGridCallHeader.setText(getActivity().getString(R.string.gridsquare)); mTVGridCallHeader.setTextColor(Color.BLACK); } } // Save some of the preferences to detect if they've changed in onResume(). mGridsquare = Utility.getPreferredGridsquare(getActivity()); mWsprAdapter.mainDisplayFormat = mainDisplayPreference; mFilterTxCallsign = Utility.getFilterCallsign(getActivity(), true); mFilterRxCallsign = Utility.getFilterCallsign(getActivity(), false); mFilterTxGridsquare = Utility.getFilterGridsquare(getActivity(), true); mFilterRxGridsquare = Utility.getFilterGridsquare(getActivity(), false); mFilterAnd = Utility.isFilterAnd(getActivity()); mFiltered = Utility.isFiltered(getActivity()); Uri wsprUri; wsprUri = WsprNetContract.SignalReportEntry.buildWspr(); // Create and return a CursorLoader that will take care of creating a Cursor for the data being displayed. return new CursorLoader(getActivity(), // context wsprUri, // URI WSPR_COLUMNS, // String[] projection mSelection, // String selection null, // String[] selectionArgs sortOrder // String sortOrder ); }
From source file:org.onebusaway.android.report.ui.Open311ProblemFragment.java
/** * Dynamically creates an edit text//from w w w . j a va 2 s. co m * * @param open311Attribute contains the open311 attributes */ private void createEditText(Open311Attribute open311Attribute) { LayoutInflater inflater = LayoutInflater.from(getActivity()); RelativeLayout layout = (RelativeLayout) inflater.inflate(R.layout.report_issue_text_item, null, false); ImageView icon = ((ImageView) layout.findViewById(R.id.ri_ic_question_answer)); icon.setColorFilter(getResources().getColor(R.color.material_gray)); Spannable desc = new SpannableString(MyTextUtils.toSentenceCase(open311Attribute.getDescription())); EditText editText = ((EditText) layout.findViewById(R.id.riti_editText)); if (open311Attribute.getRequired()) { Spannable req = new SpannableString("(required)"); req.setSpan(new ForegroundColorSpan(Color.RED), 0, req.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); editText.setHint(TextUtils.concat(desc, " ", req)); } else { editText.setHint(desc); } if (Open311DataType.NUMBER.equals(open311Attribute.getDatatype())) { editText.setInputType(InputType.TYPE_CLASS_NUMBER); } else if (Open311DataType.DATETIME.equals(open311Attribute.getDatatype())) { editText.setInputType(InputType.TYPE_CLASS_DATETIME); } // Restore view state from attribute result hash map AttributeValue av = mAttributeValueHashMap.get(open311Attribute.getCode()); if (av != null) { editText.setText(av.getSingleValue()); } // Dynamically fill stop id if this is a transit service // And if this is a bus stop field if (ServiceUtils.isTransitServiceByType(mService.getType()) && ServiceUtils.isStopIdField(open311Attribute.getDescription())) { icon.setImageDrawable(ContextCompat.getDrawable(getActivity(), R.drawable.ri_flag_triangle)); ObaStop obaStop = getIssueLocationHelper().getObaStop(); if (obaStop != null) { editText.setText(obaStop.getStopCode()); } } mInfoLayout.addView(layout); mDynamicAttributeUIMap.put(open311Attribute.getCode(), editText); }
From source file:org.onebusaway.android.report.ui.Open311ProblemFragment.java
/** * Dynamically creates checkboxes/*ww w.j a v a2 s.c o m*/ * * @param open311Attribute contains the open311 attributes */ private void createMultiValueList(Open311Attribute open311Attribute) { ArrayList<Object> values = (ArrayList<Object>) open311Attribute.getValues(); if (values != null && values.size() > 0) { LayoutInflater inflater = LayoutInflater.from(getActivity()); RelativeLayout layout = (RelativeLayout) inflater.inflate(R.layout.report_issue_multi_value_list_item, null, false); ((ImageView) layout.findViewById(R.id.ri_ic_checkbox)) .setColorFilter(getResources().getColor(R.color.material_gray)); Spannable word = new SpannableString(open311Attribute.getDescription()); ((TextView) layout.findViewById(R.id.rimvli_textView)).setText(word); if (open311Attribute.getRequired()) { Spannable wordTwo = new SpannableString(" *Required"); wordTwo.setSpan(new ForegroundColorSpan(Color.RED), 0, wordTwo.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); ((TextView) layout.findViewById(R.id.rimvli_textView)).append(wordTwo); } // Restore view state from attribute result hash map AttributeValue av = mAttributeValueHashMap.get(open311Attribute.getCode()); LinearLayout cg = (LinearLayout) layout.findViewById(R.id.rimvli_checkBoxGroup); for (int i = 0; i < values.size(); i++) { LinkedHashMap<String, String> value = (LinkedHashMap<String, String>) values.get(i); CheckBox cb = new CheckBox(getActivity()); cg.addView(cb); String attributeKey = ""; String attributeValue = ""; for (LinkedHashMap.Entry<String, String> entry : value.entrySet()) { if (Open311Attribute.NAME.equals(entry.getKey())) { cb.setText(entry.getValue()); if (av != null && av.getValues().contains(entry.getValue())) { cb.setChecked(true); } attributeKey = open311Attribute.getCode() + entry.getValue(); } else if (Open311Attribute.KEY.equals(entry.getKey())) { attributeValue = entry.getValue(); } } mOpen311AttributeKeyNameMap.put(attributeKey, attributeValue); } mInfoLayout.addView(layout); mDynamicAttributeUIMap.put(open311Attribute.getCode(), cg); } }