Category: Exemplos Java

Alguns exemplos de códigos Java

WebView

https://youtu.be/3RAlKq5vz1I 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 …

Continue a ler

Press Back twice to Exit

https://youtu.be/DFflSzAQbbo 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 …

Continue a ler

Animation Drawable

https://youtu.be/jQ_K6sOOiUs 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); …

Continue a ler

SeekBar with decimal

https://youtu.be/9TfkyAaCIyA 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 + ” %”; …

Continue a ler

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 = …

Continue a ler

AlertDialog with EditText

https://youtu.be/e3WfylNHHC4 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 …

Continue a ler