For more info, check out:
Support Library Docs: https://goo.gl/rOJEa7
What's New in Android Support Library, Google I/O '17 talk:
<?xml version="1.0" encoding="utf-8"?>
<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="match_parent"
android:layout_margin="20dp"
android:orientation="vertical"
tools:context="com.blogspot.android_er.androidedittextchanged.MainActivity">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@android:mipmap/sym_def_app_icon"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:autoLink="web"
android:text="http://android-er.blogspot.com/"
android:textStyle="bold"/>
<EditText
android:id="@+id/edittext1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="normal EditText"/>
<EditText
android:id="@+id/edittext2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="EditText with drawableLeft"
android:drawableLeft="@mipmap/ic_launcher"/>
<EditText
android:id="@+id/edittext3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="EditText with drawableRight"
android:drawableRight="@mipmap/ic_launcher_round"/>
<EditText
android:id="@+id/edittext4"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="EditText with drawableTop"
android:drawableTop="@mipmap/ic_launcher"/>
<EditText
android:id="@+id/edittext5"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="EditText with drawableBottom"
android:drawableBottom="@mipmap/ic_launcher_round"/>
<EditText
android:id="@+id/edittext6"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="EditText with background"
android:background="@mipmap/ic_launcher"/>
</LinearLayout>
</FrameLayout>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<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="match_parent"
android:layout_margin="20dp"
android:orientation="vertical"
tools:context="com.blogspot.android_er.androidedittextchanged.MainActivity">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@android:mipmap/sym_def_app_icon"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:autoLink="web"
android:text="http://android-er.blogspot.com/"
android:textStyle="bold"/>
<EditText
android:id="@+id/edittext1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="28dp"
android:text="normal EditText"/>
<EditText
android:id="@+id/edittext2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="EditText with background #50FFFFFF"
android:textSize="28dp"
android:background="#50FFFFFF"/>
<EditText
android:id="@+id/edittext3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="EditText with background #FFFFFF"
android:textSize="28dp"
android:background="#FFFFFF"/>
<EditText
android:id="@+id/edittext4"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="EditText with background #FFFFFF and alpha=0.5"
android:textSize="28dp"
android:background="#FFFFFF"
android:alpha="0.5"/>
</LinearLayout>
</FrameLayout>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle"
android:padding="10dp">
<solid android:color="#505050"/>
<corners
android:bottomRightRadius="10dp"
android:bottomLeftRadius="10dp"
android:topLeftRadius="10dp"
android:topRightRadius="10dp"/>
</shape>
<?xml version="1.0" encoding="utf-8"?>
<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="match_parent"
android:layout_margin="20dp"
android:orientation="vertical"
tools:context="com.blogspot.android_er.androidedittextchanged.MainActivity">
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:autoLink="web"
android:text="http://android-er.blogspot.com/"
android:textStyle="bold"/>
<EditText
android:id="@+id/edittext1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="normal EditText"/>
<EditText
android:id="@+id/edittext2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="EditText with custom shape"
android:textColorHint="#B0B0B0"
android:textColor="#F0F0F0"
android:background="@drawable/myshape" />
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<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="match_parent"
android:layout_margin="20dp"
android:orientation="vertical"
tools:context="com.blogspot.android_er.androidedittextchanged.MainActivity">
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:autoLink="web"
android:text="http://android-er.blogspot.com/"
android:textStyle="bold"/>
<AutoCompleteTextView
android:id="@+id/autocompletetextview"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<resources>
<string name="app_name">AndroidEditTextChanged</string>
<string-array name="suggestion">
<item>January</item>
<item>February</item>
<item>March</item>
<item>April</item>
<item>May</item>
<item>June</item>
<item>July</item>
<item>August</item>
<item>September</item>
<item>October</item>
<item>November</item>
<item>December</item>
</string-array>
</resources>
package com.blogspot.android_er.androidedittextchanged;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
public class MainActivity extends AppCompatActivity {
AutoCompleteTextView autoCompleteTextView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
autoCompleteTextView =
(AutoCompleteTextView)findViewById(R.id.autocompletetextview);
String[] suggestion = getResources().getStringArray(R.array.suggestion);
ArrayAdapter<String> adapter =
new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, suggestion);
autoCompleteTextView.setAdapter(adapter);
}
}
package com.blogspot.android_er.androidedittextchanged;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.Editable;
import android.text.TextWatcher;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
EditText editText;
TextView tvMsg;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
editText = (EditText)findViewById(R.id.edittext);
tvMsg = (TextView)findViewById(R.id.msg);
editText.addTextChangedListener(myTextWatcher);
}
TextWatcher myTextWatcher = new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence,
int i, int i1, int i2) {
}
@Override
public void onTextChanged(CharSequence charSequence,
int i, int i1, int i2) {
}
@Override
public void afterTextChanged(Editable editable) {
tvMsg.setText(editable.toString().toUpperCase());
}
};
}
<?xml version="1.0" encoding="utf-8"?>
<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="match_parent"
android:layout_margin="20dp"
android:orientation="vertical"
tools:context="com.blogspot.android_er.androidedittextchanged.MainActivity">
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:autoLink="web"
android:text="http://android-er.blogspot.com/"
android:textStyle="bold"/>
<EditText
android:id="@+id/edittext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter text"
android:textSize="24dp"/>
<TextView
android:id="@+id/msg"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textStyle="bold"
android:textSize="24dp"/>
</LinearLayout>
package com.blogspot.android_er.androidedittextchanged;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.Editable;
import android.text.TextWatcher;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
EditText editText;
TextView tvMsg, tvInfo;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
editText = (EditText)findViewById(R.id.edittext);
tvMsg = (TextView)findViewById(R.id.msg);
tvInfo = (TextView)findViewById(R.id.info);
editText.addTextChangedListener(myTextWatcher);
}
TextWatcher myTextWatcher = new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence,
int i, int i1, int i2) {
tvInfo.setText("beforeTextChanged(): \n"
+ charSequence + "\n"
+ i + "\n"
+ i1 + "\n"
+ i2);
}
@Override
public void onTextChanged(CharSequence charSequence,
int i, int i1, int i2) {
tvInfo.setText("onTextChanged(): \n"
+ charSequence + "\n"
+ i + "\n"
+ i1 + "\n"
+ i2);
tvMsg.setText(charSequence);
}
@Override
public void afterTextChanged(Editable editable) {
/*
String s = editable.toString();
tvInfo.setText("afterTextChanged(): \n"
+ s);
*/
}
};
}
<?xml version="1.0" encoding="utf-8"?>
<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="match_parent"
android:layout_margin="20dp"
android:orientation="vertical"
tools:context="com.blogspot.android_er.androidedittextchanged.MainActivity">
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:autoLink="web"
android:text="http://android-er.blogspot.com/"
android:textStyle="bold"/>
<EditText
android:id="@+id/edittext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter text"
android:textSize="24dp"/>
<TextView
android:id="@+id/msg"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textStyle="bold"
android:textSize="24dp"/>
<TextView
android:id="@+id/info"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textStyle="italic"
android:textSize="20dp"/>
</LinearLayout>
package com.blogspot.android_er.androiddatetime;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.TextView;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
public class MainActivity extends AppCompatActivity {
TextView tvNow, tvNowFormatted1, tvNowFormatted2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tvNow = (TextView)findViewById(R.id.now);
tvNowFormatted1 = (TextView)findViewById(R.id.nowformatted1);
tvNowFormatted2 = (TextView)findViewById(R.id.nowformatted2);
Date now = new Date();
tvNow.setText(now.toString());
String nowFormatted1 = DateFormat.getDateTimeInstance().format(now);
tvNowFormatted1.setText(nowFormatted1);
String nowFormatted2 = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss").format(now);
tvNowFormatted2.setText(nowFormatted2);
}
}
<?xml version="1.0" encoding="utf-8"?>
<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="match_parent"
android:layout_margin="20dp"
android:orientation="vertical"
tools:context="com.blogspot.android_er.androiddatetime.MainActivity">
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:autoLink="web"
android:text="http://android-er.blogspot.com/"
android:textStyle="bold"/>
<TextView
android:id="@+id/now"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="28dp"/>
<TextView
android:id="@+id/nowformatted1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#FF0000"
android:textStyle="bold"
android:textSize="28dp"/>
<TextView
android:id="@+id/nowformatted2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#0000FF"
android:textStyle="italic"
android:textSize="28dp"/>
</LinearLayout>
package com.blogspot.android_er.androidcontentloadingprogressbar;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.SystemClock;
import android.support.v4.widget.ContentLoadingProgressBar;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.ProgressBar;
public class MainActivity extends AppCompatActivity {
Button btnStartShortProgress, btnStartLongProgress;
ProgressBar progressBar;
ContentLoadingProgressBar contentLoadingProgressBar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnStartShortProgress = (Button)findViewById(R.id.startshortprogress);
btnStartLongProgress = (Button)findViewById(R.id.startlongprogress);
progressBar = (ProgressBar)findViewById(R.id.ProgressBar);
contentLoadingProgressBar =
(ContentLoadingProgressBar)findViewById(R.id.ContentLoadingProgressBar);
btnStartShortProgress.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
btnStartShortProgress.setEnabled(false);
btnStartLongProgress.setEnabled(false);
MyAsyncTask myAsyncTask = new MyAsyncTask();
myAsyncTask.execute(3);
}
});
btnStartLongProgress.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
btnStartShortProgress.setEnabled(false);
btnStartLongProgress.setEnabled(false);
MyAsyncTask myAsyncTask = new MyAsyncTask();
myAsyncTask.execute(50);
}
});
}
public class MyAsyncTask extends AsyncTask<Integer, Integer, Void> {
@Override
protected Void doInBackground(Integer... integers) {
int i = integers[0];
while(i-- > 0){
SystemClock.sleep(100);
}
return null;
}
@Override
protected void onPreExecute() {
progressBar.setVisibility(View.VISIBLE);
contentLoadingProgressBar.show();
}
@Override
protected void onPostExecute(Void aVoid) {
progressBar.setVisibility(View.GONE);
contentLoadingProgressBar.hide();
btnStartShortProgress.setEnabled(true);
btnStartLongProgress.setEnabled(true);
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<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="match_parent"
android:layout_margin="20dp"
android:orientation="vertical"
tools:context="com.blogspot.android_er.androidcontentloadingprogressbar.MainActivity">
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:autoLink="web"
android:text="http://android-er.blogspot.com/"
android:textStyle="bold"
/>
<Button
android:id="@+id/startshortprogress"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Start SHORT Progress"/>
<Button
android:id="@+id/startlongprogress"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Start LONG Progress"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="ProgressBar"
android:textStyle="bold"/>
<ProgressBar
android:id="@+id/ProgressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="ContentLoadingProgressBar"
android:textStyle="bold"/>
<android.support.v4.widget.ContentLoadingProgressBar
android:id="@+id/ContentLoadingProgressBar"
style="?android:attr/progressBarStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@mipmap/ic_launcher"/>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/background">
<shape>
<corners android:radius="5dip" />
<gradient
android:angle="180"
android:centerY="1.0"
android:startColor="#E8E8E8"
android:centerColor="#F0F0F0"
android:endColor="#F8F8F8" />
</shape>
</item>
<item android:id="@android:id/secondaryProgress">
<clip>
<shape>
<corners android:radius="5dip" />
<gradient
android:angle="270"
android:centerY="1.0"
android:startColor="#6000F000"
android:centerColor="#60008080"
android:endColor="#600000F0" />
</shape>
</clip>
</item>
<item android:id="@android:id/progress">
<clip>
<shape>
<corners android:radius="5dip" />
<gradient
android:angle="270"
android:centerY="1.0"
android:startColor="#E000F000"
android:centerColor="#E0008080"
android:endColor="#E00000F0" />
</shape>
</clip>
</item>
</layer-list>
<?xml version="1.0" encoding="utf-8"?>
<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="match_parent"
android:layout_margin="20dp"
android:orientation="vertical"
tools:context="com.blogspot.android_er.androidprogressbar.MainActivity">
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:autoLink="web"
android:text="http://android-er.blogspot.com/"
android:textStyle="bold"/>
<Button
android:id="@+id/startprogress"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Start ProgressBar"/>
<ProgressBar
android:id="@+id/progressbar"
style="@android:style/Widget.ProgressBar.Horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:max="10"
android:progress="0"
android:secondaryProgress="0"
android:visibility="gone"/>
<ProgressBar
android:id="@+id/myprogressbar"
style="@android:style/Widget.ProgressBar.Horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:max="10"
android:progress="0"
android:secondaryProgress="0"
android:visibility="gone"
android:progressDrawable="@drawable/myprogressbar"/>
</LinearLayout>
package com.blogspot.android_er.androidprogressbar;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.SystemClock;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.ProgressBar;
public class MainActivity extends AppCompatActivity {
Button btnStartProgress;
ProgressBar progressBar, myProgressBar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnStartProgress = (Button)findViewById(R.id.startprogress);
progressBar = (ProgressBar)findViewById(R.id.progressbar);
myProgressBar = (ProgressBar)findViewById(R.id.myprogressbar);
btnStartProgress.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
btnStartProgress.setEnabled(false);
MyAsyncTask myAsyncTask = new MyAsyncTask();
myAsyncTask.execute();
}
});
}
public class MyAsyncTask extends AsyncTask<Void, Integer, Void> {
@Override
protected void onPreExecute() {
progressBar.setVisibility(View.VISIBLE);
myProgressBar.setVisibility(View.VISIBLE);
progressBar.setProgress(0);
progressBar.setSecondaryProgress(0);
myProgressBar.setProgress(0);
myProgressBar.setSecondaryProgress(0);
}
@Override
protected Void doInBackground(Void... voids) {
for(int i=0; i<10; i++){
for(int j=0; j<10; j++){
publishProgress(i, j);
SystemClock.sleep(100);
}
}
return null;
}
@Override
protected void onProgressUpdate(Integer... values) {
progressBar.setProgress(values[0]);
progressBar.setSecondaryProgress(values[1]);
myProgressBar.setProgress(values[0]);
myProgressBar.setSecondaryProgress(values[1]);
}
@Override
protected void onPostExecute(Void aVoid) {
progressBar.setVisibility(View.GONE);
myProgressBar.setVisibility(View.GONE);
btnStartProgress.setEnabled(true);
}
}
}
package com.blogspot.android_er.androidprogressbar;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.SystemClock;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.ProgressBar;
public class MainActivity extends AppCompatActivity {
Button btnStartProgress;
ProgressBar progressBar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnStartProgress = (Button)findViewById(R.id.startprogress);
progressBar = (ProgressBar)findViewById(R.id.progressbar);
btnStartProgress.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
btnStartProgress.setEnabled(false);
MyAsyncTask myAsyncTask = new MyAsyncTask();
myAsyncTask.execute();
}
});
}
public class MyAsyncTask extends AsyncTask<Void, Integer, Void> {
@Override
protected void onPreExecute() {
progressBar.setVisibility(View.VISIBLE);
progressBar.setProgress(0);
progressBar.setSecondaryProgress(0);
}
@Override
protected Void doInBackground(Void... voids) {
for(int i=0; i<10; i++){
for(int j=0; j<10; j++){
publishProgress(i, j);
SystemClock.sleep(100);
}
}
return null;
}
@Override
protected void onProgressUpdate(Integer... values) {
progressBar.setProgress(values[0]);
progressBar.setSecondaryProgress(values[1]);
}
@Override
protected void onPostExecute(Void aVoid) {
progressBar.setVisibility(View.GONE);
btnStartProgress.setEnabled(true);
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<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="match_parent"
android:layout_margin="20dp"
android:orientation="vertical"
tools:context="com.blogspot.android_er.androidprogressbar.MainActivity">
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:autoLink="web"
android:text="http://android-er.blogspot.com/"
android:textStyle="bold"
/>
<Button
android:id="@+id/startprogress"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Start ProgressBar"/>
<ProgressBar
android:id="@+id/progressbar"
style="@android:style/Widget.ProgressBar.Horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:max="10"
android:progress="0"
android:secondaryProgress="0"
android:visibility="gone"/>
</LinearLayout>
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
</resources>
<?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="com.blogspot.android_er.toolbarprogressbar.MainActivity">
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="0dp"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/toolbar"
app:layout_constraintVertical_bias="0.501" />
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="368dp"
android:layout_height="wrap_content"
android:layout_marginLeft="0dp"
android:layout_marginRight="0dp"
android:layout_marginTop="0dp"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize"
android:theme="?attr/actionBarTheme"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ProgressBar
android:id="@+id/progressBar"
style="?android:attr/progressBarStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="8dp"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginTop="8dp"
android:visibility="gone"/>
</android.support.constraint.ConstraintLayout>
package com.blogspot.android_er.toolbarprogressbar;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.SystemClock;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
TextView tvTitle;
ProgressBar myProgressBar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tvTitle = (TextView)findViewById(R.id.title);
myProgressBar = (ProgressBar)findViewById(R.id.progressBar);
tvTitle.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(getBaseContext(),
"ProgressBar start running",
Toast.LENGTH_LONG).show();
tvTitle.setClickable(false);
MyAsyncTask myAsyncTask = new MyAsyncTask();
myAsyncTask.execute();
}
});
}
public class MyAsyncTask extends AsyncTask<Void, Integer, Void> {
@Override
protected void onPreExecute() {
myProgressBar.setVisibility(View.VISIBLE);
myProgressBar.setProgress(0);
}
@Override
protected Void doInBackground(Void... voids) {
for(int i=0; i<100; i++){
publishProgress(i);
SystemClock.sleep(100);
}
return null;
}
@Override
protected void onProgressUpdate(Integer... values) {
myProgressBar.setProgress(values[0]);
}
@Override
protected void onPostExecute(Void aVoid) {
myProgressBar.setVisibility(View.GONE);
tvTitle.setClickable(true);
}
}
}
<?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="com.blogspot.android_er.toolbarprogressbar.MainActivity">
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="0dp"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/toolbar"
app:layout_constraintVertical_bias="0.501" />
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="368dp"
android:layout_height="wrap_content"
android:layout_marginLeft="0dp"
android:layout_marginRight="0dp"
android:layout_marginTop="0dp"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize"
android:theme="?attr/actionBarTheme"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ProgressBar
android:id="@+id/progressBar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="0dp"
android:layout_marginLeft="0dp"
android:layout_marginRight="0dp"
app:layout_constraintBottom_toBottomOf="@+id/toolbar"
app:layout_constraintLeft_toLeftOf="@+id/toolbar"
app:layout_constraintRight_toRightOf="@+id/toolbar" />
</android.support.constraint.ConstraintLayout>
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/background">
<shape>
<corners android:radius="10dip" />
<gradient
android:startColor="#000000"
android:centerColor="#FF0000"
android:centerY="1.0"
android:endColor="#B0B0B0"
android:angle="180"
/>
</shape>
</item>
<item android:id="@android:id/progress">
<clip>
<shape>
<corners android:radius="10dip" />
<gradient
android:startColor="#101010"
android:centerColor="#808080"
android:centerY="1.0"
android:endColor="#F0F0F0"
android:angle="270"
/>
</shape>
</clip>
</item>
</layer-list>
<?xml version="1.0" encoding="utf-8"?>
<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="match_parent"
android:layout_margin="20dp"
android:orientation="vertical"
tools:context="com.blogspot.android_er.androidprogressbar.MainActivity">
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:autoLink="web"
android:text="http://android-er.blogspot.com/"
android:textStyle="bold"
/>
<Button
android:id="@+id/startprogress"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Start ProgressBar"/>
<ProgressBar
android:id="@+id/progressbar"
style="@android:style/Widget.ProgressBar.Horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:progress="0"
android:visibility="gone"/>
<ProgressBar
android:id="@+id/myprogressbar"
style="@android:style/Widget.ProgressBar.Horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:progress="0"
android:visibility="gone"
android:progressDrawable="@drawable/myprogressbar"/>
</LinearLayout>
package com.blogspot.android_er.androidprogressbar;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.SystemClock;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.ProgressBar;
public class MainActivity extends AppCompatActivity {
Button btnStartProgress;
ProgressBar progressBar, myProgressBar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnStartProgress = (Button)findViewById(R.id.startprogress);
progressBar = (ProgressBar)findViewById(R.id.progressbar);
myProgressBar = (ProgressBar)findViewById(R.id.myprogressbar);
btnStartProgress.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
btnStartProgress.setEnabled(false);
MyAsyncTask myAsyncTask = new MyAsyncTask();
myAsyncTask.execute();
}
});
}
public class MyAsyncTask extends AsyncTask<Void, Integer, Void> {
@Override
protected void onPreExecute() {
myProgressBar.setVisibility(View.VISIBLE);
myProgressBar.setProgress(0);
progressBar.setVisibility(View.VISIBLE);
progressBar.setProgress(0);
}
@Override
protected Void doInBackground(Void... voids) {
for(int i=0; i<100; i++){
publishProgress(i);
SystemClock.sleep(100);
}
return null;
}
@Override
protected void onProgressUpdate(Integer... values) {
myProgressBar.setProgress(values[0]);
progressBar.setProgress(values[0]);
}
@Override
protected void onPostExecute(Void aVoid) {
myProgressBar.setVisibility(View.GONE);
progressBar.setVisibility(View.GONE);
btnStartProgress.setEnabled(true);
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<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="match_parent"
android:layout_margin="20dp"
android:orientation="vertical"
tools:context="com.blogspot.android_er.androidprogressbar.MainActivity">
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:autoLink="web"
android:text="http://android-er.blogspot.com/"
android:textStyle="bold"
/>
<Button
android:id="@+id/startprogress"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Start ProgressBar"/>
<ProgressBar
android:id="@+id/indeterminateBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone" />
<ProgressBar
android:id="@+id/determinateBar1"
style="@android:style/Widget.ProgressBar.Horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:progress="0"
android:visibility="gone"/>
<ProgressBar
android:id="@+id/determinateBar2"
style="@android:style/Widget.ProgressBar.Inverse"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"/>
<ProgressBar
android:id="@+id/determinateBar3"
style="@android:style/Widget.ProgressBar.Large"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"/>
<ProgressBar
android:id="@+id/determinateBar4"
style="@android:style/Widget.ProgressBar.Large.Inverse"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"/>
<ProgressBar
android:id="@+id/determinateBar5"
style="@android:style/Widget.ProgressBar.Small"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"/>
<ProgressBar
android:id="@+id/determinateBar6"
style="@android:style/Widget.ProgressBar.Small.Inverse"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@mipmap/ic_launcher"/>
</LinearLayout>
package com.blogspot.android_er.androidprogressbar;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.SystemClock;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.ProgressBar;
public class MainActivity extends AppCompatActivity {
Button btnStartProgress;
ProgressBar indeterminateBar;
ProgressBar determinateBar1, determinateBar2, determinateBar3,
determinateBar4, determinateBar5, determinateBar6;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnStartProgress = (Button)findViewById(R.id.startprogress);
indeterminateBar = (ProgressBar)findViewById(R.id.indeterminateBar);
determinateBar1 = (ProgressBar)findViewById(R.id.determinateBar1);
determinateBar2 = (ProgressBar)findViewById(R.id.determinateBar2);
determinateBar3 = (ProgressBar)findViewById(R.id.determinateBar3);
determinateBar4 = (ProgressBar)findViewById(R.id.determinateBar4);
determinateBar5 = (ProgressBar)findViewById(R.id.determinateBar5);
determinateBar6 = (ProgressBar)findViewById(R.id.determinateBar6);
btnStartProgress.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
btnStartProgress.setEnabled(false);
MyAsyncTask myAsyncTask = new MyAsyncTask();
myAsyncTask.execute();
}
});
}
public class MyAsyncTask extends AsyncTask<Void, Integer, Void> {
@Override
protected void onPreExecute() {
indeterminateBar.setVisibility(View.VISIBLE);
determinateBar1.setVisibility(View.VISIBLE);
determinateBar1.setProgress(0);
determinateBar2.setVisibility(View.VISIBLE);
determinateBar3.setVisibility(View.VISIBLE);
determinateBar4.setVisibility(View.VISIBLE);
determinateBar5.setVisibility(View.VISIBLE);
determinateBar6.setVisibility(View.VISIBLE);
}
@Override
protected Void doInBackground(Void... voids) {
for(int i=0; i<100; i++){
publishProgress(i);
SystemClock.sleep(100);
}
return null;
}
@Override
protected void onProgressUpdate(Integer... values) {
determinateBar1.setProgress(values[0]);
}
@Override
protected void onPostExecute(Void aVoid) {
indeterminateBar.setVisibility(View.GONE);
determinateBar1.setVisibility(View.GONE);
determinateBar2.setVisibility(View.GONE);
determinateBar3.setVisibility(View.GONE);
determinateBar4.setVisibility(View.GONE);
determinateBar5.setVisibility(View.GONE);
determinateBar6.setVisibility(View.GONE);
btnStartProgress.setEnabled(true);
}
}
}
compile 'com.google.android.gms:play-services-base:11.0.0'
compile 'com.google.android.gms:play-services-basement:11.0.0'
compile 'com.google.android.gms:play-services-safetynet:11.0.0'
compile 'com.google.android.gms:play-services-tasks:11.0.0'
package com.blogspot.android_er.recaptcha;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.common.api.ResultCallback;
import com.google.android.gms.common.api.Status;
import com.google.android.gms.safetynet.SafetyNet;
import com.google.android.gms.safetynet.SafetyNetApi;
public class MainActivity extends AppCompatActivity
implements GoogleApiClient.ConnectionCallbacks,
GoogleApiClient.OnConnectionFailedListener{
final String SiteKey = "6LdMKyUUAAAAAN0ndw7byI03_qpbpjxKY-mTQnLw";
final String SecretKey = "6LdMKyUUAAAAALjcWovpXgcoXiI4i9ykn1U9qs8I";
private GoogleApiClient mGoogleApiClient;
Button btnRequest;
TextView tvResult;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tvResult = (TextView)findViewById(R.id.result);
btnRequest = (Button)findViewById(R.id.request);
btnRequest.setOnClickListener(RqsOnClickListener);
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addApi(SafetyNet.API)
.addConnectionCallbacks(MainActivity.this)
.addOnConnectionFailedListener(MainActivity.this)
.build();
mGoogleApiClient.connect();
}
View.OnClickListener RqsOnClickListener = new View.OnClickListener() {
@Override
public void onClick(View view) {
tvResult.setText("");
SafetyNet.SafetyNetApi.verifyWithRecaptcha(mGoogleApiClient, SiteKey)
.setResultCallback(new ResultCallback<SafetyNetApi.RecaptchaTokenResult>() {
@Override
public void onResult(SafetyNetApi.RecaptchaTokenResult result) {
Status status = result.getStatus();
if ((status != null) && status.isSuccess()) {
tvResult.setText("isSuccess()\n");
// Indicates communication with reCAPTCHA service was
// successful. Use result.getTokenResult() to get the
// user response token if the user has completed
// the CAPTCHA.
if (!result.getTokenResult().isEmpty()) {
tvResult.append("!result.getTokenResult().isEmpty()");
// User response token must be validated using the
// reCAPTCHA site verify API.
}else{
tvResult.append("result.getTokenResult().isEmpty()");
}
} else {
Log.e("MY_APP_TAG", "Error occurred " +
"when communicating with the reCAPTCHA service.");
tvResult.setText("Error occurred " +
"when communicating with the reCAPTCHA service.");
// Use status.getStatusCode() to determine the exact
// error code. Use this code in conjunction with the
// information in the "Handling communication errors"
// section of this document to take appropriate action
// in your app.
}
}
});
}
};
@Override
public void onConnected(@Nullable Bundle bundle) {
Toast.makeText(this, "onConnected()", Toast.LENGTH_LONG).show();
}
@Override
public void onConnectionSuspended(int i) {
Toast.makeText(this,
"onConnectionSuspended: " + i,
Toast.LENGTH_LONG).show();
}
@Override
public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
Toast.makeText(this,
"onConnectionFailed():\n" + connectionResult.getErrorMessage(),
Toast.LENGTH_LONG).show();
}
}
<?xml version="1.0" encoding="utf-8"?>
<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="match_parent"
android:orientation="vertical"
android:layout_margin="20dp"
tools:context="com.blogspot.android_er.recaptcha.MainActivity" >
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:autoLink="web"
android:text="http://android-er.blogspot.com/"
android:textStyle="bold" />
<Button
android:id="@+id/request"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Request SafetyNet reCAPTCHA API"/>
<TextView
android:id="@+id/result"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>