List of usage examples for android.text.format Time setToNow
public void setToNow()
From source file:net.networksaremadeofstring.rhybudd.RhybuddHome.java
@Override protected void onResume() { super.onResume(); //Can't hurt to try and start the service just in case startService(new Intent(this, ZenossPoller.class)); //User is about to see the list of events - no need for them to hang around ((NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE)) .cancel(Notifications.NOTIFICATION_POLLED_ALERTS); ((NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE)) .cancel(Notifications.NOTIFICATION_GCM_GENERIC); //Lets try and bind to our service (if it's alive) doBindService();/*from w ww .ja v a2 s .co m*/ //Might as well update GCM whilst we're here if (settings.contains(ZenossAPI.PREFERENCE_PUSHKEY) && !settings.getString(ZenossAPI.PREFERENCE_PUSHKEY, "").equals("")) { doGCMRegistration(settings.getString(ZenossAPI.PREFERENCE_PUSHKEY, "")); } //OnCreate checks the settings for various bits. If they aren't there it sets first run to true //Checking a single bool is a hell of a lot more lightweight than 3 Preferences each onResume ! if (firstRun) { //We need to set this now as no doubt on resume gets called before onActivityResult firstRun = false; Intent SettingsIntent = new Intent(RhybuddHome.this, FirstRunSettings.class); SettingsIntent.putExtra("firstRun", true); //Test RhybuddHome.this.startActivityForResult(SettingsIntent, requestCode); } else { boolean lastCheckRequired = false; if (null != settings && settings.contains("lastCheck")) { Time now = new Time(); now.setToNow(); Long timesinceLastRefresh = (now.toMillis(true) - settings.getLong("lastCheck", 0)); Log.e("timesinceLastRefresh", Long.toString(timesinceLastRefresh)); if (timesinceLastRefresh > 900000) { lastCheckRequired = true; } } //If we've resumed from one of our own activities we probably don't want to do a full refresh //finishStart will force a full refresh if backgroundPolling isn't enabled //if(resumeOnResultPollAPI || lastCheckRequired) if (resumeOnResultPollAPI) { finishStart(false); //Refresh(); } else { //Nice and fast for returning from within our own app DBGetThread(); resumeOnResultPollAPI = true; } } }
From source file:cw.kop.autobackground.settings.WearSettingsFragment.java
private void drawDigital() { canvas = surfaceView.getHolder().lockCanvas(); if (canvas == null) { return;// w w w . ja v a 2 s.co m } setPaints(); Time time = new Time(); time.setToNow(); time.set(time.toMillis(false) + timeOffset); float centerX = watchContainer.getWidth() * 0.222f; float centerY = watchContainer.getHeight() * 0.222f; if (imageBitmap != null) { canvas.drawBitmap(imageBitmap, 0, 0, bitmapPaint); } float x = xOffset + (time.hour < 10 ? hourPaint.measureText("0") : 0); float hourWidth = hourPaint.measureText("" + time.hour); float minuteWidth = minutePaint.measureText(String.format("%02d", time.minute)); canvas.drawText("" + time.hour, x - 2.0f, centerY - 2.0f, hourShadowPaint); canvas.drawText("" + time.hour, x, centerY, hourPaint); x += hourPaint.measureText("" + time.hour); canvas.drawText(timeSeparator, x - 2.0f, centerY - 2.0f, separatorShadowPaint); canvas.drawText(timeSeparator, x, centerY, separatorPaint); x += separatorWidth; canvas.drawText(String.format("%02d", time.minute), x - 2.0f, centerY - 2.0f, minuteShadowPaint); canvas.drawText(String.format("%02d", time.minute), x, centerY, minutePaint); x += minutePaint.measureText(String.format("%02d", time.minute)); canvas.drawText(timeSeparator, x - 2.0f, centerY - 2.0f, separatorShadowPaint); canvas.drawText(timeSeparator, x, centerY, separatorPaint); x += separatorWidth; canvas.drawText(String.format("%02d", time.second), x - 2.0f, centerY - 2.0f, secondShadowPaint); canvas.drawText(String.format("%02d", time.second), x, centerY, secondPaint); surfaceView.getHolder().unlockCanvasAndPost(canvas); }
From source file:com.wso2.mobile.mdm.services.Operation.java
public Operation(Context context, int mode, Intent intent) { this.context = context; this.intent = intent; this.mode = mode; logger = new LoggerCustom(context); Time now = new Time(); now.setToNow(); String log_in = logger.readFileAsString("wso2log.txt"); String to_write = ""; if (CommonUtilities.DEBUG_MODE_ENABLED) { if (log_in != null && !log_in.equals("") && !log_in.equals("null")) { to_write = "<br> SERVER TO AGENT AT " + now.hour + ":" + now.minute + " : <br> CODE : " + intent.getStringExtra("message").trim() + "<br> MSG ID : " + intent.getStringExtra("token").trim() + "<br> DATA : " + intent.getStringExtra("data") + "<br>==========================================================<br>" + log_in; } else {/*www . j a v a 2 s .c om*/ to_write = "<br> SERVER TO AGENT AT " + now.hour + ":" + now.minute + ": <br> CODE : " + intent.getStringExtra("message").trim() + "<br> MSG ID : " + intent.getStringExtra("token").trim() + "<br> DATA : " + intent.getStringExtra("data") + "<br>==========================================================<br>"; } logger.writeStringAsFile(to_write, "wso2log.txt"); } if (intent.getStringExtra("message").trim().equals(CommonUtilities.OPERATION_POLICY_MONITOR)) { policy_token = intent.getStringExtra("token").trim(); policy_code = intent.getStringExtra("message").trim(); Log.v("Token", policy_token); } else { token = intent.getStringExtra("token").trim(); code = intent.getStringExtra("message").trim(); Log.v("Code", code); Log.v("Token", token); } if (intent.getStringExtra("data") != null) { data = intent.getStringExtra("data"); Log.v("Data", data); } if (intent.getStringExtra("message").trim().equals(CommonUtilities.OPERATION_POLICY_BUNDLE)) { try { SharedPreferences mainPrefp = context.getSharedPreferences("com.mdm", Context.MODE_PRIVATE); Editor editorp = mainPrefp.edit(); editorp.putString("policy", ""); editorp.commit(); SharedPreferences mainPref = context.getSharedPreferences("com.mdm", Context.MODE_PRIVATE); Editor editor = mainPref.edit(); editor.putString("policy", data); editor.commit(); /*if (mainPref.getString("policy_applied", "") == null || mainPref.getString("policy_applied", "").trim() .equals("0") || mainPref.getString("policy_applied", "").trim() .equals("")) {*/ executePolicy(); //} /* * JSONArray jArray = new JSONArray(data); for(int i = 0; * i<jArray.length(); i++){ JSONObject policyObj = * (JSONObject)jArray.getJSONObject(i); * if(policyObj.getString("data")!=null && * policyObj.getString("data")!=""){ * doTask(policyObj.getString("code"), * policyObj.getString("data"), REQUEST_MODE_BUNDLE); } } * doTask(code, "", REQUEST_MODE_NORMAL); */ } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } else if (intent.getStringExtra("message").trim().equals(CommonUtilities.OPERATION_POLICY_MONITOR)) { doTask(policy_code, data, REQUEST_MODE_NORMAL); } else { doTask(code, data, REQUEST_MODE_NORMAL); } }
From source file:cw.kop.autobackground.settings.WearSettingsFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final DisplayMetrics displayMetrics = getResources().getDisplayMetrics(); View view;/* ww w . j ava 2 s. c o m*/ if (displayMetrics.widthPixels > displayMetrics.heightPixels) { view = inflater.inflate(R.layout.wear_settings_layout_landscape, container, false); watchContainer = (RelativeLayout) view.findViewById(R.id.watch_face_container); watchContainer.getViewTreeObserver() .addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { int height = watchBackground.getHeight(); ViewGroup.LayoutParams watchContainerParams = watchContainer.getLayoutParams(); watchContainerParams.height = height; watchContainerParams.width = height; watchContainer.setLayoutParams(watchContainerParams); watchContainer.setPadding(Math.round(height * 0.278f), Math.round(height * 0.23f), Math.round(height * 0.278f), Math.round(height * 0.33f)); watchContainer.getViewTreeObserver().removeGlobalOnLayoutListener(this); redraw(); } }); watchContainer.setOnClickListener(this); watchBackground = (ImageView) view.findViewById(R.id.watch_face_background); watchBackground.getViewTreeObserver() .addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { if (getView() == null) { return; } ViewGroup.LayoutParams watchContainerParams = watchBackground.getLayoutParams(); watchContainerParams.width = watchBackground.getHeight(); watchBackground.setLayoutParams(watchContainerParams); watchBackground.getViewTreeObserver().removeGlobalOnLayoutListener(this); } }); } else { view = inflater.inflate(R.layout.wear_settings_layout, container, false); watchContainer = (RelativeLayout) view.findViewById(R.id.watch_face_container); watchContainer.getViewTreeObserver() .addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { int width = displayMetrics.widthPixels; ViewGroup.LayoutParams watchContainerParams = watchContainer.getLayoutParams(); watchContainerParams.height = width; watchContainerParams.width = width; watchContainer.setLayoutParams(watchContainerParams); watchContainer.setPadding(Math.round(width * 0.278f), Math.round(width * 0.23f), Math.round(width * 0.278f), Math.round(width * 0.33f)); watchContainer.getViewTreeObserver().removeGlobalOnLayoutListener(this); redraw(); } }); watchContainer.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { preferenceList.setVisibility(View.VISIBLE); recyclerView.setAdapter(null); recyclerView.setVisibility(View.GONE); } }); watchBackground = (ImageView) view.findViewById(R.id.watch_face_background); watchBackground.getViewTreeObserver() .addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { if (getView() == null) { return; } ViewGroup.LayoutParams watchContainerParams = watchBackground.getLayoutParams(); watchContainerParams.height = watchBackground.getWidth(); watchBackground.setLayoutParams(watchContainerParams); watchBackground.getViewTreeObserver().removeGlobalOnLayoutListener(this); } }); } surfaceView = (SurfaceView) view.findViewById(R.id.surface_view); // surfaceView.setZOrderOnTop(true); surfaceView.setOnClickListener(this); surfaceView.setOnTouchListener(this); SurfaceHolder holder = surfaceView.getHolder(); holder.addCallback(new SurfaceHolder.Callback() { @Override public void surfaceCreated(SurfaceHolder holder) { loadImageFile(); redraw(); } @Override public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { loadImageFile(); redraw(); } @Override public void surfaceDestroyed(SurfaceHolder holder) { } }); recyclerView = (RecyclerView) view.findViewById(R.id.watch_options_list); recyclerView.setHasFixedSize(true); recyclerView.setLayoutManager(new LinearLayoutManager(getActivity())); recyclerView.setItemAnimator(new DefaultItemAnimator()); preferenceList = (ListView) view.findViewById(android.R.id.list); Button syncButton = (Button) view.findViewById(R.id.sync_button); syncButton.setText("Sync Settings"); syncButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Log.i(TAG, "syncButton pressed"); syncSettings(); } }); // findPreference("wear_time_type").setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { // @Override // public boolean onPreferenceClick(Preference preference) { // // DialogFactory.ListDialogListener listDialogListener = new DialogFactory.ListDialogListener() { // @Override // public void onItemClick(AdapterView<?> parent, // View view, // int position, // long id) { // // switch (position) { // case 0: // AppSettings.setTimeType(AppSettings.DIGITAL); // recyclerView.setAdapter(null); // preferenceList.setVisibility(View.VISIBLE); // recyclerView.setVisibility(View.GONE); // redraw(); // break; // case 1: // AppSettings.setTimeType(AppSettings.ANALOG); // recyclerView.setAdapter(null); // preferenceList.setVisibility(View.VISIBLE); // recyclerView.setVisibility(View.GONE); // redraw(); // break; // } // dismissDialog(); // } // }; // // DialogFactory.showListDialog(appContext, // "Watch face", // listDialogListener, // R.array.wear_time_types); // return true; // } // }); findPreference("wear_time_adjust").setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { DialogFactory.TimeDialogListener listener = new DialogFactory.TimeDialogListener() { @Override public void onTimeSet(TimePicker view, int hour, int minute) { Time time = new Time(); time.setToNow(); long offset = (hour - time.hour) * 3600000 + (minute - time.minute) * 60000; Log.i(TAG, "Time offset set: " + offset); AppSettings.setTimeOffset(offset); this.dismissDialog(); redraw(); } }; DialogFactory.showTimeDialog(appContext, "Enter time", listener, -1, -1); return true; } }); return view; }
From source file:com.android.calendar.AllInOneActivity.java
private void updateSecondaryTitleFields(long visibleMillisSinceEpoch) { mShowWeekNum = Utils.getShowWeekNumber(this); mTimeZone = Utils.getTimeZone(this, mHomeTimeUpdater); if (visibleMillisSinceEpoch != -1) { int weekNum = Utils.getWeekNumberFromTime(visibleMillisSinceEpoch, this); mWeekNum = weekNum;//from w w w .j ava 2 s . c o m } if (mShowWeekNum && (mCurrentView == ViewType.WEEK) && mIsTabletConfig && mWeekTextView != null) { String weekString = getResources().getQuantityString(R.plurals.weekN, mWeekNum, mWeekNum); mWeekTextView.setText(weekString); mWeekTextView.setVisibility(View.VISIBLE); } else if (visibleMillisSinceEpoch != -1 && mWeekTextView != null && mCurrentView == ViewType.DAY && mIsTabletConfig) { Time time = new Time(mTimeZone); time.set(visibleMillisSinceEpoch); int julianDay = Time.getJulianDay(visibleMillisSinceEpoch, time.gmtoff); time.setToNow(); int todayJulianDay = Time.getJulianDay(time.toMillis(false), time.gmtoff); String dayString = Utils.getDayOfWeekString(julianDay, todayJulianDay, visibleMillisSinceEpoch, this); mWeekTextView.setText(dayString); mWeekTextView.setVisibility(View.VISIBLE); } else if (mWeekTextView != null && (!mIsTabletConfig || mCurrentView != ViewType.DAY)) { mWeekTextView.setVisibility(View.GONE); } if (mHomeTime != null && (mCurrentView == ViewType.DAY || mCurrentView == ViewType.WEEK || mCurrentView == ViewType.AGENDA) && !TextUtils.equals(mTimeZone, Time.getCurrentTimezone())) { Time time = new Time(mTimeZone); time.setToNow(); long millis = time.toMillis(true); boolean isDST = time.isDst != 0; int flags = DateUtils.FORMAT_SHOW_TIME; if (DateFormat.is24HourFormat(this)) { flags |= DateUtils.FORMAT_24HOUR; } // Formats the time as String timeString = (new StringBuilder(Utils.formatDateRange(this, millis, millis, flags))).append(" ") .append(TimeZone.getTimeZone(mTimeZone).getDisplayName(isDST, TimeZone.SHORT, Locale.getDefault())) .toString(); mHomeTime.setText(timeString); mHomeTime.setVisibility(View.VISIBLE); // Update when the minute changes mHomeTime.removeCallbacks(mHomeTimeUpdater); mHomeTime.postDelayed(mHomeTimeUpdater, DateUtils.MINUTE_IN_MILLIS - (millis % DateUtils.MINUTE_IN_MILLIS)); } else if (mHomeTime != null) { mHomeTime.setVisibility(View.GONE); } }
From source file:com.xandy.calendar.AllInOneActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { Time t = null; int viewType = ViewType.CURRENT; long extras = CalendarController.EXTRA_GOTO_TIME; final int itemId = item.getItemId(); if (itemId == R.id.action_refresh) { mController.refreshCalendars();//from ww w .j a v a2s. com return true; } else if (itemId == R.id.action_today) { viewType = ViewType.CURRENT; t = new Time(mTimeZone); t.setToNow(); extras |= CalendarController.EXTRA_GOTO_TODAY; } else if (itemId == R.id.action_create_event) { t = new Time(); t.set(mController.getTime()); if (t.minute > 30) { t.hour++; t.minute = 0; } else if (t.minute > 0 && t.minute < 30) { t.minute = 30; } mController.sendEventRelatedEvent(this, EventType.CREATE_EVENT, -1, t.toMillis(true), 0, 0, 0, -1); return true; } else if (itemId == R.id.action_select_visible_calendars) { mController.sendEvent(this, EventType.LAUNCH_SELECT_VISIBLE_CALENDARS, null, null, 0, 0); return true; } else if (itemId == R.id.action_settings) { mController.sendEvent(this, EventType.LAUNCH_SETTINGS, null, null, 0, 0); return true; } else if (itemId == R.id.action_hide_controls) { mHideControls = !mHideControls; Utils.setSharedPreference(this, GeneralPreferences.KEY_SHOW_CONTROLS, !mHideControls); item.setTitle(mHideControls ? mShowString : mHideString); if (!mHideControls) { mMiniMonth.setVisibility(View.VISIBLE); mCalendarsList.setVisibility(View.VISIBLE); mMiniMonthContainer.setVisibility(View.VISIBLE); } final ObjectAnimator slideAnimation = ObjectAnimator.ofInt(this, "controlsOffset", mHideControls ? 0 : mControlsAnimateWidth, mHideControls ? mControlsAnimateWidth : 0); slideAnimation.setDuration(mCalendarControlsAnimationTime); ObjectAnimator.setFrameDelay(0); slideAnimation.start(); return true; } else if (itemId == R.id.action_search) { return false; } else { return mExtensions.handleItemSelected(item, this); } mController.sendEvent(this, EventType.GO_TO, t, null, t, -1, viewType, extras, null, null); return true; }
From source file:org.wso2.cdm.agent.services.Operation.java
public Operation(Context context, int mode, Intent intent) { this.context = context; this.intent = intent; this.mode = mode; if (CommonUtilities.DEBUG_MODE_ENABLED) { logger = new LoggerCustom(context); Time now = new Time(); now.setToNow(); String log_in = logger.readFileAsString("wso2log.txt"); String to_write = ""; if (log_in != null && !log_in.equals("") && !log_in.equals("null")) { to_write = "<br> SERVER TO AGENT AT " + now.hour + ":" + now.minute + " : <br> CODE : " + intent.getStringExtra("message").trim() + "<br> MSG ID : " + intent.getStringExtra("token").trim() + "<br> DATA : " + intent.getStringExtra("data") + "<br>==========================================================<br>" + log_in; } else {/*w w w. j a v a2 s. c o m*/ to_write = "<br> SERVER TO AGENT AT " + now.hour + ":" + now.minute + ": <br> CODE : " + intent.getStringExtra("message").trim() + "<br> MSG ID : " + intent.getStringExtra("token").trim() + "<br> DATA : " + intent.getStringExtra("data") + "<br>==========================================================<br>"; } logger.writeStringAsFile(to_write, "wso2log.txt"); } if (intent.getStringExtra("message").trim().equals(CommonUtilities.OPERATION_POLICY_MONITOR)) { policy_token = intent.getStringExtra("token").trim(); policy_code = intent.getStringExtra("message").trim(); Log.v("Token", policy_token); } else { token = intent.getStringExtra("token").trim(); code = intent.getStringExtra("message").trim(); Log.v("Code", code); Log.v("Token", token); } if (intent.getStringExtra("data") != null) { data = intent.getStringExtra("data"); Log.v("Data", data); } if (intent.getStringExtra("message").trim().equals(CommonUtilities.OPERATION_POLICY_BUNDLE)) { try { SharedPreferences mainPrefp = context.getSharedPreferences("com.mdm", Context.MODE_PRIVATE); Editor editorp = mainPrefp.edit(); editorp.putString("policy", ""); editorp.commit(); SharedPreferences mainPref = context.getSharedPreferences("com.mdm", Context.MODE_PRIVATE); Editor editor = mainPref.edit(); editor.putString("policy", data); editor.commit(); /*if (mainPref.getString("policy_applied", "") == null || mainPref.getString("policy_applied", "").trim() .equals("0") || mainPref.getString("policy_applied", "").trim() .equals("")) {*/ //executePolicy(); //} /* * JSONArray jArray = new JSONArray(data); for(int i = 0; * i<jArray.length(); i++){ JSONObject policyObj = * (JSONObject)jArray.getJSONObject(i); * if(policyObj.getString("data")!=null && * policyObj.getString("data")!=""){ * doTask(policyObj.getString("code"), * policyObj.getString("data"), REQUEST_MODE_BUNDLE); } } * doTask(code, "", REQUEST_MODE_NORMAL); */ } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } else if (intent.getStringExtra("message").trim().equals(CommonUtilities.OPERATION_POLICY_MONITOR)) { doTask(policy_code, data, REQUEST_MODE_NORMAL); } else { doTask(code, data, REQUEST_MODE_NORMAL); } }
From source file:com.android.calendar.AllInOneActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { Time t = null; int viewType = ViewType.CURRENT; long extras = CalendarController.EXTRA_GOTO_TIME; final int itemId = item.getItemId(); if (itemId == R.id.action_refresh) { mController.refreshCalendars();//from w ww .jav a 2 s . c o m return true; } else if (itemId == R.id.action_today) { viewType = ViewType.CURRENT; t = new Time(mTimeZone); t.setToNow(); extras |= CalendarController.EXTRA_GOTO_TODAY; } else if (itemId == R.id.action_goto) { Time todayTime; t = new Time(mTimeZone); t.set(mController.getTime()); todayTime = new Time(mTimeZone); todayTime.setToNow(); if (todayTime.month == t.month) { t = todayTime; } DatePickerDialog datePickerDialog = DatePickerDialog .newInstance(new DatePickerDialog.OnDateSetListener() { @Override public void onDateSet(DatePickerDialog dialog, int year, int monthOfYear, int dayOfMonth) { Time selectedTime = new Time(mTimeZone); selectedTime.year = year; selectedTime.month = monthOfYear; selectedTime.monthDay = dayOfMonth; long extras = CalendarController.EXTRA_GOTO_TIME | CalendarController.EXTRA_GOTO_DATE; mController.sendEvent(this, EventType.GO_TO, selectedTime, null, selectedTime, -1, ViewType.CURRENT, extras, null, null); } }, t.year, t.month, t.monthDay); datePickerDialog.show(getFragmentManager(), "datePickerDialog"); } else if (itemId == R.id.action_hide_controls) { mHideControls = !mHideControls; Utils.setSharedPreference(this, GeneralPreferences.KEY_SHOW_CONTROLS, !mHideControls); item.setTitle(mHideControls ? mShowString : mHideString); if (!mHideControls) { mMiniMonth.setVisibility(View.VISIBLE); mCalendarsList.setVisibility(View.VISIBLE); mMiniMonthContainer.setVisibility(View.VISIBLE); } final ObjectAnimator slideAnimation = ObjectAnimator.ofInt(this, "controlsOffset", mHideControls ? 0 : mControlsAnimateWidth, mHideControls ? mControlsAnimateWidth : 0); slideAnimation.setDuration(mCalendarControlsAnimationTime); ObjectAnimator.setFrameDelay(0); slideAnimation.start(); return true; } else if (itemId == R.id.action_search) { return false; } else if (itemId == R.id.action_import) { ImportActivity.pickImportFile(this); } else { return mExtensions.handleItemSelected(item, this); } mController.sendEvent(this, EventType.GO_TO, t, null, t, -1, viewType, extras, null, null); return true; }
From source file:com.dwdesign.tweetings.util.Utils.java
public static String formatToLongTimeString(final Context context, final long timestamp) { if (context == null) return null; final Time then = new Time(); then.set(timestamp);/* www .ja v a2 s.com*/ final Time now = new Time(); now.setToNow(); int format_flags = DateUtils.FORMAT_NO_NOON_MIDNIGHT | DateUtils.FORMAT_CAP_AMPM; format_flags |= DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_TIME; return DateUtils.formatDateTime(context, timestamp, format_flags); }
From source file:com.dwdesign.tweetings.util.Utils.java
public static String formatTimeStampString(final Context context, final long timestamp) { if (context == null) return null; final Time then = new Time(); then.set(timestamp);//from w w w .j av a2 s . co m final Time now = new Time(); now.setToNow(); int format_flags = DateUtils.FORMAT_NO_NOON_MIDNIGHT | DateUtils.FORMAT_ABBREV_ALL | DateUtils.FORMAT_CAP_AMPM; if (then.year != now.year) { format_flags |= DateUtils.FORMAT_SHOW_YEAR | DateUtils.FORMAT_SHOW_DATE; } else if (then.yearDay != now.yearDay) { format_flags |= DateUtils.FORMAT_SHOW_DATE; } else { format_flags |= DateUtils.FORMAT_SHOW_TIME; } return DateUtils.formatDateTime(context, timestamp, format_flags); }