团队冲刺第十天
Posted yumazemadui
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了团队冲刺第十天相关的知识,希望对你有一定的参考价值。
1、今天将自己的运动数据保存到了数据库。并且通过数据库的调用获取定位点绘制除了静态地图轨迹。
/**
* 讲google地图的wgs84坐标转化为百度地图坐标
*/
private void coordinateConvert(){
DBOpenMessageUserlocation dbOpenMessageUserlocation;
dbOpenMessageUserlocation=new DBOpenMessageUserlocation(StaticDemo.this,"db_location",null,1);
Cursor cursor = dbOpenMessageUserlocation.getAllLocation("1");
location location=new location();
if (cursor != null) {
while (cursor.moveToNext()) {
location.points=cursor.getString(cursor.getColumnIndex("points"));
}
}
// List<LatLng> list = null;
// if (!wen.equals("null")) {
// list = gson.fromJson(wen, new TypeToken<List<LatLng>>() {}.getType());
// for(int i = 0; i < list.size() ; i++)
// {
// LatLng p = list.get(i);
// list.add(p);
// }
// }
String wen="";
wen=location.getPoints();
String[] ll = wen.split(",");
Toast.makeText(StaticDemo.this,"初始化完成",Toast.LENGTH_SHORT).show();
CoordinateConverter converter = new CoordinateConverter();
converter.from(CoordType.COMMON);
double lanSum = 0;
double lonSum = 0;
System.out.println(Double.valueOf(ll[0]));
Toast.makeText(StaticDemo.this,String.valueOf(Double.valueOf(ll[0])),Toast.LENGTH_SHORT).show();
for (int i = 0; ll.length> i; ) {
LatLng desLatLng = new LatLng(Double.valueOf(ll[i]), Double.valueOf(ll[i+1]));
//converter.coord(sourceLatLng);
//LatLng desLatLng = converter.convert();
latLngs.add(desLatLng);
lanSum += desLatLng.latitude;
lonSum += desLatLng.longitude;
i+=2;
}
target = new LatLng(lanSum/latLngs.size(), lonSum/latLngs.size());
}
2、
摘要:今天主要解决了昨天的问题,问题一:当退出APP再进入时,所有的闹钟都变成了关闭状态。这个问题的原因是代码中显示开关按钮状态部分的代码逻辑出现了问题,重新换了个思路后就轻松解决了这个问题。还有就是长按删除的问题,虽然数据可以删除,但是没有解决页面刷新的问题,目前正在找可以在apapter里刷新list的解决方法。除了解决这俩问题,另外又美化了一些界面,并把队友做的音乐播放部分的内容添加到了整个项目中。下面是主要代码和截图。
package com.alarm;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Build;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CompoundButton;
import android.widget.LinearLayout;
import android.widget.Switch;
import android.widget.TextView;
import android.widget.Toast;
import androidx.appcompat.app.AlertDialog;
import com.example.keeprunning1.R;
import java.util.Calendar;
import java.util.List;
import static android.content.Context.ALARM_SERVICE;
public class AlarmAdapter extends BaseAdapter {
private List<Alarm> mlist;
private Context mContext;
private LayoutInflater mlayoutInflater;
private AlarmOperator malarmOperator;
Calendar calendar;
public AlarmAdapter(Context context, List<Alarm> list) {
mContext = context;
mlist = list;
mlayoutInflater = LayoutInflater.from(context);
malarmOperator = new AlarmOperator(context);
}
@Override
public int getCount() {
return mlist.size();
}
@Override
public Object getItem(int position) {
return position;
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
final ViewHolder viewHolder;
if (convertView == null) {
viewHolder = new ViewHolder();
convertView = mlayoutInflater.inflate(R.layout.alarmitem, null);
viewHolder.mHour = convertView.findViewById(R.id.hour);
viewHolder.mMinute = convertView.findViewById(R.id.minute);
viewHolder.mContent = convertView.findViewById(R.id.content_item);
viewHolder.mNet=convertView.findViewById(R.id.net);
viewHolder.mClockType = convertView.findViewById(R.id.switch_control);
viewHolder.todetail = convertView.findViewById(R.id.todetail);
convertView.setTag(viewHolder);
} else {
viewHolder = (ViewHolder) convertView.getTag();
}
final Alarm bean = mlist.get(position);
final String name = bean.getUsername();
final String hour = bean.getHour();
final String minute = bean.getMinute();
Log.i("name", name);
int clockType = bean.getClockType();
Log.d("volley", String.valueOf(clockType));
if (clockType == 1) {
viewHolder.mClockType.setChecked(true);
} else if (clockType == 0) {
viewHolder.mClockType.setChecked(false);
viewHolder.mHour.setTextColor(mContext.getResources().getColor(R.color.colorGray));
viewHolder.mMinute.setTextColor(mContext.getResources().getColor(R.color.colorGray));
viewHolder.mNet.setTextColor(mContext.getResources().getColor(R.color.colorGray));
viewHolder.mContent.setTextColor(mContext.getResources().getColor(R.color.colorGray));
}
viewHolder.todetail.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
builder.setMessage("确定删除?");
builder.setTitle("提示");
builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
malarmOperator.deletebyuser(name, hour, minute);
//notifyDataSetChanged();
AlarmManager am;
Intent intent1 = new Intent(mContext, CallAlarm.class);
PendingIntent sender1=PendingIntent.getBroadcast(
mContext,0, intent1, 0);
am =(AlarmManager)mContext.getSystemService(ALARM_SERVICE);
am.cancel(sender1);
Toast.makeText(mContext, "删除成功", Toast.LENGTH_SHORT).show();
}
});
builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
builder.create().show();
return true;
}
});
viewHolder.mClockType.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
malarmOperator.updateswitch(name, hour, minute);
// viewHolder.mClockType.setChecked(true);
Toast.makeText(mContext, "开启闹钟", Toast.LENGTH_SHORT).show();
viewHolder.mHour.setTextColor(mContext.getResources().getColor(R.color.colorBlack));
viewHolder.mMinute.setTextColor(mContext.getResources().getColor(R.color.colorBlack));
viewHolder.mNet.setTextColor(mContext.getResources().getColor(R.color.colorBlack));
viewHolder.mContent.setTextColor(mContext.getResources().getColor(R.color.colorBlack));
Intent intent = new Intent(mContext, CallAlarm.class);
PendingIntent sender = PendingIntent.getBroadcast(
mContext, 0, intent, 0);
AlarmManager am;
//使用闹钟服务
am = (AlarmManager) mContext.getSystemService(ALARM_SERVICE);
calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
calendar.set(Calendar.HOUR_OF_DAY, Integer.parseInt(bean.getHour()));
calendar.set(Calendar.MINUTE, Integer.parseInt(bean.getMinute()));
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0);
Log.e("TAG", calendar.getTimeInMillis() + "");
Log.e("TAG", System.currentTimeMillis() + "");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
if (System.currentTimeMillis() > calendar.getTimeInMillis() + 40000) {
//加24小时
am.setExact(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis() + 86400000, sender);
} else {
am.setExact(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), sender);
}
}
} else if (!isChecked) {
malarmOperator.updateswitch1(name, hour, minute);
viewHolder.mHour.setTextColor(mContext.getResources().getColor(R.color.colorGray));
viewHolder.mMinute.setTextColor(mContext.getResources().getColor(R.color.colorGray));
viewHolder.mNet.setTextColor(mContext.getResources().getColor(R.color.colorGray));
viewHolder.mContent.setTextColor(mContext.getResources().getColor(R.color.colorGray));
Intent intent = new Intent(mContext, CallAlarm.class);
PendingIntent sender = PendingIntent.getBroadcast(
mContext, 0, intent, 0);
AlarmManager am;
am = (AlarmManager) mContext.getSystemService(ALARM_SERVICE);
am.cancel(sender);
Toast.makeText(mContext, "关闭闹钟", Toast.LENGTH_SHORT).show();
}
}
});
viewHolder.mContent.setText(bean.content);
viewHolder.mHour.setText(bean.hour+"");
viewHolder.mMinute.setText(bean.minute+"");
return convertView;
}
public class ViewHolder {
public TextView mHour;
public TextView mMinute;
public TextView mContent;
public TextView mNet;
Switch mClockType;
LinearLayout todetail;
//public CheckBox mCheckBox;
}
}
3、今天在昨天的基础上,增加了打卡的功能实现,点击打卡,显示打卡成功。根据不同时间段的日期,会有返回当前日期提醒。遇到的问题:当天打卡后,不可以时时更新显示在日历上,只有返回别的界面或者重选日期再次回到当前日期时才会显示打卡标志。计划明天完成这个功能。
package com.example.rili.sign; import android.content.Context; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import java.util.ArrayList; import java.util.List; public class SignInHelper { private static final String TAG="SignInHelper--->>>"; private SQLiteDatabase db; public SignInHelper(Context context){ db=new LocalDbOpenHelper(context).getReadableDatabase(); } public void insert(String signIn){ String sql = "insert into signIn values(‘"+signIn+"‘)"; db.execSQL(sql); } public List<String> query(int year,int month) { String mid = month > 9 ? "-" : "-0"; String selection = "date like ?"; String[] selectArgs = new String[]{"%" + year + mid + month + "%"}; Cursor cursor = db.query("signIn",null,selection,selectArgs,null,null,null); List<String> result=new ArrayList<>(); while (cursor.moveToNext()){ String date=cursor.getString(cursor.getColumnIndex("date")); result.add(date); } cursor.close(); return result; } }
package com.example.rili; import androidx.appcompat.app.AppCompatActivity; import android.app.DatePickerDialog; import android.content.Context; import android.content.DialogInterface; import android.graphics.Color; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.DatePicker; import android.widget.TextView; import android.widget.Toast; import com.example.rili.view.MonPickerDialog; import com.example.rili.view.SignView; import java.util.Calendar; public class MainActivity extends AppCompatActivity { private static final String TAG = "MainActivity--->>>"; private SignView signDate; private TextView tvYear; private Button sign; private Context context = this; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); initView(); } private void initView() { sign = findViewById(R.id.btn_sign); signDate = findViewById(R.id.signDate); tvYear = signDate.findViewById(R.id.tvYear); signDate.init(); if(signDate.isSign()) { sign.setBackgroundColor(Color.GRAY); sign.setText("今日已打卡"); sign.setClickable(false); }else { sign.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { handle(); } }); } tvYear.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { showMonPicker(); } }); } private void handle() { signDate.signIn(new DateAdapter.OnSignListener() { @Override public void OnSignedSucceed() { showToast("打卡成功"); sign.setBackgroundColor(Color.GRAY); sign.setText("今日已打卡"); sign.setClickable(false); } @Override public void OnSignedFail() { showToast("打卡失败"); } }); } private void showMonPicker() { final Calendar localCalendar = Calendar.getInstance(); localCalendar.setTime(DateUtil.strToDate("yyyy-MM", tvYear.getText().toString())); MonPickerDialog dialog = new MonPickerDialog(context,new DatePickerDialog.OnDateSetListener() { @Override public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { localCalendar.set(Calendar.YEAR, year); localCalendar.set(Calendar.MONTH, monthOfYear); localCalendar.set(Calendar.DATE, dayOfMonth); } }, localCalendar.get(Calendar.YEAR), localCalendar.get(Calendar.MONTH),localCalendar.get(Calendar.DATE)); dialog.show(); dialog.setButton(DialogInterface.BUTTON_POSITIVE, "确定", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { tvYear.setText(DateUtil.calendarToDateTime(localCalendar, "yyyy-MM")); refresh(localCalendar.get(Calendar.YEAR),localCalendar.get(Calendar.MONTH)+1); } }); } private void refresh(int year,int month) { if(year!=DateUtil.year || month!=DateUtil.month){ signDate.init(year,month); sign.setBackgroundColor(getResources().getColor(R.color.sky_blue)); sign.setText("返回当前日期"); sign.setClickable(true); sign.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { initView(); } }); } } private void showToast(String msg){ Toast.makeText(context, msg, Toast.LENGTH_SHORT).show(); } }
相关截图:
以上是关于团队冲刺第十天的主要内容,如果未能解决你的问题,请参考以下文章