android.preference.PreferenceActivity Java Examples

The following examples show how to use android.preference.PreferenceActivity. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Util.java    From AppOpsXposed with GNU General Public License v3.0 6 votes vote down vote up
public static Intent createAppOpsIntent(String packageName)
{
	final Intent intent = new Intent();
	intent.setClassName(AppOpsActivity.class.getPackage().getName(),
			AppOpsActivity.class.getName());
	intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK
			| Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NO_ANIMATION);

	if(packageName != null)
	{
		final Bundle args = new Bundle();
		args.putString(AppOpsDetails.ARG_PACKAGE_NAME, packageName);
		intent.putExtra(PreferenceActivity.EXTRA_SHOW_FRAGMENT_ARGUMENTS, args);
		intent.putExtra(PreferenceActivity.EXTRA_SHOW_FRAGMENT, AppOpsDetails.class.getName());
	}

	return intent;
}
 
Example #2
Source File: SettingsActivity.java    From green_android with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getSupportActionBar().setBackgroundDrawable(getResources().getDrawable(android.R.color.transparent));
    final String preference;
    try {
        preference = getIntent().getStringExtra(PreferenceActivity.EXTRA_SHOW_FRAGMENT);
    } catch (final Exception e) {
        e.printStackTrace();
        return;
    }

    if (preference.equals(SPVPreferenceFragment.class.getName()))
        fragment = new SPVPreferenceFragment();
    else if (preference.equals(PinPreferenceFragment.class.getName()))
        fragment = new PinPreferenceFragment();
    else
        fragment = new GeneralPreferenceFragment();
    getSupportFragmentManager().beginTransaction().add(android.R.id.content, fragment).commit();
}
 
Example #3
Source File: BlacklistActivity.java    From HeadsUp with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void setListAdapter(ListAdapter adapter) {
    if (adapter == null) {
        super.setListAdapter(null);
    } else {
        List<Header> headers = null;
        try {
            Method method = PreferenceActivity.class.getDeclaredMethod("getHeaders");
            method.setAccessible(true);
            headers = (List<Header>) method.invoke(this);
        } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) {
            e.printStackTrace();
        }

        super.setListAdapter(new HeaderAdapter(this, headers));
    }
}
 
Example #4
Source File: TestUtilities.java    From google-authenticator-android with Apache License 2.0 6 votes vote down vote up
/** Taps the specified preference displayed by the provided Activity. */
@FixWhenMinSdkVersion(11)
@SuppressWarnings("deprecation")
public static void tapPreference(PreferenceActivity activity, Preference preference) {
  // IMPLEMENTATION NOTE: There's no obvious way to find out which View corresponds to the
  // preference because the Preference list in the adapter is flattened, whereas the View
  // hierarchy in the ListView is not.
  // Thus, we go for the Reflection-based invocation of Preference.performClick() which is as
  // close to the invocation stack of a normal tap as it gets.

  // Only perform the click if the preference is in the adapter to catch cases where the
  // preference is not part of the PreferenceActivity for some reason.
  ListView listView = activity.getListView();
  ListAdapter listAdapter = listView.getAdapter();
  for (int i = 0, len = listAdapter.getCount(); i < len; i++) {
    if (listAdapter.getItem(i) == preference) {
      invokePreferencePerformClickOnMainThread(preference, activity.getPreferenceScreen());
      return;
    }
  }
  throw new IllegalArgumentException("Preference " + preference + " not in list");
}
 
Example #5
Source File: BlacklistActivity.java    From AcDisplay with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void setListAdapter(ListAdapter adapter) {
    if (adapter == null) {
        super.setListAdapter(null);
    } else {
        List<Header> headers = null;
        try {
            Method method = PreferenceActivity.class.getDeclaredMethod("getHeaders");
            method.setAccessible(true);
            headers = (List<Header>) method.invoke(this);
        } catch (Exception e) {
            e.printStackTrace();
        }

        super.setListAdapter(new HeaderAdapter(this, headers));
    }
}
 
Example #6
Source File: SettingsElements.java    From slide-android with GNU General Public License v2.0 6 votes vote down vote up
public SettingsElements(final PreferenceActivity activity, boolean firstRun)
{
    this.activity = activity;
    setPrefs();

    if (firstRun)
    {
        loadFactoryDefaults();
    } else
    {
        loadSavedDefaults();
    }

    setPrefValues();
    setPrefListeners();
}
 
