Added progress bar on list items while moving certificate.
This commit is contained in:
parent
1238d2ca61
commit
73d6e1de7c
4 changed files with 40 additions and 7 deletions
|
@ -58,6 +58,7 @@
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
|
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
|
||||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates" />
|
<excludeFolder url="file://$MODULE_DIR$/build/intermediates" />
|
||||||
<excludeFolder url="file://$MODULE_DIR$/build/outputs" />
|
<excludeFolder url="file://$MODULE_DIR$/build/outputs" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/build/tmp" />
|
||||||
</content>
|
</content>
|
||||||
<orderEntry type="jdk" jdkName="Android API 19 Platform" jdkType="Android SDK" />
|
<orderEntry type="jdk" jdkName="Android API 19 Platform" jdkType="Android SDK" />
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
|
|
@ -8,6 +8,7 @@ import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.ArrayAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
|
import android.widget.ProgressBar;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -37,16 +38,25 @@ public class CertificateAdapter extends ArrayAdapter<Certificate> implements
|
||||||
convertView = inflater.inflate(R.layout.certificate_list_item, parent, false);
|
convertView = inflater.inflate(R.layout.certificate_list_item, parent, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TextView title = (TextView) convertView.findViewById(R.id.title);
|
||||||
|
Button button = (Button) convertView.findViewById(R.id.button);
|
||||||
|
ProgressBar loading = (ProgressBar) convertView.findViewById(R.id.loading);
|
||||||
|
TextView summary = (TextView) convertView.findViewById(R.id.summary);
|
||||||
|
|
||||||
|
button.setVisibility(View.VISIBLE);
|
||||||
|
loading.setVisibility(View.INVISIBLE);
|
||||||
|
|
||||||
final Certificate cert = getItem(position);
|
final Certificate cert = getItem(position);
|
||||||
// NOTE: This should be called asynchronously.
|
// NOTE: This should be called asynchronously.
|
||||||
Pair<String, String> desc = CertificateManager.getDescription(cert);
|
Pair<String, String> desc = CertificateManager.getDescription(cert);
|
||||||
TextView title = (TextView) convertView.findViewById(R.id.title);
|
|
||||||
title.setText(desc.first);
|
title.setText(desc.first);
|
||||||
TextView summary = (TextView) convertView.findViewById(R.id.summary);
|
|
||||||
summary.setText(desc.second);
|
summary.setText(desc.second);
|
||||||
Button button = (Button) convertView.findViewById(R.id.button);
|
int colorRes = android.R.color.primary_text_light;
|
||||||
int colorRes;
|
if (mCertificateManager.isMovingCertificate(cert)) {
|
||||||
if (cert.isSystemCertificate()) {
|
button.setVisibility(View.INVISIBLE);
|
||||||
|
loading.setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
|
else if (cert.isSystemCertificate()) {
|
||||||
button.setText(R.string.delete);
|
button.setText(R.string.delete);
|
||||||
button.setOnClickListener(new View.OnClickListener() {
|
button.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -13,6 +13,7 @@ import java.security.cert.CertificateException;
|
||||||
import java.security.cert.CertificateFactory;
|
import java.security.cert.CertificateFactory;
|
||||||
import java.security.cert.X509Certificate;
|
import java.security.cert.X509Certificate;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import eu.chainfire.libsuperuser.Shell;
|
import eu.chainfire.libsuperuser.Shell;
|
||||||
|
@ -40,6 +41,11 @@ public class CertificateManager {
|
||||||
ReadWrite
|
ReadWrite
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Contains all certificates that are currently being moved from user to system storage.
|
||||||
|
*/
|
||||||
|
private LinkedList<Certificate> mCurrentlyMoving = new LinkedList<Certificate>();
|
||||||
|
|
||||||
private OnCertificateChangedListener mOnCertificateChangedListener;
|
private OnCertificateChangedListener mOnCertificateChangedListener;
|
||||||
|
|
||||||
public void setOnCertificateChangedListener(OnCertificateChangedListener listener) {
|
public void setOnCertificateChangedListener(OnCertificateChangedListener listener) {
|
||||||
|
@ -68,6 +74,10 @@ public class CertificateManager {
|
||||||
* @return The updated certificate (located in system storage).
|
* @return The updated certificate (located in system storage).
|
||||||
*/
|
*/
|
||||||
public Certificate moveCertificateToSystem(Certificate certificate) {
|
public Certificate moveCertificateToSystem(Certificate certificate) {
|
||||||
|
mCurrentlyMoving.add(certificate);
|
||||||
|
if (mOnCertificateChangedListener != null) {
|
||||||
|
mOnCertificateChangedListener.onCertificateChanged();
|
||||||
|
}
|
||||||
remountSystem(Mode.ReadWrite);
|
remountSystem(Mode.ReadWrite);
|
||||||
// NOTE: Using mv gives error: "failed on *file* - Cross-device link".
|
// NOTE: Using mv gives error: "failed on *file* - Cross-device link".
|
||||||
run("cp " + USER_CERTIFICATES_DIR + "/" + certificate.getFile().getName() +
|
run("cp " + USER_CERTIFICATES_DIR + "/" + certificate.getFile().getName() +
|
||||||
|
@ -75,6 +85,7 @@ public class CertificateManager {
|
||||||
run("chmod 644 " + SYSTEM_CERTIFICATES_DIR + "/" + certificate.getFile().getName());
|
run("chmod 644 " + SYSTEM_CERTIFICATES_DIR + "/" + certificate.getFile().getName());
|
||||||
remountSystem(Mode.ReadOnly);
|
remountSystem(Mode.ReadOnly);
|
||||||
deleteCertificate(certificate);
|
deleteCertificate(certificate);
|
||||||
|
mCurrentlyMoving.remove(certificate);
|
||||||
Certificate newCert = new Certificate(certificate.getFile().getName(), true);
|
Certificate newCert = new Certificate(certificate.getFile().getName(), true);
|
||||||
if (mOnCertificateChangedListener != null) {
|
if (mOnCertificateChangedListener != null) {
|
||||||
mOnCertificateChangedListener.onCertificateChanged();
|
mOnCertificateChangedListener.onCertificateChanged();
|
||||||
|
@ -171,4 +182,8 @@ public class CertificateManager {
|
||||||
return new Pair<String, String>(primary, secondary);
|
return new Pair<String, String>(primary, secondary);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isMovingCertificate(Certificate cert) {
|
||||||
|
return mCurrentlyMoving.contains(cert);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,13 @@
|
||||||
android:layout_alignParentRight="true"
|
android:layout_alignParentRight="true"
|
||||||
style="?android:attr/buttonStyleSmall" />
|
style="?android:attr/buttonStyleSmall" />
|
||||||
|
|
||||||
|
<ProgressBar
|
||||||
|
android:id="@+id/loading"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_alignTop="@id/title"
|
||||||
|
android:layout_alignParentRight="true" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/summary"
|
android:id="@+id/summary"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
|
Reference in a new issue