Android Open Source - Happy-Look-Project H P Service






From Project

Back to project page Happy-Look-Project.

License

The source code is released under:

http://www.iconspedia.com/icon/iphone-wallpaper.html

If you think the Android project Happy-Look-Project listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.salamandroid.happylook;
//w  ww.ja va 2  s  . co m
import java.util.Calendar;
import java.util.Timer;
import java.util.TimerTask;

import android.annotation.SuppressLint;
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;

@SuppressLint("ShowToast")
public class HPService extends Service
{

    private Preferences pref;
    private Timer timer;
    private long SERVICE_INTERVAL_PERIOD = 10000;
    private Wallpaper wallpaper;

    @Override
    public IBinder onBind(Intent arg0)
    {
  return null;
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId)
    {
  timer = new Timer();
  wallpaper = new Wallpaper();
  pref = (Preferences) intent.getSerializableExtra("preferences");
  WallpaperUpdaterService();
  return START_STICKY;
    }

    private void WallpaperUpdaterService()
    {
  timer.scheduleAtFixedRate(new TimerTask()
  {

      public void run()
      {
    if (rightDayForUpdate() && rightTimeForUpdate())
        wallpaper.updateWallpaper(pref, getApplicationContext());
      }
  }, 0, SERVICE_INTERVAL_PERIOD);
    }

    private boolean rightDayForUpdate()
    {
  final Calendar calendar = Calendar.getInstance();
  if ((pref.sunday == true &&
    calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY)
    || (pref.monday == true &&
    calendar.get(Calendar.DAY_OF_WEEK) == Calendar.MONDAY)
    || (pref.wednesday == true &&
    calendar.get(Calendar.DAY_OF_WEEK) == Calendar.WEDNESDAY)
    || (pref.friday == true &&
    calendar.get(Calendar.DAY_OF_WEEK) == Calendar.FRIDAY))
      return true;
  else
      return true;
    }

    private boolean rightTimeForUpdate()
    {
  final Calendar calendar = Calendar.getInstance();
  if (calendar.get(Calendar.HOUR_OF_DAY) == 6)
      return true;
  else
      return true;
    }

    @Override
    public void onDestroy()
    {
  timer.cancel();
  super.onDestroy();
    }
}




Java Source Code List

com.salamandroid.happylook.HPService.java
com.salamandroid.happylook.ImageDownloader.java
com.salamandroid.happylook.MainActivity.java
com.salamandroid.happylook.Preferences.java
com.salamandroid.happylook.Wallpaper.java