[go: nahoru, domu]

Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/origin/develop' into issue/132-…
Browse files Browse the repository at this point in the history
…formatbar-keyboard-old-api
  • Loading branch information
aforcier committed Apr 27, 2015
2 parents 0699bb6 + 4478cf3 commit c5882ba
Show file tree
Hide file tree
Showing 155 changed files with 554 additions and 90 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.util.Set;

import static org.junit.Assert.assertEquals;
import static org.wordpress.android.editor.Utils.buildMapFromKeyValuePairs;
import static org.wordpress.android.editor.Utils.getChangeMapFromSets;
import static org.wordpress.android.editor.Utils.splitDelimitedString;

Expand All @@ -34,6 +35,40 @@ public void testSplitDelimitedString() {
assertEquals(Collections.emptySet(), splitDelimitedString("", "~"));
}

@Test
public void testBuildMapFromKeyValuePairs() {
Set<String> keyValueSet = new HashSet<>();
Map<String, String> expectedMap = new HashMap<>();

// Test normal usage
keyValueSet.add("id=test");
keyValueSet.add("name=example");

expectedMap.put("id", "test");
expectedMap.put("name", "example");

assertEquals(expectedMap, buildMapFromKeyValuePairs(keyValueSet));

// Test mixed valid and invalid entries
keyValueSet.clear();
keyValueSet.add("test");
keyValueSet.add("name=example");

expectedMap.clear();
expectedMap.put("name", "example");

assertEquals(expectedMap, buildMapFromKeyValuePairs(keyValueSet));

// Test invalid entry
keyValueSet.clear();
keyValueSet.add("test");

assertEquals(Collections.emptyMap(), buildMapFromKeyValuePairs(keyValueSet));

// Test empty sets
assertEquals(Collections.emptyMap(), buildMapFromKeyValuePairs(Collections.<String>emptySet()));
}

@Test
public void testGetChangeMapFromSets() {
Set<String> oldSet = new HashSet<>();
Expand Down
83 changes: 80 additions & 3 deletions WordPressEditor/src/main/java/org/wordpress/android/editor/EditorFragment.java
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,16 @@ public class EditorFragment extends EditorFragmentAbstract implements View.OnCli

private static final String JS_CALLBACK_HANDLER = "nativeCallbackHandler";

private static final String TAG_FORMAT_BAR_BUTTON_MEDIA = "media";
private static final String TAG_FORMAT_BAR_BUTTON_BOLD = "bold";
private static final String TAG_FORMAT_BAR_BUTTON_ITALIC = "italic";
private static final String TAG_FORMAT_BAR_BUTTON_QUOTE = "blockquote";
private static final String TAG_FORMAT_BAR_BUTTON_UL = "unorderedList";
private static final String TAG_FORMAT_BAR_BUTTON_OL = "orderedList";
private static final String TAG_FORMAT_BAR_BUTTON_LINK = "link";

private static final float TOOLBAR_ALPHA_ENABLED = 1;
private static final float TOOLBAR_ALPHA_DISABLED = 0.5f;

private String mParamTitle;
private String mParamContent;
Expand Down Expand Up @@ -72,10 +81,34 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
mWebView = (EditorWebViewAbstract) view.findViewById(R.id.webview);
initWebView();

ToggleButton boldButton = (ToggleButton) view.findViewById(R.id.bold);
boldButton.setOnClickListener(this);
ToggleButton mediaButton = (ToggleButton) view.findViewById(R.id.format_bar_button_media);
mTagToggleButtonMap.put(TAG_FORMAT_BAR_BUTTON_MEDIA, mediaButton);

ToggleButton boldButton = (ToggleButton) view.findViewById(R.id.format_bar_button_bold);
mTagToggleButtonMap.put(TAG_FORMAT_BAR_BUTTON_BOLD, boldButton);

ToggleButton italicButton = (ToggleButton) view.findViewById(R.id.format_bar_button_italic);
mTagToggleButtonMap.put(TAG_FORMAT_BAR_BUTTON_ITALIC, italicButton);

ToggleButton quoteButton = (ToggleButton) view.findViewById(R.id.format_bar_button_quote);
mTagToggleButtonMap.put(TAG_FORMAT_BAR_BUTTON_QUOTE, quoteButton);

ToggleButton ulButton = (ToggleButton) view.findViewById(R.id.format_bar_button_ul);
mTagToggleButtonMap.put(TAG_FORMAT_BAR_BUTTON_UL, ulButton);

ToggleButton olButton = (ToggleButton) view.findViewById(R.id.format_bar_button_ol);
mTagToggleButtonMap.put(TAG_FORMAT_BAR_BUTTON_OL, olButton);

ToggleButton linkButton = (ToggleButton) view.findViewById(R.id.format_bar_button_link);
mTagToggleButtonMap.put(TAG_FORMAT_BAR_BUTTON_LINK, linkButton);

ToggleButton htmlButton = (ToggleButton) view.findViewById(R.id.format_bar_button_html);
htmlButton.setOnClickListener(this);

for (ToggleButton button : mTagToggleButtonMap.values()) {
button.setOnClickListener(this);
}

return view;
}

Expand Down Expand Up @@ -120,8 +153,25 @@ public boolean onJsAlert(WebView view, String url, String message, JsResult resu
@Override
public void onClick(View v) {
int id = v.getId();
if (id == R.id.bold) {
if (id == R.id.format_bar_button_bold) {
mWebView.execJavaScriptFromString("ZSSEditor.setBold();");
} else if (id == R.id.format_bar_button_italic) {
mWebView.execJavaScriptFromString("ZSSEditor.setItalic();");
} else if (id == R.id.format_bar_button_quote) {
mWebView.execJavaScriptFromString("ZSSEditor.setBlockquote();");
} else if (id == R.id.format_bar_button_ul) {
mWebView.execJavaScriptFromString("ZSSEditor.setUnorderedList();");
} else if (id == R.id.format_bar_button_ol) {
mWebView.execJavaScriptFromString("ZSSEditor.setOrderedList();");
} else if (id == R.id.format_bar_button_media) {
// TODO: Handle inserting media
((ToggleButton) v).setChecked(false);
} else if (id == R.id.format_bar_button_link) {
// TODO: Handle inserting a link
((ToggleButton) v).setChecked(false);
} else if (id == R.id.format_bar_button_html) {
// TODO: Handle HTML mode toggling
((ToggleButton) v).setChecked(false);
}
}

Expand Down Expand Up @@ -200,4 +250,31 @@ public void run() {
}
});
}

public void onSelectionChanged(final Map<String, String> selectionArgs) {
final String id = selectionArgs.get("id"); // The field currently in focus
mWebView.post(new Runnable() {
@Override
public void run() {
if (!id.isEmpty()) {
switch(id) {
case "zss_field_title":
updateToolbarEnabledState(false);
break;
case "zss_field_content":
updateToolbarEnabledState(true);
break;
}
}
}
});
}

