Skip to content

Commit

Permalink
FUNMODE fully working. resolves #89
Browse files Browse the repository at this point in the history
  • Loading branch information
brianmwadime committed Jul 11, 2016
1 parent 045b522 commit ac03aee
Show file tree
Hide file tree
Showing 24 changed files with 78 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
import com.mozilla.hackathon.kiboko.activities.FindIconsActivity;
import com.mozilla.hackathon.kiboko.activities.TutorialSlideActivity;
import com.mozilla.hackathon.kiboko.models.Topic;
import com.mozilla.hackathon.kiboko.settings.SettingsUtils;

import org.sufficientlysecure.htmltextview.EmojiUtils;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -90,6 +93,12 @@ public View getView(final int position, View convertView, ViewGroup parent) {

final Topic topic = topics.get(position);
holder.tv.setText(topic.getName());

if(SettingsUtils.isFunModeEnabled(context)){
holder.tv.setText(EmojiUtils.parse(topic.getName()));
}else{
holder.tv.setText(topic.getName());
}
holder.img.setImageResource(topic.getImage());

viewItem.setOnClickListener(new View.OnClickListener() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package com.mozilla.hackathon.kiboko.fragments;

/**
* Created by mwadime on 6/9/2016.
*/

import android.content.res.TypedArray;
import android.os.Bundle;
import android.support.v4.app.Fragment;
Expand All @@ -16,6 +14,7 @@
import android.widget.TextView;

import com.mozilla.hackathon.kiboko.R;
import com.mozilla.hackathon.kiboko.settings.SettingsUtils;
import com.mozilla.hackathon.kiboko.utilities.Utils;
import com.mozilla.hackathon.kiboko.widgets.NotifyingScrollView;

Expand All @@ -25,7 +24,6 @@
import pl.droidsonroids.gif.GifImageView;

import static com.mozilla.hackathon.kiboko.utilities.LogUtils.makeLogTag;

/**
* A fragment representing a single step in a wizard. The fragment shows a dummy title indicating
* the page number, along with some dummy text.
Expand All @@ -39,19 +37,14 @@ public class ScreenSlidePageFragment extends Fragment {
public static final String ARG_PAGE_TITLE = "page_title";
public static final String ARG_PAGE_DESCRIPTION = "page_description";
public static final String ARG_PAGE_IMAGE = "page_image";

private float mActionBarHeight;
private ActionBar mActionBar;


private GifDrawable gifDrawable;

/**
* The fragment's page number, which is set to the argument value for {@link #ARG_PAGE}.
*/
private int mPageNumber;
private String mPageDescription, mPageTitle, mPageImage;

/**
* Factory method for this fragment class. Constructs a new fragment for the given page number.
*/
Expand Down Expand Up @@ -95,6 +88,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
// Set the title view to show the page number.
((TextView) rootView.findViewById(R.id.step_title)).setText(mPageTitle);

((HtmlTextView) rootView.findViewById(R.id.step_description)).setFunMode(SettingsUtils.isFunModeEnabled(getContext()));
((HtmlTextView) rootView.findViewById(R.id.step_description)).setHtmlFromString(mPageDescription,new HtmlTextView.LocalImageGetter());

GifImageView gifImageView = (GifImageView) rootView.findViewById(R.id.step_image);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ public class SettingsUtils {
*/
public static final String PREF_ANALYTICS_ENABLED = "pref_analytics_enabled";

/**
* Boolean preference indicating whether the app is in fun mode
*/
public static final String PREF_FUNMODE_ENABLED = "pref_funmode_enabled";

/**
* Mark that the app has finished loading the {@code R.raw.bootstrap_data bootstrap data}.
*
Expand Down Expand Up @@ -66,6 +71,17 @@ public static boolean isDataBootstrapDone(final Context context) {
// sp.edit().putBoolean(PREF_DECLINED_WIFI_SETUP, newValue).apply();
// }

/**
* Set fun mode.
*
* @param context Context to be used to edit the {@link android.content.SharedPreferences}.
* @param newValue New value that will be set.
*/
public static void setFunMode(final Context context, boolean newValue) {
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
sp.edit().putBoolean(PREF_FUNMODE_ENABLED, newValue).apply();
}

/**
* Return true if analytics are enabled, false if user has disabled them.
*
Expand All @@ -76,6 +92,16 @@ public static boolean isAnalyticsEnabled(final Context context) {
return sp.getBoolean(PREF_ANALYTICS_ENABLED, true);
}

/**
* Return true if fun mode is enabled, false if user has disabled them.
*
* @param context Context to be used to lookup the {@link android.content.SharedPreferences}.
*/
public static boolean isFunModeEnabled(final Context context) {
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
return sp.getBoolean(PREF_FUNMODE_ENABLED, false);
}

/**
* Helper method to register a settings_prefs listener. This method does not automatically handle
* {@code unregisterOnSharedPreferenceChangeListener() un-registering} the listener at the end
Expand Down
Binary file removed app/src/main/res/drawable-nodpi/emoji_1f60a.png
Binary file not shown.
Binary file removed app/src/main/res/drawable-nodpi/emoji_1f60b.png
Binary file not shown.
Binary file removed app/src/main/res/drawable-nodpi/emoji_1f60c.png
Binary file not shown.
Binary file removed app/src/main/res/drawable-nodpi/emoji_1f60d.png
Binary file not shown.
Binary file removed app/src/main/res/drawable-nodpi/emoji_1f60e.png
Binary file not shown.
Binary file removed app/src/main/res/drawable-nodpi/emoji_1f60f.png
Binary file not shown.
Binary file removed app/src/main/res/drawable-nodpi/emoji_1f61a.png
Binary file not shown.
Binary file removed app/src/main/res/drawable-nodpi/emoji_1f61b.png
Binary file not shown.
Binary file removed app/src/main/res/drawable-nodpi/emoji_1f61c.png
Binary file not shown.
Binary file removed app/src/main/res/drawable-nodpi/emoji_1f61d.png
Binary file not shown.
Binary file removed app/src/main/res/drawable-nodpi/emoji_1f61e.png
Binary file not shown.
Binary file removed app/src/main/res/drawable-nodpi/emoji_1f61f.png
Binary file not shown.
Binary file removed app/src/main/res/drawable-nodpi/emoji_1f62a.png
Binary file not shown.
Binary file removed app/src/main/res/drawable-nodpi/emoji_1f62b.png
Binary file not shown.
Binary file removed app/src/main/res/drawable-nodpi/emoji_1f62c.png
Binary file not shown.
Binary file removed app/src/main/res/drawable-nodpi/emoji_1f62d.png
Binary file not shown.
Binary file removed app/src/main/res/drawable-nodpi/emoji_1f62e.png
Binary file not shown.
Binary file removed app/src/main/res/drawable-nodpi/emoji_1f62f.png
Binary file not shown.
4 changes: 2 additions & 2 deletions app/src/main/res/raw/bootstrap_data.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@
"description": "If you have problems connecting to a Wi-Fi hotspot, here is a list of things you can try:<ul><li>Make sure you have the right hotspot name.</li><li>Make sure you have the right password.</li><li>If you have the right password, make sure it's entered correctly.</li><li>Talk to the hotspot owner (shopkeeper, librarian, IT assistant, etc.) and explain your problems. They may be able to help solve your problem.</li><li>In the Wi-Fi menu, delete the hotspot by holding its name until a menu appears. Then, choose <b>\"Forget Network\"</b>, and connect again.</li></ul>"
}, {
"id": "6",
"title": "Enjoy",
"title": "Enjoy :-)",
"gifUrl": "connectwifi9",
"description": "Now, you should be connected! Enjoy!"
"description": "Now, you should be connected! Enjoy! :-)"
}]
}, {
"id": "3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,50 @@
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
* Created by secretrobotron on 7/10/16.
* Class for converting :-) emoji text or github style :smile: into emojis
*/
public class EmojiUtils {
public static final Map<String, Integer> emojiMap;
private static final Set<String> emojiKeys;
private static final String EMOTICON_DELIMITER = "";
// Normal text smiles pattern :-) etc
public static final Pattern SMILEY_REGEX_PATTERN = Pattern.compile(":[)DdpP]|:[ -]\\)|<3");
// github style pattern :happy: etc
public static final Pattern GITHUB_REGEX_PATTERN = Pattern.compile(":[^:]+:");
// frowny pattern :( etc
public static final Pattern FROWNY_REGEX_PATTERN = Pattern.compile(":[(<]|:[ -]\\(");
public static final Pattern EMOTICON_REGEX_PATTERN =
Pattern.compile("(?<=^|" + EMOTICON_DELIMITER + ")("
+ SMILEY_REGEX_PATTERN.pattern() + "|" + FROWNY_REGEX_PATTERN.pattern() + "|" + GITHUB_REGEX_PATTERN.pattern()
+ ")+(?=$|" + EMOTICON_DELIMITER + ")");

//TODO: add missing icons/smilies
static {
HashMap<String, Integer> map = new HashMap<String, Integer>();

map.put(":happy:", 0x1F601);
map.put(":-)", 0x1F601);
map.put(":happy2:", 0x1F602);
map.put(":happ3:", 0x1F603);
map.put(":happy4:", 0x1F604);
map.put(":happy5:", 0x1F605);
map.put(":happy6:", 0x1F606);
map.put(":wink:", 0x1F609);
map.put(":blush:", 0x1F60A);
map.put(";-)", 0x1F609);
map.put(":$", 0x1F60A);
map.put(":delicious:", 0x1F60B);
map.put(":relief:", 0x1F60C);
map.put(":hearts:", 0x1F60D);
map.put(":smirk:", 0x1F60F);
map.put(":unamused:", 0x1F612);
map.put(":sweating:", 0x1F613);
map.put("(:|", 0x1F613);
map.put(":pensive:", 0x1F614);
map.put(":confounded:", 0x1F616);
map.put(":kiss:", 0x1F618);
map.put(":kiss2:", 0x1F61A);
map.put(":tongue", 0x1F61C);
map.put(":P", 0x1F61C);
map.put(":tongue2:", 0x1F61D);
map.put(":disappointed:", 0x1F61E);
map.put(":angry:", 0x1F620);
Expand Down Expand Up @@ -77,18 +88,18 @@ public class EmojiUtils {

emojiMap = Collections.unmodifiableMap(map);

emojiKeys = emojiMap.keySet();
}

/**
* Does the actual replacing for emojis. see {@link Pattern} {@link Pattern}
* @param input test with emoticons
* @return converted string with emojis
*/
public static String parse(String input) {
Pattern pattern = Pattern.compile("(:[^:]+:)");
Matcher matcher = pattern.matcher(input);

Matcher matcher = EMOTICON_REGEX_PATTERN.matcher(input);
String output = "";

int start = 0;
int end = 0;

while (matcher.find()) {
String match = matcher.group();
start = matcher.start();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public class HtmlTextView extends JellyBeanSpanFixTextView {
public static final boolean DEBUG = false;
boolean mDontConsumeNonUrlClicks = true;
boolean mLinkHit;
private boolean mfunMode = false;
private boolean removeFromHtmlSpace = false;
private ClickableTableSpan mClickableTableSpan;
private DrawTableLinkSpan mDrawTableLinkSpan;
Expand All @@ -54,6 +55,14 @@ public void setRemoveFromHtmlSpace(boolean removeFromHtmlSpace) {
this.removeFromHtmlSpace = removeFromHtmlSpace;
}

/**
* Note that this must be called before setting text for it to work
* @param funMode true/false
*/
public void setFunMode(boolean funMode) {
this.mfunMode = funMode;
}

public interface ImageGetter {
}

Expand Down Expand Up @@ -137,11 +146,17 @@ public void setHtmlFromStringWithHtmlImageGetter(String html, Html.ImageGetter h
final HtmlTagHandler htmlTagHandler = new HtmlTagHandler();
htmlTagHandler.setClickableTableSpan(mClickableTableSpan);
htmlTagHandler.setDrawTableLinkSpan(mDrawTableLinkSpan);

if(mfunMode){
html = EmojiUtils.parse(html);
}

if (removeFromHtmlSpace) {
setText(removeHtmlBottomPadding(Html.fromHtml(html, htmlImageGetter, htmlTagHandler)));
} else {
setText(Html.fromHtml(html, htmlImageGetter, htmlTagHandler));
}

// make links work
setMovementMethod(LocalLinkMovementMethod.getInstance());
}
Expand Down

0 comments on commit ac03aee

Please sign in to comment.