Search in sources :

Example 1 with KillAppFragment

use of edu.berkeley.cs.amplab.carat.android.subscreens.KillAppFragment in project carat by amplab.

the class SuggestionsFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    if (CaratApplication.storage.getHogReport().length == 0 && CaratApplication.storage.getBugReport().length == 0) {
        root = inflater.inflate(R.layout.emptyactions, container, false);
        return root;
    }
    root = inflater.inflate(R.layout.suggestions, container, false);
    final ListView lv = (ListView) root.findViewById(android.R.id.list);
    lv.setCacheColorHint(0);
    lv.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> a, View v, int position, long id) {
            Object o = lv.getItemAtPosition(position);
            SimpleHogBug fullObject = (SimpleHogBug) o;
            final String raw = fullObject.getAppName();
            // Log.v(TAG, "Showing kill view for " + raw);
            if (raw.equals("OsUpgrade"))
                mMainActivity.showHTMLFile("upgradeos", getString(R.string.upgradeosinfo), false);
            else //					GoToSyncScreen();
            if (raw.equals(getString(R.string.helpcarat))) {
                mMainActivity.showHTMLFile("collectdata", getString(R.string.collectdatainfo), false);
            } else if (raw.equals(getString(R.string.questionnaire))) {
                openQuestionnaire();
            } else {
                displayKillAppFragment(fullObject, raw);
            }
        }

        /*
			 * display a fragment (KillAppFragment) for killing the buggy app
			 */
        private void displayKillAppFragment(SimpleHogBug fullObject, final String raw) {
            // we need to pass the buggy app info (as a bundle named "args")
            // to the fragment
            Bundle args = new Bundle();
            args.putString("raw", raw);
            Constants.Type type = fullObject.getType();
            if (type == Constants.Type.BUG) {
                args.putBoolean("isBug", true);
                args.putBoolean("isHog", false);
                args.putBoolean("isOther", false);
            } else if (type == Constants.Type.HOG) {
                args.putBoolean("isHog", true);
                args.putBoolean("isBug", false);
                args.putBoolean("isOther", false);
            }
            if (type == Constants.Type.OTHER) {
                args.putString("appPriority", fullObject.getAppPriority());
            } else {
                args.putString("appPriority", CaratApplication.translatedPriority(fullObject.getAppPriority()));
            }
            args.putString("benefit", fullObject.getBenefitText());
            Fragment fragment = new KillAppFragment();
            fragment.setArguments(args);
            CaratApplication.getMainActivity().replaceFragment(fragment, getString(R.string.kill) + " " + raw, false);
        /*
				 * if (raw.equals("Disable bluetooth")) { double benefitOther =
				 * PowerProfileHelper. bluetoothBenefit(c); hours = (int)
				 * (benefitOther); min = (int) (benefitOther * 60); min -= hours
				 * * 60; } else if (raw.equals("Disable Wifi")) { double
				 * benefitOther = PowerProfileHelper.wifiBenefit(c); hours =
				 * (int) (benefitOther); min = (int) (benefitOther * 60); min -=
				 * hours * 60; } else if (raw.equals("Dim the Screen")) { double
				 * benefitOther = PowerProfileHelper.
				 * screenBrightnessBenefit(c); hours = (int) (benefitOther); min
				 * = (int) (benefitOther * 60); min -= hours * 60; }
				 */
        }
    });
    initUpgradeOsView(root);
    /*
        getActivity().setTitle(getResources().getString(R.string.tab_actions));
        */
    return root;
}
Also used : OnItemClickListener(android.widget.AdapterView.OnItemClickListener) Bundle(android.os.Bundle) KillAppFragment(edu.berkeley.cs.amplab.carat.android.subscreens.KillAppFragment) LocalizedWebView(edu.berkeley.cs.amplab.carat.android.ui.LocalizedWebView) View(android.view.View) AdapterView(android.widget.AdapterView) ListView(android.widget.ListView) Fragment(android.support.v4.app.Fragment) KillAppFragment(edu.berkeley.cs.amplab.carat.android.subscreens.KillAppFragment) ListView(android.widget.ListView) SimpleHogBug(edu.berkeley.cs.amplab.carat.android.storage.SimpleHogBug)

Aggregations

Bundle (android.os.Bundle)1 Fragment (android.support.v4.app.Fragment)1 View (android.view.View)1 AdapterView (android.widget.AdapterView)1 OnItemClickListener (android.widget.AdapterView.OnItemClickListener)1 ListView (android.widget.ListView)1 SimpleHogBug (edu.berkeley.cs.amplab.carat.android.storage.SimpleHogBug)1 KillAppFragment (edu.berkeley.cs.amplab.carat.android.subscreens.KillAppFragment)1 LocalizedWebView (edu.berkeley.cs.amplab.carat.android.ui.LocalizedWebView)1