Skip to content

Instantly share code, notes, and snippets.

View andrea-liu87's full-sized avatar
Need more coffee to stay motivated

Andrea andrea-liu87

Need more coffee to stay motivated
View GitHub Profile
@andrea-liu87
andrea-liu87 / SampleService.java
Created April 3, 2020 17:20 — forked from hiq-larryschiefer/SampleService.java
Example of an Android Service using a periodic Runnable on a simple background thread
/*
* Example code to help with Stack Overflow post:
* http://stackoverflow.com/questions/35843374/android-pausing-service-thread-asynctask-using-a-handler-with-postdelayed-for
*
* THIS IS JUST SAMPLE CODE, HAS NOT BEEN BUILT OR TESTED.
*/
public class MyService extends Service {
protected static final DEFAULT_TIMEOUT = 5000;
protected static final EXTENDED_TIMEOUT = 20000;
pickupTime.setContentText("10.00 AM");
pickupDate.setContentText("02/02/2019");
loadSize.setContentText("5 Tonne");
loadMethod.setContentText("Scrappe");
public class OrderSummaryActivity extends AppCompatActivity {
private CustomView pickupTime;
private CustomView pickupDate;
private CustomView loadSize;
private CustomView loadMethod;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_order_summary);
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="8dp"
android:orientation="vertical">
<TextView
android:id="@+id/order_status_tv"
public class CustomView extends FrameLayout {
private String labelText;
private String contentText;
private TextView labelTextView;
private TextView contentTextView;
public CustomView(Context context) {
super(context);
<resources>
<declare-styleable name="CustomView">
<attr name="label_text" format="string"/>
<attr name="content_text" format="string"/>
</declare-styleable>
</resources>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#E0E0E0"
android:orientation="vertical"
android:padding="8dp">
<TextView
@andrea-liu87
andrea-liu87 / kt
Last active October 13, 2019 07:07
If-Else-Null
fun ifNullElse (string : String?){
string?.let {
Log.d("Message","The string var is null")
} ?: kotlin.run {
Log.d("Message","The string var is not null")
}
}
@Override
public void onMapReady(GoogleMap googleMap) {
//Google map setup
mMap = googleMap;
mMap.getUiSettings().setZoomControlsEnabled(true);
mMap.setMyLocationEnabled(true);
mMap.getUiSettings().setMyLocationButtonEnabled(true);
// Show marker on the screen and adjust the zoom level
mMap.addMarker(new MarkerOptions().position(mOrigin).title("Origin"));
//Parse JSON Object from Google Direction API & display it on Map
public class TaskParseDirection extends AsyncTask<String, Void, List<List<HashMap<String, String>>>> {
@Override
protected List<List<HashMap<String, String>>> doInBackground(String... jsonString) {
List<List<HashMap<String, String>>> routes = null;
JSONObject jsonObject = null;
try {
jsonObject = new JSONObject(jsonString[0]);
DirectionParser parser = new DirectionParser();