Example usage for android.os RemoteException printStackTrace

List of usage examples for android.os RemoteException printStackTrace

Introduction

In this page you can find the example usage for android.os RemoteException printStackTrace.

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:com.xmobileapp.rockplayer.RockPlayer.java

/**********************************
 * // ww  w.  ja  v  a2  s.  c o m
 * NextSongClickListenerHelper
 * 
 **********************************/
public void nextSongClickListenerHelper() {
    try {
        /* In case the album is paused */
        //AlphaAnimation   fadeIn = new AlphaAnimation((float)1.0,(float)1.0);
        //fadeIn.setFillAfter(true);
        //fadeIn.setDuration(1);
        //currentAlbumPlayingLayout.startAnimation(fadeIn);

        /* Play next song */
        playerServiceIface.playNext();
    } catch (RemoteException e) {
        e.printStackTrace();
    }
}

From source file:com.xmobileapp.rockplayer.RockPlayer.java

/*************************************
 * /*from   w w w.  j  a v a 2 s .  co m*/
 * Update Song Progress
 * 
 *************************************/
private void updateSongProgress() {
    try {

        this.songProgressBar.setMax((int) this.songCursor
                .getDouble(this.songCursor.getColumnIndexOrThrow(MediaStore.Audio.Media.DURATION)));
        this.songProgressBar.setProgress(playerServiceIface.getPlayingPosition());

        if (playerServiceIface.isPlaying()) {
            if (songProgressTimer != null)
                songProgressTimer.cancel();
            this.songProgressTimer = new Timer();
            this.songProgressTimer.scheduleAtFixedRate(new SongProgressTimerTask(), 100, 1000);

        }

    } catch (RemoteException e) {
        e.printStackTrace();
    }
}

From source file:com.xmobileapp.rockplayer.RockPlayer.java

/*************************************
 * /*  www  .j  a v a 2  s  . com*/
 * showSongList
 * 
 *************************************/
private void showSongList() {

    /*
     * Move album Cursor
     */
    try {
        albumCursor.moveToPosition(playerServiceIface.getAlbumCursorPosition());
    } catch (RemoteException e) {
        e.printStackTrace();
    }
    albumNavigatorItemLongClickIndex = albumCursor.getPosition();

    /*
     * getSongCursor
     */
    songCursor = initializeSongCursor(
            albumCursor.getString(albumCursor.getColumnIndexOrThrow(MediaStore.Audio.Albums.ALBUM)));

    /*
     * populate song list
     */
    String[] fieldsFrom = new String[1];
    int[] fieldsTo = new int[1];
    fieldsFrom[0] = MediaStore.Audio.Media.TITLE;
    fieldsTo[0] = R.id.songlist_item_song_name;
    SongCursorAdapter songAdapter = new SongCursorAdapter(this, R.layout.songlist_dialog_item, songCursor,
            fieldsFrom, fieldsTo);

    /*
     * Create Dialog
     */
    AlertDialog.Builder aD = new AlertDialog.Builder(context);
    aD.create();
    aD.setTitle(albumCursor.getString(albumCursor.getColumnIndexOrThrow(MediaStore.Audio.Albums.ALBUM)) + "\n"
            + albumCursor.getString(albumCursor.getColumnIndexOrThrow(MediaStore.Audio.Albums.ARTIST)));
    aD.setAdapter(songAdapter, songListDialogClickListener);
    aD.show();
}

From source file:com.xmobileapp.rockplayer.RockPlayer.java

/*********************************************
 * /*from  ww  w.j a va2s.co m*/
 * getCurrentPlaying
 *    get what the player service is currently
 *    playing and update UI
 *
 *********************************************/
public void getCurrentPlaying() {
    //if(true) return;

    /*
     * ask the player service if/what he is playing
     */
    int albumCursorPosition = 0;
    int songCursorPosition = 0;
    try {
        albumCursorPosition = this.playerServiceIface.getAlbumCursorPosition();
        songCursorPosition = this.playerServiceIface.getSongCursorPosition();
    } catch (RemoteException e) {
        e.printStackTrace();
    }
    if (albumCursorPosition == -1 || songCursorPosition == -1) {
        //         Log.i("GETCURPLAY", "BOTH CURSORS ARE -1");
        //         try{
        //            Random rand = new Random();
        //            if(albumCursor != null && rand != null)
        //               albumCursorPosition = rand.nextInt(albumCursor.getCount()-1);
        //            else
        //               albumCursorPosition = 1;
        //            albumCursorPositionPlaying = albumCursorPosition;
        //            songCursorPosition = 0;
        //         } catch (Exception e) {
        //            try{
        //               if(albumCursor != null)
        //                  Log.i("EXCP", ""+albumCursor.getCount());
        //            } catch (Exception ee){
        //               ee.printStackTrace();
        //            }
        //            e.printStackTrace();
        //            albumCursorPosition = 0;
        //            albumCursorPositionPlaying = albumCursorPosition;
        //            songCursorPosition = 0;
        //         }
        //         try {
        //            playerServiceIface.setAlbumCursorPosition(albumCursorPosition);
        //            playerServiceIface.setSongCursorPosition(songCursorPosition);
        //            playerServiceIface.play(albumCursorPosition, songCursorPosition);
        //            playerServiceIface.pause();
        //            // HACKzzzzzzzzz we need a paused event from the service
        //            this.stopSongProgress();
        //         } catch (RemoteException e) {
        //            e.printStackTrace();
        //         }
    } else {
        try {
            if (playerServiceIface.isPlaying()) {
                TransitionDrawable playPauseTDrawable = (TransitionDrawable) playPauseImage.getDrawable();
                playPauseTDrawable.setCrossFadeEnabled(true);
                playPauseTDrawable.startTransition(1);
                playPauseTDrawable.invalidateSelf();
                //                this.playPauseImage.setImageResource(android.R.drawable.ic_media_pause);          }
            } else {
                albumCursorPosition = playerServiceIface.getAlbumCursorPosition();
                songCursorPosition = playerServiceIface.getSongCursorPosition();
                albumCursorPositionPlaying = albumCursorPosition;

                //               Log.i("INIT", albumCursorPosition+" "+songCursorPosition);
                //               playerServiceIface.play(albumCursorPositionPlaying,
                //                                 songCursorPosition);
                //               playerServiceIface.pause();
                this.stopSongProgress();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    // TODO: ask if he is playing
    /*
     * If media Library is empty just show a popup
     */
    if (albumCursor.getCount() == 0) {
        Dialog noMediaDialog = new Dialog(this);
        noMediaDialog.setTitle("No Media Available");
        //TextView noMediaText = new TextView(this);
        //noMediaText.setText("Please add some Music to your SD Card");
        //noMediaDialog.setContentView(noMediaText);
        noMediaDialog.show();
        return;
    }

    /*
     * Go to the current playing Media
     */
    Log.i("GETCURPLAY", "MOVING CURSORS");

    try {
        albumCursor.moveToPosition(albumCursorPosition);
        albumCursorPositionPlaying = albumCursorPosition;
        songCursor = initializeSongCursor(
                albumCursor.getString(albumCursor.getColumnIndexOrThrow(MediaStore.Audio.Albums.ALBUM)));
        songCursor.moveToPosition(songCursorPosition);
    } catch (Exception e) {
        e.printStackTrace();
    }

    Log.i("GETCURPLAY", "GET ALBUM ART");

    try {
        //         /*
        //          * get albumArt
        //          */
        //         String albumCoverPath = albumCursor.getString(
        //                              albumCursor.getColumnIndexOrThrow(
        //                                 MediaStore.Audio.Albums.ALBUM_ART));
        //          // if it does not exist in database look for our dir
        //          if(albumCoverPath == null){
        //             String artistName = albumCursor.getString(
        //                              albumCursor.getColumnIndexOrThrow(
        //                                    MediaStore.Audio.Albums.ARTIST));
        //             String albumName = albumCursor.getString(
        //                              albumCursor.getColumnIndexOrThrow(
        //                                    MediaStore.Audio.Albums.ALBUM));
        //             String path = this.FILEX_ALBUM_ART_PATH+
        //                         validateFileName(artistName)+
        //                        " - "+
        //                        validateFileName(albumName)+
        //                        FILEX_FILENAME_EXTENSION;
        //             File albumCoverFilePath = new File(path);
        //            if(albumCoverFilePath.exists() && albumCoverFilePath.length() > 0){
        //               albumCoverPath = path;
        //            }
        //          }
        //          
        //          Log.i("GETCURPLAY", "UPDATING UI COMPONENT");
        //
        //           /*
        //           * Update currentPlaying albumArt UI component
        //           */
        //         if(albumCoverPath != null){
        //            // TODO:
        //            // adjust sample size
        //            Options opts = new Options();
        //            opts.inSampleSize = 1;
        //            Bitmap albumCoverBitmap = BitmapFactory.decodeFile(albumCoverPath, opts);
        //            this.currentAlbumPlayingImageView.setImageBitmap(albumCoverBitmap);
        //         } else {
        //            // TODO:
        //            // adjust sample size dynamically
        //            Options opts = new Options();
        //            opts.inSampleSize = 1;
        //            Bitmap albumCoverBitmap = BitmapFactory.decodeResource(this.context.getResources(),
        //                                                R.drawable.albumart_mp_unknown, opts);
        //            if(albumCoverBitmap != null)
        //               this.currentAlbumPlayingImageView.setImageBitmap(albumCoverBitmap);
        //         }

        if (VIEW_STATE == FULLSCREEN_VIEW)
            this.currentAlbumPlayingImageView.setImageBitmap(
                    albumAdapter.getAlbumBitmap(albumCursor.getPosition(), BITMAP_SIZE_FULLSCREEN));
        else
            this.currentAlbumPlayingImageView
                    .setImageBitmap(albumAdapter.getAlbumBitmap(albumCursor.getPosition(), BITMAP_SIZE_NORMAL));

        if (showFrame)
            this.currentAlbumPlayingOverlayImageView.setVisibility(View.VISIBLE);
        else
            this.currentAlbumPlayingOverlayImageView.setVisibility(View.GONE);

        Log.i("GETCURPLAY", "UPDATING REST OF UI");

        /*
         * Update currentPlaying artist UI component
         */
        this.updateArtistTextUI();
        /*
         * Update currentPlaying song UI component
         */
        this.updateSongTextUI();
        /*
         * Update Song Progress
         */
        this.updateSongProgress();

        Log.i("GETCURPLAY", "CENTER ALBUMLIST");

        /*
         * Center Album List
         */
        albumNavigatorList.setSelectionFromTop(albumCursorPositionPlaying,
                (int) Math.round((display.getHeight() - 20) / 2.0
                        - (display.getWidth() * (1 - CURRENT_PLAY_SCREEN_FRACTION_LANDSCAPE))));
        this.albumNavigatorScrollListener.onScrollStateChanged(this.albumNavigatorList,
                OnScrollListener.SCROLL_STATE_IDLE);

    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.xmobileapp.rockplayer.RockPlayer.java

public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    /*//ww  w  . j av  a 2s  .  co  m
     * Shuffle
     */
    case 0:
        if (this.SHUFFLE)
            this.SHUFFLE = false;
        else
            this.SHUFFLE = true;
        try {
            playerServiceIface.setShuffle(this.SHUFFLE);
        } catch (RemoteException e) {
            e.printStackTrace();
        }
        RockOnPreferenceManager settings = new RockOnPreferenceManager(FILEX_PREFERENCES_PATH);
        settings.putBoolean("Shuffle", this.SHUFFLE);
        return true;
    /*
     * Search
     */
    case 1:
        if (GRATIS) {
            showLitePopup();
            return true;
        }

        //this.hideMainUI();
        this.showSongSearch();
        this.songSearchTextView.requestFocus();
        Cursor allSongsCursor = contentResolver.query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, SONG_COLS, // we should minimize the number of columns
                null, // all songs
                null, // parameters to the previous parameter - which is null also 
                null // sort order, SQLite-like
        );
        SimpleCursorAdapter songAdapter = new SimpleCursorAdapter(this, R.layout.simple_dropdown_item_2line,
                allSongsCursor, new String[] { MediaStore.Audio.Media.TITLE, MediaStore.Audio.Media.ARTIST },
                new int[] { R.id.text1, R.id.text2 });
        FilterQueryProvider songSearchFilterProvider = new FilterQueryProvider() {
            @Override
            public Cursor runQuery(CharSequence constraint) {
                String whereClause = MediaStore.Audio.Media.TITLE + " LIKE '%" + constraint + "%'" + " OR "
                        + MediaStore.Audio.Media.ARTIST + " LIKE '%" + constraint + "%'";
                Log.i("SEARCH", whereClause);
                //whereClause = null;
                Cursor songsCursor = contentResolver.query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
                        SONG_COLS, // we should minimize the number of columns
                        whereClause, // songs where the title or artist name matches
                        null, // parameters to the previous parameter - which is null also 
                        null // sort order, SQLite-like
                );
                return songsCursor;
            }
        };
        songAdapter.setFilterQueryProvider(songSearchFilterProvider);
        this.songSearchTextView.setAdapter(songAdapter);
        songAdapter
                .setStringConversionColumn(allSongsCursor.getColumnIndexOrThrow(MediaStore.Audio.Media.TITLE));
        //this.songSearchTextView.setOnKeyListener(songSearchKeyListener);
        return true;
    /*
     * Share
     */
    case 5:
        if (GRATIS) {
            showLitePopup();
            return true;
        }

        ShareSong shareSong = new ShareSong(context, songCursor);
        shareSong.shareByMail();
        return true;
    /*
     * Get Art
     */
    case 3:
        //           if(GRATIS){
        //              showLitePopup();
        //              return true;
        //           }
        albumReloadProgressDialog = new ProgressDialog(this);
        albumReloadProgressDialog.setIcon(R.drawable.ic_menu_music_library);
        albumReloadProgressDialog.setTitle("Loading Album Art");
        albumReloadProgressDialog.setMessage("Waiting for Last.FM connection");
        // TODO: set powered by Last.FM
        albumReloadProgressDialog.show();
        Thread albumArtThread = new Thread() {
            public void run() {
                try {
                    LastFmAlbumArtImporter lastFmArtImporter = new LastFmAlbumArtImporter(context);
                    lastFmArtImporter.getAlbumArt();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        };
        //albumArtThread.setUncaughtExceptionHandler(albumArtUncaughtExceptionHandler);
        albumArtThread.start();
        //containerLayout.addView(albumReloadProgressDialog);
        return true;
    /*
     * Concerts
     */
    case 4:
        if (GRATIS) {
            showLitePopup();
            return true;
        }

        this.hideMainUI();
        this.mainUIContainer.setVisibility(View.GONE);
        //this.hideHelpUI();
        this.showEventUI();

        /*
         * Concert Radius Thing 
         */
        // TODO: need a metric
        //         SharedPreferences prefs = getSharedPreferences(PREFS_NAME, 0);
        RockOnPreferenceManager prefs = new RockOnPreferenceManager(FILEX_PREFERENCES_PATH);
        concertRadius = prefs.getLong("ConcertRadius", (long) (this.CONCERT_RADIUS_DEFAULT));
        this.eventListRadius.setText(String.valueOf(Math.round((float) concertRadius / 1000)));

        /*
         * Show a dialog to give some nice feedback to the user
         */
        concertAnalysisProgressDialog = new ProgressDialog(this);
        concertAnalysisProgressDialog.setIcon(android.R.drawable.ic_menu_today);
        concertAnalysisProgressDialog.setTitle("Analysing concert information");
        concertAnalysisProgressDialog.setMessage("Waiting for Last.FM connection");
        concertAnalysisProgressDialog.show();

        /*
         * Analyze concert info
         */
        lastFmEventImporter = new LastFmEventImporter(context);
        new Thread() {
            public void run() {
                try {
                    lastFmEventImporter.getArtistEvents();
                } catch (SAXException e) {
                    e.printStackTrace();
                } catch (ParserConfigurationException e) {
                    e.printStackTrace();
                }
            }
        }.start();
        return true;
    /*
     * Playlists
     */
    case 6:
        if (GRATIS) {
            showLitePopup();
            return true;
        }

        /*
         * Get the views and make them visible
         */
        String sortOrder = MediaStore.Audio.Playlists.NAME + " ASC";
        Cursor playlistAllCursor = contentResolver.query(MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI,
                this.PLAYLIST_COLS, null, null, sortOrder);

        /*
         * Create Array with custom playlist + system playlists
         */
        Playlist playlistTemp;
        ArrayList<Playlist> playlistArray = new ArrayList<Playlist>();
        /* ALL Playlist*/
        playlistTemp = new Playlist();
        playlistTemp.id = constants.PLAYLIST_ALL;
        playlistTemp.name = "All songs";
        playlistArray.add(playlistTemp);
        /* Recently Added */
        playlistTemp = new Playlist();
        playlistTemp.id = constants.PLAYLIST_RECENT;
        playlistTemp.name = "Recently Added";
        playlistArray.add(playlistTemp);
        /* ... other system playlists ... */

        /* add every playlist in the media store */
        while (playlistAllCursor.moveToNext()) {
            playlistTemp = new Playlist();
            playlistTemp.id = playlistAllCursor
                    .getLong(playlistAllCursor.getColumnIndexOrThrow(MediaStore.Audio.Playlists._ID));
            playlistTemp.name = playlistAllCursor
                    .getString(playlistAllCursor.getColumnIndexOrThrow(MediaStore.Audio.Playlists.NAME));
            playlistArray.add(playlistTemp);
            Log.i("PLAYLIST MENU", playlistTemp.id + " " + playlistTemp.name);
        }

        //           String[] fieldsFrom = new String[1];
        //          int[]   fieldsTo = new int[1];
        //           fieldsFrom[0] = MediaStore.Audio.Playlists.NAME;
        //          fieldsTo[0] = R.id.playlist_name;
        //           PlaylistCursorAdapter playlistAllAdapter = new PlaylistCursorAdapter(this.getApplicationContext(),
        //                                                                 R.layout.playlist_item, 
        //                                                                 playlistAllCursor, 
        //                                                                 fieldsFrom, 
        //                                                                 fieldsTo);
        PlaylistArrayAdapter playlistAllAdapter = new PlaylistArrayAdapter(getApplicationContext(),
                R.layout.playlist_item, playlistArray);

        /*
         * Create Dialog
         */
        AlertDialog.Builder aD = new AlertDialog.Builder(context);
        aD.create();
        aD.setTitle("Select Playlist");
        aD.setAdapter(playlistAllAdapter, playlistDialogClickListener);
        aD.show();

        //           playlistView.setAdapter(playlistAllAdapter);
        //           
        //           playlistView.setOnItemClickListener(playlistItemClickListener);

        //           /*
        //            * Animate scroll up of the listview
        //            */
        //           TranslateAnimation slideUp = new TranslateAnimation(0,0,display.getHeight(),0);
        //           slideUp.setFillAfter(true);
        //           slideUp.setDuration(250);
        //           playlistContainer.startAnimation(slideUp);
        //           
        //this.mainUIContainer.addView(playlistAllSpinner);
        return true;
    /*
     * Preferences
     */
    case 7:
        if (GRATIS) {
            showLitePopup();
            return true;
        }

        Intent i = new Intent();
        i.setClass(getApplicationContext(), RockOnSettings.class);
        //              this.recentPlaylistPeriod = getSharedPreferences(PREFS_NAME, 0)
        (new RockOnPreferenceManager(FILEX_PREFERENCES_PATH)).getInt(new Constants().PREF_KEY_RECENT_PERIOD,
                new Constants().RECENT_PERIOD_DEFAULT_IN_DAYS);
        startActivityForResult(i, new Constants().PREFERENCES_REQUEST);
        return true;
    /*
     * Help
     */
    case 8:
        this.hideMainUI();
        //this.mainUIContainer.setVisibility(View.GONE);
        this.showHelpUI();
        return true;
    /*
     * Exit
     */
    case 2:
        try {
            this.playerServiceIface.destroy();
            this.finish();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return true;
    }
    return false;
}

From source file:org.tvbrowser.tvbrowser.TvBrowser.java

private void synchronizeDontWantToSee(final boolean replace) {
    new Thread() {
        public void run() {
            if (!SettingConstants.UPDATING_FILTER) {
                SettingConstants.UPDATING_FILTER = true;

                Context applicationContext = getApplicationContext();

                NotificationCompat.Builder builder;

                builder = new NotificationCompat.Builder(TvBrowser.this);
                builder.setSmallIcon(R.drawable.ic_stat_notify);
                builder.setOngoing(true);
                builder.setContentTitle(getResources().getText(R.string.action_dont_want_to_see));
                builder.setContentText(getResources().getText(R.string.dont_want_to_see_notification_text));

                int notifyID = 2;

                NotificationManager notification = (NotificationManager) getSystemService(
                        Context.NOTIFICATION_SERVICE);
                notification.notify(notifyID, builder.build());

                updateProgressIcon(true);

                URL documentUrl;/*from   w  ww . j  ava2s .c o  m*/

                try {
                    documentUrl = new URL(
                            "http://android.tvbrowser.org/data/scripts/syncDown.php?type=dontWantToSee");
                    URLConnection connection = documentUrl.openConnection();

                    SharedPreferences pref = getSharedPreferences("transportation", Context.MODE_PRIVATE);

                    String car = pref.getString(SettingConstants.USER_NAME, null);
                    String bicycle = pref.getString(SettingConstants.USER_PASSWORD, null);

                    if (car != null && bicycle != null) {
                        String userpass = car + ":" + bicycle;
                        String basicAuth = "basic "
                                + Base64.encodeToString(userpass.getBytes(), Base64.NO_WRAP);

                        connection.setRequestProperty("Authorization", basicAuth);

                        BufferedReader read = new BufferedReader(new InputStreamReader(
                                new GZIPInputStream(connection.getInputStream()), "UTF-8"));

                        String line = null;

                        StringBuilder exclusionBuilder = new StringBuilder();
                        HashSet<String> exclusions = new HashSet<String>();
                        ArrayList<DontWantToSeeExclusion> exclusionList = new ArrayList<DontWantToSeeExclusion>();

                        while ((line = read.readLine()) != null) {
                            if (line.contains(";;") && line.trim().length() > 0) {
                                exclusions.add(line);
                                exclusionList.add(new DontWantToSeeExclusion(line));
                                exclusionBuilder.append(line).append("\n");
                            }
                        }

                        String key = getString(R.string.I_DONT_WANT_TO_SEE_ENTRIES);
                        SharedPreferences pref1 = PreferenceManager.getDefaultSharedPreferences(TvBrowser.this);

                        Set<String> oldValues = pref1.getStringSet(key, null);

                        if (exclusions.size() > 0) {
                            if (!replace && oldValues != null) {
                                for (String old : oldValues) {
                                    if (!exclusions.contains(old)) {
                                        exclusions.add(old);
                                        exclusionList.add(new DontWantToSeeExclusion(old));
                                        exclusionBuilder.append(old).append("\n");
                                    }
                                }
                            }

                            Editor edit = pref1.edit();

                            edit.putStringSet(key, exclusions);
                            edit.commit();

                            DontWantToSeeExclusion[] exclusionArr = exclusionList
                                    .toArray(new DontWantToSeeExclusion[exclusionList.size()]);

                            Cursor c = getContentResolver().query(TvBrowserContentProvider.CONTENT_URI_DATA,
                                    new String[] { TvBrowserContentProvider.KEY_ID,
                                            TvBrowserContentProvider.DATA_KEY_TITLE },
                                    null, null, TvBrowserContentProvider.KEY_ID);
                            c.moveToPosition(-1);

                            builder.setProgress(c.getCount(), 0, true);
                            notification.notify(notifyID, builder.build());

                            ArrayList<ContentProviderOperation> updateValuesList = new ArrayList<ContentProviderOperation>();

                            int keyColumn = c.getColumnIndex(TvBrowserContentProvider.KEY_ID);
                            int titleColumn = c.getColumnIndex(TvBrowserContentProvider.DATA_KEY_TITLE);

                            while (c.moveToNext()) {
                                builder.setProgress(c.getCount(), c.getPosition(), false);
                                notification.notify(notifyID, builder.build());

                                String title = c.getString(titleColumn);

                                boolean filter = UiUtils.filter(getApplicationContext(), title, exclusionArr);
                                long progID = c.getLong(keyColumn);

                                ContentValues values = new ContentValues();
                                values.put(TvBrowserContentProvider.DATA_KEY_DONT_WANT_TO_SEE, filter ? 1 : 0);

                                ContentProviderOperation.Builder opBuilder = ContentProviderOperation
                                        .newUpdate(ContentUris.withAppendedId(
                                                TvBrowserContentProvider.CONTENT_URI_DATA_UPDATE, progID));
                                opBuilder.withValues(values);

                                updateValuesList.add(opBuilder.build());
                            }

                            c.close();

                            if (!updateValuesList.isEmpty()) {
                                try {
                                    getContentResolver().applyBatch(TvBrowserContentProvider.AUTHORITY,
                                            updateValuesList);
                                    UiUtils.sendDontWantToSeeChangedBroadcast(applicationContext, true);
                                    handler.post(new Runnable() {
                                        @Override
                                        public void run() {
                                            Toast.makeText(getApplicationContext(),
                                                    R.string.dont_want_to_see_sync_success, Toast.LENGTH_LONG)
                                                    .show();
                                        }
                                    });
                                } catch (RemoteException e) {
                                    e.printStackTrace();
                                } catch (OperationApplicationException e) {
                                    e.printStackTrace();
                                }
                            }

                            if (!replace && exclusionBuilder.length() > 0) {
                                startSynchronizeUp(false, exclusionBuilder.toString(),
                                        "http://android.tvbrowser.org/data/scripts/syncUp.php?type=dontWantToSee",
                                        null, null);
                            }
                        } else {
                            if (!replace && oldValues != null && !oldValues.isEmpty()) {
                                for (String old : oldValues) {
                                    exclusionBuilder.append(old).append("\n");
                                }

                                startSynchronizeUp(false, exclusionBuilder.toString(),
                                        "http://android.tvbrowser.org/data/scripts/syncUp.php?type=dontWantToSee",
                                        null, null);
                            }

                            handler.post(new Runnable() {
                                @Override
                                public void run() {
                                    Toast.makeText(getApplicationContext(), R.string.no_dont_want_to_see_sync,
                                            Toast.LENGTH_LONG).show();
                                }
                            });
                        }
                    }
                } catch (Throwable t) {
                    handler.post(new Runnable() {
                        @Override
                        public void run() {
                            Toast.makeText(getApplicationContext(), R.string.no_dont_want_to_see_sync,
                                    Toast.LENGTH_LONG).show();
                        }
                    });
                }

                notification.cancel(notifyID);
                updateProgressIcon(false);

                SettingConstants.UPDATING_FILTER = false;
            }
        }
    }.start();
}

From source file:org.tvbrowser.tvbrowser.TvBrowser.java

private void editDontWantToSee() {
    if (!SettingConstants.UPDATING_FILTER) {
        Set<String> currentExclusions = PrefUtils.getStringSetValue(R.string.I_DONT_WANT_TO_SEE_ENTRIES, null);

        final ArrayList<ExclusionEdit> mCurrentExclusionList = new ArrayList<TvBrowser.ExclusionEdit>();

        if (currentExclusions != null && !currentExclusions.isEmpty()) {
            for (String exclusion : currentExclusions) {
                mCurrentExclusionList.add(new ExclusionEdit(exclusion));
            }/*from  w w w .  j av  a2s .  com*/
        }

        Collections.sort(mCurrentExclusionList);

        final ArrayAdapter<ExclusionEdit> exclusionAdapter = new ArrayAdapter<TvBrowser.ExclusionEdit>(
                TvBrowser.this, android.R.layout.simple_list_item_1, mCurrentExclusionList);

        View view = getLayoutInflater().inflate(R.layout.dont_want_to_see_exclusion_edit_list,
                getParentViewGroup(), false);

        ListView list = (ListView) view.findViewById(R.id.dont_want_to_see_exclusion_list);

        list.setAdapter(exclusionAdapter);

        final Runnable cancel = new Runnable() {
            @Override
            public void run() {
            }
        };

        AdapterView.OnItemClickListener onClickListener = new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                final ExclusionEdit edit = exclusionAdapter.getItem(position);

                View editView = getLayoutInflater().inflate(R.layout.dont_want_to_see_edit,
                        getParentViewGroup(), false);

                final TextView exclusion = (TextView) editView.findViewById(R.id.dont_want_to_see_value);
                final CheckBox caseSensitive = (CheckBox) editView
                        .findViewById(R.id.dont_want_to_see_case_sensitve);

                exclusion.setText(edit.mExclusion);
                caseSensitive.setSelected(edit.mIsCaseSensitive);

                Runnable editPositive = new Runnable() {
                    @Override
                    public void run() {
                        if (exclusion.getText().toString().trim().length() > 0) {
                            edit.mExclusion = exclusion.getText().toString();
                            edit.mIsCaseSensitive = caseSensitive.isSelected();

                            exclusionAdapter.notifyDataSetChanged();
                        }
                    }
                };

                showAlertDialog(getString(R.string.action_dont_want_to_see), null, editView, null, editPositive,
                        null, cancel, false, false);
            }
        };

        list.setOnItemClickListener(onClickListener);
        list.setOnCreateContextMenuListener(new View.OnCreateContextMenuListener() {
            @Override
            public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
                getMenuInflater().inflate(R.menu.don_want_to_see_context, menu);

                MenuItem item = menu.findItem(R.id.dont_want_to_see_delete);

                item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
                    @Override
                    public boolean onMenuItemClick(MenuItem item) {
                        ExclusionEdit edit = exclusionAdapter
                                .getItem(((AdapterView.AdapterContextMenuInfo) item.getMenuInfo()).position);
                        exclusionAdapter.remove(edit);
                        exclusionAdapter.notifyDataSetChanged();

                        return true;
                    }
                });
            }
        });

        Thread positive = new Thread() {
            @Override
            public void run() {
                SettingConstants.UPDATING_FILTER = true;

                final NotificationCompat.Builder builder = new NotificationCompat.Builder(TvBrowser.this);
                builder.setSmallIcon(R.drawable.ic_stat_notify);
                builder.setOngoing(true);
                builder.setContentTitle(getResources().getText(R.string.action_dont_want_to_see));
                builder.setContentText(
                        getResources().getText(R.string.dont_want_to_see_refresh_notification_text));

                final int notifyID = 2;

                final NotificationManager notification = (NotificationManager) getSystemService(
                        Context.NOTIFICATION_SERVICE);
                notification.notify(notifyID, builder.build());

                updateProgressIcon(true);

                HashSet<String> newExclusions = new HashSet<String>();
                final ArrayList<DontWantToSeeExclusion> exclusionList = new ArrayList<DontWantToSeeExclusion>();

                for (ExclusionEdit edit : mCurrentExclusionList) {
                    String exclusion = edit.getExclusion();

                    newExclusions.add(exclusion);
                    exclusionList.add(new DontWantToSeeExclusion(exclusion));
                }

                new Thread() {
                    public void run() {
                        Cursor programs = getContentResolver().query(TvBrowserContentProvider.CONTENT_URI_DATA,
                                new String[] { TvBrowserContentProvider.KEY_ID,
                                        TvBrowserContentProvider.DATA_KEY_TITLE },
                                null, null, TvBrowserContentProvider.KEY_ID);
                        programs.moveToPosition(-1);

                        builder.setProgress(programs.getCount(), 0, true);
                        notification.notify(notifyID, builder.build());

                        ArrayList<ContentProviderOperation> updateValuesList = new ArrayList<ContentProviderOperation>();

                        int keyColumn = programs.getColumnIndex(TvBrowserContentProvider.KEY_ID);
                        int titleColumn = programs.getColumnIndex(TvBrowserContentProvider.DATA_KEY_TITLE);

                        DontWantToSeeExclusion[] exclusionArr = exclusionList
                                .toArray(new DontWantToSeeExclusion[exclusionList.size()]);

                        while (programs.moveToNext()) {
                            builder.setProgress(programs.getCount(), programs.getPosition(), false);
                            notification.notify(notifyID, builder.build());

                            String title = programs.getString(titleColumn);

                            boolean filter = UiUtils.filter(getApplicationContext(), title, exclusionArr);
                            long progID = programs.getLong(keyColumn);

                            ContentValues values = new ContentValues();
                            values.put(TvBrowserContentProvider.DATA_KEY_DONT_WANT_TO_SEE, filter ? 1 : 0);

                            ContentProviderOperation.Builder opBuilder = ContentProviderOperation.newUpdate(
                                    ContentUris.withAppendedId(TvBrowserContentProvider.CONTENT_URI_DATA_UPDATE,
                                            progID));
                            opBuilder.withValues(values);

                            updateValuesList.add(opBuilder.build());
                        }

                        notification.cancel(notifyID);

                        programs.close();

                        if (!updateValuesList.isEmpty()) {
                            try {
                                getContentResolver().applyBatch(TvBrowserContentProvider.AUTHORITY,
                                        updateValuesList);
                                UiUtils.sendDontWantToSeeChangedBroadcast(getApplicationContext(), true);
                                handler.post(new Runnable() {
                                    @Override
                                    public void run() {
                                        Toast.makeText(getApplicationContext(),
                                                R.string.dont_want_to_see_sync_success, Toast.LENGTH_LONG)
                                                .show();
                                    }
                                });
                            } catch (RemoteException e) {
                                e.printStackTrace();
                            } catch (OperationApplicationException e) {
                                e.printStackTrace();
                            }
                        }

                        updateProgressIcon(false);
                        SettingConstants.UPDATING_FILTER = false;
                    }
                }.start();

                Editor edit = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).edit();
                edit.putStringSet(getString(R.string.I_DONT_WANT_TO_SEE_ENTRIES), newExclusions);
                edit.commit();
            }
        };

        showAlertDialog(getString(R.string.action_dont_want_to_see_edit), null, view, null, positive, null,
                cancel, false, true);
    }
}

