Twitter Facebook Delicious Digg Stumbleupon Favorites More

Saturday, 16 December 2017

to do app

package com.example.viraj.app_honey_do_list_sharedpreference;

import android.content.Context;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;

public class MainActivity extends AppCompatActivity {
    private Button button;
    private EditText editText_message;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        editText_message = (EditText) findViewById(R.id.id_entertext);
        button = (Button) findViewById(R.id.id_button);

        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //logic goes here
                if (!editText_message.getText().toString().equals("")) {
                    String message = editText_message.getText().toString();
                    writetofile(message);
                } else {
                    //do nothing for now
                }

            }
        });
        try {
            //-----------------------------
            if (readfromfile() != null) {
                editText_message.setText(readfromfile());
            }//----------------------------
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    //------------------------
    private void writetofile(String message) {
        try {
            //-------------------------itna hi likha he
            OutputStreamWriter outputStreamWriter = new OutputStreamWriter(openFileOutput("todolist.txt", Context.MODE_PRIVATE));
            outputStreamWriter.write(message);
            outputStreamWriter.close();//alwas close your stream
            //-----------------------------
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    private String readfromfile() throws IOException {
        String result = "";
        InputStream inputStream = openFileInput("todolist.txt");

        if (inputStream != null) {
            InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
            //we need buffer behav like a bucket
            BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
            //empty string to to do things
            String tempstring = "";
            StringBuilder stringBuilder = new StringBuilder();
            //temp string me read hone jaayega
            while ((tempstring = bufferedReader.readLine()) != null) {
                stringBuilder.append(tempstring);
            }
            inputStream.close();
            result = stringBuilder.toString();
        }

        return result;
    }
}



<?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.example.viraj.app_honey_do_list_sharedpreference.MainActivity">

    <EditText
        android:id="@+id/id_entertext"
        android:layout_width="276dp"
        android:layout_height="282dp"
        android:layout_marginBottom="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:ems="10"
        android:hint="ENTER YOUT LIST"
        android:inputType="textMultiLine"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.084" />

    <Button
        android:id="@+id/id_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button"
        tools:layout_editor_absoluteX="148dp"
        tools:layout_editor_absoluteY="406dp" />
</android.support.constraint.ConstraintLayout>

Share:

Friday, 15 December 2017

shared preferences in android

package com.example.viraj.sharedpreferences;

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

public class MainActivity extends AppCompatActivity {
    private Button savebutton;
    private EditText entertext;
    private TextView resultdisplay;
    private SharedPreferences myPref;
//information isme store kart he iss liy create kiya
    private static final String PREF_NAME = "MY_PREF_FILE";

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

        savebutton = (Button) findViewById(R.id.id_savedata);
        entertext = (EditText) findViewById(R.id.id_entersomething);
        resultdisplay = (TextView) findViewById(R.id.id_resulttextview);

        savebutton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                myPref = getSharedPreferences(PREF_NAME, 0);
                SharedPreferences.Editor editor = myPref.edit();
//editor liya our save kiya
                editor.putString("key_messgae_ki_he", entertext.getText().toString());
                //save commit
                editor.commit();

            }

        });
//get data back
        SharedPreferences pref = getSharedPreferences(PREF_NAME, 0);//level o he
        if (pref.contains("key_messgae_ki_he")) {
            String message = pref.getString("key_messgae_ki_he", "not found");
            resultdisplay.setText("MESSAGE" + message);
        }

    }
}

<?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.example.viraj.sharedpreferences.MainActivity">

    <EditText
        android:id="@+id/id_entersomething"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="48dp"
        android:ems="10"
        android:hint="ENTER SOMETHING"
        android:inputType="textPersonName"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.503"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <Button
        android:id="@+id/id_savedata"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="52dp"
        android:text="Button"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/id_entersomething" />

    <TextView
        android:id="@+id/id_resulttextview"
        android:layout_width="252dp"
        android:layout_height="28dp"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="60dp"
        android:text="TextView"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/id_savedata" />

    <RatingBar
        android:id="@+id/ratingBar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
</android.support.constraint.ConstraintLayout>


