Android Open Source - PhoneProfiles_Eclipse Activate Profile 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;
/*from  w w  w.j  a  va  2s.co m*/
import android.os.Bundle;
import android.app.Fragment;
import android.content.Intent;
import android.content.res.Configuration;

import android.support.v7.app.ActionBarActivity;
import android.util.TypedValue;
import android.view.Display;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.WindowManager;
import android.view.WindowManager.LayoutParams;

public class ActivateProfileActivity extends ActionBarActivity {

  private static ActivateProfileActivity instance;
  
  private float popupWidth;
  private float popupMaxHeight;
  private float popupHeight;
  private float actionBarHeight;

  @SuppressWarnings({ "deprecation" })
  @Override
  protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    
    instance = this;
    
    GUIData.setTheme(this, true);
    GUIData.setLanguage(getBaseContext());
    
  // set window dimensions ----------------------------------------------------------
    
    Display display = getWindowManager().getDefaultDisplay();
    
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND, WindowManager.LayoutParams.FLAG_DIM_BEHIND);
    LayoutParams params = getWindow().getAttributes();
    params.alpha = 1.0f;
    params.dimAmount = 0.5f;
    getWindow().setAttributes(params);
    
    // display dimensions
    popupWidth = display.getWidth();
    popupMaxHeight = display.getHeight();
    popupHeight = 0;
    actionBarHeight = 0;

    // action bar height
    TypedValue tv = new TypedValue();
    if (getTheme().resolveAttribute(android.support.v7.appcompat.R.attr.actionBarSize, tv, true))
          actionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data,getResources().getDisplayMetrics());
    
    // set max. dimensions for display orientation
    if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE)
    {
      //popupWidth = Math.round(popupWidth / 100f * 50f);
      //popupMaxHeight = Math.round(popupMaxHeight / 100f * 90f);
      popupWidth = popupWidth / 100f * 50f;
      popupMaxHeight = popupMaxHeight / 100f * 90f;
    }
    else
    {
      //popupWidth = Math.round(popupWidth / 100f * 70f);
      //popupMaxHeight = Math.round(popupMaxHeight / 100f * 90f);
      popupWidth = popupWidth / 100f * 80f;
      popupMaxHeight = popupMaxHeight / 100f * 90f;
    }

    // add action bar height
    popupHeight = popupHeight + actionBarHeight;
    
    final float scale = getResources().getDisplayMetrics().density;
    
    // add header height
    if (GlobalData.applicationActivatorHeader)
      popupHeight = popupHeight + 64f * scale;
    
    // add list items height
    DataWrapper dataWrapper = new DataWrapper(getBaseContext(), false, false, 0);
    int profileCount = dataWrapper.getDatabaseHandler().getProfilesCount();
    dataWrapper.invalidateDataWrapper();

    if (!GlobalData.applicationActivatorGridLayout)
    {
      // add list items height
      popupHeight = popupHeight + (50f * scale * profileCount); // item
      popupHeight = popupHeight + (5f * scale * (profileCount-1)); // divider
    }
    else
    {
      // add grid items height
      int modulo = profileCount % 3;
      profileCount = profileCount / 3;
      if (modulo > 0)
        ++profileCount;
      popupHeight = popupHeight + (75f * scale * profileCount); // item
      popupHeight = popupHeight + (5f * scale * (profileCount-1)); // divider
    }

    popupHeight = popupHeight + (20f * scale); // listview padding
    
    if (popupHeight > popupMaxHeight)
      popupHeight = popupMaxHeight;
  
    // set popup window dimensions
    getWindow().setLayout((int) (popupWidth + 0.5f), (int) (popupHeight + 0.5f));
    
  //-----------------------------------------------------------------------------------

    //Debug.startMethodTracing("phoneprofiles");

  // Layout ---------------------------------------------------------------------------------
    
    //long nanoTimeStart = GlobalData.startMeasuringRunTime();
    
    setContentView(R.layout.activity_activate_profile);
    
    //GlobalData.getMeasuredRunTime(nanoTimeStart, "ActivateProfileActivity.onCreate - setContnetView");

    //getSupportActionBar().setHomeButtonEnabled(true);
    //getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setTitle(R.string.title_activity_activator);

    //-----------------------------------------------------------------------------------------    

    //Log.d("PhoneProfileActivity.onCreate", "xxxx");
    
  }
  
  public static ActivateProfileActivity getInstance()
  {
    return instance;
  }
  
  @Override
  protected void onStart()
  {
    super.onStart();
  }
  
  @Override
  protected void onPause()
  {
    super.onPause();
  }
  
  @Override
  protected void onStop()
  {
    super.onStop();
    instance = null;
  }

  @Override 
  protected void onResume()
  {
    //Debug.stopMethodTracing();
    super.onResume();
    if (instance == null)
    {
      instance = this;
      refreshGUI();
    }
  }
  
  @Override
  protected void onDestroy()
  {
  //  Debug.stopMethodTracing();

    super.onDestroy();
  }

  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.activity_activate_profile, menu);
    return true;
  }
  
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.menu_edit_profiles:
      //Log.d("ActivateProfileActivity.onOptionsItemSelected", "menu_settings");
      
      Intent intent = new Intent(getBaseContext(), EditorProfilesActivity.class);
      intent.putExtra(GlobalData.EXTRA_START_APP_SOURCE, GlobalData.STARTUP_SOURCE_ACTIVATOR);
      startActivity(intent);
      
      finish();

      return true;
    default:
      return super.onOptionsItemSelected(item);
    }
  }

  @Override
  public void onConfigurationChanged(Configuration newConfig)
  {
    super.onConfigurationChanged(newConfig);
    
    getBaseContext().getResources().updateConfiguration(newConfig, getBaseContext().getResources().getDisplayMetrics());
    //setContentView(R.layout.activity_phone_profiles);
    
    GUIData.reloadActivity(this, false);
  }

  public void refreshGUI()
  {
    Fragment fragment = getFragmentManager().findFragmentById(R.id.activate_profile_list);
    if (fragment != null)
    {
      ((ActivateProfileListFragment)fragment).refreshGUI();
    }
  }
  
}




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