Android Open Source - nxt-remote-controller Base Activity






From Project

Back to project page nxt-remote-controller.

License

The source code is released under:

MIT License

If you think the Android project nxt-remote-controller 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 (c) 2014 EgaTuts & Esa Garca - All Rights Reserved                 *
 *                                                                                 *
 *  Open-source code licensed under the MIT License (the "License").               *
 *                                                                                 *
 *  Permission is hereby granted, free of charge, to any person obtaining a copy   *
 *  of this software and associated documentation files (the "Software"), to deal  *
 *  in the Software without restriction, including without limitation the rights   *
 *  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell      *
 *  copies of the Software, and to permit persons to whom the Software is          *
 *  furnished to do so, subject to the following conditions:                       *
 *                                                                                 *
 *  The above copyright notice and this permission notice shall be included in     *
 *  all copies or substantial portions of the Software.                            *
 *                                                                                 *
 *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR     *
 *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,       *
 *  FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE    *
 *  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER         *
 *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,  *
 *  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN      *
 *  THE SOFTWARE.                                                                  *
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
//from   www  .j  ava2  s.  c o  m
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 *  You can find the entire project at:                                                                                                                        *
 *                                                                                                                                                             *
 *    https://github.com/Egatuts/nxt-remote-controller                                                                                                         *
 *                                                                                                                                                             *
 *  And the corresponding file at:                                                                                                                             *
 *                                                                                                                                                             *
 *    https://github.com/Egatuts/nxt-remote-controller/blob/master/Android%20App/app/src/main/java/git/egatuts/nxtremotecontroller/activity/BaseActivity.java  *
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
package git.egatuts.nxtremotecontroller.activity;

import android.content.Context;
import android.content.Intent;
import android.content.res.Resources.Theme;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.widget.Toolbar;
import android.view.WindowManager;

import git.egatuts.nxtremotecontroller.GlobalUtils;
import git.egatuts.nxtremotecontroller.R;
import git.egatuts.nxtremotecontroller.bluetooth.BluetoothUtils;
import git.egatuts.nxtremotecontroller.preference.PreferencesUtils;
import git.egatuts.nxtremotecontroller.views.BaseIndeterminateProgressDialog;
import git.egatuts.nxtremotecontroller.views.LongIndeterminateProgressDialog;
import git.egatuts.nxtremotecontroller.views.ShortIndeterminateProgressDialog;

/*
 *  Most basic class to extend Activity (ActionBarActivity) classes.
 *  It can override the default theme to the one selected in the SharedPreferences.
 *  It can enable the Toolbar home button as "up".
 *  It can instantiates most used classes:
 *    BluetoothUtils
 *    FragmentManager
 *    GlobalUtils
 *    PreferencesUtils
 *      PreferencesUtils#Editor
 *  And creates the variable Toolbar (not instantiated).
 */
public abstract class BaseActivity extends ActionBarActivity {

  /*
   * Constants used, normally resources IDs and key names.
   */
  public static final String PREFERENCE_THEME_NAME = "preference_theme";
  public static final int PREFERENCE_THEME_VALUE = R.string.preference_value_theme;

  protected BluetoothUtils bluetoothUtils;
  protected FragmentManager fragmentManager;
  protected GlobalUtils globalUtils;
  protected PreferencesUtils preferencesUtils;
  protected PreferencesUtils.Editor preferencesEditor;
  protected Toolbar toolbar;
  protected BaseIndeterminateProgressDialog progressDialog;

  /*
   *  Some getters for the properties.
   */
  public BluetoothUtils getBluetoothUtils () {
    return this.bluetoothUtils;
  }

  public FragmentManager getBaseFragmentManager () {
    return this.fragmentManager;
  }

  public GlobalUtils getGlobalUtils () {
    return this.globalUtils;
  }

  public PreferencesUtils getPreferencesUtils () {
    return this.preferencesUtils;
  }

  public PreferencesUtils.Editor getPreferencesEditor () {
    return this.preferencesEditor;
  }

  public BaseIndeterminateProgressDialog getProgressDialog () {
    return this.progressDialog;
  }

  /*
   *  Sets, shows and enables "up" the home button on the Toolbar (ActionBar/AppBar).
   */
  protected void setSupportToolbar () {
    super.setSupportActionBar(toolbar);
    super.getSupportActionBar().setHomeButtonEnabled(true);
    super.getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    super.getSupportActionBar().setDisplayShowHomeEnabled(true);
  }

  /*
   *  Getter and setter for the active Theme.
   */
  protected Theme getActiveTheme () {
    return globalUtils.getActiveTheme();
  }

  protected void setActiveTheme (String name) {
    globalUtils.setActiveTheme(name);
  }

