use of wseemann.media.romote.adapter.DeviceAdapter in project RoMote by wseemann.
the class MainFragment method onActivityCreated.
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
mList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Device device = (Device) parent.getItemAtPosition(position);
DBUtils.insertDevice(getActivity(), device);
PreferenceUtils.setConnectedDevice(getActivity(), device.getSerialNumber());
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
SharedPreferences.Editor editor = prefs.edit();
editor.putBoolean("first_use", false);
editor.commit();
Toast.makeText(getActivity(), "Device " + device.getSerialNumber() + " " + getString(R.string.connected), Toast.LENGTH_SHORT).show();
MainFragment.this.getActivity().sendBroadcast(new Intent(Constants.UPDATE_DEVICE_BROADCAST));
AppWidgetManager widgetManager = AppWidgetManager.getInstance(getActivity());
ComponentName widgetComponent = new ComponentName(getActivity(), RokuAppWidgetProvider.class);
int[] widgetIds = widgetManager.getAppWidgetIds(widgetComponent);
Intent update = new Intent();
update.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, widgetIds);
update.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
getActivity().sendBroadcast(update);
if (mListener != null) {
mListener.onDeviceSelected();
}
mAvailableDeviceAdapter.clear();
mAdapter.notifyDataSetChanged();
getLoaderManager().restartLoader(1, new Bundle(), mPairedDevicesLoader);
}
});
mFab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// ManualConnectionDialog fragment = ManualConnectionDialog.getInstance(getActivity());
// fragment.show(MainFragment.this.getFragmentManager(), ManualConnectionDialog.class.getName());
Intent intent = new Intent(MainFragment.this.getActivity(), ManualConnectionActivity.class);
startActivityForResult(intent, 0);
}
});
mAdapter = new SeparatedListAdapter(getActivity());
mPairedDeviceAdapter = new DeviceAdapter(getActivity(), new ArrayList<Device>(), mHandler);
mAvailableDeviceAdapter = new DeviceAdapter(getActivity(), new ArrayList<Device>(), mHandler);
mAdapter.addSection("Paired devices", mPairedDeviceAdapter);
mAdapter.addSection("Available devices", mAvailableDeviceAdapter);
setListAdapter(mAdapter);
refreshList(false);
}
use of wseemann.media.romote.adapter.DeviceAdapter in project RoMote by wseemann.
the class AltMainActivity method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// ManualConnectionDialog fragment = ManualConnectionDialog.getInstance(this);
// fragment.show(MainFragment.this.getFragmentManager(), ManualConnectionDialog.class.getName());
Intent intent = new Intent(AltMainActivity.this, ManualConnectionActivity.class);
startActivityForResult(intent, 0);
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
if (drawer.isDrawerOpen(GravityCompat.START)) {
drawer.closeDrawer(GravityCompat.START);
}
}
});
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
if (prefs.getBoolean("first_use", true)) {
startActivity(new Intent(this, ConfigureDeviceActivity.class));
finish();
}
Intent intent = getIntent();
if (intent != null && intent.getData() != null) {
String channelCode = intent.getData().getPath().replace("/install/", "");
InstallChannelDialog fragment = InstallChannelDialog.getInstance(this, channelCode);
fragment.show(getFragmentManager(), InstallChannelDialog.class.getName());
}
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.addDrawerListener(toggle);
toggle.syncState();
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
// Create the adapter that will return a fragment for each of the three
// primary sections of the activity.
mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
// Set up the ViewPager with the sections adapter.
mViewPager = (ViewPager) findViewById(R.id.container);
mViewPager.setAdapter(mSectionsPagerAdapter);
mViewPager.setOffscreenPageLimit(3);
TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
tabLayout.setupWithViewPager(mViewPager);
// Bind to NotificationService
Intent intent1 = new Intent(this, NotificationService.class);
bindService(intent1, mConnection, Context.BIND_AUTO_CREATE);
mSelectDeviceText = (TextView) findViewById(R.id.select_device_text);
mProgressLayout = (RelativeLayout) findViewById(R.id.progress_layout);
mList = (ListView) findViewById(android.R.id.list);
View emptyView = findViewById(android.R.id.empty);
mList.setEmptyView(emptyView);
mSwiperefresh = (SwipeRefreshLayout) findViewById(R.id.swiperefresh);
/*mSwiperefresh.setOnRefreshListener(
new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
// This method performs the actual data-refresh operation.
// The method calls setRefreshing(false) when it's finished.
setLoadingText(true);
getLoaderManager().restartLoader(0, new Bundle(), mAvailableDevicesLoader);
}
}
);*/
mList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Device device = (Device) parent.getItemAtPosition(position);
DBUtils.insertDevice(AltMainActivity.this, device);
PreferenceUtils.setConnectedDevice(AltMainActivity.this, device.getSerialNumber());
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(AltMainActivity.this);
SharedPreferences.Editor editor = prefs.edit();
editor.putBoolean("first_use", false);
editor.commit();
Toast.makeText(AltMainActivity.this, "Device " + device.getSerialNumber() + " " + getString(R.string.connected), Toast.LENGTH_SHORT).show();
sendBroadcast(new Intent(Constants.UPDATE_DEVICE_BROADCAST));
AppWidgetManager widgetManager = AppWidgetManager.getInstance(AltMainActivity.this);
ComponentName widgetComponent = new ComponentName(AltMainActivity.this, RokuAppWidgetProvider.class);
int[] widgetIds = widgetManager.getAppWidgetIds(widgetComponent);
Intent update = new Intent();
update.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, widgetIds);
update.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
sendBroadcast(update);
if (mListener != null) {
mListener.onDeviceSelected();
}
mAvailableDeviceAdapter.clear();
mAdapter.notifyDataSetChanged();
getLoaderManager().restartLoader(1, new Bundle(), mPairedDevicesLoader);
}
});
mAdapter = new SeparatedListAdapter(this);
mPairedDeviceAdapter = new DeviceAdapter(this, new ArrayList<Device>(), mHandler);
mAvailableDeviceAdapter = new DeviceAdapter(this, new ArrayList<Device>(), mHandler);
mAdapter.addSection("Paired devices", mPairedDeviceAdapter);
mAdapter.addSection("Available devices", mAvailableDeviceAdapter);
mList.setAdapter(mAdapter);
refreshList(false);
ImageButton refreshButton = (ImageButton) findViewById(R.id.refresh_button);
refreshButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
getLoaderManager().restartLoader(0, new Bundle(), mAvailableDevicesLoader);
}
});
}
Aggregations