Android Open Source - utwitterapi Proxied Clients List Fragment






From Project

Back to project page utwitterapi.

License

The source code is released under:

GNU General Public License

If you think the Android project utwitterapi 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

package org.mariotaku.utwitterapi.fragment;
//from www  .j  ava 2s . c o  m
import java.util.List;

import org.mariotaku.utwitterapi.Constants;
import org.mariotaku.utwitterapi.R;
import org.mariotaku.utwitterapi.adapter.ApplicationsListAdapter;
import org.mariotaku.utwitterapi.loader.ProxiedApplicationsLoader;

import android.annotation.SuppressLint;
import android.app.ListFragment;
import android.app.LoaderManager.LoaderCallbacks;
import android.content.Context;
import android.content.Intent;
import android.content.Loader;
import android.content.SharedPreferences;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.util.SparseBooleanArray;
import android.view.ActionMode;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.AbsListView.MultiChoiceModeListener;
import android.widget.ListView;

public class ProxiedClientsListFragment extends ListFragment implements Constants,
    LoaderCallbacks<List<ApplicationInfo>>, OnSharedPreferenceChangeListener, MultiChoiceModeListener {

  private ApplicationsListAdapter mAdapter;
  private SharedPreferences mClientPreferences;

  @Override
  public boolean onActionItemClicked(final ActionMode mode, final MenuItem item) {
    switch (item.getItemId()) {
      case R.id.delete: {
        final SharedPreferences.Editor editor = mClientPreferences.edit();
        final SparseBooleanArray checked = getListView().getCheckedItemPositions();
        for (int i = 0, j = checked.size(); i < j; i++) {
          if (checked.valueAt(i)) {
            editor.remove(mAdapter.getItem(checked.keyAt(i)).packageName);
          }
        }
        editor.apply();
        break;
      }
    }
    mode.finish();
    return true;
  }

  @SuppressWarnings("deprecation")
  @SuppressLint("WorldReadableFiles")
  @Override
  public void onActivityCreated(final Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    final Context context = getActivity();
    mClientPreferences = context.getSharedPreferences(SHARED_PREFERENCE_NAME_CLIENTS, Context.MODE_WORLD_READABLE);
    mClientPreferences.registerOnSharedPreferenceChangeListener(this);
    mAdapter = new ApplicationsListAdapter(context, context.getPackageManager());
    setListAdapter(mAdapter);
    setListShownNoAnimation(false);
    final ListView listView = getListView();
    listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);
    listView.setMultiChoiceModeListener(this);
    getLoaderManager().initLoader(0, null, this);
  }

  @Override
  public boolean onCreateActionMode(final ActionMode mode, final Menu menu) {
    mode.setTitle(R.string.select_apps);
    new MenuInflater(getActivity()).inflate(R.menu.action_multiselect, menu);
    return true;
  }

  @Override
  public Loader<List<ApplicationInfo>> onCreateLoader(final int id, final Bundle args) {
    return new ProxiedApplicationsLoader(getActivity());
  }

  @Override
  public void onDestroyActionMode(final ActionMode mode) {

  }

  @Override
  public void onItemCheckedStateChanged(final ActionMode mode, final int position, final long id,
      final boolean checked) {

  }

  @Override
  public void onListItemClick(final ListView l, final View v, final int position, final long id) {
    final PackageManager pm = getActivity().getPackageManager();
    final ApplicationInfo info = mAdapter.getItem(position);
    final Intent intent = pm.getLaunchIntentForPackage(info.packageName);
    if (intent != null) {
      startActivity(intent);
    }
  }

  @Override
  public void onLoaderReset(final Loader<List<ApplicationInfo>> loader) {
    mAdapter.setData(null);
  }

  @Override
  public void onLoadFinished(final Loader<List<ApplicationInfo>> loader, final List<ApplicationInfo> data) {
    mAdapter.setData(data);
    setListShown(true);
  }

  @Override
  public boolean onPrepareActionMode(final ActionMode mode, final Menu menu) {
    return true;
  }

  @Override
  public void onSharedPreferenceChanged(final SharedPreferences sharedPreferences, final String key) {
    if (getActivity() == null || isDetached()) return;
    getLoaderManager().restartLoader(0, null, this);
  }

}




Java Source Code List

org.mariotaku.utwitterapi.Constants.java
org.mariotaku.utwitterapi.UTwitterAPIPlugin.java
org.mariotaku.utwitterapi.activity.BrowserSigninAgentActivity.java
org.mariotaku.utwitterapi.activity.PinCodeActivity.java
org.mariotaku.utwitterapi.activity.PluginSettingsActivity.java
org.mariotaku.utwitterapi.adapter.ApplicationsListAdapter.java
org.mariotaku.utwitterapi.fragment.AddApplicationDialogFragmnt.java
org.mariotaku.utwitterapi.fragment.EditAPIDialogFragment.java
org.mariotaku.utwitterapi.fragment.ProgressDialogFragment.java
org.mariotaku.utwitterapi.fragment.ProxiedClientsListFragment.java
org.mariotaku.utwitterapi.fragment.XposedNotAvailableDialogFragment.java
org.mariotaku.utwitterapi.hook.ApacheSSLSocketFactoryHook.java
org.mariotaku.utwitterapi.hook.HttpClientModifyRequestCallback.java
org.mariotaku.utwitterapi.hook.HttpsURLConnectionSetHostnameVerifierCallback.java
org.mariotaku.utwitterapi.hook.HttpsURLConnectionSetSSLSocketFactoryCallback.java
org.mariotaku.utwitterapi.hook.OkHttpClientModifyRequestCallback.java
org.mariotaku.utwitterapi.hook.SchemeGetSocketFactoryCallback.java
org.mariotaku.utwitterapi.hook.Twitter4JFixURLCallback.java
org.mariotaku.utwitterapi.hook.Twitter4JForceHttpsCallback.java
org.mariotaku.utwitterapi.hook.URLConnectionModifyRequestCallback.java
org.mariotaku.utwitterapi.loader.AbsApplicationsLoader.java
org.mariotaku.utwitterapi.loader.ApplicationsLoader.java
org.mariotaku.utwitterapi.loader.ProxiedApplicationsLoader.java
org.mariotaku.utwitterapi.util.AllowAllHostnameVerifierImpl.java
org.mariotaku.utwitterapi.util.OAuthPasswordAuthenticator.java
org.mariotaku.utwitterapi.util.TrustAllApacheSSLSocketFactory.java
org.mariotaku.utwitterapi.util.TrustAllSSLSocketFactory.java
org.mariotaku.utwitterapi.util.TrustAllX509TrustManager.java
org.mariotaku.utwitterapi.util.Utils.java
org.mariotaku.utwitterapi.util.XposedPluginUtils.java