Back to project page AGOGCyberStat.
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.
package com.agog.cyberstat; //w w w . j a v a2s . c o m import com.agog.cyberstat.MyPrefs; import com.agog.cyberstat.R; import me.allenz.androidapplog.LogTextView; import me.allenz.androidapplog.Logger; import me.allenz.androidapplog.LoggerFactory; import android.app.Activity; import android.os.Bundle; import android.view.KeyEvent; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.Toast; /** * @author greg@agog.com * * Simple interface for JSON settings and control buttons. */ public class MainActivity extends Activity { private static final Logger logger = LoggerFactory.getLogger(); private LogTextView mLogView; private EditText mEditTextJSON; private Boolean mLogVisible = false; @Override protected void onDestroy() { hideLog(); LoggerFactory.unbindTextView(); super.onDestroy(); } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mLogView = LoggerFactory.createLogScrollView(this); LoggerFactory.bindTextView(mLogView); logger.debug("onCreate"); MyPrefs.init(this); Button btn = (Button) findViewById(R.id.buttonSave); btn.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { MyPrefs.putString("jsonsettings", mEditTextJSON.getText().toString()); // Commit the edits! MyPrefs.commit(); } }); btn = (Button) findViewById(R.id.ButtonWarm); btn.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { changeTemp(true); } }); btn = (Button) findViewById(R.id.ButtonCool); btn.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { changeTemp(false); } }); mEditTextJSON = (EditText) findViewById(R.id.editTextJSON); String str = MyPrefs.getString("jsonsettings",null); if(str != null) { mEditTextJSON.setText(str); } } @Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { hideLog(); return true; } return super.onKeyDown(keyCode, event); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); if (id == R.id.action_logview) { showLog(); return true; } return super.onOptionsItemSelected(item); } protected void changeTemp(Boolean warm) { CharSequence text = warm ? "Warm" : "Cool"; int duration = Toast.LENGTH_SHORT; Toast toast = Toast.makeText(this, text, duration); toast.show(); /* Default to sound normal alert for voice action */ Trigger tr = new Trigger(); tr.notify = true; tr.sound = true; tr.ringtone = null; String str = MyPrefs.getString("jsonsettings",null); JSONSettings jsonsettings = new JSONSettings(str); int temp = warm ? jsonsettings.getWarm() : jsonsettings.getCold(); String s = Integer.valueOf(temp).toString(); logger.debug("setTemp " + temp + " " + s); new MotisonNetTask(this).execute(jsonsettings.getEmail(), jsonsettings.getPassword(),tr,s,"Button"); } protected void showLog() { logger.debug("showLog"); if(!mLogVisible) { mLogView.addScrollView(this); mLogVisible = true; } } protected void hideLog() { if(mLogVisible) { mLogView.removeScrollView(this); mLogVisible = false; } } }