-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
docweirdo
committed
Feb 17, 2022
1 parent
4d305cd
commit deb284f
Showing
5 changed files
with
96 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,4 +12,4 @@ | |
/app/build | ||
/captures | ||
.externalNativeBuild | ||
.cxx | ||
.cxx |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
app/src/main/java/de/docweirdo/spongemock/StrikeThrough.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package de.docweirdo.spongemock; | ||
|
||
import androidx.appcompat.app.AppCompatActivity; | ||
|
||
import android.content.ClipData; | ||
import android.content.ClipboardManager; | ||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.os.Bundle; | ||
import android.widget.Toast; | ||
|
||
|
||
public class StrikeThrough extends AppCompatActivity { | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
|
||
CharSequence text = getIntent() | ||
.getCharSequenceExtra(Intent.EXTRA_PROCESS_TEXT); | ||
|
||
boolean readonly = getIntent() | ||
.getBooleanExtra(Intent.EXTRA_PROCESS_TEXT_READONLY, false); | ||
|
||
assert text != null; | ||
|
||
String replacementText = strikeThrough(text.toString()); | ||
|
||
if (readonly){ | ||
|
||
ClipboardManager cm = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE); | ||
ClipData cd = ClipData.newPlainText("struck through text", replacementText); | ||
cm.setPrimaryClip(cd); | ||
|
||
Context context = getApplicationContext(); | ||
CharSequence msg = "Struck through text copied to clipboard"; | ||
int duration = Toast.LENGTH_SHORT; | ||
Toast toast = Toast.makeText(context, msg, duration); | ||
toast.show(); | ||
finish(); | ||
|
||
} else { | ||
Intent intent = new Intent(); | ||
intent.putExtra(Intent.EXTRA_PROCESS_TEXT, replacementText); | ||
setResult(RESULT_OK, intent); | ||
finish(); | ||
} | ||
} | ||
|
||
protected String strikeThrough(String text){ | ||
|
||
char cp = '\u0336'; | ||
|
||
text = insertPeriodically(text, cp, 1); | ||
|
||
return text; | ||
} | ||
|
||
public static String insertPeriodically( | ||
String text, char character, int period) | ||
{ | ||
StringBuilder builder = new StringBuilder( | ||
text.length() * (text.length()/period)+1); | ||
|
||
int index = 0; | ||
String prefix = ""; | ||
while (index < text.length()) | ||
{ | ||
// Don't put the insert in the very first iteration. | ||
// This is easier than appending it *after* each substring | ||
builder.append(prefix); | ||
prefix = "" + character; | ||
builder.append(text.substring(index, | ||
Math.min(index + period, text.length()))); | ||
index += period; | ||
} | ||
|
||
builder.append(prefix); | ||
|
||
return builder.toString(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters