コード例 #1
0
    @Override
    public void run() {
      String TAG = StaticBlob.TAG();
      // Set the effects for if the episode has been downloaded or is in queue, etc
      boolean inDLQueue = StaticBlob.databaseConnector.isInActiveDownloadQueueAtAll(id);

      boolean mp3exists = (music_file_location != null && music_file_location.exists());
      boolean mp3complete = mp3exists && music_file_location.length() == mp3size;
      boolean videxists = (video_file_location != null && video_file_location.exists());
      boolean vidcomplete = videxists && video_file_location.length() == vidsize;

      if (inDLQueue || mp3exists || videxists) {
        if (mp3complete || vidcomplete) {
          ((TextView) v.findViewById(R.id.rowTextView)).setTypeface(null, Typeface.BOLD);
          ((TextView) v.findViewById(R.id.rowSubTextView)).setTypeface(null, Typeface.BOLD);
        } else {
          ((TextView) v.findViewById(R.id.rowTextView)).setTypeface(null, Typeface.ITALIC);
          ((TextView) v.findViewById(R.id.rowSubTextView)).setTypeface(null, Typeface.ITALIC);
        }
      } else // No typeface
      {
        ((TextView) v.findViewById(R.id.rowTextView)).setTypeface(null, 0);
        ((TextView) v.findViewById(R.id.rowSubTextView)).setTypeface(null, 0);
      }
    }
コード例 #2
0
 @Override
 public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
   String TAG = StaticBlob.TAG();
   current_episode = view;
   Intent viewEpisode = new Intent(ShowList.this, EpisodeDesc.class);
   long clickedID =
       Long.parseLong((String) ((TextView) view.findViewById(R.id.hiddenId)).getText());
   viewEpisode.putExtra("id", clickedID);
   Log.v(TAG, "Selected ID: " + clickedID);
   setProgressBarIndeterminateVisibility(true);
   startActivity(viewEpisode);
 }
コード例 #3
0
 @Override
 public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
   String TAG = StaticBlob.TAG();
   Long id =
       Long.parseLong(
           (String)
               ((TextView) ((View) buttonView.getParent()).findViewById(R.id.hiddenId))
                   .getText());
   StaticBlob.databaseConnector.markNew(id, isChecked);
   Log.v(TAG, "Toggling new for:" + id + " is " + isChecked);
   Cursor c = StaticBlob.databaseConnector.getOneEpisode(id);
   c.moveToFirst();
 }
コード例 #4
0
 @Override
 public void handleMessage(Message msg) {
   String TAG = StaticBlob.TAG();
   if (msg.arg1 != 0) {
     Cursor r = StaticBlob.databaseConnector.getShow(currentShow, filter);
     ShowList.this.showAdapter.changeCursor(r);
     ShowList.this.showAdapter.notifyDataSetChanged();
     Log.i(TAG, "Changing cursor");
   } else {
     Log.i(TAG, "Not Changing cursor");
     loading.setText(ShowList.this.getResources().getString(R.string.list_empty));
   }
 }
コード例 #5
0
 @Override
 protected void onPostExecute(Message result) {
   String TAG = StaticBlob.TAG();
   TextView loading = (TextView) ShowList.this.findViewById(android.R.id.empty);
   loading.setText(ShowList.this.getResources().getString(R.string.list_empty));
   if (result.arg1 == -1) {
     Log.w(TAG, "An error occurred while updating the show " + currentShow);
     Toast.makeText(
             ShowList.this,
             getResources().getString(R.string.show_update_error)
                 + ":\n\n"
                 + result.getData().getString("ERROR"),
             Toast.LENGTH_LONG)
         .show();
   } else if (mainListView != null) ShowList.this.updateHandler.sendMessage((Message) result);
   setProgressBarIndeterminateVisibility(false);
 }
コード例 #6
0
  /**
   * Called when the activity is first created. Sets up the view.
   *
   * @param savedInstanceState Um I don't even know. Read the Android documentation.
   */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    String TAG = StaticBlob.TAG();
    if (android.os.Build.VERSION.SDK_INT >= 11) setTheme(R.style.Default_New);
    // General create stuff
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    Log.v(TAG, "Launching Activity");
    mainListView = new ListView(this);
    Callisto.build_layout(this, mainListView);

    // Get the settings for this show
    currentShow = getIntent().getExtras().getString("current_show");
    currentShowAudio = getIntent().getExtras().getString("current_show_audio");
    currentShowVideo = getIntent().getExtras().getString("current_show_video");
    showSettings = getSharedPreferences(currentShow, 0);
    filter = showSettings.getBoolean("filter", false);
    loading = (TextView) findViewById(android.R.id.empty);
    // If it has been checked before but there are no episodes, show that it is empty, not just
    // loading.
    if (StaticBlob.databaseConnector.getShow(currentShow, filter).getCount() == 0)
      loading.setText(this.getResources().getString(R.string.list_empty));
    else loading.setText(this.getResources().getString(R.string.loading));
    loading.setGravity(Gravity.CENTER_HORIZONTAL);
    // If it has never been checked before add a refresh button
    if (showSettings.getString("last_checked", null) == null) {
      refresh = new Button(this);
      refresh.setText(this.getResources().getString(R.string.refresh));
      refresh.setTextColor(this.getResources().getColor(R.color.txtClr));
      LinearLayout.LayoutParams p =
          new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
      p.setMargins(20, 10, 20, 10);
      refresh.setLayoutParams(p);
      ((LinearLayout) loading.getParent()).setGravity(Gravity.CENTER_HORIZONTAL);
      refresh.setPadding(100, 10, 100, 10);
      refresh.setOnClickListener(
          new OnClickListener() {
            @Override
            public void onClick(View v) {
              reload();
            }
          });
      ((LinearLayout) mainListView.getParent()).addView(refresh, 1);
      ((LinearLayout) mainListView.getParent())
          .setBackgroundColor(this.getResources().getColor(R.color.backClr));
      mainListView.setEmptyView(refresh);
      loading.setVisibility(View.INVISIBLE);
    } else {
      mainListView.setEmptyView(loading);
    }
    // Finish setting up the listview
    mainListView.setOnItemClickListener(selectEpisode);
    mainListView.setBackgroundColor(getResources().getColor(R.color.backClr));
    mainListView.setCacheColorHint(getResources().getColor(R.color.backClr));
    setTitle(currentShow);
    // Get the shows from the SQL; make it async because of reasons
    new GetShowTask().execute((Object[]) null);
    Cursor r = StaticBlob.databaseConnector.getShow(currentShow, filter);
    showAdapter = new ShowListCursorAdapter(ShowList.this, R.layout.row, r);
    mainListView.setAdapter(showAdapter);
    return;
  }
コード例 #7
0
    public View getView(int pos, View inView, ViewGroup parent) {
      String TAG = StaticBlob.TAG();
      View v = inView;
      if (v == null) {
        LayoutInflater inflater =
            (LayoutInflater) this.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        v = inflater.inflate(R.layout.row, null);
      }
      this.c = getCursor();
      this.c.moveToPosition(pos);

      Date tempDate =
          new Date(); // We use this variable to get thisYear as well as parsing the actual date
      // later
      int thisYear =
          tempDate.getYear(); // If the date for the show is this year, no need to show the year
      // Set the data From->To

      // Get info for selected episode
      long id = this.c.getLong(this.c.getColumnIndex("_id"));
      this.c = StaticBlob.databaseConnector.getOneEpisode(id);
      this.c.moveToFirst();
      String date = this.c.getString(this.c.getColumnIndex("date"));
      String title = this.c.getString(this.c.getColumnIndex("title"));
      String mp3_link = this.c.getString(this.c.getColumnIndex("mp3link"));
      String vid_link = this.c.getString(this.c.getColumnIndex("vidlink"));

      // _id
      ((TextView) v.findViewById(R.id.hiddenId)).setText(Long.toString(id));
      // title
      ((TextView) v.findViewById(R.id.rowTextView)).setText(title);
      LinearLayout.LayoutParams lp =
          (LinearLayout.LayoutParams) v.findViewById(R.id.rowTextView).getLayoutParams();
      lp.setMargins((int) (10 * StaticBlob.DP), lp.topMargin, lp.rightMargin, lp.bottomMargin);
      ;
      // date
      String d = date;
      try {
        tempDate = StaticBlob.sdfRaw.parse(d);
        if (tempDate.getYear() == thisYear) d = StaticBlob.sdfHuman.format(tempDate);
        else d = StaticBlob.sdfHumanLong.format(tempDate);
        // d = Callisto.sdfDestination.format();
      } catch (ParseException e) {
        Log.e(TAG + ":ParseException", "Error parsing a date from the SQLite db: ");
        Log.e(TAG + ":ParseException", d);
        Log.e(TAG + ":ParseException", "(This should never happen).");
        e.printStackTrace();
      }
      ((TextView) v.findViewById(R.id.rowSubTextView)).setText(d);

      File music_file_location = null, video_file_location = null;
      try {
        music_file_location = new File(StaticBlob.storage_path + File.separator + currentShow);
        music_file_location =
            new File(
                music_file_location,
                StaticBlob.sdfFile.format(tempDate)
                    + "__"
                    + StaticBlob.makeFileFriendly(title)
                    + EpisodeDesc.getExtension(mp3_link));
      } catch (NullPointerException npe) {
        Log.e(TAG, "Null pointer when determining file status: Audio");
      }
      try {
        video_file_location = new File(StaticBlob.storage_path + File.separator + currentShow);
        video_file_location =
            new File(
                video_file_location,
                StaticBlob.sdfFile.format(tempDate)
                    + "__"
                    + StaticBlob.makeFileFriendly(title)
                    + EpisodeDesc.getExtension(vid_link));
      } catch (NullPointerException npe) {
        Log.e(TAG, "Null pointer when determining file status: Video");
      }

      runOnUiThread(
          new updateBoldOrItalic(
              id,
              v,
              music_file_location,
              video_file_location,
              this.c.getLong(this.c.getColumnIndex("mp3size")),
              this.c.getLong(this.c.getColumnIndex("vidsize"))));

      // Mark current queue item
      Cursor c = StaticBlob.databaseConnector.currentQueueItem();
      if (currentQueueItem == null || currentQueueItem == v) {
        if (c.getCount() > 0) {
          c.moveToFirst();
          if (c.getLong(c.getColumnIndex("identity")) == id) currentQueueItem = v;
          else currentQueueItem = null;
        } else currentQueueItem = null;
      }
      // Mark current download item
      c = StaticBlob.databaseConnector.getActiveDownloads();
      if (currentDownloadItem == null || currentDownloadItem == v) {
        if (c.getCount() > 0) {
          c.moveToFirst();
          Log.i(
              TAG,
              "  currentDownloadItem =? "
                  + currentDownloadItem
                  + "   "
                  + c.getLong(c.getColumnIndex("identity"))
                  + " == "
                  + id);
          if (c.getLong(c.getColumnIndex("identity")) == id) currentDownloadItem = v;
          else currentDownloadItem = null;
        } else currentDownloadItem = null;
      }
      Log.i(TAG, "currentDownloadItem == " + currentDownloadItem);

      // Hide the specific views
      int[] hide = new int[] {R.id.remove, R.id.progress, R.id.grabber, R.id.rightTextView};
      for (int i = 0; i < hide.length; i++) v.findViewById(hide[i]).setVisibility(View.GONE);

      // Check the Jupiter icon if it is new
      boolean is_new = this.c.getInt(this.c.getColumnIndex("new")) > 0;
      CheckBox rb = ((CheckBox) v.findViewById(R.id.img));
      rb.setChecked(is_new);
      rb.setOnCheckedChangeListener(toggleNew);

      return (v);
    }
