Android Open Source - utwitterapi Add Application Dialog Fragmnt






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   w w  w . j  ava2  s .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.ApplicationsLoader;

import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.DialogFragment;
import android.app.LoaderManager.LoaderCallbacks;
import android.content.Context;
import android.content.Loader;
import android.content.SharedPreferences;
import android.content.pm.ApplicationInfo;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.ProgressBar;

public class AddApplicationDialogFragmnt extends DialogFragment implements Constants,
    LoaderCallbacks<List<ApplicationInfo>>, TextWatcher, OnItemClickListener {

  private ApplicationsListAdapter mAdapter;
  private ListView mListView;
  private ProgressBar mProgressBar;
  private EditText mEditSearchQuery;

  @Override
  public void afterTextChanged(final Editable s) {
  }

  @Override
  public void beforeTextChanged(final CharSequence s, final int start, final int count, final int after) {

  }

  @Override
  public Dialog onCreateDialog(final Bundle savedInstanceState) {
    final Context context = getActivity();
    final View view = LayoutInflater.from(context).inflate(R.layout.dialog_add_app, null);
    mAdapter = new ApplicationsListAdapter(context);
    mListView = (ListView) view.findViewById(android.R.id.list);
    mProgressBar = (ProgressBar) view.findViewById(android.R.id.progress);
    mEditSearchQuery = (EditText) view.findViewById(R.id.edit_search_query);
    mListView.setAdapter(mAdapter);
    mListView.setOnItemClickListener(this);
    mEditSearchQuery.addTextChangedListener(this);
    final AlertDialog.Builder builder = new AlertDialog.Builder(context);
    builder.setTitle(R.string.select_app);
    builder.setView(view);
    getLoaderManager().initLoader(0, null, this);
    return builder.create();
  }

  @Override
  public Loader<List<ApplicationInfo>> onCreateLoader(final int id, final Bundle args) {
    mListView.setVisibility(View.GONE);
    mProgressBar.setVisibility(View.VISIBLE);
    return new ApplicationsLoader(getActivity(), mEditSearchQuery.getText());
  }

  @SuppressLint("WorldReadableFiles")
  @Override
  public void onItemClick(final AdapterView<?> view, final View child, final int position, final long id) {
    final Context context = getActivity();
    @SuppressWarnings("deprecation")
    final SharedPreferences prefs = context.getSharedPreferences(SHARED_PREFERENCE_NAME_CLIENTS,
        Context.MODE_WORLD_READABLE);
    final SharedPreferences.Editor editor = prefs.edit();
    final ApplicationInfo app = mAdapter.getItem(position);
    editor.putBoolean(app.packageName, true);
    editor.apply();
    dismiss();
  }

  @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);
    mListView.setVisibility(View.VISIBLE);
    mProgressBar.setVisibility(View.GONE);
  }

  @Override
  public void onTextChanged(final CharSequence s, final int start, final int before, final int count) {
    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