Twitter Facebook Delicious Digg Stumbleupon Favorites More

Wednesday, 23 May 2018

media player basic not original

image

package com.example.viraj.musicapp;

import android.media.MediaPlayer;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.SeekBar;
import android.widget.Switch;
import android.widget.TextView;

import java.text.SimpleDateFormat;
import java.util.Date;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {
    private MediaPlayer mediaPlayer;
    private ImageView artistimage;
    private TextView lefttime, righttime, artistname, songname;
    private SeekBar seekBar;
    private Button previousbuttion, playpausebutton, nextbutton;
    private Thread thread;

    @Override    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //----------------------------        setUpUI();
        //------------------------------        seekBar.setMax(mediaPlayer.getDuration());
        //------------------------------        seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                if (fromUser) {
                    mediaPlayer.seekTo(progress);
                }
                //------inside start time formate class  set min sdk to 24 on gradle build.gradle modul app                SimpleDateFormat dateFormat = new SimpleDateFormat("mm:ss");
                int currentpos = mediaPlayer.getCurrentPosition();
                int duration = mediaPlayer.getDuration();
                lefttime.setText(String.valueOf(dateFormat.format(new Date(currentpos))));
                righttime.setText(String.valueOf(dateFormat.format(new Date(duration - currentpos))));
                //------inside start time formate class            }

            @Override            public void onStartTrackingTouch(SeekBar seekBar) {

            }

            @Override            public void onStopTrackingTouch(SeekBar seekBar) {

            }
        });
//-----------------------------------------    }

    public void setUpUI() {
        mediaPlayer = new MediaPlayer();
        mediaPlayer = MediaPlayer.create(getApplicationContext(), R.raw.tola);
        artistimage = (ImageView) findViewById(R.id.id_artistimage);
        lefttime = (TextView) findViewById(R.id.id_lefttime);
        righttime = (TextView) findViewById(R.id.id_righttime);
        seekBar = (SeekBar) findViewById(R.id.id_seekBar);
        previousbuttion = (Button) findViewById(R.id.id_previousbutton);
        playpausebutton = (Button) findViewById(R.id.id_playbutton);
        nextbutton = (Button) findViewById(R.id.id_nextbutton);
        artistname = (TextView) findViewById(R.id.id_artistname);
        songname = (TextView) findViewById(R.id.id_songname);

        previousbuttion.setOnClickListener(this);
        playpausebutton.setOnClickListener(this);
        nextbutton.setOnClickListener(this);
    }

    @Override    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.id_previousbutton:
                //code                backMusic();
                break;
            case R.id.id_playbutton:
                //code                if (mediaPlayer.isPlaying()) {
                    pauseMusic();
                } else {
                    startMusic();
                }
                break;
            case R.id.id_nextbutton:
                //code                nextMusic();
                break;
        }
    }

    //method he    public void pauseMusic() {
        if (mediaPlayer != null) {
            mediaPlayer.pause();
            playpausebutton.setBackgroundResource(android.R.drawable.ic_media_play);
        }
    }

    public void startMusic() {
        if (mediaPlayer != null) {
            mediaPlayer.start();
            updateThread();
            playpausebutton.setBackgroundResource(android.R.drawable.ic_media_pause);
        }
    }
public void backMusic()
{
   if (mediaPlayer.isPlaying())
   {
       //for no       mediaPlayer.seekTo(0);
   }
}
public void nextMusic()
{
    if (mediaPlayer.isPlaying())
    {
        mediaPlayer.seekTo(mediaPlayer.getDuration()-100);
    }
}
    public void updateThread() {
        thread = new Thread() {
            @Override            public void run() {
                try {
                    while (mediaPlayer != null && mediaPlayer.isPlaying()) {
                        Thread.sleep(50);
                        runOnUiThread(new Runnable() {
                            @Override                            public void run() {
                                int newPositio = mediaPlayer.getCurrentPosition();
                                int newMax = mediaPlayer.getDuration();
                                seekBar.setMax(newMax);
                                seekBar.setProgress(newPositio);
//update the text                                lefttime.setText(String.valueOf(new java.text.SimpleDateFormat("mm:ss")
                                        .format(new Date(mediaPlayer.getCurrentPosition()))));
                                righttime.setText(String.valueOf(new java.text.SimpleDateFormat("mm:ss")
                                        .format(new Date(mediaPlayer.getCurrentPosition()))));
                            }
                        });
                    }

                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        };
        thread.start();

    }

    @Override    protected void onDestroy() {
      if (mediaPlayer!=null && mediaPlayer.isPlaying())
      {
          mediaPlayer.stop();
          mediaPlayer.release();
          mediaPlayer=null;
      }
      thread.interrupt();
      thread=null;
        super.onDestroy();
    }
}
xml file

