Android Open Source - HistoryCleanerPro Abstract Plugin Activity






From Project

Back to project page HistoryCleanerPro.

License

The source code is released under:

Copyright (c) 2014, John Phillips All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: ...

If you think the Android project HistoryCleanerPro 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

/*
 * Copyright 2013 two forty four a.m. LLC <http://www.twofortyfouram.com>
 *//from  w  w w  . java2 s  .c  om
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in
 * compliance with the License. You may obtain a copy of the License at
 * <http://www.apache.org/licenses/LICENSE-2.0>
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the License is
 * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and limitations under the License.
 */

package com.ayros.historycleaner.locale.ui;

import android.annotation.TargetApi;
import android.app.Activity;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;

import com.ayros.historycleaner.locale.Constants;
import com.twofortyfouram.locale.BreadCrumber;
import com.twofortyfouram.locale.api.R;

/**
 * Superclass for plug-in Activities. This class takes care of initializing
 * aspects of the plug-in's UI to look more integrated with the plug-in host.
 */
public abstract class AbstractPluginActivity extends Activity
{
  /**
   * Flag boolean that can only be set to true via the "Don't Save"
   * {@link com.twofortyfouram.locale.platform.R.id#twofortyfouram_locale_menu_dontsave}
   * menu item in {@link #onMenuItemSelected(int, MenuItem)}.
   */
  /*
   * There is no need to save/restore this field's state.
   */
  private boolean mIsCancelled = false;
  
  @Override
  protected void onCreate(final Bundle savedInstanceState)
  {
    super.onCreate(savedInstanceState);
    
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
    {
      setupTitleApi11();
    }
    else
    {
      setTitle(BreadCrumber.generateBreadcrumb(getApplicationContext(), getIntent(),
          getString(com.ayros.historycleaner.R.string.app_plugin_name)));
    }
  }
  
  @TargetApi(Build.VERSION_CODES.HONEYCOMB)
  private void setupTitleApi11()
  {
    CharSequence callingApplicationLabel = null;
    try
    {
      callingApplicationLabel = getPackageManager().getApplicationLabel(
          getPackageManager().getApplicationInfo(getCallingPackage(), 0));
    }
    catch (final NameNotFoundException e)
    {
      if (Constants.IS_LOGGABLE)
      {
        Log.e(Constants.LOG_TAG, "Calling package couldn't be found", e); //$NON-NLS-1$
      }
    }
    if (null != callingApplicationLabel)
    {
      setTitle(callingApplicationLabel);
    }
  }
  
  @Override
  public boolean onCreateOptionsMenu(final Menu menu)
  {
    super.onCreateOptionsMenu(menu);
    
    getMenuInflater().inflate(R.menu.twofortyfouram_locale_help_save_dontsave, menu);
    
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
    {
      setupActionBarApi11();
    }
    
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH)
    {
      setupActionBarApi14();
    }
    
    return true;
  }
  
  @TargetApi(Build.VERSION_CODES.HONEYCOMB)
  private void setupActionBarApi11()
  {
    getActionBar().setSubtitle(
      BreadCrumber.generateBreadcrumb(getApplicationContext(), getIntent(),
        getString(com.ayros.historycleaner.R.string.app_plugin_name)));
  }
  
  @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
  private void setupActionBarApi14()
  {
    getActionBar().setDisplayHomeAsUpEnabled(true);
    
    /*
     * Note: There is a small TOCTOU error here, in that the host could be
     * uninstalled right after launching the plug-in. That would cause
     * getApplicationIcon() to return the default application icon. It won't
     * fail, but it will return an incorrect icon.
     * 
     * In practice, the chances that the host will be uninstalled while the
     * plug-in UI is running are very slim.
     */
    try
    {
      getActionBar().setIcon(getPackageManager().getApplicationIcon(getCallingPackage()));
    }
    catch (final NameNotFoundException e)
    {
      if (Constants.IS_LOGGABLE)
      {
        Log.w(Constants.LOG_TAG, "An error occurred loading the host's icon", e); //$NON-NLS-1$
      }
    }
  }
  
  @Override
  public boolean onMenuItemSelected(final int featureId, final MenuItem item)
  {
    final int id = item.getItemId();
    
    if (android.R.id.home == id)
    {
      finish();
      return true;
    }
    else if (R.id.twofortyfouram_locale_menu_dontsave == id)
    {
      mIsCancelled = true;
      finish();
      return true;
    }
    else if (R.id.twofortyfouram_locale_menu_save == id)
    {
      finish();
      return true;
    }
    
    return super.onOptionsItemSelected(item);
  }
  
  /**
   * During {@link #finish()}, subclasses can call this method to determine
   * whether the Activity was canceled.
   * 
   * @return True if the Activity was canceled. False if the Activity was not
   *         canceled.
   */
  protected boolean isCanceled()
  {
    return mIsCancelled;
  }
}




