Search in sources :

Example 91 with SwipeRefreshLayout

use of android.support.v4.widget.SwipeRefreshLayout in project BaseRecyclerViewAdapter by donghan0912.

the class StaggeredFragment method onViewCreated.

@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    SwipeRefreshLayout refreshLayout = (SwipeRefreshLayout) view.findViewById(R.id.swip_refresh);
    refreshLayout.setEnabled(false);
    RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.recycler_view);
    StaggeredGridLayoutManager manager = new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL);
    recyclerView.setLayoutManager(manager);
    for (int i = 0; i < 20; i++) {
        WQ wq = new WQ(getRandomHeight(), getDrawable());
        list.add(new FourthItem(wq));
    }
    final BaseRecyclerViewAdapter adapter = new BaseRecyclerViewAdapter(list);
    recyclerView.setAdapter(adapter);
    adapter.addHeader(new SimpleItem(R.layout.layout_staggered_head) {

        @Override
        public void onBindViewHolder(BaseViewHolder holder, int position) {
            StaggeredGridLayoutManager.LayoutParams p = (StaggeredGridLayoutManager.LayoutParams) holder.itemView.getLayoutParams();
            p.setFullSpan(true);
        }
    });
    // 设置加载更多布局,并占满整行
    adapter.setExtraItem(new SimpleItem(R.layout.layout_loadmore) {

        @Override
        public void onBindViewHolder(BaseViewHolder holder, int position) {
            StaggeredGridLayoutManager.LayoutParams p = (StaggeredGridLayoutManager.LayoutParams) holder.itemView.getLayoutParams();
            p.setFullSpan(true);
        }
    });
    recyclerView.addOnScrollListener(new EndlessRecyclerOnScrollListener() {

        @Override
        public void onLoadMore() {
            if (!loadMore) {
                return;
            }
            new Handler().postDelayed(new Runnable() {

                @Override
                public void run() {
                    new Handler().postDelayed(new Runnable() {

                        @Override
                        public void run() {
                            List<FourthItem> list2 = new ArrayList<>();
                            for (int i = 0; i < 21; i++) {
                                WQ wq = new WQ(getRandomHeight(), getDrawable());
                                list2.add(new FourthItem(wq));
                            }
                            list.addAll(list2);
                            if (list.size() > 70) {
                                adapter.setExtraItem(new SimpleItem(R.layout.layout_loadmore_complete) {

                                    @Override
                                    public void onBindViewHolder(BaseViewHolder holder, int position) {
                                        StaggeredGridLayoutManager.LayoutParams p = (StaggeredGridLayoutManager.LayoutParams) holder.itemView.getLayoutParams();
                                        p.setFullSpan(true);
                                    }
                                });
                                loadMore = false;
                            }
                            adapter.addData(list2);
                        }
                    }, 3000);
                }
            }, 3000);
        }
    });
}
Also used : BaseViewHolder(com.hpu.baserecyclerviewadapter.BaseViewHolder) EndlessRecyclerOnScrollListener(com.hpu.baserecyclerviewadapter.EndlessRecyclerOnScrollListener) Handler(android.os.Handler) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) FourthItem(com.hpu.baserecyclerviewadapter.sample.multi.FourthItem) RecyclerView(android.support.v7.widget.RecyclerView) WQ(com.hpu.baserecyclerviewadapter.sample.bean.WQ) ArrayList(java.util.ArrayList) List(java.util.List) BaseRecyclerViewAdapter(com.hpu.baserecyclerviewadapter.BaseRecyclerViewAdapter) SimpleItem(com.hpu.baserecyclerviewadapter.SimpleItem)

Example 92 with SwipeRefreshLayout

use of android.support.v4.widget.SwipeRefreshLayout in project sentinel-android by Samourai-Wallet.

