Android Open Source - PhoneProfiles_Eclipse Profile List Widget Factory






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;
/*  ww  w .ja v  a 2  s  . co  m*/
import java.util.List;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.style.StyleSpan;
import android.util.TypedValue;
import android.widget.RemoteViews;
import android.widget.RemoteViewsService;

@SuppressLint("NewApi")
public class ProfileListWidgetFactory implements RemoteViewsService.RemoteViewsFactory {

  private DataWrapper dataWrapper;

  private Context context=null;
  //private int appWidgetId;
  private List<Profile> profileList;

  public ProfileListWidgetFactory(Context ctxt, Intent intent) {
    context = ctxt;
    /*appWidgetId=intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID,
                                       AppWidgetManager.INVALID_APPWIDGET_ID); */
  }
  
  public void createProfilesDataWrapper()
  {
    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;

    if (dataWrapper == null)
    {
      dataWrapper = new DataWrapper(context, true,  
                            GlobalData.applicationWidgetListIconColor.equals("1"), 
                            monochromeValue);
    }
    else
    {
      dataWrapper.setParameters(true, GlobalData.applicationWidgetListIconColor.equals("1"), 
                            monochromeValue);
    }
  }
  
  public void onCreate() {
    //Log.e("ProfileListWidgetFactory.onCreate","xxx");
  }
  
  public void onDestroy() {
    if (dataWrapper != null)
      dataWrapper.invalidateDataWrapper();
    dataWrapper = null;
  }

  public int getCount() {
    return(profileList.size());
  }

  public RemoteViews getViewAt(int position) {
    
    //Log.e("ProfileListWidgetFactory.getViewAt","xxx");
    
    RemoteViews row;
    if (!GlobalData.applicationWidgetListGridLayout)
      row=new RemoteViews(context.getPackageName(), R.layout.profile_list_widget_item);
    else
      row=new RemoteViews(context.getPackageName(), R.layout.profile_grid_widget_item);
    
    Profile profile = profileList.get(position);

    if (profile.getIsIconResourceID())
    {
      row.setImageViewResource(R.id.widget_profile_list_item_profile_icon, 
          context.getResources().getIdentifier(profile.getIconIdentifier(), "drawable", context.getPackageName()));
    }
    else
    {
        row.setImageViewBitmap(R.id.widget_profile_list_item_profile_icon, profile._iconBitmap);
    }
    if ((!GlobalData.applicationWidgetListHeader) && (profile._checked))
    {
      // hm, interesting, how to set bold style for RemoteView text ;-)
      Spannable sb = new SpannableString(profile._name);
      sb.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), 0, profile._name.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
      row.setTextViewText(R.id.widget_profile_list_item_profile_name, sb);
    }  
    else
      row.setTextViewText(R.id.widget_profile_list_item_profile_name, profile._name);
    int red = 0xFF;
    int green = 0xFF;
    int 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;
    if (!GlobalData.applicationWidgetListHeader)
    {
      if (profile._checked)
      {
          if (android.os.Build.VERSION.SDK_INT >= 16)
            row.setTextViewTextSize(R.id.widget_profile_list_item_profile_name, TypedValue.COMPLEX_UNIT_SP, 17);
          
            //if (GlobalData.applicationWidgetListIconColor.equals("1"))
          row.setTextColor(R.id.widget_profile_list_item_profile_name, Color.argb(0xFF, red, green, blue));
            //else
        //  row.setTextColor(R.id.widget_profile_list_item_profile_name, Color.parseColor("#33b5e5"));
      }
      else
      {
          if (android.os.Build.VERSION.SDK_INT >= 16)
            row.setTextViewTextSize(R.id.widget_profile_list_item_profile_name, TypedValue.COMPLEX_UNIT_SP, 15);
        
            //if (GlobalData.applicationWidgetListIconColor.equals("1"))
              row.setTextColor(R.id.widget_profile_list_item_profile_name, Color.argb(0xCC, red, green, blue));
            //else
            //  row.setTextColor(R.id.widget_profile_list_item_profile_name, Color.argb(0xFF, red, green, blue));
      }
    }
    else
    {
      row.setTextColor(R.id.widget_profile_list_item_profile_name, Color.argb(0xFF, red, green, blue));
    }
    if (!GlobalData.applicationWidgetListGridLayout)
    {
      if (GlobalData.applicationWidgetListPrefIndicator)
        row.setImageViewBitmap(R.id.widget_profile_list_profile_pref_indicator, profile._preferencesIndicator);
      else
        row.setImageViewResource(R.id.widget_profile_list_profile_pref_indicator, R.drawable.ic_empty);
    }

    Intent i=new Intent();
    Bundle extras=new Bundle();
    
    extras.putLong(GlobalData.EXTRA_PROFILE_ID, profile._id);
    extras.putInt(GlobalData.EXTRA_START_APP_SOURCE, GlobalData.STARTUP_SOURCE_SHORTCUT);
    i.putExtras(extras);
    row.setOnClickFillInIntent(R.id.widget_profile_list_item, i);

    return(row);
  }

  public RemoteViews getLoadingView() {
    return(null);
  }
  
  public int getViewTypeCount() {
    return(1);
  }

  public long getItemId(int position) {
    return(position);
  }

  public boolean hasStableIds() {
    return(true);
  }

  public void onDataSetChanged() {
    //Log.e("ProfileListWidgetFactory.onDataSetChanged","xxx");

    createProfilesDataWrapper();
    
    dataWrapper.clearProfileList();
    profileList = dataWrapper.getProfileList();
    //Log.e("ProfileListWidgetFactory.onDataSetChanged",""+profileList);
  }
}




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