trying to customize the webview context menu ...
With no success.
This commit is contained in:
parent
35480aaffc
commit
8e5934c2b1
6 changed files with 173 additions and 3 deletions
|
|
@ -343,6 +343,8 @@
|
|||
<Compile Include="Markdown\MarkdownViewModel.cs" />
|
||||
<Compile Include="Markdown\MarkdownViewRenderer.cs" />
|
||||
<Compile Include="Markdown\MarkdownWebChromeClient.cs" />
|
||||
<Compile Include="Markdown\MDContextMenu.cs" />
|
||||
<Compile Include="Markdown\MDWebView.cs" />
|
||||
<Compile Include="OAuth2\YaOAuth2Authenticator.cs" />
|
||||
<Compile Include="Rendering\ImageButtonRenderer.cs" />
|
||||
<Compile Include="Resources\Resource.Designer.cs" />
|
||||
|
|
@ -374,6 +376,9 @@
|
|||
<AndroidResource Include="Resources\layout\EditEstimate.axml">
|
||||
<SubType>Designer</SubType>
|
||||
</AndroidResource>
|
||||
<AndroidResource Include="Resources\menu\md_menu.axml">
|
||||
<SubType>Designer</SubType>
|
||||
</AndroidResource>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<AndroidResource Include="Resources\drawable\icon.png" />
|
||||
|
|
@ -383,7 +388,9 @@
|
|||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<AndroidResource Include="Resources\layout\Tabbar.axml" />
|
||||
<AndroidResource Include="Resources\layout\Toolbar.axml" />
|
||||
<AndroidResource Include="Resources\layout\Toolbar.axml">
|
||||
<SubType>Designer</SubType>
|
||||
</AndroidResource>
|
||||
<AndroidResource Include="Resources\values\styles.xml">
|
||||
<SubType>Designer</SubType>
|
||||
</AndroidResource>
|
||||
|
|
|
|||
73
BookAStar/BookAStar.Droid/Markdown/MDContextMenu.cs
Normal file
73
BookAStar/BookAStar.Droid/Markdown/MDContextMenu.cs
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
using Android.App;
|
||||
using Android.Content;
|
||||
using Android.OS;
|
||||
using Android.Runtime;
|
||||
using Android.Views;
|
||||
using Android.Widget;
|
||||
using Android.Support.V7.App;
|
||||
using XLabs.Ioc;
|
||||
using XLabs.Platform.Mvvm;
|
||||
using XLabs.Forms;
|
||||
using static Android.Views.View;
|
||||
|
||||
namespace BookAStar.Droid.Markdown
|
||||
{
|
||||
class MDContextMenu : AppCompatDialog
|
||||
{
|
||||
private ActionMode mActionMode = null;
|
||||
public MDContextMenu(Context context) : base(context)
|
||||
{
|
||||
|
||||
}
|
||||
public override void OnActionModeStarted(ActionMode mode)
|
||||
{
|
||||
if (mActionMode == null)
|
||||
{
|
||||
mActionMode = mode;
|
||||
var menu = mode.Menu;
|
||||
// Remove the default menu items (select all, copy, paste, search)
|
||||
menu.Clear();
|
||||
|
||||
// If you want to keep any of the defaults,
|
||||
// remove the items you don't want individually:
|
||||
// menu.removeItem(android.R.id.[id_of_item_to_remove])
|
||||
|
||||
// Inflate your own menu items
|
||||
mode.MenuInflater.Inflate(Resource.Menu.md_menu, menu);
|
||||
|
||||
}
|
||||
mActionMode = mode;
|
||||
base.OnActionModeStarted(mode);
|
||||
}
|
||||
public override void OnActionModeFinished(ActionMode mode)
|
||||
{
|
||||
base.OnActionModeFinished(mode);
|
||||
}
|
||||
protected override void OnCreate(Bundle savedInstanceState)
|
||||
{
|
||||
base.OnCreate(savedInstanceState);
|
||||
}
|
||||
public void OnCreateContextMenu(IContextMenu menu, View v, IContextMenuContextMenuInfo menuInfo)
|
||||
{
|
||||
/* if (menuInfo!=null)
|
||||
{
|
||||
var info = menuInfo.ToString();
|
||||
}
|
||||
menu.Add(0, 0, 0, "test");
|
||||
var subMenu = menu.AddSubMenu(
|
||||
0, 1, 1, "...");
|
||||
subMenu.Add(0, 3, 0, "nkjnkjn");
|
||||
var app = Resolver.Resolve<IXFormsApp>() as IXFormsApp<XFormsCompatApplicationDroid>;
|
||||
|
||||
var mgr = ClipboardManager.FromContext(app.AppContext);
|
||||
if (mgr.HasText)
|
||||
menu.Add(0, 0, 0, "Coller!");*/
|
||||
//base.OnCreateContextMenu(menu, v, menuInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
28
BookAStar/BookAStar.Droid/Markdown/MDWebView.cs
Normal file
28
BookAStar/BookAStar.Droid/Markdown/MDWebView.cs
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
using Android.App;
|
||||
using Android.Content;
|
||||
using Android.OS;
|
||||
using Android.Runtime;
|
||||
using Android.Views;
|
||||
using Android.Widget;
|
||||
using Android.Webkit;
|
||||
|
||||
namespace BookAStar.Droid.Markdown
|
||||
{
|
||||
class MDWebView : WebView
|
||||
{
|
||||
public MDWebView (Context context) : base (context)
|
||||
{
|
||||
}
|
||||
|
||||
public override ActionMode StartActionMode(ActionMode.ICallback callback)
|
||||
{
|
||||
return base.StartActionMode(callback);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -12,6 +12,11 @@ using Android.Views;
|
|||
namespace BookAStar.Droid
|
||||
{
|
||||
using Markdown;
|
||||
using XLabs.Forms;
|
||||
using XLabs.Ioc;
|
||||
using XLabs.Platform.Mvvm;
|
||||
using static View;
|
||||
|
||||
public class MarkdownViewRenderer : ViewRenderer<MarkdownView, WebView>
|
||||
{
|
||||
private WebView editorView;
|
||||
|
|
@ -35,7 +40,9 @@ namespace BookAStar.Droid
|
|||
{
|
||||
if (view == null || xview == null) return;
|
||||
var vch = view.ContentHeight;
|
||||
xview.HeightRequest = vch > xview.MinimumHeightRequest ? vch : xview.MinimumHeightRequest;
|
||||
// var oldH = xview.Height;
|
||||
var newH = vch > xview.MinimumHeightRequest ? vch : xview.MinimumHeightRequest;
|
||||
xview.HeightRequest = newH;
|
||||
}
|
||||
|
||||
protected override void OnElementChanged(ElementChangedEventArgs<MarkdownView> e)
|
||||
|
|
@ -73,7 +80,7 @@ namespace BookAStar.Droid
|
|||
Control.LoadUrl(string.Format("javascript: {0}", script));
|
||||
}
|
||||
}
|
||||
|
||||
MDContextMenu contextMenu;
|
||||
private WebView CreateNativeControl()
|
||||
{
|
||||
editorView = new WebView(Context);
|
||||
|
|
@ -93,9 +100,18 @@ namespace BookAStar.Droid
|
|||
EditorView.Settings.DomStorageEnabled = true;
|
||||
EditorView.AddJavascriptInterface(new JsBridgeMarkdown(this), "jsBridge");
|
||||
EditorView.ViewTreeObserver.PreDraw += ViewTreeObserver_PreDraw;
|
||||
//var app = Resolver.Resolve<IXFormsApp>() as IXFormsApp<XFormsCompatApplicationDroid>;
|
||||
//contextMenu = new MDContextMenu(app.AppContext);
|
||||
//EditorView.SetOnCreateContextMenuListener(contextMenu);
|
||||
|
||||
return EditorView;
|
||||
}
|
||||
|
||||
private void EditorView_Touch(object sender, TouchEventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void ViewTreeObserver_PreDraw(object sender, ViewTreeObserver.PreDrawEventArgs e)
|
||||
{
|
||||
AdjustHeightRequest(Element, Control);
|
||||
|
|
|
|||
33
BookAStar/BookAStar.Droid/Resources/menu/md_menu.axml
Normal file
33
BookAStar/BookAStar.Droid/Resources/menu/md_menu.axml
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:id="@+id/copy"
|
||||
android:title="@string/copy"/>
|
||||
<group android:id="@+id/group">
|
||||
<item android:id="@+id/past"
|
||||
android:title="@string/past"
|
||||
android:showAsAction="ifRoom|withText"/>
|
||||
</group>
|
||||
<item android:id="@+id/submenu_character"
|
||||
android:title="@string/character" >
|
||||
<menu>
|
||||
<item android:id="@+id/bold"
|
||||
android:title="@string/bold" />
|
||||
<item android:id="@+id/italic"
|
||||
android:title="@string/italic" />
|
||||
<item android:id="@+id/underline"
|
||||
android:title="@string/underline" />
|
||||
</menu>
|
||||
</item>
|
||||
<item android:id="@+id/submenu_paragraph"
|
||||
android:title="@string/paragraph" >
|
||||
<menu>
|
||||
|
||||
<item android:id="@+id/header1"
|
||||
android:onClick="onGroupItemClick"
|
||||
android:title="@string/header1" />
|
||||
<item android:id="@+id/header2"
|
||||
android:onClick="onGroupItemClick"
|
||||
android:title="@string/header2" />
|
||||
</menu>
|
||||
</item>
|
||||
</menu>
|
||||
|
|
@ -17,6 +17,19 @@
|
|||
<string name="google_app_id">325408689282</string>
|
||||
<string name="pref_screen_title">Comptes Booking Star</string>
|
||||
<string name="account_authenticator_label">Comptes Booking Star</string>
|
||||
|
||||
<string name="copy">Copier</string>
|
||||
<string name="past">Coller</string>
|
||||
|
||||
<string name="character">Caractère</string>
|
||||
<string name="bold">Gras</string>
|
||||
<string name="italic">Italique</string>
|
||||
<string name="underline">Sousligné</string>
|
||||
|
||||
<string name="paragraph">Paragraphe</string>
|
||||
<string name="header1">Titre</string>
|
||||
<string name="header2">Sous-titre</string>
|
||||
|
||||
|
||||
<string name="accounts">Comptes</string>
|
||||
<string name="bookingstar_accounts_pref_screen_summary">
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue