Skip to content

Commit

Permalink
Major refactor: switch to native fragments.
Browse files Browse the repository at this point in the history
Change-Id: I8ad7c72f1b214aea3033e26725b02a4d155da58f
  • Loading branch information
koush committed Apr 29, 2014
1 parent 2c008c6 commit 4db1b62
Show file tree
Hide file tree
Showing 16 changed files with 848 additions and 1,197 deletions.
2 changes: 1 addition & 1 deletion Superuser/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
android:versionName="1.0.3.0" >

<uses-sdk
android:minSdkVersion="8"
android:minSdkVersion="14"
android:targetSdkVersion="19" />

<permission
Expand Down
5 changes: 3 additions & 2 deletions Superuser/Superuser.iml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/gen" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/gen" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/res" type="java-resource" />
</content>
<orderEntry type="jdk" jdkName="Android 4.2.2 Platform" jdkType="Android SDK" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module" module-name="Widgets" />
</component>
Expand Down
14 changes: 7 additions & 7 deletions Superuser/src/com/koushikdutta/superuser/AboutFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ protected void onCreate(Bundle savedInstanceState, View view) {
catch (NameNotFoundException e) {
}

addItem(R.string.about, new ListItem(getInternal(), getString(R.string.superuser), version, R.drawable.ic_launcher) {
addItem(R.string.about, new ListItem(this, getString(R.string.superuser), version, R.drawable.ic_launcher) {
@Override
public void onClick(View view) {
super.onClick(view);
Expand All @@ -49,7 +49,7 @@ public void onClick(View view) {
}
});

addItem(R.string.about, new ListItem(getInternal(), "Koushik Dutta", "@koush", R.drawable.koush) {
addItem(R.string.about, new ListItem(this, "Koushik Dutta", "@koush", R.drawable.koush) {
@Override
public void onClick(View view) {
super.onClick(view);
Expand All @@ -67,7 +67,7 @@ public void onClick(View view) {
});

final String uri = "http://github.com/koush/Superuser";
addItem(R.string.about, new ListItem(getInternal(), "Github", uri, R.drawable.github) {
addItem(R.string.about, new ListItem(this, "Github", uri, R.drawable.github) {
@Override
public void onClick(View view) {
super.onClick(view);
Expand All @@ -78,7 +78,7 @@ public void onClick(View view) {
}
});

addItem(R.string.apps, new ListItem(getInternal(), "ROM Manager", "The ultimate backup, restore, and ROM installation tool", R.drawable.clockwork512) {
addItem(R.string.apps, new ListItem(this, "ROM Manager", "The ultimate backup, restore, and ROM installation tool", R.drawable.clockwork512) {
@Override
public void onClick(View view) {
super.onClick(view);
Expand All @@ -87,7 +87,7 @@ public void onClick(View view) {
startActivity(i);
}
});
addItem(R.string.apps, new ListItem(getInternal(), "Helium", "Android's missing backup solution", R.drawable.carbon) {
addItem(R.string.apps, new ListItem(this, "Helium", "Android's missing backup solution", R.drawable.carbon) {
@Override
public void onClick(View view) {
super.onClick(view);
Expand All @@ -96,7 +96,7 @@ public void onClick(View view) {
startActivity(i);
}
});
addItem(R.string.apps, new ListItem(getInternal(), "DeskSMS", "Seamlessly text message from your email, browser, or instant messenger", R.drawable.desksms) {
addItem(R.string.apps, new ListItem(this, "DeskSMS", "Seamlessly text message from your email, browser, or instant messenger", R.drawable.desksms) {
@Override
public void onClick(View view) {
super.onClick(view);
Expand All @@ -105,7 +105,7 @@ public void onClick(View view) {
startActivity(i);
}
});
addItem(R.string.apps, new ListItem(getInternal(), "Tether", "Use your phone's web connection on a laptop or PC", R.drawable.tether) {
addItem(R.string.apps, new ListItem(this, "Tether", "Use your phone's web connection on a laptop or PC", R.drawable.tether) {
@Override
public void onClick(View view) {
super.onClick(view);
Expand Down
178 changes: 161 additions & 17 deletions Superuser/src/com/koushikdutta/superuser/LogFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,176 @@

package com.koushikdutta.superuser;

import java.util.ArrayList;

import android.support.v4.app.Fragment;
import android.content.Context;
import android.os.Bundle;
import android.text.TextUtils;
import android.text.format.DateFormat;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.MenuItem.OnMenuItemClickListener;
import android.view.View;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.TextView;

import com.koushikdutta.widgets.SupportFragment;
import com.koushikdutta.superuser.db.LogEntry;
import com.koushikdutta.superuser.db.SuDatabaseHelper;
import com.koushikdutta.superuser.db.SuperuserDatabaseHelper;
import com.koushikdutta.superuser.db.UidPolicy;
import com.koushikdutta.superuser.util.Settings;
import com.koushikdutta.widgets.BetterListFragment;
import com.koushikdutta.widgets.ListItem;

public class LogFragment extends SupportFragment<LogFragmentInternal> {
public class LogFragment extends BetterListFragment {
UidPolicy up;
public LogFragment setUidPolicy(UidPolicy up) {
this.up = up;
return this;
}

int mListContentId;
public void setListContentId(int id) {
mListContentId = id;
}

public int getListContentId() {
return mListContentId;
}

void onDelete() {
}

@Override
public LogFragmentInternal createFragmentInterface() {
return new LogFragmentInternal(this) {
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {

inflater.inflate(R.menu.policy, menu);
MenuItem delete = menu.findItem(R.id.delete);
delete.setOnMenuItemClickListener(new OnMenuItemClickListener() {
@Override
void onDelete() {
super.onDelete();
LogFragment.this.onDelete(getListContentId());
public boolean onMenuItemClick(MenuItem item) {
if (up != null)
SuDatabaseHelper.delete(getActivity(), up);
else
SuperuserDatabaseHelper.deleteLogs(getActivity());
onDelete();
return true;
}
};
});
}

@Override
protected int getListItemResource() {
return R.layout.log_item;
}

void onDelete(int id) {
// getFragmentManager().beginTransaction().remove(this).commit();
// getFragmentManager().popBackStack("content", FragmentManager.POP_BACK_STACK_INCLUSIVE);
Fragment f = getFragmentManager().findFragmentById(id);
if (f != null && f instanceof PolicyFragment) {
PolicyFragment p = (PolicyFragment)f;
((PolicyFragmentInternal)p.getInternal()).load();
((PolicyFragmentInternal)p.getInternal()).showAllLogs();
@Override
protected void onCreate(Bundle savedInstanceState, View view) {
super.onCreate(savedInstanceState, view);

LayoutInflater inflater = (LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
getListView().addHeaderView(inflater.inflate(R.layout.policy_header, null));

setHasOptionsMenu(true);

if (up == null) {
Bundle bundle = getArguments();
if (bundle != null) {
String command = bundle.getString("command");
int uid = bundle.getInt("uid", -1);
int desiredUid = bundle.getInt("desiredUid", -1);
if (uid != -1 && desiredUid != -1) {
up = SuDatabaseHelper.get(getContext(), uid, desiredUid, command);
}
}
}

ArrayList<LogEntry> logs;
java.text.DateFormat day = DateFormat.getDateFormat(getActivity());
java.text.DateFormat time = DateFormat.getTimeFormat(getActivity());
if (up != null) {
ImageView icon = (ImageView)view.findViewById(R.id.image);
icon.setImageDrawable(Helper.loadPackageIcon(getActivity(), up.packageName));
TextView name = (TextView)view.findViewById(R.id.name);
name.setText(up.name);

((TextView)view.findViewById(R.id.uid_header)).setText(Integer.toString(up.desiredUid));
((TextView)view.findViewById(R.id.command_header)).setText(TextUtils.isEmpty(up.command) ? getString(R.string.all_commands) : up.command);
String app = up.username;
if (app == null || app.length() == 0)
app = String.valueOf(up.uid);
((TextView)view.findViewById(R.id.app_header)).setText(app);
((TextView)view.findViewById(R.id.package_header)).setText(up.packageName);

getListView().setSelector(android.R.color.transparent);

logs = SuperuserDatabaseHelper.getLogs(getActivity(), up, -1);
}
else {
setEmpty(R.string.no_logs);
view.findViewById(R.id.policy_header).setVisibility(View.GONE);
logs = SuperuserDatabaseHelper.getLogs(getActivity());
}

for (LogEntry log: logs) {
final String date = time.format(log.getDate());
String title = date;
String summary = getString(log.getActionResource());
if (up == null) {
title = log.getName();
}
addItem(day.format(log.getDate()), new ListItem(this, title, summary, null) {
@Override
public View getView(android.content.Context context, View convertView) {
View ret = super.getView(context, convertView);
if (up == null) {
((TextView)ret.findViewById(R.id.extra)).setText(date);
}
return ret;
}
});
}

final CompoundButton logging = (CompoundButton)view.findViewById(R.id.logging);
if (up == null) {
logging.setChecked(Settings.getLogging(getActivity()));
}
else {
logging.setChecked(up.logging);
}
logging.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton button, boolean isChecked) {
if (up == null) {
Settings.setLogging(getActivity(), isChecked);
}
else {
up.logging = isChecked;
SuDatabaseHelper.setPolicy(getActivity(), up);
}
}
});

final CompoundButton notification = (CompoundButton)view.findViewById(R.id.notification);
if (up == null) {
view.findViewById(R.id.notification_container).setVisibility(View.GONE);
}
else {
notification.setChecked(up.notification);
}
notification.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton button, boolean isChecked) {
if (up == null) {
}
else {
up.notification = isChecked;
SuDatabaseHelper.setPolicy(getActivity(), up);
}
}
});
}
}
Loading

1 comment on commit 4db1b62

@lbdroid
Copy link

@lbdroid lbdroid commented on 4db1b62 Jul 9, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change breaks the embedding patch;
http://review.cyanogenmod.org/#/c/32957

Please sign in to comment.