private void updateMicroThumbBackground(long newId) {
    for (int i = 1; i < mData.size(); i++) {
      StickerMicroThumb stickerMicroThumb = mData.get(i);
      stickerMicroThumb.isSelected = false;

      if (stickerMicroThumb.sticker != null) {
        if (stickerMicroThumb.sticker.setId == newId) {
          stickerMicroThumb.isSelected = true;
          mLinearLayoutManager.scrollToPosition(i);
        }
      }
    }

    if (newId == -1) {
      mData.get(1).isSelected = true;
      mLinearLayoutManager.scrollToPosition(0);
    }
    // без runInUI не работает на версии 4,1
    AndroidUtil.runInUI(
        new Runnable() {
          @Override
          public void run() {
            notifyDataSetChanged();
          }
        },
        1);
  }
  private void updateMicroThumbBackground(long oldId, long newId) {
    int counter = 0;

    if (newId == -1) {
      mData.get(1).isSelected = true;
      mLinearLayoutManager.scrollToPosition(0);
    } else {
      if (oldId == -1) {
        mData.get(1).isSelected = false;
      }
      for (int i = 2; i < mData.size(); i++) {
        StickerMicroThumb stickerMicroThumb = mData.get(i);
        if (stickerMicroThumb.sticker.setId == oldId) {
          stickerMicroThumb.isSelected = false;
          counter++;
        } else {
          stickerMicroThumb.isSelected = false;
        }

        if (stickerMicroThumb.sticker.setId == newId) {
          stickerMicroThumb.isSelected = true;
          if (i == 2) {
            mLinearLayoutManager.scrollToPosition(0);
          } else mLinearLayoutManager.scrollToPosition(i);
          counter++;
        }

        if (counter == 2) {
          break;
        }

        if (oldId == -1 && counter == 1) {
          break;
        }
      }
    }
    // без runInUI не работает на версии 4,1
    AndroidUtil.runInUI(
        new Runnable() {
          @Override
          public void run() {
            notifyDataSetChanged();
          }
        },
        1);
  }
Esempio n. 3
0
  @Override
  public void onEventMainThread(AddNote2Main event) {
    FragMain fragMain = adapter.getItem(mPosition);
    FragMainAdapter fmad = fragMain.getAdapter();
    LinearLayoutManager llmng = fragMain.getLinearLayoutManager();
    if (!event.isEdit()) {

      fmad.insert(event.getNote(), 0);
      llmng.scrollToPosition(0);

    } else {
      int editPosition = fragMain.getEditPosition();
      Note editNote = event.getNote();
      fmad.setItem(editNote, editPosition);
      llmng.scrollToPosition(editPosition);
    }
  }
 private void setMood(int position) {
   AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context);
   alertDialogBuilder.setTitle("Choose mood");
   View view = ((Activity) context).getLayoutInflater().inflate(R.layout.dialog_listview, null);
   com.architjn.acjmusicplayer.utils.Mood mood = new com.architjn.acjmusicplayer.utils.Mood();
   List<String> moods = mood.getAllMoods();
   RecyclerView gv = (RecyclerView) view.findViewById(R.id.dialog_playlist_rv);
   LinearLayoutManager gridLayoutManager = new LinearLayoutManager(context);
   gridLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
   gridLayoutManager.scrollToPosition(0);
   gv.setLayoutManager(gridLayoutManager);
   gv.setHasFixedSize(true);
   alertDialogBuilder.setView(view);
   alertDialogBuilder.setPositiveButton(
       "OK",
       new DialogInterface.OnClickListener() {
         @Override
         public void onClick(DialogInterface dialog, int which) {
           dialog.dismiss();
         }
       });
   alertDialogBuilder.setNegativeButton(
       "Cancel",
       new DialogInterface.OnClickListener() {
         @Override
         public void onClick(DialogInterface dialog, int which) {
           dialog.dismiss();
         }
       });
   AlertDialog dialog = alertDialogBuilder.create();
   DialogMoodAdapter adapter = new DialogMoodAdapter(context, moods, data.get(position), dialog);
   gv.setAdapter(adapter);
   WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
   lp.copyFrom(dialog.getWindow().getAttributes());
   lp.width = WindowManager.LayoutParams.MATCH_PARENT;
   lp.height = WindowManager.LayoutParams.MATCH_PARENT;
   dialog.show();
 }
Esempio n. 5
0
  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);
  }
 public void setPosition(int position) {
   mPosition = position;
   if (mLayoutManager != null && mAdapter != null) {
     mLayoutManager.scrollToPosition(Math.min(mPosition, mAdapter.getCount() - 1));
   }
 }