コード例 #8
0
 /**
  * Called when an item in the menu is pressed.
  *
  * @param item The menu item ID that was pressed
  */
 @Override
 public boolean onOptionsItemSelected(MenuItem item) {
   AlertDialog d;
   switch (item.getItemId()) {
     case STOP_ID: // Stop playing
       PlayerControls.stop(this);
       return true;
     case RELOAD_ID: // Check for new episodes
       reload();
       return true;
     case CLEAR_ID: // Show a dialog to clear all items of this show from the SQL database
       d =
           new AlertDialog.Builder(this)
               .setTitle(this.getResources().getString(R.string.confirm))
               .setMessage(this.getResources().getString(R.string.confirm_clear))
               .setIcon(android.R.drawable.ic_dialog_alert)
               .setPositiveButton(
                   android.R.string.yes,
                   new DialogInterface.OnClickListener() {
                     public void onClick(DialogInterface dialog, int whichButton) {
                       loading.setText(
                           ShowList.this.getResources().getString(R.string.list_empty));
                       StaticBlob.databaseConnector.clearShow(ShowList.this, currentShow);
                       Cursor r = StaticBlob.databaseConnector.getShow(currentShow, filter);
                       ShowList.this.showAdapter.changeCursor(r);
                       ShowList.this.showAdapter.notifyDataSetChanged();
                       SharedPreferences.Editor editor = showSettings.edit();
                       editor.putString("last_checked", null);
                       editor.commit();
                     }
                   })
               .setNegativeButton(android.R.string.no, null)
               .show();
       StaticBlob.formatAlertDialogButtons(d);
       return true;
     case FILTER_ID: // Filter or unfilter the results showing only new or all
       filter = !filter;
       if (filter) item.setTitle(this.getResources().getString(R.string.unfilter));
       else item.setTitle(this.getResources().getString(R.string.filter));
       Cursor r = StaticBlob.databaseConnector.getShow(currentShow, filter);
       ShowList.this.showAdapter.changeCursor(r);
       ShowList.this.showAdapter.notifyDataSetChanged();
       SharedPreferences.Editor editor = showSettings.edit();
       editor.putBoolean("filter", filter);
       editor.commit();
       return true;
     case MARK_ID: // Mark all in the show as new or old
       d =
           new AlertDialog.Builder(this)
               .setTitle(this.getResources().getString(R.string.mark_all))
               .setPositiveButton(
                   this.getResources().getString(R.string.new_),
                   new DialogInterface.OnClickListener() {
                     public void onClick(DialogInterface dialog, int whichButton) {
                       StaticBlob.databaseConnector.markAllNew(currentShow, true);
                       Cursor r = StaticBlob.databaseConnector.getShow(currentShow, filter);
                       ShowList.this.showAdapter.changeCursor(r);
                       ShowList.this.showAdapter.notifyDataSetChanged();
                     }
                   })
               .setNegativeButton(
                   this.getResources().getString(R.string.old),
                   new DialogInterface.OnClickListener() {
                     public void onClick(DialogInterface dialog, int whichButton) {
                       StaticBlob.databaseConnector.markAllNew(currentShow, false);
                       Cursor r = StaticBlob.databaseConnector.getShow(currentShow, filter);
                       ShowList.this.showAdapter.changeCursor(r);
                       ShowList.this.showAdapter.notifyDataSetChanged();
                     }
                   })
               .show();
       d.getButton(Dialog.BUTTON_POSITIVE).setBackgroundResource(R.drawable.blue_button);
       d.getButton(Dialog.BUTTON_POSITIVE)
           .setPadding(
               (int) (15 * StaticBlob.DP),
               (int) (15 * StaticBlob.DP),
               (int) (15 * StaticBlob.DP),
               (int) (15 * StaticBlob.DP));
       d.getButton(Dialog.BUTTON_NEGATIVE).setBackgroundResource(R.drawable.blue_button);
       d.getButton(Dialog.BUTTON_NEGATIVE)
           .setPadding(
               (int) (15 * StaticBlob.DP),
               (int) (15 * StaticBlob.DP),
               (int) (15 * StaticBlob.DP),
               (int) (15 * StaticBlob.DP));
       ((View) d.getButton(Dialog.BUTTON_POSITIVE).getParent())
           .setBackgroundResource(R.color.backClr);
       return true;
     default:
       return super.onOptionsItemSelected(item);
   }
 }
