You are on page 1of 7

MAIN ACTIVITY(admin/1234)

package com.example.password;

import
import
import
import
import
import
import
import
import
import
import
import
import
import

android.app.Activity;
android.content.Intent;
android.graphics.Color;
android.os.Bundle;
android.os.Handler;
android.text.InputType;
android.view.Menu;
android.view.MenuItem;
android.view.View;
android.view.View.OnClickListener;
android.widget.Button;
android.widget.EditText;
android.widget.ProgressBar;
android.widget.Toast;

public class MainActivity extends Activity {


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button enter = (Button)findViewById(R.id.button1);
Button clear = (Button)findViewById(R.id.button2);
final ProgressBar pg = (ProgressBar)findViewById(R.id.progressBar1);
pg.setVisibility(View.INVISIBLE);
final EditText uzre = (EditText)findViewById(R.id.editText1);
final EditText pass = (EditText)findViewById(R.id.editText2);
pass.setActivated(true);
pass.setHint("Password");
pass.setInputType(InputType.TYPE_CLASS_TEXT |
InputType.TYPE_TEXT_VARIATION_PASSWORD);
enter.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
String pash = pass.getText().toString();
String usher = uzre.getText().toString();
if(usher.equals("admin") && pash.equals("1234")){
Toast.makeText(getApplicationContext(), "Logging in.
Please Wait",Toast.LENGTH_SHORT).show();
pg.setVisibility(View.VISIBLE);
int x = 3000;
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
Intent intent = new Intent(MainActivity.this,
SecondActivity.class);

startActivity(intent);
uzre.setTextColor(Color.GREEN);
pass.setTextColor(Color.GREEN);
}
}, x);

}
if(usher.isEmpty()&&pash.isEmpty()){
Toast.makeText(getApplicationContext(), "Please
provide anything",Toast.LENGTH_SHORT).show();
}
if(usher.isEmpty()){
Toast.makeText(getApplicationContext(), "Please provide
a Username",Toast.LENGTH_SHORT).show();
}
if(pash.isEmpty()){

Toast.makeText(getApplicationContext(), "Please provide


a Password",Toast.LENGTH_SHORT).show();
}
else{
uzre.setText("");
pass.setText("");
}
}
});
clear.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
uzre.setText("");
pass.setText("");
}
});

@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;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}

----------------------------------------------------------------------------------------------------------------------------------------<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.example.password.MainActivity"
android:background="@drawable/download">
<EditText
android:id="@+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/button1"
android:layout_centerHorizontal="true"
android:ems="10"
android:inputType="textPassword" />
<EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/editText2"

android:layout_alignLeft="@+id/editText2"
android:layout_alignRight="@+id/editText2"
android:layout_marginBottom="25dp"
android:ems="10" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/button1"
android:layout_alignTop="@+id/button1"
android:layout_marginTop="79dp"
android:text="Clear" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="178dp"
android:text="Enter" />
<ProgressBar
android:id="@+id/progressBar1"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="21dp" />
</RelativeLayout>

SECOND ACTIVITY
package com.example.password;
import
import
import
import
import
import
import
import
import
import

android.app.Activity;
android.graphics.Color;
android.os.Bundle;
android.view.Menu;
android.view.MenuItem;
android.view.View;
android.view.View.OnClickListener;
android.widget.Button;
android.widget.SeekBar;
android.widget.TextView;

public class SecondActivity extends Activity {


int howRed;
int howGreen;
int howBlue;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.second);
getIntent();
final SeekBar sbR = (SeekBar) findViewById(R.id.seekBar1);
final SeekBar sbG = (SeekBar) findViewById(R.id.seekBar2);
final SeekBar sbB = (SeekBar) findViewById(R.id.seekBar3);
final TextView tv = (TextView) findViewById(R.id.textView1);
final TextView tvr = (TextView) findViewById(R.id.textView2);
final TextView tvg = (TextView) findViewById(R.id.textView3);
final TextView tvb = (TextView) findViewById(R.id.textView4);
Button yell = (Button) findViewById(R.id.button1);
Button Viol = (Button) findViewById(R.id.button2);
Button Pink = (Button) findViewById(R.id.button3);
sbR.setMax(225);
sbG.setMax(225);
sbB.setMax(225);

yell.setBackgroundColor(Color.YELLOW);
Viol.setBackgroundColor(Color.rgb(152, 51, 225));
Pink.setBackgroundColor(Color.rgb(225, 0, 125));

yell.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
sbR.setProgress(225);
sbG.setProgress(225);
sbB.setProgress(0);
}
});
Viol.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
sbR.setProgress(127);
sbG.setProgress(0);
sbB.setProgress(225);
}
});
Pink.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
sbR.setProgress(225);
sbG.setProgress(102);
sbB.setProgress(178);

}
});
sbR.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
howRed = progress;
bgcolor() ;
tv.setText(howWhat());
tvr.setText("R= "+howRed);
}
});
sbG.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
howGreen = progress;
bgcolor() ;
tv.setText(howWhat());
tvg.setText("G= "+howGreen);
}
});

sbB.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
howBlue = progress;

}
});

bgcolor() ;
tv.setText(howWhat());
tvb.setText("B= "+howBlue);

}
private void bgcolor() {
int color = Color.rgb(howRed,howGreen, howBlue);
View scre = this.getWindow().getDecorView();
scre.setBackgroundColor(color);
}
private String howWhat(){
String howWhy = null;
if(howRed>howBlue && howRed>howGreen){
howWhy = "Too Red";

}
if(howBlue>howRed && howBlue>howGreen){
howWhy = "Too Blue";

}
if(howGreen>howRed && howGreen>howBlue){
howWhy = "Too Green";
}
return howWhy;
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.second, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
<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.example.asadaa.MainActivity" >
<SeekBar
android:id="@+id/seekBar1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_marginBottom="189dp" />
<SeekBar
android:id="@+id/seekBar2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignTop="@+id/seekBar1"
android:layout_marginTop="41dp" />
<SeekBar
android:id="@+id/seekBar3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/seekBar2"
android:layout_marginTop="14dp" />
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/textView2"
android:layout_alignLeft="@+id/textView1"
android:orientation="vertical" >
</LinearLayout>
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView2"
android:layout_below="@+id/linearLayout1"
android:layout_marginTop="25dp"
android:text="G = 0"
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView3"
android:layout_below="@+id/textView3"
android:layout_marginTop="24dp"
android:text="B = 0"
android:textAppearance="?android:attr/textAppearanceSmall" />
<Button
android:id="@+id/button1"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/button2"
android:layout_alignBottom="@+id/button2"
android:layout_alignParentLeft="true"
android:text="Yellow" />
<Button
android:id="@+id/button3"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/button2"
android:layout_alignBottom="@+id/button2"
android:layout_alignParentRight="true"
android:text="Pink" />

<Button
android:id="@+id/button2"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/seekBar3"
android:layout_centerHorizontal="true"
android:layout_marginTop="34dp"
android:text="Violet" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textView1"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:text="R = 0"
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="41dp"
android:text="Neutral"
android:textAppearance="?android:attr/textAppearanceLarge" />
</RelativeLayout>