1

I created an application to calculate remaining days in Android. I also have live wallpaper application.

Now I want to set that remaining days in live wallpaper screen. How can I do that?

Sathyajith Bhat
  • 21,321
  • 22
  • 95
  • 134

2 Answers2

1

You can use web service if client have Internet access or you can store date some where and update is , its simple if you knowledge of Java

Bhargav Mistri
  • 944
  • 8
  • 20
  • this applications is same as Twilight Screenboard – Bhargav Mistri Nov 11 '11 at 10:49
  • ya you are right .. but if i want to make it simple in device. like live wallpaper service.. –  Nov 11 '11 at 11:14
  • hi use code like this for write date of time in wallpaper Canvas StaticLayout layout = new StaticLayout(text, txtpaint, textW,Layout.Alignment.ALIGN_NORMAL, 1.3f, 0, false); txtcanvas.translate(xoffs, yoffs); //position the text layout.draw(txtcanvas); – Bhargav Mistri Nov 11 '11 at 12:30
1
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;

public class DateTest {

public class DateTest {

static SimpleDateFormat sdf = new SimpleDateFormat("dd-MMM-yyyy");

public static void main(String[] args) {

  TimeZone.setDefault(TimeZone.getTimeZone("Europe/London"));

  //diff between these 2 dates should be 1
  Date d1 = new Date("01/01/2007 12:00:00");
  Date d2 = new Date("01/02/2007 12:00:00");

  //diff between these 2 dates should be 1
  Date d3 = new Date("03/24/2007 12:00:00");
  Date d4 = new Date("03/25/2007 12:00:00");

  Calendar cal1 = Calendar.getInstance();cal1.setTime(d1);
  Calendar cal2 = Calendar.getInstance();cal2.setTime(d2);
  Calendar cal3 = Calendar.getInstance();cal3.setTime(d3);
  Calendar cal4 = Calendar.getInstance();cal4.setTime(d4);

  printOutput("Manual   ", d1, d2, calculateDays(d1, d2));
  printOutput("Calendar ", d1, d2, daysBetween(cal1, cal2));
  System.out.println("---");
  printOutput("Manual   ", d3, d4, calculateDays(d3, d4));
  printOutput("Calendar ", d3, d4, daysBetween(cal3, cal4));
}


private static void printOutput(String type, Date d1, Date d2, long result) {
  System.out.println(type+ "- Days between: " + sdf.format(d1)
                    + " and " + sdf.format(d2) + " is: " + result);
}

/** Manual Method - YIELDS INCORRECT RESULTS - DO NOT USE**/
/* This method is used to find the no of days between the given dates */
public static long calculateDays(Date dateEarly, Date dateLater) {
  return (dateLater.getTime() - dateEarly.getTime()) / (24 * 60 * 60 * 1000);
}

/** Using Calendar - THE CORRECT WAY**/
public static long daysBetween(Calendar startDate, Calendar endDate) {
  Calendar date = (Calendar) startDate.clone();
  long daysBetween = 0;
  while (date.before(endDate)) {
    date.add(Calendar.DAY_OF_MONTH, 1);
    daysBetween++;
  }
  return daysBetween;
}
}
Reno
  • 33,594
  • 11
  • 89
  • 102
Bhargav Mistri
  • 944
  • 8
  • 20