Android Open Source - openmidaas-android-app Manage Consent Activity






From Project

Back to project page openmidaas-android-app.

License

The source code is released under:

Apache License

If you think the Android project openmidaas-android-app listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*******************************************************************************
 * Copyright 2013 SecureKey Technologies Inc.
 * //  w  w w.  ja  v  a 2s. c  o  m
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 ******************************************************************************/
package org.openmidaas.app.activities;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.openmidaas.app.R;
import org.openmidaas.app.activities.ui.ConsentedDetailsDialog;
import org.openmidaas.app.activities.ui.list.ConsentListAdapter;
import org.openmidaas.app.common.DialogUtils;
import org.openmidaas.app.common.Intents;
import org.openmidaas.app.common.Logger;
import org.openmidaas.app.session.ConsentManager;
import org.openmidaas.library.model.core.AbstractAttribute;
import org.openmidaas.library.model.core.MIDaaSException;
import org.openmidaas.library.persistence.AttributePersistenceCoordinator;
import org.openmidaas.library.persistence.core.AttributeDataCallback;

import android.app.Activity;
import android.app.FragmentManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class ManageConsentActivity extends AbstractActivity {
  
  private ListView mConsentListView;
  
  private TextView tvNoConsents;
  
  private ConsentListAdapter mListAdapter;
  
  private Activity mActivity;
  
  private Map<String, ArrayList<AbstractAttribute<?>>> mConsentMap;
  
  private final FragmentManager fm = getFragmentManager();
  
  private String[] mKeys;
  
  private final int REFRESH_CONSENT_LIST = 1;
  
  private final int ERROR_CREATING_CONSENT_LIST = -1;
  
  @Override
  public void onCreate(Bundle savedState) {
    super.onCreate(savedState);
    mConsentListView = (ListView)findViewById(R.id.lvConsents);
    tvNoConsents = (TextView)findViewById(R.id.tvNoConsentsPresent);
    tvNoConsents.setVisibility(View.GONE);
    mListAdapter = new ConsentListAdapter(this);
    mActivity = this;
    mConsentMap = new HashMap<String, ArrayList<AbstractAttribute<?>>>();
    fetchAllAttributesAndDisplayConsent();
    mConsentListView.setOnItemClickListener(new OnItemClickListener() {

      @Override
      public void onItemClick(AdapterView<?> adapterView, View view, int position,
          long id) {
        
        ConsentedDetailsDialog dialog = new ConsentedDetailsDialog();
        dialog.setData(mKeys[position], mConsentMap.get(mKeys[position]));
        dialog.setRetainInstance(true);
        dialog.show(fm, "consent_dialog");
      }
      
    });
  }

  private void fetchAllAttributesAndDisplayConsent() {
    mProgressDialog.setMessage("Loading consents...");
    mProgressDialog.show();
    this.mConsentMap.clear();
    Logger.debug(getClass(), "Building consent list");
    new Thread(new Runnable() {

      @Override
      public void run() {
        AttributePersistenceCoordinator.getAllAttributes(new AttributeDataCallback() {

          @Override
          public void onError(MIDaaSException exception) {
            Message msg = Message.obtain();
            msg.what =ERROR_CREATING_CONSENT_LIST;
            mHandler.sendMessage(msg);
          }

          @Override
          public void onSuccess(List<AbstractAttribute<?>> attributeList) {
            displayConsentSummary(attributeList);
          }
          
        });
      }
      
    }).start();
    
  }
  
  private void displayConsentSummary(List<AbstractAttribute<?>> attributeList) {
    List<String> rpIds = ConsentManager.getAllConsents(mActivity);
    for(String rpId: rpIds) {
      for(AbstractAttribute<?> attribute: attributeList)
      if(attribute != null) {
        if(ConsentManager.checkConsent(mActivity, rpId, attribute)) {
          if(mConsentMap.containsKey(rpId)) {
            mConsentMap.get(rpId).add(attribute);
          } else {
            ArrayList<AbstractAttribute<?>> list = new ArrayList<AbstractAttribute<?>>();
            list.add(attribute);
            mConsentMap.put(rpId, list);
          }
        }
      }
    }
    this.mKeys = this.mConsentMap.keySet().toArray(new String[this.mConsentMap.size()]);
    Message msg = Message.obtain();
    msg.what =REFRESH_CONSENT_LIST;
    mHandler.sendMessage(msg);
  }
  
  private Handler mHandler = new Handler(new Handler.Callback() {

    @Override
    public boolean handleMessage(Message msg) {
      dismissDialog();
      switch(msg.what) {
        case REFRESH_CONSENT_LIST:
          if(!mConsentMap.isEmpty()) {
            tvNoConsents.setVisibility(View.VISIBLE);
            mConsentListView.setVisibility(View.VISIBLE);
            mListAdapter.setConsentDataList(mConsentMap);
            mConsentListView.setAdapter(mListAdapter);
            RelativeLayout.LayoutParams textViewParams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                    ViewGroup.LayoutParams.WRAP_CONTENT);
            RelativeLayout.LayoutParams listViewParams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                    ViewGroup.LayoutParams.WRAP_CONTENT);
            listViewParams.addRule(RelativeLayout.BELOW, R.id.tvNoConsentsPresent);
            textViewParams.addRule(RelativeLayout.ALIGN_PARENT_TOP, RelativeLayout.TRUE);
            textViewParams.addRule(RelativeLayout.CENTER_HORIZONTAL, RelativeLayout.TRUE);
            mConsentListView.setLayoutParams(listViewParams);
            tvNoConsents.setTextSize(15);
            tvNoConsents.setPadding(5, 8, 5, 12);
            tvNoConsents.setLayoutParams(textViewParams);
            tvNoConsents.setGravity(Gravity.LEFT);
            tvNoConsents.setText(mActivity.getString(R.string.consentsSummaryInfoText));
            mListAdapter.notifyDataSetChanged();
          } else {
            RelativeLayout.LayoutParams textViewParams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                    ViewGroup.LayoutParams.WRAP_CONTENT);
            textViewParams.addRule(RelativeLayout.CENTER_HORIZONTAL, RelativeLayout.TRUE);
            textViewParams.addRule(RelativeLayout.CENTER_VERTICAL, RelativeLayout.TRUE);
            tvNoConsents.setLayoutParams(textViewParams);
            tvNoConsents.setGravity(Gravity.CENTER);
            tvNoConsents.setText(mActivity.getString(R.string.noConsentsPresentText));
            mConsentListView.setVisibility(View.GONE);
            tvNoConsents.setTextSize(18);
            tvNoConsents.setVisibility(View.VISIBLE);
          }
        break;
        case ERROR_CREATING_CONSENT_LIST:
          DialogUtils.showNeutralButtonDialog(mActivity, "Error", "Error creating consent list");
        break;
      }
      return true;
    }
  });
  
  @Override
  protected String getTitlebarText() {
    return (getString(R.string.consentActivityTitleText));
  }

  @Override
  protected int getLayoutResourceId() {
    return (R.layout.consent_summary);
  }
  
  @Override
  public void onResume() {
    super.onResume();
    registerReceiver(refreshConsentReceiver, new IntentFilter(Intents.REFRESH_CONSENT_LIST));
  }
  
  @Override
  public void onPause() {
    super.onPause();
    unregisterReceiver(refreshConsentReceiver);
  }
  
  private BroadcastReceiver refreshConsentReceiver = new BroadcastReceiver() {

    @Override
    public void onReceive(Context context, Intent intent) {
      
      fetchAllAttributesAndDisplayConsent();
    }
  };
}




