version:1.0.1
update:优化屏幕适配,更换图标 bugfixes:
This commit is contained in:
@@ -31,7 +31,6 @@ import androidx.fragment.app.FragmentManager;
|
||||
import androidx.fragment.app.FragmentTransaction;
|
||||
import androidx.lifecycle.Observer;
|
||||
|
||||
import com.alarmclock.uiui.IAlarmAidlInterface;
|
||||
import com.blankj.utilcode.util.NetworkUtils;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
@@ -256,22 +255,6 @@ public class MainActivity extends BaseMvvmActivity<MainViewModel, PhoneActivityM
|
||||
// mViewModel.getAppList();
|
||||
|
||||
registReceiver();
|
||||
|
||||
mAlarmServiceConnection = new ServiceConnection() {
|
||||
@Override
|
||||
public void onServiceConnected(ComponentName name, IBinder service) {
|
||||
Log.e(TAG, "onServiceConnected: ");
|
||||
mIAlarmAidlInterface = IAlarmAidlInterface.Stub.asInterface(service);
|
||||
getAlarmData();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onServiceDisconnected(ComponentName name) {
|
||||
Log.e(TAG, "onServiceDisconnected: ");
|
||||
mIAlarmAidlInterface = null;
|
||||
}
|
||||
};
|
||||
bindAlarmService();
|
||||
RemoteManager.setListener(this);
|
||||
initAmap();
|
||||
}
|
||||
@@ -298,20 +281,7 @@ public class MainActivity extends BaseMvvmActivity<MainViewModel, PhoneActivityM
|
||||
}
|
||||
|
||||
private ServiceConnection mAlarmServiceConnection;
|
||||
private IAlarmAidlInterface mIAlarmAidlInterface;
|
||||
|
||||
private void bindAlarmService() {
|
||||
if (mIAlarmAidlInterface == null) {
|
||||
//这是连接aidl服务的代码
|
||||
Intent intent = new Intent();
|
||||
intent.setAction("com.alarmclock.uiui.IAlarmAidlInterface");
|
||||
intent.setPackage("com.alarmclock.uiui");
|
||||
intent.setComponent(new ComponentName("com.alarmclock.uiui", "com.alarmclock.uiui.AIDLAlarmService"));
|
||||
bindService(intent, mAlarmServiceConnection, Context.BIND_AUTO_CREATE);
|
||||
} else {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static void toggleNotificationListenerService(Context context) {
|
||||
Log.e(TAG, "toggleNotificationListenerService");
|
||||
@@ -323,28 +293,6 @@ public class MainActivity extends BaseMvvmActivity<MainViewModel, PhoneActivityM
|
||||
PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
|
||||
}
|
||||
|
||||
private void getAlarmData() {
|
||||
if (mIAlarmAidlInterface == null) {
|
||||
bindAlarmService();
|
||||
return;
|
||||
}
|
||||
try {
|
||||
String json = mIAlarmAidlInterface.getAlarm();
|
||||
Log.e(TAG, "onServiceConnected: " + json);
|
||||
if ("暂无闹钟".equalsIgnoreCase(json) || TextUtils.isEmpty(json)) {
|
||||
// mCustomFragment.setAlarmItem(null);
|
||||
return;
|
||||
}
|
||||
Type type = new TypeToken<List<AlarmItem>>() {
|
||||
}.getType();
|
||||
List<AlarmItem> alarmItem = new Gson().fromJson(json, type);
|
||||
// mCustomFragment.setAlarmItem(alarmItem);
|
||||
} catch (RemoteException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void addData() {
|
||||
Log.e(TAG, "addData: ");
|
||||
List<Fragment> fragmentList = new ArrayList<>();
|
||||
@@ -425,7 +373,6 @@ public class MainActivity extends BaseMvvmActivity<MainViewModel, PhoneActivityM
|
||||
super.onStart();
|
||||
AppUsedTimeUtils.getInstance().setAppPackageName(BuildConfig.APPLICATION_ID);
|
||||
AppUsedTimeUtils.getInstance().setStartTime(System.currentTimeMillis());
|
||||
getAlarmData();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -103,7 +103,7 @@ public class MainViewModel extends BaseViewModel<PhoneActivityMainBinding, Activ
|
||||
if (Code.OK == weatherBean.getCode()) {
|
||||
WeatherNowBean.NowBaseBean now = weatherBean.getNow();
|
||||
LiveEventBus
|
||||
.get("some_key1")
|
||||
.get("getWeatherNowKey")
|
||||
.post(now);
|
||||
mNowBaseBeanData.postValue(now);
|
||||
Log.d("getWeatherNow", "onSuccess: now " + new Gson().toJson(now));
|
||||
@@ -138,7 +138,7 @@ public class MainViewModel extends BaseViewModel<PhoneActivityMainBinding, Activ
|
||||
WeatherHourlyBean.HourlyBean now = hourly.get(0);
|
||||
mHourlyBeanData.postValue(now);
|
||||
LiveEventBus
|
||||
.get("some_key2")
|
||||
.get("getWeather24HourlyKey")
|
||||
.post(now);
|
||||
}
|
||||
} else {
|
||||
@@ -174,7 +174,7 @@ public class MainViewModel extends BaseViewModel<PhoneActivityMainBinding, Activ
|
||||
WeatherDailyBean.DailyBean dailyBean = weatherDailyBean.getDaily().get(0);
|
||||
DailyBeanData.postValue(dailyBean);
|
||||
LiveEventBus
|
||||
.get("some_key3")
|
||||
.get("getWeather7DKey")
|
||||
.post(dailyBean);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -210,7 +210,7 @@ public class WeatherViewModel extends BaseViewModel<ActivityWeatherBinding, Acti
|
||||
mWeatherNowData.setValue(weatherBean);
|
||||
WeatherNowBean.NowBaseBean now = weatherBean.getNow();
|
||||
LiveEventBus
|
||||
.get("some_key1")
|
||||
.get("getWeatherNowKey")
|
||||
.post(now);
|
||||
}
|
||||
});
|
||||
@@ -238,7 +238,7 @@ public class WeatherViewModel extends BaseViewModel<ActivityWeatherBinding, Acti
|
||||
mWeatherDailyData.setValue(weatherDailyBean);
|
||||
WeatherDailyBean.DailyBean dailyBean = weatherDailyBean.getDaily().get(0);
|
||||
LiveEventBus
|
||||
.get("some_key3")
|
||||
.get("getWeather7DKey")
|
||||
.post(dailyBean);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -22,6 +22,7 @@ import com.tencent.mmkv.MMKV;
|
||||
import com.xxpatx.os.R;
|
||||
import com.xxpatx.os.activity.contact.AddWechatContactActivity;
|
||||
import com.xxpatx.os.activity.contact.EditContactActivity;
|
||||
import com.xxpatx.os.activity.weather.WeatherActivity;
|
||||
import com.xxpatx.os.adapter.WechatContactAdapter;
|
||||
import com.xxpatx.os.base.mvvm.fragment.BaseMvvmFragment;
|
||||
import com.xxpatx.os.bean.BaseResponse;
|
||||
@@ -31,6 +32,8 @@ import com.xxpatx.os.config.CommonConfig;
|
||||
import com.xxpatx.os.databinding.FragmentContactHomeBinding;
|
||||
import com.xxpatx.os.dialog.EditContactDialog;
|
||||
import com.xxpatx.os.utils.DayUtils;
|
||||
import com.xxpatx.os.utils.ScreenUtils;
|
||||
import com.xxpatx.os.view.EquallyDividedItemDecoration;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
@@ -43,6 +46,7 @@ public class ContactFragment extends BaseMvvmFragment<ContactViewModel, Fragment
|
||||
|
||||
private FragmentActivity mContext;
|
||||
private WechatContactAdapter mContactAdapter;
|
||||
private int SPAN_COUNT;
|
||||
|
||||
@Override
|
||||
protected int getLayoutId() {
|
||||
@@ -68,10 +72,13 @@ public class ContactFragment extends BaseMvvmFragment<ContactViewModel, Fragment
|
||||
}
|
||||
});
|
||||
if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
|
||||
mViewDataBinding.rvContact.setLayoutManager(new GridLayoutManager(getContext(), 3));
|
||||
SPAN_COUNT = 3;
|
||||
} else {
|
||||
mViewDataBinding.rvContact.setLayoutManager(new GridLayoutManager(getContext(), 2));
|
||||
SPAN_COUNT = 2;
|
||||
}
|
||||
mViewDataBinding.rvContact.setLayoutManager(new GridLayoutManager(getContext(), SPAN_COUNT));
|
||||
EquallyDividedItemDecoration equallyDividedItemDecoration = new EquallyDividedItemDecoration(SPAN_COUNT, ScreenUtils.dip2px(mContext, 6));
|
||||
mViewDataBinding.rvContact.addItemDecoration(equallyDividedItemDecoration);
|
||||
mViewDataBinding.rvContact.setAdapter(mContactAdapter);
|
||||
setTime();
|
||||
initAmap();
|
||||
@@ -105,7 +112,7 @@ public class ContactFragment extends BaseMvvmFragment<ContactViewModel, Fragment
|
||||
@Override
|
||||
protected void initData(Bundle savedInstanceState) {
|
||||
LiveEventBus
|
||||
.get("some_key1", WeatherNowBean.NowBaseBean.class)
|
||||
.get("getWeatherNowKey", WeatherNowBean.NowBaseBean.class)
|
||||
.observe(this, new Observer<WeatherNowBean.NowBaseBean>() {
|
||||
@Override
|
||||
public void onChanged(@Nullable WeatherNowBean.NowBaseBean nowBaseBean) {
|
||||
@@ -132,7 +139,7 @@ public class ContactFragment extends BaseMvvmFragment<ContactViewModel, Fragment
|
||||
});
|
||||
|
||||
LiveEventBus
|
||||
.get("some_key2", WeatherHourlyBean.HourlyBean.class)
|
||||
.get("getWeather24HourlyKey", WeatherHourlyBean.HourlyBean.class)
|
||||
.observe(this, new Observer<WeatherHourlyBean.HourlyBean>() {
|
||||
@Override
|
||||
public void onChanged(@Nullable WeatherHourlyBean.HourlyBean hourlyBean) {
|
||||
@@ -152,7 +159,7 @@ public class ContactFragment extends BaseMvvmFragment<ContactViewModel, Fragment
|
||||
});
|
||||
|
||||
LiveEventBus
|
||||
.get("some_key3", WeatherDailyBean.DailyBean.class)
|
||||
.get("getWeather7DKey", WeatherDailyBean.DailyBean.class)
|
||||
.observe(this, new Observer<WeatherDailyBean.DailyBean>() {
|
||||
@Override
|
||||
public void onChanged(@Nullable WeatherDailyBean.DailyBean dailyBean) {
|
||||
@@ -256,5 +263,9 @@ public class ContactFragment extends BaseMvvmFragment<ContactViewModel, Fragment
|
||||
Intent intent = new Intent(getContext(), AddWechatContactActivity.class);
|
||||
startActivity(intent);
|
||||
}
|
||||
|
||||
public void toWeather(View view) {
|
||||
startActivity(new Intent(mContext, WeatherActivity.class));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -224,7 +224,7 @@ public class HomeFragment extends BaseMvvmFragment<HomeViewModel, FragmentHomeBi
|
||||
}
|
||||
});
|
||||
LiveEventBus
|
||||
.get("some_key1", WeatherNowBean.NowBaseBean.class)
|
||||
.get("getWeatherNowKey", WeatherNowBean.NowBaseBean.class)
|
||||
.observe(this, new Observer<WeatherNowBean.NowBaseBean>() {
|
||||
@Override
|
||||
public void onChanged(@Nullable WeatherNowBean.NowBaseBean nowBaseBean) {
|
||||
@@ -251,7 +251,7 @@ public class HomeFragment extends BaseMvvmFragment<HomeViewModel, FragmentHomeBi
|
||||
});
|
||||
|
||||
LiveEventBus
|
||||
.get("some_key2", WeatherHourlyBean.HourlyBean.class)
|
||||
.get("getWeather24HourlyKey", WeatherHourlyBean.HourlyBean.class)
|
||||
.observe(this, new Observer<WeatherHourlyBean.HourlyBean>() {
|
||||
@Override
|
||||
public void onChanged(@Nullable WeatherHourlyBean.HourlyBean hourlyBean) {
|
||||
@@ -271,7 +271,7 @@ public class HomeFragment extends BaseMvvmFragment<HomeViewModel, FragmentHomeBi
|
||||
});
|
||||
|
||||
LiveEventBus
|
||||
.get("some_key3", WeatherDailyBean.DailyBean.class)
|
||||
.get("getWeather7DKey", WeatherDailyBean.DailyBean.class)
|
||||
.observe(this, new Observer<WeatherDailyBean.DailyBean>() {
|
||||
@Override
|
||||
public void onChanged(@Nullable WeatherDailyBean.DailyBean dailyBean) {
|
||||
@@ -509,7 +509,7 @@ public class HomeFragment extends BaseMvvmFragment<HomeViewModel, FragmentHomeBi
|
||||
}
|
||||
|
||||
public void toVideoplayer(View view) {
|
||||
ApkUtils.openPackage(mContext, "com.uiui.videoplayer", "com.uiui.videoplayer.activity.main.MainActivity");
|
||||
ApkUtils.openPackage(mContext, "com.xxpatx.jtxc", "com.xxpatx.jtxc.activity.main.MainActivity");
|
||||
}
|
||||
|
||||
public void openSettings(View view) {
|
||||
|
||||
@@ -104,7 +104,7 @@ public class SettingsFragment extends BaseMvvmFragment<SettingsViewModel, Fragme
|
||||
}
|
||||
});
|
||||
LiveEventBus
|
||||
.get("some_key1", WeatherNowBean.NowBaseBean.class)
|
||||
.get("getWeatherNowKey", WeatherNowBean.NowBaseBean.class)
|
||||
.observe(this, new Observer<WeatherNowBean.NowBaseBean>() {
|
||||
@Override
|
||||
public void onChanged(@Nullable WeatherNowBean.NowBaseBean nowBaseBean) {
|
||||
@@ -131,7 +131,7 @@ public class SettingsFragment extends BaseMvvmFragment<SettingsViewModel, Fragme
|
||||
});
|
||||
|
||||
LiveEventBus
|
||||
.get("some_key2", WeatherHourlyBean.HourlyBean.class)
|
||||
.get("getWeather24HourlyKey", WeatherHourlyBean.HourlyBean.class)
|
||||
.observe(this, new Observer<WeatherHourlyBean.HourlyBean>() {
|
||||
@Override
|
||||
public void onChanged(@Nullable WeatherHourlyBean.HourlyBean hourlyBean) {
|
||||
@@ -151,7 +151,7 @@ public class SettingsFragment extends BaseMvvmFragment<SettingsViewModel, Fragme
|
||||
});
|
||||
|
||||
LiveEventBus
|
||||
.get("some_key3", WeatherDailyBean.DailyBean.class)
|
||||
.get("getWeather7DKey", WeatherDailyBean.DailyBean.class)
|
||||
.observe(this, new Observer<WeatherDailyBean.DailyBean>() {
|
||||
@Override
|
||||
public void onChanged(@Nullable WeatherDailyBean.DailyBean dailyBean) {
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
package com.xxpatx.os.view;
|
||||
|
||||
import android.graphics.Rect;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
public class EquallyDividedItemDecoration extends RecyclerView.ItemDecoration {
|
||||
private static final String TAG = "EquallyDividedItemDecoration";
|
||||
|
||||
private int mSpanCount;//横条目数量
|
||||
private int mHalfRowSpacing;//行间距的一半
|
||||
private int mHalfColumnSpacing;// 列间距的一半
|
||||
|
||||
|
||||
public EquallyDividedItemDecoration(int spanCount, int halfRowSpacing) {
|
||||
mSpanCount = spanCount;
|
||||
mHalfRowSpacing = halfRowSpacing;
|
||||
mHalfColumnSpacing = halfRowSpacing;
|
||||
}
|
||||
|
||||
public EquallyDividedItemDecoration(int spanCount, int halfRowSpacing, int halfColumnSpacing) {
|
||||
mSpanCount = spanCount;
|
||||
mHalfRowSpacing = halfRowSpacing;
|
||||
mHalfColumnSpacing = halfColumnSpacing;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getItemOffsets(@NonNull Rect outRect, @NonNull View view, @NonNull RecyclerView parent, @NonNull RecyclerView.State state) {
|
||||
super.getItemOffsets(outRect, view, parent, state);
|
||||
int position = parent.getChildAdapterPosition(view); // 获取view 在adapter中的位置。
|
||||
Log.d(TAG, "getItemOffsets: position = " + position);
|
||||
|
||||
int itemCount = parent.getAdapter().getItemCount();//item全部数量
|
||||
Log.d(TAG, "getItemOffsets: itemCount = " + itemCount);
|
||||
|
||||
int column = position % mSpanCount; // view 所在的列
|
||||
Log.d(TAG, "getItemOffsets: column = " + column);
|
||||
|
||||
if (column == 0) {
|
||||
// outRect.left = 2 * mHalfRowSpacing;
|
||||
outRect.left = 0;
|
||||
outRect.right = mHalfRowSpacing;
|
||||
} else if (column == mSpanCount - 1) {
|
||||
outRect.left = mHalfRowSpacing;
|
||||
// outRect.right = 2 * mHalfRowSpacing;
|
||||
outRect.right = 0;
|
||||
} else {
|
||||
outRect.left = mHalfRowSpacing;
|
||||
outRect.right = mHalfRowSpacing;
|
||||
}
|
||||
|
||||
int row = (position / mSpanCount);//所在行
|
||||
Log.d(TAG, "getItemOffsets: row = " + row);
|
||||
int maxRow = (int) Math.ceil((double) itemCount / mSpanCount);//一共多少行
|
||||
Log.d(TAG, "getItemOffsets: maxRow = " + maxRow);
|
||||
|
||||
if (row == 0) {
|
||||
// outRect.top = 2 * mHalfColumnSpacing;
|
||||
outRect.top = 0;
|
||||
outRect.bottom = mHalfColumnSpacing;
|
||||
} else if (row == maxRow - 1) {
|
||||
outRect.top = mHalfColumnSpacing;
|
||||
// outRect.bottom = 2 * mHalfColumnSpacing;
|
||||
outRect.bottom = 0;
|
||||
} else {
|
||||
outRect.top = mHalfColumnSpacing;
|
||||
outRect.bottom = mHalfColumnSpacing;
|
||||
}
|
||||
|
||||
Log.d(TAG, "getItemOffsets: outRect.left = " + outRect.left);
|
||||
Log.d(TAG, "getItemOffsets: outRect.right = " + outRect.right);
|
||||
Log.d(TAG, "getItemOffsets: outRect.top = " + outRect.top);
|
||||
Log.d(TAG, "getItemOffsets: outRect.bottom = " + outRect.bottom);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user