Created
April 5, 2014 08:44
-
-
Save penkzhou/9989190 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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