From source file:android.app.Activity.java

/**
 * Migrate the application to other device.
 * This method is called by the Android system.
 *
 * @hide/* w  ww.  j  av a 2 s  . c o m*/
 * @param savedInstanceState A state the application needs to restore.
 * @return true if migration successed.
 */
private boolean systemMigrate(Bundle savedInstanceState) {
    boolean result = true;
    String cName;
    String pName;

    if (savedInstanceState == null)
        savedInstanceState = new Bundle();

    /* store Intent object this Activity has and requestCode for next Activity */
    savedInstanceState.putParcelable("MIGRATED_INTENT", getIntent());
    savedInstanceState.putInt("MIGRATED REQUEST CODE", currentCode);
    savedInstanceState.putBundle("MIGRATED REQUEST OPTIONS", currentOption);
    currentCode = -1;
    currentOption = null;

    if (mMigrator == null) {
        mMigrator = IMigratorService.Stub.asInterface(ServiceManager.getService("Migrator"));
    }

    pName = getPackageName();
    cName = mComponent.getClassName();

    try {
        /* mStartedActivity is true if this Activity calls startActivityForResult().
         * This means the next Activity exists. */
        result = mMigrator.migrate(savedInstanceState, pName, cName, mStartedActivity);
        mStartedActivity = false;
    } catch (RemoteException e) {
        Log.w("MIGRATOR", "Migrate failed");
        result = false;
        e.printStackTrace();
    }

    return result;
}

