Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
halo
packages_apps_ExactCalculator
Commits
380f24f1
Commit
380f24f1
authored
10 years ago
by
Hans Boehm
Committed by
Android Git Automerger
10 years ago
Browse files
Options
Download
Plain Diff
am
7f83e36b
: Improve copy/paste menu appearance
* commit '
7f83e36b
': Improve copy/paste menu appearance
parents
a8046043
7f83e36b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
48 additions
and
2 deletions
+48
-2
res/layout/display.xml
res/layout/display.xml
+1
-0
src/com/android/calculator2/CalculatorResult.java
src/com/android/calculator2/CalculatorResult.java
+33
-1
src/com/android/calculator2/CalculatorText.java
src/com/android/calculator2/CalculatorText.java
+14
-1
No files found.
res/layout/display.xml
View file @
380f24f1
...
...
@@ -57,6 +57,7 @@
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:layout_below=
"@id/formula"
android:bufferType=
"spannable"
android:singleLine=
"true"
android:textColor=
"@color/display_result_text_color"
/>
...
...
This diff is collapsed.
Click to expand it.
src/com/android/calculator2/CalculatorResult.java
View file @
380f24f1
...
...
@@ -20,10 +20,13 @@ import android.content.ClipData;
import
android.content.ClipDescription
;
import
android.content.ClipboardManager
;
import
android.content.Context
;
import
android.graphics.Rect
;
import
android.text.Layout
;
import
android.text.Spannable
;
import
android.text.SpannableString
;
import
android.text.Spanned
;
import
android.text.TextPaint
;
import
android.text.style.BackgroundColorSpan
;
import
android.text.style.ForegroundColorSpan
;
import
android.util.AttributeSet
;
import
android.view.ActionMode
;
...
...
@@ -522,11 +525,26 @@ public class CalculatorResult extends AlignedTextView {
// Copy support:
private
ActionMode
.
Callback
mCopyActionModeCallback
=
new
ActionMode
.
Callback
()
{
private
ActionMode
.
Callback2
mCopyActionModeCallback
=
new
ActionMode
.
Callback2
()
{
private
BackgroundColorSpan
mHighlightSpan
;
private
void
highlightResult
()
{
final
Spannable
text
=
(
Spannable
)
getText
();
mHighlightSpan
=
new
BackgroundColorSpan
(
getHighlightColor
());
text
.
setSpan
(
mHighlightSpan
,
0
,
text
.
length
(),
Spanned
.
SPAN_EXCLUSIVE_EXCLUSIVE
);
}
private
void
unhighlightResult
()
{
final
Spannable
text
=
(
Spannable
)
getText
();
text
.
removeSpan
(
mHighlightSpan
);
}
@Override
public
boolean
onCreateActionMode
(
ActionMode
mode
,
Menu
menu
)
{
MenuInflater
inflater
=
mode
.
getMenuInflater
();
inflater
.
inflate
(
R
.
menu
.
copy
,
menu
);
highlightResult
();
return
true
;
}
...
...
@@ -549,8 +567,22 @@ public class CalculatorResult extends AlignedTextView {
@Override
public
void
onDestroyActionMode
(
ActionMode
mode
)
{
unhighlightResult
();
mActionMode
=
null
;
}
@Override
public
void
onGetContentRect
(
ActionMode
mode
,
View
view
,
Rect
outRect
)
{
super
.
onGetContentRect
(
mode
,
view
,
outRect
);
outRect
.
left
+=
getPaddingLeft
();
outRect
.
top
+=
getPaddingTop
();
outRect
.
right
-=
getPaddingRight
();
outRect
.
bottom
-=
getPaddingBottom
();
final
int
width
=
(
int
)
Layout
.
getDesiredWidth
(
getText
(),
getPaint
());
if
(
width
<
outRect
.
width
())
{
outRect
.
left
=
outRect
.
right
-
width
;
}
}
};
public
boolean
stopActionMode
()
{
...
...
This diff is collapsed.
Click to expand it.
src/com/android/calculator2/CalculatorText.java
View file @
380f24f1
...
...
@@ -20,6 +20,7 @@ import android.content.ClipData;
import
android.content.ClipboardManager
;
import
android.content.Context
;
import
android.content.res.TypedArray
;
import
android.graphics.Rect
;
import
android.text.Layout
;
import
android.text.TextPaint
;
import
android.text.method.ScrollingMovementMethod
;
...
...
@@ -37,7 +38,8 @@ import android.widget.TextView;
*/
public
class
CalculatorText
extends
AlignedTextView
implements
View
.
OnLongClickListener
{
private
final
ActionMode
.
Callback
mPasteActionModeCallback
=
new
ActionMode
.
Callback
()
{
private
final
ActionMode
.
Callback2
mPasteActionModeCallback
=
new
ActionMode
.
Callback2
()
{
@Override
public
boolean
onActionItemClicked
(
ActionMode
mode
,
MenuItem
item
)
{
if
(
item
.
getItemId
()
==
R
.
id
.
menu_paste
)
{
...
...
@@ -53,6 +55,7 @@ public class CalculatorText extends AlignedTextView implements View.OnLongClickL
final
ClipboardManager
clipboard
=
(
ClipboardManager
)
getContext
()
.
getSystemService
(
Context
.
CLIPBOARD_SERVICE
);
if
(
clipboard
.
hasPrimaryClip
())
{
bringPointIntoView
(
length
());
MenuInflater
inflater
=
mode
.
getMenuInflater
();
inflater
.
inflate
(
R
.
menu
.
paste
,
menu
);
return
true
;
...
...
@@ -70,6 +73,16 @@ public class CalculatorText extends AlignedTextView implements View.OnLongClickL
public
void
onDestroyActionMode
(
ActionMode
mode
)
{
mActionMode
=
null
;
}
@Override
public
void
onGetContentRect
(
ActionMode
mode
,
View
view
,
Rect
outRect
)
{
super
.
onGetContentRect
(
mode
,
view
,
outRect
);
outRect
.
top
+=
getTotalPaddingTop
();
outRect
.
right
-=
getTotalPaddingRight
();
outRect
.
bottom
-=
getTotalPaddingBottom
();
// Encourage menu positioning towards the right, possibly over formula.
outRect
.
left
=
outRect
.
right
;
}
};
// Temporary paint for use in layout methods.
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment