Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@
android:name=".othercomponent.unreadnotification.JBCommentsToMeNotificationServiceHelper"/>
<service android:name=".othercomponent.unreadnotification.BigTextNotificationService"/>
<service android:name=".othercomponent.unreadnotification.SimpleTextNotificationService"/>
<service android:name=".othercomponent.DownloadEmotionsService"/>

<!---broadcast receiver -->
<!--<receiver-->
Expand Down
1 change: 1 addition & 0 deletions res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
<!--emotions-->
<string name="weibo_emotions">微博表情</string>
<string name="download_emotions">下载表情</string>
<string name="download_emotions_summary">只有下载了表情你才能在时间线上看到,表情总计有几千张,不过都很小</string>
<string name="background_downloading">后台下载中</string>

<!-- listview-->
Expand Down
6 changes: 5 additions & 1 deletion res/xml/other_pref.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
</PreferenceCategory>
<PreferenceCategory android:title="@string/pref_cache_title">

<Preference android:title="@string/download_emotions"
android:summary="@string/download_emotions_summary"
android:key="download_emotions"
/>
<Preference
android:key="click_to_clean_cache"
android:summary="@string/getting_cache_size"
Expand All @@ -38,4 +42,4 @@
/>

</PreferenceCategory>
</PreferenceScreen>
</PreferenceScreen>
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ protected Void doInBackground(Void... params) {
List<EmotionBean> needList = new ArrayList<EmotionBean>();

for (EmotionBean bean : list) {
if (TextUtils.isEmpty(bean.getCategory())) {
if (!TextUtils.isEmpty(bean.getCategory())) {
needList.add(bean);
}
}
Expand Down
31 changes: 31 additions & 0 deletions src/org/qii/weiciyuan/support/file/FileManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ public class FileManager {
private static final String WEBVIEW_FAVICON = "favicon";
private static final String LOG = "log";
private static final String WEICIYUAN = "weiciyuan";
private static final String SDCARD_PATH = GlobalContext.getInstance().getExternalCacheDir().getAbsolutePath();
private static final String EMOTION = "emotion";

/**
* install weiciyuan, open app and login in, Android system will create cache dir.
Expand Down Expand Up @@ -141,6 +143,24 @@ public static String getLogDir() {
}
}

private static String getFileRelativePathFromUrl(String url) {
//AppLogger.d(url);
int index = url.indexOf("//");

String s = url.substring(index + 2);

String result = s.substring(s.indexOf("/"));


return result;
}

private static String getFileAbsolutePathFromRelativePath(String relativePath) {
String result = SDCARD_PATH + File.separator + relativePath;

return result;
}

public static String getFilePathFromUrl(String url, FileLocationMethod method) {

if (!isExternalStorageMounted()) {
Expand All @@ -150,6 +170,17 @@ public static String getFilePathFromUrl(String url, FileLocationMethod method) {
if (TextUtils.isEmpty(url)) {
return "";
}
switch(method){
case emotion:
String oldRelativePath = getFileRelativePathFromUrl(url);
String newRelativePath = "";
String name = new File(oldRelativePath).getName();
newRelativePath = File.separator + EMOTION + File.separator + name;
String absolutePath = getFileAbsolutePathFromRelativePath(newRelativePath);
return absolutePath;
default:
break;
}

return DownloadPicturesDBTask.get(url);
}
Expand Down
1 change: 1 addition & 0 deletions src/org/qii/weiciyuan/support/smileypicker/SmileyMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class SmileyMap {
public static final int GENERAL_EMOTION_POSITION = 0;
public static final int EMOJI_EMOTION_POSITION = 2;
public static final int HUAHUA_EMOTION_POSITION = 1;
public static final int EXTRA_EMOTION_POSITION = 4;

private static SmileyMap instance = new SmileyMap();
private Map<String, String> general = new LinkedHashMap<String, String>();
Expand Down
44 changes: 44 additions & 0 deletions src/org/qii/weiciyuan/support/utils/GlobalContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
import org.qii.weiciyuan.support.database.GroupDBTask;
import org.qii.weiciyuan.support.settinghelper.SettingUtility;
import org.qii.weiciyuan.support.smileypicker.SmileyMap;
import org.qii.weiciyuan.support.database.DatabaseManager;
import org.qii.weiciyuan.support.file.FileLocationMethod;
import org.qii.weiciyuan.support.file.FileManager;

import android.app.Activity;
import android.app.ActivityManager;
Expand All @@ -28,6 +31,8 @@
import android.util.LruCache;
import android.view.Display;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
Expand Down Expand Up @@ -242,11 +247,50 @@ public synchronized Map<String, Bitmap> getHuahuaPics() {
}
}

public synchronized Map<String, Bitmap> getExtraPics() {
if (emotionsPic != null && emotionsPic.size() > 0) {
return emotionsPic.get(SmileyMap.EXTRA_EMOTION_POSITION);
} else {
getEmotionsTask();
return emotionsPic.get(SmileyMap.EXTRA_EMOTION_POSITION);
}
}

public LinkedHashMap<String, Bitmap> getExtraEmotionMap(){
Map<String, String> textUrlMap = DatabaseManager.getInstance().getEmotionsMap();
LinkedHashMap<String, Bitmap> bitmapMap = new LinkedHashMap<String, Bitmap>();

for (String str : textUrlMap.keySet()){
String url = textUrlMap.get(str);
String path = FileManager.getFilePathFromUrl(url, FileLocationMethod.emotion);
try {
FileInputStream inputStream = new FileInputStream(new File(path));
Bitmap bitmap = BitmapFactory.decodeStream(inputStream);
if (bitmap != null) {
Bitmap scaledBitmap = Bitmap.createScaledBitmap(bitmap,
Utility.dip2px(getResources().getInteger(R.integer.emotion_size)),
Utility.dip2px(getResources().getInteger(R.integer.emotion_size)),
true);
if (bitmap != scaledBitmap) {
bitmap.recycle();
bitmap = scaledBitmap;
}
bitmapMap.put(str, bitmap);
}
} catch (IOException ignored) {
//e.printStackTrace();
}
}
return bitmapMap;
}

private void getEmotionsTask() {
Map<String, String> general = SmileyMap.getInstance().getGeneral();
emotionsPic.put(SmileyMap.GENERAL_EMOTION_POSITION, getEmotionsTask(general));
Map<String, String> huahua = SmileyMap.getInstance().getHuahua();
emotionsPic.put(SmileyMap.HUAHUA_EMOTION_POSITION, getEmotionsTask(huahua));

emotionsPic.put(SmileyMap.EXTRA_EMOTION_POSITION, getExtraEmotionMap());
}

private LinkedHashMap<String, Bitmap> getEmotionsTask(Map<String, String> emotionMap) {
Expand Down
8 changes: 7 additions & 1 deletion src/org/qii/weiciyuan/support/utils/TimeLineUtility.java
Original file line number Diff line number Diff line change
Expand Up @@ -301,17 +301,23 @@ private static void addEmotions(SpannableString value) {
String str2 = localMatcher.group(0);
int k = localMatcher.start();
int m = localMatcher.end();
if (m - k < 8) {
/*if (m - k < 8) "[哆啦A梦花心]".length == 8 */ {
Bitmap bitmap = GlobalContext.getInstance().getEmotionsPics().get(str2);
if (bitmap == null) {
bitmap = GlobalContext.getInstance().getHuahuaPics().get(str2);
}
if (bitmap == null) {
bitmap = GlobalContext.getInstance().getExtraPics().get(str2);
}
if (bitmap != null) {
ImageSpan localImageSpan = new ImageSpan(
GlobalContext.getInstance().getActivity(), bitmap,
ImageSpan.ALIGN_BASELINE);
value.setSpan(localImageSpan, k, m, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
else {
android.util.Log.e("smiley", String.format("notfound: %s", str2));
}
}
}
}
Expand Down
14 changes: 13 additions & 1 deletion src/org/qii/weiciyuan/ui/preference/OtherActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
import android.preference.PreferenceScreen;
import android.view.MenuItem;
import android.widget.Toast;
import android.preference.Preference.OnPreferenceClickListener;
import org.qii.weiciyuan.othercomponent.DownloadEmotionsService;
import org.qii.weiciyuan.support.utils.GlobalContext;

/**
* User: qii
Expand Down Expand Up @@ -83,7 +86,16 @@ public boolean onPreferenceClick(Preference preference) {
return true;
}
});

findPreference(SettingActivity.DOWNLOAD_EMOTIONS)
.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
Intent service = new Intent(getActivity(), DownloadEmotionsService.class);
service.putExtra("token", GlobalContext.getInstance().getSpecialToken());
getActivity().startService(service);
return true;
}
});
detectDebugPreference();
}

Expand Down
1 change: 1 addition & 0 deletions src/org/qii/weiciyuan/ui/preference/SettingActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ public class SettingActivity extends AbstractAppActivity {
public static final String AUTHOR = "pref_author_key";
public static final String DEBUG_MEM_INFO = "pref_mem_key";
public static final String CRASH = "pref_crash_key";
public static final String DOWNLOAD_EMOTIONS = "download_emotions";

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand Down