App settings activity

This commit is contained in:
Dominik Schürmann
2013-09-04 23:47:40 +02:00
parent d8bd6e2946
commit fcec7e830c
13 changed files with 174 additions and 50 deletions

View File

@@ -2,34 +2,89 @@ package org.sufficientlysecure.keychain.remote_api;
import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.provider.KeychainContract;
import org.sufficientlysecure.keychain.util.Log;
import android.content.ContentUris;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.TextView;
import com.actionbarsherlock.app.SherlockFragmentActivity;
public class AppSettingsActivity extends SherlockFragmentActivity {
private PackageManager pm;
long id;
String packageName;
long keyId;
boolean asciiArmor;
// derived
String appName;
// view
TextView selectedKey;
Button selectKeyButton;
CheckBox asciiArmorCheckBox;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
pm = getApplicationContext().getPackageManager();
setContentView(R.layout.api_app_settings_activity);
// check if add new or edit existing
selectedKey = (TextView) findViewById(R.id.api_app_settings_selected_key);
selectKeyButton = (Button) findViewById(R.id.api_app_settings_select_key_button);
asciiArmorCheckBox = (CheckBox) findViewById(R.id.api_app_ascii_armor);
Intent intent = getIntent();
Uri appUri = intent.getData();
if (appUri == null) {
Log.e(Constants.TAG, "Intent data missing. Should be Uri of app!");
finish();
return;
} else {
Log.d(Constants.TAG, "uri: " + appUri);
loadData(appUri);
}
}
private void loadData(Uri appUri) {
Cursor cur = getContentResolver().query(appUri, null, null, null, null);
id = ContentUris.parseId(appUri);
if (cur.moveToFirst()) {
do {
packageName = cur.getString(cur
.getColumnIndex(KeychainContract.CryptoConsumers.PACKAGE_NAME));
// get application name
try {
ApplicationInfo ai = pm.getApplicationInfo(packageName, 0);
appName = (String) pm.getApplicationLabel(ai);
} catch (final NameNotFoundException e) {
appName = getString(R.string.api_unknown_app);
}
// asciiArmor = (cur.getInt(cur
// .getColumnIndex(KeychainContract.CryptoConsumers.ASCII_ARMOR)) == 1);
// display values
// asciiArmorCheckBox.setChecked(asciiArmor);
} while (cur.moveToNext());
}
Log.d(Constants.TAG, "uri: " + appUri);
}
}

View File

@@ -1,15 +1,28 @@
package org.sufficientlysecure.keychain.remote_api;
import org.sufficientlysecure.keychain.Id;
import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.ui.SelectSecretKeyActivity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.widget.Button;
import android.widget.LinearLayout;
public class AppSettingsFragment extends Fragment {
private LinearLayout advancedSettingsContainer;
private Button advancedSettingsButton;
private Button selectKeyButton;
/**
* Inflate the layout for this fragment
*/
@@ -17,4 +30,55 @@ public class AppSettingsFragment extends Fragment {
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.api_app_settings_fragment, container, false);
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
advancedSettingsButton = (Button) getActivity().findViewById(
R.id.api_app_settings_advanced_button);
advancedSettingsContainer = (LinearLayout) getActivity().findViewById(
R.id.api_app_settings_advanced);
selectKeyButton = (Button) getActivity().findViewById(
R.id.api_app_settings_select_key_button);
final Animation visibleAnimation = new AlphaAnimation(0.0f, 1.0f);
visibleAnimation.setDuration(250);
final Animation invisibleAnimation = new AlphaAnimation(1.0f, 0.0f);
invisibleAnimation.setDuration(250);
// TODO: Better: collapse/expand animation
// final Animation animation2 = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f,
// Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, -1.0f,
// Animation.RELATIVE_TO_SELF, 0.0f);
// animation2.setDuration(150);
advancedSettingsButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (advancedSettingsContainer.getVisibility() == View.VISIBLE) {
advancedSettingsContainer.startAnimation(invisibleAnimation);
advancedSettingsContainer.setVisibility(View.INVISIBLE);
} else {
advancedSettingsContainer.startAnimation(visibleAnimation);
advancedSettingsContainer.setVisibility(View.VISIBLE);
}
}
});
selectKeyButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
selectSecretKey();
}
});
}
private void selectSecretKey() {
Intent intent = new Intent(getActivity(), SelectSecretKeyActivity.class);
startActivityForResult(intent, Id.request.secret_keys);
}
}

View File

@@ -35,9 +35,8 @@ public class RegisteredAppsAdapter extends CursorAdapter {
private LayoutInflater mInflater;
private PackageManager pm;
@SuppressWarnings("deprecation")
public RegisteredAppsAdapter(Context context, Cursor c) {
super(context, c);
public RegisteredAppsAdapter(Context context, Cursor c, int flags) {
super(context, c, flags);
mInflater = LayoutInflater.from(context);
pm = context.getApplicationContext().getPackageManager();

View File

@@ -51,7 +51,7 @@ public class RegisteredAppsListFragment extends SherlockListFragment implements
setHasOptionsMenu(true);
// Create an empty adapter we will use to display the loaded data.
mAdapter = new RegisteredAppsAdapter(getActivity(), null);
mAdapter = new RegisteredAppsAdapter(getActivity(), null, 0);
setListAdapter(mAdapter);
// Prepare the loader. Either re-connect with an existing one,