Java Source Code List

org.openmidaas.app.App.java
org.openmidaas.app.Settings.java
org.openmidaas.app.activities.AboutUsActivity.java
org.openmidaas.app.activities.AbstractActivity.java
org.openmidaas.app.activities.AbstractAttributeRegistrationActivity.java
org.openmidaas.app.activities.AddressActivity.java
org.openmidaas.app.activities.AttributeListFragment.java
org.openmidaas.app.activities.AuthorizationActivity.java
org.openmidaas.app.activities.CreditCardActivity.java
org.openmidaas.app.activities.EmailRegistrationActivity.java
org.openmidaas.app.activities.EnterURLDialogFragment.java
org.openmidaas.app.activities.MainTabActivity.java
org.openmidaas.app.activities.ManageConsentActivity.java
org.openmidaas.app.activities.PhoneRegistrationActivity.java
org.openmidaas.app.activities.ProfileFragment.java
org.openmidaas.app.activities.PushNotificationActivity.java
org.openmidaas.app.activities.ScanFragment.java
org.openmidaas.app.activities.SplashActivity.java
org.openmidaas.app.activities.ui.ConsentedDetailsDialogListAdapter.java
org.openmidaas.app.activities.ui.ConsentedDetailsDialog.java
org.openmidaas.app.activities.ui.list.AbstractAttributeListElement.java
org.openmidaas.app.activities.ui.list.AbstractListCategory.java
org.openmidaas.app.activities.ui.list.AddressCategory.java
org.openmidaas.app.activities.ui.list.AddressListElement.java
org.openmidaas.app.activities.ui.list.AttributeExpandableListAdapter.java
org.openmidaas.app.activities.ui.list.AuthorizationListAdapter.java
org.openmidaas.app.activities.ui.list.BirthdayListElement.java
org.openmidaas.app.activities.ui.list.ConsentListAdapter.java
org.openmidaas.app.activities.ui.list.CreditCardCategory.java
org.openmidaas.app.activities.ui.list.CreditCardListElement.java
org.openmidaas.app.activities.ui.list.EmailAttributeListElement.java
org.openmidaas.app.activities.ui.list.EmailCategory.java
org.openmidaas.app.activities.ui.list.GenderListElement.java
org.openmidaas.app.activities.ui.list.GeneralCategory.java
org.openmidaas.app.activities.ui.list.GenericAttributeListElement.java
org.openmidaas.app.activities.ui.list.OnListElementLongTouch.java
org.openmidaas.app.activities.ui.list.OnListElementTouch.java
org.openmidaas.app.activities.ui.list.PersonalListCategory.java
org.openmidaas.app.activities.ui.list.PhoneAttributeListElement.java
org.openmidaas.app.activities.ui.list.PhoneCategory.java
org.openmidaas.app.activities.ui.spinner.AttributeSpinnerAdapter.java
org.openmidaas.app.common.AttributeRegistrationHelper.java
org.openmidaas.app.common.CategoryManager.java
org.openmidaas.app.common.CategoryMap.java
org.openmidaas.app.common.Constants.java
org.openmidaas.app.common.DialogUtils.java
org.openmidaas.app.common.Intents.java
org.openmidaas.app.common.Logger.java
org.openmidaas.app.common.Utils.java
org.openmidaas.app.services.GCMIntentService.java
org.openmidaas.app.services.GCMReceiver.java
org.openmidaas.app.session.AttributeFetchException.java
org.openmidaas.app.session.AttributeRequestObjectException.java
org.openmidaas.app.session.ConsentManager.java
org.openmidaas.app.session.EssentialAttributeMissingException.java
org.openmidaas.app.session.PostbackReturnStrategy.java
org.openmidaas.app.session.ReturnStrategyFactory.java
org.openmidaas.app.session.ReturnStrategy.java
org.openmidaas.app.session.SessionCreationException.java
org.openmidaas.app.session.SessionManager.java
org.openmidaas.app.session.Session.java
org.openmidaas.app.session.attributeset.AbstractAttributeSet.java
org.openmidaas.app.session.attributeset.AddressAttributeSet.java
org.openmidaas.app.session.attributeset.AttributeSetFactory.java
org.openmidaas.app.session.attributeset.CreditCardAttributeSet.java
org.openmidaas.app.session.attributeset.EmailAttributeSet.java
org.openmidaas.app.session.attributeset.GenericAttributeSet.java
org.openmidaas.app.session.attributeset.PhoneAttributeSet.java