• R/O
  • HTTP
  • SSH
  • HTTPS

提交

标签
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Commit MetaInfo

修订版ef4db618691d8521279ad98fd5d829e9c63d81c7 (tree)
时间2017-08-21 01:36:34
作者HMML <hmml3939@gmai...>
CommiterHMML

Log Message

Fix delayed image loading with MikuWeater icons.

更改概述

差异

--- a/app/src/main/java/cloud/hmml/mmw/MainApplication.java
+++ b/app/src/main/java/cloud/hmml/mmw/MainApplication.java
@@ -1,19 +1,60 @@
11 package cloud.hmml.mmw;
22
33 import android.app.Application;
4+import android.content.Context;
5+import android.content.pm.PackageManager;
6+import android.content.res.Resources;
7+import android.graphics.Bitmap;
8+import android.graphics.BitmapFactory;
9+import android.net.Uri;
410
511 import com.nostra13.universalimageloader.cache.memory.impl.LruMemoryCache;
612 import com.nostra13.universalimageloader.core.ImageLoader;
713 import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
14+import com.nostra13.universalimageloader.core.decode.ImageDecoder;
15+import com.nostra13.universalimageloader.core.decode.ImageDecodingInfo;
16+import com.nostra13.universalimageloader.core.download.BaseImageDownloader;
17+
18+import java.io.IOException;
19+import java.io.InputStream;
820
921
1022 public class MainApplication extends Application {
23+ class MmwImageDownloader extends BaseImageDownloader {
24+ public MmwImageDownloader(Context context) {
25+ super(context);
26+ }
27+
28+ @Override
29+ public InputStream getStream(String imageUri, Object extra) throws IOException {
30+ if (Uri.parse(imageUri).getScheme().equals("mikuweather-icon"))
31+ return getStreamFromMikuWeather(imageUri, extra);
32+ return super.getStream(imageUri, extra);
33+ }
34+
35+ public InputStream getStreamFromMikuWeather(String imageUri, Object extra) throws IOException {
36+ Context mx_context = null;
37+ Uri uri = Uri.parse(imageUri);
38+ try {
39+ mx_context = context.createPackageContext("com.mikuxperia.mikuweatherwidget", Context.CONTEXT_RESTRICTED);
40+ } catch (PackageManager.NameNotFoundException e) {
41+ throw new IOException("Faeild to resolv miku weather package");
42+ }
43+ Resources resources = mx_context.getResources();
44+ int resourceId = resources.getIdentifier(uri.getSchemeSpecificPart(), "drawable", "com.mikuxperia.mikuweatherwidget");
45+ return resources.openRawResource(resourceId);
46+ }
47+
48+ }
49+
50+
1151 @Override
1252 public void onCreate() {
1353 super.onCreate();
1454 ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(getApplicationContext())
1555 .memoryCache(new LruMemoryCache(5 * 1024 * 1024))
1656 .memoryCacheSize(5 * 1024 * 1024)
57+ .imageDownloader(new MmwImageDownloader(getApplicationContext()))
1758 .build();
1859 ImageLoader.getInstance().init(config);
1960
--- a/app/src/main/java/cloud/hmml/mmw/Theme.java
+++ b/app/src/main/java/cloud/hmml/mmw/Theme.java
@@ -232,6 +232,7 @@ public class Theme {
232232 try {
233233 theme = JSON.decode(istream, Theme.class);
234234 } catch (IOException e) {
235+ Log.e("theme", "Failed to decode theme definition json: " + e.getMessage());
235236 e.printStackTrace();
236237 return null;
237238 }
@@ -246,7 +247,10 @@ public class Theme {
246247
247248 public String getIconURL(String iconIdent) {
248249 if (type == TYPE_MIKU_WEATHER) {
249- return null;
250+ String icon_name = MW_RES_MAP.get(iconIdent);
251+ if (icon_name == null)
252+ return null;
253+ return "mikuweather-icon:tenki_"+icon_name;
250254 } else if (type == TYPE_BUILTIN) {
251255 return "assets://themes/" + id + "/" + W_FNAME_MAP.get(iconIdent);
252256 } else if (type == TYPE_IN_STORAGE) {
@@ -318,5 +322,4 @@ public class Theme {
318322 return null;
319323 }
320324 }
321-
322325 }
--- a/app/src/main/java/cloud/hmml/mmw/ThemePickerActivity.java
+++ b/app/src/main/java/cloud/hmml/mmw/ThemePickerActivity.java
@@ -3,14 +3,17 @@ package cloud.hmml.mmw;
33 import android.content.Context;
44 import android.content.Intent;
55 import android.content.res.Resources;
6+import android.graphics.Bitmap;
67 import android.graphics.Color;
78 import android.graphics.drawable.Drawable;
89 import android.net.Uri;
10+import android.os.AsyncTask;
911 import android.os.Bundle;
1012 import android.support.annotation.LayoutRes;
1113 import android.support.annotation.NonNull;
1214 import android.support.design.widget.FloatingActionButton;
1315 import android.support.design.widget.Snackbar;
16+import android.support.v4.content.AsyncTaskLoader;
1417 import android.support.v4.content.ContextCompat;
1518 import android.support.v7.app.AppCompatActivity;
1619 import android.support.v7.widget.Toolbar;
@@ -26,6 +29,8 @@ import android.widget.TextView;
2629
2730 import com.nostra13.universalimageloader.core.ImageLoader;
2831 import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
32+import com.nostra13.universalimageloader.core.assist.FailReason;
33+import com.nostra13.universalimageloader.core.listener.ImageLoadingListener;
2934
3035 import java.util.List;
3136
@@ -37,7 +42,7 @@ public class ThemePickerActivity extends AppCompatActivity {
3742 }
3843
3944 @Override
40- public View getView(int position, View convertView, ViewGroup parent) {
45+ public View getView(final int position, View convertView, ViewGroup parent) {
4146 final Theme theme = (Theme) getItem(position);
4247
4348 // Check if an existing view is being reused, otherwise inflate the view
@@ -52,19 +57,14 @@ public class ThemePickerActivity extends AppCompatActivity {
5257 ImageView image2 = (ImageView) convertView.findViewById(R.id.theme_image2);
5358 ImageView image3 = (ImageView) convertView.findViewById(R.id.theme_image3);
5459
60+
5561 // Populate the data into the template view using the data object
5662 name.setText(theme.name);
5763 author.setText(theme.author);
58- if (theme.getType() == Theme.TYPE_MIKU_WEATHER) {
59- image1.setImageBitmap(theme.getIcon(Theme.W_CLEAR_D + Theme.W_RAIN));
60- image2.setImageBitmap(theme.getIcon(Theme.W_SNOW + Theme.W_CLEAR_N));
61- image3.setImageBitmap(theme.getIcon(Theme.W_CLOUD + Theme.W_THUNDER));
62- } else {
63- ImageLoader imageLoader = ImageLoader.getInstance();
64- imageLoader.displayImage(theme.getIconURL(Theme.W_CLEAR_D + Theme.W_RAIN), image1);
65- imageLoader.displayImage(theme.getIconURL(Theme.W_SNOW + Theme.W_CLEAR_N), image2);
66- imageLoader.displayImage(theme.getIconURL(Theme.W_CLOUD + Theme.W_THUNDER), image3);
67- }
64+ ImageLoader imageLoader = ImageLoader.getInstance();
65+ imageLoader.displayImage(theme.getIconURL(Theme.W_CLEAR_D + Theme.W_RAIN), image1);
66+ imageLoader.displayImage(theme.getIconURL(Theme.W_SNOW + Theme.W_CLEAR_N), image2);
67+ imageLoader.displayImage(theme.getIconURL(Theme.W_CLOUD + Theme.W_THUNDER), image3);
6868 image2.setVisibility(View.VISIBLE);
6969 image3.setVisibility(View.VISIBLE);
7070
@@ -78,7 +78,6 @@ public class ThemePickerActivity extends AppCompatActivity {
7878 image2.setBackground(bg);
7979 image3.setBackground(bg);
8080
81-
8281 if (theme.getUri() != null) {
8382 author.setTextColor(Color.BLUE);
8483 author.setOnClickListener(new View.OnClickListener() {