Example #7
Source File: PrettyPreferenceActivity.java    From MHViewer with Apache License 2.0 5 votes vote down vote up
@Override
public void setListAdapter(ListAdapter adapter) {
  if (adapter == null) {
    super.setListAdapter(null);
    return;
  }

  int count = adapter.getCount();
  List<PreferenceActivity.Header> headers = new ArrayList<>(count);
  for (int i = 0; i < count; ++i) {
    headers.add((PreferenceActivity.Header) adapter.getItem(i));
  }

  super.setListAdapter(new HeaderAdapter(this, headers, R.layout.item_preference_header, true));
}
 
Example #8
Source File: AppListFragment.java    From AppOpsXposed with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onListItemClick(ListView l, View v, int position, long id)
{
	final Bundle args = new Bundle();
	args.putString(AppOpsDetails.ARG_PACKAGE_NAME, ((ViewHolder) v.getTag()).packageName);

	final Fragment f = new AppOpsDetails();
	f.setArguments(args);

	((PreferenceActivity) getActivity()).startPreferenceFragment(f, true);
}
 
Example #9
Source File: AppOpsCategory.java    From AppOpsXposed with GNU General Public License v3.0 5 votes vote down vote up
private void startApplicationDetailsActivity() {
    // start new fragment to display extended information
    Bundle args = new Bundle();
    args.putString(AppOpsDetails.ARG_PACKAGE_NAME, mCurrentPkgName);

    PreferenceActivity pa = (PreferenceActivity)getActivity();
    pa.startPreferencePanel(AppOpsDetails.class.getName(), args,
            R.string.app_ops_settings, null, this, RESULT_APP_DETAILS);
}
 
Example #10
Source File: PrettyPreferenceActivity.java    From EhViewer with Apache License 2.0 5 votes vote down vote up
private HeaderAdapter(Context context, List<PreferenceActivity.Header> objects, int layoutResId,
    boolean removeIconBehavior) {
  super(context, 0, objects);
  mInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  mLayoutResId = layoutResId;
  mRemoveIconIfEmpty = removeIconBehavior;
}
 
Example #11
Source File: PrettyPreferenceActivity.java    From EhViewer with Apache License 2.0 5 votes vote down vote up
@Override
public void setListAdapter(ListAdapter adapter) {
  if (adapter == null) {
    super.setListAdapter(null);
    return;
  }

  int count = adapter.getCount();
  List<PreferenceActivity.Header> headers = new ArrayList<>(count);
  for (int i = 0; i < count; ++i) {
    headers.add((PreferenceActivity.Header) adapter.getItem(i));
  }

  super.setListAdapter(new HeaderAdapter(this, headers, R.layout.item_preference_header, true));
}
 
Example #12
Source File: UserDictionaryAddWordFragment.java    From Indic-Keyboard with Apache License 2.0 5 votes vote down vote up
@Override
public void onItemSelected(final AdapterView<?> parent, final View view, final int pos,
        final long id) {
    final LocaleRenderer locale = (LocaleRenderer)parent.getItemAtPosition(pos);
    if (locale.isMoreLanguages()) {
        PreferenceActivity preferenceActivity = (PreferenceActivity)getActivity();
        preferenceActivity.startPreferenceFragment(new UserDictionaryLocalePicker(), true);
    } else {
        mContents.updateLocale(locale.getLocaleString());
    }
}
 
Example #13
Source File: Preferences.java    From XInstaller with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@SuppressWarnings("deprecation")
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    activity = getActivity();
    context = activity.getApplicationContext();

    resources = context.getResources();
    getPreferenceManager().setSharedPreferencesMode(
            Context.MODE_WORLD_READABLE);

    // If we are on a tablet
    isLarge = ((PreferenceActivity) activity).onIsMultiPane();

    ActionBar ab = activity.getActionBar();
    if (ab != null) {
        if (!isLarge) {
            ab.setDisplayHomeAsUpEnabled(true);
        }
        else
            ab.setTitle(R.string.app_name);
    }
    String whichSettings = getArguments().getString("settings");
    int prefsType = getPrefsType(whichSettings);

    addPreferencesFromResource(prefsType);

    prefs = PreferenceManager.getDefaultSharedPreferences(context);

    appLocaleManager = new AppLocaleManager(context);
    appLocaleManager.initialize();

}
 
