public void selectCategory(int category_id, boolean forceUpdate) { if (mCategoryId != category_id || forceUpdate) { mCategoryId = category_id; if ((mAdapter = getAdapter(mCategoryId)) == null) { mAdapter = new MainListAdapter( getActivity(), AccountManager.getInstance().getAccountsByCategory(mCategoryId), Application.getThemedIcons(), R.drawable.pb_unknown); mListView.postDelayed( new Runnable() { @Override public void run() { mAdapter.enableAnimation(false); } }, 100); cacheAdapter(mCategoryId, mAdapter); } mAdapter.setListener(this); mListView.setAdapter(mAdapter); mAdapter.notifyDataSetChanged(); mToBeRemoved = new int[mAdapter.getCount()]; ((TextView) mListView.getEmptyView()).setText(R.string.no_accounts); mCategoryIcon = -1; mCategoryName = null; } }
@Override public void onResp(int id, Resp resp, Object... obj) { if (id != requestId) return; boolean scrollEnd = (Boolean) obj[0]; if (resp.success) { if (cachedData == null) { cachedData = new DataArray(resp); } else { cachedData.append(resp); } adapter.notifyDataSetChanged(); if (scrollEnd && mReachEnd) { list.postDelayed( new Runnable() { public void run() { UI.toast(null); list.smoothScrollToPosition(adapter.getCount() - 1); } }, 500); // list.setSelection(); } } loadingEnd(); }
/** * 滚动列表到顶端 * * @param listView */ public static void smoothScrollListViewToTop(final ListView listView) { if (listView == null) { return; } smoothScrollListView(listView, 0); listView.postDelayed( new Runnable() { @Override public void run() { listView.setSelection(0); } }, 200); }
@Override public void onReceive(Context context, Intent intent) { if (mListView != null) { mTrackAdapter.notifyDataSetChanged(); // Scroll to the currently playing track in the queue if (mPlaylistId == PLAYLIST_QUEUE) mListView.postDelayed( new Runnable() { @Override public void run() { mListView.setSelection(MusicUtils.getQueuePosition()); } }, 100); } }
@Override public void onReceive(Context arg0, Intent intent) { Runnable r = new Runnable() { public void run() { try { if (currentDir == null) { listRoots(); } else { listFiles(currentDir); } } catch (Exception e) { FileLog.e("tmessages", e); } } }; if (Intent.ACTION_MEDIA_UNMOUNTED.equals(intent.getAction())) { listView.postDelayed(r, 1000); } else { r.run(); } }
@Override public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_main, container, false); mListView = (ListView) rootView.findViewById(android.R.id.list); if ((mAdapter = getAdapter(mCategoryId)) == null) { mAdapter = new MainListAdapter( getActivity(), AccountManager.getInstance().getAccountsByCategory(mCategoryId), Application.getThemedIcons(), R.drawable.pb_unknown); mListView.postDelayed( new Runnable() { @Override public void run() { mAdapter.enableAnimation(false); } }, 100); cacheAdapter(mCategoryId, mAdapter); } mAdapter.setListener(this); mListView.setAdapter(mAdapter); mListView.setEmptyView(rootView.findViewById(android.R.id.empty)); mListView.setOnItemClickListener(this); mListView.setOnItemLongClickListener(this); mToBeRemoved = new int[mAdapter.getCount()]; mFab = (ImageButton) rootView.findViewById(R.id.fab); mFab.setOnClickListener(this); if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT) { LayerDrawable background = (LayerDrawable) mFab.getBackground(); background .getDrawable(1) .setColorFilter(C.ThemedColors[C.colorAccent], PorterDuff.Mode.SRC_ATOP); } if (!getResources().getBoolean(R.bool.snackbar_left_align)) { mFabToPush = (int) (getResources().getDimension(R.dimen.snackbar_height_single) + 0.5f); } else { mFabToPush = 0; } mCategoryEditView = rootView.findViewById(R.id.category_editor); EditText editCategoryName = (EditText) rootView.findViewById(R.id.category_name); editCategoryName.addTextChangedListener( new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) {} @Override public void onTextChanged(CharSequence s, int start, int before, int count) {} @Override public void afterTextChanged(Editable s) { if (mActionMode != null) { mCategoryName = s.toString(); mCategorySavable = mCategoryName.length() > 0; mActionMode.invalidate(); } } }); if (mIsEditing) { mIsEditing = false; editCategory(); } else if (mSelectionMode) { mActionMode = ((MainActivity) getActivity()).startSupportActionMode(mActionModeCallback); } return rootView; }
@SuppressLint("NewApi") @Override protected void onCreate(Bundle savedInstanceState) { mCatList = new ArrayList<>(); Calendar cala = Calendar.getInstance(); cala.setTimeInMillis(System.currentTimeMillis()); // setDailyAlarm(this); // if(Build.VERSION.SDK_INT >= 21){ // Window window = getWindow(); // window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); // window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); // window.setStatusBarColor(getResources().getColor(R.color.primary_dark)); // // inside your activity (if you did not enable transitions in your theme) // // window.requestFeature(Window.FEATURE_CONTENT_TRANSITIONS); // // window.setExitTransition(new Explode()); // // window.setEnterTransition(new Fade()); // } super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); getSupportLoaderManager().initLoader(LOADER_ID, null, this); toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); getSupportActionBar().setDisplayShowHomeEnabled(true); checknCallDailyAlarm(); // mFab = (ButtonFloat) findViewById(R.id.fab); // mFab.setOnClickListener(this); // getCountList(); // load slide menu items navMenuTitles = getResources().getStringArray(R.array.nav_drawer_items); // populateCategoryDb(navMenuTitles); // populateCategoryDb(navMenuTitles); // nav drawer icons from resources // navMenuIcons = getResources().obtainTypedArray(R.array.nav_drawer_icons); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawerList = (ListView) findViewById(R.id.list_slidermenu); mDrawerList.setOnItemClickListener(new SlideMenuClickListener()); adapter = new CategoryCursorListAdapter(this, null, CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER); // navMenuIcons.recycle(); mDrawerList.setAdapter(adapter); mDrawerToggle = new ActionBarDrawerToggle( this, mDrawerLayout, toolbar, // nav menu toggle icon R.string.app_name, // nav drawer open - description for accessibility R.string.app_name // nav drawer close - description for accessibility ) { public void onDrawerClosed(View view) {} public void onDrawerOpened(View drawerView) {} }; mDrawerToggle.syncState(); mDrawerLayout.setDrawerListener(mDrawerToggle); // ivProfilePic = (ImageView) findViewById(R.id.profile_img); mDrawerList.postDelayed( new Runnable() { @Override public void run() { displayView(TasksTable.TASK_TYPE_COMMING_UP, 1); } }, 100); TextView tvDate = (TextView) findViewById(R.id.tv_date); TextView tvMonth = (TextView) findViewById(R.id.tv_month); Calendar cal = Calendar.getInstance(); SimpleDateFormat mFormatDate = new SimpleDateFormat("dd", Locale.getDefault()); SimpleDateFormat mFormatMonth = new SimpleDateFormat("MMMM", Locale.getDefault()); tvDate.setText(mFormatDate.format(cal.getTime())); tvMonth.setText(mFormatMonth.format(cal.getTime())); Intent mIntent = getIntent(); if (mIntent != null) { if (mIntent.getAction() != null) { if (mIntent.getAction().equals(StringConstants.NOTIF_ACTION)) { int cat = Integer.valueOf( mIntent.getIntExtra( IntentKeyConstants.KEY_TYPE_OF_ALARM, TasksTable.TASK_TYPE_ALL_TASKS)); displayView(TasksTable.TASK_TYPE_NORMAL, cat); isNotif = true; } } } MaterialCalendarView mCal = (MaterialCalendarView) findViewById(R.id.calendarView); if (mCal != null) mCal.setSelectedDate( new CalendarDay( cal.get(Calendar.YEAR), cal.get(Calendar.MONDAY), cal.get(Calendar.DAY_OF_MONTH))); // GoogleAnalytics.getInstance(getBaseContext()).dispatchLocalHits(); // Tracker t = ((IReminder)getApplication()).getTracker(TrackerName.APP_TRACKER); // t.setScreenName("Main activity"); // t.send(new HitBuilders.AppViewBuilder().build()); reciever = new ColorChangeReciever(); }
/* * Receive stop action from service to stop recitation and hide audio bar * (non-Javadoc) * * @see * android.content.BroadcastReceiver#onReceive(android.content.Context, * android.content.Intent) */ @Override public void onReceive(Context mContext, Intent intent) { String mIntent = intent.getStringExtra("recitationControl"); if (mIntent.equals("stopRecitation")) { toolsBarObject.onAudioButtonClick(false, false, true); } else if (mIntent.equals("displayCurrentAyah")) { /* * Check if the current recited Surah does not match the * displayed surah don't show ayah highlight instead show a * toast message telling user that current Surah is not the one * being recited */ int recitingSurahID = pref.getPrefObj().getInt("recitationSurahNumber", 1); if (surahID == recitingSurahID) { final Integer ayahID = pref.getPrefObj().getInt("recitationAyahNumber", 1); /* * We are not going to use this code since * smoothScrollToPosition is not user friendly we are going * to use only setSelection * * * // smoothScrollToPosition() was introduced in version 8 (FROYO) * // so we use setSelection() if the system is not Froyo * int SDK_INT = android.os.Build.VERSION.SDK_INT; * if(SDK_INT >= 8) * ayahList.smoothScrollToPosition(ayahID); * else * ayahList.setSelection(ayahID); */ /* * Set selection to the ayah that is currenlty recited Also, * we use postDelayed function to delay highlight feature by * 100 or 200 milliseconds in order for the ayah to be * displayed, otherwise we will get nullPointerException */ ayahList.setSelection(ayahID); ayahList.postDelayed( new Runnable() { public void run() { int ayah = 0; /* * Get the first visible item in the adapter, the * ayah position number will refere to its position * relative to the whole adapter and not just the * visible views. Then we use this number to * calcuate what the position of the ayah in the * visible views (since they are zero-based) */ int visibleItem = ayahList.getFirstVisiblePosition(); if (ayahID > visibleItem) { ayah = ayahID - visibleItem; } else if (ayahID == visibleItem) { ayah = 0; } // We make sure once again that the view is not null (Visible) View currentAyah = ayahList.getChildAt(ayah); if (currentAyah != null) currentAyah.setSelected(true); } }, 200); } else { // The visible surah does not match the recited one ToastNotification toastMessage = new ToastNotification(mContext); toastMessage.show(R.drawable.toast_warning, R.string.recitationCurrentSurahNoMatch); } } }