Translate To Your Own Langauge

Showing posts with label Splash Screen Using Thread. Show all posts
Showing posts with label Splash Screen Using Thread. Show all posts

Splash screen in Android using Thread

Splash Screen is one of the most important topic in Android app Development. In almost every app, we see a screen for a short time and then actual Home screen is displayed. The purpose of this screen is to display logo of our app or any advert in our app. In this tutorial, I will show you the actual implementation of "Splash screen in Android using Thread". Before going in detail, one should know the use of Thread.
Definition: A thread is a single sequential flow of control within a program.
Now you have a rough idea about what is thread. Now we will use this concept to implement Splash screen in Android using Thread. For this, you need two XML files and Two .java files. Layout Doesn't matter in this tutorial because we are dealing with code in this example but still i am providing the xml code for you.
Follow these steps:

Read more »

by Unknown · 25

Change the Profile Mode Programmatically (Android Example)

Many of the times when we are dealing with Android app development, we need to change the profile mode of our phone as per user's requirement or if you are working with location based app then you need to change the mode according to the location. In this tutorial, i will show you how to change the profile mode of our phone Programmatically

  Follow these simple steps:
1. In the Activity_main.xml file, drag and drop three buttons. If you want to setup an easy UI, just copy and paste the following code into your XML file.

Activity_main.xml
<RelativeLayout 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:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

    <Button
        android:id="@+id/btnSilent"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="56dp"
        android:text="Silent" />

    <Button
        android:id="@+id/btnVibe"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/btnSilent"
        android:layout_below="@+id/btnSilent"
        android:layout_marginTop="61dp"
        android:text="Viberate" />

    <Button
        android:id="@+id/btnRinger"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/btnVibe"
        android:layout_below="@+id/btnVibe"
        android:layout_marginTop="82dp"
        android:text="Ringer" />

</RelativeLayout>



2. Now you are done with UI, Lets work on the programming part. To do so, copy and paste the following code into mainActivity.java file.

mainActivity.java
package com.example.modeswitcher;

import android.media.AudioManager;
import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

public class MainActivity extends Activity {
       Button btnSilent, btnVibe, btnRinger;

       @Override
       protected void onCreate(Bundle savedInstanceState) {
              super.onCreate(savedInstanceState);
              setContentView(R.layout.activity_main);
              final AudioManager mode=(AudioManager)this.getSystemService(Context.AUDIO_SERVICE);
              // Initialization of buttons
              btnSilent = (Button) findViewById(R.id.btnSilent);
              btnVibe = (Button) findViewById(R.id.btnVibe);
              btnRinger = (Button) findViewById(R.id.btnRinger);
              // functionallity of btnSilent
              btnSilent.setOnClickListener(new View.OnClickListener() {

                     @Override
                     public void onClick(View arg0) {
                           // TODO Auto-generated method stub
                           mode.setRingerMode(AudioManager.RINGER_MODE_SILENT);
                           Toast.makeText(getApplicationContext(), "silent mode set", Toast.LENGTH_LONG).show();
                     }
              });

              // functionallity of btnVibe
              btnVibe.setOnClickListener(new View.OnClickListener() {

                     @Override
                     public void onClick(View arg0) {
                           // TODO Auto-generated method stub
                           mode.setRingerMode(AudioManager.RINGER_MODE_VIBRATE);
                           Toast.makeText(getApplicationContext(), "Viberate mode set", Toast.LENGTH_LONG).show();
                     }
              });

              // functionallity of btnRinger
              btnRinger.setOnClickListener(new View.OnClickListener() {

                     @Override
                     public void onClick(View arg0) {
                           // TODO Auto-generated method stub
                           mode.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
                           Toast.makeText(getApplicationContext(), "Ringer mode set", Toast.LENGTH_LONG).show();
                     }
              });

       }

       @Override
       public boolean onCreateOptionsMenu(Menu menu) {
              // Inflate the menu; this adds items to the action bar if it is present.
              getMenuInflater().inflate(R.menu.main, menu);
              return true;
       }

}

by Unknown · 14

Blogger Widgets
All Rights Reserved Android Tutorials | Designed by: Deepak Anand