/**
  * Called when a shared preference is changed, added, or removed. This may be called even if a
  * preference is set to its existing value.
  *
  * <p>
  *
  * <p>This callback will be run on your main thread.
  *
  * @param sharedPreferences The {@link SharedPreferences} that received the change.
  * @param key The key of the preference that was changed, added, or
  */
 @Override
 public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
   if (key.equals("Refresh_Network")) {
     if (MainActivity.getInstance() != null) MainActivity.getInstance().checkNetwork();
   } else if (key.equals("Connection_Host")) {
     m_connectionHost.setText(
         sharedPreferences.getString("Connection_Host", m_connectionHost.getText()));
   } else if (key.equals("Connection_Port")) {
     m_connectionPort.setText(
         sharedPreferences.getString("Connection_Port", m_connectionPort.getText()));
   }
 }
示例#2
0
  public void setupNotification() {
    //  From Google: http://developer.android.com/guide/topics/ui/notifiers/notifications.html
    NotificationCompat.Builder mBuilder =
        new NotificationCompat.Builder(this)
            .setSmallIcon(R.mipmap.earphone)
            .setContentTitle("Cloud Player")
            .setContentText(cds.playlist_selected.get(cds.song_index));
    Intent resultIntent = new Intent(this, MainActivity.class);

    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    stackBuilder.addParentStack(MainActivity.class);
    stackBuilder.addNextIntent(resultIntent);
    PendingIntent resultPendingIntent =
        stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    mBuilder.setContentIntent(resultPendingIntent);
    NotificationManager mNotificationManager =
        (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    myspref = PreferenceManager.getDefaultSharedPreferences(MainActivity.getInstance());
    SharedPreferences.Editor editor = myspref.edit();
    editor.putBoolean("NOTIFICATION", true);
    editor.apply();

    resultIntent.putExtra("fromNotification", true);

    mNotificationManager.notify(NOTIFY_ID, mBuilder.build());
  }
 @Override
 protected void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   setContentView(R.layout.activity_maps);
   SupportMapFragment mapFragment =
       (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
   mapFragment.getMapAsync(this);
   Bundle od = getIntent().getExtras();
   wyd_id = od.getInt("wyd_id");
   wydarzenie = MainActivity.getInstance().dm.getWydarzenie(wyd_id);
 }
示例#4
0
  @Override
  public void onCreate() {
    super.onCreate();

    Log.i("CP:PlayerSrv", "onCreate entered");
    cds = MainActivity.getInstance().ds;
    mp = new MediaPlayer();
    mp.setAudioStreamType(AudioManager.STREAM_MUSIC);

    progressIntent = new Intent(BROADCAST_PROGRESS);
    initMediaPlayer();
  }
  public PlayArrayAdapter(
      Context context, int resource, int textViewResourceId, ArrayList<String> objects) {
    super(context, resource, textViewResourceId, objects);
    inflater = LayoutInflater.from(context);
    this.playlist = objects;
    ctx = context.getApplicationContext();
    cds = MainActivity.getInstance().ds;
    //        Log.i("PlayArrayAdapter", this.playlist.toString());

    for (int i = 0; i < objects.size(); i++) {
      cds.myChecked.put(i, false);
    }
  }
  @Override
  protected void onStop() {
    leftDrawerPlaylist.onStop();
    MainActivity.getInstance()
        .runOnUiThread(
            () -> {
              // SpotifyFragment.getThis.albumAdapter.setDisplayCurrentTrack(true);
              try {
                SpotifyFragment.getInstance().albumAdapter.notifyDataSetChanged();
              } catch (Exception e) {
                Log.v("samba", Log.getStackTraceString(e));
              }
            });

    super.onStop();
  }
示例#7
0
 /** 根据传入的index参数来设置选中的tab页。 */
 @SuppressLint("NewApi")
 public void setTabSelection(int index) {
   // 开启一个Fragment事务
   FragmentTransaction transaction = fragmentManager.beginTransaction();
   // 先隐藏掉所有的Fragment,以防止有多个Fragment显示在界面上的情况
   hideFragments(transaction);
   switch (index) {
     case 0:
       curPage = 0;
       if (mTab01 == null) {
         // 如果MessageFragment为空,则创建一个并添加到界面上
         mTab01 = new FirstPageTab1Fragment();
         transaction.add(R.id.id_content, mTab01);
       } else {
         // 如果MessageFragment不为空,则直接将它显示出来
         transaction.show(mTab01);
       }
       break;
     case 1:
       curPage = 1;
       if (StringUtil.isEmpty(readPreference("tip2"))) {
         writePreference("tip2", "1");
         MainActivity.getInstance().showTip("2");
       }
       if (mTab02 == null) {
         // 如果MessageFragment为空,则创建一个并添加到界面上
         mTab02 = new FirstPageTab2Fragment();
         transaction.add(R.id.id_content, mTab02);
       } else {
         // 如果MessageFragment不为空,则直接将它显示出来
         transaction.show(mTab02);
       }
       break;
   }
   //        transaction.commit();
   transaction
       .commitAllowingStateLoss(); // 为了解决换量页面返回时报的错误,详情见http://blog.csdn.net/ranxiedao/article/details/8214936
 }
示例#8
0
  public void playSong() {
    Log.i("CP:CP:PlayerSrv", "onPlaySong Entered");

    cds = MainActivity.getInstance().ds;
    cds.play_song_selected = cds.playlist_selected.get(cds.song_index);
    String track_id =
        cds.play_song_selected.substring(0, 8) + cds.play_song_selected.substring(10, 12);
    String track_location = cds.track_location.get(track_id);
    cds.play_location = cds.music_url + track_location;
    Log.i("CP:CP:PlayerSrv", cds.play_location);

    mp.reset();
    try {
      mp.setDataSource(cds.play_location);
    } catch (Exception e) {
      Log.e("CP:CP:PlayerSrv", "Error setting data source", e);
    }
    try {
      mp.prepare(); // prepareAsync was skipping songs
    } catch (IOException e) {
      e.printStackTrace();
    }
  }