Android Open Source - PhoneProfiles_Eclipse Profile Preference Dialog






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;
/*w  w  w .  j av  a2s. co m*/
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

import android.app.Dialog;
import android.content.Context;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
//import android.preference.Preference;
//import android.preference.Preference.OnPreferenceChangeListener;
import android.view.View;


public class ProfilePreferenceDialog extends Dialog
{

  public ProfilePreference profilePreference;
  public int addNoActivateItem;
  private ProfilePreferenceAdapter profilePreferenceAdapter;
  
  public List<Profile> profileList;
  String profileId;
  
  private Context _context;
  
  private ListView listView;

  public ProfilePreferenceDialog(Context context) {
    super(context);
  }
  
  public ProfilePreferenceDialog(Context context, ProfilePreference preference, String profileId)
  {
    super(context);
    
    profilePreference = preference;

    this.profileId = profileId;
    profileList = ProfilePreference.dataWrapper.getProfileList();
      Collections.sort(profileList, new AlphabeticallyComparator());
    
    addNoActivateItem = profilePreference.addNoActivateItem;


    _context = context;
    
    setContentView(R.layout.activity_profile_pref_dialog);
    
    listView = (ListView)findViewById(R.id.profile_pref_dlg_listview);
    
    profileList = ProfilePreference.dataWrapper.getProfileList();
      Collections.sort(profileList, new AlphabeticallyComparator());
    
    profilePreferenceAdapter = new ProfilePreferenceAdapter(this, _context, profileId, profileList); 
    listView.setAdapter(profilePreferenceAdapter);

    int position;
    long iProfileId;
    if (profileId.isEmpty())
      iProfileId = 0;
    else
      iProfileId = Long.valueOf(profileId);
      if ((addNoActivateItem == 1) && (iProfileId == GlobalData.PROFILE_NO_ACTIVATE))
        position = 0;
      else
      {
        boolean found = false;
        position = 0;
        for (Profile profile : profileList)
        {
          if (profile._id == iProfileId)
          {
            found = true;
            break;
          }
          position++;
        }
        if (found)
        {
          if (addNoActivateItem == 1)
            position++;
        }
        else
          position = 0;
      }
    listView.setSelection(position);
    listView.setItemChecked(position, true);
    listView.smoothScrollToPosition(position);
    
    listView.setOnItemClickListener(new OnItemClickListener() {
      public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
        doOnItemSelected(position);
      }

    });
    
  }

  public void doOnItemSelected(int position)
  {
    if (addNoActivateItem == 1)
    {
      long profileId;
      if (position == 0)
        profileId = GlobalData.PROFILE_NO_ACTIVATE;
      else
        profileId = profilePreferenceAdapter.profileList.get(position-1)._id;
      profilePreference.setProfileId(profileId);  
    }
    else
      profilePreference.setProfileId(profilePreferenceAdapter.profileList.get(position)._id);
    ProfilePreferenceDialog.this.dismiss();
  }
  
  private class AlphabeticallyComparator implements Comparator<Profile> {

    public int compare(Profile lhs, Profile rhs) {

        int res = GUIData.collator.compare(lhs._name, rhs._name);
          return res;
      }
  }
  
}




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