private static View GetViewForDoorHandle(Context context, HomeMaticChannel channel) { var view = LayoutInflater.From(context).Inflate(Resource.Layout.DoorHandle, null); var state = (channel as DoorHandle).State; switch (state) { case DoorHandleState.Open: view.FindViewById<TextView>(Resource.Id.tvState).Text = context.GetString(Resource.String.open); view.FindViewById<ImageView>(Resource.Id.ivOpen).Visibility = ViewStates.Visible; view.FindViewById<ImageView>(Resource.Id.ivClosed).Visibility = ViewStates.Gone; break; case DoorHandleState.Tilted: view.FindViewById<TextView>(Resource.Id.tvState).Text = context.GetString(Resource.String.tilted); view.FindViewById<ImageView>(Resource.Id.ivOpen).Visibility = ViewStates.Visible; view.FindViewById<ImageView>(Resource.Id.ivClosed).Visibility = ViewStates.Gone; break; case DoorHandleState.Closed: view.FindViewById<TextView>(Resource.Id.tvState).Text = context.GetString(Resource.String.closed); view.FindViewById<ImageView>(Resource.Id.ivOpen).Visibility = ViewStates.Gone; view.FindViewById<ImageView>(Resource.Id.ivClosed).Visibility = ViewStates.Visible; break; } return view; }
/// <summary> /// Determines whether the specified context is metric. /// </summary> /// <param name="context">The context.</param> /// <returns></returns> public static bool IsMetric(Context context) { // get the location and units preferences for this data var prefs = PreferenceManager.GetDefaultSharedPreferences(context); var units = prefs.GetString(context.GetString(Resource.String.TempPrefKey), context.GetString(Resource.String.LocationPrefDefault)); return units.Equals(context.GetString(Resource.String.TempPrefMetric)); }
public StringResource(Context context) { _dictionary = new Dictionary<string, string> (); _dictionary.Add ("subject", context.GetString(Resource.String.subject)); _dictionary.Add ("message_frontend", context.GetString(Resource.String.message_frontend)); _dictionary.Add ("message_backend", context.GetString(Resource.String.message_backend)); _dictionary.Add ("message_mobile", context.GetString(Resource.String.message_mobile)); _dictionary.Add ("message_generic", context.GetString(Resource.String.message_generic)); }
public HSVColorPickerDialog(Context context, Color initialColor, Action<Color> listener) : base(context) { this.selectedColor = initialColor; this.listener = listener; colorWheel = new HSVColorWheel(context); valueSlider = new HSVValueSlider(context); var padding = (int)(context.Resources.DisplayMetrics.Density * PADDING_DP); var borderSize = (int)(context.Resources.DisplayMetrics.Density * BORDER_DP); var layout = new RelativeLayout(context); var lp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MatchParent, RelativeLayout.LayoutParams.MatchParent); lp.BottomMargin = (int)(context.Resources.DisplayMetrics.Density * CONTROL_SPACING_DP); colorWheel.setListener((color) => valueSlider.SetColor(color, true)); colorWheel.setColor(initialColor); colorWheel.Id = (1); layout.AddView(colorWheel, lp); int selectedColorHeight = (int)(context.Resources.DisplayMetrics.Density * SELECTED_COLOR_HEIGHT_DP); var valueSliderBorder = new FrameLayout(context); valueSliderBorder.SetBackgroundColor(BORDER_COLOR); valueSliderBorder.SetPadding(borderSize, borderSize, borderSize, borderSize); valueSliderBorder.Id = (2); lp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MatchParent, selectedColorHeight + 2 * borderSize); lp.BottomMargin = (int)(context.Resources.DisplayMetrics.Density * CONTROL_SPACING_DP); lp.AddRule(LayoutRules.Below, 1); layout.AddView(valueSliderBorder, lp); valueSlider.SetColor(initialColor, false); valueSlider.SetListener((color) => { selectedColor = color; selectedColorView.SetBackgroundColor(color); }); valueSliderBorder.AddView(valueSlider); var selectedColorborder = new FrameLayout(context); selectedColorborder.SetBackgroundColor(BORDER_COLOR); lp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MatchParent, selectedColorHeight + 2 * borderSize); selectedColorborder.SetPadding(borderSize, borderSize, borderSize, borderSize); lp.AddRule(LayoutRules.Below, 2); layout.AddView(selectedColorborder, lp); selectedColorView = new View(context); selectedColorView.SetBackgroundColor(selectedColor); selectedColorborder.AddView(selectedColorView); SetButton((int)DialogButtonType.Negative, context.GetString(Android.Resource.String.Cancel), ClickListener); SetButton((int)DialogButtonType.Positive, context.GetString(Android.Resource.String.Ok), ClickListener); SetView(layout, padding, padding, padding, padding); }
//returns correct Typeface from fontName public static Typeface SelectTypeface(Context context, String fontName) { if (fontName.Equals (context.GetString (Resource.String.Verveine))) return Typeface.CreateFromAsset (context.Assets, "fonts/Verveine W01 Regular.ttf"); else if (fontName.Equals (context.GetString (Resource.String.DIN_light))) return Typeface.CreateFromAsset (context.Assets, "fonts/DINPro-Light.ttf"); else if (fontName.Equals (context.GetString (Resource.String.DIN_regular))) return Typeface.CreateFromAsset (context.Assets, "fonts/DINPro-Regular.ttf"); else if (fontName.Equals (context.GetString (Resource.String.Sketchblock))) return Typeface.CreateFromAsset (context.Assets, "fonts/sketch_block_light.ttf"); else return null; }
public static void onSelectImageOk(Context context, UploadPhoto uploadPhoto, PopupNoticeInfomation popupNotice, int requestCode, Result resultCode, Intent data, Guid bookingId, bool isInConference){ if (data == null) { try{ Intent mediaScanIntent = new Intent (Intent.ActionMediaScannerScanFile); Uri contentUri = Uri.FromFile (App._file); mediaScanIntent.SetData (contentUri); //SendBroadcast (mediaScanIntent); uploadPhoto.onResultChoosed (contentUri, isInConference, bookingId); } catch(Exception e){ Console.Write (e.Message); popupNotice.showNoticeDialog (context.GetString(Resource.String.title_notice), context.GetString(Resource.String.get_img_from_lib)); } } else { uploadPhoto.onResultChoosed (data, isInConference, bookingId); } }
/// <summary> /// Plaies a sound from an Assets sound file /// </summary> /// <param name="context">Context.</param> /// <param name="fileName">File name.</param> /// <param name = "folderName">Folder Name. Takes "Sounds" if nothing else is set</param> public static void PlaySound(Context context, string fileName, string folderName = null) { // Set default folder "Sounds" if nothing else is set if (folderName == null) folderName = "Sounds"; try { // Describe sound file from Assets properly var descriptor = context.Assets.OpenFd(folderName + "/" + fileName); // Reset player if still playing Stop(); // Play sound file player.SetDataSource(descriptor.FileDescriptor, descriptor.StartOffset, descriptor.Length); player.Prepare(); player.Start(); } catch (FileNotFoundException) { Toast.MakeText(context, context.GetString(Resource.String.error_soundfileNotFound), ToastLength.Short); System.Console.WriteLine("Error: Soundfile '" + fileName + "' could not be found."); } }
public override void OnReceive (Context context, Intent intent) { // Create deep link intent with correct action and add play store referral information var deepLinkIntent = AppInviteReferral.AddPlayStoreReferrerToIntent(intent, new Intent(context.GetString(Resource.String.action_deep_link))); // Let any listeners know about the change LocalBroadcastManager.GetInstance(context).SendBroadcast(deepLinkIntent); }
public LocalizationService(Context context, Type stringType) { _strings = stringType.GetRuntimeFields() .Where(field => field.IsLiteral) .ToDictionary( field => field.Name, field => context.GetString((int)field.GetRawConstantValue()) ); }
public static void StartMap(Context context) { var locationIntent = new Intent(Intent.ActionView); var prefs = PreferenceManager.GetDefaultSharedPreferences(context); var location = prefs.GetString(context.GetString(Resource.String.LocationPrefKey), context.GetString(Resource.String.LocationPrefDefault)); var geoLocation = Uri.Parse("geo:0,0?").BuildUpon().AppendQueryParameter("q", location).Build(); locationIntent.SetData(geoLocation); if (locationIntent.ResolveActivity(context.PackageManager) != null) { context.StartActivity(locationIntent); } else { Log.Debug("SpringTime", "Could not open activity with location: " + location); } }
public NumberPickerPreference(Context context, IAttributeSet attrs) : base (context, attrs) { DialogLayoutResource = (BuildVersionCodes.Honeycomb > Build.VERSION.SdkInt) ? Resource.Layout.RadioGroupDialog : Resource.Layout.NumberPickerDialog; SetPositiveButtonText(Android.Resource.String.Ok); SetNegativeButtonText(Android.Resource.String.Cancel); int value = PreferenceManager.GetDefaultSharedPreferences(Context).GetInt(SettingsScreen.DefaultRadiusKey, SettingsScreen.DefaultRadiusValue); Summary = string.Format(context.GetString(Resource.String.settings_default_radius_sum), value); }
/** * Format and return the given {@link Blocks} and {@link Rooms} values using * {@link #CONFERENCE_TIME_ZONE}. */ public static string FormatSessionSubtitle (long blockStart, long blockEnd, String roomName, Context context) { Java.Util.TimeZone.Default = ConferenceTimeZone; // NOTE: There is an efficient version of formatDateRange in Eclair and // beyond that allows you to recycle a StringBuilder. string timeString = DateUtils.FormatDateRange (context, blockStart, blockEnd, TIME_FLAGS); return context.GetString (Resource.String.session_subtitle, timeString, roomName); }
public static String formatTemperature(Context context, double temperature, bool isMetric) { double temp; if (!isMetric) { temp = 9 * temperature / 5 + 32; } else { temp = temperature; } return String.Format (context.GetString (Resource.String.format_temperature), temp); }
public static void ShowSimpleDialog(Context context, string title, string message) { AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.SetTitle(title); builder.SetMessage(message); AlertDialog dialog = builder.Create(); dialog.SetButton(context.GetString(Resource.String.text_button_ok), (sender, args) => dialog.Dismiss()); dialog.Show(); }
/** * Formats the address for display. * * @param context The context to get String resources from. * @param address The {@link Address} to format. * @return The address in a format suitable for display to the user. */ public static string FormatAddress (Context context, Address address) { // different locales may need different address formats, which would be handled in // R.string.address_format var address2 = string.IsNullOrEmpty (address.Address2) ? address.Address2 : address.Address2 + "\n"; var address3 = string.IsNullOrEmpty (address.Address3) ? address.Address3 : address.Address3 + "\n"; return context.GetString (Resource.String.address_format, address.Name, address.Address1, address2, address3, address.City, address.State, address.PostalCode); }
private static View GetViewForContact(Context context, HomeMaticChannel channel) { var view = LayoutInflater.From(context).Inflate(Resource.Layout.DoorHandle, null); var state = (channel as Contact).State; if (state) { view.FindViewById<TextView>(Resource.Id.tvState).Text = context.GetString(Resource.String.open); view.FindViewById<ImageView>(Resource.Id.ivOpen).Visibility = ViewStates.Visible; view.FindViewById<ImageView>(Resource.Id.ivClosed).Visibility = ViewStates.Gone; } else { view.FindViewById<TextView>(Resource.Id.tvState).Text = context.GetString(Resource.String.closed); view.FindViewById<ImageView>(Resource.Id.ivOpen).Visibility = ViewStates.Gone; view.FindViewById<ImageView>(Resource.Id.ivClosed).Visibility = ViewStates.Visible; } return view; }
/** * Given a day, returns just the name to use for that day. * E.g "today", "tomorrow", "wednesday". * * @param context Context to use for resource localization * @param dateInMillis The date in milliseconds * @return */ public static String getDayName(Context context, long dateInMillis) { // If the date is today, return the localized version of "Today" instead of the actual // day name. var todayDate = DateTime.Now.ToLocalTime ().Date; long currentDay = DateTime.Today.Ticks; DateTime dateAsDay = new DateTime (); var forecastDay = dateAsDay.AddTicks (dateInMillis).ToLocalTime ().Date; if (todayDate == forecastDay) { return context.GetString (Resource.String.today); } else if (forecastDay == todayDate.AddDays (1)) { return context.GetString (Resource.String.tomorrow); } else { // Otherwise, the format is just the day of the week (e.g "Wednesday". return forecastDay.ToString ("dddd"); } }
public Content (Context context, IAttributeSet attrs) : base (context, attrs) { mNavHider = () => SetNavVisibility (false); mText = new TextView (context); mText.SetTextSize (ComplexUnitType.Dip, 16); mText.Text = context.GetString (Resource.String.alert_dialog_two_buttons2ultra_msg); mText.Clickable = false; mText.SetOnClickListener (this); mText.SetTextIsSelectable (true); AddView (mText, new ViewGroup.LayoutParams ( ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.WrapContent)); SetOnSystemUiVisibilityChangeListener (this); }
public static Android.Support.V7.App.AlertDialog.Builder ErrorDialog( Context context, string message, Action<object, DialogClickEventArgs> buttonAction) { return BuildDialog( context, context.GetString(Resource.String.title_error), message, buttonAction, null, null, Android.Resource.String.Ok, 0, 0); }
public static Android.Support.V7.App.AlertDialog.Builder QuestionDialog( Context context, string message, Action<object, DialogClickEventArgs> positiveAction, Action<object, DialogClickEventArgs> negativeAction) { return BuildDialog( context, context.GetString(Resource.String.title_question), message, positiveAction, negativeAction, null, Android.Resource.String.Yes, Android.Resource.String.No, 0); }
/// <summary> /// Plays a sound from an Assets sound file /// </summary> /// <param name="context">Context.</param> /// <param name="waitForCompletion">Wait for the last audio to finish before starting to play this audio file</param> /// <param name="fileName">File name.</param> /// <param name = "folderName">Folder Name. Takes "Sounds" if nothing else is set</param> public static async void PlaySound(Context context, bool waitForCompletion, string fileName, string folderName = null) { try { // Describe sound file from Assets properly var descriptor = AssetHelper.Instance.OpenFd(folderName ?? DataHolder.Current.Common.AssetSoundDir + "/" + fileName); // Mark as active waitForCompletionActive = waitForCompletion; // Still playing? while (waitForCompletion && IsPlaying) { await Task.Delay(500); } // Continue to play next sound? if (waitForCompletion && !waitForCompletionActive) { return; } // Reset player if still playing Stop(); // Play sound file player.SetDataSource(descriptor.FileDescriptor, descriptor.StartOffset, descriptor.Length); player.Prepare(); player.Start(); } catch (FileNotFoundException) { Toast.MakeText(context, context.GetString(Resource.String.error_soundfileNotFound), ToastLength.Short); System.Console.WriteLine("Error: Soundfile '" + fileName + "' could not be found."); } catch (Java.Lang.IllegalStateException) { System.Console.WriteLine("Error: Player is in an invalid state - trying to play '" + fileName + "'"); player.Stop(); player.Reset(); } }
public override void OnReceive (Context context, Intent intent) { if (MessagingService.REPLY_ACTION.Equals (intent.Action)) { int conversationId = intent.GetIntExtra (MessagingService.CONVERSATION_ID, -1); var reply = GetMessageText (intent); if (conversationId != -1) { Log.Debug (TAG, "Got reply (" + reply + ") for ConversationId " + conversationId); MessageLogger.LogMessage (context, "ConversationId: " + conversationId + " received a reply: [" + reply + "]"); using (var notificationManager = NotificationManagerCompat.From (context)) { var notificationBuilder = new NotificationCompat.Builder (context); notificationBuilder.SetSmallIcon (Resource.Drawable.notification_icon); notificationBuilder.SetLargeIcon (BitmapFactory.DecodeResource (context.Resources, Resource.Drawable.android_contact)); notificationBuilder.SetContentText (context.GetString (Resource.String.replied)); Notification repliedNotification = notificationBuilder.Build (); notificationManager.Notify (conversationId, repliedNotification); } } } }
public static void GotoMarket(Context context) { GotoUrl(context, context.GetString(Resource.String.MarketURL)+context.PackageName); }
/** * Shows a (long) toast. * * @param context * @param resourceId */ public static void showToast (Context context, int resourceId) { Toast.MakeText (context, context.GetString (resourceId), ToastLength.Long).Show (); }
public LoadingLayout(Context context, Mode mode, PtrOrientation scrollDirection, TypedArray attrs) : base(context) { //base(context); mMode = mode; mScrollDirection = scrollDirection; switch (scrollDirection) { case PtrOrientation.HORIZONTAL: LayoutInflater.From(context).Inflate(Resource.Layout.pull_to_refresh_header_horizontal, this); break; case PtrOrientation.VERTICAL: default: LayoutInflater.From(context).Inflate(Resource.Layout.pull_to_refresh_header_vertical, this); break; } mInnerLayout = (FrameLayout)FindViewById(Resource.Id.fl_inner); mHeaderText = (TextView)mInnerLayout.FindViewById(Resource.Id.pull_to_refresh_text); mHeaderProgress = (ProgressBar)mInnerLayout.FindViewById(Resource.Id.pull_to_refresh_progress); mSubHeaderText = (TextView)mInnerLayout.FindViewById(Resource.Id.pull_to_refresh_sub_text); mHeaderImage = (ImageView)mInnerLayout.FindViewById(Resource.Id.pull_to_refresh_image); FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams)mInnerLayout.LayoutParameters; switch (mode) { case Mode.PULL_FROM_END: lp.Gravity = scrollDirection == PtrOrientation.VERTICAL ? GravityFlags.Top : GravityFlags.Left; // Load in labels mPullLabel = context.GetString(Resource.String.pull_to_refresh_from_bottom_pull_label); mRefreshingLabel = context.GetString(Resource.String.pull_to_refresh_from_bottom_refreshing_label); mReleaseLabel = context.GetString(Resource.String.pull_to_refresh_from_bottom_release_label); break; case Mode.PULL_FROM_START: default: lp.Gravity = scrollDirection == PtrOrientation.VERTICAL ? GravityFlags.Bottom : GravityFlags.Right; // Load in labels mPullLabel = context.GetString(Resource.String.pull_to_refresh_pull_label); mRefreshingLabel = context.GetString(Resource.String.pull_to_refresh_refreshing_label); mReleaseLabel = context.GetString(Resource.String.pull_to_refresh_release_label); break; } if (attrs.HasValue(Resource.Styleable.PullToRefresh_ptrHeaderBackground)) { Drawable background = attrs.GetDrawable(Resource.Styleable.PullToRefresh_ptrHeaderBackground); if (null != background) { ViewCompat.setBackground(this, background); } } if (attrs.HasValue(Resource.Styleable.PullToRefresh_ptrHeaderTextAppearance)) { TypedValue styleID = new TypedValue(); attrs.GetValue(Resource.Styleable.PullToRefresh_ptrHeaderTextAppearance, styleID); setTextAppearance(styleID.Data); } if (attrs.HasValue(Resource.Styleable.PullToRefresh_ptrSubHeaderTextAppearance)) { TypedValue styleID = new TypedValue(); attrs.GetValue(Resource.Styleable.PullToRefresh_ptrSubHeaderTextAppearance, styleID); setSubTextAppearance(styleID.Data); } // Text Color attrs need to be set after TextAppearance attrs if (attrs.HasValue(Resource.Styleable.PullToRefresh_ptrHeaderTextColor)) { ColorStateList colors = attrs.GetColorStateList(Resource.Styleable.PullToRefresh_ptrHeaderTextColor); if (null != colors) { setTextColor(colors); } } if (attrs.HasValue(Resource.Styleable.PullToRefresh_ptrHeaderSubTextColor)) { ColorStateList colors = attrs.GetColorStateList(Resource.Styleable.PullToRefresh_ptrHeaderSubTextColor); if (null != colors) { setSubTextColor(colors); } } // Try and get defined drawable from Attrs Drawable imageDrawable = null; if (attrs.HasValue(Resource.Styleable.PullToRefresh_ptrDrawable)) { imageDrawable = attrs.GetDrawable(Resource.Styleable.PullToRefresh_ptrDrawable); } // Check Specific Drawable from Attrs, these overrite the generic // drawable attr above switch (mode) { case Mode.PULL_FROM_START: default: if (attrs.HasValue(Resource.Styleable.PullToRefresh_ptrDrawableStart)) { imageDrawable = attrs.GetDrawable(Resource.Styleable.PullToRefresh_ptrDrawableStart); } else if (attrs.HasValue(Resource.Styleable.PullToRefresh_ptrDrawableTop)) { Utils.warnDeprecation("ptrDrawableTop", "ptrDrawableStart"); imageDrawable = attrs.GetDrawable(Resource.Styleable.PullToRefresh_ptrDrawableTop); } break; case Mode.PULL_FROM_END: if (attrs.HasValue(Resource.Styleable.PullToRefresh_ptrDrawableEnd)) { imageDrawable = attrs.GetDrawable(Resource.Styleable.PullToRefresh_ptrDrawableEnd); } else if (attrs.HasValue(Resource.Styleable.PullToRefresh_ptrDrawableBottom)) { Utils.warnDeprecation("ptrDrawableBottom", "ptrDrawableEnd"); imageDrawable = attrs.GetDrawable(Resource.Styleable.PullToRefresh_ptrDrawableBottom); } break; } // If we don't have a user defined drawable, load the default if (null == imageDrawable) { imageDrawable = context.Resources.GetDrawable(getDefaultDrawableResId()); } // Set Drawable, and save width/height setLoadingDrawable(imageDrawable); reset(); }
public static void PrepareNoDonatePreference(Context ctx, Preference preference) { ISharedPreferences prefs = PreferenceManager.GetDefaultSharedPreferences(ctx); long usageCount = prefs.GetLong(ctx.GetString(Resource.String.UsageCount_key), 0); #if DEBUG preference.Enabled = (usageCount > 1); #else preference.Enabled = (usageCount > 50); #endif preference.PreferenceChange += delegate(object sender, Preference.PreferenceChangeEventArgs args) { if ((bool) args.NewValue) { new AlertDialog.Builder(ctx) .SetTitle(ctx.GetString(AppNames.AppNameResource)) .SetCancelable(false) .SetPositiveButton(Android.Resource.String.Ok, delegate(object o, DialogClickEventArgs eventArgs) { GotoDonateUrl(ctx); ((Dialog) o).Dismiss(); }) .SetMessage(Resource.String.NoDonateOption_question) .Create().Show(); } }; }
public static void PrepareDonateOptionMenu(IMenu menu, Context ctx) { var donateItem = menu.FindItem(Resource.Id.menu_donate); if (donateItem != null) { donateItem.SetVisible( !PreferenceManager.GetDefaultSharedPreferences(ctx) .GetBoolean(ctx.GetString(Resource.String.NoDonateOption_key), false) ); } }
public static void GotoUrl(Context context, int resId) { GotoUrl(context, context.GetString(resId)); }
public static bool GotoDonateUrl(Context context) { string donateUrl = context.GetString(Resource.String.donate_url, new Java.Lang.Object[]{context.Resources.Configuration.Locale.Language, context.PackageName }); try { GotoUrl(context, donateUrl); return true; } catch (ActivityNotFoundException) { Toast.MakeText(context, Resource.String.error_failed_to_launch_link, ToastLength.Long).Show(); return false; } }
public override void OnReceive (Context context, Intent intent) { var deepLinkIntent = AppInviteReferral.AddPlayStoreReferrerToIntent (intent, new Intent (context.GetString (Resource.String.action_deep_link))); LocalBroadcastManager.GetInstance (context).SendBroadcast (deepLinkIntent); }