use of edu.berkeley.cs.amplab.carat.android.storage.SimpleHogBug in project carat by amplab.
the class BugsOrHogsFragment method initEnergyDetails.
private void initEnergyDetails(View root, ViewGroup container) {
LayoutInflater inflater = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
detailPage = inflater.inflate(R.layout.graph, container);
w = new DrawView(getActivity());
OnClickListener detailViewer = new OnClickListener() {
@Override
public void onClick(View arg0) {
SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(getActivity());
if (p != null) {
String uuId = p.getString(CaratApplication.getRegisteredUuid(), "UNKNOWN");
HashMap<String, String> options = new HashMap<String, String>();
options.put("status", getActivity().getTitle().toString());
options.put("type", isBugs ? "Bugs" : "Hogs");
options.put("app", ((TextView) detailPage.findViewById(R.id.name)).getText() + "");
options.put("benefit", ((TextView) detailPage.findViewById(R.id.benefit)).getText().toString().replace('±', '+'));
ClickTracking.track(uuId, "whatnumbers", options, getActivity());
}
}
};
View moreinfo = detailPage.findViewById(R.id.jscore_info);
moreinfo.setOnClickListener(detailViewer);
View item = detailPage.findViewById(R.id.benefit);
item.setClickable(true);
item.setOnClickListener(detailViewer);
item = detailPage.findViewById(R.id.benefit);
item.setClickable(true);
item.setOnClickListener(detailViewer);
item = detailPage.findViewById(R.id.name);
item.setClickable(true);
item.setOnClickListener(detailViewer);
item = detailPage.findViewById(R.id.appIcon);
item.setClickable(true);
item.setOnClickListener(detailViewer);
final ListView lv = (ListView) root.findViewById(android.R.id.list);
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;
AppDetailsFragment fragment = AppDetailsFragment.getInstance(Constants.Type.BUG, fullObject, isBugs);
CaratApplication.getMainActivity().replaceFragment(fragment, fullObject.getAppName(), false);
}
});
}
use of edu.berkeley.cs.amplab.carat.android.storage.SimpleHogBug 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;
}
use of edu.berkeley.cs.amplab.carat.android.storage.SimpleHogBug in project carat by amplab.
the class HogsBugsComparator method helpCaratCollectMoreData.
/*
private void acceptDimScreen(ArrayList<SimpleHogBug> result) {
// set the screen threshold to be 50
if(!SamplingLibrary.isAutoBrightness(a.getApplicationContext()) && SamplingLibrary.getScreenBrightness(a.getApplicationContext())>50){
SimpleHogBug item=new SimpleHogBug(a.getString(R.string.dimscreen), Type.OS);
result.add(item);
}
}
private void acceptDisableWifi(ArrayList<SimpleHogBug> result) {
if(SamplingLibrary.getWifiEnabled(a.getApplicationContext())){
SimpleHogBug item=new SimpleHogBug(a.getString(R.string.disablewifi), Type.OS);
result.add(item);
}
}
private void acceptDisableLocSev(ArrayList<SimpleHogBug> result) {
List<String> providers = SamplingLibrary.getEnabledLocationProviders(a.getApplicationContext());
if (providers != null && providers.size() > 1){
// Always has 1 provider
SimpleHogBug item=new SimpleHogBug(a.getString(R.string.disablelocation), Type.OS);
result.add(item);
}
}
private void acceptDisableGps(ArrayList<SimpleHogBug> result) {
if(SamplingLibrary.getGpsEnabled(a.getApplicationContext())==true){
SimpleHogBug item=new SimpleHogBug(a.getString(R.string.disablegps), Type.OS);
result.add(item);
}
}
private void acceptDisableBluetooth(ArrayList<SimpleHogBug> result) {
BluetoothAdapter myBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
if (myBluetoothAdapter.isEnabled()==true) {
SimpleHogBug item=new SimpleHogBug(a.getString(R.string.disablebluetooth), Type.OS);
result.add(item);
}
}
private void acceptDisableHapticFb(ArrayList<SimpleHogBug> result) {
try {
if(Settings.System.getInt(
a.getApplicationContext().getContentResolver(),
Settings.System.HAPTIC_FEEDBACK_ENABLED)== 1){
SimpleHogBug item=new SimpleHogBug(a.getString(R.string.disablehapticfeedback), Type.OS);
// TODO Get expected benefit
result.add(item);
}
} catch (SettingNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private void acceptSetAutoBrightness(ArrayList<SimpleHogBug> result) {
if(!SamplingLibrary.isAutoBrightness(a.getApplicationContext())){
SimpleHogBug item=new SimpleHogBug(a.getString(R.string.automaticbrightness), Type.OS);
// TODO Get expected benefit
result.add(item);
}
}
private void acceptDisableNetwork(ArrayList<SimpleHogBug> result) {
if(SamplingLibrary.networkAvailable(a.getApplicationContext())==true){
SimpleHogBug item=new SimpleHogBug(a.getString(R.string.disablenetwork), Type.OS);
// TODO Get expected benefit
result.add(item);
}
}
private void acceptDisableVibration(ArrayList<SimpleHogBug> result) {
AudioManager myAudioManager = (AudioManager) a.getApplicationContext()
.getSystemService(Context.AUDIO_SERVICE);
if(myAudioManager.getVibrateSetting(1)==1||myAudioManager.getVibrateSetting(0)==1){
SimpleHogBug item=new SimpleHogBug(a.getString(R.string.disablevibration), Type.OS);
// TODO Get expected benefit
result.add(item);
}
}
private void acceptSetScreenTimeout(ArrayList<SimpleHogBug> result) {
try {
if(Settings.System.getInt(
a.getApplicationContext().getContentResolver(),
Settings.System.SCREEN_OFF_TIMEOUT)>30000){
SimpleHogBug item=new SimpleHogBug(a.getString(R.string.shortenscreentimeout), Type.OS);
// TODO Get expected benefit
result.add(item);
}
} catch (SettingNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private void acceptDisableAutoSync(ArrayList<SimpleHogBug> result) {
if (ContentResolver.getMasterSyncAutomatically() == true) {
SimpleHogBug item = new SimpleHogBug(
a.getString(R.string.disableautomaticsync), Type.OS);
// TODO Get expected benefit
result.add(item);
}
}*/
private void helpCaratCollectMoreData(ArrayList<SimpleHogBug> result) {
SimpleHogBug item = new SimpleHogBug(a.getString(R.string.helpcarat), Constants.Type.OS);
result.add(item);
}
use of edu.berkeley.cs.amplab.carat.android.storage.SimpleHogBug in project carat by amplab.
the class HogsBugsComparator method questionnaire.
private void questionnaire(ArrayList<SimpleHogBug> result) {
SimpleHogBug item = new SimpleHogBug(a.getString(R.string.questionnaire), Constants.Type.OTHER, a.getString(R.string.questionnaire2));
result.add(item);
}
use of edu.berkeley.cs.amplab.carat.android.storage.SimpleHogBug in project carat by amplab.
the class HogsBugsComparator method getView.
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.suggestion, null);
holder = new ViewHolder();
holder.icon = (ImageView) convertView.findViewById(R.id.suggestion_app_icon);
holder.txtName = (TextView) convertView.findViewById(R.id.actionName);
holder.txtType = (TextView) convertView.findViewById(R.id.suggestion_type);
holder.txtBenefit = (TextView) convertView.findViewById(R.id.expectedBenefit);
holder.moreInfo = (ImageView) convertView.findViewById(R.id.jscore_info);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
if (indexes == null || position < 0 || position >= indexes.length)
return convertView;
SimpleHogBug item = indexes[position];
if (item == null)
return convertView;
final String raw = item.getAppName();
Drawable icon = CaratApplication.iconForApp(a.getApplicationContext(), raw);
if (raw.equals(FAKE_ITEM)) {
holder.txtName.setText(a.getString(R.string.osupgrade));
holder.txtType.setText(a.getString(R.string.information));
holder.txtBenefit.setText(a.getString(R.string.unknown));
} else {
String label = CaratApplication.labelForApp(a.getApplicationContext(), raw);
if (label == null)
label = a.getString(R.string.unknown);
holder.icon.setImageDrawable(icon);
Constants.Type type = item.getType();
if (type == Constants.Type.BUG)
holder.txtName.setText(a.getString(R.string.restart) + " " + label);
else if (type == Constants.Type.HOG)
holder.txtName.setText(a.getString(R.string.kill) + " " + label);
else {
// Other action
holder.txtName.setText(label);
}
if (type == Constants.Type.OTHER)
holder.txtType.setText(item.getAppPriority());
else
holder.txtType.setText(CaratApplication.translatedPriority(item.getAppPriority()));
// Do not show a benefit for things that have none.
if (item.getExpectedValue() == 0 && item.getExpectedValueWithout() == 0) {
holder.txtBenefit.setText("");
TextView bl = (TextView) convertView.findViewById(R.id.benefitLegend);
bl.setText("");
} else
holder.txtBenefit.setText(item.getBenefitText());
// holder.moreInfo...
}
// }
return convertView;
}
Aggregations