<?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"    android:orientation="vertical"    tools:context=".MainActivity">

    <ImageView        android:id="@+id/id_artistimage"        android:layout_width="150dp"        android:layout_height="150dp"        android:layout_marginEnd="8dp"        android:layout_marginLeft="8dp"        android:layout_marginRight="8dp"        android:layout_marginStart="8dp"        android:layout_marginTop="28dp"        app:layout_constraintEnd_toEndOf="parent"        app:layout_constraintStart_toStartOf="parent"        app:layout_constraintTop_toTopOf="parent"        app:srcCompat="@drawable/oval" />

    <ImageView        android:id="@+id/imageView2"        android:layout_width="342dp"        android:layout_height="7dp"        android:layout_marginBottom="8dp"        android:layout_marginEnd="8dp"        android:layout_marginLeft="8dp"        android:layout_marginRight="8dp"        android:layout_marginStart="8dp"        android:layout_marginTop="8dp"        app:layout_constraintBottom_toBottomOf="parent"        app:layout_constraintEnd_toEndOf="parent"        app:layout_constraintStart_toStartOf="parent"        app:layout_constraintTop_toBottomOf="@+id/id_artistimage"        app:layout_constraintVertical_bias="0.077"        app:srcCompat="@drawable/divider" />

    <TextView        android:id="@+id/id_songname"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_marginEnd="8dp"        android:layout_marginLeft="8dp"        android:layout_marginRight="8dp"        android:layout_marginStart="8dp"        android:layout_marginTop="20dp"        android:text="@string/songname"        android:textColor="@color/pink"        android:textSize="24sp"        android:textStyle="bold"        app:fontFamily="monospace"        app:layout_constraintEnd_toEndOf="parent"        app:layout_constraintHorizontal_bias="0.425"        app:layout_constraintStart_toStartOf="parent"        app:layout_constraintTop_toBottomOf="@+id/imageView2" />

    <TextView        android:id="@+id/id_artistname"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_marginBottom="8dp"        android:layout_marginEnd="8dp"        android:layout_marginLeft="8dp"        android:layout_marginRight="8dp"        android:layout_marginStart="8dp"        android:layout_marginTop="8dp"        android:text="@string/Artist"        android:textColor="@color/pink"        android:textSize="24sp"        android:textStyle="bold"        app:fontFamily="monospace"        app:layout_constraintBottom_toBottomOf="parent"        app:layout_constraintEnd_toEndOf="parent"        app:layout_constraintHorizontal_bias="0.502"        app:layout_constraintStart_toStartOf="parent"        app:layout_constraintTop_toBottomOf="@+id/id_songname"        app:layout_constraintVertical_bias="0.03" />

    <SeekBar        android:id="@+id/id_seekBar"        android:layout_width="360dp"        android:layout_height="28dp"        android:layout_marginBottom="8dp"        android:layout_marginEnd="8dp"        android:layout_marginLeft="8dp"        android:layout_marginRight="8dp"        android:layout_marginStart="8dp"        android:layout_marginTop="8dp"        app:layout_constraintBottom_toBottomOf="parent"        app:layout_constraintEnd_toEndOf="parent"        app:layout_constraintStart_toStartOf="parent"        app:layout_constraintTop_toBottomOf="@+id/id_artistname"        app:layout_constraintVertical_bias="0.026" />

    <TextView        android:id="@+id/id_lefttime"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_marginBottom="8dp"        android:layout_marginLeft="16dp"        android:layout_marginStart="16dp"        android:layout_marginTop="8dp"        android:text="@string/lefttime"        app:layout_constraintBottom_toBottomOf="parent"        app:layout_constraintStart_toStartOf="parent"        app:layout_constraintTop_toBottomOf="@+id/id_seekBar"        app:layout_constraintVertical_bias="0.0" />

    <TextView        android:id="@+id/id_righttime"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_marginBottom="8dp"        android:layout_marginEnd="12dp"        android:layout_marginLeft="8dp"        android:layout_marginRight="12dp"        android:layout_marginStart="8dp"        android:layout_marginTop="8dp"        android:text="@string/righttime"        app:layout_constraintBottom_toBottomOf="parent"        app:layout_constraintEnd_toEndOf="parent"        app:layout_constraintHorizontal_bias="0.968"        app:layout_constraintStart_toEndOf="@+id/id_lefttime"        app:layout_constraintTop_toBottomOf="@+id/id_seekBar"        app:layout_constraintVertical_bias="0.0" />

    <TableRow        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_marginBottom="8dp"        android:layout_marginEnd="8dp"        android:layout_marginLeft="8dp"        android:layout_marginRight="8dp"        android:layout_marginStart="8dp"        android:layout_marginTop="8dp"android:background="@color/colorPrimaryDark"        android:gravity="center"        android:padding="14dp"        app:layout_constraintBottom_toBottomOf="parent"        app:layout_constraintEnd_toEndOf="parent"        app:layout_constraintStart_toStartOf="parent"        app:layout_constraintTop_toBottomOf="@+id/id_lefttime"        app:layout_constraintVertical_bias="0.0">

        <Button            android:id="@+id/id_previousbutton"            android:layout_width="40dp"            android:layout_height="40dp"
            android:background="@android:drawable/ic_media_previous" />

        <Button            android:id="@+id/id_playbutton"            android:layout_width="40dp"            android:layout_height="40dp"            android:background="@android:drawable/ic_media_play" />

        <Button            android:id="@+id/id_nextbutton"            android:layout_width="40dp"            android:layout_height="40dp"            android:background="@android:drawable/ic_media_next" />
    </TableRow>

