void Refresh(object o = null) { string what = o == null ? "" : (string)o; if (activeObject == null || this.Activity == null) return; Activity.RunOnUiThread(() => { if(Activity == null) return; // Assign this item's values to the various subviews ctrl.SupportActionBar.SetDisplayShowHomeEnabled(true); string name = activeObject.Name == null ? "" : activeObject.Name; if (what.Equals ("") || what.Equals ("Name")) { if (activeObject is Task) ctrl.SupportActionBar.Title = (((Task)activeObject).Complete ? (((Task)activeObject).CorrectState == TaskCorrectness.NotCorrect ? Strings.TaskNotCorrect : Strings.TaskCorrect) + " " : "") + name; else ctrl.SupportActionBar.Title = name; } if (what.Equals ("") || what.Equals ("Media")) { if (activeObject.Image != null) { using (Bitmap bm = ctrl.ConvertMediaToBitmap(activeObject.Image)) { _imageView.SetImageBitmap(null); _imageView.SetImageBitmap(bm); } _imageView.Visibility = ViewStates.Visible; } else { _imageView.Visibility = ViewStates.Gone; } } if (what.Equals ("") || what.Equals ("Description")) { if (!String.IsNullOrWhiteSpace (activeObject.Description)) { _textDescription.Visibility = ViewStates.Visible; _textDescription.Text = activeObject.Description; // Html.FromHtml(activeObject.HTML.Replace("<BR>", "<br>").Replace("<br>\n", "<br>").Replace("\n", "<br>")); _textDescription.Gravity = Main.Prefs.TextAlignment.ToSystem(); _textDescription.SetTextSize(global::Android.Util.ComplexUnitType.Sp, (float)Main.Prefs.TextSize); } else { _textDescription.Visibility = ViewStates.Visible; _textDescription.Text = ""; _textDescription.Gravity = Main.Prefs.TextAlignment.ToSystem(); _textDescription.SetTextSize(global::Android.Util.ComplexUnitType.Sp, (float)Main.Prefs.TextSize); } } // Tasks don't have any command button or direction if (activeObject is Task) { _layoutBottom.Visibility = ViewStates.Gone; return; } // Check, if the bottom should be displayed or not _layoutButtons.Visibility = ((Thing)activeObject).ActiveCommands.Count == 0 ? ViewStates.Invisible : ViewStates.Visible; _layoutDirection.Visibility = ctrl.Engine.Player.Inventory.Contains(activeObject) ? ViewStates.Gone : (((Thing)activeObject).VectorFromPlayer == null ? ViewStates.Gone : ViewStates.Visible); _layoutBottom.Visibility = (_layoutButtons.Visibility == ViewStates.Visible || _layoutDirection.Visibility == ViewStates.Visible) ? ViewStates.Visible : ViewStates.Gone; if (_layoutButtons.Visibility == ViewStates.Visible) { _layoutButtons.RemoveAllViews (); commands = ((Thing)activeObject).ActiveCommands; _layoutButtons.WeightSum = 1; if (commands.Count > 0) { Button btnView = new Button (Activity.ApplicationContext); btnView.Text = commands.Count == 1 ? commands[0].Text : GetString(Resource.String.screen_detail_commands); btnView.SetTextColor(Color.White); btnView.SetHighlightColor(Color.White); btnView.SetBackgroundResource(Resource.Drawable.apptheme_btn_default_holo_light); btnView.LayoutChange += (object sender, View.LayoutChangeEventArgs e) => SetTextScale(btnView); btnView.Click += OnButtonClicked; // Set size of button Android.Views.ViewGroup.LayoutParams lp = new Android.Views.ViewGroup.LayoutParams(Android.Views.ViewGroup.LayoutParams.FillParent, Android.Views.ViewGroup.LayoutParams.FillParent); // Add button to view _layoutButtons.AddView (btnView, lp); } } if (_layoutDirection.Visibility == ViewStates.Visible) { // Draw direction content var direction = ((Thing)activeObject).VectorFromPlayer; if ( direction != null) { _textDirection.Visibility = ViewStates.Visible; _imageDirection.Visibility = ViewStates.Visible; _textDirection.Text = direction.Distance.BestMeasureAs(DistanceUnit.Meters); Bitmap bm; _imageDirection.SetImageBitmap(null); if (direction.Distance.Value == 0) { _imageDirection.SetImageBitmap (BitmapFactory.DecodeResource(Resources, Resource.Drawable.ic_direction_position)); } else { _imageDirection.SetImageBitmap(BitmapArrow.Draw(Math.Min(_imageDirection.Width, _imageDirection.Height), direction.Bearing.Value + Main.GPS.Bearing)); // AsyncImageFromDirection.LoadBitmap(_imageDirection, direction.Bearing.Value + Main.GPS.Bearing, 48, 48); // TODO: // Remove // bm = ctrl.DrawArrow (direction.Bearing.Value + Main.GPS.Bearing); // _imageDirection.SetImageBitmap (bm); // bm = null; } } } // Resize scrollview _layoutDefault.Invalidate(); }); }
/* (non-Javadoc) * @see android.app.Activity#setContentView(android.view.View, android.view.ViewGroup.LayoutParams) */ //@Override public override void SetContentView(View v, LayoutParams lparams) { base.SetContentView(v, lparams); mHelper.registerAboveContentView(v, lparams); }
protected virtual void LoadView(SearchHandler searchHandler) { var query = searchHandler.Query; var placeholder = searchHandler.Placeholder; LP lp; var context = Context; _cardView = new CardView(context); using (lp = new LayoutParams(LP.MatchParent, LP.MatchParent)) _cardView.LayoutParameters = lp; var linearLayout = new LinearLayout(context); using (lp = new LP(LP.MatchParent, LP.MatchParent)) linearLayout.LayoutParameters = lp; linearLayout.Orientation = Orientation.Horizontal; _cardView.AddView(linearLayout); int padding = (int)context.ToPixels(8); _searchButton = CreateImageButton(context, searchHandler, SearchHandler.QueryIconProperty, Resource.Drawable.abc_ic_search_api_material, padding, 0, "SearchIcon"); lp = new LinearLayout.LayoutParams(0, LP.MatchParent) { Gravity = GravityFlags.Fill, Weight = 1 }; _textBlock = new AppCompatAutoCompleteTextView(context) { LayoutParameters = lp, Text = query, Hint = placeholder, ImeOptions = ImeAction.Done }; lp.Dispose(); _textBlock.Enabled = searchHandler.IsSearchEnabled; _textBlock.SetBackground(null); _textBlock.SetPadding(padding, 0, padding, 0); _textBlock.SetSingleLine(true); _textBlock.Threshold = 1; _textBlock.Adapter = new ShellSearchViewAdapter(SearchHandler, _shellContext); _textBlock.ItemClick += OnTextBlockItemClicked; _textBlock.SetDropDownBackgroundDrawable(new ClipDrawableWrapper(_textBlock.DropDownBackground)); // A note on accessibility. The _textBlocks hint is what android defaults to reading in the screen // reader. Therefore, we do not need to set something else. _clearButton = CreateImageButton(context, searchHandler, SearchHandler.ClearIconProperty, Resource.Drawable.abc_ic_clear_material, 0, padding, nameof(SearchHandler.ClearIcon)); _clearPlaceholderButton = CreateImageButton(context, searchHandler, SearchHandler.ClearPlaceholderIconProperty, -1, 0, padding, nameof(SearchHandler.ClearPlaceholderIcon)); linearLayout.AddView(_searchButton); linearLayout.AddView(_textBlock); linearLayout.AddView(_clearButton); linearLayout.AddView(_clearPlaceholderButton); UpdateClearButtonState(); // hook all events down here to avoid getting events while doing setup searchHandler.PropertyChanged += OnSearchHandlerPropertyChanged; _textBlock.AddTextChangedListener(this); _textBlock.SetOnEditorActionListener(this); _clearButton.Click += OnClearButtonClicked; _clearPlaceholderButton.Click += OnClearPlaceholderButtonClicked; _searchButton.Click += OnSearchButtonClicked; AddView(_cardView); linearLayout.Dispose(); }
/* (non-Javadoc) * @see com.jeremyfeinstein.slidingmenu.lib.app.SlidingActivityBase#setBehindContentView(android.view.View, android.view.ViewGroup.LayoutParams) */ public void setBehindContentView(View v, LayoutParams lparams) { mHelper.setBehindContentView(v, lparams); }
protected virtual BottomSheetDialog CreateMoreBottomSheet(Action <int, BottomSheetDialog> selectCallback) { var bottomSheetDialog = new BottomSheetDialog(Context); var bottomSheetLayout = new LinearLayout(Context); using (var bottomShellLP = new LP(LP.MatchParent, LP.WrapContent)) bottomSheetLayout.LayoutParameters = bottomShellLP; bottomSheetLayout.Orientation = Orientation.Vertical; // handle the more tab var items = ((IShellItemController)ShellItem).GetItems(); for (int i = _bottomView.MaxItemCount - 1; i < items.Count; i++) { var closure_i = i; var shellContent = ShellItem.Items[i]; using (var innerLayout = new LinearLayout(Context)) { innerLayout.SetClipToOutline(true); innerLayout.SetBackground(CreateItemBackgroundDrawable()); innerLayout.SetPadding(0, (int)Context.ToPixels(6), 0, (int)Context.ToPixels(6)); innerLayout.Orientation = Orientation.Horizontal; using (var param = new LP(LP.MatchParent, LP.WrapContent)) innerLayout.LayoutParameters = param; // technically the unhook isn't needed // we dont even unhook the events that dont fire void clickCallback(object s, EventArgs e) { selectCallback(closure_i, bottomSheetDialog); if (!innerLayout.IsDisposed()) { innerLayout.Click -= clickCallback; } } innerLayout.Click += clickCallback; var image = new ImageView(Context); var lp = new LinearLayout.LayoutParams((int)Context.ToPixels(32), (int)Context.ToPixels(32)) { LeftMargin = (int)Context.ToPixels(20), RightMargin = (int)Context.ToPixels(20), TopMargin = (int)Context.ToPixels(6), BottomMargin = (int)Context.ToPixels(6), Gravity = GravityFlags.Center }; image.LayoutParameters = lp; lp.Dispose(); ShellContext.ApplyDrawableAsync(shellContent, ShellSection.IconProperty, icon => { if (!image.IsDisposed()) { var color = Color.Black.MultiplyAlpha(0.6).ToAndroid(); icon.SetTint(color); image.SetImageDrawable(icon); } }); innerLayout.AddView(image); using (var text = new TextView(Context)) { text.Typeface = "sans-serif-medium".ToTypeFace(); text.SetTextColor(AColor.Black); text.Text = shellContent.Title; lp = new LinearLayout.LayoutParams(0, LP.WrapContent) { Gravity = GravityFlags.Center, Weight = 1 }; text.LayoutParameters = lp; lp.Dispose(); innerLayout.AddView(text); } bottomSheetLayout.AddView(innerLayout); } } bottomSheetDialog.SetContentView(bottomSheetLayout); bottomSheetLayout.Dispose(); return(bottomSheetDialog); }