WebView

package com.byronsystemdeveloper.byronsystemdeveloper;

import android.graphics.Bitmap;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.webkit.WebResourceRequest;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ProgressBar;

public class MainActivity extends AppCompatActivity {

private ProgressBar progressBar;
private WebView webView;
private WebSettings webSettings;
private String url;

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

progressBar=findViewById(R.id.progressBar);
webView=findViewById(R.id.webView);
url="http://34.105.161.132";
webView.loadUrl(url);
webSettings=webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webView.setWebViewClient(new mWebViewClient());

}

private class mWebViewClient extends WebViewClient {

@Override
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
view.loadUrl(url);
return true;
}

@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
progressBar.setVisibility(View.VISIBLE);
super.onPageStarted(view, url, favicon);
}

@Override
public void onPageFinished(WebView view, String url) {
progressBar.setVisibility(View.GONE);
super.onPageFinished(view, url);
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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="match_parent">

<WebView
android:id="@+id/webView"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" >

</WebView>

<ProgressBar
android:id="@+id/progressBar"
style="?android:attr/progressBarStyle"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:layout_editor_absoluteX="172dp"
tools:layout_editor_absoluteY="333dp" />
</android.support.constraint.ConstraintLayout>
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.byronsystemdeveloper.byronsystemdeveloper" >

<uses-permission android:name="android.permission.INTERNET"/>

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>

Press Back twice to Exit


import android.content.Intent;
import android.os.CountDownTimer;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

private static boolean userPressedBackAgain;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

}

@Override
public void onBackPressed() {

if(!userPressedBackAgain){
Toast.makeText(this, "Back again to exit", Toast.LENGTH_LONG).show();
userPressedBackAgain=true;
} else {
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}

new CountDownTimer(3000,1000){
@Override
public void onTick(long millisUntilFinished) {

}

@Override
public void onFinish() {
userPressedBackAgain =false;
}
}.start();
}
}

Animation Drawable

import android.graphics.drawable.AnimationDrawable;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ImageView;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

ImageView imageView = findViewById(R.id.imageViewLayout);
AnimationDrawable animationDrawable = new AnimationDrawable();
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v1),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v2),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v3),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v4),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v5),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v6),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v7),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v8),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v9),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v10),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v11),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v12),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v13),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v14),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v15),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v16),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v17),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v18),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v19),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v20),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v21),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v22),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v23),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v24),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v25),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v26),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v27),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v28),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v29),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v30),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v31),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v32),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v33),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v34),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v35),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v36),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v37),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v38),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v39),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v40),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v41),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v42),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v43),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v44),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v45),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v46),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v47),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v48),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v49),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v50),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v51),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v52),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v53),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v54),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v55),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v56),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v57),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v58),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v59),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v60),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v61),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v62),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v63),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v64),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v65),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v66),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v67),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v68),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v69),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v70),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v71),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v72),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v73),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v74),50);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.v75),50);
animationDrawable.setOneShot(false); // true for stop after play the image
imageView.setImageDrawable(animationDrawable);
animationDrawable.start();


}
}
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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="match_parent"
tools:context=".MainActivity">

<ImageView
android:id="@+id/imageViewLayout"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:srcCompat="@tools:sample/backgrounds/scenic" />
</android.support.constraint.ConstraintLayout>

SeekBar with decimal


import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.SeekBar;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

private TextView textView;
private SeekBar seekBar;
private Float aFloat;
private String string;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

textView=findViewById(R.id.textViewlayout);
seekBar=findViewById(R.id.seekBarlayout);

seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {

aFloat=(float)(progress *0.1);
string= Float.toString(aFloat);
string= string + " %";
textView.setText(string);

//For 100.0% » 100%
//And 0.0% » 0 %

if(textView.getText().toString().equals("100.0 %")) textView.setText("100 %");
if(textView.getText().toString().equals("0.0 %")) textView.setText("0 %");


}

@Override
public void onStartTrackingTouch(SeekBar seekBar) {

}

@Override
public void onStopTrackingTouch(SeekBar seekBar) {

}
});
}
}
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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="match_parent"
tools:context=".MainActivity">

<TextView
android:id="@+id/textViewlayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="51dp"
android:text="Move Thumb"
android:textSize="30sp"
app:layout_constraintBottom_toTopOf="@+id/seekBarlayout"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />

<SeekBar
android:id="@+id/seekBarlayout"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:layout_marginBottom="341dp"
android:max="1000"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
</android.support.constraint.ConstraintLayout>

Alert Dialog Builder

import android.content.DialogInterface;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

private Button mybutton;
private AlertDialog.Builder dialog;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

mybutton = findViewById(R.id.buttonLayout);

mybutton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {


// Create dialog
// Criar o dialog
dialog = new AlertDialog.Builder(MainActivity.this);

// Dialog Title
// Titulo da dialog
dialog.setTitle("Title of dialog");

// Dialog Mesage
// Mensagem da dialog
dialog.setMessage("Dialog Message blá, blá, blá ?");

// Not possible to cancel
// Caixa obrigatoria não cancelável
dialog.setCancelable(false);

// Put ant icon in the dialog
// Colocar um icon na caixa de dialogo
dialog.setIcon(android.R.drawable.ic_dialog_info);

// Creat positive and negative answer
// Criar resposta positiva e negativa
dialog.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
Toast.makeText(MainActivity.this, "Yes pressed", Toast.LENGTH_LONG).show();
}
});
dialog.setNegativeButton("No", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
Toast.makeText(MainActivity.this, "No pressed", Toast.LENGTH_LONG).show();
}
});

// Mont dialog box
// Montar a dialog
dialog.create();
dialog.show();
}
});
}
}

AlertDialog with EditText


import android.content.DialogInterface;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.InputType;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

private Button myButton;
private String myText;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

myButton=findViewById(R.id.button);

myButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
AlertDialog.Builder mydialog = new AlertDialog.Builder(MainActivity.this);
mydialog.setTitle("Weight in Kilograms? Example 21.6");

final EditText weightInput = new EditText(MainActivity.this);
weightInput.setInputType(InputType.TYPE_CLASS_PHONE);
mydialog.setView(weightInput);

mydialog.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
myText=weightInput.getText().toString();
Toast.makeText(MainActivity.this, "Weight is "
+myText, Toast.LENGTH_LONG).show();
}
});

mydialog.setNegativeButton("Cancel",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
dialogInterface.cancel();
}
});
mydialog.show();
}
});
}
}