Search in sources :

Example 1 with DeviceAdapter

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);
}
Also used : SharedPreferences(android.content.SharedPreferences) Device(com.jaku.model.Device) Bundle(android.os.Bundle) AppWidgetManager(android.appwidget.AppWidgetManager) ArrayList(java.util.ArrayList) Intent(android.content.Intent) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) SuppressLint(android.annotation.SuppressLint) ManualConnectionActivity(wseemann.media.romote.activity.ManualConnectionActivity) SeparatedListAdapter(wseemann.media.romote.adapter.SeparatedListAdapter) RokuAppWidgetProvider(wseemann.media.romote.widget.RokuAppWidgetProvider) DeviceAdapter(wseemann.media.romote.adapter.DeviceAdapter) AdapterView(android.widget.AdapterView) ComponentName(android.content.ComponentName)

Example 2 with DeviceAdapter

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);
        }
    });
}
Also used : NavigationView(android.support.design.widget.NavigationView) ActionBarDrawerToggle(android.support.v7.app.ActionBarDrawerToggle) ArrayList(java.util.ArrayList) ImageButton(android.widget.ImageButton) TabLayout(android.support.design.widget.TabLayout) FloatingActionButton(android.support.design.widget.FloatingActionButton) DeviceAdapter(wseemann.media.romote.adapter.DeviceAdapter) ComponentName(android.content.ComponentName) DrawerLayout(android.support.v4.widget.DrawerLayout) Toolbar(android.support.v7.widget.Toolbar) SharedPreferences(android.content.SharedPreferences) Device(com.jaku.model.Device) Bundle(android.os.Bundle) AppWidgetManager(android.appwidget.AppWidgetManager) Intent(android.content.Intent) NavigationView(android.support.design.widget.NavigationView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) SuppressLint(android.annotation.SuppressLint) SeparatedListAdapter(wseemann.media.romote.adapter.SeparatedListAdapter) RokuAppWidgetProvider(wseemann.media.romote.widget.RokuAppWidgetProvider) AdapterView(android.widget.AdapterView) InstallChannelDialog(wseemann.media.romote.fragment.InstallChannelDialog)

Aggregations

SuppressLint (android.annotation.SuppressLint)2 AppWidgetManager (android.appwidget.AppWidgetManager)2 ComponentName (android.content.ComponentName)2 Intent (android.content.Intent)2 SharedPreferences (android.content.SharedPreferences)2 Bundle (android.os.Bundle)2 View (android.view.View)2 AdapterView (android.widget.AdapterView)2 ListView (android.widget.ListView)2 TextView (android.widget.TextView)2 Device (com.jaku.model.Device)2 ArrayList (java.util.ArrayList)2 DeviceAdapter (wseemann.media.romote.adapter.DeviceAdapter)2 SeparatedListAdapter (wseemann.media.romote.adapter.SeparatedListAdapter)2 RokuAppWidgetProvider (wseemann.media.romote.widget.RokuAppWidgetProvider)2 FloatingActionButton (android.support.design.widget.FloatingActionButton)1 NavigationView (android.support.design.widget.NavigationView)1 TabLayout (android.support.design.widget.TabLayout)1 DrawerLayout (android.support.v4.widget.DrawerLayout)1 ActionBarDrawerToggle (android.support.v7.app.ActionBarDrawerToggle)1