Android Open Source - iLitIt_Android Settings Fragment






From Project

Back to project page iLitIt_Android.

License

The source code is released under:

GNU General Public License

If you think the Android project iLitIt_Android 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 de.unifreiburg.es.iLitIt;
//from w  ww . j  av a 2s .  co  m
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

import java.util.Date;

/**
 * Created by phil on 11/18/14.
 */
public class SettingsFragment extends Fragment implements MainActivity.MyFragment {
    private ObservableLinkedList<CigaretteEvent> mModel;
    private LighterBluetoothService mServiceconnection;
    private Button mClear;
    private TextView mMacAddr;
    private View mRootView = null;
    private TextView mBatVolt = null;

    private DelayedObserver rUpdateFields = new DelayedObserver(10, new Runnable() {
        @Override
        public void run() {
            if (mRootView==null || mServiceconnection==null)
                return; // not fully initialised

            mBatVolt.setText(String.format("%.2fV%s",
                    mServiceconnection.get_bat_voltage(),
                    mServiceconnection.is_bat_empty() ? "(empty)" : ""));

            mMacAddr.setText(mServiceconnection.get_mac_addr());
        }
    });

    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        mRootView = inflater.inflate(R.layout.settings_fragment, container, false);

        mClear = (Button) mRootView.findViewById(R.id.cleardatabutton);
        mClear.setOnClickListener(new View.OnClickListener() {
                @Override
            public void onClick(View v) {
                Log.e(MainActivity.USER_INTERACTION_TAG, "cleared all cigarettes from Settings");
                if (mModel!=null) mModel.clear();
            }
        });

        mMacAddr = (TextView) mRootView.findViewById(R.id.macaddr);
        mMacAddr.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mServiceconnection!=null) mServiceconnection.clear_mac_addr();
                }
        });
        mBatVolt = (TextView) mRootView.findViewById(R.id.batteryVoltage);

        if (mServiceconnection!=null) rUpdateFields.mAction.run();
        return mRootView;
    }

    @Override
    public void setModel(ObservableLinkedList<CigaretteEvent> list) {
        if (mModel!=null) mModel.unregister(rUpdateFields);
        mModel = list;
        mModel.register(rUpdateFields);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        if (mModel!=null) mModel.unregister(rUpdateFields);
    }

    @Override
    public void setBluetoothService(LighterBluetoothService service) {
        mServiceconnection = service;
        rUpdateFields.mAction.run();
    }

    @Override
    public void setUserVisibleHint(boolean isVisibleToUser) {
        super.setUserVisibleHint(isVisibleToUser);
        //rUpdateFields.mAction.run();
    }
}




Java Source Code List

de.unifreiburg.es.iLitIt.CigAnnotationWriter.java
de.unifreiburg.es.iLitIt.CigIntentBroadcaster.java
de.unifreiburg.es.iLitIt.CigaretteEvent.java
de.unifreiburg.es.iLitIt.DelayedObserver.java
de.unifreiburg.es.iLitIt.HeatMapFragment.java
de.unifreiburg.es.iLitIt.HomescreenFragment.java
de.unifreiburg.es.iLitIt.JournalFragment.java
de.unifreiburg.es.iLitIt.LighterBluetoothService.java
de.unifreiburg.es.iLitIt.MainActivity.java
de.unifreiburg.es.iLitIt.ObservableLinkedList.java
de.unifreiburg.es.iLitIt.SettingsFragment.java
de.unifreiburg.es.iLitIt.StatsHelper.java