public abstract class

SCBaseController

extends Object
implements View.OnAttachStateChangeListener IActivityResultListener IController<T extends IViewHolder>
java.lang.Object
   ↳ com.c2call.sdk.pub.gui.core.controller.SCBaseController<T extends com.c2call.sdk.pub.gui.core.controller.IViewHolder>
Known Direct Subclasses
Known Indirect Subclasses

Class Overview

This is one of the central classes within the C2Call SDK. Every Controller has to be derived from this class in order to work properly together with the other parts of the SDK.

Summary

Public Constructors
SCBaseController(View view, SCViewDescription viewDescription)
Instantiates a new SCBaseController.
SCBaseController(View view, SCViewDescription viewDescription, IControllerRequestListener requestListener)
Instantiates a new SCBaseController.
Public Methods
static boolean bindCheckChangedListener(CompoundButton v, CompoundButton.OnCheckedChangeListener listener)
Binds an OnCheckedChangeListener to a given view if neither is null.
static boolean bindClickListener(View v, View.OnClickListener listener)
Binds an OnClickListener to a given view if neither is null.
static boolean bindEditActionListener(TextView v, TextView.OnEditorActionListener listener)
Binds an OnEditorActionListener to a given view if neither is null.
static boolean bindFocusChangeListener(View v, View.OnFocusChangeListener listener)
Binds an OnFocusChangeListener to a given view if neither is null.
static boolean bindItemClickListener(ListView v, AdapterView.OnItemClickListener listener)
Binds an AdapterView.OnItemClickListener to a given view if neither is null.
static boolean bindLongClickListener(View v, View.OnLongClickListener listener)
Binds an OnLongClickListener to a given view if neither is null.
static boolean bindRecyclerListener(ListView v, AbsListView.RecyclerListener listener)
Binds an AdapterView.RecyclerListener to a given view if neither is null.
static boolean bindTextWacther(TextView v, TextWatcher watcher)
Binds an TextWatcher to a given view if neither is null.
static boolean bindTouchListener(View v, View.OnTouchListener listener)
Binds an OnTouchListener to a given view if neither is null.
synchronized void fireEvent(SCBaseControllerEvent event)
Fires an event to the IControllerRequestListener of this this controller, if any.
Activity getContext()
Activity getContext(boolean throwIfNull)
Gets the context this controller was cretaed in and will throws an Exception if the context was not correctly initialized and throwIfNull is true
Fragment getFragment()
Handler getHandler()
static int getId(View v)
Convenient method to get the resource ID of a view, if that is not null
IControllerRequestListener getRequestListener()
SCActivityResultDispatcher getResultDispatcher()
Gets the SCActivityResultDispatcher of this controller.
static String getText(TextView v)
Convenient method to get the text of a TextView if that is not null.
View getView()
T getViewHolder()
boolean handleMustBeOnline()
Checks if the user is currently online and displays a little Toast if not
static boolean isChecked(CompoundButton v)
Convenient method to check if a CompoundButton is not null and checked
static boolean isVisibile(View v)
Convenient method to check if a view is not null and visbile
void onActivityResult(int requestCode, int resultCode, Intent data)
See onActivityResult() for further details
boolean onBackPressed()
Notify the controller that the back button was pressed
boolean onConfigurationChanged(Configuration newConfig)
Notifies the controller about configuration changes.
void onCreate(Activity context, SCActivityResultDispatcher resultDispatcher)
This should be called when your Activity is created.
final void onCreate(Fragment fragment, SCActivityResultDispatcher resultDispatcher)
This should be called when your Fragment is created, if any.
synchronized void onDestroy()
Notifies the controller that tha surrounding activity will be destroyed.
void onPause()
Notifies the controller that tha surrounding activity has paused
void onPostCreate()
Called within onCreate(Activity, SCActivityResultDispatcher) but after all other initialization is done.
void onResume()
Notifies the controller that tha surrounding activity is resumed.
void onStart()
Notifies the controller that tha surrounding activity has started.
void onStop()
Notifies the controller that tha surrounding activity has stopped.
void onViewAttachedToWindow(View v)
void onViewDetachedFromWindow(View v)
static void requestFocus(View v)
Convenient method to request the focus a given view, if that is not null.
void reset()
Resets the controller
static void setAdapter(ListView v, ListAdapter adapter)
Convenient method to set the adapter of a ListView if that is not null
static void setChecked(CompoundButton v, boolean checked)
Conveinient method to sets the check state of a CompoundButton, if that is not null.
static void setEnabled(View v, boolean value)
Convenient method to enables/disables a given view, if that is not null.
static void setError(TextView v, String error)
Sets an input error for a given view, if that is not null
static void setImageBitmap(ImageView v, Bitmap bitmap)
Convenient method to set image bitmap of an ImageView, if that is not null.
static void setImageResource(ImageView v, int res)
Convenient method to set image resource of an ImageView, if that is not null.
static void setProgress(ProgressBar v, int progress)
Convenient method to set the progress of a given ProgressBar, if that is not null
void setRequestListener(IControllerRequestListener listener)
Sets the request listener for this controller
static void setText(TextView v, CharSequence s)
Convenient method to set the text of TextView, if that is not null.
static void setVisibility(View v, boolean isVisible)
Convenient method to set the visibilite of a view, if that is not null.
static void setVisibility(View v, int visibility)
Convenient method to set the visibilite of a view, if that is not null.
void showProgressDialog(boolean show)
Show a simple progress dialog for background tasks.
void startActivityForResult(Intent intent, int requestCode)
Starts an activity for result.
Protected Methods
void finish()
Calls finish(long) with delay 0
synchronized void finish(long delayMillis)
Fires a SCFinishEvent with a given delay.
SCViewDescription getViewDescription()
abstract void onBindViewHolder(T vh)
abstract T onCreateViewHolder(View v, SCViewDescription vd)
[Expand]
Inherited Methods
From class java.lang.Object
From interface android.view.View.OnAttachStateChangeListener
From interface com.c2call.sdk.pub.gui.core.common.IActivityResultListener
From interface com.c2call.sdk.pub.gui.core.controller.IController

