copy the result or formula to clipboard on long press
This commit is contained in:
parent
9829186618
commit
f83a63daf8
|
@ -1,5 +1,7 @@
|
||||||
package com.simplemobiletools.calculator;
|
package com.simplemobiletools.calculator;
|
||||||
|
|
||||||
|
import android.content.ClipData;
|
||||||
|
import android.content.ClipboardManager;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
@ -122,6 +124,32 @@ public class MainActivity extends AppCompatActivity implements Calculator {
|
||||||
calc.numpadClicked(id);
|
calc.numpadClicked(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@OnLongClick(R.id.formula)
|
||||||
|
public boolean formulaLongPressed() {
|
||||||
|
copyToClipboard(false);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@OnLongClick(R.id.result)
|
||||||
|
public boolean resultLongPressed() {
|
||||||
|
copyToClipboard(true);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void copyToClipboard(boolean copyResult) {
|
||||||
|
String value;
|
||||||
|
if (copyResult) {
|
||||||
|
value = result.getText().toString();
|
||||||
|
} else {
|
||||||
|
value = formula.getText().toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
final ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
|
||||||
|
final ClipData clip = ClipData.newPlainText(getResources().getString(R.string.app_name), value);
|
||||||
|
clipboard.setPrimaryClip(clip);
|
||||||
|
Utils.showToast(getApplicationContext(), R.string.copied_to_clipboard);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setValue(String value) {
|
public void setValue(String value) {
|
||||||
result.setText(value);
|
result.setText(value);
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
package com.simplemobiletools.calculator;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
public class Utils {
|
||||||
|
public static void showToast(Context context, int resId) {
|
||||||
|
Toast.makeText(context, context.getResources().getString(resId), Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,5 +1,6 @@
|
||||||
<resources>
|
<resources>
|
||||||
<string name="app_name">Simple Calculator</string>
|
<string name="app_name">Simple Calculator</string>
|
||||||
|
<string name="copied_to_clipboard">Value copied to clipboard</string>
|
||||||
|
|
||||||
<!-- About -->
|
<!-- About -->
|
||||||
<string name="about">About</string>
|
<string name="about">About</string>
|
||||||
|
|
Loading…
Reference in New Issue