textswitcher android example using android studio
Hello Guys. Welcome to our new tutorial of textswitcher android example using android studio. this post you can learn how
Read MoreOnline Education
Hello Guys. Welcome to our new tutorial of textswitcher android example using android studio. this post you can learn how
Read Morehello android developer In this android programming code example, we are going the learn how to pinch ImageView to zoom-in
Read MoreXML (activity_main.xml)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/rl" android:layout_width="match_parent" android:layout_height="match_parent" android:padding="16dp" tools:context=".Notification"> <Button android:id="@+id/btn" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:text="Notification" /> </RelativeLayout> |
JAVA (MainActivity.java)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.app.NotificationManager; import android.content.Context; import android.content.res.Resources; import android.graphics.BitmapFactory; import android.support.v4.app.NotificationCompat; import android.view.View; import android.widget.Button; import android.widget.RelativeLayout; import android.graphics.Bitmap; public class Notification extends AppCompatActivity { private Context mContext; private Resources mResources; private RelativeLayout mRelativeLayout; private Button mButton; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_notification); mContext = getApplicationContext(); mResources = getResources(); mRelativeLayout = (RelativeLayout) findViewById(R.id.rl); mButton = (Button) findViewById(R.id.btn); mButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { NotificationCompat.Builder builder = new NotificationCompat.Builder(mContext); builder.setSmallIcon(R.drawable.android); Bitmap bitmap = BitmapFactory.decodeResource(mResources, R.drawable.android); builder.setLargeIcon(bitmap); builder.setContentTitle("Android Studio Pro"); builder.setContentText("Learn Android App Development"); int notificationId = 001; NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); manager.notify(notificationId, builder.build()); } }); } } |
Read More
XML (activity_main.xml)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
<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" android:layout_gravity="center" android:gravity="center" android:orientation="vertical" tools:context=".Mp3MediaPlayer"> <TextView android:id="@+id/textView5" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="32dp" android:gravity="center" android:text="PLAY/STOP SONG.\nSCRUB WITH SEEKBAR" android:textStyle="bold" app:layout_constraintBottom_toTopOf="@+id/seekbar" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> <SeekBar android:id="@+id/seekbar" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center" android:layout_margin="16dp" app:layout_constraintBottom_toTopOf="@+id/button" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/textView5" /> <TextView android:id="@+id/textView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="8dp" app:layout_constraintBottom_toTopOf="@+id/seekbar" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" /> <android.support.design.widget.FloatingActionButton android:id="@+id/button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="16dp" android:layout_marginBottom="32dp" android:src="@android:drawable/ic_media_play" android:text="PLAY SOUND" app:layout_constraintBottom_toTopOf="@+id/adView" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/seekbar" /> </android.support.constraint.ConstraintLayout> |
JAVA (MainActivity.java)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
import android.content.res.AssetFileDescriptor; import android.media.MediaPlayer; import android.support.design.widget.FloatingActionButton; import android.support.v4.content.ContextCompat; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.SeekBar; import android.widget.TextView; public class Mp3MediaPlayer extends AppCompatActivity implements Runnable { MediaPlayer mp3player = new MediaPlayer(); SeekBar seekBar; boolean play = false; FloatingActionButton fab; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_mp3_media_player); fab = findViewById(R.id.button); fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { playSong(); } }); final TextView seekBarHint = findViewById(R.id.textView); seekBar = findViewById(R.id.seekbar); seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onStartTrackingTouch(SeekBar seekBar) { seekBarHint.setVisibility(View.VISIBLE); } @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromTouch) { seekBarHint.setVisibility(View.VISIBLE); int x = (int) Math.ceil(progress / 1000f); if (x < 10) seekBarHint.setText("0:0" + x); else seekBarHint.setText("0:" + x); double percent = progress / (double) seekBar.getMax(); int offset = seekBar.getThumbOffset(); int seekWidth = seekBar.getWidth(); int val = (int) Math.round(percent * (seekWidth - 2 * offset)); int labelWidth = seekBarHint.getWidth(); seekBarHint.setX(offset + seekBar.getX() + val - Math.round(percent * offset) - Math.round(percent * labelWidth / 2)); if (progress > 0 && mp3player != null && !mp3player.isPlaying()) { clearMediaPlayer(); fab.setImageDrawable(ContextCompat.getDrawable(Mp3MediaPlayer.this, android.R.drawable.ic_media_play)); Mp3MediaPlayer.this.seekBar.setProgress(0); } } @Override public void onStopTrackingTouch(SeekBar seekBar) { if (mp3player != null && mp3player.isPlaying()) { mp3player.seekTo(seekBar.getProgress()); } } }); } public void playSong() { try { if (mp3player != null && mp3player.isPlaying()) { clearMediaPlayer(); seekBar.setProgress(0); play = true; fab.setImageDrawable(ContextCompat.getDrawable(Mp3MediaPlayer.this, android.R.drawable.ic_media_play)); } if (!play) { if (mp3player == null) { mp3player = new MediaPlayer(); } fab.setImageDrawable(ContextCompat.getDrawable(Mp3MediaPlayer.this, android.R.drawable.ic_media_pause)); AssetFileDescriptor descriptor = getAssets().openFd("50_Cal_Shells_Drop.mp3"); mp3player.setDataSource(descriptor.getFileDescriptor(), descriptor.getStartOffset(), descriptor.getLength()); descriptor.close(); mp3player.prepare(); mp3player.setVolume(0.5f, 0.5f); mp3player.setLooping(false); seekBar.setMax(mp3player.getDuration()); mp3player.start(); new Thread(this).start(); } play = false; } catch (Exception e) { e.printStackTrace(); } } public void run() { int currentPosition = mp3player.getCurrentPosition(); int total = mp3player.getDuration(); while (mp3player != null && mp3player.isPlaying() && currentPosition < total) { try { Thread.sleep(1000); currentPosition = mp3player.getCurrentPosition(); } catch (InterruptedException e) { return; } catch (Exception e) { return; } seekBar.setProgress(currentPosition); } } @Override protected void onDestroy() { super.onDestroy(); clearMediaPlayer(); } private void clearMediaPlayer() { mp3player.stop(); mp3player.release(); mp3player = null; } } |
hello developer, today I will tell you how to create flashlight application in android studio. every smartphone has a flashlight
Read MoreXML (activity_main.xml)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:ads="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=".after32.Rewardvideoads"> <TextView android:id="@+id/text" android:gravity="center" android:layout_marginTop="50dp" android:layout_centerHorizontal="true" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="hello_world" /> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/watch" android:text="show" android:layout_marginTop="50dp" android:layout_below="@+id/text" /> </RelativeLayout> |
JAVA (MainActivity.java)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.view.View; import android.widget.Button; import android.widget.TextView; import android.widget.Toast; import com.google.android.gms.ads.AdRequest; import com.google.android.gms.ads.MobileAds; import com.google.android.gms.ads.reward.RewardItem; import com.google.android.gms.ads.reward.RewardedVideoAd; import com.google.android.gms.ads.reward.RewardedVideoAdListener; import com.tutorial.personal.androidstudiopro.R; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; public class Rewardvideoads extends AppCompatActivity implements RewardedVideoAdListener { private Button mWatch; private TextView mText; private RewardedVideoAd mAd; int coin=0; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_rewardvideoads); mWatch=(Button)findViewById(R.id.watch); mText=(TextView) findViewById(R.id.text); mWatch.setVisibility(View.INVISIBLE); mAd= MobileAds.getRewardedVideoAdInstance(this); mAd.setRewardedVideoAdListener(this); ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor(); scheduler.scheduleAtFixedRate(new Runnable() { public void run() { runOnUiThread(new Runnable() { public void run() { if (!mAd.isLoaded()) { loadAd(); } else { } } }); } }, 3, 5, TimeUnit.SECONDS); mWatch.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if(mAd.isLoaded()){ mAd.show(); } } }); } public void loadAd(){ if(!mAd.isLoaded()){ mAd.loadAd("ca-app-pub-394454099942544/55445917",new AdRequest.Builder().build()); } } @Override public void onRewardedVideoAdLoaded() { mWatch.setVisibility(View.VISIBLE); Toast.makeText(this, "Click this button for earn coin", Toast.LENGTH_SHORT).show(); } @Override public void onRewardedVideoAdOpened() { Toast.makeText(this, "Rewarded Video Ad has opened", Toast.LENGTH_SHORT).show(); } @Override public void onRewardedVideoStarted() { Toast.makeText(this, "Watch full video for earn Coin", Toast.LENGTH_SHORT).show(); } @Override public void onRewardedVideoAdClosed() { Toast.makeText(this, "Rewarded Video Ad has closed", Toast.LENGTH_SHORT).show(); loadAd(); mWatch.setVisibility(View.INVISIBLE); } @Override public void onRewarded(RewardItem rewardItem) { coin=coin+rewardItem.getAmount(); mText.setText("Your coin : "+coin); } @Override public void onRewardedVideoAdLeftApplication() { Toast.makeText(this, "Rewarded Video Ad has closed", Toast.LENGTH_SHORT).show(); } @Override public void onRewardedVideoAdFailedToLoad(int i) { } @Override public void onRewardedVideoCompleted() { } @Override public void onPause() { super.onPause(); mAd.pause(this); } @Override public void onResume() { super.onResume(); mAd.resume(this); loadAd(); } @Override public void onDestroy() { super.onDestroy(); mAd.destroy(this); } @Override protected void onStart() { loadAd(); super.onStart(); } } |
Read More
XML (activity_main.xml)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
<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:id="@+id/activity_main" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" android:paddingBottom="@dimen/activity_vertical_margin" android:gravity="center_horizontal|center_vertical" > <EditText android:id="@+id/et_phone_no" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="80dp" android:hint="Enter Phone number" android:inputType="phone" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> <Button android:id="@+id/btn_dial" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:layout_marginTop="80dp" android:text="Dial" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/et_phone_no" /> </android.support.constraint.ConstraintLayout> |
JAVA (MainActivity.java)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
import android.content.Intent; import android.net.Uri; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.text.TextUtils; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.Toast; public class PhoneCallsactivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_phone_callsactivity); Button mDialButton = (Button) findViewById(R.id.btn_dial); final EditText mPhoneNoEt = (EditText) findViewById(R.id.et_phone_no); mDialButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { String phoneNo = mPhoneNoEt.getText().toString(); if(!TextUtils.isEmpty(phoneNo)) { String dial = "tel:" + phoneNo; startActivity(new Intent(Intent.ACTION_DIAL, Uri.parse(dial))); }else { Toast.makeText(PhoneCallsactivity.this, "Enter a phone number", Toast.LENGTH_SHORT).show(); } } }); } } |
Read More
hello guys, this article I am going to show you how to copy text to clipboard in android studio. clipboard
Read Morehello, android developer once again welcomes back to another android app development tutorial in this article here I am going
Read Morehello, android developer today I will tell you how to make a brightness control app using android studio. or how
Read More