コード例 #1
0
        public WordPopup(AnnotationActivity activity)
        {
            mContext = activity;
            mWindow  = new PopupWindow(mContext);
            if (Build.VERSION.SdkInt >= BuildVersionCodes.Honeycomb)
            {
                mWindow.SoftInputMode = SoftInput.AdjustNothing;
            }
            mWindowManager = activity.GetSystemService(Context.WindowService).JavaCast <IWindowManager>();
            history        = new List <int>();

            LayoutInflater inflater = (LayoutInflater)mContext.GetSystemService(Context.LayoutInflaterService);

            mRootView               = inflater.Inflate(Resource.Layout.Popup, null);
            mBubble                 = (LinearLayout)mRootView.FindViewById(Resource.Id.bubble);
            mScroll                 = (ScrollView)mRootView.FindViewById(Resource.Id.scroller);
            mArrowDown              = (ImageView)mRootView.FindViewById(Resource.Id.arrow_down);
            mArrowUp                = (ImageView)mRootView.FindViewById(Resource.Id.arrow_up);
            mChars                  = (TextView)mRootView.FindViewById(Resource.Id.charsText);
            mChars.LinksClickable   = true;
            mChars.MovementMethod   = LinkMovementMethod.Instance;
            mContent                = (TextView)mRootView.FindViewById(Resource.Id.content);
            mContent.LinksClickable = true;
            mContent.MovementMethod = LinkMovementMethod.Instance;
            mBookmark               = (TextView)mRootView.FindViewById(Resource.Id.bookmarkTitle);

            this.Configure(mContext);

            mWindow.SetBackgroundDrawable(new BitmapDrawable());
            mWindow.Width            = ViewGroup.LayoutParams.WrapContent;
            mWindow.Height           = ViewGroup.LayoutParams.WrapContent;
            mWindow.Touchable        = true;
            mWindow.Focusable        = false;
            mWindow.OutsideTouchable = false;
            mWindow.ContentView      = mRootView;

            Button copyButton = (Button)mRootView.FindViewById(Resource.Id.charsCopy);

            copyButton.Touch += Button_Touch;
            copyButton.Click += CopyButton_Click;

            splitButton        = (Button)mRootView.FindViewById(Resource.Id.button_split);
            splitButton.Touch += Button_Touch;
            splitButton.Click += SplitButton_Click;

            Button starButton = (Button)mRootView.FindViewById(Resource.Id.button_star);

            starButton.Touch += Button_Touch;
            starButton.Click += StarButton_Click;

            bookmarkButton        = (Button)mRootView.FindViewById(Resource.Id.button_bookmark);
            bookmarkButton.Touch += Button_Touch;
            bookmarkButton.Click += BookmarkButton_Click;

            Button shareButton = (Button)mRootView.FindViewById(Resource.Id.button_share);

            shareButton.Touch += Button_Touch;
            shareButton.Click += ShareButton_Click;

            LinearLayout popupButtons = (LinearLayout)mRootView.FindViewById(Resource.Id.popupButtons);

            Dictionaries.DictInfo[] dicts = Dictionaries.DictList;
            PackageManager          pm    = mContext.PackageManager;

            foreach (Dictionaries.DictInfo dict in dicts)
            {
                bool installed = Dictionaries.IsPackageInstalled(pm, dict.packageName);
                if (installed)
                {
                    Button dictBtn = new Button(mContext);
                    dictBtn.Text     = dict.id;
                    dictBtn.TextSize = 20;
                    dictBtn.SetTextColor(Color.ParseColor("#99333333"));
                    //dictBtn.Tag = dict;
                    dictBtn.SetPadding((int)(10 * scale), (int)(2 * scale), 0, (int)(2 * scale));
                    dictBtn.SetBackgroundColor(Color.Transparent);
                    dictBtn.SetMinimumWidth(0);
                    dictBtn.SetMinWidth(0);
                    dictBtn.SetMinimumHeight(0);
                    dictBtn.SetMinHeight(0);
                    dictBtn.SetSingleLine(true);
                    dictBtn.Touch += Button_Touch;
                    popupButtons.AddView(dictBtn);
                    dictBtn.Click += DictBtn_Click;
                }
            }
        }
コード例 #2
0
        private void CopyButton_Click(object sender, EventArgs e)
        {
            string ch = Dict.GetCh(entry);

            if (Build.VERSION.SdkInt < BuildVersionCodes.Honeycomb)
            {
                global::Android.Text.ClipboardManager clipboard = (global::Android.Text.ClipboardManager)mContext.GetSystemService(Context.ClipboardService);
                clipboard.Text = ch;
            }
            else
            {
                global::Android.Content.ClipboardManager clipboard = (global::Android.Content.ClipboardManager)mContext.GetSystemService(Context.ClipboardService);
                ClipData clip = ClipData.NewPlainText("Chinese", ch);
                clipboard.PrimaryClip = clip;
            }

            AnnotationActivity.sharedPrefs.Edit().PutString("lastText", ch).Commit();
            Toast.MakeText(mContext, "Copied to clipboard", ToastLength.Short).Show();
        }