Example #14
Source File: SuntimesActivity.java    From SuntimesWidget with GNU General Public License v3.0 5 votes vote down vote up
protected void showGeneralSettings()
{
    Intent settingsIntent = new Intent(this, SuntimesSettingsActivity.class);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
    {
        settingsIntent.putExtra( PreferenceActivity.EXTRA_SHOW_FRAGMENT, SuntimesSettingsActivity.GeneralPrefsFragment.class.getName() );
        settingsIntent.putExtra( PreferenceActivity.EXTRA_NO_HEADERS, true );

    } else {
        settingsIntent.setAction(SuntimesSettingsActivity.ACTION_PREFS_GENERAL);
    }
    startActivity(settingsIntent);
    overridePendingTransition(R.anim.transition_next_in, R.anim.transition_next_out);
}
 
Example #15
Source File: NotificationsActivity.java    From Android-Carbon-Forum with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_notifications);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    // Create the adapter that will return a fragment for each of the three
    // primary sections of the activity.
    mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
    // Set up the ViewPager with the sections adapter.
    mViewPager = (ViewPager) findViewById(R.id.container);
    mViewPager.setAdapter(mSectionsPagerAdapter);

    TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
    tabLayout.setupWithViewPager(mViewPager);
    ImageButton imageButton = (ImageButton) toolbar.findViewById(R.id.notifications_settings_button);
    imageButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent intent = new Intent(NotificationsActivity.this, SettingsActivity.class);
            intent.putExtra(PreferenceActivity.EXTRA_SHOW_FRAGMENT, SettingsActivity.NotificationPreferenceFragment.class.getName());
            intent.putExtra(PreferenceActivity.EXTRA_NO_HEADERS, true);
            startActivity(intent);
        }
    });
}
 
Example #16
Source File: LatinIME.java    From hackerskeyboard with Apache License 2.0 5 votes vote down vote up
protected void launchSettings(
        Class<? extends PreferenceActivity> settingsClass) {
    handleClose();
    Intent intent = new Intent();
    intent.setClass(LatinIME.this, settingsClass);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(intent);
}
 
Example #17
Source File: UserDictionaryAddWordFragment.java    From openboard with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onItemSelected(final AdapterView<?> parent, final View view, final int pos,
        final long id) {
    final LocaleRenderer locale = (LocaleRenderer)parent.getItemAtPosition(pos);
    if (locale.isMoreLanguages()) {
        PreferenceActivity preferenceActivity = (PreferenceActivity)getActivity();
        preferenceActivity.startPreferenceFragment(new UserDictionaryLocalePicker(), true);
    } else {
        mContents.updateLocale(locale.getLocaleString());
    }
}
 
Example #18
Source File: PrettyPreferenceActivity.java    From MHViewer with Apache License 2.0 5 votes vote down vote up
private HeaderAdapter(Context context, List<PreferenceActivity.Header> objects, int layoutResId,
    boolean removeIconBehavior) {
  super(context, 0, objects);
  mInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  mLayoutResId = layoutResId;
  mRemoveIconIfEmpty = removeIconBehavior;
}
 
Example #19
Source File: UserDictionaryAddWordFragment.java    From Android-Keyboard with Apache License 2.0 5 votes vote down vote up
@Override
public void onItemSelected(final AdapterView<?> parent, final View view, final int pos,
        final long id) {
    final LocaleRenderer locale = (LocaleRenderer)parent.getItemAtPosition(pos);
    if (locale.isMoreLanguages()) {
        PreferenceActivity preferenceActivity = (PreferenceActivity)getActivity();
        preferenceActivity.startPreferenceFragment(new UserDictionaryLocalePicker(), true);
    } else {
        mContents.updateLocale(locale.getLocaleString());
    }
}
 
