Skip to content

Instantly share code, notes, and snippets.

@penkzhou
Created April 5, 2014 08:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save penkzhou/9989190 to your computer and use it in GitHub Desktop.
Save penkzhou/9989190 to your computer and use it in GitHub Desktop.
public class Photo extends Activity implements View.OnClickListener{
private ImageView ivImage ;
private Button btnSet;
private ImageButton ibSelect;
private Bitmap bitmap;
private Intent i;
final static int cameraData = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.photo);
initialVars();
InputStream is = getResources().openRawResource(R.drawable.apple_logo);
bitmap = BitmapFactory.decodeStream(is);
btnSet.setOnClickListener(this);
ibSelect.setOnClickListener(this);
}
private void initialVars() {
ivImage = (ImageView)findViewById(R.id.ivImage);
ibSelect = (ImageButton)findViewById(R.id.ibSelect);
btnSet = (Button)findViewById(R.id.btnSetWall);
}
@Override
public void onClick(View v) {
switch (v.getId()){
case R.id.btnSetWall:
try {
WallpaperManager.getInstance(this).setBitmap(bitmap);
} catch (IOException e) {
e.printStackTrace();
}
break;
case R.id.ibSelect:
i = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(i,cameraData);
break;
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK){
Bundle imgdata = data.getExtras();
bitmap = (Bitmap)imgdata.get("data");
ivImage.setImageBitmap(bitmap);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment