Android Open Source - HistoryCleanerPro Edit 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  ww w.  j  a  va  2  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 java.util.List;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.SpinnerAdapter;

import com.ayros.historycleaner.Globals;
import com.ayros.historycleaner.R;
import com.ayros.historycleaner.cleaning.ProfileList;
import com.ayros.historycleaner.locale.bundle.BundleScrubber;
import com.ayros.historycleaner.locale.bundle.PluginBundleManager;

/**
 * This is the "Edit" activity for a Locale Plug-in.
 * <p>
 * This Activity can be started in one of two states:
 * <ul>
 * <li>New plug-in instance: The Activity's Intent will not contain
 * {@link com.twofortyfouram.locale.Intent#EXTRA_BUNDLE}.</li>
 * <li>Old plug-in instance: The Activity's Intent will contain
 * {@link com.twofortyfouram.locale.Intent#EXTRA_BUNDLE} from a previously saved
 * plug-in instance that the user is editing.</li>
 * </ul>
 * 
 * @see com.twofortyfouram.locale.Intent#ACTION_EDIT_SETTING
 * @see com.twofortyfouram.locale.Intent#EXTRA_BUNDLE
 */
public final class EditPluginActivity extends AbstractPluginActivity
{
  List<String> profileNames;
  
  @Override
  protected void onCreate(final Bundle savedInstanceState)
  {
    super.onCreate(savedInstanceState);
    
    if (Globals.getContext() == null)
    {
      Globals.setContext(this);
    }
    
    if (!ProfileList.isLoaded())
    {
      ProfileList.load();
    }
    profileNames = ProfileList.getNamesList(false);
    
    BundleScrubber.scrub(getIntent());
    
    final Bundle localeBundle = getIntent().getBundleExtra(com.twofortyfouram.locale.Intent.EXTRA_BUNDLE);
    BundleScrubber.scrub(localeBundle);
    
    setContentView(R.layout.activity_edit_plugin);
    
    Spinner profileSpinner = (Spinner)findViewById(R.id.editPlugin_profileSpinner);
    profileSpinner.setAdapter(getSpinnerAdapter());
    
    if (savedInstanceState == null)
    {
      if (PluginBundleManager.isBundleValid(localeBundle))
      {
        String profile = localeBundle.getString(PluginBundleManager.BUNDLE_EXTRA_STRING_CLEAN_PROFILE);
        
        int index = indexOfProfileName(profile);
        if (index != -1)
        {
          profileSpinner.setSelection(index);
        }
      }
    }
  }
  
  private int indexOfProfileName(String profile)
  {
    for (int i = 0; i < profileNames.size(); i++)
    {
      if (profileNames.get(i).equals(profile))
      {
        return i;
      }
    }
    
    return -1;
  }
  
  private SpinnerAdapter getSpinnerAdapter()
  {
    return new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, profileNames);
  }
  
  @Override
  public void finish()
  {
    if (!isCanceled())
    {
      Spinner profileSpinner = (Spinner)findViewById(R.id.editPlugin_profileSpinner);
      int index = profileSpinner.getSelectedItemPosition();
      
      if (index >= 0)
      {
        String profileName = profileNames.get(index);
        
        Intent resultIntent = new Intent();
        
        /*
         * This extra is the data to ourselves: either for the Activity
         * or the BroadcastReceiver. Note that anything placed in this
         * Bundle must be available to Locale's class loader. So storing
         * String, int, and other standard objects will work just fine.
         * Parcelable objects are not acceptable, unless they also
         * implement Serializable. Serializable objects must be standard
         * Android platform objects (A Serializable class private to
         * this plug-in's APK cannot be stored in the Bundle, as
         * Locale's classloader will not recognize it).
         */
        Bundle resultBundle = PluginBundleManager.generateBundle(getApplicationContext(), profileName);
        resultIntent.putExtra(com.twofortyfouram.locale.Intent.EXTRA_BUNDLE, resultBundle);
        
        /*
         * The blurb is concise status text to be displayed in the
         * host's UI.
         */
        String blurb = generateBlurb(getApplicationContext(), profileName);
        resultIntent.putExtra(com.twofortyfouram.locale.Intent.EXTRA_STRING_BLURB, blurb);
        
        setResult(RESULT_OK, resultIntent);
      }
    }
    
    super.finish();
  }
  
  /**
   * @param context
   *            Application context.
   * @param message
   *            The toast message to be displayed by the plug-in. Cannot be
   *            null.
   * @return A blurb for the plug-in.
   */
  static String generateBlurb(final Context context, final String message)
  {
    final int maxBlurbLength = context.getResources().getInteger(
      com.twofortyfouram.locale.api.R.integer.twofortyfouram_locale_maximum_blurb_length);
    
    if (message.length() > maxBlurbLength)
    {
      return message.substring(0, maxBlurbLength);
    }
    
    return message;
  }
}




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