/** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.simple_calendar_view);
// /////////////////////////////////////////////////////////////////////////////////////// // Inner Class public class GridCellAdapter extends BaseAdapter implements OnClickListener { private static final String tag = "GridCellAdapter"; private final Context _context;
private final List list; private static final int DAY_OFFSET = 1; private final String[] weekdays = new String[]{"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}; private final String[] months = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}; private final int[] daysOfMonth = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; private final int month, year; private int daysInMonth, prevMonthDays; private int currentDayOfMonth; private int currentWeekDay; private Button gridcell; private TextView num_events_per_day; private final HashMap eventsPerMonthMap; private final SimpleDateFormat dateFormatter = new SimpleDateFormat("dd-MMM-yyyy");
// Days in Current Month public GridCellAdapter(Context context, int textViewResourceId, int month, int year) { super(); this._context = context; this.list = new ArrayList(); this.month = month; this.year = year;
Log.d(tag, "==> Passed in Date FOR Month: " + month + " " + "Year: " + year); Calendar calendar = Calendar.getInstance(); setCurrentDayOfMonth(calendar.get(Calendar.DAY_OF_MONTH)); setCurrentWeekDay(calendar.get(Calendar.DAY_OF_WEEK)); Log.d(tag, "New Calendar:= " + calendar.getTime().toString()); Log.d(tag, "CurrentDayOfWeek :" + getCurrentWeekDay()); Log.d(tag, "CurrentDayOfMonth :" + getCurrentDayOfMonth());
// Print Month printMonth(month, year);
// Find Number of Events eventsPerMonthMap = findNumberOfEventsPerMonth(year, month); } private String getMonthAsString(int i) { return months[i]; }
private int getNumberOfDaysOfMonth(int i) { return daysOfMonth[i]; }
public String getItem(int position) { return list.get(position); }
@Override public int getCount() { return list.size(); }
/** * Prints Month * * @param mm * @param yy */ private void printMonth(int mm, int yy) { Log.d(tag, "==> printMonth: mm: " + mm + " " + "yy: " + yy); // The number of days to leave blank at // the start of this month. int trailingSpaces = 0; int leadSpaces = 0; int daysInPrevMonth = 0; int prevMonth = 0; int prevYear = 0; int nextMonth = 0; int nextYear = 0;
int currentMonth = mm - 1; String currentMonthName = getMonthAsString(currentMonth); daysInMonth = getNumberOfDaysOfMonth(currentMonth);
// Gregorian Calendar : MINUS 1, set to FIRST OF MONTH GregorianCalendar cal = new GregorianCalendar(yy, currentMonth, 1); Log.d(tag, "Gregorian Calendar:= " + cal.getTime().toString());
// Compute how much to leave before before the first day of the // month. // getDay() returns 0 for Sunday. int currentWeekDay = cal.get(Calendar.DAY_OF_WEEK) - 1; trailingSpaces = currentWeekDay;
Log.d(tag, "Week Day:" + currentWeekDay + " is " + getWeekDayAsString(currentWeekDay)); Log.d(tag, "No. Trailing space to Add: " + trailingSpaces); Log.d(tag, "No. of Days in Previous Month: " + daysInPrevMonth);
if (cal.isLeapYear(cal.get(Calendar.YEAR)) && mm == 1) { ++daysInMonth; }
// Current Month Days for (int i = 1; i <= daysInMonth; i++) { Log.d(currentMonthName, String.valueOf(i) + " " + getMonthAsString(currentMonth) + " " + yy); if (i == getCurrentDayOfMonth()) { list.add(String.valueOf(i) + "-BLUE" + "-" + getMonthAsString(currentMonth) + "-" + yy); } else { list.add(String.valueOf(i) + "-WHITE" + "-" + getMonthAsString(currentMonth) + "-" + yy); } }
// Leading Month days for (int i = 0; i < list.size() % 7; i++) { Log.d(tag, "NEXT MONTH:= " + getMonthAsString(nextMonth)); list.add(String.valueOf(i + 1) + "-GREY" + "-" + getMonthAsString(nextMonth) + "-" + nextYear); } }
/** * NOTE: YOU NEED TO IMPLEMENT THIS PART Given the YEAR, MONTH, retrieve * ALL entries from a SQLite database for that month. Iterate over the * List of All entries, and get the dateCreated, which is converted into * day. * * @param year * @param month * @return */ private HashMap findNumberOfEventsPerMonth(int year, int month) { HashMap map = new HashMap(); // DateFormat dateFormatter2 = new DateFormat(); // // String day = dateFormatter2.format("dd", dateCreated).toString(); // // if (map.containsKey(day)) // { // Integer val = (Integer) map.get(day) + 1; // map.put(day, val); // } // else // { // map.put(day, 1); // } return map; }
@Override public long getItemId(int position) { return position; }
The methods onSaveInstanceState(Bundle outState) and onRestoreInstanceState(Bundle savedInstanceState) are the good place to Save and Restore Instance State.
Called to retrieve per-instance state from an activity before being killed so that the state can be restored in onCreate(Bundle) or onRestoreInstanceState(Bundle) (the Bundle populated by this method will be passed to both).
This method is called before an activity may be killed so that when it comes back some time in the future it can restore its state. For example, if activity B is launched in front of activity A, and at some point activity A is killed to reclaim resources, activity A will have a chance to save the current state of its user interface via this method so that when the user returns to activity A, the state of the user interface can be restored via onCreate(Bundle) or onRestoreInstanceState(Bundle).
Do not confuse this method with activity lifecycle callbacks such as onPause(), which is always called when an activity is being placed in the background or on its way to destruction, or onStop() which is called before destruction. One example of when onPause() and onStop() is called and not this method is when a user navigates back from activity B to activity A: there is no need to call onSaveInstanceState(Bundle) on B because that particular instance will never be restored, so the system avoids calling it. An example when onPause() is called and not onSaveInstanceState(Bundle) is when activity B is launched in front of activity A: the system may avoid calling onSaveInstanceState(Bundle) on activity A if it isn't killed during the lifetime of B since the state of the user interface of A will stay intact.
The default implementation takes care of most of the UI per-instance state for you by calling onSaveInstanceState() on each view in the hierarchy that has an id, and by saving the id of the currently focused view (all of which is restored by the default implementation of onRestoreInstanceState(Bundle)). If you override this method to save additional information not captured by each individual view, you will likely want to call through to the default implementation, otherwise be prepared to save all of the state of each view yourself.
If called, this method will occur before onStop(). There are no guarantees about whether it will occur before or after onPause().
This method is called after onStart() when the activity is being re-initialized from a previously saved state, given here in savedInstanceState. Most implementations will simply use onCreate(Bundle) to restore their state, but it is sometimes convenient to do it here after all of the initialization has been done or to allow subclasses to decide whether to use your default implementation. The default implementation of this method performs a restore of any view state that had previously been frozen by onSaveInstanceState(Bundle).
This method is called between onStart() and onPostCreate(Bundle).
Now download a file fromhere which encodeBytes in Base64 Format. Put this file in the same package of UploadImage.java. See the screenshot.
Now the server part. Create a folder named Upload_image_ANDROID in your htdocs folder and inside that create a file named upload_image.php and copy this code into it.
public void onClick(View v) { if (v.getId() == R.id.buttonVideoSample) { // ********************************** // HERE SET YOUR VIDEO URI //String video_uri = "VIDEO_URI"; // For example: http://www.pocketjourney.com/downloads/pj/video/famous.3gp // ********************************** String video_uri = "http://www.pocketjourney.com/downloads/pj/video/famous.3gp"; Intent intent = new Intent(this, VideoSample.class); intent.putExtra("video_path", video_uri); startActivity(intent); } }
It's a simple example of using MapView, with everything implement in main activity.
In this article, I'm going to implement a custom MyMapView extends MapView. Most of the routine works will be moved in MyMapView, include MyItemizedOverlay, MyLocationOverlay and some initialization such as setClickable(true), setBuiltInZoomControls(true)...etc. Such that the main activity will become simple and clear.
public class AndroidCustomMapViewActivity extends MapActivity {
MyMapView myMapView;
/** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); myMapView = (MyMapView)findViewById(R.id.mymapview);
GeoPoint myPoint1 = new GeoPoint(0*1000000, 0*1000000); myMapView.addMarker(myPoint1, "myPoint1", "myPoint1"); GeoPoint myPoint2 = new GeoPoint(50*1000000, 50*1000000); myMapView.addMarker(myPoint2, "myPoint2", "myPoint2"); }
Remember to modify AndroidManifest.xml to include uses-library of "com.google.android.maps", and grant permission of "android.permission.INTERNET" and "android.permission.ACCESS_FINE_LOCATION".