EditAlarmActivity created
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
package com.philliphsu.clock2;
|
||||
|
||||
import android.media.AudioManager;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.CallSuper;
|
||||
import android.support.annotation.LayoutRes;
|
||||
import android.support.annotation.MenuRes;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v7.app.ActionBar;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.view.Menu;
|
||||
|
||||
import butterknife.Bind;
|
||||
import butterknife.ButterKnife;
|
||||
|
||||
/**
|
||||
* Created by Phillip Hsu on 5/31/2016.
|
||||
*/
|
||||
public abstract class BaseActivity extends AppCompatActivity {
|
||||
|
||||
@Nullable @Bind(R.id.toolbar) Toolbar mToolbar;
|
||||
private Menu mMenu;
|
||||
|
||||
@LayoutRes protected abstract int layoutResId();
|
||||
@MenuRes protected abstract int menuResId();
|
||||
|
||||
@CallSuper
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(layoutResId());
|
||||
// Initialize the associated SharedPreferences file with default values
|
||||
// for each preference when the user first opens your application.
|
||||
// When false, the system sets the default values only if this method has
|
||||
// never been called in the past (or the KEY_HAS_SET_DEFAULT_VALUES in the
|
||||
// default value shared preferences file is false).
|
||||
//TODO PreferenceManager.setDefaultValues(this, R.xml.preferences, false);
|
||||
// Direct volume changes to the alarm stream
|
||||
setVolumeControlStream(AudioManager.STREAM_ALARM);
|
||||
ButterKnife.bind(this);
|
||||
if (mToolbar != null) {
|
||||
setSupportActionBar(mToolbar);
|
||||
ActionBar ab = getSupportActionBar();
|
||||
if (ab != null) {
|
||||
ab.setDisplayHomeAsUpEnabled(isDisplayHomeUpEnabled());
|
||||
ab.setDisplayShowTitleEnabled(isDisplayShowTitleEnabled());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean onCreateOptionsMenu(Menu menu) {
|
||||
if (menuResId() != 0) {
|
||||
getMenuInflater().inflate(menuResId(), menu);
|
||||
mMenu = menu;
|
||||
}
|
||||
return super.onCreateOptionsMenu(menu);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public final Menu getMenu() {
|
||||
return mMenu;
|
||||
}
|
||||
|
||||
protected boolean isDisplayHomeUpEnabled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
protected boolean isDisplayShowTitleEnabled() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -43,7 +43,7 @@ public class DaysOfWeek {
|
||||
sAppContext = context.getApplicationContext();
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
// TODO First day of week preference. Entries are the full days' names and values are their respective integers.
|
||||
String preferredFirstDay = prefs.getString("", "0");
|
||||
String preferredFirstDay = prefs.getString("", "6");
|
||||
if (sInstance == null || !preferredFirstDay.equals(sLastPreferredFirstDay)) {
|
||||
sLastPreferredFirstDay = preferredFirstDay;
|
||||
sInstance = new DaysOfWeek(Integer.parseInt(preferredFirstDay));
|
||||
|
||||
@@ -6,25 +6,22 @@ import android.content.Intent;
|
||||
import android.media.RingtoneManager;
|
||||
import android.os.Bundle;
|
||||
import android.support.design.widget.FloatingActionButton;
|
||||
import android.support.design.widget.Snackbar;
|
||||
import android.support.design.widget.TabLayout;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v4.app.FragmentPagerAdapter;
|
||||
import android.support.v4.view.ViewPager;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.philliphsu.clock2.alarms.AlarmsFragment;
|
||||
import com.philliphsu.clock2.editalarm.EditAlarmActivity;
|
||||
import com.philliphsu.clock2.ringtone.RingtoneActivity;
|
||||
|
||||
public class MainActivity extends AppCompatActivity implements AlarmsFragment.OnAlarmInteractionListener {
|
||||
public class MainActivity extends BaseActivity implements AlarmsFragment.OnAlarmInteractionListener {
|
||||
|
||||
/**
|
||||
* The {@link android.support.v4.view.PagerAdapter} that will provide
|
||||
@@ -44,10 +41,7 @@ public class MainActivity extends AppCompatActivity implements AlarmsFragment.On
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main);
|
||||
|
||||
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
|
||||
setSupportActionBar(toolbar);
|
||||
// Create the adapter that will return a fragment for each of the three
|
||||
// primary sections of the activity.
|
||||
mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
|
||||
@@ -63,6 +57,8 @@ public class MainActivity extends AppCompatActivity implements AlarmsFragment.On
|
||||
fab.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
startActivity(new Intent(MainActivity.this, EditAlarmActivity.class));
|
||||
/*
|
||||
scheduleAlarm();
|
||||
Snackbar.make(view, "Alarm set for 1 minute from now", Snackbar.LENGTH_INDEFINITE)
|
||||
.setAction("Dismiss", new View.OnClickListener() {
|
||||
@@ -77,17 +73,24 @@ public class MainActivity extends AppCompatActivity implements AlarmsFragment.On
|
||||
sendBroadcast(intent);
|
||||
}
|
||||
}).show();
|
||||
*/
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int layoutResId() {
|
||||
return R.layout.activity_main;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
// Inflate the menu; this adds items to the action bar if it is present.
|
||||
getMenuInflater().inflate(R.menu.menu_main, menu);
|
||||
return true;
|
||||
protected int menuResId() {
|
||||
return R.menu.menu_main;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isDisplayHomeUpEnabled() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -180,7 +183,7 @@ public class MainActivity extends AppCompatActivity implements AlarmsFragment.On
|
||||
|
||||
@Override
|
||||
public void onListItemInteraction(Alarm item) {
|
||||
// TODO react to click
|
||||
startActivity(new Intent(this, EditAlarmActivity.class));
|
||||
}
|
||||
|
||||
private void scheduleAlarm() {
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
package com.philliphsu.clock2.editalarm;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.widget.SwitchCompat;
|
||||
import android.widget.Button;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ToggleButton;
|
||||
|
||||
import com.philliphsu.clock2.BaseActivity;
|
||||
import com.philliphsu.clock2.DaysOfWeek;
|
||||
import com.philliphsu.clock2.R;
|
||||
|
||||
import butterknife.Bind;
|
||||
|
||||
public class EditAlarmActivity extends BaseActivity {
|
||||
|
||||
@Bind(R.id.save) Button mSave;
|
||||
@Bind(R.id.delete) Button mDelete;
|
||||
@Bind(R.id.on_off) SwitchCompat mSwitch;
|
||||
@Bind(R.id.input_time) EditText mTimeText;
|
||||
@Bind({R.id.day0, R.id.day1, R.id.day2, R.id.day3, R.id.day4, R.id.day5, R.id.day6})
|
||||
ToggleButton[] mDays;
|
||||
@Bind(R.id.label) EditText mLabel;
|
||||
@Bind(R.id.ringtone) Button mRingtone;
|
||||
@Bind(R.id.vibrate) CheckBox mVibrate;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setWeekDaysText();
|
||||
getSupportActionBar().setTitle("Snoozing until 12:40 PM");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int layoutResId() {
|
||||
return R.layout.activity_edit_alarm;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int menuResId() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isDisplayShowTitleEnabled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
private void setWeekDaysText() {
|
||||
for (int i = 0; i < mDays.length; i++) {
|
||||
int weekDay = DaysOfWeek.getInstance(this).weekDay(i);
|
||||
String label = DaysOfWeek.getLabel(weekDay);
|
||||
mDays[i].setTextOn(label);
|
||||
mDays[i].setTextOff(label);
|
||||
mDays[i].setChecked(mDays[i].isChecked()); // force update the text, otherwise it won't be shown
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user