I'm starting an activity from the background service by using following piece of code:
Intent intent = new Intent(getApplicationContext(),AlarmActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
But when I finish the activity by clicking the OK or Snooze button the app doesn't close but minimises instead.
When that minimised app is opened, the alarm starts ringing again until the app is closed manually.
I've tried by following commands as well but no gain.
android.os.Process.killProcess(android.os.Process.myPid());
System.exit(1);
What could be the issue?
ActivityCode:
import android.content.Context;
import android.graphics.Point;
import android.graphics.PorterDuff;
import android.media.AudioAttributes;
import android.media.AudioManager;
import android.media.Ringtone;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.PowerManager;
import android.os.Vibrator;
import android.support.annotation.RequiresApi;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.view.Display;
import android.view.Gravity;
import android.view.View;
import android.view.WindowManager;
import android.view.animation.Animation;
import android.view.animation.ScaleAnimation;
import android.widget.ImageView;
import android.widget.TextView;
import com.solutionz.battery.saver.master.alarm.utils.AdInterstitial;
import com.solutionz.battery.saver.master.alarm.utils.AppGlobal;
import com.solutionz.battery.saver.master.alarm.utils.MySharedPreferences;
public class AlarmActivity extends AppCompatActivity {
Context context;
TextView title_tv, message_tv;
ImageView batteryIcon_iv;
TextView ok_tv, snooze_tv;
boolean isCharging;
Ringtone ringtone;
Vibrator vibrator;
Handler handler;
Runnable runnable;
PowerManager.WakeLock screenLock;
MySharedPreferences mySharedPreferences;
AdInterstitial adInterstitial;
long[] pattern = {1000, 500, 1000, 1000, 500};
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
context = this;
setContentView(R.layout.activity_alarm);
mySharedPreferences = new MySharedPreferences(context);
adInterstitial = new AdInterstitial(context);
screenLock = ((PowerManager) getSystemService(POWER_SERVICE)).newWakeLock(
PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "TAG");
screenLock.acquire();
setScreenSize();
setViews();
setContent();
setTimer();
adInterstitial.requestLoadInterstitial(false);
}
private void setScreenSize() {
// getting and setting the window size
Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
// int width = (int) (size.x * 0.7);
// int height = (int) (size.y * 0.4);
WindowManager.LayoutParams params = getWindow().getAttributes();
params.gravity = Gravity.CENTER;
//params.height = height;
//params.width = width;
params.height = WindowManager.LayoutParams.WRAP_CONTENT;
params.width = WindowManager.LayoutParams.WRAP_CONTENT;
this.getWindow().setAttributes(params);
}
private void setViews() {
title_tv = (TextView) findViewById(R.id.title_tv);
message_tv = (TextView) findViewById(R.id.message_tv);
batteryIcon_iv = (ImageView) findViewById(R.id.batteryIcon_iv);
ok_tv = (TextView) findViewById(R.id.ok_tv);
snooze_tv = (TextView) findViewById(R.id.snooze_tv);
scaleView(batteryIcon_iv, 0.7f, 1.0f);
ok_tv.getCompoundDrawables()[1].mutate().setColorFilter(ContextCompat.getColor(context, R.color.white), PorterDuff.Mode.SRC_ATOP);
snooze_tv.getCompoundDrawables()[1].mutate().setColorFilter(ContextCompat.getColor(context, R.color.white), PorterDuff.Mode.SRC_ATOP);
ok_tv.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
mySharedPreferences.SetLastNotifiedChargingState(isCharging);
mySharedPreferences.SetIsNotified(true);
finish();
//android.os.Process.killProcess(android.os.Process.myPid());
// System.exit(1);
}
});
snooze_tv.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
mySharedPreferences.SetIsSnoozed(true);
finish();
//android.os.Process.killProcess(android.os.Process.myPid());
// System.exit(1);
}
}
});
}
private void setContent() {
Bundle bundle = getIntent().getBundleExtra("data");
title_tv.setText(bundle.getString("title"));
message_tv.setText(bundle.getString("message"));
isCharging = bundle.getBoolean("isCharging");
if (!isCharging) {
batteryIcon_iv.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.ic_battery_30));
batteryIcon_iv.getDrawable().mutate().setColorFilter(ContextCompat.getColor(context, R.color.white), PorterDuff.Mode.SRC_ATOP);
} else {
batteryIcon_iv.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.ic_battery_charging_80));
batteryIcon_iv.getDrawable().mutate().setColorFilter(ContextCompat.getColor(context, R.color.white), PorterDuff.Mode.SRC_ATOP);
}
// playAlarmTone();
mediaPlayerSetting();
}
public void scaleView(View v, float startScale, float endScale) {
Animation anim = new ScaleAnimation(
startScale, endScale, // Start and end values for the X axis scaling
startScale, endScale, // Start and end values for the Y axis scaling
Animation.RELATIVE_TO_SELF, 0.5f, // Pivot point of X scaling
Animation.RELATIVE_TO_SELF, 0.5f); // Pivot point of Y scaling
anim.setFillAfter(true); // Needed to keep the result of the animation
anim.setDuration(1000);
anim.setRepeatMode(Animation.REVERSE);
anim.setRepeatCount(Animation.INFINITE);
v.startAnimation(anim);
}
public void mediaPlayerSetting() {
AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM);
ringtone = RingtoneManager.getRingtone(getApplicationContext(), notification);
if (mySharedPreferences.GetIsSoundEnabled()) // Play sound
{
int volume = audioManager.getStreamVolume(AudioManager.STREAM_ALARM);
if (volume == 0)
volume = audioManager.getStreamMaxVolume(AudioManager.STREAM_ALARM);
audioManager.setStreamVolume(AudioManager.STREAM_ALARM, volume, AudioManager.FLAG_REMOVE_SOUND_AND_VIBRATE);
ringtone = RingtoneManager.getRingtone(getApplicationContext(), notification);
if (ringtone != null) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
ringtone.setAudioAttributes(new AudioAttributes.Builder().setUsage(AudioAttributes.USAGE_ALARM).build());
} else {
ringtone.setStreamType(AudioManager.STREAM_ALARM);
}
ringtone.play();
}
}
if (mySharedPreferences.GetIsVibrationEnabled()) // Start vibration
{
vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
vibrator.vibrate(pattern, 0);
}
}
private void setTimer() {
handler = new Handler();
runnable = new Runnable() {
#RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN)
#Override
public void run() {
AppGlobal.showNotification(getApplicationContext(), title_tv.getText().toString(), message_tv.getText().toString());
AlarmActivity.this.finish();
}
};
handler.postDelayed(runnable, mySharedPreferences.GetAlarmDuration() * 1000);
}
#Override
protected void onDestroy() {
super.onDestroy();
if (ringtone != null && ringtone.isPlaying()) ringtone.stop();
if (vibrator != null) vibrator.cancel();
handler.removeCallbacks(runnable);
screenLock.release();
}
}
In Android finish() method is not closing the app but minizing it
No. First of all there's no concept of "minimizing" apps on Android, and finish() is NOT closing the main app process, but only finished the activity.
Related
i find this canvas that allows you to write geometrics form in your layout , i use this to cover the android status bar and the android notification bar and it worked so right now i want to cover , with another rectangle , the navigation bar but i can't achieve this goal.
i tried to change the hight of the top of the rectangle to be at the bottom of the screen but it didn't work because the rectangle remains at the top of the screen.
can you help me to move this rectangle to the bottom?
this is my customViewGroup :
package com.liliumduva;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.PixelFormat;
import android.graphics.Rect;
import android.util.Log;
import android.view.MotionEvent;
import android.view.ViewGroup;
import android.view.WindowManager;
public class CustomViewGroup extends ViewGroup {
public CustomViewGroup(Context context) {
super(context);
}
#Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
Paint paint = new Paint();
// paint.setColor(Color.RED);
//canvas.drawRect(0, 0, getWidth(), getHeight() / 10, paint);
Rect rect = new Rect();
paint.setColor(Color.BLUE);
rect.left = 0;
rect.top = getHeight() - getHeight() / 10 - getStatusBarHeight();
rect.right = getWidth();
rect.bottom = getHeight() - getResources().getDimensionPixelSize(getResources().getIdentifier("navigation_bar_height", "dimen", "android"));
canvas.drawRect(rect, paint);
}
private int getStatusBarHeight() {
int result = 0;
int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
if (resourceId > 0) {
result = getResources().getDimensionPixelSize(resourceId);
}
return result;
}
#Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
}
#Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int width = MeasureSpec.getSize(widthMeasureSpec);
int height = MeasureSpec.getSize(heightMeasureSpec);
setMeasuredDimension(width, height);
}
#Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
Log.v("CustomViewGroup", "**********Intercepted");
return true;
}
}
and this is my main activity:
package com.liliumduva;
import android.app.Activity;
import android.app.Notification;
import android.app.PendingIntent;
import android.app.Service;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.PixelFormat;
import android.hardware.usb.UsbAccessory;
import android.hardware.usb.UsbManager;
import android.os.Build;
import android.os.Bundle;
import android.os.IBinder;
import android.util.Log;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import com.facebook.react.ReactActivity;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Set;
import java.util.Timer;
import java.util.TimerTask;
import com.facebook.react.ReactPackage;
import com.facebook.react.shell.MainReactPackage;
public class MainActivity extends ReactActivity {
#Override
protected String getMainComponentName() {
return "liliumDuva";
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
hideSystemUI();
//Remove notification bar
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
WindowManager manager = ((WindowManager) getApplicationContext()
.getSystemService(Context.WINDOW_SERVICE));
WindowManager.LayoutParams localLayoutParams = new WindowManager.LayoutParams();
localLayoutParams.type = WindowManager.LayoutParams.TYPE_SYSTEM_ERROR;
localLayoutParams.gravity = Gravity.TOP;
localLayoutParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
// this is to enable the notification to receive touch events
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL |
// Draws over status bar
WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
localLayoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
localLayoutParams.height = (int) (35 * getResources()
.getDisplayMetrics().scaledDensity);
localLayoutParams.format = PixelFormat.TRANSPARENT;
CustomViewGroup view = new CustomViewGroup(this);
manager.addView(view, localLayoutParams);
manager = ((WindowManager) getApplicationContext()
.getSystemService(Context.WINDOW_SERVICE));
localLayoutParams = new WindowManager.LayoutParams();
localLayoutParams.type = WindowManager.LayoutParams.TYPE_SYSTEM_ERROR;
localLayoutParams.gravity = Gravity.BOTTOM;
localLayoutParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL |
WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
localLayoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
localLayoutParams.height = (int) (80 * getResources()
.getDisplayMetrics().scaledDensity);
localLayoutParams.format = PixelFormat.TRANSPARENT;
}
#Override
public void onBackPressed() {
// Define custom behavior for the back button here
}
#Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
if (keyCode==KeyEvent.KEYCODE_HOME)
return false;
if (keyCode==KeyEvent.KEYCODE_BACK)
return false;
if (keyCode==KeyEvent.KEYCODE_MENU)
return false;
if (keyCode==KeyEvent.KEYCODE_VOLUME_DOWN) {
return false;
}
if (keyCode==KeyEvent.KEYCODE_VOLUME_UP) {
return false;
}
if (keyCode==KeyEvent.KEYCODE_APP_SWITCH)
return false;
if (keyCode==KeyEvent.KEYCODE_ALL_APPS)
return false;
return super.onKeyUp(keyCode,event);
}
#Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
// nothing to do here
// … really
if (keyCode==KeyEvent.KEYCODE_HOME)
return false;
if (keyCode==KeyEvent.KEYCODE_BACK)
return false;
if (keyCode==KeyEvent.KEYCODE_MENU)
return false;
if (keyCode==KeyEvent.KEYCODE_APP_SWITCH)
return false;
if (keyCode==KeyEvent.KEYCODE_ALL_APPS)
return false;
return super.onKeyDown(keyCode,event);
}
public class RelaunchService extends Service {
private Notification mNotification;
private Timer mTimer;
public RelaunchService() {
}
#Override
public int onStartCommand(Intent intent, int flags, int startId) {
super.onStartCommand(intent, flags, startId);
startForeground(1, mNotification);
mTimer.schedule(new TimerTask() {
#Override
public void run() {
Intent intent = new Intent(RelaunchService.this, MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
}, 300);
return START_STICKY;
}
#Override
public void onDestroy() {
super.onDestroy();
stopForeground(true);
mTimer.cancel();
}
#Override
public IBinder onBind(Intent intent) {
throw new UnsupportedOperationException("Not yet implemented");
}
}
#Override
protected void onResume() {
super.onResume();
boolean exitAllowed = false;
Intent servIntent = new Intent(this, RelaunchService.class);
stopService(servIntent);
}
#Override
protected void onPause() {
super.onPause();
savePersistentData();
boolean exitAllowed = false;
if (!exitAllowed) {
Intent servIntent = new Intent(this, RelaunchService.class);
startService(servIntent);
}
}
private void savePersistentData() {
}
private void hideSystemUI() {
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
}
#Override
public void onWindowFocusChanged(boolean hasFocus)
{
super.onWindowFocusChanged(hasFocus);
if(android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && hasFocus)
{
hideSystemUI();
}
}
}
I want to make android app like the following site.
https://sectional-anatomy.org/ct-abdomen/ or like https://radiopaedia.org/cases/squamous-cell-carcinoma-oral-cavity
There are multiple pictures and these are changing by scrolling.
I have done something like that with imageswitcher and onTouch event with action_down and action_up but it doesn't work because when I remove my finger then it goes to the first image it doesn't stay where I left.
Here is my code:
package com.radiology.radiologymenu.tomografi;
import android.content.SharedPreferences;
import android.graphics.Point;
import android.os.Bundle;
import android.os.Handler;
import android.preference.PreferenceManager;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.Display;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.view.WindowManager;
import android.webkit.WebView;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.HorizontalScrollView;
import android.widget.ImageSwitcher;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.ViewSwitcher;
import com.radiology.radiologymenu.R;
import java.util.ArrayList;
import java.util.Timer;
import java.util.TimerTask;
public class ImageChangeActivity extends AppCompatActivity {
private ImageSwitcher imageSwitcher;
private ImageView box;
// Size
private int frameHeight;
private int boxSize;
private int screenHeight;
// Position
private int boxY;
// Speed
private int boxSpeed;
// Score
private int score = 0;
// Initialize Class
private Handler handler = new Handler();
private Timer timer = new Timer();
// Status Check
private boolean action_flg = false;
private boolean start_flg = false;
private String pic;
private ArrayList<Integer> slidePictures;
private static final Integer[] image= {
R.drawable.sagittal_boyun_1, R.drawable.sagittal_boyun_2, R.drawable.sagittal_boyun_3, R.drawable.sagittal_boyun_4,
R.drawable.sagittal_boyun_5, R.drawable.sagittal_boyun_6, R.drawable.sagittal_boyun_7, R.drawable.sagittal_boyun_8,
R.drawable.sagittal_boyun_9, R.drawable.sagittal_boyun_10, R.drawable.sagittal_boyun_11,
R.drawable.sagittal_boyun_12, R.drawable.sagittal_boyun_13, R.drawable.sagittal_boyun_14, R.drawable.sagittal_boyun_15,
R.drawable.sagittal_boyun_16, R.drawable.sagittal_boyun_17, R.drawable.sagittal_boyun_18, R.drawable.sagittal_boyun_19,
R.drawable.sagittal_boyun_20, R.drawable.sagittal_boyun_21, R.drawable.sagittal_boyun_22, R.drawable.sagittal_boyun_23,
R.drawable.sagittal_boyun_24, R.drawable.sagittal_boyun_25, R.drawable.sagittal_boyun_26, R.drawable.sagittal_boyun_27,
R.drawable.sagittal_boyun_28, R.drawable.sagittal_boyun_29, R.drawable.sagittal_boyun_30, R.drawable.sagittal_boyun_31,
R.drawable.sagittal_boyun_32, R.drawable.sagittal_boyun_33, R.drawable.sagittal_boyun_34, R.drawable.sagittal_boyun_35,
R.drawable.sagittal_boyun_36, R.drawable.sagittal_boyun_37, R.drawable.sagittal_boyun_38, R.drawable.sagittal_boyun_39,
R.drawable.sagittal_boyun_40, R.drawable.sagittal_boyun_41, R.drawable.sagittal_boyun_42, R.drawable.sagittal_boyun_43,
R.drawable.sagittal_boyun_44, R.drawable.sagittal_boyun_45 };
int i = 0;
#Override
protected void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.slide_activity_main);
pic = getIntent().getExtras().getString("pic");
slidePictures = (ArrayList<Integer>) getIntent().getExtras().getSerializable("slidePictures");
getView2(pic,slidePictures);
}
public void getView2(String strings, ArrayList<Integer> slidePictures){
setContentView(R.layout.slide_activity_main);
TextView textView = (TextView) findViewById(R.id.resimText);
textView.setText(strings.toString());
imageSwitcher = (ImageSwitcher) findViewById(R.id.imageSwitcher);
box = (ImageView) findViewById(R.id.box);
// Get screen size.
WindowManager wm = getWindowManager();
Display disp = wm.getDefaultDisplay();
Point size = new Point();
disp.getSize(size);
screenHeight = size.y;
boxSpeed = Math.round(screenHeight / 60); // 1280 / 60 = 21.333... => 21
imageSwitcher.setFactory(new ViewSwitcher.ViewFactory() {
#Override
public View makeView() {
ImageView imageView = new ImageView(getApplicationContext());
imageView.setScaleType(ImageView.ScaleType.FIT_XY);
FrameLayout.LayoutParams params = new ImageSwitcher.LayoutParams(
FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT);
imageView.setLayoutParams(params);
return imageView;
}
});
imageSwitcher.setImageResource(slidePictures.get(0));
}
#Override
public boolean onKeyDown(int keyCode, KeyEvent event)
{
if ((keyCode == KeyEvent.KEYCODE_BACK))
{
finish();
}
return super.onKeyDown(keyCode, event);
}
public void changePos() {
// Move Box
if (action_flg == true) {
// Touching
boxY -= boxSpeed;
if (i<slidePictures.size()-1){
i++;
imageSwitcher.setImageResource(slidePictures.get(i));
}
} else {
// Releasing
boxY += boxSpeed;
if (i>0){
i--;
imageSwitcher.setImageResource(slidePictures.get(i));
}
}
// Check box position.
if (boxY < 0) boxY = 0;
if (boxY > frameHeight - boxSize) boxY = frameHeight - boxSize;
box.setY(boxY);
}
public boolean onTouchEvent(MotionEvent me) {
if (start_flg == false) {
start_flg = true;
// Why get frame height and box height here?
// Because the UI has not been set on the screen in OnCreate()!!
FrameLayout frame = (FrameLayout) findViewById(R.id.frame);
frameHeight = frame.getHeight();
boxY = (int)box.getY();
// The box is a square.(height and width are the same.)
boxSize = box.getHeight();
timer.schedule(new TimerTask() {
#Override
public void run() {
handler.post(new Runnable() {
#Override
public void run() {
changePos();
}
});
}
}, 0, 40);
} else {
if (me.getAction() == MotionEvent.ACTION_DOWN) {
action_flg = false;
} else if (me.getAction() == MotionEvent.ACTION_UP) {
action_flg = true;
}
}
return true;
}
}
I am creating the app in ionic framework and I am calling the custom plugin which have the video player. Now my problem is Video player is opening in new window rather than current opening window. I want it to open on top of my Html page but not full screen only half screen. the final page will have html page on top of that In right side half page i want my plugin to open.any help how to do this thanks in advance.
this is my plugin
package cordova.plugin.VLCPlugin;
import android.app.Activity;
import android.content.res.Configuration;
import android.graphics.PixelFormat;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.Gravity;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.webkit.WebView;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.SeekBar;
import android.widget.TextView;
import android.widget.Toast;
import com.mindtree.gladiuscms.R;
import org.videolan.libvlc.EventHandler;
import org.videolan.libvlc.IVideoPlayer;
import org.videolan.libvlc.LibVLC;
import org.videolan.libvlc.Media;
import org.videolan.libvlc.MediaList;
import java.lang.ref.WeakReference;
import cordova.plugin.VLCPlugin.util.SystemUiHider;
import cordova.plugin.VLCPlugin.util.UrlProvider;
/**
* An example full-screen activity that shows and hides the system UI (i.e.
* status bar and navigation/system bar) with user interaction.
*
* #see SystemUiHider
*/
public class FullscreenVlcPlayer extends Activity implements SurfaceHolder.Callback, IVideoPlayer {
private String urlToStream;
// Display Surface
private LinearLayout vlcContainer;
private SurfaceView mSurface;
private SurfaceHolder holder;
// Overlay / Controls
private FrameLayout vlcOverlay;
private ImageView vlcButtonPlayPause;
private Handler handlerOverlay;
private Runnable runnableOverlay;
private Handler handlerSeekbar;
private Runnable runnableSeekbar;
private SeekBar vlcSeekbar;
private TextView vlcDuration;
private TextView overlayTitle;
// media player
private LibVLC libvlc;
private int mVideoWidth;
private int mVideoHeight;
private final static int VideoSizeChanged = -1;
private UrlProvider urlProvider = new UrlProvider();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Retrieve our url
// Bundle b = getIntent().getExtras();
UrlProvider urlProvider = UrlProvider.getInstance();
urlToStream = urlProvider.getUrl();
Log.d("Data url sdfjksdf", urlToStream);
// urlToStream = "rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mov";// b.getString("url", null);
// HIDE THE ACTION BAR
// getActionBar().hide();
// SETUP THE UI
try{
getActionBar().hide();
setContentView(R.layout.activity_fullscreen_vlc_player);
}catch(Exception e){
Log.d("TAG", "error");
}
// VLC
vlcContainer = (LinearLayout) findViewById(R.id.vlc_container);
mSurface = (SurfaceView) findViewById(R.id.vlc_surface);
// OVERLAY / CONTROLS
vlcOverlay = (FrameLayout) findViewById(R.id.vlc_overlay);
vlcButtonPlayPause = (ImageView) findViewById(R.id.vlc_button_play_pause);
vlcSeekbar = (SeekBar) findViewById(R.id.vlc_seekbar);
vlcDuration = (TextView) findViewById(R.id.vlc_duration);
overlayTitle = (TextView) findViewById(R.id.vlc_overlay_title);
// overlayTitle.setText("rtsp://172.22.68.96:21212/Stream-2");
// AUTOSTART
playMovie();
}
private void showOverlay() {
vlcOverlay.setVisibility(View.VISIBLE);
}
private void hideOverlay() {
vlcOverlay.setVisibility(View.GONE);
}
private void setupControls() {
getActionBar().hide();
// PLAY PAUSE
vlcButtonPlayPause.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
if (libvlc.isPlaying()) {
libvlc.pause();
// vlcButtonPlayPause.setImageDrawable(getResources().getDrawable(R.drawable.ic_action_play_over_video));
} else {
libvlc.play();
// vlcButtonPlayPause.setImageDrawable(getResources().getDrawable(R.drawable.ic_action_pause_over_video));
}
}
});
// SEEKBAR
handlerSeekbar = new Handler();
runnableSeekbar = new Runnable() {
#Override
public void run() {
if (libvlc != null) {
long curTime = libvlc.getTime();
long totalTime = (long) (curTime / libvlc.getPosition());
int minutes = (int) (curTime / (60 * 1000));
int seconds = (int) ((curTime / 1000) % 60);
int endMinutes = (int) (totalTime / (60 * 1000));
int endSeconds = (int) ((totalTime / 1000) % 60);
String duration = String.format("%02d:%02d / %02d:%02d", minutes, seconds, endMinutes, endSeconds);
vlcSeekbar.setProgress((int) (libvlc.getPosition() * 100));
vlcDuration.setText(duration);
}
handlerSeekbar.postDelayed(runnableSeekbar, 1000);
}
};
runnableSeekbar.run();
vlcSeekbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
#Override
public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
Log.v("NEW POS", "pos is : " + i);
//if (i != 0)
// libvlc.setPosition(((float) i / 100.0f));
}
#Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
#Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
// OVERLAY
handlerOverlay = new Handler();
runnableOverlay = new Runnable() {
#Override
public void run() {
vlcOverlay.setVisibility(View.GONE);
toggleFullscreen(true);
}
};
final long timeToDisappear = 3000;
handlerOverlay.postDelayed(runnableOverlay, timeToDisappear);
vlcContainer.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
vlcOverlay.setVisibility(View.VISIBLE);
handlerOverlay.removeCallbacks(runnableOverlay);
handlerOverlay.postDelayed(runnableOverlay, timeToDisappear);
}
});
}
public void playMovie() {
if (libvlc != null && libvlc.isPlaying())
return ;
vlcContainer.setVisibility(View.VISIBLE);
holder = mSurface.getHolder();
holder.addCallback(this);
createPlayer(urlToStream);
}
private void toggleFullscreen(boolean fullscreen)
{
WindowManager.LayoutParams attrs = getWindow().getAttributes();
if (fullscreen)
{
attrs.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN;
vlcContainer.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
}
else
{
attrs.flags &= ~WindowManager.LayoutParams.FLAG_FULLSCREEN;
}
getWindow().setAttributes(attrs);
}
#Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
setSize(mVideoWidth, mVideoHeight);
}
#Override
protected void onResume() {
super.onResume();
}
#Override
protected void onPause() {
super.onPause();
//releasePlayer();
}
#Override
protected void onDestroy() {
super.onDestroy();
releasePlayer();
}
/**
* **********
* Surface
* ***********
*/
public void surfaceCreated(SurfaceHolder holder) {
}
public void surfaceChanged(SurfaceHolder surfaceholder, int format,
int width, int height) {
if (libvlc != null)
libvlc.attachSurface(surfaceholder.getSurface(), this);
}
public void surfaceDestroyed(SurfaceHolder surfaceholder) {
}
private void setSize(int width, int height) {
mVideoWidth = width;
mVideoHeight = height;
if (mVideoWidth * mVideoHeight <= 1)
return;
// get screen size
int w = getWindow().getDecorView().getWidth();
int h = getWindow().getDecorView().getHeight();
// getWindow().getDecorView() doesn't always take orientation into
// account, we have to correct the values
boolean isPortrait = getResources().getConfiguration().orientation `**enter code here**`== Configuration.ORIENTATION_PORTRAIT;
if (w > h && isPortrait || w < h && !isPortrait) {
int i = w;
w = h;
h = i;
}
float videoAR = (float) mVideoWidth / (float) mVideoHeight;
float screenAR = (float) w / (float) h;
if (screenAR < videoAR)
h = (int) (w / videoAR);
else
w = (int) (h * videoAR);
// force surface buffer size
if (holder != null)
holder.setFixedSize(mVideoWidth, mVideoHeight);
// set display size
ViewGroup.LayoutParams lp = mSurface.getLayoutParams();
lp.width = w;
lp.height = h;
mSurface.setLayoutParams(lp);
mSurface.invalidate();
}
#Override
public void setSurfaceSize(int width, int height, int visible_width,
int visible_height, int sar_num, int sar_den) {
Message msg = Message.obtain(mHandler, VideoSizeChanged, width, height);
msg.sendToTarget();
}
/**
* **********
* Player
* ***********
*/
private void createPlayer(String media) {
releasePlayer();
setupControls();
try {
if (media.length() > 0) {
Toast toast = Toast.makeText(this, media, Toast.LENGTH_LONG);
toast.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0,
0);
toast.show();
}
// Create a new media player
libvlc = LibVLC.getInstance();
libvlc.setHardwareAcceleration(LibVLC.HW_ACCELERATION_FULL);
libvlc.eventVideoPlayerActivityCreated(true);
libvlc.setSubtitlesEncoding("");
libvlc.setAout(LibVLC.AOUT_OPENSLES);
libvlc.setTimeStretching(true);
libvlc.setChroma("RV32");
libvlc.setVerboseMode(true);
LibVLC.restart(this);
EventHandler.getInstance().addHandler(mHandler);
holder.setFormat(PixelFormat.RGBX_8888);
holder.setKeepScreenOn(true);
MediaList list = libvlc.getMediaList();
list.clear();
list.add(new Media(libvlc, LibVLC.PathToURI(media)), false);
libvlc.playIndex(0);
} catch (Exception e) {
Toast.makeText(this, "Could not create Vlc Player", Toast.LENGTH_LONG).show();
}
}
private void releasePlayer() {
if (handlerSeekbar != null && runnableSeekbar != null)
handlerSeekbar.removeCallbacks(runnableSeekbar);
EventHandler.getInstance().removeHandler(mHandler);
if (libvlc == null)
return;
libvlc.stop();
libvlc.detachSurface();
holder = null;
libvlc.closeAout();
mVideoWidth = 0;
mVideoHeight = 0;
}
/**
* **********
* Events
* ***********
*/
private Handler mHandler = new MyHandler(this);
private static class MyHandler extends Handler {
private WeakReference<FullscreenVlcPlayer> mOwner;
public MyHandler(FullscreenVlcPlayer owner) {
mOwner = new WeakReference<FullscreenVlcPlayer>(owner);
}
#Override
public void handleMessage(Message msg) {
FullscreenVlcPlayer player = mOwner.get();
// Player events
if (msg.what == VideoSizeChanged) {
player.setSize(msg.arg1, msg.arg2);
return;
}
// Libvlc events
Bundle b = msg.getData();
switch (b.getInt("event")) {
case EventHandler.MediaPlayerEndReached:
player.releasePlayer();
break;
case EventHandler.MediaPlayerPlaying:
case EventHandler.MediaPlayerPaused:
case EventHandler.MediaPlayerStopped:
default:
break;
}
}
}
}
//it use some helper class and
xml file attached to this
cordova plugin
package cordova.plugin.VLCPlugin;
import android.app.Application;
import android.content.Intent;
import android.content.res.Resources;
import android.graphics.Rect;
import android.widget.FrameLayout;
import com.mindtree.gladiuscms.R;
import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaInterface;
import org.apache.cordova.CordovaPlugin;
import org.apache.cordova.CordovaWebView;
import org.json.JSONArray;
import org.json.JSONException;
import cordova.plugin.VLCPlugin.util.UrlProvider;
public class VLCPlugin extends CordovaPlugin {
UrlProvider urlProvider = new UrlProvider();
#Override
public void initialize(CordovaInterface cordova, CordovaWebView webView) {
FrameLayout layout = (FrameLayout) webView.getView().getParent();
}
#Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
if(action.equals("play")) {
String url = args.getString(0);
UrlProvider urlProvide = UrlProvider.getInstance();
urlProvide.setUrl(url);
resources.getIdentifier("R.layout.activity_fullscreen_vlc_player", "layout", package_name);
cordova.getActivity().runOnUiThread(new Runnable() {
public void run() {
Application app = cordova.getActivity().getApplication();
Intent intent = new Intent(app, FullscreenVlcPlayer.class);
cordova.getActivity().startActivity(intent);
}
return false;
}
}
now i am cslling this plugin from my controller
window.vlcPlugin.onMediaLoad("http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4");}
an my html code is
<div ng-drag="true" ng-drag-data="video" ng-drag-success="onDragComplete()"></div>
i want to see video in this div
<div class="video_player_screen" ng-drop="tru >
I was wondering whether to display SystemUI and Listenering. The window is created in Service
package com.example.testwindow;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.PixelFormat;
import android.os.IBinder;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.WindowManager.LayoutParams;
import com.android.internal.policy.PolicyManager;
public class WindowManagerService extends Service {
private String TAG ="WindowManagerService";
private Context mContext;
private WindowManager mWindowManager;
private Window mWindow;
#Override
public void onCreate() {
super.onCreate();
Log.i(TAG, "onCreate view");
this.mWindowManager = ((WindowManager) getSystemService("window"));
mContext = this;
}
#Override
public int onStartCommand(Intent intent, int flags, int startId) {
int i = super.onStartCommand(intent, flags, startId);
View editWindow = LayoutInflater.from(mContext).inflate(R.layout.activity_main, null);
mWindow = addWindow(editWindow, 0, 0, LayoutParams.TYPE_PHONE);
int mSystemUiVisibility = mWindow.getDecorView().getSystemUiVisibility();
mWindow.getDecorView().setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener(){
#Override
public void onSystemUiVisibilityChange(int visibility) {
Log.e(TAG,"systemUI onSystemUiVisibilityChange ="+visibility);
}
});
Log.e(TAG, "mSystemUiVisibility ="+mSystemUiVisibility);
WindowManager.LayoutParams layoutParams = mWindow.getAttributes();
layoutParams.x = 0;
layoutParams.y = 0;
layoutParams.width = 500;
layoutParams.height = 600;
layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
layoutParams.hasSystemUiListeners = true;
layoutParams.setTitle("WindowManagerService");
mWindow.setAttributes(layoutParams);
mWindowManager.updateViewLayout(mWindow.getDecorView(), layoutParams);
return i;
}
public WindowManager.LayoutParams createLayoutParams() {
Log.i(TAG , "createLayoutParams");
WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams(
LayoutParams.TYPE_SYSTEM_ERROR,
LayoutParams.FLAG_NOT_FOCUSABLE,
PixelFormat.TRANSLUCENT);
layoutParams.softInputMode = LayoutParams.SOFT_INPUT_ADJUST_PAN;
layoutParams.setTitle(getClass().getName());
return layoutParams;
}
public Window addWindow(View paramView, int width, int height,
int type) {
Log.i(TAG, "addWindow view");
WindowManager.LayoutParams layoutParams = createLayoutParams();
Window localWindow = PolicyManager.makeNewWindow(this.mContext);
if (localWindow != null) {
localWindow.setWindowManager(this.mWindowManager, null, null);
localWindow.requestFeature(Window.FEATURE_NO_TITLE);
localWindow.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
layoutParams.width = width;
layoutParams.height = height;
layoutParams.type = type;
layoutParams.format= PixelFormat.TRANSPARENT;
layoutParams.flags = (LayoutParams.FLAG_NOT_FOCUSABLE | layoutParams.flags);
localWindow.setAttributes(layoutParams);
localWindow.setContentView(paramView);
View localView = localWindow.getDecorView();
if (localView != null) {
localView.setVisibility(View.VISIBLE);
this.mWindowManager.addView(localView, layoutParams);
}
return localWindow;
}
return null;
}
#Override
public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
return null;
}
#Override
public void onDestroy() {
if (mWindow != null) {
mWindowManager.removeView(mWindow.getDecorView());
mWindow = null;
}
super.onDestroy();
}
}
When I start service,Other App changed to FULLSCREEN or not ,I can't get the log "systemUI onSystemUiVisibilityChange ="
Can someone explain the behaviour? Why can't listener the change?
You can try to add the listener before calling addView.
i'm writing service class that has image overlay
imageView overlay was visible, but it isn't visible after i added imageview resize code.
Also, MotionEvent for resized imageview isn't works well
Why imageview overlay isn't visible and MotionEvent isn't works well?
Could you help me to solve this problem?
here's my code
This code show ImageView overlay which isn't resized,
it is visible and MotionEvent works well
package kr.hybdms.sidepanel;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Context;
import android.content.ContextWrapper;
import android.content.Intent;
import android.net.Uri;
import android.os.IBinder;
import android.util.Log;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.view.WindowManager;
import android.widget.ImageView;
import android.graphics.PixelFormat;
public class TouchDetectService extends Service {
private ImageView mTouchDetector;
private WindowManager.LayoutParams mParams;
private WindowManager mWindowManager;
private static final int MY_NOTIFICATION_ID=1;
private NotificationManager notificationManager;
private Notification myNotification;
final static String ACTION = "NotifyServiceAction";
final static String STOP_SERVICE = "";
final static int RQS_STOP_SERVICE = 1;
private OnTouchListener mViewTouchListener = new OnTouchListener() {
#Override public boolean onTouch(View v, MotionEvent event) {
switch(event.getAction()) {
case MotionEvent.ACTION_MOVE:
Intent lsp = new Intent(getBaseContext(), SidePanel.class);
lsp.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
getApplication().startActivity(lsp);
break;
}
return true;
}
};
#Override
public IBinder onBind(Intent arg0) { return null; }
#Override
public void onCreate() {
super.onCreate();
boolean rightpanel = getSharedPreferences(getPackageName() + "_preferences", Context.MODE_PRIVATE).getBoolean("panelpos_right", true);
boolean notificationison = getSharedPreferences(getPackageName() + "_preferences", Context.MODE_PRIVATE).getBoolean("noti_toggle", true);
Log.i("BOOTSVC", "Service started at the BOOT_COMPLETED.");
if(rightpanel)
{
mTouchDetector = new ImageView(this);
mTouchDetector.setImageResource(R.drawable.detector);
mTouchDetector.setOnTouchListener(mViewTouchListener);
mParams = new WindowManager.LayoutParams(
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.TYPE_PHONE,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
PixelFormat.TRANSLUCENT);
mParams.gravity = Gravity.RIGHT | Gravity.CENTER;
mWindowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
mWindowManager.addView(mTouchDetector, mParams);
}
else
{
mTouchDetector = new ImageView(this);
mTouchDetector.setImageResource(R.drawable.detector);
mTouchDetector.setOnTouchListener(mViewTouchListener);
mParams = new WindowManager.LayoutParams(
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.TYPE_PHONE,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
PixelFormat.TRANSLUCENT);
mParams.gravity = Gravity.LEFT | Gravity.CENTER;
mWindowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
mWindowManager.addView(mTouchDetector, mParams);
}
if(notificationison){
notificationManager =
(NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
myNotification = new Notification(R.drawable.ic_stat_sidepanel,
getText(R.string.service_notification),
System.currentTimeMillis());
Context context = getApplicationContext();
CharSequence notificationTitle = getText(R.string.service_running);
CharSequence notificationText = getText(R.string.service_running_desc);
Intent myIntent = new Intent(getBaseContext(), Settings.class);;
PendingIntent pendingIntent
= PendingIntent.getActivity(getBaseContext(),
0, myIntent,
Intent.FLAG_ACTIVITY_NEW_TASK);
myNotification.defaults |= Notification.DEFAULT_SOUND;
myNotification.flags |= Notification.FLAG_AUTO_CANCEL;
myNotification.flags = Notification.FLAG_ONGOING_EVENT;
myNotification.setLatestEventInfo(context,
notificationTitle,
notificationText,
pendingIntent);
notificationManager.notify(MY_NOTIFICATION_ID, myNotification);
}
else
{
}
}
#Override
public void onDestroy() {
if(mWindowManager != null) {
if(mTouchDetector != null) mWindowManager.removeView(mTouchDetector);
}
super.onDestroy();
notificationManager.cancel(MY_NOTIFICATION_ID);
}
}
This code show ImageView overlay which resized,
it isn't visible and MotionEvent isn't works well
imageview is resizes by preference value
package kr.hybdms.sidepanel;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.IBinder;
import android.os.Vibrator;
import android.preference.PreferenceManager;
import android.util.Log;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.view.WindowManager;
import android.widget.ImageView;
import android.graphics.PixelFormat;
public class TouchDetectService extends Service {
private ImageView mTouchDetector;
private WindowManager.LayoutParams mParams;
private WindowManager mWindowManager;
private static final int MY_NOTIFICATION_ID=1;
private NotificationManager notificationManager;
private Notification myNotification;
final static String ACTION = "NotifyServiceAction";
final static String STOP_SERVICE = "";
final static int RQS_STOP_SERVICE = 1;
private OnTouchListener mViewTouchListener = new OnTouchListener() {
#Override public boolean onTouch(View v, MotionEvent event) {
switch(event.getAction()) {
case MotionEvent.ACTION_MOVE:
boolean vibeon = getSharedPreferences(getPackageName() + "_preferences", Context.MODE_PRIVATE).getBoolean("vibe_toggle", true);
if(vibeon){
Vibrator vibe = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
vibe.vibrate(10);}
else{}
Intent lsp = new Intent(getBaseContext(), SidePanel.class);
lsp.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
getApplication().startActivity(lsp);
break;
}
return true;
}
};
#Override
public IBinder onBind(Intent arg0) { return null; }
#Override
public void onCreate() {
super.onCreate();
boolean rightpanel = getSharedPreferences(getPackageName() + "_preferences", Context.MODE_PRIVATE).getBoolean("panelpos_right", true);
boolean notificationison = getSharedPreferences(getPackageName() + "_preferences", Context.MODE_PRIVATE).getBoolean("noti_toggle", true);
Log.i("BOOTSVC", "Service started at the BOOT_COMPLETED.");
SharedPreferences myPreference = PreferenceManager.getDefaultSharedPreferences(this);
String dw = myPreference.getString("detector_width", "");
String dh = myPreference.getString("detector_height", "");
mTouchDetector = new ImageView(this);
mTouchDetector.setImageResource(R.drawable.detector);
mTouchDetector.setOnTouchListener(mViewTouchListener);
WindowManager.LayoutParams params = new WindowManager.LayoutParams();
if(dw.equals("025")){
params.height = (int) (mTouchDetector.getDrawable().getIntrinsicWidth()*0.25);
}
else if(dw.equals("050")){
params.height = (int) (mTouchDetector.getDrawable().getIntrinsicWidth()*0.5);
}
else if(dw.equals("075")){
params.height = (int) (mTouchDetector.getDrawable().getIntrinsicWidth()*0.75);
}
else if(dw.equals("100")){
params.height = mTouchDetector.getDrawable().getIntrinsicWidth();
}
else if(dw.equals("200")){
params.height = mTouchDetector.getDrawable().getIntrinsicWidth()*2;
}
else if(dw.equals("300")){
params.height = mTouchDetector.getDrawable().getIntrinsicWidth()*3;
}
else if(dw.equals("400")){
params.height = mTouchDetector.getDrawable().getIntrinsicWidth()*4;
}
if (dh.equals("025")){
params.width = (int) (mTouchDetector.getDrawable().getIntrinsicHeight()*0.25);
}
else if (dh.equals("050")){
params.width = (int) (mTouchDetector.getDrawable().getIntrinsicHeight()*0.5);
}
else if (dh.equals("075")){
params.width = (int) (mTouchDetector.getDrawable().getIntrinsicHeight()*0.75);
}
else if (dh.equals("100")){
params.width = mTouchDetector.getDrawable().getIntrinsicHeight();
}
else if (dh.equals("200")){
params.width = mTouchDetector.getDrawable().getIntrinsicHeight()*2;
}
else if (dh.equals("300")){
params.width = mTouchDetector.getDrawable().getIntrinsicHeight()*3;
}
else if (dh.equals("400")){
params.width = mTouchDetector.getDrawable().getIntrinsicHeight()*4;
}
params.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
params.format = PixelFormat.TRANSLUCENT;
params.type = WindowManager.LayoutParams.TYPE_PHONE;
if(rightpanel)
{
params.gravity = Gravity.RIGHT & Gravity.CENTER;
}
else
{
params.gravity = Gravity.LEFT & Gravity.CENTER;
}
mWindowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
mWindowManager.addView(mTouchDetector, params);
if(notificationison){
notificationManager =
(NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
myNotification = new Notification(R.drawable.ic_stat_sidepanel,
getText(R.string.service_notification),
System.currentTimeMillis());
Context context = getApplicationContext();
CharSequence notificationTitle = getText(R.string.service_running);
CharSequence notificationText = getText(R.string.service_running_desc);
Intent myIntent = new Intent(getBaseContext(), Settings.class);;
PendingIntent pendingIntent
= PendingIntent.getActivity(getBaseContext(),
0, myIntent,
Intent.FLAG_ACTIVITY_NEW_TASK);
myNotification.defaults |= Notification.DEFAULT_SOUND;
myNotification.flags |= Notification.FLAG_AUTO_CANCEL;
myNotification.flags = Notification.FLAG_ONGOING_EVENT;
myNotification.setLatestEventInfo(context,
notificationTitle,
notificationText,
pendingIntent);
notificationManager.notify(MY_NOTIFICATION_ID, myNotification);
}
else
{
}
}
#Override
public void onDestroy() {
if(mWindowManager != null) {
if(mTouchDetector != null) mWindowManager.removeView(mTouchDetector);
}
super.onDestroy();
notificationManager.cancel(MY_NOTIFICATION_ID);
}
}
The code that you are complaining about isn't adding the ImageView - mTouchDetector - to your layout. You must add it in order for it to be visible if you are using plain Java instead of XML. Look at your first example (the working one):
mWindowManager.addView(mTouchDetector, mParams);
That's the idea here.