-
Notifications
You must be signed in to change notification settings - Fork 0
/
FifteenActivity.java
158 lines (133 loc) · 5.93 KB
/
FifteenActivity.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
package test.ojassoft.com.ys;
import android.app.ProgressDialog;
import android.content.Intent;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Spinner;
import android.widget.TextView;
public class FifteenActivity extends AppCompatActivity implements AdapterView.OnItemSelectedListener {
Toolbar toolbar;
String size[]={"M","L","XL","XXL"};
String color[]={"Red","Black","Blue"};
ImageView imageView;
TextView textView;
TextView textView1;
TextView textView2;
Button button;
ProgressDialog pd;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_fifteen);
pd=new ProgressDialog(FifteenActivity.this);
pd.setTitle("Loading Activity");
pd.setMessage("Please Wait ...");
pd.setMax(5);
pd.setIndeterminate(false);
pd.setProgressStyle(ProgressDialog.STYLE_SPINNER);
toolbar=(Toolbar) findViewById(R.id.toolbar);
toolbar.setTitle("SHOPPING.COM");
setSupportActionBar(toolbar);
button=(Button) findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
new AsyncTask<Integer, Long, Boolean>() {
@Override
protected Boolean doInBackground(Integer... params) {
publishProgress(0L);
long start = System.currentTimeMillis();
long waitTime = params[0] * 1000;
try {
while (System.currentTimeMillis() - start < waitTime) {
Thread.sleep(500);
publishProgress(System.currentTimeMillis() - start);
}
} catch (Exception e) {
return false;
}
return true;
}
@Override
protected void onProgressUpdate(Long... values) {
if (values[0] == 0) {
pd.show();
} else {
pd.setProgress((int) (values[0] / 1000));
}
}
@Override
protected void onPostExecute(Boolean result) {
pd.dismiss();
Intent intent=new Intent(FifteenActivity.this,EleventhActivity.class);
startActivity(intent);
}
}.execute(5);}});
imageView = (ImageView) findViewById(R.id.imageview);
textView = (TextView) findViewById(R.id.textview);
textView1 = (TextView) findViewById(R.id.textview1);
textView2 = (TextView) findViewById(R.id.textview2);
Intent intent = getIntent();
imageView.setImageBitmap(decodeSampledBitmapFromResource(getResources(),intent.getIntExtra("imageview",0),100,100));
String itemN = intent.getStringExtra("textview");
textView.setText(itemN);
Spinner spinner = (Spinner) findViewById(R.id.spinner);
spinner.setOnItemSelectedListener(this);
Spinner spinner1=(Spinner) findViewById(R.id.spinner1);
spinner1.setOnItemSelectedListener(this);
ArrayAdapter aa = new ArrayAdapter(this, android.R.layout.simple_spinner_item, size);
ArrayAdapter aaa=new ArrayAdapter(this,android.R.layout.simple_spinner_item,color);
aa.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
//Setting the ArrayAdapter data on the Spinner
spinner.setAdapter(aa);
spinner1.setAdapter(aaa);
}
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1, int position, long id) {
// Toast.makeText(getApplicationContext(),size[position],Toast.LENGTH_LONG).show();
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
public static Bitmap decodeSampledBitmapFromResource(Resources res, int resId,
int reqWidth, int reqHeight) {
// First decode with inJustDecodeBounds=true to check dimensions
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeResource(res, resId, options);
// Calculate inSampleSize
options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);
// Decode bitmap with inSampleSize set
options.inJustDecodeBounds = false;
return BitmapFactory.decodeResource(res, resId, options);
}
public static int calculateInSampleSize(
BitmapFactory.Options options, int reqWidth, int reqHeight) {
// Raw height and width of image
final int height = options.outHeight;
final int width = options.outWidth;
int inSampleSize = 1;
if (height > reqHeight || width > reqWidth) {
final int halfHeight = height / 2;
final int halfWidth = width / 2;
// Calculate the largest inSampleSize value that is a power of 2 and keeps both
// height and width larger than the requested height and width.
while ((halfHeight / inSampleSize) > reqHeight
&& (halfWidth / inSampleSize) > reqWidth) {
inSampleSize *= 2;
}
}
return inSampleSize;
}
}//