From source file:com.piusvelte.taplock.client.core.TapLockService.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    if (intent != null) {
        String action = intent.getAction();
        if (BluetoothAdapter.ACTION_STATE_CHANGED.equals(action)) {
            int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.STATE_OFF);
            if (state == BluetoothAdapter.STATE_ON) {
                if (mStartedBT) {
                    if (mUIInterface != null) {
                        try {
                            mUIInterface.setMessage("Bluetooth enabled");
                        } catch (RemoteException e) {
                            Log.e(TAG, e.getMessage());
                        }/* w w w. j av a  2  s  .com*/
                    }
                    if ((mQueueAddress != null) && (mQueueState != null))
                        requestWrite(mQueueAddress, mQueueState, mQueuePassphrase);
                    else if (mRequestDiscovery && !mBtAdapter.isDiscovering())
                        mBtAdapter.startDiscovery();
                    else if (mUIInterface != null) {
                        try {
                            mUIInterface.setBluetoothEnabled();
                        } catch (RemoteException e) {
                            Log.e(TAG, e.getMessage());
                        }
                    }
                }
            } else if (state == BluetoothAdapter.STATE_TURNING_OFF) {
                if (mUIInterface != null) {
                    try {
                        mUIInterface.setMessage("Bluetooth disabled");
                    } catch (RemoteException e) {
                        Log.e(TAG, e.getMessage());
                    }
                }
                stopThreads();
            }
        } else if (BluetoothDevice.ACTION_FOUND.equals(action)) {
            // Get the BluetoothDevice object from the Intent
            BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
            if (device.getBondState() == BluetoothDevice.BOND_BONDED) {
                // connect if configured
                String address = device.getAddress();
                for (JSONObject deviceJObj : mDevices) {
                    try {
                        if (deviceJObj.getString(KEY_ADDRESS).equals(address)) {
                            // if queued
                            mDeviceFound = (mQueueAddress != null) && mQueueAddress.equals(address)
                                    && (mQueueState != null);
                            break;
                        }
                    } catch (JSONException e) {
                        Log.e(TAG, e.getMessage());
                    }
                }
            } else if (mRequestDiscovery && (mUIInterface != null)) {
                String unpairedDevice = TapLock
                        .createDevice(device.getName(), device.getAddress(), DEFAULT_PASSPHRASE).toString();
                try {
                    mUIInterface.setUnpairedDevice(unpairedDevice);
                } catch (RemoteException e) {
                    Log.e(TAG, e.getMessage());
                }
            }
        } else if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action)) {
            if (mDeviceFound) {
                requestWrite(mQueueAddress, mQueueState, mQueuePassphrase);
                mDeviceFound = false;
            } else if (mRequestDiscovery) {
                mRequestDiscovery = false;
                if (mUIInterface != null) {
                    try {
                        mUIInterface.setDiscoveryFinished();
                    } catch (RemoteException e) {
                        Log.e(TAG, e.toString());
                    }
                }
            }
        } else if (ACTION_TOGGLE.equals(action) && intent.hasExtra(EXTRA_DEVICE_ADDRESS)) {
            String address = intent.getStringExtra(EXTRA_DEVICE_ADDRESS);
            requestWrite(address, ACTION_TOGGLE, null);
        } else if (AppWidgetManager.ACTION_APPWIDGET_UPDATE.equals(action)) {
            // create widget
            if (intent.hasExtra(AppWidgetManager.EXTRA_APPWIDGET_ID)) {
                int appWidgetId = intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID,
                        AppWidgetManager.INVALID_APPWIDGET_ID);
                if (intent.hasExtra(EXTRA_DEVICE_NAME)) {
                    // add a widget
                    String deviceName = intent.getStringExtra(EXTRA_DEVICE_NAME);
                    for (int i = 0, l = mDevices.size(); i < l; i++) {
                        String name = null;
                        try {
                            name = mDevices.get(i).getString(KEY_NAME);
                        } catch (JSONException e1) {
                            e1.printStackTrace();
                        }
                        if ((name != null) && name.equals(deviceName)) {
                            JSONObject deviceJObj = mDevices.remove(i);
                            JSONArray widgetsJArr;
                            if (deviceJObj.has(KEY_WIDGETS)) {
                                try {
                                    widgetsJArr = deviceJObj.getJSONArray(KEY_WIDGETS);
                                } catch (JSONException e) {
                                    widgetsJArr = new JSONArray();
                                }
                            } else
                                widgetsJArr = new JSONArray();
                            widgetsJArr.put(appWidgetId);
                            try {
                                deviceJObj.put(KEY_WIDGETS, widgetsJArr);
                            } catch (JSONException e) {
                                e.printStackTrace();
                            }
                            mDevices.add(i, deviceJObj);
                            TapLock.storeDevices(this, getSharedPreferences(KEY_PREFS, MODE_PRIVATE), mDevices);
                            break;
                        }
                    }
                }
                buildWidget(appWidgetId);
            } else if (intent.hasExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS)) {
                int[] appWidgetIds = intent.getIntArrayExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS);
                if (appWidgetIds != null) {
                    for (int appWidgetId : appWidgetIds)
                        buildWidget(appWidgetId);
                }
            }
        } else if (AppWidgetManager.ACTION_APPWIDGET_DELETED.equals(action)) {
            int appWidgetId = intent.getExtras().getInt(AppWidgetManager.EXTRA_APPWIDGET_ID,
                    AppWidgetManager.INVALID_APPWIDGET_ID);
            Log.d(TAG, "delete appWidgetId: " + appWidgetId);
            for (int i = 0, l = mDevices.size(); i < l; i++) {
                JSONObject deviceJObj = mDevices.get(i);
                if (deviceJObj.has(KEY_WIDGETS)) {
                    JSONArray widgetsJArr = null;
                    try {
                        widgetsJArr = deviceJObj.getJSONArray(KEY_WIDGETS);
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                    if (widgetsJArr != null) {
                        boolean wasUpdated = false;
                        JSONArray newWidgetsJArr = new JSONArray();
                        for (int widgetIdx = 0, wdigetsLen = widgetsJArr
                                .length(); widgetIdx < wdigetsLen; widgetIdx++) {
                            int widgetId;
                            try {
                                widgetId = widgetsJArr.getInt(widgetIdx);
                            } catch (JSONException e) {
                                widgetId = AppWidgetManager.INVALID_APPWIDGET_ID;
                                e.printStackTrace();
                            }
                            Log.d(TAG, "eval widgetId: " + widgetId);
                            if ((widgetId != AppWidgetManager.INVALID_APPWIDGET_ID)
                                    && (widgetId == appWidgetId)) {
                                Log.d(TAG, "skip: " + widgetId);
                                wasUpdated = true;
                            } else {
                                Log.d(TAG, "include: " + widgetId);
                                newWidgetsJArr.put(widgetId);
                            }
                        }
                        if (wasUpdated) {
                            try {
                                deviceJObj.put(KEY_WIDGETS, newWidgetsJArr);
                                mDevices.remove(i);
                                mDevices.add(i, deviceJObj);
                                TapLock.storeDevices(this, getSharedPreferences(KEY_PREFS, MODE_PRIVATE),
                                        mDevices);
                                Log.d(TAG, "stored: " + deviceJObj.toString());
                            } catch (JSONException e) {
                                e.printStackTrace();
                            }
                        }
                    }
                } else {
                    JSONArray widgetsJArr = new JSONArray();
                    try {
                        deviceJObj.put(KEY_WIDGETS, widgetsJArr);
                        mDevices.remove(i);
                        mDevices.add(i, deviceJObj);
                        TapLock.storeDevices(this, getSharedPreferences(KEY_PREFS, MODE_PRIVATE), mDevices);
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    }
    return START_STICKY;
}