コード例 #9
0
 /** Called when the activity is going to be destroyed. */
 @Override
 public void onDestroy() {
   String TAG = StaticBlob.TAG();
   super.onDestroy();
   thisInstance = null;
 }
コード例 #10
0
  /**
   * Called when the activity is resumed, like when you return from another activity or also when it
   * is first created.
   */
  @Override
  public void onResume() {
    String TAG = StaticBlob.TAG();
    super.onResume();
    thisInstance = this;
    setProgressBarIndeterminateVisibility(false);
    StaticBlob.playerInfo.update(ShowList.this); // Update player controls
    if (StaticBlob.audioFocus != null) StaticBlob.audioFocus.setContext(this);
    if (CallistoService.audioJackReceiver != null)
      CallistoService.audioJackReceiver.setContext(this);

    if (current_episode == null) // If we aren't returning from an EpisodeDesc, we're done.
    return;

    try {
      long id =
          Long.parseLong(
              (String)
                  ((TextView) current_episode.findViewById(R.id.hiddenId))
                      .getText()); // Get the id of the episode that was visited in an EpisodeDesc
      Cursor c = StaticBlob.databaseConnector.getOneEpisode(id);
      c.moveToFirst();

      // New marker
      boolean is_new = c.getInt(c.getColumnIndex("new")) > 0;
      ((CheckBox) current_episode.findViewById(R.id.img)).setChecked(is_new);

      Date tempDate =
          StaticBlob.sdfRaw.parse(
              c.getString(c.getColumnIndex("date"))); // Need this for file location
      String title = c.getString(c.getColumnIndex("title")),
          mp3_link = c.getString(c.getColumnIndex("mp3link")), // Need this for file extension
          vid_link = c.getString(c.getColumnIndex("vidlink")); // ^
      File music_file_location = new File(StaticBlob.storage_path + File.separator + currentShow);
      music_file_location =
          new File(
              music_file_location,
              StaticBlob.sdfFile.format(tempDate)
                  + "__"
                  + StaticBlob.makeFileFriendly(title)
                  + EpisodeDesc.getExtension(mp3_link));
      File video_file_location = new File(StaticBlob.storage_path + File.separator + currentShow);
      video_file_location =
          new File(
              video_file_location,
              StaticBlob.sdfFile.format(tempDate)
                  + "__"
                  + StaticBlob.makeFileFriendly(title)
                  + EpisodeDesc.getExtension(vid_link));

      runOnUiThread(
          new updateBoldOrItalic(
              id,
              current_episode,
              music_file_location,
              video_file_location,
              c.getLong(c.getColumnIndex("mp3size")),
              c.getLong(c.getColumnIndex("vidsize"))));

      c = StaticBlob.databaseConnector.currentQueueItem();
      if (currentQueueItem == null || currentQueueItem == current_episode) {
        if (c.getCount() > 0) {
          c.moveToFirst();
          if (c.getLong(c.getColumnIndex("identity")) == id) currentQueueItem = current_episode;
          else currentQueueItem = null;
        } else currentQueueItem = null;
      }
      // Mark current download item
      c = StaticBlob.databaseConnector.getActiveDownloads();
      if (currentDownloadItem == null || currentDownloadItem == current_episode) {
        if (c.getCount() > 0) {
          c.moveToFirst();
          Log.i(
              TAG,
              "  currentDownloadItem =? "
                  + currentDownloadItem
                  + "   "
                  + c.getLong(c.getColumnIndex("identity"))
                  + " == "
                  + id);
          if (c.getLong(c.getColumnIndex("identity")) == id) currentDownloadItem = current_episode;
          else currentDownloadItem = null;
        } else currentDownloadItem = null;
      }

    } catch (Exception e) {
      Log.e(
          TAG,
          "Error: " + e.getClass() + " - " + e.getMessage() + "(this should never happen...?)");
    }
    current_episode = null;
  }