Android Open Source - PhoneProfiles_Eclipse One Row 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 w  w w.  j  a 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.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.widget.RemoteViews;

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

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

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

    // ziskanie vsetkych wigetov tejtor triedy na plochach lauchera
    ComponentName thisWidget = new ComponentName(context, OneRowWidgetProvider.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;
      }
      
      RemoteViews remoteViews;
      if (GlobalData.applicationWidgetListPrefIndicator)
        remoteViews = new RemoteViews(context.getPackageName(), R.layout.one_row_widget);
      else
        remoteViews = new RemoteViews(context.getPackageName(), R.layout.one_row_widget_no_indicator);
      

      // set background
      int red = 0;
      int green = 0;
      int blue = 0;
      if (GlobalData.applicationWidgetListLightnessB.equals("0")) red = 0x00;
      if (GlobalData.applicationWidgetListLightnessB.equals("25")) red = 0x40;
      if (GlobalData.applicationWidgetListLightnessB.equals("50")) red = 0x80;
      if (GlobalData.applicationWidgetListLightnessB.equals("75")) red = 0xC0;
      if (GlobalData.applicationWidgetListLightnessB.equals("100")) red = 0xFF;
      green = red; blue = red;
      int alpha = 0x40;
      if (GlobalData.applicationWidgetListBackground.equals("0")) alpha = 0x00;
      if (GlobalData.applicationWidgetListBackground.equals("25")) alpha = 0x40;
      if (GlobalData.applicationWidgetListBackground.equals("50")) alpha = 0x80;
      if (GlobalData.applicationWidgetListBackground.equals("75")) alpha = 0xC0;
      if (GlobalData.applicationWidgetListBackground.equals("100")) alpha = 0xFF;
      remoteViews.setInt(R.id.widget_one_row_root, "setBackgroundColor", Color.argb(alpha, red, green, blue));
      
      if (isIconResourceID)
          {
            //remoteViews.setImageViewResource(R.id.activate_profile_widget_icon, 0);
            int iconResource = context.getResources().getIdentifier(iconIdentifier, "drawable", context.getPackageName());
            remoteViews.setImageViewResource(R.id.widget_one_row_header_profile_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.widget_one_row_header_profile_icon, profile._iconBitmap);
          }
          //if (GlobalData.applicationWidgetListIconColor.equals("1"))
          //{
          red = 0xFF;
          green = 0xFF;
          blue = 0xFF;
          if (GlobalData.applicationWidgetListLightnessT.equals("0")) red = 0x00;
          if (GlobalData.applicationWidgetListLightnessT.equals("25")) red = 0x40;
          if (GlobalData.applicationWidgetListLightnessT.equals("50")) red = 0x80;
          if (GlobalData.applicationWidgetListLightnessT.equals("75")) red = 0xC0;
          if (GlobalData.applicationWidgetListLightnessT.equals("100")) red = 0xFF;
          green = red; blue = red;
          remoteViews.setTextColor(R.id.widget_one_row_header_profile_name, Color.argb(0xFF, red, green, blue));
          //}
          //else
          //{
          //  remoteViews.setTextColor(R.id.widget_one_row_header_profile_name, Color.parseColor("#33b5e5"));
          //}
      remoteViews.setTextViewText(R.id.widget_one_row_header_profile_name, profileName);
      if (GlobalData.applicationWidgetListPrefIndicator)
      {
        if (profile._preferencesIndicator == null)
          remoteViews.setImageViewResource(R.id.widget_one_row_header_profile_pref_indicator, R.drawable.ic_empty);
        else
          remoteViews.setImageViewBitmap(R.id.widget_one_row_header_profile_pref_indicator, profile._preferencesIndicator);
      }
          if (GlobalData.applicationWidgetListIconColor.equals("1"))
          {
        monochromeValue = 0xFF;
        if (GlobalData.applicationWidgetListIconLightness.equals("0")) monochromeValue = 0x00;
        if (GlobalData.applicationWidgetListIconLightness.equals("25")) monochromeValue = 0x40;
        if (GlobalData.applicationWidgetListIconLightness.equals("50")) monochromeValue = 0x80;
        if (GlobalData.applicationWidgetListIconLightness.equals("75")) monochromeValue = 0xC0;
        if (GlobalData.applicationWidgetListIconLightness.equals("100")) monochromeValue = 0xFF;
            
            Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_profile_activated);
            bitmap = BitmapManipulator.monochromeBitmap(bitmap, monochromeValue, context);
            remoteViews.setImageViewBitmap(R.id.widget_one_row_header_profile_activated, bitmap);
          }
          else
          {
            remoteViews.setImageViewResource(R.id.widget_one_row_header_profile_activated, R.drawable.ic_profile_activated);
          }
      
      
      
      // 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.widget_one_row_header, 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