Android Open Source - MrParkingNavigator Main Widget Provider






From Project

Back to project page MrParkingNavigator.

License

The source code is released under:

MIT License

If you think the Android project MrParkingNavigator 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 ru.mail.parking.widget;
/*  w w  w  . ja v  a 2s  .c o m*/
import android.app.PendingIntent;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import android.widget.RemoteViews;

import ru.mail.parking.R;
import ru.mail.parking.floors.Place;

import static ru.mail.parking.App.app;
import static ru.mail.parking.App.prefs;
import static ru.mail.parking.Preferences.TimeFormat;

public class MainWidgetProvider extends AppWidgetProvider {
  @Override
  public void onEnabled(Context context) {
    app().setHasWidgets(true);
  }

  @Override
  public void onDisabled(Context context) {
    app().setHasWidgets(false);
  }

  @Override
  public void onUpdate(Context context, AppWidgetManager wmgr, int[] appWidgetIds) {
    update(context, wmgr, appWidgetIds);
  }

  private static void update(Context context, AppWidgetManager wmgr, int[] appWidgetIds) {
    Place place = prefs().getStoredPlace();

    int resId;
    String count;
    String info = "";

    if (place == null) {
      int free = prefs().getLastPlaces();
      count = (free == Place.INVALID ? "???" : String.valueOf(free));

      TimeFormat tf = prefs().getTimeFormat();
      boolean showTime = (tf != TimeFormat.none);

      resId = showTime ? R.layout.widget
                       : R.layout.widget_counter_only;
      if (showTime)
        info = prefs().getLastRefresh();
    } else {
      resId = R.layout.widget_place;
      count = String.valueOf(place.getNumber());
      info = app().getString(R.string.floor_format, place.getFloor(), place.getSide().name());
    }


    for (int id: appWidgetIds) {
      RemoteViews frame = new RemoteViews(context.getPackageName(), resId);
      frame.setTextViewText(R.id.count, count);
      if (!TextUtils.isEmpty(info))
        frame.setTextViewText(R.id.info, info);

      Intent it = new Intent(context, MainReceiver.class);
      it.setAction(MainReceiver.ACTION_TAP);

      PendingIntent pi = PendingIntent.getBroadcast(context, 0, it, PendingIntent.FLAG_CANCEL_CURRENT);
      frame.setOnClickPendingIntent(R.id.frame, pi);
      wmgr.updateAppWidget(id, frame);
    }
  }

  public static int[] getWidgetIds() {
    AppWidgetManager mgr = AppWidgetManager.getInstance(app());
    if (mgr == null)
      return new int[0];

    return mgr.getAppWidgetIds(new ComponentName(app().getPackageName(), MainWidgetProvider.class.getName()));
  }

  public static void updateAll() {
    AppWidgetManager mgr = AppWidgetManager.getInstance(app());
    if (mgr != null)
      update(app(), mgr, getWidgetIds());
  }
}




Java Source Code List

com.sonyericsson.extras.liveware.aef.control.Control.java
com.sonyericsson.extras.liveware.aef.control.package-info.java
com.sonyericsson.extras.liveware.aef.notification.Notification.java
com.sonyericsson.extras.liveware.aef.notification.package-info.java
com.sonyericsson.extras.liveware.aef.registration.Registration.java
com.sonyericsson.extras.liveware.aef.registration.package-info.java
com.sonyericsson.extras.liveware.aef.sensor.Sensor.java
com.sonyericsson.extras.liveware.aef.sensor.package-info.java
com.sonyericsson.extras.liveware.extension.util.Dbg.java
com.sonyericsson.extras.liveware.extension.util.ExtensionService.java
com.sonyericsson.extras.liveware.extension.util.ExtensionUtils.java
com.sonyericsson.extras.liveware.extension.util.control.ControlExtension.java
com.sonyericsson.extras.liveware.extension.util.control.ControlListItem.java
com.sonyericsson.extras.liveware.extension.util.control.ControlObjectClickEvent.java
com.sonyericsson.extras.liveware.extension.util.control.ControlTouchEvent.java
com.sonyericsson.extras.liveware.extension.util.control.ControlViewGroup.java
com.sonyericsson.extras.liveware.extension.util.control.ControlView.java
com.sonyericsson.extras.liveware.extension.util.notification.DelayedContentObserver.java
com.sonyericsson.extras.liveware.extension.util.notification.NotificationUtil.java
com.sonyericsson.extras.liveware.extension.util.registration.DeviceInfoHelper.java
com.sonyericsson.extras.liveware.extension.util.registration.DeviceInfo.java
com.sonyericsson.extras.liveware.extension.util.registration.DisplayInfo.java
com.sonyericsson.extras.liveware.extension.util.registration.HostApplicationInfo.java
com.sonyericsson.extras.liveware.extension.util.registration.IRegisterCallback.java
com.sonyericsson.extras.liveware.extension.util.registration.InputInfo.java
com.sonyericsson.extras.liveware.extension.util.registration.KeyPadInfo.java
com.sonyericsson.extras.liveware.extension.util.registration.RegisterExtensionTask.java
com.sonyericsson.extras.liveware.extension.util.registration.RegistrationAdapter.java
com.sonyericsson.extras.liveware.extension.util.registration.RegistrationInformation.java
com.sonyericsson.extras.liveware.extension.util.sensor.AccessorySensorEventListener.java
com.sonyericsson.extras.liveware.extension.util.sensor.AccessorySensorEvent.java
com.sonyericsson.extras.liveware.extension.util.sensor.AccessorySensorException.java
com.sonyericsson.extras.liveware.extension.util.sensor.AccessorySensorManager.java
com.sonyericsson.extras.liveware.extension.util.sensor.AccessorySensorType.java
com.sonyericsson.extras.liveware.extension.util.sensor.AccessorySensor.java
ru.mail.parking.App.java
ru.mail.parking.Preferences.java
ru.mail.parking.floors.FloorNavigator.java
ru.mail.parking.floors.Floor.java
ru.mail.parking.floors.Place.java
ru.mail.parking.sw2.SwControlFlow.java
ru.mail.parking.sw2.screens.SwBaseScreen.java
ru.mail.parking.sw2.screens.SwEnterPlaceScreen.java
ru.mail.parking.sw2.screens.SwFreePlacesScreen.java
ru.mail.parking.sw2.screens.SwNavigatorScreen.java
ru.mail.parking.sw2.screens.SwPlaceScreen.java
ru.mail.parking.sw2.system.SwReceiver.java
ru.mail.parking.sw2.system.SwRegInfo.java
ru.mail.parking.sw2.system.SwService.java
ru.mail.parking.ui.AboutActivity.java
ru.mail.parking.ui.DataDetailsActivity.java
ru.mail.parking.ui.EnterPlaceActivity.java
ru.mail.parking.ui.MultiscrollView.java
ru.mail.parking.ui.NavigatorActivity.java
ru.mail.parking.ui.NavigatorFloorView.java
ru.mail.parking.ui.SettingsActivity.java
ru.mail.parking.utils.NetworkAwaiter.java
ru.mail.parking.utils.NetworkStateReceiver.java
ru.mail.parking.utils.Utils.java
ru.mail.parking.widget.MainReceiver.java
ru.mail.parking.widget.MainWidgetProvider.java
ru.mail.parking.widget.SmartUpdate.java
ru.mail.parking.widget.UpdateService.java