Android Open Source - AGOGCyberStat Log Text View






From Project

Back to project page AGOGCyberStat.

License

The source code is released under:

MIT License

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

package me.allenz.androidapplog;
/*from  w w w .j av  a  2 s  . c  o  m*/
import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.text.Editable;
import android.text.TextWatcher;
import android.text.method.ScrollingMovementMethod;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.ViewGroup.LayoutParams;
import android.widget.FrameLayout;
import android.widget.ScrollView;
import android.widget.TextView;

public class LogTextView extends TextView {
    ScrollView mParentScrollView;

    public LogTextView(final Context context){
        super(context);
        setAttributes();
    }

    public LogTextView(final Context context, final AttributeSet attrs){
        super(context, attrs);
    }

    public LogTextView(final Context context, final AttributeSet attrs, final int defStyle){
        super(context, attrs, defStyle);
    }
    
    public void setScrollView(ScrollView sv) {
      mParentScrollView = sv;
      mParentScrollView.addView(this);
    }
    
    public ScrollView getScrollView() {
      return(mParentScrollView);
    }

    public void addScrollView(final Activity activity) {
      final FrameLayout root = (FrameLayout) activity.getWindow().getDecorView().findViewById(android.R.id.content);

      root.addView(mParentScrollView);
      root.bringChildToFront(mParentScrollView);    
    }

    public void removeScrollView(final Activity activity) {
      final FrameLayout root = (FrameLayout) activity.getWindow().getDecorView().findViewById(android.R.id.content);

      root.removeView(mParentScrollView);
    }


    private void setAttributes() {
        setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
        setTextColor(Color.parseColor("#66000000"));
        setTextSize(TypedValue.COMPLEX_UNIT_SP, 10f);
        setGravity(Gravity.BOTTOM);
        setSingleLine(false);
        setBackgroundColor(Color.parseColor("#ffffffff"));
        setKeyListener(null);
        setMovementMethod(ScrollingMovementMethod.getInstance());
        addTextChangedListener(new TextWatcher(){

            @Override
            public void onTextChanged(final CharSequence s, final int start, final int before, final int count) {}

            @Override
            public void beforeTextChanged(final CharSequence s, final int start, final int count, final int after) {}

            @Override
            public void afterTextChanged(final Editable s) {
                if(getLayout() != null) {
                  if(mParentScrollView != null) {
                    mParentScrollView.fullScroll(ScrollView.FOCUS_DOWN);
                  }
                  else {
                    final int scrollAmount =
                        getLayout().getLineTop(getLineCount()) -
                            getHeight();
                    if (scrollAmount > 0) {
                        scrollTo(0, scrollAmount);
                    } else {
                        scrollTo(0, 0);
                    }
                  }
                }
            }
        });
    }

    @Override
    public boolean dispatchTouchEvent(final MotionEvent event) {
        return false;
    }

}




Java Source Code List

com.agog.cyberstat.BrR.java
com.agog.cyberstat.JSONSettings.java
com.agog.cyberstat.MainActivity.java
com.agog.cyberstat.MotisonNetTask.java
com.agog.cyberstat.MotisonXML.java
com.agog.cyberstat.MyPrefs.java
com.agog.cyberstat.NetR.java
com.agog.cyberstat.Trigger.java
me.allenz.androidapplog.AbstractAppender.java
me.allenz.androidapplog.AbstractLogger.java
me.allenz.androidapplog.AppenderSupportLogger.java
me.allenz.androidapplog.Appender.java
me.allenz.androidapplog.AsyncAppender.java
me.allenz.androidapplog.Configure.java
me.allenz.androidapplog.InternalLogger.java
me.allenz.androidapplog.LogCatAppender.java
me.allenz.androidapplog.LogEvent.java
me.allenz.androidapplog.LogLevel.java
me.allenz.androidapplog.LogTextView.java
me.allenz.androidapplog.LoggerConfig.java
me.allenz.androidapplog.LoggerFactory.java
me.allenz.androidapplog.Logger.java
me.allenz.androidapplog.PropertiesParser.java
me.allenz.androidapplog.ReflectUtils.java
me.allenz.androidapplog.Repository.java
me.allenz.androidapplog.RollingFileAppender.java
me.allenz.androidapplog.TextViewAppender.java