Share:

Sunday, 10 December 2017

MUSIC PLAYER APP


Share:

basic play mp3 part 3

package com.example.viraj.mediaplayerapp;

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.SeekBar;
import android.widget.Toast;

//import static com.example.viraj.mediaplayerapp.R.raw.ashique;

public class MainActivity extends AppCompatActivity {
    private MediaPlayer mediaPlayer;
    private Button playbutton;
    private SeekBar M_seekBar;
    @Override    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        M_seekBar = (SeekBar) findViewById(R.id.id_seekbar);
        mediaPlayer = new MediaPlayer();
        mediaPlayer = MediaPlayer.create(MainActivity.this, R.raw.mercy);
        M_seekBar.setMax(mediaPlayer.getDuration());
//-------seekbar        M_seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override            public void onProgressChanged(SeekBar seekBar, int i_879, boolean b_123) {
                if (b_123) {
                    mediaPlayer.seekTo(i_879);
                }
            }

            @Override            public void onStartTrackingTouch(SeekBar seekBar) {

            }

            @Override            public void onStopTrackingTouch(SeekBar seekBar) {

            }
        });
        //----------------seekbar        //set on completion method-----------------        mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
            @Override            public void onCompletion(MediaPlayer mediaPlayer_mp) {
                int duration = mediaPlayer_mp.getDuration();
                String mduration = String.valueOf(duration / 1000);
                Toast.makeText(getApplicationContext(), "Duration" + mduration, Toast.LENGTH_LONG).show();
            }
        });

        //----------------------------        playbutton = (Button) findViewById(R.id.MusicPlay);
        playbutton.setOnClickListener(new View.OnClickListener() {
            @Override            public void onClick(View view) {
                if (mediaPlayer.isPlaying()) {
                    //stop music and give option                    pausemusic();
                } else {
                    startmusic();
                }
            }
        });

    }

    //create method in side of our class    public void pausemusic() {
        if (mediaPlayer != null)
            mediaPlayer.pause();
        playbutton.setText("PLAY MUSIC");
    }

    public void startmusic()

    {
        if (mediaPlayer != null) {
            mediaPlayer.start();
            playbutton.setText("PAUSE MUSIC");
        }

    }

    //memory consume karta he iss liye    @Override    protected void onDestroy() {
        if (mediaPlayer != null && mediaPlayer.isPlaying()) {
            mediaPlayer.stop();
            mediaPlayer.release();
            mediaPlayer = null;
        }
        super.onDestroy();
    }
}
Share:

basic play mp3 part 2

package com.example.viraj.mediaplayerapp;
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.Toast;
//import static com.example.viraj.mediaplayerapp.R.raw.ashique;

public class MainActivity extends AppCompatActivity {
    private MediaPlayer mediaPlayer;
    private Button playbutton;

    @Override    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mediaPlayer = new MediaPlayer();
        mediaPlayer = MediaPlayer.create(MainActivity.this,R.raw.mercy);

       //set on completion method-----------------        mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
    @Override    public void onCompletion(MediaPlayer mediaPlayer_mp) {
        int duration =mediaPlayer_mp.getDuration();
        String mduration=String.valueOf(duration/1000);
        Toast.makeText(getApplicationContext(),"Duration"+mduration,Toast.LENGTH_LONG).show();
    }
});

        //----------------------------
        playbutton = (Button) findViewById(R.id.MusicPlay);
        playbutton.setOnClickListener(new View.OnClickListener() {
            @Override            public void onClick(View view) {
                if (mediaPlayer.isPlaying()) {
                    //stop music and give option                    pausemusic();
                }
                else                {
                    startmusic();
                }
            }
        });

    }
    //create method in side of our class    public void pausemusic() {
        if (mediaPlayer != null)
            mediaPlayer.pause();
        playbutton.setText("PLAY MUSIC");
    }

    public void startmusic()

    {
        if (mediaPlayer != null) {
            mediaPlayer.start();
            playbutton.setText("PAUSE MUSIC");
        }

    }//memory consume karta he iss liye    @Override    protected void onDestroy() {
       if (mediaPlayer!=null && mediaPlayer.isPlaying())
       {
           mediaPlayer.stop();
           mediaPlayer.release();
           mediaPlayer=null;
       }
        super.onDestroy();
    }
}
Share:

