You may want to create an activity that sits on top of another but you want the former to be invisible (for instance, you want to encapsulate something that involves a call to startActivityForResult, which was my case).
In my particular case I wanted to be able to pick an image from the Gallery or the Camera and after that I wanted to crop the obtained image and return the result to an activity.
Manifest
<activity
android:name="package.activities.GetImageActivity"
android:theme="@style/Theme.Transparent"
android:configChanges="orientation"
android:label="@string/title_activity_get_image"
android:screenOrientation="portrait" >
</activity>
styles
<style name="Theme.Transparent" parent="android:Theme">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsFloating">true</item>
<item name="android:backgroundDimEnabled">false</item>
</style>
Class
public class GetImageActivity extends BaseActivity {
private static final int REQUEST_CODE_CROP_IMAGE = 300;
private Uri outputFileUri;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_get_image);
ImagePicker imagePicker = new ImagePicker(this);
imagePicker.setOwnerActivity(this);
imagePicker.show();
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent imageReturnedIntent) {
super.onActivityResult(requestCode, resultCode, imageReturnedIntent);
switch (requestCode) {
case ImagePicker.SELECT_PHOTO_FROM_GALLERY:
cropGalleryImage(resultCode, imageReturnedIntent);
break;
case ImagePicker.SELECT_PHOTO_FROM_CAMERA:
cropCameraImage(resultCode);
break;
case REQUEST_CODE_CROP_IMAGE:
String path = imageReturnedIntent.getStringExtra(CropImage.IMAGE_PATH);
Intent intent = getIntent();
intent.putExtra(CropImage.IMAGE_PATH, path);
this.setResult(RESULT_OK, intent);
finish();
break;
}
}
}
Layout
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
</LinearLayout>
No hay comentarios:
Publicar un comentario