Public Constructors

public SCBaseController (View view, SCViewDescription viewDescription)

Instantiates a new SCBaseController.

Parameters
view the view that this Controller will take control of
viewDescription the view description that maps the various view items within view to known keys.

public SCBaseController (View view, SCViewDescription viewDescription, IControllerRequestListener requestListener)

Instantiates a new SCBaseController.

Parameters
view view the view that this Controller will take control of
viewDescription viewDescription the view description that maps the various view items within view to known keys.
requestListener a listener that listens for controller events

Public Methods

public static boolean bindCheckChangedListener (CompoundButton v, CompoundButton.OnCheckedChangeListener listener)

Binds an OnCheckedChangeListener to a given view if neither is null.

Parameters
v the view to set the OnCheckedChangeListener for
listener the listener to set
Returns
  • whether the listener was set.

public static boolean bindClickListener (View v, View.OnClickListener listener)

Binds an OnClickListener to a given view if neither is null.

Parameters
v the view to set the OnClickListener for
listener the listener to set
Returns
  • whether the listener was set.

public static boolean bindEditActionListener (TextView v, TextView.OnEditorActionListener listener)

Binds an OnEditorActionListener to a given view if neither is null.

Parameters
v the view to set the OnEditorActionListener for
listener the listener to set
Returns
  • whether the listener was set.

public static boolean bindFocusChangeListener (View v, View.OnFocusChangeListener listener)

Binds an OnFocusChangeListener to a given view if neither is null.

Parameters
v the view to set the OnFocusChangeListener for
listener the listener to set
Returns
  • whether the listener was set.

public static boolean bindItemClickListener (ListView v, AdapterView.OnItemClickListener listener)

Binds an AdapterView.OnItemClickListener to a given view if neither is null.

Parameters
v the view to set the OnItemClickListener for
listener the listener to set
Returns
  • whether the listener was set.

public static boolean bindLongClickListener (View v, View.OnLongClickListener listener)

Binds an OnLongClickListener to a given view if neither is null.

Parameters
v the view to set the OnLongClickListener for
listener the listener to set
Returns
  • whether the listener was set.

public static boolean bindRecyclerListener (ListView v, AbsListView.RecyclerListener listener)

Binds an AdapterView.RecyclerListener to a given view if neither is null.

Parameters
v the view to set the RecyclerListener for
listener the listener to set
Returns
  • whether the listener was set.

public static boolean bindTextWacther (TextView v, TextWatcher watcher)

Binds an TextWatcher to a given view if neither is null.

Parameters
v the view to set the TextWatcher for
watcher the watcher to set
Returns
  • whether the watcher was set.

public static boolean bindTouchListener (View v, View.OnTouchListener listener)

Binds an OnTouchListener to a given view if neither is null.

Parameters
v the view to set the OnTouchListener for
listener the listener to set
Returns
  • whether the listener was set.

public synchronized void fireEvent (SCBaseControllerEvent event)

Fires an event to the IControllerRequestListener of this this controller, if any.

Parameters
event the event to be fired

public Activity getContext ()

public Activity getContext (boolean throwIfNull)

Gets the context this controller was cretaed in and will throws an Exception if the context was not correctly initialized and throwIfNull is true

Returns
  • the context this controller was created in.

public Fragment getFragment ()

public Handler getHandler ()

public static int getId (View v)

Convenient method to get the resource ID of a view, if that is not null

Parameters
v the view to get thet ID of
Returns
  • the ID of the view.

public IControllerRequestListener getRequestListener ()

public SCActivityResultDispatcher getResultDispatcher ()

Gets the SCActivityResultDispatcher of this controller. This dispatcher is used to forward activity results to sub-controllers

Returns
  • the result dispatcher of this Controller

public static String getText (TextView v)

Convenient method to get the text of a TextView if that is not null.

Parameters
v the TextView to get the text of
Returns
  • the if the specified TextView is not null then this method return the text of that view, otherwise null.

public View getView ()