</android.support.constraint.ConstraintLayout>
Share:

Tuesday, 22 May 2018

basic music play from saved mp3 android app

package com.example.viraj.mplay;

import android.media.MediaPlayer;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.accessibility.AccessibilityManager;
import android.widget.Button;
import android.widget.SeekBar;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {
    private MediaPlayer mediaPlayer;
    private Button playButton;
    private SeekBar MseekBar;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        MseekBar=(SeekBar)findViewById(R.id.id_seekbar);
        mediaPlayer = new MediaPlayer();
        mediaPlayer = MediaPlayer.create(MainActivity.this, R.raw.free);
MseekBar.setMax(mediaPlayer.getDuration());
        MseekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
if (fromUser)
{
    mediaPlayer.seekTo(progress);
}
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {

            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {

            }
        });
        mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
            @Override
            public void onCompletion(MediaPlayer mp) {
                int duration=mp.getDuration();
                String mDuration=String.valueOf(duration/1000);
                Toast.makeText(getApplicationContext(),"Duration is"+mDuration,Toast.LENGTH_LONG).show();
            }
        });

        playButton = (Button) findViewById(R.id.id_button);
        playButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mediaPlayer.isPlaying()) {
                    //stop and give option
                    pausemusic();
                }
                else {
                    startmusic();
                }
            }
        });
    }

    public void pausemusic() {
        if (mediaPlayer != null) {
            mediaPlayer.pause();
            playButton.setText("play");
        }
    }

    public void startmusic() {
        if (mediaPlayer != null) {
            mediaPlayer.start();
            playButton.setText("PAUSE");
        }
    }

    @Override
    protected void onDestroy() {
        if (mediaPlayer!=null && mediaPlayer.isPlaying())
        {
mediaPlayer.stop();
mediaPlayer.release();
mediaPlayer=null;
        }
        super.onDestroy();
    }
}



xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
    android:orientation="vertical"
    android:gravity="center">

    <Button
        android:id="@+id/id_button"
        android:layout_width="wrap_content"

        android:layout_height="wrap_content"
        android:text="@string/Buttonplay" />

    <SeekBar
        android:id="@+id/id_seekbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

</LinearLayout>

Share:

Saturday, 19 May 2018

raw file creation


Share:

Saturday, 12 May 2018

PET BIO ORIGINAL


FIRST PAGE JAVA

package com.gohool.petbio.petbio;