void updateToolbarEnabledState(boolean enabled) {
float alpha = (enabled ? TOOLBAR_ALPHA_ENABLED : TOOLBAR_ALPHA_DISABLED);
for(ToggleButton button : mTagToggleButtonMap.values()) {
button.setEnabled(enabled);
button.setAlpha(alpha);
}
}
}
5 changes: 4 additions & 1 deletion WordPressEditor/src/main/java/org/wordpress/android/editor/JsCallbackReceiver.java
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,11 @@ public void executeCallback(String callbackId, String params) {
mPreviousStyleSet = newStyleSet;
break;
case CALLBACK_SELECTION_CHANGED:
// Called when changes are made to selection (includes moving the caret without selecting text)
// Called for changes to the field in current focus and for changes made to selection
// (includes moving the caret without selecting text)
// TODO: Possibly needed for handling WebView scrolling when caret moves (from iOS)
Set<String> selectionKeyValueSet = Utils.splitDelimitedString(params, JS_CALLBACK_DELIMITER);
mListener.onSelectionChanged(Utils.buildMapFromKeyValuePairs(selectionKeyValueSet));
break;
case CALLBACK_INPUT:
// Called on key press
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ private WPEditImageSpan createWPEditImageSpanLocal(Context context, MediaFile me
}

private WPEditImageSpan createWPEditImageSpanRemote(Context context, MediaFile mediaFile) {
int drawable = mediaFile.isVideo() ? R.drawable.media_movieclip : R.drawable.dashicon_format_image_big_grey;
int drawable = mediaFile.isVideo() ? R.drawable.media_movieclip : R.drawable.legacy_dashicon_format_image_big_grey;
Uri uri = Uri.parse(mediaFile.getFileURL());
WPEditImageSpan imageSpan = new WPEditImageSpan(context, drawable, uri);
imageSpan.setMediaFile(mediaFile);
Expand Down Expand Up @@ -1046,7 +1046,7 @@ public void appendGallery(MediaGallery mediaGallery) {

editableText.insert(selectionStart, " ");
MediaGalleryImageSpan is = new MediaGalleryImageSpan(getActivity(), mediaGallery,
R.drawable.icon_mediagallery_placeholder);
R.drawable.legacy_icon_mediagallery_placeholder);
editableText.setSpan(is, selectionStart, selectionEnd + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
AlignmentSpan.Standard as = new AlignmentSpan.Standard(Layout.Alignment.ALIGN_CENTER);
editableText.setSpan(as, selectionStart, selectionEnd + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@

public interface OnJsEditorStateChangedListener {
void onDomLoaded();
void onSelectionChanged(Map<String, String> selectionArgs);
void onSelectionStyleChanged(Map<String, Boolean> changeSet);
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,22 @@ public static Set<String> splitDelimitedString(String string, String delimiter)
return splitString;
}

/**
* Accepts a set of strings, each string being a key-value pair (<code>id=5</code>,
* <code>name=content-filed</code>). Returns a map of all the key-value pairs in the set.
* @param keyValueSet the set of key-value pair strings
*/
public static Map<String, String> buildMapFromKeyValuePairs(Set<String> keyValueSet) {
Map<String, String> selectionArgs = new HashMap<>();
for (String pair : keyValueSet) {
String[] splitString = pair.split("=");
if (splitString.length == 2) {
selectionArgs.put(splitString[0], splitString[1]);
}
}
return selectionArgs;
}

/**
* Compares two <code>Sets</code> and returns a <code>Map</code> of elements not contained in both
* <code>Sets</code>. Elements contained in <code>oldSet</code> but not in <code>newSet</code> will be marked
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 9 additions & 5 deletions WordPressEditor/src/main/res/drawable/format_bar_button_bold_selected_state.xml
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@
<layer-list
xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape>
<solid android:color="@color/format_bar_button_selected"/>
</shape>
<bitmap
android:src="@drawable/format_bar_button_bold_highlighted"
android:gravity="center"/>
</item>
<item>
<bitmap android:src="@drawable/dashicon_editor_bold" android:gravity="center"/>
<item android:top="@dimen/format_bar_button_highlighted_underline_top">
<shape android:shape="line">
<stroke
android:width="@dimen/format_bar_button_highlighted_underline_width"
android:color="@color/format_bar_button_highlighted_color"/>
</shape>
</item>
</layer-list>
6 changes: 4 additions & 2 deletions WordPressEditor/src/main/res/drawable/format_bar_button_bold_selector.xml
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true" android:drawable="@drawable/format_bar_button_bold_selected_state"/>
<item android:state_pressed="true" android:drawable="@drawable/format_bar_button_bold_selected_state"/>
<item>
<bitmap android:src="@drawable/dashicon_editor_bold_grey" android:gravity="center"/>
<bitmap
android:src="@drawable/format_bar_button_bold"
android:gravity="center"/>
</item>
</selector>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<shape android:shape="line" xmlns:android="http://schemas.android.com/apk/res/android">
<stroke
android:width="@dimen/format_bar_button_highlighted_underline_width"
android:color="@color/format_bar_button_highlighted_color"/>
</shape>
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list
xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<bitmap
android:src="@drawable/format_bar_button_html_highlighted"
android:gravity="center"/>
</item>
<item android:top="@dimen/format_bar_button_highlighted_underline_top">
<shape android:shape="line">
<stroke
android:width="@dimen/format_bar_button_highlighted_underline_width"
android:color="@color/format_bar_button_highlighted_color"/>
</shape>
</item>
</layer-list>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true" android:drawable="@drawable/format_bar_button_html_selected_state"/>
<item android:state_pressed="true" android:drawable="@drawable/format_bar_button_html_selected_state"/>
<item>
<bitmap
android:src="@drawable/format_bar_button_html"
android:gravity="center"/>
</item>
</selector>
14 changes: 9 additions & 5 deletions WordPressEditor/src/main/res/drawable/format_bar_button_italic_selected_state.xml
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@
<layer-list
xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape>
<solid android:color="@color/format_bar_button_selected"/>
</shape>
<bitmap
android:src="@drawable/format_bar_button_italic_highlighted"
android:gravity="center"/>
</item>
<item>
<bitmap android:src="@drawable/dashicon_editor_italic" android:gravity="center"/>
<item android:top="@dimen/format_bar_button_highlighted_underline_top">
<shape android:shape="line">
<stroke
android:width="@dimen/format_bar_button_highlighted_underline_width"
android:color="@color/format_bar_button_highlighted_color"/>
</shape>
</item>
</layer-list>
6 changes: 4 additions & 2 deletions WordPressEditor/src/main/res/drawable/format_bar_button_italic_selector.xml
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true" android:drawable="@drawable/format_bar_button_italic_selected_state"/>
<item android:state_pressed="true" android:drawable="@drawable/format_bar_button_italic_selected_state"/>
<item>
<bitmap android:src="@drawable/dashicon_editor_italic_grey" android:gravity="center"/>
<bitmap
android:src="@drawable/format_bar_button_italic"
android:gravity="center"/>
</item>
</selector>
14 changes: 9 additions & 5 deletions WordPressEditor/src/main/res/drawable/format_bar_button_link_selected_state.xml
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@
<layer-list
xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape>
<solid android:color="@color/format_bar_button_selected"/>
</shape>
<bitmap
android:src="@drawable/format_bar_button_link_highlighted"
android:gravity="center"/>
</item>
<item>
<bitmap android:src="@drawable/dashicon_admin_links" android:gravity="center"/>
<item android:top="@dimen/format_bar_button_highlighted_underline_top">
<shape android:shape="line">
<stroke
android:width="@dimen/format_bar_button_highlighted_underline_width"
android:color="@color/format_bar_button_highlighted_color"/>
</shape>
</item>
</layer-list>
6 changes: 4 additions & 2 deletions WordPressEditor/src/main/res/drawable/format_bar_button_link_selector.xml
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true" android:drawable="@drawable/format_bar_button_link_selected_state"/>
<item android:state_pressed="true" android:drawable="@drawable/format_bar_button_link_selected_state"/>
<item>
<bitmap android:src="@drawable/dashicon_admin_links_grey" android:gravity="center"/>
<bitmap
android:src="@drawable/format_bar_button_link"
android:gravity="center"/>
</item>
</selector>
14 changes: 9 additions & 5 deletions WordPressEditor/src/main/res/drawable/format_bar_button_media_selected_state.xml
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@
<layer-list
xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape>
<solid android:color="@color/format_bar_button_selected"/>
</shape>
<bitmap
android:src="@drawable/format_bar_button_media_highlighted"
android:gravity="center"/>
</item>
<item>
<bitmap android:src="@drawable/noticon_picture" android:gravity="center"/>
<item android:top="@dimen/format_bar_button_highlighted_underline_top">
<shape android:shape="line">
<stroke
android:width="@dimen/format_bar_button_highlighted_underline_width"
android:color="@color/format_bar_button_highlighted_color"/>
</shape>
</item>
</layer-list>
6 changes: 4 additions & 2 deletions WordPressEditor/src/main/res/drawable/format_bar_button_media_selector.xml
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true" android:drawable="@drawable/format_bar_button_media_selected_state"/>
<item android:state_pressed="true" android:drawable="@drawable/format_bar_button_media_selected_state"/>
<item>
<bitmap android:src="@drawable/noticon_picture_grey" android:gravity="center"/>
<bitmap
android:src="@drawable/format_bar_button_media"
android:gravity="center"/>
</item>
</selector>
Loading

0 comments on commit c5882ba

Please sign in to comment.