Example #20
Source File: DataInteractionsTest.java    From android-espresso-revealed with Apache License 2.0 5 votes vote down vote up
@Test
public void dataInteractionSample() {
    openDrawer();
    onView(allOf(withId(R.id.design_menu_item_text),
            withText(R.string.settings_title))).perform(click());

    // Start of the flow as shown on Figure 1-8.
    onData(instanceOf(PreferenceActivity.Header.class))
            .inAdapterView(withId(android.R.id.list))
            .atPosition(0)
            .onChildView(withId(android.R.id.title))
            .check(matches(withText("General")))
            .perform(click());
    onData(withKey("email_edit_text"))
            /*we have to point explicitly what is the parent of of the General prefs list
            because there are two {@ListView}s with the same id - android.R.id.list in the hierarchy*/
            .inAdapterView(allOf(withId(android.R.id.list), withParent(withId(android.R.id.list_container))))
            .check(matches(isDisplayed()))
            .perform(click());
    onView(withId(android.R.id.edit)).perform(replaceText("[email protected]"));
    onView(withId(android.R.id.button1)).perform(click());

    // Verify new email is shown.
    onData(withKey("email_edit_text"))
            .inAdapterView(allOf(withId(android.R.id.list), withParent(withId(android.R.id.list_container))))
            .onChildView(withId(android.R.id.summary))
            .check(matches(withText("[email protected]")));
}
 
Example #21
Source File: UserDictionaryAddWordFragment.java    From AOSP-Kayboard-7.1.2 with Apache License 2.0 5 votes vote down vote up
@Override
public void onItemSelected(final AdapterView<?> parent, final View view, final int pos,
        final long id) {
    final LocaleRenderer locale = (LocaleRenderer)parent.getItemAtPosition(pos);
    if (locale.isMoreLanguages()) {
        PreferenceActivity preferenceActivity = (PreferenceActivity)getActivity();
        preferenceActivity.startPreferenceFragment(new UserDictionaryLocalePicker(), true);
    } else {
        mContents.updateLocale(locale.getLocaleString());
    }
}
 
Example #22
Source File: SettingsActivity.java    From gift-card-guard with GNU General Public License v3.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public void onBuildHeaders(List<PreferenceActivity.Header> target)
{
    loadHeadersFromResource(R.xml.pref_headers, target);
}
 
Example #23
Source File: BaseActivity.java    From android-slideshow with MIT License 5 votes vote down vote up
/**
 * Handle options menu
 */
@Override
public boolean onOptionsItemSelected(MenuItem item) {
	int id = item.getItemId();

	if (id == android.R.id.home) {
		// Do the same thing as the back button.
		onBackPressed();
		return true;
	} else if (id == R.id.action_settings) {
		Intent intent = new Intent(this, SettingsActivity.class);
		intent.putExtra(PreferenceActivity.EXTRA_SHOW_FRAGMENT, SettingsActivity.SlideshowPreferenceFragment.class.getName());
		intent.putExtra(PreferenceActivity.EXTRA_NO_HEADERS, true);
		startActivity(intent);
		return true;
	} else if (id == R.id.action_credits) {
		startActivity(new Intent(this, CreditsActivity.class));
		return true;
	} else if (id == R.id.action_change_log) {
		showChangeLog(true);
		return true;
	} else if (id == R.id.action_controls) {
		new ControlsDialog().show(getSupportFragmentManager(), ControlsDialog.TAG);
		return true;
	}
	return super.onOptionsItemSelected(item);
}
 
