Skip to content

Commit

Permalink
added strike through feature
Browse files Browse the repository at this point in the history
  • Loading branch information
docweirdo committed Feb 17, 2022
1 parent 4d305cd commit deb284f
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
/app/build
/captures
.externalNativeBuild
.cxx
.cxx
6 changes: 3 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ android {
defaultConfig {
applicationId "de.docweirdo.spongemock"
minSdkVersion 23
targetSdkVersion 29
versionCode 3
versionName "1.2"
targetSdkVersion 30
versionCode 4
versionName "1.3"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down
9 changes: 9 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@
<data android:mimeType="text/plain" />
</intent-filter>
</activity>
<activity
android:name=".StrikeThrough"
android:label="@string/process_text_action_name_strike_through">
<intent-filter>
<action android:name="android.intent.action.PROCESS_TEXT" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
</activity>
</application>

</manifest>
82 changes: 82 additions & 0 deletions app/src/main/java/de/docweirdo/spongemock/StrikeThrough.java
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();
}
}
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
<string name="app_name">Morbus Mock</string>
<string name="process_text_action_name_mock">Mock</string>
<string name="process_text_action_name_special">Specialize</string>
<string name="process_text_action_name_strike_through">Strike</string>
</resources>

0 comments on commit deb284f

Please sign in to comment.