  /*
   *  Getter for the Theme saved in the default SharedPreferences.
   */
  protected String getPreferenceTheme () {
    String defaultValue = globalUtils.getStringResource(BaseActivity.PREFERENCE_THEME_VALUE);
    return preferencesEditor.getString(BaseActivity.PREFERENCE_THEME_NAME, defaultValue);
  }

  /*
   *  Instantiates the objects defined above.
   */
  @Override
  public void onCreate (Bundle savedInstanceState) {

    /*
     *  Super method. MUST BE CALLED.
     */
    super.onCreate(savedInstanceState);

    /*
     *  Variables instantiation.
     */
    this.bluetoothUtils = new BluetoothUtils();
    this.fragmentManager = super.getSupportFragmentManager();
    this.globalUtils = new GlobalUtils(this);
    this.preferencesUtils = new PreferencesUtils(this);
    this.preferencesUtils.privateMode();
    this.preferencesEditor = preferencesUtils.getEditor();
    this.preferencesEditor.edit();

    /*
     *  If version is equal or greater than Android Lollipop (API 21) enable FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS
     *  to change the navigation and notification bar colors.
     */
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
      this.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
    }
  }

  /*
   *  Overridden method Activity#startActivity() and variants to use ActivityPendingTransition interface.
   */
  private void startNewActivity (Intent intent, ActivityPendingTransition transitionInterface) {
    ActivityPendingTransition transition = transitionInterface != null ? transitionInterface : new DefaultActivityPendingTransition();
    int[] transitions = transition.onForward(intent);
    super.startActivity(intent);
    if (transitions.length == 2)
      super.overridePendingTransition(transitions[0], transitions[1]);
  }

  public void startActivity (Context context, Class<?> defClass, ActivityPendingTransition transitionInterface) {
    this.startNewActivity(new Intent(context, defClass), transitionInterface);
  }

  public void startActivity (Context context, Class<?> defClass) {
    this.startActivity(context, defClass, null);
  }

  public void startActivity (Intent intent, ActivityPendingTransition interfaceTransition) {
    this.startNewActivity(intent, interfaceTransition);
  }

  /*
   *  Returns a short progress dialog (doFirstAnimation = false and setCancelable = false)
   */
  public BaseIndeterminateProgressDialog getShortProgressDialog () {
    if ( !(this.progressDialog instanceof ShortIndeterminateProgressDialog) ) {
      this.progressDialog = new ShortIndeterminateProgressDialog(this);
    }
    return this.progressDialog;
  }

  /*
   *  Returns a long progress dialog (doFirstAnimation = true and setCancelable = true)
   */
  public BaseIndeterminateProgressDialog getLongProgressDialog () {
    if ( !(this.progressDialog instanceof LongIndeterminateProgressDialog) ) {
      this.progressDialog = new LongIndeterminateProgressDialog(this);
    }
    return this.progressDialog;
  }

  @Override
  public void startActivity (Intent intent) {
    this.startNewActivity(intent, null);
  }

  /*
   *  Overridden method Activity#finish() and variants to use ActivityPendingTransition interface.
   */
  private void finishActivity (ActivityPendingTransition transitionInterface) {
    ActivityPendingTransition transition = transitionInterface != null ? transitionInterface : new DefaultActivityPendingTransition();
    int[] transitions = transition.onBackward();
    super.finish();
    if (transitions.length == 2)
      super.overridePendingTransition(transitions[0], transitions[1]);
  }

  public void finish (ActivityPendingTransition transitionInterface) {
    this.finishActivity(transitionInterface);
  }

  @Override
  public void finish () {
    this.finishActivity(null);
  }

}




Java Source Code List

.OldPadControllerFragment.java
com.andexert.library.ApplicationTest.java
com.andexert.library.RippleView.java
com.andexert.rippleeffect.ApplicationTest.java
com.andexert.rippleeffect.CustomAdapter.java
com.andexert.rippleeffect.MainActivity.java
com.andexert.rippleeffect.OnTapListener.java
com.gc.materialdesign.utils.Utils.java
com.gc.materialdesign.views.ButtonFlat.java
com.gc.materialdesign.views.ButtonFloatSmall.java
com.gc.materialdesign.views.ButtonFloat.java
com.gc.materialdesign.views.ButtonIcon.java
com.gc.materialdesign.views.ButtonRectangle.java
com.gc.materialdesign.views.Button.java
com.gc.materialdesign.views.Card.java
com.gc.materialdesign.views.CheckBox.java
com.gc.materialdesign.views.CustomView.java
com.gc.materialdesign.views.LayoutRipple.java
com.gc.materialdesign.views.ProgressBarCircularIndeterminate.java
com.gc.materialdesign.views.ProgressBarDeterminate.java
com.gc.materialdesign.views.ProgressBarIndeterminateDeterminate.java
com.gc.materialdesign.views.ProgressBarIndeterminate.java
com.gc.materialdesign.views.RippleView.java
com.gc.materialdesign.views.ScrollView.java
com.gc.materialdesign.views.Slider.java
com.gc.materialdesign.views.Switch.java
com.gc.materialdesign.widgets.ColorSelector.java
com.gc.materialdesign.widgets.Dialog.java
com.gc.materialdesign.widgets.SnackBar.java
git.egatuts.nxtremotecontroller.ApplicationTest.java
git.egatuts.nxtremotecontroller.GlobalUtils.java
git.egatuts.nxtremotecontroller.activity.ActivityPendingTransition.java
git.egatuts.nxtremotecontroller.activity.BaseActivity.java
git.egatuts.nxtremotecontroller.activity.ControllerActivity.java
git.egatuts.nxtremotecontroller.activity.DefaultActivityPendingTransition.java
git.egatuts.nxtremotecontroller.activity.MainActivity.java
git.egatuts.nxtremotecontroller.activity.SettingsActivity.java
git.egatuts.nxtremotecontroller.bluetooth.BluetoothConstants.java
git.egatuts.nxtremotecontroller.bluetooth.BluetoothUtils.java
git.egatuts.nxtremotecontroller.bluetooth.NXTConnector.java
git.egatuts.nxtremotecontroller.device.PairedDeviceAdapter.java
git.egatuts.nxtremotecontroller.device.PairedDeviceItemClickListener.java
git.egatuts.nxtremotecontroller.device.PairedDeviceViewHolder.java
git.egatuts.nxtremotecontroller.device.PairedDevice.java
git.egatuts.nxtremotecontroller.exception.SocketCreationException.java
git.egatuts.nxtremotecontroller.fragment.ActivityBaseFragment.java
git.egatuts.nxtremotecontroller.fragment.BaseFragment.java
git.egatuts.nxtremotecontroller.fragment.BluetoothFragment.java
git.egatuts.nxtremotecontroller.fragment.ControllerBaseFragment.java
git.egatuts.nxtremotecontroller.fragment.DefaultFragmentPendingTransition.java
git.egatuts.nxtremotecontroller.fragment.FragmentPendingTransition.java
git.egatuts.nxtremotecontroller.fragment.HomeFragment.java
git.egatuts.nxtremotecontroller.fragment.LocalControllerFragment.java
git.egatuts.nxtremotecontroller.fragment.OnlineControllerFragment.java
git.egatuts.nxtremotecontroller.fragment.ScanFragment.java
git.egatuts.nxtremotecontroller.fragment.SettingsFragment.java
git.egatuts.nxtremotecontroller.listener.AnimationEndListener.java
git.egatuts.nxtremotecontroller.listener.AppKillerListener.java
git.egatuts.nxtremotecontroller.listener.BaseListener.java
git.egatuts.nxtremotecontroller.listener.BluetoothDiscoveryListener.java
git.egatuts.nxtremotecontroller.listener.BluetoothEnableListener.java
git.egatuts.nxtremotecontroller.listener.BluetoothPairingListener.java
git.egatuts.nxtremotecontroller.navigation.DrawerItemViewHolder.java
git.egatuts.nxtremotecontroller.navigation.DrawerItem.java
git.egatuts.nxtremotecontroller.navigation.NavigationDrawerAdapter.java
git.egatuts.nxtremotecontroller.navigation.NavigationDrawerCallback.java
git.egatuts.nxtremotecontroller.navigation.NavigationDrawerFragment.java
git.egatuts.nxtremotecontroller.preference.PreferencesUtils.java
git.egatuts.nxtremotecontroller.receiver.AppKillerReceiver.java
git.egatuts.nxtremotecontroller.receiver.BaseReceiver.java
git.egatuts.nxtremotecontroller.receiver.BluetoothDiscoveryReceiver.java
git.egatuts.nxtremotecontroller.receiver.BluetoothEnableReceiver.java
git.egatuts.nxtremotecontroller.receiver.BluetoothPairingReceiver.java
git.egatuts.nxtremotecontroller.thread.BaseThread.java
git.egatuts.nxtremotecontroller.thread.ConnectThread.java
git.egatuts.nxtremotecontroller.thread.ConnectedThread.java
git.egatuts.nxtremotecontroller.views.BaseIndeterminateProgressDialog.java
git.egatuts.nxtremotecontroller.views.BaseProgressDialog.java
git.egatuts.nxtremotecontroller.views.JoystickView.java
git.egatuts.nxtremotecontroller.views.LongIndeterminateProgressDialog.java
git.egatuts.nxtremotecontroller.views.ShortIndeterminateProgressDialog.java