Java Source Code List

com.ayros.historycleaner.Globals.java
com.ayros.historycleaner.ProfileAdapter.java
com.ayros.historycleaner.UIRunner.java
com.ayros.historycleaner.cleaning.CategoryList.java
com.ayros.historycleaner.cleaning.Category.java
com.ayros.historycleaner.cleaning.CleanItem.java
com.ayros.historycleaner.cleaning.CleanListener.java
com.ayros.historycleaner.cleaning.Cleaner.java
com.ayros.historycleaner.cleaning.ProfileList.java
com.ayros.historycleaner.cleaning.Profile.java
com.ayros.historycleaner.cleaning.SimpleDatabaseItem.java
com.ayros.historycleaner.cleaning.SimpleFileItem.java
com.ayros.historycleaner.cleaning.items._AdobeReader_Recent.java
com.ayros.historycleaner.cleaning.items._FirefoxBeta_Cache.java
com.ayros.historycleaner.cleaning.items._FirefoxBeta_Cookies.java
com.ayros.historycleaner.cleaning.items._FirefoxBeta_History.java
com.ayros.historycleaner.cleaning.items._FirefoxBeta_LocalStorage.java
com.ayros.historycleaner.cleaning.items._FirefoxBeta_OpenTabs.java
com.ayros.historycleaner.cleaning.items._Firefox_Cache.java
com.ayros.historycleaner.cleaning.items._Firefox_Cookies.java
com.ayros.historycleaner.cleaning.items._Firefox_History.java
com.ayros.historycleaner.cleaning.items._Firefox_LocalStorage.java
com.ayros.historycleaner.cleaning.items._Firefox_OpenTabs.java
com.ayros.historycleaner.cleaning.items._ONEBrowser_Cache.java
com.ayros.historycleaner.cleaning.items._ONEBrowser_LocalStorage.java
com.ayros.historycleaner.cleaning.items._System_BrowserHistory.java
com.ayros.historycleaner.cleaning.items._System_Cache.java
com.ayros.historycleaner.cleaning.items._System_Clipboard.java
com.ayros.historycleaner.cleaning.items._System_FrequentContacts.java
com.ayros.historycleaner.cleaning.items._System_RecentCalls.java
com.ayros.historycleaner.cleaning.items._System_SMS.java
com.ayros.historycleaner.helpers.DBHelper.java
com.ayros.historycleaner.helpers.DatabaseModifier.java
com.ayros.historycleaner.helpers.Helper.java
com.ayros.historycleaner.helpers.Logger.java
com.ayros.historycleaner.helpers.PrefsModifier.java
com.ayros.historycleaner.helpers.RootHelper.java
com.ayros.historycleaner.helpers.XML.java
com.ayros.historycleaner.locale.Constants.java
com.ayros.historycleaner.locale.bundle.BundleScrubber.java
com.ayros.historycleaner.locale.bundle.PluginBundleManager.java
com.ayros.historycleaner.locale.receiver.FireReceiver.java
com.ayros.historycleaner.locale.ui.AbstractPluginActivity.java
com.ayros.historycleaner.locale.ui.EditPluginActivity.java
com.ayros.historycleaner.ui.CleanFragment.java
com.ayros.historycleaner.ui.DataViewActivity.java
com.ayros.historycleaner.ui.HelpActivity.java
com.ayros.historycleaner.ui.MainActivity.java
com.ayros.historycleaner.ui.OnProfileUpdated.java
com.ayros.historycleaner.ui.ProfileFragment.java
com.ayros.historycleaner.ui.ShortcutActivity.java
com.ayros.historycleaner.ui.ShortcutCleanActivity.java
com.twofortyfouram.locale.BreadCrumber.java
com.twofortyfouram.locale.Constants.java
com.twofortyfouram.locale.Intent.java
com.twofortyfouram.locale.PackageUtilities.java