BASIC play mp3 android studio

create raw folder  value resource type raw select kare

package com.example.viraj.mediaplayerapp;

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

//import static com.example.viraj.mediaplayerapp.R.raw.ashique;


public class MainActivity extends AppCompatActivity {
    private MediaPlayer mediaPlayer;
    private Button playbutton;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mediaPlayer = new MediaPlayer();
        mediaPlayer = MediaPlayer.create(MainActivity.this,R.raw.haa);

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

    }
    //create method in side of our class
    public void pausemusic() {
        if (mediaPlayer != null)
            mediaPlayer.pause();
        playbutton.setText("PLAY MUSIC");
    }

    public void startmusic()

    {
        if (mediaPlayer != null) {
            mediaPlayer.start();
            playbutton.setText("PAUSE MUSIC");
        }

    }
}



<?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.example.viraj.mediaplayerapp.MainActivity">

    <Button
        android:id="@+id/MusicPlay"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:text="PLAY"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>

Share:

Thursday, 30 November 2017

dog cat app


PART 1 BASIC-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
package com.example.viraj.petbioapp;

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 dog;
    private ImageView cat;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        dog = (ImageView) findViewById(R.id.id_dog);
        cat = (ImageView) findViewById(R.id.id_cat);

        dog.setOnClickListener(this);
        cat.setOnClickListener(this);

    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.id_dog:
                Toast.makeText(getApplicationContext(), "dog clicked", Toast.LENGTH_LONG).show();
                break;
            case R.id.id_cat:
                Toast.makeText(getApplicationContext(), "cat clicked", Toast.LENGTH_LONG).show();
                break;
        }
    }
}
PART 2-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
create another bio activity single page to display either dog or either cat and its name
main activity
package com.example.viraj.petbioapp;

import android.content.Intent;
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 dog;
    private ImageView cat;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        dog = (ImageView) findViewById(R.id.id_dog);
        cat = (ImageView) findViewById(R.id.id_cat);

        dog.setOnClickListener(this);
        cat.setOnClickListener(this);

    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.id_dog:
               // Toast.makeText(getApplicationContext(), "dog clicked", Toast.LENGTH_LONG).show();
                Intent dogintent=new Intent(getApplicationContext(),BioActivity.class);
               dogintent.putExtra("key_is_name","DOG");
               dogintent.putExtra("key_is_Decr","Dog is very lovely animal");
               startActivity(dogintent);
                break;
            case R.id.id_cat:
                //Toast.makeText(getApplicationContext(), "cat clicked", Toast.LENGTH_LONG).show();
               Intent catintent = new Intent(getApplicationContext(),BioActivity.class);
                catintent.putExtra("key_is_name","CAT");
                catintent.putExtra("key_is_Decr","Cat is very lovely animal");
                startActivity(catintent);
                break;
        }
    }
}

<?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.example.viraj.petbioapp.MainActivity">

    <ImageView
        android:id="@+id/id_dog"
        android:layout_width="172dp"
        android:layout_height="141dp"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="52dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:srcCompat="@drawable/dogimage" />

    <ImageView
        android:id="@+id/id_cat"
        android:layout_width="172dp"
        android:layout_height="185dp"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="96dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/id_dog"
        app:srcCompat="@drawable/cat" />
</android.support.constraint.ConstraintLayout>



secondpage.java////////////////////////////////////////////////////////////

package com.example.viraj.petbioapp;

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

