Android Open Source - syncarnet Peer List Dialog






From Project

Back to project page syncarnet.

License

The source code is released under:

GNU General Public License

If you think the Android project syncarnet listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*
 * Copyright (C) 2013-14 Nicolas Miller, Florian Paindorge
 */*from  w ww  .  j a v  a 2s  . com*/
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

package fr.syncarnet.sync;

import android.app.Dialog;
import android.app.DialogFragment;
import android.app.AlertDialog;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;

import android.net.wifi.p2p.WifiP2pDevice;
import android.os.Bundle;

import android.content.DialogInterface;

import android.util.Log;

import java.util.List;

import fr.syncarnet.*;
import fr.syncarnet.R;
import fr.syncarnet.sync.*;

public class PeerListDialog extends DialogFragment {
  private List<WifiP2pDevice> peers;
  private OnPeerSelected callback;
  private PeerListAdapter adapter;
  private Intent serviceIntent;
  private ProgressDialog progressDialog; 
  
  public PeerListDialog(List<WifiP2pDevice> peers, OnPeerSelected callback) {
    this.peers = peers;
    this.callback = callback;
  }

  @Override
  public Dialog onCreateDialog(Bundle savedInstanceState) {
    adapter = new PeerListAdapter(getActivity(), peers);
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setTitle(R.string.choosepeer);
    builder.setAdapter(adapter, new DialogInterface.OnClickListener() {
      @Override
      public void onClick(DialogInterface Dialog, int which) {
        PeerListDialog.this.callback.onPeerSelected(
          (WifiP2pDevice)PeerListDialog.this.adapter.getItem(which)
          );
        PeerListDialog.this.dismiss();
      }
    });

    return builder.create();
  }

  public void setPeerList(List<WifiP2pDevice> peers) {
    this.peers = peers;
  }

  public OnPeerSelected getPeerSelection() {
    return this.callback;
  }

  public boolean peerListEmpty() {
    return this.peers.isEmpty();
  }

  public void reconnect(SynCarnet synCarnet) {
    serviceIntent = new Intent(synCarnet, TaskListTransferService.class);
    progressDialog = ProgressDialog.show(synCarnet, synCarnet.getString(R.string.backCancel), synCarnet.getString(R.string.syncing), true,
        true, new DialogInterface.OnCancelListener() {

          @Override
          public void onCancel(DialogInterface dialog) {

          }
        });
    synCarnet.syncService.setProgressDialog(progressDialog);
    synCarnet.startService(serviceIntent);
  }

  public interface OnPeerSelected {
    public void onPeerSelected(WifiP2pDevice device);
    public void setConnected();
  }

}




Java Source Code List

fr.syncarnet.ProjectsAdapter.java
fr.syncarnet.SynCarnet.java
fr.syncarnet.TaskAddFragment.java
fr.syncarnet.TaskEditFragment.java
fr.syncarnet.TaskListAdapter.java
fr.syncarnet.TaskListFragment.java
fr.syncarnet.helpers.PrioritySpinnerHelper.java
fr.syncarnet.sync.DeviceListActivity.java
fr.syncarnet.sync.PeerListAdapter.java
fr.syncarnet.sync.PeerListDialog.java
fr.syncarnet.sync.PeerList.java
fr.syncarnet.sync.PeerSelection.java
fr.syncarnet.sync.SynCarnetBroadcastReceiver.java
fr.syncarnet.sync.SyncBTService.java
fr.syncarnet.sync.SyncService.java
fr.syncarnet.sync.SyncedDevice.java
fr.syncarnet.sync.SyncedDevicesFragment.java
fr.syncarnet.sync.TaskListTransferService.java
fr.syncarnet.tasks.DeletedTasks.java
fr.syncarnet.tasks.Priority.java
fr.syncarnet.tasks.TaskList.java
fr.syncarnet.tasks.Task.java