the class BalanceActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_balance);
    BalanceActivity.this.getActionBar().setTitle(R.string.app_name);
    // 
    // account selection
    // 
    account_selections = new String[1];
    account_selections[0] = "";
    adapter = new ArrayAdapter<String>(getBaseContext(), android.R.layout.simple_spinner_dropdown_item, account_selections);
    getActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
    navigationListener = new ActionBar.OnNavigationListener() {

        @Override
        public boolean onNavigationItemSelected(int itemPosition, long itemId) {
            SamouraiSentinel.getInstance(BalanceActivity.this).setCurrentSelectedAccount(itemPosition);
            refreshTx(false);
            return false;
        }
    };
    getActionBar().setListNavigationCallbacks(adapter, navigationListener);
    LayoutInflater inflator = BalanceActivity.this.getLayoutInflater();
    tvBalanceBar = (LinearLayout) inflator.inflate(R.layout.balance_layout, null);
    tvBalanceBar.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            isBTC = (isBTC) ? false : true;
            displayBalance();
            txAdapter.notifyDataSetChanged();
            return false;
        }
    });
    tvBalanceAmount = (TextView) tvBalanceBar.findViewById(R.id.BalanceAmount);
    tvBalanceUnits = (TextView) tvBalanceBar.findViewById(R.id.BalanceUnits);
    ibQuickSend = (FloatingActionsMenu) findViewById(R.id.wallet_menu);
    actionReceive = (FloatingActionButton) findViewById(R.id.receive);
    actionReceive.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            confirmAccountSelection(false);
        }
    });
    actionXPUB = (FloatingActionButton) findViewById(R.id.xpub);
    actionXPUB.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            TimeOutUtil.getInstance().updatePin();
            Intent intent = new Intent(BalanceActivity.this, XPUBListActivity.class);
            startActivity(intent);
        }
    });
    txList = (ListView) findViewById(R.id.txList);
    txAdapter = new TransactionAdapter();
    txList.setAdapter(txAdapter);
    txList.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, final View view, int position, long id) {
            if (position == 0) {
                return;
            }
            long viewId = view.getId();
            View v = (View) view.getParent();
            Tx tx = txs.get(position - 1);
            ImageView ivTxStatus = (ImageView) v.findViewById(R.id.TransactionStatus);
            TextView tvConfirmationCount = (TextView) v.findViewById(R.id.ConfirmationCount);
            if (viewId == R.id.ConfirmationCount || viewId == R.id.TransactionStatus) {
                if (txStates.containsKey(tx.getHash()) && txStates.get(tx.getHash()) == true) {
                    txStates.put(tx.getHash(), false);
                    displayTxStatus(false, tx.getConfirmations(), tvConfirmationCount, ivTxStatus);
                } else {
                    txStates.put(tx.getHash(), true);
                    displayTxStatus(true, tx.getConfirmations(), tvConfirmationCount, ivTxStatus);
                }
            } else {
                String strTx = tx.getHash();
                if (strTx != null) {
                    int sel = PrefsUtil.getInstance(BalanceActivity.this).getValue(PrefsUtil.BLOCK_EXPLORER, 0);
                    CharSequence url = BlockExplorerUtil.getInstance().getBlockExplorerUrls()[sel];
                    Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url + strTx));
                    startActivity(browserIntent);
                }
            }
        }
    });
    swipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swiperefresh);
    swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {

        @Override
        public void onRefresh() {
            new Handler().post(new Runnable() {

                @Override
                public void run() {
                    refreshTx(true);
                }
            });
        }
    });
    swipeRefreshLayout.setColorSchemeResources(android.R.color.holo_blue_bright, android.R.color.holo_green_light, android.R.color.holo_orange_light, android.R.color.holo_red_light);
    if (!AppUtil.getInstance(BalanceActivity.this.getApplicationContext()).isServiceRunning(WebSocketService.class)) {
        BalanceActivity.this.startService(new Intent(BalanceActivity.this.getApplicationContext(), WebSocketService.class));
    }
    restoreWatchOnly();
}
Also used : SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) TextView(android.widget.TextView) WebSocketService(com.samourai.sentinel.service.WebSocketService) ImageView(android.widget.ImageView) ActionBar(android.app.ActionBar) Tx(com.samourai.sentinel.api.Tx) Handler(android.os.Handler) Intent(android.content.Intent) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) MotionEvent(android.view.MotionEvent) LayoutInflater(android.view.LayoutInflater) OnClickListener(android.view.View.OnClickListener) AdapterView(android.widget.AdapterView)

Example 93 with SwipeRefreshLayout

use of android.support.v4.widget.SwipeRefreshLayout in project remusic by aa112901.

