Added certificate listing with colors to MainActivity.
This commit is contained in:
parent
11e4cc882b
commit
5159fa88b1
8 changed files with 142 additions and 16 deletions
|
@ -0,0 +1,43 @@
|
|||
package com.nutomic.zertman.test;
|
||||
|
||||
import android.test.AndroidTestCase;
|
||||
import android.test.suitebuilder.annotation.SmallTest;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.nutomic.zertman.Certificate;
|
||||
import com.nutomic.zertman.CertificateAdapter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class CertificateAdapterTest extends AndroidTestCase {
|
||||
|
||||
private CertificateAdapter mCertificateAdapter;
|
||||
|
||||
private ArrayList<Certificate> mTestCertificates = new ArrayList<Certificate>();
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
|
||||
mCertificateAdapter = new CertificateAdapter(getContext());
|
||||
mTestCertificates.add(new Certificate("first", false));
|
||||
mTestCertificates.add(new Certificate("second", true));
|
||||
mCertificateAdapter.addAll(mTestCertificates);
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
public void testAdapter() {
|
||||
for (int i = 0; i < mTestCertificates.size(); i++) {
|
||||
TextView tv1 = (TextView) mCertificateAdapter.getView(i, null, null)
|
||||
.findViewById(android.R.id.text1);
|
||||
assertTrue(tv1.getText().equals(mTestCertificates.get(i).getFile().getName()));
|
||||
}
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
public void testColors() {
|
||||
assertNotSame(mCertificateAdapter.getView(0, null, null).getBackground(),
|
||||
mCertificateAdapter.getView(1, null, null).getBackground());
|
||||
}
|
||||
|
||||
}
|
|
@ -1,19 +1,46 @@
|
|||
package com.nutomic.zertman.test;
|
||||
|
||||
import android.content.pm.ActivityInfo;
|
||||
import android.test.ActivityInstrumentationTestCase2;
|
||||
import android.test.ActivityUnitTestCase;
|
||||
import android.test.suitebuilder.annotation.SmallTest;
|
||||
import android.util.Log;
|
||||
|
||||
import com.nutomic.zertman.MainActivity;
|
||||
|
||||
public class MainActivityTest extends ActivityUnitTestCase<MainActivity> {
|
||||
public class MainActivityTest extends ActivityInstrumentationTestCase2<MainActivity> {
|
||||
|
||||
private static final String TAG = "MainActivityTest";
|
||||
|
||||
private MainActivity mActivity;
|
||||
|
||||
public MainActivityTest() {
|
||||
super(MainActivity.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
|
||||
setActivityInitialTouchMode(false);
|
||||
|
||||
mActivity = getActivity();
|
||||
getInstrumentation().waitForIdleSync();
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
public void testBlah() {
|
||||
// TODO: test for showing ListView with all cert files
|
||||
public void testOrientation() {
|
||||
try {
|
||||
mActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
|
||||
Thread.sleep(50);
|
||||
assertTrue(true);
|
||||
mActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
|
||||
Thread.sleep(50);
|
||||
assertTrue(true);
|
||||
}
|
||||
catch (InterruptedException e) {
|
||||
Log.w(TAG, "Sleep failed", e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -33,5 +33,8 @@ public class Certificate {
|
|||
? new File(CertificateManager.SYSTEM_CERTIFICATES_DIR, mFilename)
|
||||
: new File(CertificateManager.USER_CERTIFICATES_DIR, mFilename);
|
||||
}
|
||||
public boolean isSystemCertificate() {
|
||||
return mIsSystemCertificate;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
package com.nutomic.zertman;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.TextView;
|
||||
|
||||
/**
|
||||
* List Adapter for {@link Certificate}.
|
||||
*/
|
||||
public class CertificateAdapter extends ArrayAdapter<Certificate> {
|
||||
|
||||
public CertificateAdapter(Context context) {
|
||||
super(context, android.R.layout.simple_list_item_1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
if (convertView == null) {
|
||||
LayoutInflater inflater = (LayoutInflater) getContext()
|
||||
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
convertView = inflater.inflate(android.R.layout.simple_list_item_1, parent, false);
|
||||
}
|
||||
|
||||
TextView title = (TextView) convertView.findViewById(android.R.id.text1);
|
||||
title.setText(getItem(position).getFile().getName());
|
||||
convertView.setBackgroundColor(getContext().getResources().getColor(
|
||||
(getItem(position).isSystemCertificate())
|
||||
? R.color.background_system_certificate
|
||||
: R.color.background_user_certificate));
|
||||
return convertView;
|
||||
}
|
||||
|
||||
}
|
|
@ -8,6 +8,9 @@ import java.util.List;
|
|||
|
||||
import eu.chainfire.libsuperuser.Shell;
|
||||
|
||||
/**
|
||||
* Provides functions to handle system and user certificates using root.
|
||||
*/
|
||||
public class CertificateManager {
|
||||
|
||||
private static final String TAG = "CertificateManager";
|
||||
|
|
|
@ -1,15 +1,31 @@
|
|||
package com.nutomic.zertman;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.ListActivity;
|
||||
import android.os.Bundle;
|
||||
import android.widget.ListView;
|
||||
|
||||
|
||||
public class MainActivity extends Activity {
|
||||
public class MainActivity extends ListActivity {
|
||||
|
||||
private ListView mListView;
|
||||
|
||||
private CertificateAdapter mCertificateAdapter;
|
||||
|
||||
private CertificateManager mCertificateManager;
|
||||
|
||||
/**
|
||||
* Sets up ListView showing all certificates.
|
||||
*/
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main);
|
||||
|
||||
mListView = getListView();
|
||||
mCertificateAdapter = new CertificateAdapter(this);
|
||||
mCertificateManager = new CertificateManager();
|
||||
mCertificateAdapter.addAll(mCertificateManager.getCertificates(false));
|
||||
mCertificateAdapter.addAll(mCertificateManager.getCertificates(true));
|
||||
mListView.setAdapter(mCertificateAdapter);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +0,0 @@
|
|||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".MainActivity">
|
||||
|
||||
</RelativeLayout>
|
5
app/src/main/res/values/colors.xml
Normal file
5
app/src/main/res/values/colors.xml
Normal file
|
@ -0,0 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<color name="background_system_certificate">#ffe2f0b6</color>
|
||||
<color name="background_user_certificate">#ffffcaca</color>
|
||||
</resources>
|
Reference in a new issue