public class BioActivity extends AppCompatActivity {
    private ImageView imageView_all;
    private TextView txt1_name, txt2_desc;
private Bundle extras;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_bio);

        imageView_all = (ImageView) findViewById(R.id.id_imageall);
        txt1_name = (TextView) findViewById(R.id.id_name);
        txt2_desc = (TextView) findViewById(R.id.id_description);

        extras=getIntent().getExtras();
        if(extras!=null)
        {
            String name=extras.getString("key_is_name");
            String desc=extras.getString("key_is_Decr");
            setup(name,desc);
        }

    }
    public void setup(String name,String desc)
    {
if (name.equals("DOG"))
{
    imageView_all.setImageDrawable(getDrawable(R.drawable.dogimage));
    txt1_name.setText(name);
    txt2_desc.setText(desc);
//we show dog stuff
}
else if(name.equals("CAT"))
{
    //we show cat stuff
     imageView_all.setImageDrawable(getDrawable(R.drawable.cat));
    txt1_name.setText(name);
    txt2_desc.setText(desc);
}
    }
}

<?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.example.viraj.petbioapp.BioActivity">

    <ImageView
        android:id="@+id/id_imageall"
        android:layout_width="294dp"
        android:layout_height="214dp"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="16dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.422"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:srcCompat="@mipmap/ic_launcher" />

    <TextView
        android:id="@+id/id_name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="124dp"
        android:text="TextView"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/id_imageall" />

    <TextView
        android:id="@+id/id_description"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="84dp"
        android:text="TextView"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/id_name" />
</android.support.constraint.ConstraintLayout>


Share:

Intent Activity For Result

Intent Activity For Result


first page

package com.gohool.showactivity.showactivity;

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

import static android.app.Activity.RESULT_OK;

public class FirstActivity extends AppCompatActivity {
    private Button goToSecondButton;
    private final int REQUEST_CODE = 2;

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

        goToSecondButton = (Button) findViewById(R.id.showButtonID);
        goToSecondButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //Code goes here
                Intent intent = new Intent(FirstActivity.this, SecondActivity.class);
                intent.putExtra("Message", "Hello From First Activity");
                intent.putExtra("SecondMessage", "Hello Again");
                intent.putExtra("Value", 123);

                //startActivity(intent);
                startActivityForResult(intent, REQUEST_CODE);
                //startActivity(new Intent(FirstActivity.this, SecondActivity.class));
            }
        });
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == REQUEST_CODE) {
             if (resultCode == RESULT_OK) {
                  String result = data.getStringExtra("returnData");

                 Toast.makeText(FirstActivity.this, result, Toast.LENGTH_LONG).show();


             }
        }


    }
}





second activity  

package com.gohool.showactivity.showactivity;

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

public class SecondActivity extends AppCompatActivity {

    private TextView showMessage;
    private Button backButton;

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

        Bundle extras = getIntent().getExtras();

        showMessage = (TextView) findViewById(R.id.messageTextView);
        backButton = (Button) findViewById(R.id.goBackButtonID);

        //check
        if (extras != null) {
            String message = extras.getString("SecondMessage");
            int myInt = extras.getInt("Value");

            showMessage.setText("Message is" + message + " and : " + String.valueOf(myInt));
        }


        backButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //code goes here
                Intent returnIntent = getIntent();
                returnIntent.putExtra("returnData", "From SecondActivity");
                setResult(RESULT_OK, returnIntent);
                finish();

            }
        });
    }
}

Share:

Tuesday, 28 November 2017

Tip calculator

package com.example.viraj.tipcalculator;

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

public class MainActivity extends AppCompatActivity implements View.OnClickListener {
    private EditText enteramount;
    private SeekBar seekbar_tip_sleekbar;
    private TextView seekbar_text_amount;
    private Button caluclate_button;
    private TextView text_your_tip_is;
    private TextView total_amount_final;

    private int seekbarpercentage;
    private float enterbillfloat;

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

