Example usage for android.os PowerManager newWakeLock

List of usage examples for android.os PowerManager newWakeLock

Introduction

In this page you can find the example usage for android.os PowerManager newWakeLock.

Prototype

public WakeLock newWakeLock(int levelAndFlags, String tag) 

Source Link

Document

Creates a new wake lock with the specified level and flags.

Usage

From source file:com.devalladolid.musictoday.MusicService.java

@Override
public void onCreate() {
    if (D)//from  w ww .  j ava2s  .  c om
        Log.d(TAG, "Creating service");
    super.onCreate();

    mNotificationManager = NotificationManagerCompat.from(this);

    // gets a pointer to the playback state store
    mPlaybackStateStore = MusicPlaybackState.getInstance(this);
    mSongPlayCount = SongPlayCount.getInstance(this);
    mRecentStore = RecentStore.getInstance(this);

    mHandlerThread = new HandlerThread("MusicPlayerHandler", android.os.Process.THREAD_PRIORITY_BACKGROUND);
    mHandlerThread.start();

    mPlayerHandler = new MusicPlayerHandler(this, mHandlerThread.getLooper());

    mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
    mMediaButtonReceiverComponent = new ComponentName(getPackageName(),
            MediaButtonIntentReceiver.class.getName());
    mAudioManager.registerMediaButtonEventReceiver(mMediaButtonReceiverComponent);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
        setUpMediaSession();

    mPreferences = getSharedPreferences("Service", 0);
    mCardId = getCardId();

    registerExternalStorageListener();

    mPlayer = new MultiPlayer(this);
    mPlayer.setHandler(mPlayerHandler);

    // Initialize the intent filter and each action
    final IntentFilter filter = new IntentFilter();
    filter.addAction(SERVICECMD);
    filter.addAction(TOGGLEPAUSE_ACTION);
    filter.addAction(PAUSE_ACTION);
    filter.addAction(STOP_ACTION);
    filter.addAction(NEXT_ACTION);
    filter.addAction(PREVIOUS_ACTION);
    filter.addAction(PREVIOUS_FORCE_ACTION);
    filter.addAction(REPEAT_ACTION);
    filter.addAction(SHUFFLE_ACTION);
    // Attach the broadcast listener
    registerReceiver(mIntentReceiver, filter);

    mMediaStoreObserver = new MediaStoreObserver(mPlayerHandler);
    getContentResolver().registerContentObserver(MediaStore.Audio.Media.INTERNAL_CONTENT_URI, true,
            mMediaStoreObserver);
    getContentResolver().registerContentObserver(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, true,
            mMediaStoreObserver);

    // Initialize the wake lock
    final PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
    mWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, getClass().getName());
    mWakeLock.setReferenceCounted(false);

    final Intent shutdownIntent = new Intent(this, MusicService.class);
    shutdownIntent.setAction(SHUTDOWN);

    mAlarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
    mShutdownIntent = PendingIntent.getService(this, 0, shutdownIntent, 0);

    scheduleDelayedShutdown();

    reloadQueueAfterPermissionCheck();
    notifyChange(QUEUE_CHANGED);
    notifyChange(META_CHANGED);
}

From source file:com.grazerss.EntryManager.java

private void switchStorageProvider() {

    Log.d(TAG, "Switch Storage Provider");

    if (isModelCurrentlyUpdated()) {
        return;//w  w w .  j  a  v a2 s  .c o m
    }

    final String newPrefValue = getSharedPreferences().getString(SETTINGS_STORAGE_PROVIDER_KEY, null);
    final String oldStorageProviderClass = fileContextAdapter.getClass().getName();

    final String newStorageProviderClass = STORAGE_PROVIDER_SD_CARD.equals(newPrefValue)
            ? SdCardStorageAdapter.class.getName()
            : PhoneMemoryStorageAdapter.class.getName();
    if (!oldStorageProviderClass.equals(newStorageProviderClass)) {

        runningThread = new Thread(new Runnable() {

            public void run() {
                final PowerManager pm = (PowerManager) ctx.getSystemService(Context.POWER_SERVICE);
                final PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG);
                Log.i(TAG, "Wake lock acquired at " + new Date().toString() + ".");
                wl.acquire();
                Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
                final Timing t = new Timing("Storage Provider Switch", ctx);
                ModelUpdateResult result = null;
                if (isModelCurrentlyUpdated()) {
                    return;
                }
                try {
                    lockModel("EM.switchStorageProvider.run");
                } catch (final IllegalStateException ise) {
                    return;
                }
                try {

                    Log.i(TAG, "Switching storage providers started at " + new Date().toString() + ".");

                    fireModelUpdateStarted("Switching storage providers", false, true);
                    Log.d(TAG, "Change of storage provider detected.");

                    final List<Job> jobList = new LinkedList<Job>();

                    final Job clearOldStorageProvider = new Job("Clearing Old Storage Provider",
                            EntryManager.this) {

                        @Override
                        public void run() {
                            Log.d(TAG, "Clearing the old storage provider.");
                            doClearCache();
                            if (fileContextAdapter.canWrite()) {
                                WebPageDownloadDirector.removeAllAssets(fileContextAdapter, ctx);
                            }
                        }

                    };
                    jobList.add(clearOldStorageProvider);
                    final Job switchStorageProviders = new Job("Switching Storage Providers",
                            EntryManager.this) {

                        @Override
                        public void run() throws Exception {
                            Log.d(TAG, "Establishing new storage provider: " + newStorageProviderClass);
                            fileContextAdapter = newStorageProviderClass.equals(
                                    SdCardStorageAdapter.class.getName()) ? new SdCardStorageAdapter(ctx)
                                            : new PhoneMemoryStorageAdapter(ctx);

                            Log.d(TAG, "New storage provider established.");
                        }

                    };
                    jobList.add(switchStorageProviders);

                    final Job clearNewStorageProvider = new Job("Clearing New Storage Provider",
                            EntryManager.this) {

                        @Override
                        public void run() {
                            Log.d(TAG, "Clearing the new storage provider.");
                            doClearCache();
                            if (fileContextAdapter.canWrite()) {
                                WebPageDownloadDirector.removeAllAssets(fileContextAdapter, ctx);
                            }
                        }

                    };
                    jobList.add(clearNewStorageProvider);

                    runJobs(jobList);

                    result = new SwitchStorageProviderResult();

                } catch (final Throwable throwable) {
                    result = new SwitchStorageProviderFailed(throwable);
                    Log.d(TAG, "Problem during switching storage providers.", throwable);
                    t.stop();
                } finally {
                    unlockModel("EM.switchStorageProvider.run");
                    clearCancelState();
                    fireModelUpdateFinished(result);
                    fireStatusUpdated();
                    Log.i(TAG, "Switching storage providers finished at " + new Date().toString() + ".");

                    wl.release();
                    t.stop();
                }
            }

        }, "Storage Provider Switch Worker");
        runningThread.start();
    }
}

From source file:github.daneren2005.dsub.service.DownloadService.java

@Override
public void onCreate() {
    super.onCreate();

    final SharedPreferences prefs = Util.getPreferences(this);
    new Thread(new Runnable() {
        public void run() {
            Looper.prepare();//from www.j ava 2s .  co  m

            mediaPlayer = new MediaPlayer();
            mediaPlayer.setWakeMode(DownloadService.this, PowerManager.PARTIAL_WAKE_LOCK);

            audioSessionId = -1;
            Integer id = prefs.getInt(Constants.CACHE_AUDIO_SESSION_ID, -1);
            if (id != -1) {
                try {
                    audioSessionId = id;
                    mediaPlayer.setAudioSessionId(audioSessionId);
                } catch (Throwable e) {
                    audioSessionId = -1;
                }
            }

            if (audioSessionId == -1) {
                mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
                try {
                    audioSessionId = mediaPlayer.getAudioSessionId();
                    prefs.edit().putInt(Constants.CACHE_AUDIO_SESSION_ID, audioSessionId).commit();
                } catch (Throwable t) {
                    // Froyo or lower
                }
            }

            mediaPlayer.setOnErrorListener(new MediaPlayer.OnErrorListener() {
                @Override
                public boolean onError(MediaPlayer mediaPlayer, int what, int more) {
                    handleError(new Exception("MediaPlayer error: " + what + " (" + more + ")"));
                    return false;
                }
            });

            try {
                Intent i = new Intent(AudioEffect.ACTION_OPEN_AUDIO_EFFECT_CONTROL_SESSION);
                i.putExtra(AudioEffect.EXTRA_AUDIO_SESSION, audioSessionId);
                i.putExtra(AudioEffect.EXTRA_PACKAGE_NAME, getPackageName());
                sendBroadcast(i);
            } catch (Throwable e) {
                // Froyo or lower
            }

            effectsController = new AudioEffectsController(DownloadService.this, audioSessionId);
            if (prefs.getBoolean(Constants.PREFERENCES_EQUALIZER_ON, false)) {
                getEqualizerController();
            }

            mediaPlayerLooper = Looper.myLooper();
            mediaPlayerHandler = new Handler(mediaPlayerLooper);

            if (runListenersOnInit) {
                onSongsChanged();
                onSongProgress();
                onStateUpdate();
            }

            Looper.loop();
        }
    }, "DownloadService").start();

    Util.registerMediaButtonEventReceiver(this);

    if (mRemoteControl == null) {
        // Use the remote control APIs (if available) to set the playback state
        mRemoteControl = RemoteControlClientHelper.createInstance();
        ComponentName mediaButtonReceiverComponent = new ComponentName(getPackageName(),
                MediaButtonIntentReceiver.class.getName());
        mRemoteControl.register(this, mediaButtonReceiverComponent);
    }

    PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
    wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, this.getClass().getName());
    wakeLock.setReferenceCounted(false);

    try {
        timerDuration = Integer.parseInt(prefs.getString(Constants.PREFERENCES_KEY_SLEEP_TIMER_DURATION, "5"));
    } catch (Throwable e) {
        timerDuration = 5;
    }
    sleepTimer = null;

    keepScreenOn = prefs.getBoolean(Constants.PREFERENCES_KEY_KEEP_SCREEN_ON, false);

    mediaRouter = new MediaRouteManager(this);

    instance = this;
    shufflePlayBuffer = new ShufflePlayBuffer(this);
    artistRadioBuffer = new ArtistRadioBuffer(this);
    lifecycleSupport.onCreate();
}

From source file:com.plusot.senselib.SenseMain.java

@SuppressWarnings("deprecation")
private void unlockScreen() {
    if (Globals.testing.isVerbose())
        LLog.d(Globals.TAG, CLASSTAG + ".unLockScreen");
    getWindow().addFlags(//from   ww w.  ja v a 2 s.  c om
            WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
                    | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
    final PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
    final PowerManager.WakeLock wl = pm.newWakeLock(
            (PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE),
            Globals.TAG + "_WakeLock2");
    wl.acquire();
    new SleepAndWake(new SleepAndWake.Listener() {
        @Override
        public void onWake() {
            wl.release();
        }
    }, 2000);

}

From source file:com.koma.music.service.MusicService.java

private void handleHeadsetHookClick(long timestamp) {
    if (mHeadsetHookWakeLock == null) {
        PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
        mHeadsetHookWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "KomaMusic headset button");
        mHeadsetHookWakeLock.setReferenceCounted(false);
    }// ww  w.  j a  va  2 s  . c o m
    // Make sure we don't indefinitely hold the wake lock under any circumstances
    mHeadsetHookWakeLock.acquire(10000);

    Message msg = mPlayerHandler.obtainMessage(MusicServiceConstants.HEADSET_HOOK_EVENT,
            Long.valueOf(timestamp));
    msg.sendToTarget();
}

From source file:org.yammp.MusicPlaybackService.java

@Override
public void onCreate() {

    super.onCreate();

    mApplication = (YAMMPApplication) getApplication();

    mUtils = mApplication.getMediaUtils();

    mPlaybackIntent = new Intent();

    mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);

    mAudioManager.registerMediaButtonEventReceiver(
            new ComponentName(getPackageName(), MediaButtonIntentReceiver.class.getName()));

    mPrefs = new PreferencesEditor(getApplicationContext());

    mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    mShakeDetector = new ShakeListener(this);

    mCardId = mUtils.getCardId();//from   ww w. j a v  a  2  s  .  c  om

    registerExternalStorageListener();
    registerA2dpServiceListener();

    // Needs to be done in this thread, since otherwise
    // ApplicationContext.getPowerManager() crashes.
    mPlayer = new MultiPlayer();
    mPlayer.setHandler(mMediaplayerHandler);

    if (mEqualizerSupported) {
        mEqualizer = new EqualizerWrapper(0, getAudioSessionId());
        if (mEqualizer != null) {
            mEqualizer.setEnabled(true);
            reloadEqualizer();
        }
    }

    reloadQueue();

    IntentFilter commandFilter = new IntentFilter();
    commandFilter.addAction(SERVICECMD);
    commandFilter.addAction(TOGGLEPAUSE_ACTION);
    commandFilter.addAction(PAUSE_ACTION);
    commandFilter.addAction(NEXT_ACTION);
    commandFilter.addAction(PREVIOUS_ACTION);
    commandFilter.addAction(CYCLEREPEAT_ACTION);
    commandFilter.addAction(TOGGLESHUFFLE_ACTION);
    commandFilter.addAction(BROADCAST_PLAYSTATUS_REQUEST);
    registerReceiver(mIntentReceiver, commandFilter);

    registerReceiver(mExternalAudioDeviceStatusReceiver, new IntentFilter(Intent.ACTION_HEADSET_PLUG));

    PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
    mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, this.getClass().getName());
    mWakeLock.setReferenceCounted(false);

    // If the service was idle, but got killed before it stopped itself, the
    // system will relaunch it. Make sure it gets stopped again in that
    // case.
    Message msg = mDelayedStopHandler.obtainMessage();
    mDelayedStopHandler.sendMessageDelayed(msg, IDLE_DELAY);
}

From source file:com.bluros.music.MusicService.java

@Override
public void onCreate() {
    if (D)//  w  ww. j ava  2 s  .  c  om
        Log.d(TAG, "Creating service");
    super.onCreate();

    mNotificationManager = NotificationManagerCompat.from(this);

    // gets a pointer to the playback state store
    mPlaybackStateStore = MusicPlaybackState.getInstance(this);
    mSongPlayCount = SongPlayCount.getInstance(this);
    mRecentStore = RecentStore.getInstance(this);

    mHandlerThread = new HandlerThread("MusicPlayerHandler", android.os.Process.THREAD_PRIORITY_BACKGROUND);
    mHandlerThread.start();

    mPlayerHandler = new MusicPlayerHandler(this, mHandlerThread.getLooper());

    mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
    mMediaButtonReceiverComponent = new ComponentName(getPackageName(),
            MediaButtonIntentReceiver.class.getName());
    mAudioManager.registerMediaButtonEventReceiver(mMediaButtonReceiverComponent);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
        setUpMediaSession();

    mPreferences = getSharedPreferences("Service", 0);
    mCardId = getCardId();

    registerExternalStorageListener();

    mPlayer = new MultiPlayer(this);
    mPlayer.setHandler(mPlayerHandler);

    // Initialize the intent filter and each action
    final IntentFilter filter = new IntentFilter();
    filter.addAction(SERVICECMD);
    filter.addAction(TOGGLEPAUSE_ACTION);
    filter.addAction(PAUSE_ACTION);
    filter.addAction(STOP_ACTION);
    filter.addAction(SLEEP_MODE_STOP_ACTION);
    filter.addAction(NEXT_ACTION);
    filter.addAction(PREVIOUS_ACTION);
    filter.addAction(PREVIOUS_FORCE_ACTION);
    filter.addAction(REPEAT_ACTION);
    filter.addAction(SHUFFLE_ACTION);
    filter.addAction(RemoteSelectDialog.REMOTE_START_SCAN);
    filter.addAction(RemoteSelectDialog.REMOTE_STOP_SCAN);
    filter.addAction(RemoteSelectDialog.REMOTE_CONNECT);
    // Attach the broadcast listener
    registerReceiver(mIntentReceiver, filter);

    mMediaStoreObserver = new MediaStoreObserver(mPlayerHandler);
    getContentResolver().registerContentObserver(MediaStore.Audio.Media.INTERNAL_CONTENT_URI, true,
            mMediaStoreObserver);
    getContentResolver().registerContentObserver(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, true,
            mMediaStoreObserver);

    // Initialize the wake lock
    final PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
    mWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, getClass().getName());
    mWakeLock.setReferenceCounted(false);

    final Intent shutdownIntent = new Intent(this, MusicService.class);
    shutdownIntent.setAction(SHUTDOWN);

    mAlarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
    mShutdownIntent = PendingIntent.getService(this, 0, shutdownIntent, 0);

    scheduleDelayedShutdown();

    reloadQueueAfterPermissionCheck();
    notifyChange(QUEUE_CHANGED);
    notifyChange(META_CHANGED);
}