import android.content.Intent;
import android.media.Image;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity implements View.OnClickListener{
    private ImageView catView;
    private ImageView dogView;

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

        catView = (ImageView) findViewById(R.id.catID);
        dogView = (ImageView) findViewById(R.id.dogId);

        catView.setOnClickListener(this);
        dogView.setOnClickListener(this);


    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.catID:
                //go to second activity
                Intent catIntent = new Intent(MainActivity.this, BioActivity.class);
                catIntent.putExtra("name", "Jarvis");
                catIntent.putExtra("bio", "Great cat.  Loves people and meows a lot!");
                startActivity(catIntent);
              //  Toast.makeText(MainActivity.this, "Cat", Toast.LENGTH_LONG).show();
                break;

            case R.id.dogId:
                //go to second activity
                Intent dogIntent = new Intent(MainActivity.this, BioActivity.class);
                dogIntent.putExtra("name", "Dufus");
                dogIntent.putExtra("bio", "Great Dog.  Loves people and barks and eats a lot!");
                startActivity(dogIntent);
              //  Toast.makeText(MainActivity.this, "Dog", Toast.LENGTH_LONG).show();
                break;


        }

    }
}


SECOND PAGE

package com.gohool.petbio.petbio;

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

import org.w3c.dom.Text;

public class BioActivity extends AppCompatActivity {
    private ImageView petImageView;
    private TextView petName;
    private TextView petBio;
    private Bundle extras;

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

        petImageView = (ImageView) findViewById(R.id.petImageViewID);
        petName = (TextView) findViewById(R.id.nameID);
        petBio = (TextView) findViewById(R.id.bioTextID);


        extras = getIntent().getExtras();

        if (extras != null) {
            String name = extras.getString("name");
            String bio = extras.getString("bio");

            setUp(name, bio);
        }



    }

    public void setUp(String name, String bio) {

        if (name.equals("Dufus")) {
              //We show Dog stuff
            petImageView.setImageDrawable(getResources().getDrawable(R.drawable.icon_lg_dog));
            petName.setText(name);
            petBio.setText(bio);




        } else if (name.equals("Jarvis")) {

             //We show cat stuff
            petImageView.setImageDrawable(getResources().getDrawable(R.drawable.icon_lg_cat));
            petName.setText(name);
            petBio.setText(bio);

        }

    }
}






FIRST PAGE XML

<?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"
    android:background="@color/colorAccent"
    tools:context="com.gohool.petbio.petbio.MainActivity">

    <ImageView
        android:id="@+id/catID"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:srcCompat="@drawable/icon_lg_cat"
        app:layout_constraintHorizontal_bias="0.502"
        app:layout_constraintTop_toTopOf="parent"
        android:layout_marginTop="8dp"
        app:layout_constraintBottom_toBottomOf="parent"
        android:layout_marginBottom="8dp"
        app:layout_constraintVertical_bias="0.216" />

    <ImageView
        android:id="@+id/dogId"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="72dp"
        app:layout_constraintHorizontal_bias="0.486"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/catID"
        app:srcCompat="@drawable/icon_lg_dog" />
</android.support.constraint.ConstraintLayout>



SECOND PAGE XML

<?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:id="@+id/petBioImageViewID"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.gohool.petbio.petbio.BioActivity">

    <ImageView
        android:id="@+id/petImageViewID"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp"
        android:layout_marginTop="8dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintHorizontal_bias="0.501"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.109"
        app:srcCompat="@android:drawable/screen_background_dark_transparent"
        tools:layout_editor_absoluteX="188dp"
        tools:layout_editor_absoluteY="58dp" />

    <TextView
        android:id="@+id/nameID"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp"
        android:layout_marginTop="0dp"
        android:text="TextView"
        android:textSize="18sp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/petImageViewID"
        app:layout_constraintVertical_bias="0.148" />

    <TextView
        android:id="@+id/bioTextID"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginTop="8dp"
        android:text="TextView"
        android:textSize="24sp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/nameID" />
</android.support.constraint.ConstraintLayout>

Share:

switch case and set on click on diffrent side

public class MainActivity extends AppCompatActivity implements View.OnClickListener{
    private ImageView catView;
    private ImageView dogView;

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

        catView = (ImageView) findViewById(R.id.catID);
        dogView = (ImageView) findViewById(R.id.dogId);

        catView.setOnClickListener(this);
        dogView.setOnClickListener(this);


    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.catID:
                //go to second activity
                Intent catIntent = new Intent(MainActivity.this, BioActivity.class);
                catIntent.putExtra("name", "Jarvis");
                catIntent.putExtra("bio", "Great cat.  Loves people and meows a lot!");
                startActivity(catIntent);
              //  Toast.makeText(MainActivity.this, "Cat", Toast.LENGTH_LONG).show();
                break;

