Android Open Source - PhoneProfiles_Eclipse Icon Widget Provider






From Project

Back to project page PhoneProfiles_Eclipse.

License

The source code is released under:

Apache License

If you think the Android project PhoneProfiles_Eclipse 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 sk.henrichg.phoneprofiles;
/*from  ww  w  . j  av  a 2 s. co 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.widget.RemoteViews;

public class IconWidgetProvider extends AppWidgetProvider {
  
  private DataWrapper dataWrapper;
  
  @Override
  public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds)
  {
    
    GlobalData.loadPreferences(context);

    int monochromeValue = 0xFF;
    if (GlobalData.applicationWidgetIconLightness.equals("0")) monochromeValue = 0x00;
    if (GlobalData.applicationWidgetIconLightness.equals("25")) monochromeValue = 0x40;
    if (GlobalData.applicationWidgetIconLightness.equals("50")) monochromeValue = 0x80;
    if (GlobalData.applicationWidgetIconLightness.equals("75")) monochromeValue = 0xC0;
    if (GlobalData.applicationWidgetIconLightness.equals("100")) monochromeValue = 0xFF;

    dataWrapper = new DataWrapper(context, true, 
                            GlobalData.applicationWidgetIconColor.equals("1"), 
                            monochromeValue);
    
    Profile profile = dataWrapper.getActivatedProfile();

    // ziskanie vsetkych wigetov tejtor triedy na plochach lauchera
    ComponentName thisWidget = new ComponentName(context, IconWidgetProvider.class);
    int[] allWidgetIds = appWidgetManager.getAppWidgetIds(thisWidget);

    // prechadzame vsetky ziskane widgety
    for (int widgetId : allWidgetIds)
    {
      boolean isIconResourceID;
      String iconIdentifier;
      String profileName;
      if (profile != null)
      {
        isIconResourceID = profile.getIsIconResourceID();
        iconIdentifier = profile.getIconIdentifier();
        profileName = profile._name;
      }
      else
      {
        // create empty profile and set icon resource
        profile = new Profile();
        profile._name = context.getResources().getString(R.string.profiles_header_profile_name_no_activated);
        profile._icon = GlobalData.PROFILE_ICON_DEFAULT+"|1";

        profile.generateIconBitmap(context, 
            GlobalData.applicationWidgetListIconColor.equals("1"), 
            monochromeValue);
        isIconResourceID = profile.getIsIconResourceID();
        iconIdentifier = profile.getIconIdentifier();
        profileName = profile._name;
      }
      
      // priprava view-u na aktualizacia widgetu
      RemoteViews remoteViews;
      if (GlobalData.applicationWidgetIconHideProfileName)
        remoteViews = new RemoteViews(context.getPackageName(), R.layout.icon_widget_no_profile_name);
      else
        remoteViews = new RemoteViews(context.getPackageName(), R.layout.icon_widget);
          if (isIconResourceID)
          {
            //remoteViews.setImageViewResource(R.id.activate_profile_widget_icon, 0);
            int iconResource = context.getResources().getIdentifier(iconIdentifier, "drawable", context.getPackageName());
            remoteViews.setImageViewResource(R.id.icon_widget_icon, iconResource);
          }
          else
          {
          //Resources resources = context.getResources();
            //remoteViews.setImageViewBitmap(R.id.activate_profile_widget_icon, null);
          //int height = (int) resources.getDimension(android.R.dimen.app_icon_size);
          //int width = (int) resources.getDimension(android.R.dimen.app_icon_size);
          //Bitmap bitmap = BitmapResampler.resample(iconIdentifier, width, height);
            //remoteViews.setImageViewBitmap(R.id.activate_profile_widget_icon, bitmap);
            remoteViews.setImageViewBitmap(R.id.icon_widget_icon, profile._iconBitmap);
          }
      if (!GlobalData.applicationWidgetIconHideProfileName)
        remoteViews.setTextViewText(R.id.icon_widget_name, profileName);
      
      // konfiguracia, ze ma spustit hlavnu aktivitu zoznamu profilov, ked kliknme na widget
      Intent intent = new Intent(context, ActivateProfileActivity.class);
      intent.putExtra(GlobalData.EXTRA_START_APP_SOURCE, GlobalData.STARTUP_SOURCE_WIDGET);
      PendingIntent pendingIntent = PendingIntent.getActivity(context, 1, intent, PendingIntent.FLAG_UPDATE_CURRENT);
      remoteViews.setOnClickPendingIntent(R.id.icon_widget_icon, pendingIntent);
      remoteViews.setOnClickPendingIntent(R.id.icon_widget_name, pendingIntent);
      
      // aktualizacia widgetu
      appWidgetManager.updateAppWidget(widgetId, remoteViews);
    }
    
    dataWrapper.invalidateDataWrapper();
    dataWrapper = null;
    
  }
}




Java Source Code List

sk.henrichg.phoneprofiles.ActivateProfileActivity.java
sk.henrichg.phoneprofiles.ActivateProfileHelper.java
sk.henrichg.phoneprofiles.ActivateProfileListAdapter.java
sk.henrichg.phoneprofiles.ActivateProfileListFragment.java
sk.henrichg.phoneprofiles.ApplicationsCache.java
sk.henrichg.phoneprofiles.ApplicationsPreferenceAdapter.java
sk.henrichg.phoneprofiles.ApplicationsPreferenceDialog.java
sk.henrichg.phoneprofiles.ApplicationsPreference.java
sk.henrichg.phoneprofiles.BackgroundActivateProfileActivity.java
sk.henrichg.phoneprofiles.BitmapManipulator.java
sk.henrichg.phoneprofiles.BootUpReceiver.java
sk.henrichg.phoneprofiles.BrightnessDialogPreference.java
sk.henrichg.phoneprofiles.BrightnessView.java
sk.henrichg.phoneprofiles.DashClockBroadcastReceiver.java
sk.henrichg.phoneprofiles.DataWrapper.java
sk.henrichg.phoneprofiles.DatabaseHandler.java
sk.henrichg.phoneprofiles.EditorProfileListAdapter.java
sk.henrichg.phoneprofiles.EditorProfileListFragment.java
sk.henrichg.phoneprofiles.EditorProfilesActivity.java
sk.henrichg.phoneprofiles.ExecuteRadioProfilePrefsService.java
sk.henrichg.phoneprofiles.ExecuteVolumeProfilePrefsService.java
sk.henrichg.phoneprofiles.FirstStartService.java
sk.henrichg.phoneprofiles.GUIData.java
sk.henrichg.phoneprofiles.GlobalData.java
sk.henrichg.phoneprofiles.IconWidgetProvider.java
sk.henrichg.phoneprofiles.ImageViewPreferenceAdapter.java
sk.henrichg.phoneprofiles.ImageViewPreferenceDialog.java
sk.henrichg.phoneprofiles.ImageViewPreference.java
sk.henrichg.phoneprofiles.KeyguardService.java
sk.henrichg.phoneprofiles.Keyguard.java
sk.henrichg.phoneprofiles.LocaleChangedReceiver.java
sk.henrichg.phoneprofiles.NumberPickerPreference.java
sk.henrichg.phoneprofiles.OneRowWidgetProvider.java
sk.henrichg.phoneprofiles.PackageReplacedReceiver.java
sk.henrichg.phoneprofiles.PhoneCallBroadcastReceiver.java
sk.henrichg.phoneprofiles.PhoneCallReceiver.java
sk.henrichg.phoneprofiles.PhoneProfilesDashClockExtension.java
sk.henrichg.phoneprofiles.PhoneProfilesHelper.java
sk.henrichg.phoneprofiles.PhoneProfilesPreferencesActivity.java
sk.henrichg.phoneprofiles.PhoneProfilesPreferencesFragment.java
sk.henrichg.phoneprofiles.ProfileDurationAlarmBroadcastReceiver.java
sk.henrichg.phoneprofiles.ProfileListWidgetFactory.java
sk.henrichg.phoneprofiles.ProfileListWidgetProvider.java
sk.henrichg.phoneprofiles.ProfileListWidgetService.java
sk.henrichg.phoneprofiles.ProfilePreferenceAdapter.java
sk.henrichg.phoneprofiles.ProfilePreferenceDialog.java
sk.henrichg.phoneprofiles.ProfilePreference.java
sk.henrichg.phoneprofiles.ProfilePreferencesFragmentActivity.java
sk.henrichg.phoneprofiles.ProfilePreferencesFragment.java
sk.henrichg.phoneprofiles.ProfilePreferencesIndicator.java
sk.henrichg.phoneprofiles.Profile.java
sk.henrichg.phoneprofiles.ReceiversService.java
sk.henrichg.phoneprofiles.RefreshGUIBroadcastReceiver.java
sk.henrichg.phoneprofiles.RemoteExportDataActivity.java
sk.henrichg.phoneprofiles.RemoveBrightnessViewBroadcastReceiver.java
sk.henrichg.phoneprofiles.ScreenOnOffBroadcastReceiver.java
sk.henrichg.phoneprofiles.ShortcutCreatorActivity.java
sk.henrichg.phoneprofiles.ShortcutCreatorListFragment.java
sk.henrichg.phoneprofiles.ShortcutProfileListAdapter.java
sk.henrichg.phoneprofiles.UpgradePPHelperActivity.java
sk.henrichg.phoneprofiles.VolumeDialogPreference.java