Skip to content

Instantly share code, notes, and snippets.

@Devofure
Created September 16, 2014 18:48
Show Gist options
  • Save Devofure/0e33db36668ca9f629e5 to your computer and use it in GitHub Desktop.
Save Devofure/0e33db36668ca9f629e5 to your computer and use it in GitHub Desktop.
package se.project.generic.androidbaseapp;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.MenuItem;
import android.view.Window;
import android.widget.TextView;
import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.Background;
import org.androidannotations.annotations.Click;
import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.InstanceState;
import org.androidannotations.annotations.LongClick;
import org.androidannotations.annotations.OnActivityResult;
import org.androidannotations.annotations.OptionsItem;
import org.androidannotations.annotations.OptionsMenu;
import org.androidannotations.annotations.OptionsMenuItem;
import org.androidannotations.annotations.Trace;
import org.androidannotations.annotations.UiThread;
import org.androidannotations.annotations.ViewById;
import org.androidannotations.annotations.WindowFeature;
import java.util.Date;
import quickutils.core.QuickUtils;
@WindowFeature({Window.FEATURE_NO_TITLE, Window.FEATURE_INDETERMINATE_PROGRESS})
@EActivity(R.layout.activity_main)
@OptionsMenu(R.menu.main)
public class QuickMainActivity extends Activity {
private static final int REQUEST_CODE = 23423;
private final String TAG = "QuickMainActivity";
/*marks methods that receives menu selection events*/
@OptionsMenuItem
protected MenuItem action_settings;
//@NonConfigurationInstance
//Bitmap someBitmap;
@ViewById
protected TextView helloWorldEditText;
@InstanceState
protected String dataString;
/**
* **************************************************************************************
* --------------------------------- Android Life Cycle -------------------------------------
* **************************************************************************************
*/
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
dataString = "this will be save on the onSaveInstanceState";
}
/*The @ViewById annotation indicates that an activity field should be bound with the
corresponding View component from the layout. It is the same as calling the findViewById()
method.*/
@AfterViews
protected void initViews() {
helloWorldEditText.setText("Date: " + new Date());
}
/*Called when the activity is becoming visible to the user. Followed by onResume() if the
activity comes to the foreground, or onStop() if it becomes hidden.*/
@Override
public void onStart() {
super.onStart();
Log.d(TAG, "onStart()");
}
/*Called after your activity has been stopped, prior to it being started again. Always followed
by onStart()*/
@Override
public void onRestart() {
super.onRestart();
Log.d(TAG, "onRestart(");
}
/*Called when the activity will start interacting with the user. At this point your activity is
at the top of the activity stack, with user input going to it. Always followed by onPause().*/
@Override
public void onResume() {
super.onResume();
Log.d(TAG, "onResume()...");
}
/*Called as part of the activity lifecycle when an activity is going into the background, but
has not (yet) been killed. The counterpart to onResume(). When activity B is launched in front
of activity A, this callback will be invoked on A. B will not be created until A's onPause()
returns, so be sure to not do anything lengthy here.*/
@Override
public void onPause() {
super.onPause();
Log.d(TAG, "onPause()...");
}
/*Called when you are no longer visible to the user. You will next receive either onRestart(),
onDestroy(), or nothing, depending on later user activity.
Note that this method may never be called, in low memory situations where the system does not
have enough memory to keep your activity's process running after its onPause() method is
called.*/
@Override
public void onStop() {
super.onStop();
Log.d(TAG, "onStop()...");
}
/*The final call you receive before your activity is destroyed. This can happen either because
the activity is finishing (someone called finish() on it, or because the system is temporarily
destroying this instance of the activity to save space. You can distinguish between these two
scenarios with the isFinishing() method.*/
@Override
public void onDestroy() {
super.onDestroy();
Log.d(TAG, "onDestroy()...");
}
/*The @Trace annotation allows you to trace the execution of a method by writing log entries.*/
@Trace(tag = "CustomTag", level = Log.WARN)
protected void doWork() {
// ... Do Work ...
}
/*This annotation is intended to be used on methods to receive results from an activity started
with android.app.Activity.startActivityForResult(Intent, int)*/
@OnActivityResult(REQUEST_CODE)
protected void onResult(int resultCode, Intent data) {
}
@OptionsItem
protected void action_settings() {
// You can specify the ID in the annotation, or use the naming convention
}
/**
* **************************************************************************************
* --------------------------------- Android Listener -------------------------------------
* **************************************************************************************
*/
//@Touch
@LongClick
@Click
protected void button() {
Log.e("AEFESF", "fsefesf");
QuickUtils.system.navigateToActivity(this, MainActivity.class);
}
/**
* **************************************************************************************
* ---------------------------------- Android Threads --------------------------------------
* **************************************************************************************
*/
@Trace(tag = TAG + " Background", level = Log.WARN)
@Background
protected void doSomethingInBackground() {
// do something
updateUI("result");
}
// Notice that we manipulate the activity ref only from the UI thread
@UiThread
protected void updateUI(String result) {
Log.e("ssdvs", result);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment