想要源码私聊我
mainactivity部分代码
private TickApplication mApplication;
private DrawerLayout mDrawerLayout;
private MenuItem mMenuItemIDLE;
private Button mBtnStart;
private Button mBtnPause;
private Button mBtnResume;
private Button mBtnStop;
private Button mBtnSkip;
private TextView mTextCountDown;
private TextView mTextTimeTile;
private TickProgressBar mProgressBar;
private RippleWrapper mRippleWrapper;
private long mLastClickTime = 0;
public static Intent newIntent(Context context) {
return new Intent(context, MainActivity.class);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle drawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,
toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close) {
@Override
public void onDrawerClosed(View drawerView) {
super.onDrawerClosed(drawerView);
invalidateOptionsMenu();
}
@Override
public void onDrawerOpened(View drawerView) {
super.onDrawerOpened(drawerView);
invalidateOptionsMenu();
}
@Override
public void onDrawerStateChanged(int newState) {
super.onDrawerStateChanged(newState);
if (mMenuItemIDLE != null && newState == DrawerLayout.STATE_IDLE) {
runNavigationItemSelected(mMenuItemIDLE);
mMenuItemIDLE = null;
}
}
};
mDrawerLayout.addDrawerListener(drawerToggle);
drawerToggle.syncState();
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
mApplication = (TickApplication)getApplication();
mBtnStart = (Button)findViewById(R.id.btn_start);
mBtnPause = (Button)findViewById(R.id.btn_pause);
mBtnResume = (Button)findViewById(R.id.btn_resume);
mBtnStop = (Button)findViewById(R.id.btn_stop);
mBtnSkip = (Button)findViewById(R.id.btn_skip);
mTextCountDown = (TextView)findViewById(R.id.text_count_down);
mTextTimeTile = (TextView)findViewById(R.id.text_time_title);
mProgressBar = (TickProgressBar)findViewById(R.id.tick_progress_bar);
mRippleWrapper = (RippleWrapper)findViewById(R.id.ripple_wrapper);
initActions();
}
private void initActions() {
mBtnStart.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent i = TickService.newIntent(getApplicationContext());
i.setAction(TickService.ACTION_START);
startService(i);
mApplication.start();
updateButtons();
updateTitle();
updateRipple();
}
});
mBtnPause.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent i = TickService.newIntent(getApplicationContext());
i.setAction(TickService.ACTION_PAUSE);
i.putExtra("time_left", (String) mTextCountDown.getText());
startService(i);
mApplication.pause();
updateButtons();
updateRipple();
}
});
mBtnResume.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent i = TickService.newIntent(getApplicationContext());
i.setAction(TickService.ACTION_RESUME);
startService(i);
mApplication.resume();
updateButtons();
updateRipple();
}
});
mBtnStop.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent i = TickService.newIntent(getApplicationContext());
i.setAction(TickService.ACTION_STOP);
startService(i);
mApplication.stop();
reload();
}
});
mBtnSkip.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent i = TickService.newIntent(getApplicationContext());
i.setAction(TickService.ACTION_STOP);
startService(i);
mApplication.skip();
reload();
}
});
mRippleWrapper.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
long clickTime = System.currentTimeMillis();
if (clickTime - mLastClickTime < 500) {
boolean isSoundOn = getSharedPreferences()
.getBoolean("pref_key_tick_sound", true);
|