/** * The IntentService calls this method from the default worker thread with the intent that started * the service. When this method returns, IntentService stops the service, as appropriate. */ @Override protected void onHandleIntent(Intent intent) { Bundle extras = intent.getExtras(); if (extras == null) { Log.e(Constants.TAG, "Extras bundle is null!"); return; } if (intent.getAction() == null) { Log.e(Constants.TAG, "Intent must contain an action!"); return; } if (extras.containsKey(EXTRA_MESSENGER)) { mMessenger = (Messenger) extras.get(EXTRA_MESSENGER); } String action = intent.getAction(); setProgressCircleWithHandler(true); // execute action if (ACTION_CHANGE_COLOR.equals(action)) { // update calendar color if enabled if (new AccountHelper(this).isAccountActivated()) { CalendarSyncAdapterService.updateCalendarColor(this); } } else if (ACTION_MANUAL_COMPLETE_SYNC.equals(action)) { // perform blocking sync CalendarSyncAdapterService.performSync(this); } setProgressCircleWithHandler(false); }
/** * The IntentService calls this method from the default worker thread with the intent that started * the service. When this method returns, IntentService stops the service, as appropriate. */ @Override protected void onHandleIntent(Intent intent) { Bundle extras = intent.getExtras(); if (extras == null) { Log.e(Constants.TAG, "Extras bundle is null!"); return; } if (!(extras.containsKey(EXTRA_ACTION))) { Log.e(Constants.TAG, "Extra bundle must contain an action!"); return; } if (extras.containsKey(EXTRA_MESSENGER)) { mMessenger = (Messenger) extras.get(EXTRA_MESSENGER); } Bundle data = extras.getBundle(EXTRA_DATA); int action = extras.getInt(EXTRA_ACTION); setProgressCircleWithHandler(true); // execute action from extra bundle switch (action) { case ACTION_CHANGE_COLOR: int newColor = data.getInt(CHANGE_COLOR_NEW_COLOR); // only if enabled if (new AccountHelper(this).isAccountActivated()) { // update calendar color CalendarSyncAdapterService.updateCalendarColor(this, newColor); } break; case ACTION_CHANGE_REMINDER: int newMinutes = data.getInt(CHANGE_REMINDER_NEW_MINUTES); int reminderNo = data.getInt(CHANGE_REMINDER_NO); // only if enabled if (new AccountHelper(this).isAccountActivated()) { // Update all reminders to new minutes CalendarSyncAdapterService.updateAllReminders(this, reminderNo, newMinutes); } break; case ACTION_MANUAL_SYNC: // Force synchronous sync CalendarSyncAdapterService.performSync(this); break; default: break; } setProgressCircleWithHandler(false); }
@Override public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.about_fragment, container, false); // load html from html file from /res/raw InputStream inputStreamText = this.getActivity().getResources().openRawResource(R.raw.about); TextView versionText = (TextView) view.findViewById(R.id.about_version); versionText.setText(getString(R.string.about_version) + " " + getVersion()); JellyBeanSpanFixTextView aboutTextView = (JellyBeanSpanFixTextView) view.findViewById(R.id.about_text); // load html into textview HtmlSpanner htmlSpanner = new HtmlSpanner(); htmlSpanner.setStripExtraWhiteSpace(true); try { aboutTextView.setText(htmlSpanner.fromHtml(inputStreamText)); } catch (IOException e) { Log.e(Constants.TAG, "Error while reading raw resources as stream", e); } // make links work aboutTextView.setMovementMethod(LinkMovementMethod.getInstance()); // no flickering when clicking textview for Android < 4 aboutTextView.setTextColor( getResources().getColor(android.R.color.secondary_text_dark_nodisable)); return view; }
/** * Get the current package version. * * @return The current version. */ private String getVersion() { String result = ""; try { PackageManager manager = getActivity().getPackageManager(); PackageInfo info = manager.getPackageInfo(getActivity().getPackageName(), 0); result = String.format("%s (%s)", info.versionName, info.versionCode); } catch (NameNotFoundException e) { Log.w(Constants.TAG, "Unable to get application version: " + e.getMessage()); result = "Unable to get application version."; } return result; }
private void setProgressCircleWithHandler(boolean value) { Message msg = Message.obtain(); if (value) { msg.what = BackgroundStatusHandler.BACKGROUND_STATUS_HANDLER_ENABLE; } else { msg.what = BackgroundStatusHandler.BACKGROUND_STATUS_HANDLER_DISABLE; } if (mMessenger != null) { try { mMessenger.send(msg); } catch (RemoteException e) { Log.w(Constants.TAG, "Exception sending message, Is handler present?", e); } } }