Android Open Source - PhoneProfiles_Eclipse Profile Preferences Fragment Activity






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 a  v a 2s.  c  o  m
import sk.henrichg.phoneprofiles.ProfilePreferencesFragment.OnHideActionMode;
import sk.henrichg.phoneprofiles.ProfilePreferencesFragment.OnRedrawProfileListFragment;
import sk.henrichg.phoneprofiles.ProfilePreferencesFragment.OnRestartProfilePreferences;
import sk.henrichg.phoneprofiles.ProfilePreferencesFragment.OnShowActionMode;

import android.content.Intent;
import android.os.Bundle;
import android.preference.PreferenceScreen;
import android.support.v7.app.ActionBarActivity;
import android.view.KeyEvent;
import android.view.MenuItem;
 
public class ProfilePreferencesFragmentActivity extends ActionBarActivity
                        implements OnRestartProfilePreferences,
                                                         OnRedrawProfileListFragment,
                                                         OnShowActionMode,
                                                         OnHideActionMode
{
  private long profile_id = 0;
  int newProfileMode = EditorProfileListFragment.EDIT_MODE_UNDEFINED;
  
  @Override
    public void onCreate(Bundle savedInstanceState) {
    
    // must by called before super.onCreate() for PreferenceActivity
    GUIData.setTheme(this, false); // must by called before super.onCreate()
    GUIData.setLanguage(getBaseContext());
    
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_profile_preferences);

    getSupportActionBar().setHomeButtonEnabled(true);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

        profile_id = getIntent().getLongExtra(GlobalData.EXTRA_PROFILE_ID, 0);
        newProfileMode = getIntent().getIntExtra(GlobalData.EXTRA_NEW_PROFILE_MODE, EditorProfileListFragment.EDIT_MODE_UNDEFINED);

        if (profile_id == GlobalData.DEFAULT_PROFILE_ID)
          getSupportActionBar().setTitle(R.string.title_activity_default_profile_preferences);
        else
          getSupportActionBar().setTitle(R.string.title_activity_profile_preferences);
        
      //Log.e("ProfilePreferencesFragmentActivity.onCreate", "profile_id="+profile_id);
      //Log.e("ProfilePreferencesFragmentActivity.onCreate", "newProfileMode="+newProfileMode);
        
    if (savedInstanceState == null) {
      Bundle arguments = new Bundle();
      arguments.putLong(GlobalData.EXTRA_PROFILE_ID, profile_id);
      arguments.putInt(GlobalData.EXTRA_NEW_PROFILE_MODE, newProfileMode);
      if (profile_id == GlobalData.DEFAULT_PROFILE_ID)
        arguments.putInt(GlobalData.EXTRA_PREFERENCES_STARTUP_SOURCE, GlobalData.PREFERENCES_STARTUP_SOURCE_DEFAUT_PROFILE);
      else
        arguments.putInt(GlobalData.EXTRA_PREFERENCES_STARTUP_SOURCE, GlobalData.PREFERENCES_STARTUP_SOURCE_ACTIVITY);
      ProfilePreferencesFragment fragment = new ProfilePreferencesFragment();
      fragment.setArguments(arguments);
      getFragmentManager().beginTransaction()
          .replace(R.id.activity_profile_preferences_container, fragment, "ProfilePreferencesFragment").commit();
    }
    
      //Log.d("ProfilePreferencesFragmentActivity.onCreate", "xxxx");
    
    }
  
  @Override
  protected void onDestroy()
  {
    super.onDestroy();
  }
  
  @Override
  public void finish() {
    
    //Log.e("ProfilePreferencesFragmentActivity.finish","xxx");

    ProfilePreferencesFragment fragment = (ProfilePreferencesFragment)getFragmentManager().findFragmentById(R.id.activity_profile_preferences_container);
    if (fragment != null)
      profile_id = fragment.profile_id;

    //Log.e("ProfilePreferencesFragmentActivity.finish","profile_id="+profile_id);
    
    
    // for startActivityForResult
    Intent returnIntent = new Intent();
    returnIntent.putExtra(GlobalData.EXTRA_PROFILE_ID, profile_id);
    returnIntent.putExtra(GlobalData.EXTRA_NEW_PROFILE_MODE, newProfileMode);
    setResult(RESULT_OK,returnIntent);
  
      super.finish();
  }

  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home:
      finish();
      return true;
    default:
      return super.onOptionsItemSelected(item);
    }
  }
  
  /*
  @Override
  public void onConfigurationChanged(Configuration newConfig)
  {
    super.onConfigurationChanged(newConfig);
    
    getBaseContext().getResources().updateConfiguration(newConfig, getBaseContext().getResources().getDisplayMetrics());
    GUIData.reloadActivity(this);
  }
  */

  @Override
  public void onActivityResult(int requestCode, int resultCode, Intent data)
  {
    ProfilePreferencesFragment fragment = (ProfilePreferencesFragment)getFragmentManager().findFragmentById(R.id.activity_profile_preferences_container);
    if (fragment != null)
      fragment.doOnActivityResult(requestCode, resultCode, data);
  }

  @Override
  public boolean dispatchKeyEvent(KeyEvent event) {
        if (event.getKeyCode() == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_UP) {
            // handle your back button code here
          ProfilePreferencesFragment fragment = (ProfilePreferencesFragment)getFragmentManager().findFragmentById(R.id.activity_profile_preferences_container);
        if ((fragment != null) && (fragment.isActionModeActive()))
        {
          fragment.finishActionMode(ProfilePreferencesFragment.BUTTON_CANCEL);
              return true; // consumes the back key event - ActionMode is not finished
        }
        else
            return super.dispatchKeyEvent(event);
        }
      return super.dispatchKeyEvent(event);
  }
  
  public void onRestartProfilePreferences(Profile profile, int newProfileMode) {
    if ((newProfileMode != EditorProfileListFragment.EDIT_MODE_INSERT) &&
        (newProfileMode != EditorProfileListFragment.EDIT_MODE_DUPLICATE))
    {
      Bundle arguments = new Bundle();
      arguments.putLong(GlobalData.EXTRA_PROFILE_ID, profile._id);
      arguments.putInt(GlobalData.EXTRA_NEW_PROFILE_MODE, newProfileMode);
      if (profile_id == GlobalData.DEFAULT_PROFILE_ID)
        arguments.putInt(GlobalData.EXTRA_PREFERENCES_STARTUP_SOURCE, GlobalData.PREFERENCES_STARTUP_SOURCE_DEFAUT_PROFILE);
      else
        arguments.putInt(GlobalData.EXTRA_PREFERENCES_STARTUP_SOURCE, GlobalData.PREFERENCES_STARTUP_SOURCE_ACTIVITY);
      ProfilePreferencesFragment fragment = new ProfilePreferencesFragment();
      fragment.setArguments(arguments);
      getFragmentManager().beginTransaction()
          .replace(R.id.activity_profile_preferences_container, fragment, "ProfilePreferencesFragment").commit();
    }
    else
    {
      ProfilePreferencesFragment fragment = (ProfilePreferencesFragment)getFragmentManager().findFragmentById(R.id.editor_profile_detail_container);
      if (fragment != null)
      {
        getFragmentManager().beginTransaction()
          .remove(fragment).commit();
      }
    }
  }

  public void onRedrawProfileListFragment(Profile profile, int newProfileMode) {
    // all redraws are in EditorProfilesActivity.onActivityResult()
  }

  public void onPreferenceAttached(PreferenceScreen root, int xmlId) {
    
  }

  @Override
  public void onHideActionMode() {

  }

  @Override
  public void onShowActionMode() {
    
  }

}




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