package nl.rhinofly.twelvetalk;
import android.app.Application;
import android.content.SharedPreferences;
import android.content.SharedPreferences.*;
import android.preference.PreferenceManager;
import android.text.Layout;
import android.text.method.ScrollingMovementMethod;
import android.util.Log;
import android.widget.TextView;
import android.view.View;
import android.widget.TextView;
public class TTApplication extends Application implements OnSharedPreferenceChangeListener{
private SharedPreferences prefs;
private View view;
private TextView logView = null;
static final String TAG = TTApplication.class.getSimpleName(); ;
@Override
public void onCreate() { //
super.onCreate();
this.prefs = PreferenceManager.getDefaultSharedPreferences(this);
this.getPrefs().registerOnSharedPreferenceChangeListener(this);
}
@Override
public void onTerminate() { //
super.onTerminate();
Log.i(TAG, "onTerminated"); }
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
String key) {
// TODO Auto-generated method stub
}
public SharedPreferences getPrefs() {
return prefs;
}
public void log(String message){
this.doLog(TAG,message);
}
public void log(String customTAG, String message){
this.doLog(customTAG, message);
}
private void doLog(String TAG, String message){
if (this.getLogView() != null){
this.appendTextAndScroll(message);
}
Log.i(TAG, message);
}
public TextView getLogView() {
return logView;
}
public void setLogView(TextView logView) {
this.logView = logView;
this.getLogView().setMovementMethod(new ScrollingMovementMethod());
}
private void appendTextAndScroll(String text)
{
if(logView != null){
logView.append(text + "\n");
final Layout layout = logView.getLayout();
if(layout != null){
int scrollDelta = layout.getLineBottom(logView.getLineCount() - 1)
- logView.getScrollY() - logView.getHeight();
if(scrollDelta > 0)
logView.scrollBy(0, scrollDelta);
}
}
}
}