@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); final Context context = this; setContentView(R.layout.activity_preferences); Toolbar toolbar = (Toolbar) findViewById(R.id.fragmentToolbar); setSupportActionBar(toolbar); getSupportActionBar().setTitle(getTitle()); getSupportActionBar().setDisplayShowHomeEnabled(true); Drawer.OnDrawerItemClickListener drawerListener = new Drawer.OnDrawerItemClickListener() { @Override public boolean onItemClick( AdapterView<?> parent, View view, int position, long id, IDrawerItem drawerItem) { switch (drawerItem.getIdentifier()) { case R.string.idLocations: goToRoot(); return true; case R.string.idPager: Intent intent1 = new Intent(context, ActivityMessages.class); startActivity(intent1); return true; case R.string.idWaypoints: Intent intent = new Intent(context, ActivityWaypoints.class); startActivity(intent); return true; case R.string.idSettings: return true; case R.string.idStatistics: Intent intent2 = new Intent(context, ActivityStatistics.class); startActivity(intent2); return true; } return false; } }; DrawerFactory.buildDrawer(this, toolbar, drawerListener, 2); getFragmentManager() .beginTransaction() .replace(R.id.content_frame, new FragmentPreferences(), "preferences") .commit(); }
protected void onCreate(Bundle savedInstanceState) { startService(new Intent(this, ServiceProxy.class)); ServiceProxy.runOrBind( this, new Runnable() { @Override public void run() { Log.v("ActivityMain", "ServiceProxy bound"); } }); super.onCreate(savedInstanceState); setContentView(R.layout.activity_messages); toolbar = (Toolbar) findViewById(R.id.fragmentToolbar); setSupportActionBar(toolbar); toolbar.setTitle(getTitle()); final Context context = this; Drawer.OnDrawerItemClickListener drawerListener = new Drawer.OnDrawerItemClickListener() { @Override public boolean onItemClick( AdapterView<?> parent, View view, int position, long id, IDrawerItem drawerItem) { if (drawerItem == null) return false; switch (drawerItem.getIdentifier()) { case R.string.idLocations: goToRoot(); return true; case R.string.idPager: return true; case R.string.idWaypoints: Intent intent2 = new Intent(context, ActivityWaypoints.class); startActivity(intent2); return true; case R.string.idSettings: Intent intent = new Intent(context, ActivityPreferences.class); startActivity(intent); return true; case R.string.idStatistics: Intent intent3 = new Intent(context, ActivityStatistics.class); startActivity(intent3); return true; } return false; } }; DrawerFactory.buildDrawer(this, toolbar, drawerListener, 1); LinearLayoutManager layoutManager = new LinearLayoutManager(this); layoutManager.setOrientation(LinearLayoutManager.VERTICAL); layoutManager.scrollToPosition(0); listAdapter = new MessageAdapter(this); listView = (org.owntracks.android.support.RecyclerView) findViewById(R.id.listView); listView.setLayoutManager(layoutManager); listView.setAdapter(listAdapter); listView.addItemDecoration( new DividerItemDecoration(this, DividerItemDecoration.VERTICAL_LIST)); listView.setItemAnimator(new DefaultItemAnimator()); listView.setEmptyView(findViewById(R.id.messageListPlaceholder)); listAdapter.setOnViewHolderClickListener(this); getSupportLoaderManager().initLoader(LOADER_ID, null, this); ItemTouchHelper.SimpleCallback simpleItemTouchCallback = new ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.LEFT) { public int getSwipeDirs(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) { if (!(viewHolder instanceof MessageAdapter.ItemViewHolder)) return 0; return super.getSwipeDirs(recyclerView, viewHolder); } @Override public boolean onMove( RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) { return false; } @Override public void onSwiped(RecyclerView.ViewHolder viewHolder, int swipeDir) { Log.v(TAG, "onSwiped: " + viewHolder); if (swipeDir == ItemTouchHelper.LEFT) { Log.v(TAG, "deleting message " + viewHolder.getItemId()); Log.v(TAG, "oldPosition " + viewHolder.getOldPosition()); Log.v(TAG, "layoutPositon " + viewHolder.getLayoutPosition()); Log.v(TAG, "adapterPosition " + viewHolder.getAdapterPosition()); Dao.getMessageDao().deleteByKey(viewHolder.getItemId()); // listAdapter.notifyItemRemoved(viewHolder.getAdapterPosition()); // listAdapter.notifyDataSetChanged(); requery(); } } }; ItemTouchHelper itemTouchHelper = new ItemTouchHelper(simpleItemTouchCallback); itemTouchHelper.attachToRecyclerView(listView); }