-
-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#116 "Help: format" option in the menu
- Loading branch information
1 parent
45ce901
commit 6760966
Showing
7 changed files
with
318 additions
and
7 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
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
105 changes: 105 additions & 0 deletions
105
app/src/main/java/it/niedermann/owncloud/notes/formattinghelp/FormattingHelpActivity.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,105 @@ | ||
package it.niedermann.owncloud.notes.formattinghelp; | ||
|
||
import android.content.Intent; | ||
import android.net.Uri; | ||
import android.os.Bundle; | ||
import android.text.TextUtils; | ||
import android.widget.Toast; | ||
|
||
import androidx.annotation.Nullable; | ||
|
||
import com.yydcdut.markdown.MarkdownProcessor; | ||
import com.yydcdut.markdown.syntax.text.TextFactory; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
|
||
import it.niedermann.owncloud.notes.R; | ||
import it.niedermann.owncloud.notes.android.fragment.ExceptionDialogFragment; | ||
import it.niedermann.owncloud.notes.branding.BrandedActivity; | ||
import it.niedermann.owncloud.notes.databinding.ActivityFormattingHelpBinding; | ||
|
||
import static it.niedermann.owncloud.notes.util.MarkDownUtil.CHECKBOX_CHECKED_MINUS; | ||
import static it.niedermann.owncloud.notes.util.MarkDownUtil.CHECKBOX_CHECKED_STAR; | ||
import static it.niedermann.owncloud.notes.util.MarkDownUtil.CHECKBOX_UNCHECKED_MINUS; | ||
import static it.niedermann.owncloud.notes.util.MarkDownUtil.CHECKBOX_UNCHECKED_STAR; | ||
import static it.niedermann.owncloud.notes.util.MarkDownUtil.getMarkDownConfiguration; | ||
import static it.niedermann.owncloud.notes.util.MarkDownUtil.parseCompat; | ||
|
||
public class FormattingHelpActivity extends BrandedActivity { | ||
|
||
private static final String TAG = FormattingHelpActivity.class.getSimpleName(); | ||
private ActivityFormattingHelpBinding binding; | ||
|
||
@Override | ||
public void onCreate(@Nullable Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
|
||
binding = ActivityFormattingHelpBinding.inflate(getLayoutInflater()); | ||
setContentView(binding.getRoot()); | ||
|
||
setSupportActionBar(binding.toolbar); | ||
final StringBuilder stringBuilder = new StringBuilder(); | ||
try (BufferedReader reader = new BufferedReader(new InputStreamReader(getResources().openRawResource(R.raw.formatting_help)))) { | ||
String line; | ||
while ((line = reader.readLine()) != null) { | ||
stringBuilder.append(line).append("\n"); | ||
} | ||
} catch (IOException e) { | ||
ExceptionDialogFragment.newInstance(e).show(getSupportFragmentManager(), ExceptionDialogFragment.class.getSimpleName()); | ||
} | ||
|
||
String content = stringBuilder.toString(); | ||
|
||
final MarkdownProcessor markdownProcessor = new MarkdownProcessor(this); | ||
markdownProcessor.factory(TextFactory.create()); | ||
markdownProcessor.config(getMarkDownConfiguration(binding.content.getContext()) | ||
.setOnTodoClickCallback((view, line, lineNumber) -> { | ||
try { | ||
String[] lines = TextUtils.split(content, "\\r?\\n"); | ||
/* | ||
* Workaround for RxMarkdown-bug: | ||
* When (un)checking a checkbox in a note which contains code-blocks, the "`"-characters get stripped out in the TextView and therefore the given lineNumber is wrong | ||
* Find number of lines starting with ``` before lineNumber | ||
*/ | ||
for (int i = 0; i < lines.length; i++) { | ||
if (lines[i].startsWith("```")) { | ||
lineNumber++; | ||
} | ||
if (i == lineNumber) { | ||
break; | ||
} | ||
} | ||
|
||
/* | ||
* Workaround for multiple RxMarkdown-bugs: | ||
* When (un)checking a checkbox which is in the last line, every time it gets toggled, the last character of the line gets lost. | ||
* When (un)checking a checkbox, every markdown gets stripped in the given line argument | ||
*/ | ||
if (lines[lineNumber].startsWith(CHECKBOX_UNCHECKED_MINUS) || lines[lineNumber].startsWith(CHECKBOX_UNCHECKED_STAR)) { | ||
lines[lineNumber] = lines[lineNumber].replace(CHECKBOX_UNCHECKED_MINUS, CHECKBOX_CHECKED_MINUS); | ||
lines[lineNumber] = lines[lineNumber].replace(CHECKBOX_UNCHECKED_STAR, CHECKBOX_CHECKED_STAR); | ||
} else { | ||
lines[lineNumber] = lines[lineNumber].replace(CHECKBOX_CHECKED_MINUS, CHECKBOX_UNCHECKED_MINUS); | ||
lines[lineNumber] = lines[lineNumber].replace(CHECKBOX_CHECKED_STAR, CHECKBOX_UNCHECKED_STAR); | ||
} | ||
|
||
binding.content.setText(parseCompat(markdownProcessor, TextUtils.join("\n", lines))); | ||
} catch (IndexOutOfBoundsException e) { | ||
Toast.makeText(this, R.string.checkbox_could_not_be_toggled, Toast.LENGTH_SHORT).show(); | ||
e.printStackTrace(); | ||
} | ||
return line; | ||
} | ||
) | ||
.setOnLinkClickCallback((view, link) -> startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(link)))) | ||
.build()); | ||
binding.content.setText(parseCompat(markdownProcessor, content)); | ||
} | ||
|
||
@Override | ||
public void applyBrand(int mainColor, int textColor) { | ||
|
||
} | ||
} |
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,5 @@ | ||
<vector android:height="24dp" android:tint="#757575" | ||
android:viewportHeight="24" android:viewportWidth="24" | ||
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<path android:fillColor="#757575" android:pathData="M11,18h2v-2h-2v2zM12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM12,20c-4.41,0 -8,-3.59 -8,-8s3.59,-8 8,-8 8,3.59 8,8 -3.59,8 -8,8zM12,6c-2.21,0 -4,1.79 -4,4h2c0,-1.1 0.9,-2 2,-2s2,0.9 2,2c0,2 -3,1.75 -3,5h2c0,-2.25 3,-2.5 3,-5 0,-2.21 -1.79,-4 -4,-4z"/> | ||
</vector> |
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,43 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:background="@color/primary" | ||
android:orientation="vertical"> | ||
|
||
<com.google.android.material.appbar.AppBarLayout | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content"> | ||
|
||
<androidx.appcompat.widget.Toolbar | ||
android:id="@+id/toolbar" | ||
android:layout_width="match_parent" | ||
android:layout_height="?attr/actionBarSize" | ||
android:background="?attr/colorPrimary" | ||
app:contentInsetStartWithNavigation="0dp" | ||
app:navigationIcon="@drawable/ic_arrow_back_grey600_24dp" | ||
app:title="@string/action_formatting_help" | ||
app:titleMarginStart="0dp" /> | ||
</com.google.android.material.appbar.AppBarLayout> | ||
|
||
<ScrollView | ||
android:id="@+id/scrollView" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:orientation="vertical" | ||
tools:context="it.niedermann.owncloud.notes.android.activity.EditNoteActivity"> | ||
|
||
<com.yydcdut.markdown.MarkdownTextView | ||
android:id="@+id/content" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:padding="@dimen/spacer_2x" | ||
android:textAppearance="?android:attr/textAppearanceMedium" | ||
android:textColor="@color/fg_default" | ||
android:textIsSelectable="true" | ||
android:theme="@style/textViewStyle" | ||
tools:text="@tools:sample/lorem/random" /> | ||
</ScrollView> | ||
</LinearLayout> |
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,150 @@ | ||
# Context based formatting | ||
|
||
A major design goal of the Notes app is to provide a distraction free tool. Though you will be able to format your texts with Markdown. For various of the below mentioned examples, you can use shortcuts so you can format your notes without typing in the codes below. | ||
Just select a range of text or tap on your cursor at any position and you will get a popup menu which contains next to the default entries `Cut`, `Copy`, `Select all` entries like `Link` or `Checkbox`. | ||
|
||
--- | ||
|
||
# Text | ||
|
||
It's very easy to make some words **bold** and other words *italic* with Markdown. You can ~~strike~~ some words through and even [link to Google](http://google.com). | ||
|
||
``` | ||
It's very easy to make some words **bold** and other words *italic* with Markdown. You can ~~strike~~ some words through and even [link to Google](http://google.com). | ||
``` | ||
|
||
--- | ||
|
||
# Lists | ||
|
||
Sometimes you want numbered lists: | ||
|
||
1. One | ||
2. Two | ||
3. Three | ||
|
||
Sometimes you want bullet points: | ||
|
||
* Start a line with a star | ||
* Profit! | ||
|
||
Alternatively, | ||
|
||
- Dashes work just as well | ||
- And if you have sub points, put two spaces before the dash or star: | ||
- Like this | ||
- And this | ||
|
||
``` | ||
Sometimes you want numbered lists: | ||
1. One | ||
2. Two | ||
3. Three | ||
Sometimes you want bullet points: | ||
* Start a line with a star | ||
* Profit! | ||
Alternatively, | ||
- Dashes work just as well | ||
- And if you have sub points, put two spaces before the dash or star: | ||
- Like this | ||
- And this | ||
``` | ||
|
||
--- | ||
|
||
# Checkbox | ||
|
||
To create a checkbox, use a list followed by brackets | ||
|
||
- [ ] Item 1 | ||
* [ ] Item 2 | ||
|
||
``` | ||
To create a checkbox, use a list followed by brackets | ||
- [ ] Item 1 | ||
* [ ] Item 2 | ||
``` | ||
|
||
--- | ||
|
||
# Structured documents | ||
|
||
Sometimes it's useful to have different levels of headings to structure your documents. Start lines with a `#` to create headings. Multiple `##` in a row denote smaller heading sizes. | ||
|
||
### This is a third-tier heading | ||
|
||
You can use one `#` all the way up to `######` six for different heading sizes. | ||
|
||
If you'd like to quote someone, use the > character before the line: | ||
|
||
> Coffee. The finest organic suspension ever devised... I beat the Borg with it. | ||
> - Captain Janeway | ||
``` | ||
# Structured documents | ||
Sometimes it's useful to have different levels of headings to structure your documents. Start lines with a `#` to create headings. Multiple `##` in a row denote smaller heading sizes. | ||
### This is a third-tier heading | ||
You can use one `#` all the way up to `######` six for different heading sizes. | ||
If you'd like to quote someone, use the > character before the line: | ||
> Coffee. The finest organic suspension ever devised... I beat the Borg with it. | ||
> - Captain Janeway | ||
``` | ||
|
||
--- | ||
|
||
# Code | ||
|
||
There are many different ways to style code with Markdown. If you have inline code blocks, wrap them in backticks: | ||
|
||
\`var example = true\` | ||
`var example = true` | ||
|
||
Markdown also supports something called code fencing, which allows for multiple lines without indentation: | ||
|
||
\`\`\` | ||
if (isAwesome){ | ||
return true | ||
} | ||
\`\`\` | ||
|
||
``` | ||
if (isAwesome){ | ||
return true | ||
} | ||
``` | ||
|
||
And if you'd like to use syntax highlighting, include the language: | ||
|
||
\`\`\`javascript | ||
if (isAwesome){ | ||
return true | ||
} | ||
\`\`\` | ||
|
||
```javascript | ||
if (isAwesome){ | ||
return true | ||
} | ||
``` | ||
|
||
--- | ||
|
||
# Unsupported | ||
|
||
While we try to continuously improve the support for Markdown, there are a few features which are not yet supported by Notes: | ||
|
||
- Tables | ||
- Images | ||
|
||
If you are interested in contributing support for one of those features, get in contact with us via GitHub or E-Mail. |
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