the class MainFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_main, container, false);
    swipeRefresh = (SwipeRefreshLayout) view.findViewById(R.id.swiperefresh);
    recyclerView = (RecyclerView) view.findViewById(R.id.recyclerview);
    layoutManager = new LinearLayoutManager(mContext);
    recyclerView.setLayoutManager(layoutManager);
    // swipeRefresh.setColorSchemeResources(R.color.theme_color_PrimaryAccent);
    swipeRefresh.setColorSchemeColors(ThemeUtils.getColorById(mContext, R.color.theme_color_primary));
    swipeRefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {

        @Override
        public void onRefresh() {
            reloadAdapter();
        }
    });
    // 先给adapter设置空数据,异步加载好后更新数据,防止Recyclerview no attach
    mAdapter = new MainFragmentAdapter(mContext);
    recyclerView.setAdapter(mAdapter);
    recyclerView.setHasFixedSize(true);
    recyclerView.addItemDecoration(new DividerItemDecoration(mContext, DividerItemDecoration.VERTICAL_LIST));
    // 设置没有item动画
    ((SimpleItemAnimator) recyclerView.getItemAnimator()).setSupportsChangeAnimations(false);
    reloadAdapter();
    mContext.getWindow().setBackgroundDrawableResource(R.color.background_material_light_1);
    return view;
}
Also used : SimpleItemAnimator(android.support.v7.widget.SimpleItemAnimator) MainFragmentAdapter(com.wm.remusic.adapter.MainFragmentAdapter) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) DividerItemDecoration(com.wm.remusic.widget.DividerItemDecoration) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout)

Example 94 with SwipeRefreshLayout

use of android.support.v4.widget.SwipeRefreshLayout in project talk-android by nextcloud.

the class CallsListController method fetchData.

private void fetchData(boolean fromBottomSheet) {
    dispose(null);
    callItems = new ArrayList<>();
    roomsQueryDisposable = ncApi.getRooms(ApiUtils.getCredentials(userEntity.getUsername(), userEntity.getToken()), ApiUtils.getUrlForGetRooms(userEntity.getBaseUrl())).subscribeOn(Schedulers.newThread()).observeOn(AndroidSchedulers.mainThread()).subscribe(roomsOverall -> {
        if (roomsOverall != null) {
            for (int i = 0; i < roomsOverall.getOcs().getData().size(); i++) {
                callItems.add(new CallItem(roomsOverall.getOcs().getData().get(i), userEntity));
            }
            adapter.updateDataSet(callItems, true);
            Collections.sort(callItems, (callItem, t1) -> Long.compare(t1.getModel().getLastPing(), callItem.getModel().getLastPing()));
            if (searchItem != null) {
                searchItem.setVisible(callItems.size() > 0);
            }
        }
        if (swipeRefreshLayout != null) {
            swipeRefreshLayout.setRefreshing(false);
        }
    }, throwable -> {
        if (searchItem != null) {
            searchItem.setVisible(false);
        }
        if (throwable instanceof HttpException) {
            HttpException exception = (HttpException) throwable;
            switch(exception.code()) {
                case 401:
                    if (getParentController() != null && getParentController().getRouter() != null) {
                        getParentController().getRouter().pushController((RouterTransaction.with(new WebViewLoginController(userEntity.getBaseUrl(), true)).pushChangeHandler(new VerticalChangeHandler()).popChangeHandler(new VerticalChangeHandler())));
                    }
                    break;
                default:
                    break;
            }
        }
        if (swipeRefreshLayout != null) {
            swipeRefreshLayout.setRefreshing(false);
        }
        dispose(roomsQueryDisposable);
    }, () -> {
        dispose(roomsQueryDisposable);
        if (swipeRefreshLayout != null) {
            swipeRefreshLayout.setRefreshing(false);
        }
        if (fromBottomSheet) {
            new Handler().postDelayed(() -> {
                bottomSheet.setCancelable(true);
                if (bottomSheet.isShowing()) {
                    bottomSheet.cancel();
                }
            }, 2500);
        }
    });
}
Also used : AutoInjector(autodagger.AutoInjector) Bundle(android.os.Bundle) UserUtils(com.nextcloud.talk.utils.database.user.UserUtils) EntryMenuController(com.nextcloud.talk.controllers.bottomsheet.EntryMenuController) SearchView(android.support.v7.widget.SearchView) CallMenuController(com.nextcloud.talk.controllers.bottomsheet.CallMenuController) AndroidSchedulers(io.reactivex.android.schedulers.AndroidSchedulers) DividerItemDecoration(android.support.v7.widget.DividerItemDecoration) BindView(butterknife.BindView) ApiUtils(com.nextcloud.talk.utils.ApiUtils) BottomSheet(com.kennyc.bottomsheet.BottomSheet) Handler(android.os.Handler) View(android.view.View) Schedulers(io.reactivex.schedulers.Schedulers) VerticalChangeHandler(com.bluelinelabs.conductor.changehandler.VerticalChangeHandler) Participant(com.nextcloud.talk.models.json.participants.Participant) MenuItemCompat(android.support.v4.view.MenuItemCompat) HttpException(retrofit2.HttpException) InputType(android.text.InputType) FlexibleAdapter(eu.davidea.flexibleadapter.FlexibleAdapter) ThreadMode(org.greenrobot.eventbus.ThreadMode) ViewGroup(android.view.ViewGroup) NoOpControllerChangeHandler(com.bluelinelabs.conductor.internal.NoOpControllerChangeHandler) BundleKeys(com.nextcloud.talk.utils.bundle.BundleKeys) List(java.util.List) Disposable(io.reactivex.disposables.Disposable) Parcels(org.parceler.Parcels) FastScroller(eu.davidea.fastscroller.FastScroller) CallItem(com.nextcloud.talk.adapters.items.CallItem) Nullable(android.support.annotation.Nullable) SearchManager(android.app.SearchManager) EditorInfo(android.view.inputmethod.EditorInfo) Context(android.content.Context) MoreMenuClickEvent(com.nextcloud.talk.events.MoreMenuClickEvent) UserEntity(com.nextcloud.talk.models.database.UserEntity) SmoothScrollLinearLayoutManager(eu.davidea.flexibleadapter.common.SmoothScrollLinearLayoutManager) Intent(android.content.Intent) NonNull(android.support.annotation.NonNull) MenuItem(android.view.MenuItem) ArrayList(java.util.ArrayList) BottomSheetLockEvent(com.nextcloud.talk.events.BottomSheetLockEvent) Inject(javax.inject.Inject) BaseController(com.nextcloud.talk.controllers.base.BaseController) MenuInflater(android.view.MenuInflater) EventBus(org.greenrobot.eventbus.EventBus) Menu(android.view.Menu) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) NcApi(com.nextcloud.talk.api.NcApi) BottomNavigationView(android.support.design.widget.BottomNavigationView) R(com.nextcloud.talk.R) Room(com.nextcloud.talk.models.json.rooms.Room) LayoutInflater(android.view.LayoutInflater) TextUtils(android.text.TextUtils) HorizontalChangeHandler(com.bluelinelabs.conductor.changehandler.HorizontalChangeHandler) RecyclerView(android.support.v7.widget.RecyclerView) Subscribe(org.greenrobot.eventbus.Subscribe) KeyboardUtils(com.nextcloud.talk.utils.KeyboardUtils) CallActivity(com.nextcloud.talk.activities.CallActivity) ViewTreeObserver(android.view.ViewTreeObserver) Collections(java.util.Collections) NextcloudTalkApplication(com.nextcloud.talk.application.NextcloudTalkApplication) RouterTransaction(com.bluelinelabs.conductor.RouterTransaction) Handler(android.os.Handler) VerticalChangeHandler(com.bluelinelabs.conductor.changehandler.VerticalChangeHandler) NoOpControllerChangeHandler(com.bluelinelabs.conductor.internal.NoOpControllerChangeHandler) HorizontalChangeHandler(com.bluelinelabs.conductor.changehandler.HorizontalChangeHandler) CallItem(com.nextcloud.talk.adapters.items.CallItem) HttpException(retrofit2.HttpException) VerticalChangeHandler(com.bluelinelabs.conductor.changehandler.VerticalChangeHandler)

Example 95 with SwipeRefreshLayout

use of android.support.v4.widget.SwipeRefreshLayout in project BetterBatteryStats by asksven.

