做android日程管理系统时参考学习的博客

做android日程管理系统时参考学习的博客

比如十二小时制可以通过
int apm=calendar.get(Calendar.AM_PM);
判断当前 时间是am还是pm,apm=0,则当前是am;apm=1,则当前是pm;
然后可以通过判断,插入相应的背景图片:

		if(apm==0){ //上午
            getWindow().setBackgroundDrawableResource(R.drawable.am);
        }else if(apm==1) //中午
            getWindow().setBackgroundDrawableResource(R.drawable.am_pm);

如果需要24小时制,则可以通过date对象判断:

private void getDate() {
        Date d = new Date();
        if (d.getHours() < 10) {
            apm=0;
        } else if (d.getHours() < 17) {
            apm=1;
        } else if (d.getHours() < 20) {
            apm=2;
        } else if (d.getHours() < 24) {
            apm=3;
        }
    }
  • android滑动手势监听事件

参考博文Android开发之手势滑动(滑动手势监听)详解

手势监听实例
看过的文章
其中需要了解两个方面:
一是触摸屏事件,考虑其触摸事件,用到setOnTouchListener(new View.OnTouchListener(),实现时需实现OnTouch()方法。如:

relativeLayout.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                Log.i(getClass().getName(),"onTouch---------"+getActionName(event.getAction()));
                gestureDetector.onTouchEvent(event);
                return true;
            }
        });

二是手势检测,通过生成GestureDetector()对象,实现接口GestureDetector().OnGestureListener需实现以下六个方法:
OnDown()按下、OnFling()手指拖过、OnLongPress()长按、Onscroll()、OnShowPress()、OnSIngleTapUp()轻击。如例:

public class RingActivity extends AppCompatActivity implements GestureDetector.OnGestureListener{...}
 @Override
    public boolean onDown(MotionEvent e) {
        return false;
    }

    @Override
    public void onShowPress(MotionEvent e) {

    }

    @Override
    public boolean onSingleTapUp(MotionEvent e) {
        return false;
    }

    @Override
    public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
        return false;
    }

    @Override
    public void onLongPress(MotionEvent e) {

    }

    @Override
    public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
        //获取坐标判断向上还是向下滑动
        //上滑
        int E2_E1= (int) (e1.getX()-e2.getX());
        if(FLING_MIN_VELOCITY>E2_E1&&E2_E1>FLING_MIN_DISTANCE){
            stop();
            return true;
        }
        return false;
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        return gestureDetector.onTouchEvent(event);
    }

这里好像除了点问题,getY的时候按理说应该是竖直方向的手势监听,但是此处在手机调试时却变成了水平方向的手势判断,深感疑惑,所以这里我改成了getX来实现。但是滑动很不灵,需要滑动很多次才能实现stop()方法。

  • 图标按原比例缩放问题,参考链接(https://blog.csdn.net/xiaoming1430026911/article/details/73162322)

一开始很直接的将图标用这种方法实现,但是在用scale设置xy比例是,发现图片还是占同样的空间,而仅仅是图片变小了,周边像是设置了padding的效果

android:background="@drawable/up"

于是google找到了问题解决办法

<ImageView
        android:layout_width="35dip"
        android:layout_height="35dip"
        android:src="@drawable/up"
        android:scaleType="centerInside"
        android:layout_gravity="center"
        android:layout_marginTop="10dp"
        />
  • 时期时间格式问题

参考文章
文章1
文章2

Button stopButton = (Button) this
            .findViewById(R.id.StartTrackingEditStopTime_button);
    // 格式化时间
    SimpleDateFormat sdfStopTime = new SimpleDateFormat("hh:mm:ss a",
            Locale.ENGLISH);
    // 当前时间
    String newStoptime = sdfStopTime
            .format(new Date(System.currentTimeMillis()));

    stopButton.append(newStoptime);

此处如果是24小时则将hh改为HH
但是我这里调试的时候出现了问题,显示的时间一直不变,尚未解决该问题。

  • datepick、timepick问题,参考链接如下

更改datepick的例子

  • 日程提醒一天锁屏通知提醒设置

按照需求,希望做到将当天闹钟显示在锁屏屏幕。
效果图如下:
图片描述
对新手来说,一些没接触过的功能的确是比较难的诶,然后一开始没想法的时候确实比较抓狂,然后了解了之后,发现不过是几行代码的事情,暴哭啊。一开始想到是是直接像闹钟提醒那样直接用广播,但是一直纠结只想要弹出通知,而不需要跳转app,后面才想起用接收器接收intent,蠢哭。代码如下:

这里因为要提前一天提醒,所以我这里减去一天24小时的毫秒。哈哈哈好蠢一开始竟然用了“+”,然后左等右等等不到通知提醒。

public void set_notice(Calendar calendar){
        Intent intent_notice=new Intent();
        intent_notice.setAction("NotificationReceiver");
        // 用广播管理闹铃
        PendingIntent pi = PendingIntent.getBroadcast(this, lastid, intent_notice, 0);
        // 获取闹铃管理
        AlarmManager am = (AlarmManager) getSystemService(Activity.ALARM_SERVICE);
        // 设置闹钟
        am.set(AlarmManager.RTC_WAKEUP,calendar.getTimeInMillis()-86400000,pi);

    }

然后是receiver的代码

public class NotificationReceiver extends BroadcastReceiver {

    private static final int NOTIFICATION_FLAG = 1;
    @Override
    public void onReceive(Context context, Intent intent) {
        if(intent.getAction().equals("NotificationReceiver")){
        sendNotificationWithAction(context,intent);
        }
    }
    public void sendNotificationWithAction(Context context,Intent intent){
        //实例化管理
        final NotificationManager nm= (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        //实例化通知
        final   NotificationCompat.Builder nc=new NotificationCompat.Builder(context);
        //默认哪些特色提示
        nc.setDefaults(NotificationCompat.DEFAULT_ALL);
        nc.setAutoCancel(true);
        //通知标题
        nc.setContentTitle("日程提醒");
        //设置通知图片
        nc.setSmallIcon(android.R.drawable.ic_lock_idle_alarm);
        //通知内容
        nc.setContentText("您今日有日程安排!");
        nc.setContentIntent(mainPendingIntent);
        //得到build
        Notification notification=nc.build();
        //发送通知
        nm.notify(NOTIFICATION_FLAG,notification);
    }
}

别忘了在manifest注册接收器

 <receiver
            android:name=".NotificationReceiver"
            android:enabled="true"
            android:exported="true">
            <intent-filter>
                <action android:name="NotificationReceiver" />
            </intent-filter>
        </receiver>

参考博文如下:
Android 如何让程序定时进行消息通知到通知栏
Android使用CountDownTimer类实现倒计时闹钟
Android定时任务的应用及实现
LoaderMan
学习笔记<言简-实用-高效>
Android向系统日历添加日程提醒事件

Android中pendingIntent的深入理解

  • 1
    点赞
  • 22
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值