Returns
  • the view that this Controller controls

public T getViewHolder ()

public boolean handleMustBeOnline ()

Checks if the user is currently online and displays a little Toast if not

Returns
  • true if user is offline, false otherwise

public static boolean isChecked (CompoundButton v)

Convenient method to check if a CompoundButton is not null and checked

Parameters
v the button to check
Returns
  • true if the button is not null and checked

public static boolean isVisibile (View v)

Convenient method to check if a view is not null and visbile

Parameters
v the view to check
Returns
  • true if the view is not null and has the visibility View.VISIBLE, false otherwise

public void onActivityResult (int requestCode, int resultCode, Intent data)

See onActivityResult() for further details

public boolean onBackPressed ()

Notify the controller that the back button was pressed

Returns
  • true if this event was consumed.

public boolean onConfigurationChanged (Configuration newConfig)

Notifies the controller about configuration changes. See onConfigurationChanged(...) for more details.

Returns
  • whether this event was consumed or not.

public void onCreate (Activity context, SCActivityResultDispatcher resultDispatcher)

This should be called when your Activity is created. Typically in onCreate(...) of the surrounding Activiy.

Parameters
context the surrounding activity
resultDispatcher a result dispatcher that is used by the controller

public final void onCreate (Fragment fragment, SCActivityResultDispatcher resultDispatcher)

This should be called when your Fragment is created, if any. Typically in onActivityCreated(...) of the surrounding Fragmeent.

Parameters
fragment the surrounding fragment
resultDispatcher a result dispatcher that is used by the controller

public synchronized void onDestroy ()

Notifies the controller that tha surrounding activity will be destroyed.

public void onPause ()

Notifies the controller that tha surrounding activity has paused

public void onPostCreate ()

Called within onCreate(Activity, SCActivityResultDispatcher) but after all other initialization is done.

public void onResume ()

Notifies the controller that tha surrounding activity is resumed.

public void onStart ()

Notifies the controller that tha surrounding activity has started.

public void onStop ()

Notifies the controller that tha surrounding activity has stopped.

public void onViewAttachedToWindow (View v)

public void onViewDetachedFromWindow (View v)

public static void requestFocus (View v)

Convenient method to request the focus a given view, if that is not null.

Parameters
v the view to request focus for

public void reset ()

Resets the controller

public static void setAdapter (ListView v, ListAdapter adapter)

Convenient method to set the adapter of a ListView if that is not null

Parameters
v the ListView to set the adapter for
adapter the adapter to be set.

public static void setChecked (CompoundButton v, boolean checked)

Conveinient method to sets the check state of a CompoundButton, if that is not null.

Parameters
v the button the change the check state for.
checked whether the button should be checked.

public static void setEnabled (View v, boolean value)

Convenient method to enables/disables a given view, if that is not null.

Parameters
v the view to enable/disable
value whether the view should be enabled

public static void setError (TextView v, String error)

Sets an input error for a given view, if that is not null

Parameters
v the view to set the error for.
error the error string to be stet

public static void setImageBitmap (ImageView v, Bitmap bitmap)

Convenient method to set image bitmap of an ImageView, if that is not null.

Parameters
v the ImageView to set the resource for.
bitmap the bitmap id to be set

public static void setImageResource (ImageView v, int res)

Convenient method to set image resource of an ImageView, if that is not null.

Parameters
v the ImageView to set the resource for.
res the resource id to be set

public static void setProgress (ProgressBar v, int progress)

Convenient method to set the progress of a given ProgressBar, if that is not null

Parameters
v the ProrgressBar to set the progress for
progress the progress to be set

public void setRequestListener (IControllerRequestListener listener)

Sets the request listener for this controller

public static void setText (TextView v, CharSequence s)

Convenient method to set the text of TextView, if that is not null.

Parameters
v the TextVie to set the text for
s the text to be set.

public static void setVisibility (View v, boolean isVisible)

Convenient method to set the visibilite of a view, if that is not null.

Parameters
v the view to set the visibility for
isVisible if true the Visibility will be set to View.VISIBLE, otherwise to View.GONE

public static void setVisibility (View v, int visibility)

Convenient method to set the visibilite of a view, if that is not null.

Parameters
v the view to set the visibility for
visibility the visibility to set

public void showProgressDialog (boolean show)

Show a simple progress dialog for background tasks.

Parameters
show whether to show or hide

public void startActivityForResult (Intent intent, int requestCode)

Starts an activity for result. By contract this should start the new activity from the fragment (if any) of this controller

Parameters
intent the intent to start.
requestCode the requst code that is passed to startActivityForResult(...)

Protected Methods

protected void finish ()

Calls finish(long) with delay 0

protected synchronized void finish (long delayMillis)

Fires a SCFinishEvent with a given delay.

Parameters
delayMillis the delay until the event will be fired, in milliseconds.

protected SCViewDescription getViewDescription ()

Returns
  • the ViewDescription that this controller uses for its view mapping

protected abstract void onBindViewHolder (T vh)

protected abstract T onCreateViewHolder (View v, SCViewDescription vd)