From source file:org.kontalk.service.msgcenter.MessageCenterService.java

@Override
public void onCreate() {
    configure();//  w w  w. ja v  a 2  s  . co m

    // create the roster store
    mRosterStore = new SQLiteRosterStore(this);

    // create the global wake lock
    PowerManager pwr = (PowerManager) getSystemService(Context.POWER_SERVICE);
    mWakeLock = pwr.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, Kontalk.TAG);
    mWakeLock.setReferenceCounted(false);
    mPingLock = pwr.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, Kontalk.TAG + "-Ping");
    mPingLock.setReferenceCounted(false);

    mAlarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
    // cancel any pending alarm intent
    cancelIdleAlarm();

    mLocalBroadcastManager = LocalBroadcastManager.getInstance(this);
    mPushService = PushServiceManager.getInstance(this);

    // create idle handler
    createIdleHandler();

    // create main thread handler
    mHandler = new Handler();

    // register screen off listener for manual inactivation
    registerInactivity();
}

From source file:com.plusot.senselib.SenseMain.java

@SuppressLint("Wakelock")
@SuppressWarnings("deprecation")
public void updateSetting(SharedPreferences prefs, PreferenceKey key, boolean firstTime) {
    switch (key) {
    case AUTOSWITCH:
        if (key.getInt() > 1800000) {
            PreferenceKey.CLICKSWITCH.set(true);
        }//from  w ww.  j  a  v  a  2  s.  c o  m
        break;
    case CLICKSWITCH:
        clickSwitch = key.isTrue();
        break;
    case DIM:
        if (wakeLock != null && wakeLock.isHeld()) {
            wakeLock.release();
            wakeLock = null;
        }
        final PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
        allowHandWake = false;
        switch (PreferenceKey.getDimmable()) {
        case SCREENOFF_WAKE:
            allowHandWake = true;
        case SCREENOFF_FULL:
            getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
            wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, Globals.TAG + "_WakeLock");
            wakeLock.acquire();
            break;
        case NODIM:
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
            break;
        case DIM:
        default:
            allowHandWake = true;
            getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
            wakeLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, Globals.TAG + "_WakeLock");
            wakeLock.acquire();
            break;
        }
        break;
    case DISPLAYNAME:
        UserInfo.UserData user = UserInfo.getUserData();
        if (user == null)
            return;
        key.getString(user.name);
        break;
    case HASMAP:
        new SleepAndWake(new SleepAndWake.Listener() {

            @Override
            public void onWake() {
                if (PreferenceKey.HASMAP.isTrue()) {
                    addMap();
                    adjustViews();
                } else {
                    releaseMap();
                    if (!visible)
                        toggleValuesVisible();
                }
            }
        }, 500);

        break;
    case HTTPPOST:
        HttpSender.isHttpPost = key.isTrue();
        break;
    case STOPSTATE:
        PreferenceKey.getStopState();
        break;
    case STORAGE:
        Value.fileTypes = PreferenceKey.getStorageFiles();
        break;
    case TESTING:
        PreferenceKey.isTesting();
        break;
    case WHEELSIZE:
    case WHEELCIRC:
        PreferenceKey.getWheelCirc();

        break;
    case XTRAVALUES:
        key.isTrue();
        break;
    case IMEI:
        UserInfo.resetDeviceId();
        break;
    case TILESOURCE:
        key.get();
        if (!firstTime) {
            if (map != null) {
                RelativeLayout view = (RelativeLayout) findViewById(R.id.main_rootlayout);
                view.removeView(map);
                map.removeAllViews();
                map.setOnTouchListener((ClickableOverlay.Listener) null);
                map = null;
            }

            addMap();
            //ToastHelper.showToastLong(R.string.change_tilesource);
        }
        break;
    case BLE_DEVICE:
        key.get();
        break;
    default:
        key.get();
    }
}

