@Override public void onResume() { if (activity != null) { Boolean a = s.getBoolean(IS_TIME_TABLE_CHANGED, true); timetable = s.getString(GET_TIME_TABLE, null); adapter2 = new CustomList_calendar(activity, days, p0, p1, p2, p3, p4, p5, p6, p7, p8, p9); lvTest.setAdapter(adapter2); lvTest.setItemMargin(10); if (a || timetable == null) { if (Utils.isNetworkAvailable(activity)) new DownloadWebPageTask2().execute(); else { if (activity != null) SnackbarManager.show( Snackbar.with(activity.getApplicationContext()) .text("Check Your Internet Connection") .duration(Snackbar.SnackbarDuration.LENGTH_SHORT), activity); } } else { load(); } } super.onResume(); }
@Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); final Activity activity = getActivity(); mToast = Toast.makeText(activity, "", Toast.LENGTH_SHORT); mToast.setGravity(Gravity.CENTER, 0, 0); mRecyclerView = (TwoWayView) view.findViewById(R.id.list); mRecyclerView.setHasFixedSize(true); mRecyclerView.setLongClickable(true); mPositionText = (TextView) view.getRootView().findViewById(R.id.position); mCountText = (TextView) view.getRootView().findViewById(R.id.count); mStateText = (TextView) view.getRootView().findViewById(R.id.state); updateState(SCROLL_STATE_IDLE); final ItemClickSupport itemClick = ItemClickSupport.addTo(mRecyclerView); itemClick.setOnItemClickListener( new OnItemClickListener() { @Override public void onItemClick(RecyclerView parent, View child, int position, long id) { mToast.setText("Item clicked: " + position); mToast.show(); } }); itemClick.setOnItemLongClickListener( new OnItemLongClickListener() { @Override public boolean onItemLongClick(RecyclerView parent, View child, int position, long id) { mToast.setText("Item long pressed: " + position); mToast.show(); return true; } }); mRecyclerView.setOnScrollListener( new RecyclerView.OnScrollListener() { @Override public void onScrollStateChanged(int scrollState) { updateState(scrollState); } @Override public void onScrolled(int i, int i2) { mPositionText.setText("First: " + mRecyclerView.getFirstVisiblePosition()); mCountText.setText("Count: " + mRecyclerView.getChildCount()); } }); final Drawable divider = getResources().getDrawable(R.drawable.divider); mRecyclerView.addItemDecoration(new DividerItemDecoration(divider)); mRecyclerView.setAdapter(new SimpleAdapter(activity, mRecyclerView, mLayoutId)); }
@Override public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_calender, container, false); lvTest = (TwoWayView) rootView.findViewById(R.id.lvItems); if (activity == null) return rootView; s = PreferenceManager.getDefaultSharedPreferences(activity); e = s.edit(); Boolean b = s.getBoolean(IS_CLASS_SET, false); if (!b) { Intent i = new Intent(activity, ChooseClass.class); startActivity(i); } Boolean a = s.getBoolean(IS_TIME_TABLE_CHANGED, true); timetable = s.getString(GET_TIME_TABLE, null); adapter2 = new CustomList_calendar(activity, days, p0, p1, p2, p3, p4, p5, p6, p7, p8, p9); lvTest.setAdapter(adapter2); lvTest.setItemMargin(10); if (a == true || timetable == null) { if (Utils.isNetworkAvailable(activity)) new DownloadWebPageTask2().execute(); else { SnackbarManager.show( Snackbar.with(activity.getApplicationContext()) .text("Check Your Internet Connection") .duration(Snackbar.SnackbarDuration.LENGTH_SHORT), activity); } } else { load(); } lvTest.setOnScrollListener( new TwoWayView.OnScrollListener() { @Override public void onScrollStateChanged(TwoWayView view, int scrollState) {} @Override public void onScroll( TwoWayView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { int lastInScreen = firstVisibleItem + visibleItemCount; if ((lastInScreen == totalItemCount) && !(loadingMore)) { load(); } adapter2.notifyDataSetChanged(); } }); return rootView; }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.requestWindowFeature(Window.FEATURE_NO_TITLE); this.getWindow() .setFlags( WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); setContentView(R.layout.activity_kairos); kairosApps = KairosAppLoader.instance().getKairosApps(); appDeckAdapter = new AppAdapter(this, kairosApps); appDeckGridView = (TwoWayView) findViewById(R.id.appDeckGridView); appDeckGridView.setAdapter(appDeckAdapter); appDeckGridView.setOnItemClickListener( new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { displayAppInfoFragment((int) id); } }); contextImageView = (ImageView) findViewById(R.id.contextImageView); contextTextView = (TextView) findViewById(R.id.contextTextView); appInfoFrameLayout = (FrameLayout) findViewById(R.id.appInfoFrameLayout); navigationFragment = new NavigationFragment(); getSupportFragmentManager() .beginTransaction() .add(R.id.navigationFrameLayout, navigationFragment) .commit(); notificationFragment = new NotificationFragment(); getSupportFragmentManager() .beginTransaction() .add(R.id.notificationFrameLayout, notificationFragment) .commit(); TouchpadInputProvider.instance().requestInputControls(this); CarContextProvider.instance().requestDriverLoad(this); CarContextProvider.instance().requestCarStates(this); }
@Override public void onBindViewHolder(SimpleViewHolder holder, int position) { holder.title.setText(String.valueOf(position)); boolean isVertical = (mRecyclerView.getOrientation() == Orientation.VERTICAL); final View itemView = holder.itemView; if (mLayoutId == R.layout.layout_staggered_grid) { final int id; if (position % 3 == 0) { id = R.dimen.staggered_child_medium; } else if (position % 5 == 0) { id = R.dimen.staggered_child_large; } else if (position % 7 == 0) { id = R.dimen.staggered_child_xlarge; } else { id = R.dimen.staggered_child_small; } final int span; if (position == 2) { span = 2; } else { span = 1; } final int size = mContext.getResources().getDimensionPixelSize(id); final StaggeredGridLayoutManager.LayoutParams lp = (StaggeredGridLayoutManager.LayoutParams) itemView.getLayoutParams(); if (!isVertical && lp.width != id) { lp.span = span; lp.width = size; itemView.setLayoutParams(lp); } else if (isVertical && lp.height != id) { lp.span = span; lp.height = size; itemView.setLayoutParams(lp); } } else if (mLayoutId == R.layout.layout_spannable_grid) { final SpannableGridLayoutManager.LayoutParams lp = (SpannableGridLayoutManager.LayoutParams) itemView.getLayoutParams(); final int span1 = (position == 0 || position == 3 ? 2 : 1); final int span2 = (position == 0 ? 2 : (position == 3 ? 3 : 1)); final int colSpan = (isVertical ? span2 : span1); final int rowSpan = (isVertical ? span1 : span2); if (lp.rowSpan != rowSpan || lp.colSpan != colSpan) { lp.rowSpan = rowSpan; lp.colSpan = colSpan; itemView.setLayoutParams(lp); } } }
private void setUIState(State state) { this.state = state; switch (state) { case PLAIN: appDeckGridView.setVisibility(View.GONE); appInfoFrameLayout.setVisibility(View.GONE); break; case APP_DECK_ACTIVE: appDeckAdapter.notifyDataSetChanged(); appDeckGridView.setVisibility(View.VISIBLE); appInfoFrameLayout.setVisibility(View.GONE); break; case APP_MAIN_ACTIVE: appDeckGridView.setVisibility(View.GONE); appInfoFrameLayout.setVisibility(View.VISIBLE); break; } }