Android Open Source - Exif-Editor Ega Fragment Activity Base






From Project

Back to project page Exif-Editor.

License

The source code is released under:

MIT License

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

/*
 * @user https://github.com/Egatuts/*from   w w  w .j  a  v  a  2  s .c om*/
 * @repo https://github.com/Egatuts/Exif-Editor.git
 * @file https://github.com/Egatuts/Exif-Editor/blob/master/src/git/egatuts/android/fragment/EgaFragmentActivityBase.java
 * @package git.egatuts.android.fragment
 * @license MIT (http://www.opensource.org/licenses/MIT)
 */
package git.egatuts.android.fragment;

import android.app.Activity;
import android.os.Bundle;
import android.content.Intent;
import android.content.res.Resources;
import android.widget.Toast;

/**
 * Abstraction layer for Android Axtivity with view utils.
 * @author Esa Garca
 * @author EgaTuts
 * @version 1.0.0
 * @created 27/8/2014 at 16:18:54.
 */
public abstract class EgaFragmentActivityBase extends Activity
{
  
  /**
   * Sets the active activity.
   * @param newActivity    The new active activity.
   */
  public abstract void setActiveActivity (Activity newActivity);
  
  /**
   * Gets the active activity.
   * @return The active activity.
   */
  public abstract Activity getActiveActivity ();
  
  /**
   * Interface to listen for back button.
   */
  public static interface OnBackClickListener
  {
    
    /**
     * Executed when it's clicked the back button.
     * @return boolean state.
     */
    public boolean onClick ();
  }
  
  /**
   * OnBackClickListener reference.
   */
  private static OnBackClickListener onBackClickListener = null;
  
  /**
   * Sets the back click listener.
   * @param listener    The back click listener.
   */
  public void setOnBackClickListener (OnBackClickListener listener)
  {
    onBackClickListener = listener;
  }
  
  /**
   * Gets the active OnBackClickListener.
   * @return The active click listener.
   */
  public OnBackClickListener getOnBackClickListener ()
  {
    return onBackClickListener;
  }
  
  /**
   * Calls it's super method and saves the active activity.
   * @see android.app.Activity#onCreate(Bundle)
   */
  @Override
  public void onCreate (Bundle savedInstanceState)
  {
    super.onCreate(savedInstanceState);
    setActiveActivity(this);
  }
  
  /**
   * Calls it's super method and saves the active activity.
   * @see android.app.Activity#onResume()
   */
  @Override
  public void onResume ()
  {
    super.onResume();
    setActiveActivity(this);
  }
  
  /**
   * Removes the active activity reference and calls it's super method.
   * @see android.app.Activity#onPause()
   */
  @Override
  public void onPause ()
  {
    setActiveActivity(null);
    super.onPause();
  }
  
  /**
   * Removes the active activity reference and calla it's super method.
   * @see android.app.Activity#onDestroy()
   */
  @Override
  public void onDestroy ()
  {
    setActiveActivity(null);
    super.onDestroy();
  }
  
  
  /**
   * Forward enter animation.
   */
  protected int FORWARD_ENTER_ANIM  = -1;
  
  /**
   * Forward exit animation.
   */
  protected int FORWARD_EXIT_ANIM   = -1;
  
  
  /**
   * Backward enter animation.
   */
  protected int BACKWARD_ENTER_ANIM = -1;
  
  /**
   * Backward exit animation.
   */
  protected int BACKWARD_EXIT_ANIM  = -1;
  
  /**
   * Overrides pending transition between activities.
   * @param enterAnim    The enter animation defined for the new activity.
   * @param exitAnim     The exit animation defined for the old activity.
   */
  public void overrideTransition (final int enterAnim, final int exitAnim)
  {
    super.overridePendingTransition(enterAnim, exitAnim);
  }
  
  /**
   * Starts a new activity. Can use animations if wanted.
   * @param intent        Android Intent specifying the activity (class) to start.
   * @param transition    Flags if the transitions should be overridden.
   */
  public void startActivity (Intent intent, boolean transition)
  {
    super.startActivity(intent);
    if (transition)
    {
      
      if(FORWARD_ENTER_ANIM != -1 || FORWARD_EXIT_ANIM != -1)
      {
        overrideTransition(FORWARD_ENTER_ANIM, FORWARD_EXIT_ANIM);
      }
      
    }
  }
  
  /**
   * Starts a new actovoty overridding the pending transition.
   * @param intent    The Activity Intent.
   * @see #startActivity(Intent, boolean)
   */
  public void startActivity (Intent intent)
  {
    startActivity(intent, true);
  }
  
  /**
   * Finishes the activity lifecycle.
   * @param transition    Flags if it overrides the pending transition.
   */
  public void finish (boolean transition)
  {
    super.finish();
    if (transition)
    {
      
      if(BACKWARD_ENTER_ANIM != -1 || BACKWARD_EXIT_ANIM != -1)
      {
        overrideTransition(BACKWARD_ENTER_ANIM, BACKWARD_EXIT_ANIM);
      }
      
    }
  }
  
  /**
   * Finishes the activity lifecycle overriding the pending transition.
   * @see #finish(boolean)
   */
  public void finish ()
  {
    finish(true);
  }
  
  /**
   * Returns the application Resources instance.
   * @return The application resources.
   */
  public Resources res ()
  {
    return getResources();
  }
  
  /**
   * Gets the resource string with the given ID.
   * @param id    The resource ID.
   * @return The string value.
   */
  public String string (int id)
  {
    return res().getString(id);
  }
  
  /**
   * Gets the resource color with the given ID.
   * @param id    The resource ID.
   * @return The color value.
   */
  public int color (int id)
  {
    return res().getColor(id);
  }
  
  /**
   * Shows a toast message on the main UI thread.
   * @param message     The message to show.
   * @param duration    The duration.
   */
  public void toastMessage (final String message, final int duration)
  {
    runOnUiThread(new Runnable ()
    {
      @Override
      public void run ()
      {
        Toast.makeText(getActiveActivity(), message, duration).show();
      }
    });
  }
  
  /**
   * Shows a toast message with long duration.
   * @param message    The message to show.
   * @see #toastMessage(String, int)
   */
  public void toastMessage (final String message)
  {
    toastMessage(message, Toast.LENGTH_LONG);
  }
  
}




Java Source Code List

git.egatuts.android.FileUtils.EgaCursorLoader.java
git.egatuts.android.FileUtils.EgaFileSystemBase.java
git.egatuts.android.FileUtils.EgaFileSystem.java
git.egatuts.android.FileUtils.EgaStorageUtils.java
git.egatuts.android.fragment.EgaFragmentActivityBase.java
git.egatuts.android.fragment.EgaFragmentActivity.java
git.egatuts.android.utils.EgaActivityManager.java
git.egatuts.exifeditor.MainActivity.java