Example #24
Source File: Main.java    From Mizuu with Apache License 2.0 4 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    setTheme(R.style.Mizuu_Theme_Overview);

    super.onCreate(savedInstanceState);

    mPicasso = MizuuApplication.getPicasso(getApplicationContext());

    SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this);
    mStartup = Integer.valueOf(settings.getString(STARTUP_SELECTION, "1"));

    mDbHelper = MizuuApplication.getMovieAdapter();
    mDbHelperTv = MizuuApplication.getTvDbAdapter();

    mTfMedium = TypefaceUtils.getRobotoMedium(getApplicationContext());
    mTfRegular = TypefaceUtils.getRoboto(getApplicationContext());

    setupMenuItems();

    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerLayout.setStatusBarBackgroundColor(getResources().getColor(R.color.color_primary_dark));
    mDrawerLayout.setDrawerShadow(R.drawable.drawer_list_shadow, GravityCompat.START);

    mDrawerList = (ListView) findViewById(R.id.listView1);
    mDrawerList.setLayoutParams(new FrameLayout.LayoutParams(ViewUtils.getNavigationDrawerWidth(this), FrameLayout.LayoutParams.MATCH_PARENT));
    mDrawerList.setAdapter(new MenuAdapter());
    mDrawerList.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
            switch (mMenuItems.get(arg2).getType()) {
                case MenuItem.HEADER:

                    Intent intent = new Intent(getApplicationContext(), Preferences.class);
                    intent.putExtra(PreferenceActivity.EXTRA_SHOW_FRAGMENT, AccountsFragment.class.getName());
                    intent.putExtra(PreferenceActivity.EXTRA_NO_HEADERS, true);
                    intent.putExtra(PreferenceActivity.EXTRA_SHOW_FRAGMENT_TITLE, getString(R.string.social));
                    intent.putExtra(PreferenceActivity.EXTRA_SHOW_FRAGMENT_SHORT_TITLE, getString(R.string.social));

                    startActivity(intent);
                    break;

                case MenuItem.SECTION:
                    loadFragment(mMenuItems.get(arg2).getFragment());
                    break;
                case MenuItem.SETTINGS_AREA:

                    Intent smallIntent = new Intent(getApplicationContext(), Preferences.class);
                    startActivity(smallIntent);

                    mDrawerLayout.closeDrawers();

                    break;
            }
        }
    });

    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setHomeButtonEnabled(true);

    mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.string.drawer_open, R.string.drawer_close);
    mDrawerLayout.setDrawerListener(mDrawerToggle);

    if (savedInstanceState != null && savedInstanceState.containsKey("selectedIndex")) {
        selectedIndex = savedInstanceState.getInt("selectedIndex");
        loadFragment(selectedIndex);
    } else if (getIntent().getExtras() != null && getIntent().getExtras().containsKey("startup")) {
        loadFragment(Integer.parseInt(getIntent().getExtras().getString("startup")));
    } else {
        loadFragment(mStartup);
    }

    LocalBroadcastManager.getInstance(this).registerReceiver(mMessageReceiver, new IntentFilter(LocalBroadcastUtils.UPDATE_MOVIE_LIBRARY));
    LocalBroadcastManager.getInstance(this).registerReceiver(mMessageReceiver, new IntentFilter(LocalBroadcastUtils.UPDATE_TV_SHOW_LIBRARY));
}
 
Example #25
Source File: SettingsActivity.java    From island with Apache License 2.0 4 votes vote down vote up
public static void startWithPreference(final Context context, final Class<? extends PreferenceFragment> fragment) {
	final Intent intent = new Intent(context, SettingsActivity.class).putExtra(PreferenceActivity.EXTRA_SHOW_FRAGMENT, fragment.getName());
	Activities.startActivity(context, intent);
}
 
Example #26
Source File: PreferenceActivityAssert.java    From assertj-android with Apache License 2.0 4 votes vote down vote up
public PreferenceActivityAssert(PreferenceActivity actual) {
  super(actual, PreferenceActivityAssert.class);
}
 
Example #27
Source File: AppOpsDetails.java    From AppOpsXposed with GNU General Public License v3.0 4 votes vote down vote up
private void setIntentAndFinish(boolean finish, boolean appChanged) {
    Intent intent = new Intent();
    intent.putExtra("chg", appChanged);
    PreferenceActivity pa = (PreferenceActivity)getActivity();
    pa.finishPreferencePanel(this, Activity.RESULT_OK, intent);
}
 
Example #28
Source File: ViewUtils.java    From android-open-project-demo with Apache License 2.0 4 votes vote down vote up
public static void inject(Object handler, PreferenceActivity preferenceActivity) {
    injectObject(handler, new ViewFinder(preferenceActivity));
}
 
Example #29
Source File: ViewUtils.java    From android-open-project-demo with Apache License 2.0 4 votes vote down vote up
public static void inject(PreferenceActivity preferenceActivity) {
    injectObject(preferenceActivity, new ViewFinder(preferenceActivity));
}
 
Example #30
Source File: ViewFinder.java    From android-open-project-demo with Apache License 2.0 4 votes vote down vote up
public ViewFinder(PreferenceActivity preferenceActivity) {
    this.preferenceActivity = preferenceActivity;
    this.activity = preferenceActivity;
}