Back to project page rfcx-client-stream-android.
The source code is released under:
Apache License
If you think the Android project rfcx-client-stream-android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package org.rfcx.android.stream; /*from w w w. j a v a2s . co m*/ import android.support.v7.app.ActionBar; import android.support.v7.app.ActionBarActivity; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.widget.ImageView; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; public class BaseActivity extends ActionBarActivity { private ActionBar mActionBar; private static final String START_TIME = "06:00"; private static final String END_TIME = "18:00"; private boolean isDay = false; private View mActionBarView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Init view for custom action bar mActionBarView = getLayoutInflater().inflate(R.layout.actionbar_rcfx, null); // Set custom actionbar mActionBar = getSupportActionBar(); if (mActionBar != null) { mActionBar.setCustomView(mActionBarView); mActionBar.setDisplayShowCustomEnabled(true); mActionBar.setDisplayShowTitleEnabled(false); } } @Override protected void onResume() { super.onResume(); // Init day or night setDay(); // Update UI updateTheme(); } protected void updateTheme() { if (isDay) { dayTheme(); } else { nightTheme(); } } protected void dayTheme() { // Set background getWindow().setBackgroundDrawableResource(R.drawable.bg_forest); } protected void nightTheme() { // Set background getWindow().setBackgroundDrawableResource(R.drawable.bg_night_forest); } private void setDay() { SimpleDateFormat timeFormat = new SimpleDateFormat("HH:mm"); Date startTime, endTime, currentTime; long startMilliseconds, endMilliseconds, currentMilliseconds; try { // Init start/end time startTime = timeFormat.parse(START_TIME); startMilliseconds = startTime.getTime(); endTime = timeFormat.parse(END_TIME); endMilliseconds = endTime.getTime(); // Init current time Calendar calendar = Calendar.getInstance(); currentTime = calendar.getTime(); String currentTimeStr = timeFormat.format(currentTime); currentTime = timeFormat.parse(currentTimeStr); currentMilliseconds = currentTime.getTime(); // Set day/night isDay = currentMilliseconds >= startMilliseconds && currentMilliseconds <= endMilliseconds; } catch (ParseException e) { e.printStackTrace(); isDay = false; } } protected boolean isDay() { return isDay; } }