the class StatsActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
    super.onCreate(savedInstanceState);
    // HockeyApp
    try {
        MetricsManager.register(getApplication());
    } catch (Exception e) {
        Log.e(TAG, e.getMessage());
    }
    // Log.i(TAG, "OnCreated called");
    setContentView(R.layout.stats);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    toolbar.setTitle(getString(R.string.app_name));
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayUseLogoEnabled(false);
    // set debugging
    if (sharedPrefs.getBoolean("debug_logging", false)) {
        LogSettings.DEBUG = true;
        CommonLogSettings.DEBUG = true;
    } else {
        LogSettings.DEBUG = false;
        CommonLogSettings.DEBUG = false;
    }
    swipeLayout = (SwipeRefreshLayout) findViewById(R.id.swiperefresh);
    swipeLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {

        @Override
        public void onRefresh() {
            doRefresh(true);
        }
    });
    // /////////////////////////////////////////////
    // check if we have a new release
    // /////////////////////////////////////////////
    // if yes do some migration (if required) and show release notes
    String strLastRelease = sharedPrefs.getString("last_release", "0");
    String strCurrentRelease = "";
    try {
        PackageInfo pinfo = getPackageManager().getPackageInfo(getPackageName(), 0);
        strCurrentRelease = Integer.toString(pinfo.versionCode);
    } catch (Exception e) {
    // nop strCurrentRelease is set to ""
    }
    // if root is available use it
    boolean ignoreSystemApp = sharedPrefs.getBoolean("ignore_system_app", false);
    // Grant permissions if they are missing and root is available
    if (!SysUtils.hasBatteryStatsPermission(this) || !SysUtils.hasDumpsysPermission(this) || !SysUtils.hasPackageUsageStatsPermission(this)) {
        if ((!ignoreSystemApp && RootShell.getInstance().hasRootPermissions())) {
            // attempt to set perms using pm-comand
            Log.i(TAG, "attempting to grant perms with 'pm grant'");
            String pkg = this.getPackageName();
            RootShell.getInstance().run("pm grant " + pkg + " android.permission.BATTERY_STATS");
            RootShell.getInstance().run("pm grant " + pkg + " android.permission.DUMP");
            RootShell.getInstance().run("pm grant " + pkg + " android.permission.PACKAGE_USAGE_STATS");
            if (SysUtils.hasBatteryStatsPermission(this)) {
                Log.i(TAG, "succeeded");
            } else {
                Log.i(TAG, "failed");
            }
        }
    }
    // Package usage stats were introduced in SDK21 so we need to make the distinction
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        // show install as system app screen if root available but perms missing
        if (!SysUtils.hasBatteryStatsPermission(this) || !SysUtils.hasDumpsysPermission(this) || !SysUtils.hasPackageUsageStatsPermission(this)) {
            Intent intentSystemApp = new Intent(this, SystemAppActivity.class);
            this.startActivity(intentSystemApp);
        }
    } else {
        if (!SysUtils.hasBatteryStatsPermission(this) || !SysUtils.hasDumpsysPermission(this)) {
            Intent intentSystemApp = new Intent(this, SystemAppActivity.class);
            this.startActivity(intentSystemApp);
        }
    }
    final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    // first start
    if (strLastRelease.equals("0")) {
        boolean firstLaunch = !prefs.getBoolean("launched", false);
        if (firstLaunch) {
            // Save that the app has been launched
            SharedPreferences.Editor editor = prefs.edit();
            editor.putBoolean("launched", true);
            editor.commit();
            // start service to persist reference
            Intent serviceIntent = new Intent(this, WriteUnpluggedReferenceService.class);
            this.startService(serviceIntent);
            // refresh widgets
            Intent intentRefreshWidgets = new Intent(LargeWidgetProvider.WIDGET_UPDATE);
            this.sendBroadcast(intentRefreshWidgets);
        }
        SharedPreferences.Editor updater = sharedPrefs.edit();
        updater.putString("last_release", strCurrentRelease);
        updater.commit();
    } else if (!strLastRelease.equals(strCurrentRelease)) {
        // save the current release to properties so that the dialog won't be shown till next version
        SharedPreferences.Editor updater = sharedPrefs.edit();
        updater.putString("last_release", strCurrentRelease);
        updater.commit();
        // we don't need to delete refs as long as we don't change the database schema
        // Toast.makeText(this, getString(R.string.info_deleting_refs), Toast.LENGTH_SHORT).show();
        // ReferenceStore.deleteAllRefs(this);
        // Intent i = new Intent(this, WriteBootReferenceService.class);
        // this.startService(i);
        // i = new Intent(this, WriteUnpluggedReferenceService.class);
        // this.startService(i);
        ChangeLog cl = new ChangeLog(this);
        cl.getLogDialog().show();
    }
    // /////////////////////////////////////////////
    // retrieve default selections for spinners
    // if none were passed
    // /////////////////////////////////////////////
    m_iStat = Integer.valueOf(sharedPrefs.getString("default_stat", "0"));
    m_refFromName = sharedPrefs.getString("default_stat_type", Reference.UNPLUGGED_REF_FILENAME);
    if (!ReferenceStore.hasReferenceByName(m_refFromName, this)) {
        m_refFromName = Reference.BOOT_REF_FILENAME;
        Toast.makeText(this, getString(R.string.info_fallback_to_boot), Toast.LENGTH_SHORT).show();
    }
    if (LogSettings.DEBUG)
        Log.i(TAG, "onCreate state from preferences: refFrom=" + m_refFromName + " refTo=" + m_refToName);
    try {
        // recover any saved state
        if ((savedInstanceState != null) && (!savedInstanceState.isEmpty())) {
            m_iStat = (Integer) savedInstanceState.getSerializable("stat");
            m_refFromName = (String) savedInstanceState.getSerializable("stattypeFrom");
            m_refToName = (String) savedInstanceState.getSerializable("stattypeTo");
            if (LogSettings.DEBUG)
                Log.i(TAG, "onCreate retrieved saved state: refFrom=" + m_refFromName + " refTo=" + m_refToName);
        }
    } catch (Exception e) {
        m_iStat = Integer.valueOf(sharedPrefs.getString("default_stat", "0"));
        m_refFromName = sharedPrefs.getString("default_stat_type", Reference.UNPLUGGED_REF_FILENAME);
        Log.e(TAG, "Exception: " + e.getMessage());
        DataStorage.LogToFile(LOGFILE, "Exception in onCreate restoring Bundle");
        DataStorage.LogToFile(LOGFILE, e.getMessage());
        DataStorage.LogToFile(LOGFILE, e.getStackTrace());
        Toast.makeText(this, getString(R.string.info_state_recovery_error), Toast.LENGTH_SHORT).show();
    }
    // Handle the case the Activity was called from an intent with paramaters
    Bundle extras = getIntent().getExtras();
    if ((extras != null) && !extras.isEmpty()) {
        // Override if some values were passed to the intent
        if (extras.containsKey(StatsActivity.STAT))
            m_iStat = extras.getInt(StatsActivity.STAT);
        if (extras.containsKey(StatsActivity.STAT_TYPE_FROM))
            m_refFromName = extras.getString(StatsActivity.STAT_TYPE_FROM);
        if (extras.containsKey(StatsActivity.STAT_TYPE_TO))
            m_refToName = extras.getString(StatsActivity.STAT_TYPE_TO);
        if (LogSettings.DEBUG)
            Log.i(TAG, "onCreate state from extra: refFrom=" + m_refFromName + " refTo=" + m_refToName);
        boolean bCalledFromNotification = extras.getBoolean(StatsActivity.FROM_NOTIFICATION, false);
        // Clear the notifications that was clicked to call the activity
        if (bCalledFromNotification) {
            NotificationManager nM = (NotificationManager) getSystemService(Service.NOTIFICATION_SERVICE);
            nM.cancel(EventWatcherService.NOTFICATION_ID);
        }
    }
    // Spinner for selecting the stat
    Spinner spinnerStat = (Spinner) findViewById(R.id.spinnerStat);
    ArrayAdapter spinnerStatAdapter = ArrayAdapter.createFromResource(this, R.array.stats, // android.R.layout.simple_spinner_item);
    R.layout.bbs_spinner_layout);
    // android.R.layout.simple_spinner_dropdown_item);
    spinnerStatAdapter.setDropDownViewResource(R.layout.bbs_spinner_dropdown_item);
    spinnerStat.setAdapter(spinnerStatAdapter);
    // setSelection MUST be called after setAdapter
    spinnerStat.setSelection(m_iStat);
    spinnerStat.setOnItemSelectedListener(this);
    // /////////////////////////////////////////////
    // Spinner for Selecting the Stat type
    // /////////////////////////////////////////////
    Spinner spinnerStatType = (Spinner) findViewById(R.id.spinnerStatType);
    // android.R.layout.simple_spinner_item);
    m_spinnerFromAdapter = new ReferencesAdapter(this, R.layout.bbs_spinner_layout);
    // android.R.layout.simple_spinner_dropdown_item);
    m_spinnerFromAdapter.setDropDownViewResource(R.layout.bbs_spinner_dropdown_item);
    spinnerStatType.setAdapter(m_spinnerFromAdapter);
    try {
        this.setListViewAdapter();
    } catch (BatteryInfoUnavailableException e) {
        Log.e(TAG, "Exception: " + Log.getStackTraceString(e));
        Snackbar.make(findViewById(android.R.id.content), R.string.info_service_connection_error, Snackbar.LENGTH_LONG).show();
    // Toast.makeText(this,
    // getString(R.string.info_service_connection_error),
    // Toast.LENGTH_LONG).show();
    } catch (Exception e) {
        // Log.e(TAG, e.getMessage(), e.fillInStackTrace());
        Log.e(TAG, "Exception: " + Log.getStackTraceString(e));
        Toast.makeText(this, getString(R.string.info_unknown_stat_error), Toast.LENGTH_LONG).show();
    }
    // setSelection MUST be called after setAdapter
    spinnerStatType.setSelection(m_spinnerFromAdapter.getPosition(m_refFromName));
    spinnerStatType.setOnItemSelectedListener(this);
    // /////////////////////////////////////////////
    // Spinner for Selecting the end sample
    // /////////////////////////////////////////////
    Spinner spinnerStatSampleEnd = (Spinner) findViewById(R.id.spinnerStatSampleEnd);
    // android.R.layout.simple_spinner_item);
    m_spinnerToAdapter = new ReferencesAdapter(this, R.layout.bbs_spinner_layout);
    // android.R.layout.simple_spinner_dropdown_item);
    m_spinnerToAdapter.setDropDownViewResource(R.layout.bbs_spinner_dropdown_item);
    spinnerStatSampleEnd.setVisibility(View.VISIBLE);
    spinnerStatSampleEnd.setAdapter(m_spinnerToAdapter);
    // setSelection must be called after setAdapter
    if ((m_refToName != null) && !m_refToName.equals("")) {
        int pos = m_spinnerToAdapter.getPosition(m_refToName);
        spinnerStatSampleEnd.setSelection(pos);
    } else {
        spinnerStatSampleEnd.setSelection(m_spinnerToAdapter.getPosition(Reference.CURRENT_REF_FILENAME));
    }
    spinnerStatSampleEnd.setOnItemSelectedListener(this);
    // /////////////////////////////////////////////
    // sorting
    // /////////////////////////////////////////////
    m_iSorting = 0;
    // log reference store
    ReferenceStore.logReferences(this);
    if (LogSettings.DEBUG) {
        Log.i(TAG, "onCreate final state: refFrom=" + m_refFromName + " refTo=" + m_refToName);
        Log.i(TAG, "OnCreated end");
    }
}
Also used : NotificationManager(android.app.NotificationManager) SharedPreferences(android.content.SharedPreferences) PackageInfo(android.content.pm.PackageInfo) Bundle(android.os.Bundle) Spinner(android.widget.Spinner) Intent(android.content.Intent) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) BatteryInfoUnavailableException(com.asksven.android.common.privateapiproxies.BatteryInfoUnavailableException) ReferencesAdapter(com.asksven.betterbatterystats.adapters.ReferencesAdapter) ChangeLog(de.cketti.library.changelog.ChangeLog) BatteryInfoUnavailableException(com.asksven.android.common.privateapiproxies.BatteryInfoUnavailableException) ArrayAdapter(android.widget.ArrayAdapter) Toolbar(android.support.v7.widget.Toolbar)

Aggregations

SwipeRefreshLayout (android.support.v4.widget.SwipeRefreshLayout)115 View (android.view.View)65 RecyclerView (android.support.v7.widget.RecyclerView)58 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)43 TextView (android.widget.TextView)30 Bundle (android.os.Bundle)21 Intent (android.content.Intent)20 Handler (android.os.Handler)17 DefaultItemAnimator (android.support.v7.widget.DefaultItemAnimator)16 Toolbar (android.support.v7.widget.Toolbar)16 ArrayList (java.util.ArrayList)16 AdapterView (android.widget.AdapterView)14 ListView (android.widget.ListView)12 ImageView (android.widget.ImageView)11 GridLayoutManager (android.support.v7.widget.GridLayoutManager)10 Context (android.content.Context)9 LayoutInflater (android.view.LayoutInflater)9 ViewGroup (android.view.ViewGroup)9 DialogInterface (android.content.DialogInterface)8 FrameLayout (android.widget.FrameLayout)7