            case R.id.dogId:
                //go to second activity
                Intent dogIntent = new Intent(MainActivity.this, BioActivity.class);
                dogIntent.putExtra("name", "Dufus");
                dogIntent.putExtra("bio", "Great Dog.  Loves people and barks and eats a lot!");
                startActivity(dogIntent);
              //  Toast.makeText(MainActivity.this, "Dog", Toast.LENGTH_LONG).show();
                break;


        }

    }
}
Share:

Tuesday, 17 April 2018

Tips to speed Up Android Studio

  • Update Android Studio(2.3) and Java To the latest One
  • Disable unwanted Plugins. Demo Video
  • If you are not using VCS and Google Cloud Services then disable the following Plugins:
GitIntegration, GitHub, CVS Integration, Google Login and its dependent Plugins, Subversion Integration.
  • Close All Windows and Browser While Using Android Studio.
  • Avoid Built in Emulators. Try GenyMotion or Real Devices(Recommended)
  • Disable Unwanted Startup Programs. Check the help here
  • Tweak the Gradle to reduce Build Time
  • Update Your RAM to 8GB (atleast 4GB)
Hope its helpful..!! Happy Androidify...!!!!

video link 
Share:

Sunday, 11 February 2018

calories counter android app

1) 
Share:

Thursday, 1 February 2018

Destination app

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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.example.viraj.destiniapp.MainActivity"
    android:background="@drawable/background"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    >


    <TextView
        android:id="@+id/storyTextView"
        android:text="@string/T1_Story"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true"
        android:textSize="24sp"
        android:textColor="#ffffffff"
        />

    <Button
        android:id="@+id/buttonTop"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/T1_Ans1"
        android:layout_alignParentBottom="true"
        android:layout_marginBottom="61dp"
        android:background="#e74c3c"
        android:textColor="#ecf0f1"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true"
        android:textSize="15sp"
        />

    <Button
        android:id="@+id/buttonBottom"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/T1_Ans2"
        android:layout_alignParentBottom="true"
        android:layout_alignLeft="@+id/buttonTop"
        android:layout_alignStart="@+id/buttonTop"
        android:layout_alignRight="@+id/buttonTop"
        android:layout_alignEnd="@+id/buttonTop"
        android:background="#3498db"
        android:textColor="#ecf0f1"
        android:textSize="15sp"/>

</RelativeLayout>

MAINACTIVITY.JAVA

package com.example.viraj.destiniapp;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {
    // TODO: Steps 4 & 8 - Declare member variables here:
    private TextView mstoryTextView;
    private Button mTopButton, mBottomButton;
    private int nStoryIndex = 1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);
        // TODO: Step 5 - Wire up the 3 views from the layout to the member variables:
        mstoryTextView = findViewById(R.id.storyTextView);
        mTopButton = findViewById(R.id.buttonTop);
        mBottomButton = findViewById(R.id.buttonBottom);


        // TODO: Steps 6, 7, & 9 - Set a listener on the top button:

        mTopButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
               if (nStoryIndex==1 || nStoryIndex==2){
                mstoryTextView.setText(R.string.T3_Story);
                mTopButton.setText(R.string.T3_Ans1);
                mBottomButton.setText(R.string.T3_Ans2);
                   nStoryIndex = 3;
            }else if (nStoryIndex==3){
                   mstoryTextView.setText(R.string.T6_End);
                   mTopButton.setVisibility(view.GONE);
                   mBottomButton.setVisibility(view.GONE);
               }
              }
        });


        // TODO: Steps 6, 7, & 9 - Set a listener on the bottom button:
        mBottomButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (nStoryIndex == 1) {
                    mstoryTextView.setText(R.string.T2_Story);
                    mTopButton.setText(R.string.T2_Ans1);
                    mBottomButton.setText(R.string.T2_Ans2);
                    nStoryIndex = 2;
                } else if (nStoryIndex == 2) {
                    mstoryTextView.setText(R.string.T4_End);
                    mTopButton.setVisibility(view.GONE);
                    mBottomButton.setVisibility(view.GONE);
                }
                else  {
                    mstoryTextView.setText(R.string.T5_End);
                    mTopButton.setVisibility(view.GONE);
                    mBottomButton.setVisibility(view.GONE);
                }
            }
        });
    }
}

dimension xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <!-- Default screen margins, per the Android Design guidelines. -->
    <dimen name="activity_horizontal_margin">16dp</dimen>
    <dimen name="activity_vertical_margin">16dp</dimen>
</resources>

