• 第一阶段个人冲刺博客第十天


    今天是第一阶段项目冲刺的最后一天,我们团队一起开了一次对接会议,将每个人的个人独立项目合成到组长的主项目中,完成了第一阶段冲刺的的总目标,虽然有很多不足,但基本的功能都实现了,算是开了个好头。

    package com.example.superman.test;
    
    import android.content.Context;
    import android.content.DialogInterface;
    import android.content.Intent;
    import android.content.SharedPreferences;
    import android.os.Bundle;
    import android.provider.Settings;
    import android.support.design.widget.FloatingActionButton;
    import android.support.design.widget.Snackbar;
    import android.support.v7.app.AlertDialog;
    import android.view.Gravity;
    import android.view.View;
    import android.support.design.widget.NavigationView;
    import android.support.v4.view.GravityCompat;
    import android.support.v4.widget.DrawerLayout;
    import android.support.v7.app.ActionBarDrawerToggle;
    import android.support.v7.app.AppCompatActivity;
    import android.support.v7.widget.Toolbar;
    import android.view.Menu;
    import android.view.MenuItem;
    import android.view.ViewGroup;
    import android.widget.TableLayout;
    import android.widget.TableRow;
    import android.widget.TextView;
    import android.widget.Toast;
    
    import java.sql.Time;
    import java.text.ParseException;
    import java.text.SimpleDateFormat;
    import java.util.Calendar;
    import java.util.Date;
    
    public class MainActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener {
        private final int WC = ViewGroup.LayoutParams.WRAP_CONTENT;
        private final int MP = ViewGroup.LayoutParams.MATCH_PARENT;
        private TableLayout tableLayout;
        private int Sumline;
        private int MorningLesson;
        private int AfternoonLesson;
        private int NightLesson;
        private int lie;
        private String Lesson;
        private String lessonno;
        private int WeekNumer;
        private static Context sContext = null;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
    
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            sContext = this;
            Toolbar toolbar = findViewById(R.id.toolbar);
            setSupportActionBar(toolbar);
            IsSummer();
            SharedPreferences Table=ReviseTable();
            GetInitNum(Table);
            SetWeekShow(Table);
            Init(Table);
            ShowTableInformation(Table);
    
            FloatingActionButton fab = findViewById(R.id.fab);
            fab.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                            .setAction("Action", null).show();
                }
            });
    
            DrawerLayout drawer =  findViewById(R.id.drawer_layout);
            ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
                    this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
            drawer.addDrawerListener(toggle);
            toggle.syncState();
            NavigationView navigationView = findViewById(R.id.nav_view);
            navigationView.setNavigationItemSelectedListener(this);
        }
    
        private void IsSummer() {
            String BeginTime="2019-05-01";
            String EndTime="2019-10-01";
            String MowYear=new TimeTool().getYear();
            BeginTime.replace("2019",MowYear);
            EndTime.replace("2019",MowYear);
            SharedPreferences sp=getSharedPreferences("Table",MODE_PRIVATE);
    
        }
    
    
        private void ShowTableInformation(SharedPreferences sp)
        {
            Calendar cal = Calendar.getInstance();
            String GetTodayLessonNameTemp="";
            int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK)-1;
            for(int i=1;i<=Sumline;i++)
            {
                String temp=sp.getString(dayOfWeek*100+i+"","");
                if(temp.equals(""))
                {
                    continue;
                }
                else
                {
                    GetTodayLessonNameTemp=temp+","+GetTodayLessonNameTemp;
                }
    
            }
            if(GetTodayLessonNameTemp.equals(""))
            {
                PushService.addNotification(0,"课程提示","今日课程","今天没有课程,休息一下吧");
            }
            else
            {
                PushService.addNotification(0,"课程提示","今日课程",GetTodayLessonNameTemp);
            }
        }
    
        @Override
        public void onBackPressed() {
            DrawerLayout drawer = findViewById(R.id.drawer_layout);
            if (drawer.isDrawerOpen(GravityCompat.START)) {
                drawer.closeDrawer(GravityCompat.START);
            } else {
                super.onBackPressed();
            }
        }
        @Override
        public boolean onCreateOptionsMenu(Menu menu) {
            // Inflate the menu; this adds items to the action bar if it is present.
            getMenuInflater().inflate(R.menu.main, menu);
            return true;
        }
    
        @Override
        public boolean onOptionsItemSelected(MenuItem item) {
            // Handle action bar item clicks here. The action bar will
            // automatically handle clicks on the Home/Up button, so long
            // as you specify a parent activity in AndroidManifest.xml.
            int id = item.getItemId();
    
            //noinspection SimplifiableIfStatement
            if (id == R.id.action_settings)
            {
                Intent intent=new Intent();
                intent.setClass(MainActivity.this,Setting.class);
                startActivity(intent);
                //return true;
            }
            else if(id==R.id.action_addlesson)
            {
                Intent intent=new Intent();
                intent.setClass(MainActivity.this,AddLesson.class);
                startActivity(intent);
            }
            //return super.onOptionsItemSelected(item);
            return false;
        }
    
        @SuppressWarnings("StatementWithEmptyBody")
        @Override
        public boolean onNavigationItemSelected(MenuItem item) {
            // Handle navigation view item clicks here.
            int id = item.getItemId();
    
            if (id == R.id.SearchEmptyClassRoom) {
                Intent intent=new Intent(MainActivity.this,SearchEmptyClassroom.class);
                startActivity(intent);
                // Handle the camera action
            } else if (id == R.id.nav_gallery) {
    
            } else if (id == R.id.nav_manage) {
    
            } else if (id == R.id.SetAlarm) {
                SetAlarm();
    
            } else if (id == R.id.nav_share) {
    
            } else if (id == R.id.nav_send) {
    
            }
    
            DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
            drawer.closeDrawer(GravityCompat.START);
            return true;
        }
    
        private void SetAlarm() {
            AlertDialog alertDialog = new AlertDialog.Builder(this)
                    .setTitle("温馨提示")
                    .setMessage("是否设置课程前十分钟闹钟提醒")
                    .setIcon(R.mipmap.ic_launcher)
                    .setPositiveButton("设置", new DialogInterface.OnClickListener() {//添加"Yes"按钮
                        @Override
                        public void onClick(DialogInterface dialogInterface, int i) {
                            SharedPreferences sp=getSharedPreferences("Table",MODE_PRIVATE);
                            SharedPreferences.Editor editor=sp.edit();
                            editor.putBoolean("IsSetAlarm",true);
                            editor.commit();
                            Toast.makeText(MainActivity.this,"设置成功",Toast.LENGTH_SHORT).show();
    
                        }
                    })
    
                    .setNegativeButton("关闭", new DialogInterface.OnClickListener() {//添加取消
                        @Override
                        public void onClick(DialogInterface dialogInterface, int i) {
                            SharedPreferences sp=getSharedPreferences("Table",MODE_PRIVATE);
                            SharedPreferences.Editor editor=sp.edit();
                            editor.putBoolean("IsSetAlarm",false);
                            editor.commit();
                            Toast.makeText(MainActivity.this,"成功取消闹钟",Toast.LENGTH_SHORT).show();
                        }
                    })
                    .create();
            alertDialog.show();
        }
    
        public SharedPreferences ReviseTable()
        {
            SharedPreferences sp=getSharedPreferences("Table",MODE_PRIVATE);
            SharedPreferences.Editor editor=sp.edit();
            if(!(sp.getBoolean("HaveTable",false)))
            {
                editor.putBoolean("HaveTable",false);
                editor.commit();
                Toast.makeText(MainActivity.this,"未检测到课程,请添加课程",Toast.LENGTH_LONG).show();
            }
            return sp;
        }
        private void GetInitNum(SharedPreferences sp)
        {
            boolean isfirst=sp.getBoolean("IsFirst",true);
            if(isfirst==true)
            {
                ShowFirst();
                SharedPreferences.Editor editor=sp.edit();
                editor.putBoolean("IsFirst",false);
                editor.commit();
            }
            MorningLesson=sp.getInt("MorningLesson",2);
            AfternoonLesson=sp.getInt("AfternoonLesson",2);
            NightLesson=sp.getInt("NightLesson",1);
            Sumline=MorningLesson+AfternoonLesson+NightLesson+1;
            lie=sp.getInt("row",8);
        }
    
        private void ShowFirst()
        {
            AlertDialog alertDialog = new AlertDialog.Builder(this)
                    .setTitle("温馨提示")
                    .setMessage("APP需求通知权限来提醒您当日课程,若关闭可前往设置打开")
                    .setIcon(R.mipmap.ic_launcher)
                    .setPositiveButton("前往设置", new DialogInterface.OnClickListener() {//添加"Yes"按钮
                        @Override
                        public void onClick(DialogInterface dialogInterface, int i) {
                            Intent intent = new Intent(Settings.ACTION_SETTINGS);
                            startActivity(intent);
                        }
                    })
    
                    .setNegativeButton("知道了", new DialogInterface.OnClickListener() {//添加取消
                        @Override
                        public void onClick(DialogInterface dialogInterface, int i) {
                        }
                    })
                    .create();
            alertDialog.show();
    
        }
    
        public void Init(SharedPreferences sp)
        {
    
            //获取控件tableLayout
            tableLayout = (TableLayout)findViewById(R.id.table1);
            //清除表格所有行
            tableLayout.removeAllViews();
            //全部列自动填充空白处
            tableLayout.setStretchAllColumns(true);
            //生成X行,Y列的表格
            for(int i=1;i<=Sumline;i++)
            {
                TableRow tableRow=new TableRow(MainActivity.this);
                if(i==1)
                {
                    String date=null;
                    for(int dateline=0;dateline<8;dateline++)
                    {
                        switch (dateline)
                        {
                            case 0:
                            {
                                date="#";
                            }break;
                            case 1:
                            {
                                date="星期一";
                            }break;
                            case 2:
                            {
                                date="星期二";
                            }break;
                            case 3:
                            {
                                date="星期三";
                            }break;
                            case 4:
                            {
                                date="星期四";
                            }break;
                            case 5:
                            {
                                date="星期五";
                            }break;
                            case 6:
                            {
                                date="星期六";
                            }break;
                            case 7: {
                                date = "星期日";
                            }break;
                        }
                        //tv用于显示
                        TextView tv=new TextView(MainActivity.this);
                        tv.setHeight(30);
                        tv.setText(date);
    
                        tableRow.addView(tv);
                    }
                    tableLayout.addView(tableRow, new TableLayout.LayoutParams(MP, WC,1));
                }
                else
                {
                    for(int j=1;j<=lie;j++)
                    {
                        if(j==1)
                        {
                            switch (i)
                            {
                                case 2:
                                {
                                    lessonno="1";
                                }break;
                                case 3:
                                {
                                    lessonno="2";
                                }break;
                                case 4:
                                {
                                    lessonno="3";
                                }break;
                                case 5:
                                {
                                    lessonno="4";
                                }break;
                                case 6:
                                {
                                    lessonno="5";
                                }break;
                                case 7:
                                {
                                    lessonno="6";
                                }break;
                                case 8:
                                {
                                    lessonno="7";
                                }break;
                                case 9:
                                {
                                    lessonno="8";
                                }break;
                                case 10:
                                {
                                    lessonno="9";
                                }break;
                                case 11:
                                {
                                    lessonno="10";
                                }break;
                                case 12:
                                {
                                    lessonno="11";
                                }break;
                                case 13:
                                {
                                    lessonno="12";
                                }break;
                            }
                            //tv用于显示
                            TextView tv=new TextView(MainActivity.this);
                            //Button bt=new Button(MainActivity.this);
                            tv.setText(lessonno);
                            tableRow.addView(tv);
                        }
                        else
                        {
                            //tv用于显示
                            TextView tv=new TextView(MainActivity.this);
                            //Button bt=new Button(MainActivity.this);
                            tv.setMaxEms(6);
                            tv.setGravity(Gravity.CENTER);
                            int no=(j-1)*100+i-1;
                            lessonno=String.valueOf(no);
                            Lesson=sp.getString(lessonno,"软件工程");
                            String LeesonStart=lessonno+"Start";
                            String LessonEnd=lessonno+"End";
                            String LessonWeekNum=lessonno+"单双周";
                            int GetLessonStart=sp.getInt(LeesonStart,1);
                            int GetLessonEnd=sp.getInt(LessonEnd,18);
                            int GetLessonWeekNum=sp.getInt(LessonWeekNum,0);
                            if(GetLessonWeekNum==0)
                            {
                                if(WeekNumer>=GetLessonStart&&WeekNumer<=GetLessonEnd)
                                {
                                    tv.setText(Lesson);
                                }
                                else
                                {
                                    tv.setText("");
                                }
                            }
                            else
                            {
                                int IsLessonWeekNum=WeekNumer%2;
                                if(IsLessonWeekNum==GetLessonWeekNum)
                                {
                                    if(WeekNumer>=GetLessonStart&&WeekNumer<=GetLessonEnd)
                                    {
                                        tv.setText(Lesson);
                                    }
                                    else
                                    {
                                        tv.setText("");
                                    }
                                }
                                else
                                {
                                    tv.setText("");
                                }
                            }
                            tableRow.addView(tv);
                        }
                    }
                    //新建的TableRow添加到TableLayout
                    tableLayout.addView(tableRow, new TableLayout.LayoutParams(MP, WC,1));
                }
            }
        }
        public void SetWeekShow(SharedPreferences sp)  {
            //获取当前的日期
            Date today = new Date();
            //设置要获取到什么样的时间
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            //获取String类型的时间
            String DateYear = sdf.format(today);
            //得到学期开始的日期格式
            String GetSemesterStart=sp.getString("SemesterStart","2000-01-01");
    
            Date SemesterStart = null;
            int WeekNum=0;
            try {
                SemesterStart = sdf.parse(GetSemesterStart);
                Date Today_Date=sdf.parse(DateYear);
                //获取天数
                long Days = (Today_Date.getTime()-SemesterStart.getTime())/(24*60*60*1000);
                WeekNum=(int)Days/7;
            } catch (ParseException e) {
                e.printStackTrace();
            }
    
    
            //获取今天是星期几
            Calendar c=Calendar.getInstance();
            c.setTime(today);
            int weekday=c.get(Calendar.DAY_OF_WEEK);
            String TodayWeek=null;
            switch (weekday)
            {
                case 1:
                {
                    TodayWeek="星期日";
                }break;
                case 2:
                {
                    TodayWeek="星期一";
                }break;
                case 3:
                {
                    TodayWeek="星期二";
                }break;
                case 4:
                {
                    TodayWeek="星期三";
                }break;
                case 5:
                {
                    TodayWeek="星期四";
                }break;
                case 6:
                {
                    TodayWeek="星期五";
                }break;
                case 7:
                {
                    TodayWeek="星期六";
                }break;
            }
            if(GetSemesterStart.equals("2000-01-01"))
            {
                super.setTitle(DateYear+"  "+TodayWeek+" "+"未设置开学时间");
            }
            else
            {
                super.setTitle(DateYear+"  "+TodayWeek+" 开学第"+WeekNum+"周");
            }
            WeekNumer=WeekNum;
        }
        public static Context getContext() {
            return sContext;
        }
    }
    

      

  • 相关阅读:
    Android 6.0 运行时权限处理完全解析
    Android 6.0 运行时权限处理
    史上比较用心的纯代码实现 AutoLayout
    hdu 4268 Alice and Bob(multiset|段树)
    在单调的队列
    Python re正则表达式
    minihomepage.exe 百度视频迷你主页
    POJ 2914 Minimum Cut 最小割图论
    移植kl档,但调用默认Generic.kl解决的方法
    iOS 删除黑色边框线导航栏&amp;删除搜索框的阴影边界线和中黑色文本输入框 - 解
  • 原文地址:https://www.cnblogs.com/cuijunfeng/p/10940035.html
Copyright © 2020-2023  润新知