Пример #1
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    MyApp.initOnBroadCastReceiver(this);
    super.onCreate(savedInstanceState);
    // prefs = getSharedPreferences("teamproject.glasgow.reminders_app", MODE_PRIVATE);
    prefs = MyApp.getPrefs();

    setContentView(R.layout.activity_reminders);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    //        cloudMem = new ParseStorageAdapter(this);
    //        cloudMem.testAddNewTaskToDB();
    //        cloudMem.getRemindersFromDB();

    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mActivityTitle = getTitle().toString();
    mDrawerList = (ListView) findViewById(R.id.navList);

    addDrawerItems();
    setupDrawer();

    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setHomeButtonEnabled(true);

    if (prefs.getBoolean("firstrun", true)) {
      reminders = HelperFunctions.generateReminderInitData();
      PersistencyManager.saveReminders(reminders, true);
    } else {
      // reminders = PersistencyManager.getReminders();
      reminders = MyApp.getReminders();
    }

    // reminders = cloudMem.getRemindersFromDB();
    //        cloudMem.searchReminder("a");

    expandableListView = (ExpandableListView) findViewById(R.id.ExpList);

    // Display indicator on the right
    Display newDisplay = getWindowManager().getDefaultDisplay();
    int width = newDisplay.getWidth();
    expandableListView.setIndicatorBounds(width - 100, width);

    ExpAdapter = new ExpandListAdapter(Reminders.this, reminders);
    expandableListView.setAdapter(ExpAdapter);

    // expand all items
    for (int i = 0; i < ExpAdapter.getGroupCount(); i++) {
      expandableListView.expandGroup(i);
    }

    expandableListView.setOnChildClickListener(
        new ExpandableListView.OnChildClickListener() {

          @Override
          public boolean onChildClick(
              ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
            Occurrence occurrence = (Occurrence) ExpAdapter.getChild(groupPosition, childPosition);
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setClassName(
                "teamproject.glasgow.reminders_app",
                "teamproject.glasgow.reminders_app.ModifyReminder");
            intent.putExtra("display_type", "modify_reminder");
            Reminder reminder = occurrence.getReminder();
            intent.putExtra("reminder", reminder);
            intent.putExtra("index", reminders.getReminders().indexOf(reminder));
            // AlarmSetter.cancelRepeatingAlarmForReminder(reminder, null);
            startActivityForResult(intent, 2);
            return true;
          }
        });

    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View view) {

            // Intent intent = new Intent(view.getContext(), ModifyReminder.class);
            // startActivity(intent);
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setClassName(
                "teamproject.glasgow.reminders_app",
                "teamproject.glasgow.reminders_app.ModifyReminder");
            intent.putExtra("display_type", "add_reminder");
            startActivityForResult(intent, 1);
          }
        });

    // setButtonColor
    Drawable myFabSrc =
        ResourcesCompat.getDrawable(getResources(), android.R.drawable.ic_input_add, getTheme());
    Drawable white = myFabSrc.getConstantState().newDrawable();
    white.mutate().setColorFilter(Color.WHITE, PorterDuff.Mode.SRC_ATOP);
    fab.setImageDrawable(white);

    _reminders = this;
    MyApp.setReminders(reminders);
    UserID = MyApp.getUserID();
    Intent i = this.getIntent();
    if (i.getBooleanExtra("restart", false)) {
      moveTaskToBack(true);
    }
  }
Пример #2
0
 //    @Override
 //    public void onStop() {
 //        super.onStop();
 //        Log.d("Nok", "onStop: "+reminders.getReminders().size());
 ////        PersistencyManager.saveReminders(reminders);
 //    }
 @Override
 public void onPause() {
   super.onPause();
   //        Log.d("Nok", "onPause: " + reminders.getReminders().size());
   PersistencyManager.saveReminders(reminders, false);
 }