dimension 8210 dp xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <!-- Example customization of dimensions originally defined in res/values/dimens.xml
         (such as screen margins) for screens with more than 820dp of available width. This
         would include 7" and 10" devices in landscape (~960dp and ~1280dp respectively). -->
    <dimen name="activity_horizontal_margin">64dp</dimen>
</resources>

string.xml

<resources>
    <string name="app_name">Destini</string>

    <string name="T1_Story">Your car has blown a tire on a winding road in the middle of nowhere with no cell phone reception. You decide to hitchhike. A rusty pickup truck rumbles to a stop next to you. A man with a wide brimmed hat with soulless eyes opens the passenger door for you and asks: \"Need a ride, boy?\". </string>
    <string name="T1_Ans1">I\'ll hop in. Thanks for the help! </string>
    <string name="T1_Ans2">Better ask him if he\'s a murderer first. </string>


    <string name="T2_Story">He nods slowly, unphased by the question.</string>
    <string name="T2_Ans1">At least he\'s honest. I\'ll climb in.</string>
    <string name="T2_Ans2">Wait, I know how to change a tire.</string>


    <string name="T3_Story">As you begin to drive, the stranger starts talking about his relationship with his mother. He gets angrier and angrier by the minute. He asks you to open the glovebox. Inside you find a bloody knife, two severed fingers, and a cassette tape of Elton John. He reaches for the glove box.</string>
    <string name="T3_Ans1">I love Elton John! Hand him the cassette tape.</string>
    <string name="T3_Ans2">It\'s him or me! You take the knife and stab him.</string>


    <string name="T4_End">What? Such a cop out! Did you know traffic accidents are the second leading cause of accidental death for most adult age groups?</string>
    <string name="T5_End">As you smash through the guardrail and careen towards the jagged rocks below you reflect on the dubious wisdom of stabbing someone while they are driving a car you are in.</string>
    <string name="T6_End">You bond with the murderer while crooning verses of "Can you feel the love tonight". He drops you off at the next town. Before you go he asks you if you know any good places to dump bodies. You reply: \"Try the pier.\"</string>

</resources>
Share:

Wednesday, 31 January 2018

imp xml

style.xml
<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>

        <item name="windowNoTitle">true</item>
        <item name="windowActionBar">false</item>
        <item name="android:windowFullscreen">true</item>
        <item name="android:windowContentOverlay">@null</item>

    </style>

</resources>



DIMENSION.XML 
<resources>
    <!-- Default screen margins, per the Android Design guidelines. -->
    <dimen name="activity_horizontal_margin">16dp</dimen>
    <dimen name="activity_vertical_margin">16dp</dimen>
</resources>


DIMENSION W820.XML

<resources>
    <!-- Example customization of dimensions originally defined in res/values/dimens.xml
         (such as screen margins) for screens with more than 820dp of available width. This
         would include 7" and 10" devices in landscape (~960dp and ~1280dp respectively). -->
    <dimen name="activity_horizontal_margin">64dp</dimen>
</resources>

MAIN XML 

<?xml version="1.0" encoding="utf-8"?>
<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="com.londonappbrewery.destini.MainActivity"
    android:background="@drawable/background">



    <TextView
        android:id="@+id/storyTextView"
        android:text="@string/T1_Story"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true"
        android:textSize="24sp"
        android:textColor="#ffffffff"
        />

    <Button
        android:id="@+id/buttonTop"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/T1_Ans1"
        android:layout_alignParentBottom="true"
        android:layout_marginBottom="61dp"
        android:background="#e74c3c"
        android:textColor="#ecf0f1"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true"
        android:textSize="15sp"
        />

    <Button
        android:id="@+id/buttonBottom"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/T1_Ans2"
        android:layout_alignParentBottom="true"
        android:layout_alignLeft="@+id/buttonTop"
        android:layout_alignStart="@+id/buttonTop"
        android:layout_alignRight="@+id/buttonTop"
        android:layout_alignEnd="@+id/buttonTop"
        android:background="#3498db"
        android:textColor="#ecf0f1"
        android:textSize="15sp"/>



</RelativeLayout>

Share:

Search This Blog

Popular Posts

Pages

how to make crores from 1 lakh in stock markets in 1 year

how to make crores from 1 lakh in stock markets in 1 year

Blogger Tutorials

Blogger Templates

Sample Text

Copyright © ANDROID TUTORIAL CODE | Powered by Blogger
Design by SimpleWpThemes | Blogger Theme by NewBloggerThemes.com & Distributed By Protemplateslab