From source file:org.telegram.ui.Components.ChatActivityEnterView.java

private void updateRecordIntefrace() {
    if (recordingAudioVideo) {
        if (recordInterfaceState == 1) {
            return;
        }/*from   w w w .j ava2s .c om*/
        recordInterfaceState = 1;
        try {
            if (wakeLock == null) {
                PowerManager pm = (PowerManager) ApplicationLoader.applicationContext
                        .getSystemService(Context.POWER_SERVICE);
                wakeLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE,
                        "audio record lock");
                wakeLock.acquire();
            }
        } catch (Exception e) {
            FileLog.e(e);
        }
        AndroidUtilities.lockOrientation(parentActivity);

        recordPanel.setVisibility(VISIBLE);
        recordCircle.setVisibility(VISIBLE);
        recordCircle.setAmplitude(0);
        recordTimeText.setText("00:00");
        recordDot.resetAlpha();
        lastTimeString = null;

        FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) slideText.getLayoutParams();
        params.leftMargin = AndroidUtilities.dp(30);
        slideText.setLayoutParams(params);
        slideText.setAlpha(1);
        recordPanel.setX(AndroidUtilities.displaySize.x);
        recordCircle.setTranslationX(0);
        if (runningAnimationAudio != null) {
            runningAnimationAudio.cancel();
        }
        runningAnimationAudio = new AnimatorSet();
        runningAnimationAudio.playTogether(ObjectAnimator.ofFloat(recordPanel, "translationX", 0),
                ObjectAnimator.ofFloat(recordCircle, "scale", 1),
                ObjectAnimator.ofFloat(audioVideoButtonContainer, "alpha", 0));
        runningAnimationAudio.setDuration(300);
        runningAnimationAudio.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animator) {
                if (runningAnimationAudio != null && runningAnimationAudio.equals(animator)) {
                    recordPanel.setX(0);
                    runningAnimationAudio = null;
                }
            }
        });
        runningAnimationAudio.setInterpolator(new DecelerateInterpolator());
        runningAnimationAudio.start();
    } else {
        if (wakeLock != null) {
            try {
                wakeLock.release();
                wakeLock = null;
            } catch (Exception e) {
                FileLog.e(e);
            }
        }
        AndroidUtilities.unlockOrientation(parentActivity);
        if (recordInterfaceState == 0) {
            return;
        }
        recordInterfaceState = 0;

        if (runningAnimationAudio != null) {
            runningAnimationAudio.cancel();
        }
        runningAnimationAudio = new AnimatorSet();
        runningAnimationAudio.playTogether(
                ObjectAnimator.ofFloat(recordPanel, "translationX", AndroidUtilities.displaySize.x),
                ObjectAnimator.ofFloat(recordCircle, "scale", 0.0f),
                ObjectAnimator.ofFloat(audioVideoButtonContainer, "alpha", 1.0f));
        runningAnimationAudio.setDuration(300);
        runningAnimationAudio.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animator) {
                if (runningAnimationAudio != null && runningAnimationAudio.equals(animator)) {
                    FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) slideText.getLayoutParams();
                    params.leftMargin = AndroidUtilities.dp(30);
                    slideText.setLayoutParams(params);
                    slideText.setAlpha(1);
                    recordPanel.setVisibility(GONE);
                    recordCircle.setVisibility(GONE);
                    runningAnimationAudio = null;
                }
            }
        });
        runningAnimationAudio.setInterpolator(new AccelerateInterpolator());
        runningAnimationAudio.start();
    }
}