2

My app is fullscreen so I use this in my style.xml:

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowFullscreen">true</item>
</style>

I implemented a notification for uploading. Now how do you show the status bar temporarily like when swiping down the app a transparent version of it shows.

-EDIT-

public class UploadService extends IntentService {
private NotificationManager mNotificationManager;

public UploadService() {
    super("UploadService");
}

@Override
public void onDestroy() {
    super.onDestroy();
    mNotificationManager.cancel(0);
}

@Override
protected void onHandleIntent(Intent intent) {
    Resources resources = getResources();
    final Notification uploadNotification = new NotificationCompat.Builder(this)
            .setTicker(resources.getString(R.string.upload))
            .setSmallIcon(android.R.drawable.ic_menu_upload)
            .setContentTitle(resources.getString(R.string.app_name))
            .setContentText(resources.getString(R.string.upload_progress))
            .setProgress(0, 0, true)
            .build();


    final Notification failedNotification = new NotificationCompat.Builder(this)
            .setSmallIcon(android.R.drawable.ic_menu_report_image)
            .setTicker(resources.getString(R.string.upload_failed))
            .setContentTitle(resources.getString(R.string.upload_failed))
            .setAutoCancel(true)
            .build();

    mNotificationManager = (NotificationManager)
            getSystemService(NOTIFICATION_SERVICE);

    mNotificationManager.notify(0, uploadNotification);

    ParseFile parseFile = null;
    boolean success = true;

    Bundle bundle = intent.getBundleExtra("bundleImage");

    String userID = bundle.getString("userID");
    ParseUser parseUser = ParseUser.createWithoutData(ParseUser.class, userID);

    String image = bundle.getString("imagePath");
    Uri imageUri = Uri.parse(image);

    String filename = bundle.getString("imageName");

    ByteArrayOutputStream baos;
    InputStream is;
    try {
        baos = new ByteArrayOutputStream();
        is = getContentResolver().openInputStream(imageUri);
        Bitmap bitmap = BitmapFactory.decodeStream(is);
        bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);

        parseFile = new ParseFile(filename, baos.toByteArray());
        baos.close();
        is.close();
    } catch (Exception e) {
        success = false;

        mNotificationManager.notify(0, failedNotification);
    }

    if (success) {
        Frames frames = new Frames();
        frames.setUploader(parseUser);
        frames.setFrameFile(parseFile);
        try {
            frames.save();
        } catch (ParseException e) {
            mNotificationManager.notify(0, failedNotification);
        }
    }
}
Jan
  • 3,393
  • 4
  • 21
  • 47

1 Answers1

1

You can override the onTouchEvent and just add/clear the FLAG_FULLSCREEN flag.

public boolean mIsVisible = false;
...
...
@Override
public boolean onTouchEvent(MotionEvent event)
{
  if ( event.getAction() == MotionEvent.ACTION_DOWN )
  {
    if ( mIsVisible)
      getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
    else
      getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);

    mIsVisible = !mIsVisible;
  }

  return super.onTouchEvent(event);
}
Piyush
  • 18,895
  • 5
  • 32
  • 63
Christian Abella
  • 5,747
  • 2
  • 30
  • 42
  • what if i use it in my service? – Jan Apr 21 '15 at 05:36
  • Your service will not have a pointer to your Activity. But you can send a message from your service to your activity when to show/hide the status bar. In your Activity class you can implement the hiding/showing of status bar when your receive the message from your Service. – Christian Abella Apr 21 '15 at 05:38
  • if it fails. i just show the status bar temporarily – Jan Apr 21 '15 at 05:57
  • you can do this. http://stackoverflow.com/questions/12997463/send-intent-from-service-to-activity to send message from your service to your activity. – Christian Abella Apr 21 '15 at 05:59