增加天气每小时显示,去掉autosize,增加svg显示
This commit is contained in:
@@ -29,8 +29,6 @@ import net.lucode.hackware.magicindicator.ViewPagerHelper;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import me.jessyan.autosize.AutoSize;
|
||||
|
||||
public class MainActivity extends BaseMvvmActivity<MainViewModel, ActivityMainBinding> {
|
||||
private static final String TAG = "MainActivity";
|
||||
private MMKV mMMKV = MMKV.mmkvWithID(CommonConfig.MMKV_ID, MMKV.MULTI_PROCESS_MODE);
|
||||
@@ -172,7 +170,6 @@ public class MainActivity extends BaseMvvmActivity<MainViewModel, ActivityMainBi
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
//修补autozie fragment item大小不一致
|
||||
AutoSize.autoConvertDensityOfGlobal(this);
|
||||
Log.e(TAG, "onResume: ");
|
||||
mViewModel.getOutsideApp();
|
||||
}
|
||||
|
||||
@@ -8,9 +8,11 @@ import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import com.baidu.location.BDLocation;
|
||||
import com.jeremyliao.liveeventbus.LiveEventBus;
|
||||
import com.qweather.sdk.response.weather.WeatherDaily;
|
||||
import com.qweather.sdk.response.weather.WeatherHourly;
|
||||
import com.qweather.sdk.response.weather.WeatherNow;
|
||||
import com.tencent.mmkv.MMKV;
|
||||
import com.ttstd.dialer.R;
|
||||
import com.ttstd.dialer.adapter.HourlyWeatherAdapter;
|
||||
import com.ttstd.dialer.adapter.WeatherAdapter;
|
||||
import com.ttstd.dialer.base.mvvm.BaseMvvmActivity;
|
||||
import com.ttstd.dialer.config.CommonConfig;
|
||||
@@ -26,6 +28,7 @@ public class WeatherMainActivity extends BaseMvvmActivity<WeatherMainViewModel,
|
||||
|
||||
private MMKV mMMKV = MMKV.mmkvWithID(CommonConfig.MMKV_ID, MMKV.MULTI_PROCESS_MODE);
|
||||
private WeatherAdapter mWeatherAdapter;
|
||||
private HourlyWeatherAdapter mHourlyWeatherAdapter;
|
||||
|
||||
// @Override
|
||||
// public boolean setfitWindow() {
|
||||
@@ -51,6 +54,13 @@ public class WeatherMainActivity extends BaseMvvmActivity<WeatherMainViewModel,
|
||||
mViewDataBinding.recyclerView.setAdapter(mWeatherAdapter);
|
||||
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(WeatherMainActivity.this, LinearLayoutManager.VERTICAL, false);
|
||||
mViewDataBinding.recyclerView.setLayoutManager(linearLayoutManager);
|
||||
|
||||
mHourlyWeatherAdapter = new HourlyWeatherAdapter();
|
||||
mViewDataBinding.rvHourly.setAdapter(mHourlyWeatherAdapter);
|
||||
LinearLayoutManager horizontalLinearLayoutManager = new LinearLayoutManager(WeatherMainActivity.this, LinearLayoutManager.HORIZONTAL, false);
|
||||
mViewDataBinding.rvHourly.setLayoutManager(horizontalLinearLayoutManager);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -63,6 +73,12 @@ public class WeatherMainActivity extends BaseMvvmActivity<WeatherMainViewModel,
|
||||
mViewDataBinding.setWeatherNow(weatherNow);
|
||||
}
|
||||
});
|
||||
mViewModel.mWeather24hData.observe(this, new Observer<List<WeatherHourly>>() {
|
||||
@Override
|
||||
public void onChanged(List<WeatherHourly> weatherHourlies) {
|
||||
mHourlyWeatherAdapter.setWeatherHourlyList(weatherHourlies);
|
||||
}
|
||||
});
|
||||
mViewModel.mWeatherDailyListData.observe(this, new Observer<List<WeatherDaily>>() {
|
||||
@Override
|
||||
public void onChanged(List<WeatherDaily> weatherDailies) {
|
||||
@@ -92,6 +108,7 @@ public class WeatherMainActivity extends BaseMvvmActivity<WeatherMainViewModel,
|
||||
public void onChanged(BDLocation bdLocation) {
|
||||
mViewDataBinding.tvLocation.setText(bdLocation.getDistrict());
|
||||
mViewModel.getWeatherNow(bdLocation.getAdCode());
|
||||
mViewModel.getWeather24h(bdLocation.getAdCode());
|
||||
mViewModel.getWeather10D(bdLocation.getAdCode());
|
||||
}
|
||||
});
|
||||
|
||||
@@ -8,6 +8,8 @@ import com.qweather.sdk.Callback;
|
||||
import com.qweather.sdk.response.error.ErrorResponse;
|
||||
import com.qweather.sdk.response.weather.WeatherDaily;
|
||||
import com.qweather.sdk.response.weather.WeatherDailyResponse;
|
||||
import com.qweather.sdk.response.weather.WeatherHourly;
|
||||
import com.qweather.sdk.response.weather.WeatherHourlyResponse;
|
||||
import com.qweather.sdk.response.weather.WeatherNow;
|
||||
import com.qweather.sdk.response.weather.WeatherNowResponse;
|
||||
import com.trello.rxlifecycle4.android.ActivityEvent;
|
||||
@@ -47,6 +49,32 @@ public class WeatherMainViewModel extends BaseViewModel<ActivityWeatherMainBindi
|
||||
});
|
||||
}
|
||||
|
||||
public MutableLiveData<List<WeatherHourly>> mWeather24hData = new MutableLiveData<>();
|
||||
|
||||
public void getWeather24h(String adCode) {
|
||||
Log.e(TAG, "getWeather24h: " + adCode);
|
||||
WeatherManager.getInstance().getWeather24h(adCode, new Callback<WeatherHourlyResponse>() {
|
||||
@Override
|
||||
public void onSuccess(WeatherHourlyResponse weatherHourlyResponse) {
|
||||
Log.e("getWeather24h", "onSuccess: " + weatherHourlyResponse);
|
||||
List<WeatherHourly> weatherHourlies = weatherHourlyResponse.getHourly();
|
||||
Log.e("getWeather24h", "onSuccess: " + GsonUtils.toJSONString(weatherHourlies));
|
||||
mWeather24hData.postValue(weatherHourlies);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(ErrorResponse errorResponse) {
|
||||
Log.e("getWeather24h", "onFailure: " + errorResponse.getError().getStatus());
|
||||
Log.e("getWeather24h", "onFailure: " + errorResponse.getError().getDetail());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onException(Throwable throwable) {
|
||||
Log.e("getWeather24h", "onException: " + throwable.getMessage());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public MutableLiveData<List<WeatherDaily>> mWeatherDailyListData = new MutableLiveData<>();
|
||||
|
||||
@@ -57,7 +85,7 @@ public class WeatherMainViewModel extends BaseViewModel<ActivityWeatherMainBindi
|
||||
public void onSuccess(WeatherDailyResponse weatherDailyResponse) {
|
||||
Log.e("getWeather10D", "onSuccess: ");
|
||||
List<WeatherDaily> weatherDailyList = weatherDailyResponse.getDaily();
|
||||
Log.e("getWeather10D", "onSuccess: "+ GsonUtils.toJSONString(weatherDailyList));
|
||||
Log.e("getWeather10D", "onSuccess: " + GsonUtils.toJSONString(weatherDailyList));
|
||||
mWeatherDailyListData.postValue(weatherDailyList);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
package com.ttstd.dialer.adapter;
|
||||
|
||||
import android.graphics.drawable.PictureDrawable;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.RequestBuilder;
|
||||
import com.bumptech.glide.load.engine.DiskCacheStrategy;
|
||||
import com.qweather.sdk.response.weather.WeatherHourly;
|
||||
import com.ttstd.dialer.R;
|
||||
import com.ttstd.dialer.glide.GlideApp;
|
||||
import com.ttstd.dialer.glide.svg.SvgSoftwareLayerSetter;
|
||||
import com.ttstd.dialer.utils.TimeUtils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions.withCrossFade;
|
||||
|
||||
public class HourlyWeatherAdapter extends RecyclerView.Adapter<HourlyWeatherAdapter.HourlyWeather> {
|
||||
private static final String TAG = "HourlyWeatherAdapter";
|
||||
|
||||
private FragmentActivity mContext;
|
||||
private List<WeatherHourly> mWeatherHourlyList;
|
||||
private RequestBuilder<PictureDrawable> requestBuilder;
|
||||
|
||||
public void setWeatherHourlyList(List<WeatherHourly> weatherHourlyList) {
|
||||
mWeatherHourlyList = weatherHourlyList;
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public HourlyWeather onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
mContext = (FragmentActivity) parent.getContext();
|
||||
requestBuilder = GlideApp.with(mContext)
|
||||
.as(PictureDrawable.class)
|
||||
.placeholder(R.drawable.image_loading)
|
||||
.error(R.drawable.not_applicable)
|
||||
.transition(withCrossFade())
|
||||
.listener(new SvgSoftwareLayerSetter());
|
||||
return new HourlyWeather(LayoutInflater.from(mContext).inflate(R.layout.item_hourly_weather, parent, false));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull HourlyWeather holder, int position) {
|
||||
WeatherHourly weatherHourly = mWeatherHourlyList.get(position);
|
||||
String fxTime = weatherHourly.getFxTime();
|
||||
holder.tv_time.setText(TimeUtils.formatToHourDescription(fxTime));
|
||||
String icon = weatherHourly.getIcon();
|
||||
// 获取资源ID
|
||||
String fileName = "qweather_" + icon; // 替换为你的文件名
|
||||
int resId = mContext.getResources().getIdentifier(fileName, "raw", mContext.getPackageName());
|
||||
if (resId != 0) {
|
||||
// 使用Glide加载,假设已配置SVG支持
|
||||
Glide.with(mContext)
|
||||
.as(PictureDrawable.class)
|
||||
.load(resId) // 加载raw资源ID
|
||||
.diskCacheStrategy(DiskCacheStrategy.NONE) // raw资源通常不缓存
|
||||
.into(holder.iv_icon);
|
||||
} else {
|
||||
// 处理错误
|
||||
Log.e("GlideLoad", "Raw resource not found: " + fileName);
|
||||
}
|
||||
|
||||
holder.tv_temp.setText(weatherHourly.getTemp() + "°");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return mWeatherHourlyList == null ? 0 : mWeatherHourlyList.size();
|
||||
}
|
||||
|
||||
public class HourlyWeather extends RecyclerView.ViewHolder {
|
||||
TextView tv_time, tv_temp;
|
||||
ImageView iv_icon;
|
||||
|
||||
public HourlyWeather(@NonNull View itemView) {
|
||||
super(itemView);
|
||||
tv_time = itemView.findViewById(R.id.tv_time);
|
||||
tv_temp = itemView.findViewById(R.id.tv_temp);
|
||||
iv_icon = itemView.findViewById(R.id.iv_icon);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
package com.ttstd.dialer.annotations;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.bumptech.glide.GlideBuilder;
|
||||
import com.bumptech.glide.annotation.GlideModule;
|
||||
import com.bumptech.glide.load.engine.bitmap_recycle.LruBitmapPool;
|
||||
import com.bumptech.glide.load.engine.cache.InternalCacheDiskCacheFactory;
|
||||
import com.bumptech.glide.load.engine.cache.LruResourceCache;
|
||||
import com.bumptech.glide.module.AppGlideModule;
|
||||
|
||||
@GlideModule
|
||||
public class CustomGlideModule extends AppGlideModule {
|
||||
@Override
|
||||
public void applyOptions(@NonNull Context context, @NonNull GlideBuilder builder) {
|
||||
super.applyOptions(context, builder);
|
||||
//内存缓存
|
||||
int memoryCacheSizeBytes = 1024 * 1024 * 32; // 20mb
|
||||
builder.setMemoryCache(new LruResourceCache(memoryCacheSizeBytes));
|
||||
//Bitmap 池
|
||||
int bitmapPoolSizeBytes = 1024 * 1024 * 64; // 30mb
|
||||
builder.setBitmapPool(new LruBitmapPool(bitmapPoolSizeBytes));
|
||||
//磁盘缓存
|
||||
int diskCacheSizeBytes = 1024 * 1024 * 128; // 100MB
|
||||
builder.setDiskCache(new InternalCacheDiskCacheFactory(context, diskCacheSizeBytes));
|
||||
|
||||
}
|
||||
}
|
||||
@@ -9,8 +9,6 @@ import androidx.appcompat.app.AlertDialog;
|
||||
|
||||
import com.ttstd.dialer.utils.ScreenUtils;
|
||||
|
||||
import me.jessyan.autosize.AutoSizeCompat;
|
||||
|
||||
public class BaseAlertDialogBuilder extends AlertDialog.Builder {
|
||||
|
||||
/**
|
||||
@@ -39,9 +37,9 @@ public class BaseAlertDialogBuilder extends AlertDialog.Builder {
|
||||
@Override
|
||||
public Resources getResources() {
|
||||
if (ScreenUtils.isTablet(context)) {
|
||||
AutoSizeCompat.autoConvertDensityBaseOnWidth(mResources, ALERT_BASE_WIDTH_TABLE);
|
||||
// AutoSizeCompat.autoConvertDensityBaseOnWidth(mResources, ALERT_BASE_WIDTH_TABLE);
|
||||
} else {
|
||||
AutoSizeCompat.autoConvertDensityBaseOnWidth(mResources, ALERT_BASE_WIDTH);
|
||||
// AutoSizeCompat.autoConvertDensityBaseOnWidth(mResources, ALERT_BASE_WIDTH);
|
||||
}
|
||||
return mResources;
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ import com.hjq.toast.Toaster;
|
||||
import com.tencent.bugly.crashreport.CrashReport;
|
||||
import com.tencent.mmkv.MMKV;
|
||||
import com.ttstd.dialer.BuildConfig;
|
||||
import com.ttstd.dialer.config.CommonConfig;
|
||||
import com.ttstd.dialer.manager.AppManager;
|
||||
import com.ttstd.dialer.manager.MapManager;
|
||||
import com.ttstd.dialer.manager.WeatherManager;
|
||||
@@ -62,6 +63,7 @@ public class BaseApplication extends Application {
|
||||
|
||||
String rootDir = MMKV.initialize(this);
|
||||
Log.e(TAG, "mmkv root: " + rootDir);
|
||||
MMKV mmkv = MMKV.mmkvWithID(CommonConfig.MMKV_ID, MMKV.MULTI_PROCESS_MODE);
|
||||
|
||||
/*jpush start*/
|
||||
JPushInterface.setDebugMode(true);
|
||||
@@ -101,6 +103,13 @@ public class BaseApplication extends Application {
|
||||
AppManager.init(this);
|
||||
MapManager.init(this);
|
||||
MapManager.getInstance().initMap();
|
||||
boolean manually = mmkv.decodeBool(CommonConfig.MANUALLY_SELECT_LOCATION, false);
|
||||
Log.e(TAG, "init: manually location " + manually);
|
||||
if (manually) {
|
||||
|
||||
} else {
|
||||
MapManager.getInstance().startLocation();
|
||||
}
|
||||
WeatherManager.init(this);
|
||||
IconCacheManager.init(this);
|
||||
}
|
||||
|
||||
@@ -15,8 +15,6 @@ import com.ttstd.dialer.R;
|
||||
import com.ttstd.dialer.base.rx.BaseRxActivity;
|
||||
import com.zackratos.ultimatebarx.ultimatebarx.java.UltimateBarX;
|
||||
|
||||
import me.jessyan.autosize.AutoSizeCompat;
|
||||
|
||||
public abstract class BaseTransparentActivity extends BaseRxActivity {
|
||||
|
||||
public BaseTransparentActivity() {
|
||||
@@ -48,7 +46,6 @@ public abstract class BaseTransparentActivity extends BaseRxActivity {
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
AutoSizeCompat.autoConvertDensityOfGlobal(getResources());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -167,9 +167,9 @@ public class HomeFragment extends BaseMvvmFragment<HomeViewModel, FragmentHomeBi
|
||||
private void setTime() {
|
||||
if (isAdded()) {
|
||||
mViewDataBinding.tvTime.setText(DateUtil.formatDateHour());
|
||||
// mViewDataBinding.tvDate.setText(DataUtil.formatDateDay());
|
||||
// mViewDataBinding.tvWeek.setText(TimeUtils.getWeek());
|
||||
// mViewDataBinding.tvLunar.setText(mFestivalUtils.getLunarCalendar());
|
||||
mViewDataBinding.tvDate.setText(DateUtil.formatDateDay());
|
||||
mViewDataBinding.tvWeek.setText(DateUtil.convertToChineseWeekdayAll());
|
||||
mViewDataBinding.tvLunar.setText(mFestivalUtils.getLunarCalendar());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
package com.ttstd.dialer.glide;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.drawable.PictureDrawable;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.GlideBuilder;
|
||||
import com.bumptech.glide.Registry;
|
||||
import com.bumptech.glide.annotation.GlideModule;
|
||||
import com.bumptech.glide.load.engine.bitmap_recycle.LruBitmapPool;
|
||||
import com.bumptech.glide.load.engine.cache.InternalCacheDiskCacheFactory;
|
||||
import com.bumptech.glide.load.engine.cache.LruResourceCache;
|
||||
import com.bumptech.glide.module.AppGlideModule;
|
||||
import com.caverock.androidsvg.SVG;
|
||||
import com.ttstd.dialer.glide.svg.SvgDecoder;
|
||||
import com.ttstd.dialer.glide.svg.SvgDrawableTranscoder;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
@GlideModule
|
||||
public class CustomGlideModule extends AppGlideModule {
|
||||
|
||||
@Override
|
||||
public void applyOptions(@NonNull Context context, @NonNull GlideBuilder builder) {
|
||||
super.applyOptions(context, builder);
|
||||
//内存缓存
|
||||
int memoryCacheSizeBytes = 1024 * 1024 * 16; // 16mb
|
||||
builder.setMemoryCache(new LruResourceCache(memoryCacheSizeBytes));
|
||||
//Bitmap 池
|
||||
int bitmapPoolSizeBytes = 1024 * 1024 * 32; // 32mb
|
||||
builder.setBitmapPool(new LruBitmapPool(bitmapPoolSizeBytes));
|
||||
//磁盘缓存
|
||||
int diskCacheSizeBytes = 1024 * 1024 * 64; // 64MB
|
||||
builder.setDiskCache(new InternalCacheDiskCacheFactory(context, diskCacheSizeBytes));
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerComponents(@NonNull Context context, @NonNull Glide glide, @NonNull Registry registry) {
|
||||
registry.register(SVG.class, PictureDrawable.class, new SvgDrawableTranscoder())
|
||||
.append(InputStream.class, SVG.class, new SvgDecoder());
|
||||
}
|
||||
|
||||
// Disable manifest parsing to avoid adding similar modules twice.
|
||||
@Override
|
||||
public boolean isManifestParsingEnabled() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
46
app/src/main/java/com/ttstd/dialer/glide/svg/SvgDecoder.java
Normal file
46
app/src/main/java/com/ttstd/dialer/glide/svg/SvgDecoder.java
Normal file
@@ -0,0 +1,46 @@
|
||||
package com.ttstd.dialer.glide.svg;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.bumptech.glide.load.Options;
|
||||
import com.bumptech.glide.load.ResourceDecoder;
|
||||
import com.bumptech.glide.load.engine.Resource;
|
||||
import com.bumptech.glide.load.resource.SimpleResource;
|
||||
import com.caverock.androidsvg.SVG;
|
||||
import com.caverock.androidsvg.SVGParseException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import static com.bumptech.glide.request.target.Target.SIZE_ORIGINAL;
|
||||
|
||||
/*https://github.com/bumptech/glide/tree/master/samples/svg*/
|
||||
|
||||
/**
|
||||
* Decodes an SVG internal representation from an {@link InputStream}.
|
||||
*/
|
||||
public class SvgDecoder implements ResourceDecoder<InputStream, SVG> {
|
||||
|
||||
@Override
|
||||
public boolean handles(@NonNull InputStream source, @NonNull Options options) {
|
||||
// TODO: Can we tell?
|
||||
return true;
|
||||
}
|
||||
|
||||
public Resource<SVG> decode(
|
||||
@NonNull InputStream source, int width, int height, @NonNull Options options)
|
||||
throws IOException {
|
||||
try {
|
||||
SVG svg = SVG.getFromInputStream(source);
|
||||
if (width != SIZE_ORIGINAL) {
|
||||
svg.setDocumentWidth(width);
|
||||
}
|
||||
if (height != SIZE_ORIGINAL) {
|
||||
svg.setDocumentHeight(height);
|
||||
}
|
||||
return new SimpleResource<>(svg);
|
||||
} catch (SVGParseException ex) {
|
||||
throw new IOException("Cannot load SVG from stream", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.ttstd.dialer.glide.svg;
|
||||
|
||||
import android.graphics.Picture;
|
||||
import android.graphics.drawable.PictureDrawable;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.bumptech.glide.load.Options;
|
||||
import com.bumptech.glide.load.engine.Resource;
|
||||
import com.bumptech.glide.load.resource.SimpleResource;
|
||||
import com.bumptech.glide.load.resource.transcode.ResourceTranscoder;
|
||||
import com.caverock.androidsvg.SVG;
|
||||
|
||||
/**
|
||||
* Convert the {@link SVG}'s internal representation to an Android-compatible one ({@link Picture}).
|
||||
*/
|
||||
public class SvgDrawableTranscoder implements ResourceTranscoder<SVG, PictureDrawable> {
|
||||
@Nullable
|
||||
@Override
|
||||
public Resource<PictureDrawable> transcode(@NonNull Resource<SVG> toTranscode, @NonNull Options options) {
|
||||
SVG svg = toTranscode.get();
|
||||
Picture picture = svg.renderToPicture();
|
||||
PictureDrawable drawable = new PictureDrawable(picture);
|
||||
return new SimpleResource<>(drawable);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.ttstd.dialer.glide.svg;
|
||||
|
||||
import android.graphics.drawable.PictureDrawable;
|
||||
import android.widget.ImageView;
|
||||
import androidx.annotation.NonNull;
|
||||
import com.bumptech.glide.load.DataSource;
|
||||
import com.bumptech.glide.load.engine.GlideException;
|
||||
import com.bumptech.glide.request.RequestListener;
|
||||
import com.bumptech.glide.request.target.ImageViewTarget;
|
||||
import com.bumptech.glide.request.target.Target;
|
||||
|
||||
/**
|
||||
* Listener which updates the {@link ImageView} to be software rendered, because {@link
|
||||
* com.caverock.androidsvg.SVG SVG}/{@link android.graphics.Picture Picture} can't render on a
|
||||
* hardware backed {@link android.graphics.Canvas Canvas}.
|
||||
*/
|
||||
public class SvgSoftwareLayerSetter implements RequestListener<PictureDrawable> {
|
||||
|
||||
@Override
|
||||
public boolean onLoadFailed(
|
||||
GlideException e,
|
||||
Object model,
|
||||
@NonNull Target<PictureDrawable> target,
|
||||
boolean isFirstResource) {
|
||||
ImageView view = ((ImageViewTarget<?>) target).getView();
|
||||
view.setLayerType(ImageView.LAYER_TYPE_NONE, null);
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onResourceReady(
|
||||
@NonNull PictureDrawable resource,
|
||||
@NonNull Object model,
|
||||
Target<PictureDrawable> target,
|
||||
@NonNull DataSource dataSource,
|
||||
boolean isFirstResource) {
|
||||
ImageView view = ((ImageViewTarget<?>) target).getView();
|
||||
view.setLayerType(ImageView.LAYER_TYPE_SOFTWARE, null);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,6 @@ import android.content.pm.PackageManager;
|
||||
import android.os.Build;
|
||||
import android.provider.Settings;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.core.app.ActivityCompat;
|
||||
|
||||
@@ -37,7 +36,7 @@ public class MapManager {
|
||||
@SuppressLint("StaticFieldLeak")
|
||||
private static volatile MapManager sInstance;
|
||||
private final Context mContext; // 使用Application Context避免内存泄漏
|
||||
private final MMKV mMMKV;
|
||||
private final MMKV mMMKV = MMKV.mmkvWithID(CommonConfig.MMKV_ID, MMKV.MULTI_PROCESS_MODE);
|
||||
private LocationClient mLocationClient;
|
||||
private LocationClientOption mOption;
|
||||
// 线程安全的回调列表
|
||||
@@ -53,7 +52,6 @@ public class MapManager {
|
||||
private MapManager(Context context) {
|
||||
// 使用Application Context,避免持有Activity导致内存泄漏
|
||||
this.mContext = context.getApplicationContext();
|
||||
this.mMMKV = MMKV.mmkvWithID(CommonConfig.MMKV_ID, MMKV.MULTI_PROCESS_MODE);
|
||||
}
|
||||
|
||||
// 初始化单例(线程安全)
|
||||
@@ -100,11 +98,6 @@ public class MapManager {
|
||||
mLocationClient = new LocationClient(mContext);
|
||||
mLocationClient.setLocOption(getDefaultLocationClientOption());
|
||||
mLocationClient.registerLocationListener(mLocationListener);
|
||||
// 确保先停止再启动,避免重复启动
|
||||
if (mLocationClient.isStarted()) {
|
||||
mLocationClient.stop();
|
||||
}
|
||||
mLocationClient.start();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
Logger.e(TAG, "initMap: " + e.getMessage());
|
||||
@@ -113,6 +106,15 @@ public class MapManager {
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void startLocation() {
|
||||
// 确保先停止再启动,避免重复启动
|
||||
if (mLocationClient.isStarted()) {
|
||||
mLocationClient.stop();
|
||||
}
|
||||
mLocationClient.start();
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查定位权限
|
||||
*/
|
||||
|
||||
@@ -13,6 +13,7 @@ import com.qweather.sdk.basic.Lang;
|
||||
import com.qweather.sdk.basic.Unit;
|
||||
import com.qweather.sdk.parameter.weather.WeatherParameter;
|
||||
import com.qweather.sdk.response.weather.WeatherDailyResponse;
|
||||
import com.qweather.sdk.response.weather.WeatherHourlyResponse;
|
||||
import com.qweather.sdk.response.weather.WeatherNowResponse;
|
||||
import com.ttstd.dialer.BuildConfig;
|
||||
import com.ttstd.dialer.bean.CityInfo;
|
||||
@@ -158,6 +159,15 @@ public class WeatherManager {
|
||||
mQWeather.weatherNow(parameter, callback);
|
||||
}
|
||||
|
||||
public void getWeather24h(String adCode, Callback<WeatherHourlyResponse> callback) {
|
||||
String locationID = getLocationID(adCode);
|
||||
Log.e(TAG, "getWeatherNow: locationID = " + locationID);
|
||||
WeatherParameter parameter = new WeatherParameter(locationID)
|
||||
.lang(Lang.ZH_HANS)
|
||||
.unit(Unit.METRIC);
|
||||
mQWeather.weather24h(parameter, callback);
|
||||
}
|
||||
|
||||
public void getWeather10D(String adCode, Callback<WeatherDailyResponse> callback) {
|
||||
String locationID = getLocationID(adCode);
|
||||
Log.e(TAG, "getWeather10D: locationID = " + locationID);
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
package com.ttstd.dialer.network;
|
||||
|
||||
public class UrlAddress {
|
||||
|
||||
}
|
||||
@@ -43,6 +43,18 @@ public class DateUtil {
|
||||
}
|
||||
}
|
||||
|
||||
// 根据日期取得星期几
|
||||
public static String getWeek() {
|
||||
Date date = new Date();
|
||||
String[] weeks = {"星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"};
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.setTime(date);
|
||||
int weekIndex = cal.get(Calendar.DAY_OF_WEEK) - 1;
|
||||
if (weekIndex < 0) {
|
||||
weekIndex = 0;
|
||||
}
|
||||
return weeks[weekIndex];
|
||||
}
|
||||
|
||||
public static boolean isToday(String dateStr) {
|
||||
try {
|
||||
@@ -78,19 +90,20 @@ public class DateUtil {
|
||||
|
||||
public static String getWeekDayFromDateAll(String dateStr, Locale locale) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
return getWeekDayFromDate26(dateStr,locale);
|
||||
}else {
|
||||
return getWeekDayFromDate(dateStr,locale);
|
||||
return getWeekDayFromDate26(dateStr, locale);
|
||||
} else {
|
||||
return getWeekDayFromDate(dateStr, locale);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 将 yyyy-MM-dd 格式的日期字符串转换为星期几
|
||||
* @param dateStr 日期字符串,格式:yyyy-MM-dd
|
||||
* @param locale 地区设置,如 Locale.CHINA
|
||||
* @return 星期几的中文表示(如:星期一)
|
||||
*/
|
||||
/**
|
||||
* 将 yyyy-MM-dd 格式的日期字符串转换为星期几
|
||||
*
|
||||
* @param dateStr 日期字符串,格式:yyyy-MM-dd
|
||||
* @param locale 地区设置,如 Locale.CHINA
|
||||
* @return 星期几的中文表示(如:星期一)
|
||||
*/
|
||||
@RequiresApi(api = Build.VERSION_CODES.O)
|
||||
public static String getWeekDayFromDate26(String dateStr, Locale locale) {
|
||||
// 定义日期格式
|
||||
@@ -103,8 +116,9 @@ public class DateUtil {
|
||||
|
||||
/**
|
||||
* 将 yyyy-MM-dd 格式的日期字符串转换为星期几
|
||||
*
|
||||
* @param dateStr 日期字符串,格式:yyyy-MM-dd
|
||||
* @param locale 地区设置,如 Locale.CHINA
|
||||
* @param locale 地区设置,如 Locale.CHINA
|
||||
* @return 星期几的中文表示
|
||||
*/
|
||||
public static String getWeekDayFromDate(String dateStr, Locale locale) {
|
||||
@@ -122,18 +136,32 @@ public class DateUtil {
|
||||
}
|
||||
}
|
||||
|
||||
public static String convertToChineseWeekdayAll(String dateStr) {
|
||||
public static String convertToChineseWeekdayAll() {
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
||||
// 设置时区(可选,默认为系统时区)
|
||||
// sdf.setTimeZone(TimeZone.getTimeZone("GMT+8"));
|
||||
long timestamp = System.currentTimeMillis();
|
||||
Date date = new Date(timestamp);
|
||||
String dateStr = sdf.format(date);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
return convertToChineseWeekdayWithLocalDate(dateStr);
|
||||
}else {
|
||||
} else {
|
||||
return convertToChineseWeekday(dateStr);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 将yyyy-MM-dd格式的日期字符串转换为"周几"格式
|
||||
* 例如:2026-02-17 → 周二
|
||||
*/
|
||||
public static String convertToChineseWeekdayAll(String dateStr) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
return convertToChineseWeekdayWithLocalDate(dateStr);
|
||||
} else {
|
||||
return convertToChineseWeekday(dateStr);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 将yyyy-MM-dd格式的日期字符串转换为"周几"格式
|
||||
* 例如:2026-02-17 → 周二
|
||||
*/
|
||||
public static String convertToChineseWeekday(String dateStr) {
|
||||
try {
|
||||
// 解析日期
|
||||
|
||||
@@ -39,7 +39,7 @@ public class LunarCalendarFestivalUtils {
|
||||
}
|
||||
|
||||
public String getLunarCalendar() {
|
||||
return lunarMonth + "月" + lunarDay;
|
||||
return ganZhiYear + "年" + "\t" + lunarMonth + "月" + lunarDay;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,19 +1,24 @@
|
||||
package com.ttstd.dialer.utils;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.time.ZonedDateTime;
|
||||
|
||||
public class TimeUtils {
|
||||
// 根据日期取得星期几
|
||||
public static String getWeek() {
|
||||
Date date = new Date();
|
||||
String[] weeks = {"星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"};
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.setTime(date);
|
||||
int weekIndex = cal.get(Calendar.DAY_OF_WEEK) - 1;
|
||||
if (weekIndex < 0) {
|
||||
weekIndex = 0;
|
||||
public static String formatToHourDescription(String isoTimeString) {
|
||||
// 解析输入的时间字符串(例如:"2026-03-19T00:00+08:00")
|
||||
ZonedDateTime inputTime = ZonedDateTime.parse(isoTimeString);
|
||||
|
||||
// 获取当前时间,使用与输入时间相同的时区
|
||||
ZonedDateTime now = ZonedDateTime.now(inputTime.getZone());
|
||||
|
||||
// 提取输入时间的小时
|
||||
int inputHour = inputTime.getHour();
|
||||
int currentHour = now.getHour();
|
||||
|
||||
// 比较输入时间与当前时间的小时和日期
|
||||
if (inputHour == currentHour && inputTime.toLocalDate().equals(now.toLocalDate())) {
|
||||
return "现在";
|
||||
} else {
|
||||
return inputHour + "时";
|
||||
}
|
||||
return weeks[weekIndex];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user