        enteramount = (EditText) findViewById(R.id.id_enteramount);
        seekbar_tip_sleekbar = (SeekBar) findViewById(R.id.id_seekbar);
        seekbar_text_amount = (TextView) findViewById(R.id.id_text_seekpercentage);
        caluclate_button = (Button) findViewById(R.id.id_submitbutton);
        text_your_tip_is = (TextView) findViewById(R.id.id_text_yourtip_is);
        total_amount_final = (TextView) findViewById(R.id.id_text_totalamount);
        //----------------------------
        seekbar_text_amount.setText("YOU SELECT " + seekbar_tip_sleekbar.getProgress() + "%");
        //-----------------------------
        caluclate_button.setOnClickListener(this);
        //-----------------------------
        seekbar_tip_sleekbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {

            @Override
            public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
                seekbar_text_amount.setText("YOU SELECT " + String.valueOf(seekbar_tip_sleekbar.getProgress()) + "%");
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {
                Toast.makeText(getApplicationContext(), "START", Toast.LENGTH_LONG).show();
            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {
                seekbarpercentage = seekbar_tip_sleekbar.getProgress();
                //Toast.makeText(getApplicationContext(), "STOP", Toast.LENGTH_LONG).show();
            }
        });
    }

    //-----------------------------
    @Override
    public void onClick(View view) {
        calculate();
    }

    public void calculate() {
        float result = 0.0f;
        if (!enteramount.getText().toString().equals("")) {

            enterbillfloat = Float.parseFloat(enteramount.getText().toString());
            result=(enterbillfloat*seekbarpercentage/100);
            text_your_tip_is.setText("TIP ->" + String.valueOf(result));

            total_amount_final.setText("TOTAL AMOUNT IS ->"+ String.valueOf(enterbillfloat + result)+"- RS");

        } else {
Toast.makeText(getApplicationContext(), "PLZ ENTER AMOUNT", Toast.LENGTH_LONG).show();
        }

    }
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

<?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.example.viraj.tipcalculator.MainActivity">

    <EditText
        android:id="@+id/id_enteramount"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="16dp"
        android:ems="10"
        android:hint="Enter amount"
        android:inputType="number"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.503"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="32dp"
        android:text="SELECT TIP PERCENTAGE"
        android:textSize="24sp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/id_enteramount" />

    <SeekBar
        android:id="@+id/id_seekbar"
        android:layout_width="297dp"
        android:layout_height="26dp"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="32dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.507"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/textView" />

    <TextView
        android:id="@+id/id_text_seekpercentage"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="36dp"
        android:text="0%"
        android:textSize="24sp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/id_seekbar" />

    <Button
        android:id="@+id/id_submitbutton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="40dp"
        android:text="Button"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/id_text_seekpercentage" />

    <TextView
        android:id="@+id/id_text_yourtip_is"
        android:layout_width="130dp"
        android:layout_height="32dp"
        android:layout_marginEnd="208dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="28dp"
        android:text="YOUR TIP IS"
        android:textSize="24sp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/id_submitbutton" />

    <TextView
        android:id="@+id/id_text_totalamount"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="28dp"
        android:text="YOUR TOTAL AMOUNT IS "
        android:textSize="18sp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.116"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/id_text_yourtip_is" />
</android.support.constraint.ConstraintLayout>

Share:

Wednesday, 22 November 2017

Radio Button direct Click

package com.example.viraj.radiobuton;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {
    private RadioGroup radioGroup;
    private RadioButton radioButton;
   

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        radioGroup = (RadioGroup) findViewById(R.id.id_radioGroup);
       
        radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int i) {
                radioButton = (RadioButton) findViewById(i);

                switch (radioButton.getId()) {
                    case R.id.id_yes: {
                        if (radioButton.isChecked()) {
                            Toast.makeText(getApplicationContext(), "YES I AM COMING", Toast.LENGTH_LONG).show();
                        }

                    }
                    break;
                    case R.id.id_no: {
                        if (radioButton.isChecked()) ;
                        {
                            Toast.makeText(getApplicationContext(), "NO I AM NOT COMING", Toast.LENGTH_LONG).show();
                        }
                    }
                    break;
                    case R.id.id_maybe: {
                        if (radioButton.isChecked()) ;
                        {
                            Toast.makeText(getApplicationContext(), "MAY BE COMING", Toast.LENGTH_LONG).show();
                        }
                    }
                    break;
                }
            }
        });


    }
}


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:background="@drawable/one"
    tools:context="com.example.viraj.radiobuton.MainActivity">

    <RadioGroup
        android:id="@+id/id_radioGroup"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="52dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/textView">

        <RadioButton
            android:id="@+id/id_yes"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="YES" />

        <RadioButton
            android:id="@+id/id_no"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="NO" />

        <RadioButton
            android:id="@+id/id_maybe"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="MAY BE" />
    </RadioGroup>

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="76dp"
        android:text="ARE YOU COMING ...."
        android:textColor="@color/colorPrimaryDark"
        android:textSize="24sp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.503"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>

Share:

colour converter app

package com.gohool.trymeoriginal.trymeoriginal;


import android.graphics.Color;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;

import com.example.viraj.trymecolourconverter.R;

import java.util.Random;


public class MainActivity extends AppCompatActivity {

    private View windowView;
    private Button tryMeButton;
    private int[] colors;


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

        colors = new int[]{Color.CYAN, Color.GREEN, Color.RED, Color.BLUE, Color.BLACK, Color.DKGRAY,
                Color.LTGRAY, Color.MAGENTA, Color.YELLOW};

        windowView = findViewById(R.id.windowViewId);



        tryMeButton = (Button) findViewById(R.id.tryMeButton);
        tryMeButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                //Array length
                int colorArrayLength = colors.length;

                Random random = new Random();
                int randomNum = random.nextInt(colorArrayLength);

                windowView.setBackgroundColor(colors[randomNum]);

                Log.d("Random", String.valueOf(randomNum));
            }
        });







    }
}

Share:

Tuesday, 21 November 2017

meter to inch conversion

package com.example.viraj.metertoinch;

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

public class MainActivity extends AppCompatActivity {
    private EditText entertext;
    private Button button;
    private TextView resultdisplay;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        entertext = (EditText) findViewById(R.id.id_enter_meter);
        resultdisplay = (TextView) findViewById(R.id.id_text_display);
        button = (Button) findViewById(R.id.id_button);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //1m = (1/0.0254)″ = 39.37007874″
                //conversion data
                double multiplier = 39.37007874;
                double result = 0.0;
                //is se if txt not enter it display msg
                if (entertext.getText().toString().equals("")) {
                    resultdisplay.setText("PLZ ENTER VALID NO");
                    resultdisplay.setTextColor(Color.RED);
                } else {

                    double converter = Double.parseDouble(entertext.getText().toString());
                    result = converter * multiplier;
                    //resultdisplay.setText(Double.toString(result));
                    //decimal ke bad ko formate karne ke liye %.2f   % ke bad 2 decimal tak
                    resultdisplay.setText(String.format("%.2f", result) + "inch");
                }

            }
        });
    }
}

xml code

<?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.example.viraj.metertoinch.MainActivity">

    <EditText
        android:id="@+id/id_enter_meter"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="64dp"
        android:ems="10"
        android:hint="ENTER METER"
        android:inputType="textPersonName"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/textView" />

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="64dp"
        android:text="METER TO INCH CONVERTER"

        android:textColor="@android:color/holo_green_dark"
        android:textSize="24sp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <Button
        android:id="@+id/id_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="84dp"
        android:text="Button"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/id_enter_meter" />

    <TextView
        android:id="@+id/id_text_display"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="60dp"
        android:text="o"
        android:textSize="30dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/id_button" />
</android.support.constraint.ConstraintLayout>


Share:

basic things java

https://github.com/FahdSheraz/androidOSource/blob/master/MMethods/src/com/gohooljava/com/Main.java

package com.gohooljava.com;

public class Main {

    public static void main(String[] args) {

   // write your code here
        myName("Paulo");

        int finalResult = addNums(4, 5);

        System.out.println( finalResult);


       System.out.println( fullName("George", "The Man"));

       System.out.println(showChar('D'));


    }

    //Method
     public static void myName(String mName) {

        System.out.println(mName);

     }

     // Return an integer

     public static int addNums(int a, int b) {
        int result;
        result = a + b;
      //  System.out.println(" Sum = "  + (a + b));

        return result ; // (a+b)
     }

     //Return a string

    public static String fullName(String firstName, String lastName){

        return firstName + " " + lastName;
    }

    // Return Character
    public static char showChar(char c) {
        return c;
    }



}

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